You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
5.6 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
namespace BarcodeLib.UI
{
public partial class Barcodekleber : Form
{
string connecionstring = string.Empty;
public Barcodekleber()
{
InitializeComponent();
}
public Barcodekleber(string connectoinstring)
{
InitializeComponent();
this.connecionstring = connectoinstring;
}
private void Barcodekleber_Load(object sender, EventArgs e)
{
DirectoryInfo d = new DirectoryInfo(Application.StartupPath+ @"\bck"); //Assuming Test is your Folder
FileInfo[] Files = d.GetFiles("*.frx"); //Getting Text files
string str = "";
foreach (FileInfo file in Files)
{
this.cbxreportname.Items.Add(file.Name);
}
this.cbxreportname.SelectedIndex = 0;
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataSet dataSet = new DataSet();
dt.Columns.Add("barcode");
dt.Columns.Add("barcodetext");
for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
{
DataRow dr = dt.NewRow();
string s;
s = i.ToString();
while (s.Length < 8) { s = "0" + s; };
dr[0] = Bar25I(s);
dr[1] = s;
dt.Rows.Add(dr);
}
dataSet.Tables.Add(dt);
dt.TableName = "Barcodes";
FastReport.Report report = new FastReport.Report();
if (System.IO.File.Exists(Application.StartupPath + @"\bck\" + cbxreportname.Text) == true)
{
report.Load(Application.StartupPath + @"\bck\" + cbxreportname.Text);
}
else { }
report.RegisterData(dataSet);
report.GetDataSource("Barcodes").Enabled = true;
report.Preview = previewControl1;
report.Prepare();
report.Design();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataSet dataSet = new DataSet();
dt.Columns.Add("barcode");
dt.Columns.Add("barcodetext");
for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
{
DataRow dr = dt.NewRow();
Database.DB dB = new Database.DB(connecionstring);
string key = dB.get_dbkey("barcodeetikette");
string s;
s = key;
while (s.Length < 5) { s = "0" + s; };
s = DateTime.Now.Year.ToString()+s;
s = s+Helper.DivFnkt.modulo10(s).ToString();
dr[0] = Bar25I(s);
dr[1] = s;
dt.Rows.Add(dr);
}
dataSet.Tables.Add(dt);
dt.TableName = "Barcodes";
FastReport.Report report = new FastReport.Report();
if (System.IO.File.Exists(Application.StartupPath + @"\bck\" + cbxreportname.Text) == true)
{
report.Load(Application.StartupPath + @"\bck\" + cbxreportname.Text);
}
else { }
report.RegisterData(dataSet);
report.GetDataSource("Barcodes").Enabled = true;
report.Preview = previewControl1;
report.Prepare();
report.ShowPrepared();
}
public bool IsNumeric(string value)
{
return value.All(char.IsNumber);
}
public string Bar25I(string BarTextIn)
{
string Bar25IRet = default;
string BarTextOut = "";
string TempString = "";
long CharValue = 0;
string barcodeout = "";
// Initialize input and output strings
BarTextOut = "";
BarTextIn = BarTextIn.Trim();
// Throw away non-numeric data
TempString = "";
for (int II = 1, loopTo = BarTextIn.Length; II <= loopTo; II++)
{
if (IsNumeric(BarTextIn.Substring(II - 1, 1)))
{
TempString = TempString + BarTextIn.Substring(II - 1, 1);
}
}
// If not an even number of digits, add a leading 0
if (TempString.Length % 2 == 1)
{
TempString = "0" + TempString;
}
// Break digit pairs up and convert to characters- build output string
for (int II = 1, loopTo1 = TempString.Length; II <= loopTo1; II += 2)
{
// Break string into pairs of digits and get value
CharValue = Convert.ToInt32(TempString.Substring(II - 1, 2));
// translate value to ASCII and save in BarTextOut
if (CharValue < 90)
{
BarTextOut = BarTextOut + (char)(CharValue + 33);
}
else
{
BarTextOut = BarTextOut + (char)(CharValue + 71);
}
}
// Build ouput string, trailing space for Windows rasterization bug
barcodeout = "{" + BarTextOut + "} ";
// Return the string
Bar25IRet = barcodeout;
return Bar25IRet;
}
}
}