F_MST_012006.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_012006.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_012006 : DKFormBase
  22. {
  23. /// <summary>
  24. /// 工序条码打印用
  25. /// </summary>
  26. private static F_MST_012006 _thisForm = null;
  27. /// <summary>
  28. /// 条码打印
  29. /// </summary>
  30. public F_MST_012006()
  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. #if DEBUG
  85. Dongke.IBOSS.PRD.Basics.Library.OutputLog.Trace(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
  86. "PrintBarcodeIn",
  87. "begin",
  88. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"));
  89. #endif
  90. // 获取打印模板和数据
  91. ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
  92. {
  93. ClientRequestEntity clientRequestEntity = new ClientRequestEntity();
  94. clientRequestEntity.NameSpace = "InvoiceLayout";
  95. clientRequestEntity.Name = "GetBarCodePrintDATA";
  96. clientRequestEntity.Properties["Barcode"] = barcode;
  97. clientRequestEntity.Properties["IsGBarcode"] = !inputCopies;
  98. return SystemModuleProxy.Service.DoBarCodePrint(clientRequestEntity);
  99. });
  100. if (result.Status != Basics.BaseResources.Constant.ServiceResultStatus.Success)
  101. {
  102. MessageBox.Show(result.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  103. return;
  104. }
  105. if (result.Data == null || result.Data.Tables.Count != 2)
  106. {
  107. MessageBox.Show("没有打印数据。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  108. return;
  109. }
  110. DataTable layoutData = result.Data.Tables[0];
  111. DataTable printData = result.Data.Tables[1];
  112. if (layoutData == null || layoutData.Rows.Count == 0)
  113. {
  114. MessageBox.Show(string.Format("此产品类别【{0}】没有对应的打印模板。", printData.Rows[0]["goodstypename"]), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  115. return;
  116. }
  117. byte[] bytes = layoutData.Rows[0]["LayoutData"] as byte[];
  118. if (bytes != null)
  119. {
  120. this.layoutBox.ReadLayout(bytes);
  121. }
  122. if (!inputCopies && printData.Rows.Count > 0)
  123. {
  124. int goodsCopies = Convert.ToInt32(printData.Rows[0]["printcopies"]);
  125. if (goodsCopies > 0)
  126. {
  127. copies = goodsCopies;
  128. }
  129. }
  130. layoutBox.DataSource = printData;
  131. layoutBox.Refresh();
  132. layoutBox.PrintDataSource = printData;
  133. layoutBox.NumberOfCopies = copies;
  134. bool isPrint = layoutBox.Print();
  135. if (!isPrint)
  136. {
  137. return;
  138. }
  139. // 记录打印日志
  140. //ServiceResultEntity result1 = this.DoAsync<ServiceResultEntity>(() =>
  141. //{
  142. // ClientRequestEntity clientRequestEntity = new ClientRequestEntity();
  143. // clientRequestEntity.NameSpace = "InvoiceLayout";
  144. // clientRequestEntity.Name = "SetBarCodePrintLog";
  145. // clientRequestEntity.Properties["Barcode"] = barcode;
  146. // clientRequestEntity.Properties["LayoutID"] = layoutData.Rows[0]["LayoutID"];
  147. // return SystemModuleProxy.Service.DoBarCodePrint(clientRequestEntity);
  148. //});
  149. }
  150. /// <summary>
  151. /// 打印条码
  152. /// </summary>
  153. /// <param name="barcode"></param>
  154. /// <param name="copies"></param>
  155. /// <param name="owner"></param>
  156. /// <returns></returns>
  157. public static bool PrintBarcode(string barcode, int copies, Form owner)
  158. {
  159. if (_thisForm == null)
  160. {
  161. _thisForm = new F_MST_012006();
  162. }
  163. if (string.IsNullOrEmpty(barcode))
  164. {
  165. return false;
  166. }
  167. try
  168. {
  169. _thisForm.PrintBarcodeIn(barcode, copies);
  170. }
  171. catch (Exception ex)
  172. {
  173. ClientPrintException cpe = new ClientPrintException(barcode, ex);
  174. if (owner == null)
  175. {
  176. throw cpe;
  177. }
  178. else
  179. {
  180. // 对异常进行共通处理
  181. ExceptionManager.HandleEventException(owner.ToString(),
  182. System.Reflection.MethodBase.GetCurrentMethod().Name, owner.Text, cpe);
  183. }
  184. return false;
  185. }
  186. return true;
  187. }
  188. }
  189. }