VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Begin VB.Form DC_CarrierComp 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Carrier company maintenance"
   ClientHeight    =   8970
   ClientLeft      =   1470
   ClientTop       =   2535
   ClientWidth     =   5805
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   8970
   ScaleWidth      =   5805
   ShowInTaskbar   =   0   'False
   Begin VB.Frame frm_DC_link_detail 
      Height          =   1095
      Left            =   360
      TabIndex        =   23
      Top             =   4200
      Visible         =   0   'False
      Width           =   2655
      Begin VB.CheckBox chk_isTender 
         Caption         =   "Tender Carrier"
         Height          =   195
         Left            =   120
         TabIndex        =   25
         Top             =   600
         Width           =   2415
      End
      Begin VB.CheckBox chk_isSample 
         Caption         =   "Sample Carrier"
         Height          =   195
         Left            =   120
         TabIndex        =   24
         Top             =   240
         Width           =   2415
      End
   End
   Begin VB.CommandButton btn_delSurcharge 
      CausesValidation=   0   'False
      Height          =   612
      Left            =   165
      Style           =   1  'Graphical
      TabIndex        =   22
      Tag             =   "btn_addSurcharge"
      ToolTipText     =   "#Delete charge"
      Top             =   6780
      Width           =   612
   End
   Begin VB.CommandButton btn_addSurcharge 
      CausesValidation=   0   'False
      Height          =   612
      Left            =   825
      Style           =   1  'Graphical
      TabIndex        =   21
      Tag             =   "btn_addSurcharge"
      ToolTipText     =   "#Add charge"
      Top             =   6780
      Width           =   612
   End
   Begin VB.TextBox txt_email 
      Height          =   288
      Left            =   1575
      MaxLength       =   150
      TabIndex        =   4
      Top             =   1740
      Width           =   4092
   End
   Begin VB.TextBox txt_SAP_Code 
      Height          =   288
      Left            =   1575
      MaxLength       =   15
      TabIndex        =   5
      Top             =   2520
      Width           =   2292
   End
   Begin VB.CheckBox chk_woolCarrier 
      Alignment       =   1  'Right Justify
      Caption         =   "#Wool carrier"
      Height          =   210
      Left            =   135
      TabIndex        =   6
      Top             =   2880
      Width           =   1635
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   612
      Left            =   5100
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   8235
      Width           =   612
   End
   Begin VB.CommandButton spp_save 
      Default         =   -1  'True
      Height          =   612
      Left            =   4380
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   8235
      Width           =   612
   End
   Begin VB.TextBox txt_Fax 
      Height          =   288
      Left            =   1575
      MaxLength       =   15
      TabIndex        =   3
      Top             =   1335
      Width           =   2292
   End
   Begin VB.TextBox txt_Comments 
      Height          =   288
      Left            =   1575
      MaxLength       =   30
      TabIndex        =   2
      Top             =   945
      Width           =   4092
   End
   Begin VB.TextBox txt_CarrierCompany 
      Height          =   288
      Left            =   1575
      MaxLength       =   35
      TabIndex        =   1
      Top             =   540
      Width           =   4092
   End
   Begin VB.TextBox txt_Code 
      Height          =   288
      Left            =   1575
      MaxLength       =   10
      TabIndex        =   0
      Top             =   120
      Width           =   1452
   End
   Begin Project1.ArmCheckView ckv_dc 
      Height          =   3060
      Left            =   1560
      TabIndex        =   7
      Top             =   3255
      Width           =   4095
      _ExtentX        =   7223
      _ExtentY        =   5398
   End
   Begin Project1.ArmCheckView ckv_surcharges 
      Height          =   1650
      Left            =   1575
      TabIndex        =   20
      Top             =   6435
      Width           =   4095
      _ExtentX        =   7223
      _ExtentY        =   2910
   End
   Begin VB.Label lbl_linkedSurcharges 
      Caption         =   "#Surcharges"
      Height          =   255
      Left            =   135
      TabIndex        =   19
      Top             =   6435
      Width           =   1455
   End
   Begin MSForms.ComboBox cbo_prefLanguage 
      Height          =   315
      Left            =   1575
      TabIndex        =   18
      Top             =   2115
      Width           =   3120
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "5503;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin VB.Label lbl_preferedLanguage 
      Caption         =   "#Pref. Language"
      Height          =   255
      Left            =   135
      TabIndex        =   17
      Top             =   2145
      Width           =   1455
   End
   Begin VB.Label lbl_email 
      Caption         =   "#Email"
      Height          =   255
      Left            =   135
      TabIndex        =   16
      Top             =   1755
      Width           =   1455
   End
   Begin VB.Label lbl_SAP_Code 
      Caption         =   "SAP Code"
      Height          =   255
      Left            =   135
      TabIndex        =   15
      Top             =   2520
      Width           =   1455
   End
   Begin VB.Label lbl_DC 
      Caption         =   "#Active for DC"
      Height          =   255
      Left            =   135
      TabIndex        =   14
      Top             =   3255
      Width           =   1455
   End
   Begin VB.Label lbl_Fax 
      Caption         =   "Fax"
      Height          =   255
      Left            =   135
      TabIndex        =   13
      Top             =   1335
      Width           =   1455
   End
   Begin VB.Label lbl_Comments 
      Caption         =   "Comments"
      Height          =   255
      Left            =   135
      TabIndex        =   12
      Top             =   945
      Width           =   1455
   End
   Begin VB.Label lbl_CarrierCompany 
      Caption         =   "Carrier company"
      Height          =   255
      Left            =   135
      TabIndex        =   11
      Top             =   540
      Width           =   1455
   End
   Begin VB.Label lbl_Code 
      Caption         =   "Code"
      Height          =   255
      Left            =   135
      TabIndex        =   10
      Top             =   120
      Width           =   1455
   End
