Imports System.Linq
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Bt.SysLib
Imports Bt
'*******************************************************************************
'* File name         : Indicates the file's name or identifier.
'* Created           : 2004/10/02
'* Project           : PICS2004 Development
'* Updates           : 
'* Version           : 1.0
'*******************************************************************************
'* Convert By        : Thanthima 
'* Date              : 2024/06/15
'*******************************************************************************
Module modPublicHT
    '*******************************************************************************
    '   which is to handle the display of a message box (MsgBox).
    '   parameters: wMsgId, String, Message ID
    '               wDispMode, String, Display Mode (1: Information, 2: Warning, 3: Error)
    '               wMsgName, String, Message Title
    '               wButton, String, Button ID
    '               wIcon, String, Icon ID
    '   Return Value: String, Result of the MsgBox function
    '                 (If the button clicked is "OK" on a Form, for example)   Translate
    '*******************************************************************************
    Public Function fFnc_WrpMsg(ByVal pStatus As String, ByVal pMID As String, Optional ByVal pCountry As String = "ND", Optional ByVal wintSelect As Integer = 1) As Integer
        Dim wstrImgFile As String = ""
        Dim wMsg As New clsWrpMsg

        If pCountry = "ND" Then
            pCountry = gstrctKDHT.strCountry
        End If

        Select Case pStatus
            Case "H"
                wstrImgFile = G_CONST_IMG_DIR & "H" & pCountry & "-" & pMID & G_CONST_IMG_EXT
            Case "E"
                wstrImgFile = G_CONST_IMG_DIR & "E" & pCountry & "-" & pMID & G_CONST_IMG_EXT
            Case "S"
                wstrImgFile = G_CONST_IMG_DIR & "S" & pCountry & "-" & pMID & G_CONST_IMG_EXT
        End Select

        With wMsg
            .pImgFile = wstrImgFile
            .pSelection = wintSelect
            .sMsgBox()
            Return .pRtnCode
        End With
    End Function
    Public Enum BEEP_TYPE
        A = 1
        B = 2
        C = 3
        D = 4
        E = 5
    End Enum

    Public Enum BEEP_SELECTION
        OK = 1
        NG = 2
    End Enum
    Public Sub sBeepSound(ByVal pType As BEEP_TYPE, ByVal pSelection As BEEP_SELECTION)

        Select Case pSelection

            Case BEEP_SELECTION.OK

                Select Case pType

                    Case BEEP_TYPE.A
                        'f0.WarpCtrl1.BeepEx("<-200>")
                        'Bt.SysLib.Device.btSetKeySound()
                        'setSoundOK()

                    Case BEEP_TYPE.B
                        'f0.WarpCtrl1.BeepEx("<-100>-50<-100>")
                        'setSoundOK()

                    Case BEEP_TYPE.C
                        'f0.WarpCtrl1.BeepEx("<-200>-200<-200>")
                        'setSoundOK()

                    Case BEEP_TYPE.D
                        'f0.WarpCtrl1.BeepEx("<LB+200>-200<LB+200>")
                        'setSoundOK()

                    Case BEEP_TYPE.E
                        'f0.WarpCtrl1.BeepEx("<-200><-200>")
                        'setSoundOK()

                End Select

            Case BEEP_SELECTION.NG

                Select Case pType
                    Case BEEP_TYPE.A
                        'f0.WarpCtrl1.BeepEx("<LB+2000>")
                        'setSoundNG()

                    Case BEEP_TYPE.B
                        'f0.WarpCtrl1.BeepEx("LB+200-100LB+200-100LB+200-100LB+200-100LB+200")
                        'setSoundNG()

                    Case BEEP_TYPE.C
                        'f0.WarpCtrl1.BeepEx("<LB+300><LB+300><LB+300><LB+300><LB+300>")
                        'setSoundNG()

                    Case BEEP_TYPE.D
                        'f0.WarpCtrl1.BeepEx("LB+1000")
                        'f0.WarpCtrl1.BeepEx("<-200><-200><-200><-200><-200><-200><-200>")
                        'setSoundNG()

                    Case BEEP_TYPE.E
                        'f0.WarpCtrl1.BeepEx("<LB+1000>")
                        'setSoundNG()

                End Select

        End Select

    End Sub

    Public Sub setSoundNG()

        Dim ret As Int32 = 0
        Dim disp As [String] = ""

        Dim stBuzzerSet As New LibDef.BT_BUZZER_PARAM()
        ' Buzzer control structure (Set)
        ' Set to repeat "500 ms on, 500 ms off" 3 times
        stBuzzerSet.dwOn = 500
        ' Rumble time [ms] (1 to 5000)
        stBuzzerSet.dwOff = 500
        ' Stop time [ms] (0 to 5000)
        stBuzzerSet.dwCount = 3
        ' Rumble count [times] (0 to 100)
        stBuzzerSet.bTone = 16
        ' Musical scale (1 to 16)
        stBuzzerSet.bVolume = 3
        ' Buzzer volume (1 to 3)
        Try
            ' btBuzzer Rumble
            ret = Device.btBuzzer(1, stBuzzerSet)
            If ret <> LibDef.BT_OK Then
                disp = "btBuzzer error ret[" & ret & "]"
                MessageBox.Show(disp, "Error")
                Return
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try


    End Sub

    Public Sub setSoundOK()

        Dim ret As Int32 = 0
        Dim disp As [String] = ""

        Dim stBuzzerSet As New LibDef.BT_BUZZER_PARAM()
        ' Buzzer control structure (Set)
        ' Set to repeat "500 ms on, 500 ms off" 3 times
        stBuzzerSet.dwOn = 100
        ' Rumble time [ms] (1 to 5000)
        stBuzzerSet.dwOff = 100
        ' Stop time [ms] (0 to 5000)
        stBuzzerSet.dwCount = 1
        ' Rumble count [times] (0 to 100)
        stBuzzerSet.bTone = 16
        ' Musical scale (1 to 16)
        stBuzzerSet.bVolume = 3
        ' Buzzer volume (1 to 3)
        Try
            ' btBuzzer Rumble
            ret = Device.btBuzzer(1, stBuzzerSet)
            If ret <> LibDef.BT_OK Then
                disp = "btBuzzer error ret[" & ret & "]"
                MessageBox.Show(disp, "Error")
                Return
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try


    End Sub

    '*******************************************************************************
    '* Function   : Calculates the state based on the given value
    '* Parameter  : pstrValue    String  - Input value
    '* Return     : Calculated state value
    '* Remarks    : 
    '*******************************************************************************
    Private Function wfGetCode(ByVal pstrValue As String) As Integer
        Dim i As Integer

        wfGetCode = -1

        For i = 0 To UBound(mstrChr)
            If mstrChr(i) = pstrValue Then
                wfGetCode = mintChr(i)
                Exit Function
            End If
        Next

    End Function
    '*******************************************************************************
    '* Function   : Determines the status based on the input parameters
    '* Parameter  : pstrBarCode    String  - Barcode
    '*            : pblnInp        Boolean - True: Input active, False: Input inactive
    '* Return     : Returns True if the input is valid
    '* Remarks    : 
    '*******************************************************************************
    Public Function fCheckCode(ByRef pstrBarCode As String) As Boolean
        Dim i As Integer
        Dim wintChr() As Integer
        Dim wintSum As Integer
        Dim wintAmari As Integer
        Dim wstrBarCode As String
        Dim wstrDigit As String

        fCheckCode = False

        If Len(pstrBarCode) = 0 Then Exit Function

        wstrBarCode = Mid(pstrBarCode, 2, Len(pstrBarCode) - 2)
        wstrDigit = Mid(pstrBarCode, Len(pstrBarCode), 1)

        '// Determines the state (M43) based on the given conditions
        ReDim wintChr(Len(wstrBarCode) - 1)
        For i = 1 To Len(wstrBarCode)
            wintChr(i - 1) = wfGetCode(Mid(wstrBarCode, i, 1))
        Next

        wintSum = 0
        For i = 0 To UBound(wintChr)
            wintSum = wintSum + wintChr(i)
        Next

        wintAmari = wintSum Mod 43

        'MessageBox.Show(wfGetValue(wintAmari) + " | " + wstrDigit)

        If wfGetValue(wintAmari) <> wstrDigit Then
            ' Determines the state based on the conditions
            'fFnc_Msg("0304", "3")
            Exit Function
        End If

        pstrBarCode = wstrBarCode
        fCheckCode = True
    End Function
    '*******************************************************************************
    '* Function   : Calculates the state based on the given integer value
    '* Parameter  : pintValue    Integer  - Input value
    '* Return     : Calculated state value
    '* Remarks    : 
    '*******************************************************************************
    Private Function wfGetValue(ByVal pintValue As Integer) As String
        Dim i As Integer

        wfGetValue = -1

        For i = 0 To UBound(mintChr)
            If mintChr(i) = pintValue Then
                wfGetValue = mstrChr(i)
                Exit Function
            End If
        Next

    End Function
    '*******************************************************************************
    '   Version   : OCMENUBACK or HTCTRL.ExeName
    '   Additional Information:
    '   Return Value: Translate
    '*******************************************************************************
    'Public Sub sFinishApp()
    '    Dim rut As Integer = 0
    '    Dim wintCnt As Integer = 0
    '    Dim wstrWhere As String = ""
    '    Dim wstrKey(0) As String, wstrKeyValue(0) As String

    '    Try

    '        BtLib.Transaction.BeginConCurrent()

    '        wstrWhere = "@HTNumber = " & gstrctKDHT.strHdNo
    '        wintCnt = gclsDB.fGetData(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, wstrWhere, "CTRL2")

    '        If wintCnt > 0 Then
    '            gclsDB.fCloseRecord("CTRL2")
    '        ElseIf wintCnt = 0 Then
    '            gclsDB.fCloseRecord("CTRL2")
    '            BtLib.Transaction.Abort()
    '            fFnc_WrpMsg("S", G_CONST_MID_S0010, "001")
    '            Exit Sub
    '        ElseIf wintCnt = -1 Then
    '            gclsDB.fCloseRecord("CTRL2")
    '            BtLib.Transaction.Abort()
    '            fFnc_WrpMsg("S", G_CONST_MID_S0010, "001")
    '            Exit Sub
    '        End If


    '        gclsDB.Setcolumn = ("ExeName,SearchKey")                 'Invalid path/file name
    '        gclsDB.SetData = Space(8) & "," & Space(30)              'Invalid directory/folder

    '        wstrKey(0) = "HTNumber"
    '        wstrKeyValue(0) = gstrctKDHT.strHdNo

    '        If gclsDB.fUpdRecords(G_CONST_TBL_HTCTRL, G_CONST_KEY_HTCTRLKEY00, wstrKey, wstrKeyValue) = -1 Then
    '            BtLib.Transaction.Abort()

    '        End If

    '        BtLib.Transaction.End()


    '    Catch ex As Exception
    '        BtLib.Transaction.Abort()
    '        sErrLog(gAppName, "sFinishApp", ex.ToString)
    '    End Try

    'End Sub

    Public Sub sSetImgFName(ByVal pMID As String, ByRef pWarpBox As PictureBox, Optional ByVal pintFlag As Integer = 0)
        Dim wstrImgFile As String
        Dim wMsg As New clsWrpMsg

        If pintFlag = 0 Then
            wstrImgFile = G_CONST_IMG_DIR & "H" & gstrctKDHT.strCountry & "-" & pMID & G_CONST_IMG_EXT
        Else
            wstrImgFile = G_CONST_IMG_DIR & "E" & gstrctKDHT.strCountry & "-" & pMID & G_CONST_IMG_EXT
        End If

        'pWarpBox.SetImage(wstrImgFile)

        pWarpBox.Image = Image.FromHbitmap(wstrImgFile)

    End Sub
    '*******************************************************************************
    '   Version: Input form data check (-)
    '   Parameter: pstrData    String
    '   Return: String (12345 or 12-345)
    '*******************************************************************************
    Public Function fstrDivision(ByVal pintCut As Integer, ByVal pstrData As String) As String
        Dim wstrValue As String
        Dim wstrFront As String
        Dim wstrBack As String
        Dim wintData As String
        Dim rut As Integer

        fstrDivision = " "

        Try

            wstrFront = pstrData.Substring(0, pintCut)
            wstrBack = pstrData.Substring(pintCut)

            wstrValue = wstrFront & "-" & wstrBack

            fstrDivision = wstrValue

        Catch ex As Exception
            sErrLog(gAppName, "fstrDivision", ex.ToString)
        End Try

    End Function
End Module
