F_MST_0205.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0205.cs
  5. * 2.功能描述:打印工号条码
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/10/27 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Drawing;
  13. using System.Drawing.Imaging;
  14. using System.Drawing.Printing;
  15. using System.Windows.Forms;
  16. using Dongke.IBOSS.PRD.Basics.BaseControls;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Dongke.IBOSS.PRD.Basics.Library;
  19. using Dongke.IBOSS.PRD.Client.CommonModule;
  20. namespace Dongke.IBOSS.PRD.Client.SystemModule
  21. {
  22. public partial class F_MST_0205 : FormBase
  23. {
  24. #region 成员变量
  25. // 文本张数
  26. private string _txtTotal = "共{0}张";
  27. // 图片集
  28. List<Image> _imgList = new List<Image>();
  29. #endregion
  30. #region 属性
  31. /// <summary>
  32. /// 条码集
  33. /// </summary>
  34. public List<string> BarcodeList { get; set; }
  35. #endregion
  36. #region 构造
  37. public F_MST_0205()
  38. {
  39. InitializeComponent();
  40. this.Text = FormTitles.F_MST_0205;
  41. this.btnPreviousPage.Text = ButtonText.BTN_PREVIOUSPAGE;
  42. this.btnAfterPage.Text = ButtonText.BTN_AFTERPAGE;
  43. this.btnResetPage.Text = ButtonText.BTN_RESETPAGE;
  44. this.btnPrint.Text = ButtonText.BTN_PRINT;
  45. this.btnSaveImage.Text = ButtonText.BTN_SAVEIMAGE;
  46. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  47. }
  48. #endregion
  49. #region 事件
  50. /// <summary>
  51. /// 页面加载
  52. /// </summary>
  53. /// <param name="sender"></param>
  54. /// <param name="e"></param>
  55. private void F_MST_0208_Load(object sender, System.EventArgs e)
  56. {
  57. try
  58. {
  59. this.DrawImg();
  60. }
  61. catch (Exception ex)
  62. {
  63. // 对异常进行共通处理
  64. ExceptionManager.HandleEventException(this.ToString(),
  65. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  66. }
  67. }
  68. /// <summary>
  69. /// 前页按钮事件
  70. /// </summary>
  71. /// <param name="sender"></param>
  72. /// <param name="e"></param>
  73. private void btnPreviousPage_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. int currentPaper = int.Parse(this.lblCurrentPaper.Text);
  78. this.picboxBarcode.Image = _imgList[currentPaper - 2];
  79. this.lblCurrentPaper.Text = (currentPaper - 1).ToString();
  80. if (currentPaper - 1 == Constant.INT_IS_ONE)
  81. {
  82. this.btnPreviousPage.Enabled = false;
  83. }
  84. this.btnAfterPage.Enabled = true;
  85. }
  86. catch (Exception ex)
  87. {
  88. // 对异常进行共通处理
  89. ExceptionManager.HandleEventException(this.ToString(),
  90. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  91. }
  92. }
  93. /// <summary>
  94. /// 后页按钮事件
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void btnAfterPage_Click(object sender, EventArgs e)
  99. {
  100. try
  101. {
  102. int currentPaper = int.Parse(this.lblCurrentPaper.Text);
  103. this.picboxBarcode.Image = _imgList[currentPaper];
  104. this.lblCurrentPaper.Text = (currentPaper + 1).ToString();
  105. if (currentPaper + 1 == _imgList.Count)
  106. {
  107. this.btnAfterPage.Enabled = false;
  108. }
  109. this.btnPreviousPage.Enabled = true;
  110. }
  111. catch (Exception ex)
  112. {
  113. // 对异常进行共通处理
  114. ExceptionManager.HandleEventException(this.ToString(),
  115. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  116. }
  117. }
  118. /// <summary>
  119. /// 重新绘制图片
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. private void btnResetPage_Click(object sender, EventArgs e)
  124. {
  125. try
  126. {
  127. this.DrawImg();
  128. }
  129. catch (Exception ex)
  130. {
  131. // 对异常进行共通处理
  132. ExceptionManager.HandleEventException(this.ToString(),
  133. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  134. }
  135. }
  136. /// <summary>
  137. /// 保存图片
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void btnSaveImage_Click(object sender, EventArgs e)
  142. {
  143. try
  144. {
  145. this.saveFileDialog.Filter = "所有文件(*.*)|*.*";
  146. this.saveFileDialog.RestoreDirectory = true;
  147. this.saveFileDialog.FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  148. DialogResult dialogResult = this.saveFileDialog.ShowDialog();
  149. if (dialogResult == DialogResult.OK)
  150. {
  151. string localFilePath = this.saveFileDialog.FileName.ToString(); //获得文件路径
  152. //获取文件路径,不带文件名
  153. string path = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
  154. foreach (Image img in _imgList)
  155. {
  156. img.Save(path + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg", ImageFormat.Jpeg);
  157. }
  158. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "图片", "保存"), this.Text,
  159. MessageBoxButtons.OK, MessageBoxIcon.Information);
  160. }
  161. }
  162. catch (Exception ex)
  163. {
  164. // 对异常进行共通处理
  165. ExceptionManager.HandleEventException(this.ToString(),
  166. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  167. }
  168. }
  169. /// <summary>
  170. /// 打印图片
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void btnPrint_Click(object sender, EventArgs e)
  175. {
  176. try
  177. {
  178. // 实现一次打印多页详见 http://blog.csdn.net/tsapi/article/details/6237695
  179. foreach (Image img in _imgList)
  180. {
  181. //打印事件设置
  182. this.printDocument.PrintPage += new PrintPageEventHandler((obj, printPageEventArgs) =>
  183. {
  184. printPageEventArgs.Graphics.DrawImage(_imgList[0], 0, 0);
  185. });
  186. this.printDocument.Print();
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. // 对异常进行共通处理
  192. ExceptionManager.HandleEventException(this.ToString(),
  193. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  194. }
  195. }
  196. /// <summary>
  197. /// 关闭
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. private void btnClose_Click(object sender, EventArgs e)
  202. {
  203. this.Close();
  204. }
  205. #endregion
  206. #region 私有方法
  207. /// <summary>
  208. /// 绘制图片
  209. /// </summary>
  210. private void DrawImg()
  211. {
  212. this._imgList = BarcodePrintUtility.BarcodeDrawPaper(BarcodeList, int.Parse(this.txtWidth.Text), int.Parse(this.txtHeight.Text), BarcodePrintUtility.PaperType.A4);
  213. this.picboxBarcode.Image = _imgList[0];
  214. this.picboxBarcode.SizeMode = PictureBoxSizeMode.CenterImage;
  215. this.lblTotal.Text = string.Format(_txtTotal, _imgList.Count);
  216. this.lblCurrentPaper.Text = "1";
  217. this.btnPreviousPage.Enabled = false;
  218. if (_imgList.Count == Constant.INT_IS_ONE)
  219. {
  220. this.btnAfterPage.Enabled = false;
  221. }
  222. }
  223. #endregion
  224. }
  225. }