End
Attribute VB_Name = "DC_CarrierComp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const SEP1 As String = "®"
Private Const C_DC_REPORT_WOOL As String = "DC_REPORT_WOOL"


Private Const C_DCS_CODE_IDX As Long = 0
Private Const C_DCS_DESC_IDX As Long = 1
Private Const C_DCS_LINKED_IDX As Long = 2

Private mo_ChargeDlg As DC_SurchargeDetail

Private msa_updatedDC() As String
Private ml_updatedDCMax As Long

Private Sub btn_delSurcharge_Click()
On Error GoTo errhandler

    If ckv_surcharges.SelectedItem Is Nothing Then Exit Sub
    
    Dim lo_ItemInfo As ArmItemInfo
    Set lo_ItemInfo = ckv_surcharges.SelectedItem.Tag
    
    If lo_ItemInfo.GetData(C_DCS_LINKED_IDX) > 0 _
            Then
        ' display warning that item cannot be unchecked because it is ussed on some trasaction
        Call MsgBox("Item cannot be deleted as it is ussed on some transport!")
        Exit Sub
    End If

    Call mo_ChargeDlg.Run(lo_ItemInfo.GetData(C_DCS_CODE_IDX), _
                            lo_ItemInfo.GetData(C_DCS_LINKED_IDX), "D")
                            
    If mo_ChargeDlg.Result Then
        ' delete a line from the checkview
        ckv_surcharges.LoadEditLists
        ckv_surcharges.LoadList
        Call lo_ItemInfo.CheckList.DisplayList
    End If

    Exit Sub
errhandler:
'     Call ErrorMessage("btn_delSurcharge_Click()")
End Sub

Private Sub cbo_prefLanguage_DropButtonClick()
    MouseOff
    If cbo_prefLanguage.Tag = UNLOADED Then
        Dim as_oldLang As String
        as_oldLang = MCombo_GetCode(cbo_prefLanguage)
        cbo_prefLanguage.Clear
        MCombo_Fill cbo_prefLanguage, "EXEC Language_cbo"
        MCombo_CodeSelect(cbo_prefLanguage) = as_oldLang
        cbo_prefLanguage.Tag = Loaded
    End If
    MouseOn
End Sub

Private Sub btn_addSurcharge_Click()
On Error GoTo errhandler
    Call mo_ChargeDlg.Run("", 0, "A")
                            
    If mo_ChargeDlg.Result Then
        ' add iteminfo offline
        Call ckv_surcharges.RoleList("MAIN").AddItemInfo(Array(mo_ChargeDlg.DCS_Code, mo_ChargeDlg.DCS_Desc), False, True)
        Call ckv_surcharges.RoleList("EDIT").AddItemInfo(Array(mo_ChargeDlg.DCS_Code, mo_ChargeDlg.DCS_Desc, 0), False, True)
        
        Call ckv_surcharges.RoleList("EDIT").DisplayList
    End If
    Exit Sub
errhandler:
'     Call ErrorMessage("btn_addSurcharge_Click()")
End Sub

Private Sub chk_isSample_Click()
On Error GoTo ErrHandler
    If ckv_dc.SelectedItem Is Nothing Then Exit Sub
    
        Dim lo_selData As ArmItemInfo
    Set lo_selData = ckv_dc.SelectedItem.Tag
    
    Call lo_selData.SetData(2, IIf(chk_isSample.Value = 0, "", "x"))
    
    ckv_dc.SelectedItem.ListSubItems(1).Text = lo_selData.GetData(2)
    
    If lo_selData.GetData(4) <> "0" Then
        AddToUpdateDC (lo_selData.GetData(0))
    End If
    
    
    Exit Sub
ErrHandler:
'     Call ErrorMessage("chk_isSample_Click()")
End Sub

