Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

人事考勤打卡.vb 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 人事考勤打卡
  4. Private Property MYSQL As String
  5. Dim conn As New SqlConnection
  6. Dim da As New SqlDataAdapter
  7. Dim cmd As New SqlCommand
  8. Dim ds As New DataSet : Dim ds1 As New DataSet
  9. Dim dr As SqlDataReader
  10. Dim DTP As String : Dim DTP1 As String
  11. Dim 有無資料判別 As String = ""
  12. Private Sub 人事考勤打卡_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  13. ConString = "Data Source=192.168.10.5;Initial Catalog=METO-MES-SYS;Persist Security Info=True;User ID=b70340;Password=0911274990;Max pool size = 200;Connection Timeout=0"
  14. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  15. Label1.Text = Year(Today) : Label3.Text = Month(Today) : Label5.Text = Strings.Right(Format(Today(), "yyyy/MM/dd"), 2) : Label7.Text = Format(TimeOfDay(), "HH:mm:ss")
  16. If Val(Strings.Left(Label7.Text, 2)) < 12 Then : Label14.Text = "上午上班" : Else : Label14.Text = "下午下班" : End If
  17. Label16.Text = "" : Label18.Text = "" : Label10.Text = "" : Label12.Text = "" : Button1.Text = "打卡系統運行中"
  18. Label1.BackColor = Color.Transparent : Label2.BackColor = Color.Transparent : Label3.BackColor = Color.Transparent : Label4.BackColor = Color.Transparent : Label5.BackColor = Color.Transparent
  19. Label6.BackColor = Color.Transparent : Label7.BackColor = Color.Transparent : Label8.BackColor = Color.Transparent : Label9.BackColor = Color.Transparent : Label10.BackColor = Color.Transparent
  20. Label11.BackColor = Color.Transparent : Label12.BackColor = Color.Transparent : Label13.BackColor = Color.Transparent : Label14.BackColor = Color.Transparent : Label15.BackColor = Color.Transparent
  21. Label16.BackColor = Color.Transparent : Label17.BackColor = Color.Transparent : Label18.BackColor = Color.Transparent
  22. Label7.Visible = False
  23. End Sub
  24. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  25. Label16.Text = "" : Label18.Text = "" : Label10.Text = "" : Label12.Text = "" : Button1.Text = "打卡系統運行中"
  26. Timer1.Enabled = False
  27. End Sub
  28. Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
  29. If TextBox2.Text <> "" Then
  30. Label10.Text = "" : Label12.Text = ""
  31. End If
  32. Label1.Text = Year(Today) : Label3.Text = Month(Today) : Label5.Text = Strings.Right(Format(Today(), "yyyy/MM/dd"), 2) : Label7.Text = Format(TimeOfDay(), "HH:mm:ss")
  33. If Val(Strings.Left(Label7.Text, 2)) < 12 Then : Label14.Text = "上午上班" : Else : Label14.Text = "下午下班" : End If
  34. If IsNumeric(TextBox2.Text) = True Then
  35. If TextBox2.Text.Length = 10 Then
  36. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  37. MYSQL = "SELECT 姓名, 員工編號 FROM 使用者權限管理表 WHERE (ID卡號 = '" & TextBox2.Text & "')"
  38. cmd.Connection = conn : cmd.CommandText = MYSQL : dr = cmd.ExecuteReader
  39. If dr.Read() Then
  40. Label16.Text = dr("姓名").ToString
  41. Label18.Text = dr("員工編號").ToString
  42. conn.Close()
  43. Else
  44. TextBox2.Text = "" : TextBox2.Focus() : conn.Close()
  45. End If
  46. Timer1.Enabled = False
  47. Me.Button1.PerformClick()
  48. End If
  49. End If
  50. End Sub
  51. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  52. Me.Close()
  53. End Sub
  54. Private Sub Set_日期格式轉換()
  55. DTP = Format(Today(), "yyyy/MM/dd")
  56. End Sub
  57. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  58. Timer1.Enabled = True
  59. Label7.Text = Format(TimeOfDay(), "HH:mm:ss")
  60. Dim 判斷請假 As String = "" : Button1.Text = "打卡系統運行中"
  61. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  62. SQL1 = "SELECT 請假類別 FROM 人事考勤明細表 WHERE 員工編號 LIKE '" & Label18.Text & "' AND 日期 LIKE '" & Format(Today(), "yyyy/MM/dd") & "'"
  63. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  64. If dr.Read() Then : 判斷請假 = dr("請假類別").ToString : End If : conn.Close()
  65. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  66. SQL1 = "SELECT 上午上班, 下午下班 FROM 人事考勤明細表 WHERE 員工編號 LIKE '" & Label18.Text & "' AND 日期 LIKE '" & Format(Today(), "yyyy/MM/dd") & "'"
  67. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  68. If dr.Read() Then : Label10.Text = dr("上午上班").ToString : Label12.Text = dr("下午下班").ToString : End If : conn.Close()
  69. If Label10.Text = "XXX" Or Label10.Text = "" Then : Label10.Text = "未打卡" : End If : If Label12.Text = "XXX" Or Label12.Text = "" Then : Label12.Text = "未打卡" : End If
  70. If Strings.Right(判斷請假, 2) = "一天" Then
  71. Button1.Text = "本日請假中,無法打卡"
  72. Else
  73. If Label18.Text = "" Then
  74. Button1.Text = "該帳號持有人無需打卡"
  75. Else
  76. Set_日期格式轉換()
  77. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  78. SQL1 = "SELECT 員工編號 FROM 人事考勤明細表 WHERE 員工編號 LIKE '" & Label18.Text & "' AND 日期 LIKE '" & Format(Today(), "yyyy/MM/dd") & "'"
  79. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  80. If dr.Read() Then : 有無資料判別 = dr("員工編號").ToString : End If : conn.Close()
  81. If 有無資料判別 = "" And Label14.Text = "上午上班" Then
  82. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  83. SQL1 = "INSERT INTO 人事考勤明細表 (員工編號, 日期, 請假類別, 上午上班, 下午下班) SELECT N'" & Label18.Text & "',N'" & DTP & "',N'','" & Format(TimeOfDay(), "HH:mm:ss") & "',''"
  84. Label10.Text = Format(TimeOfDay(), "HH:mm:ss")
  85. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  86. Button1.Text = "打卡成功"
  87. ElseIf 有無資料判別 = "" And Label14.Text = "下午下班" Then
  88. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  89. SQL1 = "INSERT INTO 人事考勤明細表 (員工編號, 日期, 請假類別, 上午上班, 下午下班) SELECT N'" & Label18.Text & "',N'" & DTP & "',N'','','" & Format(TimeOfDay(), "HH:mm:ss") & "'"
  90. Label12.Text = Format(TimeOfDay(), "HH:mm:ss")
  91. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  92. Button1.Text = "打卡成功"
  93. ElseIf 有無資料判別 <> "" And Label14.Text = "上午上班" Then
  94. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  95. SQL1 = "UPDATE 人事考勤明細表 SET 上午上班 = '" & Format(TimeOfDay(), "HH:mm:ss") & "' WHERE (員工編號 = '" & Label18.Text & "') AND (日期 LIKE '" & Format(Today(), "yyyy/MM/dd") & "')"
  96. Label10.Text = Format(TimeOfDay(), "HH:mm:ss")
  97. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  98. Button1.Text = "打卡成功"
  99. ElseIf 有無資料判別 <> "" And Label14.Text = "下午下班" Then
  100. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  101. SQL1 = "UPDATE 人事考勤明細表 SET 下午下班 = '" & Format(TimeOfDay(), "HH:mm:ss") & "' WHERE (員工編號 = '" & Label18.Text & "') AND (日期 LIKE '" & Format(Today(), "yyyy/MM/dd") & "')"
  102. Label12.Text = Format(TimeOfDay(), "HH:mm:ss")
  103. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  104. Button1.Text = "打卡成功"
  105. Else
  106. Button1.Text = "打卡失敗,請再試一下。"
  107. End If
  108. End If
  109. End If
  110. TextBox2.Text = "" : TextBox2.Focus()
  111. End Sub
  112. End Class