如何在连接到设备后将数据显示到网格视图中?

时间:2014-01-19 12:30:31

标签: datagrid vb.net-2010

在这个程序中我正在尝试读取指纹读取设备,一切正常但在从设备获取数据后如何在网格视图中显示它,任何帮助:(

选项严格关闭 选项明确的 Imports System.Runtime.InteropServices

Public Class Form1     继承System.Windows.Forms.Form

Const gMaxLow As Short = 30000
Dim mMachineNumber As Integer
Dim gGlogSearched As Boolean = False
Dim prevGlogIndex As Integer = -1
Public gstrLogItem As Object
Public gMachineNumber As Integer
Dim mOpenFlag As Boolean
Private Sub ShowGlogItem(ByVal vTMachineNumber As Integer, ByVal vSEnrollNumber As Integer, ByVal vSMachineNumber As Integer, ByVal vVerifyMode As Integer, ByVal vYear As Integer, ByVal vMonth As Integer, ByVal vDay As Integer, ByVal vHour As Integer, ByVal vMinute As Integer, ByVal vSecond As Integer, ByVal vIndex As Integer, ByVal vMaxLogCnt As Integer, ByVal gridGlogData As AxMSFlexGridLib.AxMSFlexGrid)
    Dim vAttStatus As Integer, vAntipass As Integer
    Dim stAttStatus As String = "", stAntipass As String = ""
    Dim vDiv As Integer = 65536

    vAntipass = vVerifyMode / vDiv
    vVerifyMode = vVerifyMode Mod vDiv
    vAttStatus = vVerifyMode / 256
    vVerifyMode = vVerifyMode Mod 256

    If vAttStatus = 0 Then
        stAttStatus = "_DutyOn"
    ElseIf vAttStatus = 1 Then
        stAttStatus = "_DutyOff"
    ElseIf vAttStatus = 2 Then
        stAttStatus = "_OverOn"
    ElseIf vAttStatus = 3 Then
        stAttStatus = "_OverOff"
    ElseIf vAttStatus = 4 Then
        stAttStatus = "_GoIn"
    ElseIf vAttStatus = 5 Then
        stAttStatus = "_GoOut"
    End If

    If vAntipass = 1 Then
        stAntipass = "(AP_In)"
    ElseIf vAntipass = 3 Then
        stAntipass = "(AP_Out)"
    End If

    With gridGlogData
        .Row = vIndex - vMaxLogCnt
        .Col = 0
        .Text = vIndex
        .Col = 1
        If vTMachineNumber = -1 Then
            .Text = "No Photo"
        Else
            .Text = CStr(vTMachineNumber)
        End If
        .Col = 2
        .Text = CStr(vSEnrollNumber)
        .Col = 3
        .Text = CStr(vSMachineNumber)
        .Col = 4
        vVerifyMode = vVerifyMode Mod 256
        If vVerifyMode = 1 Then
            .Text = "Fp"
        ElseIf vVerifyMode = 2 Then
            .Text = "Password"
        ElseIf vVerifyMode = 3 Then
            .Text = "Card"
        ElseIf vVerifyMode = 10 Then
            .Text = "Hand Lock"
        ElseIf vVerifyMode = 11 Then
            .Text = "Prog Lock"
        ElseIf vVerifyMode = 12 Then
            .Text = "Prog Open"
        ElseIf vVerifyMode = 13 Then
            .Text = "Prog Close"
        ElseIf vVerifyMode = 14 Then
            .Text = "Auto Recover"
        ElseIf vVerifyMode = 20 Then
            .Text = "Lock Over"
        ElseIf vVerifyMode = 21 Then
            .Text = "Illegal Open"
        ElseIf vVerifyMode = 51 Then
            .Text = "Fp"
        ElseIf vVerifyMode = 52 Then
            .Text = "Password"
        ElseIf vVerifyMode = 53 Then
            .Text = "Card"
        ElseIf vVerifyMode = 101 Then
            .Text = "Fp"
        ElseIf vVerifyMode = 102 Then
            .Text = "Password"
        ElseIf vVerifyMode = 103 Then
            .Text = "Card"
        ElseIf vVerifyMode = 151 Then
            .Text = "Fp"
        ElseIf vVerifyMode = 152 Then
            .Text = "Password"
        ElseIf vVerifyMode = 153 Then
            .Text = "Card"
        Else
            .Text = "--"
        End If

        If 1 <= vVerifyMode And vVerifyMode <= 7 Then
            .Text = .Text & stAttStatus
        ElseIf 51 <= vVerifyMode And vVerifyMode <= 53 Then
            .Text = .Text + stAttStatus
        ElseIf 101 <= vVerifyMode And vVerifyMode <= 103 Then
            .Text = .Text + stAttStatus
        ElseIf 151 <= vVerifyMode And vVerifyMode <= 153 Then
            .Text = .Text + stAttStatus
        End If

        gridGlogData.Text = gridGlogData.Text + stAntipass

        .Col = 5
        .Text = CStr(vYear) & "/" & Format(vMonth, "0#") & "/" & Format(vDay, "0#") & " " & Format(vHour, "0#") & ":" & Format(vMinute, "0#")
    End With
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim IPAddress As String
    If TextBox1.Text = "" Then
        ErrorProvider1.SetError(TextBox1, "This Field Is Required")
    End If
    If TextBox2.Text = "" Then
        ErrorProvider2.SetError(TextBox2, "This Field Is Required")
    End If
    Try
        gMachineNumber = TextBox4.Text

        IPAddress = TextBox1.Text

        If AxSBXPC1.ConnectTcpip(gMachineNumber, IPAddress, CInt(TextBox2.Text), CInt(TextBox3.Text)) Then
            Button2.Enabled = True
            Button3.Enabled = True
            Button1.Enabled = False
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    AxSBXPC1.Disconnect()
    mOpenFlag = False
    Button1.Enabled = True
    Button2.Enabled = False
    Button3.Enabled = False
End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click

    With DataGridView1

        .ColumnCount = 5
        .Columns(0).HeaderText = "Photo No."
        .Columns(0).Width = 100
        .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter


        .Columns(1).HeaderText = "Enroll No."
        .Columns(1).Width = 100
        .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        .Columns(2).HeaderText = "EMachine No."
        .Columns(2).Width = 100
        .Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        .Columns(3).HeaderText = "Veri Mode"
        .Columns(3).Width = 100
        .Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        .Columns(4).HeaderText = "Date / Time"
        .Columns(4).Width = 100
        .Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

    End With

    loaddata()
End Sub
Private Sub loaddata()
    gGlogSearched = True

    Dim vTMachineNumber As Integer
    Dim vSMachineNumber As Integer
    Dim vSEnrollNumber As Integer
    Dim vVerifyMode As Integer
    Dim vYear As Integer
    Dim vMonth As Integer
    Dim vDay As Integer
    Dim vHour As Integer
    Dim vMinute As Integer
    Dim vSecond As Integer
    Dim vErrorCode As Integer
    Dim vRet As Boolean
    Dim i As Integer
    Dim n As Integer
    Dim vMaxLogCnt As Integer

    vMaxLogCnt = gMaxLow

    lblMessage.Text = "Waiting..."
    LabelTotal.Text = "Total : "

    System.Windows.Forms.Application.DoEvents()
    gstrLogItem = New Object() {"", "Photo No", "EnrollNo", "EMachineNo", "VeriMode", "DateTime"}

    vRet = AxSBXPC1.ReadAllGLogData(TextBox4.Text)
    vRet = AxSBXPC1.GetGeneralLogData(mMachineNumber, vTMachineNumber, vSEnrollNumber, vSMachineNumber, vVerifyMode, vYear, vMonth, vDay, vHour, vMinute, vSecond)
    If vRet = True Then
        lblMessage.Text = "getting"
        Cursor = System.Windows.Forms.Cursors.WaitCursor
        System.Windows.Forms.Application.DoEvents()
        **With DataGridView1
            i = 1
            Do
                vRet = AxSBXPC1.GetAllGLogData(mMachineNumber, vTMachineNumber, vSEnrollNumber, vSMachineNumber, vVerifyMode, vYear, vMonth, vDay, vHour, vMinute, vSecond)
                If vRet = True And i <> 1 Then
                    '.Item(CStr(i))
                    '.DataSource = vSEnrollNumber
                End If
            Loop**
        End With
    End If
End Sub

结束班

1 个答案:

答案 0 :(得分:0)

设置网格的数据源,并确保填充或dataBIND要显示的数据..您可能需要重新绑定每个更新,而不仅仅是更改数据源....

例如:

private void DataSetBtn_Click(object sender, System.EventArgs e)
{
// Create a DataSet & add DataTable A and B to it
DataTable table = CreateDataTableA();
DataSet ds = new DataSet("ABSet");
ds.Tables.Add(table);
table = CreateDataTableB();
ds.Tables.Add(table); 
// Bind DataSet to the DataGrid
dataGrid1.SetDataBinding(ds,"B");
}

如果您有更多详细信息,我们非常乐意帮助您解决问题。