/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_012001.cs * 2.功能描述:票据信息一览 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2016/01/26 1.00 新建 * 周兴 2016/03/11 1.00 编辑 *******************************************************************************/ using System; using System.Data; 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_012001 : DKDockPanelBase { #region 静态变量 /// /// 条码打印模板 /// public static string TITLE_F_MST_012001 = "条码打印模板"; /// /// 新建条码打印模板 /// public static string TITLE_F_MST_012001_ADD = "新建条码打印模板"; /// /// 编辑条码打印模板 /// public static string TITLE_F_MST_012001_EDIT = "编辑条码打印模板"; /// /// 新建条码打印模板-{0} /// public static string TITLE_F_MST_012001_NEW = "新建条码打印模板-{0}"; /// /// 编辑条码打印模板-{0} /// public static string TITLE_F_MST_012002_EDIT = "编辑条码打印模板-{0}"; #endregion #region 成员变量 private ClientRequestEntity _clientRequestEntity = null; // 查询条件实体 private int _invoiceLayoutID; // 票据格式ID //private int _selectedRowIndex; // 记录当前选择行的索引 private static F_MST_012001 _instance = null; // 窗体单例模式 #endregion #region 构造函数 public F_MST_012001() { InitializeComponent(); // 窗口标题 this.Text = F_MST_012001.TITLE_F_MST_012001; // 工具栏按钮文本赋值 this.tsbtnAddInvoice.Text = ButtonText.TSBTN_ADD; this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT; this.tsbtnEditInvoice.Text = "编辑格式(&L)"; this.tsbtnPreviewInvoice.Text = "预览(&P)"; this.tsbtnDelete.Text = ButtonText.TSBTN_DELETE; this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE; //this.tsbtnExport.Text = ButtonText.TSBTN_EXPORT; //this.tsbtnImport.Text = ButtonText.TSBTN_IMPORT; // 查询、清空条件按钮文本赋值 this.tsbtnSearch.Text = ButtonText.BTN_SEARCH; this.tsbtnClearCondition.Text = ButtonText.BTN_CLEARCONDITION; // 设置表格不自动创建列 this.dgvInvoice.AutoGenerateColumns = false; this.chkValueFlag.FlagBoxChecked = FlagCheckBoxChecked.Yes; // 编辑、导出和预览按钮不可用 this.tsbtnEditInvoice.Enabled = false; this.tsbtnEdit.Enabled = false; this.tsbtnPreviewInvoice.Enabled = false; this.tsbtnExport.Enabled = false; this.tsbtnDelete.Enabled = false; } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_MST_012001 Instance { get { if (_instance == null) { _instance = new F_MST_012001(); } return _instance; } } #endregion #region 控件事件 /// /// 画面打开 /// /// /// private void F_MST_012001_Load(object sender, EventArgs e) { try { DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo(); if (logoInfo != null && logoInfo.Tables.Count > 0) { this.ckcLogo.DataSource = logoInfo.Tables[0]; this.ckcLogo.DisplayMember = "LogoNameCode"; this.ckcLogo.ValueMember = "LogoID"; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 画面关闭 /// /// /// private void F_MST_012001_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 查询 /// /// /// private void tsbtnSearch_Click(object sender, EventArgs e) { try { this.QueryDataFromOther(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 清空查询条件 /// /// /// private void tsbtnClearCondition_Click(object sender, EventArgs e) { this.ClearConditions(); } /// /// 点击新建票据按钮,新建票据 /// /// /// private void tsbtnAddInvoice_Click(object sender, System.EventArgs e) { try { F_MST_012002 frm012002 = new F_MST_012002(); DialogResult dialogresult = frm012002.ShowDialog(); if (DialogResult.OK == dialogresult) { QueryDataFromOther(); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 点击编辑按钮,编辑现有票据基本信息 /// /// /// private void tsbtnEdit_Click(object sender, EventArgs e) { try { // 获取活动行 DataGridViewRow currentRow = this.dgvInvoice.CurrentRow; if (currentRow != null) { this._invoiceLayoutID = Convert.ToInt32(currentRow.Cells["InvoiceLayoutID"].Value); // 弹出填写票据基本信息窗体 F_MST_012004 frmI012004 = new F_MST_012004(); frmI012004.LayoutID = this._invoiceLayoutID; frmI012004.FromForm = 3; DialogResult dialogResult = frmI012004.ShowDialog(); if (DialogResult.OK == dialogResult) { QueryDataFromOther(); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 点击编辑票据格式按钮,编辑现有的票据格式 /// /// /// private void tsbtnEditInvoice_Click(object sender, System.EventArgs e) { try { // 获取活动行 DataGridViewRow currentRow = this.dgvInvoice.CurrentRow; if (currentRow != null) { this._invoiceLayoutID = Convert.ToInt32(currentRow.Cells["InvoiceLayoutID"].Value); // 给票据编辑画面赋值,并打开 F_MST_012003 frm012003 = new F_MST_012003(this._invoiceLayoutID); if (DialogResult.OK == frm012003.ShowDialog()) { QueryDataFromOther(); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 预览票据按钮按下 /// /// /// private void tsbtnPreviewInvoice_Click(object sender, EventArgs e) { try { // 获取活动行 DataGridViewRow currentRow = this.dgvInvoice.CurrentRow; if (currentRow != null) { // 给票据预览画面赋值,并打开 F_MST_012005 frm012005 = new F_MST_012005(); frm012005.LayoutID = Convert.ToInt32(currentRow.Cells["InvoiceLayoutID"].Value); frm012005.ShowDialog(); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 点击删除按钮 /// /// /// private void tsbtnDelete_Click(object sender, EventArgs e) { try { // 获取活动行 DataGridViewRow currentRow = this.dgvInvoice.CurrentRow; if (currentRow != null) { DialogResult dr = MessageBox.Show("是否删除当前选择条码打印模板。", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr != System.Windows.Forms.DialogResult.Yes) { return; } int layoutID = Convert.ToInt32(currentRow.Cells["InvoiceLayoutID"].Value); ServiceResultEntity sre = DoAsync(() => { ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "InvoiceLayout"; cre.Name = "DeleteBarCodePrintLayout"; cre.Properties["LayoutID"] = layoutID; return SystemModuleProxy.Service.DoBarCodePrint(cre); } ); if (sre.Status == Dongke.IBOSS.PRD.Basics.BaseResources.Constant.ServiceResultStatus.Success) { MessageBox.Show(string.Format("{0}的{1}操作成功完成了。", "条码打印模板", "删除"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); QueryDataFromOther(); } } else { MessageBox.Show("没有选择任何条码打印模板。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 票据的导出 /// /// /// private void tsbtnExport_Click(object sender, EventArgs e) { try { // 获取活动行 //DataGridViewRow currentRow = this.dgvInvoice.CurrentRow; //if (currentRow != null) //{ // _invoiceLayoutID = Convert.ToInt32(currentRow.Cells["InvoiceLayoutID"].Value); // // 准备打开保存文件对话框 // SaveFileDialog saveFileDialogExport = new SaveFileDialog(); // saveFileDialogExport.Filter = "东科票据文件(*.DK)|*.DK"; // saveFileDialogExport.Title = "导出票据格式"; // saveFileDialogExport.FileName = currentRow.Cells["LayoutName"].Value.ToString(); // saveFileDialogExport.RestoreDirectory = true; // if (DialogResult.OK == saveFileDialogExport.ShowDialog()) // { // ServiceResultEntity resultEntity; // bool result = this.DoAsync(() => // { // return this.GetInvoiceData(this._invoiceLayoutID); // }, out resultEntity); // DataSet LayoutDataSet = resultEntity.Data; // SoapFormatter formatter = new SoapFormatter(); // FileStream stream = new FileStream(saveFileDialogExport.FileName, FileMode.Create, FileAccess.Write); // formatter.Serialize(stream, LayoutDataSet); // stream.Close(); // MessageBox.Show("票据格式导出成功", // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // } //} } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 票据的导入 /// /// /// private void tsbtnImport_Click(object sender, EventArgs e) { try { //OpenFileDialog ofdOpenFile = new OpenFileDialog(); //ofdOpenFile.InitialDirectory = Environment.SpecialFolder.MyComputer.ToString(); //ofdOpenFile.Title = "选择导入文件"; //ofdOpenFile.Filter = "东科票据文件(*.DK)|*.DK"; //ofdOpenFile.CheckFileExists = true; //ofdOpenFile.CheckPathExists = true; //ofdOpenFile.ValidateNames = true; //if (DialogResult.OK == ofdOpenFile.ShowDialog()) //{ // if (!string.IsNullOrEmpty(ofdOpenFile.FileName)) // { // SoapFormatter formatter = new SoapFormatter(); // FileStream stream = new FileStream(ofdOpenFile.FileName, FileMode.Open, FileAccess.Read); // DataSet readData = (DataSet)formatter.Deserialize(stream); // stream.Close(); // // 弹出填写票据基本信息窗体 // F_MST_012004 frmI012004 = new F_MST_012004(); // frmI012004.InvoiceName = readData.Tables[0].Rows[0]["LayoutName"].ToString(); // frmI012004.InvoiceType = readData.Tables[0].Rows[0]["InvoiceCode"].ToString(); // frmI012004.FromForm = 2; // DialogResult dialogResult = frmI012004.ShowDialog(); // if (DialogResult.OK == dialogResult) // { // // 插入数据库数据 // readData.Tables[0].Rows[0]["OrganizationID"] = frmI012004.OrganizationID; // readData.Tables[0].Rows[0]["OrganizationCode"] = frmI012004.OrganizationCode; // readData.Tables[0].Rows[0]["OrganizationName"] = frmI012004.OrganizationName; // readData.Tables[0].Rows[0]["OrganizationFullName"] = ""; // readData.Tables[0].Rows[0]["Remarks"] = "导入票据格式"; // readData.Tables[0].Rows[0]["LayoutName"] = frmI012004.InvoiceName; // ServiceResultEntity resultEntity2; // bool result = this.DoAsync(() => // { // return this.SaveAddLayoutData(readData); // }, out resultEntity2); // int invoiceLayoutID = Convert.ToInt32(resultEntity2.Result);// this.SaveAddLayoutData(readData); // if (invoiceLayoutID > 0) // { // MessageBox.Show(string.Format("{0}的{1}操作成功完成了。", "票据格式", "票据导入"), // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // int[] IDList = new int[] { invoiceLayoutID }; // // 查询时先清空数据源 // this.dgvInvoice.DataSource = null; // this.tsbtnEditInvoice.Enabled = false; // this.tsbtnEdit.Enabled = false; // this.tsbtnPreviewInvoice.Enabled = false; // this.tsbtnExport.Enabled = false; // this.tsbtnDelete.Enabled = false; // SearchSelectEntity(); // ServiceResultEntity resultEntity; // result = this.DoAsync(() => // { // return this.GetInvoiceLayout(); // }, out resultEntity); // DataSet invoiceInfo = resultEntity.Data; // if (invoiceInfo != null && invoiceInfo.Tables.Count > 0 // && invoiceInfo.Tables[0].Rows.Count > 0) // { // this.dgvInvoice.DataSource = invoiceInfo.Tables[0]; // // 设置编辑按钮可用 // this.tsbtnEditInvoice.Enabled = true; // this.tsbtnEdit.Enabled = true; // this.tsbtnPreviewInvoice.Enabled = true; // this.tsbtnExport.Enabled = true; // this.tsbtnDelete.Enabled = true; // } // } // else // { // MessageBox.Show(string.Format("{0}的{1}操作没有更新任何数据,请确认该数据是否存在。", "导入票据", "保存"), // this.Text, // MessageBoxButtons.OK, // MessageBoxIcon.Warning); // } // } // } //} } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 单击自适应列宽,将所有的列宽都自动去适应内容 /// /// /// private void tsbtnAdaptive_Click(object sender, System.EventArgs e) { this.dgvInvoice.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// KeyDown事件 /// /// /// private void dgvInvoice_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyData == (Keys.Control | Keys.C)) { if (dgvInvoice.CurrentRow != null && !string.IsNullOrEmpty(dgvInvoice.CurrentRow.Cells [dgvInvoice.CurrentCell.ColumnIndex].EditedFormattedValue + "")) { try { Clipboard.SetText(dgvInvoice.CurrentRow.Cells [dgvInvoice.CurrentCell.ColumnIndex].EditedFormattedValue + ""); } catch { } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 关闭页面 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 所选数据发生改变时 /// /// /// private void dgvInvoice_SelectionChanged(object sender, EventArgs e) { try { if (this.dgvInvoice.CurrentCell == null || this.dgvInvoice.SelectedRows.Count == 0) { this.tsbtnEditInvoice.Enabled = false; this.tsbtnEdit.Enabled = false; this.tsbtnExport.Enabled = false; this.tsbtnPreviewInvoice.Enabled = false; this.tsbtnDelete.Enabled = false; } else { if (!this.tsbtnEditInvoice.Enabled) { this.tsbtnEditInvoice.Enabled = true; } if (!this.tsbtnEdit.Enabled) { this.tsbtnEdit.Enabled = true; } if (!this.tsbtnPreviewInvoice.Enabled) { this.tsbtnPreviewInvoice.Enabled = true; } if (!this.tsbtnExport.Enabled) { this.tsbtnExport.Enabled = true; } this.tsbtnDelete.Enabled = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 双击进入编辑页面 /// /// /// private void dgvInvoice_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (-1 < e.RowIndex && -1 < e.ColumnIndex && this.tsbtnEditInvoice.Enabled) { this.tsbtnEditInvoice_Click(sender, e); } } #endregion #region 重写方法 /// /// 查询数据 /// /// 验证通过true,其他false private void QueryDataFromOther() { try { this.SearchSelectEntity(); this.dgvInvoice.DataSource = null; ServiceResultEntity sre = DoAsync(() => { return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { // 查询成功 this.dgvInvoice.DataSource = sre.Data.Tables[0]; if (sre.Data.Tables[0].Rows.Count > 0) { this.dgvInvoice.Rows[0].Selected = true; } } } catch (Exception ex) { throw ex; } } /// /// 清除查询条件 /// public void ClearConditions() { this.txtInvoiceName.Text = string.Empty; this.scbGoodsType.ClearValue(); this.txtRemarks.Text = string.Empty; this.chkValueFlag.FlagBoxChecked = FlagCheckBoxChecked.Yes; this.ckcLogo.ClearValue(); } #endregion #region 私有方法 /// /// 获取查询实体 /// private void SearchSelectEntity() { this._clientRequestEntity = new ClientRequestEntity(); this._clientRequestEntity.NameSpace = "InvoiceLayout"; this._clientRequestEntity.Name = "GetBarCodePrintLayoutList"; // 模板名称 this._clientRequestEntity.Properties["layoutname"] = this.txtInvoiceName.Text.Trim(); this._clientRequestEntity.Properties["remarks"] = this.txtRemarks.Text.Trim(); this._clientRequestEntity.Properties["goodstypecode"] = scbGoodsType.SearchedValue; if (this.ckcLogo.CheckedValues.Length > 0) { this._clientRequestEntity.Properties["logos"] = "," + this.ckcLogo.CheckedValue + ","; } // 正常标识 if (this.chkValueFlag.FlagBoxChecked == FlagCheckBoxChecked.Yes) { this._clientRequestEntity.Properties["valueflag"] = "1"; } else if (this.chkValueFlag.FlagBoxChecked == FlagCheckBoxChecked.No) { this._clientRequestEntity.Properties["valueflag"] = "0"; } } #endregion } }