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.

200 lines
6.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.Sql;
  11. using System.Data.SqlClient;
  12. using ManagementSystem.Utility;
  13. namespace ManagementSystem
  14. {
  15. public partial class DayOffEstimate : Form
  16. {
  17. //程式內共用物件
  18. public string strFrmStatus = ""; //表單狀態
  19. public string strPKey = ""; //程式內的Key值
  20. string strKey = ""; //程式內加密的Key值
  21. string strActiveUserID = ""; //取得登入作用的使用者帳號
  22. string strAccountingBookID = ""; //取得作用中的帳本
  23. SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
  24. SqlTransaction sqlTran;
  25. SqlDataAdapter sqlAdapter = new SqlDataAdapter();
  26. SqlCommand sqlCmd = new SqlCommand();
  27. DataSet sdInsurance = new System.Data.DataSet();
  28. public DayOffEstimate()
  29. {
  30. InitializeComponent();
  31. }
  32. #region 自定義程式
  33. private void StatusChange(string strStatus) //變更主畫面狀態
  34. {
  35. strActiveUserID = MainForm.strActiveUserID;
  36. strAccountingBookID = MainForm.strAccountingBookID;
  37. strKey = MainForm.strKey;
  38. switch (strStatus.ToUpper())
  39. {
  40. case "NONE":
  41. //本功能無None狀態
  42. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "";
  43. strFrmStatus = "";
  44. CleanToolbar();
  45. CleanForm();
  46. LockForm();
  47. tsbSearch.Enabled = true;
  48. tsbOK.Visible = false;
  49. tsbCancel.Visible = false;
  50. break;
  51. case "SEARCH":
  52. //查詢功能
  53. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "搜尋";
  54. tsbSearch.Visible = false;
  55. tsbOK.Visible = true;
  56. tsbCancel.Visible = true;
  57. UnLockForm();
  58. break;
  59. case "ADD":
  60. //本程式無新增功能
  61. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "新增";
  62. strFrmStatus = "ADD";
  63. break;
  64. case "MODIFY":
  65. //本程式無修改功能
  66. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "修改";
  67. strFrmStatus = "MODIFY";
  68. break;
  69. case "DEL":
  70. //本程式無刪除功能
  71. ((MainForm)ParentForm).SsStatus.Items["tsslStatus"].Text = "刪除";
  72. strFrmStatus = "DEL";
  73. break;
  74. }
  75. }
  76. private void GoEvent() //執行動作
  77. {
  78. CleanForm();
  79. string strAskUser = "";
  80. double dcLeaveCount = 0.0;
  81. DateTime dtStartDate = DateTime.Now.AddMonths(-1).AddDays(-(DateTime.Now.AddMonths(-1).Day - 1));
  82. DateTime dtEndDate = dtStartDate.AddDays(DateTime.DaysInMonth(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month) - 1);
  83. StringBuilder sbSQL = new StringBuilder();
  84. sbSQL.Append("Select AskUser, LeaveDateStart, LeaveDateEnd, [Type],[dbo].OFN_SYS_ArgumentValueByArgumentID(Type,'LeaveType') AS TypeName ");
  85. sbSQL.Append("From OTB_HR_AskLeave Where 1=1 ");
  86. sbSQL.Append("And LeaveDateStart > Convert(datetime, '" + dtStartDate.ToShortDateString() + " 00:00:00AM') ");
  87. sbSQL.Append("And LeaveDateStart < Convert(datetime, '" + dtEndDate.ToShortDateString() + " 12:59:59PM') ");
  88. sbSQL.Append("Order by AskUser,LeaveDateStart ");
  89. //本程式只有查詢結果
  90. DataTable dtTemp = UtilityClass.GetSQLResult(sbSQL.ToString()).Tables["Result"];
  91. foreach (DataRow drData in dtTemp.Rows)
  92. {
  93. if (strAskUser != "")
  94. {
  95. }
  96. else
  97. {
  98. strAskUser = drData["AskUser"].ToString();
  99. //應該計算的內容:起啟日期在上月日期區間中,計算至上月月底 + 結束日期在上月日期區間中,計算至上月月底
  100. }
  101. }
  102. }
  103. private void CleanToolbar() //清除工具列
  104. {
  105. //設定Toolbar狀態
  106. tsbSearch.Visible = true;
  107. tsbAdd.Visible = false;
  108. tsbEdit.Visible = false;
  109. tsbDelete.Visible = false;
  110. tsbSave.Visible = false;
  111. tsbOK.Visible = false;
  112. tsbCancel.Visible = false;
  113. }
  114. private void LockForm() //鎖定物件
  115. {
  116. cbYear.Enabled = false;
  117. cbMonth.Enabled = false;
  118. }
  119. private void UnLockForm() //物件解鎖
  120. {
  121. cbYear.Enabled = true;
  122. cbMonth.Enabled = true;
  123. }
  124. private void CleanForm() //清除畫面
  125. {
  126. //設定畫面物件狀態
  127. string strYear = DateTime.Now.AddMonths(-1).Year.ToString();
  128. string strMonth = DateTime.Now.AddMonths(-1).Month.ToString();
  129. cbYear.Items.Clear();
  130. for (int intCount = DateTime.Now.Year; intCount >= DateTime.Now.AddYears(-4).Year; intCount--)
  131. {
  132. cbYear.Items.Add(intCount.ToString());
  133. }
  134. cbYear.SelectedItem = strYear;
  135. cbMonth.SelectedItem = strMonth;
  136. //清除GridView
  137. dgvDayOffList.Columns.Clear();
  138. }
  139. #endregion
  140. #region 事件觸發及問題處理
  141. private void DayOffEstimate_Load(object sender, EventArgs e)
  142. {
  143. StatusChange("NONE");
  144. }
  145. private void tsbSearch_Click(object sender, EventArgs e)
  146. {
  147. CleanForm();
  148. UnLockForm();
  149. tsbOK.Visible = true;
  150. tsbOK.Enabled = true;
  151. tsbCancel.Visible = true;
  152. tsbCancel.Enabled = true;
  153. StatusChange("SEARCH");
  154. }
  155. private void tsbClean_Click(object sender, EventArgs e)
  156. {
  157. CleanForm();
  158. }
  159. private void tsbOK_Click(object sender, EventArgs e)
  160. {
  161. GoEvent();
  162. StatusChange("NONE");
  163. }
  164. private void tsbCancel_Click(object sender, EventArgs e)
  165. {
  166. CleanToolbar();
  167. CleanForm();
  168. LockForm();
  169. }
  170. private void tsbExit_Click(object sender, EventArgs e)
  171. {
  172. this.Close();
  173. }
  174. #endregion
  175. }
  176. }