Imports System.Drawing.Imaging
Imports System.IO
Imports System.IO.Ports
Imports System.Math
Imports System.Threading
Imports Mysqlx.XDevAPI.Relational

Public Class mainForm
    Private Enum formModList
        Search
        Write
        Delete
        ReturnP
    End Enum
    Private runMod As Int16

    Private Enum tdDataList
        TDSN
        TDDate
        TestDate
        TestTime
        Grade
    End Enum
    Private tdReadData(tdDataList.Grade) As String
    Private tdReadTxb(tdDataList.Grade) As TextBox

    Private Enum dotDataList
        dotDate
        dotTime
        dotPower
        dotDepth
    End Enum
    Private dotReadData(dotDataList.dotDepth) As String
    Private dotReadTxb(dotDataList.dotDepth) As TextBox

    Private Enum hifuDataList
        hifuDate
        hifuTime
        hifuFW
        hifuBaterry
        hifuDtemp
        hifuCtemp
        hifuFreq
        hifuData1_txb
        hifuData2
        hifuData3
    End Enum
    Private hifuReadData(hifuDataList.hifuData3) As String
    Private hifuReadTxb(hifuDataList.hifuData1_txb) As TextBox

    Private Enum rfDataList
        rfDate
        rfTime
        rfR1Vrms_txb1
        rfR1Freq_txb2
        rfR2Vrms_txb3
        rfR2Freq
        rfR3Vrms
        rfR3Freq
        epR1Vpp
        epR1Freq
        epR1PWidth
        epR1NWidth
        epR2Vpp
        epR2Freq
        epR2PWidth
        epR2NWidth
        epR3Vpp
        epR3Freq
        epR3PWidth
        epR3NWidth

        mcR1Wave
        mcR1Vpp
        mcR1Freq
        mcR2Wave
        mcR2Vpp
        mcR2Freq
    End Enum
    Private rfReadData(rfDataList.mcR2Freq) As String
    Private rfReadTxb(rfDataList.rfR2Vrms_txb3) As TextBox


    Private Enum pd2DataList
        pd2DateTime
        prodDate
        pd2Serial
        pd2Factory
        pd2Model
        pd2Type
        pd2Country
        pd2Agency
        pd2Face
        pd2Eye

        pd2Max
    End Enum
    Private pd2ReadData(pd2DataList.pd2Max - 1) As String
    Private pd2ReadTxb(pd2DataList.pd2Max - 1) As TextBox

    Private Enum saveDataList
        opFw
        opFreqMax
        opFreqMin
        opBatMax
        opBatMin
        opDtempMax
        opDtempMin
        opCtempMax
        opCtempMin
        opHF1Max
        opHF1Min
        opHF2Max
        opHF2Min
        opHF3Max
        opHF3Min
        opHF12
        opHF23
        optg1FrqMax
        optg1FrqMin
        optg1VrMax
        optg1VrMin
        optg2FrqMax
        optg2FrqMin
        optg2VrMax
        optg2VrMin
        optg3FrqMax
        optg3FrqMin
        optg3VrMax
        optg3VrMin
        opdy1DtMax
        opdy1DtMin
        opdy1FrMax
        opdy1FrMin
        opdy1VpMax
        opdy1VpMin
        opdy2DtMax
        opdy2DtMin
        opdy2FrMax
        opdy2FrMin
        opdy2VpMax
        opdy2VpMin
        opcs1Dy
        opcs1FrMax
        opcs1FrMin
        opcs1VpMax
        opcs1VpMin
        opcs2Dy
        opcs2FrMax
        opcs2FrMin
        opcs2VpMax
        opcs2VpMin
        opcs3Dy
        opcs3FrMax
        opcs3FrMin
        opcs3VpMax
        opcs3VpMin

        opFW_AT
        opBatMax_AT
        opBatMin_AT
        opDtempMax_AT
        opDtempMin_AT
        opCtempMax_AT
        opCtempMin_AT

        optg1FrqMax_AT
        optg1FrqMin_AT
        optg1VrMax_AT
        optg1VrMin_AT
        optg2FrqMax_AT
        optg2FrqMin_AT
        optg2VrMax_AT
        optg2VrMin_AT
        optg3FrqMax_AT
        optg3FrqMin_AT
        optg3VrMax_AT
        optg3VrMin_AT

        opcs1Dy_AT
        opcs1FrMax_AT
        opcs1FrMin_AT
        opcs1VpMax_AT
        opcs1VpMin_AT
        opcs2Dy_AT
        opcs2FrMax_AT
        opcs2FrMin_AT
        opcs2VpMax_AT
        opcs2VpMin_AT
        opcs3Dy_AT
        opcs3FrMax_AT
        opcs3FrMin_AT
        opcs3VpMax_AT
        opcs3VpMin_AT
    End Enum
    Private saveTextData(saveDataList.opcs3VpMin_AT) As TextBox

    Private Enum dbRegList
        dbTD
        dbDot
        dbHifu
        dbWave
        dbInfo
        DBALL
    End Enum
    Private saveDBCkb(dbRegList.dbInfo) As CheckBox
    Private dataOkNg(dbRegList.DBALL) As Boolean

    Private Enum prodTypeList
        cartSet
        cartFace
        cartEye
        cartBody
        device
        allInOne
        cartEtc
    End Enum

    Private cartSerial(prodTypeList.cartEtc) As String
    Private TDUseCompare As Boolean
    Private LDMUseCompare As Boolean
    Private RfEpOnlyCompare As Boolean
    Private searchType As String
    Private colorType As String
    Private deviceType As String
    Private modelType As String

    Private Enum csvDataList
        csvModel
        csvShot
        csvVersion
        csvProWeight
        csvLuxWeight
        csvMaxWeight
        csvOkNg
        csvSetSr
        csvFaceSr
        csvEyeSr
        csvBodySr
        csvEtcSr
        csvRefer
    End Enum

    Private Const oldProdLength As Int16 = 12
    Private Const newProdLength As Int16 = 16

    Private monCalNum As String
    Private monCalTime As Boolean

    Public InputCnt As Long
    Public InputCntVal As Integer = 10

    Private DBCmd As String
    Private tmpCmdMessage As String
    Private cmdMessage, rxMessage, CsvRegData As String
    Private itemList As String

    Private runThread As Thread
    Private Delegate Sub commDelegate()
    Private commDelegateFunc As commDelegate

    Private Delegate Sub failDelegate(ngCount As Int16)
    Private failDelegateFunc As failDelegate

    Private Sub mainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        startSetting()
        formFullReset() '메인 화면 청소
        dataSetting()
        ComboBoxSetting()
        configLoad()
    End Sub

    Private Sub txbProdSerial_TextChanged(sender As Object, e As EventArgs) Handles txbProdSerial.TextChanged
        Dim tmpStr As String

        If InputCnt = 0 And ckbBarcode.Checked = True Then
            tmpStr = txbProdSerial.Text
            If (Len(tmpStr) > 1) Then
                tmpStr = Mid(tmpStr, Len(tmpStr), 1)
                txbProdSerial.Clear()
                txbProdSerial.AppendText(tmpStr)
            End If
            SetInputCnt()
        End If
    End Sub

    Private Sub SetInputCnt()
        InputCnt = InputCntVal
        barTimer.Enabled = True
    End Sub

    Private Sub barTimer_Tick(sender As Object, e As EventArgs) Handles barTimer.Tick
        If InputCnt Then
            InputCnt -= 1
        Else
            barTimer.Enabled = False

            If ckbBarcode.Checked Then
                btnSearch_Click(sender, e)
            Else
                txbProdSerial.Focus()
                txbProdSerial.Refresh()
            End If
        End If
    End Sub

    Private Sub startSetting()
        Const programName As String = "MAXIMUM FUNCTION DATA INFO VER."
        Const programVer As String = "2.0.3"
        Me.Text = programName & programVer
        Me.Size = New Size(1920, 1060)
        Me.Location = New Point(0, 0)

        ckbBarcode.Checked = True  '' 기본 설정
        ckbExcel.Checked = True
        rdbSearch.Checked = True
    End Sub

    Private Sub btnSerial_Click(sender As Object, e As EventArgs) Handles btnSerial.Click
        If btnSerial.Text = "스캔" Then

            If cmdSerial.IsOpen = True Then
                cmdSerial.Close()
            End If

            LoadComport()
            btnSerial.Text = "연결"
        Else
            openSerial(cboSerial.SelectedItem)
            btnSerial.Text = "스캔"
        End If

        txbProdSerial.Focus()
    End Sub

    Private Function openSerial(serialName As String)
        Try
            If serialName <> "" Or serialName <> Nothing Then

                With cmdSerial
                    .PortName = serialName
                    .BaudRate = 230400
                    .DataBits = 8
                    .Parity = Parity.None
                    .StopBits = StopBits.One
                    .Handshake = Handshake.None
                End With

                cmdSerial.Open()
                Return False
            Else
                MsgBox("통신 포트를 지정하여 주십시오.", vbCritical)
                Return True
            End If

            Return False
        Catch ex As Exception
            MsgBox("통신 포트 에러 !! :: " & ex.Message, vbCritical)
            Return True
        End Try
    End Function

    Private Sub LoadComport()
        Dim port() As String

        Try
            cboSerial.Items.Clear()
            port = SerialPort.GetPortNames

            For i = 0 To port.Length - 1
                cboSerial.Items.Add(port(i))
            Next

            cboSerial.Text = "PRESS!"

        Catch ex As Exception
            MsgBox("포트를 불러오는 도중 오류가 발생하였습니다. :: " & ex.Message, vbCritical)
        End Try
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If txbProdSerial.Text = String.Empty Or txbProdSerial.Text.Replace(" ", "") = "" Then
            MsgBox("시리얼 번호를 입력하지 않았습니다.", vbExclamation)
            Exit Sub
        End If

        If txbProdSerial.Text.Length <> oldProdLength And txbProdSerial.Text.Length <> newProdLength Then
            MsgBox("잘못된 시리얼 번호를 입력하였습니다.", vbExclamation)
            Exit Sub
        End If

        Dim prodSerial As String = txbProdSerial.Text

        If dataSearchFunc(prodSerial) Then
            txbProdSerial.BackColor = Color.Green

            If rdbWrite.Checked = True Or rdbDelete.Checked = True Or rdbReturn.Checked = True Then
                If ckbAutoReg.Checked = True Then
                    TypeFunction()
                End If
            End If
        Else
            txbProdSerial.BackColor = Color.Red
        End If
    End Sub

    Private Sub TypeFunction()
        Select Case runMod
            Case formModList.Write

                If cmdSerial.IsOpen = True Then
                    threadOn()
                Else
                    MsgBox("통신 포트가 닫혀 있습니다!", vbExclamation)
                End If

            Case formModList.Delete
                runningcomm()
            Case formModList.ReturnP
                runningcomm()
        End Select
    End Sub

    Private Sub threadOff()
        runThread = New Thread(AddressOf threadRunFunc)

        If runThread.IsAlive = True Then
            runThread.Abort()
        End If

        txbRunState.Text = "대 기"
        txbRunState.BackColor = Color.White
    End Sub

    Private Sub threadOn()
        runThread = New Thread(AddressOf threadRunFunc)

        txbRunState.Text = "입력대기"
        txbRunState.BackColor = Color.DarkGray

        If runThread.IsAlive = True Then
            runThread.Abort()
        End If

        runThread.IsBackground = True
        runThread.Start()
    End Sub

    Const ngLimit As Int16 = 3

    Private Sub threadRunFunc()
        Dim okNg As Boolean = False
        Dim ngCount As Int16 = 0
        Do Until okNg = True
            Dim conCheck As String = shot_search()

            If IsNumeric(conCheck) And conCheck <> "-1" Then
                commDelegateFunc = New commDelegate(AddressOf runningcomm)
                Me.Invoke(commDelegateFunc)
                okNg = True
            End If
            Thread.Sleep(1000)

            If ngCount = ngLimit Then
                okNg = True
            End If

            ngCount += 1
        Loop

        failDelegateFunc = New failDelegate(AddressOf loadFail)
        Me.Invoke(failDelegateFunc, ngCount)
    End Sub

    Private Sub loadFail(ngCount As Int16)
        If ngCount > ngLimit Then
            txbRunState.Text = "시간초과"
            txbRunState.BackColor = Color.Red
        End If
    End Sub

    Private Function shot_search() As String
        Dim retVal As String = "-1"
        tmpCmdMessage = "shotconf"
        cmdMessage = "[" & tmpCmdMessage & "]" + vbCrLf
        If SendData(cmdMessage) Then
            Return "-1"
        End If

        retVal = PollingReceiveData(1000)
        Return retVal
    End Function

    Private Sub startReset()

        For i = 0 To dbRegList.dbInfo
            dataOkNg(i) = True
        Next
        dataOkNg(dbRegList.DBALL) = False

        ReDim tdReadData(tdDataList.Grade)
        ReDim dotReadData(dotDataList.dotDepth)
        ReDim hifuReadData(hifuDataList.hifuData3)
        ReDim rfReadData(rfDataList.mcR2Freq)
        ReDim pd2ReadData(pd2DataList.pd2Max - 1)
        ReDim cartSerial(prodTypeList.cartEtc)

    End Sub

    Private Sub FormReset()
        For i = 0 To tdDataList.Grade
            With tdReadTxb(i)
                .Text = "대기"
                .BackColor = Color.White
                .Refresh()
            End With
        Next

        For i = 0 To dotDataList.dotDepth
            With dotReadTxb(i)
                .Text = "대기"
                .BackColor = Color.White
                .Refresh()
            End With
        Next

        For i = 0 To hifuDataList.hifuData1_txb
            With hifuReadTxb(i)
                .Text = "대기"
                .BackColor = Color.White
                .Refresh()
            End With
        Next

        For i = 0 To rfDataList.rfR2Vrms_txb3
            With rfReadTxb(i)
                .Text = "대기"
                .BackColor = Color.White
                .Refresh()
            End With
        Next

        For i = 0 To pd2DataList.pd2Max - 1
            With pd2ReadTxb(i)
                .Text = "대기"
                .BackColor = Color.White
                .Refresh()
            End With
        Next

        With txbReCount
            .Text = "대기"
            .BackColor = Color.White
            .Refresh()
        End With
    End Sub

    Private Function dataSearchFunc(prodSerial As String) As Boolean
        FormReset()
        startReset()
        prodSerialType(prodSerial)

        If prodSerialExist(prodSerial) Then  '' 제품 시리얼 번호가 있는지 확인
            Return False
        End If

        If prodSerialTD(prodSerial) Then  '' TD 정보 검색
            Return False
        End If

        If prodSerialDot(prodSerial) Then  '' 도트 정보 검색
            Return False
        End If

        If ckbopV1.Checked = True And modelCompare() <> "ALTO" And modelCompare() <> "NEMO" And modelCompare() <> "MAREUMMO" Then
            If v1BeforeHifu() Then
                Return False
            End If

            If v1BeforeRF() Then
                Return False
            End If
        Else
            If prodSerialHIFU() Then   '' hifu 테스트 결과 검색
                Return False
            End If
            If modelCompare() = "MAXIMUM" Or modelCompare() = "OYWON" Or modelCompare() = "WON" Then
                If prodSerialRF() Then   '' rf 테스트 결과 검색
                    Return False
                End If
            End If
        End If

        If prodSerialPD2(prodSerial) Then  '' 정보 입력 결과 검색
            Return False
        End If

        ReturnDataSearch()

        'saveCsvData(prodSerial)

        If lastQCDBReg(prodSerial) Then
            Return False
        Else
            If saveCsvData(prodSerial) Then
                Return False
            End If
        End If

        Return True
    End Function

    Private Sub ReturnDataSearch()
        DBCmd = "SELECT IFNULL(MAX(ReturnCount),'0') FROM " & ApplyReturnDB & " where Product_SN = '" & txbProdSerial.Text & "'"
        txbReCount.Text = DBQueryScalar(DBCmd)
    End Sub


    Private Function saveCsvData(prodSerial As String) As Boolean '엑셀 파일로 저장'
        Try
            If ckbExcel.Checked = True Then
                Dim strData As String = String.Empty
                Dim shotData As String = String.Empty
                Dim rowData(,) As String

                Dim saveYear As String = Format(Now, "yyyy")
                Dim saveMonth As String = Format(Now, "MM")
                Dim saveDay As String = Format(Now, "dd")
                Dim firstRowData As String = "순번,모델,샷,버전,PRO 최종무게,LUX 최종무게,MAX 최종무게,합격여부,셋트 S/N,페이스 카트리지 S/N,아이 카트리지 S/N,바디 카트리지 S/N,기타 S/N,상세설명" & vbLf

                If pd2ReadData(pd2DataList.pd2Face) = "0" And pd2ReadData(pd2DataList.pd2Eye) = "0" Then
                    shotData = "무제한"
                End If
                Dim saveRowData As String = pd2ReadData(pd2DataList.pd2Model) & "," & shotData & "," & hifuReadData(hifuDataList.hifuFW) & ",,,해당,합격," & cartSerial(prodTypeList.cartSet) & "," & cartSerial(prodTypeList.cartFace) & "," & cartSerial(prodTypeList.cartEye) & "," & cartSerial(prodTypeList.cartBody) & "," & cartSerial(prodTypeList.cartEtc) & "," & "" & vbLf

                Dim filePath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\SaveData"

                If Dir(filePath, vbDirectory) = "" Then
                    MkDir(filePath)
                End If

                Dim modelName As String = fileModelCompare()
                Dim typeName As String = fileTypeCompare()

                Dim colorName As String = fileColorCompare()

                Dim fileName As String = filePath & "\" & saveYear & "-" & saveMonth & "-" & saveDay & "(" & modelName & "_" & typeName & "_" & colorName & ")" & ".csv"

                If File.Exists(fileName) Then
                    strData = File.ReadAllText(fileName)
                    strData = Mid(strData, InStr(strData, vbLf) + 1, strData.Length)

                    If strData <> String.Empty Then
                        Dim rowCount As Integer = UBound(Split(strData, vbLf)) - 1
                        ReDim rowData(csvDataList.csvRefer, rowCount)

                        For i = 0 To rowCount
                            Dim rowLineData As String = Mid(strData, 1, InStr(strData, vbLf) - 1)
                            strData = Mid(strData, InStr(strData, vbLf) + 1, strData.Length)

                            rowLineData = Mid(rowLineData, InStr(rowLineData, ",") + 1, rowLineData.Length) & ","

                            For row = 0 To csvDataList.csvRefer
                                rowData(row, i) = Mid(rowLineData, 1, InStr(rowLineData, ",") - 1)
                                rowLineData = Mid(rowLineData, InStr(rowLineData, ",") + 1, rowLineData.Length)
                            Next
                        Next

                        Dim chkSerial As Int16 = 0

                        Select Case typeCompare()
                            Case "FACE"
                                chkSerial = csvDataList.csvFaceSr
                            Case "EYE"
                                chkSerial = csvDataList.csvEyeSr
                            Case "BODY"
                                chkSerial = csvDataList.csvBodySr
                            Case Else
                                chkSerial = csvDataList.csvSetSr
                        End Select

                        Dim delSwitch As Boolean = False

                        For chk = 0 To rowData.GetLength(1) - 1
                            If rowData(chkSerial, chk) = prodSerial Then
                                For del = 0 To csvDataList.csvRefer
                                    rowData(del, chk) = String.Empty
                                Next

                                delSwitch = True
                            End If
                        Next

                        If delSwitch = True Then
                            Dim nowRow As Integer = 0
                            For row = 0 To rowData.GetLength(1) - 1

                                If rowData(csvDataList.csvModel, row) <> String.Empty Then
                                    For csv = 0 To csvDataList.csvRefer
                                        rowData(csv, nowRow) = rowData(csv, row)
                                    Next

                                    nowRow += 1
                                End If
                            Next

                            ReDim Preserve rowData(csvDataList.csvRefer, nowRow - 1)
                        End If

                        Dim lastNum As Integer = 0
                        strData = String.Empty
                        For row = 0 To rowData.GetLength(1) - 1
                            lastNum = row + 1

                            For csv = 0 To csvDataList.csvRefer
                                If csv = csvDataList.csvRefer Then
                                    strData = strData & rowData(csv, row) & vbLf
                                Else
                                    If csv = csvDataList.csvModel Then

                                        strData = strData & lastNum & "," & rowData(csv, row) & ","
                                    Else
                                        strData = strData & rowData(csv, row) & ","
                                    End If
                                End If
                            Next
                        Next

                        lastNum += 1
                        strData = firstRowData & strData & lastNum & "," & saveRowData
                    Else
                        strData = firstRowData & "1," & saveRowData
                    End If

                Else
                    strData = firstRowData & "1," & saveRowData
                End If

                File.WriteAllText(fileName, strData, System.Text.Encoding.UTF8)

            End If

            Return False
        Catch ex As Exception
            MsgBox("csv 저장 오류 발생!! :: " & ex.Message, vbCritical)
            Return True
        End Try

    End Function

    Private Function fileTypeCompare() As String
        DBCmd = "SELECT CartTypeName FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & modelType & "' AND CartTypeCode = '" & searchType & "' LIMIT 1"

        If DBQueryReader(DBCmd) Then
            Return sqlDataQuery(0)
        Else
            Return "ETC"
        End If
    End Function

    Private Function fileModelCompare() As String
        DBCmd = "SELECT ModelName FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & modelType & "' LIMIT 1"

        If DBQueryReader(DBCmd) Then
            Return sqlDataQuery(0)
        Else
            Return "ETC"
        End If
    End Function

    Private Function fileColorCompare() As String
        DBCmd = "SELECT ColorName FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & modelType & "' AND CartTypeCode = '" & searchType & "' AND ColorCode = '" & colorType & "'"

        If DBQueryReader(DBCmd) Then
            Return sqlDataQuery(0)
        Else
            Return "ETC"
        End If
    End Function

    Private Function lastQCDBReg(prodSerial As String) As Boolean

        If ckbopTD.Checked = True Then
            If dataOkNg(dbRegList.dbTD) = False Then
                MsgBox("TD 정보 중 불량 데이터 존재", vbCritical)
                Return True
            End If
        End If

        If ckbopDot.Checked = True Then
            If dataOkNg(dbRegList.dbDot) = False Then
                MsgBox("DOT 정보 중 불량 데이터 존재", vbCritical)
                Return True
            End If
        End If

        If ckbopHifu.Checked = True Then
            If dataOkNg(dbRegList.dbHifu) = False Then
                MsgBox("HIFU 정보 중 불량 데이터 존재", vbCritical)
                Return True
            End If
        End If

        If ckbopWave.Checked = True Then
            If dataOkNg(dbRegList.dbWave) = False Then
                MsgBox("파형 정보 중 불량 데이터 존재", vbCritical)
                Return True
            End If
        End If

        If ckbopInfo.Checked = True Then
            If dataOkNg(dbRegList.dbInfo) = False Then
                MsgBox("정보입력 정보 중 불량 데이터 존재", vbCritical)
                Return True
            End If
        End If

        Dim regDate As String = Format(Now, "yyyy") & "-" & Format(Now, "MM") & "-" & Format(Now, "dd")
        Dim regTime As String = Format(Now, "HH") & ":" & Format(Now, "mm") & ":" & Format(Now, "ss")

        If TDUseCompare = True Then
            DBCmd = "UPDATE " & applyCartDB & " SET LastQC_Date = '" & regDate & "', LastQC_Time = '" & regTime & "' WHERE Product_SN = '" & prodSerial & "'"
        ElseIf LDMUseCompare = True Then
            DBCmd = "UPDATE " & ApplyLdmDB & " SET LastQC_Date = '" & regDate & "', LastQC_Time = '" & regTime & "' WHERE Product_SN = '" & prodSerial & "'"
        Else
            DBCmd = "UPDATE " & applyNonTDDB & " SET LastQC_Date = '" & regDate & "', LastQC_Time = '" & regTime & "' WHERE Product_SN = '" & prodSerial & "'"
        End If



        If DBCommand(DBCmd) Then
            dataOkNg(dbRegList.DBALL) = True
            Return False
        Else
            MsgBox("서버에 데이터 등록 중 오류가 발생하였습니다.", vbCritical)
            Return True
        End If
    End Function

    Private Function v1BeforeRF() As Boolean
        Dim table As String
        If LDMUseCompare Then
            table = ApplyLdmDB
        Else
            table = applyCartDB
        End If
        DBCmd = "SELECT CONVERT(P1_Date,CHAR),CONVERT(P1_Time,CHAR) FROM " & table & " WHERE PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"
        If DBQueryReader(DBCmd) Then
            txbRDate_M1.Text = sqlDataQuery(0)
            txbRTime_M1.Text = sqlDataQuery(1)
            txbRRF_M1.Text = "합격"
            txbRMC_M1.Text = "합격"
            txbREP_M1.Text = "합격"

            txbRDate_M1.BackColor = Color.Green
            txbRTime_M1.BackColor = Color.Green
            txbRRF_M1.BackColor = Color.Green
            txbRMC_M1.BackColor = Color.Green
            txbREP_M1.BackColor = Color.Green

            Return False
        Else
            GoTo DataFail
        End If

