Нужна помощь в импорте данных машины посещаемости для доступа к базе данных
Я новичок в Visual Basic. Я использую visual basic 6 с базой данных Microsoft Access для просмотра и записи данных о посещаемости. Мне удалось подключить машину и просмотреть данные о посещаемости в DataGrid view с помощью Machine sdk. Однако в базе данных есть только одна строка импортированных данных. Нужна помощь. Я приложил код. Также я буду благодарен, если кто-то покажет мне, как его улучшить. Спасибо
Что я уже пробовал:
Private Sub cmdGlogData_Click() Dim vTMachineNumber As Long Dim vSMachineNumber As Long Dim vSEnrollNumber As Long Dim vVerifyMode As Long Dim vYear As Long Dim vMonth As Long Dim vDay As Long Dim vHour As Long Dim vMinute As Long Dim vErrorCode As Long Dim vRet As Boolean Dim i, n As Long Dim vMaxLogCnt As Long Dim vinouttype As Long Dim vaction As Long With RawData .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db\dbase.mdb;Persist Security Info=False" .RecordSource = "select * from RawData" .Refresh Do vMaxLogCnt = gMaxLow lblMessage.Caption = "Waiting..." DoEvents gridSLogData.Height = 4800 gridSLogData.Redraw = False gridSLogData.Clear gstrLogItem = Array("", "TMachineNo", "EnrollNo", "EMachineNo", "InOut", "VeriMode", "DateTime") With gridSLogData .Row = 0 .ColWidth(0) = 600 For i = 1 To 6 .Col = i .Text = gstrLogItem(i) .ColAlignment(i) = 3 .ColWidth(i) = 1200 Next i .Col = 6 .ColWidth(5) = 2000 .ColWidth(6) = 2000 .ColWidth(7) = 100 .ColWidth(8) = 100 n = .Rows If n > 2 Then Do If n = 2 Then Exit Do .RemoveItem (n) n = n - 1 Loop End If .Redraw = True End With MousePointer = vbHourglass vRet = frm_DataImp.FP_CLOCK1.EnableDevice(mMachineNumber, False) If vRet = False Then lblMessage.Caption = gstrNoDevice MousePointer = vbDefault Exit Sub End If vRet = frm_DataImp.FP_CLOCK1.ReadAllGLogData(mMachineNumber) If vRet = False Then frm_DataImp.FP_CLOCK1.GetLastError vErrorCode lblMessage.Caption = ErrorPrint(vErrorCode) End If If vRet = True Then lblMessage.Caption = "Getting..." frm_DataImp.FP_CLOCK1.EnableDevice mMachineNumber, True MousePointer = vbHourglass DoEvents gridSLogData.Redraw = False With gridSLogData i = 1 Do EEE: vRet = frm_DataImp.FP_CLOCK1.GetAllGLogData(mMachineNumber, _ vTMachineNumber, _ vSEnrollNumber, _ vSMachineNumber, _ vVerifyMode, _ vYear, _ vMonth, _ vDay, _ vHour, _ vMinute) If vRet = False Then Exit Do If vRet = True And i <> 1 Then .AddItem (1) End If vinouttype = Int(vVerifyMode / 8) vaction = vVerifyMode Mod 8 .Row = i .Col = 0 .Text = i .Col = 1 .Text = vTMachineNumber .Col = 2 .Text = vSEnrollNumber .Col = 3 .Text = vSMachineNumber .Col = 4 .Text = vinouttype .Col = 5 If vSEnrollNumber <> 0 Then If vaction = 0 Then .Text = vaction & "/Normal" ElseIf vaction = 1 Then .Text = vaction & "/f1" ElseIf vaction = 2 Then .Text = vaction & "/f2" ElseIf vaction = 3 Then .Text = vaction & "/f3" ElseIf vaction = 4 Then .Text = vaction & "/f4" ElseIf vaction = 5 Then .Text = vaction & "/in" ElseIf vaction = 6 Then .Text = vaction & "/out" Else .Text = vaction & "/--" End If Else If vaction = 0 Then .Text = vaction & "/Closed" ElseIf vaction = 1 Then .Text = vaction & "/Opened" ElseIf vaction = 2 Then .Text = vaction & "/HandOpen" ElseIf vaction = 3 Then .Text = vaction & "/ProcOpen" ElseIf vaction = 4 Then .Text = vaction & "/ProcClose" ElseIf vaction = 5 Then .Text = vaction & "/IllegalOpen" ElseIf vaction = 6 Then .Text = vaction & "/IlleagalRemove" ElseIf vaction = 7 Then .Text = vaction & "/Alarm" Else .Text = vaction & "/--" End If End If .Col = 6 .Text = CStr(vYear) & "/" & Format(vMonth, "0#") & "/" & Format(vDay, "0#") & _ " " & Format(vHour, "0#") & ":" & Format(vMinute, "0#") DoEvents i = i + 1 If i > vMaxLogCnt Then Exit Do Loop End With If i > vMaxLogCnt Then gridSLogData.Height = gridSLogData.Height / 2 End If vMaxLogCnt = vMaxLogCnt * 2 If i > vMaxLogCnt Then gridSLogData.Height = gridSLogData.Height * 2 / 3 End If gridSLogData.Redraw = True lblMessage.Caption = "ReadAllGLogData OK" End If 'Writing to database ' ' ' With .Recordset .AddNew !TMachineNo = vTMachineNumber !EnrollNo = vSEnrollNumber !EMachineNo = vSMachineNumber !InOut = vinouttype If vSEnrollNumber <> 0 Then If vaction = 0 Then !VeriMode = vaction & "/Normal" ElseIf vaction = 1 Then !VeriMode = vaction & "/f1" ElseIf vaction = 2 Then !VeriMode = vaction & "/f2" ElseIf vaction = 3 Then !VeriMode = vaction & "/f3" ElseIf vaction = 4 Then !VeriMode = vaction & "/f4" ElseIf vaction = 5 Then !VeriMode = vaction & "/in" ElseIf vaction = 6 Then !VeriMode = vaction & "/out" Else !VeriMode = vaction & "/--" End If Else If vaction = 0 Then !VeriMode = vaction & "/Closed" ElseIf vaction = 1 Then !VeriMode = vaction & "/Opened" ElseIf vaction = 2 Then !VeriMode = vaction & "/HandOpen" ElseIf vaction = 3 Then !VeriMode = vaction & "/ProcOpen" ElseIf vaction = 4 Then !VeriMode = vaction & "/ProcClose" ElseIf vaction = 5 Then !VeriMode = vaction & "/IllegalOpen" ElseIf vaction = 6 Then !VeriMode = vaction & "/IlleagalRemove" ElseIf vaction = 7 Then !VeriMode = vaction & "/Alarm" Else !VeriMode = vaction & "/--" End If End If !DateTime = CStr(vYear) & "/" & Format(vMonth, "0#") & "/" & Format(vDay, "0#") & _ " " & Format(vHour, "0#") & ":" & Format(vMinute, "0#") .Update FFF: End With Loop gGetState = False If .Recordset.RecordCount > 1 Then .Recordset.MoveLast End With MousePointer = vbDefault DoEvents frm_DataImp.FP_CLOCK1.EnableDevice mMachineNumber, True End Sub