Private Sub chk_isTender_Click()
On Error GoTo ErrHandler
    If ckv_dc.SelectedItem Is Nothing Then Exit Sub
    
    Dim lo_selData As ArmItemInfo
    Set lo_selData = ckv_dc.SelectedItem.Tag
    
    Call lo_selData.SetData(3, IIf(chk_isTender.Value = 0, "", "x"))
    
    ckv_dc.SelectedItem.ListSubItems(2).Text = lo_selData.GetData(3)
    
    If lo_selData.GetData(4) <> "0" Then
        AddToUpdateDC (lo_selData.GetData(0))
    End If
    
    Exit Sub
ErrHandler:
'     Call ErrorMessage("chk_isTender_Click()")
End Sub

Private Sub ckv_dc_DblClick()
On Error GoTo ErrHandler
    If ckv_dc.SelectedItem Is Nothing Then Exit Sub
    
    If Not ckv_dc.SelectedItem.Checked Then Exit Sub
    
    ' load data into detail form
    Dim lo_selData As ArmItemInfo
    Set lo_selData = ckv_dc.SelectedItem.Tag

    
    
    chk_isSample.Value = IIf(lo_selData.GetData(2) = "", 0, 1)
    chk_isTender.Value = IIf(lo_selData.GetData(3) = "", 0, 1)
    
    ' display edit form
    frm_DC_link_detail.Top = ckv_dc.SelectedItem.Top + ckv_dc.Top + ckv_dc.SelectedItem.Height
    frm_DC_link_detail.Left = ckv_dc.SelectedItem.Left + ckv_dc.Left + 10
    frm_DC_link_detail.Width = ckv_dc.SelectedItem.Width - 10
    
    frm_DC_link_detail.Visible = True
    chk_isSample.SetFocus
    
    Exit Sub
ErrHandler:
'     Call ErrorMessage("ckv_dc_DblClick()")
End Sub

Private Sub ckv_dc_ItemClick(ByVal Item As MSComctlLib.ListItem)
    ' hide edit form
    frm_DC_link_detail.Visible = False
End Sub

Private Sub ckv_dc_LostFocus()
    If Me.ActiveControl Is Nothing Then Exit Sub
    
    If Left(Me.ActiveControl.Name, 6) = "chk_is" Then Exit Sub
    
    ' hide edit form
    frm_DC_link_detail.Visible = False
End Sub

Private Sub ckv_surcharges_DblClick()
On Error GoTo errhandler
    
'    If gs_Action <> "Add" And gs_Action <> "Update" Then Exit Sub
    
    If Not ckv_surcharges.SelectedItem Is Nothing Then
    
        Dim lo_ItemInfo As ArmItemInfo
        ' find the record in edit echek list
        Set lo_ItemInfo = ckv_surcharges.RoleList("EDIT").GetItem(ckv_surcharges.SelectedItem.Tag.CheckList.GetItemKey(ckv_surcharges.SelectedItem.Tag))
        
        If lo_ItemInfo.CurrentChecked Then
            
            Call mo_ChargeDlg.Run(lo_ItemInfo.GetData(C_DCS_CODE_IDX), _
                                    lo_ItemInfo.GetData(C_DCS_LINKED_IDX), _
                                    IIf(gs_Action = "Add" Or gs_Action = "Update", "U", "V"))
                                    
            If mo_ChargeDlg.Result Then
                Call lo_ItemInfo.SetData(C_DCS_DESC_IDX, mo_ChargeDlg.DCS_Desc)
                
                ' update main rolelist items
                Dim lo_infoMain As ArmItemInfo
                Set lo_infoMain = lo_ItemInfo.CheckList.ViewCheckList.GetItem(lo_ItemInfo.CheckList.GetItemKey(lo_ItemInfo))
                
                ' if it exists in view rolelist
                If Not lo_infoMain Is Nothing Then
                    Call lo_infoMain.SetData(C_DCS_DESC_IDX, mo_ChargeDlg.DCS_Desc)
                End If
            
                Call lo_ItemInfo.CheckList.DisplayList
            End If
            
        End If
        
    End If
    
    Exit Sub
errhandler:
'     Call ErrorMessage("ckv_surcharges_DblClick()")

End Sub

Private Sub ckv_surcharges_ItemCheck(ByVal Item As MSComctlLib.ListItem)
On Error GoTo errhandler

MouseOff
    Dim lo_ItemInfo As ArmItemInfo
    Set lo_ItemInfo = Item.Tag
    
    If Not lo_ItemInfo.CurrentChecked And _
            lo_ItemInfo.GetData(C_DCS_LINKED_IDX) > 0 _
            Then
        ' display warning that item cannot be unchecked because it is ussed on some trasaction
        Call MsgBox("Item cannot be unchecked as it is ussed on some transport!")
        Call ckv_surcharges.SetItemState(lo_ItemInfo.CheckList.Name, lo_ItemInfo.CheckList.GetItemKey(lo_ItemInfo), True)
    End If

MouseOn
Exit Sub

errhandler:
StdError

End Sub

