| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_013006.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
- {
- /// <summary>
- /// 条码打印
- /// </summary>
- public partial class F_MST_013006 : DKFormBase
- {
- /// <summary>
- /// 工序条码打印用
- /// </summary>
- private static F_MST_013006 _thisForm = null;
- /// <summary>
- /// 条码打印
- /// </summary>
- public F_MST_013006()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 打印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 输入条码后回车
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtBarcode_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- this.btnPrint_Click(sender, null);
- }
- }
- /// <summary>
- /// 打印条码
- /// </summary>
- /// <param name="barcode"></param>
- /// <param name="copies"></param>
- private void PrintBarcodeIn(string barcode, int copies, bool inputCopies = false)
- {
- // 获取打印模板和数据
- ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
- {
- ClientRequestEntity clientRequestEntity = new ClientRequestEntity();
- clientRequestEntity.NameSpace = "MouldLableLayout";
- clientRequestEntity.Name = "GetMouldLablePrintDATA";
- 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<ServiceResultEntity>(() =>
- //{
- // 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);
- //});
- }
- /// <summary>
- /// 打印条码
- /// </summary>
- /// <param name="barcode"></param>
- /// <param name="copies"></param>
- /// <param name="owner"></param>
- /// <returns></returns>
- public static bool PrintBarcode(string barcode, int copies, Form owner)
- {
- if (_thisForm == null)
- {
- _thisForm = new F_MST_013006();
- }
- 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;
- }
- }
- }
|