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 TextBox5.Text = "0" : TextBox6.Text = "0" : TextBox7.Text = "0" : TextBox8.Text = "0" : TextBox16.Text = "0" : TextBox9.Text = "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 T = 上午 \ 86400 : T1 = 上午 Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60 If S = 0 Then : S2 = "" : Else : S2 = T * 24 + S & "時" : End If : If F = 0 Then : F2 = "" : Else : F2 = F & "分" : End If : M2 = M & "秒" TextBox1.Text = S2 & F2 & M2 T = 下午 \ 86400 : T1 = 下午 Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60 If S = 0 Then : S2 = "" : Else : S2 = T * 24 + S & "時" : End If : If F = 0 Then : F2 = "" : Else : F2 = F & "分" : End If : M2 = M & "秒" TextBox2.Text = S2 & F2 & M2 T = (上午 + 下午) \ 86400 : T1 = (上午 + 下午) Mod 86400 : S = T1 \ 3600 : S1 = T1 Mod 3600 : F = S1 \ 60 : M = S1 Mod 60 If S = 0 Then : S2 = "" : Else : S2 = T * 24 + S & "時" : End If : If F = 0 Then : F2 = "" : Else : F2 = F & "分" : End If : M2 = M & "秒" TextBox3.Text = S2 & F2 & M2 If DataGridView1.Rows(i).Cells("日期").Value < Today() Then If DataGridView1.Rows(i).Cells("星期").Value.ToString = "星期日" Or DataGridView1.Rows(i).Cells("星期").Value.ToString = "星期六" Then ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString <> "" Then Else If DataGridView1.Rows(i).Cells("上午上班").Value.ToString = "" Then : 漏打 = 漏打 + 1 : End If If DataGridView1.Rows(i).Cells("下午下班").Value.ToString = "" Then : 漏打 = 漏打 + 1 : End If End If End If If DataGridView1.Rows(i).Cells("上午補登").Value.ToString = "1" Then : 漏打 = 漏打 + 1 : End If If DataGridView1.Rows(i).Cells("下午補登").Value.ToString = "1" Then : 漏打 = 漏打 + 1 : End If TextBox4.Text = 漏打 If DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "育嬰假一天" Then : TextBox5.Text = Val(TextBox5.Text) + 1 ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "育嬰假半天" Then : TextBox5.Text = Val(TextBox5.Text) + 0.5 End If If DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "事假一天" Then : TextBox6.Text = Val(TextBox6.Text) + 1 ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "事假半天" Then : TextBox6.Text = Val(TextBox6.Text) + 0.5 End If If DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "病假一天" Then : TextBox7.Text = Val(TextBox7.Text) + 1 ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "病假半天" Then : TextBox7.Text = Val(TextBox7.Text) + 0.5 End If If DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "婚嫁一天" Then : TextBox8.Text = Val(TextBox8.Text) + 1 ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "婚嫁半天" Then : TextBox8.Text = Val(TextBox8.Text) + 0.5 End If If DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "特休一天" Then : TextBox16.Text = Val(TextBox16.Text) + 1 ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "特休半天" Then : TextBox16.Text = Val(TextBox16.Text) + 0.5 End If If DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "喪假一天" Then : TextBox9.Text = Val(TextBox9.Text) + 1 ElseIf DataGridView1.Rows(i).Cells("請假類別").Value.ToString = "喪假半天" Then : TextBox9.Text = Val(TextBox9.Text) + 0.5 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 Set_年度考勤明細() DataGridView3.DataSource = Nothing : ds2.Clear() DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView3.ColumnHeadersHeight = 25 DataGridView3.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If If Val(ComboBox1.Text) > 2019 Then SQL1 = "SELECT 萬年曆.日期, 萬年曆.星期, QQ.請假類別, AA.事由, AA.是否生效, AA.核准人, AA.核准日期, QQ.上午上班, QQ.上午上班 AS 上午下班, QQ.上午上班 AS 上午工時, QQ.下午下班 AS 下午上班, QQ.下午下班, QQ.下午下班 AS 下午工時, QQ.下午下班 AS 整日工時, BB.上午補登, BB.下午補登, QQ.員工編號 FROM 萬年曆 LEFT OUTER JOIN (SELECT 員工編號, 日期, 請假類別, 事由, 是否生效, 核准人, 核准日期 FROM 人事請假單 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "%')) AS AA ON 萬年曆.日期 = AA.日期 LEFT OUTER JOIN (SELECT 員工編號, 日期, 請假類別, 上午上班, 下午下班 FROM 人事考勤明細表 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "%')) AS QQ ON 萬年曆.日期 = QQ.日期 LEFT OUTER JOIN (SELECT 員工編號, 日期, 上午補登, 下午補登 FROM 人事漏打卡補登紀錄 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 LIKE '" & ComboBox1.Text & "%')) AS BB ON 萬年曆.日期 = BB.日期 WHERE (萬年曆.日期 LIKE '" & ComboBox1.Text & "%') ORDER BY 萬年曆.日期" ElseIf Val(ComboBox1.Text) = 2019 Then SQL1 = "SELECT 萬年曆.日期, 萬年曆.星期, QQ.請假類別, AA.事由, AA.是否生效, AA.核准人, AA.核准日期, QQ.上午上班, QQ.上午上班 AS 上午下班, QQ.上午上班 AS 上午工時, QQ.下午下班 AS 下午上班, QQ.下午下班, QQ.下午下班 AS 下午工時, QQ.下午下班 AS 整日工時, BB.上午補登, BB.下午補登, QQ.員工編號 FROM 萬年曆 LEFT OUTER JOIN (SELECT 員工編號, 日期, 請假類別, 事由, 是否生效, 核准人, 核准日期 FROM 人事請假單 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 BETWEEN '2019/11/01' AND '2019/12/31')) AS AA ON 萬年曆.日期 = AA.日期 LEFT OUTER JOIN (SELECT 員工編號, 日期, 請假類別, 上午上班, 下午下班 FROM 人事考勤明細表 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 BETWEEN '2019/11/01' AND '2019/12/31')) AS QQ ON 萬年曆.日期 = QQ.日期 LEFT OUTER JOIN (SELECT 員工編號, 日期, 上午補登, 下午補登 FROM 人事漏打卡補登紀錄 WHERE (員工編號 LIKE '" & 編號 & "') AND (日期 BETWEEN '2019/11/01' AND '2019/12/31')) AS BB ON 萬年曆.日期 = BB.日期 WHERE (萬年曆.日期 BETWEEN '2019/11/01' AND '2019/12/31') ORDER BY 萬年曆.日期" End If cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close() : Set_grid2() End Sub Private Sub Set_grid2() Dim 漏打 As Integer = 0 TextBox15.Text = "0" : TextBox14.Text = "0" : TextBox13.Text = "0" : TextBox12.Text = "0" : TextBox17.Text = "0" : TextBox11.Text = "0" For i As Integer = 0 To DataGridView3.Rows.Count - 1 資料數 = DataGridView3.Rows.Count : MyModule1.進度條() If DataGridView3.Rows(i).Cells("日期").Value < Today() Then If DataGridView3.Rows(i).Cells("星期").Value.ToString = "星期日" Or DataGridView3.Rows(i).Cells("星期").Value.ToString = "星期六" Then ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString <> "" Then Else If DataGridView3.Rows(i).Cells("上午上班").Value.ToString = "" Then : 漏打 = 漏打 + 1 : End If If DataGridView3.Rows(i).Cells("下午下班").Value.ToString = "" Then : 漏打 = 漏打 + 1 : End If End If End If If DataGridView3.Rows(i).Cells("上午補登").Value.ToString = "1" Then : 漏打 = 漏打 + 1 : End If If DataGridView3.Rows(i).Cells("下午補登").Value.ToString = "1" Then : 漏打 = 漏打 + 1 : End If TextBox10.Text = 漏打 If DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "育嬰假一天" Then : TextBox15.Text = Val(TextBox15.Text) + 1 ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "育嬰假半天" Then : TextBox15.Text = Val(TextBox15.Text) + 0.5 End If If DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "事假一天" Then : TextBox14.Text = Val(TextBox14.Text) + 1 ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "事假半天" Then : TextBox14.Text = Val(TextBox14.Text) + 0.5 End If If DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "病假一天" Then : TextBox13.Text = Val(TextBox13.Text) + 1 ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "病假半天" Then : TextBox13.Text = Val(TextBox13.Text) + 0.5 End If If DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "婚嫁一天" Then : TextBox12.Text = Val(TextBox12.Text) + 1 ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "婚嫁半天" Then : TextBox12.Text = Val(TextBox12.Text) + 0.5 End If If DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "特休一天" Then : TextBox17.Text = Val(TextBox17.Text) + 1 ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "特休半天" Then : TextBox17.Text = Val(TextBox17.Text) + 0.5 End If If DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "喪假一天" Then : TextBox11.Text = Val(TextBox11.Text) + 1 ElseIf DataGridView3.Rows(i).Cells("請假類別").Value.ToString = "喪假半天" Then : TextBox11.Text = Val(TextBox11.Text) + 0.5 End If Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 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 Set_人員清單() : ComboBox1下拉表單資料載入() : DataGridView3.Visible = False ComboBox1.Text = Year(Today) : ComboBox2.SelectedIndex = Month(Today) - 1 TextBox5.Text = "0" : TextBox6.Text = "0" : TextBox7.Text = "0" : TextBox8.Text = "0" : TextBox16.Text = "0" : TextBox9.Text = "0" TextBox15.Text = "0" : TextBox14.Text = "0" : TextBox13.Text = "0" : TextBox12.Text = "0" : TextBox17.Text = "0" : TextBox11.Text = "0" 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_考勤明細() : Set_年度考勤明細() : DateTimePicker1.Value = DataGridView2(3, e.RowIndex).Value.ToString Dim TSFM As Integer = DateDiff("d", DateTimePicker1.Value, Today()) : TextBox18.Text = TSFM End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Set_考勤明細() : Set_年度考勤明細() End Sub End Class