Public Class frmBCP5Demo

    Private Sub frmBCP5Demo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For i As Integer = 0 To My.Computer.Ports.SerialPortNames.Count - 1
            cbbCOMPorts.Items.Add(My.Computer.Ports.SerialPortNames(i))
        Next
        cbbCOMPorts.Text = My.Computer.Ports.SerialPortNames(0)
    End Sub

    Private Sub btOpenBCP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOpenBCP.Click
        'Open BCP5
        cbOpened.Checked = False
        BCP5Upload1.PortName = cbbCOMPorts.Text

        If BCP5Upload1.Open(tbPassword.Text) Then
            cbOpened.Checked = True
        Else
            cbOpened.Checked = False
        End If
    End Sub

    Private Sub cbCloseBCP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCloseBCP.Click
        'Close
        BCP5Upload1.Close()
        cbOpened.Checked = False
    End Sub

    Private Sub btSYNC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSYNC.Click
        If BCP5Upload1.SyncUpHostTime Then
            MsgBox("OK ", MsgBoxStyle.Information)
        Else
            MsgBox("Fail ", MsgBoxStyle.Critical)
        End If
    End Sub

    Private Sub btUploadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUploadData.Click
        RichTextBox1.Text = ""
        If Not BCP5Upload1.GetRawData() Then
            MsgBox("Error !! ", MsgBoxStyle.Critical)
            Exit Sub
        End If
        If BCP5Upload1.ConvertRawData Then
            RichTextBox1.Text = BCP5Upload1.UploadRecords
        End If
    End Sub

    Private Sub btEraseData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btEraseData.Click
        If BCP5Upload1.EraseData Then
            MsgBox("OK ", MsgBoxStyle.Information)
        Else
            MsgBox("Failed ", MsgBoxStyle.Critical)
        End If
    End Sub

    Private Sub cbShowRTC_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbShowRTC.CheckedChanged
        BCP5Upload1.ShowRTC = IIf(cbShowRTC.Checked, True, False)
    End Sub

    Private Sub cbShowMachineID_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbShowMachineID.CheckedChanged
        BCP5Upload1.ShowMachineID = IIf(cbShowMachineID.Checked, True, False)
    End Sub

End Class
