F_MST_0404.cs 23 KB

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