DataFail:
        For i = 0 To rfDataList.rfR2Vrms_txb3
            rfReadData(i) = "NULL"
            rfReadTxb(i).Text = rfReadData(i)
            rfReadTxb(i).BackColor = Color.Red
        Next
        Return True
    End Function

    Private Function prodSerialRF() As Boolean

        If RfEpOnlyCompare = True Then
            '' RF, MC 제외 EP 검사만 하는 경우
            DBCmd = "SELECT CONVERT(TestDate,CHAR),CONVERT(TestTime,CHAR),EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth FROM " & applyRFDB & " WHERE PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"

            If DBQueryReader(DBCmd) Then
                If sqlDataQuery.Length - 1 = 13 Then
                    rfReadData(0) = sqlDataQuery(0)
                    rfReadData(1) = sqlDataQuery(1)
                    For i = 2 To 7
                        rfReadData(i) = "NULL"
                    Next
                    For i = 0 To 11
                        rfReadData(rfDataList.epR1Vpp + i) = sqlDataQuery(2 + i)
                    Next
                    For i = 20 To 25
                        rfReadData(i) = "NULL"
                    Next

                    For i = 0 To rfDataList.rfR2Vrms_txb3
                        Dim oKNG As Boolean = False

                        Select Case i
                            Case rfDataList.rfR1Vrms_txb1
                                rfReadData(i) = "N/A"
                                oKNG = True
                            Case rfDataList.rfR1Freq_txb2
                                rfReadData(i) = "N/A"
                                oKNG = True
                            Case rfDataList.rfR2Vrms_txb3
                                If TDUseCompare = True Then
                                    If Val(rfReadData(rfDataList.epR1Vpp)) >= Val(txbopcs1_VpMin.Text) And Val(rfReadData(rfDataList.epR1Vpp)) <= Val(txbopcs1_VpMax.Text) Then
                                        If Val(rfReadData(rfDataList.epR1Freq)) >= Val(txbopcs1_FrMin.Text) And Val(rfReadData(rfDataList.epR1Freq)) <= Val(txbopcs1_FrMax.Text) Then
                                            Dim pnWidth As Single = Val(rfReadData(rfDataList.epR1PWidth)) - Val(rfReadData(rfDataList.epR1NWidth))
                                            If Abs(pnWidth) < Val(txbopcs1_DyRg.Text) Then
                                                If Val(rfReadData(rfDataList.epR2Vpp)) >= Val(txbopcs2_VpMin.Text) And Val(rfReadData(rfDataList.epR2Vpp)) <= Val(txbopcs2_VpMax.Text) Then
                                                    If Val(rfReadData(rfDataList.epR2Freq)) >= Val(txbopcs2_FrMin.Text) And Val(rfReadData(rfDataList.epR2Freq)) <= Val(txbopcs2_FrMax.Text) Then
                                                        pnWidth = Val(rfReadData(rfDataList.epR2PWidth)) - Val(rfReadData(rfDataList.epR2NWidth))
                                                        If Abs(pnWidth) < Val(txbopcs2_DyRg.Text) Then
                                                            If Val(rfReadData(rfDataList.epR3Vpp)) >= Val(txbopcs3_VpMin.Text) And Val(rfReadData(rfDataList.epR3Vpp)) <= Val(txbopcs3_VpMax.Text) Then
                                                                If Val(rfReadData(rfDataList.epR3Freq)) >= Val(txbopcs3_FrMin.Text) And Val(rfReadData(rfDataList.epR3Freq)) <= Val(txbopcs3_FrMax.Text) Then
                                                                    pnWidth = Val(rfReadData(rfDataList.epR3PWidth)) - Val(rfReadData(rfDataList.epR3NWidth))
                                                                    If Abs(pnWidth) < Val(txbopcs3_DyRg.Text) Then
                                                                        rfReadData(i) = "합격"
                                                                        oKNG = True
                                                                    Else
                                                                        rfReadData(i) = "불합격"
                                                                        dataOkNg(dbRegList.dbWave) = False
                                                                    End If
                                                                Else
                                                                    rfReadData(i) = "불합격"
                                                                    dataOkNg(dbRegList.dbWave) = False
                                                                End If
                                                            Else
                                                                rfReadData(i) = "불합격"
                                                                dataOkNg(dbRegList.dbWave) = False
                                                            End If
                                                        Else
                                                            rfReadData(i) = "불합격"
                                                            dataOkNg(dbRegList.dbWave) = False
                                                        End If
                                                    Else
                                                        rfReadData(i) = "불합격"
                                                        dataOkNg(dbRegList.dbWave) = False
                                                    End If
                                                Else
                                                    rfReadData(i) = "불합격"
                                                    dataOkNg(dbRegList.dbWave) = False
                                                End If
                                            Else
                                                rfReadData(i) = "불합격"
                                                dataOkNg(dbRegList.dbWave) = False
                                            End If
                                        Else
                                            rfReadData(i) = "불합격"
                                            dataOkNg(dbRegList.dbWave) = False
                                        End If
                                    Else
                                        rfReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbWave) = False
                                    End If
                                End If
                            Case Else
                                oKNG = True
                        End Select

                        dataResult(rfReadTxb(i), rfReadData(i), oKNG)
                    Next

                    Return False
                Else
                    GoTo FailData
                End If
            Else
                GoTo FailData
            End If

        Else
            '' RF + MC + EP 전체 검사
            DBCmd = "SELECT CONVERT(TestDate,CHAR),CONVERT(TestTime,CHAR),RF_R1Vrms,RF_R1Freq,RF_R2Vrms,RF_R2Freq,RF_R3Vrms,RF_R3Freq,EP_R1Vpp,EP_R1Freq,EP_R1PWidth,EP_R1NWidth,EP_R2Vpp,EP_R2Freq,EP_R2PWidth,EP_R2NWidth,EP_R3Vpp,EP_R3Freq,EP_R3PWidth,EP_R3NWidth,MC_R1Wave,MC_R1Vpp,MC_R1Freq,MC_R2Wave,MC_R2Vpp,MC_R2Freq FROM " & applyRFDB & " WHERE PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"

            If DBQueryReader(DBCmd) Then

                If rfDataList.mcR2Freq = sqlDataQuery.Length - 1 Then
                    For i = 0 To rfDataList.mcR2Freq
                        rfReadData(i) = sqlDataQuery(i)
                    Next

                    For i = 0 To rfDataList.rfR2Vrms_txb3
                        Dim oKNG As Boolean = False

                        If TDUseCompare = True Then

                            Select Case i
                                Case rfDataList.rfR1Vrms_txb1
                                    If Val(rfReadData(rfDataList.rfR1Vrms_txb1)) >= Val(txboptg1_VrMin.Text) And Val(rfReadData(rfDataList.rfR1Vrms_txb1)) <= Val(txboptg1_VrMax.Text) Then
                                        If Val(rfReadData(rfDataList.rfR1Freq_txb2)) >= Val(txboptg1_FrMin.Text) And Val(rfReadData(rfDataList.rfR1Freq_txb2)) <= Val(txboptg1_FrMax.Text) Then
                                            If Val(rfReadData(rfDataList.rfR2Vrms_txb3)) >= Val(txboptg2_VrMin.Text) And Val(rfReadData(rfDataList.rfR2Vrms_txb3)) <= Val(txboptg2_VrMax.Text) Then
                                                If Val(rfReadData(rfDataList.rfR2Freq)) >= Val(txboptg2_FrMin.Text) And Val(rfReadData(rfDataList.rfR2Freq)) <= Val(txboptg2_FrMax.Text) Then
                                                    If Val(rfReadData(rfDataList.rfR3Vrms)) >= Val(txboptg3_VrMin.Text) And Val(rfReadData(rfDataList.rfR3Vrms)) <= Val(txboptg3_VrMax.Text) Then
                                                        If Val(rfReadData(rfDataList.rfR3Freq)) >= Val(txboptg3_FrMin.Text) And Val(rfReadData(rfDataList.rfR3Freq)) <= Val(txboptg3_FrMax.Text) Then
                                                            rfReadData(i) = "합격"
                                                            oKNG = True
                                                        Else
                                                            rfReadData(i) = "불합격"
                                                            dataOkNg(dbRegList.dbWave) = False
                                                        End If
                                                    Else
                                                        rfReadData(i) = "불합격"
                                                        dataOkNg(dbRegList.dbWave) = False
                                                    End If
                                                Else
                                                    rfReadData(i) = "불합격"
                                                    dataOkNg(dbRegList.dbWave) = False
                                                End If
                                            Else
                                                rfReadData(i) = "불합격"
                                                dataOkNg(dbRegList.dbWave) = False
                                            End If
                                        Else
                                            rfReadData(i) = "불합격"
                                            dataOkNg(dbRegList.dbWave) = False
                                        End If
                                    Else
                                        rfReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbWave) = False
                                    End If
                                Case rfDataList.rfR1Freq_txb2

                                    If Val(rfReadData(rfDataList.mcR1Wave)) >= Val(txbopdy1_DtMin.Text) And Val(rfReadData(rfDataList.mcR1Wave)) <= Val(txbopdy1_DtMax.Text) Then
                                        If Val(rfReadData(rfDataList.mcR1Vpp)) >= Val(txbopdy1_VpMin.Text) And Val(rfReadData(rfDataList.mcR1Vpp)) <= Val(txbopdy1_VpMax.Text) Then
                                            If Val(rfReadData(rfDataList.mcR1Freq)) >= Val(txbopdy1_FrMin.Text) And Val(rfReadData(rfDataList.mcR1Freq)) <= Val(txbopdy1_FrMax.Text) Then
                                                If Val(rfReadData(rfDataList.mcR2Wave)) >= Val(txbopdy2_DtMin.Text) And Val(rfReadData(rfDataList.mcR2Wave)) <= Val(txbopdy2_DtMax.Text) Then
                                                    If Val(rfReadData(rfDataList.mcR2Vpp)) >= Val(txbopdy2_VpMin.Text) And Val(rfReadData(rfDataList.mcR2Vpp)) <= Val(txbopdy2_VpMax.Text) Then
                                                        If Val(rfReadData(rfDataList.mcR2Freq)) >= Val(txbopdy2_FrMin.Text) And Val(rfReadData(rfDataList.mcR2Freq)) <= Val(txbopdy2_FrMax.Text) Then
                                                            rfReadData(i) = "합격"
                                                            oKNG = True
                                                        Else
                                                            rfReadData(i) = "불합격"
                                                            dataOkNg(dbRegList.dbWave) = False
                                                        End If
                                                    Else
                                                        rfReadData(i) = "불합격"
                                                        dataOkNg(dbRegList.dbWave) = False
                                                    End If
                                                Else
                                                    rfReadData(i) = "불합격"
                                                    dataOkNg(dbRegList.dbWave) = False
                                                End If
                                            Else
                                                rfReadData(i) = "불합격"
                                                dataOkNg(dbRegList.dbWave) = False
                                            End If
                                        Else
                                            rfReadData(i) = "불합격"
                                            dataOkNg(dbRegList.dbWave) = False
                                        End If
                                    Else
                                        rfReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbWave) = False
                                    End If

                                Case rfDataList.rfR2Vrms_txb3

                                    If Val(rfReadData(rfDataList.epR1Vpp)) >= Val(txbopcs1_VpMin.Text) And Val(rfReadData(rfDataList.epR1Vpp)) <= Val(txbopcs1_VpMax.Text) Then
                                        If Val(rfReadData(rfDataList.epR1Freq)) >= Val(txbopcs1_FrMin.Text) And Val(rfReadData(rfDataList.epR1Freq)) <= Val(txbopcs1_FrMax.Text) Then
                                            Dim pnWidth As Single = Val(rfReadData(rfDataList.epR1PWidth)) - Val(rfReadData(rfDataList.epR1NWidth))
                                            If Abs(pnWidth) < Val(txbopcs1_DyRg.Text) Then
                                                If Val(rfReadData(rfDataList.epR2Vpp)) >= Val(txbopcs2_VpMin.Text) And Val(rfReadData(rfDataList.epR2Vpp)) <= Val(txbopcs2_VpMax.Text) Then
                                                    If Val(rfReadData(rfDataList.epR2Freq)) >= Val(txbopcs2_FrMin.Text) And Val(rfReadData(rfDataList.epR2Freq)) <= Val(txbopcs2_FrMax.Text) Then
                                                        pnWidth = Val(rfReadData(rfDataList.epR2PWidth)) - Val(rfReadData(rfDataList.epR2NWidth))
                                                        If Abs(pnWidth) < Val(txbopcs2_DyRg.Text) Then
                                                            If Val(rfReadData(rfDataList.epR3Vpp)) >= Val(txbopcs3_VpMin.Text) And Val(rfReadData(rfDataList.epR3Vpp)) <= Val(txbopcs3_VpMax.Text) Then
                                                                If Val(rfReadData(rfDataList.epR3Freq)) >= Val(txbopcs3_FrMin.Text) And Val(rfReadData(rfDataList.epR3Freq)) <= Val(txbopcs3_FrMax.Text) Then
                                                                    pnWidth = Val(rfReadData(rfDataList.epR3PWidth)) - Val(rfReadData(rfDataList.epR3NWidth))
                                                                    If Abs(pnWidth) < Val(txbopcs3_DyRg.Text) Then
                                                                        rfReadData(i) = "합격"
                                                                        oKNG = True
                                                                    Else
                                                                        rfReadData(i) = "불합격"
                                                                        dataOkNg(dbRegList.dbWave) = False
                                                                    End If
                                                                Else
                                                                    rfReadData(i) = "불합격"
                                                                    dataOkNg(dbRegList.dbWave) = False
                                                                End If
                                                            Else
                                                                rfReadData(i) = "불합격"
                                                                dataOkNg(dbRegList.dbWave) = False
                                                            End If
                                                        Else
                                                            rfReadData(i) = "불합격"
                                                            dataOkNg(dbRegList.dbWave) = False
                                                        End If
                                                    Else
                                                        rfReadData(i) = "불합격"
                                                        dataOkNg(dbRegList.dbWave) = False
                                                    End If
                                                Else
                                                    rfReadData(i) = "불합격"
                                                    dataOkNg(dbRegList.dbWave) = False
                                                End If
                                            Else
                                                rfReadData(i) = "불합격"
                                                dataOkNg(dbRegList.dbWave) = False
                                            End If
                                        Else
                                            rfReadData(i) = "불합격"
                                            dataOkNg(dbRegList.dbWave) = False
                                        End If
                                    Else
                                        rfReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbWave) = False
                                    End If

                                Case Else
                                    oKNG = True
                            End Select

                        Else

                            Select Case i
                                Case rfDataList.rfR1Vrms_txb1
                                    If Val(rfReadData(rfDataList.rfR1Vrms_txb1)) >= Val(txboptg1_VrMinAT.Text) And Val(rfReadData(rfDataList.rfR1Vrms_txb1)) <= Val(txboptg1_VrMaxAT.Text) Then
                                        If Val(rfReadData(rfDataList.rfR1Freq_txb2)) >= Val(txboptg1_FrMinAT.Text) And Val(rfReadData(rfDataList.rfR1Freq_txb2)) <= Val(txboptg1_FrMaxAT.Text) Then
                                            If Val(rfReadData(rfDataList.rfR2Vrms_txb3)) >= Val(txboptg2_VrMinAT.Text) And Val(rfReadData(rfDataList.rfR2Vrms_txb3)) <= Val(txboptg2_VrMaxAT.Text) Then
                                                If Val(rfReadData(rfDataList.rfR2Freq)) >= Val(txboptg2_FrMinAT.Text) And Val(rfReadData(rfDataList.rfR2Freq)) <= Val(txboptg2_FrMaxAT.Text) Then
                                                    If Val(rfReadData(rfDataList.rfR3Vrms)) >= Val(txboptg3_VrMinAT.Text) And Val(rfReadData(rfDataList.rfR3Vrms)) <= Val(txboptg3_VrMaxAT.Text) Then
                                                        If Val(rfReadData(rfDataList.rfR3Freq)) >= Val(txboptg3_FrMinAT.Text) And Val(rfReadData(rfDataList.rfR3Freq)) <= Val(txboptg3_FrMaxAT.Text) Then
                                                            rfReadData(i) = "합격"
                                                            oKNG = True
                                                        Else
                                                            rfReadData(i) = "불합격"
                                                            dataOkNg(dbRegList.dbWave) = False
                                                        End If
                                                    Else
                                                        rfReadData(i) = "불합격"
                                                        dataOkNg(dbRegList.dbWave) = False
                                                    End If
                                                Else
                                                    rfReadData(i) = "불합격"
                                                    dataOkNg(dbRegList.dbWave) = False
                                                End If
                                            Else
                                                rfReadData(i) = "불합격"
                                                dataOkNg(dbRegList.dbWave) = False
                                            End If
                                        Else
                                            rfReadData(i) = "불합격"
                                            dataOkNg(dbRegList.dbWave) = False
                                        End If
                                    Else
                                        rfReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbWave) = False
                                    End If
                                Case rfDataList.rfR1Freq_txb2

                                    rfReadData(i) = "NULL"
                                    oKNG = True

                                Case rfDataList.rfR2Vrms_txb3

                                    If Val(rfReadData(rfDataList.epR1Vpp)) >= Val(txbopcs1_VpMinAT.Text) And Val(rfReadData(rfDataList.epR1Vpp)) <= Val(txbopcs1_VpMaxAT.Text) Then
                                        If Val(rfReadData(rfDataList.epR1Freq)) >= Val(txbopcs1_FrMinAT.Text) And Val(rfReadData(rfDataList.epR1Freq)) <= Val(txbopcs1_FrMaxAT.Text) Then
                                            Dim pnWidth As Single = Val(rfReadData(rfDataList.epR1PWidth)) - Val(rfReadData(rfDataList.epR1NWidth))
                                            If Abs(pnWidth) < Val(txbopcs1_DyRgAT.Text) Then
                                                If Val(rfReadData(rfDataList.epR2Vpp)) >= Val(txbopcs2_VpMinAT.Text) And Val(rfReadData(rfDataList.epR2Vpp)) <= Val(txbopcs2_VpMaxAT.Text) Then
                                                    If Val(rfReadData(rfDataList.epR2Freq)) >= Val(txbopcs2_FrMinAT.Text) And Val(rfReadData(rfDataList.epR2Freq)) <= Val(txbopcs2_FrMaxAT.Text) Then
                                                        pnWidth = Val(rfReadData(rfDataList.epR2PWidth)) - Val(rfReadData(rfDataList.epR2NWidth))
                                                        If Abs(pnWidth) < Val(txbopcs2_DyRgAT.Text) Then
                                                            If Val(rfReadData(rfDataList.epR3Vpp)) >= Val(txbopcs3_VpMinAT.Text) And Val(rfReadData(rfDataList.epR3Vpp)) <= Val(txbopcs3_VpMaxAT.Text) Then
                                                                If Val(rfReadData(rfDataList.epR3Freq)) >= Val(txbopcs3_FrMinAT.Text) And Val(rfReadData(rfDataList.epR3Freq)) <= Val(txbopcs3_FrMaxAT.Text) Then
                                                                    pnWidth = Val(rfReadData(rfDataList.epR3PWidth)) - Val(rfReadData(rfDataList.epR3NWidth))
                                                                    If Abs(pnWidth) < Val(txbopcs3_DyRgAT.Text) Then
                                                                        rfReadData(i) = "합격"
                                                                        oKNG = True
                                                                    Else
                                                                        rfReadData(i) = "불합격"
                                                                        dataOkNg(dbRegList.dbWave) = False
                                                                    End If
                                                                Else
                                                                    rfReadData(i) = "불합격"
                                                                    dataOkNg(dbRegList.dbWave) = False
                                                                End If
                                                            Else
                                                                rfReadData(i) = "불합격"
                                                                dataOkNg(dbRegList.dbWave) = False
                                                            End If
                                                        Else
                                                            rfReadData(i) = "불합격"
                                                            dataOkNg(dbRegList.dbWave) = False
                                                        End If
                                                    Else
                                                        rfReadData(i) = "불합격"
                                                        dataOkNg(dbRegList.dbWave) = False
                                                    End If
                                                Else
                                                    rfReadData(i) = "불합격"
                                                    dataOkNg(dbRegList.dbWave) = False
                                                End If
                                            Else
                                                rfReadData(i) = "불합격"
                                                dataOkNg(dbRegList.dbWave) = False
                                            End If
                                        Else
                                            rfReadData(i) = "불합격"
                                            dataOkNg(dbRegList.dbWave) = False
                                        End If
                                    Else
                                        rfReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbWave) = False
                                    End If

                                Case Else
                                    oKNG = True
                            End Select

                        End If

                        dataResult(rfReadTxb(i), rfReadData(i), oKNG)
                    Next

                Else
                    GoTo FailData
                End If

                Return False
            Else
                GoTo FailData
            End If
        End If

