Displaying Forms With Strings - mysql

How do I get all messages before showing a form, and display this form one by one?
First of all, I have a program that gets an entry if the "Client" is already checked out or if a reservation of a client has already expired. With this method, I will get their transaction number and client number in put their infos in a form and display it. Notice that I have a different form for EXPIRED RESERVATION and CHECK OUT
Can someone check my program? Here is my code for getting the client if his/her check in has expired.
Public Sub computeRemainingDaysForCheckedIns()
Dim computedDays As Integer
Dim dateNow As Date = Date.Now.ToString("yyyy-MM-dd")
Try
mysqlconn = New MySqlConnection(con)
mysqlconn.Open()
query = "select TransactionNumber, ClientNumber, DATEDIFF(dateout,curdate()) as 'ComputedDays' from dbo_transactions where ClientStatus = 'Checked In'"
cmd = New MySqlCommand(query, mysqlconn)
rd = cmd.ExecuteReader
If rd.HasRows Then
'hasRows ibig sabhin mayLAMAN ung table
While rd.Read
computedDays = rd.GetString("ComputedDays")
'Console.WriteLine(computedDays)
If computedDays > 0 Then
getTransactionNumber = ""
getClientNumber = ""
ElseIf computedDays < 0 Then
getTransactionNumber = rd.GetString("TransactionNumber")
getClientNumber = rd.GetString("ClientNumber")
iTitle = "CHECK OUT CLIENT."
iMessage.AppendLine("* Client: " & getClientNumber & ", Transaction: " & getTransactionNumber & " *")
isCNotifShowed = True
End If
End While
'notificationFormC.Show()
Else
'no data
End If
mysqlconn.Close()
Catch ex As Exception
isCNotifShowed = False
MsgBox("Something Went Wrong!" & vbNewLine &
ex.Message, MsgBoxStyle.Exclamation)
Finally
mysqlconn.Dispose()
End Try
End Sub
Public Sub computeRemainingDaysForReservations()
Dim computedDays As Integer
Try
mysqlconn = New MySqlConnection(con)
mysqlconn.Open()
query = "Select TransactionNumber, ClientNumber, DATEDIFF(DateIn, CURDATE()) as 'ComputedDays' from dbo_transactions where ClientStatus = 'Reserved'"
cmd = New MySqlCommand(query, mysqlconn)
rd = cmd.ExecuteReader
If rd.HasRows Then
'hasRows ibig sabhin mayLAMAN ung table
While rd.Read
computedDays = rd.GetString("ComputedDays")
'Console.WriteLine(computedDays)
If computedDays > 0 Then
getTransactionNumber = ""
getClientNumber = ""
ElseIf computedDays <= 0 Then
getTransactionNumber = rd.GetString("TransactionNumber")
getClientNumber = rd.GetString("ClientNumber")
iiTitle = "RESERVATION IS ALREADY EXPIRED."
iiMessage.AppendLine("* " & getClientNumber & ", Transaction: " & getTransactionNumber & " *")
isRNotifShowed = True
End If
End While
Else
'no data
End If
rd.Close()
mysqlconn.Close()
Catch ex As Exception
isRNotifShowed = False
MsgBox("Something Went Wrong!" & vbNewLine &
ex.Message, MsgBoxStyle.Exclamation)
Finally
mysqlconn.Dispose()
End Try
End Sub
then for displaying the client using a form
Private Sub RepeatProcess()
computeRemainingDaysForReservations()
computeRemainingDaysForCheckedIns()
If iMessage.Length <> 0 Then
ElseIf iiMessage.Length <> 0 Then
End If
'If isCNotifShowed = True Then
'notificationFormC.Show()
'ElseIf isRNotifShowed = True Then
' notificationFormR.Show()
'Else
'End If
End Sub
Private Sub timerTask_Tick_1(sender As Object, e As EventArgs) Handles timerTask.Tick
tCount += 1
If tCount = tSecs Then
Call RepeatProcess()
tCount = 0 'reset
End If
End Sub

Perhaps this is not the best way of doing this. Opening a new form/pop-up/whatever for every booking that is out of date could potentially suck up all of your resources.
I would recommend that you display a GridView, DataGrid, ListView or similar (we're still chiselling stone tablets out in VS2008, so I'm not sure what extremes of technology there are in more recent versions!). The code behind could be written to highlight the problem records in a different colour so that they are more obvious.
To do this you'd simply need to create a DataSource on your form with the relevant query(ies) then display the results in a the appropriate data enabled grid.

