F_MST_0411.cs 21 KB

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