
'*******************************************************************************
'* 作成会社 : 株式会社エコー・システム
'* 作成者   : 下久保 壮雄
'* 作成日   : 2010/08/09
'* 概要     : 移動番号取得ｸﾗｽ
'* 更新履歴 : 
'* ﾊﾞｰｼﾞｮﾝ  : 1.0
'*******************************************************************************
'Imports WarpControl
'Imports WarpControl.WarpApi2
'Imports CommonMove.clsBTRFile
'Imports CommonMove.clsConst

Imports System
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 BTClientLib
Imports System.IO
Imports System.Reflection

Public Class clsGetSeq

    'Private dbClient As BtrieveDbClient
    Private tmpStr As List(Of Dictionary(Of String, String))
    Private affected_rows As Integer

#Region "// Param Area /////////////////////////////////////////////////////////////////////////////"

    Private mstrFuncName As String = ""                     '関数名

    Private mstrMoveNo As String = ""                       '移動番号
    Private mstrDate As String = ""                         '対象日付
    Private mstrGrNo As String = ""                         '括り番号

#End Region

#Region "// プロパティ宣言エリア ///////////////////////////////////////////////////////////////////////"

    '移動番号
    Public ReadOnly Property Get_MoveNo() As String
        Get
            Return mstrMoveNo
        End Get
    End Property

    '対象日付
    Public WriteOnly Property Set_Date() As String
        Set(ByVal Value As String)
            mstrDate = Value
        End Set
    End Property

    '括り番号
    Public WriteOnly Property Set_GrNo() As String
        Set(ByVal Value As String)
            mstrGrNo = Value
        End Set
    End Property

#End Region

