Ei kuvausta
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.

考勤打卡資料補登.vb 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 考勤打卡資料補登
  4. Dim conn As New SqlConnection
  5. Dim da As New SqlDataAdapter
  6. Dim cmd As New SqlCommand
  7. Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet
  8. Dim dr As SqlDataReader
  9. Dim 編號 As String
  10. Private Sub Set_考勤明細()
  11. DataGridView1.DataSource = Nothing : ds.Clear()
  12. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  13. DataGridView1.ColumnHeadersHeight = 25
  14. DataGridView1.AllowUserToAddRows = False
  15. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  16. SQL1 = "SELECT 萬年曆.日期, 萬年曆.星期, QQ.請假類別, AA.事由, AA.是否生效, AA.核准人, AA.核准日期, QQ.上午上班, QQ.上午上班 AS 上午下班, QQ.上午上班 AS 上午工時, QQ.下午下班 AS 下午上班,
  17. QQ.下午下班, QQ.下午下班 AS 下午工時, QQ.下午下班 AS 整日工時, BB.上午補登, BB.下午補登, BB.公出事由, QQ.員工編號
  18. FROM 萬年曆 LEFT OUTER JOIN
  19. (SELECT 員工編號, 日期, 請假類別, 事由, 是否生效, 核准人, 核准日期
  20. FROM 人事請假單
  21. WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%')) AS AA ON 萬年曆.日期 = AA.日期
  22. LEFT OUTER JOIN
  23. (SELECT 員工編號, 日期, 請假類別, 上午上班, 下午下班
  24. FROM 人事考勤明細表
  25. WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%')) AS QQ ON 萬年曆.日期 = QQ.日期
  26. LEFT OUTER JOIN
  27. (SELECT 員工編號, 日期, 上午補登, 下午補登, 公出事由
  28. FROM 人事漏打卡補登紀錄
  29. WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%')) AS BB ON 萬年曆.日期 = BB.日期
  30. WHERE (萬年曆.日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%') ORDER BY 萬年曆.日期"
  31. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
  32. End Sub
  33. Private Sub Set_grid()
  34. DataGridView1.Columns(0).Width = 85 : DataGridView1.Columns(1).Width = 60 : DataGridView1.Columns(2).Width = 90 : DataGridView1.Columns(3).Width = 262
  35. DataGridView1.Columns(4).Width = 80 : DataGridView1.Columns(5).Width = 65 : DataGridView1.Columns(6).Width = 90 : DataGridView1.Columns(7).Width = 75
  36. DataGridView1.Columns(8).Width = 75 : DataGridView1.Columns(9).Width = 80 : DataGridView1.Columns(10).Width = 75 : DataGridView1.Columns(11).Width = 75
  37. DataGridView1.Columns(12).Width = 80 : DataGridView1.Columns(13).Width = 90 : DataGridView1.Columns(14).Width = 70 : DataGridView1.Columns(15).Width = 70
  38. DataGridView1.Columns(16).Width = 262 : DataGridView1.Columns(17).Visible = False
  39. Dim T, S, F, M, T1, S1 As Integer : Dim T2, S2, F2, M2 As String : Dim 上午 As Integer = 0 : Dim 下午 As Integer = 0 : Dim 漏打 As Integer = 0
  40. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  41. 資料數 = DataGridView1.Rows.Count : MyModule1.進度條()
  42. Dim QASW As Integer = 0
  43. If DataGridView1.Rows(i).Cells("上午上班").Value.ToString <> "" Then
  44. DataGridView1.Rows(i).Cells("上午下班").Value = "12:00:00"
  45. Dim TSFM As Integer = DateDiff("s", DataGridView1.Rows(i).Cells("上午上班").Value.ToString, DataGridView1.Rows(i).Cells("上午下班").Value)
  46. T = TSFM \ 86400 : T1 = TSFM Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60
  47. If T = 0 Then : T2 = "" : Else : T2 = T & "天" : End If : If S = 0 Then : S2 = "" : Else : S2 = S & "時" : End If : If F = 0 Then : F2 = "" : Else : F2 = F & "分" : End If : M2 = M & "秒"
  48. DataGridView1.Rows(i).Cells("上午工時").Value = T2 & S2 & F2 & M2
  49. QASW = QASW + TSFM : 上午 = 上午 + TSFM
  50. End If
  51. If DataGridView1.Rows(i).Cells("下午下班").Value.ToString <> "" Then
  52. DataGridView1.Rows(i).Cells("下午上班").Value = "13:30:00"
  53. Dim TSFM As Integer = DateDiff("s", DataGridView1.Rows(i).Cells("下午上班").Value.ToString, DataGridView1.Rows(i).Cells("下午下班").Value)
  54. T = TSFM \ 86400 : T1 = TSFM Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60
  55. If T = 0 Then : T2 = "" : Else : T2 = T & "天" : End If : If S = 0 Then : S2 = "" : Else : S2 = S & "時" : End If : If F = 0 Then : F2 = "" : Else : F2 = F & "分" : End If : M2 = M & "秒"
  56. DataGridView1.Rows(i).Cells("下午工時").Value = T2 & S2 & F2 & M2
  57. QASW = QASW + TSFM : 下午 = 下午 + TSFM
  58. End If
  59. If QASW = 0 Then : Else
  60. T = QASW \ 86400 : T1 = QASW Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60
  61. If T = 0 Then : T2 = "" : Else : T2 = T & "天" : End If : If S = 0 Then : S2 = "" : Else : S2 = S & "時" : End If : If F = 0 Then : F2 = "" : Else : F2 = F & "分" : End If : M2 = M & "秒"
  62. DataGridView1.Rows(i).Cells("整日工時").Value = T2 & S2 & F2 & M2
  63. End If
  64. Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  65. End Sub
  66. Private Sub Set_人員清單()
  67. DataGridView2.DataSource = Nothing : ds1.Clear()
  68. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  69. DataGridView2.ColumnHeadersHeight = 25
  70. DataGridView2.AllowUserToAddRows = False
  71. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  72. SQL1 = "SELECT 人事資料表.員工編號, 使用者權限管理表.姓名 AS 系統登入姓名, 人事資料表.姓名, 人事資料表.入職日期, 人事資料表.離職日期
  73. FROM 使用者權限管理表 LEFT OUTER JOIN
  74. 人事資料表 ON 使用者權限管理表.員工編號 = 人事資料表.員工編號 AND
  75. 使用者權限管理表.姓名 = 人事資料表.系統登入姓名
  76. WHERE (使用者權限管理表.CC49 = 0) AND (人事資料表.員工編號 IS NOT NULL) AND (人事資料表.離職日期 LIKE '在職')
  77. ORDER BY 使用者權限管理表.職稱"
  78. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1()
  79. End Sub
  80. Private Sub Set_grid1()
  81. DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Width = 150 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).Visible = False
  82. DataGridView2.Columns(4).Visible = False
  83. End Sub
  84. Private Sub ComboBox1下拉表單資料載入()
  85. conn.Close()
  86. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  87. SQL1 = "SELECT 年份 FROM 年份清單 ORDER BY 年份 DESC"
  88. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  89. ComboBox1.Items.Clear()
  90. While (dr.Read()) : ComboBox1.Items.Add(dr("年份")) : End While
  91. conn.Close()
  92. End Sub
  93. Private Sub 考勤打卡資料補登_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  94. Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  95. ComboBox1下拉表單資料載入() : Set_人員清單()
  96. ComboBox1.Text = Year(Today) : ComboBox2.SelectedIndex = Month(Today) - 1
  97. ComboBox12.Enabled = False : ComboBox11.Enabled = False : ComboBox10.Enabled = False : ComboBox9.Enabled = False : ComboBox8.Enabled = False
  98. ComboBox3.Enabled = False : ComboBox4.Enabled = False : ComboBox5.Enabled = False : ComboBox6.Enabled = False : ComboBox7.Enabled = False
  99. End Sub
  100. Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  101. If e.RowIndex = -1 Then : Else
  102. TextBox4.Text = DataGridView1(0, e.RowIndex).Value.ToString
  103. End If
  104. End Sub
  105. Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  106. If e.RowIndex = -1 Then : Else
  107. 編號 = DataGridView2(0, e.RowIndex).Value.ToString : Set_考勤明細() : DateTimePicker1.Value = DataGridView2(3, e.RowIndex).Value.ToString
  108. Dim TSFM As Integer = DateDiff("d", DateTimePicker1.Value, Today()) : TextBox18.Text = TSFM
  109. TextBox1.Text = DataGridView2(1, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView2(0, e.RowIndex).Value.ToString
  110. End If
  111. End Sub
  112. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  113. Button2.Enabled = False : Button3.Enabled = True : Label8.Text = "選擇補登考勤時段 : 上午上班"
  114. ComboBox12.Enabled = False : ComboBox11.Enabled = False : ComboBox10.Enabled = False : ComboBox9.Enabled = False : ComboBox8.Enabled = False
  115. ComboBox3.Enabled = True : ComboBox4.Enabled = True : ComboBox5.Enabled = True : ComboBox6.Enabled = True : ComboBox7.Enabled = True
  116. End Sub
  117. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  118. Button2.Enabled = True : Button3.Enabled = False : Label8.Text = "選擇補登考勤時段 : 下午下班"
  119. ComboBox12.Enabled = True : ComboBox11.Enabled = True : ComboBox10.Enabled = True : ComboBox9.Enabled = True : ComboBox8.Enabled = True
  120. ComboBox3.Enabled = False : ComboBox4.Enabled = False : ComboBox5.Enabled = False : ComboBox6.Enabled = False : ComboBox7.Enabled = False
  121. End Sub
  122. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  123. Label9.Text = "選擇補登考勤特性 : 公事出差,考勤表會取消該次漏打卡紀錄"
  124. Button4.Enabled = True : Button5.Enabled = False
  125. End Sub
  126. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  127. Label9.Text = "選擇補登考勤特性 : 漏打卡,考勤表不會取消該次漏打卡紀錄"
  128. Button4.Enabled = False : Button5.Enabled = True
  129. End Sub
  130. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  131. Dim 有無資料判別1 As String = "" : Dim 有無資料判別2 As String = "" : PA = ""
  132. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  133. SQL1 = "SELECT 員工編號 FROM 人事漏打卡補登紀錄 WHERE 員工編號 LIKE '" & 編號 & "' AND 日期 LIKE '" & TextBox4.Text & "'"
  134. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  135. If dr.Read() Then : 有無資料判別1 = dr("員工編號").ToString : End If : conn.Close()
  136. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  137. SQL1 = "SELECT 員工編號 FROM 人事考勤明細表 WHERE 員工編號 LIKE '" & 編號 & "' AND 日期 LIKE '" & TextBox4.Text & "'"
  138. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  139. If dr.Read() Then : 有無資料判別2 = dr("員工編號").ToString : End If : conn.Close()
  140. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  141. If 有無資料判別1 = "" Then
  142. If Button5.Enabled = False And Button4.Enabled = True Then
  143. PA = InputBox("請輸入公出原因")
  144. If PA = "" Then
  145. MsgBox("公出原因不可空白") : Exit Sub
  146. End If
  147. End If
  148. If Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = False And Button4.Enabled = True Then
  149. SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'','" & PA & "'"
  150. ElseIf Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = True And Button4.Enabled = False Then
  151. SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'1','漏打卡'"
  152. ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = False And Button4.Enabled = True Then
  153. SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'','" & PA & "'"
  154. ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = True And Button4.Enabled = False Then
  155. SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'1','漏打卡'"
  156. End If
  157. Else
  158. If Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = False And Button4.Enabled = True Then
  159. ElseIf Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = True And Button4.Enabled = False Then
  160. SQL1 = "UPDATE 人事漏打卡補登紀錄 SET 上午補登 = N'1' WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')"
  161. ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = False And Button4.Enabled = True Then
  162. ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = True And Button4.Enabled = False Then
  163. SQL1 = "UPDATE 人事漏打卡補登紀錄 SET 下午補登 = N'1' WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')"
  164. End If
  165. End If
  166. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  167. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  168. If 有無資料判別2 = "" Then
  169. If Button2.Enabled = False And Button3.Enabled = True Then
  170. SQL1 = "INSERT INTO 人事考勤明細表 (員工編號, 日期, 請假類別, 上午上班, 下午下班) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',
  171. N'" & ComboBox3.Text & ":" & ComboBox4.Text & ComboBox5.Text & ":" & ComboBox6.Text & ComboBox7.Text & "', N''"
  172. ElseIf Button2.Enabled = True And Button3.Enabled = False Then
  173. SQL1 = "INSERT INTO 人事考勤明細表 (員工編號, 日期, 請假類別, 上午上班, 下午下班) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',
  174. N'', N'" & ComboBox12.Text & ":" & ComboBox11.Text & ComboBox10.Text & ":" & ComboBox9.Text & ComboBox8.Text & "'"
  175. End If
  176. Else
  177. If Button2.Enabled = False And Button3.Enabled = True Then
  178. SQL1 = "UPDATE 人事考勤明細表 SET 上午上班 = N'" & ComboBox3.Text & ":" & ComboBox4.Text & ComboBox5.Text & ":" & ComboBox6.Text & ComboBox7.Text & "'
  179. WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')"
  180. ElseIf Button2.Enabled = True And Button3.Enabled = False Then
  181. SQL1 = "UPDATE 人事考勤明細表 SET 下午下班 = N'" & ComboBox12.Text & ":" & ComboBox11.Text & ComboBox10.Text & ":" & ComboBox9.Text & ComboBox8.Text & "'
  182. WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')"
  183. End If
  184. End If
  185. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  186. Set_考勤明細() : MsgBox("補打卡成功")
  187. Button4.Enabled = True : Button5.Enabled = True : Button2.Enabled = True : Button3.Enabled = True
  188. ComboBox12.Enabled = False : ComboBox11.Enabled = False : ComboBox10.Enabled = False : ComboBox9.Enabled = False : ComboBox8.Enabled = False
  189. ComboBox3.Enabled = False : ComboBox4.Enabled = False : ComboBox5.Enabled = False : ComboBox6.Enabled = False : ComboBox7.Enabled = False
  190. End Sub
  191. End Class