F_SET_014003.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO.Packaging;
  7. using System.Reflection;
  8. using System.Runtime.InteropServices;
  9. using System.Windows.Forms;
  10. using Curtain.Framework.Json;
  11. using Dongke.IBOSS.PRD.Basics.BaseResources;
  12. using Dongke.IBOSS.PRD.Client.CommonModule;
  13. using Dongke.IBOSS.PRD.WCF.DataModels;
  14. using Dongke.IBOSS.PRD.WCF.DataModels.BarcodeBatchSet;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. using Dongke.WinForm.Controls;
  17. namespace Dongke.IBOSS.PRD.Client.Controls
  18. {
  19. public partial class F_SET_014003 : DKFormBase
  20. {
  21. private ClientRequestEntity _clientRequestEntity = null; // 查询条件实体
  22. private BarcodeBatchConfig _setData;
  23. private DataTable _DataItem;
  24. public List<DataRow> PrintData
  25. {
  26. get;
  27. set;
  28. }
  29. public F_SET_014003()
  30. {
  31. InitializeComponent();
  32. }
  33. private void F_SET_014003_Load(object sender, EventArgs e)
  34. {
  35. try
  36. {
  37. //_printDataRow = new List<DataRow>();
  38. //if (PrintData != null)
  39. //{
  40. // foreach (DataRow item in PrintData.Rows)
  41. // {
  42. // if (item["SEL"] + "" == "1" && string.IsNullOrEmpty(item["BARCODE"] + ""))
  43. // {
  44. // _printDataRow.Add(item);
  45. // }
  46. // }
  47. //}
  48. }
  49. catch (Exception ex)
  50. {
  51. // 对异常进行共通处理
  52. ExceptionManager.HandleEventException(this.ToString(),
  53. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  54. }
  55. }
  56. private void F_SET_014003_Shown(object sender, EventArgs e)
  57. {
  58. try
  59. {
  60. this.QueryDataFromOther();
  61. }
  62. catch (Exception ex)
  63. {
  64. // 对异常进行共通处理
  65. ExceptionManager.HandleEventException(this.ToString(),
  66. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  67. }
  68. }
  69. private void tsbtnClose_Click(object sender, EventArgs e)
  70. {
  71. this.Close();
  72. }
  73. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  74. {
  75. this.dgvInvoice.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  76. }
  77. private void tsbtnClearCondition_Click(object sender, EventArgs e)
  78. {
  79. this.ClearConditions();
  80. }
  81. /// <summary>
  82. /// 清除查询条件
  83. /// </summary>
  84. public void ClearConditions()
  85. {
  86. this.txtInvoiceName.Text = string.Empty;
  87. this.txtRemarks.Text = string.Empty;
  88. }
  89. private void tsbtnSearch_Click(object sender, EventArgs e)
  90. {
  91. try
  92. {
  93. this.QueryDataFromOther();
  94. }
  95. catch (Exception ex)
  96. {
  97. // 对异常进行共通处理
  98. ExceptionManager.HandleEventException(this.ToString(),
  99. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  100. }
  101. }
  102. /// <summary>
  103. /// 获取查询实体
  104. /// </summary>
  105. private void SearchSelectEntity()
  106. {
  107. this._clientRequestEntity = new ClientRequestEntity();
  108. this._clientRequestEntity.NameSpace = "F_SET_014001";
  109. this._clientRequestEntity.Name = "GetBarCodeBatchLayoutList";
  110. // 模板名称
  111. this._clientRequestEntity.Properties["layoutname"] = this.txtInvoiceName.Text.Trim();
  112. this._clientRequestEntity.Properties["remarks"] = this.txtRemarks.Text.Trim();
  113. this._clientRequestEntity.Properties["valueflag"] = "1";
  114. }
  115. /// <summary>
  116. /// 查询数据
  117. /// </summary>
  118. /// <returns>验证通过true,其他false</returns>
  119. private void QueryDataFromOther()
  120. {
  121. try
  122. {
  123. this.SearchSelectEntity();
  124. this.dgvInvoice.DataSource = null;
  125. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  126. {
  127. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  128. }
  129. );
  130. if (sre.Status == Constant.ServiceResultStatus.Success)
  131. {
  132. // 查询成功
  133. this.dgvInvoice.DataSource = sre.Data.Tables[0];
  134. if (sre.Data.Tables[0].Rows.Count > 0)
  135. {
  136. this.dgvInvoice.Rows[0].Selected = true;
  137. }
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. throw ex;
  143. }
  144. }
  145. private void tsbtnPageSetting_Click(object sender, EventArgs e)
  146. {
  147. try
  148. {
  149. this.pageSetupDialog.ShowDialog();
  150. }
  151. catch (Exception ex)
  152. {
  153. // 对异常进行共通处理
  154. ExceptionManager.HandleEventException(this.ToString(),
  155. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  156. }
  157. }
  158. private void tsbtnPrinterSetting_Click(object sender, EventArgs e)
  159. {
  160. try
  161. {
  162. this.printDialog.ShowDialog();
  163. }
  164. catch (Exception ex)
  165. {
  166. // 对异常进行共通处理
  167. ExceptionManager.HandleEventException(this.ToString(),
  168. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  169. }
  170. }
  171. private bool CheckLayoutData()
  172. {
  173. if (PrintData == null || PrintData.Count == 0)
  174. {
  175. MessageBox.Show("没有打印数据", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  176. return false;
  177. }
  178. DataRowView row = this.dgvInvoice.CurrentRow?.DataBoundItem as DataRowView;
  179. if (row == null)
  180. {
  181. MessageBox.Show("未选择打印模板", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  182. return false;
  183. }
  184. int LayoutID = Convert.ToInt32(row["LayoutID"]);
  185. ClientRequestEntity cre = new ClientRequestEntity();
  186. cre.NameSpace = "F_SET_014001";
  187. cre.Name = "GetBarCodeBatchLayout";
  188. cre.Properties["LayoutID"] = LayoutID;
  189. ServiceResultEntity sre = SystemModuleProxy.Service.DoBarCodePrint(cre);
  190. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0)
  191. {
  192. byte[] bytes = sre.Data.Tables[0].Rows[0]["LayoutData"] as byte[];
  193. string ss_dd = System.Text.Encoding.UTF8.GetString(bytes);
  194. _setData = JsonHelper.ToObject<BarcodeBatchConfig>(ss_dd);
  195. _DataItem = sre.Data.Tables[1];
  196. printDocument1.DocumentName = sre.Data.Tables[0].Rows[0]["LayoutName"] + "";
  197. }
  198. else
  199. {
  200. MessageBox.Show("无打印模板", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  201. return false;
  202. }
  203. return true;
  204. }
  205. private void tsbtnPrintPreview_Click(object sender, EventArgs e)
  206. {
  207. try
  208. {
  209. if (!CheckLayoutData())
  210. {
  211. return;
  212. }
  213. printPreviewDialog1.WindowState = FormWindowState.Maximized;
  214. printPreviewDialog1.PrintPreviewControl.Columns = 1;
  215. printPreviewDialog1.PrintPreviewControl.Rows = 1;
  216. printPreviewDialog1.PrintPreviewControl.StartPage = 0;
  217. printPreviewDialog1.ShowDialog();
  218. }
  219. catch (Exception ex)
  220. {
  221. // 对异常进行共通处理
  222. ExceptionManager.HandleEventException(this.ToString(),
  223. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  224. }
  225. }
  226. private void tsbtnPrint_Click(object sender, EventArgs e)
  227. {
  228. try
  229. {
  230. if (!CheckLayoutData())
  231. {
  232. return;
  233. }
  234. printDocument1.Print();
  235. }
  236. catch (Exception ex)
  237. {
  238. // 对异常进行共通处理
  239. ExceptionManager.HandleEventException(this.ToString(),
  240. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  241. }
  242. }
  243. private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  244. {
  245. try
  246. {
  247. _nextIndex = 0;
  248. }
  249. catch (Exception ex)
  250. {
  251. // 对异常进行共通处理
  252. ExceptionManager.HandleEventException(this.ToString(),
  253. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  254. }
  255. }
  256. private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  257. {
  258. try
  259. {
  260. }
  261. catch (Exception ex)
  262. {
  263. // 对异常进行共通处理
  264. ExceptionManager.HandleEventException(this.ToString(),
  265. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  266. }
  267. }
  268. private void printDocument1_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
  269. {
  270. try
  271. {
  272. }
  273. catch (Exception ex)
  274. {
  275. // 对异常进行共通处理
  276. ExceptionManager.HandleEventException(this.ToString(),
  277. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  278. }
  279. }
  280. private int _nextIndex = 0;
  281. //List<DataRow> _printDataRow;
  282. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  283. {
  284. try
  285. {
  286. if (_nextIndex == 0)
  287. {
  288. _setData.DpiX = e.Graphics.DpiX;
  289. _setData.DpiY = e.Graphics.DpiY;
  290. BarcodeBatchPrint.DoToPixel(_setData);
  291. }
  292. using (Image image = BarcodeBatchPrint.CreateImagePage(_setData, _DataItem, PrintData, _nextIndex, out _nextIndex))
  293. {
  294. //image.Save("D://p" + _nextIndex + ".png");
  295. Rectangle rect = _setData.RangePixel;
  296. rect.X = 0;
  297. rect.Y = 0;
  298. e.Graphics.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel);
  299. }
  300. if (_nextIndex < 0 || _nextIndex >= PrintData.Count)
  301. {
  302. e.HasMorePages = false;
  303. }
  304. else
  305. {
  306. e.HasMorePages = true;
  307. }
  308. }
  309. catch (Exception ex)
  310. {
  311. // 对异常进行共通处理
  312. ExceptionManager.HandleEventException(this.ToString(),
  313. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  314. }
  315. }
  316. }
  317. }