123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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 dr As SqlDataReader
- Dim STR1 As String
- Dim dt As DateTime
- Dim DTP As String
- Dim aa As MsgBoxResult
- Dim QQWQ As String
- 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
- If PA = "" Then
- SQL1 = "SELECT 已有考勤日期 AS 日期 FROM 已有考勤日期 ORDER BY 日期 DESC"
- Else
- SQL1 = "SELECT 已有考勤日期 AS 日期 FROM 已有考勤日期 WHERE 已有考勤日期 LIKE '%" & PA & "%' ORDER BY 日期 DESC"
- End If
- 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).Width = 80
- End Sub
- 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 資料流水號, DataID, 員工名稱, 出勤日期, 星期, 第1班上班, 第1班下班, 第1班合計, 第2班上班, 第2班下班, 第2班合計, 第3班上班, 第3班下班, 第3班合計, " &
- "第1班合計 + 第2班合計 + 第3班合計 AS 上班時長, 第1班合計 + 第2班合計 AS 應上班 FROM 考勤資料庫 " &
- "WHERE (出勤日期 LIKE '" & TextBox1.Text & "') ORDER BY DataID"
- 列印用SQL = SQL1
- 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).Visible = False : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Width = 70
- DataGridView1.Columns(3).Width = 80 : DataGridView1.Columns(4).Width = 60 : DataGridView1.Columns(5).Width = 70 : DataGridView1.Columns(6).Width = 70
- DataGridView1.Columns(7).Width = 70 : DataGridView1.Columns(8).Width = 70 : DataGridView1.Columns(9).Width = 80 : DataGridView1.Columns(10).Width = 80
- DataGridView1.Columns(11).Width = 80 : DataGridView1.Columns(12).Width = 80 : DataGridView1.Columns(13).Width = 80 : DataGridView1.Columns(14).Width = 80
- DataGridView1.Columns(15).Width = 80 : Set_自動彙總1()
- End Sub
- Private Sub Set_自動彙總1()
- Dim 加總(4) As Double : Dim EU(11) As Double
- For i As Integer = 0 To DataGridView1.Rows.Count - 1
- 加總(0) += DataGridView1.Rows(i).Cells("第1班合計").Value : 加總(1) += DataGridView1.Rows(i).Cells("第2班合計").Value : 加總(2) += DataGridView1.Rows(i).Cells("第3班合計").Value
- 加總(3) += DataGridView1.Rows(i).Cells("上班時長").Value : 加總(4) += DataGridView1.Rows(i).Cells("應上班").Value
- Next i
- TextBox3.Text = Format(Val(加總(0)), "#,##0.0") : TextBox4.Text = Format(Val(加總(1)), "#,##0.0") : TextBox5.Text = Format(Val(加總(2)), "#,##0.0")
- TextBox6.Text = Format(Val(加總(3)), "#,##0.0") : TextBox7.Text = Format(Val(加總(4)), "#,##0.0")
- End Sub
- Private Sub 考勤管理_依日期_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.MdiParent = 楠晉鞋業AAS : Me.AutoScroll = True
- Set_日期清單()
- TextBox1.Visible = False
- ComboBox3.Text = Year(Today) : ComboBox1.SelectedIndex = Month(Today) - 1
- End Sub
- Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
- TextBox1.Text = DataGridView2.Rows(e.RowIndex).Cells("日期").Value.ToString
- QQWQ = "0"
- Set_清單()
- End Sub
- Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
- If QQWQ = "1" Then
- Dim linePen As New Pen(Color.Blue, 2)
- If e.RowIndex = DataGridView1.Rows.Count - 1 Then
- Exit Sub
- Else
- If DataGridView1(2, e.RowIndex).Value.ToString <> DataGridView1(2, e.RowIndex + 1).Value.ToString Then
- Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- Exit Sub
- End If
- End If
- End If
- End Sub
- Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
- PA = InputBox("請輸入要查詢的日期") : Set_日期清單() : PA = ""
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- QQWQ = "1"
- 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 資料流水號, DataID, 員工名稱, 出勤日期, 星期, 第1班上班, 第1班下班, 第1班合計, 第2班上班, 第2班下班, 第2班合計, 第3班上班, 第3班下班, 第3班合計, " &
- "第1班合計 + 第2班合計 + 第3班合計 AS 上班時長, 第1班合計 + 第2班合計 AS 應上班 FROM 考勤資料庫 " &
- "WHERE (出勤日期 LIKE '" & ComboBox3.Text & "-" & ComboBox1.Text & "%') ORDER BY DataID, 出勤日期"
- 列印用SQL = SQL1
- 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 Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- 導出成EXCEL.Show()
- End Sub
- End Class
|