Results 1 to 7 of 7

Thread: Blocking the user in Exit which is not already Logged in at the Entrance

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2017
    Posts
    22

    Exclamation Blocking the user in Exit which is not already Logged in at the Entrance

    Good Day, I need help for my vb.net application which is using RFID reader rc522 and arduino Uno, all is well and already functioning regarding the card scanning. When the card is scanned the data from the database will be retrieve and show to the interface screen, I have 2 RFID which is located in separated doors, ENTRANCE and EXIT and 1 server database to save the logged in students and out..Now the problem is when the student don't scan his/her RFID card in the entrance , the error will show in the EXIT interface when the student scan his Id in the EXIT. Is there any way to block the student who are not scanning his rfid in the entrance to the exit ? Thank you This is my code



    Private Sub Students_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    loadtable()
    ''Date Now
    Timer2.Start()

    logins.ForeColor = Color.White
    Try

    With DataGridView1
    .AllowUserToAddRows = False ' Disabled or hide (*) Symbol...

    .RowHeadersVisible = False 'To hide Left indicator..
    .DefaultCellStyle.SelectionBackColor = Color.SteelBlue 'Selection backcolor....
    .AlternatingRowsDefaultCellStyle.BackColor = Color.LightGoldenrodYellow 'Alternating Backcolor.
    .AllowUserToResizeRows = False 'Disabled row resize...
    .ReadOnly = True
    .MultiSelect = False
    .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    .ShowRowErrors = False
    .ShowCellErrors = False
    .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill


    End With



    Catch ex As Exception

    End Try



    ''The combobox filled with serial ports available

    comPORT = ""
    For Each sp As String In My.Computer.Ports.SerialPortNames
    comPort_ComboBox.Items.Add(sp)
    Next
    ''Paglalagay ng collections



    End Sub

    ''FFor Replacing the textbox for a new card

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

    Dim StringIn As String = SerialPort1.ReadLine()
    StringIn = StringIn.Replace(Chr(10), "").Replace(Chr(13), "")
    Me.Invoke(Sub() studtag.Text = StringIn) 'we need to invoke since we're on another thread




    End Sub

    Public Sub insert()

    con = New MySqlConnection
    con.ConnectionString = "server=localhost;userid=root;password=1234;database=dat"
    Dim reader As MySqlDataReader
    Dim mstream As New System.IO.MemoryStream()

    Dim arrImage() As Byte = mstream.GetBuffer()
    mstream.Close()

    Try

    con.Open()
    Dim query3 As String

    query3 = "insert into dat.studlogs (studtags,idno,lastxt,firstxt,middletxt,dob,log,timein,crse,studpic) values ('" & tagtxt.Text & "','" & idno.Text & "','" & lastxt.Text & "','" & firstxt.Text & "','" & middletxt.Text & "','" & dob.Text & "','" & log.Text & "','" & timein.Text & "','" & crsetxt.Text & "',@studpic)"
    cmd = New MySqlCommand(query3, con)
    cmd.Parameters.AddWithValue("@studpic", arrImage)
    reader = cmd.ExecuteReader


    con.Close()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    con.Dispose()
    End Try

    End Sub
    Public Sub loadtable()



    con = New MySqlConnection
    con.ConnectionString = "server=localhost;userid=root;password=1234;database=dat"
    Dim SDA As New MySqlDataAdapter
    Dim dbDataset As New DataTable
    Dim bSource As New BindingSource


    Try

    con.Open()
    Dim query3 As String

    query3 = "select idno as 'Student_ID',lastxt as 'LastName',firstxt as 'FirstName',middletxt as 'MiddleName',log as 'Status',timein as 'Timein',crse as 'Course' from dat.studlogs"
    cmd = New MySqlCommand(query3, con)
    SDA.SelectCommand = cmd
    SDA.Fill(dbDataset)
    bSource.DataSource = dbDataset
    DataGridView1.DataSource = bSource
    SDA.Update(dbDataset)

    DataGridView1.Sort(DataGridView1.Columns(5), System.ComponentModel.ListSortDirection.Descending)


    If dbDataset.Rows.Count > 0 Then
    logins.Text = dbDataset.Rows.Count.ToString()
    End If


    con.Close()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    con.Dispose()
    End Try
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    bday.Text = Date.Now.ToString("MMMM d")
    datenow.Text = Date.Now.ToString("MMMM d, yyyy")
    times.Text = TimeOfDay.ToString("h:mm:ss tt")
    wholedate.Text = Now
    End Sub


    ''Here is the Scanning

    Private Sub studtag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles studtag.TextChanged

    Notenrolled.Close()
    greet.Text = ""
    PictureBox4.Visible = False

    If studtag.Text = "44F2F38B" Then

    Endday()

    End If

    If studtag.TextLength = 8 Then

    DataGridView1.Sort(DataGridView1.Columns(6), System.ComponentModel.ListSortDirection.Descending)
    con = New MySqlConnection
    con.ConnectionString = "server=localhost;userid=root;password=1234;database=dat"
    Dim query As String

    query = "select * from dat.students"
    cmd = New MySqlCommand(query, con)



    Dim table As New DataTable

    Try
    con.Open()
    'Gets or sets an SQL statement or stored procedure used to select records in the database.
    With cmd
    .Connection = con
    .CommandText = "SELECT * from students where `studtags`='" & studtag.Text & "';"
    End With
    da.SelectCommand = cmd
    da.Fill(table)
    'it gets the data from specific column and fill it into Label

    idno.Text = table.Rows(0).Item(1)
    lastxt.Text = table.Rows(0).Item(2)
    firstxt.Text = table.Rows(0).Item(3)
    middletxt.Text = table.Rows(0).Item(4)
    dob.Text = table.Rows(0).Item(6)
    year.Text = table.Rows(0).Item(7)
    crsetxt.Text = table.Rows(0).Item(10)

    tagtxt.Text = studtag.Text
    timein.Text = times.Text

    dr = cmd.ExecuteReader()
    dr.Read()

    If dob.Text = bday.Text Then
    greet.Text = firstxt.Text + " Today is your Birthday. Greetings ."
    PictureBox4.Visible = True

    End If



    Dim img() As Byte = CType(dr("studpic"), Byte())


    Using ms As New IO.MemoryStream(img)
    PictureBox1.Image = Image.FromStream(ms)

    End Using
    insert()
    loadtable()
    studdailyhistory()


    Catch ex As Exception
    Notenrolled.Show()
    DataGridView1.Sort(DataGridView1.Columns(5), System.ComponentModel.ListSortDirection.Descending)
    If studtag.Text = "44F2F38B" Then
    Notenrolled.Close()
    End If

    Finally

    con.Dispose()
    con.Close()

    End Try

    End If

    End Sub

    The Out code is almost the same as IN. Thank you. Ask me anything if you have questions about this..Any Advice and answers is so much appreciated..Save me for my final defense.
    The Problem with this, is when the students left their RFID card and make a way to get inside the university except in ENTRANCE GATE due to no Card to scan

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Blocking the user in Exit which is not already Logged in at the Entrance

    There's really way too much code there. Please only post the RELEVANT code. Also, please use formatting tags when posting code, i.e.

    [HIGHLIGHT=vb.net]your code here[/HIGHLIGHT]

    or

    [CODE]your code here[/CODE]

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Blocking the user in Exit which is not already Logged in at the Entrance

    You didn't say which line of code was throwing the error, I'm guessing this one.
    Code:
    idno.Text = table.Rows(0).Item(1)
    The problem is your assuming that
    Code:
    "SELECT * from students where `studtags`='" & studtag.Text & "';"
    Will return a row of data.

    It's easy enough to test "If table.rows.Count > 0 Then ....."

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2017
    Posts
    22

    Re: Blocking the user in Exit which is not already Logged in at the Entrance

    Hello Thank you for that. But i have no problem with the code I just need a additional code for this problem..

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2017
    Posts
    22

    Re: Blocking the user in Exit which is not already Logged in at the Entrance

    Quote Originally Posted by jmcilhinney View Post
    There's really way too much code there. Please only post the RELEVANT code. Also, please use formatting tags when posting code, i.e.

    [HIGHLIGHT=vb.net]your code here[/HIGHLIGHT]

    or

    [CODE]your code here[/CODE]
    Hello Thank you for that. But i have no problem with the code I just need a additional code for this problem..

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Blocking the user in Exit which is not already Logged in at the Entrance

    Quote Originally Posted by sangguko19 View Post
    Hello Thank you for that. But i have no problem with the code I just need a additional code for this problem..
    I showed you how to solve the problem.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Blocking the user in Exit which is not already Logged in at the Entrance

    Quote Originally Posted by sangguko19 View Post
    Hello Thank you for that. But i have no problem with the code I just need a additional code for this problem..
    Why did you post a large block of unformatted code if it has no relevance?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width