Imports System.IO
Imports System.IO.Ports
Imports System.Management
Imports System.Drawing.Printing
Imports System.Threading
Imports System.Runtime.InteropServices


Public Class MainForm

    Public FormMaxWidth, FormMaxHeight As Integer
    Public FirstLogin As Boolean = True
    Public TITLE_NAME As String = "DUALSONIC Infomaion Configuration Utillity"
    Public PROGRAM_VERSION As String = "VER 1.0.0"
    Public PROGRAM_TITLE_NAME As String = TITLE_NAME & " " & PROGRAM_VERSION
    Public ParaComport As String


    ''시리얼 통신 변수
    Private mySerialPort As New SerialPort
    Private Delegate Sub SerialDelegate()
    Private UpdateSerialDelegate As SerialDelegate
    Public cmdMessage As String
    Public rxMessage As String
    Public RmainRxMessage As String
    Public UsedSerial As Boolean

    ''시리얼 통신 수신 처리 변수 
    Public Const ReceiveCntVal As Integer = 100
    Public ReceiveCnt As Integer = ReceiveCntVal
    Public ReceiveCntEnable As Boolean = False
    Public Const TDSN_ReceiveCntVal As Integer = 20
    Public TDSN_ReceiveCnt As Integer = TDSN_ReceiveCntVal
    Public TDSN_ReceiveCntEnable As Boolean = False

    ''바코드 파싱 처리 변수 
    Public BarCodeWaitCnt As Long
    Public Const BarCodeWaitTime As Integer = 20
    Public BarCodeFixedText As Boolean = True '' 바코드 텍스트 변경에 따른 커서 이동 방지 변수

    ''정보 쓰기 후 수신 값 동일 여부 확인 변수 
    Public ResultTextBoxList(DS_TYPE.MAX_DS_TYPE_NUM, 9) As TextBox

    Public FaceInfoSet_X As Integer
    Public FaceInfoSet_Y As Integer
    Public DevInfoSet_X As Integer
    Public DevInfoSet_Y As Integer
    Public EyeInfoSet_X As Integer
    Public EyeInfoSet_Y As Integer

    ''객체 배열 선언 
    Public gpbInfoSet(DS_TYPE.MAX_DS_TYPE_NUM) As GroupBox
    Public InfoSet_X(DS_TYPE.MAX_DS_TYPE_NUM) As Integer
    Public InfoSet_Y(DS_TYPE.MAX_DS_TYPE_NUM) As Integer

    Public chkDeviceUse(DS_TYPE.MAX_DS_TYPE_NUM) As CheckBox

    Public txbInfo_Barcord(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Model(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Cart(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Manufacture(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Year(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Month(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_SN(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_TDSN(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_FW(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Abroad(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Agency(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Rshot(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Tshot(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Freq(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Power(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_Date(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox

    Public txbInfo_AGDate(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_AGShot(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_AGStart(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_AGOkNg(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_AGPower(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_AGEnd(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_CTDate(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_CTFreq(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_IQCDate(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_IQCTD(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_IQCGrade(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox
    Public txbInfo_IQCCap(DS_TYPE.MAX_DS_TYPE_NUM) As TextBox

    Public lblInfo_Model(DS_TYPE.MAX_DS_TYPE_NUM) As Label
    Public lblInfo_YearMonth(DS_TYPE.MAX_DS_TYPE_NUM) As Label
    Public lblInfo_Year(DS_TYPE.MAX_DS_TYPE_NUM) As Label
    Public lblInfo_Month(DS_TYPE.MAX_DS_TYPE_NUM) As Label
    Public lblInfo_SN(DS_TYPE.MAX_DS_TYPE_NUM) As Label

    Public pnlModel(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlManufacture(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlYearMonth(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlSN(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlTDSN(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlFW(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlCart(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlAbroad(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlAgency(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlRshot(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlTshot(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlFreq(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlPower(DS_TYPE.MAX_DS_TYPE_NUM) As Panel
    Public pnlDate(DS_TYPE.MAX_DS_TYPE_NUM) As Panel

    Public gpbAgingInfo(DS_TYPE.MAX_DS_TYPE_NUM) As GroupBox
    Public gpbCTInfo(DS_TYPE.MAX_DS_TYPE_NUM) As GroupBox
    Public gpbIQCInfo(DS_TYPE.MAX_DS_TYPE_NUM) As GroupBox


    Public cmbInfo_Year(DS_TYPE.MAX_DS_TYPE_NUM) As ComboBox
    Public cmbInfo_Month(DS_TYPE.MAX_DS_TYPE_NUM) As ComboBox
    Public cmbInfo_Day(DS_TYPE.MAX_DS_TYPE_NUM) As ComboBox

    Public txbProductCntPro(4) As TextBox
    Public txbProductCntLux(4) As TextBox

    Public ItemSelectItem(15) As TextBox
    Public txbItemSelectModel(15) As TextBox
    Public ItemSelectFace(15) As TextBox
    Public ItemSelectEye(15) As TextBox
    Public ItemSelectAbroad(15) As TextBox
    Public ItemSelectAgency(15) As TextBox

    '' 프린터 관련 변수
    Private print_data(1, 1) As String
    Delegate Sub delegate_print(ByRef str As String)
    Private TH_print As Thread
    Private thread_print As Boolean
    Private print_OnOff As Boolean
    Private Compare_Print As Boolean = False
    Private txtName As String
    Private active_onoff As Boolean = False

    Private Enum printnum
        face
        dev
        eye
        max
    End Enum
    Private printnumtype(printnum.max) As String

    <DllImport("user32.dll")>
    Private Shared Function FindWindow(ByVal SclassName As String, ByVal SWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll")>
    Private Shared Function SetForegroundWindow(ByVal findName As IntPtr) As Boolean
    End Function
    <DllImport("user32.dll")>
    Private Shared Function ShowWindowAsync(ByVal findname As IntPtr, ByVal howShow As Integer) As Boolean
    End Function

    Private Const showNORMAL As Integer = 1
    Private Const showMINIMIZED As Integer = 2
    Private Const showMAXIMIZED As Integer = 3

    Private Sub print_func()
        Do While thread_print
            If print_OnOff = True Then
                print_th_play()
            End If
        Loop
    End Sub

    Private Sub print_th_play()
        Dim print_num As String
        If Compare_Print = True Then
            print_num = txtName
        Else
            print_num = print_number()
        End If


        If print_num <> 0 Then
            printOptionData(print_num)
            print_on(print_num)
        End If
    End Sub

    Private Sub frmPruduct_info_set_disponse(sender As Object, e As EventArgs) Handles MyBase.Disposed
        active_onoff = False
        If TH_print.IsAlive = True Then
            thread_print = False
            TH_print.Abort()
        End If
    End Sub

    Private Sub active_form()
        Dim findname As IntPtr = FindWindow(Nothing, Me.Text)

        If Not findname.Equals(IntPtr.Zero) Then
            'ShowWindowAsync(findname, showNORMAL)
            SetForegroundWindow(findname)
        End If
    End Sub

    Private Sub frmPruduct_info_set_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        frmLogin.ShowDialog()
        If GetLoginStatus() <= LOGIN_STATUS.CHECK_IN_FAIL Then End
        SetLoginStatus(LOGIN_STATUS.ENTER_PROGRAM)

        txbBarcodeNum.ImeMode = ImeMode.Off

        SetVariableBinding()
        SetFormLoad(RunMode)
        Read_ini("infoset")
        Read_ini("printer")

        If UsedSerial Then
            OpenSerial()
            SetStatus(DS_STATUS.INIT)
            SendData("[carttdsn 2]")
            SendData("[dsfwver 1]")
            SendData("[carttdsn 3]")
        End If
        Reset_All_DS_Reg()
        SetBarCodeBoxFocus()

        dgvPrinter.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        TH_print = New Thread(AddressOf print_func)
        thread_print = True
        TH_print.Start()
        TH_print.IsBackground = True
        active_onoff = True
    End Sub

    Private Sub DateComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
        Try
            Dim combo As ComboBox = DirectCast(sender, ComboBox)

            ' 년도나 월이 변경되면 일 콤보박스 업데이트
            For i As Integer = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                If combo Is cmbInfo_Year(i) Or combo Is cmbInfo_Month(i) Then
                    UpdateDayComboBox(i)
                    Exit For
                End If
            Next
        Catch ex As Exception
            Console.WriteLine("DateComboBox_SelectedIndexChanged Error: " & ex.Message)
        End Try
    End Sub


    ' 일 콤보박스를 년월에 맞게 업데이트하는 메서드
    Private Sub UpdateDayComboBox(deviceType As Integer)
        Try
            If cmbInfo_Year(deviceType) Is Nothing Or cmbInfo_Month(deviceType) Is Nothing Or cmbInfo_Day(deviceType) Is Nothing Then
                Return
            End If

            If cmbInfo_Year(deviceType).SelectedItem Is Nothing Or cmbInfo_Month(deviceType).SelectedItem Is Nothing Then
                Return
            End If

            Dim selectedYear As Integer = CInt(cmbInfo_Year(deviceType).SelectedItem.ToString())
            Dim selectedMonth As Integer = CInt(cmbInfo_Month(deviceType).SelectedItem.ToString())

            ' 현재 선택된 일자 저장
            Dim currentSelectedDay As String = ""
            If cmbInfo_Day(deviceType).SelectedItem IsNot Nothing Then
                currentSelectedDay = cmbInfo_Day(deviceType).SelectedItem.ToString()
            End If

            ' 해당 년월의 마지막 날짜 계산
            Dim daysInMonth As Integer = DateTime.DaysInMonth(selectedYear, selectedMonth)

            ' 일 콤보박스 다시 설정
            cmbInfo_Day(deviceType).Items.Clear()
            For day As Integer = 1 To daysInMonth
                cmbInfo_Day(deviceType).Items.Add(day.ToString("00"))
            Next

            ' 이전에 선택된 일자가 유효하면 다시 선택, 아니면 현재 날짜 또는 1일로 설정
            If Not String.IsNullOrEmpty(currentSelectedDay) AndAlso CInt(currentSelectedDay) <= daysInMonth Then
                cmbInfo_Day(deviceType).SelectedItem = currentSelectedDay
            ElseIf DateTime.Now.Year = selectedYear AndAlso DateTime.Now.Month = selectedMonth Then
                cmbInfo_Day(deviceType).SelectedItem = DateTime.Now.Day.ToString("00")
            Else
                cmbInfo_Day(deviceType).SelectedIndex = 0 ' 첫 번째 항목 선택
            End If

        Catch ex As Exception
            Console.WriteLine("UpdateDayComboBox Error: " & ex.Message)
        End Try
    End Sub

    Private Function GetSelectedDate(deviceType As Integer) As String
        Try
            If cmbInfo_Year(deviceType) IsNot Nothing AndAlso cmbInfo_Year(deviceType).SelectedItem IsNot Nothing AndAlso
           cmbInfo_Month(deviceType) IsNot Nothing AndAlso cmbInfo_Month(deviceType).SelectedItem IsNot Nothing AndAlso
           cmbInfo_Day(deviceType) IsNot Nothing AndAlso cmbInfo_Day(deviceType).SelectedItem IsNot Nothing Then

                ' 2자리 년도를 4자리로 변환 (25 -> 2025)
                Dim twoDigitYear As String = cmbInfo_Year(deviceType).SelectedItem.ToString()
                Dim fourDigitYear As String = "20" & twoDigitYear

                Return fourDigitYear & "-" &
                   cmbInfo_Month(deviceType).SelectedItem.ToString().PadLeft(2, "0"c) & "-" &
                   cmbInfo_Day(deviceType).SelectedItem.ToString().PadLeft(2, "0"c)
            End If
            Return ""
        Catch ex As Exception
            Console.WriteLine("GetSelectedDate Error: " & ex.Message)
            Return ""
        End Try
    End Function


    Private Sub SetFormLoad(Type As FORM_TYPE)
        Me.Hide()
        Me.Text = PROGRAM_TITLE_NAME
        Me.Size = New Size(1936, 1056)
        Me.Location = New Size(-8, -8)
        FormMaxWidth = Val(Me.Width)
        FormMaxHeight = Val(Me.Height)

        ''메인 패널
        pnlMain.Location = New Size(0, 0)
        pnlMain.Size = New Size(1915, 1050)
        pnlMain.Visible = True

        ''설정창 패널
        pnlConf.Location = New Size(0, 0)
        pnlConf.Size = New Size(1915, 1050)
        pnlConf.Visible = False

        Select Case Type
            Case FORM_TYPE.WRITE_MODE

                ckbmainprint.Visible = True

                ''''''''''''''''''''''''''''''''''''''''''''''
                ''사양 입력 창 그룹박스
                ''''''''''''''''''''''''''''''''''''''''''''''
                gpbInfoSetTitle.Location = New Size(10, 90)
                gpbInfoSetTitle.Size = New Size(1895, 125)
                gpbInfoSetTitle.Visible = True

                pnlLog.Location = New Size(10, 10)
                pnlLog.Size = New Size(410, 85)
                pnlLog.Visible = False

                'gpbTime.Location = New Size(10, 10)
                'gpbTime.Size = New Size(525, 85)
                'gpbTime.Visible = True

                gpbTime.Location = New Size(10, 10)
                gpbTime.Size = New Size(335, 85)
                gpbTime.Visible = True

                gpbProgSet.Location = New Size(350, 10)
                gpbProgSet.Size = New Size(360, 85)
                gpbProgSet.Visible = True

                gpbDeviceUse.Location = New Size(715, 10)
                gpbDeviceUse.Size = New Size(455, 85)
                gpbDeviceUse.Visible = True

                gpbLoadCondition.Location = New Size(1175, 10)
                gpbLoadCondition.Size = New Size(455, 85)
                gpbLoadCondition.Visible = True

                btnReset.Location = New Size(1635, 9)
                btnReset.Size = New Size(90, 87)
                btnReset.Visible = True

                btnSetup.Location = New Size(1725, 9)
                btnSetup.Size = New Size(90, 87)
                btnSetup.Visible = True
                btnSetup.Enabled = True

                btnExit.Location = New Size(1815, 9)
                btnExit.Size = New Size(90, 87)
                btnExit.Visible = True

                ''''''''''''''''''''''''''''''''''''''''''''''
                ''판정 창 그룹박스
                ''''''''''''''''''''''''''''''''''''''''''''''
                gpbJudge.Location = New Size(10, 210)
                gpbJudge.Size = New Size(1895, 175)
                gpbJudge.Visible = True

                lblJudge.Location = New Size(340, 50)
                lblJudge.Size = New Size(159, 83)
                lblJudge.Visible = True
                lblJudge.Text = "판정"

                txbBarcodeNum.Location = New Size(528, 15)
                txbBarcodeNum.Size = New Size(840, 147)
                txbBarcodeNum.Visible = True
                txbBarcodeNum.Font = New Font("함초롬바탕", 80.24999)

                btnCmdInput.Location = New Size(1413, 41)
                btnCmdInput.Size = New Size(345, 104)
                btnCmdInput.Visible = False
                ''''''''''''''''''''''''''''''''''''''''''''''
                ''정보출력창 
                ''''''''''''''''''''''''''''''''''''''''''''''
                gpbDeviceInfo.Location = New Size(10, 385)
                gpbDeviceInfo.Size = New Size(1895, 460)
                gpbDeviceInfo.Visible = True

                ''정보출력창(Face/Body) 
                FaceInfoSet_X = 10
                FaceInfoSet_Y = 10
                gpbFaceInfoSet.Location = New Size(FaceInfoSet_X, FaceInfoSet_Y)
                gpbFaceInfoSet.Size = New Size(610, 445)
                gpbFaceInfoSet.Visible = True
                InfoSet_X(DS_TYPE.DS_FACE) = FaceInfoSet_X
                InfoSet_Y(DS_TYPE.DS_FACE) = FaceInfoSet_Y
                InfoSet_X(DS_TYPE.DS_BODY) = FaceInfoSet_X
                InfoSet_Y(DS_TYPE.DS_BODY) = FaceInfoSet_Y

                ''정보출력창(Main) 
                DevInfoSet_X = 640
                DevInfoSet_Y = 10
                InfoSet_X(DS_TYPE.DS_DEV) = DevInfoSet_X
                InfoSet_Y(DS_TYPE.DS_DEV) = DevInfoSet_Y
                gpbDevInfoSet.Location = New Size(DevInfoSet_X, DevInfoSet_Y)
                gpbDevInfoSet.Size = New Size(610, 445)
                gpbDevInfoSet.Visible = True

                ''정보출력창(Eye) 
                EyeInfoSet_X = 1270
                EyeInfoSet_Y = 10
                InfoSet_X(DS_TYPE.DS_EYE) = EyeInfoSet_X
                InfoSet_Y(DS_TYPE.DS_EYE) = EyeInfoSet_Y
                gpbEyeInfoSet.Location = New Size(EyeInfoSet_X, EyeInfoSet_Y)
                gpbEyeInfoSet.Size = New Size(610, 445)
                gpbEyeInfoSet.Visible = True


                ''정보출력 기기정보창(Face) 
                gpbFaceInfo.Location = New Size(10, 130)
                gpbFaceInfo.Size = New Size(589, 360)
                gpbFaceInfo.Visible = True

                ''정보출력 기기정보창(Main) 
                gpbDevInfo.Location = New Size(10, 130)
                gpbDevInfo.Size = New Size(610, 360)
                gpbDevInfo.Visible = True

                ''정보출력 기기정보창(Eye) 
                gpbEyeInfo.Location = New Size(10, 130)
                gpbEyeInfo.Size = New Size(610, 360)
                gpbEyeInfo.Visible = True

                For i = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    pnlModel(i).Location = New Size(10, 30)
                    pnlModel(i).Size = New Size(285, 45)
                    pnlModel(i).Visible = True

                    pnlManufacture(i).Location = New Size(10, 85)
                    pnlManufacture(i).Size = New Size(285, 45)
                    pnlManufacture(i).Visible = True

                    pnlYearMonth(i).Location = New Size(10, 140)
                    pnlYearMonth(i).Size = New Size(285, 45)
                    pnlYearMonth(i).Visible = True

                    pnlSN(i).Location = New Size(10, 195)
                    pnlSN(i).Size = New Size(285, 45)
                    pnlSN(i).Visible = True

                    pnlTDSN(i).Location = New Size(10, 250)
                    pnlTDSN(i).Size = New Size(285, 45)
                    pnlTDSN(i).Visible = True

                    pnlFW(i).Location = New Size(10, 250)
                    pnlFW(i).Size = New Size(285, 45)
                    pnlFW(i).Visible = True

                    pnlAbroad(i).Location = New Size(300, 30)
                    pnlAbroad(i).Size = New Size(285, 45)
                    pnlAbroad(i).Visible = True

                    pnlAgency(i).Location = New Size(300, 85)
                    pnlAgency(i).Size = New Size(285, 45)
                    pnlAgency(i).Visible = True

                    pnlRshot(i).Location = New Size(300, 140)
                    pnlRshot(i).Size = New Size(285, 45)
                    pnlRshot(i).Visible = True

                    pnlTshot(i).Location = New Size(300, 195)
                    pnlTshot(i).Size = New Size(285, 45)
                    pnlTshot(i).Visible = True

                    pnlFreq(i).Location = New Size(300, 250)
                    pnlFreq(i).Size = New Size(285, 45)
                    pnlFreq(i).Visible = False

                    pnlPower(i).Location = New Size(300, 305)
                    pnlPower(i).Size = New Size(285, 45)
                    pnlPower(i).Visible = False

                    pnlCart(i).Visible = False
                    pnlDate(i).Visible = False

                    If cmbInfo_Year(i) IsNot Nothing Then
                        cmbInfo_Year(i).Items.Clear()
                        Dim currentYear As Integer = DateTime.Now.Year
                        For year As Integer = currentYear - 5 To currentYear + 5
                            ' 2자리 년도로 표시 (2025 -> 25)
                            cmbInfo_Year(i).Items.Add(year.ToString().Substring(2, 2))
                        Next
                        ' 현재 년도를 2자리로 선택
                        cmbInfo_Year(i).SelectedItem = currentYear.ToString().Substring(2, 2)
                    End If

                    ' 월 콤보박스 초기화 (1~12월)
                    If cmbInfo_Month(i) IsNot Nothing Then
                        cmbInfo_Month(i).Items.Clear()
                        For month As Integer = 1 To 12
                            cmbInfo_Month(i).Items.Add(month.ToString("00"))
                        Next
                        cmbInfo_Month(i).SelectedItem = DateTime.Now.Month.ToString("00")
                    End If

                    ' 일 콤보박스 초기화 (현재 선택된 년월에 맞는 일수로 동적 설정)
                    If cmbInfo_Day(i) IsNot Nothing Then
                        UpdateDayComboBox(i)
                    End If

                    ''=== 콤보박스 이벤트 핸들러 연결 ===
                    If cmbInfo_Year(i) IsNot Nothing Then
                        AddHandler cmbInfo_Year(i).SelectedIndexChanged, AddressOf DateComboBox_SelectedIndexChanged
                    End If
                    If cmbInfo_Month(i) IsNot Nothing Then
                        AddHandler cmbInfo_Month(i).SelectedIndexChanged, AddressOf DateComboBox_SelectedIndexChanged
                    End If
                    If cmbInfo_Day(i) IsNot Nothing Then
                        AddHandler cmbInfo_Day(i).SelectedIndexChanged, AddressOf DateComboBox_SelectedIndexChanged
                    End If

                Next

                pnlDevTDSN.Visible = False
                pnlDevPower.Visible = False
                pnlDevFreq.Visible = False

                pnlFaceFW.Visible = False
                pnlFacePower.Visible = False
                pnlFaceFreq.Visible = False

                pnlEyeFW.Visible = False
                pnlEyePower.Visible = False
                pnlEyeFreq.Visible = False
                ''''''''''''''''''''''''''''''''''''''''''''''
                ''생산수량카운터창 
                ''''''''''''''''''''''''''''''''''''''''''''''
                gpbOKCnt.Location = New Size(20, 860)
                gpbOKCnt.Size = New Size(925, 140)
                gpbOKCnt.Visible = True

                ''실행버튼
                btnCmdStart.Size = New Size(925, 140)
                btnCmdStart.Location = New Size(965, 860)
                btnCmdStart.Visible = True
                btnCmdStart.Enabled = False

                UsedSerial = True
                TextBoxAllReset()
                Download_CountInfo()
            Case FORM_TYPE.READ_MODE
                ''사양 입력 창 그룹박스
                ckbmainprint.Visible = False
                gpbInfoSetTitle.Visible = False

                pnlLog.Location = New Size(10, 10)
                pnlLog.Size = New Size(410, 80)
                pnlLog.Visible = True

                gpbTime.Location = New Size(425, 10)
                gpbTime.Size = New Size(530, 80)
                gpbTime.Visible = True

                gpbProgSet.Location = New Size(960, 10)
                gpbProgSet.Size = New Size(460, 80)
                gpbProgSet.Visible = True
                chkBarcode.Location = New Size(30, 40)
                chkBarcode.Size = New Size(154, 28)
                ckbReserved.Location = New Size(200, 40)
                ckbReserved.Size = New Size(238, 28)
                ckbReserved.Enabled = False
                ckbReserved.Visible = True

                gpbDeviceUse.Visible = False
                gpbLoadCondition.Visible = False
                btnReset.Visible = False

                btnSetup.Location = New Size(1428, 9)
                btnSetup.Size = New Size(238, 82)
                btnSetup.Visible = True
                btnSetup.Enabled = False

                btnExit.Location = New Size(1668, 9)
                btnExit.Size = New Size(238, 82)
                btnExit.Visible = True

                ''판정 창 그룹박스
                gpbJudge.Location = New Size(10, 90)
                gpbJudge.Size = New Size(1895, 130)
                gpbJudge.Visible = True

                lblJudge.Location = New Size(300, 27)
                lblJudge.Size = New Size(159, 83)
                lblJudge.Visible = True
                lblJudge.Text = "바코드"

                txbBarcodeNum.Location = New Size(528, 15)
                txbBarcodeNum.Size = New Size(840, 105)
                txbBarcodeNum.Visible = True
                txbBarcodeNum.Font = New Font("함초롬바탕", 56.25)

                btnCmdInput.Location = New Size(1413, 17)
                btnCmdInput.Size = New Size(345, 104)
                btnCmdInput.Visible = False

                ''정보출력창 
                gpbDeviceInfo.Location = New Size(10, 220)
                gpbDeviceInfo.Size = New Size(1895, 785)  '1895, 460
                gpbDeviceInfo.Visible = True

                ''정보출력창(Face/Body) 
                FaceInfoSet_X = 10
                FaceInfoSet_Y = 10
                InfoSet_X(DS_TYPE.DS_FACE) = FaceInfoSet_X
                InfoSet_Y(DS_TYPE.DS_FACE) = FaceInfoSet_Y
                InfoSet_X(DS_TYPE.DS_BODY) = FaceInfoSet_X
                InfoSet_Y(DS_TYPE.DS_BODY) = FaceInfoSet_Y
                gpbFaceInfoSet.Location = New Size(FaceInfoSet_X, FaceInfoSet_Y)
                gpbFaceInfoSet.Size = New Size(610, 770)
                gpbFaceInfoSet.Visible = True


                ''정보출력창(Main) 
                DevInfoSet_X = 640
                DevInfoSet_Y = 10
                InfoSet_X(DS_TYPE.DS_DEV) = DevInfoSet_X
                InfoSet_Y(DS_TYPE.DS_DEV) = DevInfoSet_Y
                gpbDevInfoSet.Location = New Size(DevInfoSet_X, DevInfoSet_Y)
                gpbDevInfoSet.Size = New Size(610, 770)
                gpbDevInfoSet.Visible = True

                ''정보출력창(Eye) 
                EyeInfoSet_X = 1270
                EyeInfoSet_Y = 10
                InfoSet_X(DS_TYPE.DS_EYE) = EyeInfoSet_X
                InfoSet_Y(DS_TYPE.DS_EYE) = EyeInfoSet_Y
                gpbEyeInfoSet.Location = New Size(EyeInfoSet_X, EyeInfoSet_Y)
                gpbEyeInfoSet.Size = New Size(610, 770)
                gpbEyeInfoSet.Visible = True

                ''정보출력 기기정보창(Face) 
                gpbFaceInfo.Location = New Size(10, 120)
                gpbFaceInfo.Size = New Size(589, 255)
                gpbFaceInfo.Visible = True

                ''정보출력 기기정보창(Main) 
                gpbDevInfo.Location = New Size(10, 120)
                gpbDevInfo.Size = New Size(589, 255)
                gpbDevInfo.Visible = True

                ''정보출력 기기정보창(Eye) 
                gpbEyeInfo.Location = New Size(10, 120)
                gpbEyeInfo.Size = New Size(589, 255)
                gpbEyeInfo.Visible = True

                For i = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    pnlModel(i).Location = New Size(10, 25)
                    pnlModel(i).Size = New Size(285, 45)
                    pnlModel(i).Visible = True

                    pnlManufacture(i).Location = New Size(10, 70)
                    pnlManufacture(i).Size = New Size(285, 45)
                    pnlManufacture(i).Visible = True

                    pnlYearMonth(i).Location = New Size(10, 115)
                    pnlYearMonth(i).Size = New Size(285, 45)
                    pnlYearMonth(i).Visible = True

                    pnlSN(i).Location = New Size(10, 160)
                    pnlSN(i).Size = New Size(285, 45)
                    pnlSN(i).Visible = True

                    pnlDate(i).Location = New Size(10, 205)
                    pnlDate(i).Size = New Size(285, 45)
                    pnlDate(i).Visible = True

                    pnlCart(i).Location = New Size(300, 25)
                    pnlCart(i).Size = New Size(285, 45)
                    pnlCart(i).Visible = True

                    pnlAbroad(i).Location = New Size(300, 70)
                    pnlAbroad(i).Size = New Size(285, 45)
                    pnlAbroad(i).Visible = True

                    pnlAgency(i).Location = New Size(300, 115)
                    pnlAgency(i).Size = New Size(285, 45)
                    pnlAgency(i).Visible = True

                    pnlRshot(i).Location = New Size(300, 160)
                    pnlRshot(i).Size = New Size(285, 45)
                    pnlRshot(i).Visible = True

                    pnlTshot(i).Location = New Size(300, 205)
                    pnlTshot(i).Size = New Size(285, 45)
                    pnlTshot(i).Visible = True

                    pnlTDSN(i).Visible = False
                    pnlFW(i).Visible = False
                    pnlPower(i).Visible = False
                    pnlFreq(i).Visible = False

                    gpbAgingInfo(i).Location = New Size(10, 385)
                    gpbAgingInfo(i).Size = New Size(589, 165)
                    gpbAgingInfo(i).Visible = True

                    gpbCTInfo(i).Location = New Size(10, 560)
                    gpbCTInfo(i).Size = New Size(589, 80)
                    gpbCTInfo(i).Visible = True

                    gpbIQCInfo(i).Location = New Size(10, 650)
                    gpbIQCInfo(i).Size = New Size(589, 120)
                    gpbIQCInfo(i).Visible = True
                Next

                gpbFaceInfo.BackColor = Color.Silver
                gpbEyeInfo.BackColor = Color.Silver

                pnlFW(DS_TYPE.DS_DEV).Location = New Size(10, 160)
                pnlFW(DS_TYPE.DS_DEV).Size = New Size(285, 45)
                pnlFW(DS_TYPE.DS_DEV).Visible = True
                pnlRshot(DS_TYPE.DS_DEV).Visible = False
                pnlTshot(DS_TYPE.DS_DEV).Visible = False
                PanelFaceDate.Visible = False
                PanelDevDate.Visible = False
                PanelEyeDate.Visible = False

                ''생산수량카운터창 
                gpbOKCnt.Visible = False

                ''실행버튼
                btnCmdStart.Visible = False

                ReadModeTextBoxAllReset()
            Case FORM_TYPE.READ_DETIL_MODE
        End Select

        'Me.WindowState = FormWindowState.Maximized
        Me.Show()
        Me.Refresh()
    End Sub
    Private Sub SetVariableBinding()
        ResultTextBoxList(DS_TYPE.DS_DEV, 0) = txbInfo_DevBarcord
        ResultTextBoxList(DS_TYPE.DS_DEV, 1) = txbInfo_DevManufacture
        ResultTextBoxList(DS_TYPE.DS_DEV, 2) = txbInfo_DevSN
        ResultTextBoxList(DS_TYPE.DS_DEV, 3) = txbInfo_DevModel
        ResultTextBoxList(DS_TYPE.DS_DEV, 4) = txbInfo_DevAbroad
        ResultTextBoxList(DS_TYPE.DS_DEV, 5) = txbInfo_DevAgency
        ResultTextBoxList(DS_TYPE.DS_DEV, 6) = txbInfo_DevRshot
        ResultTextBoxList(DS_TYPE.DS_DEV, 7) = txbInfo_DevTshot
        ResultTextBoxList(DS_TYPE.DS_DEV, 8) = txbInfo_DevYear
        ResultTextBoxList(DS_TYPE.DS_DEV, 9) = txbInfo_DevMonth

        ResultTextBoxList(DS_TYPE.DS_FACE, 0) = txbInfo_FaceBarcord
        ResultTextBoxList(DS_TYPE.DS_FACE, 1) = txbInfo_FaceManufacture
        ResultTextBoxList(DS_TYPE.DS_FACE, 2) = txbInfo_FaceSN
        ResultTextBoxList(DS_TYPE.DS_FACE, 3) = txbInfo_FaceModel
        ResultTextBoxList(DS_TYPE.DS_FACE, 4) = txbInfo_FaceAbroad
        ResultTextBoxList(DS_TYPE.DS_FACE, 5) = txbInfo_FaceAgency
        ResultTextBoxList(DS_TYPE.DS_FACE, 6) = txbInfo_FaceRshot
        ResultTextBoxList(DS_TYPE.DS_FACE, 7) = txbInfo_FaceTshot
        ResultTextBoxList(DS_TYPE.DS_FACE, 8) = txbInfo_FaceYear
        ResultTextBoxList(DS_TYPE.DS_FACE, 9) = txbInfo_FaceMonth

        ResultTextBoxList(DS_TYPE.DS_EYE, 0) = txbInfo_EyeBarcord
        ResultTextBoxList(DS_TYPE.DS_EYE, 1) = txbInfo_EyeManufacture
        ResultTextBoxList(DS_TYPE.DS_EYE, 2) = txbInfo_EyeSN
        ResultTextBoxList(DS_TYPE.DS_EYE, 3) = txbInfo_EyeModel
        ResultTextBoxList(DS_TYPE.DS_EYE, 4) = txbInfo_EyeAbroad
        ResultTextBoxList(DS_TYPE.DS_EYE, 5) = txbInfo_EyeAgency
        ResultTextBoxList(DS_TYPE.DS_EYE, 6) = txbInfo_EyeRshot
        ResultTextBoxList(DS_TYPE.DS_EYE, 7) = txbInfo_EyeTshot
        ResultTextBoxList(DS_TYPE.DS_EYE, 8) = txbInfo_EyeYear
        ResultTextBoxList(DS_TYPE.DS_EYE, 9) = txbInfo_EyeMonth

        ResultTextBoxList(DS_TYPE.DS_BODY, 0) = txbInfo_FaceBarcord
        ResultTextBoxList(DS_TYPE.DS_BODY, 1) = txbInfo_FaceManufacture
        ResultTextBoxList(DS_TYPE.DS_BODY, 2) = txbInfo_FaceSN
        ResultTextBoxList(DS_TYPE.DS_BODY, 3) = txbInfo_FaceModel
        ResultTextBoxList(DS_TYPE.DS_BODY, 4) = txbInfo_FaceAbroad
        ResultTextBoxList(DS_TYPE.DS_BODY, 5) = txbInfo_FaceAgency
        ResultTextBoxList(DS_TYPE.DS_BODY, 6) = txbInfo_FaceRshot
        ResultTextBoxList(DS_TYPE.DS_BODY, 7) = txbInfo_FaceTshot
        ResultTextBoxList(DS_TYPE.DS_BODY, 8) = txbInfo_FaceYear
        ResultTextBoxList(DS_TYPE.DS_BODY, 9) = txbInfo_FaceMonth

        gpbInfoSet(DS_TYPE.DS_DEV) = gpbDevInfoSet
        gpbInfoSet(DS_TYPE.DS_FACE) = gpbFaceInfoSet
        gpbInfoSet(DS_TYPE.DS_EYE) = gpbEyeInfoSet
        gpbInfoSet(DS_TYPE.DS_BODY) = gpbFaceInfoSet

        chkDeviceUse(DS_TYPE.DS_DEV) = chkDevUse
        chkDeviceUse(DS_TYPE.DS_FACE) = chkFaceUse
        chkDeviceUse(DS_TYPE.DS_EYE) = chkEyeUse
        chkDeviceUse(DS_TYPE.DS_BODY) = chkBodyUse

        txbInfo_Barcord(DS_TYPE.DS_DEV) = txbInfo_DevBarcord
        txbInfo_Barcord(DS_TYPE.DS_FACE) = txbInfo_FaceBarcord
        txbInfo_Barcord(DS_TYPE.DS_EYE) = txbInfo_EyeBarcord
        txbInfo_Barcord(DS_TYPE.DS_BODY) = txbInfo_FaceBarcord

        txbInfo_Model(DS_TYPE.DS_DEV) = txbInfo_DevModel
        txbInfo_Model(DS_TYPE.DS_FACE) = txbInfo_FaceModel
        txbInfo_Model(DS_TYPE.DS_EYE) = txbInfo_EyeModel
        txbInfo_Model(DS_TYPE.DS_BODY) = txbInfo_FaceModel

        txbInfo_Cart(DS_TYPE.DS_DEV) = txbInfo_DevCart
        txbInfo_Cart(DS_TYPE.DS_FACE) = txbInfo_FaceCart
        txbInfo_Cart(DS_TYPE.DS_EYE) = txbInfo_EyeCart
        txbInfo_Cart(DS_TYPE.DS_BODY) = txbInfo_FaceCart

        txbInfo_Date(DS_TYPE.DS_DEV) = txbInfo_DevDate
        txbInfo_Date(DS_TYPE.DS_FACE) = txbInfo_FaceDate
        txbInfo_Date(DS_TYPE.DS_EYE) = txbInfo_EyeDate
        txbInfo_Date(DS_TYPE.DS_BODY) = txbInfo_FaceDate

        txbInfo_Manufacture(DS_TYPE.DS_DEV) = txbInfo_DevManufacture
        txbInfo_Manufacture(DS_TYPE.DS_FACE) = txbInfo_FaceManufacture
        txbInfo_Manufacture(DS_TYPE.DS_EYE) = txbInfo_EyeManufacture
        txbInfo_Manufacture(DS_TYPE.DS_BODY) = txbInfo_FaceManufacture

        txbInfo_Year(DS_TYPE.DS_DEV) = txbInfo_DevYear
        txbInfo_Year(DS_TYPE.DS_FACE) = txbInfo_FaceYear
        txbInfo_Year(DS_TYPE.DS_EYE) = txbInfo_EyeYear
        txbInfo_Year(DS_TYPE.DS_BODY) = txbInfo_FaceYear

        txbInfo_Month(DS_TYPE.DS_DEV) = txbInfo_DevMonth
        txbInfo_Month(DS_TYPE.DS_FACE) = txbInfo_FaceMonth
        txbInfo_Month(DS_TYPE.DS_EYE) = txbInfo_EyeMonth
        txbInfo_Month(DS_TYPE.DS_BODY) = txbInfo_FaceMonth

        txbInfo_SN(DS_TYPE.DS_DEV) = txbInfo_DevSN
        txbInfo_SN(DS_TYPE.DS_FACE) = txbInfo_FaceSN
        txbInfo_SN(DS_TYPE.DS_EYE) = txbInfo_EyeSN
        txbInfo_SN(DS_TYPE.DS_BODY) = txbInfo_FaceSN

        txbInfo_FW(DS_TYPE.DS_DEV) = txbInfo_DevFW
        txbInfo_FW(DS_TYPE.DS_FACE) = txbInfo_FaceFW
        txbInfo_FW(DS_TYPE.DS_EYE) = txbInfo_EyeFW
        txbInfo_FW(DS_TYPE.DS_BODY) = txbInfo_FaceFW

        txbInfo_Abroad(DS_TYPE.DS_DEV) = txbInfo_DevAbroad
        txbInfo_Abroad(DS_TYPE.DS_FACE) = txbInfo_FaceAbroad
        txbInfo_Abroad(DS_TYPE.DS_EYE) = txbInfo_EyeAbroad
        txbInfo_Abroad(DS_TYPE.DS_BODY) = txbInfo_FaceAbroad

        txbInfo_Agency(DS_TYPE.DS_DEV) = txbInfo_DevAgency
        txbInfo_Agency(DS_TYPE.DS_FACE) = txbInfo_FaceAgency
        txbInfo_Agency(DS_TYPE.DS_EYE) = txbInfo_EyeAgency
        txbInfo_Agency(DS_TYPE.DS_BODY) = txbInfo_FaceAgency

        txbInfo_TDSN(DS_TYPE.DS_DEV) = txbInfo_DevTDSN
        txbInfo_TDSN(DS_TYPE.DS_FACE) = txbInfo_FaceTDSN
        txbInfo_TDSN(DS_TYPE.DS_EYE) = txbInfo_EyeTDSN
        txbInfo_TDSN(DS_TYPE.DS_BODY) = txbInfo_FaceTDSN

        txbInfo_Rshot(DS_TYPE.DS_DEV) = txbInfo_DevRshot
        txbInfo_Rshot(DS_TYPE.DS_FACE) = txbInfo_FaceRshot
        txbInfo_Rshot(DS_TYPE.DS_EYE) = txbInfo_EyeRshot
        txbInfo_Rshot(DS_TYPE.DS_BODY) = txbInfo_FaceRshot

        txbInfo_Tshot(DS_TYPE.DS_DEV) = txbInfo_DevTshot
        txbInfo_Tshot(DS_TYPE.DS_FACE) = txbInfo_FaceTshot
        txbInfo_Tshot(DS_TYPE.DS_EYE) = txbInfo_EyeTshot
        txbInfo_Tshot(DS_TYPE.DS_BODY) = txbInfo_FaceTshot

        txbInfo_Freq(DS_TYPE.DS_DEV) = txbInfo_DevFreq
        txbInfo_Freq(DS_TYPE.DS_FACE) = txbInfo_FaceFreq
        txbInfo_Freq(DS_TYPE.DS_EYE) = txbInfo_EyeFreq
        txbInfo_Freq(DS_TYPE.DS_BODY) = txbInfo_FaceFreq

        txbInfo_Power(DS_TYPE.DS_DEV) = txbInfo_DevPower
        txbInfo_Power(DS_TYPE.DS_FACE) = txbInfo_FacePower
        txbInfo_Power(DS_TYPE.DS_EYE) = txbInfo_EyePower
        txbInfo_Power(DS_TYPE.DS_BODY) = txbInfo_FacePower

        lblInfo_Model(DS_TYPE.DS_DEV) = lblInfo_DevModel
        lblInfo_Model(DS_TYPE.DS_FACE) = lblInfo_FaceModel
        lblInfo_Model(DS_TYPE.DS_EYE) = lblInfo_EyeModel
        lblInfo_Model(DS_TYPE.DS_BODY) = lblInfo_FaceModel

        lblInfo_YearMonth(DS_TYPE.DS_DEV) = lblInfo_DevYearMonth
        lblInfo_YearMonth(DS_TYPE.DS_FACE) = lblInfo_FaceYearMonth
        lblInfo_YearMonth(DS_TYPE.DS_EYE) = lblInfo_EyeYearMonth
        lblInfo_YearMonth(DS_TYPE.DS_BODY) = lblInfo_FaceYearMonth

        lblInfo_Year(DS_TYPE.DS_DEV) = lblInfo_DevYear
        lblInfo_Year(DS_TYPE.DS_FACE) = lblInfo_FaceYear
        lblInfo_Year(DS_TYPE.DS_EYE) = lblInfo_EyeYear
        lblInfo_Year(DS_TYPE.DS_BODY) = lblInfo_FaceYear

        lblInfo_Month(DS_TYPE.DS_DEV) = lblInfo_DevMonth
        lblInfo_Month(DS_TYPE.DS_FACE) = lblInfo_FaceMonth
        lblInfo_Month(DS_TYPE.DS_EYE) = lblInfo_EyeMonth
        lblInfo_Month(DS_TYPE.DS_BODY) = lblInfo_FaceMonth

        lblInfo_SN(DS_TYPE.DS_DEV) = lblInfo_DevSN
        lblInfo_SN(DS_TYPE.DS_FACE) = lblInfo_FaceSN
        lblInfo_SN(DS_TYPE.DS_EYE) = lblInfo_EyeSN
        lblInfo_SN(DS_TYPE.DS_BODY) = lblInfo_FaceSN

        pnlModel(DS_TYPE.DS_DEV) = pnlDevModel
        pnlModel(DS_TYPE.DS_FACE) = pnlFaceModel
        pnlModel(DS_TYPE.DS_EYE) = pnlEyeModel
        pnlModel(DS_TYPE.DS_BODY) = pnlFaceModel

        pnlCart(DS_TYPE.DS_DEV) = pnlDevCart
        pnlCart(DS_TYPE.DS_FACE) = pnlFaceCart
        pnlCart(DS_TYPE.DS_EYE) = pnlEyeCart
        pnlCart(DS_TYPE.DS_BODY) = pnlFaceCart

        pnlDate(DS_TYPE.DS_DEV) = pnlDevDate
        pnlDate(DS_TYPE.DS_FACE) = pnlFaceDate
        pnlDate(DS_TYPE.DS_EYE) = pnlEyeDate
        pnlDate(DS_TYPE.DS_BODY) = pnlFaceDate

        pnlManufacture(DS_TYPE.DS_DEV) = pnlDevManufacture
        pnlManufacture(DS_TYPE.DS_FACE) = pnlFaceManufacture
        pnlManufacture(DS_TYPE.DS_EYE) = pnlEyeManufacture
        pnlManufacture(DS_TYPE.DS_BODY) = pnlFaceManufacture

        pnlYearMonth(DS_TYPE.DS_DEV) = pnlDevYearMonth
        pnlYearMonth(DS_TYPE.DS_FACE) = pnlFaceYearMonth
        pnlYearMonth(DS_TYPE.DS_EYE) = pnlEyeYearMonth
        pnlYearMonth(DS_TYPE.DS_BODY) = pnlFaceYearMonth

        pnlSN(DS_TYPE.DS_DEV) = pnlDevSN
        pnlSN(DS_TYPE.DS_FACE) = pnlFaceSN
        pnlSN(DS_TYPE.DS_EYE) = pnlEyeSN
        pnlSN(DS_TYPE.DS_BODY) = pnlFaceSN

        pnlTDSN(DS_TYPE.DS_DEV) = pnlDevTDSN
        pnlTDSN(DS_TYPE.DS_FACE) = pnlFaceTDSN
        pnlTDSN(DS_TYPE.DS_EYE) = pnlEyeTDSN
        pnlTDSN(DS_TYPE.DS_BODY) = pnlFaceTDSN

        pnlFW(DS_TYPE.DS_DEV) = pnlDevFW
        pnlFW(DS_TYPE.DS_FACE) = pnlFaceFW
        pnlFW(DS_TYPE.DS_EYE) = pnlEyeFW
        pnlFW(DS_TYPE.DS_BODY) = pnlFaceFW

        pnlAbroad(DS_TYPE.DS_DEV) = pnlDevAbroad
        pnlAbroad(DS_TYPE.DS_FACE) = pnlFaceAbroad
        pnlAbroad(DS_TYPE.DS_EYE) = pnlEyeAbroad
        pnlAbroad(DS_TYPE.DS_BODY) = pnlFaceAbroad

        pnlAgency(DS_TYPE.DS_DEV) = pnlDevAgency
        pnlAgency(DS_TYPE.DS_FACE) = pnlFaceAgency
        pnlAgency(DS_TYPE.DS_EYE) = pnlEyeAgency
        pnlAgency(DS_TYPE.DS_BODY) = pnlFaceAgency

        pnlRshot(DS_TYPE.DS_DEV) = pnlDevRshot
        pnlRshot(DS_TYPE.DS_FACE) = pnlFaceRshot
        pnlRshot(DS_TYPE.DS_EYE) = pnlEyeRshot
        pnlRshot(DS_TYPE.DS_BODY) = pnlFaceRshot

        pnlTshot(DS_TYPE.DS_DEV) = pnlDevTshot
        pnlTshot(DS_TYPE.DS_FACE) = pnlFaceTshot
        pnlTshot(DS_TYPE.DS_EYE) = pnlEyeTshot
        pnlTshot(DS_TYPE.DS_BODY) = pnlFaceTshot

        pnlFreq(DS_TYPE.DS_DEV) = pnlDevFreq
        pnlFreq(DS_TYPE.DS_FACE) = pnlFaceFreq
        pnlFreq(DS_TYPE.DS_EYE) = pnlEyeFreq
        pnlFreq(DS_TYPE.DS_BODY) = pnlFaceFreq

        pnlPower(DS_TYPE.DS_DEV) = pnlDevPower
        pnlPower(DS_TYPE.DS_FACE) = pnlFacePower
        pnlPower(DS_TYPE.DS_EYE) = pnlEyePower
        pnlPower(DS_TYPE.DS_BODY) = pnlFacePower

        txbProductCntPro(1) = txbProductCntPS
        txbProductCntPro(2) = txbProductCntPF
        txbProductCntPro(3) = txbProductCntPE
        txbProductCntPro(4) = txbProductCntPB
        txbProductCntLux(1) = txbProductCntLS
        txbProductCntLux(2) = txbProductCntLF
        txbProductCntLux(3) = txbProductCntLE
        txbProductCntLux(4) = txbProductCntLB

        ItemSelectItem(1) = ItemSelectItem01
        ItemSelectItem(2) = ItemSelectItem02
        ItemSelectItem(3) = ItemSelectItem03
        ItemSelectItem(4) = ItemSelectItem04
        ItemSelectItem(5) = ItemSelectItem05
        ItemSelectItem(6) = ItemSelectItem06
        ItemSelectItem(7) = ItemSelectItem07
        ItemSelectItem(8) = ItemSelectItem08
        ItemSelectItem(9) = ItemSelectItem09
        ItemSelectItem(10) = ItemSelectItem10
        ItemSelectItem(11) = ItemSelectItem11
        ItemSelectItem(12) = ItemSelectItem12
        ItemSelectItem(13) = ItemSelectItem13
        ItemSelectItem(14) = ItemSelectItem14
        ItemSelectItem(15) = ItemSelectItem15

        txbItemSelectModel(1) = txbItemSelectModel01
        txbItemSelectModel(2) = txbItemSelectModel02
        txbItemSelectModel(3) = txbItemSelectModel03
        txbItemSelectModel(4) = txbItemSelectModel04
        txbItemSelectModel(5) = txbItemSelectModel05
        txbItemSelectModel(6) = txbItemSelectModel06
        txbItemSelectModel(7) = txbItemSelectModel07
        txbItemSelectModel(8) = txbItemSelectModel08
        txbItemSelectModel(9) = txbItemSelectModel09
        txbItemSelectModel(10) = txbItemSelectModel10
        txbItemSelectModel(11) = txbItemSelectModel11
        txbItemSelectModel(12) = txbItemSelectModel12
        txbItemSelectModel(13) = txbItemSelectModel13
        txbItemSelectModel(14) = txbItemSelectModel14
        txbItemSelectModel(15) = txbItemSelectModel15

        ItemSelectFace(1) = ItemSelectFace01
        ItemSelectFace(2) = ItemSelectFace02
        ItemSelectFace(3) = ItemSelectFace03
        ItemSelectFace(4) = ItemSelectFace04
        ItemSelectFace(5) = ItemSelectFace05
        ItemSelectFace(6) = ItemSelectFace06
        ItemSelectFace(7) = ItemSelectFace07
        ItemSelectFace(8) = ItemSelectFace08
        ItemSelectFace(9) = ItemSelectFace09
        ItemSelectFace(10) = ItemSelectFace10
        ItemSelectFace(11) = ItemSelectFace11
        ItemSelectFace(12) = ItemSelectFace12
        ItemSelectFace(13) = ItemSelectFace13
        ItemSelectFace(14) = ItemSelectFace14
        ItemSelectFace(15) = ItemSelectFace15

        ItemSelectEye(1) = ItemSelectEye01
        ItemSelectEye(2) = ItemSelectEye02
        ItemSelectEye(3) = ItemSelectEye03
        ItemSelectEye(4) = ItemSelectEye04
        ItemSelectEye(5) = ItemSelectEye05
        ItemSelectEye(6) = ItemSelectEye06
        ItemSelectEye(7) = ItemSelectEye07
        ItemSelectEye(8) = ItemSelectEye08
        ItemSelectEye(9) = ItemSelectEye09
        ItemSelectEye(10) = ItemSelectEye10
        ItemSelectEye(11) = ItemSelectEye11
        ItemSelectEye(12) = ItemSelectEye12
        ItemSelectEye(13) = ItemSelectEye13
        ItemSelectEye(14) = ItemSelectEye14
        ItemSelectEye(15) = ItemSelectEye15

        ItemSelectAbroad(1) = ItemSelectAbroad01
        ItemSelectAbroad(2) = ItemSelectAbroad02
        ItemSelectAbroad(3) = ItemSelectAbroad03
        ItemSelectAbroad(4) = ItemSelectAbroad04
        ItemSelectAbroad(5) = ItemSelectAbroad05
        ItemSelectAbroad(6) = ItemSelectAbroad06
        ItemSelectAbroad(7) = ItemSelectAbroad07
        ItemSelectAbroad(8) = ItemSelectAbroad08
        ItemSelectAbroad(9) = ItemSelectAbroad09
        ItemSelectAbroad(10) = ItemSelectAbroad10
        ItemSelectAbroad(11) = ItemSelectAbroad11
        ItemSelectAbroad(12) = ItemSelectAbroad12
        ItemSelectAbroad(13) = ItemSelectAbroad13
        ItemSelectAbroad(14) = ItemSelectAbroad14
        ItemSelectAbroad(15) = ItemSelectAbroad15

        ItemSelectAgency(1) = ItemSelectAgency01
        ItemSelectAgency(2) = ItemSelectAgency02
        ItemSelectAgency(3) = ItemSelectAgency03
        ItemSelectAgency(4) = ItemSelectAgency04
        ItemSelectAgency(5) = ItemSelectAgency05
        ItemSelectAgency(6) = ItemSelectAgency06
        ItemSelectAgency(7) = ItemSelectAgency07
        ItemSelectAgency(8) = ItemSelectAgency08
        ItemSelectAgency(9) = ItemSelectAgency09
        ItemSelectAgency(10) = ItemSelectAgency10
        ItemSelectAgency(11) = ItemSelectAgency11
        ItemSelectAgency(12) = ItemSelectAgency12
        ItemSelectAgency(13) = ItemSelectAgency13
        ItemSelectAgency(14) = ItemSelectAgency14
        ItemSelectAgency(15) = ItemSelectAgency15

        gpbAgingInfo(DS_TYPE.DS_DEV) = gpbFaceAgingInfo
        gpbAgingInfo(DS_TYPE.DS_FACE) = gpbFaceAgingInfo
        gpbAgingInfo(DS_TYPE.DS_EYE) = gpbEyeAgingInfo
        gpbAgingInfo(DS_TYPE.DS_BODY) = gpbFaceAgingInfo

        gpbCTInfo(DS_TYPE.DS_DEV) = gpbFaceCTInfo
        gpbCTInfo(DS_TYPE.DS_FACE) = gpbFaceCTInfo
        gpbCTInfo(DS_TYPE.DS_EYE) = gpbEyeCTInfo
        gpbCTInfo(DS_TYPE.DS_BODY) = gpbFaceCTInfo

        gpbIQCInfo(DS_TYPE.DS_DEV) = gpbFaceIQCInfo
        gpbIQCInfo(DS_TYPE.DS_FACE) = gpbFaceIQCInfo
        gpbIQCInfo(DS_TYPE.DS_EYE) = gpbEyeIQCInfo
        gpbIQCInfo(DS_TYPE.DS_BODY) = gpbFaceIQCInfo

        txbInfo_AGDate(DS_TYPE.DS_DEV) = txbInfo_FaceAGDate
        txbInfo_AGDate(DS_TYPE.DS_FACE) = txbInfo_FaceAGDate
        txbInfo_AGDate(DS_TYPE.DS_EYE) = txbInfo_EyeAGDate
        txbInfo_AGDate(DS_TYPE.DS_BODY) = txbInfo_FaceAGDate

        txbInfo_AGShot(DS_TYPE.DS_DEV) = txbInfo_FaceAGShot
        txbInfo_AGShot(DS_TYPE.DS_FACE) = txbInfo_FaceAGShot
        txbInfo_AGShot(DS_TYPE.DS_EYE) = txbInfo_EyeAGShot
        txbInfo_AGShot(DS_TYPE.DS_BODY) = txbInfo_FaceAGShot

        txbInfo_AGStart(DS_TYPE.DS_DEV) = txbInfo_FaceAGStart
        txbInfo_AGStart(DS_TYPE.DS_FACE) = txbInfo_FaceAGStart
        txbInfo_AGStart(DS_TYPE.DS_EYE) = txbInfo_EyeAGStart
        txbInfo_AGStart(DS_TYPE.DS_BODY) = txbInfo_FaceAGStart

        txbInfo_AGOkNg(DS_TYPE.DS_DEV) = txbInfo_FaceAGOkNg
        txbInfo_AGOkNg(DS_TYPE.DS_FACE) = txbInfo_FaceAGOkNg
        txbInfo_AGOkNg(DS_TYPE.DS_EYE) = txbInfo_EyeAGOkNg
        txbInfo_AGOkNg(DS_TYPE.DS_BODY) = txbInfo_FaceAGOkNg

        txbInfo_AGPower(DS_TYPE.DS_DEV) = txbInfo_FaceAGPower
        txbInfo_AGPower(DS_TYPE.DS_FACE) = txbInfo_FaceAGPower
        txbInfo_AGPower(DS_TYPE.DS_EYE) = txbInfo_EyeAGPower
        txbInfo_AGPower(DS_TYPE.DS_BODY) = txbInfo_FaceAGPower

        txbInfo_AGEnd(DS_TYPE.DS_DEV) = txbInfo_FaceAGEnd
        txbInfo_AGEnd(DS_TYPE.DS_FACE) = txbInfo_FaceAGEnd
        txbInfo_AGEnd(DS_TYPE.DS_EYE) = txbInfo_EyeAGEnd
        txbInfo_AGEnd(DS_TYPE.DS_BODY) = txbInfo_FaceAGEnd

        txbInfo_CTDate(DS_TYPE.DS_DEV) = txbInfo_FaceCTDate
        txbInfo_CTDate(DS_TYPE.DS_FACE) = txbInfo_FaceCTDate
        txbInfo_CTDate(DS_TYPE.DS_EYE) = txbInfo_EyeCTDate
        txbInfo_CTDate(DS_TYPE.DS_BODY) = txbInfo_FaceCTDate

        txbInfo_CTFreq(DS_TYPE.DS_DEV) = txbInfo_FaceCTFreq
        txbInfo_CTFreq(DS_TYPE.DS_FACE) = txbInfo_FaceCTFreq
        txbInfo_CTFreq(DS_TYPE.DS_EYE) = txbInfo_EyeCTFreq
        txbInfo_CTFreq(DS_TYPE.DS_BODY) = txbInfo_FaceCTFreq

        txbInfo_IQCGrade(DS_TYPE.DS_DEV) = txbInfo_FaceIQCGrade
        txbInfo_IQCGrade(DS_TYPE.DS_FACE) = txbInfo_FaceIQCGrade
        txbInfo_IQCGrade(DS_TYPE.DS_EYE) = txbInfo_EyeIQCGrade
        txbInfo_IQCGrade(DS_TYPE.DS_BODY) = txbInfo_FaceIQCGrade

        txbInfo_IQCDate(DS_TYPE.DS_DEV) = txbInfo_FaceIQCDate
        txbInfo_IQCDate(DS_TYPE.DS_FACE) = txbInfo_FaceIQCDate
        txbInfo_IQCDate(DS_TYPE.DS_EYE) = txbInfo_EyeIQCDate
        txbInfo_IQCDate(DS_TYPE.DS_BODY) = txbInfo_FaceIQCDate

        txbInfo_IQCTD(DS_TYPE.DS_DEV) = txbInfo_FaceIQCTD
        txbInfo_IQCTD(DS_TYPE.DS_FACE) = txbInfo_FaceIQCTD
        txbInfo_IQCTD(DS_TYPE.DS_EYE) = txbInfo_EyeIQCTD
        txbInfo_IQCTD(DS_TYPE.DS_BODY) = txbInfo_FaceIQCTD

        txbInfo_IQCCap(DS_TYPE.DS_DEV) = txbInfo_FaceIQCCap
        txbInfo_IQCCap(DS_TYPE.DS_FACE) = txbInfo_FaceIQCCap
        txbInfo_IQCCap(DS_TYPE.DS_EYE) = txbInfo_EyeIQCCap
        txbInfo_IQCCap(DS_TYPE.DS_BODY) = txbInfo_FaceIQCCap

        ''=== 년월일 콤보박스 바인딩 ===
        cmbInfo_Year(DS_TYPE.DS_DEV) = cmbInfo_DevYear
        cmbInfo_Year(DS_TYPE.DS_FACE) = cmbInfo_FaceYear
        cmbInfo_Year(DS_TYPE.DS_EYE) = cmbInfo_EyeYear
        cmbInfo_Year(DS_TYPE.DS_BODY) = cmbInfo_FaceYear

        cmbInfo_Month(DS_TYPE.DS_DEV) = cmbInfo_DevMonth
        cmbInfo_Month(DS_TYPE.DS_FACE) = cmbInfo_FaceMonth
        cmbInfo_Month(DS_TYPE.DS_EYE) = cmbInfo_EyeMonth
        cmbInfo_Month(DS_TYPE.DS_BODY) = cmbInfo_FaceMonth

        cmbInfo_Day(DS_TYPE.DS_DEV) = cmbInfo_DevDay
        cmbInfo_Day(DS_TYPE.DS_FACE) = cmbInfo_FaceDay
        cmbInfo_Day(DS_TYPE.DS_EYE) = cmbInfo_EyeDay
        cmbInfo_Day(DS_TYPE.DS_BODY) = cmbInfo_FaceDay

    End Sub

    Private Sub RunProcess_Click(sender As Object, e As EventArgs) Handles btnCmdStart.Click, btnCmdInput.Click
        RunProcess()
    End Sub
    Public Sub RunProcess()
        Select Case RunMode
            Case FORM_TYPE.WRITE_MODE
                RunProcessWrite()
            Case FORM_TYPE.READ_MODE
                RunProcessRead()
        End Select
    End Sub

    Private Function td_Compare(tmpCmd As String, CountType As String, tblName As String) As Boolean
        StrCmd = "SELECT COUNT(" & CountType & ") FROM " & tblName & " WHERE " & CountType & " = '" & tmpCmd & "'"
        Dim CellCount As Int16 = DBQueryScalar(StrCmd)
        If CellCount = 0 Then
            Return False
        End If

        Return True
    End Function

    Public Sub RunProcessRead()
        Dim tmpCmd As String = txbBarcodeNum.Text
        Dim tmpModelType As DS_TYPE
        Dim tmpType As DS_TYPE
        Dim CheckFlag As Boolean = False

        Try
            ''바코드 유효성 확인
            tmpModelType = Val(Mid(txbBarcodeNum.Text, 1, 2))

            If tmpModelType = DS_PRODUCT.DS_PRO_DEV Or tmpModelType = DS_PRODUCT.DS_PRO_FACE Or tmpModelType = DS_PRODUCT.DS_PRO_EYE Or tmpModelType = DS_PRODUCT.DS_PRO_BODY Then
            ElseIf tmpModelType = DS_PRODUCT.DS_LUX_DEV Or tmpModelType = DS_PRODUCT.DS_LUX_FACE Or tmpModelType = DS_PRODUCT.DS_LUX_EYE Or tmpModelType = DS_PRODUCT.DS_LUX_BODY Then
            ElseIf tmpModelType = DS_PRODUCT.DS_ALPHA_DEV Or tmpModelType = DS_PRODUCT.DS_ALPHA_FACE Or tmpModelType = DS_PRODUCT.DS_ALPHA_EYE Or tmpModelType = DS_PRODUCT.DS_ALPHA_BODY Then
            Else
                Return
            End If

            If Len(tmpCmd) <> 12 Then Return

            txbBarcodeNum.BackColor = Color.YellowGreen
            txbBarcodeNum.Clear()
            txbBarcodeNum.AppendText("정보 읽기 중")
            txbBarcodeNum.Refresh()

            tmpType = Val(Mid(tmpCmd, 2, 1))

            ReadModeTextBoxAllReset()

            DelayMs(100)

            If tmpType = DS_TYPE.DS_DEV Then
                gpbInfoSet(DS_TYPE.DS_DEV).Location = New Size(InfoSet_X(DS_TYPE.DS_DEV), InfoSet_Y(DS_TYPE.DS_DEV))
                gpbInfoSet(DS_TYPE.DS_DEV).Visible = True
                gpbInfoSet(DS_TYPE.DS_FACE).Location = New Size(InfoSet_X(DS_TYPE.DS_FACE), InfoSet_Y(DS_TYPE.DS_FACE))
                gpbInfoSet(DS_TYPE.DS_FACE).Text = "FACE카트리지 정보"
                gpbInfoSet(DS_TYPE.DS_FACE).Visible = True
                gpbInfoSet(DS_TYPE.DS_EYE).Location = New Size(InfoSet_X(DS_TYPE.DS_EYE), InfoSet_Y(DS_TYPE.DS_EYE))
                gpbInfoSet(DS_TYPE.DS_EYE).Visible = True

                txbInfo_Barcord(DS_TYPE.DS_DEV).Text = tmpCmd

                If ReadDeviceInfo() = False Then
                    CheckFlag = True
                    txbInfo_Barcord(DS_TYPE.DS_DEV).BackColor = Color.Red
                End If


                txbInfo_Barcord(DS_TYPE.DS_FACE).Text = GetProductSN(tmpCmd, DS_TYPE.DS_FACE)
                If txbInfo_Barcord(DS_TYPE.DS_FACE).Text = "N/A" Then
                    CheckFlag = True
                    txbInfo_Barcord(DS_TYPE.DS_FACE).BackColor = Color.Red
                Else

                    If ReadCartInfo(DS_TYPE.DS_FACE) = False Then
                            CheckFlag = True
                            txbInfo_Barcord(DS_TYPE.DS_FACE).BackColor = Color.Red
                        End If
                    End If

                txbInfo_Barcord(DS_TYPE.DS_EYE).Text = GetProductSN(tmpCmd, DS_TYPE.DS_EYE)
                If txbInfo_Barcord(DS_TYPE.DS_EYE).Text = "N/A" Then
                    CheckFlag = True
                    txbInfo_Barcord(DS_TYPE.DS_EYE).BackColor = Color.Red
                Else
                    If ReadCartInfo(DS_TYPE.DS_EYE) = False Then
                            CheckFlag = True
                            txbInfo_Barcord(DS_TYPE.DS_EYE).BackColor = Color.Red
                        End If
                    End If
            Else
                For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    If tmpType = cnt Then
                        gpbInfoSet(tmpType).Location = New Size(InfoSet_X(DS_TYPE.DS_FACE), InfoSet_Y(DS_TYPE.DS_FACE))
                        gpbInfoSet(tmpType).Visible = True

                        If tmpType = DS_TYPE.DS_BODY Then
                            gpbInfoSet(DS_TYPE.DS_FACE).Text = "BODY카트리지 정보"
                        ElseIf tmpType = DS_TYPE.DS_FACE Then
                            gpbInfoSet(DS_TYPE.DS_FACE).Text = "FACE카트리지 정보"
                        End If
                    Else
                        If cnt <> DS_TYPE.DS_BODY Then
                            gpbInfoSet(cnt).Visible = False
                        End If
                    End If
                Next

                txbInfo_Barcord(tmpType).Text = tmpCmd
                If ReadCartInfo(tmpType) = False Then
                    CheckFlag = True
                    txbInfo_Barcord(tmpType).BackColor = Color.Red
                End If
            End If

            If CheckFlag = True Then
                txbBarcodeNum.Text = "정보 읽기 실패"
                txbBarcodeNum.BackColor = Color.Red
            Else
                txbBarcodeNum.Text = "정보 읽기 성공"
                txbBarcodeNum.BackColor = Color.Green
            End If

            SetBarCodeBoxFocus()

            Exit Sub

        Catch ex As Exception
            Save_ErrorCSV("RunProcessRead," & ex.Message)
        End Try
    End Sub
    Public Sub RunProcessWrite()
        Dim tmpCmd As String = txbBarcodeNum.Text
        Dim CheckFlag As Boolean = True
        Dim tmpNum As Integer

        Try
            CheckFlag = True
            '' 명령어 인지 확인
            Select Case tmpCmd
                Case "[START]"
                    WriteTextBarCodeBox("바코드 입력")
                    If GetStatus() <> DS_STATUS.REWIRTTING Then Return
                Case "[STOP]"
                    Reset_All_DS_Reg()
                    TextBoxAllReset()
                    Reset_All_Connect() '' 모든 기기 미연결 상태로 체크
                    SetStatus(DS_STATUS.STANDBY)
                    WriteTextBarCodeBox("바코드 입력")
                    Return
                Case "[EXIT]"
                    WriteTextBarCodeBox("바코드 입력")
                    Exit_Process()
                    Return
                Case "[MODEL01]", "[MODEL02]", "[MODEL03]", "[MODEL04]", "[MODEL05]", "[MODEL06]", "[MODEL07]", "[MODEL08]", "[MODEL09]", "[MODEL10]", "[MODEL11]", "[MODEL12]", "[MODEL13]", "[MODEL14]", "[MODEL15]"
                    tmpNum = Val(Mid(tmpCmd, 7, 2))
                    cboLoadSelect.SelectedIndex = tmpNum - 1
                    WriteTextBarCodeBox("바코드 입력")
                    Return
                Case "[MODE01]", "[MODE02]", "[MODE03]", "[MODE04]"
                    tmpNum = Val(Mid(tmpCmd, 6, 2)) - 1
                    chkDeviceUse(tmpNum).Checked = Not chkDeviceUse(tmpNum).Checked
                    WriteTextBarCodeBox("바코드 입력")
                    Return
            End Select

            '' 시리얼번호 진행
            txbBarcodeNum.BackColor = Color.Green
            Select Case GetStatus()
                Case DS_STATUS.INIT, DS_STATUS.STANDBY
                    Reset_All_DS_Reg() '' Init DS Register
                    TextBoxAllReset()  '' Init Textbox of Color and Text
                    SetStatus(DS_STATUS.INPUT)
                    RunInput_Process()
                Case DS_STATUS.COMPLETE
                    CheckFlag = True
                    For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                        If chkDeviceUse(cnt).Checked = True And ConnectStatus(cnt) = True Then CheckFlag = False
                    Next
                    If CheckFlag = True Then
                        Reset_All_DS_Reg() '' Init DS Register
                        TextBoxAllReset()  '' Init Textbox of Color and Text
                        SetStatus(DS_STATUS.INPUT)
                        RunInput_Process()
                    Else
                        btnCmdStart.Text = "기기 모두를 제거해 주세요."
                    End If
                Case DS_STATUS.INPUT
                    RunInput_Process()
                Case DS_STATUS.READY
                    RunWrite_Process()
                Case DS_STATUS.REWIRTTING
                    RunReWrite_Process()
            End Select

            SetBarCodeBoxFocus()

        Catch ex As Exception
            Save_ErrorCSV("RunProcess," & ex.Message)
        End Try
    End Sub
    Private Function GetProductSN(strDate As String, ChNum As DS_TYPE) As String
        Dim ItemName As String = ""

        Try
            If ChNum = DS_TYPE.DS_FACE Then
                ItemName = "FaceCart_SN"
            ElseIf ChNum = DS_TYPE.DS_EYE Then
                ItemName = "EyeCart_SN"
            End If

            If ChNum = DS_TYPE.DS_FACE Or ChNum = DS_TYPE.DS_EYE Then
                StrCmd = "Select " & ItemName & " from jomtProductTbl where Product_SN='" & strDate & "';"
                If DBQueryReader(StrCmd) Then
                    Return sqlDataQuery(0)
                End If
            End If

            Return "N/A"
        Catch ex As Exception
            Save_ErrorCSV("GetProductSN," & ex.Message)
            Return "N/A"
        End Try
    End Function
    Private Function ReadDeviceInfo() As Boolean
        Dim strDate As String = txbInfo_Barcord(DS_TYPE.DS_DEV).Text
        Dim tmpStr As String

        Try
            StrCmd = "select Model,Type,Manufacture_Name,Abroad,Manufacture_Year,Manufacture_Month," &
                     "Agency,SN,Manufacture_Date,FW_VER"

            StrCmd = StrCmd & " from jomtDeviceTbl where " & "Product_SN='" & strDate & "';"

            If DBQueryReader(StrCmd) Then
                txbInfo_Model(DS_TYPE.DS_DEV).Text = sqlDataQuery(0)
                txbInfo_Cart(DS_TYPE.DS_DEV).Text = sqlDataQuery(1)
                txbInfo_Manufacture(DS_TYPE.DS_DEV).Text = sqlDataQuery(2)
                txbInfo_Abroad(DS_TYPE.DS_DEV).Text = sqlDataQuery(3)
                txbInfo_Year(DS_TYPE.DS_DEV).Text = sqlDataQuery(4)
                txbInfo_Month(DS_TYPE.DS_DEV).Text = sqlDataQuery(5)
                txbInfo_Agency(DS_TYPE.DS_DEV).Text = sqlDataQuery(6)
                txbInfo_SN(DS_TYPE.DS_DEV).Text = sqlDataQuery(7)
                tmpStr = sqlDataQuery(8)
                txbInfo_Date(DS_TYPE.DS_DEV).Text = Mid(tmpStr, 3, 8)
                txbInfo_FW(DS_TYPE.DS_DEV).Text = sqlDataQuery(9)
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            Save_ErrorCSV("ReadDeviceInfo," & ex.Message)
            Return False
        End Try
    End Function
    Private Function ReadCartInfo(ChNum As DS_TYPE) As Boolean
        Dim strDate As String = txbInfo_Barcord(ChNum).Text
        Dim tmpStr As String

        Try
            StrCmd = "select Ct_Model,Ct_Type,Ct_Manufacture_Name,Ct_Abroad,Ct_Manufacture_Year,Ct_Manufacture_Month," &
                     "Ct_Agency,Ct_SN,Ct_Remain_ShotCnt,Manufacture_Date,Ct_Max_ShotCnt," &
                     "P1_Date,P1_Frequency," &
                     "QC_Date,QC_Grade,PV_SN,QC_Capacito"

            StrCmd = StrCmd & " from jomtCartridgeTbl where " & "Product_SN='" & strDate & "';"

            If DBQueryReader(StrCmd) Then
                txbInfo_Model(ChNum).Text = sqlDataQuery(0)
                txbInfo_Cart(ChNum).Text = sqlDataQuery(1)
                txbInfo_Manufacture(ChNum).Text = sqlDataQuery(2)
                txbInfo_Abroad(ChNum).Text = sqlDataQuery(3)
                txbInfo_Year(ChNum).Text = sqlDataQuery(4)
                txbInfo_Month(ChNum).Text = sqlDataQuery(5)
                txbInfo_Agency(ChNum).Text = sqlDataQuery(6)
                txbInfo_SN(ChNum).Text = sqlDataQuery(7)
                txbInfo_Rshot(ChNum).Text = sqlDataQuery(8)
                tmpStr = sqlDataQuery(9)
                txbInfo_Date(ChNum).Text = Mid(tmpStr, 3, 8)
                txbInfo_Tshot(ChNum).Text = sqlDataQuery(10)
                tmpStr = sqlDataQuery(11)
                txbInfo_CTDate(ChNum).Text = Mid(tmpStr, 3, 8)
                txbInfo_CTFreq(ChNum).Text = sqlDataQuery(12)
                tmpStr = sqlDataQuery(13)
                txbInfo_IQCDate(ChNum).Text = Mid(tmpStr, 3, 8)
                txbInfo_IQCGrade(ChNum).Text = sqlDataQuery(14)
                txbInfo_IQCTD(ChNum).Text = sqlDataQuery(15)
                txbInfo_IQCCap(ChNum).Text = sqlDataQuery(16)
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            Save_ErrorCSV("ReadCartInfo," & ex.Message)
            Return False
        End Try
    End Function
    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Exit_Process()
    End Sub
    Private Sub Exit_Process()
        Try
            cmdSerialPort.Close()
            ''Save_ini()
            End
        Catch ex As Exception
            Save_ErrorCSV("Exit_Process," & ex.Message)
        End Try
    End Sub
    Private Sub SetBarCodeBoxFocus()
        If chkBarcode.Checked Then
            BarCodeFixedText = True
            ''cboLoadSelect.Focus()
            lblTime.Focus()
            txbBarcodeNum.Focus()
            BarCodeFixedText = False
        End If
    End Sub
    Private Sub WriteTextBarCodeBox(BarCodeText As String)
        If chkBarcode.Checked Then
            BarCodeFixedText = True
            txbBarcodeNum.Text = BarCodeText
            cboLoadSelect.Focus()
            txbBarcodeNum.Focus()
            BarCodeFixedText = False
        End If
    End Sub
    Private Sub SetConnectStatus(DevType As DS_TYPE, OnOff As Boolean)
        Try
            ConnectStatus(DevType) = OnOff
            EnableBarCodeTxbToggle(DevType) = False
            If OnOff = True Then
                If IsComplete() = "COMPLETE" And GetStatus() = DS_STATUS.READY Then
                    RunProcess()
                End If
            End If
        Catch ex As Exception
            Save_ErrorCSV("SetConnectStatus," & ex.Message)
        End Try
    End Sub
    Private Function GetConnectStatus(DevType As DS_TYPE) As Boolean
        Return ConnectStatus(DevType)
    End Function
    Private Function isConnectStandby() As Boolean
        Dim CheckFlag As Boolean = True

        For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
            If chkDeviceUse(cnt).Checked And ConnectStatus(cnt) Then CheckFlag = False
            If txbInfo_Barcord(cnt).Text <> "N/A" Then CheckFlag = False
        Next

        Return CheckFlag
    End Function
    Private Sub isConnectEnable()
        Dim CheckFlag As Boolean = True

        For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
            If chkDeviceUse(cnt).Checked Then
                If LOAD_FLAG(cnt) = False And ConnectStatus(cnt) Then
                    CheckFlag = False
                End If
            End If
        Next

        If CheckFlag Then
            For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                If chkDeviceUse(cnt).Checked Then
                    If LOAD_FLAG(cnt) = True And ConnectStatus(cnt) Then
                        lblInfo_Model(cnt).ForeColor = Color.Black
                        lblInfo_YearMonth(cnt).ForeColor = Color.Black
                        lblInfo_SN(cnt).ForeColor = Color.Black
                        lblInfo_Year(cnt).ForeColor = Color.Black
                        lblInfo_Month(cnt).ForeColor = Color.Black

                        txbInfo_Model(cnt).ForeColor = Color.Blue
                        txbInfo_SN(cnt).ForeColor = Color.Blue
                        txbInfo_Year(cnt).ForeColor = Color.Blue
                        txbInfo_Month(cnt).ForeColor = Color.Blue
                        txbInfo_Model(cnt).BackColor = Color.FromArgb(255, 255, 192)
                        txbInfo_SN(cnt).BackColor = Color.FromArgb(255, 255, 192)
                        txbInfo_Year(cnt).BackColor = Color.FromArgb(255, 255, 192)
                        txbInfo_Month(cnt).BackColor = Color.FromArgb(255, 255, 192)
                    End If
                End If
            Next
        End If
    End Sub
    Private Sub OpenSerial()
        AddHandler cmdSerialPort.DataReceived, AddressOf cmdSerialPort_DataReceived

        Try
            If ParaComport <> "" Then
                If cmdSerialPort.IsOpen = False Then
                    With cmdSerialPort
                        .PortName = ParaComport
                        .BaudRate = 115200
                        .DataBits = 8
                        .Parity = IO.Ports.Parity.None
                        .StopBits = IO.Ports.StopBits.One
                        .Handshake = IO.Ports.Handshake.None
                    End With
                    cmdSerialPort.Open()
                End If
            Else
                MsgBox("시리얼포트를 설정해주세요!" & vbCrLf & "", vbCritical, PROGRAM_TITLE_NAME)
            End If
        Catch ex As Exception
            '' MsgBox("COM 포트 에러" & vbCrLf & "", vbOK + vbCritical, PROGRAM_TITLE_NAME)
            Save_ErrorCSV("OpenSerial," & ex.Message)
        End Try
    End Sub
    Private Sub cmdSerialPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles cmdSerialPort.DataReceived
        Dim n As Integer = cmdSerialPort.BytesToRead
        Dim comBuffer As Byte()

        UpdateSerialDelegate = New SerialDelegate(AddressOf RunSerial_Progress)

        Try
            comBuffer = New Byte(n - 1) {}
            cmdSerialPort.Read(comBuffer, 0, n)

            If RmainRxMessage <> "" Then rxMessage = rxMessage & RmainRxMessage
            For cnt = 0 To comBuffer.Length - 1
                rxMessage = rxMessage & Chr(comBuffer(cnt))
            Next

            Me.Invoke(UpdateSerialDelegate)
        Catch ex As Exception
            ''MsgBox("에러(DataReceived) : " & ex.Message & vbCrLf & "", vbCritical, TITLE_NAME)
            Save_ErrorCSV("DataReceived," & ex.Message)
        End Try
    End Sub

    ' 제품 꽂을 시 정보 읽어오기 기능
    Private Sub RunSerial_Progress()
        Dim cmdStr As String = ""
        Dim cmdVal(0 To 10) As String
        Dim chNum As DS_TYPE
        Dim Head_InChar, Tail_InChar, VbCr_InChar, VbLf_InChar As Integer
        Dim tmpMessage As String = ""
        Dim i As Integer
        Dim ErrCnt As Long = 0

        Try
            If Len(rxMessage) Then
                ErrCnt = ErrCnt + 1
                While Len(rxMessage)

                    ErrCnt = 100
                    While (InStr(rxMessage, vbNullChar))
                        If InStr(rxMessage, vbNullChar) <> 1 Then
                            tmpMessage = Mid(rxMessage, 1, InStr(rxMessage, vbNullChar) - 1)
                            rxMessage = tmpMessage & Mid(rxMessage, InStr(rxMessage, vbNullChar) + 1, Len(rxMessage) - InStr(rxMessage, vbNullChar))
                        Else
                            rxMessage = Mid(rxMessage, InStr(rxMessage, vbNullChar) + 1, Len(rxMessage) - InStr(rxMessage, vbNullChar))
                        End If
                    End While

                    ErrCnt = 200
                    Head_InChar = InStr(rxMessage, "[")
                    Tail_InChar = InStr(rxMessage, "]")
                    VbCr_InChar = InStr(rxMessage, vbCr)
                    VbLf_InChar = InStr(rxMessage, vbLf)

                    If Tail_InChar = 0 And VbCr_InChar = 0 And VbLf_InChar = 0 Then
                        If Len(rxMessage) <> 0 Then
                            RmainRxMessage = rxMessage
                            rxMessage = ""
                        End If
                        Exit While
                    Else
                        RmainRxMessage = ""
                    End If

                    ErrCnt = 300
                    If Tail_InChar Then
                        tmpMessage = Mid(rxMessage, Head_InChar, Tail_InChar)
                        rxMessage = Mid(rxMessage, Tail_InChar + 1, Len(rxMessage) - Tail_InChar)
                    End If

                    While (Mid(rxMessage, 1, 1) = vbCr Or Mid(rxMessage, 1, 1) = vbLf)
                        If Mid(rxMessage, 1, 1) = vbCr Then rxMessage = Mid(rxMessage, 2, Len(rxMessage) - 1)
                        If Mid(rxMessage, 1, 1) = vbLf Then rxMessage = Mid(rxMessage, 2, Len(rxMessage) - 1)
                    End While

                    ErrCnt = 400
                    If Len(tmpMessage) = 0 Then Continue While
                    ErrCnt = ErrCnt + 1
                    If Mid(tmpMessage, 1, 1) = "[" Then
                        ErrCnt = ErrCnt + 1
                        tmpMessage = Mid(tmpMessage, 2, Len(tmpMessage))
                        ErrCnt = ErrCnt + 1
                        If InStr(tmpMessage, " ") Then
                            ErrCnt = 410
                            cmdStr = Mid(tmpMessage, 1, (InStr(tmpMessage, " ") - 1))
                            ErrCnt = ErrCnt + 1
                            tmpMessage = Mid(tmpMessage, InStr(tmpMessage, " ") + 1, Len(tmpMessage))
                        ElseIf InStr(tmpMessage, "]") Then
                            ErrCnt = 420
                            cmdStr = Mid(tmpMessage, 1, (InStr(tmpMessage, "]") - 1))
                            ErrCnt = ErrCnt + 1
                            tmpMessage = Mid(tmpMessage, InStr(tmpMessage, "]") + 1, Len(tmpMessage))
                        End If
                        ErrCnt = ErrCnt + 1

                        For i = 1 To 10
                            If InStr(tmpMessage, ",") <> 0 Then
                                cmdVal(i) = Mid(tmpMessage, 1, InStr(tmpMessage, ",") - 1)
                                tmpMessage = Mid(tmpMessage, InStr(tmpMessage, ",") + 1, Len(tmpMessage))
                            ElseIf InStr(tmpMessage, "]") <> 0 Then
                                cmdVal(i) = Mid(tmpMessage, 1, InStr(tmpMessage, "]") - 1)
                                tmpMessage = Mid(tmpMessage, InStr(tmpMessage, "]") + 1, Len(tmpMessage))
                                Exit For
                            End If
                        Next i

                        ErrCnt = 500
                        If Len(cmdVal(1)) <> 1 Then Continue While
                        ErrCnt = ErrCnt + 1
                        chNum = Val(cmdVal(1))
                        If chkDeviceUse(DS_TYPE.DS_BODY).Checked And chNum = 2 Then
                            chNum = DS_TYPE.DS_BODY
                        Else
                            chNum = chNum - 1
                        End If
                        If chkDeviceUse(chNum).Checked = False Then Continue While
                        ErrCnt = ErrCnt + 1

                        Select Case cmdStr
                            Case "devconn", "cartconn", "carttdsn"
                                ErrCnt = 600
                                If cmdVal(2) = "1" Then ' 장착
                                    ErrCnt = 700

                                    If txbInfo_Barcord(chNum).Text = "N/A" Then
                                        txbInfo_Barcord(chNum).BackColor = Color.Red
                                        btnCmdStart.Text = "정보입력 전 기기를 제거해주세요."
                                        If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                            SetStatus(DS_STATUS.INPUT)
                                        End If
                                    Else
                                        If txbInfo_Barcord(chNum).BackColor <> Color.Red Then
                                            txbInfo_Barcord(chNum).BackColor = Color.DarkGreen
                                        End If
                                    End If
                                    ErrCnt = ErrCnt + 1
                                    If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                        txbInfo_TDSN(chNum).BackColor = Color.Green
                                    End If

                                    SetConnectStatus(chNum, True)
                                ElseIf cmdVal(2) = "0" Then ' 탈착
                                    ErrCnt = 800
                                    SetConnectStatus(chNum, False)
                                    TextBoxReset(chNum)
                                    Reset_DS_Reg(chNum)
                                    ErrCnt = ErrCnt + 1
                                    If isConnectStandby() Then
                                        TextBoxAllReset()
                                        Reset_All_DS_Reg()
                                        SetStatus(DS_STATUS.STANDBY)
                                        btnCmdStart.Text = "시작"
                                        WriteTextBarCodeBox("바코드 입력")
                                    Else
                                        isConnectEnable()
                                        If GetStatus() = DS_STATUS.REWIRTTING Then
                                            SetStatus(DS_STATUS.COMPLETE)
                                            btnCmdStart.Enabled = False
                                            btnCmdStart.Text = "시작"
                                        End If
                                        If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                            SetStatus(DS_STATUS.INPUT)
                                        End If
                                    End If
                                ElseIf cmdVal(2) <> "disconnect" Then ' 장착
                                    ErrCnt = 900
                                    If chNum <> DS_TYPE.DS_DEV Then
                                        ErrCnt = ErrCnt + 1
                                        If txbInfo_Barcord(chNum).Text = "N/A" Then
                                            txbInfo_Barcord(chNum).BackColor = Color.Red
                                            btnCmdStart.Text = "정보입력 전 기기를 제거해주세요."
                                            If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                                SetStatus(DS_STATUS.INPUT)
                                            End If
                                        Else
                                            If txbInfo_Barcord(chNum).BackColor <> Color.Red Then
                                                txbInfo_Barcord(chNum).BackColor = Color.DarkGreen
                                            End If
                                        End If
                                        ErrCnt = ErrCnt + 1
                                        If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                            txbInfo_TDSN(chNum).Text = cmdVal(2).ToUpper()
                                            txbInfo_TDSN(chNum).BackColor = Color.Green
                                        End If
                                        ErrCnt = ErrCnt + 1
                                        SetConnectStatus(chNum, True)
                                    End If
                                    ErrCnt = ErrCnt + 1
                                End If
                                ErrCnt = 1000
                            Case "dsfwver" ' 장착
                                ErrCnt = 1100
                                If chNum = DS_TYPE.DS_DEV Then
                                    ErrCnt = ErrCnt + 1
                                    If txbInfo_Barcord(chNum).Text = "N/A" Then
                                        txbInfo_Barcord(chNum).BackColor = Color.Red
                                        If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                            SetStatus(DS_STATUS.INPUT)
                                        End If
                                    Else
                                        If txbInfo_Barcord(chNum).BackColor <> Color.Red Then
                                            txbInfo_Barcord(chNum).BackColor = Color.DarkGreen
                                        End If
                                    End If
                                    ErrCnt = ErrCnt + 1
                                    If GetStatus() <> DS_STATUS.COMPLETE And GetStatus() <> DS_STATUS.REWIRTTING Then
                                        txbInfo_DevFW.Text = cmdVal(2)
                                        txbInfo_DevFW.BackColor = Color.Green
                                    End If
                                    ErrCnt = ErrCnt + 1
                                    SetConnectStatus(chNum, True)
                                End If
                                ErrCnt = 1200
                            Case "cartoqc", "wrstconf"
                                ErrCnt = 1300
                                If chNum = DS_TYPE.DS_DEV And i <> 6 Then
                                    Exit Select
                                ElseIf (chNum >= DS_TYPE.DS_FACE And chNum <= DS_TYPE.DS_BODY) And i <> 8 Then
                                    Exit Select
                                End If

                                ErrCnt = ErrCnt + 1
                                For cnt = 0 To i - 1
                                    If cmdVal(cnt + 1) = "success" Then Exit Select
                                    ErrCnt = ErrCnt + 1
                                    ReturnValue(chNum, cnt) = cmdVal(cnt + 1)
                                    ErrCnt = ErrCnt + 1
                                Next
                                ErrCnt = 1400

                                ''정보쓰기 실행 후 리턴값이 수신이 되었는지 확인
                                ReceiveReturnVal(chNum) = True
                                ErrCnt = ErrCnt + 1
                                '' 정보쓰기 실행 후 리턴값과 송신 데이터가 같은 체크
                                If CheckDiffCompReturnVal(chNum) Then ''정보쓰기 성공시 DB업로드 진행
                                    If UploadInfoData(chNum) = False Then
                                        '' 정보쓰기 실패시 시리얼창에 RED 색상 표시
                                        ResultTextBoxList(chNum, 0).ForeColor = Color.Red
                                    Else
                                        ResultTextBoxList(chNum, 0).ForeColor = Color.Blue
                                    End If
                                Else '' 정보쓰기 실패시 시리얼창에 RED 색상 표시
                                    ResultTextBoxList(chNum, 0).ForeColor = Color.Red
                                End If
                                ErrCnt = ErrCnt + 1
                                '' 전체 송수신 여부 및 송수신 데이터 비교 후 판정 진행
                                ReceiveComplete = True
                                DiffCompComplete = True
                                DBuploadComplete = True
                                ErrCnt = 1500
                                For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                                    If chkDeviceUse(cnt).Checked Then
                                        '' 전체 정보쓰기 리턴값 수신여부 체크
                                        If ReceiveReturnVal(cnt) = False Then
                                            ReceiveComplete = False
                                        End If
                                        '' 전체 정보쓰기 성공여부 체크
                                        If DiffCompReturnVal(cnt) = False Then
                                            DiffCompComplete = False
                                        End If
                                        '' 전체 DB업로드 성공여부 체크
                                        If UploadDBComplete(cnt) = False Then
                                            DBuploadComplete = False
                                        End If
                                    End If
                                Next
                                ErrCnt = 1600
                                If ReceiveComplete Then
                                    ErrCnt = ErrCnt + 1
                                    WriteInfoTimerEnable(False)
                                    ErrCnt = ErrCnt + 1
                                    If DiffCompComplete And DBuploadComplete Then
                                        DBAssyuploadComplete = Upload_AssyInfo()
                                        ErrCnt = ErrCnt + 1
                                        If DBAssyuploadComplete Then
                                            ErrCnt = ErrCnt + 1
                                            print_OnOff = True
                                            WriteSuccessProcess()
                                        Else
                                            ErrCnt = ErrCnt + 1
                                            WriteFailProcess()
                                        End If
                                    End If
                                End If
                                ErrCnt = 1800
                            Case Else

                        End Select
                    End If

                End While

            End If

        Catch ex As Exception
            ''MsgBox("RunSerial[" & cnt1 & "]:" & ex.Message & vbCrLf & "", vbCritical, TITLE_NAME)
            Save_ErrorCSV("RunSerial[" & ErrCnt & "]," & ex.Message)
        End Try
    End Sub
    Public Function CheckDiffCompReturnVal(chNum As Integer) As Boolean
        Try
            DiffCompReturnVal(chNum) = True
            For cnt = 0 To 9
                If SendValue(chNum, cnt) <> ReturnValue(chNum, cnt) Then
                    DiffCompReturnVal(chNum) = False
                    If cnt = 2 Then
                        Dim tmpYear, tmpMonth, tmpSN_LOW, tmpSN_HIGH, tmpSN As String
                        tmpYear = Mid(ReturnValue(chNum, cnt), 1, 2)
                        tmpMonth = Mid(ReturnValue(chNum, cnt), 3, 2)
                        tmpSN_LOW = Mid(ReturnValue(chNum, cnt), 5, 3)
                        tmpSN_HIGH = Mid(ReturnValue(chNum, cnt), 8, 3)
                        tmpSN = tmpSN_HIGH & tmpSN_LOW

                        If tmpYear <> DS_SN(chNum).YEAR Then
                            ResultTextBoxList(chNum, 8).ForeColor = Color.Red
                        End If
                        If tmpYear <> DS_SN(chNum).MONTH Then
                            ResultTextBoxList(chNum, 9).ForeColor = Color.Red
                        End If
                        If tmpYear <> DS_SN(chNum).SN Then
                            ResultTextBoxList(chNum, 2).ForeColor = Color.Red
                        End If
                        If tmpYear <> DS_SN(chNum).YEAR Then

                        End If
                        DS_SN(chNum).YEAR = tmpYear
                        DS_SN(chNum).MONTH = tmpMonth
                        DS_SN(chNum).SN = tmpSN
                        ResultTextBoxList(chNum, cnt).ForeColor = Color.Red

                    Else
                        ResultTextBoxList(chNum, cnt).ForeColor = Color.Red
                    End If
                End If
            Next

            If DiffCompReturnVal(chNum) = False Then
                ResultTextBoxList(chNum, 0).ForeColor = Color.Red
            End If

            Save_InfoWrite_LogCSV(chNum)

            Return DiffCompReturnVal(chNum)
        Catch ex As Exception
            Save_ErrorCSV("CheckDiffCompReturnVal," & ex.Message)
            Return False
        End Try
    End Function
    Public Function UploadInfoData(chNum As Integer) As Boolean
        Try
            UploadDBComplete(chNum) = False

            If chkDeviceUse(chNum).Checked And chNum = DS_TYPE.DS_DEV Then
                If Upload_DeviceInfo(chNum) Then UploadDBComplete(chNum) = True
            Else
                If Upload_CartInfo(chNum) Then UploadDBComplete(chNum) = True
            End If

            Save_InfoUpload_LogCSV(chNum)

            Return UploadDBComplete(chNum)
        Catch ex As Exception
            Save_ErrorCSV("UploadInfoData," & ex.Message)
            Return False
        End Try
    End Function
    Public Function UploadAssyInfoData(chNum As Integer) As Boolean
        Try
            UploadDBComplete(chNum) = False

            If chkDeviceUse(chNum).Checked And chNum = DS_TYPE.DS_DEV Then
                If Upload_DeviceInfo(chNum) Then UploadDBComplete(chNum) = True
            Else
                If Upload_CartInfo(chNum) Then UploadDBComplete(chNum) = True
            End If

            Return UploadDBComplete(chNum)

        Catch ex As Exception
            Save_ErrorCSV("UploadAssyInfoData," & ex.Message)
            Return False
        End Try
    End Function
    Public Function Upload_CartInfo(chNum As Integer) As String
        Dim UploadVar(13) As String
        Dim UploadVal(13) As String
        Dim TypeStr As String = ""
        Dim CheckFlag As Boolean = True
        Dim LastCnt As Integer = 12
        Dim strTDSN As String = txbInfo_TDSN(chNum).Text.ToUpper
        Dim strCTSN As String = txbInfo_Barcord(chNum).Text.ToUpper
        Dim tmpTDSN, tmpCTSN As String

        Try
            tmpTDSN = CheckExistTD_SN(strTDSN)
            tmpCTSN = CheckExistCT_SN(strCTSN)

            If tmpTDSN = False Then
                txbInfo_TDSN(chNum).ForeColor = Color.Red
                txbInfo_Barcord(chNum).Text = "TD S/N 미검색"
                ReTryDisable = True
                Return False
            End If
            If tmpTDSN <> tmpCTSN And tmpCTSN <> False Then
                txbInfo_Barcord(chNum).ForeColor = Color.Red
                txbInfo_Barcord(chNum).Text = "제품 S/N 중복"
                ReTryDisable = False
                Return False
            End If

            If chNum = DS_TYPE.DS_DEV Then
                TypeStr = "DEVICE"
            ElseIf chNum = DS_TYPE.DS_FACE Then
                TypeStr = "FACE"
            ElseIf chNum = DS_TYPE.DS_EYE Then
                TypeStr = "EYE"
            ElseIf chNum = DS_TYPE.DS_BODY Then
                TypeStr = "BODY"
            Else
            End If

            UploadVar(0) = "P3_DateTime"
            UploadVar(1) = "Product_SN"
            UploadVar(2) = "Ct_Manufacture_Name"
            UploadVar(3) = "Ct_Manufacture_Year"
            UploadVar(4) = "Ct_Manufacture_Month"
            UploadVar(5) = "Ct_SN"
            UploadVar(6) = "Ct_Model"
            UploadVar(7) = "Ct_Type"
            UploadVar(8) = "Ct_Abroad"
            UploadVar(9) = "Ct_Agency"
            UploadVar(10) = "Ct_Max_ShotCnt"
            UploadVar(11) = "Ct_Remain_ShotCnt"
            UploadVar(12) = "Manufacture_Date"

            UploadVal(0) = "Now()"
            UploadVal(1) = txbInfo_Barcord(chNum).Text
            UploadVal(2) = txbInfo_Manufacture(chNum).Text
            UploadVal(3) = txbInfo_Year(chNum).Text
            UploadVal(4) = txbInfo_Month(chNum).Text
            UploadVal(5) = txbInfo_SN(chNum).Text
            UploadVal(6) = txbInfo_Model(chNum).Text
            UploadVal(7) = TypeStr
            UploadVal(8) = txbInfo_Abroad(chNum).Text
            UploadVal(9) = txbInfo_Agency(chNum).Text
            UploadVal(10) = txbInfo_Tshot(chNum).Text
            UploadVal(11) = txbInfo_Rshot(chNum).Text
            UploadVal(12) = GetSelectedDate(chNum)

            StrCmd = "update jomtCartridgeTbl Set " & UploadVar(0) & "=" & UploadVal(0) & ","
            For cnt = 1 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt) & "='" & UploadVal(cnt)
                If cnt < LastCnt Then
                    StrCmd = StrCmd & "',"
                End If
            Next
            StrCmd = StrCmd & "' where PV_SN = '" & strTDSN & "';"

            DBCommand(StrCmd)


            StrCmd = "select "
            For cnt = 0 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt)
                If cnt < LastCnt Then
                    StrCmd = StrCmd & ","
                End If
            Next
            StrCmd = StrCmd & " from jomtCartridgeTbl where PV_SN ='" & strTDSN & "';"

            If DBQueryReader(StrCmd) Then
                If sqlDataQuery(0).ToString = "" Then CheckFlag = False
                For cnt = 1 To LastCnt
                    If sqlDataQuery(cnt) <> UploadVal(cnt) Then CheckFlag = False
                Next

                If CheckFlag = True Then
                    Return True
                Else
                    Return False
                End If
            End If

            Return False
        Catch ex As Exception
            Save_ErrorCSV("Upload_CartInfo," & ex.Message)
            Return False
        End Try
    End Function
    Public Function Upload_DeviceInfo(chNum As Integer) As String
        Dim UploadVar(13) As String
        Dim UploadVal(13) As String
        Dim TypeStr As String = ""
        Dim CheckFlag As Boolean = True
        Dim strSN As String = txbInfo_Barcord(chNum).Text.ToUpper
        Dim LastCnt As Integer = 11
        Try
            If CheckExistDEV_SN(strSN) = False Then
                StrCmd = "insert jomtDeviceTbl set Product_SN='" & strSN & "';"
                DBCommand(StrCmd)
                If CheckExistDEV_SN(strSN) = False Then Return False
            End If


            If chNum = DS_TYPE.DS_DEV Then
                TypeStr = "DEVICE"
            ElseIf chNum = DS_TYPE.DS_FACE Then
                TypeStr = "FACE"
            ElseIf chNum = DS_TYPE.DS_EYE Then
                TypeStr = "EYE"
            ElseIf chNum = DS_TYPE.DS_BODY Then
                TypeStr = "BODY"
            Else
            End If

            UploadVar(0) = "DateTime"
            UploadVar(1) = "Product_SN"
            UploadVar(2) = "FW_VER"
            UploadVar(3) = "Manufacture_Name"
            UploadVar(4) = "Manufacture_Year"
            UploadVar(5) = "Manufacture_Month"
            UploadVar(6) = "SN"
            UploadVar(7) = "Model"
            UploadVar(8) = "Type"
            UploadVar(9) = "Abroad"
            UploadVar(10) = "Agency"
            UploadVar(11) = "Manufacture_Date"


            UploadVal(0) = "Now()"
            UploadVal(1) = txbInfo_Barcord(chNum).Text
            UploadVal(2) = txbInfo_FW(chNum).Text
            UploadVal(3) = txbInfo_Manufacture(chNum).Text
            UploadVal(4) = txbInfo_Year(chNum).Text
            UploadVal(5) = txbInfo_Month(chNum).Text
            UploadVal(6) = txbInfo_SN(chNum).Text
            UploadVal(7) = txbInfo_Model(chNum).Text
            UploadVal(8) = TypeStr
            UploadVal(9) = txbInfo_Abroad(chNum).Text
            UploadVal(10) = txbInfo_Agency(chNum).Text
            UploadVal(11) = GetSelectedDate(chNum)

            StrCmd = "update jomtDeviceTbl Set " & UploadVar(0) & "=" & UploadVal(0) & ","
            For cnt = 1 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt) & "='" & UploadVal(cnt)
                If cnt < LastCnt Then
                    StrCmd = StrCmd & "',"
                End If
            Next
            StrCmd = StrCmd & "' where Product_SN = '" & strSN & "';"
            DBCommand(StrCmd)


            StrCmd = "select "
            For cnt = 0 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt)
                If cnt < LastCnt Then
                    StrCmd = StrCmd & ","
                End If
            Next
            StrCmd = StrCmd & " from jomtDeviceTbl where Product_SN ='" & strSN & "';"

            If DBQueryReader(StrCmd) Then
                If sqlDataQuery(0).ToString = "" Then Return False
                For cnt = 1 To LastCnt
                    If sqlDataQuery(cnt) <> UploadVal(cnt) Then Return False
                Next
                Return True
            End If
            Return False
        Catch ex As Exception
            Save_ErrorCSV("Upload_DeviceInfo," & ex.Message)
            Return False
        End Try
    End Function
    Public Function Upload_AssyInfo() As String
        Dim UploadVar(3) As String
        Dim UploadVal(3) As String
        Dim LastCnt As Integer = 3
        Dim CheckFlag As Boolean = True
        Dim strDEVSN As String = txbInfo_Barcord(DS_TYPE.DS_DEV).Text.ToString
        Dim strFACESN As String = txbInfo_Barcord(DS_TYPE.DS_FACE).Text.ToString
        Dim strEYESN As String = txbInfo_Barcord(DS_TYPE.DS_EYE).Text.ToString

        If chkDevUse.Checked = True And chkFaceUse.Checked = True And chkEyeUse.Checked = True Then

            Dim tmpDEVSN As Long = CheckExistAssy_SN("Product_SN", strDEVSN)
            Dim tmpFACESN As Long = CheckExistAssy_SN("FaceCart_SN", strFACESN)
            Dim tmpEYESN As Long = CheckExistAssy_SN("EyeCart_SN", strEYESN)

            Try
                If tmpFACESN Or tmpEYESN Then
                    If (tmpFACESN And tmpEYESN) And ((tmpDEVSN = tmpFACESN) And (tmpDEVSN = tmpEYESN)) Then
                    ElseIf (tmpFACESN And tmpEYESN = False) And (tmpDEVSN = tmpFACESN) Then
                    ElseIf (tmpFACESN = False And tmpEYESN) And (tmpDEVSN = tmpEYESN) Then
                    Else

                        Return False
                    End If
                End If

                UploadVar(0) = "DateTime"
                UploadVar(1) = "Product_SN"
                UploadVar(2) = "FaceCart_SN"
                UploadVar(3) = "EyeCart_SN"

                UploadVal(0) = "Now()"
                UploadVal(1) = strDEVSN
                UploadVal(2) = strFACESN
                UploadVal(3) = strEYESN

                If tmpDEVSN Then
                    StrCmd = "update jomtProductTbl Set " & UploadVar(0) & "=" & UploadVal(0)
                Else
                    StrCmd = "insert jomtProductTbl Set " & UploadVar(0) & "=" & UploadVal(0)
                End If

                If tmpDEVSN = 0 Then StrCmd = StrCmd & "," & UploadVar(1) & "='" & UploadVal(1) & "'"
                If tmpFACESN = 0 Then StrCmd = StrCmd & "," & UploadVar(2) & "='" & UploadVal(2) & "'"
                If tmpEYESN = 0 Then StrCmd = StrCmd & "," & UploadVar(3) & "='" & UploadVal(3) & "'"

                If tmpDEVSN Then
                    StrCmd = StrCmd & " where Product_SN='" & strDEVSN & "';"
                Else
                    StrCmd = StrCmd & ";"
                End If

                DBCommand(StrCmd)


                StrCmd = "select "
                For cnt = 0 To LastCnt
                    StrCmd = StrCmd & UploadVar(cnt)

                    If cnt < LastCnt Then
                        StrCmd = StrCmd & ","
                    End If
                Next
                StrCmd = StrCmd & " from jomtProductTbl where Product_SN ='" & strDEVSN & "';"

                If DBQueryReader(StrCmd) Then
                    If sqlDataQuery(0).ToString = "" Then Return False
                    For cnt = 1 To LastCnt
                        If sqlDataQuery(cnt) <> UploadVal(cnt) Then Return False
                    Next
                    Return True
                End If
                Return False
            Catch ex As Exception
                Save_ErrorCSV("Upload_AssyInfo," & ex.Message)
                Return False
            End Try

        Else
            Return True
        End If
    End Function
    Public Function Upload_CountInfo() As String
        Dim UploadVar(8) As String
        Dim UploadVal(8) As String
        Dim LastCnt As Integer = 8
        Dim strDate As String = getNowDate().ToString

        Try
            If CheckExistCountDate(strDate) = "0" Then
                StrCmd = "insert jomtMES_ProductTbl Set Date='" & strDate & "';"
            End If
            DBCommand(StrCmd)

            UploadVar(0) = "Date"
            UploadVar(1) = "PRO_Set_CNT"
            UploadVar(2) = "LUX_Set_CNT"
            UploadVar(3) = "PRO_FACE_CNT"
            UploadVar(4) = "LUX_FACE_CNT"
            UploadVar(5) = "PRO_EYE_CNT"
            UploadVar(6) = "LUX_EYE_CNT"
            UploadVar(7) = "PRO_BODY_CNT"
            UploadVar(8) = "LUX_BODY_CNT"

            UploadVal(0) = strDate
            UploadVal(1) = txbProductCntPS.Text
            UploadVal(2) = txbProductCntLS.Text
            UploadVal(3) = txbProductCntPF.Text
            UploadVal(4) = txbProductCntLF.Text
            UploadVal(5) = txbProductCntPE.Text
            UploadVal(6) = txbProductCntLE.Text
            UploadVal(7) = txbProductCntPB.Text
            UploadVal(8) = txbProductCntLB.Text

            StrCmd = "update jomtMES_ProductTbl set "
            For cnt = 1 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt) & "='" & UploadVal(cnt)
                If cnt < LastCnt Then
                    StrCmd = StrCmd & "',"
                Else
                    StrCmd = StrCmd & "'"
                End If
            Next
            StrCmd = StrCmd & " where " & UploadVar(0) & "='" & UploadVal(0) & "';"
            DBCommand(StrCmd)

            StrCmd = "select "
            For cnt = 0 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt)

                If cnt < LastCnt Then
                    StrCmd = StrCmd & ","
                End If
            Next
            StrCmd = StrCmd & " from jomtMES_ProductTbl where " & UploadVar(0) & "='" & UploadVal(0) & "';"

            If DBQueryReader(StrCmd) Then
                If sqlDataQuery(0).ToString = "" Then Return False
                For cnt = 1 To LastCnt
                    If sqlDataQuery(cnt) <> UploadVal(cnt) Then Return False
                Next
                Return True
            End If
            Return False
        Catch ex As Exception
            Save_ErrorCSV("Upload_CountInfo," & ex.Message)
            Return False
        End Try
    End Function
    Public Function Download_CountInfo() As String
        Dim UploadVar(8) As String
        Dim UploadVal(8) As TextBox
        Dim LastCnt As Integer = 8
        Dim CheckFlag As Boolean = True
        Dim strDate As String = getNowDate().ToString

        Try
            If CheckExistCountDate(strDate) = "0" Then
                StrCmd = "insert jomtMES_ProductTbl Set Date='" & strDate & "';"
            End If
            DBCommand(StrCmd)

            UploadVar(0) = "Date"
            UploadVar(1) = "PRO_Set_CNT"
            UploadVar(2) = "LUX_Set_CNT"
            UploadVar(3) = "PRO_FACE_CNT"
            UploadVar(4) = "LUX_FACE_CNT"
            UploadVar(5) = "PRO_EYE_CNT"
            UploadVar(6) = "LUX_EYE_CNT"
            UploadVar(7) = "PRO_BODY_CNT"
            UploadVar(8) = "LUX_BODY_CNT"


            UploadVal(1) = txbProductCntPS
            UploadVal(2) = txbProductCntLS
            UploadVal(3) = txbProductCntPF
            UploadVal(4) = txbProductCntLF
            UploadVal(5) = txbProductCntPE
            UploadVal(6) = txbProductCntLE
            UploadVal(7) = txbProductCntPB
            UploadVal(8) = txbProductCntLB

            StrCmd = "select "
            For cnt = 0 To LastCnt
                StrCmd = StrCmd & UploadVar(cnt)

                If cnt < LastCnt Then
                    StrCmd = StrCmd & ","
                End If
            Next
            StrCmd = StrCmd & " from jomtMES_ProductTbl where " & UploadVar(0) & "='" & strDate & "';"

            If DBQueryReader(StrCmd) Then
                If sqlDataQuery(0).ToString <> "" Then
                    For cnt = 1 To LastCnt
                        UploadVal(cnt).Text = sqlDataQuery(cnt)
                    Next
                    Return True
                End If
            End If
            Return False
        Catch ex As Exception
            Save_ErrorCSV("Download_CountInfo," & ex.Message)
            Return False
        End Try
    End Function
    Private Sub UpdateCompleteCount()
        If chkDeviceUse(DS_TYPE.DS_DEV).Checked And chkDeviceUse(DS_TYPE.DS_FACE).Checked And chkDeviceUse(DS_TYPE.DS_EYE).Checked Then
            If txbConf_Model.Text = "PRO" Then
                txbProductCntPS.Text = txbProductCntPS.Text + 1
            ElseIf txbConf_Model.Text = "LUX" Then
                txbProductCntLS.Text = txbProductCntLS.Text + 1
            End If
        ElseIf chkDeviceUse(DS_TYPE.DS_FACE).Checked And chkDeviceUse(DS_TYPE.DS_EYE).Checked Then
            If txbConf_Model.Text = "PRO" Then
                txbProductCntPF.Text = txbProductCntPF.Text + 1
                txbProductCntPE.Text = txbProductCntPE.Text + 1
            ElseIf txbConf_Model.Text = "LUX" Then
                txbProductCntLF.Text = txbProductCntLF.Text + 1
                txbProductCntLE.Text = txbProductCntLE.Text + 1
            End If
        ElseIf chkDeviceUse(DS_TYPE.DS_FACE).Checked Then
            If txbConf_Model.Text = "PRO" Then
                txbProductCntPF.Text = txbProductCntPF.Text + 1
            ElseIf txbConf_Model.Text = "LUX" Then
                txbProductCntLF.Text = txbProductCntLF.Text + 1
            End If
        ElseIf chkDeviceUse(DS_TYPE.DS_EYE).Checked Then
            If txbConf_Model.Text = "PRO" Then
                txbProductCntPE.Text = txbProductCntPE.Text + 1
            ElseIf txbConf_Model.Text = "LUX" Then
                txbProductCntLE.Text = txbProductCntLE.Text + 1
            End If
        ElseIf chkDeviceUse(DS_TYPE.DS_BODY).Checked Then
            If txbConf_Model.Text = "PRO" Then
                txbProductCntPB.Text = txbProductCntPB.Text + 1
            ElseIf txbConf_Model.Text = "LUX" Then
                txbProductCntLB.Text = txbProductCntLB.Text + 1
            End If
        End If

        Upload_CountInfo()
    End Sub
    Public Sub WriteSuccessProcess()
        Try
            'If print_num <> 0 Then
            '    print_on(print_num)
            'End If


            WriteBarCodeWindow("정보 쓰기 성공")
            txbBarcodeNum.BackColor = Color.Green
            btnCmdStart.Text = "기기 모두를 제거해 주세요."
            btnCmdStart.Enabled = False

            UpdateCompleteCount()

            SetStatus(DS_STATUS.COMPLETE)

            txbBarcodeNum.Focus()
        Catch ex As Exception
            Save_ErrorCSV("WriteSuccessProcess," & ex.Message)
        End Try
    End Sub

    Private Function print_number() As String
        Dim print_num As String = "0"

        For i = 0 To printnum.max - 1
            printnumtype(i) = "0"
        Next

        If txbInfo_FaceBarcord.Text = "N/A" Then
            printnumtype(printnum.face) = "0"
        Else
            printnumtype(printnum.face) = txbInfo_FaceBarcord.Text
        End If

        If txbInfo_DevBarcord.Text = "N/A" Then
            printnumtype(printnum.dev) = "0"
        Else
            printnumtype(printnum.dev) = txbInfo_DevBarcord.Text
        End If

        If txbInfo_EyeBarcord.Text = "N/A" Then
            printnumtype(printnum.eye) = "0"
        Else
            printnumtype(printnum.eye) = txbInfo_EyeBarcord.Text
        End If

        For i = 0 To printnum.max - 1
            If printnumtype(i) <> "0" Then
                If print_num <> "0" Then
                    If print_num > printnumtype(i) Then
                        print_num = printnumtype(i)
                    End If
                Else
                    print_num = printnumtype(i)
                End If
            End If
        Next

        Return print_num

    End Function
    Public Sub WriteFailProcess()
        Try
            If DiffCompComplete Then
                If DBuploadComplete Then
                    If DBAssyuploadComplete = False Then
                        WriteBarCodeWindow("S/N 업로드 실패")
                        txbBarcodeNum.BackColor = Color.Fuchsia
                    End If
                Else
                    WriteBarCodeWindow("정보 업로드 실패")
                    txbBarcodeNum.BackColor = Color.Fuchsia
                End If
            Else
                WriteBarCodeWindow("정보 쓰기 실패")
                txbBarcodeNum.BackColor = Color.Red
            End If

            If ReTryDisable = False Then
                btnCmdStart.Text = "재시작"
                btnCmdStart.Enabled = True
            Else
                btnCmdStart.Text = "기기 모두들 제거해 주세요."
            End If

            If failDeleteInfo() = False Then
                MsgBox("DB 내용 삭제 실패", vbCritical)
            End If

            SetStatus(DS_STATUS.REWIRTTING)
        Catch ex As Exception
            Save_ErrorCSV("WriteFailProcess," & ex.Message)
        End Try
    End Sub

    Private Function failDeleteInfo() As Boolean
        StrCmd = "UPDATE jomtCartridgeTbl SET Product_SN = NULL WHERE Product_SN = '" & txbInfo_FaceBarcord.Text & "'"
        If DBCommand(StrCmd) Then
            StrCmd = "UPDATE jomtCartridgeTbl SET Product_SN = NULL WHERE Product_SN = '" & txbInfo_EyeBarcord.Text & "'"
            If DBCommand(StrCmd) Then
                StrCmd = "DELETE FROM jomtDeviceTbl WHERE Product_SN = '" & txbInfo_DevBarcord.Text & "'"
                If DBCommand(StrCmd) Then
                    Return True
                Else
                    MsgBox("본체 정보 삭제 오류", vbCritical)
                End If
            Else
                MsgBox("눈가 정보 삭제 오류", vbCritical)
            End If
        Else
            MsgBox("페이스 정보 삭제 오류", vbCritical)
        End If

        Return False

    End Function

    Private Sub ReadModeTextBoxAllReset()
        Try
            For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_EYE
                ReadModeTextBoxReset(cnt)
            Next
        Catch ex As Exception
            Save_ErrorCSV("ReadModeTextBoxAllReset," & ex.Message)
        End Try
    End Sub
    Private Sub ReadModeTextBoxReset(DevType As DS_TYPE)

        lblInfo_Model(DevType).ForeColor = Color.Black
        lblInfo_YearMonth(DevType).ForeColor = Color.Black
        lblInfo_SN(DevType).ForeColor = Color.Black
        lblInfo_Year(DevType).ForeColor = Color.Black
        lblInfo_Month(DevType).ForeColor = Color.Black

        txbInfo_Barcord(DevType).Text = "N/A"
        txbInfo_Barcord(DevType).BackColor = Color.LightCyan
        txbInfo_Barcord(DevType).ForeColor = Color.Blue
        txbInfo_Barcord(DevType).Refresh()
        txbInfo_FW(DevType).Text = "N/A"
        txbInfo_FW(DevType).ForeColor = Color.Blue
        txbInfo_FW(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_FW(DevType).Refresh()
        txbInfo_Model(DevType).Text = "N/A"
        txbInfo_Model(DevType).ForeColor = Color.Blue
        txbInfo_Model(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Model(DevType).Refresh()
        txbInfo_Manufacture(DevType).Text = "N/A"
        txbInfo_Manufacture(DevType).ForeColor = Color.Blue
        txbInfo_Manufacture(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Manufacture(DevType).Refresh()
        txbInfo_Year(DevType).Text = "N/A"
        txbInfo_Year(DevType).ForeColor = Color.Blue
        txbInfo_Year(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Year(DevType).Refresh()
        txbInfo_Month(DevType).Text = "N/A"
        txbInfo_Month(DevType).ForeColor = Color.Blue
        txbInfo_Month(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Month(DevType).Refresh()
        txbInfo_SN(DevType).Text = "N/A"
        txbInfo_SN(DevType).ForeColor = Color.Blue
        txbInfo_SN(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_SN(DevType).Refresh()
        txbInfo_Abroad(DevType).Text = "N/A"
        txbInfo_Abroad(DevType).ForeColor = Color.Blue
        txbInfo_Abroad(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Abroad(DevType).Refresh()
        txbInfo_Agency(DevType).Text = "N/A"
        txbInfo_Agency(DevType).ForeColor = Color.Blue
        txbInfo_Agency(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Agency(DevType).Refresh()
        txbInfo_TDSN(DevType).Text = "N/A"
        txbInfo_TDSN(DevType).ForeColor = Color.Blue
        txbInfo_TDSN(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_TDSN(DevType).Refresh()
        txbInfo_Rshot(DevType).Text = "N/A"
        txbInfo_Rshot(DevType).ForeColor = Color.Blue
        txbInfo_Rshot(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Rshot(DevType).Refresh()
        txbInfo_Tshot(DevType).Text = "N/A"
        txbInfo_Tshot(DevType).ForeColor = Color.Blue
        txbInfo_Tshot(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Tshot(DevType).Refresh()
        txbInfo_Freq(DevType).Text = "N/A"
        txbInfo_Freq(DevType).ForeColor = Color.Blue
        txbInfo_Freq(DevType).Refresh()
        txbInfo_Power(DevType).Text = "N/A"
        txbInfo_Power(DevType).ForeColor = Color.Blue
        txbInfo_Power(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Power(DevType).Refresh()
        txbInfo_Date(DevType).Text = "N/A"
        txbInfo_Date(DevType).ForeColor = Color.Blue
        txbInfo_Date(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Date(DevType).Refresh()
        txbInfo_Cart(DevType).Text = "N/A"
        txbInfo_Cart(DevType).ForeColor = Color.Blue
        txbInfo_Cart(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Cart(DevType).Refresh()

        If DevType <> DS_TYPE.DS_DEV Then
            txbInfo_AGDate(DevType).Text = "N/A"
            txbInfo_AGDate(DevType).ForeColor = Color.Gray
            txbInfo_AGDate(DevType).Refresh()
            txbInfo_AGShot(DevType).Text = "N/A"
            txbInfo_AGShot(DevType).ForeColor = Color.Gray
            txbInfo_AGShot(DevType).Refresh()
            txbInfo_AGStart(DevType).Text = "N/A"
            txbInfo_AGStart(DevType).ForeColor = Color.Gray
            txbInfo_AGStart(DevType).Refresh()
            txbInfo_AGOkNg(DevType).Text = "N/A"
            txbInfo_AGOkNg(DevType).ForeColor = Color.Gray
            txbInfo_AGOkNg(DevType).Refresh()
            txbInfo_AGPower(DevType).Text = "N/A"
            txbInfo_AGPower(DevType).ForeColor = Color.Gray
            txbInfo_AGPower(DevType).Refresh()
            txbInfo_AGEnd(DevType).Text = "N/A"
            txbInfo_AGEnd(DevType).ForeColor = Color.Gray
            txbInfo_AGEnd(DevType).Refresh()
            txbInfo_CTDate(DevType).Text = "N/A"
            txbInfo_CTDate(DevType).ForeColor = Color.Gray
            txbInfo_CTDate(DevType).Refresh()
            txbInfo_CTFreq(DevType).Text = "N/A"
            txbInfo_CTFreq(DevType).ForeColor = Color.Gray
            txbInfo_CTFreq(DevType).Refresh()
            txbInfo_IQCDate(DevType).Text = "N/A"
            txbInfo_IQCDate(DevType).ForeColor = Color.Gray
            txbInfo_IQCDate(DevType).Refresh()
            txbInfo_IQCGrade(DevType).Text = "N/A"
            txbInfo_IQCGrade(DevType).ForeColor = Color.Gray
            txbInfo_IQCGrade(DevType).Refresh()
            txbInfo_IQCTD(DevType).Text = "N/A"
            txbInfo_IQCTD(DevType).ForeColor = Color.Gray
            txbInfo_IQCTD(DevType).Refresh()
            txbInfo_IQCCap(DevType).Text = "N/A"
            txbInfo_IQCCap(DevType).ForeColor = Color.Gray
            txbInfo_IQCCap(DevType).Refresh()
        End If

    End Sub
    Private Sub TextBoxAllReset()
        Try
            txbBarcodeNum.ForeColor = Color.Black
            txbBarcodeNum.BackColor = Color.Green
            btnCmdStart.Text = "시작"

            For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_EYE
                If chkDeviceUse(cnt).Checked Then
                    If cnt = DS_TYPE.DS_BODY Then
                        TextBoxReset(DS_TYPE.DS_FACE)
                    Else
                        TextBoxReset(cnt)
                    End If
                End If
            Next
        Catch ex As Exception
            Save_ErrorCSV("TextBoxAllReset," & ex.Message)
        End Try
    End Sub
    Private Sub TextBoxReset(DevType As DS_TYPE)

        lblInfo_Model(DevType).ForeColor = Color.Black
        lblInfo_YearMonth(DevType).ForeColor = Color.Black
        lblInfo_SN(DevType).ForeColor = Color.Black
        lblInfo_Year(DevType).ForeColor = Color.Black
        lblInfo_Month(DevType).ForeColor = Color.Black

        txbInfo_Barcord(DevType).Text = "N/A"
        txbInfo_Barcord(DevType).BackColor = Color.LightCyan
        txbInfo_Barcord(DevType).ForeColor = Color.Blue
        txbInfo_FW(DevType).Text = "N/A"
        txbInfo_FW(DevType).ForeColor = Color.Blue
        txbInfo_Model(DevType).Text = "N/A"
        txbInfo_Model(DevType).ForeColor = Color.Blue
        txbInfo_Manufacture(DevType).Text = "N/A"
        txbInfo_Manufacture(DevType).ForeColor = Color.Blue
        txbInfo_Year(DevType).Text = "N/A"
        txbInfo_Year(DevType).ForeColor = Color.Blue
        txbInfo_Month(DevType).Text = "N/A"
        txbInfo_Month(DevType).ForeColor = Color.Blue
        txbInfo_SN(DevType).Text = "N/A"
        txbInfo_SN(DevType).ForeColor = Color.Blue
        txbInfo_Abroad(DevType).Text = "N/A"
        txbInfo_Abroad(DevType).ForeColor = Color.Blue
        txbInfo_Agency(DevType).Text = "N/A"
        txbInfo_Agency(DevType).ForeColor = Color.Blue
        txbInfo_TDSN(DevType).Text = "N/A"
        txbInfo_TDSN(DevType).ForeColor = Color.Blue
        txbInfo_Rshot(DevType).Text = "N/A"
        txbInfo_Rshot(DevType).ForeColor = Color.Blue
        txbInfo_Tshot(DevType).Text = "N/A"
        txbInfo_Tshot(DevType).ForeColor = Color.Blue
        txbInfo_Freq(DevType).Text = "N/A"
        txbInfo_Freq(DevType).ForeColor = Color.Blue
        txbInfo_Power(DevType).Text = "N/A"
        txbInfo_Power(DevType).ForeColor = Color.Blue

        txbInfo_Model(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_SN(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Year(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_Month(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_FW(DevType).BackColor = Color.FromArgb(255, 255, 192)
        txbInfo_TDSN(DevType).BackColor = Color.FromArgb(255, 255, 192)
    End Sub
    Public Function SendData(SendMessage As String) As Boolean
        Try
            If cmdSerialPort.IsOpen = True Then
                cmdSerialPort.DiscardInBuffer()
                cmdSerialPort.DiscardOutBuffer()
                If cmdSerialPort.BytesToRead Then
                    cmdSerialPort.DiscardInBuffer()
                End If
                cmdSerialPort.WriteTimeout = -1
                cmdSerialPort.WriteLine(SendMessage)
            Else
                MsgBox("통신 포트가 열리지 않았습니다.")
            End If
        Catch ex As Exception
            Save_ErrorCSV("SendData," & ex.Message)
            Return True
        End Try
        Return False
    End Function
    Private Function Read_ini(read_type As String) As Boolean
        Dim FilePath As String
        Dim FileName As String
        Dim ConifgStr As String
        Dim objReader As System.IO.StreamReader

        Try
            FilePath = System.AppDomain.CurrentDomain.BaseDirectory() & "\Config"

            '디렉토리가 없을 경우
            If Dir(FilePath, vbDirectory) = "" Then
                MkDir(FilePath)
            End If

            Select Case read_type
                Case "infoset"

                    FileName = FilePath & "\" & "DS_INFO_SET_Config" & ".ini"

                    If File.Exists(FileName) = True Then
                        objReader = New System.IO.StreamReader(FileName, True)
                        ConifgStr = objReader.ReadLine()
                        objReader.Close()

                        cboComPort.Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                        ParaComport = cboComPort.Text
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))

                        For i = 1 To 15
                            If Len(ConifgStr) = 0 Then Exit For

                            ItemSelectItem(i).Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                            ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))

                            txbItemSelectModel(i).Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                            ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))

                            ItemSelectFace(i).Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                            ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))

                            ItemSelectEye(i).Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                            ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))

                            ItemSelectAbroad(i).Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                            ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))

                            ItemSelectAgency(i).Text = Mid(ConifgStr, 1, InStr(ConifgStr, ",") - 1)
                            ConifgStr = Mid(ConifgStr, InStr(ConifgStr, ",") + 1, Len(ConifgStr))
                        Next

                        cboLoadSelect.Items.Clear()

                        For i = 1 To 15
                            If ItemSelectItem(i).Text = "" Then Continue For
                            cboLoadSelect.Items.Add(ItemSelectItem(i).Text)
                        Next i

                        Return True
                    Else
                        MsgBox("검사기 정보가 없습니다." & vbCrLf & "검사기 설정을 진행하세요.", vbCritical, PROGRAM_TITLE_NAME)

                        RunSetupWindow()

                        Return False
                    End If

                Case "printer"

                    FileName = FilePath & "\" & "Printer_Config" & ".ini"

                    If File.Exists(FileName) = True Then
                        objReader = New System.IO.StreamReader(FileName, True)
                        ConifgStr = objReader.ReadLine()
                        objReader.Close()

                        ckbprintBar.Checked = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        ckbPrintWar.Checked = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txbname1.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txblabel1.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txbSingle1.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txbbarcode1.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txbtext1.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txbname2.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txblabel2.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)
                        ConifgStr = Mid(ConifgStr, InStr(ConifgStr, "☏") + 1, ConifgStr.Length)

                        txbtext2.Text = Mid(ConifgStr, 1, InStr(ConifgStr, "☏") - 1)

                    End If
            End Select

            Exit Function

        Catch ex As Exception
            Save_ErrorCSV("Read_ini," & ex.Message)
            Return False
        End Try
    End Function

    Private Sub Save_ini(save_type As String)
        Dim FilePath As String
        Dim FileName As String = ""
        Dim ConifgStr As String = ""
        Dim objWriter As System.IO.StreamWriter

        Try

            FilePath = System.AppDomain.CurrentDomain.BaseDirectory() & "\Config"

            '디렉토리가 없을 경우
            If Dir(FilePath, vbDirectory) = "" Then
                MkDir(FilePath)
            End If

            Select Case save_type
                Case "infoset"

                    FileName = FilePath & "\" & "DS_INFO_SET_Config" & ".ini"

                    ConifgStr = cboComPort.Text & ","

                    For i = 1 To 15
                        If ItemSelectItem(i).Text = "" Then Exit For

                        ConifgStr = ConifgStr & ItemSelectItem(i).Text & ","
                        ConifgStr = ConifgStr & txbItemSelectModel(i).Text & ","
                        ConifgStr = ConifgStr & ItemSelectFace(i).Text & ","
                        ConifgStr = ConifgStr & ItemSelectEye(i).Text & ","
                        ConifgStr = ConifgStr & ItemSelectAbroad(i).Text & ","
                        If i = 15 Then
                            ConifgStr = ConifgStr & ItemSelectAgency(i).Text
                        Else
                            ConifgStr = ConifgStr & ItemSelectAgency(i).Text & ","
                        End If
                        If ItemSelectItem(i).Text = "" Then ItemSelectItem(i).Text = "0"
                    Next

                Case "printer"

                    FileName = FilePath & "\" & "Printer_Config" & ".ini"

                    ConifgStr = ckbprintBar.Checked & "☏" & ckbPrintWar.Checked & "☏" & txbname1.Text & "☏" & txblabel1.Text & "☏" & txbSingle1.Text & "☏" & txbbarcode1.Text & "☏" & txbtext1.Text & "☏" & txbname2.Text & "☏" & txblabel2.Text & "☏" & txbtext2.Text & "☏"
            End Select


            System.IO.File.Delete(FileName)
            objWriter = New System.IO.StreamWriter(FileName, True)

            objWriter.Flush()
            objWriter.WriteLine(ConifgStr)

            objWriter.Close()
            Exit Sub

        Catch ex As Exception
            Save_ErrorCSV("Save_ini," & ex.Message)
        End Try
    End Sub
    Private Sub Save_InfoWrite_LogCSV(ChNum As DS_TYPE)
        Dim FilePath As String
        Dim syear As String
        Dim smonth As String
        Dim sday As String
        Dim runFlag As Boolean = True
        Dim FileName As String
        Dim ItemList As String = ""
        Dim WriteCsvData(35) As String
        Dim SaveData As String = ""
        Dim TypeStr As String = ""
        Dim objWriter As System.IO.StreamWriter

        Try
            syear = DateAndTime.Year(Now)
            smonth = DateAndTime.Month(Now)
            sday = DateAndTime.Day(Now)

            If ChNum = DS_TYPE.DS_DEV Then
                TypeStr = "DEVICE"
            ElseIf ChNum = DS_TYPE.DS_FACE Then
                TypeStr = "FACE"
            ElseIf ChNum = DS_TYPE.DS_EYE Then
                TypeStr = "EYE"
            ElseIf ChNum = DS_TYPE.DS_BODY Then
                TypeStr = "BODY"
            End If

            WriteCsvData(0) = getNowDate().ToString            ''Date
            WriteCsvData(1) = getNowTime().ToString            ''Time
            WriteCsvData(2) = "WRITE"                          ''Barcord
            WriteCsvData(3) = txbInfo_Barcord(ChNum).Text      ''Barcord
            If ResultTextBoxList(ChNum, 0).ForeColor = Color.Red Then
                WriteCsvData(4) = "FAIL"
            Else
                WriteCsvData(4) = "SUCCESS"
            End If
            WriteCsvData(5) = txbInfo_Model(ChNum).Text        ''Model
            WriteCsvData(6) = TypeStr                          ''Type
            WriteCsvData(7) = txbInfo_Manufacture(ChNum).Text  ''Manufactured Name
            WriteCsvData(8) = txbInfo_Year(ChNum).Text         ''Manufactured Year
            WriteCsvData(9) = txbInfo_Month(ChNum).Text        ''Manufactured Month
            WriteCsvData(10) = txbInfo_SN(ChNum).Text           ''SN
            WriteCsvData(11) = txbInfo_TDSN(ChNum).Text         ''TD S/N
            WriteCsvData(12) = txbInfo_FW(ChNum).Text          ''F/W Version
            WriteCsvData(13) = txbInfo_Abroad(ChNum).Text      ''Abroad
            WriteCsvData(14) = txbInfo_Agency(ChNum).Text      ''Agency
            WriteCsvData(15) = txbInfo_Rshot(ChNum).Text       ''Remain Shot
            WriteCsvData(16) = txbInfo_Tshot(ChNum).Text       ''Total Shot,Info

            For i = 0 To 7
                WriteCsvData(17 + (i * 2)) = SendValue(ChNum, i)     ''Send Data Value
                WriteCsvData(17 + ((i * 2) + 1)) = ReturnValue(ChNum, i)   ''Receive Data Value
            Next

            FilePath = System.AppDomain.CurrentDomain.BaseDirectory() & "LogData"

            '디렉토리가 없을 경우
            If Dir(FilePath, vbDirectory) = "" Then
                MkDir(FilePath)
            End If

            FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_LogData.csv"

            ItemList = "Date,Time,Run Step,Product Code,Complete,Model,Type,Manufactured Name,Manufactured Year,Manufactured Month,SN,TD S/N,F/W Version,Abroad,Agency,Remain Shot,Total Shot" &
                       ",SendData(0),ReceiveData(0),SendData(1),ReceiveData(1),SendData(2),ReceiveData(2),SendData(3),ReceiveData(3),SendData(4),ReceiveData(4),SendData(5),ReceiveData(5),SendData(6),ReceiveData(6),SendData(7),ReceiveData(7)"

            For i = 0 To 32
                SaveData = SaveData & WriteCsvData(i) & ","
            Next

            SaveData = SaveData & WriteCsvData(33)

            If File.Exists(FileName) = True Then
                objWriter = New System.IO.StreamWriter(FileName, True, System.Text.Encoding.GetEncoding("euc-kr"))
                objWriter.WriteLine(SaveData)
            Else
                objWriter = New System.IO.StreamWriter(FileName, True, System.Text.Encoding.GetEncoding("euc-kr"))
                objWriter.WriteLine(ItemList)
                objWriter.WriteLine(SaveData)
            End If

            objWriter.Close()

            Exit Sub
        Catch ex As Exception
            Save_ErrorCSV("Save_InfoWrite_LogCSV," & ex.Message)
            MsgBox("Log Data Save Fail:" & ex.Message, vbCritical, PROGRAM_TITLE_NAME)
            Exit Sub
        End Try
    End Sub
    Private Sub Save_InfoUpload_LogCSV(ChNum As DS_TYPE)
        Dim FilePath As String
        Dim syear As String
        Dim smonth As String
        Dim sday As String
        Dim runFlag As Boolean = True
        Dim FileName As String
        Dim ItemList As String = ""
        Dim SaveData As String = ""
        Dim TypeStr As String = ""
        Dim objWriter As System.IO.StreamWriter

        Try
            syear = DateAndTime.Year(Now)
            smonth = DateAndTime.Month(Now)
            sday = DateAndTime.Day(Now)

            If ChNum = DS_TYPE.DS_DEV Then
                TypeStr = "DEVICE"
            ElseIf ChNum = DS_TYPE.DS_FACE Then
                TypeStr = "FACE"
            ElseIf ChNum = DS_TYPE.DS_EYE Then
                TypeStr = "EYE"
            ElseIf ChNum = DS_TYPE.DS_BODY Then
                TypeStr = "BODY"
            End If

            FilePath = System.AppDomain.CurrentDomain.BaseDirectory() & "LogData"

            '디렉토리가 없을 경우
            If Dir(FilePath, vbDirectory) = "" Then
                MkDir(FilePath)
            End If

            FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_LogData.csv"

            ItemList = "Date,Time,Run Step,Product Code,Complete,Model,Type,Manufactured Name,Manufactured Year,Manufactured Month,SN,TD S/N,F/W Version,Abroad,Agency,Remain Shot,Total Shot" &
                   ",SendData(0),ReceiveData(0),SendData(1),ReceiveData(1),SendData(2),ReceiveData(2),SendData(3),ReceiveData(3),SendData(4),ReceiveData(4),SendData(5),ReceiveData(5),SendData(6),ReceiveData(6),SendData(7),ReceiveData(7)"

            SaveData = getNowDate() & "," & getNowTime() & ","
            SaveData = SaveData & "UPLOAD" & ","
            SaveData = SaveData & txbInfo_Barcord(ChNum).Text & ","
            If UploadDBComplete(ChNum) Then
                SaveData = SaveData & "SUCCESS"
            Else
                SaveData = SaveData & "FAIL"
            End If

            If File.Exists(FileName) = True Then
                objWriter = New System.IO.StreamWriter(FileName, True, System.Text.Encoding.GetEncoding("euc-kr"))
                objWriter.WriteLine(SaveData)
            Else
                objWriter = New System.IO.StreamWriter(FileName, True, System.Text.Encoding.GetEncoding("euc-kr"))
                objWriter.WriteLine(ItemList)
                objWriter.WriteLine(SaveData)
            End If

            objWriter.Close()

            Exit Sub

        Catch ex As Exception
            Save_ErrorCSV("Save_InfoUpload_LogCSV," & ex.Message)
        End Try
    End Sub
    Private Sub Save_ErrorCSV(ErrorData As String)
        Dim FilePath As String
        Dim syear As String
        Dim smonth As String
        Dim sday As String
        Dim runFlag As Boolean = True
        Dim FileName As String
        Dim ItemList As String = ""
        Dim SaveData As String
        Dim TypeStr As String = ""
        Dim objWriter As System.IO.StreamWriter

        Try

            syear = DateAndTime.Year(Now)
            smonth = DateAndTime.Month(Now)
            sday = DateAndTime.Day(Now)

            SaveData = getNowDate().ToString & "," & getNowTime().ToString & "," & ErrorData

            FilePath = System.AppDomain.CurrentDomain.BaseDirectory() & "ErrorData"

            '디렉토리가 없을 경우
            If Dir(FilePath, vbDirectory) = "" Then
                MkDir(FilePath)
            End If

            FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_ErrorData.csv"

            ItemList = "Date,Time,Location,Description"


            If File.Exists(FileName) = True Then
                objWriter = New System.IO.StreamWriter(FileName, True, System.Text.Encoding.GetEncoding("euc-kr"))
                objWriter.WriteLine(SaveData)
            Else
                objWriter = New System.IO.StreamWriter(FileName, True, System.Text.Encoding.GetEncoding("euc-kr"))
                objWriter.WriteLine(ItemList)
                objWriter.WriteLine(SaveData)
            End If

            objWriter.Close()

            Exit Sub

        Catch ex As Exception
            Save_ErrorCSV("Save_ErrorCSV," & ex.Message)
        End Try
    End Sub
    Private Sub chkDevice_CheckedChanged(sender As Object, e As EventArgs) Handles chkDevUse.CheckedChanged
        If chkDevUse.Checked Then
            gpbDevInfoSet.Visible = True
            chkBodyUse.Checked = False

        Else
            gpbDevInfoSet.Visible = False
        End If
        gpbDevInfoSet.Refresh()
        SetBarCodeBoxFocus()
    End Sub

    Private Sub chkFace_CheckedChanged(sender As Object, e As EventArgs) Handles chkFaceUse.CheckedChanged
        If chkFaceUse.Checked Then
            txbConf_FaceShot.Visible = True
            txbConf_BodyShot.Visible = False
            chkBodyUse.Checked = False
            gpbFaceInfoSet.Text = "FACE카트리지 정보"
            gpbFaceInfoSet.Visible = True
            gpbFaceSet.Text = "FACE카트리지 정보 설정"
            gpbFaceSet.Visible = True
        Else
            txbConf_BodyShot.Visible = True
            gpbFaceInfoSet.Visible = False
            gpbFaceSet.Visible = False
        End If
        gpbFaceInfoSet.Refresh()
        gpbFaceSet.Refresh()
        SetBarCodeBoxFocus()
    End Sub

    Private Sub chkEye_CheckedChanged(sender As Object, e As EventArgs) Handles chkEyeUse.CheckedChanged
        If chkEyeUse.Checked Then
            'txbConf_EyeShot.Text = "60000"
            chkBodyUse.Checked = False
            gpbEyeInfoSet.Visible = True
            gpbEyeSet.Visible = True
        Else
            gpbEyeInfoSet.Visible = False
            gpbEyeSet.Visible = False
        End If
        gpbEyeInfoSet.Refresh()
        gpbEyeSet.Refresh()
        SetBarCodeBoxFocus()
    End Sub
    Private Sub chkBody_CheckedChanged(sender As Object, e As EventArgs) Handles chkBodyUse.CheckedChanged
        If chkBodyUse.Checked Then
            txbConf_BodyShot.Visible = True
            txbConf_FaceShot.Visible = False
            chkDevUse.Checked = False
            chkFaceUse.Checked = False
            chkEyeUse.Checked = False
            chkBodyUse.Checked = True
            gpbFaceInfoSet.Text = "BODY카트리지 정보"
            gpbFaceInfoSet.Visible = True
            gpbDevInfoSet.Visible = False
            gpbEyeInfoSet.Visible = False
            gpbFaceSet.Text = "BODY카트리지 정보 설정"
            gpbFaceSet.Visible = True
        Else
            txbConf_BodyShot.Visible = False
            txbConf_FaceShot.Visible = True
            gpbFaceInfoSet.Text = "FACE카트리지 정보"
            gpbFaceInfoSet.Visible = False
            gpbFaceSet.Text = "FACE카트리지 정보 설정"
            gpbFaceSet.Visible = False
        End If
        gpbFaceInfoSet.Refresh()
        gpbFaceSet.Refresh()
        SetBarCodeBoxFocus()
    End Sub

    Private Sub runTimeTimer_Tick(sender As Object, e As EventArgs) Handles runTimeTimer.Tick
        lblTime.Text = Now
        lblTime.Refresh()

        If active_onoff = True Then
            active_form()
        End If


        For num = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
            If EnableBarCodeTxbToggle(num) Then
                If EnableBarCodeTxbToggle(DS_TYPE.MAX_DS_TYPE_NUM) Then
                    txbInfo_Barcord(num).BackColor = Color.DodgerBlue
                Else
                    txbInfo_Barcord(num).BackColor = Color.Yellow
                End If
            End If
        Next
        EnableBarCodeTxbToggle(DS_TYPE.MAX_DS_TYPE_NUM) = Not EnableBarCodeTxbToggle(DS_TYPE.MAX_DS_TYPE_NUM)

    End Sub

    Private Sub chkBarcode_CheckedChanged(sender As Object, e As EventArgs) Handles chkBarcode.CheckedChanged

        Select Case RunMode
            Case FORM_TYPE.WRITE_MODE
                If chkBarcode.Checked Then
                    lblJudge.Location = New Size(340, 50)
                    lblJudge.Size = New Size(159, 83)
                    lblJudge.Text = "판정"
                    btnCmdInput.Visible = False
                Else
                    lblJudge.Location = New Size(175, 50)
                    lblJudge.Size = New Size(345, 83)
                    lblJudge.Text = "바코드번호"
                    btnCmdInput.Visible = True
                End If
            Case FORM_TYPE.READ_MODE
                lblJudge.Location = New Size(300, 27)
                lblJudge.Size = New Size(221, 83)
                lblJudge.Text = "바코드"

                If chkBarcode.Checked Then
                    btnCmdInput.Visible = False
                Else
                    btnCmdInput.Visible = True
                End If
        End Select


        lblJudge.Refresh()
        btnCmdInput.Refresh()
    End Sub

    Private Sub RunInput_Process()
        Dim RET_VAL As String
        Dim RET_TYPE As DS_TYPE
        Dim tmpModelType As Integer
        Dim DiffFlag As Boolean = False

        Try
            If btnCmdStart.Text = "정보입력 전 기기를 제거해주세요." Then Return

            btnCmdStart.Text = "시작"

            ''바코드 유효성 확인
            tmpModelType = Val(Mid(txbBarcodeNum.Text, 1, 2))

            If tmpModelType = DS_PRODUCT.DS_PRO_DEV Or tmpModelType = DS_PRODUCT.DS_PRO_FACE Or tmpModelType = DS_PRODUCT.DS_PRO_EYE Or tmpModelType = DS_PRODUCT.DS_PRO_BODY Then
            ElseIf tmpModelType = DS_PRODUCT.DS_LUX_DEV Or tmpModelType = DS_PRODUCT.DS_LUX_FACE Or tmpModelType = DS_PRODUCT.DS_LUX_EYE Or tmpModelType = DS_PRODUCT.DS_LUX_BODY Then
            ElseIf tmpModelType = DS_PRODUCT.DS_ALPHA_DEV Or tmpModelType = DS_PRODUCT.DS_ALPHA_FACE Or tmpModelType = DS_PRODUCT.DS_ALPHA_EYE Or tmpModelType = DS_PRODUCT.DS_ALPHA_BODY Then
            Else
                Return
            End If

            If td_Compare(txbBarcodeNum.Text, "Product_SN", "jomtProductTbl") Then
                GoTo DUPLICATION_NG
            End If
            If td_Compare(txbBarcodeNum.Text, "Product_SN", "jomtCartridgeTbl") Then
                GoTo DUPLICATION_NG
            End If

            If Len(txbBarcodeNum.Text) <> 12 Then Return

            RET_VAL = RunSN_Parsing(txbBarcodeNum.Text)

            If InStr(RET_VAL, ",") <> 0 Then
                RET_TYPE = Val(Mid(RET_VAL, 1, 1))
                RET_VAL = Mid(RET_VAL, InStr(RET_VAL, ",") + 1, Len(RET_VAL) - InStr(RET_VAL, ","))
            Else
                RET_TYPE = Val(Mid(RET_VAL, 1, 1))
                RET_VAL = ""
            End If

            If RET_VAL = "INSERT_DIVICE" Then Return

            For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                If chkDeviceUse(cnt).Checked Then
                    lblInfo_Model(cnt).ForeColor = Color.Black
                    lblInfo_SN(cnt).ForeColor = Color.Black
                    lblInfo_YearMonth(cnt).ForeColor = Color.Black
                    lblInfo_Year(cnt).ForeColor = Color.Black
                    lblInfo_Month(cnt).ForeColor = Color.Black
                    txbInfo_Model(cnt).BackColor = Color.FromArgb(255, 255, 192)
                    txbInfo_SN(cnt).BackColor = Color.FromArgb(255, 255, 192)
                    txbInfo_Year(cnt).BackColor = Color.FromArgb(255, 255, 192)
                    txbInfo_Month(cnt).BackColor = Color.FromArgb(255, 255, 192)
                End If
            Next

            If RET_VAL = "NOISE" Or RET_VAL = "DISABLE" Then Return

            If RET_VAL = "DIFFERENT" Then
                If DIFF_MATCH_FLAG(DIFF_MATCH.MODEL_DIFFERENT) Then
                    For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                        If chkDeviceUse(cnt).Checked Then
                            If cnt = RET_TYPE Then
                                lblInfo_Model(cnt).ForeColor = Color.Red
                                txbInfo_Model(cnt).BackColor = Color.Red
                            Else
                                If LOAD_FLAG(cnt) Then
                                    lblInfo_Model(cnt).ForeColor = Color.Red
                                Else
                                    lblInfo_Model(cnt).ForeColor = Color.Black
                                End If
                            End If
                        End If
                    Next
                End If

                If DIFF_MATCH_FLAG(DIFF_MATCH.SN_DIFFERENT) Then
                    For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                        If chkDeviceUse(cnt).Checked Then
                            If cnt = RET_TYPE Then
                                lblInfo_SN(cnt).ForeColor = Color.Red
                                txbInfo_SN(cnt).BackColor = Color.Red
                            Else
                                If LOAD_FLAG(cnt) Then
                                    lblInfo_SN(cnt).ForeColor = Color.Red
                                Else
                                    lblInfo_SN(cnt).ForeColor = Color.Black
                                End If
                            End If
                        End If
                    Next
                End If

                If DIFF_MATCH_FLAG(DIFF_MATCH.DATE_DIFFERENT) Then
                    For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                        If chkDeviceUse(cnt).Checked Then
                            If cnt = RET_TYPE Then
                                lblInfo_YearMonth(cnt).ForeColor = Color.Red
                                lblInfo_Year(cnt).ForeColor = Color.Red
                                lblInfo_Month(cnt).ForeColor = Color.Red
                                txbInfo_Year(cnt).BackColor = Color.Red
                                txbInfo_Month(cnt).BackColor = Color.Red
                            Else
                                If LOAD_FLAG(cnt) Then
                                    lblInfo_YearMonth(cnt).ForeColor = Color.Red
                                    lblInfo_Year(cnt).ForeColor = Color.Red
                                    lblInfo_Month(cnt).ForeColor = Color.Red
                                Else
                                    lblInfo_YearMonth(cnt).ForeColor = Color.Black
                                    lblInfo_Year(cnt).ForeColor = Color.Black
                                    lblInfo_Month(cnt).ForeColor = Color.Black
                                End If
                            End If
                        End If
                    Next
                End If

                For cnt = 1 To (DIFF_MATCH.MAX_DIFF_MATCH_NUM - 1)
                    If DIFF_MATCH_FLAG(cnt) Then DiffFlag = True
                    DIFF_MATCH_FLAG(cnt) = False
                Next
            End If

            If chkDeviceUse(RET_TYPE).Checked = False Then Return

            If GetConnectStatus(RET_TYPE) Then
                If LOAD_FLAG(RET_TYPE) = True Then Return
                txbInfo_Barcord(RET_TYPE).BackColor = Color.Red
                Return
            End If

            txbInfo_Barcord(RET_TYPE).Text = txbBarcodeNum.Text

            DisplayInfoType(RET_TYPE)

            If RET_VAL = "" Then
                EnableBarCodeTxbToggle(RET_TYPE) = True
            Else
                EnableBarCodeTxbToggle(RET_TYPE) = False
                txbInfo_Barcord(RET_TYPE).BackColor = Color.Red
            End If

            If IsComplete() = "COMPLETE" Then
                btnCmdStart.Enabled = True
                SetStatus(DS_STATUS.READY)
                RunProcess()
            Else
                btnCmdStart.Enabled = False
            End If

            Exit Sub

DUPLICATION_NG:
            If MsgBox("데이터베이스에 중복된 시리얼 번호가 존재합니다. 허나 바코드는 재인쇄가 가능합니다." & vbCrLf & "바코드를 재인쇄 하시겠습니까?", vbExclamation + vbYesNo) = MsgBoxResult.Yes Then
                Compare_Print = True
                txtName = txbBarcodeNum.Text
                print_OnOff = True

                SetBarCodeBoxFocus()

                txbBarcodeNum.Text = "인쇄 완료"
                txbBarcodeNum.BackColor = Color.Green
                Exit Sub
            End If

            txbBarcodeNum.Text = "중복 오류"
            txbBarcodeNum.BackColor = Color.Red
            Exit Sub

        Catch ex As Exception
            Save_ErrorCSV("RunBarCodeInput," & ex.Message)
        End Try
    End Sub
    Private Sub DisplayInfoType(MODEL_TYPE As DS_TYPE)

        If chkDeviceUse(MODEL_TYPE).Checked = True Then
            If DS_SN(MODEL_TYPE).MODEL = DS_MODEL.DS_PRO Then
                txbInfo_Model(MODEL_TYPE).Text = "PRO"
            ElseIf DS_SN(MODEL_TYPE).MODEL = DS_MODEL.DS_LUX Then
                txbInfo_Model(MODEL_TYPE).Text = "LUX"
            ElseIf DS_SN(MODEL_TYPE).MODEL = DS_MODEL.DS_ALPHA Then
                txbInfo_Model(MODEL_TYPE).Text = "ALPHA"
            End If
            txbInfo_Manufacture(MODEL_TYPE).Text = "JOMT"
            txbInfo_Year(MODEL_TYPE).Text = DS_SN(MODEL_TYPE).YEAR
            txbInfo_Month(MODEL_TYPE).Text = DS_SN(MODEL_TYPE).MONTH
            txbInfo_SN(MODEL_TYPE).Text = DS_SN(MODEL_TYPE).SN

            txbInfo_Abroad(MODEL_TYPE).Text = txbConf_Abroad.Text
            txbInfo_Agency(MODEL_TYPE).Text = txbConf_Agency.Text

            If MODEL_TYPE = DS_TYPE.DS_FACE Then
                txbInfo_Rshot(MODEL_TYPE).Text = txbConf_FaceShot.Text
                txbInfo_Tshot(MODEL_TYPE).Text = txbConf_FaceShot.Text
            ElseIf MODEL_TYPE = DS_TYPE.DS_EYE Then
                txbInfo_Rshot(MODEL_TYPE).Text = txbConf_EyeShot.Text
                txbInfo_Tshot(MODEL_TYPE).Text = txbConf_EyeShot.Text
            ElseIf MODEL_TYPE = DS_TYPE.DS_BODY Then
                txbInfo_Rshot(MODEL_TYPE).Text = txbConf_BodyShot.Text
                txbInfo_Tshot(MODEL_TYPE).Text = txbConf_BodyShot.Text
            End If
        End If

    End Sub

    Private Function WriteCartInfoData(CT_TYPE As DS_TYPE) As String
        Dim ChNum As Integer = CT_TYPE + 1
        Dim CmdString As String = "cartoqc"
        Dim tmpSN As String = txbInfo_Year(CT_TYPE).Text & txbInfo_Month(CT_TYPE).Text & txbInfo_SN(CT_TYPE).Text
        Dim tmpModelType As String = DS_SN(CT_TYPE).MODEL & DS_SN(CT_TYPE).TYPE
        Dim cmdStr As String = ""
        Dim VariableMaxCnt As Integer = 7
        Try

            If CT_TYPE = DS_TYPE.DS_DEV Then Return "TYPE"
            If CT_TYPE = DS_TYPE.DS_BODY Then ChNum = 2

            SendValue(CT_TYPE, 0) = ChNum.ToString
            SendValue(CT_TYPE, 1) = "jomt"
            SendValue(CT_TYPE, 2) = tmpSN
            SendValue(CT_TYPE, 3) = tmpModelType
            SendValue(CT_TYPE, 4) = txbInfo_Abroad(CT_TYPE).Text
            SendValue(CT_TYPE, 5) = txbInfo_Agency(CT_TYPE).Text
            SendValue(CT_TYPE, 6) = txbInfo_Tshot(CT_TYPE).Text
            SendValue(CT_TYPE, 7) = txbInfo_Rshot(CT_TYPE).Text

            For cnt = 0 To VariableMaxCnt
                If SendValue(CT_TYPE, cnt) = "N/A" Then Return "N/A"
                If cnt < VariableMaxCnt Then
                    cmdStr = cmdStr & SendValue(CT_TYPE, cnt) & ","
                Else
                    cmdStr = cmdStr & SendValue(CT_TYPE, cnt)
                End If
            Next

            cmdMessage = "[" & CmdString & " " & cmdStr & "]" & vbCrLf
            SendData(cmdMessage)

            Return "SUCCESS"

        Catch ex As Exception
            Save_ErrorCSV("RunBarCodeInput," & ex.Message)
            Return "FAIL"
        End Try
    End Function

    Private Function WriteDevInfoData() As String
        Dim ChNum As Integer = 1
        Dim CT_TYPE As DS_TYPE = DS_TYPE.DS_DEV
        Dim CmdString As String = "wrstconf"
        Dim cmdStr As String = ""
        Dim tmpSN As String = txbInfo_Year(DS_TYPE.DS_DEV).Text & txbInfo_Month(DS_TYPE.DS_DEV).Text & txbInfo_SN(DS_TYPE.DS_DEV).Text
        Dim tmpModelType As String = DS_SN(DS_TYPE.DS_DEV).MODEL & DS_SN(DS_TYPE.DS_DEV).TYPE
        Dim VariableMaxCnt As Integer = 5

        Try
            If CT_TYPE <> DS_TYPE.DS_DEV Then Return "TYPE"

            SendValue(CT_TYPE, 0) = ChNum
            SendValue(CT_TYPE, 1) = "jomt"
            SendValue(CT_TYPE, 2) = tmpSN
            SendValue(CT_TYPE, 3) = tmpModelType
            SendValue(CT_TYPE, 4) = txbInfo_Abroad(CT_TYPE).Text
            SendValue(CT_TYPE, 5) = txbInfo_Agency(CT_TYPE).Text

            For cnt = 0 To VariableMaxCnt
                If SendValue(CT_TYPE, cnt) = "N/A" Then Return "N/A"
                If cnt < VariableMaxCnt Then
                    cmdStr = cmdStr & SendValue(CT_TYPE, cnt) & ","
                Else
                    cmdStr = cmdStr & SendValue(CT_TYPE, cnt)
                End If
            Next

            cmdMessage = "[" & CmdString & " " & cmdStr & "]" & vbCrLf
            SendData(cmdMessage)

            Return "SUCCESS"
        Catch ex As Exception
            Save_ErrorCSV("WriteDevInfoData," & ex.Message)
            Return "FAIL"
        End Try
    End Function
    Public Sub WriteInfoTimerEnable(OnOff As Boolean)
        ReceiveCnt = ReceiveCntVal
        If OnOff Then
            ReceiveCntEnable = True
        Else
            ReceiveCntEnable = False
        End If
    End Sub
    Public Sub CheckTDSN_TimerEnable(OnOff As Boolean)
        TDSN_ReceiveCnt = TDSN_ReceiveCntVal
        If OnOff Then
            TDSN_ReceiveCntEnable = True
        Else
            TDSN_ReceiveCntEnable = False
        End If
    End Sub
    Public Sub WriteBarCodeWindow(WrStr As String)
        BarCodeFixedText = True
        txbBarcodeNum.Clear()
        txbBarcodeNum.AppendText(WrStr)
        cboLoadSelect.Focus()
        txbBarcodeNum.Focus()
        BarCodeFixedText = False
    End Sub
    Public Sub RunWrite_Process()
        Try
            If IsComplete() <> "COMPLETE" Then
                txbBarcodeNum.BackColor = Color.Red
                WriteBarCodeWindow("쓰기조건 불충분")
                Exit Sub
            End If

            For cnt = DS_TYPE.DS_FACE To DS_TYPE.DS_BODY
                If chkDeviceUse(cnt).Checked And Mid(txbInfo_TDSN(cnt).Text, 1, 3).ToUpper <> "DIT" And Mid(txbInfo_TDSN(cnt).Text, 1, 1) <> "J" Then
                    txbBarcodeNum.BackColor = Color.Red
                    txbInfo_TDSN(cnt).ForeColor = Color.Red
                    txbInfo_Barcord(cnt).BackColor = Color.Red
                    WriteBarCodeWindow("TD SN 없음")
                    btnCmdStart.Text = "해당 기기를 제거해주세요."
                    Exit Sub
                End If
            Next

            SetStatus(DS_STATUS.WIRTTING)
            WriteBarCodeWindow("정보 쓰기 중")

            For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                If chkDeviceUse(cnt).Checked = True Then
                    Reset_Return_Reg(cnt)

                    For i = 0 To 9
                        ResultTextBoxList(cnt, i).ForeColor = Color.Blue
                    Next
                    txbInfo_TDSN(cnt).ForeColor = Color.Blue
                    txbInfo_FW(cnt).ForeColor = Color.Blue

                    If cnt = DS_TYPE.DS_DEV Then
                        WriteDevInfoData()
                    Else
                        WriteCartInfoData(cnt)
                    End If
                End If
            Next

            WriteInfoTimerEnable(True)

            btnCmdStart.Enabled = False
            SetBarCodeBoxFocus()
        Catch ex As Exception
            Save_ErrorCSV("RunWrite_Process," & ex.Message)
        End Try
    End Sub
    Public Sub RunReWrite_Process()
        Try
            SetStatus(DS_STATUS.REWIRTTING)

            If DiffCompComplete = False Then
                WriteBarCodeWindow("정보 다시쓰기 중")
                For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    If chkDeviceUse(cnt).Checked = True Then
                        If DiffCompReturnVal(cnt) = False And ConnectStatus(cnt) = True Then
                            WriteInfoData(cnt)
                        End If
                    End If
                Next
                WriteInfoTimerEnable(True)
                btnCmdStart.Enabled = False
            Else
                WriteBarCodeWindow("정보 업로드 중")
                For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    If chkDeviceUse(cnt).Checked = True Then
                        If UploadDBComplete(cnt) = False And ConnectStatus(cnt) = True Then
                            If UploadInfoData(cnt) Then
                                ResultTextBoxList(cnt, 0).ForeColor = Color.Blue
                            Else
                                ResultTextBoxList(cnt, 0).ForeColor = Color.Red
                            End If
                        End If
                    End If
                Next

                DBuploadComplete = True
                For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    If chkDeviceUse(cnt).Checked = True Then
                        If UploadDBComplete(cnt) = False Then
                            DBuploadComplete = False
                        End If
                    End If
                Next

                If DiffCompComplete And DBuploadComplete Then
                    DBAssyuploadComplete = Upload_AssyInfo()
                    If DBAssyuploadComplete Then
                        thread_print = True
                        WriteSuccessProcess()
                    Else
                        WriteFailProcess()
                    End If
                End If
            End If

            SetBarCodeBoxFocus()
        Catch ex As Exception
            Save_ErrorCSV("RunReWrite_Process," & ex.Message)
        End Try
    End Sub
    Private Sub WriteInfoData(cnt As DS_TYPE)
        Try
            If chkDeviceUse(cnt).Checked = True Then
                Reset_Return_Reg(cnt)
                For i = 0 To 9
                    ResultTextBoxList(cnt, i).ForeColor = Color.Blue
                Next
                txbInfo_TDSN(cnt).ForeColor = Color.Blue
                txbInfo_FW(cnt).ForeColor = Color.Blue
                If cnt = DS_TYPE.DS_DEV Then
                    WriteDevInfoData()
                Else
                    WriteCartInfoData(cnt)
                End If
            End If
        Catch ex As Exception
            Save_ErrorCSV("WriteInfoData," & ex.Message)
        End Try
    End Sub
    Private Sub loadSetupWindows()

        ''gpbSetupWindow.Visible = True
        ''gpbSetupWindow.Location = New Size(1, 9)
        ''gpbSetupWindow.Size = New Size(1021, 734)
        ''DefaultTextColor()
    End Sub
    Private Sub cmdSerial_Click(sender As Object, e As EventArgs) Handles cmdSerial.Click
        LoadComportName()
    End Sub
    Private Sub LoadComportName()
        Dim portname() As String
        Dim i As Integer

        Try
            cboComPort.Items.Clear()
            portname = cmdSerialPort.GetPortNames

            For i = 1 To portname.Length
                cboComPort.Items.Add(portname(i - 1))
            Next i

            cboComPort.Text = "PRESS!"
        Catch ex As Exception
            Save_ErrorCSV("LoadComportName," & ex.Message)
        End Try
    End Sub

    Private Sub btnSetup_Click(sender As Object, e As EventArgs) Handles btnSetup.Click
        RunSetupWindow()
        btndgvref_Click(sender, e)
    End Sub
    Public Sub RunSetupWindow()
        frmLogin.ShowDialog()
        If GetLoginStatus() = LOGIN_STATUS.CHECK_IN_SETUP Then
            pnlConf.Visible = True
            pnlMain.Visible = False
            SetLoginStatus(LOGIN_STATUS.ENTER_SETUP)
        End If
    End Sub

    Private Sub btnSetupExit_Click(sender As Object, e As EventArgs) Handles btnSetupExit.Click
        pnlMain.Visible = True
        pnlMain.Refresh()
        pnlConf.Visible = False
        SetLoginStatus(LOGIN_STATUS.ENTER_PROGRAM)
        pnlConf.Refresh()
        btnSetup.Enabled = True
    End Sub

    Private Sub btnSetupSave_Click(sender As Object, e As EventArgs) Handles btnSetupSave.Click
        Dim retVal As Integer

        retVal = MsgBox("설정을 저장하시겠습니까?", vbYesNo + vbExclamation, "DUALSONIC Configuation")
        If retVal = 6 Then
            Save_ini("infoset")
            Save_ini("printer")
        End If
    End Sub

    Private Sub btnSetupLoad_Click(sender As Object, e As EventArgs) Handles btnSetupLoad.Click
        Read_ini("infoset")
        Read_ini("printer")
    End Sub
    Private Sub txbBarcodeNum_Click(sender As Object, e As EventArgs) Handles txbBarcodeNum.Click
        If chkBarcode.Checked = False Then txbBarcodeNum.Clear()
    End Sub
    Private Sub txbBarcodeNum_TextChanged(sender As Object, e As EventArgs) Handles txbBarcodeNum.TextChanged
        Dim tmpStr As String

        If BarCodeFixedText = False Then
            If BarCodeWaitCnt = 0 And chkBarcode.Checked = True Then
                '' 이전에 있는 텍스트박스의 텍스트는 삭제하고 새로운 것만 채워넣음.
                tmpStr = txbBarcodeNum.Text
                If (Len(tmpStr) > 1) Then
                    tmpStr = Mid(tmpStr, Len(tmpStr), 1)
                    txbBarcodeNum.Clear()
                    txbBarcodeNum.AppendText(tmpStr)
                End If
                BarCodeWaitCnt = BarCodeWaitTime
                BarCodeWaitTimer.Enabled = True
            End If
        End If
    End Sub

    Private Sub cmdTimer_Tick(sender As Object, e As EventArgs) Handles cmdTimer.Tick
        Try
            If ReceiveCnt Then ReceiveCnt -= 1
            If TDSN_ReceiveCnt Then TDSN_ReceiveCnt -= 1

            If ReceiveCntEnable And ReceiveCnt = 0 Then
                WriteFailProcess()
                For cnt = DS_TYPE.DS_DEV To DS_TYPE.DS_BODY
                    If ReceiveReturnVal(cnt) = False And chkDeviceUse(cnt).Checked Then
                        CheckDiffCompReturnVal(cnt)
                    End If
                Next
                ReceiveCntEnable = False
            End If

            If TDSN_ReceiveCntEnable And TDSN_ReceiveCnt = 0 Then
                TDSN_ReceiveCntEnable = False
            End If
        Catch ex As Exception
            ReceiveCntEnable = False
            TDSN_ReceiveCntEnable = False
        End Try
    End Sub

    Private Sub gpbDeviceInfo_Enter(sender As Object, e As EventArgs) Handles gpbDeviceInfo.Enter

    End Sub

    Private Sub BarCodeWaitTimer_Tick(sender As Object, e As EventArgs) Handles BarCodeWaitTimer.Tick
        Dim tmpStr As String = ""
        Dim tmpCmd As String = ""

        If BarCodeWaitCnt Then
            BarCodeWaitCnt -= 1
        Else
            BarCodeWaitTimer.Enabled = False

            tmpStr = txbBarcodeNum.Text
            tmpCmd = Mid(tmpStr, 1, 5)
            If tmpCmd = "S/N: " Or tmpCmd = "ㄴ/ㅜ: " Then
                tmpStr = Mid(tmpStr, 6, Len(tmpStr) - 5).ToString
                txbBarcodeNum.Clear()
                txbBarcodeNum.AppendText(tmpStr)
            End If

            RunProcess()
        End If
    End Sub
    Private Sub cboLoadSelect_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboLoadSelect.SelectedIndexChanged
        Dim CboNum As Integer

        For cnt = 1 To 15
            If cboLoadSelect.Text = ItemSelectItem(cnt).Text Then
                CboNum = cnt
                Exit For
            End If
        Next

        chkDevUse.Checked = True
        chkFaceUse.Checked = True
        chkEyeUse.Checked = True
        chkBodyUse.Checked = False

        If CboNum Then
            txbConf_Model.Text = txbItemSelectModel(CboNum).Text
            If txbConf_Model.Text = "PRO" Then
                Conf_DS_Set.CONF_MODEL = DS_MODEL.DS_PRO
            ElseIf txbConf_Model.Text = "LUX" Then
                Conf_DS_Set.CONF_MODEL = DS_MODEL.DS_LUX
            ElseIf txbConf_Model.Text = "ALPHA" Then
                Conf_DS_Set.CONF_MODEL = DS_MODEL.DS_ALPHA
            End If

            txbConf_FaceShot.Text = ItemSelectFace(CboNum).Text
            If chkFaceUse.Checked Then
                Conf_DS_Set.CONF_FACE_RSHOT = Val(txbConf_FaceShot.Text)
                Conf_DS_Set.CONF_FACE_TSHOT = Val(txbConf_FaceShot.Text)
            End If

            txbConf_EyeShot.Text = ItemSelectEye(CboNum).Text
            If chkEyeUse.Checked Then
                Conf_DS_Set.CONF_EYE_RSHOT = Val(txbConf_EyeShot.Text)
                Conf_DS_Set.CONF_EYE_TSHOT = Val(txbConf_EyeShot.Text)
            End If

            txbConf_FaceShot.Text = ItemSelectFace(CboNum).Text
            If chkBodyUse.Checked Then
                Conf_DS_Set.CONF_BODY_RSHOT = Val(txbConf_FaceShot.Text)
                Conf_DS_Set.CONF_BODY_TSHOT = Val(txbConf_FaceShot.Text)
            End If

            txbConf_Abroad.Text = ItemSelectAbroad(CboNum).Text
            Conf_DS_Set.CONF_ABLOAD = Val(txbConf_Abroad.Text)
            txbConf_Agency.Text = ItemSelectAgency(CboNum).Text
            Conf_DS_Set.CONF_AGENCY = Val(txbConf_Agency.Text)
        End If
        SetBarCodeBoxFocus()
    End Sub

    Private Sub gpbDeviceInfo_Click(sender As Object, e As EventArgs) Handles gpbDeviceInfo.Click, gpbFaceInfoSet.Click
        SetBarCodeBoxFocus()
    End Sub

    Private Sub gpbJudge_Click(sender As Object, e As EventArgs) Handles gpbJudge.Click
        SetBarCodeBoxFocus()
    End Sub

    Private Sub txbConf_Model_TextChanged(sender As Object, e As EventArgs) Handles txbConf_Model.TextChanged
        If txbConf_Model.Text = "PRO" Then
            Conf_DS_Set.CONF_MODEL = DS_MODEL.DS_PRO
        ElseIf txbConf_Model.Text = "LUX" Then
            Conf_DS_Set.CONF_MODEL = DS_MODEL.DS_LUX
        End If
    End Sub
    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        Reset_All_DS_Reg()
        TextBoxAllReset()
        Reset_All_Connect() '' 모든 기기 미연결 상태로 체크
        SetStatus(DS_STATUS.STANDBY)
        WriteTextBarCodeBox("바코드 입력")
        SetBarCodeBoxFocus()
    End Sub

    Private Sub pnlMain_Click(sender As Object, e As EventArgs) Handles pnlMain.Click
        SetBarCodeBoxFocus()
    End Sub

    Private Sub print_on(printtext As String)

        Try
            Compare_Print = False
            txtName = Nothing
            print_OnOff = False
            active_onoff = True

            Dim doc As bpac.Document = New bpac.Document

            For i = 0 To print_data.GetLength(1) - 1

                If i = 0 Then
                    If ckbprintBar.Checked = True Then
                        If printer_state(print_data(i, 0)) Then
                            Dim print_address As String = print_data(i, 1)
                            doc.Open(print_address)

                            Dim print_name As Boolean = doc.SetPrinter(print_data(i, 0), True)

                            doc.GetObject(txbbarcode1.Text).Text = printtext
                            doc.GetObject(txbtext1.Text).Text = printtext
                        Else
                            MsgBox("프린터 연결이 잘못되었습니다. 전원이나 케이블을 확인하여 주십시오.", vbExclamation)
                        End If

                    End If
                Else
                    If ckbPrintWar.Checked = True Then
                        If printer_state(print_data(i, 0)) Then
                            Dim print_address As String = print_data(i, 1)
                            doc.Open(print_address)

                            Dim print_name As Boolean = doc.SetPrinter(print_data(i, 0), True)
                            doc.GetObject(txbtext2.Text).Text = printtext
                        Else
                            MsgBox("프린터 연결이 잘못되었습니다. 전원이나 케이블을 확인하여 주십시오.", vbExclamation)
                        End If

                    End If
                End If

                doc.StartPrint("", bpac.PrintOptionConstants.bpoDefault)
                doc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault)
                doc.EndPrint()
                doc.Close()
            Next

        Catch ex As Exception
            Compare_Print = False
            txtName = Nothing
            print_OnOff = False
            MsgBox("Print Error : " & ex.Message, vbCritical)
        End Try
    End Sub

    Private Sub btnAd1_Click(sender As Object, e As EventArgs) Handles btnAd1.Click
        Dim fileAddress As String = openfile()

        If fileAddress <> "fail" Then
            txblabel1.Text = fileAddress
        End If
    End Sub

    Private Sub btnAd2_Click(sender As Object, e As EventArgs) Handles btnAd2.Click
        Dim fileAddress As String = openfile()

        If fileAddress <> "fail" Then
            txblabel2.Text = fileAddress
        End If
    End Sub

    Private Function openfile() As String
        Dim ofd As OpenFileDialog = New OpenFileDialog
        ofd.Title = "라벨 파일 주소 불러오기"
        ofd.FileName = ""
        ofd.Filter = "라벨 파일(*.lbx) | *.lbx"

        Dim dr As DialogResult = ofd.ShowDialog

        If dr = DialogResult.OK Then
            Return ofd.FileName
        End If

        Return "fail"
    End Function

    Private Sub btndgvref_Click(sender As Object, e As EventArgs) Handles btndgvref.Click
        Dim lvi(1) As String
        Dim alList As System.Collections.ArrayList = New System.Collections.ArrayList(PrinterSettings.InstalledPrinters)

        alList.Sort()
        dgvPrinter.Rows.Clear()

        For i = 0 To alList.Count - 1
            lvi(0) = i + 1
            lvi(1) = alList(i).ToString

            dgvPrinter.Rows.Add(lvi)
        Next
    End Sub

    Private Sub btnPrint1_Click(sender As Object, e As EventArgs) Handles btnPrint1.Click
        Dim row As DataGridViewRow = dgvPrinter.SelectedRows(0)
        Dim printname As String = row.Cells(1).Value.ToString
        txbname1.Text = printname
    End Sub

    Private Sub btnprint2_Click(sender As Object, e As EventArgs) Handles btnprint2.Click
        Dim row As DataGridViewRow = dgvPrinter.SelectedRows(0)
        Dim printname As String = row.Cells(1).Value.ToString
        txbname2.Text = printname
    End Sub

    Private Function printer_state(printername As String) As Boolean
        Dim scope As ManagementScope = New ManagementScope("\root\cimv2")
        scope.Connect()

        Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_Printer")

        Dim printName As String = ""

        For Each printer As ManagementObject In searcher.Get
            printName = printer("Name").ToString
            If printName.Equals(printername) Then
                If printer("WorkOffline").ToString.ToLower.Equals("true") Then
                    Return False
                Else
                    Return True
                End If
            End If
        Next

        Return False
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs)
        printnumtype(printnum.face) = txbInfo_FaceBarcord.Text
        MsgBox(printnumtype(printnum.face))
    End Sub

    Private Sub ckbPrintAll_CheckedChanged(sender As Object, e As EventArgs) Handles ckbPrintAll.CheckedChanged
        If ckbPrintAll.Checked = True Then
            ckbprintBar.Checked = True
            ckbPrintWar.Checked = True
            gbprintck.Enabled = False
        Else
            ckbprintBar.Checked = False
            ckbPrintWar.Checked = False
            gbprintck.Enabled = True
        End If
    End Sub

    Private Sub btnSingle1_Click(sender As Object, e As EventArgs) Handles btnSingle1.Click
        Dim fileAddress As String = openfile()

        If fileAddress <> "fail" Then
            txbSingle1.Text = fileAddress
        End If
    End Sub

    Private Sub ckbmainprint_CheckedChanged(sender As Object, e As EventArgs) Handles ckbmainprint.CheckedChanged
        If ckbmainprint.Checked = True Then
            ckbPrintAll.Checked = True
        Else
            ckbPrintAll.Checked = False
        End If
    End Sub

    Private Sub printOptionData(front_data As String)
        print_data(0, 0) = txbname1.Text
        If Mid(front_data, 2, 1) = "0" Then
            print_data(0, 1) = txblabel1.Text
        Else
            print_data(0, 1) = txbSingle1.Text
        End If
        print_data(1, 0) = txbname2.Text
        print_data(1, 1) = txblabel2.Text
    End Sub
End Class