Related

Database Saves and Shows In Access While Program Still Running , But When I Close And Run Again , I Will Have To Sign Up Again Then Login

Good day to everyone,
I'm working on my final project, and i've created a signin and signup form, where the user will have to singup the first time he or she tries to login, But here is the case when i signup, the account will be created and i'll be able to login with the details used in creating the account, but immediately i close the program as i am still working on the project, then i try to run again, i'll have to signup again in other to move on to the next step.
My question here is that, is it because i'm still working on the program that is why the data isn't saving, so when i'm done then i build the project, i wont face that issue, or i'm missing something.
i want the data used in creating the account be saved in the database, so that the user wont have to be signing up everytime the program is runned.
Please any help, project needs to submitted within this week...
The codes are below:
Private Sub loginsignin_Click(sender As Object, e As EventArgs) Handles loginsignin.Click
If txtloginusername.Text = Nothing Or txtloginpass.Text = Nothing Then
MessageBox.Show("Please enter credentials", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If con.State = ConnectionState.Closed Then
con.Open()
End If
Using Command As New OleDbCommand("SELECT COUNT(*) FROM tbllogin WHERE uname = #loginusername AND pass = #loginpass", con)
Command.Parameters.AddWithValue("#uname", OleDbType.VarChar).Value = txtloginusername.Text.Trim
Command.Parameters.AddWithValue("#pass", OleDbType.VarChar).Value = txtloginpass.Text.Trim
Dim count = Convert.ToInt32(Command.ExecuteScalar())
If count > 0 Then
Me.Hide()
Dashboard.Show()
Else
MessageBox.Show("Oops!, Invalid Credentials", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
con.Close()
End Sub
Private Sub btnsignup_Click(sender As Object, e As EventArgs) Handles btnsignup.Click
If txtfname.Text = Nothing Or txtlname.Text = Nothing Or txtuname.Text = Nothing Or txtmobile.Text = Nothing Or txtpass.Text = Nothing Then
MessageBox.Show("Please enter credentials", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If txtmobile.Text.Length < 10 Then
MessageBox.Show("Invalid Telephone Number!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If con.State = ConnectionState.Closed Then
con.Open()
End If
Using command As New OleDbCommand("SELECT COUNT(*) FROM tbllogin WHERE mobile = #mobile", con)
command.Parameters.Add(New OleDb.OleDbParameter("#mobile", OleDbType.VarChar)).Value = txtmobile.Text
Dim count = Convert.ToInt32(command.ExecuteScalar())
If count > 0 Then
MessageBox.Show("Oops!, Preregistered Telephone Number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
End Using
Using create As New OleDbCommand("INSERT INTO tbllogin ([uname], [pass], [mobile], [fname], [lname]) VALUES (#uname,
#pass, #mobile, #fname, #lname)", con)
create.Parameters.Add(New OleDb.OleDbParameter(“#uname”, OleDbType.VarChar)).Value = txtuname.Text
create.Parameters.Add(New OleDb.OleDbParameter("#pass", OleDbType.VarChar)).Value = txtpass.Text
create.Parameters.Add(New OleDb.OleDbParameter("#mobile", OleDbType.VarChar)).Value = txtmobile.Text
create.Parameters.Add(New OleDb.OleDbParameter("#fname", OleDbType.VarChar)).Value = txtfname.Text
create.Parameters.Add(New OleDb.OleDbParameter("#lname", OleDbType.VarChar)).Value = txtlname.Text
If create.ExecuteNonQuery Then
MessageBox.Show("Account created", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MsgBox("Registration Failed.")
End If
End Using
End Sub
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtfname.Text = ""
End Sub

VB.NET Refresh DataGridView function works with insert and delete commands but not with update

I have a form on VB.NET with which I manage data for a mysql database.
The form, in addition to the various fields for entering data (textboxes + 1 datepicker), includes a "Save" button (which turns into "Update" when I press the "Edit" button), an "Edit" button, a "Delete" button and a DataGridView.
I have created a ShowData () to display the data in the DataGridView.
This function works on the form load, it works also when I use the "Save" command (with the mysql Insert command) and the "Delete" command (with the mysql Delete command) but it seems to create problems when I use the "Update" command.
When I use the "Update" command the data is updated in the database but the "ShowData ()" function gives me the error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 and, consequently, the data inside the DataGridView is not updated.
The "ShowData ()" function is also present on the "CellMouseDown" event of the DataGridView. The same error only shows up when I use the "Update" command first and then I move through the rows.
Public Class
Dim Connection As New MySqlConnection("server=localhost; user=root; password=; database=dbname")
Dim MySQLCMD As New MySqlCommand
Dim MySQLDA As New MySqlDataAdapter
Dim DT As New DataTable
Dim Table_Name As String = "tablename"
Dim Dati As Integer
Dim LoadImagesStr As Boolean = False
Dim data1Ram, data2Ram As String
Dim StatusInput As String = "Save"
Dim SqlCmdSearchstr As String
ShowData()
Try
Connection.Open()
Catch ex As Exception
MessageBox.Show("Connection failed !!!" & vbCrLf & "Please check that the server is ready !!!", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
MySQLCMD.CommandType = CommandType.Text
MySQLCMD.CommandText = "SELECT data1,data2 FROM " & Table_Name & " WHERE cid=" & cid.Text & ""
MySQLDA = New MySqlDataAdapter(MySQLCMD.CommandText, Connection)
DT = New DataTable
Dati = MySQLDA.Fill(DT)
If Dati > 0 Then
DataGridView1.DataSource = Nothing
DataGridView1.DataSource = DT
DataGridView1.DefaultCellStyle.ForeColor = Color.Black
DataGridView1.ClearSelection()
Else
DataGridView1.DataSource = DT
End If
Catch ex As Exception
MsgBox("Connection Error !!!" & vbCr & ex.Message, MsgBoxStyle.Critical, "Error Message")
Connection.Close()
Return
End Try
DT = Nothing
Connection.Close()
Save/Update Button Click
Dim mstream As New System.IO.MemoryStream()
If StatusInput = "Save" Then
Try
Connection.Open()
Catch ex As Exception
MessageBox.Show("Connection Failed" & vbCrLf & "Check internet connection !!!", "No connection", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
MySQLCMD = New MySqlCommand
With MySQLCMD
.CommandText = "INSERT INTO " & Table_Name & " (data1, data2) VALUES (#data1, #data2)"
.Connection = Connection
.Parameters.AddWithValue("#data1", textbox1.Text)
.Parameters.AddWithValue("#data2", textbox2.Text)
.ExecuteNonQuery()
End With
MsgBox("Data saved successfully", MsgBoxStyle.Information, "Information")
ClearInputUpdateData()
Catch ex As Exception
MsgBox("Data failed to save !!!" & vbCr & ex.Message, MsgBoxStyle.Critical, "Error Message")
Connection.Close()
Return
End Try
Connection.Close()
Else
Try
Connection.Open()
Catch ex As Exception
MessageBox.Show("Connection failed !!!" & vbCrLf & "Please check that the server is ready !!!", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
MySQLCMD = New MySqlCommand
With MySQLCMD
.CommandText = "UPDATE " & Table_Name & " SET `data1` = #data1, `data2` = #data2 WHERE id=#id"
.Connection = Connection
.Parameters.AddWithValue("#data1", textbox1.Text)
.Parameters.AddWithValue("#data2", textbox2.Text)
.Parameters.AddWithValue("#id", id.Text)
.ExecuteNonQuery()
End With
MsgBox("Data updated successfully", MsgBoxStyle.Information, "Information")
ButtonSave.Text = "Save"
DatePicker1.Enabled = True
ClearInputUpdateData()
Catch ex As Exception
MsgBox("Data failed to Update !!!" & vbCr & ex.Message, MsgBoxStyle.Critical, "Error Message")
Connection.Close()
Return
End Try
Connection.Close()
StatusInput = "Save"
End If
ShowData()
Edit Button Click
If DataGridView1.RowCount = 1 Then
textbox1.Text = data1Ram
textbox2.Text = data2Ram
ButtonSave.Text = "Update"
StatusInput = "Update"
Return
End If
DataGridView1 CellMouseDown
Try
If AllCellsSelected(DataGridView1) = False Then
If e.Button = MouseButtons.Left Then
DataGridView1.CurrentCell = DataGridView1(e.ColumnIndex, e.RowIndex)
Dim i As Integer
With DataGridView1
If e.RowIndex >= 0 Then
i = .CurrentRow.Index
LoadImagesStr = True
data1Ram = .Rows(i).Cells("data1").Value.ToString
data2Ram = .Rows(i).Cells("data2").Value.ToString
ShowData()
End If
End With
End If
End If
Catch ex As Exception
Return
End Try
EDIT 1
As the error message explains, this is a command syntax problem.
In fact, I tried replacing this string in ShowData()
"SELECT data1,data2 FROM " & Table_Name & " WHERE cid=" & cid.Text & ""
with this
"SELECT data1,data2 FROM tablename WHERE cid = 10"
and no errors appear.
So I need to figure out how to put the table name and conditions inside the command string
As the error message explains, this is a command syntax problem.
In fact, I tried replacing this string in ShowData()
"SELECT data1,data2 FROM " & Table_Name & " WHERE cid=" & cid.Text & ""
with this
"SELECT data1,data2 FROM tablename WHERE cid = 10"
and no errors appear.
So I need to figure out how to put the table name and conditions inside the command string
Edit
Solved.
Thanks to comments. Connections and Commands need to be declared and disposed in the method where they are used. Do not declare then outside this method.

Update Query is being skipped in if statement vb.net

I don't now why the method is being skipped in the if statement Can anybody help me with this problem?
here's the update sql query
Public Sub Edituser()
conn()
dbconn.Open()
sql = "UPDATE player SET First Name=#1 Last Name=#2, Gender=#3, Date of Birth=#4, Civil Status=#5, Nationality=#6, Address=#7, Status=#8 WHERE ID = " + TextBox8.Text + ""
Try
dbcomm = New MySqlCommand(sql, dbconn)
dbcomm.Parameters.Add(New MySqlParameter("#1", TextBox1.Text))
dbcomm.Parameters.Add(New MySqlParameter("#2", TextBox2.Text))
dbcomm.Parameters.Add(New MySqlParameter("#3", TextBox9.Text))
dbcomm.Parameters.Add(New MySqlParameter("#4", TextBox3.Text))
dbcomm.Parameters.Add(New MySqlParameter("#5", TextBox4.Text))
dbcomm.Parameters.Add(New MySqlParameter("#6", TextBox5.Text))
dbcomm.Parameters.Add(New MySqlParameter("#7", TextBox6.Text))
dbcomm.Parameters.Add(New MySqlParameter("#8", TextBox7.Text))
dbread = dbcomm.ExecuteReader()
dbread.Close()
MsgBox("Successfully updated!")
Catch ex As Exception
Finally
dbconn.Close()
End Try
End Sub
and here's the if statement
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox9.Text = "" Then
MsgBox("Please complete all the fields")
Else
Dim result As Integer = MessageBox.Show("Are you sure you want to Edit the information?", "Update", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If result = DialogResult.OK Then
Edituser()
MsgBox(" Player information Updated!")
Me.Close()
Player.Show()
End If
End If
End Sub
Thanks in advance.
Your UPDATE statement is syntactically wrong as it's missing , and proper quoting for column names as pointed below
sql = "UPDATE player SET `First Name`=#1, `Last Name`=#2, Gender=#3, `Date of Birth`=#4,
sub is called edituser, you are calling editplayer?
ok. you are squashing the error in the empty catch block. most likely you are hitting a sql error passing the date parameter as a string.
you would need to remove the try catch to get a look at the error message, or output it to console/msgbox.
also what #Rahul says also is correct. possibly combination of both.

Limiting the time in and time out in a day in VB.NET?

I have developed a time monitoring system using fingerprint where the employee will scan his/her finger then it will record the time in and time out. But my problem is logging in and logging out by the employee is unlimited. Is there a solution where the employee can log in and log out ONCE IN A DAY? Every employee will log in and log out once. Here is my code for my Daily Time Record Form: (Im using visual studio 2010/Digital Persona UareU for my scanner)
Imports MySql.Data.MySqlClient
Imports System.Windows.Forms
Imports DPFP
Public Class frmDTR
Dim counter As Integer = 0
Dim oConn As New MySqlConnection(ConnectionString.ConnString)
Private matcher As DPFP.Verification.Verification
Private matchResult As DPFP.Verification.Verification.Result
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Me.Close()
End Sub
Public Sub SEARCH_EMPLOYEE()
Try
'Load From DB
GlobalFunctions.db_connect()
Dim reader As MySqlDataReader
Dim command As MySqlCommand = connection.CreateCommand()
command.CommandText = "SELECT * FROM employee_records WHERE ID_Number='" & strid & "'" 'check tag number if existing
reader = command.ExecuteReader()
If (reader.HasRows) Then
While (reader.Read())
With Me
'plot the data into controls
.txtID.Text = reader(1).ToString
.txtFirst.Text = reader(2).ToString
.txtMiddle.Text = reader(3).ToString
.txtLast.Text = reader(4).ToString
.txtAge.Text = reader(5).ToString
.txtBday.Text = reader(6).ToString
.txtDepartment.Text = reader(7).ToString
.txtYear.Text = reader(8).ToString
.txtGender.Text = reader(9).ToString
.txtContact.Text = reader(10).ToString
.txtMobile.Text = reader(11).ToString
.txtEmail.Text = reader(12).ToString
'fetch image from database
Dim imgBytes() As Byte = reader("image") 'image field
Dim image As Bitmap = New Bitmap(New System.IO.MemoryStream(imgBytes)) 'convert binary to image
.ProfilePic.Image = image 'show picture to picture box
End With
Call LOG_EMP() 'look up if login /log out
Timer1.Enabled = True
End While
Else
'Me.lblStatus.Text = "ID not recognized!"
End If
Catch ex As Exception
MessageBox.Show("Error scanning: " & ex.Message)
End Try
GlobalFunctions.connection.Close()
End Sub
Public Sub LOG_EMP()
Try
' Load From DB
GlobalFunctions.db_connect()
Dim reader As MySqlDataReader
Dim command As MySqlCommand = connection.CreateCommand()
command.CommandText = "SELECT * FROM employee_logs WHERE ID_Number='" & strid & "' AND Time_Out='Null'"
reader = command.ExecuteReader()
If (reader.HasRows) Then
While (reader.Read())
End While
'logout
Call EMP_LOGOUT()
Else
'log in
Call EMPT_LOGIN()
End If
Catch ex As Exception
MessageBox.Show("Error scanning: " & ex.Message)
End Try
GlobalFunctions.connection.Close()
End Sub
'insert login data
Public Sub EMPT_LOGIN()
' Connect to Database
GlobalFunctions.db_connect()
Dim command As MySqlCommand
Dim transaction As MySqlTransaction
transaction = GlobalFunctions.connection.BeginTransaction()
Try
command = New MySqlCommand("INSERT INTO employee_logs values('','" & txtID.Text & "','" & txtFirst.Text & "','" & txtMiddle.Text & "','" & txtLast.Text & "','" & txtDepartment.Text & "','" & Date.Today & "','" & TimeOfDay & "','Null') ", GlobalFunctions.connection, transaction)
command.ExecuteNonQuery()
transaction.Commit()
'sms = txtFirst.Text & " Enter the Building Premises #" & Now 'actual sms
lblStatus.ForeColor = Color.Lime
Dim SAPI
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Welcome!" & txtFirst.Text)
Me.lblStatus.Text = "Successfully Logged IN! Welcome!" 'set status to login
'Will_SendSMS() 'send sms to number
Catch ex As MySqlException
MessageBox.Show("Error in inserting new record! Error: " & ex.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
transaction.Rollback()
End Try
'close connections
GlobalFunctions.connection.Close()
End Sub
Public Sub EMP_LOGOUT()
' Connect to Database
GlobalFunctions.db_connect()
' Dim command As MySqlCommand
Dim transaction As MySqlTransaction
transaction = GlobalFunctions.connection.BeginTransaction()
Try
GlobalFunctions.execute_nonquery("Update employee_logs set Time_Out='" & TimeOfDay & "' WHERE ID_Number='" & strid & "' AND Time_Out='Null' AND Date='" & Date.Today & "'")
transaction.Commit()
'sms = txtFirst.Text & " Left the Building Premises #" & Now & "Powered by: " ' actual sms to be sent
lblStatus.ForeColor = Color.Lime
Dim SAPI
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Goodbye!" & txtFirst.Text)
lblStatus.Text = "Successfully Logged OUT! Goodbye!" ' set status to logout
'Will_SendSMS() 'send sms
Catch ex As MySqlException
MessageBox.Show("Error in updating a record! Error: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
transaction.Rollback()
End Try
' close connections
GlobalFunctions.connection.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'counter for display
counter += 1
If counter = 6 Then
Call ClearTextBox(Me)
lblStatus.ForeColor = Color.Lime
Me.lblStatus.Text = "Please scan your finger....."
Lblverify.ForeColor = Color.Black
Lblverify.Text = "Status"
ProfilePic.Image = Nothing
Timer1.Enabled = False
counter = 0
End If
End Sub
Private Sub frmDTR_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Try
Me.VerificationControl.Focus()
Catch ex As MySqlException
MessageBox.Show("System Error: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmDTR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
matcher = New Verification.Verification()
matchResult = New Verification.Verification.Result
Me.VerificationControl.Focus()
Dim SAPI
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Please scan your finger")
End Sub
Private Sub VerificationControl_OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
Dim strSQL As String = "Select * from finger_template"
Dim oDa As New MySqlDataAdapter(strSQL, oConn)
Dim dt As New DataTable
Dim dr As DataRow
Try
oDa.Fill(dt)
For Each dr In dt.Rows
Lblverify.ForeColor = Color.Red
Lblverify.Visible = True
Dim bytes As Byte() = Nothing
bytes = dr.Item("byte_template")
Dim tmplate = New DPFP.Template()
tmplate.DeSerialize(bytes)
matcher.Verify(FeatureSet, tmplate, matchResult)
If matchResult.Verified Then
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
strid = dr.Item("Account_ID")
Call SEARCH_EMPLOYEE()
Exit For ' success
End If
If Not matchResult.Verified Then EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
Lblverify.Text = "Status"
lblStatus.Text = "Unrecognize fingerprint....."
Lblverify.ForeColor = Color.Red
lblStatus.ForeColor = Color.Red
Timer1.Start()
Next
Catch ex As Exception
End Try
End Sub
End Class
This is very nice that you are developing this logic. Actually I have come a crossed YOUR question. Now I can recommend you some vb.net code using back end MS ACCESS 2007 .well You just validate when an employee logged in then put this code after log In button or what ever you are using .
Dim cmd1 as oledbcommond
cmd1 = New OleDbCommand("SELECT * FROM LOGTIME WHERE timein<>null and timeout<>null and dt='" & Label8.Text & "' and eid='" & txtemid.Text & "' ", cn)
dr = cmd1.ExecuteReader()
If dr.Read Then
MessageBox.Show("Already this Employee ID contains today's attendance,now you can't Log again", "Information On Your ID", MessageBoxButtons.OK, MessageBoxIcon.Information)
cmd1.Dispose()
cn.Close()
Exit Sub
End If
just follow the steps
Use normal login button which will validate for user
then if the authenticate user then show his login time in another textbox in the same form.and
use one more textbox to show the logout time ,now
1)use two buttons a)button1 as logintime button and b)button2 as logout time button
2)Then write code to add the login time into the data base,and for ur better understanding put one message box too which will shows the"Time in added to the database" and after that put the above code which will validate the current day attendance if the employee wants to login twice or thrice in a day this code will not allow him to login again only once he/she can ... and code the above behind the login button
note:-keep in mind that all the procedure will work after the employee log out ..Hope this will help you out..

What's Causing My If Statement To Be Skipped?

I have an embedded IF statement that should execute following a Database query. However, I noticed at run-time that the entire statement is not being evaluated at all (the one right after While dbData.Read()). What am I doing wrong?
HERE'S THE CODE:
Private Sub ButtonNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNew.Click
If TextBoxSearch.Text = "" Then
MessageBox.Show("Sorry, you must enter an ACCOUNT# before proceeding!")
TextBoxSearch.Focus()
Else
Try
Dim dbConn As MySqlConnection
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=parts;Password=parts;Database=accounting")
Dim account As Boolean = True
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbQuery As String = "SELECT * FROM customer WHERE accountNumber = '" & TextBoxSearch.Text & "';"
Dim dbData As MySqlDataReader
Dim dbAdapter As New MySqlDataAdapter
Dim dbCmd As New MySqlCommand
dbCmd.CommandText = dbQuery
dbCmd.Connection = dbConn
dbAdapter.SelectCommand = dbCmd
dbData = dbCmd.ExecuteReader
While dbData.Read()
If dbData.HasRows Then
'MessageBox.Show("Customer record already exists!")
Call recordExists()
account = False
Call lockForm()
TextBoxSearch.Focus()
Me.Refresh()
Else
'dbData.Close()
account = True
TextBoxAccount.Text = TextBoxSearch.Text
TextBoxAccount.BackColor = Color.LightGray
TextBoxAccount.TabStop = False
Call unlockForm()
TextBoxLastName.Focus()
ButtonSubmit.Visible = True
Me.Refresh()
End If
End While
dbData.Close()
dbCmd.Dispose()
dbAdapter.Dispose()
dbConn.Close()
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
End If
End Sub
If dbData.Read() returns False, then it will not enter your loop and therefore the If statement will not be executed. If there are no rows to be read, then Read always returns False, so the If statement is useless where it's at. You need to move that If statement up so that the while loop is inside the If block:
If dbData.HasRows Then
While dbData.Read()
' ...
End While
Else
' ...
End If