Нема описа
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 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  8. Dim dr As SqlDataReader
  9. Dim STR1 As String
  10. Dim dt As DateTime
  11. Dim DTP As String
  12. Dim aa As MsgBoxResult
  13. Dim QQWQ As String
  14. Private Sub Set_日期清單()
  15. DataGridView2.DataSource = Nothing : ds1.Clear()
  16. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  17. DataGridView2.ColumnHeadersHeight = 25
  18. DataGridView2.AllowUserToAddRows = False
  19. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  20. If PA = "" Then
  21. SQL1 = "SELECT 已有考勤日期 AS 日期 FROM 已有考勤日期 ORDER BY 日期 DESC"
  22. Else
  23. SQL1 = "SELECT 已有考勤日期 AS 日期 FROM 已有考勤日期 WHERE 已有考勤日期 LIKE '%" & PA & "%' ORDER BY 日期 DESC"
  24. End If
  25. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
  26. Set_grid1()
  27. End Sub
  28. Private Sub Set_grid1()
  29. DataGridView2.Columns(0).Width = 80
  30. End Sub
  31. Private Sub Set_清單()
  32. DataGridView1.DataSource = Nothing : ds.Clear()
  33. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  34. DataGridView1.ColumnHeadersHeight = 25
  35. DataGridView1.AllowUserToAddRows = False
  36. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  37. SQL1 = "SELECT 資料流水號, DataID, 員工名稱, 出勤日期, 星期, 第1班上班, 第1班下班, 第1班合計, 第2班上班, 第2班下班, 第2班合計, 第3班上班, 第3班下班, 第3班合計, " &
  38. "第1班合計 + 第2班合計 + 第3班合計 AS 上班時長, 第1班合計 + 第2班合計 AS 應上班 FROM 考勤資料庫 " &
  39. "WHERE (出勤日期 LIKE '" & TextBox1.Text & "') ORDER BY DataID"
  40. 列印用SQL = SQL1
  41. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  42. Set_grid()
  43. End Sub
  44. Private Sub Set_grid()
  45. DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Width = 70
  46. DataGridView1.Columns(3).Width = 80 : DataGridView1.Columns(4).Width = 60 : DataGridView1.Columns(5).Width = 70 : DataGridView1.Columns(6).Width = 70
  47. DataGridView1.Columns(7).Width = 70 : DataGridView1.Columns(8).Width = 70 : DataGridView1.Columns(9).Width = 80 : DataGridView1.Columns(10).Width = 80
  48. DataGridView1.Columns(11).Width = 80 : DataGridView1.Columns(12).Width = 80 : DataGridView1.Columns(13).Width = 80 : DataGridView1.Columns(14).Width = 80
  49. DataGridView1.Columns(15).Width = 80 : Set_自動彙總1()
  50. End Sub
  51. Private Sub Set_自動彙總1()
  52. Dim 加總(4) As Double : Dim EU(11) As Double
  53. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  54. 加總(0) += DataGridView1.Rows(i).Cells("第1班合計").Value : 加總(1) += DataGridView1.Rows(i).Cells("第2班合計").Value : 加總(2) += DataGridView1.Rows(i).Cells("第3班合計").Value
  55. 加總(3) += DataGridView1.Rows(i).Cells("上班時長").Value : 加總(4) += DataGridView1.Rows(i).Cells("應上班").Value
  56. Next i
  57. TextBox3.Text = Format(Val(加總(0)), "#,##0.0") : TextBox4.Text = Format(Val(加總(1)), "#,##0.0") : TextBox5.Text = Format(Val(加總(2)), "#,##0.0")
  58. TextBox6.Text = Format(Val(加總(3)), "#,##0.0") : TextBox7.Text = Format(Val(加總(4)), "#,##0.0")
  59. End Sub
  60. Private Sub 考勤管理_依日期_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  61. Me.MdiParent = 楠晉鞋業AAS : Me.AutoScroll = True
  62. Set_日期清單()
  63. TextBox1.Visible = False
  64. ComboBox3.Text = Year(Today) : ComboBox1.SelectedIndex = Month(Today) - 1
  65. End Sub
  66. Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  67. TextBox1.Text = DataGridView2.Rows(e.RowIndex).Cells("日期").Value.ToString
  68. QQWQ = "0"
  69. Set_清單()
  70. End Sub
  71. Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  72. If QQWQ = "1" Then
  73. Dim linePen As New Pen(Color.Blue, 2)
  74. If e.RowIndex = DataGridView1.Rows.Count - 1 Then
  75. Exit Sub
  76. Else
  77. If DataGridView1(2, e.RowIndex).Value.ToString <> DataGridView1(2, e.RowIndex + 1).Value.ToString Then
  78. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  79. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  80. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  81. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  82. Exit Sub
  83. End If
  84. End If
  85. End If
  86. End Sub
  87. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  88. PA = InputBox("請輸入要查詢的日期") : Set_日期清單() : PA = ""
  89. End Sub
  90. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  91. QQWQ = "1"
  92. DataGridView1.DataSource = Nothing : ds.Clear()
  93. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  94. DataGridView1.ColumnHeadersHeight = 25
  95. DataGridView1.AllowUserToAddRows = False
  96. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  97. SQL1 = "SELECT 資料流水號, DataID, 員工名稱, 出勤日期, 星期, 第1班上班, 第1班下班, 第1班合計, 第2班上班, 第2班下班, 第2班合計, 第3班上班, 第3班下班, 第3班合計, " &
  98. "第1班合計 + 第2班合計 + 第3班合計 AS 上班時長, 第1班合計 + 第2班合計 AS 應上班 FROM 考勤資料庫 " &
  99. "WHERE (出勤日期 LIKE '" & ComboBox3.Text & "-" & ComboBox1.Text & "%') ORDER BY DataID, 出勤日期"
  100. 列印用SQL = SQL1
  101. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  102. Set_grid()
  103. End Sub
  104. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  105. 導出成EXCEL.Show()
  106. End Sub
  107. End Class