F_HR_0501.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0501.cs
  5. * 2.功能描述:工种调整
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 冯雪 2014/09/13 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.Basics.DockPanel;
  16. using Dongke.IBOSS.PRD.Basics.Library;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.DataModels.HRModule;
  21. using Dongke.IBOSS.PRD.WCF.Proxys;
  22. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  23. namespace Dongke.IBOSS.PRD.Client.HRModule
  24. {
  25. /// <summary>
  26. /// 工种调整
  27. /// </summary>
  28. public partial class F_HR_0501 : DockPanelBase
  29. {
  30. #region 成员变量
  31. // 窗体的单例模式
  32. private static F_HR_0501 _instance;
  33. //选择的行
  34. private int _selectedRowIndex;
  35. // 查询条件实体
  36. private HR_CMN_StaffEntity _staffEntity = new HR_CMN_StaffEntity();
  37. //用户编辑的ID集合
  38. int[] _staffIDList;
  39. #endregion
  40. #region 构造函数
  41. /// <summary>
  42. /// 构造函数
  43. /// </summary>
  44. public F_HR_0501()
  45. {
  46. InitializeComponent();
  47. FormPermissionManager.FormPermissionControl(this.Name, this,
  48. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  49. this.SetFromTitleInfo();
  50. }
  51. #endregion
  52. #region 单例模式
  53. /// <summary>
  54. /// 单例模式,防止重复创建窗体
  55. /// </summary>
  56. public static F_HR_0501 Instance
  57. {
  58. get
  59. {
  60. if (_instance == null)
  61. {
  62. _instance = new F_HR_0501();
  63. }
  64. return _instance;
  65. }
  66. }
  67. #endregion
  68. #region 事件
  69. /// <summary>
  70. /// 页面加载事件
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void F_HR_0501_Load(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. FormPermissionManager.FormPermissionControl(this.Name, this,
  79. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  80. // 设置表格不自动创建列
  81. this.dgvStaffRecord.AutoGenerateColumns = false;
  82. // 设置ToolStripButton状态
  83. this.SetToolStripButtonEnable();
  84. this.tsbtnDisable.Visible = false;
  85. }
  86. catch (Exception ex)
  87. {
  88. // 对异常进行共通处理
  89. ExceptionManager.HandleEventException(this.ToString(),
  90. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  91. }
  92. }
  93. /// <summary>
  94. /// 窗体关闭事件
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void F_HR_0501_FormClosed(object sender, FormClosedEventArgs e)
  99. {
  100. _instance = null;
  101. }
  102. /// <summary>
  103. /// 行获取焦点后查看明细
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void dgvStaffRecord_CellEnter(object sender, DataGridViewCellEventArgs e)
  108. {
  109. try
  110. {
  111. if (this.dgvStaffRecord.CurrentCell != null)
  112. {
  113. // 记录最后选择行
  114. this._selectedRowIndex = this.dgvStaffRecord.CurrentCell.RowIndex;
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. // 对异常进行共通处理
  120. ExceptionManager.HandleEventException(this.ToString(),
  121. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  122. }
  123. }
  124. /// <summary>
  125. /// 更多条件按钮
  126. /// </summary>
  127. /// <param name="sender"></param>
  128. /// <param name="e"></param>
  129. private void tsbtnMoreCondition_Click(object sender, EventArgs e)
  130. {
  131. HR_CMN_001 frmCMN001 = new HR_CMN_001();
  132. frmCMN001.StaffEntity = this._staffEntity;
  133. if (frmCMN001.ShowDialog() == DialogResult.OK)
  134. {
  135. this.txtOther.Text = frmCMN001.StaffEntity.GetSqlDispText();
  136. this._staffEntity = frmCMN001.StaffEntity;
  137. }
  138. }
  139. /// <summary>
  140. /// 清空条件
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void btnClearCondition_Click(object sender, EventArgs e)
  145. {
  146. this.txtStaffCode.Clear();
  147. this.txtStaffName.Clear();
  148. this.txtOther.Clear();
  149. this._staffEntity.ClearEntityValue();
  150. }
  151. /// <summary>
  152. /// 关闭按钮事件
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. /// <param name="e"></param>
  156. private void tsbtnClose_Click(object sender, EventArgs e)
  157. {
  158. this.Close();
  159. }
  160. /// <summary>
  161. /// 自动适应列宽
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  166. {
  167. this.dgvStaffRecord.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  168. }
  169. /// <summary>
  170. /// 查询按钮
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void btnSearch_Click(object sender, EventArgs e)
  175. {
  176. try
  177. {
  178. this._staffIDList = null;
  179. // 记录当前选中行
  180. int selectRowIndex = this._selectedRowIndex;
  181. this.GetDataGridViewInfo();
  182. #region 选择原有行
  183. if (((DataTable)this.dgvStaffRecord.DataSource).Rows.Count <= Constant.INT_IS_ZERO)
  184. {
  185. // 提示未查找到数据
  186. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  187. MessageBoxButtons.OK, MessageBoxIcon.Information);
  188. }
  189. if (((DataTable)this.dgvStaffRecord.DataSource).Rows.Count > Constant.INT_IS_ZERO && selectRowIndex >= Constant.INT_IS_ZERO)
  190. {
  191. if (selectRowIndex >= ((DataTable)this.dgvStaffRecord.DataSource).Rows.Count)
  192. {
  193. this.dgvStaffRecord.Rows[this.dgvStaffRecord.Rows.Count - 1].Selected = true;
  194. this.dgvStaffRecord.CurrentCell = this.dgvStaffRecord.Rows[this.dgvStaffRecord.Rows.Count - 1].Cells["StaffCode"];
  195. }
  196. else
  197. {
  198. this.dgvStaffRecord.Rows[selectRowIndex].Selected = true;
  199. this.dgvStaffRecord.CurrentCell = this.dgvStaffRecord.Rows[selectRowIndex].Cells["StaffCode"];
  200. }
  201. }
  202. #endregion
  203. }
  204. catch (Exception ex)
  205. {
  206. // 对异常进行共通处理
  207. ExceptionManager.HandleEventException(this.ToString(),
  208. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  209. }
  210. }
  211. /// <summary>
  212. /// 添加按钮
  213. /// </summary>
  214. /// <param name="sender"></param>
  215. /// <param name="e"></param>
  216. private void tsbtnAdd_Click(object sender, EventArgs e)
  217. {
  218. try
  219. {
  220. F_HR_0502 frmHR0502 = new F_HR_0502(Constant.FormMode.Add, Constant.INT_IS_NEGATIE_ONE, Constant.INT_IS_NEGATIE_ONE);
  221. DialogResult dialogresult = frmHR0502.ShowDialog();
  222. if (dialogresult.Equals(DialogResult.OK))
  223. {
  224. this._staffIDList = frmHR0502.StaffIDList.ToArray();
  225. this.GetDataGridViewInfo();
  226. }
  227. }
  228. catch (Exception ex)
  229. {
  230. // 对异常进行共通处理
  231. ExceptionManager.HandleEventException(this.ToString(),
  232. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  233. }
  234. }
  235. /// <summary>
  236. /// 更新按钮
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void tsbtnEdit_Click(object sender, EventArgs e)
  241. {
  242. try
  243. {
  244. if (this.dgvStaffRecord.CurrentRow != null)
  245. {
  246. if (this.dgvStaffRecord.CurrentRow.Cells["ApprovalStatus"].Value == null || this.dgvStaffRecord.CurrentRow.Cells["RecordType"].Value == null)
  247. {
  248. // 不能进行修改
  249. MessageBox.Show(string.Format(Messages.MSG_HR_W005, "工种调整"),
  250. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  251. }
  252. string strApprovalStatus = this.dgvStaffRecord.CurrentRow.Cells["ApprovalStatus"].Value.ToString();
  253. string strRecordType = this.dgvStaffRecord.CurrentRow.Cells["RecordType"].Value.ToString();
  254. if (strApprovalStatus.Equals(Constant.ApprovalStatus.Pending.GetHashCode().ToString())
  255. && strRecordType.Equals(Constant.StaffRecordType.AdjustJob.GetHashCode().ToString()))
  256. {
  257. int intStaffID = Convert.ToInt32(this.dgvStaffRecord.CurrentRow.Cells["StaffID"].Value);
  258. int intStaffRecordID = Convert.ToInt32(this.dgvStaffRecord.CurrentRow.Cells["StaffRecordID"].Value);
  259. F_HR_0502 frmHR0502 = new F_HR_0502(Constant.FormMode.Edit, intStaffID, intStaffRecordID);
  260. DialogResult dialogresult = frmHR0502.ShowDialog();
  261. if (dialogresult.Equals(DialogResult.OK))
  262. {
  263. this._staffIDList = frmHR0502.StaffIDList.ToArray();
  264. this.GetDataGridViewInfo();
  265. }
  266. }
  267. else
  268. {
  269. // 不能进行修改
  270. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "已经审核过的数据不能编辑"),
  271. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  272. }
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. // 对异常进行共通处理
  278. ExceptionManager.HandleEventException(this.ToString(),
  279. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  280. }
  281. }
  282. /// <summary>
  283. /// 单元格鼠标双击事件
  284. /// </summary>
  285. /// <param name="sender"></param>
  286. /// <param name="e"></param>
  287. private void dgvStaffRecord_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  288. {
  289. if (Constant.INT_IS_NEGATIE_ONE < e.RowIndex && Constant.INT_IS_NEGATIE_ONE < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
  290. {
  291. this.tsbtnEdit_Click(sender, e);
  292. }
  293. }
  294. /// <summary>
  295. /// 停用按钮事件
  296. /// </summary>
  297. /// <param name="sender"></param>
  298. /// <param name="e"></param>
  299. private void tsbtnDisable_Click(object sender, EventArgs e)
  300. {
  301. try
  302. {
  303. if (this.dgvStaffRecord.SelectedRows.Count == Constant.INT_IS_ZERO)
  304. {
  305. return;
  306. }
  307. DialogResult msgBoxResult = MessageBox.Show(
  308. string.Format(Messages.MSG_CMN_Q002, "该工种调整申请", "停用"), this.Text,
  309. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  310. if (msgBoxResult == DialogResult.Yes)
  311. {
  312. int staffid = Convert.ToInt32(this.dgvStaffRecord.CurrentRow.Cells["StaffRecordID"].Value);
  313. HRResultEntity resultStaff = (HRResultEntity)DoAsync(() =>
  314. {
  315. return HRModuleProxy.Service.SetStaffRecordValueFlag(staffid);
  316. }
  317. );
  318. this.dgvStaffRecord.ReadOnly = true;
  319. // 修改成功
  320. if (resultStaff.OperateStatus > Constant.INT_IS_ZERO)
  321. {
  322. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "工种调整", "停用"),
  323. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  324. this.btnSearch_Click(sender, e);
  325. }
  326. else if (resultStaff.OperateStatus == Constant.INT_IS_NEGATIE_FIVE)
  327. {
  328. MessageBox.Show(Messages.MSG_HR_W002,
  329. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  330. }
  331. else
  332. {
  333. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "工种调整", "停用"),
  334. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  335. }
  336. }
  337. }
  338. catch (Exception ex)
  339. {
  340. // 对异常进行共通处理
  341. ExceptionManager.HandleEventException(this.ToString(),
  342. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  343. }
  344. }
  345. #endregion
  346. #region 私有方法
  347. /// <summary>
  348. /// 设置窗体按钮的文本信息
  349. /// </summary>
  350. private void SetFromTitleInfo()
  351. {
  352. this.tsrOperate.BackgroundImage = global::Dongke.IBOSS.PRD.Client.HRModule.Properties.Resources.functionbackground;
  353. this.tsrOperate.Height = 35;
  354. this.toolStripSeparator1.Height = 25;
  355. this.toolStripSeparator1.Width = 6;
  356. this.tsbtnAdd.Height = 25;
  357. this.tsbtnEdit.Height = 25;
  358. this.tsbtnDisable.Height = 25;
  359. this.tsbtnMoreCondition.Height = 25;
  360. this.tsbtnAdaptive.Height = 25;
  361. this.tsbtnClose.Height = 25;
  362. this.btnSearch.Height = 30;
  363. this.btnSearch.Width = 85;
  364. this.btnClearCondition.Height = 30;
  365. this.btnClearCondition.Width = 85;
  366. this.dgvStaffRecord.ColumnHeadersHeight = 23;
  367. this.dgvStaffRecord.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  368. this.dgvStaffRecord.AutoGenerateColumns = false;
  369. this.dgvStaffRecord.AutoGenerateColumns = false;
  370. this.Text = FormTitles.F_HR_0501;
  371. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  372. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  373. this.tsbtnDisable.Text = ButtonText.TSBTN_DISABLE;
  374. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  375. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  376. this.tsbtnMoreCondition.Text = ButtonText.TSBTN_MORECONDITION;
  377. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  378. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  379. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  380. }
  381. /// <summary>
  382. /// 设置工具按钮的可用状态
  383. /// </summary>
  384. /// <remarks>
  385. private void SetToolStripButtonEnable()
  386. {
  387. if (this.dgvStaffRecord.CurrentCell != null)
  388. {
  389. this.tsbtnEdit.Enabled = true;
  390. }
  391. else
  392. {
  393. this.tsbtnEdit.Enabled = false;
  394. }
  395. }
  396. /// <summary>
  397. /// 获取工种调整信息
  398. /// </summary>
  399. private void GetDataGridViewInfo()
  400. {
  401. try
  402. {
  403. SearchStaffEntity searchStaffEntity = new SearchStaffEntity();
  404. DataConvert.Convert(this._staffEntity, searchStaffEntity);
  405. searchStaffEntity.StaffCode = this.txtStaffCode.Text.Trim();
  406. searchStaffEntity.StaffName = this.txtStaffName.Text.Trim();
  407. searchStaffEntity.Recordtype = Convert.ToInt32(Constant.StaffRecordType.AdjustJob);
  408. searchStaffEntity.RValueflag = Convert.ToInt32(Constant.ValueFlag.Effective);
  409. if (this._staffIDList != null && this._staffIDList.Length > Constant.INT_IS_ZERO)
  410. {
  411. searchStaffEntity.RStaffRecordIDList = this._staffIDList;
  412. }
  413. //查询
  414. DataSet dsResult = (DataSet)DoAsync(new AsyncMethod(() =>
  415. {
  416. return WCF.Proxys.HRModuleProxy.Service.SearchHrStaffAndRecord(searchStaffEntity);
  417. }));
  418. if (dsResult != null && dsResult.Tables.Count > Constant.INT_IS_ZERO)
  419. {
  420. // 记录最后选择行
  421. int selectRowIndex = this._selectedRowIndex;
  422. this.dgvStaffRecord.DataSource = dsResult.Tables[0];
  423. if (dsResult.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  424. {
  425. // 定位当前行
  426. if (this.dgvStaffRecord.Rows.Count > selectRowIndex)
  427. {
  428. this._selectedRowIndex = selectRowIndex;
  429. this.dgvStaffRecord.Rows[selectRowIndex].Selected = true;
  430. }
  431. else if (this.dgvStaffRecord.Rows.Count <= selectRowIndex)
  432. {
  433. this._selectedRowIndex = dgvStaffRecord.Rows.Count - 1;
  434. this.dgvStaffRecord.Rows[dgvStaffRecord.Rows.Count - 1].Selected = true;
  435. }
  436. // 设置ToolStripButton按钮状态
  437. this.SetToolStripButtonEnable();
  438. this.dgvStaffRecord.ReadOnly = true;
  439. }
  440. }
  441. else
  442. {
  443. // 清空明细中的数据
  444. this.dgvStaffRecord.DataSource = null;
  445. // 提示未查找到数据
  446. MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  447. }
  448. }
  449. catch (Exception ex)
  450. {
  451. throw ex;
  452. }
  453. }
  454. #endregion
  455. }
  456. }