F_MST_1002.cs 24 KB

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