/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_1003.cs * 2.功能描述:产品档案 * 编辑履历: * 作者 日期 版本 修改内容 * 庄天威 2014/09/13 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Basics.DockPanel; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.SystemModule { /// /// 产品档案 /// public partial class F_MST_1003 : DockPanelBase { #region 成员变量 private static F_MST_1003 _instance; //单例模式 #endregion #region 构造函数 public F_MST_1003() { InitializeComponent(); this.dgvGoods.AutoGenerateColumns = false; this.dgvGoodsSap.AutoGenerateColumns = false; this.Text = "产品对应辅件"; this.btnSearch.Text = ButtonText.BTN_SEARCH; this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION; this.tsbtnAdd.Text = ButtonText.TSBTN_ADD; this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT; this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE; this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_MST_1003 Instance { get { if (_instance == null) { _instance = new F_MST_1003(); } return _instance; } } #endregion #region 事件 /// /// 窗体加载 /// private void F_MST_0501_Load(object sender, EventArgs e) { try { // 加载权限 FormPermissionManager.FormPermissionControl(this.Name, this, Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData); this.chkCeaseFlag.AllItemCheck(); this.chkValueFlag.AllItemCheck(); //绑定辅件类别 ClientRequestEntity cre1 = new ClientRequestEntity(); cre1.NameSpace = "AccessoriesType"; cre1.Name = "GetAccessoriesType"; // 调用服务器端获取数据集 ServiceResultEntity sre1 = SystemModuleProxy.Service.DoRequest(cre1); if (sre1 != null && sre1.Data != null && sre1.Data.Tables.Count > 0) { DICTIONARYVALUE.DisplayMember = "DICTIONARYVALUE"; DICTIONARYVALUE.ValueMember = "DICTIONARYVALUE"; DICTIONARYVALUE.DataSource = sre1.Data.Tables[0]; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 获取数据事件 /// private void btnSearch_Click(object sender, EventArgs e) { try { this.dgvGoods.DataSource = null; this.dgvGoodsSap.DataSource = null; this.dgvAccessories.DataSource = null; object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods)); if (obGoodsResult != null) { DataSet dsGoods = (DataSet)obGoodsResult; if (dsGoods.Tables.Count != Constant.INT_IS_ZERO) { this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO]; this.dgvGoods.ReadOnly = true; this.dgvGoodsSap.ReadOnly = true; if (this.dgvGoods.Rows.Count == Constant.INT_IS_ZERO) { // 提示未查找到数据 MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { // 提示未查找到数据 MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 清空事件 /// private void btnClearCondition_Click(object sender, EventArgs e) { this.txtGoodsCode.Text = ""; this.txtGoodsModel.Text = ""; this.txtGoodsName.Text = ""; this.txtGoodsSpecification.Text = ""; this.scbGoodsType.ClearValue(); this.chkCeaseFlag.AllItemCheck(); this.chkValueFlag.AllItemCheck(); } /// /// 关闭窗体事件 /// private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 自适应事件 /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvGoods.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); dgvGoodsSap.AutoResizeColumns(); dgvAccessories.AutoResizeColumns(); } /// /// 窗体关闭事件 /// private void F_MST_0501_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 添加产品事件 /// private void tsbtnAddGoods_Click(object sender, EventArgs e) { try { F_MST_1013 frmMST1013 = new F_MST_1013(Constant.FormMode.Add, Constant.INT_IS_ZERO, Constant.INT_IS_ZERO); DialogResult dialogresult = frmMST1013.ShowDialog(); if (dialogresult.Equals(DialogResult.OK)) { this.dgvGoods.DataSource = null; object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods)); if (obGoodsResult != null) { DataSet dsGoods = (DataSet)obGoodsResult; if (dsGoods.Tables.Count != Constant.INT_IS_ZERO) { this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO]; this.dgvGoods.ReadOnly = true; } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 编辑产品事件 /// private void tsbtnEditGoods_Click(object sender, EventArgs e) { try { DataGridViewRow currentRow = this.dgvGoods.CurrentRow; if (currentRow != null) { int goodsId = 0; int logoid = 0; if (((System.Data.DataTable)this.dgvGoods.DataSource).DefaultView.Count < 1 || ((System.Data.DataTable)this.dgvGoodsSap.DataSource).DefaultView.Count < 1) { MessageBox.Show(Messages.MSG_CMN_W020, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { goodsId = Convert.ToInt32(currentRow.Cells["GoodsID"].Value); logoid = Convert.ToInt32(this.dgvGoodsSap.CurrentRow.Cells["logoid"].Value); } DataGridViewRow currentRow1 = this.dgvAccessories.CurrentRow; int Accessorestypeid = Convert.ToInt32(currentRow1.Cells["ACCESSORIESTYPEID"].Value); string Accessorestypecode = currentRow1.Cells["ACCESSORIESCODE"].Value.ToString(); string Accessorestypename = currentRow1.Cells["DICTIONARYVALUE"].Value.ToString(); F_MST_1013 frmMST1013 = new F_MST_1013(Constant.FormMode.Edit, goodsId,logoid); DialogResult dialogresult = frmMST1013.ShowDialog(); if (dialogresult.Equals(DialogResult.OK)) { this.dgvGoods.DataSource = null; btnSearch_Click(sender,e); } } else { MessageBox.Show(Messages.MSG_CMN_W020, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 双击列表事件 /// private void dgvGoods_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { //try //{ // if (e.RowIndex == -Constant.INT_IS_ONE || e.ColumnIndex == -Constant.INT_IS_ONE) // { // return; // } // int goodsId = Convert.ToInt32(this.dgvGoods.Rows[e.RowIndex].Cells["GoodsID"].Value); // int logoid = Convert.ToInt32(this.dgvGoodsSap.Rows[e.RowIndex].Cells["logoid"].Value); // F_MST_1013 frmMST1013 = new F_MST_1013(Constant.FormMode.Edit, goodsId,logoid,); // DialogResult dialogresult = frmMST1013.ShowDialog(); // if (dialogresult.Equals(DialogResult.OK)) // { // this.dgvGoods.DataSource = null; // object obGoodsResult = DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(getGoods)); // if (obGoodsResult != null) // { // DataSet dsGoods = (DataSet)obGoodsResult; // if (dsGoods.Tables.Count != Constant.INT_IS_ZERO) // { // this.dgvGoods.DataSource = dsGoods.Tables[Constant.INT_IS_ZERO]; // this.dgvGoods.ReadOnly = true; // } // } // } //} //catch (Exception ex) //{ // // 对异常进行共通处理 // ExceptionManager.HandleEventException(this.ToString(), // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); //} } #endregion #region 私有方法 /// /// 根据查询条件获取数据集合 /// public DataSet getGoods() { try { GoodsEntity goods = new GoodsEntity(); goods.GoodsCode = this.txtGoodsCode.Text; goods.GoodsModel = this.txtGoodsModel.Text; goods.GoodsName = this.txtGoodsName.Text; goods.GoodsSpecification = this.txtGoodsSpecification.Text; goods.GoodsTypeCode = this.scbGoodsType.SearchedValue + ""; //判断选择框,如有选择则赋值 object[] objListCease = chkCeaseFlag.SelectedValues; if (objListCease.Length == Constant.INT_IS_ONE) { goods.CeaseFlag = (int)objListCease[Constant.INT_IS_ZERO]; } else if (objListCease.Length == Constant.INT_IS_ZERO) { return null; } object[] objListValue = chkValueFlag.SelectedValues; if (objListValue.Length == Constant.INT_IS_ONE) { goods.ValueFlag = (int)objListValue[Constant.INT_IS_ZERO]; } else if (objListValue.Length == Constant.INT_IS_ZERO) { return null; } return SystemModuleProxy.Service.SerachGoods(goods); } catch (Exception ex) { throw ex; } } #endregion private void dgvGoods_SelectionChanged(object sender, EventArgs e) { this.dgvAccessories.DataSource = null; this.dgvGoodsSap.DataSource = null; if (this.dgvGoods.DataSource == null || this.dgvGoods.CurrentRow == null) { this.dgvGoodsSap.DataSource = null; this.dgvAccessories.DataSource = null; return; } try { int goodsid = Convert.ToInt32(this.dgvGoods.CurrentRow.Cells["GoodsID"].Value); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GoodsLogo"; cre.Name = "GetGoodsLogo"; cre.Request = goodsid; // 调用服务器端获取数据集 ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre); if (sre != null && sre.Data != null && sre.Data.Tables[0].Rows.Count > 0) { this.dgvGoodsSap.DataSource = sre.Data.Tables[0]; } else { this.tsbtnEdit.Enabled = false; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void dgvGoodsSap_SelectionChanged(object sender, EventArgs e) { if (this.dgvGoodsSap.DataSource == null || this.dgvGoodsSap.CurrentRow == null) { this.dgvAccessories.DataSource = null; return; } try { if (this.dgvGoods.DataSource != null&&this.dgvGoods.CurrentRow != null) { int goodsid = Convert.ToInt32(this.dgvGoods.CurrentRow.Cells["GoodsID"].Value); int logoid = Convert.ToInt32(this.dgvGoodsSap.CurrentRow.Cells["logoid"].Value); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GoodsLogo"; cre.Name = "GetAccessories"; DataSet ds = new DataSet(); DataTable tb = new DataTable(); tb.Columns.Add("GoodsID"); tb.Columns.Add("logoid"); DataRow dr = tb.NewRow(); dr["GoodsID"] = goodsid; dr["logoid"] = logoid; tb.Rows.Add(dr); ds.Tables.Add(tb); cre.Data = ds; // 调用服务器端获取数据集 ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre); if (sre.Data.Tables[0].Rows.Count > 0) { this.tsbtnEdit.Enabled = true; this.dgvAccessories.DataSource = sre.Data.Tables[0]; } else { this.tsbtnEdit.Enabled = false; //定义表格结构 DataTable tb2 = new DataTable(); tb2.Columns.Add("ACCESSORIESCODE"); tb2.Columns.Add("ACCESSORIESNAME"); tb2.Columns.Add("DICTIONARYVALUE"); this.dgvAccessories.DataSource = tb2; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } //保存 private void btnSave_Click(object sender, EventArgs e) { try { ((DataTable)this.dgvAccessories.DataSource).AcceptChanges(); //信息必填 foreach (DataGridViewRow gvrAcc in this.dgvAccessories.Rows) { if (gvrAcc.IsNewRow != true) { if (gvrAcc.Cells["DICTIONARYVALUE"].Value == null || gvrAcc.Cells["DICTIONARYVALUE"].Value == DBNull.Value) { MessageBox.Show("请选择辅件种类!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } if (gvrAcc.Cells["ACCESSORIESCODE"].Value == null || gvrAcc.Cells["ACCESSORIESCODE"].Value == DBNull.Value) { MessageBox.Show("请选择辅件编码!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } } } this.dgvAccessories.CurrentRow.ErrorText = string.Empty; DataTable dtAcc = (DataTable)this.dgvAccessories.DataSource; int goodsid = Convert.ToInt32(this.dgvGoods.CurrentRow.Cells["GoodsID"].Value); int logoid = Convert.ToInt32(this.dgvGoodsSap.CurrentRow.Cells["logoid"].Value); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "EditGoods"; cre.Name = "EditGoodsLogo"; DataSet ds = new DataSet(); DataTable tb = new DataTable(); tb.Columns.Add("GoodsID"); tb.Columns.Add("logoid"); DataRow dr1 = tb.NewRow(); dr1["GoodsID"] = goodsid; dr1["logoid"] = logoid; tb.Rows.Add(dr1); ds.Tables.Add(dtAcc.Copy()); ds.Tables.Add(tb.Copy()); cre.Data = ds; // 调用服务器端获取数据集 ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre); if (sre.OtherStatus != 0 && sre.OtherStatus > 0) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "辅件", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }