F_MST_013006.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_013006.cs
  5. * 2.功能描述:条码打印
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2016/10/08 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Client.CommonModule;
  14. using Dongke.IBOSS.PRD.WCF.DataModels;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. namespace Dongke.IBOSS.PRD.Client.Controls
  17. {
  18. /// <summary>
  19. /// 条码打印
  20. /// </summary>
  21. public partial class F_MST_013006 : DKFormBase
  22. {
  23. /// <summary>
  24. /// 工序条码打印用
  25. /// </summary>
  26. private static F_MST_013006 _thisForm = null;
  27. /// <summary>
  28. /// 条码打印
  29. /// </summary>
  30. public F_MST_013006()
  31. {
  32. InitializeComponent();
  33. }
  34. /// <summary>
  35. /// 打印
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. private void btnPrint_Click(object sender, EventArgs e)
  40. {
  41. string barcode = this.txtBarcode.Text.Trim();
  42. if (string.IsNullOrEmpty(barcode))
  43. {
  44. return;
  45. }
  46. int copies = 1;
  47. if (this.txtPrintCopies.DataValue.HasValue)
  48. {
  49. copies = Convert.ToInt32(this.txtPrintCopies.DataValue);
  50. }
  51. try
  52. {
  53. this.PrintBarcodeIn(barcode, copies, true);
  54. this.txtBarcode.Clear();
  55. this.txtBarcode.Focus();
  56. }
  57. catch (Exception ex)
  58. {
  59. this.txtBarcode.Clear();
  60. // 对异常进行共通处理
  61. ExceptionManager.HandleEventException(this.ToString(),
  62. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  63. }
  64. }
  65. /// <summary>
  66. /// 输入条码后回车
  67. /// </summary>
  68. /// <param name="sender"></param>
  69. /// <param name="e"></param>
  70. private void txtBarcode_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  71. {
  72. if (e.KeyChar == (char)Keys.Enter)
  73. {
  74. this.btnPrint_Click(sender, null);
  75. }
  76. }
  77. /// <summary>
  78. /// 打印条码
  79. /// </summary>
  80. /// <param name="barcode"></param>
  81. /// <param name="copies"></param>
  82. private void PrintBarcodeIn(string barcode, int copies, bool inputCopies = false)
  83. {
  84. // 获取打印模板和数据
  85. ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
  86. {
  87. ClientRequestEntity clientRequestEntity = new ClientRequestEntity();
  88. clientRequestEntity.NameSpace = "MouldLableLayout";
  89. clientRequestEntity.Name = "GetMouldLablePrintDATA";
  90. clientRequestEntity.Properties["Barcode"] = barcode;
  91. //clientRequestEntity.Properties["IsGBarcode"] = !inputCopies;
  92. return SystemModuleProxy.Service.DoBarCodePrint(clientRequestEntity);
  93. });
  94. if (result.Status != Basics.BaseResources.Constant.ServiceResultStatus.Success)
  95. {
  96. MessageBox.Show(result.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  97. return;
  98. }
  99. if (result.Data == null || result.Data.Tables.Count != 2)
  100. {
  101. MessageBox.Show("没有打印数据。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  102. return;
  103. }
  104. DataTable layoutData = result.Data.Tables[0];
  105. DataTable printData = result.Data.Tables[1];
  106. if (layoutData == null || layoutData.Rows.Count == 0)
  107. {
  108. MessageBox.Show(string.Format("此产品类别【{0}】没有对应的打印模板。", printData.Rows[0]["goodstypename"]), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  109. return;
  110. }
  111. byte[] bytes = layoutData.Rows[0]["LayoutData"] as byte[];
  112. if (bytes != null)
  113. {
  114. this.layoutBox.ReadLayout(bytes);
  115. }
  116. //if (!inputCopies && printData.Rows.Count > 0)
  117. //{
  118. // int goodsCopies = Convert.ToInt32(printData.Rows[0]["printcopies"]);
  119. // if (goodsCopies > 0)
  120. // {
  121. // copies = goodsCopies;
  122. // }
  123. //}
  124. layoutBox.DataSource = printData;
  125. layoutBox.Refresh();
  126. layoutBox.PrintDataSource = printData;
  127. layoutBox.NumberOfCopies = copies;
  128. bool isPrint = layoutBox.Print();
  129. if (!isPrint)
  130. {
  131. return;
  132. }
  133. // 记录打印日志
  134. //ServiceResultEntity result1 = this.DoAsync<ServiceResultEntity>(() =>
  135. //{
  136. // ClientRequestEntity clientRequestEntity = new ClientRequestEntity();
  137. // clientRequestEntity.NameSpace = "InvoiceLayout";
  138. // clientRequestEntity.Name = "SetBarCodePrintLog";
  139. // clientRequestEntity.Properties["Barcode"] = barcode;
  140. // clientRequestEntity.Properties["LayoutID"] = layoutData.Rows[0]["LayoutID"];
  141. // return SystemModuleProxy.Service.DoBarCodePrint(clientRequestEntity);
  142. //});
  143. }
  144. /// <summary>
  145. /// 打印条码
  146. /// </summary>
  147. /// <param name="barcode"></param>
  148. /// <param name="copies"></param>
  149. /// <param name="owner"></param>
  150. /// <returns></returns>
  151. public static bool PrintBarcode(string barcode, int copies, Form owner)
  152. {
  153. if (_thisForm == null)
  154. {
  155. _thisForm = new F_MST_013006();
  156. }
  157. if (string.IsNullOrEmpty(barcode))
  158. {
  159. return false;
  160. }
  161. try
  162. {
  163. _thisForm.PrintBarcodeIn(barcode, copies);
  164. }
  165. catch (Exception ex)
  166. {
  167. ClientPrintException cpe = new ClientPrintException(barcode, ex);
  168. if (owner == null)
  169. {
  170. throw cpe;
  171. }
  172. else
  173. {
  174. // 对异常进行共通处理
  175. ExceptionManager.HandleEventException(owner.ToString(),
  176. System.Reflection.MethodBase.GetCurrentMethod().Name, owner.Text, cpe);
  177. }
  178. return false;
  179. }
  180. return true;
  181. }
  182. }
  183. }