/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_012005.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_012005 : DKFormBase { #region 成员变量 private ClientRequestEntity _clientRequestEntity = new ClientRequestEntity(); #endregion #region 属性 /// /// 模板ID /// public int LayoutID { get; set; } /// /// 模板名称 /// public string LayoutName { get; set; } /// /// 产品类别名 /// public string GoodsTypeName { get; set; } /// /// 产品商标名 /// public string LogoName { get; set; } /// /// 纸张大小 /// public string PageSizeName { get; set; } /// /// 备注 /// public string Remarks { get; set; } /// /// 打印模板 /// public byte[] LayoutData { get; set; } #endregion #region 构造函数 /// /// 构造函数 /// /// 票据格式ID public F_MST_012005() { InitializeComponent(); this.printDialog.Document = lbxPreview.PrintDocument; this.pageSetupDialog.Document = lbxPreview.PrintDocument; this.InitializeControlText(); } #endregion #region 控件事件 /// /// 页面加载 /// /// /// 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); } } /// /// 页面设置 /// /// /// 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); } } /// /// 打印机设置 /// /// /// 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); } } /// /// 票据打印预览按钮按下 /// /// /// 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); } } /// /// 打印按钮按下 /// /// /// 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(() => //{ // 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); } } /// /// 移动到第一页 /// /// /// 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); } } /// /// 移动到前一页 /// /// /// 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); } } /// /// 移动到下一页 /// /// /// 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); } } /// /// 移动到最后一页 /// /// /// 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(); } /// /// 当单张打印选择状态改变后 /// /// /// private void rbtnSinglePrint_CheckedChanged(object sender, EventArgs e) { this.gbxSinglePrint.Enabled = this.rbtnSinglePrint.Checked; this.gbxMultiPrint.Enabled = !this.rbtnSinglePrint.Checked; } /// /// 当多张打印选择状态改变后 /// /// /// private void rbtnMultiPrint_CheckedChanged(object sender, EventArgs e) { this.gbxSinglePrint.Enabled = !this.rbtnMultiPrint.Checked; this.gbxMultiPrint.Enabled = this.rbtnMultiPrint.Checked; } #endregion #region 私有函数/方法 /// /// 页面初始化给各控件文本赋值 /// 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)"; } /// /// 设置翻页按钮可用状态 /// 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 = "InvoiceLayout"; this._clientRequestEntity.Name = "GetBarCodePrintLayout"; this._clientRequestEntity.Properties["LayoutID"] = invoiceLayoutID; return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity); } catch (Exception ex) { throw ex; } } /// /// 更新打印次数 /// /// /// 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; } /// /// 查询票据项目预览信息 /// /// /// 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; } /// /// 加载票据格式数据 /// 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) { // 页面项目赋值 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; } } /// /// 加载实例数据 /// 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; } } /// /// 根据票据类型,取得资源文件中的样例数据 /// /// 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 } }