#Region "// Main Method ///////////////////////////////////////////////////////////////////////////////"

    '*******************************************************************************
    '  概要     : Main Method メイン
    '  引数     : 
    '  戻り値   : Boolean       True:正常 / False:異常
    '  備考     :
    '*******************************************************************************
    Public Function Run() As Boolean
        mstrFuncName = "Run"

        Dim wintSeq As Integer = 0
        Dim wblnGet As Boolean = False

        Try
            '// 初期化処理
            Call wsClear()

            '// SEQ取得
            If Not wfExistMoveSeq(wblnGet, wintSeq) Then Return False

            '// MOVESEQ登録/更新
            If Not wfSetMoveSeq(wblnGet, wintSeq) Then Return False

            '// 移動番号作成
            mstrMoveNo = wfCreateMoveNo(wintSeq)

            Return True

        Catch ex As Exception
            Throw ex
        End Try
    End Function

    '*******************************************************************************
    '  概要     : 初期化処理
    '  引数     : 
    '  戻り値   : 
    '  備考     :
    '*******************************************************************************
    Private Sub wsClear()
        mstrMoveNo = ""

        If mstrDate.Length = 0 Then mstrDate = DateTime.Today.ToString("yyyyMMdd")
    End Sub

    '*******************************************************************************
    ' 概要      : 検索用パラメータ設定
    ' 引数      : pstrKey       String      検索ﾌｨｰﾙﾄﾞ名
    '           : pstrKeyValue  String      検索ﾊﾟﾗﾒｰﾀ
    ' 戻り値    : なし
    ' 備考      : 
    '*******************************************************************************
    Private Sub wsSearchKey(ByRef pstrKey() As String, ByRef pstrKeyValue() As String)
        ReDim pstrKey(1)
        ReDim pstrKeyValue(1)

        pstrKey(0) = "GrNo"
        pstrKey(1) = "MoveDate"

        pstrKeyValue(0) = mstrGrNo
        pstrKeyValue(1) = mstrDate
    End Sub

    '*******************************************************************************
    ' 概要      : 現在追番検索
    ' 引数      : pExist        Boolean     存在ﾌﾗｸﾞ  
    '           : GetSeq        Integer     現在追番(0:新規)
    ' 戻り値    : Boolean       処理結果    (True:正常/False:異常)
    ' 備考      : なし
    '*******************************************************************************
    Private Function wfExistMoveSeq(ByRef pExist As Boolean, ByRef GetSeq As Integer) As Boolean
        'gstrFuncName = "wfExistMoveSeq"

        'Dim wstrKey() As String
        'Dim wstrKeyValue() As String
        'Dim wstrTblKey As String = "M_GETSEQ"
        'Dim wintRet As CommonMove.clsDBStatus.DB_STATUS

        'GetSeq = 0

        'Try
        '    '検索条件設定
        '    Call wsSearchKey(wstrKey, wstrKeyValue)

        '    '検索
        '    wintRet = gclsDB.fOpenRecord(G_CONST_TBL_MOVESEQ, G_CONST_KEY_MOVESEQKEY00, wstrTblKey, wstrKey, wstrKeyValue, BtLib.Operation.GetEqual)

        '    'ｴﾗｰの場合、処理を抜ける
        '    If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
        '        gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
        '        gintStatus = MainModule.G_ENUM_STATUS.QUIT
        '        Return False
        '    End If

        '    Try
        '        'Keyがある場合夏期休暇
        '        If wintRet <> CommonMove.clsDBStatus.DB_STATUS.GET_DATA Then Exit Try

        '        '存在ﾌﾗｸﾞをTrueに設定
        '        pExist = True

        '        'ﾃﾞｰﾀの取得
        '        GetSeq = Integer.Parse(gclsDB.Records(wstrTblKey).Item("Seq").ToString)

        '    Catch ex As Exception
        '        Throw ex
        '    Finally
        '        'ﾃｰﾌﾞﾙｸﾛｰｽﾞ
        '        gclsDB.fCloseRecord(wstrTblKey)
        '    End Try

        '    '加算
        '    GetSeq += 1

        '    Return True

        'Catch ex As Exception
        '    gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
        '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
        '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
        'End Try
    End Function

    '*******************************************************************************
    ' 概要      : 追番登録
    ' 引数      : pExist        Boolean     存在ﾌﾗｸﾞ  
    '           : GetSeq        Integer     現在追番(0:新規)
    ' 戻り値    : Boolean       処理結果    (True:正常/False:異常)
    ' 備考      : なし
    '*******************************************************************************
    Private Function wfSetMoveSeq(ByVal pExist As Boolean, ByVal GetSeq As Integer) As Boolean
        'gstrFuncName = "wfSetMoveSeq"

        'Dim wstrKey() As String
        'Dim wstrKeyValue() As String
        'Dim wstrSetKey() As String
        'Dim wstrSetKeyValue() As String
        'Dim wstrTblKey As String = "MSETKEY"
        'Dim wintRet As CommonMove.clsDBStatus.DB_STATUS

        'Try
        '    '検索条件設定
        '    Call wsSearchKey(wstrKey, wstrKeyValue)

        '    '登録データ設定
        '    Call wsSetKey(wstrSetKey, wstrSetKeyValue, GetSeq)

        '    '更新ﾃﾞｰﾀ、新規ﾃﾞｰﾀをDBに登録
        '    Select Case pExist
        '        Case True
        '            '更新
        '            wintRet = gclsDB.fUpdRecords(G_CONST_TBL_MOVESEQ, G_CONST_KEY_MOVESEQKEY00, wstrKey, wstrKeyValue, wstrSetKey, wstrSetKeyValue)
        '        Case False
        '            '新規登録
        '            wintRet = gclsDB.fInsRecord(G_CONST_TBL_MOVESEQ, wstrSetKey, wstrSetKeyValue)
        '    End Select

        '    'ｴﾗｰの場合、処理を抜ける
        '    If wintRet = CommonMove.clsDBStatus.DB_STATUS.DB_ERROR Then
        '        gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_DB, G_CONST_EMT_DB, MWA_DB_STOP, MWA_DB_OK)
        '        gintStatus = MainModule.G_ENUM_STATUS.QUIT
        '        Return False
        '    End If

        '    '戻り値Trueを返す
        '    Return True

        'Catch ex As Exception
        '    gclsPub.sErrLog(gclsPub.gAppName, gstrFuncName, ex.ToString)
        '    gfrmMain.WarpCtrl1.MessageBox(G_CONST_EMT_WARP, ex.Message, MWA_DB_STOP, MWA_DB_OK)
        '    gintStatus = MainModule.G_ENUM_STATUS.QUIT
        'End Try
    End Function

    '*******************************************************************************
    ' 概要      : 登録用パラメータ設定
    ' 引数      : pstrKey       String      検索ﾌｨｰﾙﾄﾞ名
    '           : pstrKeyValue  String      検索ﾊﾟﾗﾒｰﾀ
    '           : GetSeq        Integer     Seq
    ' 戻り値    : なし
    ' 備考      : 
    '*******************************************************************************
    Private Sub wsSetKey(ByRef pstrKey() As String, ByRef pstrKeyValue() As String, ByVal GetSeq As Integer)
        ReDim pstrKey(5)
        ReDim pstrKeyValue(5)

        pstrKey(0) = "GrNo"
        pstrKey(1) = "MoveDate"
        pstrKey(2) = "Seq"
        pstrKey(3) = "UpdateDate"
        pstrKey(4) = "UpdateTime"
        pstrKey(5) = "Filler"

        pstrKeyValue(0) = mstrGrNo
        pstrKeyValue(1) = mstrDate
        pstrKeyValue(2) = GetSeq.ToString.PadLeft(3, "0")
        pstrKeyValue(3) = DateTime.Today.ToString("yyyyMMdd")
        pstrKeyValue(4) = Now.ToString("HHmmss")
        pstrKeyValue(5) = Space(5)
    End Sub

    '*******************************************************************************
    ' 概要      : 移動番号作成
    ' 引数      : GetSeq        Integer     Seq
    ' 戻り値    : String        移動番号
    ' 備考      : 
    '*******************************************************************************
    Private Function wfCreateMoveNo(ByVal GetSeq As Integer) As String
        gstrFuncName = "wfCreateMoveNo"

        Dim wstbMoveNo As New System.Text.StringBuilder

        Try
            '移動番号作成
            wstbMoveNo.Append(gstructHtData.GrNo)
            wstbMoveNo.Append(mstrDate)
            wstbMoveNo.Append(GetSeq.ToString.PadLeft(3, "0"))

            Return wstbMoveNo.ToString

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

End Class
