F_PC_0102.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_0102.cs
  5. * 2.功能描述:新建成型线信息
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/09/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseControls;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.PCModuleService;
  20. namespace Dongke.IBOSS.PRD.Client.PCModule
  21. {
  22. public partial class F_PC_0102 : FormBase
  23. {
  24. #region 成员变量
  25. //需要添加的成型线明细集合
  26. public List<GroutingLineDetailEntity> _addDetailList = new List<GroutingLineDetailEntity>();
  27. //模具总数量
  28. private int _mouldCount = 0;
  29. //是否已经提示过删除模具的信息
  30. private bool _isMessageShow = false;
  31. #endregion
  32. #region 构造函数
  33. public F_PC_0102()
  34. {
  35. InitializeComponent();
  36. this.Text = FormTitles.F_PC_0102;
  37. this.btnSave.Text = ButtonText.BTN_SAVE;
  38. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  39. this.btnAddMould.Text = ButtonText.BTN_ADDMOULD;
  40. this.btnDeleteSelected.Text = ButtonText.BTN_DELETESELECTED;
  41. this.dkUser.IsWorker = true;
  42. }
  43. #endregion
  44. #region 事件
  45. /// <summary>
  46. /// 添加成型线明细
  47. /// </summary>
  48. private void btnAddMould_Click(object sender, EventArgs e)
  49. {
  50. try
  51. {
  52. if (this.txtGroutingLineCode.Text == string.Empty)
  53. {
  54. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "成型线编码"), this.Text,
  55. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  56. return;
  57. }
  58. if (this.txtCount.Text == string.Empty)
  59. {
  60. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具数量"), this.Text,
  61. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  62. return;
  63. }
  64. if (this.dkGoods.GoodsID == null)
  65. {
  66. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具产品"), this.Text,
  67. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  68. return;
  69. }
  70. if (this._mouldCount == 999)
  71. {
  72. MessageBox.Show("成型线模具数量不可超过999个!", this.Text,
  73. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  74. return;
  75. }
  76. if (this._isMessageShow == false)
  77. {
  78. MessageBox.Show("生成模具信息后,修改成型线编码将导致清空模具信息。",
  79. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  80. this._isMessageShow = true;
  81. }
  82. for (int i = 0; i < Convert.ToInt32(this.txtCount.Text); i++)
  83. {
  84. int GroutingMouldCodeNum = i + _mouldCount;
  85. GroutingLineDetailEntity detailInfo = new GroutingLineDetailEntity();
  86. detailInfo.GROUTINGMOULDCODE = this.txtGroutingLineCode.Text + "-" + (GroutingMouldCodeNum + 1).ToString().PadLeft(3, '0');
  87. detailInfo.MOULDCODE = Guid.NewGuid().ToString();
  88. detailInfo.GOODSID = Convert.ToInt32(this.dkGoods.GoodsID);
  89. detailInfo.GOODSNAME = this.dkGoods.GoodsName;
  90. detailInfo.GOODSCODE = this.dkGoods.GoodsCode;
  91. detailInfo.GoodsSpecification = this.dkGoods.GoodsSpecification;
  92. detailInfo.GROUTINGCOUNT = Constant.INT_IS_ZERO;
  93. detailInfo.MOULDSTATUS = Convert.ToInt32(Constant.GMouldStatus.Normal);
  94. detailInfo.REMARKS = "-";
  95. this._addDetailList.Add(detailInfo);
  96. }
  97. this._mouldCount += Convert.ToInt32(this.txtCount.Text);
  98. this.dgvDetail.AutoGenerateColumns = false;
  99. this.dgvDetail.DataSource = ListToTable();
  100. }
  101. catch (Exception ex)
  102. {
  103. // 对异常进行共通处理
  104. ExceptionManager.HandleEventException(this.ToString(),
  105. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  106. }
  107. }
  108. /// <summary>
  109. /// 关闭窗体
  110. /// </summary>
  111. private void btnCancel_Click(object sender, EventArgs e)
  112. {
  113. this.Close();
  114. }
  115. /// <summary>
  116. /// 删除明细
  117. /// </summary>
  118. private void btnDeleteSelected_Click(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. DataGridViewRow currentRow = this.dgvDetail.CurrentRow;
  123. if (currentRow == null || currentRow.Index < Constant.INT_IS_ZERO)
  124. {
  125. return;
  126. }
  127. this._addDetailList.RemoveAt(currentRow.Index);
  128. this.dgvDetail.DataSource = ListToTable();
  129. }
  130. catch (Exception ex)
  131. {
  132. // 对异常进行共通处理
  133. ExceptionManager.HandleEventException(this.ToString(),
  134. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  135. }
  136. }
  137. /// <summary>
  138. /// 提交新建
  139. /// </summary>
  140. private void btnSave_Click(object sender, EventArgs e)
  141. {
  142. try
  143. {
  144. int ErrorId = ValidationText();
  145. if (ErrorId != Constant.INT_IS_ZERO)
  146. {
  147. string errorAddress = "";
  148. switch (ErrorId)
  149. {
  150. case 1:
  151. this.txtBuildingNo.Focus();
  152. errorAddress = "楼号";
  153. break;
  154. case 2:
  155. this.txtFloorNo.Focus();
  156. errorAddress = "楼层";
  157. break;
  158. case 3:
  159. this.txtGroutingLineNo.Focus();
  160. errorAddress = "线号";
  161. break;
  162. case 4:
  163. this.txtGroutingLineCode.Focus();
  164. errorAddress = "成型线编码";
  165. break;
  166. case 5:
  167. this.txtGroutingLineName.Focus();
  168. errorAddress = "成型线名称";
  169. break;
  170. case 7:
  171. this.dkUser.Focus();
  172. errorAddress = "工号";
  173. break;
  174. case 8:
  175. this.dkType.Focus();
  176. errorAddress = "成型线类别";
  177. break;
  178. default:
  179. break;
  180. };
  181. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress),
  182. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  183. return;
  184. }
  185. if (this._addDetailList.Count == Constant.INT_IS_ZERO)
  186. {
  187. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具信息"), this.Text,
  188. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  189. return;
  190. }
  191. GroutingLineEntity ginfo = new GroutingLineEntity();
  192. ginfo.BUILDINGNO = this.txtBuildingNo.Text.Trim();
  193. ginfo.FLOORNO = this.txtFloorNo.Text.Trim();
  194. ginfo.GROUTINGLINENO = this.txtGroutingLineNo.Text.Trim();
  195. ginfo.GROUTINGLINECODE = this.txtGroutingLineCode.Text.Trim();
  196. ginfo.GROUTINGLINENAME = this.txtGroutingLineName.Text.Trim();
  197. ginfo.REMARKS = this.txtRemarks.Text.Trim();
  198. ginfo.USERID = this.dkUser.UserID;
  199. ginfo.MOULDTYPEID = this.dkType.MouldTypeID;
  200. ginfo.MouldStatus = Convert.ToInt32(Constant.GMouldStatus.Normal);
  201. ginfo.VALUEFLAG = Convert.ToInt32(Constant.ValueFlag.Effective);
  202. ginfo.MOULDQUANTITY = this._addDetailList.Count;
  203. int myReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  204. {
  205. return PCModuleProxy.Service.AddGroutingLine(ginfo, this._addDetailList);
  206. }));
  207. if (myReturn > Constant.INT_IS_ZERO)
  208. {
  209. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "成型线信息", "保存"),
  210. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  211. this.DialogResult = DialogResult.OK;
  212. }
  213. else if (myReturn == -50)
  214. {
  215. MessageBox.Show("成型线编码已存在,请重新输入!",
  216. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  217. }
  218. else
  219. {
  220. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "成型线信息", "保存"),
  221. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  222. }
  223. }
  224. catch (Exception ex)
  225. {
  226. // 对异常进行共通处理
  227. ExceptionManager.HandleEventException(this.ToString(),
  228. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  229. }
  230. }
  231. /// <summary>
  232. /// 编号变更
  233. /// </summary>
  234. private void txtBuildingNo_TextChanged(object sender, EventArgs e)
  235. {
  236. this.txtGroutingLineCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  237. + this.txtGroutingLineNo.Text.Trim();
  238. this.txtGroutingLineName.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  239. + this.txtGroutingLineNo.Text.Trim();
  240. }
  241. /// <summary>
  242. /// 编号变更
  243. /// </summary>
  244. private void txtFloorNo_TextChanged(object sender, EventArgs e)
  245. {
  246. this.txtGroutingLineCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  247. + this.txtGroutingLineNo.Text.Trim();
  248. this.txtGroutingLineName.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  249. + this.txtGroutingLineNo.Text.Trim();
  250. }
  251. /// <summary>
  252. /// 编号变更
  253. /// </summary>
  254. private void txtGroutingLineNo_TextChanged(object sender, EventArgs e)
  255. {
  256. this.txtGroutingLineCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  257. + this.txtGroutingLineNo.Text.Trim();
  258. this.txtGroutingLineName.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  259. + this.txtGroutingLineNo.Text.Trim();
  260. }
  261. /// <summary>
  262. /// 成型线文本改变事件
  263. /// </summary>
  264. /// <param name="sender"></param>
  265. /// <param name="e"></param>
  266. private void txtGroutingLineCode_TextChanged(object sender, EventArgs e)
  267. {
  268. if (this._addDetailList.Count != Constant.INT_IS_ZERO)
  269. {
  270. MessageBox.Show("成型线编码变更后,需重新生成模具信息!",
  271. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  272. this._addDetailList.Clear();
  273. this._mouldCount = 0;
  274. this.dgvDetail.DataSource = null;
  275. }
  276. }
  277. #endregion
  278. #region 私有方法
  279. /// <summary>
  280. /// 将实体数据转换为DataTable,绑定到控件中
  281. /// </summary>
  282. protected DataTable ListToTable()
  283. {
  284. try
  285. {
  286. DataTable dtDataSourse = new DataTable();
  287. dtDataSourse.Columns.Add("GROUTINGMOULDCODE", System.Type.GetType("System.String"));
  288. dtDataSourse.Columns.Add("GOODSNAME", System.Type.GetType("System.String"));
  289. dtDataSourse.Columns.Add("GoodsCode", System.Type.GetType("System.String"));
  290. dtDataSourse.Columns.Add("GoodsSpecification", System.Type.GetType("System.String"));
  291. dtDataSourse.Columns.Add("GOODSID", System.Type.GetType("System.String"));
  292. for (int i = 0; i < _addDetailList.Count; i++)
  293. {
  294. DataRow drRow = dtDataSourse.NewRow();
  295. drRow["GROUTINGMOULDCODE"] = _addDetailList[i].GROUTINGMOULDCODE;
  296. drRow["GOODSNAME"] = _addDetailList[i].GOODSNAME;
  297. drRow["GoodsCode"] = _addDetailList[i].GOODSCODE;
  298. drRow["GoodsSpecification"] = _addDetailList[i].GoodsSpecification;
  299. drRow["GOODSID"] = _addDetailList[i].GOODSID;
  300. dtDataSourse.Rows.Add(drRow);
  301. }
  302. return dtDataSourse;
  303. }
  304. catch (Exception ex)
  305. {
  306. throw ex;
  307. }
  308. }
  309. /// <summary>
  310. /// 验证添加项
  311. /// </summary>
  312. protected int ValidationText()
  313. {
  314. int ErrorId = 0;
  315. string txtBuildingNo = this.txtBuildingNo.Text.Trim();
  316. string txtFloorNo = this.txtFloorNo.Text.Trim();
  317. string txtGroutingLineNo = this.txtGroutingLineNo.Text.Trim();
  318. string txtGroutingLineCode = this.txtGroutingLineCode.Text.Trim();
  319. string txtGroutingLineName = this.txtGroutingLineName.Text.Trim();
  320. string txtRemarks = this.txtRemarks.Text.Trim();
  321. if (txtBuildingNo == string.Empty)
  322. {
  323. ErrorId = 1;
  324. return ErrorId;
  325. }
  326. if (txtFloorNo == string.Empty)
  327. {
  328. ErrorId = 2;
  329. return ErrorId;
  330. }
  331. if (txtGroutingLineNo == string.Empty)
  332. {
  333. ErrorId = 3;
  334. return ErrorId;
  335. }
  336. if (txtGroutingLineCode == string.Empty)
  337. {
  338. ErrorId = 4;
  339. return ErrorId;
  340. }
  341. if (txtGroutingLineName == string.Empty)
  342. {
  343. ErrorId = 5;
  344. return ErrorId;
  345. }
  346. if (dkUser.UserID == null)
  347. {
  348. ErrorId = 7;
  349. return ErrorId;
  350. }
  351. if (dkType.MouldTypeID == null)
  352. {
  353. ErrorId = 8;
  354. return ErrorId;
  355. }
  356. return ErrorId;
  357. }
  358. #endregion
  359. }
  360. }