F_PC_0101_1_4.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_0101_1_4.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_4 : FormBase
  21. {
  22. #region 成员变量
  23. // 窗体标题
  24. private string _titleStr = "";
  25. private DataTable _dtBindSource = null;
  26. private string _S_PC_001 = "";
  27. private int _gridIndex = -1;
  28. private DataRowView _currentRow = null;
  29. #endregion
  30. #region 构造函数
  31. /// <summary>
  32. ///
  33. /// </summary>
  34. /// <param name="dtBindSource"></param>
  35. /// <param name="titleStr"></param>
  36. public F_PC_0101_1_4(DataTable dtBindSource, string titleStr)
  37. {
  38. InitializeComponent();
  39. _dtBindSource = dtBindSource;
  40. this.Text = titleStr;
  41. this.btnSave.Text = ButtonText.BTN_SAVE;
  42. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  43. this.txtGroutingLineCode.Text = dtBindSource.Rows[0]["GroutingLineCode"].ToString();
  44. }
  45. #endregion
  46. #region 事件
  47. /// <summary>
  48. /// 保存按钮事件
  49. /// </summary>
  50. /// <param name="sender"></param>
  51. /// <param name="e"></param>
  52. private void btnSave_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. DataTable dtName = this.dgvGroutingLineDetail.DataSource as DataTable;
  57. if (this._S_PC_001 == "2")
  58. {
  59. DataRow[] drs = dtName.Select("MouldID is null");
  60. if (drs != null && drs.Length > 0)
  61. {
  62. MessageBox.Show("不是所有成型模具都绑定了条码,请绑定条码模具后再保存。", this.Text,
  63. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  64. this.txtBarcode.Focus();
  65. return;
  66. }
  67. }
  68. else
  69. {
  70. DataRow[] drs = dtName.Select("GoodsID is null");
  71. if (drs != null && drs.Length > 0)
  72. {
  73. MessageBox.Show("不是所有成型模具都设置了新的产品型号,请设置新的产品型号后再保存。", this.Text,
  74. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  75. this.scbGoods.Focus();
  76. return;
  77. }
  78. if (this._S_PC_001 == "1")
  79. {
  80. drs = dtName.Select("MouldID is null");
  81. if (drs != null && drs.Length > 0)
  82. {
  83. DialogResult dialogResult = MessageBox.Show("不是所有成型模具都绑定了条码,是否继续保存?", this.Text,
  84. MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  85. if (dialogResult != System.Windows.Forms.DialogResult.Yes)
  86. {
  87. this.txtBarcode.Focus();
  88. return;
  89. }
  90. }
  91. }
  92. }
  93. dtName.TableName = "GMouldRecord";
  94. //for (int i = 0; i < dtName.Rows.Count; i++)
  95. //{
  96. // dtName.Rows[i]["RecordRemarks"] = dtName.Rows[i]["RecordRemarks"] + "->" + this.dkGoodsCode.Text;
  97. //}
  98. ServiceResultEntity returnRow = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  99. {
  100. return PCModuleProxy.Service.UpdateLineEndGroutingLineDetail(dtName, scbGoods.SearchedPKMember);
  101. }));
  102. if (returnRow != null)
  103. {
  104. if (returnRow.Status == Constant.ServiceResultStatus.Success)
  105. {
  106. MessageBox.Show(this.Text + "成功", this.Text,
  107. MessageBoxButtons.OK, MessageBoxIcon.Information);
  108. this.DialogResult = DialogResult.OK;
  109. }
  110. else if (returnRow.OtherStatus == -500)
  111. {
  112. MessageBox.Show("数据已经被修改,请重新编辑", this.Text,
  113. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  114. }
  115. else
  116. {
  117. MessageBox.Show(returnRow.Message,
  118. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  119. }
  120. }
  121. else
  122. {
  123. MessageBox.Show(this.Text + "失败", this.Text,
  124. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. // 对异常进行共通处理
  130. ExceptionManager.HandleEventException(this.ToString(),
  131. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  132. }
  133. }
  134. /// <summary>
  135. /// 窗体加载事件
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void F_PC_0101_1_2_Load(object sender, EventArgs e)
  140. {
  141. this.dgvGroutingLineDetail.AutoGenerateColumns = false;
  142. DateTime accountDate = (DateTime)DoAsync(new BaseAsyncMethod(() =>
  143. {
  144. return CommonModuleProxy.Service.GetAccountDate();
  145. }));
  146. this.txtDateStart.Value = accountDate;
  147. this.dgvGroutingLineDetail.DataSource = _dtBindSource;
  148. // 设置可输入单元格的颜色
  149. this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
  150. DataSet dsSetting = SystemModuleProxy.Service.GetSystemSettingDataByCode(Constant.SettingType.S_PC_001.ToString());
  151. if (dsSetting != null && dsSetting.Tables[0].Rows.Count > 0)
  152. {
  153. this._S_PC_001 = dsSetting.Tables[0].Rows[0]["SettingValue"].ToString();
  154. }
  155. if (this._S_PC_001 == "2")
  156. {
  157. this.scbGoods.Visible = false;
  158. }
  159. }
  160. /// <summary>
  161. /// 取消按钮事件
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void btnCancel_Click(object sender, EventArgs e)
  166. {
  167. this.Close();
  168. }
  169. /// <summary>
  170. /// 自适应列宽
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void btnAdaptive_Click(object sender, EventArgs e)
  175. {
  176. this.dgvGroutingLineDetail.AutoResizeColumns();
  177. }
  178. /// <summary>
  179. /// 设置只读
  180. /// </summary>
  181. /// <param name="sender"></param>
  182. /// <param name="e"></param>
  183. private void dgvGroutingLineDetail_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
  184. {
  185. DataGridView dgv = sender as DataGridView;
  186. if (dgv == null || dgv.ReadOnly || e.RowIndex < 0)
  187. {
  188. return;
  189. }
  190. try
  191. {
  192. if (string.IsNullOrEmpty(dgv.Rows[e.RowIndex].Cells["MouldID"].Value + ""))
  193. {
  194. // 自动生成模具
  195. dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = false;
  196. dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = false;
  197. }
  198. else
  199. {
  200. // 模具档案
  201. dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = true;
  202. dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = true;
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. // 对异常进行共通处理
  208. ExceptionManager.HandleEventException(this.ToString(),
  209. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  210. }
  211. }
  212. /// <summary>
  213. /// 设置非条码模具产品编码
  214. /// </summary>
  215. /// <param name="sender"></param>
  216. /// <param name="e"></param>
  217. private void scbGoods_SearchedItemChanged(object sender, EventArgs e)
  218. {
  219. try
  220. {
  221. foreach (DataGridViewRow item in this.dgvGroutingLineDetail.Rows)
  222. {
  223. DataRowView row = item.DataBoundItem as DataRowView;
  224. if (row == null || row["MouldID"] + "" != "")
  225. {
  226. continue;
  227. }
  228. row["GoodsID"] = scbGoods.SearchedPKMember;
  229. row["GoodsCode"] = scbGoods.SearchedValue + "";
  230. row["GoodsName"] = scbGoods.SearchedText;
  231. row["GoodsSpecification"] = scbGoods.SearchedItem["GoodsSpecification"];
  232. row["RecordRemarks"] = row["OldRecordRemarks"] + "][" + row["GOODSCODE"] + "]";
  233. row.EndEdit();
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. // 对异常进行共通处理
  239. ExceptionManager.HandleEventException(this.ToString(),
  240. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  241. }
  242. }
  243. ///// <summary>
  244. ///// 设置非条码模具产品编码
  245. ///// </summary>
  246. ///// <param name="sender"></param>
  247. ///// <param name="e"></param>
  248. //private void dkGoodsCode_GoodsValueChanged(object sender, Controls.SearchTextBox.dkGoodsCodeSearchBox.TextChangeEventArgs e)
  249. //{
  250. // try
  251. // {
  252. // foreach (DataGridViewRow item in this.dgvGroutingLineDetail.Rows)
  253. // {
  254. // DataRowView row = item.DataBoundItem as DataRowView;
  255. // if (row == null || row["MouldID"] + "" != "")
  256. // {
  257. // continue;
  258. // }
  259. // row["GoodsID"] = scbGoods.SearchedPKMember;
  260. // row["GoodsCode"] = scbGoods.SearchedValue + "";
  261. // row["GoodsName"] = scbGoods.SearchedText;
  262. // row["GoodsSpecification"] = scbGoods.SearchedItem["GoodsSpecification"];
  263. // row["RecordRemarks"] = row["OldRecordRemarks"] + "][" + row["GOODSCODE"] + "]";
  264. // row.EndEdit();
  265. // }
  266. // }
  267. // catch (Exception ex)
  268. // {
  269. // // 对异常进行共通处理
  270. // ExceptionManager.HandleEventException(this.ToString(),
  271. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  272. // }
  273. //}
  274. /// <summary>
  275. /// 选择改变
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void dgvGroutingLineDetail_SelectionChanged(object sender, EventArgs e)
  280. {
  281. if (dgvGroutingLineDetail.CurrentRow == null)
  282. {
  283. return;
  284. }
  285. try
  286. {
  287. this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
  288. this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
  289. this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
  290. }
  291. catch (Exception ex)
  292. {
  293. // 对异常进行共通处理
  294. ExceptionManager.HandleEventException(this.ToString(),
  295. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  296. }
  297. }
  298. /// <summary>
  299. /// 验证模具条码
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
  304. {
  305. if (e.KeyCode == Keys.Enter)
  306. {
  307. this.btnAddMouldBarcode_Click(null, null);
  308. }
  309. }
  310. /// <summary>
  311. /// 添加模具
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void btnAddMouldBarcode_Click(object sender, EventArgs e)
  316. {
  317. if (this.txtGMouldCode.Text == "" || this._gridIndex == -1 || this._currentRow == null)
  318. {
  319. MessageBox.Show("没有选择模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  320. this.txtGMouldCode.Focus();
  321. return;
  322. }
  323. string barcode = this.txtBarcode.Text.Trim();
  324. if (barcode == "")
  325. {
  326. MessageBox.Show("没有输入模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  327. this.txtBarcode.Focus();
  328. return;
  329. }
  330. try
  331. {
  332. string gMouldCode = this.txtGMouldCode.Text;
  333. DataTable dtInfo = _dtBindSource;
  334. DataRow[] dr = dtInfo.Select("GroutingMouldCode <> '" + gMouldCode + "' and NewMouldBarcode = '" + barcode + "'");
  335. if (dr.Length > 0)
  336. {
  337. MessageBox.Show("存在相同的模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  338. this.txtBarcode.Focus();
  339. this.txtBarcode.SelectAll();
  340. return;
  341. };
  342. // 验证模具条码状态
  343. ClientRequestEntity cre = new ClientRequestEntity();
  344. cre.NameSpace = "PC_Mould";
  345. cre.Name = "GetMouldData";
  346. cre.Properties["MouldBarcode"] = barcode;
  347. ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
  348. if (sre == null || sre.Data == null || sre.Data.Tables.Count == 0 || sre.Data.Tables[0].Rows.Count == 0)
  349. {
  350. MessageBox.Show("无效模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  351. this.txtBarcode.Focus();
  352. this.txtBarcode.SelectAll();
  353. return;
  354. }
  355. DataRow item = sre.Data.Tables["InfoData"].Rows[0];
  356. int mouldStatus = Convert.ToInt32(item["MouldStatus"]);
  357. if (mouldStatus != 1 && mouldStatus != 3)
  358. {
  359. MessageBox.Show("此模具当前状态为【" + item["MouldStatusName"] + "】,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  360. this.txtBarcode.Focus();
  361. this.txtBarcode.SelectAll();
  362. return;
  363. }
  364. //this._currentRow["MouldSource"] = "1";
  365. //this._currentRow["MOULDID"] = item["MOULDID"];
  366. //this._currentRow["MOULDCODE"] = item["MOULDCODE"];
  367. //this._currentRow["NewMouldBarcode"] = item["MOULDBarcode"];
  368. //this._currentRow["GOODSID"] = item["GOODSID"];
  369. //this._currentRow["GOODSNAME"] = item["GOODSNAME"];
  370. //this._currentRow["GOODSCODE"] = item["GOODSCODE"];
  371. //this._currentRow["GoodsSpecification"] = item["GoodsSpecification"];
  372. //this._currentRow["GROUTINGCOUNT"] = item["GroutingNum"];
  373. //this._currentRow["StandardGroutingCount"] = item["StandardGroutingNum"];
  374. ////this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + item["MOULDBarcode"] + "][" + item["GOODSCODE"] + "]";
  375. //this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + "][" + item["GOODSCODE"] + "]";
  376. //this._currentRow.EndEdit();
  377. //this.txtBarcode.Clear();
  378. //this.txtBarcode.Focus();
  379. //if (this._gridIndex + 1 < this.dgvGroutingLineDetail.Rows.Count)
  380. //{
  381. // this._gridIndex++;
  382. //}
  383. //else
  384. //{
  385. // this._gridIndex = 0;
  386. //}
  387. int outputCount = Convert.ToInt32(item["OutputCount"]);
  388. if (outputCount == 1)
  389. {
  390. // 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
  391. if (this._currentRow["MOULDID"] != DBNull.Value)
  392. {
  393. //int oldMouldID = Convert.ToInt32(this._currentRow["MOULDID"]);
  394. DataRow[] rows = dtInfo.Select("MOULDID=" + this._currentRow["MOULDID"]);
  395. if (rows.Length > 1)
  396. {
  397. foreach (DataRow row in rows)
  398. {
  399. row["MouldSource"] = "0";
  400. row["MOULDID"] = DBNull.Value;
  401. row["MOULDCODE"] = DBNull.Value;
  402. row["NewMouldBarcode"] = DBNull.Value;
  403. row["GROUTINGCOUNT"] = 0;
  404. row["MouldOutputNo"] = DBNull.Value;
  405. row.EndEdit();
  406. }
  407. }
  408. }
  409. this._currentRow["MouldSource"] = "1";
  410. this._currentRow["MOULDID"] = item["MOULDID"];
  411. this._currentRow["MOULDCODE"] = item["MOULDCODE"];
  412. this._currentRow["NewMouldBarcode"] = item["MOULDBarcode"];
  413. this._currentRow["GOODSID"] = item["GOODSID"];
  414. this._currentRow["GOODSNAME"] = item["GOODSNAME"];
  415. this._currentRow["GOODSCODE"] = item["GOODSCODE"];
  416. this._currentRow["GoodsSpecification"] = item["GoodsSpecification"];
  417. this._currentRow["GROUTINGCOUNT"] = item["GroutingNums"];
  418. this._currentRow["MouldOutputNo"] = DBNull.Value;
  419. this._currentRow["StandardGroutingCount"] = item["StandardGroutingNum"];
  420. //this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + item["MOULDBarcode"] + "]";
  421. this._currentRow.EndEdit();
  422. }
  423. else
  424. {
  425. // 一模多产时,必须绑定连续成型模具编号。 add by chenxy 2018-10-29
  426. string minGMouldCode = this.txtGMouldCode.Text;
  427. int maxIndex = Convert.ToInt32(minGMouldCode.Substring(minGMouldCode.Length - 3)) + outputCount;
  428. string maxGMouldCode = this.txtGroutingLineCode.Text + "-" + maxIndex.ToString("000");
  429. DataRow[] grows = dtInfo.Select("GroutingMouldCode>='" + minGMouldCode + "' and GroutingMouldCode<'" + maxGMouldCode + "'");
  430. if (grows.Length != outputCount)
  431. {
  432. MessageBox.Show("此模具的产出数量为【" + outputCount + "】,当前成型模具数量不足或编号不连续,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  433. this.txtBarcode.Focus();
  434. this.txtBarcode.SelectAll();
  435. return;
  436. }
  437. //foreach (DataRow row in grows)
  438. for (int i = 0; i < grows.Length; i++)
  439. {
  440. DataRow row = grows[i];
  441. DataRow itemOutput = sre.Data.Tables["InfoData"].Rows[i];
  442. // 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
  443. if (row["MOULDID"] != DBNull.Value)
  444. {
  445. DataRow[] rows = dtInfo.Select("MOULDID=" + row["MOULDID"]);
  446. if (rows.Length > 1)
  447. {
  448. foreach (DataRow crow in rows)
  449. {
  450. crow["MouldSource"] = "0";
  451. crow["MOULDID"] = DBNull.Value;
  452. crow["MOULDCODE"] = DBNull.Value;
  453. crow["NewMouldBarcode"] = DBNull.Value;
  454. crow["GROUTINGCOUNT"] = 0;
  455. crow["MouldOutputNo"] = DBNull.Value;
  456. crow.EndEdit();
  457. }
  458. }
  459. }
  460. row["MouldSource"] = "1";
  461. row["MOULDID"] = item["MOULDID"];
  462. row["MOULDCODE"] = item["MOULDCODE"];
  463. row["NewMouldBarcode"] = item["MOULDBarcode"];
  464. row["GOODSID"] = item["GOODSID"];
  465. row["GOODSNAME"] = item["GOODSNAME"];
  466. row["GOODSCODE"] = item["GOODSCODE"];
  467. row["GoodsSpecification"] = item["GoodsSpecification"];
  468. row["GROUTINGCOUNT"] = itemOutput["GroutingNum"];
  469. row["MouldOutputNo"] = itemOutput["OutputNo"];
  470. row["StandardGroutingCount"] = item["StandardGroutingNum"];
  471. row.EndEdit();
  472. }
  473. }
  474. this.txtBarcode.Clear();
  475. this.txtBarcode.Focus();
  476. //if (this._gridIndex + 1 < this.dgvGroutingLineDetail.Rows.Count)
  477. //{
  478. // this._gridIndex++;
  479. //}
  480. //else
  481. //{
  482. // this._gridIndex = 0;
  483. //}
  484. if (this._gridIndex + outputCount < this.dgvGroutingLineDetail.Rows.Count)
  485. {
  486. this._gridIndex += outputCount;
  487. }
  488. else
  489. {
  490. this._gridIndex = 0;
  491. }
  492. this.dgvGroutingLineDetail.CurrentCell =
  493. this.dgvGroutingLineDetail.Rows[this._gridIndex].Cells[this.dgvGroutingLineDetail.CurrentCell.ColumnIndex];
  494. this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
  495. this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
  496. this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
  497. }
  498. catch (Exception ex)
  499. {
  500. //_ShowFlag = true;
  501. // 对异常进行共通处理
  502. ExceptionManager.HandleEventException(this.ToString(),
  503. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  504. }
  505. }
  506. #endregion
  507. }
  508. }