' ============================================================
' Module Name: Master_245
' Module Desc: T2 master data management (245)
' Module Methods:
'   - Worksheet_Change
'   - Validate
' ============================================================

' ============================================================
' Event Handlers
' ============================================================
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim HasHeaderEdit As Boolean: HasHeaderEdit = CheckHeaderEdit(Me, Target)
    If HasHeaderEdit = True Then Exit Sub

End Sub

' 
Public Sub Validate(ws As Worksheet, ByVal rowNum As Long, ByVal lastDataRow As Long)

    Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()
    Dim sheetConf As Object: Set sheetConf = sheetConfDict(ws.CodeName)

    Dim startCol As String: startCol = sheetConf("StartCol")
    Dim endCol As String: endCol = sheetConf("EndCol")
    Dim errorCol As String: errorCol = sheetConf("ErrorCol")
    
    ' clear C~I columns background color
    Dim clearRange As Range: Set clearRange = ws.Range(ws.Cells(rowNum, startCol), ws.Cells(rowNum, endCol))
    clearRange.Interior.Color = vbWhite

    ' C column check
    checkResult = CheckRequired(ws, rowNum, 3, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckChar(ws, rowNum, 3, 3, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckAlphanumeric(ws, rowNum, 3, 3, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckDuplicate(ws, rowNum, 3, errorCol)
    If checkResult = False Then Exit Sub
    
    ' D column check
    checkResult = CheckRequired(ws, rowNum, 4, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckVarcharOver(ws, rowNum, 4, 80, errorCol)
    If checkResult = False Then Exit Sub

    ' E column check
    checkResult = CheckVarcharOver(ws, rowNum, 5, 80, errorCol)
    If checkResult = False Then Exit Sub
    
    ' F column check
    checkResult = CheckVarcharOver(ws, rowNum, 6, 80, errorCol)
    If checkResult = False Then Exit Sub
    
    ' G column check
    checkResult = Check01(ws, rowNum, 7, errorCol)
    If checkResult = False Then Exit Sub

    ' H column check number
    checkResult = CheckRequired(ws, rowNum, 8, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumber(ws, rowNum, 8, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumberOver(ws, rowNum, 8, 6, errorCol)
    If checkResult = False Then Exit Sub

    ' I column check number
    checkResult = CheckRequired(ws, rowNum, 9, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumber(ws, rowNum, 9, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumberOver(ws, rowNum, 9, 5, errorCol)
    If checkResult = False Then Exit Sub

    ' J column check number
    checkResult = CheckRequired(ws, rowNum, 10, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumber(ws, rowNum, 10, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumberOver(ws, rowNum, 10, 3, errorCol)
    If checkResult = False Then Exit Sub

    ' K column check number
    checkResult = CheckRequired(ws, rowNum, 11, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumber(ws, rowNum, 11, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumberOver(ws, rowNum, 11, 5, errorCol)
    If checkResult = False Then Exit Sub

    ' L column check number
    checkResult = CheckRequired(ws, rowNum, 12, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumber(ws, rowNum, 12, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumberOver(ws, rowNum, 12, 3, errorCol)
    If checkResult = False Then Exit Sub

    ' M column check number
    checkResult = CheckRequired(ws, rowNum, 13, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumber(ws, rowNum, 13, errorCol)
    If checkResult = False Then Exit Sub

    checkResult = CheckNumberOver(ws, rowNum, 13, 5, errorCol)
    If checkResult = False Then Exit Sub
    
    ws.Cells(rowNum, errorCol).ClearContents
End Sub
