F_PC_0101_1_3.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_0101_1_3.cs
  5. * 2.功能描述:操作时间及备注录入
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/09/25 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Windows.Forms;
  12. using System.Data;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. namespace Dongke.IBOSS.PRD.Client.PCModule
  19. {
  20. public partial class F_PC_0101_1_3 : FormBase
  21. {
  22. #region 成员变量
  23. private DataTable _dtBindSource = null;
  24. private string _S_PC_001 = "";
  25. private int _gridIndex = -1;
  26. private DataRowView _currentRow = null;
  27. #endregion
  28. #region 构造函数
  29. public F_PC_0101_1_3(DataTable dtBindSource, string titleStr)
  30. {
  31. InitializeComponent();
  32. _dtBindSource = dtBindSource;
  33. this.Text = titleStr;
  34. this.btnSave.Text = ButtonText.BTN_SAVE;
  35. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  36. this.txtGroutingLineCode.Text = dtBindSource.Rows[0]["GroutingLineCode"].ToString();
  37. }
  38. #endregion
  39. #region 事件
  40. /// <summary>
  41. /// 保存按钮事件
  42. /// </summary>
  43. /// <param name="sender"></param>
  44. /// <param name="e"></param>
  45. private void btnSave_Click(object sender, EventArgs e)
  46. {
  47. try
  48. {
  49. DataTable dtName = this.dgvGroutingLineDetail.DataSource as DataTable;
  50. if (this._S_PC_001 == "2")
  51. {
  52. DataRow[] drs = dtName.Select("MouldID is null");
  53. if (drs != null && drs.Length > 0)
  54. {
  55. MessageBox.Show("不是所有成型模具都绑定了条码,请绑定条码模具后再保存。", this.Text,
  56. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  57. this.txtBarcode.Focus();
  58. return;
  59. }
  60. }
  61. else if (this._S_PC_001 == "1")
  62. {
  63. DataRow[] drs = dtName.Select("MouldID is null");
  64. if (drs != null && drs.Length > 0)
  65. {
  66. DialogResult dialogResult = MessageBox.Show("不是所有成型模具都绑定了条码,是否继续保存?", this.Text,
  67. MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  68. if (dialogResult != System.Windows.Forms.DialogResult.Yes)
  69. {
  70. this.txtBarcode.Focus();
  71. return;
  72. }
  73. }
  74. }
  75. dtName.AcceptChanges();
  76. dtName.TableName = "GMouldRecord";
  77. ServiceResultEntity returnRow = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  78. {
  79. return PCModuleProxy.Service.ChangeGMouldEndGroutingLineDetail(dtName);
  80. }));
  81. if (returnRow != null)
  82. {
  83. if (returnRow.Status == Constant.ServiceResultStatus.Success)
  84. {
  85. MessageBox.Show(this.Text + "成功", this.Text,
  86. MessageBoxButtons.OK, MessageBoxIcon.Information);
  87. this.DialogResult = DialogResult.OK;
  88. }
  89. else if (returnRow.OtherStatus == -500)
  90. {
  91. MessageBox.Show("数据已经被修改,请重新编辑", this.Text,
  92. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  93. }
  94. else
  95. {
  96. MessageBox.Show(returnRow.Message,
  97. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  98. }
  99. }
  100. else
  101. {
  102. MessageBox.Show(this.Text + "失败", this.Text,
  103. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  104. }
  105. }
  106. catch (Exception ex)
  107. {
  108. // 对异常进行共通处理
  109. ExceptionManager.HandleEventException(this.ToString(),
  110. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  111. }
  112. }
  113. /// <summary>
  114. /// 窗体加载事件
  115. /// </summary>
  116. /// <param name="sender"></param>
  117. /// <param name="e"></param>
  118. private void F_PC_0101_1_2_Load(object sender, EventArgs e)
  119. {
  120. this.dgvGroutingLineDetail.AutoGenerateColumns = false;
  121. DateTime accountDate = CommonModuleProxy.Service.GetAccountDate();
  122. this.txtDateStart.Value = accountDate;
  123. this.dgvGroutingLineDetail.DataSource = _dtBindSource;
  124. // 设置可输入单元格的颜色
  125. this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
  126. DataSet dsSetting = SystemModuleProxy.Service.GetSystemSettingDataByCode(Constant.SettingType.S_PC_001.ToString());
  127. if (dsSetting != null && dsSetting.Tables[0].Rows.Count > 0)
  128. {
  129. this._S_PC_001 = dsSetting.Tables[0].Rows[0]["SettingValue"].ToString();
  130. }
  131. }
  132. /// <summary>
  133. /// 取消按钮事件
  134. /// </summary>
  135. /// <param name="sender"></param>
  136. /// <param name="e"></param>
  137. private void btnCancel_Click(object sender, EventArgs e)
  138. {
  139. this.Close();
  140. }
  141. /// <summary>
  142. /// 自适应列宽
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void btnAdaptive_Click(object sender, EventArgs e)
  147. {
  148. this.dgvGroutingLineDetail.AutoResizeColumns();
  149. }
  150. /// <summary>
  151. /// 设置只读
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void dgvGroutingLineDetail_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
  156. {
  157. DataGridView dgv = sender as DataGridView;
  158. if (dgv == null || dgv.ReadOnly || e.RowIndex < 0)
  159. {
  160. return;
  161. }
  162. try
  163. {
  164. if (string.IsNullOrEmpty(dgv.Rows[e.RowIndex].Cells["MouldID"].Value + ""))
  165. {
  166. // 自动生成模具
  167. dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = false;
  168. dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = false;
  169. }
  170. else
  171. {
  172. // 模具档案
  173. dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = true;
  174. dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = true;
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. // 对异常进行共通处理
  180. ExceptionManager.HandleEventException(this.ToString(),
  181. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  182. }
  183. }
  184. /// <summary>
  185. /// 选择改变
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void dgvGroutingLineDetail_SelectionChanged(object sender, EventArgs e)
  190. {
  191. if(dgvGroutingLineDetail.CurrentRow == null)
  192. {
  193. return;
  194. }
  195. try
  196. {
  197. this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
  198. this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
  199. this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
  200. }
  201. catch (Exception ex)
  202. {
  203. // 对异常进行共通处理
  204. ExceptionManager.HandleEventException(this.ToString(),
  205. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  206. }
  207. }
  208. /// <summary>
  209. /// 验证模具条码
  210. /// </summary>
  211. /// <param name="sender"></param>
  212. /// <param name="e"></param>
  213. private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
  214. {
  215. if (e.KeyCode == Keys.Enter)
  216. {
  217. this.btnAddMouldBarcode_Click(null, null);
  218. }
  219. }
  220. /// <summary>
  221. /// 添加模具
  222. /// </summary>
  223. /// <param name="sender"></param>
  224. /// <param name="e"></param>
  225. private void btnAddMouldBarcode_Click(object sender, EventArgs e)
  226. {
  227. if (this.txtGMouldCode.Text == "" || this._gridIndex == -1 || this._currentRow == null)
  228. {
  229. MessageBox.Show("没有选择模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  230. this.txtGMouldCode.Focus();
  231. return;
  232. }
  233. string barcode = this.txtBarcode.Text.Trim();
  234. if (barcode == "")
  235. {
  236. MessageBox.Show("没有输入模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  237. this.txtBarcode.Focus();
  238. return;
  239. }
  240. try
  241. {
  242. string gMouldCode = this.txtGMouldCode.Text;
  243. DataTable dtInfo = _dtBindSource;
  244. DataRow[] dr = dtInfo.Select("GroutingMouldCode <> '" + gMouldCode + "' and NewMouldBarcode = '" + barcode + "'");
  245. if (dr.Length > 0)
  246. {
  247. MessageBox.Show("存在相同的模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  248. this.txtBarcode.Focus();
  249. this.txtBarcode.SelectAll();
  250. return;
  251. };
  252. // 验证模具条码状态
  253. ClientRequestEntity cre = new ClientRequestEntity();
  254. cre.NameSpace = "PC_Mould";
  255. cre.Name = "GetMouldData";
  256. cre.Properties["MouldBarcode"] = barcode;
  257. ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
  258. if (sre == null || sre.Data == null || sre.Data.Tables.Count == 0 || sre.Data.Tables[0].Rows.Count == 0)
  259. {
  260. MessageBox.Show("无效模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  261. this.txtBarcode.Focus();
  262. this.txtBarcode.SelectAll();
  263. return;
  264. }
  265. DataRow item = sre.Data.Tables["InfoData"].Rows[0];
  266. int mouldStatus = Convert.ToInt32(item["MouldStatus"]);
  267. if (mouldStatus != 1 && mouldStatus != 3)
  268. {
  269. MessageBox.Show("此模具当前状态为【" + item["MouldStatusName"] + "】,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  270. this.txtBarcode.Focus();
  271. this.txtBarcode.SelectAll();
  272. return;
  273. }
  274. // 验证产品型号
  275. if (this._currentRow["GOODSID"] + "" != item["GOODSID"] + "")
  276. {
  277. MessageBox.Show("此模具产品型号为【" + item["GOODSCODE"] + "】,与当前产品型号不同,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  278. this.txtBarcode.Focus();
  279. this.txtBarcode.SelectAll();
  280. return;
  281. }
  282. int outputCount = Convert.ToInt32(item["OutputCount"]);
  283. if (outputCount == 1)
  284. {
  285. // 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
  286. if (this._currentRow["MOULDID"] != DBNull.Value)
  287. {
  288. //int oldMouldID = Convert.ToInt32(this._currentRow["MOULDID"]);
  289. DataRow[] rows = dtInfo.Select("MOULDID=" + this._currentRow["MOULDID"]);
  290. if (rows.Length > 1)
  291. {
  292. foreach (DataRow row in rows)
  293. {
  294. row["MouldSource"] = "0";
  295. row["MOULDID"] = DBNull.Value;
  296. row["MOULDCODE"] = DBNull.Value;
  297. row["NewMouldBarcode"] = DBNull.Value;
  298. row["GROUTINGCOUNT"] = 0;
  299. row["MouldOutputNo"] = DBNull.Value;
  300. row.EndEdit();
  301. }
  302. }
  303. }
  304. this._currentRow["MouldSource"] = "1";
  305. this._currentRow["MOULDID"] = item["MOULDID"];
  306. this._currentRow["MOULDCODE"] = item["MOULDCODE"];
  307. this._currentRow["NewMouldBarcode"] = item["MOULDBarcode"];
  308. this._currentRow["MouldOutputNo"] = DBNull.Value;
  309. this._currentRow["GOODSID"] = item["GOODSID"];
  310. this._currentRow["GOODSNAME"] = item["GOODSNAME"];
  311. this._currentRow["GOODSCODE"] = item["GOODSCODE"];
  312. this._currentRow["GoodsSpecification"] = item["GoodsSpecification"];
  313. this._currentRow["GROUTINGCOUNT"] = item["GroutingNums"];
  314. this._currentRow["StandardGroutingCount"] = item["StandardGroutingNum"];
  315. //this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + item["MOULDBarcode"] + "]";
  316. this._currentRow.EndEdit();
  317. }
  318. else
  319. {
  320. // 一模多产时,必须绑定连续成型模具编号。 add by chenxy 2018-10-29
  321. string minGMouldCode = this.txtGMouldCode.Text;
  322. int maxIndex = Convert.ToInt32(minGMouldCode.Substring(minGMouldCode.Length - 3)) + outputCount;
  323. string maxGMouldCode = this.txtGroutingLineCode.Text + "-" + maxIndex.ToString("000");
  324. DataRow[] grows = dtInfo.Select("goodsid="+ this._currentRow["GOODSID"]+" And GroutingMouldCode>='" + minGMouldCode + "' and GroutingMouldCode<'" + maxGMouldCode + "'");
  325. if (grows.Length != outputCount)
  326. {
  327. MessageBox.Show("此模具的产出数量为【" + outputCount + "】,当前成型模具数量不足或编号不连续,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  328. this.txtBarcode.Focus();
  329. this.txtBarcode.SelectAll();
  330. return;
  331. }
  332. //foreach (DataRow row in grows)
  333. for (int i = 0; i < grows.Length; i++)
  334. {
  335. DataRow row = grows[i];
  336. DataRow itemOutput = sre.Data.Tables["InfoData"].Rows[i];
  337. // 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
  338. if (row["MOULDID"] != DBNull.Value)
  339. {
  340. DataRow[] rows = dtInfo.Select("MOULDID=" + row["MOULDID"]);
  341. if (rows.Length > 1)
  342. {
  343. foreach (DataRow crow in rows)
  344. {
  345. crow["MouldSource"] = "0";
  346. crow["MOULDID"] = DBNull.Value;
  347. crow["MOULDCODE"] = DBNull.Value;
  348. crow["NewMouldBarcode"] = DBNull.Value;
  349. crow["GROUTINGCOUNT"] = 0;
  350. crow["MouldOutputNo"] = DBNull.Value;
  351. crow.EndEdit();
  352. }
  353. }
  354. }
  355. row["MouldSource"] = "1";
  356. row["MOULDID"] = item["MOULDID"];
  357. row["MOULDCODE"] = item["MOULDCODE"];
  358. row["NewMouldBarcode"] = item["MOULDBarcode"];
  359. row["GOODSID"] = item["GOODSID"];
  360. row["GOODSNAME"] = item["GOODSNAME"];
  361. row["GOODSCODE"] = item["GOODSCODE"];
  362. row["GoodsSpecification"] = item["GoodsSpecification"];
  363. row["GROUTINGCOUNT"] = itemOutput["GroutingNum"];
  364. row["MouldOutputNo"] = itemOutput["OutputNo"];
  365. row["StandardGroutingCount"] = item["StandardGroutingNum"];
  366. row.EndEdit();
  367. }
  368. }
  369. this.txtBarcode.Clear();
  370. this.txtBarcode.Focus();
  371. //if (this._gridIndex + 1 < this.dgvGroutingLineDetail.Rows.Count)
  372. //{
  373. // this._gridIndex++;
  374. //}
  375. //else
  376. //{
  377. // this._gridIndex = 0;
  378. //}
  379. if (this._gridIndex + outputCount < this.dgvGroutingLineDetail.Rows.Count)
  380. {
  381. this._gridIndex += outputCount;
  382. }
  383. else
  384. {
  385. this._gridIndex = 0;
  386. }
  387. this.dgvGroutingLineDetail.CurrentCell =
  388. this.dgvGroutingLineDetail.Rows[this._gridIndex].Cells[this.dgvGroutingLineDetail.CurrentCell.ColumnIndex];
  389. this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
  390. this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
  391. this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
  392. }
  393. catch (Exception ex)
  394. {
  395. //_ShowFlag = true;
  396. // 对异常进行共通处理
  397. ExceptionManager.HandleEventException(this.ToString(),
  398. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  399. }
  400. }
  401. #endregion
  402. }
  403. }