F_MST_0410.cs 24 KB

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