| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0205.cs
- * 2.功能描述:打印工号条码
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈冰 2014/10/27 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Printing;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- public partial class F_MST_0205 : FormBase
- {
- #region 成员变量
- // 文本张数
- private string _txtTotal = "共{0}张";
- // 图片集
- List<Image> _imgList = new List<Image>();
- #endregion
- #region 属性
- /// <summary>
- /// 条码集
- /// </summary>
- public List<string> BarcodeList { get; set; }
- #endregion
- #region 构造
- public F_MST_0205()
- {
- InitializeComponent();
- this.Text = FormTitles.F_MST_0205;
- this.btnPreviousPage.Text = ButtonText.BTN_PREVIOUSPAGE;
- this.btnAfterPage.Text = ButtonText.BTN_AFTERPAGE;
- this.btnResetPage.Text = ButtonText.BTN_RESETPAGE;
- this.btnPrint.Text = ButtonText.BTN_PRINT;
- this.btnSaveImage.Text = ButtonText.BTN_SAVEIMAGE;
- this.btnCancel.Text = ButtonText.BTN_CANCEL;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 页面加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0208_Load(object sender, System.EventArgs e)
- {
- try
- {
- this.DrawImg();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 前页按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnPreviousPage_Click(object sender, EventArgs e)
- {
- try
- {
- int currentPaper = int.Parse(this.lblCurrentPaper.Text);
- this.picboxBarcode.Image = _imgList[currentPaper - 2];
- this.lblCurrentPaper.Text = (currentPaper - 1).ToString();
- if (currentPaper - 1 == Constant.INT_IS_ONE)
- {
- this.btnPreviousPage.Enabled = false;
- }
- this.btnAfterPage.Enabled = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 后页按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAfterPage_Click(object sender, EventArgs e)
- {
- try
- {
- int currentPaper = int.Parse(this.lblCurrentPaper.Text);
- this.picboxBarcode.Image = _imgList[currentPaper];
- this.lblCurrentPaper.Text = (currentPaper + 1).ToString();
- if (currentPaper + 1 == _imgList.Count)
- {
- this.btnAfterPage.Enabled = false;
- }
- this.btnPreviousPage.Enabled = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 重新绘制图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnResetPage_Click(object sender, EventArgs e)
- {
- try
- {
- this.DrawImg();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 保存图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSaveImage_Click(object sender, EventArgs e)
- {
- try
- {
- this.saveFileDialog.Filter = "所有文件(*.*)|*.*";
- this.saveFileDialog.RestoreDirectory = true;
- this.saveFileDialog.FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
- DialogResult dialogResult = this.saveFileDialog.ShowDialog();
- if (dialogResult == DialogResult.OK)
- {
- string localFilePath = this.saveFileDialog.FileName.ToString(); //获得文件路径
- //获取文件路径,不带文件名
- string path = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
- foreach (Image img in _imgList)
- {
- img.Save(path + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg", ImageFormat.Jpeg);
- }
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "图片", "保存"), this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 打印图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnPrint_Click(object sender, EventArgs e)
- {
- try
- {
- // 实现一次打印多页详见 http://blog.csdn.net/tsapi/article/details/6237695
- foreach (Image img in _imgList)
- {
- //打印事件设置
- this.printDocument.PrintPage += new PrintPageEventHandler((obj, printPageEventArgs) =>
- {
- printPageEventArgs.Graphics.DrawImage(_imgList[0], 0, 0);
- });
- this.printDocument.Print();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 绘制图片
- /// </summary>
- private void DrawImg()
- {
- this._imgList = BarcodePrintUtility.BarcodeDrawPaper(BarcodeList, int.Parse(this.txtWidth.Text), int.Parse(this.txtHeight.Text), BarcodePrintUtility.PaperType.A4);
- this.picboxBarcode.Image = _imgList[0];
- this.picboxBarcode.SizeMode = PictureBoxSizeMode.CenterImage;
- this.lblTotal.Text = string.Format(_txtTotal, _imgList.Count);
- this.lblCurrentPaper.Text = "1";
- this.btnPreviousPage.Enabled = false;
- if (_imgList.Count == Constant.INT_IS_ONE)
- {
- this.btnAfterPage.Enabled = false;
- }
- }
- #endregion
- }
- }
|