FailData:
        For i = 0 To rfDataList.rfR2Vrms_txb3
            rfReadData(i) = "NULL"
            rfReadTxb(i).Text = rfReadData(i)
            rfReadTxb(i).BackColor = Color.Red
        Next

        Return True
    End Function

    Private Function v1BeforeHifu()
        Dim table As String
        If LDMUseCompare Then
            table = ApplyLdmDB
        Else
            table = applyCartDB
        End If

        DBCmd = "SELECT CONVERT(P1_Date,CHAR),CONVERT(P1_Time,CHAR),P1_Frequency FROM " & table & " WHERE PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"
        If DBQueryReader(DBCmd) Then
            txbHDate_M1.Text = sqlDataQuery(0)
            txbHTime_M1.Text = sqlDataQuery(1)
            txbHFreq_M1.Text = sqlDataQuery(2)
            hifuReadData(hifuDataList.hifuFreq) = sqlDataQuery(2)

            txbHFW_M1.Text = "1.0.9"
            hifuReadData(hifuDataList.hifuFW) = txbHFW_M1.Text

            txbHBettery_M1.Text = "합격"
            txbHCtemp_M1.Text = "합격"
            txbHDtemp_M1.Text = "합격"
            txbHHifu_M1.Text = "합격"

            txbHDate_M1.BackColor = Color.Green
            txbHTime_M1.BackColor = Color.Green
            txbHFreq_M1.BackColor = Color.Green
            txbHFW_M1.BackColor = Color.Green
            txbHBettery_M1.BackColor = Color.Green
            txbHCtemp_M1.BackColor = Color.Green
            txbHDtemp_M1.BackColor = Color.Green
            txbHHifu_M1.BackColor = Color.Green

            Return False
        Else
            GoTo DataFail
        End If

