/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_012006.cs * 2.功能描述:条码打印 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2016/10/08 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.Controls { /// /// 条码打印 /// public partial class F_MST_012006 : DKFormBase { /// /// 工序条码打印用 /// private static F_MST_012006 _thisForm = null; /// /// 条码打印 /// public F_MST_012006() { InitializeComponent(); } /// /// 打印 /// /// /// private void btnPrint_Click(object sender, EventArgs e) { string barcode = this.txtBarcode.Text.Trim(); if (string.IsNullOrEmpty(barcode)) { return; } int copies = 1; if (this.txtPrintCopies.DataValue.HasValue) { copies = Convert.ToInt32(this.txtPrintCopies.DataValue); } try { this.PrintBarcodeIn(barcode, copies, true); this.txtBarcode.Clear(); this.txtBarcode.Focus(); } catch (Exception ex) { this.txtBarcode.Clear(); // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 输入条码后回车 /// /// /// private void txtBarcode_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { this.btnPrint_Click(sender, null); } } /// /// 打印条码 /// /// /// private void PrintBarcodeIn(string barcode, int copies, bool inputCopies = false) { #if DEBUG Dongke.IBOSS.PRD.Basics.Library.OutputLog.Trace(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug, "PrintBarcodeIn", "begin", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")); #endif // 获取打印模板和数据 ServiceResultEntity result = this.DoAsync(() => { ClientRequestEntity clientRequestEntity = new ClientRequestEntity(); clientRequestEntity.NameSpace = "InvoiceLayout"; clientRequestEntity.Name = "GetBarCodePrintDATA"; clientRequestEntity.Properties["Barcode"] = barcode; clientRequestEntity.Properties["IsGBarcode"] = !inputCopies; return SystemModuleProxy.Service.DoBarCodePrint(clientRequestEntity); }); if (result.Status != Basics.BaseResources.Constant.ServiceResultStatus.Success) { MessageBox.Show(result.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (result.Data == null || result.Data.Tables.Count != 2) { MessageBox.Show("没有打印数据。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DataTable layoutData = result.Data.Tables[0]; DataTable printData = result.Data.Tables[1]; if (layoutData == null || layoutData.Rows.Count == 0) { MessageBox.Show(string.Format("此产品类别【{0}】没有对应的打印模板。", printData.Rows[0]["goodstypename"]), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } byte[] bytes = layoutData.Rows[0]["LayoutData"] as byte[]; if (bytes != null) { this.layoutBox.ReadLayout(bytes); } if (!inputCopies && printData.Rows.Count > 0) { int goodsCopies = Convert.ToInt32(printData.Rows[0]["printcopies"]); if (goodsCopies > 0) { copies = goodsCopies; } } layoutBox.DataSource = printData; layoutBox.Refresh(); layoutBox.PrintDataSource = printData; layoutBox.NumberOfCopies = copies; bool isPrint = layoutBox.Print(); if (!isPrint) { return; } // 记录打印日志 //ServiceResultEntity result1 = this.DoAsync(() => //{ // ClientRequestEntity clientRequestEntity = new ClientRequestEntity(); // clientRequestEntity.NameSpace = "InvoiceLayout"; // clientRequestEntity.Name = "SetBarCodePrintLog"; // clientRequestEntity.Properties["Barcode"] = barcode; // clientRequestEntity.Properties["LayoutID"] = layoutData.Rows[0]["LayoutID"]; // return SystemModuleProxy.Service.DoBarCodePrint(clientRequestEntity); //}); } /// /// 打印条码 /// /// /// /// /// public static bool PrintBarcode(string barcode, int copies, Form owner) { if (_thisForm == null) { _thisForm = new F_MST_012006(); } if (string.IsNullOrEmpty(barcode)) { return false; } try { _thisForm.PrintBarcodeIn(barcode, copies); } catch (Exception ex) { ClientPrintException cpe = new ClientPrintException(barcode, ex); if (owner == null) { throw cpe; } else { // 对异常进行共通处理 ExceptionManager.HandleEventException(owner.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, owner.Text, cpe); } return false; } return true; } } }