if (this.tbSetLabel.Text.Trim() == "")
{
MessageBox.Show("请先 Enter 选择标签模板文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.tbSetLabel.Focus();
return;
} int VarTag = 0;
if (tbVar0.Text.Trim() != "")
{
VarTag++;
}
if (tbVar1.Text.Trim() != "")
{
VarTag++;
}
if (tbVar2.Text.Trim() != "")
{
VarTag++;
}
if (tbVar3.Text.Trim() != "")
{
VarTag++;
}
if (VarTag <= 0)
{
MessageBox.Show("最少必须配置一个标签变量,请重新配置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.tbVar0.Focus();
return;
}
else
{
if (MessageBox.Show("您本次配置了 " + VarTag + "个 标签变量,请确认与您事先设计好的标签模板变量数量相同?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
LabelManager2.Application labelapp = new LabelManager2.Application(); //创建lppa.exe进程
try
{
string strPath = System.Windows.Forms.Application.StartupPath + "\\" + tbSetLabel.Text.Trim();
labelapp.Documents.Open(strPath, false);
LabelManager2.Document labeldoc = labelapp.ActiveDocument; if (VarTag == 1)
{
labeldoc.Variables.FormVariables.Item("var0").Value = tbVar0.Text.Trim();
}
if (VarTag == 2)
{
labeldoc.Variables.FormVariables.Item("var0").Value = tbVar0.Text.Trim();
labeldoc.Variables.FormVariables.Item("var1").Value = tbVar1.Text.Trim();
}
if (VarTag == 3)
{
string Var0 = "AB3R 7003 AG";
this.tbVar0.Text = Var0;
labeldoc.Variables.FormVariables.Item("var0").Value = Var0; string Var1 = "FFTB0212" + DateTime.Now.ToString("yyMMddHHmmss");
this.tbVar1.Text = Var1;
labeldoc.Variables.FormVariables.Item("var1").Value = Var1; labeldoc.Variables.FormVariables.Item("var2").Value = tbVar2.Text.Trim();
}
if (VarTag == 4)
{
//dataGridView1.Rows.Add(Var0);
//labeldoc.Variables.FormVariables.Item("var0").Value = dataGridView1.Rows[0].Cells[0].Value.ToString(); labeldoc.Variables.FormVariables.Item("var0").Value = tbVar0.Text.Trim();
labeldoc.Variables.FormVariables.Item("var1").Value = tbVar1.Text.Trim();
labeldoc.Variables.FormVariables.Item("var2").Value = tbVar2.Text.Trim();
labeldoc.Variables.FormVariables.Item("var3").Value = tbVar3.Text.Trim();
} string sql = "insert into BarCode_PrintRecord(BarCode0,BarCode1,BarCode2,BarCode3,CreatePerson,CreateDate) values (' " + tbVar0.Text.Trim() + " ','" + tbVar1.Text.Trim() + "','" + tbVar2.Text.Trim() + "','" + tbVar3.Text.Trim() + "','',GETDATE())";
SqlHelper.ExecuteNonQuery(sql); labeldoc.PrintDocument(); //打印一次
labeldoc.FormFeed(); //结束打印 labeldoc.Close(true); MessageBox.Show("\"打印条码\"完成!");
}
条码打印程序操作说明
(C#程序调用CodeSoft预先设计好的标签模块实现打印功能)
- 安装 CODESOFT 7 Enterprise
- 安装 条码打印机驱动程序
3. 安装 .NET Framework 4.5.2
4. 安装SQL Server 2008及以上版本,执行生成相应表脚本
以下以“南昌D4”项目为例演示:
一、设计条码模板(CODESOFT)
Var0、Var1、Var2共3个变量
设计好后 保存到 条码打印程序的根目录
二、打印条码
- 选择事先设计好的模板
- 配置标签变量(标签变量数量和模板数量相同)
- 点击”打印条码”
三、验证数据
查看对应表是否生成条码成功
查看打印机是否打印条码成功