/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_013002.cs * 2.功能描述:新票据信息操作 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2016/02/18 1.00 新建 * 周兴 2016/03/11 1.00 编辑 *******************************************************************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing.Printing; using System.Reflection; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.WinForm.Controls; namespace Dongke.IBOSS.PRD.Client.Controls { public partial class F_MST_013002 : DKFormBase { #region 成员变量 //private string _invoiceLayoutID; // 票据设置ID private static DataTable _paperSizes; // 纸张尺寸一览 private int _indexA4 = -1; private bool _isSizeChanged = false; private bool _allowChangeSize = false; private List _invoiceLayoutIDList; // 新建票据ID列表 private ClientRequestEntity _clientRequestEntity = null; // 查询条件实体 #endregion #region 构造函数 public F_MST_013002() { InitializeComponent(); dgrdPaperSize.AutoGenerateColumns = false; InitializePaperSize(); dgrdPaperSize.ClearSelection(); this._allowChangeSize = true; // 设定按钮文本及窗体文本 this.btnSave.Text = ButtonText.BTN_OK; this.btnCancel.Text = ButtonText.BTN_CANCEL; this.Text = F_MST_013001.TITLE_F_MST_013001_ADD; //if (this.FormType == WinForm.Controls.FormType.Add) //{ // this.ActiveControl = this.cbxInvoiceType; //} //else //{ // this.Text = F_MST_013001.TITLE_F_MST_013001_EDIT; //} //this._invoiceLayoutID = base.FormCode; } #endregion #region 属性 /// /// 纸张的宽(mm) /// [DefaultValue(210)] public float PaperWidth { get { return System.Convert.ToSingle(numerWidth.Value); } set { decimal d = System.Convert.ToDecimal(value); if (d < numerWidth.Minimum) { d = numerWidth.Minimum; } else if (numerWidth.Maximum < d) { d = numerWidth.Maximum; } if (numerWidth.Value != d) { _isSizeChanged = true; numerWidth.Value = d; } } } /// /// 纸张的高(mm) /// [DefaultValue(297)] public float PaperHeight { get { return System.Convert.ToSingle(numerHeight.Value); } set { decimal d = System.Convert.ToDecimal(value); if (d < numerHeight.Minimum) { d = numerHeight.Minimum; } else if (numerHeight.Maximum < d) { d = numerHeight.Maximum; } if (numerHeight.Value != d) { _isSizeChanged = true; numerHeight.Value = d; } } } /// /// 新建票据ID集合 /// public List InvoiceLayoutIDList { get { return _invoiceLayoutIDList; } set { _invoiceLayoutIDList = value; } } #endregion #region 控件事件 private bool _canChangedText = true; private void txtInvoiceName_TextChanged(object sender, EventArgs e) { this._canChangedText = false; } /// /// 列表的选择项发生改变事件 /// /// /// private void dgrdPaperSize_SelectionChanged(object sender, System.EventArgs e) { if (dgrdPaperSize.CurrentRow != null && _allowChangeSize && 0 < dgrdPaperSize.SelectedRows.Count) { PaperHeight = System.Convert.ToSingle(dgrdPaperSize.CurrentRow.Cells["colHeight"].Value); PaperWidth = System.Convert.ToSingle(dgrdPaperSize.CurrentRow.Cells["colWidth"].Value); } } /// /// 列表失去焦点事件 /// /// /// private void dgrdPaperSize_Leave(object sender, System.EventArgs e) { dgrdPaperSize.ClearSelection(); } /// /// /// /// /// private void btnOK_Click(object sender, System.EventArgs e) { try { // 判断票据名称输入是否正确 if (string.IsNullOrEmpty(this.txtInvoiceName.Text.Trim())) { MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "标签名称"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtInvoiceName.Focus(); return; } // 判断系统是否存在相同的票据 bool isExistSameInvoice = this.IsExistInvoice(); // 存在相同的票据 if (isExistSameInvoice) { MessageBox.Show(string.Format("不允许进行该操作,原因:{0}。", "在该产品类别中已存在标签模板"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.scbGoodsType.Focus(); return; } //object objLogoID = this.ftcLogo.SelectedValue; //int? logoid = null; //if (objLogoID != null && objLogoID != DBNull.Value) //{ // logoid = Convert.ToInt32(objLogoID); //} // 给票据编辑画面赋值,并打开 F_MST_013003 frmINV0301 = new F_MST_013003(scbGoodsType.SearchedPKMember, scbGoodsType.SearchedValue + "", scbGoodsType.SearchedText, null, null, this.PaperWidth, this.PaperHeight, this.txtInvoiceName.Text.Trim(), this.txtRemark.Text.Trim()); this.Hide(); DialogResult dialogresult = frmINV0301.ShowDialog(); if (DialogResult.OK == dialogresult) { this.DialogResult = DialogResult.OK; } else { this.DialogResult = DialogResult.Cancel; } this.Close(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// /// /// /// private void btnCancel_Click(object sender, System.EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } /// /// 画面打开 /// /// /// private void F_MST_013002_Load(object sender, EventArgs e) { //try //{ // DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo(); // if (logoInfo != null && logoInfo.Tables.Count > 0) // { // this.ftcLogo.DataSource = logoInfo.Tables[0]; // this.ftcLogo.DisplayMember = "LogoNameCode"; // this.ftcLogo.ValueMember = "LogoID"; // } //} //catch (Exception ex) //{ // // 对异常进行共通处理 // ExceptionManager.HandleEventException(this.ToString(), // MethodBase.GetCurrentMethod().Name, this.Text, ex); //} } #endregion #region 重写方法 #endregion #region 私有方法/函数 /// /// 根据本机的打印机取得纸张的信息 /// private void InitializePaperSize() { if (_paperSizes == null) { _paperSizes = new DataTable(); _paperSizes.TableName = "PaperSizes"; _paperSizes.Columns.Add("SizeName", typeof(string)); _paperSizes.Columns.Add("Width", typeof(float)); _paperSizes.Columns.Add("Height", typeof(float)); } else { _paperSizes.Clear(); } float height = 0; float width = 0; int index = 0; PrintDocument pd = new PrintDocument(); foreach (PaperSize ps in pd.PrinterSettings.PaperSizes) { DataRow dataRow = _paperSizes.NewRow(); height = Dongke.IBOSS.PRD.Basics.Library.Utility.Inch100ToMillimeter(ps.Height); width = Dongke.IBOSS.PRD.Basics.Library.Utility.Inch100ToMillimeter(ps.Width); dataRow[0] = string.Format("{0} {1:0}mm×{2:0}mm", ps.PaperName, width, height); dataRow[1] = Math.Round(width); dataRow[2] = Math.Round(height); _paperSizes.Rows.Add(dataRow); if (ps.PaperName.StartsWith("A4") && 210.0f.Equals(dataRow[1]) && 297.0f.Equals(dataRow[2]) && _indexA4 < 0) { _indexA4 = index; } index++; } dgrdPaperSize.DataSource = _paperSizes; } /// /// 判断系统是否存在相同的票据 /// /// /// false:不存在 /// true:存在 /// private bool IsExistInvoice() { try { int? goodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]); //if (!goodsTypeID.HasValue) //{ // return true; //} //if (this.ftcLogo.SelectedValue == null) //{ // return true; //} this._clientRequestEntity = new ClientRequestEntity(); this._clientRequestEntity.NameSpace = "MouldLableLayout"; this._clientRequestEntity.Name = "IsExistMouldLablePrintLayout"; this._clientRequestEntity.Properties["GoodsTypeID"] = goodsTypeID; //this._clientRequestEntity.Properties["LogoID"] = this.ftcLogo.SelectedValue; ServiceResultEntity sre = DoAsync(() => { return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity); } ); return Convert.ToBoolean(sre.Result); } catch (Exception ex) { throw ex; } } #endregion } }