Private Sub ckv_surcharges_ItemClick(ByVal Item As MSComctlLib.ListItem)
On Error GoTo errhandler

MouseOff

    Call SurchargeDeleteEnable
    
MouseOn
Exit Sub

errhandler:
StdError

End Sub

Private Sub SurchargeDeleteEnable()
    
    If ckv_surcharges.SelectedItem Is Nothing Then
        btn_delSurcharge.Enabled = False
        Exit Sub
    End If
    
    btn_delSurcharge.Enabled = (ckv_surcharges.SelectedItem.Tag.GetData(C_DCS_LINKED_IDX) = 0)
    
End Sub

Private Sub Form_Load()

On Error GoTo suite

MouseOff

If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

spp_save.Picture = LoadResPicture(RES_OK, 1)
ssp_quit.Picture = LoadResPicture(RES_QUIT, 1)
btn_addSurcharge.Picture = LoadResPicture(RES_ADD, 1)
btn_delSurcharge.Picture = LoadResPicture(RES_DELETE, 1)

    Set mo_ChargeDlg = New DC_SurchargeDetail
    Set mo_ChargeDlg.ArmDb = aDb
    mo_ChargeDlg.U_Code = prg.U_Code
    mo_ChargeDlg.LoginName = prg.LoginName
    mo_ChargeDlg.Language_Code = gut_LangLogin.Code
    Call mo_ChargeDlg.SetReconnectParams(prg.CurrentServerIP & prg.ServerInstance, prg.DBName, prg.LoginName, prg.U_PWD, prg.ApplicationName & prg.ApplicationVersion & "- DC_Surcharge")
    
    Call mo_ChargeDlg.Load_A_COM
    
    Set ckv_dc.ArmDb = aDb
    ckv_dc.Driven_By = "DC_Carrier"
    
    Set ckv_surcharges.ArmDb = aDb
    ckv_surcharges.Driven_By = "DC_Carrier"

    mtnc_CarrierCompany_cst

    cbo_prefLanguage.Tag = UNLOADED
    
    ckv_dc.Common_List_Load = True
    ckv_dc.Type_Of_Key = tkDependant
    ckv_dc.Calling_Key_Fields = "CARRIER_Code"
    ckv_dc.Link_Key_Fields = "DC_Code"
    Call ckv_dc.Load_A_COM

    ckv_surcharges.Common_List_Load = True
    ckv_surcharges.Type_Of_Key = tkDependant
    ckv_surcharges.Calling_Key_Fields = "CARRIER_Code"
    ckv_surcharges.Link_Key_Fields = "DCS_Code"
    Call ckv_surcharges.Load_A_COM

If gs_Action <> "Add" Then
    txt_Code = gs_TableCode
    txt_CarrierCompany = gs_TableCode3
    txt_Comments = gs_TableCode4
    txt_Fax = gs_TableCode5
    txt_SAP_Code = gs_TableCode6
    txt_email = gs_TableCode7
    MCombo_AddItemCode cbo_prefLanguage, gs_TableCode8, gs_TableCode9
    txt_Code.Enabled = KO
    If gs_Action = "Delete" Then
        txt_CarrierCompany.Enabled = KO
        txt_Comments.Enabled = KO
        txt_Fax.Enabled = KO
        txt_email.Enabled = KO
        cbo_prefLanguage.Enabled = KO
        txt_SAP_Code.Enabled = KO
        chk_woolCarrier.Enabled = KO
        btn_addSurcharge.Enabled = KO
    End If
    
    If Get_A_Config(C_DC_REPORT_WOOL) Like "*" & SEP1 & Trim(gs_TableCode) & SEP1 & "*" Then
        chk_woolCarrier.Value = vbChecked
    End If

    ckv_dc.Calling_Key_Values = gs_TableCode
    Call InitDC
    Call ckv_dc.LoadList
    
    ' init array of updated records
    If ckv_dc.CheckedCount("MAIN") > 0 Then
        ReDim msa_updatedDC(ckv_dc.CheckedCount("MAIN") - 1) As String
        ml_updatedDCMax = -1
    Else
        ReDim msa_updatedDC(-1 To -1) As String
        ml_updatedDCMax = -1
    End If
    
    ckv_surcharges.Calling_Key_Values = gs_TableCode
    Call InitCharges
    Call ckv_surcharges.LoadList
Else
    ckv_dc.Calling_Key_Values = ""
    Call InitDC
    
    ckv_surcharges.Calling_Key_Values = ""
    Call InitCharges
End If

    If gs_Action = "Add" Or gs_Action = "Update" Then
        Call ckv_dc.SetVisibleList("EDIT")
        Call ckv_surcharges.SetVisibleList("EDIT")
    Else
        Call ckv_dc.SetVisibleList("MAIN")
        Call ckv_surcharges.SetVisibleList("MAIN")
    End If
    
    Call SurchargeDeleteEnable


MouseOn
Exit Sub

