2016-10-18 31 views
-2

'公用Sub updateTextBox()如何:时间在和超时状态上vb.net

s = s + SerialPort1.ReadExisting() 

    If Len(s) > 12 Then 
     Try 

      txtReceived.Text = Microsoft.VisualBasic.Mid(s, 1, 12) 

      strSql = "SELECT * FROM stud WHERE tag = '" & txtReceived.Text & "';" 
      command.CommandText = strSql 
      command.Connection = SQLConnection 
      datapter.SelectCommand = command 
      datardr = command.ExecuteReader 
      Dim img() As Byte 
      If datardr.HasRows Then 
       datardr.Read() 
       img = datardr("picture") 
       Dim ms As New MemoryStream(img) 
       txtFname.Text = datardr("fname").ToString 
       txtLname.Text = datardr("lname").ToString 
       PictureBox1.Image = Image.FromStream(ms) 
       SQLConnection.Close() 
      End If 

      SQLConnection.Open() 
     Catch ex As Exception 
     End Try 
     Try 

      Dim i As Integer 
      Dim newtag As Boolean = True 
      Dim stringfix As String 
      Dim string1 As String 
      Dim string2 As String 

      For i = 0 To (grid.Rows.Count - 1) 
       stringfix = grid.Rows.Item(i).Cells(0).Value 
       string1 = Microsoft.VisualBasic.Mid(stringfix, 1, 10) 
       string2 = Microsoft.VisualBasic.Mid(stringfix, 2, 10) 
       If string1 = string2 Then 
        newtag = False 
        Exit For 
       Else 
        newtag = True 
       End If 
      Next 
      If newtag = True Then 
       Dim dr As Integer 
       dr = grid.Rows.Add() 
       grid.Rows.Item(dr).Cells.Item(0).Value = Microsoft.VisualBasic.Mid(s, 1, 12) 
       grid.Rows.Item(dr).Cells(1).Value = txtFname.Text 
       grid.Rows.Item(dr).Cells(2).Value = txtLname.Text 
       grid.Rows.Item(dr).Cells.Item(3).Value = txtDate.Text + " " + txtTime.Text 
       grid.Rows.Item(dr).Cells.Item(4).Value = "TIME IN" 
      ElseIf newtag = False Then 
       grid.Rows.Item(i).Cells.Item(3).Value = txtDate.Text + " " + txtTime.Text 
       grid.Rows.Item(i).Selected = True 

      End If 


     Catch ex As Exception 
     End Try 
     Dim timeOut As DateTimeOffset = Now.AddMilliseconds(1500) 

     Do 
      Application.DoEvents() 

     Loop Until Now > timeOut 

     s = SerialPort1.ReadExisting() 
     SerialPort1.DiscardOutBuffer() 
     s = String.Empty 
     SerialPort1.DtrEnable = True 
     txtReceived.Text = "" 
     txtFname.Text = "" 
     txtLname.Text = "" 
     PictureBox1.Image = Nothing 

    End If 
End Sub` 

美好的一天!我一直在为我们的论文研究一所学校的基于RFID的日常时间记录。我的问题是如何设置学生的“状态”,当他/她第一次点击RFID卡时,它应该是status = Time-In,当他/她第二次点击它时,状态应该是超时。每个学生每天有一次Time-In和一次Time-out限制。任何想法如何做到这一点?希望你们能得到我指出的内容。

+0

您需要提供更多信息并希望获得一些代码。你有什么尝试?你使用的是数据库还是硬编码的“学生”?为每个学生记录一个计数器并不困难,所以这个问题相当广泛。 – TheValyreanGroup

+0

这实际上只是一个非常宽泛的规范 - 它并不适用于堆栈溢出问答格式。另外 - 如果一个学生刻下他人的卡片并敲出来,每天限制1次,他们现在是否会陷入麻烦? –

+0

@TheValyreanGroup是的,我正在使用数据库。我该怎么处理柜台?对不起,问我,刚刚对RFID和vb.net新希望你们明白。我将加上一些我使用的代码。这段代码的进展是它可以从数据库中检索数据。不介意DataGrid。我只是不知道该怎么做才能在状态中进行暂停和超时。 –

回答

0

有很多方法可以做到这一点,它几乎太宽泛。一种简单的方法是将两列添加到您的数据库中,并分别在RFID扫描或扫描时递增。然后,当你从你的数据库中选择你可以引用这些列,如果两者都> 1,那么这样的事情。

另一种方法是使用所有学生TAG的数组。你可以在本地跟踪计数器,而不是在数据库中。扫描标签后,所以,正确的...

If inCounter(tag) > 1 or outCounter(tag) > 1 Then 
    msgbox("User has reached the quota.") 
Else 
    inCounter(tag) += 1 
    outCounter(tag) += 1 
End If 

那么你就需要实现每天重置这些计数器一个DateTime类。

+0

如果我在数据库(time_in和time_out)添加两列,如何正确的方式把TimeOfDay放到time_in当我第一次点击他的RFID,并把time_out当我第二次点击它?我得到的逻辑,但我不知道如何开始和编码:( –

+0

SO是不是一个代码写作服务。我不打算为你做,如果你在数据库中创建了2个新列TIMESTAMP列,并将其设置为CURRENT_TIMESTAMP,那么每次更新行时,它都会自动将服务器的时间放入该条目中 – TheValyreanGroup

+0

非常感谢你@TheValyreanGroup!我解决了这个问题,感谢你分享你的想法,每次扫描RFID时,我都会考虑如何增加计数器。 –