You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

851 lines
32 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.Sql;
  6. using System.Data.SqlClient;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using ManagementSystem.Utility;
  13. namespace ManagementSystem
  14. {
  15. public partial class HRMembers : Form
  16. {
  17. //程式內共用物件
  18. string strFrmStatus = ""; //表單狀態
  19. string strActiveUserID = ""; //取得登入作用的使用者帳號
  20. SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
  21. SqlCommand sqlCmd = new SqlCommand();
  22. string strPKey = ""; //程式內的Key值
  23. string strKey = ""; //程式內加密的Key值
  24. public HRMembers()
  25. {
  26. InitializeComponent();
  27. }
  28. #region 自定義程式
  29. private string CheckForm() //確認畫面必填欄位
  30. {
  31. string strResult = "";
  32. if (txtSID.Text.Trim() == "")
  33. {
  34. strResult = "請輸入身份證字號";
  35. txtSID.Focus();
  36. }
  37. if (cbHR_Class.SelectedValue.ToString().Trim() == "")
  38. {
  39. strResult = "請輸入人事類別";
  40. cbHR_Class.Focus();
  41. }
  42. if (cbDepartments.SelectedValue.ToString().Trim() == "")
  43. {
  44. strResult = "請輸入所屬部門";
  45. cbDepartments.Focus();
  46. }
  47. if (!UtilityClass.IsNumber(txtInsuranceSalary.Text.Trim()) & txtInsuranceSalary.Text.Trim() != "")
  48. {
  49. strResult = "只接受數值資料";
  50. txtInsuranceSalary.Focus();
  51. }
  52. if (!UtilityClass.IsNumber(txtSalary.Text.Trim()) & txtSalary.Text.Trim() != "")
  53. {
  54. strResult = "只接受數值資料";
  55. txtSalary.Focus();
  56. }
  57. if (!UtilityClass.IsNumber(txtBonus.Text.Trim()) & txtBonus.Text.Trim() != "")
  58. {
  59. strResult = "只接受數值資料";
  60. txtBonus.Focus();
  61. }
  62. if (!UtilityClass.IsNumber(txtSubsidy.Text.Trim()) & txtSubsidy.Text.Trim() != "")
  63. {
  64. strResult = "只接受數值資料";
  65. txtSubsidy.Focus();
  66. }
  67. return strResult;
  68. }
  69. private void SetupStatus() //畫面載入設定
  70. {
  71. try
  72. {
  73. strActiveUserID = MainForm.strActiveUserID;
  74. strKey = MainForm.strKey;
  75. if (MainForm.strKey == "")
  76. {
  77. //設定Toolbar初始狀態
  78. tsbSave.Enabled = false;
  79. tsbDelete.Enabled = false;
  80. }
  81. //設定畫面初始狀態
  82. CleanForm();
  83. CleanToolbar();
  84. LockForm();
  85. }
  86. catch (Exception ex)
  87. {
  88. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  89. }
  90. }
  91. private void GetMemberData(string strMemberID) //取得成員資料
  92. {
  93. try
  94. {
  95. string strInsuranceSalary = "";
  96. string strSalary = "";
  97. string strBonus = "";
  98. string strSubsidy = "";
  99. //排除空值
  100. if (strMemberID.Trim() == "")
  101. {
  102. return;
  103. }
  104. if (strMemberID == null)
  105. {
  106. return;
  107. }
  108. strPKey = strMemberID;
  109. StringBuilder strSQL = new StringBuilder("");
  110. strSQL.Append("Select M.MemberID, H.[SID], M.MemberName, M.DepartmentID,H.InsuranceSalary,H.CountSalary ,H.Salary,H.Bonus,H.Subsidy,H.HR_Class,M.Effective,M.ArriveDate,H.InsuranceLevel,isnull(M.LeaveDate, dateadd(YEAR,10,getdate())) as LeaveDate, H.Modify_Date, H.Modify_User ");
  111. strSQL.Append("From OTB_SYS_Members M Left Join OTB_HR_HRDetail H On M.MemberID = H.MemberID ");
  112. strSQL.Append("Where M.MemberID = '" + strPKey + "'");
  113. //進行查詢
  114. DataTable dtTemp = (DataTable)UtilityClass.GetSQLResult(strSQL.ToString()).Tables["Result"];
  115. //進行資料顯示
  116. strInsuranceSalary = UtilityClass.DecryptDES(dtTemp.Rows[0]["InsuranceSalary"].ToString(),strKey);
  117. strSalary = UtilityClass.DecryptDES(dtTemp.Rows[0]["Salary"].ToString(), strKey);
  118. strBonus = UtilityClass.DecryptDES(dtTemp.Rows[0]["Bonus"].ToString(),strKey);
  119. strSubsidy = UtilityClass.DecryptDES(dtTemp.Rows[0]["Subsidy"].ToString(), strKey);
  120. txtMemberID.Text = dtTemp.Rows[0]["MemberID"].ToString();
  121. txtSID.Text = dtTemp.Rows[0]["SID"].ToString();
  122. txtMemberName.Text = dtTemp.Rows[0]["MemberName"].ToString();
  123. cbCountSalary.Checked = dtTemp.Rows[0]["CountSalary"].ToString() == "Y" ? true : false;
  124. txtInsuranceSalary.Text = UtilityClass.MarkNumber(strInsuranceSalary);
  125. txtSalary.Text = UtilityClass.MarkNumber(strSalary);
  126. txtBonus.Text = UtilityClass.MarkNumber(strBonus);
  127. txtSubsidy.Text = UtilityClass.MarkNumber(strSubsidy);
  128. cbDepartments.SelectedValue = dtTemp.Rows[0]["DepartmentID"].ToString();
  129. cbHR_Class.SelectedValue = dtTemp.Rows[0]["HR_Class"].ToString();
  130. txtEffective.Text = dtTemp.Rows[0]["Effective"].ToString();
  131. dtpArriveDate.Text = dtTemp.Rows[0]["ArriveDate"].ToString();
  132. dtpLeaveDate.Text = dtTemp.Rows[0]["LeaveDate"].ToString();
  133. ((MainForm)ParentForm).SsStatus.Items["tsslModifyUser"].Text = dtTemp.Rows[0]["Modify_User"].ToString().Trim();
  134. ((MainForm)ParentForm).SsStatus.Items["tsslModifyDate"].Text = dtTemp.Rows[0]["Modify_Date"].ToString().Trim();
  135. txtInsuranceLevel.Text = dtTemp.Rows[0]["InsuranceLevel"].ToString();
  136. txtC_HealthInsuranceAmount.Text = "";
  137. txtS_HealthInsuranceAmount.Text = "";
  138. txtC_LaborProtection.Text = "";
  139. txtS_LaborProtection.Text = "";
  140. txtS_LaborProtection.Text = "";
  141. txtRetirementAmount.Text = "";
  142. SetInsurance();
  143. }
  144. catch (Exception ex)
  145. {
  146. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  147. }
  148. }
  149. private void LockForm() //限制唯讀物件
  150. {
  151. txtMemberID.ReadOnly = true;
  152. txtSID.ReadOnly = true;
  153. txtMemberName.ReadOnly = true;
  154. cbCountSalary.Enabled = false;
  155. txtInsuranceSalary.ReadOnly = true;
  156. txtSalary.ReadOnly = true;
  157. txtBonus.ReadOnly = true;
  158. txtSubsidy.ReadOnly = true;
  159. cbDepartments.Enabled = false;
  160. cbHR_Class.Enabled = false;
  161. txtEffective.ReadOnly = true;
  162. txtInsuranceLevel.ReadOnly = true;
  163. dtpArriveDate.Enabled = false;
  164. dtpLeaveDate.Enabled = false;
  165. }
  166. private void UnLockForm() //解除限制唯讀物件
  167. {
  168. txtMemberID.ReadOnly = false;
  169. txtSID.ReadOnly = false;
  170. txtMemberName.ReadOnly = false;
  171. cbCountSalary.Enabled = true;
  172. txtInsuranceSalary.ReadOnly = false;
  173. txtSalary.ReadOnly = false;
  174. txtBonus.ReadOnly = false;
  175. txtSubsidy.ReadOnly = false;
  176. cbDepartments.Enabled = true;
  177. cbHR_Class.Enabled = true;
  178. txtEffective.ReadOnly = false;
  179. txtInsuranceLevel.ReadOnly = false;
  180. dtpArriveDate.Enabled = false;
  181. dtpLeaveDate.Enabled = false;
  182. }
  183. private void StatusChange(string strStatus) //變更主畫面狀態
  184. {
  185. switch (strStatus.ToUpper())
  186. {
  187. case "NONE":
  188. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "";
  189. strFrmStatus = "";
  190. CleanForm();
  191. CleanToolbar();
  192. dgvHRItem.ReadOnly = false;
  193. break;
  194. case "SEARCH":
  195. tsbSearch.Visible = false;
  196. tsbEdit.Enabled = false;
  197. tsbDelete.Enabled = false;
  198. tsbOK.Visible = true;
  199. tsbCancel.Visible = true;
  200. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "搜尋";
  201. strFrmStatus = "SEARCH";
  202. break;
  203. case "ADD":
  204. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "新增";
  205. strFrmStatus = "ADD";
  206. break;
  207. case "MODIFY":
  208. tsbSearch.Enabled = false;
  209. tsbEdit.Visible = false;
  210. tsbSave.Visible = true;
  211. tsbDelete.Enabled = false;
  212. tsbCancel.Visible = true;
  213. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "修改";
  214. strFrmStatus = "MODIFY";
  215. break;
  216. case "DEL":
  217. tsbDelete.Visible = false;
  218. tsbSearch.Enabled = false;
  219. tsbEdit.Enabled = false;
  220. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "刪除";
  221. strFrmStatus = "DEL";
  222. break;
  223. }
  224. }
  225. private void CleanToolbar() //清除工具列
  226. {
  227. //設定Toolbar狀態
  228. tsbSearch.Enabled = true;
  229. tsbSearch.Visible = true;
  230. tsbEdit.Enabled = true;
  231. tsbEdit.Visible = true;
  232. tsbDelete.Enabled = true;
  233. tsbDelete.Visible = true;
  234. tsbSave.Visible = false;
  235. tsbOK.Visible = false;
  236. tsbCancel.Visible = false;
  237. }
  238. private void CleanForm() //清除畫面
  239. {
  240. //設定部門資料
  241. cbDepartments.DataSource = UtilityClass.GetOrganization().Tables[0];
  242. cbDepartments.ValueMember = "DepartmentID";
  243. cbDepartments.DisplayMember = "DepartmentName";
  244. //設定人事類別
  245. cbHR_Class.DataSource = UtilityClass.GetSystemArgument("HRClass", "zh-TW").Tables["Arguments"];
  246. cbHR_Class.DisplayMember = "ArgumentValue";
  247. cbHR_Class.ValueMember = "ArgumentID";
  248. //清除GridView
  249. string strSQL = "Select MemberID, MemberName, EMail From OTB_SYS_Members Where Effective='Y'";
  250. dgvHRItem.DataSource = UtilityClass.GetSQLResult(strSQL).Tables["Result"];
  251. //設定畫面物件狀態
  252. txtMemberID.Text = "";
  253. txtSID.Text = "";
  254. txtMemberName.Text = "";
  255. txtBonus.Text = "";
  256. cbCountSalary.Checked = false;
  257. txtInsuranceSalary.Text = "";
  258. txtSalary.Text = "";
  259. txtSubsidy.Text = "";
  260. txtEffective.Text = "";
  261. txtInsuranceLevel.Text = "";
  262. txtC_HealthInsuranceAmount.Text = "";
  263. txtS_HealthInsuranceAmount.Text = "";
  264. txtC_LaborProtection.Text = "";
  265. txtS_LaborProtection.Text = "";
  266. txtS_LaborProtection.Text = "";
  267. txtRetirementAmount.Text = "";
  268. cbDepartments.SelectedIndex = 0;
  269. cbHR_Class.SelectedIndex = 0;
  270. dtpLeaveDate.Value = DateTime.Now.AddYears(10);
  271. Application.DoEvents();
  272. }
  273. private void AddEven() //新增事件
  274. {
  275. try
  276. {
  277. //本功能無新增功能
  278. }
  279. catch (Exception ex)
  280. {
  281. throw ex;
  282. }
  283. }
  284. private void SaveEven() //儲存事件
  285. {
  286. //物件宣告
  287. string strInsuranceSalary = "";
  288. string strSalary = "";
  289. string strBonus = "";
  290. string strSubSidy = "";
  291. try
  292. {
  293. switch (strFrmStatus.ToString())
  294. {
  295. case "ADD": //新增(本功能不含新增功能)
  296. break;
  297. case "MODIFY": //修改
  298. StringBuilder sbSQL = new StringBuilder();
  299. StringBuilder sbCheckExsit = new StringBuilder();
  300. //確認資料是否存在
  301. sbCheckExsit.Append("Select * From OTB_HR_HRDetail Where MemberID = '" + strPKey + "'");
  302. if (UtilityClass.IsExist(sbCheckExsit.ToString()))
  303. {
  304. //資料存在,執行Update命令
  305. //執行命令
  306. sbSQL.Append("Update OTB_HR_HRDetail Set ");
  307. sbSQL.Append(" [SID] =@SID,");
  308. sbSQL.Append(" HR_Class = @HR_Class,");
  309. sbSQL.Append(" CountSalary = @CountSalary,");
  310. sbSQL.Append(" InsuranceSalary = @InsuranceSalary,");
  311. sbSQL.Append(" Salary = @Salary,");
  312. sbSQL.Append(" Bonus = @Bonus,");
  313. sbSQL.Append(" SubSidy = @SubSidy,");
  314. sbSQL.Append(" InsuranceLevel = @InsuranceLevel,");
  315. sbSQL.Append(" Modify_Date = GETDATE(), ");
  316. sbSQL.Append(" Modify_User = @Modify_User ");
  317. sbSQL.Append("Where MemberID = @MemberID");
  318. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
  319. {
  320. //物件處理
  321. strInsuranceSalary = txtInsuranceSalary.Text.Trim().Replace(",", "");
  322. strSalary = txtSalary.Text.Trim().Replace(",","");
  323. strBonus = txtBonus.Text.Trim().Replace(",","");
  324. strSubSidy = txtSubsidy.Text.Trim().Replace(",","");
  325. //添加參數
  326. sqlAdapter.UpdateCommand = new SqlCommand();
  327. sqlAdapter.UpdateCommand.Connection = sqlConn;
  328. sqlAdapter.UpdateCommand.CommandText = sbSQL.ToString();
  329. sqlAdapter.UpdateCommand.Parameters.AddRange
  330. (
  331. new SqlParameter[]
  332. {
  333. new SqlParameter("@MemberID",txtMemberID.Text.Trim()),
  334. new SqlParameter("@SID",txtSID.Text.Trim()),
  335. new SqlParameter("@HR_Class",cbHR_Class.SelectedValue.ToString()),
  336. new SqlParameter("@CountSalary",cbCountSalary.Checked ? "Y" : "N"),
  337. new SqlParameter("@InsuranceSalary",UtilityClass.EncryptDES(strInsuranceSalary,strKey)),
  338. new SqlParameter("@Salary",UtilityClass.EncryptDES(strSalary,strKey)),
  339. new SqlParameter("@Bonus",UtilityClass.EncryptDES(strBonus,strKey)),
  340. new SqlParameter("@SubSidy",UtilityClass.EncryptDES(strSubSidy,strKey)),
  341. new SqlParameter("@InsuranceLevel",Convert.ToInt32(txtInsuranceLevel.Text.Trim())),
  342. new SqlParameter("@Modify_User",strActiveUserID.ToString())
  343. }
  344. );
  345. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  346. {
  347. sqlConn.Open();
  348. }
  349. sqlAdapter.UpdateCommand.ExecuteNonQuery();
  350. }
  351. }
  352. else
  353. {
  354. //資料不存在,執行Insert命令
  355. //執行命令
  356. sbSQL.Append("Insert Into OTB_HR_HRDetail(MemberID, SID, HR_Class, CountSalary,InsuranceSalary, Salary, Bonus, SubSidy, InsuranceLevel, Create_Date, Create_User, Modify_Date, Modify_User) ");
  357. sbSQL.Append("Values(@MemberID, @SID, @HR_Class, @CountSalary,@InsuranceSalary, @Salary, @Bonus, @SubSidy, @InsuranceLevel, Getdate(), @Create_User, Getdate(), @Create_User)");
  358. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
  359. {
  360. //物件處理
  361. strInsuranceSalary = txtInsuranceSalary.Text.Trim().Replace(",", "");
  362. strSalary = txtSalary.Text.Trim().Replace(",", "");
  363. strBonus = txtBonus.Text.Trim().Replace(",", "");
  364. strSubSidy = txtSubsidy.Text.Trim().Replace(",", "");
  365. //添加參數
  366. sqlAdapter.InsertCommand = new SqlCommand();
  367. sqlAdapter.InsertCommand.Connection = sqlConn;
  368. sqlAdapter.InsertCommand.CommandText = sbSQL.ToString();
  369. sqlAdapter.InsertCommand.Parameters.AddRange
  370. (
  371. new SqlParameter[]
  372. {
  373. new SqlParameter("@MemberID",txtMemberID.Text.Trim()),
  374. new SqlParameter("@SID",txtSID.Text.Trim()),
  375. new SqlParameter("@HR_Class",cbHR_Class.SelectedValue.ToString()),
  376. new SqlParameter("@CountSalary",cbCountSalary.Checked ? "Y" : "N"),
  377. new SqlParameter("@InsuranceSalary",UtilityClass.EncryptDES(strInsuranceSalary,strKey)),
  378. new SqlParameter("@Salary",UtilityClass.EncryptDES(strSalary,strKey)),
  379. new SqlParameter("@Bonus",UtilityClass.EncryptDES(strBonus,strKey)),
  380. new SqlParameter("@SubSidy",UtilityClass.EncryptDES(strSubSidy,strKey)),
  381. new SqlParameter("@InsuranceLevel",Convert.ToInt32(txtInsuranceLevel.Text.Trim())),
  382. new SqlParameter("@Create_User",strActiveUserID.ToString())
  383. }
  384. );
  385. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  386. {
  387. sqlConn.Open();
  388. }
  389. sqlAdapter.InsertCommand.ExecuteNonQuery();
  390. }
  391. }
  392. break;
  393. }
  394. MessageBox.Show("儲存成功", "提示");
  395. dgvHRItem.ReadOnly = false;
  396. StatusChange("None");
  397. LockForm();
  398. }
  399. catch (Exception ex)
  400. {
  401. MessageBox.Show("儲存失敗","提示");
  402. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  403. }
  404. }
  405. private void DelEven() //刪除事件
  406. {
  407. StringBuilder sbSQL = new StringBuilder();
  408. try
  409. {
  410. //執行Delete命令
  411. //執行命令
  412. sbSQL.Append("Delete OTB_HR_HRDetail Where MemberID = @MemberID");
  413. using (SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID))
  414. {
  415. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
  416. {
  417. //添加參數
  418. sqlAdapter.DeleteCommand = new SqlCommand();
  419. sqlAdapter.DeleteCommand.Connection = sqlConn;
  420. sqlAdapter.DeleteCommand.CommandText = sbSQL.ToString();
  421. sqlAdapter.DeleteCommand.Parameters.AddRange
  422. (
  423. new SqlParameter[]
  424. {
  425. new SqlParameter("@MemberID",txtMemberID.Text.Trim()),
  426. }
  427. );
  428. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  429. {
  430. sqlConn.Open();
  431. }
  432. sqlAdapter.DeleteCommand.ExecuteNonQuery();
  433. GetMemberData(txtMemberID.Text.Trim()); //顯示該帳號的值到畫面上
  434. }
  435. }
  436. StatusChange("None");
  437. LockForm();
  438. }
  439. catch (Exception ex)
  440. {
  441. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  442. }
  443. }
  444. private void GoEvent() //執行事件
  445. {
  446. try
  447. {
  448. StringBuilder strSQL = new StringBuilder("");
  449. switch (strFrmStatus.ToString())
  450. {
  451. case "SEARCH": //搜尋
  452. strSQL.Append("Select M.MemberID, M.MemberName, M.Email ");
  453. strSQL.Append("From OTB_SYS_Members M Left Join OTB_HR_HRDetail H On M.MemberID = H.MemberID ");
  454. strSQL.Append("Where 1 = 1 ");
  455. if (txtMemberID.Text.Trim() != "") //人員帳號
  456. {
  457. strSQL.Append("And M.MemberID like '" + txtMemberID.Text.Trim() + "' ");
  458. }
  459. if (txtSID.Text.Trim() != "") //身份證字號
  460. {
  461. strSQL.Append("And H.SID like '" + txtSID.Text.Trim() + "' ");
  462. }
  463. if (txtMemberName.Text.Trim() != "") //人員姓名
  464. {
  465. strSQL.Append("And M.MemberName like '" + txtMemberName.Text.Trim() + "' ");
  466. }
  467. if (cbHR_Class.SelectedValue != null)
  468. {
  469. if (cbHR_Class.SelectedValue.ToString().Trim() != "")
  470. {
  471. strSQL.Append("And H.HR_Class = '" + cbHR_Class.SelectedValue.ToString() + "' ");
  472. }
  473. }
  474. if (txtEffective.Text.Trim() != "") //在職狀態
  475. {
  476. strSQL.Append("And M.Effective = '" + txtEffective.Text.Trim() + "' ");
  477. }
  478. if (cbDepartments.SelectedValue != null) //部門資料
  479. {
  480. if (cbDepartments.SelectedValue.ToString() != "")
  481. {
  482. strSQL.Append("And M.DepartmentID = '" + cbDepartments.SelectedValue.ToString() + "' ");
  483. }
  484. }
  485. //進行查詢
  486. dgvHRItem.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables[0];
  487. break;
  488. }
  489. StatusChange("None");
  490. LockForm();
  491. }
  492. catch (Exception ex)
  493. {
  494. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  495. }
  496. }
  497. private void SetInsurance() //取得勞、健保及勞退資料
  498. {
  499. try
  500. {
  501. string strInsuranceSalary = txtInsuranceSalary.Text.Trim().Replace(",","");
  502. string strInsruanceLevel = txtInsuranceLevel.Text.Trim();
  503. string[] strInsurances = new string[6];
  504. if (strInsruanceLevel != "")
  505. {
  506. if (UtilityClass.IsNumber(strInsruanceLevel))
  507. {
  508. strInsurances = UtilityClass.GetInsuranceByLevel(strInsruanceLevel);
  509. }
  510. else
  511. {
  512. return;
  513. }
  514. }
  515. else
  516. {
  517. if (UtilityClass.IsNumber(strInsuranceSalary) & (strInsuranceSalary != ""))
  518. {
  519. strInsurances = UtilityClass.GetInsurance(strInsuranceSalary);
  520. }
  521. else
  522. {
  523. return;
  524. }
  525. }
  526. txtInsuranceLevel.Text = UtilityClass.MarkNumber(strInsurances[0]); //投保級距
  527. txtC_LaborProtection.Text = UtilityClass.MarkNumber(strInsurances[1]); //公司提列勞保
  528. txtS_LaborProtection.Text = UtilityClass.MarkNumber(strInsurances[2]); //自行提列勞保
  529. txtC_HealthInsuranceAmount.Text = UtilityClass.MarkNumber(strInsurances[3]); //公司提列健保
  530. txtS_HealthInsuranceAmount.Text = UtilityClass.MarkNumber(strInsurances[4]); //自行提列健保
  531. txtRetirementAmount.Text = UtilityClass.MarkNumber(strInsurances[5]); //勞退金
  532. }
  533. catch (Exception ex)
  534. {
  535. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  536. }
  537. }
  538. #endregion
  539. #region 事件觸發及問題處理
  540. private void tsbAdd_Click(object sender, EventArgs e)
  541. {
  542. try
  543. {
  544. CleanToolbar();
  545. tsbSearch.Enabled = false;
  546. tsbEdit.Enabled = false;
  547. tsbSave.Visible = true;
  548. CleanForm();
  549. UnLockForm();
  550. StatusChange("ADD");
  551. }
  552. catch (Exception ex)
  553. {
  554. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  555. }
  556. }
  557. private void tsbEdit_Click(object sender, EventArgs e)
  558. {
  559. try
  560. {
  561. if (strPKey == "")
  562. {
  563. MessageBox.Show("請先選擇資料", "提示");
  564. return;
  565. }
  566. CleanToolbar();
  567. UnLockForm();
  568. txtMemberID.ReadOnly = true;
  569. txtMemberName.ReadOnly = true;
  570. cbDepartments.Enabled = false;
  571. txtEffective.ReadOnly = true;
  572. dtpArriveDate.Enabled = false;
  573. dtpLeaveDate.Enabled = false;
  574. dgvHRItem.ReadOnly = true;
  575. txtSID.Focus();
  576. StatusChange("Modify");
  577. }
  578. catch (Exception ex)
  579. {
  580. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  581. }
  582. }
  583. private void tsbSave_Click(object sender, EventArgs e)
  584. {
  585. try
  586. {
  587. string strMessage = CheckForm();
  588. if (strMessage == "")
  589. {
  590. this.SaveEven();
  591. GetMemberData(strPKey);
  592. }
  593. else
  594. {
  595. MessageBox.Show(strMessage,"提示");
  596. }
  597. }
  598. catch (Exception ex)
  599. {
  600. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  601. }
  602. }
  603. private void tsbDelete_Click(object sender, EventArgs e)
  604. {
  605. try
  606. {
  607. if (MessageBox.Show("請問您確定要刪除本資料?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  608. {
  609. this.DelEven();
  610. }
  611. }
  612. catch (Exception ex)
  613. {
  614. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  615. }
  616. }
  617. private void tsbSearch_Click(object sender, EventArgs e)
  618. {
  619. try
  620. {
  621. //設定Toolbar狀態
  622. CleanToolbar();
  623. //開放查詢條件
  624. UnLockForm();
  625. //設定畫面物件狀態
  626. CleanForm();
  627. txtMemberID.Focus();
  628. StatusChange("Search");
  629. }
  630. catch (Exception ex)
  631. {
  632. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  633. }
  634. }
  635. private void tsbOK_Click(object sender, EventArgs e)
  636. {
  637. try
  638. {
  639. GoEvent();
  640. //還原Toolbar狀態
  641. tsbSearch.Enabled = true;
  642. tsbOK.Visible = false;
  643. //關閉查詢條件
  644. LockForm();
  645. StatusChange("Search");
  646. }
  647. catch (Exception ex)
  648. {
  649. ErrorHandler.WriteErrorLog("HRMembers.cs", ex);
  650. }
  651. }
  652. private void tsbCancel_Click(object sender, EventArgs e)
  653. {
  654. CleanForm();
  655. CleanToolbar();
  656. LockForm();
  657. StatusChange("None");
  658. }
  659. private void HRMembers_Load(object sender, EventArgs e)
  660. {
  661. SetupStatus(); //設定畫面狀態
  662. }
  663. private void dgvHRItem_CellClick(object sender, DataGridViewCellEventArgs e)
  664. {
  665. GetMemberData(dgvHRItem.CurrentRow.Cells[0].Value.ToString()); //顯示該帳號的值到畫面上
  666. }
  667. private void dgvHRItem_CellEnter(object sender, DataGridViewCellEventArgs e)
  668. {
  669. GetMemberData(dgvHRItem.CurrentRow.Cells[0].Value.ToString()); //顯示該帳號的值到畫面上
  670. }
  671. private void txtSID_Leave(object sender, EventArgs e)
  672. {
  673. txtSID.Text = txtSID.Text.ToUpper();
  674. }
  675. private void txtEffective_Leave(object sender, EventArgs e)
  676. {
  677. txtEffective.Text = txtEffective.Text.ToUpper();
  678. }
  679. private void tsbExit_Click(object sender, EventArgs e)
  680. {
  681. this.Close();
  682. }
  683. private void txtSalary_Leave(object sender, EventArgs e)
  684. {
  685. txtSalary.Text = UtilityClass.MarkNumber(txtSalary.Text.Trim());
  686. }
  687. private void txtSalary_Enter(object sender, EventArgs e)
  688. {
  689. txtSalary.Text = txtSalary.Text.Replace(",", "");
  690. }
  691. private void txtBonus_Enter(object sender, EventArgs e)
  692. {
  693. txtBonus.Text = txtBonus.Text.Replace(",", "");
  694. }
  695. private void txtBonus_Leave(object sender, EventArgs e)
  696. {
  697. txtBonus.Text = UtilityClass.MarkNumber(txtBonus.Text.Trim());
  698. }
  699. private void txtSubsidy_Enter(object sender, EventArgs e)
  700. {
  701. txtSubsidy.Text = txtSubsidy.Text.Replace(",", "");
  702. }
  703. private void txtSubsidy_Leave(object sender, EventArgs e)
  704. {
  705. txtSubsidy.Text = UtilityClass.MarkNumber(txtSubsidy.Text.Trim());
  706. }
  707. private void txtInsuranceSalary_Leave(object sender, EventArgs e)
  708. {
  709. if ((strFrmStatus == "MODIFY" | strFrmStatus == "ADD") & txtInsuranceSalary.Text.Trim() != "")
  710. {
  711. SetInsurance();
  712. }
  713. txtInsuranceSalary.Text = UtilityClass.MarkNumber(txtInsuranceSalary.Text.Trim());
  714. }
  715. private void txtInsuranceSalary_Enter(object sender, EventArgs e)
  716. {
  717. txtInsuranceSalary.Text = txtInsuranceSalary.Text.Replace(",", "");
  718. }
  719. private void tsbClean_Click(object sender, EventArgs e)
  720. {
  721. CleanForm();
  722. }
  723. #endregion
  724. }
  725. }