suite:
StdError
End Sub


Private Sub Form_Unload(Cancel As Integer)
On Error GoTo errhandler

    If Not mo_ChargeDlg Is Nothing Then
        Unload mo_ChargeDlg
        Set mo_ChargeDlg = Nothing
    End If
    
    Exit Sub
errhandler:
'    Call ErrorHandler("Form_Unload")
End Sub

Private Sub spp_save_Click()

MouseOff
gb_Return = OK
Select Case gs_Action
Case "Add":
    If Add_Table Then
        txt_Code = ""
        txt_CarrierCompany = ""
        txt_Comments = ""
        txt_Fax = ""
        ckv_dc.Calling_Key_Values = ""
        Call InitDC
        
        ckv_surcharges.Calling_Key_Values = ""
        Call InitCharges
        
        Call ckv_dc.SetVisibleList("EDIT")
        Call ckv_surcharges.SetVisibleList("EDIT")
        
        frm_DC_link_detail.Visible = False
        
        txt_Code.SetFocus
        If gl_NbLineDisplay < 2 Then
            C_main.FillGrid
        End If
    End If
Case "Update":
    If Upd_Table Then
        Unload Me
        Exit Sub
    End If
Case "Delete":
    If Dlt_Table Then
        Unload Me
        Exit Sub
    End If
End Select
MouseOn

End Sub

Private Sub ssp_quit_Click()
MouseOff
Unload Me
End Sub



Private Function Control() As Boolean

    Control = KO
    If txt_Code = "" Then
        txt_Code.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Exit Function
    End If
    
    If txt_CarrierCompany = "" Then
        txt_CarrierCompany.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Exit Function
    End If

    If cbo_prefLanguage.ListIndex = -1 Then
        cbo_prefLanguage.SetFocus
        SendMessage 14, " Value must exist in the list", gut_LangLogin.Code, vbExclamation
        Exit Function
    End If

    Control = OK

End Function

Private Sub mtnc_CarrierCompany_cst()
Dim ls_Field As String, ls_Text As String
Dim ll_Statement As Long
Dim li_Status As Integer

On Error GoTo suite

If SQLSubmit(gl_Environment, gl_Database, ll_Statement, gs_ParamReqCsts) Then
    li_Status = SQL_SUCCESS
Else
    li_Status = SQL_ERROR
End If
Do While li_Status = SQL_SUCCESS Or _
         li_Status = SQL_SUCCESS_WITH_INFO
    li_Status = SQLFetch(ll_Statement)
    If li_Status = SQL_SUCCESS Or _
       li_Status = SQL_SUCCESS_WITH_INFO Then
        ls_Field = ODBCData(ll_Statement, 1)
        ls_Text = Left(ODBCData(ll_Statement, 2), 30)
        Select Case ls_Field
            Case "lbl_code": lbl_Code = ls_Text
            Case "lbl_car": lbl_CarrierCompany = ls_Text
            Case "lbl_com": lbl_Comments = ls_Text
            Case "lbl_fax": lbl_Fax = ls_Text
            Case "lbl_email": lbl_email = ls_Text
            Case "lbl_preferedLanguage": lbl_preferedLanguage.Caption = ls_Text
            Case "lbl_SAP_Code": lbl_SAP_Code = ls_Text
            Case "title": Caption = ls_Text
            Case "titleA": If gs_Action = "Add" Then Caption = Caption & " - " & ls_Text
            Case "titleU": If gs_Action = "Update" Then Caption = Caption & " - " & ls_Text
            Case "titleD": If gs_Action = "Delete" Then Caption = Caption & " - " & ls_Text
            Case "chk_woolCarrier": chk_woolCarrier.Caption = ls_Text
            Case "lbl_DC": lbl_DC.Caption = ls_Text
            Case "lbl_linkedSurcharges": lbl_linkedSurcharges.Caption = ls_Text
            Case "btn_delSurcharge": btn_delSurcharge.ToolTipText = ls_Text
            Case "btn_addSurcharge": btn_addSurcharge.ToolTipText = ls_Text
            Case "spp_save": spp_save.ToolTipText = ls_Text
            Case "ssp_quit": ssp_quit.ToolTipText = ls_Text
        End Select
    End If
Loop
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
Exit Sub

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError

End Sub

Private Function Add_Table() As Boolean
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_Code As String
Dim ls_Line As String
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String

On Error GoTo suite

Add_Table = KO

