F_MST_1013.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using Dongke.IBOSS.PRD.Basics.BaseResources;
  2. using Dongke.IBOSS.PRD.WCF.DataModels;
  3. using Dongke.IBOSS.PRD.WCF.Proxys;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. namespace Dongke.IBOSS.PRD.Client.SystemModule
  13. {
  14. public partial class F_MST_1013 : Form
  15. {
  16. #region 成员变量
  17. //产品id
  18. private int _goodsid;
  19. //商标id
  20. private int _logoid;
  21. //页面状态
  22. private Constant.FormMode _formStatus;
  23. #endregion
  24. #region 构造函数
  25. public F_MST_1013(Constant.FormMode status, int goodsId,int logoid)
  26. {
  27. InitializeComponent();
  28. _goodsid = goodsId;
  29. _logoid = logoid;
  30. this._formStatus = status;
  31. if (this._formStatus == Constant.FormMode.Add)
  32. {
  33. this.Text = "新建产品对应商标辅件";
  34. }
  35. else
  36. {
  37. this.Text = "编辑产品对应商标辅件";
  38. }
  39. }
  40. #endregion
  41. #region 事件
  42. //页面加载事件
  43. private void F_MST_1013_Load(object sender, EventArgs e)
  44. {
  45. this.dgvDataAccess.AutoGenerateColumns = false;
  46. this.dgvDataAccess.IsSetInputColumnsColor = true;
  47. //获取数据源
  48. LoadDataSource();
  49. if (this._formStatus == Constant.FormMode.Edit)
  50. {
  51. //this.dgvDataAccess
  52. // 绑定产品编码
  53. ClientRequestEntity cre = new ClientRequestEntity();
  54. cre.NameSpace = "Goods";
  55. cre.Name = "GetGoods";
  56. DataSet ds = new DataSet();
  57. DataTable tb = new DataTable();
  58. tb.Columns.Add("GoodsID");
  59. tb.Columns.Add("logoid");
  60. DataRow dr1 = tb.NewRow();
  61. dr1["GoodsID"] = _goodsid;
  62. dr1["logoid"] = _logoid;
  63. tb.Rows.Add(dr1);
  64. ds.Tables.Add(tb);
  65. cre.Data = ds;
  66. // 调用服务器端获取数据集
  67. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  68. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  69. {
  70. GOODSCODE.SelectedValue = Convert.ToInt32(sre.Data.Tables[0].Rows[0]["GOODSID"]);
  71. LOGO.SelectedValue = Convert.ToInt32(sre.Data.Tables[0].Rows[0]["LOGOID"]);
  72. }
  73. this.GOODSCODE.Enabled = false;
  74. this.LOGO.Enabled = false;
  75. }
  76. else
  77. {
  78. this.GOODSCODE.Enabled = true;
  79. this.LOGO.Enabled = true;
  80. }
  81. }
  82. //保存事件
  83. private void btnSave_Click(object sender, EventArgs e)
  84. {
  85. ((DataTable)this.dgvDataAccess.DataSource).AcceptChanges();
  86. if (this.GOODSCODE.SelectedValue.ToString() == string.Empty)
  87. {
  88. this.GOODSCODE.Focus();
  89. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品编码"),
  90. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  91. return;
  92. }
  93. if (this.LOGO.Text.ToString() == string.Empty)
  94. {
  95. this.LOGO.Focus();
  96. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "商标"),
  97. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  98. return;
  99. }
  100. //信息必填
  101. foreach (DataGridViewRow gvrAcc in this.dgvDataAccess.Rows)
  102. {
  103. if (gvrAcc.IsNewRow != true)
  104. {
  105. if (gvrAcc.Cells["DICTIONARYVALUE"].Value == null || gvrAcc.Cells["DICTIONARYVALUE"].Value == DBNull.Value)
  106. {
  107. MessageBox.Show("请选择辅件种类!",
  108. this.Text,
  109. MessageBoxButtons.OK,
  110. MessageBoxIcon.Information,
  111. MessageBoxDefaultButton.Button1);
  112. return;
  113. }
  114. if (gvrAcc.Cells["ACCESSORIESCODE"].Value == null || gvrAcc.Cells["ACCESSORIESCODE"].Value == DBNull.Value)
  115. {
  116. MessageBox.Show("请选择辅件编码!",
  117. this.Text,
  118. MessageBoxButtons.OK,
  119. MessageBoxIcon.Information,
  120. MessageBoxDefaultButton.Button1);
  121. return;
  122. }
  123. }
  124. }
  125. if (this._formStatus == Constant.FormMode.Edit)
  126. {
  127. this.dgvDataAccess.CurrentRow.ErrorText = string.Empty;
  128. DataTable dtAcc = (DataTable)this.dgvDataAccess.DataSource;
  129. ClientRequestEntity cre = new ClientRequestEntity();
  130. cre.NameSpace = "EditGoods";
  131. cre.Name = "EditGoodsLogo";
  132. DataSet ds = new DataSet();
  133. DataTable tb = new DataTable();
  134. tb.Columns.Add("GoodsID");
  135. tb.Columns.Add("logoid");
  136. DataRow dr1 = tb.NewRow();
  137. dr1["GoodsID"] =_goodsid;
  138. dr1["logoid"] =_logoid;
  139. tb.Rows.Add(dr1);
  140. ds.Tables.Add(dtAcc.Copy());
  141. ds.Tables.Add(tb.Copy());
  142. cre.Data = ds;
  143. // 调用服务器端获取数据集
  144. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  145. if (sre.OtherStatus != 0 && sre.OtherStatus > 0)
  146. {
  147. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "辅件", "保存"),
  148. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  149. this.DialogResult = DialogResult.OK;
  150. // 关闭窗体
  151. this.Close();
  152. }
  153. }
  154. //保存
  155. else if (this._formStatus == Constant.FormMode.Add)
  156. {
  157. DataTable dtAcc = (DataTable)this.dgvDataAccess.DataSource;
  158. int goodsid = Convert.ToInt32(this.GOODSCODE.SelectedValue.ToString());
  159. int logoid = Convert.ToInt32(this.LOGO.SelectedValue.ToString());
  160. ClientRequestEntity cre = new ClientRequestEntity();
  161. cre.NameSpace = "GoodsLogo";
  162. cre.Name = "AddGoodsLogo";
  163. DataSet ds = new DataSet();
  164. DataTable tb = new DataTable();
  165. tb.Columns.Add("Goodsid");
  166. tb.Columns.Add("Logoid");
  167. DataRow dr = tb.NewRow();
  168. dr["Goodsid"] = this.GOODSCODE.SelectedValue;
  169. dr["Logoid"] = this.LOGO.SelectedValue;
  170. //tb = ((DataTable)this.dgvDataAccess.DataSource).Copy();
  171. tb.Rows.Add(dr);
  172. ds.Tables.Add(tb.Copy());
  173. ds.Tables.Add(dtAcc.Copy());
  174. //ds.Tables.Add(tb2.Copy());
  175. cre.Data = ds;
  176. // 调用服务器端获取数据集
  177. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  178. if (sre.OtherStatus != 0 && sre.OtherStatus > 0)
  179. {
  180. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "辅件", "保存"),
  181. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  182. this.DialogResult = DialogResult.OK;
  183. // 关闭窗体
  184. this.Close();
  185. }
  186. }
  187. }
  188. #endregion
  189. #region 私有方法
  190. /// <summary>
  191. /// 加载页面所需的数据源
  192. /// </summary>
  193. private void LoadDataSource()
  194. {
  195. try
  196. {
  197. // 绑定产品编码
  198. ClientRequestEntity cre = new ClientRequestEntity();
  199. cre.NameSpace = "GoodsCode";
  200. cre.Name = "GetGoodsCode";
  201. // 调用服务器端获取数据集
  202. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  203. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  204. {
  205. GOODSCODE.DisplayMember = "GOODSCODE";
  206. GOODSCODE.ValueMember = "GOODSID";
  207. GOODSCODE.DataSource = sre.Data.Tables[0];
  208. }
  209. //绑定商标
  210. //DataSet logos = SystemModuleProxy.Service.GetLogoInfo();
  211. //if (logos != null && logos.Tables.Count > 0)
  212. //{
  213. // LOGO.DisplayMember = "LogoNameCode";
  214. // LOGO.ValueMember = "LogoID";
  215. // LOGO.DataSource = logos.Tables[0];
  216. //}
  217. //绑定辅件类别
  218. ClientRequestEntity cre1 = new ClientRequestEntity();
  219. cre1.NameSpace = "AccessoriesType";
  220. cre1.Name = "GetAccessoriesType";
  221. // 调用服务器端获取数据集
  222. ServiceResultEntity sre1 = SystemModuleProxy.Service.DoRequest(cre1);
  223. if (sre1 != null && sre1.Data != null && sre1.Data.Tables.Count > 0)
  224. {
  225. DICTIONARYVALUE.DisplayMember = "DICTIONARYVALUE";
  226. DICTIONARYVALUE.ValueMember = "DICTIONARYVALUE";
  227. DICTIONARYVALUE.DataSource = sre1.Data.Tables[0];
  228. }
  229. //获取辅件信息
  230. ClientRequestEntity cre2 = new ClientRequestEntity();
  231. cre2.NameSpace = "GoodsLogo";
  232. cre2.Name = "GetAccessories";
  233. DataSet ds = new DataSet();
  234. DataTable tb = new DataTable();
  235. tb.Columns.Add("GoodsID");
  236. tb.Columns.Add("logoid");
  237. DataRow dr = tb.NewRow();
  238. dr["GoodsID"] = _goodsid;
  239. dr["logoid"] = _logoid;
  240. tb.Rows.Add(dr);
  241. ds.Tables.Add(tb);
  242. cre2.Data = ds;
  243. // 调用服务器端获取数据集
  244. ServiceResultEntity sre2 = SystemModuleProxy.Service.DoRequest(cre2);
  245. if (sre2.Data.Tables[0].Rows.Count > 0)
  246. {
  247. this.dgvDataAccess.DataSource = sre2.Data.Tables[0];
  248. }
  249. else
  250. {
  251. //定义表格结构
  252. DataTable tb2 = new DataTable();
  253. tb2.Columns.Add("ACCESSORIESCODE");
  254. tb2.Columns.Add("ACCESSORIESNAME");
  255. tb2.Columns.Add("DICTIONARYVALUE");
  256. this.dgvDataAccess.DataSource = tb2;
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. throw ex;
  262. }
  263. }
  264. #endregion
  265. private void btnCancel_Click(object sender, EventArgs e)
  266. {
  267. this.Close();
  268. }
  269. private void GOODSCODE_SelectedIndexChanged(object sender, EventArgs e)
  270. {
  271. int goodsid = Convert.ToInt32(GOODSCODE.SelectedValue.ToString());
  272. ClientRequestEntity cre = new ClientRequestEntity();
  273. cre.NameSpace = "GoodsLogo";
  274. cre.Name = "GetGoodsLogo";
  275. cre.Request = goodsid;
  276. // 调用服务器端获取数据集
  277. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  278. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  279. {
  280. LOGO.DisplayMember = "LOGONAME";
  281. LOGO.ValueMember = "LOGOID";
  282. this.LOGO.DataSource = sre.Data.Tables[0];
  283. }
  284. }
  285. }
  286. }