12 Replies - 1562 Views - Last Post: 19 January 2016 - 09:38 AM Rate Topic: -----

#1 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

How to check item in ListView using vb 2008?

Posted 19 January 2016 - 03:01 AM

Hi Guysss, I have problem in ListView
Can you Help me??
I'am trying to make an attendance system..

Here's my screenshots;
Attached Image


When I put an Employee ID to txtInput.Text
The employee information will add to listview
Now, my problem is I want to check the Data in ListView Columns
Which is the DATE | A.M IN | A.M OUT | P.M IN | P.M OUT
If there is already a Date and Time for A.M IN or A.M OUT and etc...

To avoid duplication of data as you can see in figure below.
Attached Image

I'am using an "update" query to update A.M OUT | P.M IN | P.M OUT in my Database
Please Help me guysss.....

MaceySoftware, I need your suggestions....

Is This A Good Question/Topic? 0
  • +

Replies To: How to check item in ListView using vb 2008?

#2 0Pain0Gain   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 03:14 AM

You need to look at checking if the record exists, if it doesn't use insert and if it does then maybe give a message to the user

Dim i As Integer = sqlCommand.ExecuteScalar
                        If (i = 0) Then
                            MsgBox("records not found")
                            sqlCommand.CommandText = "INSERT STATEMENT"
                            sqlCommand.ExecuteNonQuery()
                            'update the listview
                        Else
                            MsgBox("records found")
                            'do something
                        End If




Do this with your statement then populate your listview afterwards with the changes if needed

I use something similar to check if the records exist in my parts system

hope this helps

I use a count statement just prior to this

sqlCommand.CommandText = "SELECT Count(*) AS stuff FROM table WHERE Exists (select * from table where [email protected]);"
sqlCommand.Parameters.AddWithValue("@stuffID", txtstuffid.text)


Hope this helps
Was This Post Helpful? 0
  • +
  • -

#3 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 03:33 AM

Thank's for the help OPainOGain...
I will try it now....
Was This Post Helpful? 0
  • +
  • -

#4 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,638
  • Joined: 07-September 13

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 04:41 AM

0Pain0Gain I don't think this is what he wants. but i could be wrong.

You are right you do want to track the status of them however he is saying when he enters the employee ID into the textbox it is creating a duplicate row, there is no point in going to the database to check this it is just a waste of a database trip.


Loop through each row and check to see if the userID already exists for today if it doesn't then add the new row otherwise throw a messagebox or exception whatever you want to state that the employee has already been added for today.
Was This Post Helpful? 0
  • +
  • -

#5 0Pain0Gain   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 05:26 AM

Yeah I read it as the user inserts an ID in the textbox and this then does a database check to retrieve the employee name, department and position, then adds this information with current date and time into the listview.

Hopefully razer20 can make it clear :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#6 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 07:12 AM

maceysoftware: Loop through each row and check to see if the userID already exists for today if it doesn't then add the new row otherwise throw a messagebox or exception whatever you want to state that the employee has already been added for today.

I think this is what I want and this is the right thing to do....
But, I dont know how to do it with listview.. can u help me??
Im just a novice programmer...
Pleaseeee help me.....
This is part of my thesis study...
Was This Post Helpful? 0
  • +
  • -

#7 0Pain0Gain   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 07:17 AM

Can you post up the code you use to populate the listview and the code that's fired on entry of ID into the textbox please as you seem to have no buttons on that form

That will be easier to edit and resolve the duplication issue
Was This Post Helpful? 0
  • +
  • -

#8 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 07:50 AM

This is my code for txtInput.Text

Private Sub txtInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInput.TextChanged

        con.ConnectionString = "server=localhost;user id=root;database=payroll_system"
        If txtInput.TextLength = "12" Then

            Dim selectSQL As String = "SELECT Employee_ID, Firstname, Lastname, Department, Position, Photo FROM employees WHERE Employee_ID='" & txtInput.Text & "'"
            con.Open()

            With com
                .Connection = con
                .CommandText = selectSQL
            End With
            reader = com.ExecuteReader()

            While reader.Read()
                lblEmpID.Text = reader("Employee_ID").ToString()
                lblEmpName.Text = reader("Firstname").ToString() + " " + reader("Lastname").ToString()
                lblDept.Text = reader("Department").ToString()
                lblPosition.Text = reader("Position").ToString()
                Dim bt As Byte() = DirectCast(reader("Photo"), Byte())
                Dim ms As New MemoryStream(bt)
                pbxPhoto.Image = Image.FromStream(ms)
            End While
            con.Close()

