private void button2_Click(object sender, EventArgs e) { // Create an instance( LabelDesign class ) LabelDesign design = new LabelDesign(); // Text design.DrawTextPtrFont("Sample Print", LabelConst.CLS_LOCALE_JP, LabelConst.CLS_PRT_FNT_TRIUMVIRATE_B, LabelConst.CLS_RT_NORMAL, 1, 1, LabelConst.CLS_PRT_FNT_SIZE_24, 20, 300); // QRCode design.DrawQRCode("DrawQRCode", LabelConst.CLS_ENC_CDPG_IBM850, LabelConst.CLS_RT_NORMAL, 4, LabelConst.CLS_QRCODE_EC_LEVEL_H, 20, 220); // Rect(fill) design.FillRect(20, 150, 350, 40, LabelConst.CLS_SHADED_PTN_11); // BarCode design.DrawBarCode("0123456789", LabelConst.CLS_BCS_CODE128, LabelConst.CLS_RT_NORMAL, 3, 3, 30, 20, 70, LabelConst.CLS_BCS_TEXT_SHOW); // Create an instance( LabelPrinter class ) LabelPrinter printer = new LabelPrinter(); // Get Type int type = (int)comboBox1.SelectedValue; // Get Address String addr = txt_Address.Text; // Set COMM Properties( COMM only ) if (LabelConst.CLS_PORT_COM == type) { printer.SetCommProperties(LabelConst.CLS_COM_BAUDRATE_9600, LabelConst.CLS_COM_PARITY_NONE, LabelConst.CLS_COM_HANDSHAKE_DTRDSR); } int result = printer.Connect(type, addr); if (LabelConst.CLS_SUCCESS == result) { int printDarkness = printer.GetPrintDarkness(); if (LabelConst.CLS_PROPERTY_DEFAULT == printDarkness) { printer.SetPrintDarkness(10); } result = printer.Print(design, 0001);// if (LabelConst.CLS_SUCCESS != result) { MessageBox.Show("Print Error : " + result.ToString(), "Citizen_Label_sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } printer.Disconnect(); } else { MessageBox.Show("Connect Error : " + result.ToString(), "Citizen_Label_sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void PrintButton_Click(object sender, EventArgs e) { Int32 index, offsetX, offsetY; LabelPrinter labelPrinter; LabelPrinter.BarCodeLabel[] barCodeLabels; LabelPrinter.BarCodeTextPositions textPosition; try { barCodeLabels = new LabelPrinter.BarCodeLabel[BarCodeListView.Items.Count]; for (index = 0; index < BarCodeListView.Items.Count; index++) { barCodeLabels[index] = ((BarCodeListViewItem)(BarCodeListView.Items[index])).GetBarCodeLabel(); } offsetX = (Int32)(OffsetX.Value); offsetY = (Int32)(OffsetY.Value); if (TextAboveRadioButton.Checked) { textPosition = LabelPrinter.BarCodeTextPositions.Above; } else { // TextBesideRadioButton is checked. textPosition = LabelPrinter.BarCodeTextPositions.Right; } labelPrinter = new LabelPrinter(PrintServerNameTextBox.Text); labelPrinter.Print(barCodeLabels, GetBarCodeHeight(), GetBarCodeWidth(), offsetX, offsetY, textPosition); } catch (Exception exception) { HandleError("Error when attempting to print bar codes", exception); } }
private void btnPrint_Click(object sender, EventArgs e) { String statusMessage = ""; int errorCode = 0; int resultCode = LabelConst.CLS_SUCCESS; int type = (int)connectType.SelectedValue; if (lstPrinters.SelectedItems.Count <= 0) { MessageBox.Show("No printer is selected.", "Error"); return; } LabelPrinter printer = new LabelPrinter(); resultCode = printer.Connect(type, lstPrinters.Items[0].Text); printer.SetLog(1, "C:\\Users\\bukha\\Desktop\\Logs", 10); if (resultCode != LabelConst.CLS_SUCCESS) { this.PrinterErrorProc(printer, eErrorKind.eErrConnect, resultCode, null); return; } resultCode = printer.PrinterCheck(); if (resultCode != LabelConst.CLS_SUCCESS) { this.PrinterErrorProc(printer, eErrorKind.eErrPrinterCheck, resultCode, null); printer.Disconnect(); return; } statusMessage = ""; this.CheckPrinterStatus(printer, ref errorCode, ref statusMessage); if (errorCode != 0) { this.PrinterErrorProc(printer, eErrorKind.eErrPrinterStatus, 0, statusMessage); printer.Disconnect(); return; } printer.SetMeasurementUnit(LabelConst.CLS_UNIT_INCH); LabelDesign design = new LabelDesign(); this.DesignLabel(design); resultCode = printer.Print(design, 3); if (resultCode != LabelConst.CLS_SUCCESS) { this.PrinterErrorProc(printer, eErrorKind.eErrPrint, resultCode, null); printer.Disconnect(); return; } System.Threading.Thread.Sleep(500); while (true) { resultCode = printer.PrinterCheck(); if (resultCode != LabelConst.CLS_SUCCESS) { this.PrinterErrorProc(printer, eErrorKind.eErrPrinterCheck, resultCode, null); printer.Disconnect(); return; } if (printer.GetPrinting() == 0 & printer.GetBatchProcessing() == 0) { break; } } statusMessage = ""; this.CheckPrinterStatus(printer, ref errorCode, ref statusMessage); if (errorCode != 0) { this.PrinterErrorProc(printer, eErrorKind.eErrPrinterStatus, 0, statusMessage); } else { MessageBox.Show("Success", "Print Result"); } }
/// </summary> /// <param name="Grade">牌号</param> /// <param name="HeatNo">炉号</param> /// <param name="RollingNo">轧制号</param> /// <param name="BudleNo">捆号</param> /// <param name="Size">规格</param> /// <param name="Weight">重量</param> /// <param name="Standard">标准</param> /// <param name="Date">日期</param> /// <param name="DStatus"></param> /// <param name="ProductName">产品名称</param> /// <param name="Licence">许可证</param> public void AutoPNGJNPrint(string Grade, string HeatNo, string RollingNo, string BudleNo, string Size, string Weight, string Standard, string Date, string DStatus, string ProductName, string Licence) { try { if (InvokeRequired) { Invoke(new PrintJNDelegate(AutoPNGJNPrint), new object[] { Grade, HeatNo, RollingNo, BudleNo, Size, Weight, Standard, Date, DStatus, ProductName, Licence }); } else { DStatus = SoftConfig.DStatus; //热轧 ProductName = SoftConfig.ProductName; //钢筋混凝 BottomData = RollingNo + BudleNo; //轧钢号+捆号 //公司名→牌号→规格→轧制号捆号→重量→生产日期→炉号→标准号→许可证号 DataMatrixStr = SoftConfig.CompanyName + ";" + Grade + ";" + Size + ";" + BottomData + ";" + Weight + ";" + Date + ";" + HeatNo + ";" + Standard + ";" + Licence; LabelDesign design = new LabelDesign(); #region 默认代码 // Text (数据,字体名称,是否旋转,水平占比,垂直占比,字体大小,?,x坐标,y坐标,DPI,计量单位) //design.DrawTextPCFont(Grade, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555,LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//牌号 //design.DrawTextPCFont(HeatNo, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//炉号 //design.DrawTextPCFont(RollingNo, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//轧制号 //design.DrawTextPCFont(BudleNo, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//捆号 //design.DrawTextPCFont(Size, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//规格 //design.DrawTextPCFont(Weight, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//重量 //design.DrawTextPCFont(Standard, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//标准 //design.DrawTextPCFont(Date, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//日期 //design.DrawTextPCFont(DStatus, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//交付状态 //design.DrawTextPCFont(ProductName, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//产品名称 //design.DrawTextPCFont(Licence, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//许可证 //design.DrawTextPCFont(BottomData, "Arial", LabelConst.CLS_RT_NORMAL, 50, 50, 12, LabelConst.CLS_FNT_DEFAULT, 85, 555, LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI);//底部数据 #endregion if (checkBox1.Checked) { string select = comboBox2.Text; int angle = 0; switch (select) { case "90": angle = 2; break; case "180": angle = 3; break; case "270": angle = 4; break; default: break; } //牌号 if (!string.IsNullOrEmpty(txt_Grade_x.Text) && !string.IsNullOrEmpty(txt_Grade_y.Text)) { design.DrawTextPCFont(Grade, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Grade_x.Text), Convert.ToInt16(txt_Grade_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //炉号 if (!string.IsNullOrEmpty(txt_HeatNo_x.Text) && !string.IsNullOrEmpty(txt_HeatNo_y.Text)) { design.DrawTextPCFont(HeatNo, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_HeatNo_x.Text), Convert.ToInt16(txt_HeatNo_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //轧制号 if (!string.IsNullOrEmpty(txt_RollingNo_x.Text) && !string.IsNullOrEmpty(txt_RollingNo_y.Text)) { design.DrawTextPCFont(RollingNo, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_RollingNo_x.Text), Convert.ToInt16(txt_RollingNo_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //捆号 if (!string.IsNullOrEmpty(txt_BudleNo_x.Text) && !string.IsNullOrEmpty(txt_BudleNo_y.Text)) { design.DrawTextPCFont(BudleNo, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_BudleNo_x.Text), Convert.ToInt16(txt_BudleNo_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //规格 if (!string.IsNullOrEmpty(txt_Size_x.Text) && !string.IsNullOrEmpty(txt_Size_y.Text)) { design.DrawTextPCFont(Size, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Size_x.Text), Convert.ToInt16(txt_Size_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //重量 if (!string.IsNullOrEmpty(txt_Weight_x.Text) && !string.IsNullOrEmpty(txt_Weight_y.Text)) { design.DrawTextPCFont(Weight, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Weight_x.Text), Convert.ToInt16(txt_Weight_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //标准 if (!string.IsNullOrEmpty(txt_Standard_x.Text) && !string.IsNullOrEmpty(txt_Standard_y.Text)) { design.DrawTextPCFont(Standard, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Standard_x.Text), Convert.ToInt16(txt_Standard_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //日期Date if (!string.IsNullOrEmpty(txt_Date_x.Text) && !string.IsNullOrEmpty(txt_Date_y.Text)) { design.DrawTextPCFont(Date, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Date_x.Text), Convert.ToInt16(txt_Date_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //交付状态 if (!string.IsNullOrEmpty(txt_DSstatus_x.Text) && !string.IsNullOrEmpty(txt_DSstatus_y.Text)) { design.DrawTextPCFont(DStatus, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_DSstatus_x.Text), Convert.ToInt16(txt_DSstatus_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //产品名称 if (!string.IsNullOrEmpty(txt_ProductName_x.Text) && !string.IsNullOrEmpty(txt_ProductName_y.Text)) { design.DrawTextPCFont(ProductName, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_ProductName_x.Text), Convert.ToInt16(txt_ProductName_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //许可证 if (!string.IsNullOrEmpty(txt_Licence_x.Text) && !string.IsNullOrEmpty(txt_Licence_y.Text)) { design.DrawTextPCFont(Licence, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Licence_x.Text), Convert.ToInt16(txt_Licence_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //底部数据 if (!string.IsNullOrEmpty(txt_BottomData_x.Text) && !string.IsNullOrEmpty(txt_BottomData_y.Text)) { design.DrawTextPCFont(BottomData, "Arial", angle, 100, 100, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_BottomData_x.Text), Convert.ToInt16(txt_BottomData_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //条形码(数据,编码格式,是否旋转,厚宽,窄宽,高度,x坐标,y坐标) if (!string.IsNullOrEmpty(txt_BarCode_x.Text) && !string.IsNullOrEmpty(txt_BarCode_y.Text)) { design.DrawBarCode(BottomData, LabelConst.CLS_BCS_CODE128, angle, 3, 3, 15, Convert.ToInt16(txt_BarCode_x.Text), Convert.ToInt16(txt_BarCode_y.Text), LabelConst.CLS_BCS_TEXT_HIDE); } //二维码(数据,编码格式,是否旋转,放大倍数,等级,x坐标,y坐标) if (!string.IsNullOrEmpty(txt_MatriStr_x.Text) && !string.IsNullOrEmpty(txt_MatriStr_y.Text)) { design.DrawQRCode(DataMatrixStr, LabelConst.CLS_ENC_CDPG_IBM850, angle, 4, LabelConst.CLS_QRCODE_EC_LEVEL_H, Convert.ToInt16(txt_MatriStr_x.Text), Convert.ToInt16(txt_MatriStr_y.Text)); } } else { //牌号 if (!string.IsNullOrEmpty(txt_Grade_x.Text) && !string.IsNullOrEmpty(txt_Grade_y.Text)) { design.DrawTextPCFont(Grade, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Grade_x.Text), Convert.ToInt16(txt_Grade_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //炉号 if (!string.IsNullOrEmpty(txt_HeatNo_x.Text) && !string.IsNullOrEmpty(txt_HeatNo_y.Text)) { design.DrawTextPCFont(HeatNo, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_HeatNo_x.Text), Convert.ToInt16(txt_HeatNo_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //轧制号 if (!string.IsNullOrEmpty(txt_RollingNo_x.Text) && !string.IsNullOrEmpty(txt_RollingNo_y.Text)) { design.DrawTextPCFont(RollingNo, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_RollingNo_x.Text), Convert.ToInt16(txt_RollingNo_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //捆号 if (!string.IsNullOrEmpty(txt_BudleNo_x.Text) && !string.IsNullOrEmpty(txt_BudleNo_y.Text)) { design.DrawTextPCFont(BudleNo, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_BudleNo_x.Text), Convert.ToInt16(txt_BudleNo_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //规格 if (!string.IsNullOrEmpty(txt_Size_x.Text) && !string.IsNullOrEmpty(txt_Size_y.Text)) { design.DrawTextPCFont(Size, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Size_x.Text), Convert.ToInt16(txt_Size_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //重量 if (!string.IsNullOrEmpty(txt_Weight_x.Text) && !string.IsNullOrEmpty(txt_Weight_y.Text)) { design.DrawTextPCFont(Weight, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Weight_x.Text), Convert.ToInt16(txt_Weight_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //标准 if (!string.IsNullOrEmpty(txt_Standard_x.Text) && !string.IsNullOrEmpty(txt_Standard_y.Text)) { design.DrawTextPCFont(Standard, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Standard_x.Text), Convert.ToInt16(txt_Standard_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //日期Date if (!string.IsNullOrEmpty(txt_Date_x.Text) && !string.IsNullOrEmpty(txt_Date_y.Text)) { design.DrawTextPCFont(Date, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Date_x.Text), Convert.ToInt16(txt_Date_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //交付状态 if (!string.IsNullOrEmpty(txt_DSstatus_x.Text) && !string.IsNullOrEmpty(txt_DSstatus_y.Text)) { design.DrawTextPCFont(DStatus, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_DSstatus_x.Text), Convert.ToInt16(txt_DSstatus_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //产品名称 if (!string.IsNullOrEmpty(txt_ProductName_x.Text) && !string.IsNullOrEmpty(txt_ProductName_y.Text)) { design.DrawTextPCFont(ProductName, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_ProductName_x.Text), Convert.ToInt16(txt_ProductName_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //许可证 if (!string.IsNullOrEmpty(txt_Licence_x.Text) && !string.IsNullOrEmpty(txt_Licence_y.Text)) { design.DrawTextPCFont(Licence, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 12, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_Licence_x.Text), Convert.ToInt16(txt_Licence_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } //底部数据 if (!string.IsNullOrEmpty(txt_BottomData_x.Text) && !string.IsNullOrEmpty(txt_BottomData_y.Text)) { if (!string.IsNullOrEmpty(txt_Size.Text)) { int size = Convert.ToInt16(txt_Size.Text); design.DrawTextPCFont(BottomData, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, size, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_BottomData_x.Text), Convert.ToInt16(txt_BottomData_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } else { design.DrawTextPCFont(BottomData, "Arial", LabelConst.CLS_RT_NORMAL, SoftConfig.hRatio, SoftConfig.vRatio, 11, LabelConst.CLS_FNT_DEFAULT, Convert.ToInt16(txt_BottomData_x.Text), Convert.ToInt16(txt_BottomData_y.Text), LabelConst.CLS_PRT_RES_300, LabelConst.CLS_UNIT_MILLI); } } //条形码(数据,编码格式,是否旋转,厚宽,窄宽,高度,x坐标,y坐标) if (!string.IsNullOrEmpty(txt_BarCode_x.Text) && !string.IsNullOrEmpty(txt_BarCode_y.Text)) { design.DrawBarCode(BottomData, LabelConst.CLS_BCS_CODE128, LabelConst.CLS_RT_NORMAL, 3, 3, 15, Convert.ToInt16(txt_BarCode_x.Text), Convert.ToInt16(txt_BarCode_y.Text), LabelConst.CLS_BCS_TEXT_HIDE); } //二维码(数据,编码格式,是否旋转,放大倍数,等级,x坐标,y坐标) if (!string.IsNullOrEmpty(txt_MatriStr_x.Text) && !string.IsNullOrEmpty(txt_MatriStr_y.Text)) { design.DrawQRCode(DataMatrixStr, LabelConst.CLS_ENC_CDPG_IBM850, LabelConst.CLS_RT_NORMAL, 4, LabelConst.CLS_QRCODE_EC_LEVEL_H, Convert.ToInt16(txt_MatriStr_x.Text), Convert.ToInt16(txt_MatriStr_y.Text)); } } int type = (int)comboBox1.SelectedValue; //string address = txt_Address.Text; LabelPrinter printer = new LabelPrinter(); int result = printer.Connect(type, SoftConfig.UsbName); // Set COMM Properties( COMM only ) if (LabelConst.CLS_PORT_COM == type) { printer.SetCommProperties(LabelConst.CLS_COM_BAUDRATE_9600, LabelConst.CLS_COM_PARITY_NONE, LabelConst.CLS_COM_HANDSHAKE_DTRDSR); } if (LabelConst.CLS_SUCCESS == result)// { int printDarkness = printer.GetPrintDarkness(); if (LabelConst.CLS_PROPERTY_DEFAULT == printDarkness) { if (!string.IsNullOrEmpty(txt_DarkNess.Text)) { int darkNess = Convert.ToInt16(txt_DarkNess.Text); printer.SetPrintDarkness(darkNess); } else { printer.SetPrintDarkness(10); } } if (checkBox2.Checked) { result = printer.Print(design, 0002); } else { result = printer.Print(design, 0001);//测试先打印一张 打印两张 } if (LabelConst.CLS_SUCCESS != result) { MessageBox.Show("Print Error : " + result.ToString(), "手动打印", MessageBoxButtons.OK, MessageBoxIcon.Error); } printer.Disconnect(); } else { MessageBox.Show("打印机连接失败,请查看原因...错误代码:" + result); } } } catch (Exception ex) { MessageBox.Show("打印出错:" + ex.Message); } }
public static string PrintLabel(Order ord, Order.IncOrder incOrd, Pack pack) { string comment; string barcode; Material labelMat; decimal gross = pack.tareWeight + pack.netWeight; if (ord.material.madeToOrd && incOrd.customer == null && ord.material.targetMatNumber != null) { //This is a bin going to AP that has an automatic material-to-material done as part of the GR process. It should be //labelled up as if it were the target material of the mat-2-mat. comment = "Converted from: " + ord.materialNum; // Use target material's details on label labelMat = CommonData.mats.Find(m => m.matNumber.Equals(ord.material.targetMatNumber)); } else { comment = ""; labelMat = ord.material; } barcode = string.Format("000000000{0:0000000000}91{1}", pack.serial, pack.useFreezer ? "1" : "0"); var dict = new Dictionary <string, string>(); dict.Add("&MATNR&", labelMat.matNumber); dict.Add("&MAKTX_1&", labelMat.labelLine1); dict.Add("&MAKTX_2&", labelMat.labelLine2); dict.Add("&MAKTX_3&", labelMat.labelLine3); dict.Add("&MAKTX_4&", labelMat.labelLine4); dict.Add("&DEVCE&", labelMat.Ean); dict.Add("&NTGEW_2DPLS&", pack.netWeight.ToString("0.00")); dict.Add("&BRGEW_2DPLS&", gross.ToString("0.00")); dict.Add("&TAGEW&", pack.tareWeight.ToString()); dict.Add("&EXIDV&", pack.serial.ToString("0000000000")); dict.Add("&BARCODE&", barcode); dict.Add("&ERNAM&", "BCP:" + pack.user); dict.Add("&HSDAT&", pack.manuDate.ToString("dd.MM.yyyy")); dict.Add("&HSDAT_S&", pack.manuDate.ToString("yyMMdd")); dict.Add("&HSDAT_DDMMMYY&", pack.manuDate.ToString("dd MMM yy")); dict.Add("&ERZET&", pack.packedOn.ToString("HH:mm:ss")); dict.Add("&VFDAT&", pack.expiryDate.ToString("dd.MM.yyyy")); dict.Add("&VFDAT_DDMMMYY&", pack.expiryDate.ToString("dd MMM yy")); dict.Add("&MBLNR&", labelMat.oldMatNumber); dict.Add("&WRK_NAME&", labelMat.custMatNumber); dict.Add("&WRK_STR&", comment); dict.Add("&TERMI&", CommonData.sapSettings.device); dict.Add("&SLDATES&", pack.slaughterDates); decimal netNoDec = decimal.Round(pack.netWeight * 100, 0); dict.Add("&NTGEW_OPUNKT&", netNoDec.ToString("000000")); dict.Add("&AAPOS&", netNoDec.ToString("0000")); printer.Print(labelMat.labelFile, dict); // Save away info of last label printed, needed for Re-print Last ordLastPrint = ord; incOrdLastPrint = incOrd; packLastPrint = pack; return(barcode); }