DataFail:
        For i = 0 To hifuDataList.hifuData1_txb
            hifuReadData(i) = "NULL"
            hifuReadTxb(i).Text = hifuReadData(i)
            hifuReadTxb(i).BackColor = Color.Red
        Next
        Return True

    End Function

    Private Function prodSerialHIFU() As Boolean
        Dim ForCnt As Int16
        If TDUseCompare = True Then
            DBCmd = "SELECT CONVERT(h.TestDate,CHAR),CONVERT(h.TestTime,CHAR),h.FW_Ver,h.BatteryLv,h.DivTemp,h.CtTemp,c.P1_Frequency,h.HF_R1Value,h.HF_R2Value,h.HF_R3Value FROM " & applyCartDB & " AS c INNER JOIN " & applyHIFUDB & " AS h ON c.PV_SN = h.PV_SN WHERE h.PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"
            If DBQueryReader(DBCmd) Then
                ForCnt = hifuDataList.hifuData1_txb
                If hifuDataList.hifuData3 = sqlDataQuery.Length - 1 Then
                    ReDim hifuReadData(sqlDataQuery.Length - 1)

                    For i = 0 To sqlDataQuery.Length - 1
                        hifuReadData(i) = sqlDataQuery(i)
                    Next
                Else
                    GoTo DataFail
                End If
            Else
                GoTo DataFail
            End If
        ElseIf LDMUseCompare = True Then
            DBCmd = "SELECT CONVERT(h.TestDate,CHAR),CONVERT(h.TestTime,CHAR),h.FW_Ver,h.BatteryLv,h.DivTemp,h.CtTemp,c.P1_Frequency,h.LDM_R1Value,h.LDM_R2Value,h.LDM_R3Value FROM " & ApplyLdmDB & " AS c INNER JOIN " & ApplyLdmHfDB & " AS h ON c.PV_SN = h.PV_SN WHERE h.PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"
            If DBQueryReader(DBCmd) Then
                ForCnt = hifuDataList.hifuData1_txb
                If hifuDataList.hifuData3 = sqlDataQuery.Length - 1 Then
                    ReDim hifuReadData(sqlDataQuery.Length - 1)

                    For i = 0 To sqlDataQuery.Length - 1
                        hifuReadData(i) = sqlDataQuery(i)
                    Next
                Else
                    GoTo DataFail
                End If
            Else
                GoTo DataFail
            End If
        Else
            DBCmd = "SELECT DATE_FORMAT(P1_DateTime,'%Y-%m-%d'),DATE_FORMAT(P1_DateTime,'%H:%i:%S'),Fw_Ver,BatteryLv,DivTemp,CtTemp FROM " & applyNonTDDB & " WHERE PV_SN = '" & tdReadData(tdDataList.TDSN) & "'"
            If DBQueryReader(DBCmd) Then
                ForCnt = hifuDataList.hifuCtemp
                If hifuDataList.hifuCtemp = sqlDataQuery.Length - 1 Then
                    ReDim hifuReadData(sqlDataQuery.Length - 1)
                    For i = 0 To sqlDataQuery.Length - 1
                        hifuReadData(i) = sqlDataQuery(i)
                    Next

                End If
            Else
                GoTo DataFail
            End If
        End If

        For i = 0 To ForCnt
            Dim OkNg As Boolean = False

            If TDUseCompare = True Or LDMUseCompare = True Then
                Select Case i
                    Case hifuDataList.hifuFW
                        If hifuReadData(i) = txbopFW.Text Then
                            OkNg = True
                        End If
                    Case hifuDataList.hifuBaterry
                        If Val(hifuReadData(i)) >= Val(txbopBat_RgMin.Text) And Val(hifuReadData(i)) <= Val(txbopBat_RgMax.Text) Then '' 배터리 상태 확인
                            hifuReadData(i) = "합격"
                            OkNg = True
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If
                    Case hifuDataList.hifuDtemp
                        If Val(hifuReadData(i)) >= Val(txbopDiv_TpMin.Text) And Val(hifuReadData(i)) <= Val(txbopDiv_TpMax.Text) Then '' 본체 온도 확인
                            hifuReadData(i) = "합격"
                            OkNg = True
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If
                    Case hifuDataList.hifuCtemp
                        If Val(hifuReadData(i)) >= Val(txbopCt_TpMin.Text) And Val(hifuReadData(i)) <= Val(txbopCt_TpMax.Text) Then '' 카트리지 온도 확인
                            hifuReadData(i) = "합격"
                            OkNg = True
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If

                    Case hifuDataList.hifuFreq
                        If Val(hifuReadData(i)) >= Val(txbOpFreq_RgMin.Text) And Val(hifuReadData(i)) <= Val(txbOpFreq_RgMax.Text) Then '' 주파수 확인
                            OkNg = True
                        End If

                    Case hifuDataList.hifuData1_txb

                        If Val(hifuReadData(i)) >= Val(txbopHF1_TpMin.Text) And Val(hifuReadData(i)) <= Val(txbopHF1_TpMax.Text) Then '' hifu 확인
                            If Val(hifuReadData(i + 1)) >= Val(txbopHF2_TpMin.Text) And Val(hifuReadData(i + 1)) <= Val(txbopHF2_TpMax.Text) Then
                                If Val(hifuReadData(i + 2)) >= Val(txbopHF3_TpMin.Text) And Val(hifuReadData(i + 2)) <= Val(txbopHF3_TpMax.Text) Then

                                    Dim hifuData12 As Single = Val(hifuReadData(i + 1)) - Val(hifuReadData(i))
                                    Dim hifuData23 As Single = Val(hifuReadData(i + 2)) - Val(hifuReadData(i + 1))

                                    If Abs(hifuData12) < Val(txbopHF12_Tp.Text) Then
                                        hifuReadData(i) = "합격"
                                        OkNg = True
                                    Else
                                        hifuReadData(i) = "불합격"
                                        dataOkNg(dbRegList.dbHifu) = False
                                    End If
                                Else
                                    hifuReadData(i) = "불합격"
                                    dataOkNg(dbRegList.dbHifu) = False
                                End If
                            Else
                                hifuReadData(i) = "불합격"
                                dataOkNg(dbRegList.dbHifu) = False
                            End If
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If
                    Case Else
                        OkNg = True
                End Select
            Else
                Select Case i
                    Case hifuDataList.hifuFW
                        If hifuReadData(i) = txbopFW_AT.Text Then
                            OkNg = True
                        End If
                    Case hifuDataList.hifuBaterry
                        If Val(hifuReadData(i)) >= Val(txbopBat_RgMinAT.Text) And Val(hifuReadData(i)) <= Val(txbopBat_RgMaxAT.Text) Then '' 배터리 상태 확인
                            hifuReadData(i) = "합격"
                            OkNg = True
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If
                    Case hifuDataList.hifuDtemp
                        If Val(hifuReadData(i)) >= Val(txbopDiv_TpMinAT.Text) And Val(hifuReadData(i)) <= Val(txbopDiv_TpMaxAT.Text) Then '' 본체 온도 확인
                            hifuReadData(i) = "합격"
                            OkNg = True
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If
                    Case hifuDataList.hifuCtemp
                        If Val(hifuReadData(i)) >= Val(txbopCt_TpMinAT.Text) And Val(hifuReadData(i)) <= Val(txbopCt_TpMaxAT.Text) Then '' 카트리지 온도 확인
                            hifuReadData(i) = "합격"
                            OkNg = True
                        Else
                            hifuReadData(i) = "불합격"
                            dataOkNg(dbRegList.dbHifu) = False
                        End If

                    Case Else
                        OkNg = True
                End Select
            End If

            dataResult(hifuReadTxb(i), hifuReadData(i), OkNg)
        Next

        Return False


DataFail:
        For i = 0 To hifuDataList.hifuData1_txb
            hifuReadData(i) = "NULL"
            hifuReadTxb(i).Text = hifuReadData(i)
            hifuReadTxb(i).BackColor = Color.Red
        Next
        Return True
    End Function

    Private Sub dataResult(setTextbox As TextBox, outData As String, OkNg As Boolean)
        If OkNg = True Then
            setTextbox.Text = outData
            setTextbox.BackColor = Color.Green
        Else
            setTextbox.Text = outData
            setTextbox.BackColor = Color.Red
        End If
    End Sub

    Private Function prodSerialPD2(prodSerial As String) As Boolean

        If TDUseCompare = True Then
            DBCmd = "SELECT CONVERT(P3_DateTime,CHAR), IFNULL(Manufacture_Date,'') as Manufacture_Date, Ct_SN,Ct_Manufacture_Name,Ct_Model,Ct_Type,Ct_Abroad,Ct_Agency,Ct_Max_ShotCnt,Ct_Remain_ShotCnt FROM " & applyCartDB & " WHERE Product_SN = '" & prodSerial & "'"
        ElseIf LDMUseCompare = True Then
            DBCmd = "SELECT CONVERT(P3_DateTime,CHAR), IFNULL(Manufacture_Date,'') as Manufacture_Date, Ct_SN,Ct_Manufacture_Name,Ct_Model,Ct_Type,Ct_Abroad,Ct_Agency,Ct_Max_ShotCnt,Ct_Remain_ShotCnt FROM " & ApplyLdmDB & " WHERE Product_SN = '" & prodSerial & "'"
        Else
            DBCmd = "SELECT CONVERT(P3_DateTime,CHAR), IFNULL(Manufacture_Date,'') as Manufacture_Date, Ct_SN,Ct_Manufacture_Name,Ct_Model,Ct_Type,Ct_Abroad,Ct_Agency FROM " & applyNonTDDB & " WHERE Product_SN = '" & prodSerial & "'"
        End If

        If DBQueryReader(DBCmd) Then

            For i = 0 To sqlDataQuery.Length - 1
                If sqlDataQuery(i).ToString <> "N" Then
                    pd2ReadData(i) = sqlDataQuery(i)
                    pd2ReadTxb(i).Text = pd2ReadData(i)
                    pd2ReadTxb(i).BackColor = Color.Green
                Else
                    If i = pd2DataList.prodDate Then
                        pd2ReadData(i) = "NULL"
                        pd2ReadTxb(i).Text = pd2ReadData(i)
                        pd2ReadTxb(i).BackColor = Color.Yellow  ' 노란색으로 표시
                        ' dataOkNg는 False로 설정하지 않음
                    Else
                        pd2ReadData(i) = "NULL"
                        pd2ReadTxb(i).Text = pd2ReadData(i)
                        pd2ReadTxb(i).BackColor = Color.Red
                        dataOkNg(dbRegList.dbInfo) = False  ' 다른 필드는 False로 설정
                    End If
                End If
            Next

            If pd2ReadData(pd2DataList.pd2Model) <> modelCompare() Then
                pd2ReadTxb(pd2DataList.pd2Model).BackColor = Color.Red
                dataOkNg(dbRegList.dbInfo) = False
            End If

            If pd2ReadData(pd2DataList.pd2Type) <> typeCompare() Then
                pd2ReadTxb(pd2DataList.pd2Type).BackColor = Color.Red
                dataOkNg(dbRegList.dbInfo) = False
            End If

            Return False
        Else
            For i = 0 To pd2DataList.pd2Max - 1
                If i = pd2DataList.prodDate Then
                    pd2ReadData(i) = "NULL"
                    pd2ReadTxb(i).Text = pd2ReadData(i)
                    pd2ReadTxb(i).BackColor = Color.Yellow  ' 노란색
                Else
                    pd2ReadData(i) = "NULL"
                    pd2ReadTxb(i).Text = pd2ReadData(i)
                    pd2ReadTxb(i).BackColor = Color.Red
                End If
            Next

            Return True
        End If
    End Function

    Private Function typeCompare() As String
        DBCmd = "SELECT CartTypeName FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & modelType & "' AND CartTypeCode = '" & searchType & "' LIMIT 1"

        If DBQueryReader(DBCmd) Then
            Return sqlDataQuery(0)
        Else
            Return "FAIL"
        End If
    End Function

    Private Function modelCompare() As String
        DBCmd = "SELECT ModelName FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & modelType & "' LIMIT 1"

        If DBQueryReader(DBCmd) Then
            Return sqlDataQuery(0)
        Else
            Return "FAIL"
        End If
    End Function

    Private Function prodSerialDot(prodSerial As String) As Boolean
        Dim table As String

        If LDMUseCompare Then
            table = ApplyLdmDB
        Else
            table = applyCartDB
        End If

        If TDUseCompare = True Or LDMUseCompare = True Then

            DBCmd = "SELECT CONVERT(P1_Date,CHAR),CONVERT(P1_Time,Char),Ct_Power,Ct_Motor_Lv FROM " & table & " WHERE Product_SN = '" & prodSerial & "'"

            If DBQueryReader(DBCmd) Then

                For i = 0 To dotDataList.dotDepth
                    If sqlDataQuery(i).ToString <> "N" Then
                        dotReadData(i) = sqlDataQuery(i)
                        dotReadTxb(i).Text = dotReadData(i)
                        dotReadTxb(i).BackColor = Color.Green
                    Else
                        dataOkNg(dbRegList.dbDot) = False
                        dotReadData(i) = "NULL"
                        dotReadTxb(i).Text = dotReadData(i)
                        dotReadTxb(i).BackColor = Color.Red
                    End If
                Next

                Return False
            Else
                For i = 0 To dotDataList.dotDepth
                    dotReadData(i) = "NULL"
                    dotReadTxb(i).Text = dotReadData(i)
                    dotReadTxb(i).BackColor = Color.Red
                Next

                Return True
            End If
        Else
            Return False
        End If

    End Function

    Private Function prodSerialTD(prodSerial As String) As Boolean
        If TDUseCompare = True Then
            DBCmd = "SELECT PV_SN,CONVERT(PV_Date,CHAR),CONVERT(QC_Date,CHAR),CONVERT(QC_Time,CHAR),QC_Grade FROM " & applyCartDB & " WHERE Product_SN = '" & prodSerial & "'"

            If DBQueryReader(DBCmd) Then
                For i = 0 To tdDataList.Grade
                    If sqlDataQuery(i).ToString <> "N" Then
                        tdReadData(i) = sqlDataQuery(i)
                        tdReadTxb(i).Text = tdReadData(i)
                        tdReadTxb(i).BackColor = Color.Green
                    Else
                        tdReadData(i) = "NULL"
                        tdReadTxb(i).Text = tdReadData(i)
                        tdReadTxb(i).BackColor = Color.Red
                        dataOkNg(dbRegList.dbTD) = False
                    End If
                Next

                Return False
            Else
                For i = 0 To tdDataList.Grade
                    tdReadData(i) = "NULL"
                    tdReadTxb(i).Text = tdReadData(i)
                    tdReadTxb(i).BackColor = Color.Red
                Next

                Return True
            End If

        ElseIf LDMUseCompare = True Then
            DBCmd = "SELECT PV_SN FROM " & ApplyLdmDB & " WHERE Product_SN = '" & prodSerial & "'"
            tdReadData(tdDataList.TDSN) = DBQueryScalar(DBCmd)

            If tdReadData(tdDataList.TDSN) = "False" Then
                MsgBox("Board 번호를 확인할 수 없습니다.", vbCritical)
                Return True
            End If

            For i = 0 To tdDataList.Grade
                If i <> tdDataList.TDSN Then
                    tdReadData(i) = "N/A"
                    tdReadTxb(i).Text = tdReadData(i)
                    tdReadTxb(i).BackColor = Color.Green
                Else
                    tdReadTxb(i).Text = tdReadData(i)
                    tdReadTxb(i).BackColor = Color.Green
                End If
            Next

            Return False

        Else
            DBCmd = "SELECT PV_SN FROM " & applyNonTDDB & " WHERE Product_SN = '" & prodSerial & "'"
            tdReadData(tdDataList.TDSN) = DBQueryScalar(DBCmd)

            If tdReadData(tdDataList.TDSN) = "False" Then
                MsgBox("Board 번호를 확인할 수 없습니다.", vbCritical)
                Return True
            End If

            For i = 0 To tdDataList.Grade
                If i <> tdDataList.TDSN Then
                    tdReadData(i) = "NULL"
                    tdReadTxb(i).Text = tdReadData(i)
                Else
                    tdReadTxb(i).Text = tdReadData(i)
                    tdReadTxb(i).BackColor = Color.Green
                End If
            Next

            Return False
        End If
    End Function

    Private Sub prodSerialType(prodSerial As String)
        If prodSerial.Length = oldProdLength Then       '12자리 시리얼번호
            modelType = Mid(prodSerial, 1, 1)
            searchType = Mid(prodSerial, 2, 1)
            colorType = Mid(prodSerial, 11, 1)
        ElseIf prodSerial.Length = newProdLength Then   '16자리 시리얼번호
            modelType = Mid(prodSerial, 1, 2)
            searchType = Mid(prodSerial, 15, 1)
            colorType = Mid(prodSerial, 3, 1)
        End If

        DBCmd = "SELECT DeviceTypeCode, TDUseYn ,LdmUseYn, LowPriceUseYn FROM " & ApplyModelInfoDB & " WHERE ModelCode = '" & modelType & "' LIMIT 1"

        If DBQueryReader(DBCmd) Then
            deviceType = sqlDataQuery(0)
            If sqlDataQuery(1) <> "Y" Then
                TDUseCompare = False
            Else
                TDUseCompare = True
            End If
            If sqlDataQuery(2) <> "Y" Then
                LDMUseCompare = False
            Else
                LDMUseCompare = True
            End If
            If sqlDataQuery(1) <> "Y" AndAlso sqlDataQuery(3) <> "Y" Then
                RfEpOnlyCompare = False
            Else
                RfEpOnlyCompare = True
            End If

        End If

        If typeCompare() <> "FACE" And typeCompare() <> "EYE" And typeCompare() <> "BODY" Then
            cartSerial(prodTypeList.cartSet) = prodSerial
        Else
            cartSerial(searchType) = prodSerial
        End If

    End Sub

    Private Function prodSerialExist(prodSerial As String) As Boolean
        If TDUseCompare = True Then
            DBCmd = "SELECT COUNT(PV_SN) FROM " & applyCartDB & " WHERE Product_SN = '" & prodSerial & "'"
        ElseIf LDMUseCompare = True Then
            DBCmd = "SELECT COUNT(PV_SN) FROM " & ApplyLdmDB & " WHERE Product_SN = '" & prodSerial & "'"
        Else
            DBCmd = "SELECT COUNT(PV_SN) FROM " & applyNonTDDB & " WHERE Product_SN = '" & prodSerial & "'"
        End If

        Dim sqlResult As String = DBQueryScalar(DBCmd)

        If sqlResult = "False" Then
            MsgBox("제품 시리얼 번호를 가져오는데에 오류가 발생하였습니다.", vbCritical)
            Return True
        End If

        If Val(sqlResult) > 0 Then
            Return False
        Else
            MsgBox("제품 시리얼 번호가 존재하지 않습니다." & vbCrLf & "정보 입력을 진행하여 주십시오.", vbExclamation)
            Return True
        End If
    End Function

    Private Sub btnExcel_Click(sender As Object, e As EventArgs) Handles btnExcel.Click
        Try

            If btnExcel.Text = "열 기" Then

                If cboCsvColor.SelectedIndex = -1 Or cboCsvProd.SelectedIndex = -1 Then
                    MsgBox("제품 및 색상 선택을 진행하지 않았습니다.", vbExclamation)
                    Exit Sub
                End If

                Dim modelText As String = cboCsvProd.SelectedItem
                Dim typeText As String = cboCsvType.SelectedItem
                Dim colorText As String = cboCsvColor.SelectedItem

                Dim openFile As String = System.AppDomain.CurrentDomain.BaseDirectory & "SaveData\" & Format(Now, "yyyy-MM-dd") & "(" & modelText & "_" & typeText & "_" & colorText & ")" & ".csv"
                Process.Start(openFile)

                pnCsv.Visible = False
                btnReset.Visible = True
                btnExcel.Text = "금일 Excel"

            Else
                cboCsvProd.SelectedIndex = -1
                cboCsvColor.SelectedIndex = -1
                cboCsvType.SelectedIndex = -1
                cboCsvProd.Text = "선택"
                cboCsvColor.Text = "선택"
                cboCsvType.Text = "선택"

                pnCsv.Visible = True
                btnReset.Visible = False
                btnExcel.Text = "열 기"
            End If

            txbProdSerial.Focus()

        Catch ex As Exception
            MsgBox("오류 발생!! : " & ex.Message, vbCritical)
            pnCsv.Visible = False
            btnReset.Visible = True
            btnExcel.Text = "금일 Excel"
        End Try
    End Sub

    Private Sub btnExcelSelect_Click(sender As Object, e As EventArgs) Handles btnExcelSelect.Click
        Try

            If btnExcelSelect.Text = "열 기" Then

                If cboCsvColor.SelectedIndex = -1 Or cboCsvProd.SelectedIndex = -1 Then
                    MsgBox("제품 및 색상 선택을 진행하지 않았습니다.", vbExclamation)
                    Exit Sub
                End If

                Dim modelText As String = cboCsvProd.SelectedItem
                Dim typeText As String = cboCsvType.SelectedItem
                Dim colorText As String = cboCsvColor.SelectedItem

                Dim openFile As String = System.AppDomain.CurrentDomain.BaseDirectory & "SaveData\" & Format(monthCal.SelectionStart, "yyyy-MM-dd") & "(" & modelText & "_" & typeText & "_" & colorText & ")" & ".csv"
                Process.Start(openFile)
                monthCal.Hide()

                CalTimer.Enabled = False
                btnExcel.Enabled = True

                pnCsv.Visible = False
                btnReset.Visible = True
                btnExcelSelect.Text = "날짜 선택 Excel"
            Else
                cboCsvProd.SelectedIndex = -1
                cboCsvColor.SelectedIndex = -1
                cboCsvType.SelectedIndex = -1
                cboCsvProd.Text = "선택"
                cboCsvColor.Text = "선택"
                cboCsvType.Text = "선택"

                monthCal.Show()
                monthCal.BringToFront()
                monthCal.SetDate(monthCal.TodayDate)
                monthCal.Refresh()

                monCalNum = String.Empty
                monCalTime = False

                btnExcel.Enabled = False
                CalTimer.Enabled = True
                pnCsv.Visible = True
                btnReset.Visible = False
                btnExcelSelect.Text = "열 기"
            End If

            txbProdSerial.Focus()
        Catch ex As Exception
            MsgBox("오류 발생!! : " & ex.Message, vbCritical)
        End Try
    End Sub

    Private Sub btnExcelExit_Click(sender As Object, e As EventArgs) Handles btnExcelExit.Click
        btnExcel.Enabled = True
        CalTimer.Enabled = False
        pnCsv.Visible = False
        btnReset.Visible = True
        monthCal.Hide()

        btnExcel.Text = "금일 Excel"
        btnExcelSelect.Text = "날짜 선택 Excel"

        txbProdSerial.Focus()
    End Sub

    Private Sub btnFuncRun_Click(sender As Object, e As EventArgs) Handles btnFuncRun.Click
        runningcomm()
    End Sub

    Private Sub runningcomm()
        Dim errStr As String = String.Empty

        If txbProdSerial.Text = String.Empty Then
            MsgBox("입력할 정보가 존재하지 않습니다. 데이터를 읽어주십시오,", vbExclamation)
            errStr = "정보없음"
            GoTo failFunc
        End If

        If txbProdSerial.Text.Length <> oldProdLength And txbProdSerial.Text.Length <> newProdLength Then
            MsgBox("잘못된 시리얼 번호를 입력하였습니다.", vbExclamation)
            errStr = "정보불량"
            GoTo failFunc
        End If

        If dataOkNg(dbRegList.DBALL) = True Then

            Select Case runMod
                Case formModList.Write
                    infoRegFunc()
                Case formModList.Delete
                    infoDelFunc()
                Case formModList.ReturnP
                    infoReturnFunc()
                Case Else
                    MsgBox("올바른 경로의 동작이 아닙니다.", vbCritical)
                    errStr = "시스템오류"
                    GoTo failFunc
            End Select

            GoTo finishFunc
        Else
            If runMod = formModList.Delete Then
                infoDelFunc()
            Else
                MsgBox("출력된 데이터 중 불량 데이터가 존재합니다. 데이터를 확인하여 주십시오.", vbExclamation)
                errStr = "데이터불량"
                GoTo failFunc
            End If
        End If