'First: When the employee time in, in the morning I get the employees info and place it to TextBox..
'Second: After getting the employees info, Now I need to insert those employee info from textbox to my attendance database..

Dim theTime As DateTime
            theTime = Now.ToLongTimeString

            '/////////////////////////////////////////////////////////////////////////
            '========================================================================
            'TIME FRAME APPLIED FOR 8:00 A.M IN THE MORNING
            'START MORNING TIME IN FOR EMPLOYEES BEFORE 8:00 AM
            '========================================================================
            If theTime >= #6:00:00 AM# AndAlso theTime <= #7:59:59 AM# Then
                '--------------------------------------------------------
                'PASOK SA DATABASE 8:00 AM
                '--------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 08:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "IN"
                lblFlag.Text = "1"


                If lblFlag.Text = "1" Then
                    Dim AMOUT = "NONE"
                    Dim PMIN = "NONE"
                    Dim PMOUT = "NONE"

                    Dim filesize As UInt32
                    con.Open()
                    Dim mstream As New System.IO.MemoryStream()
                    pbxPhoto.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    Dim arrImage() As Byte = mstream.GetBuffer()

                    filesize = mstream.Length

                    Dim comm As New MySqlCommand("INSERT INTO attendance(Employee_ID,Employee_Name,Department,Position,Date,AMstartTime,AMendTime,PMstartTime,PMendTime,StatusAM_IN,AM_in,AM_out,PM_in,PM_out,Photo) VALUES ('" + lblEmpID.Text + "','" + lblEmpName.Text + "','" + lblDept.Text + "','" + lblPosition.Text + "','" + lblDate.Text + "','" + lblTimeFrame1.Text + "','" + lblTimeFrame2.Text + "','" + lblTimeFrame3.Text + "','" + lblTimeFrame4.Text + "','" + lblStatus.Text + "','" + lblInOrOut.Text + "','" + AMOUT + "','" + PMIN + "','" + PMOUT + "',@File)", con)
                    With comm
                        .Parameters.AddWithValue("@File", arrImage)
                        .ExecuteNonQuery()
                    End With
                    con.Close()
                    txtInput.Clear()
                    txtInput.Focus()

                    ShowData()
                End If


                '========================================================================
                'END TIME IN BEFORE 8:00 AM
                '========================================================================

'Now, the employees info has already save to my attendance table
'Then, I get it to populate into listview;

Private Sub ShowData()
        con.Close()
        con.ConnectionString = "server=localhost;user id=root;database=payroll_system"
        con.Open()
        With com
            .Connection = con
            .CommandText = "SELECT * FROM attendance ORDER BY ID DESC"
        End With
        ListView1.Items.Clear()
        reader = com.ExecuteReader
        While reader.Read
            With ListView1
                Dim x As DateTime
                x = reader.GetString(5)
                .Items.Add(reader.Item(0))
                With .Items(.Items.Count - 1).SubItems
                    .Add(reader.GetString(2))
                    .Add(x)
                    .Add(reader.GetString(6))
                    .Add(reader.GetString(7))
                    .Add(reader.GetString(8))
                    .Add(reader.GetString(9))
                End With
            End With
        End While
        com.Dispose()
        con.Close()
:code:

Now, My Problem is...
If the Employee enter again his/her EmpID at the same time.It creates a duplicate entry...
Now I want to check the item or the employees info in my listview if it is already in the row, Like MaceySoftware said...

This post has been edited by modi123_1: 19 January 2016 - 07:57 AM
Reason for edit:: Please add 'code tags' to your post by highlighting the text that is your code and click the 'code' button in the editor.

Was This Post Helpful? 0
  • +
  • -

#9 0Pain0Gain   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 08:03 AM

Put the code in CODE tags please :)

As I thought you are using the change event and no buttons to run a query on the database for inserting.

The simplest solution is to put an if statement around your insert statement, this will allow you to run the insert command if the user hasn't already entered a time for today.

