F_MST_1001.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*******************************************************************************
  2. * Copyright(c) 2016 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_1001.cs
  5. * 2.功能描述:半成品缺陷管理
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2016/06/22 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.Library;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. namespace Dongke.IBOSS.PRD.Client.SystemModule
  20. {
  21. /// <summary>
  22. /// 半成品缺陷管理
  23. /// </summary>
  24. public partial class F_MST_1001 : FormBase
  25. {
  26. #region 成员变量
  27. //窗体的单例模式
  28. private static F_MST_1001 _instance;
  29. // 缺陷位置数据源
  30. private DataTable _dtSourse;
  31. #endregion
  32. #region 构造函数
  33. /// <summary>
  34. /// 构造函数
  35. /// </summary>
  36. public F_MST_1001()
  37. {
  38. InitializeComponent();
  39. // 窗体标题、按钮文字
  40. this.Text = FormTitles.F_MST_1001;
  41. this.btnSave.Text = ButtonText.BTN_SAVE;
  42. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  43. }
  44. #endregion
  45. #region 单例模式
  46. /// <summary>
  47. /// 单例模式,防止重复创建窗体
  48. /// </summary>
  49. public static F_MST_1001 Instance
  50. {
  51. get
  52. {
  53. if (_instance == null)
  54. {
  55. _instance = new F_MST_1001();
  56. }
  57. return _instance;
  58. }
  59. }
  60. #endregion
  61. #region 事件
  62. /// <summary>
  63. /// 窗体加载
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. private void F_MST_1001_Load(object sender, System.EventArgs e)
  68. {
  69. try
  70. {
  71. // 设置datagridview不自动创建列
  72. this.dgvDataDefect.AutoGenerateColumns = false;
  73. this.dgvDataDefect.AllowUserToDeleteRows = false;
  74. // 窗体启动立即加载全部半成品缺陷信息
  75. this.GetAllSemicheckDefect();
  76. this.RefreshDataGridViewData();
  77. this.dgvDataDefect.IsSetInputColumnsColor = true;
  78. //权限控制
  79. FormPermissionManager.FormPermissionControl(this.Name, this,
  80. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  81. this.dgvDataDefect.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  82. }
  83. catch (Exception ex)
  84. {
  85. // 对异常进行共通处理
  86. ExceptionManager.HandleEventException(this.ToString(),
  87. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  88. }
  89. }
  90. /// <summary>
  91. /// 点击右上角关闭按钮
  92. /// </summary>
  93. /// <param name="sender"></param>
  94. /// <param name="e"></param>
  95. private void F_MST_1001_FormClosing(object sender, FormClosingEventArgs e)
  96. {
  97. try
  98. {
  99. // 关闭的时候需要判断是否有数据变化
  100. if (DataJudge.IsChange((DataTable)this.dgvDataDefect.DataSource))
  101. {
  102. DialogResult resultMsgBox = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  103. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  104. // 保存改变的数据
  105. if (resultMsgBox == DialogResult.Yes)
  106. {
  107. DataGridViewRow row = dgvDataDefect.CurrentRow;
  108. if (!row.IsNewRow)
  109. {
  110. // 判断缺陷编码不能为空
  111. if (row.Cells["DefectCode"].Value == null
  112. || string.IsNullOrEmpty(row.Cells["DefectCode"].Value + string.Empty))
  113. {
  114. // 错误消息
  115. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷编码"),
  116. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  117. e.Cancel = true;
  118. this.btnSave.Enabled = false;
  119. return;
  120. }
  121. // 判断缺陷名称不能为空
  122. if (row.Cells["DefectName"].Value == null
  123. || string.IsNullOrEmpty(row.Cells["DefectName"].Value + string.Empty))
  124. {
  125. // 单元格的错误消息
  126. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷名称"),
  127. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  128. e.Cancel = true;
  129. this.btnSave.Enabled = false;
  130. return;
  131. }
  132. }
  133. // 异步处理
  134. object result = DoAsync(new BaseAsyncMethod(SaveSemicheckDefect));
  135. if (result.Equals(Constant.INT_IS_ONE))
  136. {
  137. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "缺陷编码"),
  138. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  139. e.Cancel = true;
  140. this.btnSave.Enabled = false;
  141. return;
  142. }
  143. // 如果保存出错,不关闭窗体
  144. if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
  145. {
  146. e.Cancel = true;
  147. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "半成品缺陷", "保存"),
  148. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  149. this.btnSave.Enabled = false;
  150. this._dtSourse.AcceptChanges();
  151. }
  152. else if (Convert.ToInt32(result) == (int)Constant.RETURN_IS_EXIST)
  153. {
  154. e.Cancel = true;
  155. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "半成品缺陷名称"),
  156. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  157. }
  158. else
  159. {
  160. e.Cancel = true;
  161. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "半成品缺陷", "保存"),
  162. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  163. }
  164. }
  165. else if (resultMsgBox == DialogResult.Cancel)
  166. {
  167. e.Cancel = true;
  168. }
  169. }
  170. }
  171. catch (Exception ex)
  172. {
  173. // 对异常进行共通处理
  174. ExceptionManager.HandleEventException(this.ToString(),
  175. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  176. }
  177. }
  178. /// <summary>
  179. /// 窗体关闭后,释放单例资源
  180. /// </summary>
  181. /// <param name="sender"></param>
  182. /// <param name="e"></param>
  183. private void F_MST_1001_FormClosed(object sender, FormClosedEventArgs e)
  184. {
  185. _instance = null;
  186. }
  187. /// <summary>
  188. /// 信息输入格式控制
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. private void dgvDataDefectPosition_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  193. {
  194. try
  195. {
  196. TextBox tb = (e.Control as TextBox);
  197. if (tb != null)
  198. {
  199. if ("DefectCode" == this.dgvDataDefect.Columns[this.dgvDataDefect.CurrentCell.ColumnIndex].Name)
  200. {
  201. tb.CharacterCasing = CharacterCasing.Upper;
  202. }
  203. else
  204. {
  205. tb.CharacterCasing = CharacterCasing.Normal;
  206. }
  207. }
  208. }
  209. catch (Exception ex)
  210. {
  211. // 对异常进行共通处理
  212. ExceptionManager.HandleEventException(this.ToString(),
  213. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  214. }
  215. }
  216. /// <summary>
  217. /// 选中新行时,设置默认值
  218. /// </summary>
  219. /// <param name="sender"></param>
  220. /// <param name="e"></param>
  221. private void dgvDataDefect_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  222. {
  223. // 设置有效属性为选中状态
  224. e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
  225. e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
  226. }
  227. /// <summary>
  228. /// 根据数据是否变化,设置保存按钮的可用状态
  229. /// </summary>
  230. /// <param name="sender"></param>
  231. /// <param name="e"></param>
  232. private void dgvDataDefectPosition_RowValidated(object sender, DataGridViewCellEventArgs e)
  233. {
  234. try
  235. {
  236. this.SetSaveBtnStatus();
  237. }
  238. catch (Exception ex)
  239. {
  240. // 对异常进行共通处理
  241. ExceptionManager.HandleEventException(this.ToString(),
  242. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  243. }
  244. }
  245. /// <summary>
  246. /// 根据数据是否变化,设置保存按钮的可用状态
  247. /// </summary>
  248. /// <param name="sender"></param>
  249. /// <param name="e"></param>
  250. private void dgvDataDefect_CellValidated(object sender, DataGridViewCellEventArgs e)
  251. {
  252. try
  253. {
  254. this.SetSaveBtnStatus();
  255. }
  256. catch (Exception ex)
  257. {
  258. // 对异常进行共通处理
  259. ExceptionManager.HandleEventException(this.ToString(),
  260. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  261. }
  262. }
  263. /// <summary>
  264. /// 单元格验证,检查
  265. /// </summary>
  266. /// <param name="sender"></param>
  267. /// <param name="e"></param>
  268. private void dgvDataDefect_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  269. {
  270. try
  271. {
  272. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  273. {
  274. return;
  275. }
  276. if (!dgvDataDefect.CurrentRow.IsNewRow)
  277. {
  278. DataGridViewRow rowItem = dgvDataDefect.Rows[e.RowIndex];
  279. DataGridViewColumn columnItem = dgvDataDefect.Columns[e.ColumnIndex];
  280. object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
  281. // 缺陷编码
  282. if ("DefectCode".Equals(columnItem.Name))
  283. {
  284. if (columnvalue != null && !string.IsNullOrEmpty(columnvalue + ""))
  285. {
  286. if (!Utility.IsUnique(columnvalue.ToString(),
  287. dgvDataDefect.CurrentRow.Index, this.dgvDataDefect, "DefectCode"))
  288. {
  289. // 单元格的错误消息
  290. this.dgvDataDefect.CurrentRow.ErrorText = string.Format(
  291. Messages.MSG_CMN_W006, "缺陷编码");
  292. e.Cancel = true;
  293. this.btnSave.Enabled = false;
  294. return;
  295. }
  296. }
  297. }
  298. // 清除单元格的错误消息
  299. this.dgvDataDefect.CurrentRow.ErrorText = string.Empty;
  300. }
  301. }
  302. catch (Exception ex)
  303. {
  304. // 对异常进行共通处理
  305. ExceptionManager.HandleEventException(this.ToString(),
  306. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  307. }
  308. }
  309. /// <summary>
  310. /// 行校验
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void dgvDataDefectPosition_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  315. {
  316. try
  317. {
  318. // 按Esc键时不校验
  319. if (!dgvDataDefect.IsCurrentRowDirty)
  320. {
  321. this.dgvDataDefect.IsSetInputColumnsColor = true;
  322. return;
  323. }
  324. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  325. {
  326. // 清除单元格的错误消息
  327. this.dgvDataDefect.CurrentRow.ErrorText = string.Empty;
  328. return;
  329. }
  330. DataGridViewRow row = dgvDataDefect.CurrentRow;
  331. if (!row.IsNewRow)
  332. {
  333. // 判断缺陷编码能为空
  334. if (row.Cells["DefectCode"].Value == null
  335. || string.IsNullOrEmpty(row.Cells["DefectCode"].Value + ""))
  336. {
  337. // 单元格的错误消息
  338. this.dgvDataDefect.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "缺陷编码");
  339. e.Cancel = true;
  340. this.btnSave.Enabled = false;
  341. return;
  342. }
  343. // 判断缺陷名称不能为空
  344. if (row.Cells["DefectName"].Value == null
  345. || string.IsNullOrEmpty(row.Cells["DefectName"].Value + ""))
  346. {
  347. // 单元格的错误消息
  348. this.dgvDataDefect.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "缺陷名称");
  349. e.Cancel = true;
  350. this.btnSave.Enabled = false;
  351. return;
  352. }
  353. // 清除单元格的错误消息
  354. this.dgvDataDefect.CurrentRow.ErrorText = string.Empty;
  355. }
  356. }
  357. catch (Exception ex)
  358. {
  359. // 对异常进行共通处理
  360. ExceptionManager.HandleEventException(this.ToString(),
  361. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  362. }
  363. }
  364. /// <summary>
  365. /// 根据是否选中停用数据,加载数据
  366. /// </summary>
  367. /// <param name="sender"></param>
  368. /// <param name="e"></param>
  369. private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  370. {
  371. try
  372. {
  373. this.RefreshDataGridViewData();
  374. this.SetSaveBtnStatus();
  375. this.dgvDataDefect.IsSetInputColumnsColor = true;
  376. }
  377. catch (Exception ex)
  378. {
  379. // 对异常进行共通处理
  380. ExceptionManager.HandleEventException(this.ToString(),
  381. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  382. }
  383. }
  384. /// <summary>
  385. /// 单元格输入时,给自动生成的行设置颜色
  386. /// </summary>
  387. /// <param name="sender"></param>
  388. /// <param name="e"></param>
  389. private void dgvDataDefectPosition_UserAddedRow(object sender, DataGridViewRowEventArgs e)
  390. {
  391. this.dgvDataDefect.IsSetInputColumnsColor = true;
  392. }
  393. /// <summary>
  394. /// 保存缺陷位置数据
  395. /// </summary>
  396. /// <param name="sender"></param>
  397. /// <param name="e"></param>
  398. private void btnSave_Click(object sender, EventArgs e)
  399. {
  400. try
  401. {
  402. int results = Conservation();
  403. //单元格必输项不能为空
  404. if (results == Constant.INT_IS_ONE)
  405. {
  406. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷编码"),
  407. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  408. this.btnSave.Enabled = false;
  409. return;
  410. }
  411. if (results == Constant.INT_IS_TWO)
  412. {
  413. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷名称"),
  414. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  415. this.btnSave.Enabled = false;
  416. return;
  417. }
  418. // 异步处理
  419. this.btnSave.Enabled = false;
  420. this.btnCancel.Enabled = false;
  421. int result = (int)DoAsync(new BaseAsyncMethod(SaveSemicheckDefect));
  422. this.btnSave.Enabled = true;
  423. this.btnCancel.Enabled = true;
  424. if (result == Constant.INT_IS_TWO)
  425. {
  426. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "半成品缺陷", "保存"),
  427. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  428. this._dtSourse.AcceptChanges();
  429. this.btnSave.Enabled = false;
  430. }
  431. else if (result == Constant.INT_IS_ONE)
  432. {
  433. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "缺陷编码"),
  434. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  435. return;
  436. }
  437. else
  438. {
  439. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "缺陷", "保存"),
  440. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  441. }
  442. this.dgvDataDefect.IsSetInputColumnsColor = true;
  443. }
  444. catch (Exception ex)
  445. {
  446. this.btnSave.Enabled = true;
  447. this.btnCancel.Enabled = true;
  448. // 对异常进行共通处理
  449. ExceptionManager.HandleEventException(this.ToString(),
  450. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  451. }
  452. }
  453. /// <summary>
  454. /// 点击关闭按钮
  455. /// </summary>
  456. /// <param name="sender"></param>
  457. /// <param name="e"></param>
  458. private void btnCancel_Click(object sender, EventArgs e)
  459. {
  460. this.Close();
  461. }
  462. /// <summary>
  463. /// 设置列表排序时的颜色
  464. /// </summary>
  465. private void dgvDataDefectPosition_Sorted(object sender, EventArgs e)
  466. {
  467. this.dgvDataDefect.IsSetInputColumnsColor = true;
  468. }
  469. #endregion
  470. #region 私有方法
  471. /// <summary>
  472. /// 加载缺陷位置数据
  473. /// </summary>
  474. /// <returns></returns>
  475. private DataSet GetDefectPositionData()
  476. {
  477. try
  478. {
  479. byte valueFlag = Convert.ToByte(chkDisplayDisabledData.Checked);
  480. DataSet dstemp = SystemModuleProxy.Service.GetDefectPositionData(valueFlag);
  481. return dstemp;
  482. }
  483. catch (Exception ex)
  484. {
  485. throw ex;
  486. }
  487. }
  488. /// <summary>
  489. /// 获取缺陷管理的全部数据
  490. /// </summary>
  491. /// <returns></returns>
  492. /// <remarks>
  493. /// 2016.06.22 王鑫 新建
  494. /// </remarks>
  495. private void GetAllSemicheckDefect()
  496. {
  497. try
  498. {
  499. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  500. {
  501. return SystemModuleProxy.Service.GetAllSemicheckDefect();
  502. }));
  503. this._dtSourse = dsResultAccount.Tables[0];
  504. }
  505. catch (Exception ex)
  506. {
  507. throw ex;
  508. }
  509. }
  510. /// <summary>
  511. /// 得到缺陷位置信息
  512. /// </summary>
  513. /// <returns></returns>
  514. private void RefreshDataGridViewData()
  515. {
  516. try
  517. {
  518. //如果checkbox未选中时标识符状态
  519. if (this.chkDisplayDisabledData.Checked == false)
  520. {
  521. this._dtSourse.DefaultView.RowFilter = "ValueFlag=1";
  522. }
  523. else
  524. {
  525. this._dtSourse.DefaultView.RowFilter = null;
  526. }
  527. this.dgvDataDefect.DataSource = this._dtSourse;
  528. this.btnSave.Enabled = false;
  529. }
  530. catch (Exception ex)
  531. {
  532. throw ex;
  533. }
  534. }
  535. /// <summary>
  536. /// 保存缺陷位置数据
  537. /// </summary>
  538. /// <returns>是否成功</returns>
  539. private object SaveSemicheckDefect()
  540. {
  541. try
  542. {
  543. // 获取当前datatJobsData数据源
  544. DataTable dataDefectData = (DataTable)this.dgvDataDefect.DataSource;
  545. int result = SystemModuleProxy.Service.SaveSemicheckDefect(dataDefectData);
  546. return result;
  547. }
  548. catch (Exception ex)
  549. {
  550. throw ex;
  551. }
  552. }
  553. /// <summary>
  554. /// 设置保存按钮的可用状态
  555. /// </summary>
  556. private void SetSaveBtnStatus()
  557. {
  558. if (DataJudge.IsChange((DataTable)this.dgvDataDefect.DataSource))
  559. {
  560. this.btnSave.Enabled = true;
  561. }
  562. else
  563. {
  564. this.btnSave.Enabled = false;
  565. }
  566. }
  567. /// <summary>
  568. /// 保存时单元格必输项不能为空
  569. /// </summary>
  570. private int Conservation()
  571. {
  572. int isConservation = Constant.INT_IS_ZERO;
  573. DataTable datatJobsData = (DataTable)this.dgvDataDefect.DataSource;
  574. foreach (DataRow drproductionData in datatJobsData.Rows)
  575. {
  576. //判断单元格必输项是否为空
  577. if (drproductionData["DefectCode"].ToString() == string.Empty)
  578. {
  579. isConservation = Constant.INT_IS_ONE;
  580. break;
  581. }
  582. if (drproductionData["DefectName"].ToString() == string.Empty)
  583. {
  584. isConservation = Constant.INT_IS_TWO;
  585. break;
  586. }
  587. }
  588. return isConservation;
  589. }
  590. #endregion
  591. }
  592. }