If Control Then
    ls_req = gs_ParamReqIns & " '" & QuoteParam(txt_Code) & "', '" _
             & QuoteParam(txt_CarrierCompany) & "', '" _
             & QuoteParam(txt_Comments) & "', '" _
             & QuoteParam(txt_Fax) & "', '" _
             & QuoteParam(txt_SAP_Code) & "', '" _
             & QuoteParam(txt_email) & "', '" _
             & MCombo_GetCode(cbo_prefLanguage) & "'"

    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        If ll_lngrows = 0 Then
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            SendMessage 4, "Insert failed", gut_LangLogin.Code
            C_main.FillGrid
        Else
            ckv_dc.Calling_Key_Values = Trim(txt_Code)
            Call ckv_dc.SaveList
            
            ckv_surcharges.Calling_Key_Values = Trim(txt_Code)
            Call ckv_surcharges.SaveList
            
            If chk_woolCarrier.Value = vbChecked Then
                
                Dim ls_CFG_Value As String
                ls_CFG_Value = Get_A_Config(C_DC_REPORT_WOOL)
                
                If right(ls_CFG_Value, 1) <> SEP1 Then ls_CFG_Value = ls_CFG_Value & SEP1
                If Left(ls_CFG_Value, 1) <> SEP1 Then ls_CFG_Value = SEP1 & ls_CFG_Value
                ls_CFG_Value = Replace(ls_CFG_Value, SEP1 & SEP1, SEP1)
                
                If Not (ls_CFG_Value Like "*" & SEP1 & Trim(txt_Code) & SEP1 & "*") Then
                    ls_CFG_Value = ls_CFG_Value & Trim(txt_Code) & SEP1
                    
                    Call Set_A_Config(C_DC_REPORT_WOOL, ls_CFG_Value)
                End If
                
            End If
            Add_Table = OK
            ' Find the code
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                ls_Code = ODBCData(ll_Statement, 1)
            End If
            ls_Line = txt_Code & Chr(9) & 1 & Chr(9) & txt_CarrierCompany & Chr(9) & txt_Comments & Chr(9) & txt_Fax & Chr(9) & txt_SAP_Code & Chr(9) & txt_email & Chr(9) & MCombo_GetCode(cbo_prefLanguage) & Chr(9) & cbo_prefLanguage.Text
            C_main.Grid.AddItem ls_Line
            C_main.Grid.Row = C_main.Grid.Rows - 1
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        End If
    Else
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            SendMessage 4, "Insert failed", gut_LangLogin.Code
    End If
End If
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError

End Function

Private Function Dlt_Table() As Boolean

Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long

Dlt_Table = KO

On Error GoTo suite

MouseOn
If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbYes Then
    MouseOff
    
    If aDb.ExecuteSQL("DELETE FROM DC_Carrier_link WHERE CARRIER_Code='" & gs_TableCode & "'") Then
    
        ls_req = gs_ParamReqDel & " '" _
                & QuoteParam(gs_TableCode) & "', " _
                & gs_TableCode2
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
            li_Status = SQLRowCount(ll_Statement, ll_lngrows)
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            If ll_lngrows = 0 Then
                SendMessage 7, "Delete failed : concurrency problem ?", gut_LangLogin.Code
                C_main.FillGrid
            Else
                
                Dim ls_CFG_Value As String
                ls_CFG_Value = Get_A_Config(C_DC_REPORT_WOOL)
                
                If right(ls_CFG_Value, 1) <> SEP1 Then ls_CFG_Value = ls_CFG_Value & SEP1
                If Left(ls_CFG_Value, 1) <> SEP1 Then ls_CFG_Value = SEP1 & ls_CFG_Value
                ls_CFG_Value = Replace(ls_CFG_Value, SEP1 & SEP1, SEP1)
                
                If ls_CFG_Value Like "*" & SEP1 & Trim(txt_Code) & SEP1 & "*" Then
                    ls_CFG_Value = Replace(ls_CFG_Value, SEP1 & Trim(txt_Code) & SEP1, SEP1)
                    
                    Call Set_A_Config(C_DC_REPORT_WOOL, ls_CFG_Value)
                End If
    
                Dlt_Table = OK
                C_main.Grid.RemoveItem C_main.Grid.Row
            End If
        Else
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            SendMessage 6, "Delete failed ", gut_LangLogin.Code
        End If
    Else
        SendMessage 6, "Delete failed ", gut_LangLogin.Code
        C_main.FillGrid
    End If
End If
MouseOff
Exit Function

suite:
Select Case Err
Case 30015
    C_main.FillGrid
Case Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Select
End Function

Private Function Upd_Table()

Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_Line As String
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String

Upd_Table = KO

On Error GoTo suite