failFunc:
        txbRunState.Text = errStr
        txbRunState.BackColor = Color.Red
finishFunc:
        txbRunState.Refresh()
        txbProdSerial.Focus()
    End Sub

    Private Sub infoReturnFunc()
        Dim OkNg As Boolean = False
        Dim ReturnCount As String = 0
        Dim UseDBName As String = String.Empty

        txbRunState.Text = "처리중.."
        txbRunState.BackColor = Color.Orange
        txbRunState.Refresh()

        If TDUseCompare = True Then
            UseDBName = applyCartDB
        ElseIf LDMUseCompare = True Then
            UseDBName = ApplyLdmDB
        Else
            UseDBName = applyNonTDDB
        End If

        DBCmd = "SELECT TestStep FROM " & UseDBName & " WHERE Product_SN = '" & txbProdSerial.Text & "'"

        Dim TestStep As String = DBQueryScalar(DBCmd)

        If TestStep = "31" Then

            DBCmd = "SELECT EXISTS (SELECT 1 FROM " & ApplyReturnDB & " WHERE Product_SN = '" & txbProdSerial.Text & "') AS dataExist"
            Dim DataExist As String = DBQueryScalar(DBCmd)

            If DataExist = True Then
                DBCmd = "SELECT MAX(ReturnCount) FROM " & ApplyReturnDB & " WHERE Product_SN = '" & txbProdSerial.Text & "'"

                ReturnCount = DBQueryScalar(DBCmd)

                If ReturnCount = "False" Then
                    MsgBox("반품 처리 도중 오류가 발생하였습니다.", vbCritical)
                    GoTo FailResult
                    Exit Sub
                End If

            End If

            ReturnCount += 1
            Dim NowDate As String = Format(Now, "yyyy-MM-dd")
            Dim NowTime As String = Format(Now, "HH:mm:ss")

            DBCmd = "UPDATE " & UseDBName & " SET TestStep = '41' WHERE Product_SN = '" & txbProdSerial.Text & "'"

            If DBCommand(DBCmd) Then

                DBCmd = "INSERT INTO " & ApplyReturnDB & "(Product_SN,ReturnCount,ReturnDate,ReturnTime) VALUES('" & txbProdSerial.Text & "','" & ReturnCount & "','" & NowDate & "','" & NowTime & "')"

                If DBCommand(DBCmd) Then

                    txbRunState.Text = "처리완료"
                    txbRunState.BackColor = Color.Green
                    txbRunState.Refresh()
                    OkNg = True

                Else
                    MsgBox("데이터베이스에 Log 등록하는데 오류가 발생하였습니다", vbCritical)
                    GoTo FailResult
                End If

            Else
                MsgBox("데이터베이스에 등록하는데 오류가 발생하였습니다", vbCritical)
                GoTo FailResult

            End If

            Dim csvSaveData As String = NowDate & "," & NowTime & "," & txbProdSerial.Text & "," & txbTDSN.Text & "," &
                    txbHFreq_M1.Text & "," & txbDotPower_M1.Text & "," & txbDotDepth_M1.Text & "," & ReturnCount & "," & OkNg

            If Save_LogCsv(csvSaveData) Then
                MsgBox("CSV를 저장하는데 오류가 발생하였습니다", vbCritical)
                GoTo FailResult
            End If

        Else

            If TestStep = "41" Then
                MsgBox("이미 반품 처리를 진행하였습니다.", vbCritical)
                GoTo FailResult
            Else
                MsgBox("정보 입력을 진행하지 않았습니다.", vbCritical)
                GoTo FailResult
            End If

        End If

        Exit Sub

FailResult:
        txbRunState.Text = "처리실패"
        txbRunState.BackColor = Color.Red
        txbRunState.Refresh()
    End Sub

    Private Sub infoDelFunc()
        Dim OkNg As Boolean = False
        prodSerialType(txbProdSerial.Text)

        txbRunState.Text = "삭제중.."
        txbRunState.BackColor = Color.Orange
        txbRunState.Refresh()

        If TDUseCompare = True Then
            DBCmd = "UPDATE " & applyCartDB & " SET TestStep = '32' ,Product_SN = NULL WHERE Product_SN = '" & txbProdSerial.Text & "'"
        ElseIf LDMUseCompare = True Then
            DBCmd = "UPDATE " & ApplyLdmDB & " SET TestStep = '32' ,Product_SN = NULL WHERE Product_SN = '" & txbProdSerial.Text & "'"
        Else
            DBCmd = "UPDATE " & applyNonTDDB & " SET TestStep = '32' ,Product_SN = NULL WHERE Product_SN = '" & txbProdSerial.Text & "'"
        End If

        If DBCommand(DBCmd) Then
            txbRunState.Text = "삭제완료"
            txbRunState.BackColor = Color.Green
            txbRunState.Refresh()
            OkNg = True
        Else
            txbRunState.Text = "삭제실패"
            txbRunState.BackColor = Color.Red
            txbRunState.Refresh()
            MsgBox("데이터베이스를 설정하는데 오류가 발생하였습니다", vbCritical)
        End If

        Dim csvSaveData As String = Format(Now, "yyyy-MM-dd") & "," & Format(Now, "HH:mm:ss") & "," & txbProdSerial.Text & "," & txbTDSN.Text & "," &
                txbHFreq_M1.Text & "," & txbDotPower_M1.Text & "," & txbDotDepth_M1.Text & "," & OkNg

        If Save_LogCsv(csvSaveData) Then
            txbRunState.Text = "CSV실패"
            txbRunState.BackColor = Color.Red
        End If
    End Sub

    Private Sub infoRegFunc()
        Dim errorStr As String = String.Empty
        Dim OkNg As Boolean = False
        CsvRegData = String.Empty

        txbRunState.Text = "입력중.."
        txbRunState.BackColor = Color.Orange
        txbRunState.Refresh()

        Dim prodCode As String = Mid(txbProdSerial.Text, 1, 2)
        Dim prodDate As String = Mid(txbProdSerial.Text, 3, 4)
        Dim prodBack As String = Mid(txbProdSerial.Text, 7, 3)
        Dim prodFront As String = Mid(txbProdSerial.Text, 10, 3)

        If prodRegData(txbFactory_M1.Text.ToLower, prodDate & prodFront & prodBack, prodCode, Val(txbCountry_M1.Text), Val(txbAgency_M1.Text)) Then
            If prodRegFreq(Val(txbHFreq_M1.Text), Val(txbDotPower_M1.Text)) Then ''입력주파수 및 파워
                If prodRegTD(txbTDSN.Text) Then
                    If prodRegMotor(Val(txbDotDepth_M1.Text)) Then ''모터
                        If prodRegShot(Val(txbFace_M1.Text)) Then ''페이스샷
                            GoTo successFunc
                        Else
                            errorStr = "샷실패"
                            GoTo failFunc
                        End If
                    Else
                        errorStr = "모터실패"
                        GoTo failFunc
                    End If
                Else
                    errorStr = "TD실패"
                    GoTo failFunc
                End If
            Else
                errorStr = "주파수실패"
                GoTo failFunc
            End If
        Else
            errorStr = "코드실패"
            GoTo failFunc
        End If

successFunc:
        txbRunState.Text = "입력완료"
        txbRunState.BackColor = Color.Green
        OkNg = True
        GoTo finishFunc
failFunc:
        txbRunState.Text = errorStr
        txbRunState.BackColor = Color.Red
        GoTo finishFunc
