F_HR_0701.cs 19 KB

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