If Control Then
   ls_req = gs_ParamReqUpd & " '" _
            & QuoteParam(gs_TableCode) & "', " _
            & gs_TableCode2 & ", '" _
            & QuoteParam(txt_CarrierCompany) & "', '" _
            & QuoteParam(txt_Comments) & "', '" _
            & QuoteParam(txt_Fax) & "', '" _
            & QuoteParam(txt_SAP_Code) & "', '" _
            & QuoteParam(txt_email) & "', '" _
            & MCombo_GetCode(cbo_prefLanguage) & "'"


    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        If ll_lngrows = 0 Then
            SendMessage 2, "Another user change the record", gut_LangLogin.Code
            C_main.FillGrid
        Else
        
            ' delete/insert
            Call ckv_dc.SaveList
            'update
            Dim ll_i As Long
            Dim ll_y As Long
            Dim lsa_checkedKeys As Variant
            
            lsa_checkedKeys = ckv_dc.CheckedKeys("EDIT")
            For ll_i = 0 To ml_updatedDCMax
                ' if checked
                For ll_y = 0 To UBound(lsa_checkedKeys)
                    If lsa_checkedKeys(ll_y)(0) = msa_updatedDC(ll_i) Then
                        ' save it
                        
                        ls_req = Replace(ckv_dc.RoleList("EDIT").RequestCheck, "$CARRIER_Code$", gs_TableCode, , , vbTextCompare)
                        ls_req = Replace(ls_req, "$DC_Code$", lsa_checkedKeys(ll_y)(0), , , vbTextCompare)
                        ls_req = Replace(ls_req, "$isSampleCarrier$", lsa_checkedKeys(ll_y)(1), , , vbTextCompare)
                        ls_req = Replace(ls_req, "$isTenderCarrier$", lsa_checkedKeys(ll_y)(2), , , vbTextCompare)
                        
                        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
                            li_Status = SQLRowCount(ll_Statement, ll_lngrows)
                            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
                            If ll_lngrows = 0 Then
                                SendMessage 666, "DC row not updated", gut_LangLogin.Code
                            End If
                        Else
                            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
                            SendMessage 666, "Update DC failed", gut_LangLogin.Code
                            Exit Function
                        End If
                        
                    End If
                Next
            Next
            
            Call ckv_surcharges.SaveList
            
            Dim ls_CFG_Value As String
            ls_CFG_Value = Get_A_Config(C_DC_REPORT_WOOL)
            
            If right(ls_CFG_Value, 1) <> SEP1 Then ls_CFG_Value = ls_CFG_Value & SEP1
            If Left(ls_CFG_Value, 1) <> SEP1 Then ls_CFG_Value = SEP1 & ls_CFG_Value
            ls_CFG_Value = Replace(ls_CFG_Value, SEP1 & SEP1, SEP1)
            
            If chk_woolCarrier.Value = vbChecked Then
                
                If Not (ls_CFG_Value Like "*" & SEP1 & Trim(txt_Code) & SEP1 & "*") Then
                    ls_CFG_Value = ls_CFG_Value & Trim(txt_Code) & SEP1
                    
                    Call Set_A_Config(C_DC_REPORT_WOOL, ls_CFG_Value)
                End If
            Else
                If ls_CFG_Value Like "*" & SEP1 & Trim(txt_Code) & SEP1 & "*" Then
                    ls_CFG_Value = Replace(ls_CFG_Value, SEP1 & Trim(txt_Code) & SEP1, SEP1)
                    
                    Call Set_A_Config(C_DC_REPORT_WOOL, ls_CFG_Value)
                End If
            End If

            Upd_Table = OK
            C_main.Grid.RemoveItem C_main.Grid.Row
            ls_Line = gs_TableCode & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & txt_CarrierCompany & Chr(9) & txt_Comments & Chr(9) & txt_Fax & Chr(9) & txt_SAP_Code & Chr(9) & txt_email & Chr(9) & MCombo_GetCode(cbo_prefLanguage) & Chr(9) & cbo_prefLanguage.Text
            C_main.Grid.AddItem ls_Line, C_main.Grid.Row
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 3, "Update failed", gut_LangLogin.Code
    End If
End If
Exit Function

suite:
Select Case Err
Case 30015
    C_main.FillGrid
Case Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Select
End Function


Private Sub InitDC()
    
    On Error GoTo Trace_Err
    
    ckv_dc.RoleCount = 2
    
    Dim la_DC_RoleMain As Variant, la_DC_RoleEdit As Variant
    
    la_DC_RoleMain = Array("MAIN", "VIEW", "", "", "Main view", "DC_Code®©DC_desc®©isSampleCarrier®©isTenderCarrier®©DC_CARRIER_Code", "DC_desc®©isSampleCarrier®©isTenderCarrier", "2000®©700®©700", "DC_code®©isSampleCarrier®©isTenderCarrier®©DC_CARRIER_Code", "exec DC_Carrier_Link_lst '$CARRIER_Code$','" & gut_LangLogin.Code & "'", "exec DC_Carrier_Link_Ins '$CARRIER_Code$','$DC_Code$', '$isSampleCarrier$', '$isTenderCarrier$'", "exec DC_Carrier_Link_Del '$CARRIER_Code$','$DC_Code$'", True, 2, False, True, 0, 0)
    la_DC_RoleEdit = Array("EDIT", "EDIT", "", "", "Edit view", "DC_Code®©DC_desc®©isSampleCarrier®©isTenderCarrier®©DC_CARRIER_Code", "DC_desc®©isSampleCarrier®©isTenderCarrier", "2000®©700®©700", "DC_code®©isSampleCarrier®©isTenderCarrier®©DC_CARRIER_Code", "exec DC_Carrier_Link_lst2 '$CARRIER_Code$', '" & gut_LangLogin.Code & "'", "exec DC_Carrier_Link_Ins '$CARRIER_Code$','$DC_Code$', '$isSampleCarrier$', '$isTenderCarrier$'", "exec DC_Carrier_Link_Del '$CARRIER_Code$','$DC_Code$'", False, 2, False, True, 3, 0)
  
    If Not ckv_dc.SetRoleList(Array(la_DC_RoleMain, la_DC_RoleEdit)) Then
        Call SendMessage(932, "#Critical error, please contact it", gut_LangLogin.Code)
        End
    End If
    
    ckv_dc.Synchronize_View = False
    ckv_dc.HideColumnHeaders = False
    ckv_dc.LoadConstants CVptStatic, "DC_desc" & CH_LDELIMIT & "DC" & CH_LDELIMIT & "isSampleCarrier" & CH_LDELIMIT & "Sample" & CH_LDELIMIT & "isTenderCarrier" & CH_LDELIMIT & "Tender", CVctColumns
    