finishFunc:
        Dim csvSaveData As String = Format(Now, "yyyy-MM-dd") & "," & Format(Now, "HH:mm:ss") & "," & txbProdSerial.Text & "," & txbTDSN.Text & "," &
            txbHFreq_M1.Text & "," & txbDotPower_M1.Text & "," & txbDotDepth_M1.Text & "," & CsvRegData & OkNg

        If Save_LogCsv(csvSaveData) Then
            txbRunState.Text = "CSV에러"
            txbRunState.BackColor = Color.Red
        End If

    End Sub

    Private Function prodRegShot(shot As Integer) As String
        Dim retval As String
        tmpCmdMessage = "shotconf"
        cmdMessage = "[" & tmpCmdMessage & " " & shot & "]" + vbCrLf
        CsvRegData = CsvRegData & cmdMessage.Replace(",", "/").Replace(vbCrLf, "") & ","
        If SendData(cmdMessage) Then
            Return False
        End If

        retval = PollingReceiveData(1000)
        CsvRegData = CsvRegData & retval.Replace(",", "/").Replace(vbCrLf, "") & ","
        If retval = shot Then
            Return True
        End If

        Return False

    End Function

    Private Function prodRegMotor(pulse As Integer) As Boolean
        Dim retval As String

        tmpCmdMessage = "setmotor"
        cmdMessage = "[" & tmpCmdMessage & " " & pulse & ",0,0,0,0]"
        CsvRegData = CsvRegData & cmdMessage.Replace(",", "/").Replace(vbCrLf, "") & ","

        If SendData(cmdMessage) Then
            Return False
        End If

        retval = PollingReceiveData(1000)
        CsvRegData = CsvRegData & retval.Replace(",", "/").Replace(vbCrLf, "") & ","

        If retval = pulse & ",0,0,0,0" Then
            Return True
        End If

        Return False
    End Function

    Private Function prodRegTD(td_reg_serial As String) As Boolean
        Dim retval As String
        tmpCmdMessage = "settdsn"
        cmdMessage = "[" & tmpCmdMessage & " " & td_reg_serial & "]" + vbCrLf
        CsvRegData = CsvRegData & cmdMessage.Replace(",", "/").Replace(vbCrLf, "") & ","
        If SendData(cmdMessage) Then
            Return False
        End If

        retval = PollingReceiveData(1500)
        CsvRegData = CsvRegData & retval.Replace(",", "/").Replace(vbCrLf, "") & ","

        If retval <> td_reg_serial.ToLower Then
            Return False
        End If

        Return True

    End Function

    Private Function prodRegFreq(freq As Int16, power As Int16) As Boolean
        Dim retVal As String
        tmpCmdMessage = "settdcnf"
        cmdMessage = "[" & tmpCmdMessage & " " & freq & "," & power & "]" + vbCrLf
        CsvRegData = CsvRegData & cmdMessage.Replace(",", "/").Replace(vbCrLf, "") & ","
        If SendData(cmdMessage) Then
            Return False
        End If

        retVal = PollingReceiveData(1000)
        CsvRegData = CsvRegData & retVal.Replace(",", "/").Replace(vbCrLf, "") & ","

        If retVal <> freq & "," & power Then
            Return False
        End If
        Return True
    End Function

    Private Function prodRegData(factory As String, prodSerial As String, prodCode As String, country As String, aboard As String) As Boolean
        tmpCmdMessage = "wrsconf1"
        cmdMessage = "[" & tmpCmdMessage & " " & factory & "," & prodSerial & "," & prodCode & "," & country & "," & aboard & "]" + vbCrLf
        CsvRegData = CsvRegData & cmdMessage.Replace(",", "/").Replace(vbCrLf, "") & ","
        If SendData(cmdMessage) Then
            Return False
        End If

        Dim retVal As String = PollingReceiveData(10000)
        CsvRegData = CsvRegData & retVal.Replace(",", "/").Replace(vbCrLf, "") & ","

        Dim dataComma As Int16 = UBound(Split(retVal, ","))

        If dataComma = 4 Then

            If retVal <> factory.ToLower & "," & prodSerial & "," & prodCode & "," & country & "," & aboard Then
                Return False
            End If

            Return True
        Else
            Return False
        End If
    End Function

    Private Function PollingReceiveData(RdTimeout As Long) As String
        Try
            If cmdSerial.IsOpen = True Then
                rxMessage = ""
                cmdSerial.ReadTimeout = RdTimeout
                rxMessage = cmdSerial.ReadLine()
                Return ParsingData(False)
            Else
                MsgBox("통신 포트가 열리지 않았습니다.", vbExclamation)
                Return True
            End If
        Catch ex As Exception
            rxMessage = ""
            Return Err.Description
        End Try
    End Function

    Private Function ParsingData(CmdInclude As Boolean) As String
        Dim cmdStr As String
        Dim cmdVal(0 To 6) As String
        Dim ReturnStr As String
        Dim i As Integer

        Try
            cmdStr = "0"

            If rxMessage <> "" Then
                cmdMessage = ""

                If Mid(rxMessage, 1, 1) = "[" Then
                    cmdMessage = Mid(rxMessage, 2, Len(rxMessage))

                    cmdStr = Mid(cmdMessage, 1, (InStr(rxMessage, " ") - 2))
                    cmdMessage = Mid(rxMessage, InStr(rxMessage, " ") + 1, Len(cmdMessage))

                    For i = 1 To 5
                        If InStr(cmdMessage, ",") <> 0 Then
                            cmdVal(i) = Mid(cmdMessage, 1, InStr(cmdMessage, ",") - 1)
                            cmdMessage = Mid(cmdMessage, InStr(cmdMessage, ",") + 1, Len(cmdMessage))
                        ElseIf InStr(cmdMessage, "]") <> 0 Then
                            cmdVal(i) = Mid(cmdMessage, 1, InStr(cmdMessage, "]") - 1)
                            'cmdMessage = Mid(cmdMessage, InStr(cmdMessage, "]") + 1, Len(cmdMessage))
                        Else
                            Exit For
                        End If
                    Next i
                    rxMessage = ""

                    If CmdInclude = True Then
                        ReturnStr = cmdStr & ","
                    End If

                    If InStr(1, cmdStr, "move") > 0 Then
                        cmdStr = "runmotor"
                    End If

                    Select Case cmdStr

                        Case "freqconf"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "settdcnf"
                            cmdStr = (cmdVal(1) & "," & cmdVal(2))
                            Return cmdStr
                        Case "wrsconf1"
                            cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5)
                            Return cmdStr
                        Case "settdsn"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "resetinf"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "rdsconf1"
                            cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5)
                            Return cmdStr
                        Case "shotconf"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "runmotor"
                            Return True
                        Case "setdepth"
                            cmdStr = cmdVal(1)
                            Return cmdStr
                        Case "setmotor"
                            cmdStr = cmdVal(1) & "," & cmdVal(2) & "," & cmdVal(3) & "," & cmdVal(4) & "," & cmdVal(5)
                            Return cmdStr
                        Case Else
                            Return "Else"
                            rxMessage = ""
                    End Select
                End If
                rxMessage = ""
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            rxMessage = ""
            Return Err.Description
        End Try
    End Function

    Private Function SendData(SendMessage As String) As Boolean
        Try
            If cmdSerial.IsOpen = True Then
                cmdSerial.DiscardInBuffer()
                cmdSerial.DiscardOutBuffer()
                If cmdSerial.BytesToRead Then
                    cmdSerial.DiscardInBuffer()
                End If
                cmdSerial.WriteTimeout = 50
                cmdSerial.WriteLine(SendMessage)
            Else
                MsgBox("통신 포트가 열리지 않았습니다.", vbExclamation)
                Return True
            End If
        Catch ex As Exception
            MsgBox("통신 포트 에러!! :: " & ex.Message, vbCritical)
            Return True
        End Try
        Return False
    End Function

    Private Sub btnEnd_Click(sender As Object, e As EventArgs) Handles btnEnd.Click
        threadOff()
        End
    End Sub

    Private Sub nowTimer_Tick(sender As Object, e As EventArgs) Handles nowTimer.Tick
        lblTime.Text = Now
    End Sub

    Private Sub ckbBarcode_CheckedChanged(sender As Object, e As EventArgs) Handles ckbBarcode.CheckedChanged
        If ckbBarcode.Checked = True Then
            txbProdSerial.Location = New Point(670, 20)
            lbProdSerial.Location = New Point(280, 18)
            btnSearch.Visible = False
            ckbAuto.Enabled = True
            ckbAuto.Checked = True
        Else
            txbProdSerial.Location = New Point(565, 20)
            lbProdSerial.Location = New Point(175, 18)
            btnSearch.Visible = True
            ckbAuto.Enabled = False
            ckbAuto.Checked = False
        End If
    End Sub

    Private Sub rdbSearch_CheckedChanged(sender As Object, e As EventArgs) Handles rdbSearch.CheckedChanged
        runMod = formModList.Search
        If rdbSearch.Checked = True Then
            modFormChange()
        End If
    End Sub

    Private Sub rdbWrite_CheckedChanged(sender As Object, e As EventArgs) Handles rdbWrite.CheckedChanged
        runMod = formModList.Write
        If rdbWrite.Checked = True Then
            modFormChange()
        End If
    End Sub

    Private Sub rdbDelete_CheckedChanged(sender As Object, e As EventArgs) Handles rdbDelete.CheckedChanged
        runMod = formModList.Delete
        If rdbDelete.Checked = True Then
            modFormChange()
        End If
    End Sub

    Private Sub rdbReturn_CheckedChanged(sender As Object, e As EventArgs) Handles rdbReturn.CheckedChanged
        runMod = formModList.ReturnP
        If rdbReturn.Checked = True Then
            modFormChange()
        End If
    End Sub

    Private Sub btnOpEnd_Click(sender As Object, e As EventArgs) Handles btnOpEnd.Click, btnOpEndAT.Click
        pnMain.Location = New Point(0, 0)
        pnStandard.Visible = False
        pnMain.Visible = True
        pnStandard.Location = New Point(1920, 0)
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click, btnSaveAT.Click
        configSave()
    End Sub

    Private Sub configSave()
        Try
            Dim filePath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\Config"

            If Dir(filePath, vbDirectory) = "" Then
                MkDir(filePath)
            End If

            Dim fileName As String = filePath & "\Standard_" & comboBoxModel.SelectedItem.ToString.Replace(" ", "") & ".ini"

            Dim saveData As String = String.Empty

            For i = 0 To saveDataList.opcs3VpMin_AT
                If saveData = String.Empty Then
                    saveData = saveTextData(i).Text
                Else
                    saveData = saveData & "^" & saveTextData(i).Text
                End If
            Next

            Dim dbRegStr As String = dbRegCheck()
            saveData = saveData & "^" & dbRegStr

            If File.Exists(fileName) Then
                File.Delete(fileName)
            End If

            File.WriteAllText(fileName, saveData, System.Text.Encoding.UTF8)

            MsgBox("저장완료!", vbInformation)
        Catch ex As Exception
            MsgBox("Config 파일 저장 오류 !! : " & ex.Message)
        End Try

    End Sub

    Private Function dbRegCheck() As String
        Dim dbRegStr As String = String.Empty

        For i = 0 To dbRegList.dbInfo
            If saveDBCkb(i).Checked = True Then
                dbRegStr = dbRegStr & i
            End If
        Next

        If ckbopV1.Checked = True And modelCompare() <> "ALTO" Then
            dbRegStr = dbRegStr & "5"
        End If

        Return dbRegStr

    End Function

    Private Sub configLoad()
        Try
            Dim filePath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\Config"

            If Dir(filePath, vbDirectory) = "" Then
                MkDir(filePath)
            End If

            Dim fileName As String = filePath & "\Standard_" & comboBoxModel.SelectedItem.ToString.Replace(" ", "") & ".ini"

            If File.Exists(fileName) Then
                Dim readData As String = File.ReadAllText(fileName, System.Text.Encoding.UTF8)

                If readData = String.Empty Then
                    optionAllReset()
                Else
                    If UBound(Split(readData, "^")) = saveDataList.opcs3VpMin_AT + 1 Then
                        For i = 0 To saveDataList.opcs3VpMin_AT
                            Dim psData As String = String.Empty
                            If InStr(readData, "^") > 0 Then
                                psData = Mid(readData, 1, InStr(readData, "^") - 1)
                                readData = Mid(readData, InStr(readData, "^") + 1, readData.Length)
                            Else
                                MsgBox("불량 데이터가 존재합니다." & vbCrLf & "합격기준 데이터 개수가 맞지 않습니다. 초기화 후 저장을 진행하여 주십시오.", vbCritical)
                                optionAllReset()
                                Exit For
                            End If

                            saveTextData(i).Text = psData
                        Next

                        dbCheckSetting(readData)

                    Else
                        MsgBox("불량 데이터가 존재합니다." & vbCrLf & "합격기준 데이터 개수가 맞지 않습니다. 초기화 후 저장을 진행하여 주십시오.", vbCritical)
                        optionAllReset()
                    End If
                End If
            Else
                optionAllReset()
            End If
        Catch ex As Exception
            MsgBox("Config 파일 로드 오류 !! : " & ex.Message)
        End Try

    End Sub

    Private Sub dbCheckSetting(ckbData As String)

        If IsNumeric(ckbData) Then
            For i = 0 To ckbData.Length - 1
                Dim selectData As Int16
                If i = ckbData Then
                    selectData = ckbData
                Else
                    selectData = Val(Mid(ckbData, 1, 1))
                    ckbData = Mid(ckbData, 2, ckbData.Length)
                End If

                If selectData = "5" Then
                    ckbopV1.Checked = True
                Else
                    saveDBCkb(selectData).Checked = True
                End If
            Next
        Else
            MsgBox("잘못된 체크 박스 데이터가 존재합니다.", vbCritical)
        End If
    End Sub

    Private Function Save_LogCsv(SaveData As String) As Boolean  ''saveType true : 입력 / false : 삭제
        On Error GoTo WR_File_Error
        Dim objWriter As StreamWriter
        Dim FileName As String

        Dim syaer As String = DateAndTime.Year(Now)
        Dim smonth As String = DateAndTime.Month(Now)
        Dim sday As String = DateAndTime.Day(Now)

        Dim FilePath As String = System.AppDomain.CurrentDomain.BaseDirectory & "\LogData"

        If Dir(FilePath, vbDirectory) = "" Then
            MkDir(FilePath)
        End If

        Select Case runMod
            Case formModList.Write
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_Reg_LogDate.csv"
            Case formModList.Delete
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_Del_LogDate.csv"
            Case formModList.ReturnP
                FileName = FilePath & "\" & DateAndTime.Year(Now) & "_" & DateAndTime.Month(Now) & "_" & DateAndTime.Day(Now) & "_Return_LogDate.csv"
            Case Else
                MsgBox("잘못된 경로 입니다.", vbCritical)
                Return True
        End Select

        If File.Exists(FileName) = True Then
            objWriter = New StreamWriter(FileName, True)
            objWriter.WriteLine(SaveData)
        Else
            objWriter = New StreamWriter(FileName, True)
            objWriter.WriteLine(itemList)
            objWriter.WriteLine(SaveData)
        End If

        objWriter.Close()

        Return False

