F_MST_0403.cs 23 KB

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