using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Dongke.IBOSS.PRD.Client.SystemModule { public partial class F_MST_1013 : Form { #region 成员变量 //产品id private int _goodsid; //商标id private int _logoid; //页面状态 private Constant.FormMode _formStatus; #endregion #region 构造函数 public F_MST_1013(Constant.FormMode status, int goodsId,int logoid) { InitializeComponent(); _goodsid = goodsId; _logoid = logoid; this._formStatus = status; if (this._formStatus == Constant.FormMode.Add) { this.Text = "新建产品对应商标辅件"; } else { this.Text = "编辑产品对应商标辅件"; } } #endregion #region 事件 //页面加载事件 private void F_MST_1013_Load(object sender, EventArgs e) { this.dgvDataAccess.AutoGenerateColumns = false; this.dgvDataAccess.IsSetInputColumnsColor = true; //获取数据源 LoadDataSource(); if (this._formStatus == Constant.FormMode.Edit) { //this.dgvDataAccess // 绑定产品编码 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "Goods"; cre.Name = "GetGoods"; 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(tb); cre.Data = ds; // 调用服务器端获取数据集 ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre); if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0) { GOODSCODE.SelectedValue = Convert.ToInt32(sre.Data.Tables[0].Rows[0]["GOODSID"]); LOGO.SelectedValue = Convert.ToInt32(sre.Data.Tables[0].Rows[0]["LOGOID"]); } this.GOODSCODE.Enabled = false; this.LOGO.Enabled = false; } else { this.GOODSCODE.Enabled = true; this.LOGO.Enabled = true; } } //保存事件 private void btnSave_Click(object sender, EventArgs e) { ((DataTable)this.dgvDataAccess.DataSource).AcceptChanges(); if (this.GOODSCODE.SelectedValue.ToString() == string.Empty) { this.GOODSCODE.Focus(); MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品编码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (this.LOGO.Text.ToString() == string.Empty) { this.LOGO.Focus(); MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "商标"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } //信息必填 foreach (DataGridViewRow gvrAcc in this.dgvDataAccess.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; } } } if (this._formStatus == Constant.FormMode.Edit) { this.dgvDataAccess.CurrentRow.ErrorText = string.Empty; DataTable dtAcc = (DataTable)this.dgvDataAccess.DataSource; 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; // 关闭窗体 this.Close(); } } //保存 else if (this._formStatus == Constant.FormMode.Add) { DataTable dtAcc = (DataTable)this.dgvDataAccess.DataSource; int goodsid = Convert.ToInt32(this.GOODSCODE.SelectedValue.ToString()); int logoid = Convert.ToInt32(this.LOGO.SelectedValue.ToString()); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GoodsLogo"; cre.Name = "AddGoodsLogo"; DataSet ds = new DataSet(); DataTable tb = new DataTable(); tb.Columns.Add("Goodsid"); tb.Columns.Add("Logoid"); DataRow dr = tb.NewRow(); dr["Goodsid"] = this.GOODSCODE.SelectedValue; dr["Logoid"] = this.LOGO.SelectedValue; //tb = ((DataTable)this.dgvDataAccess.DataSource).Copy(); tb.Rows.Add(dr); ds.Tables.Add(tb.Copy()); ds.Tables.Add(dtAcc.Copy()); //ds.Tables.Add(tb2.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; // 关闭窗体 this.Close(); } } } #endregion #region 私有方法 /// /// 加载页面所需的数据源 /// private void LoadDataSource() { try { // 绑定产品编码 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GoodsCode"; cre.Name = "GetGoodsCode"; // 调用服务器端获取数据集 ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre); if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0) { GOODSCODE.DisplayMember = "GOODSCODE"; GOODSCODE.ValueMember = "GOODSID"; GOODSCODE.DataSource = sre.Data.Tables[0]; } //绑定商标 //DataSet logos = SystemModuleProxy.Service.GetLogoInfo(); //if (logos != null && logos.Tables.Count > 0) //{ // LOGO.DisplayMember = "LogoNameCode"; // LOGO.ValueMember = "LogoID"; // LOGO.DataSource = logos.Tables[0]; //} //绑定辅件类别 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]; } //获取辅件信息 ClientRequestEntity cre2 = new ClientRequestEntity(); cre2.NameSpace = "GoodsLogo"; cre2.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); cre2.Data = ds; // 调用服务器端获取数据集 ServiceResultEntity sre2 = SystemModuleProxy.Service.DoRequest(cre2); if (sre2.Data.Tables[0].Rows.Count > 0) { this.dgvDataAccess.DataSource = sre2.Data.Tables[0]; } else { //定义表格结构 DataTable tb2 = new DataTable(); tb2.Columns.Add("ACCESSORIESCODE"); tb2.Columns.Add("ACCESSORIESNAME"); tb2.Columns.Add("DICTIONARYVALUE"); this.dgvDataAccess.DataSource = tb2; } } catch (Exception ex) { throw ex; } } #endregion private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void GOODSCODE_SelectedIndexChanged(object sender, EventArgs e) { int goodsid = Convert.ToInt32(GOODSCODE.SelectedValue.ToString()); 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.Count > 0) { LOGO.DisplayMember = "LOGONAME"; LOGO.ValueMember = "LOGOID"; this.LOGO.DataSource = sre.Data.Tables[0]; } } } }