-3
我试图让员工登录,如果他们使用按钮,保存用户名和时间来保存多次不同的时间戳这样的行:检查输入的值是否存在如果是防止保存它其他
现在我想,以防止用户通过它们在数据库进入考勤多次作出username
和comedata
之间的关系,以确保用户只能每天签上自己的出勤一次。
例
伪代码:
If username = ComeForm_CGUserName_TextBox.Text
And CGComeDate = ComeForm_CGComeDate_DateTimePicker.Value
And username Is In DB And CGComeDate Is In DataBase
Then
MsgBox("You have already signed your attendace")
Else
Insert data into DataBase easy
End If
这就是我认为它需要遵循,以防止在数据库中的多个条目的逻辑。
,目前是完整的代码ComeGo形式
Public Con As New SqlConnection("Data Source=(localdb)\ProjectsV13;Initial Catalog=Euro_SQL_Server;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")
Public ComeGoDT As New DataTable
Public ComeGoDA As New SqlDataAdapter
Public MyNewComeGoID As Integer
Public Sub Load_ComeGo()
ComeGoDT.Clear()
ComeGoDA = New SqlDataAdapter("select * from ComeGo", Con)
ComeGoDA.Fill(ComeGoDT)
End Sub
Public Sub Code_ComeGo()
Dim dt As New DataTable
Dim da As New SqlDataAdapter("select max(CGID) from ComeGo", Con)
da.Fill(dt)
If IsDBNull(dt(0)(0)) = True Then
MyNewComeGoID = 1
Else
MyNewComeGoID = dt(0)(0) + 1
End If
End Sub
Public Sub NewComeGo()
Code_ComeGo()
'Auto Generate EmployeesID
ComeForm_CGID_TextBox.Text = MyNewComeGoID
'Clearing Fields
ComeForm_CGComeDate_DateTimePicker.Value = Now.Date
ComeForm_CGComeTime_DateTimePicker.Value = Now
ComeForm_CGUserName_TextBox.Text = MangersMainMenu.MangersMainMenu_CurrentUserResult_Label.Text
ComeForm_CGNotes_TextBox.Text = ""
'Auto Generate ActionBy From Logged In UserFullName
ComeForm_ActionBy_TextBox.Text = MangersMainMenu.MangersMainMenu_CurrentUserResult_Label.Text
End Sub
Private Sub ComeForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Load EditComeGo_Form From EURO_DataBase
Load_ComeGo()
'Clear Fields
NewComeGo()
End Sub
Private Sub ComeForm_ComeSign_Button_Click(sender As Object, e As EventArgs) Handles ComeForm_ComeSign_Button.Click
'Definition Adding New ComeGo Method
ComeGoDT.Rows.Add()
Dim last As Integer = ComeGoDT.Rows.Count - 1
'Match Each Filed On The DataBase With There Filed On The Table
ComeGoDT.Rows(last).Item("CGID") = ComeForm_CGID_TextBox.Text
ComeGoDT.Rows(last).Item("CGDate") = Now.Date
ComeGoDT.Rows(last).Item("CGTime") = Now
ComeGoDT.Rows(last).Item("CGUserName") = MangersMainMenu.MangersMainMenu_CurrentUserResult_Label.Text
ComeGoDT.Rows(last).Item("CGComeDate") = ComeForm_CGComeDate_DateTimePicker.Value
ComeGoDT.Rows(last).Item("CGComeTime") = ComeForm_CGComeTime_DateTimePicker.Value
ComeGoDT.Rows(last).Item("CGNotes") = ComeForm_CGNotes_TextBox.Text
ComeGoDT.Rows(last).Item("ActionBy") = MangersMainMenu.MangersMainMenu_CurrentUserResult_Label.Text
'Definition Saving New Changes Method
Dim save As New SqlCommandBuilder(ComeGoDA)
'Refresh ComeGo DataBase Table
ComeGoDA.Update(ComeGoDT)
ComeGoDT.AcceptChanges()
'Show Massage Box
MsgBox("تم تسجيل حضور الموظف")
'Reload ComeGo Table With New UpDates
Load_ComeGo()
'Start New ComeGo Entery
NewComeGo()
End Sub
这是保存按钮
Private Sub ComeForm_ComeSign_Button_Click(sender As Object, e As EventArgs) Handles ComeForm_ComeSign_Button.Click
'Definition Adding New ComeGo Method
ComeGoDT.Rows.Add()
Dim last As Integer = ComeGoDT.Rows.Count - 1
'Match Each Filed On The DataBase With There Filed On The Table
ComeGoDT.Rows(last).Item("CGID") = ComeForm_CGID_TextBox.Text
ComeGoDT.Rows(last).Item("CGDate") = Now.Date
ComeGoDT.Rows(last).Item("CGTime") = Now
ComeGoDT.Rows(last).Item("CGUserName") = MangersMainMenu.MangersMainMenu_CurrentUserResult_Label.Text
ComeGoDT.Rows(last).Item("CGComeDate") = ComeForm_CGComeDate_DateTimePicker.Value
ComeGoDT.Rows(last).Item("CGComeTime") = ComeForm_CGComeTime_DateTimePicker.Value
ComeGoDT.Rows(last).Item("CGNotes") = ComeForm_CGNotes_TextBox.Text
ComeGoDT.Rows(last).Item("ActionBy") = MangersMainMenu.MangersMainMenu_CurrentUserResult_Label.Text
'Definition Saving New Changes Method
Dim save As New SqlCommandBuilder(ComeGoDA)
'Refresh ComeGo DataBase Table
ComeGoDA.Update(ComeGoDT)
ComeGoDT.AcceptChanges()
'Show Massage Box
MsgBox("تم تسجيل حضور الموظف")
'Reload ComeGo Table With New UpDates
Load_ComeGo()
'Start New ComeGo Entery
NewComeGo()
End Sub