If the user has then you can reject it with a message informing them they have already logged in or something.

comm.CommandText = "SELECT Count(*) AS attendance FROM table WHERE Exists (select * from attendance where [email protected] and [email protected] and [email protected] );"
comm.Parameters.AddWithValue("@empid", txtInput.Text)
comm.Parameters.AddWithValue("@date", lblDate.Text)
comm.Parameters.AddWithValue("@timein", lblTimeFrame1.Text)




Something like this will look for a record where the ID matches the input box and the time and date matches the labels

Should give you a starting point.

Then use the code I posted above and it should work fine.

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#10 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 08:17 AM

Here's my code in txtInput_TextChanged event
It works in terms of Time Frame, I did not put any Buttons because I've use a Barcode Scanner...

Private Sub txtInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInput.TextChanged

        con.ConnectionString = "server=localhost;user id=root;database=payroll_system"
        If txtInput.TextLength = "12" Then

            Dim selectSQL As String = "SELECT Employee_ID, Firstname, Lastname, Department, Position, Photo FROM employees WHERE Employee_ID='" & txtInput.Text & "'"
            con.Open()

            With com
                .Connection = con
                .CommandText = selectSQL
            End With
            reader = com.ExecuteReader()

            While reader.Read()
                lblEmpID.Text = reader("Employee_ID").ToString()
                lblEmpName.Text = reader("Firstname").ToString() + " " + reader("Lastname").ToString()
                lblDept.Text = reader("Department").ToString()
                lblPosition.Text = reader("Position").ToString()
                Dim bt As Byte() = DirectCast(reader("Photo"), Byte())
                Dim ms As New MemoryStream(bt)
                pbxPhoto.Image = Image.FromStream(ms)
            End While
            con.Close()

            Dim theTime As DateTime
            theTime = Now.ToLongTimeString

            '/////////////////////////////////////////////////////////////////////////
            '========================================================================
            'TIME FRAME APPLIED FOR 8:00 A.M IN THE MORNING
            'START MORNING TIME IN FOR EMPLOYEES BEFORE 8:00 AM
            '========================================================================
            If theTime >= #6:00:00 AM# AndAlso theTime <= #7:59:59 AM# Then
                '--------------------------------------------------------
                'PASOK SA DATABASE 8:00 AM
                '--------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 08:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "IN"
                lblFlag.Text = "1"


                If lblFlag.Text = "1" Then
                    Dim AMOUT = "NONE"
                    Dim PMIN = "NONE"
                    Dim PMOUT = "NONE"

                    Dim filesize As UInt32
                    con.Open()
                    Dim mstream As New System.IO.MemoryStream()
                    pbxPhoto.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    Dim arrImage() As Byte = mstream.GetBuffer()

                    filesize = mstream.Length

                    Dim comm As New MySqlCommand("INSERT INTO attendance(Employee_ID,Employee_Name,Department,Position,Date,AMstartTime,AMendTime,PMstartTime,PMendTime,StatusAM_IN,AM_in,AM_out,PM_in,PM_out,Photo) VALUES ('" + lblEmpID.Text + "','" + lblEmpName.Text + "','" + lblDept.Text + "','" + lblPosition.Text + "','" + lblDate.Text + "','" + lblTimeFrame1.Text + "','" + lblTimeFrame2.Text + "','" + lblTimeFrame3.Text + "','" + lblTimeFrame4.Text + "','" + lblStatus.Text + "','" + lblInOrOut.Text + "','" + AMOUT + "','" + PMIN + "','" + PMOUT + "',@File)", con)
                    With comm
                        .Parameters.AddWithValue("@File", arrImage)
                        .ExecuteNonQuery()
                    End With
                    con.Close()
                    txtInput.Clear()
                    txtInput.Focus()

                    ShowData()
                End If


                '========================================================================
                'END TIME IN BEFORE 8:00 AM
                '========================================================================
                '////////////////////////////////////////////////////////////////////////

                '/////////////////////////////////////////////////////////////////////////
                '======================================================================================
                'START TIME IN AFTER = 8:00 A.M 
                'TIME FRAME NOT APPLIED AND GET THE CURRENT TIME
                'TIME ALLOWANCE FOR MORNING TIME IN UNTIL = 8:59 A.M
                'INSERTING TIME FROM THE CURRENT TIME NOT IN TIME FRAME
                '======================================================================================
            ElseIf theTime >= #8:00:00 AM# AndAlso theTime <= #8:59:59 AM# Then
                '--------------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "IN"
                lblFlag.Text = "1"
                '=====================================================================

                If lblFlag.Text = "1" Then
                    Dim filesize As UInt32
                    con.Open()
                    Dim mstream As New System.IO.MemoryStream()
                    pbxPhoto.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    Dim arrImage() As Byte = mstream.GetBuffer()

                    filesize = mstream.Length

                    Dim comm As New MySqlCommand("INSERT INTO attendance(Employee_ID,Employee_Name,Department,Position,Date,AMstartTime,AMendTime,PMstartTime,PMendTime,StatusAM_IN,AM_in,Photo) VALUES ('" + lblEmpID.Text + "','" + lblEmpName.Text + "','" + lblDept.Text + "','" + lblPosition.Text + "','" + lblDate.Text + "','" + lblTime1.Text + "','" + lblTimeFrame2.Text + "','" + lblTimeFrame3.Text + "','" + lblTimeFrame4.Text + "','" + lblStatus.Text + "','" + lblInOrOut.Text + "',@File)", con)
                    With comm
                        .Parameters.AddWithValue("@File", arrImage)
                        .ExecuteNonQuery()
                    End With
                    con.Close()
                    ShowData()
                    txtInput.Clear()
                    txtInput.Focus()
                End If
                '========================================================================
                'END TIME IN AFTER 8:00 AM
                '========================================================================
                '////////////////////////////////////////////////////////////////////////


                '/////////////////////////////////////////////////////////////////////////
                '========================================================================
                'TIME FRAME FOR 12:00 P.M OUT NOT APPLIED
                'START TIME OUT BEFORE 12:00 P.M IN THE AFTERNOON
                'UPDATING DATA INTO ATTENDANCE TABLE
                '========================================================================
            ElseIf theTime >= #9:00:00 AM# AndAlso theTime <= #11:59:59 AM# Then
                '--------------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "OUT"
                lblFlag.Text = "0"
                '--------------------------------------------------------------

                If lblFlag.Text = "0" Then
                    con.Open()
                    Dim updateQuery As String
                    updateQuery = "UPDATE attendance SET AMendTime='" + lblTime1.Text + "',StatusAM_OUT='" + lblStatus.Text + "',AM_out='" + lblInOrOut.Text + "' WHERE Employee_ID = '" & txtInput.Text & "' AND Date='" & lblDate.Text & "'"

                    Dim i As Integer
                    With com
                        .CommandText = updateQuery
                        .Connection = con
                        i = .ExecuteNonQuery
                        ShowData()
                        txtInput.Clear()
                        txtInput.Focus()
                    End With
                End If

                '========================================================================
                'END  TIME OUT BEFORE 12:00 P.M IN THE AFTERNOON
                '========================================================================
                '////////////////////////////////////////////////////////////////////////


                '/////////////////////////////////////////////////////////////////////////
                '========================================================================
                'TIME FRAME APPLIED FOR 12:00 P.M
                'START TIME OUT EXACT OR AFTER 12:00 P.M IN THE AFTERNOON
                '========================================================================
            ElseIf theTime >= #12:00:00 PM# AndAlso theTime <= #12:30:59 PM# Then
                '--------------------------------------------------------
                'PASOK SA DATABASE 12:00 P.M
                '--------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 12:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "OUT"
                lblFlag.Text = "0"

                If lblFlag.Text = "0" Then
                    con.Open()
                    Dim updateQuery As String
                    updateQuery = "UPDATE attendance SET AMendTime='" + lblTimeFrame2.Text + "',StatusAM_OUT='" + lblStatus.Text + "',AM_out='" + lblInOrOut.Text + "' WHERE Employee_ID = '" & txtInput.Text & "' AND Date='" & lblDate.Text & "'"

                    Dim i As Integer
                    With com
                        .CommandText = updateQuery
                        .Connection = con
                        i = .ExecuteNonQuery
                        ShowData()
                        txtInput.Clear()
                        txtInput.Focus()
                    End With
                End If

                '========================================================================
                'END TIME OUT EXACT OR AFTER 12:00 P.M IN THE AFTERNOON
                '========================================================================
                '////////////////////////////////////////////////////////////////////////


                '/////////////////////////////////////////////////////////////////////////
                '========================================================================
                'TIME FRAME APPLIED FOR 1:00 P.M IN THE AFTERNOON
                'START TIME IN BEFORE 1:00 P.M IN THE AFTERNOON
                '========================================================================
            ElseIf theTime >= #12:31:00 PM# AndAlso theTime <= #12:59:59 PM# Then
                '--------------------------------------------------------
                'PASOK SA DATABASE 1:00 P.M
                '--------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 13:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "IN"
                lblFlag.Text = "ONE"

                If lblFlag.Text = "ONE" Then
                    con.Open()
                    Dim updateQuery As String
                    updateQuery = "UPDATE attendance SET PMstartTime='" + lblTimeFrame3.Text + "',StatusPM_IN='" + lblStatus.Text + "',PM_in='" + lblInOrOut.Text + "' WHERE Employee_ID = '" & txtInput.Text & "' AND Date='" & lblDate.Text & "'"

                    Dim i As Integer
                    With com
                        .CommandText = updateQuery
                        .Connection = con
                        i = .ExecuteNonQuery
                        ShowData()
                        txtInput.Clear()
                        txtInput.Focus()
                    End With
                End If

                '========================================================================
                'END TIME IN BEFORE 1:00 P.M IN THE AFTERNOON
                '========================================================================
                '////////////////////////////////////////////////////////////////////////


                '/////////////////////////////////////////////////////////////////////////
                '========================================================================
                'TIME FRAME NOT APPLIED
                'TIME ALLOWANCE FOR TIME IN, IN THE AFTERNOON = 1:30 P.M
                'START TIME IN EXACT OR AFTER 1:00 P.M IN THE AFTERNOON
                '========================================================================
            ElseIf theTime >= #1:00:00 PM# AndAlso theTime <= #1:30:59 PM# Then
                '--------------------------------------------------------
                'PASOK SA DATABASE 12:00 P.M
                '--------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "IN"
                lblFlag.Text = "ONE"

                If lblFlag.Text = "ONE" Then
                    con.Open()
                    Dim updateQuery As String
                    updateQuery = "UPDATE attendance SET PMstartTime='" + lblTime1.Text + "',StatusPM_IN='" + lblStatus.Text + "',PM_in='" + lblInOrOut.Text + "' WHERE Employee_ID = '" & txtInput.Text & "' AND Date='" & lblDate.Text & "'"

                    Dim i As Integer
                    With com
                        .CommandText = updateQuery
                        .Connection = con
                        i = .ExecuteNonQuery
                        ShowData()
                        txtInput.Clear()
                        txtInput.Focus()
                    End With
                End If

                '========================================================================
                'END TIME IN BEFORE 1:00 P.M IN THE AFTERNOON
                '========================================================================
                '////////////////////////////////////////////////////////////////////////


                '/////////////////////////////////////////////////////////////////////////
                '========================================================================
                'START TIME OUT BEFORE 5:00 P.M
                'TIME FRAME FOR 5:00 P.M OUT NOT APPLIED
                '========================================================================
            ElseIf theTime >= #1:30:00 PM# AndAlso theTime <= #4:59:59 PM# Then
                '--------------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                '--------------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "OUT"
                lblFlag.Text = "ZERO"

                If lblFlag.Text = "ZERO" Then
                    con.Open()
                    Dim updateQuery As String
                    updateQuery = "UPDATE attendance SET PMendTime='" + lblTime1.Text + "',StatusPM_OUT='" + lblStatus.Text + "',PM_out='" + lblInOrOut.Text + "' WHERE Employee_ID = '" & txtInput.Text & "' AND Date='" & lblDate.Text & "'"

                    Dim i As Integer
                    With com
                        .CommandText = updateQuery
                        .Connection = con
                        i = .ExecuteNonQuery
                        ShowData()
                        txtInput.Clear()
                        txtInput.Focus()
                    End With
                End If


                '========================================================================
                '
                '========================================================================
                '////////////////////////////////////////////////////////////////////////


                '/////////////////////////////////////////////////////////////////////////
                '========================================================================
                'TIME FRAME FOR 5:00 P.M APPLIED
                'START TIME OUT FOR 5:00 P.M IN THE SUNSET
                '========================================================================
            ElseIf theTime >= #5:00:00 PM# AndAlso theTime <= #5:59:59 PM# Then
                '--------------------------------------------------------------
                lblTimeFrame1.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame2.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame3.Text = Format(Now, "yyyy-MM-dd 00:00:00")
                lblTimeFrame4.Text = Format(Now, "yyyy-MM-dd 17:00:00")
                '--------------------------------------------------------------
                lblDate.Text = Format(Now, "yyyy-MM-dd")
                lblStatus.Text = Format(Now, "tt")
                lblInOrOut.Text = "OUT"
                lblFlag.Text = "ZERO"

                If lblFlag.Text = "ZERO" Then
                    con.Open()
                    Dim updateQuery As String
                    updateQuery = "UPDATE attendance SET PMendTime='" + lblTimeFrame4.Text + "',StatusPM_OUT='" + lblStatus.Text + "',PM_out='" + lblInOrOut.Text + "' WHERE Employee_ID = '" & txtInput.Text & "' AND Date='" & lblDate.Text & "'"

                    Dim i As Integer
                    With com
                        .CommandText = updateQuery
                        .Connection = con
                        i = .ExecuteNonQuery
                        ShowData()
                        txtInput.Clear()
                        txtInput.Focus()
                    End With
                    con.Close()
                End If


                '========================================================================
                'TIME OUT FOR 5:00 P.M IN THE SUNSET
                '========================================================================
                '////////////////////////////////////////////////////////////////////////

            End If
        End If

    End Sub

