Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

排班明細.vb 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. Option Strict Off
  2. Imports System.Drawing.Imaging
  3. Imports System.IO
  4. Public Class 排班明細
  5. ReadOnly ds, ds1 As New DataSet
  6. Dim X1, XX, XXX, AA As Double
  7. Dim Q, 開始位置1, 開始位置2, 標準長度, 行(20), 選擇項, 選擇處 As Integer
  8. Dim 開始使用 As Boolean = False
  9. Private Sub 讀取人員資料表()
  10. 人員_dgv.DataSource = Nothing : ds.Clear()
  11. 人員_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. 人員_dgv.ColumnHeadersHeight = 25 : 人員_dgv.AllowUserToAddRows = False
  13. If 全_ch.Checked = False Then
  14. SQL_排班系統_班別_人員()
  15. Else
  16. SQL_排班系統_班別_人員_全()
  17. End If
  18. da.Fill(ds) : 人員_dgv.DataSource = ds.Tables(0) : conn.Close()
  19. 人員_dgv.Columns(0).FillWeight = 70 : 人員_dgv.Columns(1).Visible = False : 人員_dgv.Columns(2).FillWeight = 100
  20. For i As Integer = 0 To 人員_dgv.Rows.Count - 1 : 人員_dgv.Rows(i).Cells("No.").Value = i + 1 : Next
  21. End Sub
  22. Private Sub 讀取排班資料表()
  23. 排班明細_dgv.DataSource = Nothing : ds1.Clear()
  24. 排班明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  25. 排班明細_dgv.ColumnHeadersHeight = 25: 排班明細_dgv.AllowUserToAddRows = False
  26. SQL_排班系統_班別_排班()
  27. da.Fill(ds1) : 排班明細_dgv.DataSource = ds1.Tables(0) : conn.Close()
  28. 排班明細_dgv.Sort(排班明細_dgv.Columns("項"), System.ComponentModel.ListSortDirection.Ascending)
  29. For i As Integer = 0 To 排班明細_dgv.Rows.Count - 1
  30. If IsDBNull(排班明細_dgv.Rows(i).Cells("請假類別").Value) = True Then
  31. 排班明細_dgv.Rows(i).Cells("請假類別").Value = ""
  32. End If
  33. If CInt(排班明細_dgv.Rows(i).Cells("項次").Value.ToString) < 10 Then
  34. 排班明細_dgv.Rows(i).Cells("項次").Value = ("0" & i + 1)
  35. Else : 排班明細_dgv.Rows(i).Cells("項次").Value = (i + 1) : End If
  36. Next
  37. End Sub
  38. Private Sub 班別_下拉表單資料載入()
  39. SQL_排班系統_班別_下拉()
  40. Dim cbList As ComboBox() = {班別_cb1, 班別_cb2, 班別_cb3, 班別_cb4, 班別_cb5, 班別_cb6, 班別_cb7, 班別_cb8, 班別_cb9, 班別_cb10, 班別_cb11, 班別_cb12, 班別_cb13, 班別_cb14, 班別_cb15,
  41. 班別_cb16, 班別_cb17, 班別_cb18, 班別_cb19, 班別_cb20} ' 將所有班別_cb放入陣列中
  42. For Each cb As ComboBox In cbList : cb.Items.Clear() : Next ' 清空每個 ComboBox 的項目
  43. While dr.Read() : For Each cb As ComboBox In cbList : cb.Items.Add(dr("時段")) : Next : End While : conn.Close() ' 讀取資料,將相同的時段加入所有 ComboBox
  44. End Sub
  45. Private Sub 職務_下拉表單資料載入()
  46. SQL_排班系統_職務_下拉()
  47. Dim cbList As ComboBox() = {ComboBox1, ComboBox2, ComboBox3, ComboBox4, ComboBox5, ComboBox6, ComboBox7, ComboBox8, ComboBox9, ComboBox10, ComboBox11, ComboBox12, ComboBox13,
  48. ComboBox14, ComboBox15, ComboBox16, ComboBox17, ComboBox18, ComboBox19, ComboBox20, ComboBox21, ComboBox22, ComboBox23, ComboBox24, ComboBox25,
  49. ComboBox26, ComboBox27, ComboBox28, ComboBox29, ComboBox30, ComboBox31, ComboBox32, ComboBox33, ComboBox34, ComboBox35, ComboBox36, ComboBox37,
  50. ComboBox38, ComboBox39, ComboBox40} ' 將所有 ComboBox 放入陣列中
  51. For Each cb As ComboBox In cbList : cb.Items.Clear() : Next ' 清除所有 ComboBox 的項目
  52. While dr.Read() : For Each cb As ComboBox In cbList : cb.Items.Add(dr("職務")) : Next : End While : conn.Close() ' 讀取資料,每一筆資料的 "職務" 加入到所有 ComboBox 中
  53. End Sub
  54. Private Sub 班表鎖定變化()
  55. If gUserName = "*系統管理者" Then 'Or gUserName = "蔡紋婷"
  56. 存檔_bt.Enabled = True : 人員_dgv.Enabled = True : 全_ch.Enabled = True
  57. For no As Integer = 1 To 20
  58. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  59. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  60. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  61. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  62. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  63. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  64. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  65. 姓名_tbS.Enabled = True : 班別_cbS.Enabled = True : CheckBoxS.Enabled = True : NumericUpDownS.Enabled = True : NUPS.Enabled = True : BUPS.Enabled = True
  66. Next
  67. Else
  68. If CC(17) = False Then
  69. 存檔_bt.Enabled = False : 人員_dgv.Enabled = False : 全_ch.Enabled = False
  70. For no As Integer = 1 To 20
  71. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  72. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  73. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  74. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  75. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  76. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  77. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  78. 姓名_tbS.Enabled = False : 班別_cbS.Enabled = False : CheckBoxS.Enabled = False : NumericUpDownS.Enabled = False : NUPS.Enabled = False : BUPS.Enabled = False
  79. Next
  80. Else
  81. 存檔_bt.Enabled = True : 人員_dgv.Enabled = True : 全_ch.Enabled = True
  82. For no As Integer = 1 To 20
  83. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  84. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  85. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  86. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  87. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  88. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  89. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  90. 姓名_tbS.Enabled = True : 班別_cbS.Enabled = True : CheckBoxS.Enabled = True : NumericUpDownS.Enabled = True : NUPS.Enabled = True : BUPS.Enabled = True
  91. Next
  92. End If
  93. End If
  94. End Sub
  95. Private Sub 進度條變化(ByVal index As Integer)
  96. If 開始使用 = True Then
  97. ' 根據 index 找到對應的控制項
  98. Dim 姓名_tb As TextBox = CType(Me.Controls.Find("姓名_tb" + index.ToString(), True)(0), TextBox)
  99. Dim 班別_cb As ComboBox = CType(Me.Controls.Find("班別_cb" + index.ToString(), True)(0), ComboBox)
  100. Dim numUD As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" & index.ToString(), True)(0), NumericUpDown)
  101. Dim bupUD As NumericUpDown = CType(Me.Controls.Find("BUP" & index.ToString(), True)(0), NumericUpDown)
  102. Dim chk As CheckBox = CType(Me.Controls.Find("CheckBox" & index.ToString(), True)(0), CheckBox)
  103. ' 假設第一組 ComboBox 的編號為 (index*2-1),第二組為 (index*2)
  104. Dim cbA As ComboBox = CType(Me.Controls.Find("ComboBox" & ((index * 2) - 1).ToString(), True)(0), ComboBox)
  105. Dim cbB As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2).ToString(), True)(0), ComboBox)
  106. If 姓名_tb.Text <> "" OrElse 班別_cb.Text <> "休" Then ' 只有當姓名不空或班別不為 "休" 時才處理
  107. Do2 = numUD.Value : 班條長度() ' 設定進度相關參數
  108. cbA.Size = New Size(標準長度 + XXX, 32) : cbB.Size = New Size(標準長度 - XXX, 25) ' 調整第一組 ComboBox 大小
  109. Do2 = bupUD.Value : 班條長度() : cbB.Size = New Size(cbB.Size.Width + XXX, 25) ' 根據 BUP 值調整第二組 ComboBox 大小
  110. Dim firstTwo As Integer = Val(Strings.Left(班別_cb.Text, 2)) ' 設定 cbB 是否顯示
  111. If chk.Checked = False AndAlso firstTwo < 17 Then : cbB.Visible = True : Else : cbB.Visible = False : End If ' 這裡先取得班別文字前兩個字轉成數值來比較
  112. End If
  113. End If
  114. End Sub
  115. Private Sub 休息變化(ByVal index As Integer)
  116. If 開始使用 = True Then
  117. ' 找到對應的控制項
  118. Dim 班別_cb As ComboBox = CType(Me.Controls.Find("班別_cb" & index.ToString(), True)(0), ComboBox)
  119. Dim NUP As NumericUpDown = CType(Me.Controls.Find("NUP" & index.ToString(), True)(0), NumericUpDown)
  120. Dim numUD As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" & index.ToString(), True)(0), NumericUpDown)
  121. Dim cbA As ComboBox = CType(Me.Controls.Find("ComboBox" & ((index * 2) - 1).ToString(), True)(0), ComboBox)
  122. Dim cbB As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2).ToString(), True)(0), ComboBox)
  123. XX = Val(Strings.Left(班別_cb.Text, 2)) * 60 + Val(Strings.Mid(班別_cb.Text, 4, 2)) : 班別圖示計算載入() ' 計算時間
  124. X1 = NUP.Value : 休息長度() : Do2 = numUD.Value : 班條長度() ' 設定長度與進度條
  125. cbA.Location = New Point(開始位置1 + XX, 行(index)) : cbB.Location = New Point(開始位置2 + XX + X1 + XXX, 行(index)) ' 設定 ComboBox 位置
  126. 進度條變化(index) ' 進度條變化
  127. End If
  128. End Sub
  129. Private Sub 半天變化(ByVal index As Integer)
  130. If 開始使用 = True Then
  131. Dim chk As CheckBox = CType(Me.Controls.Find("CheckBox" & index.ToString(), True)(0), CheckBox)
  132. Dim cbA As ComboBox = CType(Me.Controls.Find("ComboBox" & ((index * 2) - 1).ToString(), True)(0), ComboBox)
  133. Dim cbB As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2).ToString(), True)(0), ComboBox)
  134. If chk IsNot Nothing AndAlso cbA IsNot Nothing AndAlso cbB IsNot Nothing Then : cbA.Visible = True : cbB.Visible = Not chk.Checked : End If
  135. End If
  136. End Sub
  137. Private Sub 回復預設()
  138. For no As Integer = 1 To 20 : Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown) : NUPS.Value = 1 : Next
  139. XX = 0 : Q = 0
  140. For no As Integer = 1 To 20
  141. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  142. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  143. Dim ComboBoxsS1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + Q).ToString(), True)(0), ComboBox)
  144. Dim ComboBoxsS2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + 1 + Q).ToString(), True)(0), ComboBox)
  145. Dim ComboBoxs1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + Q).ToString(), True)(0), ComboBox)
  146. Dim ComboBoxs2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 1 + Q).ToString(), True)(0), ComboBox)
  147. 姓名_tbS.Text = "" : 班別_cbS.Text = "休" : ComboBoxsS1.SelectedIndex = 0 : ComboBoxsS2.SelectedIndex = 0
  148. If 姓名_tbS.Text = "" Then : ComboBoxs1.Visible = False : ComboBoxs2.Visible = False
  149. Else : ComboBoxs1.Visible = True : ComboBoxs2.Visible = True : End If
  150. Next
  151. For i As Integer = 1 To 20
  152. ' 第一欄:奇數的 ComboBox
  153. Dim cb1Name As String = "ComboBox" & ((i * 2) - 1).ToString() : Dim cb1 As ComboBox = TryCast(Me.Controls(cb1Name), ComboBox)
  154. If cb1 IsNot Nothing Then : cb1.Location = New Point(開始位置1 + XX, 行(i)) : End If
  155. ' 第二欄:偶數的 ComboBox
  156. Dim cb2Name As String = "ComboBox" & (i * 2).ToString() : Dim cb2 As ComboBox = TryCast(Me.Controls(cb2Name), ComboBox)
  157. If cb2 IsNot Nothing Then : cb2.Location = New Point(開始位置2 + XX, 行(i)) : End If
  158. Next
  159. End Sub
  160. Private Sub 重新讀取()
  161. SQL_排班簽核讀取()
  162. If dr.Read Then
  163. 值日生1_bt.Text = dr("值日生1").ToString : 值日生2_bt.Text = dr("值日生2").ToString
  164. If dr("位置1").ToString = "" Then : 紅1_nud.Value = 8 : Else : 紅1_nud.Value = dr("位置1").ToString : End If
  165. If dr("面積1").ToString = "" Then : 面1_nud.Value = 0 : Else : 面1_nud.Value = dr("面積1").ToString : End If
  166. If dr("位置2").ToString = "" Then : 紅2_nud.Value = 8 : Else : 紅2_nud.Value = dr("位置2").ToString : End If
  167. If dr("面積2").ToString = "" Then : 面2_nud.Value = 0 : Else : 面2_nud.Value = dr("面積2").ToString : End If
  168. If dr("位置3").ToString = "" Then : 紅3_nud.Value = 8 : Else : 紅3_nud.Value = dr("位置3").ToString : End If
  169. If dr("面積3").ToString = "" Then : 面3_nud.Value = 0 : Else : 面3_nud.Value = dr("面積3").ToString : End If
  170. If dr("位置4").ToString = "" Then : 紅4_nud.Value = 8 : Else : 紅4_nud.Value = dr("位置4").ToString : End If
  171. If dr("面積4").ToString = "" Then : 面4_nud.Value = 0 : Else : 面4_nud.Value = dr("面積4").ToString : End If
  172. If dr("班表簽認") = "Y" Then : 鎖定_bt.Enabled = False : Else : 鎖定_bt.Enabled = True : End If : Else : 鎖定_bt.Enabled = True
  173. End If
  174. 班表鎖定變化()
  175. SQL_排班系統_星期() : If dr.Read Then : 星期_lb.Text = dr("星期") : End If : PA6 = 星期_lb.Text
  176. SQL_門診_健保()
  177. If dr.Read Then : B1_lb.Text = dr("早") : B2_lb.Text = dr("中") : B3_lb.Text = dr("晚") : Else : B1_lb.Text = "" : B2_lb.Text = "" : B3_lb.Text = "" : End If
  178. SQL_門診_美容()
  179. If dr.Read Then : B4_lb.Text = dr("早") : B5_lb.Text = dr("中") : B6_lb.Text = dr("晚") : Else : B4_lb.Text = "" : B5_lb.Text = "" : B6_lb.Text = "" : End If
  180. 讀取排班資料表() : 排班()
  181. End Sub
  182. Private Sub 排班()
  183. If 排班明細_dgv.Rows.Count > 0 Then
  184. Q = 0
  185. For no As Integer = 1 To 20
  186. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  187. Dim 請假_tbS As TextBox = CType(Me.Controls.Find("請假_tb" + no.ToString(), True)(0), TextBox)
  188. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  189. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  190. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  191. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  192. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  193. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  194. Dim ComboBoxsS1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + Q).ToString(), True)(0), ComboBox)
  195. Dim ComboBoxsS2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + 1 + Q).ToString(), True)(0), ComboBox)
  196. Dim ComboBoxs1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + Q).ToString(), True)(0), ComboBox)
  197. Dim ComboBoxs2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 1 + Q).ToString(), True)(0), ComboBox) : Q += 1
  198. ComboBoxs1.Text = 排班明細_dgv.Rows(no - 1).Cells("一段").Value
  199. ComboBoxs2.Text = 排班明細_dgv.Rows(no - 1).Cells("二段").Value
  200. ComboBoxsS1.Text = 排班明細_dgv.Rows(no - 1).Cells("顏色1").Value
  201. ComboBoxsS2.Text = 排班明細_dgv.Rows(no - 1).Cells("顏色2").Value
  202. NUPS.Value = 排班明細_dgv.Rows(no - 1).Cells("休息").Value
  203. BUPS.Value = 排班明細_dgv.Rows(no - 1).Cells("後段").Value
  204. NumericUpDownS.Value = 排班明細_dgv.Rows(no - 1).Cells("時數").Value
  205. CheckBoxS.Checked = 排班明細_dgv.Rows(no - 1).Cells("半天").Value
  206. 班別_cbS.Text = 排班明細_dgv.Rows(no - 1).Cells("班別").Value.ToString
  207. 姓名_tbS.Text = 排班明細_dgv.Rows(no - 1).Cells("姓名").Value.ToString
  208. 請假_tbS.Text = 排班明細_dgv.Rows(no - 1).Cells("請假類別").Value.ToString
  209. ComboBoxs1.SelectionLength = 0 : ComboBoxs2.SelectionLength = 0
  210. Next
  211. End If
  212. End Sub
  213. Private Sub 班別圖示計算載入()
  214. XX = (XX - 480) * 1.25
  215. End Sub
  216. Private Sub 班條長度()
  217. Dim 小時 As Double = 75
  218. If Do2 = 4 Then : XXX = 0 : ElseIf Do2 = 1 Then : XXX = -(小時 * 3) : ElseIf Do2 = 1.5 Then : XXX = -(小時 * 2.5)
  219. ElseIf Do2 = 2 Then : XXX = -(小時 * 2) : ElseIf Do2 = 2.5 Then : XXX = -(小時) + (-(小時 / 2)) : ElseIf Do2 = 3 Then : XXX = -(小時) : ElseIf Do2 = 3.5 Then : XXX = -(小時 / 2)
  220. ElseIf Do2 = 4.5 Then : XXX = 小時 / 2 : ElseIf Do2 = 5 Then : XXX = 小時 : ElseIf Do2 = 5.5 Then : XXX = 小時 + (小時 / 2) : ElseIf Do2 = 6 Then : XXX = 小時 * 2
  221. ElseIf Do2 = 6.5 Then : XXX = 小時 * 2.5 : ElseIf Do2 = 7 Then : XXX = 小時 * 3 : ElseIf Do2 = 7.5 Then : XXX = 小時 * 3.5 : ElseIf Do2 = 8 Then : XXX = 小時 * 4 : End If
  222. End Sub
  223. Private Sub 休息長度()
  224. X1 = (X1 - 1) * 8 * 10
  225. End Sub
  226. ' 定義顏色對應的陣列
  227. Private ReadOnly colors As Color() = {
  228. Color.LawnGreen, Color.LightBlue, Color.LightCoral, Color.LightCyan,
  229. Color.LightGoldenrodYellow, Color.LightGray, Color.LightGreen, Color.LightPink,
  230. Color.LightSalmon, Color.Gray
  231. }
  232. Private Sub 排班明細_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  233. '--------------初始設定---------------------------
  234. For i As Integer = 41 To 80 ' 動態綁定 ComboBox41~ComboBox80 的 SelectedIndexChanged 事件
  235. Dim cb As ComboBox = CType(Me.Controls("ComboBox" & i), ComboBox)
  236. If cb IsNot Nothing Then : AddHandler cb.SelectedIndexChanged, AddressOf ComboBox_SelectedIndexChanged : End If
  237. Next
  238. For i As Integer = 1 To 20
  239. Dim nup As NumericUpDown = CType(Me.Controls("NUP" & i), NumericUpDown) : Dim cb As ComboBox = CType(Me.Controls("班別_cb" & i), ComboBox)
  240. If nup IsNot Nothing AndAlso cb IsNot Nothing Then : nup.Tag = i : AddHandler nup.ValueChanged, AddressOf NUP_ValueChanged : End If
  241. Next
  242. For i As Integer = 1 To 20
  243. Dim tb As TextBox = CType(Me.Controls("姓名_tb" & i), TextBox) : AddHandler tb.Click, AddressOf 姓名_tb_Click
  244. Next
  245. For i As Integer = 1 To 20
  246. Dim chk As CheckBox = CType(Me.Controls("CheckBox" & i), CheckBox) : AddHandler chk.CheckedChanged, AddressOf CheckBox_CheckedChanged
  247. Next
  248. For i As Integer = 1 To 20
  249. Dim numUpDown As NumericUpDown = CType(Me.Controls("NumericUpDown" & i), NumericUpDown)
  250. If numUpDown IsNot Nothing Then : numUpDown.Tag = i : AddHandler numUpDown.ValueChanged, AddressOf NumericUpDown_ValueChanged : End If
  251. Next
  252. For i As Integer = 1 To 20
  253. Dim num As Integer = i : Dim bup As NumericUpDown = CType(Me.Controls("BUP" & num), NumericUpDown) : AddHandler bup.ValueChanged, Sub() 進度條變化檢查(num)
  254. Next
  255. For i As Integer = 1 To 4
  256. Dim num As Integer = i : Dim nud As NumericUpDown = CType(Me.Controls("紅" & num & "_nud"), NumericUpDown) : AddHandler nud.ValueChanged, Sub() 更新紅點位置(num)
  257. Next
  258. '--------------坐標系設定---------------------------
  259. 開始位置1 = 592 : 開始位置2 = 967 : 行(0) = 27 : 標準長度 = 297
  260. 行(1) = 108 : 行(2) = 行(1) + 行(0) : 行(3) = 行(2) + 行(0) : 行(4) = 行(3) + 行(0) : 行(5) = 行(4) + 行(0) : 行(6) = 行(5) + 行(0) : 行(7) = 行(6) + 行(0) : 行(8) = 行(7) + 行(0)
  261. 行(9) = 行(8) + 行(0) : 行(10) = 行(9) + 行(0) : 行(11) = 行(10) + 行(0) : 行(12) = 行(11) + 行(0) : 行(13) = 行(12) + 行(0) : 行(14) = 行(13) + 行(0) : 行(15) = 行(14) + 行(0)
  262. 行(16) = 行(15) + 行(0) : 行(17) = 行(16) + 行(0) : 行(18) = 行(17) + 行(0) : 行(19) = 行(18) + 行(0) : 行(20) = 行(19) + 行(0)
  263. '--------------複製權限---------------------------
  264. 開始使用 = True
  265. If gUserName = "*系統管理者" Then : 存檔_bt.Enabled = True : 複製班表_bt.Enabled = True : 人員_dgv.Enabled = True : 全_ch.Enabled = True : 備註存檔_tb.Enabled = True
  266. For no As Integer = 1 To 20
  267. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  268. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  269. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  270. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  271. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  272. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  273. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  274. 姓名_tbS.Enabled = True : 班別_cbS.Enabled = True : CheckBoxS.Enabled = True : NumericUpDownS.Enabled = True : NUPS.Enabled = True : BUPS.Enabled = True
  275. Next
  276. Else
  277. If CC(17) = False Then : 存檔_bt.Enabled = False : 複製班表_bt.Enabled = False : 人員_dgv.Enabled = False : 全_ch.Enabled = False : 備註存檔_tb.Enabled = False
  278. For no As Integer = 1 To 20
  279. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  280. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  281. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  282. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  283. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  284. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  285. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  286. 姓名_tbS.Enabled = False : 班別_cbS.Enabled = False : CheckBoxS.Enabled = False : NumericUpDownS.Enabled = False : NUPS.Enabled = False : BUPS.Enabled = False
  287. Next
  288. Else : 存檔_bt.Enabled = True : 複製班表_bt.Enabled = True : 人員_dgv.Enabled = True : 全_ch.Enabled = True : 備註存檔_tb.Enabled = True
  289. For no As Integer = 1 To 20
  290. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  291. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  292. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  293. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  294. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  295. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  296. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  297. 姓名_tbS.Enabled = True : 班別_cbS.Enabled = True : CheckBoxS.Enabled = True : NumericUpDownS.Enabled = True : NUPS.Enabled = True : BUPS.Enabled = True
  298. Next
  299. End If
  300. End If : 年_lb.Text = PA : 月_lb.Text = PA1
  301. End Sub
  302. Private Sub 排班明細_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
  303. 班別_下拉表單資料載入() : 職務_下拉表單資料載入() : 讀取人員資料表() : If Val(PA2) > 9 Then : 日_lb.Text = PA2 : Else : 日_lb.Text = "0" & PA2 : End If : 回復預設()
  304. 年_cb.Text = 年_lb.Text : 月_cb.Text = 月_lb.Text : 日_cb.Text = 日_lb.Text : PA = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text : 重新讀取()
  305. End Sub
  306. Private Sub 設定尺寸(面_nud As NumericUpDown, 紅_pb As PictureBox)
  307. Dim 欄距 As Double = 37.5 : 紅_pb.Size = New Size(欄距 * (面_nud.Value * 2), 544) ' 根據數值設定尺寸
  308. If 面_nud.Value = 0 Then : 紅_pb.Size = New Size(3, 544) : End If ' 當值為0時,寬度設為 3
  309. End Sub
  310. Private Sub 面1_nud_ValueChanged(sender As Object, e As EventArgs) Handles 面1_nud.ValueChanged
  311. 設定尺寸(面1_nud, 紅1_pb)
  312. End Sub
  313. Private Sub 面2_nud_ValueChanged(sender As Object, e As EventArgs) Handles 面2_nud.ValueChanged
  314. 設定尺寸(面2_nud, 紅2_pb)
  315. End Sub
  316. Private Sub 面3_nud_ValueChanged(sender As Object, e As EventArgs) Handles 面3_nud.ValueChanged
  317. 設定尺寸(面3_nud, 紅3_pb)
  318. End Sub
  319. Private Sub 面4_nud_ValueChanged(sender As Object, e As EventArgs) Handles 面4_nud.ValueChanged
  320. 設定尺寸(面4_nud, 紅4_pb)
  321. End Sub
  322. ' 共用的事件處理函數
  323. Private Sub 更新紅點位置(index As Integer)
  324. Dim 欄距 As Double = 37.5 : Dim 起始值 As Decimal = 8D : Dim nud As NumericUpDown = CType(Me.Controls("紅" & index & "_nud"), NumericUpDown)
  325. Dim pb As PictureBox = CType(Me.Controls("紅" & index & "_pb"), PictureBox) : Dim AXX As Double = 590 + (欄距 * CInt((nud.Value - 起始值) * 2))
  326. pb.Location = New Point(AXX, 105) : pb.Visible = (nud.Value <> 8)
  327. End Sub
  328. Private Sub 進度條變化檢查(index As Integer)
  329. Dim 班別_cb As ComboBox = CType(Me.Controls("班別_cb" & index), ComboBox) : If 班別_cb.Text <> "休" Then 進度條變化(index)
  330. End Sub
  331. Private Sub NumericUpDown_ValueChanged(sender As Object, e As EventArgs)
  332. Dim numUpDown As NumericUpDown = CType(sender, NumericUpDown) : Dim index As Integer = CInt(numUpDown.Tag)
  333. Dim comboBox As ComboBox = CType(Me.Controls("班別_cb" & index), ComboBox)
  334. If comboBox IsNot Nothing AndAlso comboBox.Text <> "休" Then : 休息變化(index) : End If ' 只有當對應的 ComboBox 不是 "休" 時才執行
  335. End Sub
  336. Private Sub CheckBox_CheckedChanged(sender As Object, e As EventArgs)
  337. Dim chk As CheckBox = CType(sender, CheckBox) : Dim index As Integer = Integer.Parse(chk.Name.Replace("CheckBox", "")) ' 取得數字部分
  338. Dim cb As ComboBox = CType(Me.Controls("班別_cb" & index), ComboBox) : If cb.Text <> "休" Then : 休息變化(index) : End If
  339. End Sub
  340. Private Sub 姓名_tb_Click(sender As Object, e As EventArgs)
  341. Dim tb As TextBox = DirectCast(sender, TextBox) : Dim index As Integer = Integer.Parse(tb.Name.Replace("姓名_tb", "")) : 選擇項 = index ' 取得數字部分
  342. For i As Integer = 0 To 人員_dgv.Rows.Count - 1
  343. If tb.Text = 人員_dgv.Rows(i).Cells("姓名").Value.ToString Then : 選擇處 = i : 人員資料讀取() : Exit For : End If ' 找到就退出迴圈,提高效能
  344. Next
  345. End Sub
  346. Private Sub NUP_ValueChanged(sender As Object, e As EventArgs)
  347. Dim nup As NumericUpDown = CType(sender, NumericUpDown) : Dim index As Integer = CInt(nup.Tag)
  348. Dim 班別_cb As ComboBox = CType(Me.Controls.Find("班別_cb" & index, True)(0), ComboBox)
  349. Dim cb1 As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2 - 1), True)(0), ComboBox)
  350. Dim cb2 As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2), True)(0), ComboBox)
  351. If 班別_cb IsNot Nothing AndAlso 班別_cb.Text <> "休" Then : 休息變化(index) : 半天變化(index)
  352. Else : If cb1 IsNot Nothing Then cb1.Visible = False : If cb2 IsNot Nothing Then cb2.Visible = False
  353. End If
  354. End Sub
  355. Private Sub ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
  356. Dim cb As ComboBox = CType(sender, ComboBox) : Dim index As Integer = cb.SelectedIndex
  357. Dim num As Integer = Integer.Parse(cb.Name.Replace("ComboBox", "")) ' 獲取對應的 ComboBox 編號 (41~80)
  358. Dim targetComboBox As ComboBox = CType(Me.Controls("ComboBox" & (num - 40)), ComboBox) ' 找到對應的 ComboBox (例如 ComboBox41 對應 ComboBox1)
  359. If targetComboBox IsNot Nothing AndAlso index >= 0 AndAlso index < colors.Length Then : targetComboBox.BackColor = colors(index) : End If
  360. End Sub
  361. Private Sub 截圖_bt_Click(sender As Object, e As EventArgs) Handles 截圖_bt.Click
  362. Dim captureRectangle As New Rectangle(123, 0, 1698, 647) ' 指定要截取的範圍
  363. Dim bm As New Bitmap(captureRectangle.Width, captureRectangle.Height)
  364. Using g As Graphics = Graphics.FromImage(bm) ' 設定截圖的起點為 captureRectangle 左上角的位置
  365. g.CopyFromScreen(Me.PointToScreen(captureRectangle.Location), Point.Empty, captureRectangle.Size)
  366. End Using
  367. Me.Controls.SetChildIndex(PictureBox1, 0)
  368. My.Computer.Clipboard.SetImage(bm)
  369. PictureBox1.SendToBack()
  370. If 存檔_ch.Checked = True Then ' 保存圖片到桌面
  371. Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
  372. Dim filePath As String = Path.Combine(desktopPath, 年_lb.Text & 月_lb.Text & 日_lb.Text & 星期_lb.Text & ".png")
  373. bm.Save(filePath, ImageFormat.Png) : MsgBox("已將圖片存檔到桌面!!")
  374. End If
  375. End Sub
  376. Private Sub 上移_bt_Click(sender As Object, e As EventArgs) Handles 上移_bt.Click
  377. If 選擇項 <= 1 Then : Else
  378. If CInt(排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value) < 12 Then
  379. 排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value = "0" & CInt(排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value) - 2 & "-1"
  380. Else
  381. 排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value = CInt(排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value) - 2 & "-1"
  382. End If
  383. 排班明細_dgv.Sort(排班明細_dgv.Columns("項次"), System.ComponentModel.ListSortDirection.Ascending)
  384. For i As Integer = 0 To 排班明細_dgv.Rows.Count - 1 : 排班明細_dgv.Rows(i).Cells("項").Value = i + 1 : Next
  385. 排班明細_dgv.Sort(排班明細_dgv.Columns("項"), System.ComponentModel.ListSortDirection.Ascending)
  386. For i As Integer = 0 To 排班明細_dgv.Rows.Count - 1
  387. 排班明細_dgv.Rows(i).Cells("項次").Value = i + 1
  388. If CInt(排班明細_dgv.Rows(i).Cells("項次").Value) < 10 Then
  389. 排班明細_dgv.Rows(i).Cells("項次").Value = "0" & i + 1
  390. Else : 排班明細_dgv.Rows(i).Cells("項次").Value = i + 1 : End If
  391. Next : 選擇項 -= 1
  392. If 選擇項 <= 0 Then : 選擇項 = 0 : End If : 排班()
  393. End If
  394. End Sub
  395. Private Sub 下移_bt_Click(sender As Object, e As EventArgs) Handles 下移_bt.Click
  396. If 選擇項 = 0 Or 選擇項 = 1 Then : Else
  397. If CInt(排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value) < 9 Then
  398. 排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value = "0" & CInt(排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value) + 1 & "-1"
  399. Else
  400. 排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value = CInt(排班明細_dgv.Rows(選擇項 - 1).Cells("項次").Value) + 1 & "-1"
  401. End If
  402. 排班明細_dgv.Sort(排班明細_dgv.Columns("項次"), System.ComponentModel.ListSortDirection.Ascending)
  403. For i As Integer = 0 To 排班明細_dgv.Rows.Count - 1 : 排班明細_dgv.Rows(i).Cells("項").Value = i + 1 : Next
  404. 排班明細_dgv.Sort(排班明細_dgv.Columns("項"), System.ComponentModel.ListSortDirection.Ascending)
  405. For i As Integer = 0 To 排班明細_dgv.Rows.Count - 1
  406. 排班明細_dgv.Rows(i).Cells("項次").Value = i + 1
  407. If CInt(排班明細_dgv.Rows(i).Cells("項次").Value) < 10 Then
  408. 排班明細_dgv.Rows(i).Cells("項次").Value = "0" & i + 1
  409. Else : 排班明細_dgv.Rows(i).Cells("項次").Value = i + 1 : End If
  410. Next : 選擇項 += 1
  411. If 選擇項 >= 20 Then : 選擇項 = 20 : End If : 排班()
  412. End If
  413. End Sub
  414. Private Sub 備註存檔_tb_Click(sender As Object, e As EventArgs) Handles 備註存檔_tb.Click
  415. If 編號_tb.Text <> "" Then
  416. PA10 = 問題備註_tb.Text : PA11 = 人員職位_tb.Text : PA12 = 職務性質_tb.Text : PA13 = 早班_ch.Checked : PA14 = 晚班_ch.Checked : PA = 編號_tb.Text
  417. PA9 = 崗位01_ch.Checked : PA8 = 崗位02_ch.Checked : PA7 = 崗位03_ch.Checked : PA6 = 崗位04_ch.Checked : PA5 = 崗位05_ch.Checked : PA4 = 崗位06_ch.Checked
  418. PA3 = 崗位07_ch.Checked : PA2 = 崗位08_ch.Checked : PA1 = 穩定_ch.Checked
  419. SQL_人員備註修改() : MsgBox("存檔完成!!")
  420. End If
  421. End Sub
  422. Private Sub 人員資料讀取()
  423. PA = 人員_dgv("編號", 選擇處).Value.ToString : PA1 = 人員_dgv("姓名", 選擇處).Value.ToString
  424. 編號_tb.Text = 人員_dgv("編號", 選擇處).Value.ToString : 人員名稱_tb.Text = 人員_dgv("姓名", 選擇處).Value.ToString
  425. SQL_人員備註()
  426. If dr.Read Then
  427. 人員職位_tb.Text = dr("職位").ToString : 職務性質_tb.Text = dr("性質").ToString : 問題備註_tb.Text = dr("人員備註").ToString
  428. If IsDBNull(dr("早班")) Then : Else : 早班_ch.Checked = dr("早班") : End If : If IsDBNull(dr("晚班")) Then : Else : 晚班_ch.Checked = dr("晚班") : End If
  429. If IsDBNull(dr("崗位01")) Then : Else : 崗位01_ch.Checked = dr("崗位01") : End If : If IsDBNull(dr("崗位02")) Then : Else : 崗位02_ch.Checked = dr("崗位02") : End If
  430. If IsDBNull(dr("崗位03")) Then : Else : 崗位03_ch.Checked = dr("崗位03") : End If : If IsDBNull(dr("崗位04")) Then : Else : 崗位04_ch.Checked = dr("崗位04") : End If
  431. If IsDBNull(dr("崗位05")) Then : Else : 崗位05_ch.Checked = dr("崗位05") : End If : If IsDBNull(dr("崗位06")) Then : Else : 崗位06_ch.Checked = dr("崗位06") : End If
  432. If IsDBNull(dr("崗位07")) Then : Else : 崗位07_ch.Checked = dr("崗位07") : End If : If IsDBNull(dr("崗位08")) Then : Else : 崗位08_ch.Checked = dr("崗位08") : End If
  433. If IsDBNull(dr("穩定")) Then : Else : 穩定_ch.Checked = dr("穩定") : End If
  434. End If
  435. End Sub
  436. Private Sub 人員_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 人員_dgv.CellClick
  437. If e.RowIndex = -1 Then : Else : 選擇處 = e.RowIndex : 人員資料讀取() : End If
  438. End Sub
  439. Private Sub 班別_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles _
  440. 班別_cb1.SelectedIndexChanged, 班別_cb2.SelectedIndexChanged, 班別_cb3.SelectedIndexChanged, 班別_cb4.SelectedIndexChanged, 班別_cb5.SelectedIndexChanged, 班別_cb6.SelectedIndexChanged,
  441. 班別_cb7.SelectedIndexChanged, 班別_cb8.SelectedIndexChanged, 班別_cb9.SelectedIndexChanged, 班別_cb10.SelectedIndexChanged, 班別_cb11.SelectedIndexChanged, 班別_cb12.SelectedIndexChanged,
  442. 班別_cb13.SelectedIndexChanged, 班別_cb14.SelectedIndexChanged, 班別_cb15.SelectedIndexChanged, 班別_cb16.SelectedIndexChanged, 班別_cb17.SelectedIndexChanged, 班別_cb18.SelectedIndexChanged,
  443. 班別_cb19.SelectedIndexChanged, 班別_cb20.SelectedIndexChanged
  444. Dim cb As ComboBox = DirectCast(sender, ComboBox) : Dim index As Integer = Integer.Parse(cb.Name.Replace("班別_cb", "")) ' 取得數字部分
  445. Dim cb休息 As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2 - 1), True)(0), ComboBox)
  446. Dim cb半天 As ComboBox = CType(Me.Controls.Find("ComboBox" & (index * 2), True)(0), ComboBox)
  447. If cb.Text <> "休" Then : 休息變化(index) : 半天變化(index) : Else : cb休息.Visible = False : cb半天.Visible = False : End If
  448. End Sub
  449. Private Sub 全_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 全_ch.CheckedChanged
  450. 讀取人員資料表()
  451. End Sub
  452. Private Sub 減一天_bt_Click(sender As Object, e As EventArgs) Handles 減一天_bt.Click
  453. 年_lb.Text = 年_cb.Text : 月_lb.Text = 月_cb.Text : 日_lb.Text = 日_cb.Text
  454. DTP1.Value = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text
  455. DTP1.Value = DTP1.Value.AddDays(-1)
  456. PA = Format(DTP1.Value, "yyyy/MM/dd")
  457. 年_lb.Text = Strings.Left(PA, 4) : 月_lb.Text = Strings.Mid(PA, 6, 2) : PA2 = Strings.Right(PA, 2)
  458. '----------------回復預設-----------------------------------------------------------------------------------------------
  459. If Val(PA2) > 9 Then : 日_lb.Text = PA2 : Else : 日_lb.Text = "0" & Val(PA2) : End If
  460. 年_cb.Text = 年_lb.Text : 月_cb.Text = 月_lb.Text : 日_cb.Text = 日_lb.Text
  461. 回復預設() : 重新讀取()
  462. End Sub
  463. Private Sub 加一天_bt1_Click(sender As Object, e As EventArgs) Handles 加一天_bt1.Click
  464. 年_lb.Text = 年_cb.Text : 月_lb.Text = 月_cb.Text : 日_lb.Text = 日_cb.Text
  465. DTP1.Value = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text
  466. DTP1.Value = DTP1.Value.AddDays(+1)
  467. PA = Format(DTP1.Value, "yyyy/MM/dd")
  468. 年_lb.Text = Strings.Left(PA, 4) : 月_lb.Text = Strings.Mid(PA, 6, 2) : PA2 = Strings.Right(PA, 2)
  469. '----------------回復預設-----------------------------------------------------------------------------------------------
  470. If Val(PA2) > 9 Then : 日_lb.Text = PA2 : Else : 日_lb.Text = "0" & Val(PA2) : End If
  471. 年_cb.Text = 年_lb.Text : 月_cb.Text = 月_lb.Text : 日_cb.Text = 日_lb.Text
  472. 回復預設() : 重新讀取()
  473. End Sub
  474. Private Sub 更新日期_bt_Click(sender As Object, e As EventArgs) Handles 更新日期_bt.Click
  475. 年_lb.Text = 年_cb.Text : 月_lb.Text = 月_cb.Text : 日_lb.Text = 日_cb.Text
  476. Dim dateStr As String = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text
  477. Dim validDate As Boolean : Dim parsedDate As DateTime
  478. validDate = DateTime.TryParseExact(dateStr, "yyyy/M/d", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, parsedDate)
  479. If validDate Then
  480. DTP1.Value = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text : PA = Format(DTP1.Value, "yyyy/MM/dd")
  481. If Val(PA2) > 9 Then : 日_lb.Text = PA2 : Else : 日_lb.Text = "0" & Val(PA2) : End If
  482. 回復預設() : 重新讀取()
  483. Else : MsgBox("無效的日期!!") : End If
  484. End Sub
  485. Private Sub 鎖定_bt_Click(sender As Object, e As EventArgs) Handles 鎖定_bt.Click
  486. PA = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text : SQL_排班簽核() : MsgBox("簽核完畢!!!")
  487. 年_cb.Text = 年_lb.Text : 月_cb.Text = 月_lb.Text : 日_cb.Text = 日_lb.Text
  488. 鎖定_bt.Enabled = False
  489. 班表鎖定變化()
  490. End Sub
  491. Private Sub 解鎖_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 解鎖_ch.Click
  492. If 解鎖_ch.Checked = True Then : PA = InputBox("修改已鎖定班表請輸入密碼!!")
  493. If PA = "0003065795" Then : 解鎖_ch.Checked = True : 鎖定_bt.Enabled = True : 班表鎖定變化()
  494. Else : MsgBox("密碼錯誤!!") : 解鎖_ch.Checked = False : 鎖定_bt.Enabled = False : 班表鎖定變化() : End If
  495. ElseIf 解鎖_ch.Checked = False Then : 解鎖_ch.Checked = False : 鎖定_bt.Enabled = False : 班表鎖定變化() : End If
  496. End Sub
  497. Private Sub ComboBox40_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox40.TextChanged
  498. If ComboBox40.Text = "" Then : ComboBox40.DropDownStyle = 1 : Else : ComboBox40.DropDownStyle = 0 : End If
  499. End Sub
  500. Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
  501. 年_lb.Text = 年_cb.Text : 月_lb.Text = 月_cb.Text : 日_lb.Text = 日_cb.Text
  502. PA = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text
  503. SQL_排班明細_判斷是否有資料() : If dr.Read() Then : SQL_排班明細_刪除當天() : End If : Q = 0
  504. For no As Integer = 1 To 20
  505. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  506. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  507. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  508. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  509. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  510. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  511. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  512. Dim ComboBoxsS1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + Q).ToString(), True)(0), ComboBox)
  513. Dim ComboBoxsS2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + 1 + Q).ToString(), True)(0), ComboBox)
  514. Dim ComboBoxs1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + Q).ToString(), True)(0), ComboBox)
  515. Dim ComboBoxs2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 1 + Q).ToString(), True)(0), ComboBox) : Q += 1
  516. PA1 = A_lbS.Text : PA2 = 姓名_tbS.Text : PA3 = 班別_cbS.Text : BL1 = CheckBoxS.Checked : Do1 = NUPS.Value
  517. PA5 = ComboBoxs1.Text : PA6 = ComboBoxs2.Text : PA7 = ComboBoxsS1.Text : PA8 = ComboBoxsS2.Text : PA9 = BUPS.Value
  518. SQL_排班明細_上午上班()
  519. If dr.Read() Then : PA4 = dr("上午上班") : End If
  520. If CheckBoxS.Checked = False Then : Do3 = 8 : Else : Do3 = NumericUpDownS.Value : End If
  521. Do2 = NumericUpDownS.Value
  522. SQL_排班明細_新增當天()
  523. Next
  524. PA = 年_lb.Text & "/" & 月_lb.Text & "/" & 日_lb.Text : PA13 = 值日生1_bt.Text : PA14 = 值日生2_bt.Text
  525. SQL_值日生存檔(紅1_nud.Value, 面1_nud.Value, 紅2_nud.Value, 面2_nud.Value, 紅3_nud.Value, 面3_nud.Value, 紅4_nud.Value, 面4_nud.Value)
  526. 解鎖_ch.Checked = False : 重新讀取() : MsgBox("存檔完成!!")
  527. End Sub
  528. Private Sub 複製班表_bt_Click(sender As Object, e As EventArgs) Handles 複製班表_bt.Click
  529. Dim FF = MsgBox("確定要已該班表做模板複製到 " & Format(指定日期_dtp.Value, "yyyy/MM/dd") & " 去嗎 ?", MsgBoxStyle.OkCancel)
  530. If FF = MsgBoxResult.Ok Then
  531. PA = Format(指定日期_dtp.Value, "yyyy/MM/dd")
  532. SQL_排班明細_判斷是否有資料() : If dr.Read() Then : SQL_排班明細_刪除當天() : End If
  533. Q = 0
  534. For no As Integer = 1 To 20
  535. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  536. Dim 班別_cbS As ComboBox = CType(Me.Controls.Find("班別_cb" + no.ToString(), True)(0), ComboBox)
  537. Dim A_lbS As Label = CType(Me.Controls.Find("A_lb" + no.ToString(), True)(0), Label)
  538. Dim CheckBoxS As CheckBox = CType(Me.Controls.Find("CheckBox" + no.ToString(), True)(0), CheckBox)
  539. Dim NumericUpDownS As NumericUpDown = CType(Me.Controls.Find("NumericUpDown" + no.ToString(), True)(0), NumericUpDown)
  540. Dim NUPS As NumericUpDown = CType(Me.Controls.Find("NUP" + no.ToString(), True)(0), NumericUpDown)
  541. Dim BUPS As NumericUpDown = CType(Me.Controls.Find("BUP" + no.ToString(), True)(0), NumericUpDown)
  542. Dim ComboBoxsS1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + Q).ToString(), True)(0), ComboBox)
  543. Dim ComboBoxsS2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 40 + 1 + Q).ToString(), True)(0), ComboBox)
  544. Dim ComboBoxs1 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + Q).ToString(), True)(0), ComboBox)
  545. Dim ComboBoxs2 As ComboBox = CType(Me.Controls.Find("ComboBox" + (no + 1 + Q).ToString(), True)(0), ComboBox) : Q += 1
  546. PA1 = A_lbS.Text : PA2 = 姓名_tbS.Text : PA3 = 班別_cbS.Text : BL1 = CheckBoxS.Checked : Do1 = NUPS.Value
  547. PA5 = ComboBoxs1.Text : PA6 = ComboBoxs2.Text : PA7 = ComboBoxsS1.Text : PA8 = ComboBoxsS2.Text : PA9 = BUPS.Value
  548. SQL_排班明細_上午上班()
  549. If dr.Read() Then : PA4 = dr("上午上班") : End If
  550. If CheckBoxS.Checked = False Then : Do3 = 8 : Else : Do3 = NumericUpDownS.Value : End If
  551. Do2 = NumericUpDownS.Value
  552. SQL_排班明細_新增當天()
  553. Next : MsgBox("存檔完成,請切換到指定日期去查看!!")
  554. End If
  555. End Sub
  556. Private Sub 人員_dgv_CellContentClick_1(sender As Object, e As DataGridViewCellEventArgs) Handles 人員_dgv.CellDoubleClick
  557. If e.RowIndex = -1 Then : Else : PA = 人員_dgv("編號", e.RowIndex).Value.ToString : PA1 = 人員_dgv("姓名", e.RowIndex).Value.ToString : End If
  558. For no As Integer = 1 To 20
  559. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  560. If 姓名_tbS.Text = PA1 Then : MsgBox("該人員已在班表內,無須再新增!!") : Exit Sub : End If
  561. Next
  562. For no As Integer = 1 To 20
  563. Dim 姓名_tbS As TextBox = CType(Me.Controls.Find("姓名_tb" + no.ToString(), True)(0), TextBox)
  564. If 姓名_tbS.Text <> "" Then : Else : 姓名_tbS.Text = PA1 : Exit For : End If
  565. Next
  566. End Sub
  567. End Class