| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_013005.cs
- * 2.功能描述:新票据信息操作
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2016/02/18 1.00 新建
- * 周兴 2016/03/11 1.00 编辑
- *******************************************************************************/
- using System;
- using System.Data;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.WinForm.Controls;
- using Dongke.WinForm.Controls.InvoiceLayout;
- namespace Dongke.IBOSS.PRD.Client.Controls
- {
- public partial class F_MST_013005 : DKFormBase
- {
- #region 成员变量
- private ClientRequestEntity _clientRequestEntity = new ClientRequestEntity();
- #endregion
- #region 属性
- /// <summary>
- /// 模板ID
- /// </summary>
- public int LayoutID
- {
- get;
- set;
- }
- /// <summary>
- /// 模板名称
- /// </summary>
- public string LayoutName
- {
- get;
- set;
- }
- /// <summary>
- /// 产品类别名
- /// </summary>
- public string GoodsTypeName
- {
- get;
- set;
- }
- /// <summary>
- /// 产品商标名
- /// </summary>
- public string LogoName
- {
- get;
- set;
- }
- /// <summary>
- /// 纸张大小
- /// </summary>
- public string PageSizeName
- {
- get;
- set;
- }
- /// <summary>
- /// 备注
- /// </summary>
- public string Remarks
- {
- get;
- set;
- }
- /// <summary>
- /// 打印模板
- /// </summary>
- public byte[] LayoutData
- {
- get;
- set;
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="invoiceLayoutID">票据格式ID</param>
- public F_MST_013005()
- {
- InitializeComponent();
- this.printDialog.Document = lbxPreview.PrintDocument;
- this.pageSetupDialog.Document = lbxPreview.PrintDocument;
- this.InitializeControlText();
- }
- #endregion
- #region 控件事件
- /// <summary>
- /// 页面加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_INV_0303_Load(object sender, System.EventArgs e)
- {
- try
- {
- // 多张打印设置不可用
- //this.gbxMultiPrint.Enabled = false;
- // 加载票据格式基本信息
- this.LoadInvoiceLayout();
- // 加载实例数据
- this.LoadInvoiceData();
- // 设置翻页按钮可用状态
- this.SetMoveButtonEnable();
- }
- 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 tsbtnPageSetting_Click(object sender, System.EventArgs e)
- {
- try
- {
- this.pageSetupDialog.ShowDialog();
- }
- 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 tsbtnPrinterSetting_Click(object sender, System.EventArgs e)
- {
- try
- {
- this.printDialog.ShowDialog();
- }
- 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 tsbtnPrintPreview_Click(object sender, System.EventArgs e)
- {
- try
- {
- if (lbxPreview.DataSource != null)
- {
- DataSet ds = lbxPreview.DataSource as DataSet;
- lbxPreview.PrintDataSource = ds.Copy();
- lbxPreview.PrintDataMember = lbxPreview.DataMember;
- }
- lbxPreview.PrintAreaVisible = true;
- lbxPreview.PrintBackground = cbxBackground.Checked;
- // 纸张方向
- lbxPreview.Landscape = pageSetupDialog.PageSettings.Landscape;
- // 单张
- if (this.rbtnSinglePrint.Checked)
- {
- // 左边余白
- lbxPreview.PrintOffsetX = (float)nmrToRight.Value;
- // 上边余白
- lbxPreview.PrintOffsetY = (float)nmrToBottom.Value;
- // 打印份数
- lbxPreview.NumberOfCopies = (int)nmrPrintCopy.Value;
- lbxPreview.PrintPreview();
- }
- // 多张打印
- else
- {
- // 打印份数
- lbxPreview.NumberOfCopies = (int)nmrPrintRecord.Value;
- // 跳过页数
- lbxPreview.AllocationSkipCount = (int)nmrSkip.Value;
- // 横向个数
- lbxPreview.AllocationNumX = (int)nmrHorizontal.Value;
- // 纵向个数
- lbxPreview.AllocationNumY = (int)nmrVertical.Value;
- // 纵向间隔
- lbxPreview.AllocationVirticalSpace = (float)nmrVerticalSpace.Value;
- // 横向间隔
- lbxPreview.AllocationHorizontalSpace = (float)nmrHorizontalSpace.Value;
- // 左边余白
- lbxPreview.MarginLeft = (float)nmrLeft.Value;
- // 右边余白
- lbxPreview.MarginRight = (float)nmrRight.Value;
- // 上边余白
- lbxPreview.MarginTop = (float)nmrUpper.Value;
- // 下边余白
- lbxPreview.MarginBottom = (float)nmrBottom.Value;
- lbxPreview.AllocationPrintPreview();
- }
- }
- 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 tsbtnPrint_Click(object sender, System.EventArgs e)
- {
- try
- {
- if (lbxPreview.DataSource != null)
- {
- // 设置打印的数据源
- DataSet ds = lbxPreview.DataSource as DataSet;
- lbxPreview.PrintDataSource = ds.Copy();
- lbxPreview.PrintDataMember = lbxPreview.DataMember;
- }
- // 背景否打印
- lbxPreview.PrintAreaVisible = true;
- lbxPreview.PrintBackground = cbxBackground.Checked;
- // 打印时不打印虚线
- this.lbxPreview.PrintAreaVisible = false;
- // 纸张方向
- lbxPreview.Landscape = pageSetupDialog.PageSettings.Landscape;
- // 单张
- if (this.rbtnSinglePrint.Checked)
- {
- // 左边余白
- lbxPreview.PrintOffsetX = (float)nmrToRight.Value;
- // 上边余白
- lbxPreview.PrintOffsetY = (float)nmrToBottom.Value;
- // 打印份数
- lbxPreview.NumberOfCopies = (int)nmrPrintCopy.Value;
- lbxPreview.Print();
- }
- // 多张打印
- else
- {
- // 打印份数
- lbxPreview.NumberOfCopies = (int)nmrPrintRecord.Value;
- // 跳过页数
- lbxPreview.AllocationSkipCount = (int)nmrSkip.Value;
- // 横向个数
- lbxPreview.AllocationNumX = (int)nmrHorizontal.Value;
- // 纵向个数
- lbxPreview.AllocationNumY = (int)nmrVertical.Value;
- // 纵向间隔
- lbxPreview.AllocationVirticalSpace = (float)nmrVerticalSpace.Value;
- // 横向间隔
- lbxPreview.AllocationHorizontalSpace = (float)nmrHorizontalSpace.Value;
- // 左边余白
- lbxPreview.MarginLeft = (float)nmrLeft.Value;
- // 右边余白
- lbxPreview.MarginRight = (float)nmrRight.Value;
- // 上边余白
- lbxPreview.MarginTop = (float)nmrUpper.Value;
- // 下边余白
- lbxPreview.MarginBottom = (float)nmrBottom.Value;
- lbxPreview.AllocationPrint();
- }
- //// 更新打印次数
- //ServiceResultEntity resultEntity = null;
- //// 异步提交信息,进行数据库操作
- //bool result = this.DoAsync<ServiceResultEntity>(() =>
- //{
- // return this.SetUpdatePrintTimes();
- //}, out resultEntity);
- //if (result)
- //{
- // if (resultEntity.Status == ServiceResultStatus.Success)
- // {
- // MessageBox.Show(string.Format(Dongke.IBOSS.PRD.Basics.BaseResources.Constant.I_CMN_C_002, this.Text, "打印"),
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- // this.DialogResult = System.Windows.Forms.DialogResult.OK;
- // this.Close();
- // }
- // else
- // {
- // StateMessageClass.GetErrorMessageByStatus(this, resultEntity.Status);
- // }
- //}
- }
- 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 tsbtnFirst_Click(object sender, System.EventArgs e)
- {
- try
- {
- lbxPreview.SetPageNum(1);
- this.SetMoveButtonEnable();
- }
- 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 tsbtnPrevious_Click(object sender, System.EventArgs e)
- {
- try
- {
- lbxPreview.SetPageNum(lbxPreview.CurrentPageNum - 1);
- this.SetMoveButtonEnable();
- }
- 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 tsbtnNext_Click(object sender, System.EventArgs e)
- {
- try
- {
- lbxPreview.SetPageNum(lbxPreview.CurrentPageNum + 1);
- this.SetMoveButtonEnable();
- }
- 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 tsbtnLast_Click(object sender, System.EventArgs e)
- {
- try
- {
- lbxPreview.SetPageNum(lbxPreview.TotalPageNum);
- this.SetMoveButtonEnable();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void tsbtnClose_Click(object sender, System.EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 当单张打印选择状态改变后
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void rbtnSinglePrint_CheckedChanged(object sender, EventArgs e)
- {
- this.gbxSinglePrint.Enabled = this.rbtnSinglePrint.Checked;
- this.gbxMultiPrint.Enabled = !this.rbtnSinglePrint.Checked;
- }
- /// <summary>
- /// 当多张打印选择状态改变后
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void rbtnMultiPrint_CheckedChanged(object sender, EventArgs e)
- {
- this.gbxSinglePrint.Enabled = !this.rbtnMultiPrint.Checked;
- this.gbxMultiPrint.Enabled = this.rbtnMultiPrint.Checked;
- }
- #endregion
- #region 私有函数/方法
- /// <summary>
- /// 页面初始化给各控件文本赋值
- /// </summary>
- private void InitializeControlText()
- {
- // 设置控件的文本内容
- this.Text = "模具标签打印预览";
- this.tsbtnPageSetting.Text = "页面设置(&G)";
- this.tsbtnPrinterSetting.Text = "打印机设置(&R)";
- this.tsbtnPrintPreview.Text = "打印预览(&W)";
- this.tsbtnPrint.Text = "打印(&P)";
- this.tsbtnClose.Text = "关闭(&X)";
- }
- /// <summary>
- /// 设置翻页按钮可用状态
- /// </summary>
- private void SetMoveButtonEnable()
- {
- this.tsbtnFirst.Enabled = (this.lbxPreview.CurrentPageNum != 1);
- this.tsbtnPrevious.Enabled = (this.lbxPreview.CurrentPageNum != 1);
- this.tsbtnNext.Enabled = (this.lbxPreview.CurrentPageNum != this.lbxPreview.TotalPageNum);
- this.tsbtnLast.Enabled = (this.lbxPreview.CurrentPageNum != this.lbxPreview.TotalPageNum);
- }
- private ServiceResultEntity GetInvoiceData(int invoiceLayoutID)
- {
- try
- {
- this._clientRequestEntity = new ClientRequestEntity();
- this._clientRequestEntity.NameSpace = "MouldLableLayout";
- this._clientRequestEntity.Name = "GetMouldLablePrintLayout";
- this._clientRequestEntity.Properties["LayoutID"] = invoiceLayoutID;
- return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 更新打印次数
- /// </summary>
- /// <param name="invoiceLayoutID"></param>
- /// <returns></returns>
- private ServiceResultEntity SetUpdatePrintTimes()
- {
- //try
- //{
- // this._clientRequestEntity = new ClientRequestEntity();
- // this._clientRequestEntity.NameSpace = "Common";
- // this._clientRequestEntity.Name = "SetUpdatePrintTimes";
- // this._clientRequestEntity.OpenTransaction = true;
- // this._clientRequestEntity.Properties["InvoiceID"] = this._invoiceID;
- // this._clientRequestEntity.Properties["InvoiceCode"] = this._invoiceCode;
- // this._clientRequestEntity.Properties["LayoutID"] = this._invoiceLayoutID;
- // return CommonModuleProxy.Service.DoRequest(this._clientRequestEntity);
- //}
- //catch (Exception ex)
- //{
- // throw ex;
- //}
- return null;
- }
- /// <summary>
- /// 查询票据项目预览信息
- /// </summary>
- /// <param name="invoiceLayoutID"></param>
- /// <returns></returns>
- private ServiceResultEntity GetInvoiceItemData(int invoiceLayoutID)
- {
- //try
- //{
- // this._clientRequestEntity = new ClientRequestEntity();
- // this._clientRequestEntity.NameSpace = "InvoiceLayout";
- // this._clientRequestEntity.Name = "GetInvoiceItemData";
- // this._clientRequestEntity.OpenTransaction = false;
- // this._clientRequestEntity.Properties["InvoiceLayoutID"] = invoiceLayoutID;
- // return SystemModuleProxy.Service.DoRequest(this._clientRequestEntity);
- //}
- //catch (Exception ex)
- //{
- // throw ex;
- //}
- return null;
- }
- /// <summary>
- /// 加载票据格式数据
- /// </summary>
- private void LoadInvoiceLayout()
- {
- try
- {
- if (this.LayoutID > 0)
- {
- ServiceResultEntity result = this.GetInvoiceData(this.LayoutID);
- // 根据ID取得票据格式数据
- DataSet LayoutDataSet = result.Data;
- if (LayoutDataSet != null && LayoutDataSet.Tables.Count > 1)
- {
- // 页面项目赋值
- if (LayoutDataSet.Tables[0].Rows[0]["goodstypename"] != null || LayoutDataSet.Tables[0].Rows[0]["goodstypename"] != DBNull.Value)
- {
- this.txtGoodsType.Text = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString() + "【" + LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString() + "】";
- }
- this.txtInvoiceName.Text = LayoutDataSet.Tables[0].Rows[0]["LayoutName"].ToString();
- this.txtRemarks.Text = LayoutDataSet.Tables[0].Rows[0]["Remarks"].ToString();
- //this.txtLogo.Text = LayoutDataSet.Tables[0].Rows[0]["LogoName"].ToString();
- this.txtInvoiceSize.Text = string.Format("{0:0}mm×{1:0}mm",
- LayoutDataSet.Tables[0].Rows[0]["Width"],
- LayoutDataSet.Tables[0].Rows[0]["Height"]);
- //this._invoiceCode = LayoutDataSet.Tables[0].Rows[0]["InvoiceCode"].ToString();
- // Layout格式读取
- byte[] bytes = LayoutDataSet.Tables[0].Rows[0]["LayoutData"] as byte[];
- if (bytes != null)
- {
- bool isSuccessed = this.lbxPreview.ReadLayout(bytes);
- //if (isSuccessed)
- //{
- // lbxPreview.LayoutMode = LayoutMode.Preview;
- //}
- }
- }
- }
- else
- {
- this.txtGoodsType.Text = this.GoodsTypeName;
- this.txtInvoiceName.Text = this.LayoutName;
- this.txtRemarks.Text = this.Remarks;
- this.txtInvoiceSize.Text = this.PageSizeName;
- this.lbxPreview.ReadLayout(this.LayoutData);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 加载实例数据
- /// </summary>
- private void LoadInvoiceData()
- {
- try
- {
- //DataSet previewData = new DataSet();
- //if (this.DataSource == null)
- //{
- // previewData = GetPreviewData();
- //}
- //else
- //{
- // previewData = this.DataSource;
- //}
- //this.lbxPreview.DataSource = previewData;
- if (this.DataSource != null)
- {
- this.lbxPreview.LayoutMode = LayoutMode.Preview;
- this.lbxPreview.DataSource = this.DataSource;
- this.lbxPreview.DataMember = "Data";
- // 给列表数据赋值
- if (this.lbxPreview.OneGridItem != null)
- {
- this.lbxPreview.OneGridItem.GridDataMember = "DataDetail";
- }
- this.lbxPreview.GridDataSource = this.DataSource;
- }
- else
- {
- this.lbxPreview.LayoutMode = LayoutMode.Display;
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据票据类型,取得资源文件中的样例数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetPreviewData()
- {
- try
- {
- DataSet returnData = null;
- ServiceResultEntity result = this.GetInvoiceItemData(this.LayoutID);
- // 给数据表重命名
- if (result != null && result.Data != null && result.Data.Tables.Count == 2)
- {
- returnData = result.Data;
- returnData.Tables[0].TableName = "Data";
- returnData.Tables[1].TableName = "DataDetail";
- //// 追加条码列 周兴 先不要todo
- //string barcode = returnPreviewData.Tables[0].Rows[0]["InvoiceNo"].ToString();
- //returnPreviewData.Tables[0].Columns.Add("Barcode", typeof(Image));
- //returnPreviewData.Tables[0].Rows[0]["Barcode"] = Utility.GetCode39Image(barcode);
- //// 追加商品图片列
- //string samplePhotoFile = @"Dongke.IBOSS.PRD.Client.InvoiceManager.Resources.SamplePhoto.jpg";
- //Image imageSample = new Bitmap(asm.GetManifestResourceStream(samplePhotoFile));
- //returnPreviewData.Tables[1].Columns.Add("Photo", typeof(Image));
- //returnPreviewData.Tables[1].Columns.Add("Barcode", typeof(Image));
- //for (int i = 0; i < returnPreviewData.Tables[1].Rows.Count; i++)
- //{
- // returnPreviewData.Tables[1].Rows[i]["Photo"] = imageSample;
- // returnPreviewData.Tables[1].Rows[i]["Barcode"] = Utility.GetCode39Image(barcode);
- //}
- }
- else if (returnData.Tables.Count == 1)
- {
- returnData = result.Data;
- returnData.Tables[0].TableName = "Data";
- }
- return returnData;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|