WR_File_Error:
        MsgBox("Logdata save fail!" & Err.Description, vbCritical)
        Return True

    End Function

    Private Sub modFormChange()
        Select Case runMod
            Case formModList.Search
                btnFuncRun.Text = "쓰  기"
                btnFuncRun.Enabled = False
                ckbAutoReg.Enabled = False
                txbRunState.Enabled = False
                ckbAutoReg.Checked = False

            Case formModList.Write
                btnFuncRun.Text = "쓰  기"
                btnFuncRun.Enabled = True
                ckbAutoReg.Enabled = True
                txbRunState.Enabled = True

                btnReturn.Visible = False
                btnReturn.Enabled = False

                itemList = "InputDate,InputTime,ProdSerial,TDSerial,Frequence,Power,Depth,ProdData(Send),ProdData(Receive),ProdFreq(Send),ProdFreq(Receive),ProdTD(Send),ProdTD(Receive),ProdMotor(Send),ProdMotor(Receive),ProdShot(Send),ProdShot(Receive),OkNg"
            Case formModList.Delete
                btnFuncRun.Text = "삭  제"
                btnFuncRun.Enabled = True
                ckbAutoReg.Enabled = True
                txbRunState.Enabled = True

                itemList = "DelDate,DelTime,ProdSerial,TDSerial,Frequence,Power,Depth,OkNg"
            Case formModList.ReturnP
                btnFuncRun.Text = "처  리"
                btnFuncRun.Enabled = True
                ckbAutoReg.Enabled = True
                txbRunState.Enabled = True

                itemList = "ReDate,ReTime,ProdSerial,TDSerial,Frequence,Power,Depth,ReturnCount,OkNg"
            Case Else
                MsgBox("잘못된 경로입니다.")
        End Select
        formFullReset()
        txbProdSerial.Focus()
    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        formFullReset()
        txbProdSerial.Focus()
    End Sub

    Private Sub txbopFW_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txbopFW.KeyPress, txbOpFreq_RgMax.KeyPress, txbOpFreq_RgMin.KeyPress, txbopBat_RgMax.KeyPress, txbopBat_RgMin.KeyPress, txbopDiv_TpMax.KeyPress, txbopDiv_TpMin.KeyPress, txbopCt_TpMax.KeyPress, txbopCt_TpMin.KeyPress, txbopHF1_TpMax.KeyPress, txbopHF1_TpMin.KeyPress, txbopHF2_TpMax.KeyPress, txbopHF2_TpMin.KeyPress, txbopHF3_TpMax.KeyPress, txbopHF3_TpMin.KeyPress, txbopHF12_Tp.KeyPress, txbopHF23_Tp.KeyPress, txboptg1_FrMax.KeyPress, txboptg1_FrMin.KeyPress, txboptg1_VrMax.KeyPress, txboptg1_VrMin.KeyPress, txboptg2_FrMax.KeyPress, txboptg2_FrMin.KeyPress, txboptg2_VrMax.KeyPress, txboptg2_VrMin.KeyPress, txboptg3_FrMax.KeyPress, txboptg3_FrMin.KeyPress, txboptg3_VrMax.KeyPress, txboptg3_VrMin.KeyPress, txbopdy1_DtMax.KeyPress, txbopdy1_DtMin.KeyPress, txbopdy1_FrMax.KeyPress, txbopdy1_FrMin.KeyPress, txbopdy1_VpMax.KeyPress, txbopdy1_VpMin.KeyPress, txbopdy2_DtMax.KeyPress, txbopdy2_DtMin.KeyPress, txbopdy2_FrMax.KeyPress, txbopdy2_FrMin.KeyPress, txbopdy2_VpMax.KeyPress, txbopdy2_VpMin.KeyPress, txbopcs1_DyRg.KeyPress, txbopcs1_FrMax.KeyPress, txbopcs1_FrMin.KeyPress, txbopcs1_VpMax.KeyPress, txbopcs1_VpMin.KeyPress, txbopcs2_DyRg.KeyPress, txbopcs2_FrMax.KeyPress, txbopcs2_FrMin.KeyPress, txbopcs2_VpMax.KeyPress, txbopcs2_VpMin.KeyPress, txbopcs3_DyRg.KeyPress, txbopcs3_FrMax.KeyPress, txbopcs3_FrMin.KeyPress, txbopcs3_VpMax.KeyPress, txbopcs3_VpMin.KeyPress
        If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." Then
            e.Handled = True
        End If
    End Sub

    Private Sub formFullReset()
        startReset()
        resetTxbClear()
        resetColor()
        resetLetterColor()
        resetRefresh()
        threadOff()
    End Sub

    Private Sub resetColor()
        txbTDSN.BackColor = SystemColors.Window
        txbTDDate.BackColor = SystemColors.Window
        txbTDGrade.BackColor = SystemColors.Window
        txbTDTDate.BackColor = SystemColors.Window
        txbTDTTime.BackColor = SystemColors.Window

        txbDotDate_M1.BackColor = SystemColors.Window
        txbDotDepth_M1.BackColor = SystemColors.Window
        txbDotPower_M1.BackColor = SystemColors.Window
        txbDotTime_M1.BackColor = SystemColors.Window

        txbHBettery_M1.BackColor = SystemColors.Window
        txbHCtemp_M1.BackColor = SystemColors.Window
        txbHDate_M1.BackColor = SystemColors.Window
        txbHDtemp_M1.BackColor = SystemColors.Window
        txbHFreq_M1.BackColor = SystemColors.Window
        txbHFW_M1.BackColor = SystemColors.Window
        txbHHifu_M1.BackColor = SystemColors.Window
        txbHTime_M1.BackColor = SystemColors.Window

        txbRDate_M1.BackColor = SystemColors.Window
        txbREP_M1.BackColor = SystemColors.Window
        txbRMC_M1.BackColor = SystemColors.Window
        txbRRF_M1.BackColor = SystemColors.Window
        txbRTime_M1.BackColor = SystemColors.Window

        txbDate_M1.BackColor = SystemColors.Window
        txbDate.BackColor = SystemColors.Window
        txbSerial_M1.BackColor = SystemColors.Window
        txbFactory_M1.BackColor = SystemColors.Window
        txbModel_M1.BackColor = SystemColors.Window
        txbType_M1.BackColor = SystemColors.Window
        txbFace_M1.BackColor = SystemColors.Window
        txbEye_M1.BackColor = SystemColors.Window
        txbAgency_M1.BackColor = SystemColors.Window
        txbCountry_M1.BackColor = SystemColors.Window

        txbReCount.BackColor = SystemColors.Window

        txbRunState.BackColor = SystemColors.Window
    End Sub

    Private Sub resetTxbClear()
        txbTDSN.Text = String.Empty
        txbTDDate.Text = String.Empty
        txbTDGrade.Text = String.Empty
        txbTDTDate.Text = String.Empty
        txbTDTTime.Text = String.Empty

        txbDotDate_M1.Text = String.Empty
        txbDotDepth_M1.Text = String.Empty
        txbDotPower_M1.Text = String.Empty
        txbDotTime_M1.Text = String.Empty

        txbHBettery_M1.Text = String.Empty
        txbHCtemp_M1.Text = String.Empty
        txbHDate_M1.Text = String.Empty
        txbHDtemp_M1.Text = String.Empty
        txbHFreq_M1.Text = String.Empty
        txbHFW_M1.Text = String.Empty
        txbHHifu_M1.Text = String.Empty
        txbHTime_M1.Text = String.Empty

        txbRDate_M1.Text = String.Empty
        txbREP_M1.Text = String.Empty
        txbRMC_M1.Text = String.Empty
        txbRRF_M1.Text = String.Empty
        txbRTime_M1.Text = String.Empty

        txbDate_M1.Text = String.Empty
        txbDate.Text = String.Empty
        txbSerial_M1.Text = String.Empty
        txbFactory_M1.Text = String.Empty
        txbModel_M1.Text = String.Empty
        txbType_M1.Text = String.Empty
        txbFace_M1.Text = String.Empty
        txbEye_M1.Text = String.Empty
        txbAgency_M1.Text = String.Empty
        txbCountry_M1.Text = String.Empty

        txbReCount.Text = String.Empty

        txbRunState.Text = "대 기"
    End Sub

    Private Sub resetLetterColor()
        txbTDSN.ForeColor = Color.Black
        txbTDDate.ForeColor = Color.Black
        txbTDGrade.ForeColor = Color.Black
        txbTDTDate.ForeColor = Color.Black
        txbTDTTime.ForeColor = Color.Black

        txbDotDate_M1.ForeColor = Color.Black
        txbDotDepth_M1.ForeColor = Color.Black
        txbDotPower_M1.ForeColor = Color.Black
        txbDotTime_M1.ForeColor = Color.Black

        txbHBettery_M1.ForeColor = Color.Black
        txbHCtemp_M1.ForeColor = Color.Black
        txbHDate_M1.ForeColor = Color.Black
        txbHDtemp_M1.ForeColor = Color.Black
        txbHFreq_M1.ForeColor = Color.Black
        txbHFW_M1.ForeColor = Color.Black
        txbHHifu_M1.ForeColor = Color.Black
        txbHTime_M1.ForeColor = Color.Black

        txbRDate_M1.ForeColor = Color.Black
        txbREP_M1.ForeColor = Color.Black
        txbRMC_M1.ForeColor = Color.Black
        txbRRF_M1.ForeColor = Color.Black
        txbRTime_M1.ForeColor = Color.Black

        txbDate_M1.ForeColor = Color.Black
        txbDate.ForeColor = Color.Black
        txbSerial_M1.ForeColor = Color.Black
        txbFactory_M1.ForeColor = Color.Black
        txbModel_M1.ForeColor = Color.Black
        txbType_M1.ForeColor = Color.Black
        txbFace_M1.ForeColor = Color.Black
        txbEye_M1.ForeColor = Color.Black
        txbAgency_M1.ForeColor = Color.Black
        txbCountry_M1.ForeColor = Color.Black

        txbReCount.ForeColor = Color.Black

        txbRunState.ForeColor = Color.Black
    End Sub

    Private Sub resetRefresh()
        txbTDSN.Refresh()
        txbTDDate.Refresh()
        txbTDGrade.Refresh()
        txbTDTDate.Refresh()
        txbTDTTime.Refresh()

        txbDotDate_M1.Refresh()
        txbDotDepth_M1.Refresh()
        txbDotPower_M1.Refresh()
        txbDotTime_M1.Refresh()

        txbHBettery_M1.Refresh()
        txbHCtemp_M1.Refresh()
        txbHDate_M1.Refresh()
        txbHDtemp_M1.Refresh()
        txbHFreq_M1.Refresh()
        txbHFW_M1.Refresh()
        txbHHifu_M1.Refresh()
        txbHTime_M1.Refresh()

        txbRDate_M1.Refresh()
        txbREP_M1.Refresh()
        txbRMC_M1.Refresh()
        txbRRF_M1.Refresh()
        txbRTime_M1.Refresh()

        txbDate_M1.Refresh()
        txbDate.Refresh()
        txbSerial_M1.Refresh()
        txbFactory_M1.Refresh()
        txbModel_M1.Refresh()
        txbType_M1.Refresh()
        txbFace_M1.Refresh()
        txbEye_M1.Refresh()
        txbAgency_M1.Refresh()
        txbCountry_M1.Refresh()

        txbReCount.Refresh()

        txbRunState.Refresh()
    End Sub

    Private Sub dataSetting()
        tdReadTxb(tdDataList.TDSN) = txbTDSN
        tdReadTxb(tdDataList.TDDate) = txbTDDate
        tdReadTxb(tdDataList.TestDate) = txbTDTDate
        tdReadTxb(tdDataList.TestTime) = txbTDTTime
        tdReadTxb(tdDataList.Grade) = txbTDGrade

        dotReadTxb(dotDataList.dotDate) = txbDotDate_M1
        dotReadTxb(dotDataList.dotTime) = txbDotTime_M1
        dotReadTxb(dotDataList.dotPower) = txbDotPower_M1
        dotReadTxb(dotDataList.dotDepth) = txbDotDepth_M1

        hifuReadTxb(hifuDataList.hifuDate) = txbHDate_M1
        hifuReadTxb(hifuDataList.hifuTime) = txbHTime_M1
        hifuReadTxb(hifuDataList.hifuFW) = txbHFW_M1
        hifuReadTxb(hifuDataList.hifuFreq) = txbHFreq_M1
        hifuReadTxb(hifuDataList.hifuBaterry) = txbHBettery_M1
        hifuReadTxb(hifuDataList.hifuDtemp) = txbHDtemp_M1
        hifuReadTxb(hifuDataList.hifuCtemp) = txbHCtemp_M1
        hifuReadTxb(hifuDataList.hifuData1_txb) = txbHHifu_M1

        rfReadTxb(rfDataList.rfDate) = txbRDate_M1
        rfReadTxb(rfDataList.rfTime) = txbRTime_M1
        rfReadTxb(rfDataList.rfR1Vrms_txb1) = txbRRF_M1
        rfReadTxb(rfDataList.rfR1Freq_txb2) = txbRMC_M1
        rfReadTxb(rfDataList.rfR2Vrms_txb3) = txbREP_M1

        pd2ReadTxb(pd2DataList.pd2DateTime) = txbDate_M1
        pd2ReadTxb(pd2DataList.prodDate) = txbDate
        pd2ReadTxb(pd2DataList.pd2Serial) = txbSerial_M1
        pd2ReadTxb(pd2DataList.pd2Factory) = txbFactory_M1
        pd2ReadTxb(pd2DataList.pd2Model) = txbModel_M1
        pd2ReadTxb(pd2DataList.pd2Type) = txbType_M1
        pd2ReadTxb(pd2DataList.pd2Face) = txbFace_M1
        pd2ReadTxb(pd2DataList.pd2Eye) = txbEye_M1
        pd2ReadTxb(pd2DataList.pd2Country) = txbCountry_M1
        pd2ReadTxb(pd2DataList.pd2Agency) = txbAgency_M1

        saveTextData(saveDataList.opFw) = txbopFW
        saveTextData(saveDataList.opFreqMax) = txbOpFreq_RgMax
        saveTextData(saveDataList.opFreqMin) = txbOpFreq_RgMin
        saveTextData(saveDataList.opBatMax) = txbopBat_RgMax
        saveTextData(saveDataList.opBatMin) = txbopBat_RgMin
        saveTextData(saveDataList.opDtempMax) = txbopDiv_TpMax
        saveTextData(saveDataList.opDtempMin) = txbopDiv_TpMin
        saveTextData(saveDataList.opCtempMax) = txbopCt_TpMax
        saveTextData(saveDataList.opCtempMin) = txbopCt_TpMin
        saveTextData(saveDataList.opHF1Max) = txbopHF1_TpMax
        saveTextData(saveDataList.opHF1Min) = txbopHF1_TpMin
        saveTextData(saveDataList.opHF2Max) = txbopHF2_TpMax
        saveTextData(saveDataList.opHF2Min) = txbopHF2_TpMin
        saveTextData(saveDataList.opHF3Max) = txbopHF3_TpMax
        saveTextData(saveDataList.opHF3Min) = txbopHF3_TpMin
        saveTextData(saveDataList.opHF12) = txbopHF12_Tp
        saveTextData(saveDataList.opHF23) = txbopHF23_Tp
        saveTextData(saveDataList.optg1FrqMax) = txboptg1_FrMax
        saveTextData(saveDataList.optg1FrqMin) = txboptg1_FrMin
        saveTextData(saveDataList.optg1VrMax) = txboptg1_VrMax
        saveTextData(saveDataList.optg1VrMin) = txboptg1_VrMin
        saveTextData(saveDataList.optg2FrqMax) = txboptg2_FrMax
        saveTextData(saveDataList.optg2FrqMin) = txboptg2_FrMin
        saveTextData(saveDataList.optg2VrMax) = txboptg2_VrMax
        saveTextData(saveDataList.optg2VrMin) = txboptg2_VrMin
        saveTextData(saveDataList.optg3FrqMax) = txboptg3_FrMax
        saveTextData(saveDataList.optg3FrqMin) = txboptg3_FrMin
        saveTextData(saveDataList.optg3VrMax) = txboptg3_VrMax
        saveTextData(saveDataList.optg3VrMin) = txboptg3_VrMin
        saveTextData(saveDataList.opdy1DtMax) = txbopdy1_DtMax
        saveTextData(saveDataList.opdy1DtMin) = txbopdy1_DtMin
        saveTextData(saveDataList.opdy1FrMax) = txbopdy1_FrMax
        saveTextData(saveDataList.opdy1FrMin) = txbopdy1_FrMin
        saveTextData(saveDataList.opdy1VpMax) = txbopdy1_VpMax
        saveTextData(saveDataList.opdy1VpMin) = txbopdy1_VpMin
        saveTextData(saveDataList.opdy2DtMax) = txbopdy2_DtMax
        saveTextData(saveDataList.opdy2DtMin) = txbopdy2_DtMin
        saveTextData(saveDataList.opdy2FrMax) = txbopdy2_FrMax
        saveTextData(saveDataList.opdy2FrMin) = txbopdy2_FrMin
        saveTextData(saveDataList.opdy2VpMax) = txbopdy2_VpMax
        saveTextData(saveDataList.opdy2VpMin) = txbopdy2_VpMin
        saveTextData(saveDataList.opcs1Dy) = txbopcs1_DyRg
        saveTextData(saveDataList.opcs1FrMax) = txbopcs1_FrMax
        saveTextData(saveDataList.opcs1FrMin) = txbopcs1_FrMin
        saveTextData(saveDataList.opcs1VpMax) = txbopcs1_VpMax
        saveTextData(saveDataList.opcs1VpMin) = txbopcs1_VpMin
        saveTextData(saveDataList.opcs2Dy) = txbopcs2_DyRg
        saveTextData(saveDataList.opcs2FrMax) = txbopcs2_FrMax
        saveTextData(saveDataList.opcs2FrMin) = txbopcs2_FrMin
        saveTextData(saveDataList.opcs2VpMax) = txbopcs2_VpMax
        saveTextData(saveDataList.opcs2VpMin) = txbopcs2_VpMin
        saveTextData(saveDataList.opcs3Dy) = txbopcs3_DyRg
        saveTextData(saveDataList.opcs3FrMax) = txbopcs3_FrMax
        saveTextData(saveDataList.opcs3FrMin) = txbopcs3_FrMin
        saveTextData(saveDataList.opcs3VpMax) = txbopcs3_VpMax
        saveTextData(saveDataList.opcs3VpMin) = txbopcs3_VpMin

        saveTextData(saveDataList.opFW_AT) = txbopFW_AT
        saveTextData(saveDataList.opBatMax_AT) = txbopBat_RgMaxAT
        saveTextData(saveDataList.opBatMin_AT) = txbopBat_RgMinAT
        saveTextData(saveDataList.opDtempMax_AT) = txbopDiv_TpMaxAT
        saveTextData(saveDataList.opDtempMin_AT) = txbopDiv_TpMinAT
        saveTextData(saveDataList.opCtempMax_AT) = txbopCt_TpMaxAT
        saveTextData(saveDataList.opCtempMin_AT) = txbopCt_TpMinAT

        saveTextData(saveDataList.optg1FrqMax_AT) = txboptg1_FrMaxAT
        saveTextData(saveDataList.optg1FrqMin_AT) = txboptg1_FrMinAT
        saveTextData(saveDataList.optg1VrMax_AT) = txboptg1_VrMaxAT
        saveTextData(saveDataList.optg1VrMin_AT) = txboptg1_VrMinAT
        saveTextData(saveDataList.optg2FrqMax_AT) = txboptg2_FrMaxAT
        saveTextData(saveDataList.optg2FrqMin_AT) = txboptg2_FrMinAT
        saveTextData(saveDataList.optg2VrMax_AT) = txboptg2_VrMaxAT
        saveTextData(saveDataList.optg2VrMin_AT) = txboptg2_VrMinAT
        saveTextData(saveDataList.optg3FrqMax_AT) = txboptg3_FrMaxAT
        saveTextData(saveDataList.optg3FrqMin_AT) = txboptg3_FrMinAT
        saveTextData(saveDataList.optg3VrMax_AT) = txboptg3_VrMaxAT
        saveTextData(saveDataList.optg3VrMin_AT) = txboptg3_VrMinAT

        saveTextData(saveDataList.opcs1Dy_AT) = txbopcs1_DyRgAT
        saveTextData(saveDataList.opcs1FrMax_AT) = txbopcs1_FrMaxAT
        saveTextData(saveDataList.opcs1FrMin_AT) = txbopcs1_FrMinAT
        saveTextData(saveDataList.opcs1VpMax_AT) = txbopcs1_VpMaxAT
        saveTextData(saveDataList.opcs1VpMin_AT) = txbopcs1_VpMinAT
        saveTextData(saveDataList.opcs2Dy_AT) = txbopcs2_DyRgAT
        saveTextData(saveDataList.opcs2FrMax_AT) = txbopcs2_FrMaxAT
        saveTextData(saveDataList.opcs2FrMin_AT) = txbopcs2_FrMinAT
        saveTextData(saveDataList.opcs2VpMax_AT) = txbopcs2_VpMaxAT
        saveTextData(saveDataList.opcs2VpMin_AT) = txbopcs2_VpMinAT
        saveTextData(saveDataList.opcs3Dy_AT) = txbopcs3_DyRgAT
        saveTextData(saveDataList.opcs3FrMax_AT) = txbopcs3_FrMaxAT
        saveTextData(saveDataList.opcs3FrMin_AT) = txbopcs3_FrMinAT
        saveTextData(saveDataList.opcs3VpMax_AT) = txbopcs3_VpMaxAT
        saveTextData(saveDataList.opcs3VpMin_AT) = txbopcs3_VpMinAT

        saveDBCkb(dbRegList.dbTD) = ckbopTD
        saveDBCkb(dbRegList.dbDot) = ckbopDot
        saveDBCkb(dbRegList.dbHifu) = ckbopHifu
        saveDBCkb(dbRegList.dbWave) = ckbopWave
        saveDBCkb(dbRegList.dbInfo) = ckbopInfo
    End Sub

    Private Sub ComboBoxSetting()
        comboBoxModel.Items.Clear()
        cboCsvProd.Items.Clear()
        DBCmd = "SELECT ModelName FROM " & ApplyModelInfoDB & " WHERE DeviceTypeCode = 'A' GROUP BY ModelName"
        If DBQueryReader(DBCmd) Then
            For i = 0 To sqlDataQuery.Length - 1
                comboBoxModel.Items.Add(sqlDataQuery(i))
                cboCsvProd.Items.Add(sqlDataQuery(i))
            Next
        End If
        comboBoxModel.SelectedItem = "MAXIMUM"

        cboCsvType.Items.Clear()
        DBCmd = "SELECT CartTypeName FROM " & ApplyModelInfoDB & " WHERE DeviceTypeCode = 'A' GROUP BY CartTypeName"
        If DBQueryReader(DBCmd) Then
            For i = 0 To sqlDataQuery.Length - 1
                cboCsvType.Items.Add(sqlDataQuery(i))
            Next
        End If

        cboCsvColor.Items.Clear()
        DBCmd = "SELECT ColorName FROM " & ApplyModelInfoDB & " WHERE DeviceTypeCode = 'A' GROUP BY ColorName"
        If DBQueryReader(DBCmd) Then
            For i = 0 To sqlDataQuery.Length - 1
                cboCsvColor.Items.Add(sqlDataQuery(i))
            Next
        End If

    End Sub

    Private Sub optionAllReset()
        optionClear()
        optionRefresh()
    End Sub

    Private Sub optionClear()
        txbopFW.Text = String.Empty
        txbOpFreq_RgMax.Text = String.Empty
        txbOpFreq_RgMin.Text = String.Empty
        txbopBat_RgMax.Text = String.Empty
        txbopBat_RgMin.Text = String.Empty
        txbopDiv_TpMax.Text = String.Empty
        txbopDiv_TpMin.Text = String.Empty
        txbopCt_TpMax.Text = String.Empty
        txbopCt_TpMin.Text = String.Empty

        txbopHF1_TpMax.Text = String.Empty
        txbopHF1_TpMin.Text = String.Empty
        txbopHF2_TpMax.Text = String.Empty
        txbopHF2_TpMin.Text = String.Empty
        txbopHF3_TpMax.Text = String.Empty
        txbopHF3_TpMin.Text = String.Empty
        txbopHF12_Tp.Text = String.Empty
        txbopHF23_Tp.Text = String.Empty

        txboptg1_FrMax.Text = String.Empty
        txboptg1_FrMin.Text = String.Empty
        txboptg1_VrMax.Text = String.Empty
        txboptg1_VrMin.Text = String.Empty
        txboptg2_FrMax.Text = String.Empty
        txboptg2_FrMin.Text = String.Empty
        txboptg2_VrMax.Text = String.Empty
        txboptg2_VrMin.Text = String.Empty
        txboptg3_FrMax.Text = String.Empty
        txboptg3_FrMin.Text = String.Empty
        txboptg3_VrMax.Text = String.Empty
        txboptg3_VrMin.Text = String.Empty

        txbopdy1_DtMax.Text = String.Empty
        txbopdy1_DtMin.Text = String.Empty
        txbopdy1_FrMax.Text = String.Empty
        txbopdy1_FrMin.Text = String.Empty
        txbopdy1_VpMax.Text = String.Empty
        txbopdy1_VpMin.Text = String.Empty
        txbopdy2_DtMax.Text = String.Empty
        txbopdy2_DtMin.Text = String.Empty
        txbopdy2_FrMax.Text = String.Empty
        txbopdy2_FrMin.Text = String.Empty
        txbopdy2_VpMax.Text = String.Empty
        txbopdy2_VpMin.Text = String.Empty

        txbopcs1_DyRg.Text = String.Empty
        txbopcs1_FrMax.Text = String.Empty
        txbopcs1_FrMin.Text = String.Empty
        txbopcs1_VpMax.Text = String.Empty
        txbopcs1_VpMin.Text = String.Empty
        txbopcs2_DyRg.Text = String.Empty
        txbopcs2_FrMax.Text = String.Empty
        txbopcs2_FrMin.Text = String.Empty
        txbopcs2_VpMax.Text = String.Empty
        txbopcs2_VpMin.Text = String.Empty
        txbopcs3_DyRg.Text = String.Empty
        txbopcs3_FrMax.Text = String.Empty
        txbopcs3_FrMin.Text = String.Empty
        txbopcs3_VpMax.Text = String.Empty
        txbopcs3_VpMin.Text = String.Empty
    End Sub

    Private Sub optionRefresh()
        txbopFW.Refresh()
        txbOpFreq_RgMax.Refresh()
        txbOpFreq_RgMin.Refresh()
        txbopBat_RgMax.Refresh()
        txbopBat_RgMin.Refresh()
        txbopDiv_TpMax.Refresh()
        txbopDiv_TpMin.Refresh()
        txbopCt_TpMax.Refresh()
        txbopCt_TpMin.Refresh()

        txbopHF1_TpMax.Refresh()
        txbopHF1_TpMin.Refresh()
        txbopHF2_TpMax.Refresh()
        txbopHF2_TpMin.Refresh()
        txbopHF3_TpMax.Refresh()
        txbopHF3_TpMin.Refresh()
        txbopHF12_Tp.Refresh()
        txbopHF23_Tp.Refresh()

        txboptg1_FrMax.Refresh()
        txboptg1_FrMin.Refresh()
        txboptg1_VrMax.Refresh()
        txboptg1_VrMin.Refresh()
        txboptg2_FrMax.Refresh()
        txboptg2_FrMin.Refresh()
        txboptg2_VrMax.Refresh()
        txboptg2_VrMin.Refresh()
        txboptg3_FrMax.Refresh()
        txboptg3_FrMin.Refresh()
        txboptg3_VrMax.Refresh()
        txboptg3_VrMin.Refresh()

        txbopdy1_DtMax.Refresh()
        txbopdy1_DtMin.Refresh()
        txbopdy1_FrMax.Refresh()
        txbopdy1_FrMin.Refresh()
        txbopdy1_VpMax.Refresh()
        txbopdy1_VpMin.Refresh()
        txbopdy2_DtMax.Refresh()
        txbopdy2_DtMin.Refresh()
        txbopdy2_FrMax.Refresh()
        txbopdy2_FrMin.Refresh()
        txbopdy2_VpMax.Refresh()
        txbopdy2_VpMin.Refresh()

        txbopcs1_DyRg.Refresh()
        txbopcs1_FrMax.Refresh()
        txbopcs1_FrMin.Refresh()
        txbopcs1_VpMax.Refresh()
        txbopcs1_VpMin.Refresh()
        txbopcs2_DyRg.Refresh()
        txbopcs2_FrMax.Refresh()
        txbopcs2_FrMin.Refresh()
        txbopcs2_VpMax.Refresh()
        txbopcs2_VpMin.Refresh()
        txbopcs3_DyRg.Refresh()
        txbopcs3_FrMax.Refresh()
        txbopcs3_FrMin.Refresh()
        txbopcs3_VpMax.Refresh()
        txbopcs3_VpMin.Refresh()
    End Sub

    Private Sub btnOption_Click(sender As Object, e As EventArgs) Handles btnOption.Click
        formFullReset()
        pnStandard.Location = New Point(0, 0)
        pnMain.Visible = False
        pnStandard.Visible = True
        pnMain.Location = New Point(1920, 0)
    End Sub

    Private Sub monthCal_DateSelected(sender As Object, e As DateRangeEventArgs) Handles monthCal.DateSelected
        If monCalNum = Format(monthCal.SelectionStart, "yyyy-MM-dd") Then
            btnExcelSelect_Click(sender, e)
        Else
            monCalNum = Format(monthCal.SelectionStart, "yyyy-MM-dd")
        End If
    End Sub

    Private Sub CalTimer_Tick(sender As Object, e As EventArgs) Handles CalTimer.Tick
        If monCalTime = True Then
            monCalNum = String.Empty
            monCalTime = False
        Else
            monCalTime = True
        End If
    End Sub

    Private Sub txbProdSerial_Click(sender As Object, e As EventArgs) Handles txbProdSerial.Click
        txbProdSerial.BackColor = SystemColors.Window
        If ckbBarcode.Checked = True Then
            txbProdSerial.Select(txbProdSerial.MaxLength, 0)
        End If
    End Sub

    Private Sub btnReturn_Click(sender As Object, e As EventArgs) Handles btnReturn.Click
        If txbProdSerial.Text = String.Empty Then
            MsgBox("입력할 정보가 존재하지 않습니다. 데이터를 읽어주십시오,", vbExclamation)
            GoTo finishFunc
        End If

        If txbProdSerial.Text.Length <> oldProdLength And txbProdSerial.Text.Length <> newProdLength Then
            MsgBox("잘못된 시리얼 번호를 입력하였습니다.", vbExclamation)
            GoTo finishFunc
        End If

        DBCmd = "SELECT EXISTS (SELECT 1 FROM " & ApplyReturnDB & " WHERE Product_SN = '" & txbProdSerial.Text & "') AS a"
        Dim DataExist As String = DBQueryScalar(DBCmd)

        If DataExist Then
            ReturnForm.ShowDialog()
        Else
            MsgBox("반품 데이터가 존재하지 않습니다..", vbCritical)
        End If

