Advertisement
Guest User

swipe badge

a guest
Dec 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.10 KB | None | 0 0
  1. Function SwipeBadge(cn As SQLiteConnection, RFID As String) As TimeSession
  2.     Using cmd As New SQLiteCommand("Select count(*) from Sessions where RFID=@RFID and TimeOut IS NULL", cn)
  3.         cmd.Parameters.AddWithValue("@RFID", RFID)
  4.  
  5.         Dim cnt As Integer = cmd.ExecuteScalar
  6.  
  7.         If cnt = 1
  8.             cmd.CommandText = "Update Sessions set TimeOut=@TimeOut where RFID=@RFID and TimeOut IS NULL"
  9.             cmd.Parameters.AddWithValue("@TimeOut", DateTime.Now.ToString("o"))
  10.             Dim affected As Integer = cmd.ExecuteNonQuery
  11.             Console.WriteLine($"User {RFID} clocked out.  Updated row count: {affected}")
  12.         Else
  13.             cmd.CommandText = "Insert into Sessions (RFID,TimeIn) VALUES(@RFID, @TimeIn)"
  14.             cmd.Parameters.AddWithValue("@TimeIn", DateTime.Now.ToString("o"))
  15.             Dim affected As Integer = cmd.ExecuteNonQuery
  16.             Console.WriteLine($"User {RFID} clocked In.  Updated row count: {affected}")
  17.  
  18.         End If
  19.  
  20.     End Using
  21.  
  22. Dim sessions=GetTimeSessions(cn).Dump($"Current db status {DateTime.Now}")
  23.     Dim session = sessions.Where(Function(s) s.RFID = rfid).OrderByDescending(Function(s) s.TimeIn).First
  24.     Return session
  25.  
  26. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement