Option Strict Off Imports System.Data.SqlClient Public Class 考勤打卡資料補登 Dim conn As New SqlConnection Dim da As New SqlDataAdapter Dim cmd As New SqlCommand Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet Dim dr As SqlDataReader Dim 編號 As String Private Sub Set_考勤明細() DataGridView1.DataSource = Nothing : ds.Clear() DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView1.ColumnHeadersHeight = 25 DataGridView1.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 萬年曆.日期, 萬年曆.星期, QQ.請假類別, AA.事由, AA.是否生效, AA.核准人, AA.核准日期, QQ.上午上班, QQ.上午上班 AS 上午下班, QQ.上午上班 AS 上午工時, QQ.下午下班 AS 下午上班, QQ.下午下班, QQ.下午下班 AS 下午工時, QQ.下午下班 AS 整日工時, BB.上午補登, BB.下午補登, BB.公出事由, QQ.員工編號 FROM 萬年曆 LEFT OUTER JOIN (SELECT 員工編號, 日期, 請假類別, 事由, 是否生效, 核准人, 核准日期 FROM 人事請假單 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%')) AS AA ON 萬年曆.日期 = AA.日期 LEFT OUTER JOIN (SELECT 員工編號, 日期, 請假類別, 上午上班, 下午下班 FROM 人事考勤明細表 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%')) AS QQ ON 萬年曆.日期 = QQ.日期 LEFT OUTER JOIN (SELECT 員工編號, 日期, 上午補登, 下午補登, 公出事由 FROM 人事漏打卡補登紀錄 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%')) AS BB ON 萬年曆.日期 = BB.日期 WHERE (萬年曆.日期 LIKE '" & ComboBox1.Text & "/" & ComboBox2.Text & "%') ORDER BY 萬年曆.日期" cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid() End Sub Private Sub Set_grid() DataGridView1.Columns(0).Width = 85 : DataGridView1.Columns(1).Width = 60 : DataGridView1.Columns(2).Width = 90 : DataGridView1.Columns(3).Width = 262 DataGridView1.Columns(4).Width = 80 : DataGridView1.Columns(5).Width = 65 : DataGridView1.Columns(6).Width = 90 : DataGridView1.Columns(7).Width = 75 DataGridView1.Columns(8).Width = 75 : DataGridView1.Columns(9).Width = 80 : DataGridView1.Columns(10).Width = 75 : DataGridView1.Columns(11).Width = 75 DataGridView1.Columns(12).Width = 80 : DataGridView1.Columns(13).Width = 90 : DataGridView1.Columns(14).Width = 70 : DataGridView1.Columns(15).Width = 70 DataGridView1.Columns(16).Width = 262 : DataGridView1.Columns(17).Visible = False 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 For i As Integer = 0 To DataGridView1.Rows.Count - 1 資料數 = DataGridView1.Rows.Count : MyModule1.進度條() Dim QASW As Integer = 0 If DataGridView1.Rows(i).Cells("上午上班").Value.ToString <> "" Then DataGridView1.Rows(i).Cells("上午下班").Value = "12:00:00" Dim TSFM As Integer = DateDiff("s", DataGridView1.Rows(i).Cells("上午上班").Value.ToString, DataGridView1.Rows(i).Cells("上午下班").Value) T = TSFM \ 86400 : T1 = TSFM Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60 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 & "秒" DataGridView1.Rows(i).Cells("上午工時").Value = T2 & S2 & F2 & M2 QASW = QASW + TSFM : 上午 = 上午 + TSFM End If If DataGridView1.Rows(i).Cells("下午下班").Value.ToString <> "" Then DataGridView1.Rows(i).Cells("下午上班").Value = "13:30:00" Dim TSFM As Integer = DateDiff("s", DataGridView1.Rows(i).Cells("下午上班").Value.ToString, DataGridView1.Rows(i).Cells("下午下班").Value) T = TSFM \ 86400 : T1 = TSFM Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60 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 & "秒" DataGridView1.Rows(i).Cells("下午工時").Value = T2 & S2 & F2 & M2 QASW = QASW + TSFM : 下午 = 下午 + TSFM End If If QASW = 0 Then : Else T = QASW \ 86400 : T1 = QASW Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60 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 & "秒" DataGridView1.Rows(i).Cells("整日工時").Value = T2 & S2 & F2 & M2 End If Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 End Sub Private Sub Set_人員清單() DataGridView2.DataSource = Nothing : ds1.Clear() DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView2.ColumnHeadersHeight = 25 DataGridView2.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 人事資料表.員工編號, 使用者權限管理表.姓名 AS 系統登入姓名, 人事資料表.姓名, 人事資料表.入職日期, 人事資料表.離職日期 FROM 使用者權限管理表 LEFT OUTER JOIN 人事資料表 ON 使用者權限管理表.員工編號 = 人事資料表.員工編號 AND 使用者權限管理表.姓名 = 人事資料表.系統登入姓名 WHERE (使用者權限管理表.CC49 = 0) AND (人事資料表.員工編號 IS NOT NULL) AND (人事資料表.離職日期 LIKE '在職') ORDER BY 使用者權限管理表.職稱" cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1() End Sub Private Sub Set_grid1() DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Width = 150 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).Visible = False DataGridView2.Columns(4).Visible = False End Sub Private Sub ComboBox1下拉表單資料載入() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 年份 FROM 年份清單 ORDER BY 年份 DESC" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox1.Items.Clear() While (dr.Read()) : ComboBox1.Items.Add(dr("年份")) : End While conn.Close() End Sub Private Sub 考勤打卡資料補登_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True ComboBox1下拉表單資料載入() : Set_人員清單() ComboBox1.Text = Year(Today) : ComboBox2.SelectedIndex = Month(Today) - 1 ComboBox12.Enabled = False : ComboBox11.Enabled = False : ComboBox10.Enabled = False : ComboBox9.Enabled = False : ComboBox8.Enabled = False ComboBox3.Enabled = False : ComboBox4.Enabled = False : ComboBox5.Enabled = False : ComboBox6.Enabled = False : ComboBox7.Enabled = False End Sub Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then : Else TextBox4.Text = DataGridView1(0, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick If e.RowIndex = -1 Then : Else 編號 = DataGridView2(0, e.RowIndex).Value.ToString : Set_考勤明細() : DateTimePicker1.Value = DataGridView2(3, e.RowIndex).Value.ToString Dim TSFM As Integer = DateDiff("d", DateTimePicker1.Value, Today()) : TextBox18.Text = TSFM TextBox1.Text = DataGridView2(1, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView2(0, e.RowIndex).Value.ToString End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Button2.Enabled = False : Button3.Enabled = True : Label8.Text = "選擇補登考勤時段 : 上午上班" ComboBox12.Enabled = False : ComboBox11.Enabled = False : ComboBox10.Enabled = False : ComboBox9.Enabled = False : ComboBox8.Enabled = False ComboBox3.Enabled = True : ComboBox4.Enabled = True : ComboBox5.Enabled = True : ComboBox6.Enabled = True : ComboBox7.Enabled = True End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Button2.Enabled = True : Button3.Enabled = False : Label8.Text = "選擇補登考勤時段 : 下午下班" ComboBox12.Enabled = True : ComboBox11.Enabled = True : ComboBox10.Enabled = True : ComboBox9.Enabled = True : ComboBox8.Enabled = True ComboBox3.Enabled = False : ComboBox4.Enabled = False : ComboBox5.Enabled = False : ComboBox6.Enabled = False : ComboBox7.Enabled = False End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click Label9.Text = "選擇補登考勤特性 : 公事出差,考勤表會取消該次漏打卡紀錄" Button4.Enabled = True : Button5.Enabled = False End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click Label9.Text = "選擇補登考勤特性 : 漏打卡,考勤表不會取消該次漏打卡紀錄" Button4.Enabled = False : Button5.Enabled = True End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click Dim 有無資料判別1 As String = "" : Dim 有無資料判別2 As String = "" : PA = "" If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 員工編號 FROM 人事漏打卡補登紀錄 WHERE 員工編號 LIKE '" & 編號 & "' AND 日期 LIKE '" & TextBox4.Text & "'" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then : 有無資料判別1 = dr("員工編號").ToString : End If : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 員工編號 FROM 人事考勤明細表 WHERE 員工編號 LIKE '" & 編號 & "' AND 日期 LIKE '" & TextBox4.Text & "'" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then : 有無資料判別2 = dr("員工編號").ToString : End If : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If If 有無資料判別1 = "" Then If Button5.Enabled = False And Button4.Enabled = True Then PA = InputBox("請輸入公出原因") If PA = "" Then MsgBox("公出原因不可空白") : Exit Sub End If End If If Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = False And Button4.Enabled = True Then SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'','" & PA & "'" ElseIf Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = True And Button4.Enabled = False Then SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'1','漏打卡'" ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = False And Button4.Enabled = True Then SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'','" & PA & "'" ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = True And Button4.Enabled = False Then SQL1 = "INSERT INTO 人事漏打卡補登紀錄 (員工編號, 日期, 上午補登, 下午補登, 公出事由) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'',N'1','漏打卡'" End If Else If Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = False And Button4.Enabled = True Then ElseIf Button2.Enabled = False And Button3.Enabled = True And Button5.Enabled = True And Button4.Enabled = False Then SQL1 = "UPDATE 人事漏打卡補登紀錄 SET 上午補登 = N'1' WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')" ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = False And Button4.Enabled = True Then ElseIf Button2.Enabled = True And Button3.Enabled = False And Button5.Enabled = True And Button4.Enabled = False Then SQL1 = "UPDATE 人事漏打卡補登紀錄 SET 下午補登 = N'1' WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')" End If End If cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If If 有無資料判別2 = "" Then If Button2.Enabled = False And Button3.Enabled = True Then SQL1 = "INSERT INTO 人事考勤明細表 (員工編號, 日期, 請假類別, 上午上班, 下午下班) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'', N'" & ComboBox3.Text & ":" & ComboBox4.Text & ComboBox5.Text & ":" & ComboBox6.Text & ComboBox7.Text & "', N''" ElseIf Button2.Enabled = True And Button3.Enabled = False Then SQL1 = "INSERT INTO 人事考勤明細表 (員工編號, 日期, 請假類別, 上午上班, 下午下班) SELECT N'" & 編號 & "',N'" & TextBox4.Text & "',N'', N'', N'" & ComboBox12.Text & ":" & ComboBox11.Text & ComboBox10.Text & ":" & ComboBox9.Text & ComboBox8.Text & "'" End If Else If Button2.Enabled = False And Button3.Enabled = True Then SQL1 = "UPDATE 人事考勤明細表 SET 上午上班 = N'" & ComboBox3.Text & ":" & ComboBox4.Text & ComboBox5.Text & ":" & ComboBox6.Text & ComboBox7.Text & "' WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')" ElseIf Button2.Enabled = True And Button3.Enabled = False Then SQL1 = "UPDATE 人事考勤明細表 SET 下午下班 = N'" & ComboBox12.Text & ":" & ComboBox11.Text & ComboBox10.Text & ":" & ComboBox9.Text & ComboBox8.Text & "' WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & TextBox4.Text & "')" End If End If cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Set_考勤明細() : MsgBox("補打卡成功") Button4.Enabled = True : Button5.Enabled = True : Button2.Enabled = True : Button3.Enabled = True ComboBox12.Enabled = False : ComboBox11.Enabled = False : ComboBox10.Enabled = False : ComboBox9.Enabled = False : ComboBox8.Enabled = False ComboBox3.Enabled = False : ComboBox4.Enabled = False : ComboBox5.Enabled = False : ComboBox6.Enabled = False : ComboBox7.Enabled = False End Sub End Class