finishFunc:
        txbProdSerial.Focus()
    End Sub

    Private Sub comboBoxModel_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboBoxModel.SelectedIndexChanged
        Dim ModelName As String = comboBoxModel.SelectedItem

        gbStandard.Text = ModelName & " 합격기준"
        dataSetting()
        configLoad()

        DBCmd = "SELECT HifuUseYn, LdmUseYn FROM " & ApplyModelInfoDB & " WHERE ModelName = '" & ModelName & "' LIMIT 1"

        If DBQueryReader(DBCmd) Then
            If sqlDataQuery(0) = "Y" Or sqlDataQuery(1) = "Y" Then
                gbStandard.Visible = True
                gbStandard_AT.Visible = False
            Else
                gbStandard.Visible = False
                gbStandard_AT.Visible = True
            End If
        End If
    End Sub

    Private Sub txbProdSerial_GotFocus(sender As Object, e As EventArgs) Handles txbProdSerial.GotFocus
        txbProdSerial.Select(txbProdSerial.MaxLength, 0)
    End Sub

    Private Sub txbTDSN_GotFocus(sender As Object, e As EventArgs) Handles txbTDSN.GotFocus, txbTDDate.GotFocus, txbTDGrade.GotFocus, txbTDTDate.GotFocus, txbTDTTime.GotFocus, txbDotDate_M1.GotFocus, txbDotDepth_M1.GotFocus, txbDotPower_M1.GotFocus, txbDotTime_M1.GotFocus, txbHBettery_M1.GotFocus, txbHCtemp_M1.GotFocus, txbHDate_M1.GotFocus, txbHDtemp_M1.GotFocus, txbHFreq_M1.GotFocus, txbHFW_M1.GotFocus, txbHHifu_M1.GotFocus, txbHTime_M1.GotFocus, txbRDate_M1.GotFocus, txbREP_M1.GotFocus, txbRMC_M1.GotFocus, txbRRF_M1.GotFocus, txbRTime_M1.GotFocus, txbDate_M1.GotFocus, txbDate.GotFocus, txbSerial_M1.GotFocus, txbFactory_M1.GotFocus, txbModel_M1.GotFocus, txbType_M1.GotFocus, txbFace_M1.GotFocus, txbEye_M1.GotFocus, txbAgency_M1.GotFocus, txbCountry_M1.GotFocus
        txbProdSerial.Focus()
    End Sub
End Class
