F_TAT_0702.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_TAT_0702.cs
  5. * 2.功能描述:管理岗位工资策略明细
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/11/18 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.Client.Controls;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.TATModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.TATModule
  22. {
  23. /// <summary>
  24. /// 管理岗位工资策略明细
  25. /// </summary>
  26. public partial class F_TAT_0702 : FormBase
  27. {
  28. #region 成员变量
  29. // 窗体模式ID
  30. private Constant.FormMode _formType;
  31. // 操作实体ID
  32. private int? _entityId;
  33. // 操作实体
  34. private ManagerSalaryEntity _msEntity = new ManagerSalaryEntity();
  35. // 选择窗体弹出标识
  36. private bool _showFromFlag = true;
  37. // 数据源
  38. private DataSet _dsSourse;
  39. // 窗体加载完毕标识
  40. private bool _pageLoadOK = false;
  41. #endregion
  42. #region 构造函数
  43. /// <summary>
  44. /// 窗体构造
  45. /// </summary>
  46. /// <param name="formType">窗体开启模式</param>
  47. /// <param name="entityId">操作实体ID</param>
  48. public F_TAT_0702(Constant.FormMode formType, int managerSalaryID)
  49. {
  50. InitializeComponent();
  51. this._formType = formType;
  52. this._entityId = managerSalaryID;
  53. // 窗口标题
  54. this.Text = FormTitles.F_TAT_0702;
  55. // 按钮
  56. this.btnSubmit.Text = ButtonText.BTN_SAVE;
  57. this.btnClose.Text = ButtonText.BTN_CANCEL;
  58. }
  59. #endregion
  60. #region 事件处理
  61. /// <summary>
  62. /// 窗体加载
  63. /// </summary>
  64. /// <param name="sender"></param>
  65. /// <param name="e"></param>
  66. private void F_TAT_0702_Load(object sender, EventArgs e)
  67. {
  68. try
  69. {
  70. BindManagerSalaryType();
  71. //无论如何先绑定工种,即使没有信息,也需要Table的结构
  72. this.dgvManagers.AutoGenerateColumns = false;
  73. this.BindManagers();
  74. //如果是编辑或审核模式,还要绑定主体信息
  75. if (this._formType == Constant.FormMode.Edit || this._formType == Constant.FormMode.Display)
  76. {
  77. this.BindPage();
  78. this.tsbtnOther.Visible = true;
  79. }
  80. else
  81. {
  82. //新建模式下是不可以进入明细的
  83. if (this._formType == Constant.FormMode.Add)
  84. {
  85. this.tsbtnOther.Visible = false;
  86. }
  87. else //复制模式不可编辑明细
  88. {
  89. this.dgvManagers.ReadOnly = true;
  90. this.dgvManagers.IsSetInputColumnsColor = false;
  91. this.dgvManagers.AllowUserToAddRows = false;
  92. }
  93. }
  94. //页面加载完毕
  95. this._pageLoadOK = true;
  96. //如果是审核及观看模式
  97. if (this._formType == Constant.FormMode.Display)
  98. {
  99. this.btnPass.Visible = true;
  100. this.btnReturn.Visible = true;
  101. //列表设置为只读
  102. this.dgvManagers.ReadOnly = true;
  103. this.dgvManagers.IsSetInputColumnsColor = false;
  104. this.dgvManagers.AllowUserToAddRows = false;
  105. this.dgvManagers.AllowUserToDeleteRows = false;
  106. //控件除关闭外全部不可用
  107. this.txtManagerSalaryName.Enabled = false;
  108. this.txtRemarks.Enabled = false;
  109. this.dtpStartTime.Enabled = false;
  110. this.btnSubmit.Enabled = false;
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. // 对异常进行共通处理
  116. ExceptionManager.HandleEventException(this.ToString(),
  117. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  118. }
  119. }
  120. /// <summary>
  121. /// 提交操作
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. private void btnSubmit_Click(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. int results = Conservation();
  130. if (results == Constant.INT_IS_ONE)
  131. {
  132. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工资类型"),
  133. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  134. return;
  135. }
  136. if (results == Constant.INT_IS_TWO)
  137. {
  138. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工资百分比"),
  139. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  140. return;
  141. }
  142. if (!ValidationInput())
  143. {
  144. return;
  145. }
  146. //获取页面值绑定属性
  147. this.BindEntity();
  148. //提交操作
  149. ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
  150. {
  151. return this.EntityToServer();
  152. });
  153. ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
  154. if (srEntity.Status == Constant.ServiceResultStatus.Success)
  155. {
  156. this.DialogResult = DialogResult.OK;
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. // 对异常进行共通处理
  162. ExceptionManager.HandleEventException(this.ToString(),
  163. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  164. }
  165. }
  166. /// <summary>
  167. /// 关闭窗体
  168. /// </summary>
  169. /// <param name="sender"></param>
  170. /// <param name="e"></param>
  171. private void btnClose_Click(object sender, EventArgs e)
  172. {
  173. this.Close();
  174. }
  175. /// <summary>
  176. /// 进入明细
  177. /// </summary>
  178. /// <param name="sender"></param>
  179. /// <param name="e"></param>
  180. private void tsbtnOther_Click(object sender, EventArgs e)
  181. {
  182. try
  183. {
  184. //获取当前行,如果不为空以及非新建行的话,就可以进入明细页面
  185. DataGridViewRow gvrNow = this.dgvManagers.CurrentRow;
  186. if (gvrNow != null && !gvrNow.IsNewRow)
  187. {
  188. //判断该行是否是新建行
  189. if (gvrNow.Cells["ManagersID"].Value != DBNull.Value)
  190. {
  191. //获取需要添加明细的信息ID
  192. int ManagersId = Convert.ToInt32(gvrNow.Cells["ManagersID"].Value);
  193. string StaffName = gvrNow.Cells["StaffName"].Value.ToString();
  194. string OrganizationName = gvrNow.Cells["OrganizationName"].Value.ToString();
  195. string PostName = gvrNow.Cells["PostName"].Value.ToString();
  196. //以编辑模式打开信息窗体
  197. F_TAT_0703 frmTAT0703
  198. = new F_TAT_0703(this._formType, Convert.ToInt32(this._msEntity.ManagerSalaryID), ManagersId, StaffName, OrganizationName, PostName);
  199. DialogResult dialogResult = frmTAT0703.ShowDialog();
  200. }
  201. else
  202. {
  203. //提示用户,该管理员信息暂未保存,不可创建组内成员
  204. MessageBox.Show(Messages.MSG_TAT_W002, this.Text,
  205. MessageBoxButtons.OK,
  206. MessageBoxIcon.Warning);
  207. }
  208. }
  209. else
  210. {
  211. //不可为空或选择新建行
  212. }
  213. }
  214. catch(Exception ex)
  215. {
  216. // 对异常进行共通处理
  217. ExceptionManager.HandleEventException(this.ToString(),
  218. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  219. }
  220. }
  221. /// <summary>
  222. /// 自适应列宽
  223. /// </summary>
  224. /// <param name="sender"></param>
  225. /// <param name="e"></param>
  226. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  227. {
  228. this.dgvManagers.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  229. }
  230. /// <summary>
  231. /// 单元格值改变
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. private void dgvManagers_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  236. {
  237. try
  238. {
  239. if (this.dgvManagers.Rows.Count <= Constant.INT_IS_ONE || !_showFromFlag)
  240. {
  241. return;
  242. }
  243. DataGridViewRow rowItem = this.dgvManagers.Rows[e.RowIndex];
  244. DataGridViewColumn columnItem = this.dgvManagers.Columns[e.ColumnIndex];
  245. if (columnItem.Name == "StaffCode")
  246. {
  247. int managerSalaryID = this._entityId == null ? 0 : Convert.ToInt32(this._entityId);
  248. _showFromFlag = false;
  249. FormUtility.BindManagerRowDataSource(this.dgvManagers,
  250. e.RowIndex, columnItem.Name, null, managerSalaryID, false);
  251. _showFromFlag = true;
  252. foreach (DataGridViewRow gvrFor in this.dgvManagers.Rows)
  253. {
  254. if (!gvrFor.IsNewRow && gvrFor.Cells["Manager"].Value != DBNull.Value)
  255. {
  256. gvrFor.Cells["StaffCode"].ReadOnly = true;
  257. gvrFor.Cells["SalaryType"].ReadOnly = false;
  258. gvrFor.Cells["SalaryPercent"].ReadOnly = false;
  259. }
  260. //如果是新行,不可录入工种以外的项
  261. if (gvrFor.IsNewRow)
  262. {
  263. gvrFor.Cells["SalaryType"].ReadOnly = true;
  264. gvrFor.Cells["SalaryPercent"].ReadOnly = true;
  265. gvrFor.Cells["StaffCode"].ReadOnly = false;
  266. }
  267. }
  268. this.dgvManagers.IsSetInputColumnsColor = true;
  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 btnPass_Click(object sender, EventArgs e)
  284. {
  285. //进行审核操作
  286. this._msEntity.AuditStatus = Convert.ToInt32(Constant.AuditStatus.Agree);
  287. ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
  288. {
  289. return EntityToServer();
  290. });
  291. //服务实体共通处理
  292. ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
  293. if (srEntity.Status == Constant.ServiceResultStatus.Success)
  294. {
  295. this.DialogResult = DialogResult.OK;
  296. }
  297. }
  298. /// <summary>
  299. /// 驳回审核
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void btnReturn_Click(object sender, EventArgs e)
  304. {
  305. //进行审核操作
  306. this._msEntity.AuditStatus = Convert.ToInt32(Constant.AuditStatus.Disagree);
  307. ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
  308. {
  309. return EntityToServer();
  310. });
  311. //服务实体共通处理
  312. ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
  313. if (srEntity.Status == Constant.ServiceResultStatus.Success)
  314. {
  315. this.DialogResult = DialogResult.OK;
  316. }
  317. }
  318. #endregion
  319. #region 私有方法/函数
  320. /// <summary>
  321. /// 绑定需要操作的实体信息
  322. /// </summary>
  323. private void BindPage()
  324. {
  325. try
  326. {
  327. if (this._entityId != 0 && this._entityId != null)
  328. {
  329. this._msEntity.ManagerSalaryID = this._entityId;
  330. //获取工价策略
  331. ServiceResultEntity srEntity
  332. = TATModuleProxy.Service.GetManagerSalary(_msEntity);
  333. //如果取出了对应的数据
  334. if (srEntity.Data != null && srEntity.Data.Tables.Count != 0
  335. && srEntity.Data.Tables[0].Rows.Count != 0)
  336. {
  337. //为实体及页面相关赋值
  338. DataSet dsEntityData = (DataSet)srEntity.Data;
  339. DataRow drEntityRow = dsEntityData.Tables[0].Rows[0];
  340. this.txtManagerSalaryName.Text = drEntityRow["ManagerSalaryName"].ToString();
  341. this.txtRemarks.Text = drEntityRow["Remarks"].ToString();
  342. this.dtpStartTime.Text = drEntityRow["BeginAccountMonth"].ToString();
  343. this._msEntity.BeginAccountMonth = Convert.ToDateTime(drEntityRow["BeginAccountMonth"].ToString());
  344. this._msEntity.OPTimeStamp = Convert.ToDateTime(drEntityRow["OPTimeStamp"]);
  345. }
  346. }
  347. }
  348. catch (Exception ex)
  349. {
  350. throw ex;
  351. }
  352. }
  353. /// <summary>
  354. /// 绑定策略类型
  355. /// </summary>
  356. private void BindManagerSalaryType()
  357. {
  358. try
  359. {
  360. //绑定策略类型
  361. DataTable dtSalaryType = new DataTable();
  362. dtSalaryType.Columns.Add("SalaryType");
  363. dtSalaryType.Columns.Add("SalaryTypeName");
  364. Type ManagerSalaryTypeEnum = typeof(Constant.ManagerSalaryType);
  365. Array ManagerSalaryTypeArray = Enum.GetValues(ManagerSalaryTypeEnum);
  366. for (int i = 0; i < Constant.ManagerSalaryTypeName.Length; i++)
  367. {
  368. dtSalaryType.Rows.Add(Convert.ToInt32(ManagerSalaryTypeArray.GetValue(i)), Constant.ManagerSalaryTypeName[i]);
  369. }
  370. this.SalaryType.DisplayMember = "SalaryTypeName";
  371. this.SalaryType.ValueMember = "SalaryType";
  372. this.SalaryType.DataSource = dtSalaryType;
  373. }
  374. catch(Exception ex)
  375. {
  376. throw ex;
  377. }
  378. }
  379. /// <summary>
  380. /// 绑定对应管理者信息
  381. /// </summary>
  382. private void BindManagers()
  383. {
  384. try
  385. {
  386. //获取对应管理者信息
  387. ServiceResultEntity srEntityDetail
  388. = TATModuleProxy.Service.GetManagersById(Convert.ToInt32(this._entityId));
  389. if (srEntityDetail.Data != null && srEntityDetail.Data.Tables.Count != 0)
  390. {
  391. this._dsSourse = srEntityDetail.Data;
  392. this.dgvManagers.DataSource = srEntityDetail.Data.Tables[0];
  393. //新行单元格可用性编辑
  394. DataGridViewRow gvrNew = this.dgvManagers.Rows[this.dgvManagers.NewRowIndex];
  395. gvrNew.Cells["StaffCode"].ReadOnly = false;
  396. gvrNew.Cells["SalaryType"].ReadOnly = true;
  397. gvrNew.Cells["SalaryPercent"].ReadOnly = true;
  398. this.dgvManagers.IsSetInputColumnsColor = true;
  399. }
  400. }
  401. catch (Exception ex)
  402. {
  403. throw ex;
  404. }
  405. }
  406. /// <summary>
  407. /// 与服务交互操作
  408. /// </summary>
  409. /// <returns></returns>
  410. private ServiceResultEntity EntityToServer()
  411. {
  412. if (this._formType == Constant.FormMode.Add)
  413. {
  414. return TATModuleProxy.Service.AddManagerSalary(this._msEntity, _dsSourse);
  415. }
  416. else if (this._formType == Constant.FormMode.Edit)
  417. {
  418. return TATModuleProxy.Service.EditManagerSalary(this._msEntity, _dsSourse);
  419. }
  420. else if (_formType == Constant.FormMode.CopyAndAdd)
  421. {
  422. this._msEntity.CopyId = Convert.ToInt32(this._entityId);
  423. return TATModuleProxy.Service.AddManagerSalary(this._msEntity, _dsSourse);
  424. }
  425. else if (_formType == Constant.FormMode.Display)
  426. {
  427. return TATModuleProxy.Service.AuditManagerSalary(this._msEntity);
  428. }
  429. return null;
  430. }
  431. /// <summary>
  432. /// 为实体绑定页面属性
  433. /// </summary>
  434. private void BindEntity()
  435. {
  436. this._msEntity.ManagerSalaryName = this.txtManagerSalaryName.Text.Trim();
  437. this._msEntity.BeginAccountMonth = this.dtpStartTime.Value.Date;
  438. this._msEntity.Remarks = this.txtRemarks.Text;
  439. this._msEntity.AuditStatus = 0;
  440. }
  441. /// <summary>
  442. /// 验证必填项
  443. /// </summary>
  444. /// <returns>是否通过</returns>
  445. private bool ValidationInput()
  446. {
  447. if (string.IsNullOrWhiteSpace(this.txtManagerSalaryName.Text))
  448. {
  449. this.txtManagerSalaryName.Focus();
  450. return false;
  451. }
  452. //循环列表,除新行外,工资类别和比例都不可为空
  453. foreach (DataGridViewRow gvrFor in this.dgvManagers.Rows)
  454. {
  455. if (gvrFor.IsNewRow)
  456. {
  457. break;
  458. }
  459. if (gvrFor.Cells["SalaryType"].Value == DBNull.Value ||
  460. gvrFor.Cells["SalaryPercent"].Value == DBNull.Value)
  461. {
  462. this.dgvManagers.Rows[gvrFor.Index].Selected = true;
  463. return false;
  464. }
  465. }
  466. return true;
  467. }
  468. /// <summary>
  469. /// 保存时单元格必输项不能为空
  470. /// </summary>
  471. private int Conservation()
  472. {
  473. int isConservation = Constant.INT_IS_ZERO;
  474. DataTable datatManagers = (DataTable)this.dgvManagers.DataSource;
  475. foreach (DataRow drproductionData in datatManagers.Rows)
  476. {
  477. if (drproductionData.RowState == DataRowState.Added || drproductionData.RowState == DataRowState.Modified)
  478. {
  479. if (drproductionData["SalaryType"].ToString() == "")
  480. {
  481. isConservation = Constant.INT_IS_ONE;
  482. break;
  483. }
  484. if (drproductionData["SalaryPercent"].ToString() == "")
  485. {
  486. isConservation = Constant.INT_IS_TWO;
  487. break;
  488. }
  489. }
  490. }
  491. return isConservation;
  492. }
  493. #endregion
  494. }
  495. }