2016-10-18 67 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時,我都會考慮如何增加計數器。 –

相關問題