F_MST_0901.cs 23 KB

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