Trace_End:
    CapMouseOn
    Exit Sub
    
Trace_Err:
    CapMouseOn
    StdError
End Sub

Private Sub InitCharges()
    
    On Error GoTo Trace_Err
    
    ckv_surcharges.RoleCount = 2
    
    Dim la_DC_RoleMain As Variant, la_DC_RoleEdit As Variant
    
    la_DC_RoleMain = Array("MAIN", "VIEW", "", "", "Main view", "DCS_Code®©DCS_desc", "DCS_desc", "3000", "DCS_code", "exec DC_Surcharge_lst '$CARRIER_Code$','" & gut_LangLogin.Code & "'", "exec DC_Surcharge_chck '$DCS_Code$', '$CARRIER_Code$'", "exec DC_Surcharge_chck '$DCS_Code$', NULL", True, 2, False, False, 0, 0)
    la_DC_RoleEdit = Array("EDIT", "EDIT", "", "", "Edit view", "DCS_Code®©DCS_desc®©linkedCount", "DCS_desc", "3000", "DCS_code", "exec DC_Surcharge_lst2 '$CARRIER_Code$', '" & gut_LangLogin.Code & "'", "exec DC_Surcharge_chck '$DCS_Code$', '$CARRIER_Code$'", "exec DC_Surcharge_chck '$DCS_Code$', NULL", False, 2, False, False, 3, 0)
  
    If Not ckv_surcharges.SetRoleList(Array(la_DC_RoleMain, la_DC_RoleEdit)) Then
        Call SendMessage(932, "#Critical error, please contact it", gut_LangLogin.Code)
        End
    End If
    
    ckv_surcharges.Synchronize_View = False
    ckv_surcharges.HideColumnHeaders = False
    ckv_surcharges.LoadConstants CVptStatic, "DCS_desc" & CH_LDELIMIT & "Surcharge", CVctColumns
    
Trace_End:
    CapMouseOn
    Exit Sub
    
Trace_Err:
    CapMouseOn
    StdError
End Sub



Private Function Get_A_Config(ByVal TheKey As String) As String
On Error GoTo Get_A_Config_er
Dim curs As Long
Dim ls_req As String

    Get_A_Config = ""
    ls_req = "select cfg_value from A_config where cfg_Key ='" & UCase(TheKey) & "'"
    curs = aDb.OpenSQL(ls_req)
    
    Get_A_Config = aDb.GetFields(curs, 0)
    Call aDb.Close(curs)
    curs = 0
    
Exit Function
Get_A_Config_er:
    If curs > 0 Then
        Call aDb.Close(curs)
        curs = 0
    End If
    StdError
End Function

Private Sub Set_A_Config(ByVal TheKey As String, ByVal TheValue As String)
On Error GoTo Set_A_Config
Dim ls_req As String

    ls_req = "UPDATE A_config SET cfg_value='" & QuoteParam(TheValue) & "' where cfg_Key ='" & UCase(TheKey) & "'"
    aDb.ExecuteSQL (ls_req)
    
Exit Sub
Set_A_Config:
    StdError
End Sub

Private Sub AddToUpdateDC(ByVal as_DC_Code As String)
    On Error GoTo ErrHandler
    
    Dim ll_i As Long
    
    For ll_i = 0 To ml_updatedDCMax
        If msa_updatedDC(ll_i) = as_DC_Code Then
            Exit Sub
        End If
    Next
    
    ' add item
    Debug.Assert (ml_updatedDCMax + 1 <= UBound(msa_updatedDC))
    
    ml_updatedDCMax = ml_updatedDCMax + 1
    msa_updatedDC(ml_updatedDCMax) = as_DC_Code
    
    Exit Sub
ErrHandler:
End Sub