This post has been edited by Razor20: 19 January 2016 - 08:24 AM

Was This Post Helpful? 0
  • +
  • -

#11 0Pain0Gain   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 08:35 AM

That makes more sense now you mention the barcode scanner, I did wonder why you were using employee ID instead of their name.

I have a scanner on the parts system im coding up just now, thats where the above samples came from.

I would do the check right after the


 If txtInput.TextLength = "12" Then


This way it checks to see if a record exists, if it does it can give a message and exit the sub.

else it can progress and do the insert code

You could repeat the process and it can check for users leaving as well, so an employee cant duplicate the exit record.
Was This Post Helpful? 0
  • +
  • -

#12 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 09:17 AM

Can you give me the logic, or sample code that I can understand easily??
Was This Post Helpful? 0
  • +
  • -

#13 0Pain0Gain   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 116
  • Joined: 15-December 15

Re: How to check item in ListView using vb 2008?

Posted 19 January 2016 - 09:38 AM

Logic:

Count all records where ID, DATE, TIME match user entered ID, Current Date, Current time from Labels

If a record is found message user saying it exists

If it doesnt exist insert record to the database

Dim conString As String = "connection string"
       Using SQLConnection As New MySqlConnection(conString)
                Using sqlCommand As New MySqlCommand()
                    With sqlCommand
                         .CommandText = "SELECT Count(*) AS attendance FROM table WHERE Exists (select * from attendance where [email protected] and [email protected] and [email protected] );"
                         .Parameters.AddWithValue("@empid", txtInput.Text)
                         .Parameters.AddWithValue("@date", lblDate.Text)
                         .Parameters.AddWithValue("@timein", lblTimeFrame1.Text)
                         .Connection = SQLConnection
                         .CommandType = CommandType.Text
                    End With
                    Try
                        SQLConnection.Open()
                        Dim i As Integer = sqlCommand.ExecuteScalar
                        If (i = 0) Then
                            MsgBox("records not found")
                            sqlCommand.CommandText = "INSERT STATEMENT HERE"
                            sqlCommand.ExecuteNonQuery()
                        Else
                            MsgBox("You have already checked in today")
                        End If
                        iReturn = True
                    Catch ex As MySqlException
                        MsgBox(ex.Message.ToString)
                        iReturn = False
                    Finally
                        SQLConnection.Close()
                    End Try
                End Using
        End Using
        Return




Just editied my code with some of yours cant test the connections etc but should be good to go

hope this helps
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1