VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.UserControl EAS_Viewer 
   ClientHeight    =   12375
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   15840
   ScaleHeight     =   12375
   ScaleWidth      =   15840
   Begin VB.Frame fra_DetailItem 
      Height          =   4935
      Index           =   6
      Left            =   11640
      TabIndex        =   182
      Tag             =   "EAS_AdminCustomer"
      Top             =   5265
      Visible         =   0   'False
      Width           =   3840
      Begin VB.TextBox txt_CT_Desc 
         Height          =   315
         Index           =   6
         Left            =   705
         TabIndex        =   131
         Tag             =   "CT_Desc"
         Top             =   1965
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CT_Code 
         Height          =   315
         Index           =   6
         Left            =   210
         TabIndex        =   130
         Tag             =   "CT_Code"
         Top             =   1965
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   6
         Left            =   4665
         TabIndex        =   125
         Tag             =   "DocTypeDesc"
         Top             =   1020
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   6
         Left            =   4200
         TabIndex        =   124
         Tag             =   "DocType"
         Top             =   1035
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_CCU_Desc 
         Height          =   345
         Index           =   6
         Left            =   3360
         MaxLength       =   80
         TabIndex        =   128
         Tag             =   "CCU_Desc"
         Top             =   1425
         Width           =   5820
      End
      Begin VB.CommandButton cmd_CustomerSeek 
         Caption         =   "..."
         Height          =   360
         Index           =   6
         Left            =   9180
         TabIndex        =   129
         Top             =   1410
         Width           =   405
      End
      Begin VB.TextBox txt_Cust_Code 
         Height          =   345
         Index           =   6
         Left            =   1650
         TabIndex        =   127
         Tag             =   "Cust_Code"
         Top             =   1425
         Width           =   1650
      End
      Begin VB.TextBox txt_CCU_Capkey 
         Height          =   345
         Index           =   6
         Left            =   1035
         TabIndex        =   126
         Tag             =   "CCU_Capkey"
         Top             =   1410
         Visible         =   0   'False
         Width           =   405
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   6
         Left            =   1650
         TabIndex        =   236
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.TextBox txt_DroppedPageNr 
            Height          =   315
            Index           =   6
            Left            =   915
            TabIndex        =   133
            Tag             =   "DroppedPageNr"
            Top             =   165
            Visible         =   0   'False
            Width           =   660
         End
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   6
            Left            =   90
            TabIndex        =   237
            Top             =   165
            Width           =   6990
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   6
               Left            =   1530
               TabIndex        =   140
               Tag             =   "FileName"
               Top             =   1920
               Width           =   4995
            End
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   6
               Left            =   6525
               TabIndex        =   141
               Top             =   1905
               Width           =   345
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   6
               Left            =   1545
               TabIndex        =   134
               Tag             =   "ZipTableIndex"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   6
               Left            =   6150
               TabIndex        =   136
               Tag             =   "Status"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   6
               Left            =   1530
               TabIndex        =   139
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   6
               Left            =   1530
               TabIndex        =   138
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   6
               Left            =   1545
               TabIndex        =   137
               Tag             =   "UserName"
               Top             =   750
               Width           =   5325
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   6
               Left            =   1530
               TabIndex        =   135
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   6
               Left            =   30
               TabIndex        =   132
               Tag             =   "PageId"
               Top             =   0
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   70
               Left            =   165
               TabIndex        =   268
               Tag             =   "lbl_FileName"
               Top             =   1980
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   54
               Left            =   4785
               TabIndex        =   242
               Tag             =   "lbl_Status"
               Top             =   435
               Width           =   1230
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   53
               Left            =   165
               TabIndex        =   241
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   52
               Left            =   165
               TabIndex        =   240
               Tag             =   "lbl_NetworkBoard"
               Top             =   1200
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   51
               Left            =   165
               TabIndex        =   239
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   50
               Left            =   150
               TabIndex        =   238
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   6
            Left            =   150
            TabIndex        =   243
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   6
            Left            =   7170
            TabIndex        =   244
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   330
         Index           =   6
         Left            =   1635
         MaxLength       =   6
         TabIndex        =   123
         Tag             =   "ACU_Id"
         Top             =   1035
         Width           =   1650
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   6
         Left            =   8145
         TabIndex        =   183
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   6
         Left            =   135
         TabIndex        =   184
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   61
         Left            =   3390
         TabIndex        =   255
         Tag             =   "lbl_DocType"
         Top             =   1095
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Customer"
         Height          =   255
         Index           =   57
         Left            =   105
         TabIndex        =   248
         Tag             =   "lbl_Customer"
         Top             =   1485
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   15
         Left            =   90
         TabIndex        =   185
         Tag             =   "lbl_Code"
         Top             =   1080
         Width           =   1215
      End
   End
   Begin VB.Frame fra_DetailItem 
      Height          =   4995
      Index           =   5
      Left            =   7740
      TabIndex        =   177
      Tag             =   "EAS_OfficeInvoice"
      Top             =   5085
      Visible         =   0   'False
      Width           =   3660
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   5
         Left            =   4785
         TabIndex        =   109
         TabStop         =   0   'False
         Tag             =   "DocTypeDesc"
         Top             =   1035
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   5
         Left            =   4335
         TabIndex        =   108
         TabStop         =   0   'False
         Tag             =   "DocType"
         Top             =   1050
         Visible         =   0   'False
         Width           =   360
      End
      Begin Project1.ArmCombobox cbo_OFI_Country 
         Height          =   345
         Left            =   1635
         TabIndex        =   110
         Tag             =   "CT_Code®©CT_Desc"
         Top             =   1425
         Width           =   7905
         _ExtentX        =   13944
         _ExtentY        =   609
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   5
         Left            =   1650
         TabIndex        =   227
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.TextBox txt_DroppedPageNr 
            Height          =   315
            Index           =   5
            Left            =   885
            TabIndex        =   114
            Tag             =   "DroppedPageNr"
            Top             =   150
            Visible         =   0   'False
            Width           =   660
         End
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   5
            Left            =   90
            TabIndex        =   228
            Top             =   165
            Width           =   6990
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   5
               Left            =   1530
               TabIndex        =   121
               Tag             =   "FileName"
               Top             =   1920
               Width           =   4995
            End
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   5
               Left            =   6525
               TabIndex        =   122
               Top             =   1905
               Width           =   345
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   5
               Left            =   1500
               TabIndex        =   115
               Tag             =   "ZipTableIndex"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   5
               Left            =   30
               TabIndex        =   113
               Tag             =   "PageId"
               Top             =   0
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   5
               Left            =   1530
               TabIndex        =   116
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   5
               Left            =   1545
               TabIndex        =   118
               TabStop         =   0   'False
               Tag             =   "UserName"
               Top             =   750
               Width           =   5325
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   5
               Left            =   1530
               TabIndex        =   119
               TabStop         =   0   'False
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   5
               Left            =   1530
               TabIndex        =   120
               TabStop         =   0   'False
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   5
               Left            =   6150
               TabIndex        =   117
               TabStop         =   0   'False
               Tag             =   "Status"
               Top             =   360
               Width           =   690
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   69
               Left            =   165
               TabIndex        =   267
               Tag             =   "lbl_FileName"
               Top             =   1980
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   49
               Left            =   150
               TabIndex        =   233
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   48
               Left            =   165
               TabIndex        =   232
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   47
               Left            =   165
               TabIndex        =   231
               Tag             =   "lbl_NetworkBoard"
               Top             =   1200
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   46
               Left            =   165
               TabIndex        =   230
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   45
               Left            =   4785
               TabIndex        =   229
               Tag             =   "lbl_Status"
               Top             =   435
               Width           =   1230
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   5
            Left            =   150
            TabIndex        =   234
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   5
            Left            =   7170
            TabIndex        =   235
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   330
         Index           =   5
         Left            =   1635
         MaxLength       =   6
         TabIndex        =   107
         TabStop         =   0   'False
         Tag             =   "OFI_Id"
         Top             =   1050
         Width           =   1650
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   5
         Left            =   8145
         TabIndex        =   178
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   5
         Left            =   135
         TabIndex        =   179
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin Project1.ArmCombobox cbo_OFI_CostCentre 
         Height          =   345
         Left            =   1635
         TabIndex        =   111
         Tag             =   "COC_Code®©COC_Name"
         Top             =   1845
         Width           =   7905
         _ExtentX        =   13944
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_OFI_InvoiceType 
         Height          =   345
         Left            =   1635
         TabIndex        =   112
         Tag             =   "INV_Code®©INV_Name"
         Top             =   2220
         Width           =   7905
         _ExtentX        =   13944
         _ExtentY        =   609
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   60
         Left            =   3405
         TabIndex        =   254
         Tag             =   "lbl_DocType"
         Top             =   1095
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Invoice type"
         Height          =   255
         Index           =   56
         Left            =   105
         TabIndex        =   247
         Tag             =   "lbl_InvoiceType"
         Top             =   2265
         Width           =   1485
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Cost centre"
         Height          =   255
         Index           =   55
         Left            =   105
         TabIndex        =   246
         Tag             =   "lbl_CostCentre"
         Top             =   1890
         Width           =   1485
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   13
         Left            =   90
         TabIndex        =   181
         Tag             =   "lbl_Code"
         Top             =   1080
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Country of origin"
         Height          =   255
         Index           =   12
         Left            =   105
         TabIndex        =   180
         Tag             =   "lbl_CountryOrigin"
         Top             =   1485
         Width           =   1485
      End
   End
   Begin VB.Frame fra_DetailItem 
      Height          =   5130
      Index           =   4
      Left            =   4185
      TabIndex        =   172
      Tag             =   "EAS_Return"
      Top             =   4995
      Visible         =   0   'False
      Width           =   3480
      Begin VB.TextBox txt_CT_Desc 
         Height          =   315
         Index           =   4
         Left            =   735
         TabIndex        =   96
         Tag             =   "CT_Desc"
         Top             =   2235
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CT_Code 
         Height          =   315
         Index           =   4
         Left            =   240
         TabIndex        =   95
         Tag             =   "CT_Code"
         Top             =   2235
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CCU_Capkey 
         Height          =   345
         Index           =   4
         Left            =   1215
         TabIndex        =   91
         Tag             =   "CCU_Capkey"
         Top             =   1785
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_Cust_Code 
         Height          =   345
         Index           =   4
         Left            =   1650
         TabIndex        =   92
         Tag             =   "Cust_Code"
         Top             =   1815
         Width           =   1650
      End
      Begin VB.CommandButton cmd_CustomerSeek 
         Caption         =   "..."
         Height          =   360
         Index           =   4
         Left            =   9180
         TabIndex        =   94
         Top             =   1785
         Width           =   405
      End
      Begin VB.TextBox txt_CCU_Desc 
         Height          =   345
         Index           =   4
         Left            =   3360
         MaxLength       =   80
         TabIndex        =   93
         Tag             =   "CCU_Desc"
         Top             =   1800
         Width           =   5820
      End
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   4
         Left            =   4770
         TabIndex        =   88
         Tag             =   "DocTypeDesc"
         Top             =   1035
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   4
         Left            =   4320
         TabIndex        =   87
         Tag             =   "DocType"
         Top             =   1050
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_RET_DroppedNumber 
         Height          =   300
         Left            =   1200
         TabIndex        =   89
         Tag             =   "EAS_DroppedNumber"
         Top             =   1425
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   4
         Left            =   1650
         TabIndex        =   218
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.TextBox txt_DroppedPageNr 
            Height          =   315
            Index           =   4
            Left            =   915
            TabIndex        =   98
            Tag             =   "DroppedPageNr"
            Top             =   150
            Visible         =   0   'False
            Width           =   660
         End
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   4
            Left            =   90
            TabIndex        =   219
            Top             =   165
            Width           =   6990
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   4
               Left            =   1530
               TabIndex        =   105
               Tag             =   "FileName"
               Top             =   1920
               Width           =   4995
            End
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   4
               Left            =   6525
               TabIndex        =   106
               Top             =   1905
               Width           =   345
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   4
               Left            =   1530
               TabIndex        =   99
               Tag             =   "ZipTableIndex"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   4
               Left            =   6150
               TabIndex        =   101
               Tag             =   "Status"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   4
               Left            =   1530
               TabIndex        =   104
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   4
               Left            =   1530
               TabIndex        =   103
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   4
               Left            =   1545
               TabIndex        =   102
               Tag             =   "UserName"
               Top             =   750
               Width           =   5325
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   4
               Left            =   1530
               TabIndex        =   100
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   4
               Left            =   30
               TabIndex        =   97
               Tag             =   "PageId"
               Top             =   0
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   68
               Left            =   165
               TabIndex        =   266
               Tag             =   "lbl_FileName"
               Top             =   1980
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   44
               Left            =   4785
               TabIndex        =   224
               Tag             =   "lbl_Status"
               Top             =   435
               Width           =   1230
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   43
               Left            =   165
               TabIndex        =   223
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   42
               Left            =   165
               TabIndex        =   222
               Tag             =   "lbl_NetworkBoard"
               Top             =   1200
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   41
               Left            =   165
               TabIndex        =   221
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   40
               Left            =   150
               TabIndex        =   220
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   4
            Left            =   150
            TabIndex        =   225
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   4
            Left            =   7170
            TabIndex        =   226
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.TextBox txt_RET_Number 
         Height          =   345
         Left            =   1635
         MaxLength       =   30
         TabIndex        =   90
         Tag             =   "RET_Number"
         Top             =   1425
         Width           =   1650
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   330
         Index           =   4
         Left            =   1635
         TabIndex        =   86
         Tag             =   "RET_Id"
         Top             =   1035
         Visible         =   0   'False
         Width           =   1650
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   4
         Left            =   8145
         TabIndex        =   173
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   4
         Left            =   135
         TabIndex        =   174
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Customer"
         Height          =   255
         Index           =   64
         Left            =   105
         TabIndex        =   258
         Tag             =   "lbl_Customer"
         Top             =   1860
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   59
         Left            =   3510
         TabIndex        =   253
         Tag             =   "lbl_DocType"
         Top             =   1110
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   11
         Left            =   105
         TabIndex        =   176
         Tag             =   "lbl_Code"
         Top             =   1080
         Visible         =   0   'False
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Number"
         Height          =   255
         Index           =   10
         Left            =   105
         TabIndex        =   175
         Tag             =   "lbl_Number"
         Top             =   1470
         Width           =   1215
      End
   End
   Begin VB.Frame fra_DetailItem 
      Height          =   5235
      Index           =   3
      Left            =   15
      TabIndex        =   167
      Tag             =   "EAS_DebitMemo"
      Top             =   5025
      Visible         =   0   'False
      Width           =   3840
      Begin VB.TextBox txt_CT_Desc 
         Height          =   315
         Index           =   3
         Left            =   675
         TabIndex        =   74
         Tag             =   "CT_Desc"
         Top             =   2220
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CT_Code 
         Height          =   315
         Index           =   3
         Left            =   180
         TabIndex        =   73
         Tag             =   "CT_Code"
         Top             =   2220
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CCU_Capkey 
         Height          =   345
         Index           =   3
         Left            =   1140
         TabIndex        =   69
         Tag             =   "CCU_Capkey"
         Top             =   1800
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_Cust_Code 
         Height          =   345
         Index           =   3
         Left            =   1650
         TabIndex        =   70
         Tag             =   "Cust_Code"
         Top             =   1815
         Width           =   1650
      End
      Begin VB.CommandButton cmd_CustomerSeek 
         Caption         =   "..."
         Height          =   360
         Index           =   3
         Left            =   9180
         TabIndex        =   72
         Top             =   1830
         Width           =   405
      End
      Begin VB.TextBox txt_CCU_Desc 
         Height          =   345
         Index           =   3
         Left            =   3360
         MaxLength       =   80
         TabIndex        =   71
         Tag             =   "CCU_Desc"
         Top             =   1830
         Width           =   5820
      End
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   3
         Left            =   4785
         TabIndex        =   66
         Tag             =   "DocTypeDesc"
         Top             =   1035
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   3
         Left            =   4335
         TabIndex        =   65
         Tag             =   "DocType"
         Top             =   1050
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_DBM_DroppedNumber 
         Height          =   300
         Left            =   1140
         TabIndex        =   67
         Tag             =   "EAS_DroppedNumber"
         Top             =   1440
         Visible         =   0   'False
         Width           =   405
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   3
         Left            =   1650
         TabIndex        =   209
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.TextBox txt_DroppedPageNr 
            Height          =   315
            Index           =   3
            Left            =   915
            TabIndex        =   76
            Tag             =   "DroppedPageNr"
            Top             =   135
            Visible         =   0   'False
            Width           =   660
         End
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   3
            Left            =   90
            TabIndex        =   210
            Top             =   165
            Width           =   6990
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   3
               Left            =   1530
               TabIndex        =   83
               Tag             =   "FileName"
               Top             =   1905
               Width           =   4995
            End
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   3
               Left            =   6525
               TabIndex        =   84
               Top             =   1890
               Width           =   345
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   3
               Left            =   1560
               TabIndex        =   77
               Tag             =   "ZipTableIndex"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   3
               Left            =   30
               TabIndex        =   75
               Tag             =   "PageId"
               Top             =   -15
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   3
               Left            =   1530
               TabIndex        =   78
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   3
               Left            =   1545
               TabIndex        =   80
               Tag             =   "UserName"
               Top             =   765
               Width           =   5325
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   3
               Left            =   1530
               TabIndex        =   81
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   3
               Left            =   1530
               TabIndex        =   82
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   3
               Left            =   6150
               TabIndex        =   79
               Tag             =   "Status"
               Top             =   360
               Width           =   690
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   67
               Left            =   165
               TabIndex        =   265
               Tag             =   "lbl_FileName"
               Top             =   1965
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   39
               Left            =   150
               TabIndex        =   215
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   38
               Left            =   165
               TabIndex        =   214
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   37
               Left            =   165
               TabIndex        =   213
               Tag             =   "lbl_NetworkBoard"
               Top             =   1185
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   36
               Left            =   165
               TabIndex        =   212
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   32
               Left            =   4785
               TabIndex        =   211
               Tag             =   "lbl_Status"
               Top             =   435
               Width           =   1230
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   3
            Left            =   150
            TabIndex        =   216
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   3
            Left            =   7170
            TabIndex        =   217
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.TextBox txt_DBM_Number 
         Height          =   345
         Left            =   1635
         MaxLength       =   30
         TabIndex        =   68
         Tag             =   "DBM_Number"
         Top             =   1425
         Width           =   1650
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   330
         Index           =   3
         Left            =   1650
         TabIndex        =   64
         Tag             =   "DBM_Id"
         Top             =   1035
         Visible         =   0   'False
         Width           =   1650
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   3
         Left            =   8145
         TabIndex        =   168
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   3
         Left            =   135
         TabIndex        =   169
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Customer"
         Height          =   255
         Index           =   65
         Left            =   120
         TabIndex        =   259
         Tag             =   "lbl_Customer"
         Top             =   1890
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   58
         Left            =   3525
         TabIndex        =   252
         Tag             =   "lbl_DocType"
         Top             =   1110
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   9
         Left            =   90
         TabIndex        =   171
         Tag             =   "lbl_Code"
         Top             =   1095
         Visible         =   0   'False
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Number"
         Height          =   255
         Index           =   8
         Left            =   120
         TabIndex        =   170
         Tag             =   "lbl_Number"
         Top             =   1470
         Width           =   1215
      End
   End
   Begin VB.Frame fra_DetailItem 
      Height          =   4095
      Index           =   2
      Left            =   11625
      TabIndex        =   162
      Tag             =   "EAS_CreditMemo"
      Top             =   900
      Visible         =   0   'False
      Width           =   3465
      Begin VB.TextBox txt_CT_Desc 
         Height          =   315
         Index           =   2
         Left            =   720
         TabIndex        =   53
         Tag             =   "CT_Desc"
         Top             =   2340
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CT_Code 
         Height          =   315
         Index           =   2
         Left            =   225
         TabIndex        =   52
         Tag             =   "CT_Code"
         Top             =   2340
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CCU_Capkey 
         Height          =   345
         Index           =   2
         Left            =   1110
         TabIndex        =   48
         Tag             =   "CCU_Capkey"
         Top             =   1800
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_Cust_Code 
         Height          =   345
         Index           =   2
         Left            =   1635
         TabIndex        =   49
         TabStop         =   0   'False
         Tag             =   "Cust_Code"
         Top             =   1815
         Width           =   1650
      End
      Begin VB.CommandButton cmd_CustomerSeek 
         Caption         =   "..."
         Height          =   360
         Index           =   2
         Left            =   9195
         TabIndex        =   51
         Top             =   1800
         Width           =   405
      End
      Begin VB.TextBox txt_CCU_Desc 
         Height          =   345
         Index           =   2
         Left            =   3375
         MaxLength       =   80
         TabIndex        =   50
         TabStop         =   0   'False
         Tag             =   "CCU_Desc"
         Top             =   1800
         Width           =   5820
      End
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   2
         Left            =   4710
         TabIndex        =   45
         TabStop         =   0   'False
         Tag             =   "DocTypeDesc"
         Top             =   1065
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   2
         Left            =   4260
         TabIndex        =   44
         Tag             =   "DocType"
         Top             =   1080
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_CRM_DroppedNumber 
         Height          =   300
         Left            =   1110
         TabIndex        =   46
         Tag             =   "EAS_DroppedNumber"
         Top             =   1440
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   2
         Left            =   1650
         TabIndex        =   200
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.TextBox txt_DroppedPageNr 
            Height          =   315
            Index           =   2
            Left            =   885
            TabIndex        =   55
            Tag             =   "DroppedPageNr"
            Top             =   165
            Visible         =   0   'False
            Width           =   660
         End
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   2
            Left            =   90
            TabIndex        =   201
            Top             =   165
            Width           =   6990
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   2
               Left            =   1530
               TabIndex        =   62
               Tag             =   "FileName"
               Top             =   1905
               Width           =   4995
            End
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   2
               Left            =   6525
               TabIndex        =   63
               Top             =   1890
               Width           =   345
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   2
               Left            =   1515
               TabIndex        =   56
               Tag             =   "ZipTableIndex"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   2
               Left            =   6150
               TabIndex        =   58
               TabStop         =   0   'False
               Tag             =   "Status"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   2
               Left            =   1530
               TabIndex        =   61
               TabStop         =   0   'False
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   2
               Left            =   1530
               TabIndex        =   60
               TabStop         =   0   'False
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   2
               Left            =   1545
               TabIndex        =   59
               TabStop         =   0   'False
               Tag             =   "UserName"
               Top             =   750
               Width           =   5325
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   2
               Left            =   1530
               TabIndex        =   57
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   2
               Left            =   15
               TabIndex        =   54
               Tag             =   "PageId"
               Top             =   -15
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   66
               Left            =   165
               TabIndex        =   264
               Tag             =   "lbl_FileName"
               Top             =   1965
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   31
               Left            =   4785
               TabIndex        =   206
               Tag             =   "lbl_Status"
               Top             =   435
               Width           =   1230
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   30
               Left            =   165
               TabIndex        =   205
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   29
               Left            =   165
               TabIndex        =   204
               Tag             =   "lbl_NetworkBoard"
               Top             =   1200
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   28
               Left            =   165
               TabIndex        =   203
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   27
               Left            =   150
               TabIndex        =   202
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   2
            Left            =   150
            TabIndex        =   207
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   2
            Left            =   7170
            TabIndex        =   208
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.TextBox txt_CRM_Number 
         Height          =   345
         Left            =   1650
         MaxLength       =   30
         TabIndex        =   47
         Tag             =   "CRM_Number"
         Top             =   1410
         Width           =   1650
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   330
         Index           =   2
         Left            =   1635
         TabIndex        =   43
         TabStop         =   0   'False
         Tag             =   "CRM_Id"
         Top             =   1035
         Visible         =   0   'False
         Width           =   1650
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   2
         Left            =   8145
         TabIndex        =   163
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   2
         Left            =   135
         TabIndex        =   164
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Customer"
         Height          =   255
         Index           =   62
         Left            =   120
         TabIndex        =   256
         Tag             =   "lbl_Customer"
         Top             =   1875
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   35
         Left            =   3450
         TabIndex        =   251
         Tag             =   "lbl_DocType"
         Top             =   1140
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   7
         Left            =   90
         TabIndex        =   166
         Tag             =   "lbl_Code"
         Top             =   1065
         Visible         =   0   'False
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Number"
         Height          =   255
         Index           =   6
         Left            =   105
         TabIndex        =   165
         Tag             =   "lbl_Number"
         Top             =   1470
         Width           =   1215
      End
   End
   Begin VB.Frame fra_DetailItem 
      Height          =   4035
      Index           =   1
      Left            =   7830
      TabIndex        =   157
      Tag             =   "EAS_PriceRequest"
      Top             =   810
      Visible         =   0   'False
      Width           =   3615
      Begin VB.TextBox txt_CT_Desc 
         Height          =   315
         Index           =   1
         Left            =   645
         TabIndex        =   32
         Tag             =   "CT_Desc"
         Top             =   1860
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CT_Code 
         Height          =   315
         Index           =   1
         Left            =   150
         TabIndex        =   31
         Tag             =   "CT_Code"
         Top             =   1860
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   1
         Left            =   4755
         TabIndex        =   27
         TabStop         =   0   'False
         Tag             =   "DocTypeDesc"
         Top             =   1020
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   1
         Left            =   4290
         TabIndex        =   26
         Tag             =   "DocType"
         Top             =   1035
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_CCU_Capkey 
         Height          =   345
         Index           =   1
         Left            =   1170
         TabIndex        =   28
         Tag             =   "CCU_Capkey"
         Top             =   1410
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_Cust_Code 
         Height          =   345
         Index           =   1
         Left            =   1635
         TabIndex        =   29
         TabStop         =   0   'False
         Tag             =   "Cust_Code"
         Top             =   1410
         Width           =   1650
      End
      Begin VB.CommandButton cmd_CustomerSeek 
         Caption         =   "..."
         Height          =   360
         Index           =   1
         Left            =   9165
         TabIndex        =   245
         Top             =   1395
         Width           =   405
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   1
         Left            =   1650
         TabIndex        =   191
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   1
            Left            =   90
            TabIndex        =   192
            Top             =   150
            Width           =   6990
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   1
               Left            =   6525
               TabIndex        =   42
               Top             =   1905
               Width           =   345
            End
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   1
               Left            =   1530
               TabIndex        =   41
               Tag             =   "FileName"
               Top             =   1920
               Width           =   4995
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   1
               Left            =   1440
               TabIndex        =   35
               Tag             =   "ZipTableIndex"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_DroppedPageNr 
               Height          =   315
               Index           =   1
               Left            =   750
               TabIndex        =   34
               Tag             =   "DroppedPageNr"
               Top             =   0
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   1
               Left            =   0
               TabIndex        =   33
               Tag             =   "PageId"
               Top             =   15
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   1
               Left            =   1530
               TabIndex        =   36
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   1
               Left            =   1545
               TabIndex        =   38
               TabStop         =   0   'False
               Tag             =   "UserName"
               Top             =   750
               Width           =   5325
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   1
               Left            =   1530
               TabIndex        =   39
               TabStop         =   0   'False
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   1
               Left            =   1530
               TabIndex        =   40
               TabStop         =   0   'False
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   1
               Left            =   6150
               TabIndex        =   37
               TabStop         =   0   'False
               Tag             =   "Status"
               Top             =   375
               Width           =   690
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   26
               Left            =   165
               TabIndex        =   263
               Tag             =   "lbl_FileName"
               Top             =   1980
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   25
               Left            =   150
               TabIndex        =   197
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   24
               Left            =   165
               TabIndex        =   196
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   23
               Left            =   165
               TabIndex        =   195
               Tag             =   "lbl_NetworkBoard"
               Top             =   1200
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   22
               Left            =   165
               TabIndex        =   194
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   21
               Left            =   4785
               TabIndex        =   193
               Tag             =   "lbl_Status"
               Top             =   435
               Width           =   1230
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   1
            Left            =   150
            TabIndex        =   198
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   1
            Left            =   7170
            TabIndex        =   199
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.TextBox txt_CCU_Desc 
         Height          =   345
         Index           =   1
         Left            =   3345
         MaxLength       =   80
         TabIndex        =   30
         TabStop         =   0   'False
         Tag             =   "CCU_Desc"
         Top             =   1410
         Width           =   5820
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   345
         Index           =   1
         Left            =   1650
         MaxLength       =   6
         TabIndex        =   25
         TabStop         =   0   'False
         Tag             =   "PRQ_Id"
         Top             =   1035
         Width           =   1650
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   1
         Left            =   8145
         TabIndex        =   158
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   1
         Left            =   135
         TabIndex        =   159
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   4
         Left            =   3480
         TabIndex        =   250
         Tag             =   "lbl_DocType"
         Top             =   1095
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   5
         Left            =   90
         TabIndex        =   161
         Tag             =   "lbl_Code"
         Top             =   1080
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Customer"
         Height          =   255
         Index           =   2
         Left            =   105
         TabIndex        =   160
         Tag             =   "lbl_Customer"
         Top             =   1470
         Width           =   1215
      End
   End
   Begin VB.Frame fra_DetailItem 
      Height          =   4050
      Index           =   0
      Left            =   4050
      TabIndex        =   85
      Tag             =   "EAS_SalesOrder"
      Top             =   795
      Visible         =   0   'False
      Width           =   3585
      Begin VB.TextBox txt_CT_Desc 
         Height          =   315
         Index           =   0
         Left            =   675
         TabIndex        =   261
         Tag             =   "CT_Desc"
         Top             =   2295
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CT_Code 
         Height          =   315
         Index           =   0
         Left            =   180
         TabIndex        =   260
         Tag             =   "CT_Code"
         Top             =   2295
         Visible         =   0   'False
         Width           =   390
      End
      Begin VB.TextBox txt_CCU_Capkey 
         Height          =   345
         Index           =   0
         Left            =   1155
         TabIndex        =   11
         Tag             =   "CCU_Capkey"
         Top             =   1815
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_Cust_Code 
         Height          =   345
         Index           =   0
         Left            =   1635
         TabIndex        =   12
         TabStop         =   0   'False
         Tag             =   "Cust_Code"
         Top             =   1830
         Width           =   1650
      End
      Begin VB.CommandButton cmd_CustomerSeek 
         Caption         =   "..."
         Height          =   360
         Index           =   0
         Left            =   9195
         TabIndex        =   14
         Top             =   1815
         Width           =   405
      End
      Begin VB.TextBox txt_CCU_Desc 
         Height          =   345
         Index           =   0
         Left            =   3375
         MaxLength       =   80
         TabIndex        =   13
         TabStop         =   0   'False
         Tag             =   "CCU_Desc"
         Top             =   1830
         Width           =   5820
      End
      Begin VB.TextBox txt_DocTypeDesc 
         Height          =   345
         Index           =   0
         Left            =   4680
         TabIndex        =   8
         TabStop         =   0   'False
         Tag             =   "DocTypeDesc"
         Top             =   1005
         Width           =   2610
      End
      Begin VB.TextBox txt_DocType 
         Height          =   345
         Index           =   0
         Left            =   4230
         TabIndex        =   7
         Tag             =   "DocType"
         Top             =   1020
         Visible         =   0   'False
         Width           =   360
      End
      Begin VB.TextBox txt_SLO_DroppedNumber 
         Height          =   300
         Left            =   1155
         TabIndex        =   9
         Tag             =   "EAS_DroppedNumber"
         Top             =   1425
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Frame fra_Subdetail 
         Height          =   6270
         Index           =   0
         Left            =   1650
         TabIndex        =   151
         Tag             =   "fra_Subdetail"
         Top             =   2595
         Width           =   7950
         Begin VB.Frame fra_SubdetailItem 
            Height          =   2330
            Index           =   0
            Left            =   90
            TabIndex        =   152
            Top             =   165
            Width           =   6990
            Begin VB.CommandButton cmd_BrowseFile 
               Caption         =   "..."
               Height          =   360
               Index           =   0
               Left            =   6525
               TabIndex        =   24
               Top             =   1905
               Width           =   345
            End
            Begin VB.TextBox txt_FileName 
               Height          =   315
               Index           =   0
               Left            =   1530
               TabIndex        =   23
               Tag             =   "FileName"
               Top             =   1920
               Width           =   4995
            End
            Begin VB.TextBox txt_ZipTableIndex 
               Height          =   315
               Index           =   0
               Left            =   1575
               TabIndex        =   17
               Tag             =   "ZipTableIndex"
               Top             =   45
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_DroppedPageNr 
               Height          =   315
               Index           =   0
               Left            =   825
               TabIndex        =   16
               Tag             =   "DroppedPageNr"
               Top             =   45
               Visible         =   0   'False
               Width           =   660
            End
            Begin VB.TextBox txt_Status 
               Height          =   315
               Index           =   0
               Left            =   6150
               TabIndex        =   19
               TabStop         =   0   'False
               Tag             =   "Status"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_Computer 
               Height          =   315
               Index           =   0
               Left            =   1530
               TabIndex        =   22
               TabStop         =   0   'False
               Tag             =   "ComputerName"
               Top             =   1530
               Width           =   5340
            End
            Begin VB.TextBox txt_NetworkBoardID 
               Height          =   315
               Index           =   0
               Left            =   1530
               TabIndex        =   21
               TabStop         =   0   'False
               Tag             =   "NetworkBoardID"
               Top             =   1140
               Width           =   5340
            End
            Begin VB.TextBox txt_UserName 
               Height          =   315
               Index           =   0
               Left            =   1530
               TabIndex        =   20
               TabStop         =   0   'False
               Tag             =   "UserName"
               Top             =   750
               Width           =   5325
            End
            Begin VB.TextBox txt_PageNr 
               Height          =   315
               Index           =   0
               Left            =   1515
               TabIndex        =   18
               Tag             =   "PageNr"
               Top             =   360
               Width           =   690
            End
            Begin VB.TextBox txt_SubdetailKey 
               Height          =   285
               Index           =   0
               Left            =   30
               TabIndex        =   15
               Tag             =   "PageId"
               Top             =   45
               Visible         =   0   'False
               Width           =   720
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#File"
               Height          =   195
               Index           =   14
               Left            =   165
               TabIndex        =   262
               Tag             =   "lbl_FileName"
               Top             =   1980
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   195
               Index           =   20
               Left            =   4785
               TabIndex        =   190
               Tag             =   "lbl_Status"
               Top             =   420
               Width           =   1230
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Computer"
               Height          =   195
               Index           =   19
               Left            =   165
               TabIndex        =   189
               Tag             =   "lbl_Computer"
               Top             =   1590
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Network board"
               Height          =   195
               Index           =   18
               Left            =   165
               TabIndex        =   188
               Tag             =   "lbl_NetworkBoard"
               Top             =   1200
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#User name"
               Height          =   195
               Index           =   17
               Left            =   165
               TabIndex        =   187
               Tag             =   "lbl_UserName"
               Top             =   810
               Width           =   930
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Page nr."
               Height          =   195
               Index           =   16
               Left            =   150
               TabIndex        =   186
               Tag             =   "lbl_PageNr"
               Top             =   420
               Width           =   930
            End
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   3630
            Index           =   0
            Left            =   150
            TabIndex        =   153
            Tag             =   "grd_DocumentPages"
            Top             =   2560
            Width           =   6915
            _ExtentX        =   12197
            _ExtentY        =   6403
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   4560
            Index           =   0
            Left            =   7170
            TabIndex        =   154
            Top             =   135
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8043
         End
      End
      Begin VB.CheckBox chk_Repositioning 
         Caption         =   "#Repositioning"
         Height          =   300
         Index           =   0
         Left            =   8145
         TabIndex        =   148
         Tag             =   "lbl_Repositioning"
         Top             =   975
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1530
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   330
         Index           =   0
         Left            =   1635
         TabIndex        =   6
         Tag             =   "SLO_Id"
         Top             =   1035
         Visible         =   0   'False
         Width           =   1650
      End
      Begin VB.TextBox txt_SLO_Number 
         Height          =   345
         Left            =   1650
         MaxLength       =   30
         TabIndex        =   10
         Tag             =   "SLO_Number"
         Top             =   1425
         Width           =   1650
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   0
         Left            =   135
         TabIndex        =   146
         Top             =   180
         Width           =   9510
         _ExtentX        =   16775
         _ExtentY        =   1217
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Customer"
         Height          =   255
         Index           =   63
         Left            =   120
         TabIndex        =   257
         Tag             =   "lbl_Customer"
         Top             =   1890
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Doc type"
         Height          =   255
         Index           =   3
         Left            =   3420
         TabIndex        =   249
         Tag             =   "lbl_DocType"
         Top             =   1095
         Width           =   1230
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Number"
         Height          =   255
         Index           =   1
         Left            =   105
         TabIndex        =   149
         Tag             =   "lbl_Number"
         Top             =   1470
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Code"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   147
         Tag             =   "lbl_Code"
         Top             =   1080
         Visible         =   0   'False
         Width           =   1215
      End
   End
   Begin VB.Frame fra_MainItem 
      Height          =   4185
      Index           =   0
      Left            =   165
      TabIndex        =   142
      Top             =   720
      Visible         =   0   'False
      Width           =   3720
      Begin VB.CommandButton cmd_TVReLoad 
         Height          =   735
         Index           =   0
         Left            =   105
         Style           =   1  'Graphical
         TabIndex        =   4
         Tag             =   "cmd_TVReLoad"
         Top             =   3315
         Visible         =   0   'False
         Width           =   735
      End
      Begin VB.Frame fra_MainFilter 
         Height          =   2760
         Index           =   0
         Left            =   105
         TabIndex        =   143
         Top             =   120
         Width           =   3855
         Begin Project1.A_calocx cal11 
            Height          =   375
            Index           =   0
            Left            =   1725
            TabIndex        =   1
            Tag             =   "Date_Since"
            Top             =   150
            Width           =   1860
            _ExtentX        =   3281
            _ExtentY        =   661
         End
         Begin Project1.A_calocx cal12 
            Height          =   375
            Index           =   0
            Left            =   1740
            TabIndex        =   2
            Tag             =   "Date_Till"
            Top             =   570
            Width           =   1860
            _ExtentX        =   3281
            _ExtentY        =   661
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Since date"
            Height          =   255
            Index           =   33
            Left            =   90
            TabIndex        =   156
            Tag             =   "lbl_FilterSinceDate"
            Top             =   210
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Till date"
            Height          =   255
            Index           =   34
            Left            =   90
            TabIndex        =   155
            Tag             =   "lbl_FilterTillDate"
            Top             =   675
            Width           =   1215
         End
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   0
         Left            =   90
         TabIndex        =   3
         Top             =   2925
         Width           =   3870
         _ExtentX        =   6826
         _ExtentY        =   609
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   7530
         Index           =   0
         Left            =   4080
         TabIndex        =   144
         Tag             =   "grd_Main"
         Top             =   1020
         Width           =   7005
         _ExtentX        =   12356
         _ExtentY        =   13282
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   3180
         Index           =   0
         Left            =   90
         TabIndex        =   5
         Top             =   3300
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   5609
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   0
         Left            =   4080
         TabIndex        =   145
         Top             =   255
         Width           =   7020
         _ExtentX        =   12383
         _ExtentY        =   1217
      End
      Begin MSComctlLib.TabStrip tbs_MainTabFilter 
         Height          =   375
         Index           =   0
         Left            =   135
         TabIndex        =   150
         Top             =   8595
         Visible         =   0   'False
         Width           =   3825
         _ExtentX        =   6747
         _ExtentY        =   661
         MultiRow        =   -1  'True
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   1
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
   End
   Begin MSComDlg.CommonDialog dlg_Common 
      Left            =   11640
      Top             =   165
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSComctlLib.TabStrip tbs_Main 
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   180
      Width           =   10860
      _ExtentX        =   19156
      _ExtentY        =   661
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   1
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
   Begin VB.Menu mnu_EAS 
      Caption         =   ""
      Tag             =   "mnu_EAS"
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Sales order"
         Index           =   0
         Tag             =   "mnu_SalesOrder"
      End
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Price request"
         Index           =   1
         Tag             =   "mnu_PriceRequest"
      End
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Credit memo"
         Index           =   2
         Tag             =   "mnu_CreditMemo"
      End
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Debit memo"
         Index           =   3
         Tag             =   "mnu_DebitMemo"
      End
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Return"
         Index           =   4
         Tag             =   "mnu_Return"
      End
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Office invoice"
         Index           =   5
         Tag             =   "mnu_OfficeInvoice"
      End
      Begin VB.Menu mnu_EAS_Document 
         Caption         =   "#Admin customer"
         Index           =   6
         Tag             =   "mnu_AdminCustomer"
      End
   End
End
Attribute VB_Name = "EAS_Viewer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Option Compare Text
'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK API FUNCTION DECLARES
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lpPictDesc As PictDesc, riid As Guid, ByVal fPictureOwnsHandle As Long, ipic As IPicture) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
   (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadIconFromDLL Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Long) As Long
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK VARIABLES
'**********************************************************************************************************************************
'**********************************************************************************************************************************

#If ENV = LIVE Then
    Dim mo_Db As Object
#Else
    Dim mo_Db As ARMSYSCOMLib.ArmDb
#End If

#If ENV = LIVE Then
    Dim mo_FSO As Object
#Else
    Dim mo_FSO As Scripting.FileSystemObject
#End If

#If ENV = LIVE Then
    Dim mo_Sys As Object
#Else
    Dim mo_Sys As ARMSYSCOMLib.ArmSYS
#End If

Private mo_WshNetwork                   As Object
Private ms_Language_Code                As String       'current user interface language
Private ml_U_Code                       As Long         'U_Code (GEN_Systems_Users) of logged user
Private ms_LoginName                    As String       'contain loginname
Private ms_UserName                     As String       'contain name of logged user as defined in GEN_People
Private mb_InternalInit                 As Boolean      'framework is doing some own control manipulation, all events should handle
Private mc_Item                         As Long         'cursor which will contain currently loaded detail data
Private mc_Toolbars                     As Long         'cursor which will contain all toolbars for current usercontrol
Private ms_ToolbarRequest               As String       'request which load all toolbars for current usercontrol
Private mo_DocumentType                 As Collection
Private ml_MaxZipRecordCount            As Long
Private ms_DocumentServerDir            As String
Private ms_NetworkBoardID               As String
Private ms_ComputerName                 As String
Private ml_ZipTableIndex()              As Long
Private msa_MapNetworkDrive()           As String
Private ms_NetworkPath                  As String
Private ms_NetworkDrive                 As String
Private ms_NetworkUser                  As String
Private ms_NetworkPassword              As String
Private mb_AppCreatedMappedDrive        As Boolean

Private ms_UrlCustomer                  As String
Private ms_UrlSalesOrder                As String

Private old_cal1                        As String
Private old_cal2                        As String
Private current_cal1                    As String
Private current_cal2                    As String

Private mb_Initialized                  As Boolean      'framework is initialised or not
Private m_ConnectString                 As String       'connection string to connect SQL database
Private use_framework_connection        As Integer      'if framework should use outside connected armdb or its own connection
Private ms_DecimalSeparator             As String       'locale decimal separator
Private ms_ThousandSeparator            As String       'locale thousand separator
Private mc_ScreenLabels                 As Long         'cursor containing screen constants for current component

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK CONSTANTS
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Const SEP = "®©"
Private Const C_SEP As String = "@@"
Private Const SEP1 As String = "®"
Private Const SEP2 As String = "©"

Private Const SCREEN_NAME As String = "EAS_Viewer"
Private Const LOCALE_USER_DEFAULT = &H400
Private Const STATUS_COLUMN = "RowStatus"
Private Const ICON_RELOAD = 115

Private Const SW_SHOWNORMAL = 1

Private Const LOCALE_SDECIMAL = &HE ' Decimal separator
Private Const LOCALE_STHOUSAND = &HF ' Thousand separator
Private Const CL_COLOR_ENABLED As Long = &H80000005
Private Const CL_COLOR_DISABLED As Long = &H8000000F
Private Const CL_COLOR_LOCKED As Long = &H80000018
Private Const C_ERRORRAISE As Long = 2500
Private Const C_MSG_ID_BASE As Long = 9350

Private Const FRM_SPACE_VER = 120
Private Const FRM_SPACE_HOR = 100

Private Const C_SERVICE_USER As String = "NXT"
Private Const C_SERVICE_PASSW As String = "ous42pri"
Private Const C_DOCUMENT_TYPE_GR_CODE As Long = 70
Private Const C_ERROR_FILES_DIR As String = "Bad_Files"

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK CUSTOM TYPES
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Type PictDesc
    cbSizeofStruct As Long
    picType As Long
    hImage As Long
    xExt As Long
    yExt As Long
End Type

Private Type Guid
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type

Private Type TTreeViewInfo
    Levels As Long
    NodeRequest() As String
    GridRequest() As String
    ExcelRequest() As String
    CountRequest() As String
    FindRequest() As String
    Images() As Integer
    SelectedImages() As Integer
    TreeViewCode As String
    Loaded As Boolean
End Type

Private Type TSubdetailConfig
    NameFrame                       As String
    FrameIndex                      As Long
    DetailConfigIndex               As Long
    Initialized                     As Boolean
    ToolbarID                       As Long
    ToolbarIndex                    As Long
    ToolbarFaces                    As Variant
    RequestView                     As String
    RequestAdd                      As String
    RequestUpd                      As String
    RequestDel                      As String
    RequestCheckDelete              As String
    RequestCheckAdd                 As String
    RequestCheckUpdate              As String
    TableName                       As String
    TableOrder                      As String
    GridDelayMethod                 As eGridLoadMethod
    GridColumns                     As Variant
    DeletedRows                     As Variant
    ListFieldsMandatory             As Variant
    ListFieldsDefaultValue          As Variant
    ListFieldsToDisable             As Variant
    DeleteMsg(0, 1)                 As String
    UpdateMsg(0, 1)                 As String
    CheckAddUpdMsg(0, 1)            As String
    CheckDelMsg(0, 1)               As String
End Type

Private Type TDetailConfig
    NameFrame                       As String
    DetailKey                       As String
    FrameIndex                      As Long
    MainConfigIndex                 As Long
    IsMultiDetailFrame              As Boolean
    Initialized                     As Boolean
    ToolbarID                       As Long
    ToolbarIndex                    As Long
    ToolbarFaces                    As Variant
    RequestView                     As String
    RequestAdd                      As Variant
    RequestUpd                      As Variant
    RequestDel                      As Variant
    AffectedCount                   As Variant
    RequestCheckDelete              As String
    RequestCheckAdd                 As String
    RequestCheckUpdate              As String
    UseTransaction                  As Boolean
    TableName                       As String
    MainGridColumns                 As Variant
    InitControls                    As Variant
    ListFieldsMandatory             As Variant
    ListFieldsDefaultValue          As Variant
    ListFieldsToDisable             As Variant
    DeleteMsg(0, 1)                 As String
    UpdateMsg(0, 1)                 As String
    CheckAddUpdMsg(0, 1)            As String
    CheckDelMsg(0, 1)               As String
End Type

Private Type TMainConfig
    NameFrame                       As String
    ViewCode                        As String
    FrameIndex                      As Long
    IsMultiDetailView               As Boolean
    CurrentDetailIndex              As Long
    Initialized                     As Boolean
    ToolbarFace                     As String
    ToolbarIndex                    As Long
    ToolbarID                       As Long
    CurrentTvwSelMethod             As eTvwSelMethod
    GridDelayMethod                 As eGridLoadMethod
    GridDelayed                     As Boolean
    TreeDelayed                     As Boolean
    mTreeViewInfos()                As TTreeViewInfo
    RequestGrid                     As String
End Type

Private mt_SubdetailConfig() As TSubdetailConfig
Private mt_DetailConfig() As TDetailConfig
Private mt_MainConfig() As TMainConfig

Private Type TRect
    Top As Long
    Left As Long
    Width As Long
    Height As Long
End Type

Private Enum eMode
    emNone
    emList
    emView
    emAdd
    emUpdate
    emDelete
End Enum

Private Enum eControlPropertyIndex
    cpiControl
    cpiTag
    cpiVisible
    cpiRequest
End Enum

Private Enum eControlAction
    caDoubleClick
    caClick
    caSelect
    caLoad
End Enum

Private me_DetailMode                     As eMode
Private me_OldDetailMode                  As eMode
Private me_SubDetailMode                  As eMode

Private Enum eGridLoadMethod
    egmDelayedAlways = 0
    egmDelayedExceptLastLevel = 1
    egmLoadAlways = 2
End Enum

' The different way to select data in the treeview
Private Enum eTvwSelMethod
    etmNone = 0
    etmNode = 1         ' User click on the last node of a branch
    etmBranch = 2       ' User click on a branch and use the load button
    etmCheckBoxes = 3   ' User click on the load button when checkboxes mode is set
End Enum

Private Enum ArmErr
    DBCnxFailed = C_ERRORRAISE + 1             ' Unable to connect to the database
    CPTAlreadyInitialized = C_ERRORRAISE + 2   ' We try to initialize a component that is already initialized
    CPTNotInitialized = C_ERRORRAISE + 3       ' We try to use or free that is not initialized yet
    InvalidArgument = C_ERRORRAISE + 4
    PropertyNotSet = C_ERRORRAISE + 5
    SQLFailure = C_ERRORRAISE + 6               ' A SQL runtime error has occured : syntax wrong....
    SQLBadRowAffectedCount = C_ERRORRAISE + 7   ' A SQL request has not affected the expected rowcount (ex: one Update do nothing)
    SQLBadRowExpectedCount = C_ERRORRAISE + 8   ' A SQL request does not return the expected rowcount : select an item return nothing...
    DrivingError = C_ERRORRAISE + 9
    CompFncFailed = C_ERRORRAISE + 10           ' when component function fail
    GridLoadFailed = C_ERRORRAISE + 11          ' load function failed ... bad sql
    InvalidValue = C_ERRORRAISE + 12          ' load function failed ... bad sql
End Enum

Private Enum ArmCusErr
    DuplicityDetected = C_ERRORRAISE + 2301                ' detected row with same unique id
End Enum

Private Enum eDocumentType
    dtNone = 0
    dtSalesOrder = 1
    dtPriceRequest = 2
    dtCreditMemo = 3
    dtDebitMemo = 4
    dtReturn = 5
    dtOfficeInvoice = 6
    dtAdminCustomer = 7
End Enum

Private Enum eZipDocumentStatus
    Waiting = 1
    Uploaded = 2
End Enum

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK EVENTS
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Public Event quit()

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' COMPONENT CONSTANTS AND VARIABLES
'**********************************************************************************************************************************
'**********************************************************************************************************************************


'**********************************************************************************************************************************
'**********************************************************************************************************************************
' COMPONENT METHODS
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Function LoadUserInfo(ByRef ao_Armdb As Object, ByVal al_U_Code As Long) As String
On Error GoTo ErrHandler
Const C_REQ As String = _
    "SELECT GPL.P_First_Name + ' '+ GPL.P_Name as User_Name " & _
    "FROM GEN_Systems_Users GSU " & _
    "INNER JOIN GEN_People GPL ON (GSU.P_Code=GPL.P_Code) " & _
    "WHERE GSU.U_Code=$U_Code$"

Dim ls_req As String
Dim ll_cursor As Long
    
    ls_req = ReplacePlaceHolder(C_REQ, "$U_Code$", al_U_Code)
    ll_cursor = OpenSQLSafe(ao_Armdb, ls_req, 1)
    LoadUserInfo = ao_Armdb.GetFields(ll_cursor, "User_Name")
    Call ao_Armdb.Close(ll_cursor)
    Exit Function
    
ErrHandler:
    If ll_cursor <> 0 Then Call ao_Armdb.Close(ll_cursor)
    Call ErrorHandler("LoadUserInfo()")
End Function


Private Function GetTime(ByVal as_Time As String) As Date
On Error GoTo ErrHandler
    
    Dim lsa_Time() As String
    
    lsa_Time = Split(as_Time, ":")
    If UBound(lsa_Time) = 2 Then
        GetTime = TimeSerial(Val(lsa_Time(0)), Val(lsa_Time(1)), Val(lsa_Time(2)))
    ElseIf UBound(lsa_Time) = 1 Then
        GetTime = TimeSerial(Val(lsa_Time(0)), Val(lsa_Time(1)), 0)
    Else
        Err.Raise ArmErr.InvalidArgument, "Split", "as_Time=" & as_Time
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("GetTime()")
End Function

Private Function CheckTime(ByVal as_Time As String) As Boolean
On Error GoTo ErrHandler
    
    Dim lsa_Time() As String
    Dim ll_Hour As Long, ll_Minute As Long, ll_Second As Long
    
    CheckTime = False
    lsa_Time = Split(as_Time, ":")
    If UBound(lsa_Time) < 1 Or UBound(lsa_Time) > 2 Then
        Exit Function
    End If
    
    If Not isNumeric(lsa_Time(0)) Then
        Exit Function
    End If
    ll_Hour = Val(lsa_Time(0))
    If ll_Hour < 0 Or ll_Hour > 23 Then
        Exit Function
    End If
    
    If Not isNumeric(lsa_Time(1)) Then
        Exit Function
    End If
    ll_Minute = Val(lsa_Time(1))
    If ll_Minute < 0 Or ll_Minute > 59 Then
        Exit Function
    End If
    
    ll_Second = 0
    If UBound(lsa_Time) > 1 Then
        If Not isNumeric(lsa_Time(2)) Then
            Exit Function
        End If
        ll_Second = Val(lsa_Time(2))
    End If
    If ll_Second < 0 Or ll_Second > 59 Then
        Exit Function
    End If
    CheckTime = True
    Exit Function
ErrHandler:
    Call ErrorHandler("CheckTime()")
End Function
'**********************************************************************************************************************************
'**********************************************************************************************************************************
' COMPONENT CONTROL EVENTS
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Sub cal11_datechangee(Index As Integer)
On Error GoTo ErrHandler
   
    If Not mb_Initialized Then Exit Sub
    'Call cbo_View_ComboItemSelected(Index)
    Call SetTreeDelayedMode(Index, True)
    Exit Sub
ErrHandler:
    Call ErrorMessage("cal11_datechangee")
End Sub

Private Sub cal12_datechangee(Index As Integer)
On Error GoTo ErrHandler
   
    If Not mb_Initialized Then Exit Sub
    'Call cbo_View_ComboItemSelected(Index)
    Call SetTreeDelayedMode(Index, True)
    Exit Sub
ErrHandler:
    Call ErrorMessage("cal12_datechangee")
End Sub

Private Sub cal11_changeposition(Index As Integer, y As Integer)

    cal11(Index).Zorder
    cal11(Index).Top = cal11(Index).Top + y
End Sub

Private Sub cal12_changeposition(Index As Integer, y As Integer)

    cal12(Index).Zorder
    cal12(Index).Top = cal12(Index).Top + y
End Sub

Private Sub opt_FilterFileDate_Click(Index As Integer)
On Error GoTo ErrHandler

Dim ll_MainConfig As Long
Dim ll_MainFrame As Long

    Call LockScreen(True)
    
    ll_MainConfig = FindMainConfigByName("")
    ll_MainFrame = mt_MainConfig(ll_MainConfig).FrameIndex
    
    If Index = 1 Then
        cal11(0).Visible = True
        cal12(0).Visible = True
    Else
        cal11(0).reinit_cal
        cal12(0).reinit_cal
        cal11(0).Visible = False
        cal12(0).Visible = False
    End If
        
    Call SetTreeDelayedMode(ll_MainFrame, True)
    Call LockScreen(False)

    Exit Sub
ErrHandler:
    Call LockScreen(False)
    Call ErrorMessage("opt_FilterFileDate_Click")
End Sub


'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK CUSTOM METHODS
' Change content of methods as you need, but do not add any new method or property here !
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Function Load_A_COM_Custom() As Boolean
On Error GoTo ErrHandler

    Dim ll_Idx As Long
    Dim ls_MapNetworkDrive As String
    
    Set mo_DocumentType = New Collection
    
    ml_MaxZipRecordCount = Trim(GetAConfigData(mo_Db, "EAS_MaxZipRecordCount"))
    
    ReDim ml_ZipTableIndex(eDocumentType.dtAdminCustomer)
    For ll_Idx = 0 To eDocumentType.dtAdminCustomer
        ml_ZipTableIndex(ll_Idx) = 0
    Next
    
    Dim ls_EAS_ViewerRight As String
    ls_EAS_ViewerRight = Trim(GetAConfigData(mo_Db, "EAS_ViewerRight"))
    If InStr(1, SEP & ls_EAS_ViewerRight & SEP, SEP & ml_U_Code & SEP) <= 0 Then
        Load_A_COM_Custom = False
        Exit Function
    End If
    
    ls_MapNetworkDrive = GetAConfigDataByCountry(mo_Db, "EAS_MapNetworkDrive")
    
    If (ls_MapNetworkDrive = "") Then
        Err.Raise ArmErr.CPTNotInitialized, "EAS_MapNetworkDrive", "A_Config value 'EAS_MapNetworkDrive_XX' not initialized for country of the logged user"
    End If
    
    msa_MapNetworkDrive = Split(ls_MapNetworkDrive, SEP)
    ms_NetworkPath = msa_MapNetworkDrive(0)
    ms_NetworkUser = msa_MapNetworkDrive(1)
    ms_NetworkPassword = msa_MapNetworkDrive(2)
    ms_NetworkDrive = msa_MapNetworkDrive(3)
    
    mb_AppCreatedMappedDrive = False
    If Trim(ms_NetworkDrive) = "" Then
        ' in this case we upload using direct network path
        ms_DocumentServerDir = ms_NetworkPath
    Else
        ms_DocumentServerDir = ms_NetworkDrive & "\"
        ' check if C_MAPPED_DRIVE is mapped
        If Not NetworkDriveExists(mo_WshNetwork, ms_NetworkDrive) Then
            mb_AppCreatedMappedDrive = MapNetworkDrive(mo_WshNetwork, ms_NetworkDrive, msa_MapNetworkDrive(0), msa_MapNetworkDrive(1), msa_MapNetworkDrive(2))
        End If
    End If
    
    If (ms_DocumentServerDir <> "") And right(ms_DocumentServerDir, 1) <> "\" Then ms_DocumentServerDir = ms_DocumentServerDir & "\"
    
    If Not mo_FSO.FolderExists(ms_DocumentServerDir) Then
        ReDim ms_MsgInfo(0, 1)
        ms_MsgInfo(0, 0) = "$PATH$"
        ms_MsgInfo(0, 1) = ms_DocumentServerDir
        Call MsgBox(MsgText(666, ms_Language_Code, "Server directory does not exists: $PATH$", ms_MsgInfo))
    End If
    ' test if curently mapped drive points to service dir on the other side
    If Not mo_FSO.FolderExists(ms_DocumentServerDir & C_ERROR_FILES_DIR) Then
        ' drive is not propably pointing ok
        Call MsgBox(MsgText(666, ms_Language_Code, "Existing mapped drive is propably not configured correctly!. Upload for Hires pictures may not work."))
    End If
    
    ms_UrlCustomer = GetAConfigData(mo_Db, "EAS_UrlCustomer")
    If (ms_UrlCustomer = "") Then
        Err.Raise ArmErr.CPTNotInitialized, "EAS_UrlCustomer", "A_Config value 'EAS_UrlCustomer' not initialized"
    End If
    
    ms_UrlSalesOrder = GetAConfigData(mo_Db, "EAS_UrlSalesOrder")
    If (ms_UrlSalesOrder = "") Then
        Err.Raise ArmErr.CPTNotInitialized, "EAS_UrlSalesOrder", "A_Config value 'EAS_UrlSalesOrder' not initialized"
    End If
    
    Call DeleteTemporaryFiles
    Load_A_COM_Custom = True
    Exit Function
ErrHandler:
    Call ErrorHandler("Load_A_COM_Custom")
End Function

Private Sub UnLoad_A_COM_Custom()
On Error GoTo ErrHandler

    Set mo_DocumentType = Nothing
    Exit Sub
ErrHandler:
    Call ErrorHandler("UnLoad_A_COM_Custom")
End Sub

Private Sub Init_Custom()
On Error GoTo ErrHandler
    Dim lo_Tab As MSComctlLib.Tab
    Dim lc_Cursor As Long
    
    ms_ToolbarRequest = "exec Toolbar_sel $Module$"
    Set lo_Tab = tbs_Main.Tabs(1)
    lo_Tab.Caption = "#Viewer"
    lo_Tab.Key = "EAS_Viewer"
    lo_Tab.Tag = "EAS_Viewer"
    
    cal11(0).date_courte = Format(DateSerial(Year(Now), Month(Now), 1), "dd\/mm\/yyyy")
    cbo_OFI_CostCentre.Request = ReplaceCommonPlaceholders("exec EAS_CostCentre_lst $Language_Code$")
    cbo_OFI_InvoiceType.Request = ReplaceCommonPlaceholders("exec EAS_InvoiceType_lst $Language_Code$")
    cbo_OFI_Country.Request = ReplaceCommonPlaceholders("exec EAS_Countries_lst $Language_Code$")
    lc_Cursor = OpenSQLSafe(mo_Db, ReplaceCommonPlaceholders("exec A_References_ML_LstSafe " & C_DOCUMENT_TYPE_GR_CODE & ",$Language_Code$"))
    While Not mo_Db.EOF(lc_Cursor)
        Call mo_DocumentType.Add(mo_Db.GetFields(lc_Cursor, "RF_Desc"))
        Call mo_Db.Next(lc_Cursor)
    Wend
    Call mo_Db.Close(lc_Cursor)
    Exit Sub
ErrHandler:
    Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("Init_Custom")
End Sub

Private Sub Load_ConfigInfo()
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ll_frameIndex As Long
    
    ReDim mt_MainConfig(0)
    ReDim mt_DetailConfig(6)
    
    With mt_MainConfig(0)
        .FrameIndex = 0
        .IsMultiDetailView = True
        .Initialized = False
        .NameFrame = "EAS_Viewer"
        .ViewCode = "EAS_Viewer"
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .ToolbarFace = "0"
        .ToolbarIndex = 0
        .ToolbarID = 2814
        .RequestGrid = ""
    End With
    
    
    With mt_DetailConfig(0)
        .FrameIndex = 0
        .NameFrame = "EAS_SalesOrder"
        .MainConfigIndex = 0
        .DetailKey = 1

        .RequestView = "exec EAS_SalesOrder_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_SalesOrder_ins $SLO_Id$,$SLO_Number$,$CCU_CapKey$,$Cust_Code$,$Z_creator$"
        .RequestUpd = "exec EAS_SalesOrder_upd $SLO_Id$,$SLO_Number$,$CCU_Capkey$,$Cust_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_SalesOrder_del $SLO_Id$,$EAS_DroppedNumber$,$Z_last_upd_user$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT SLO_Id FROM EAS_SalesOrder WHERE SLO_Number=$SLO_Number$"
        .RequestCheckUpdate = "SELECT SLO_Id FROM EAS_SalesOrder WHERE SLO_Number=$SLO_Number$ AND SLO_Id<>$SLO_Id$"
        
        .UseTransaction = False
        .TableName = "EAS_SalesOrder"
        .ToolbarIndex = 0
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(1)
        .ListFieldsMandatory(0) = Array(txt_SLO_Number, 1)
        .ListFieldsMandatory(1) = Array(txt_CCU_Desc(0), 63)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(0)
        Set .ListFieldsToDisable(1) = txt_CCU_Desc(0)
        Set .ListFieldsToDisable(2) = txt_Cust_Code(0)
        Set .ListFieldsToDisable(3) = txt_DocTypeDesc(0)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")
        
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
        
    With mt_DetailConfig(1)
        .FrameIndex = 1
        .NameFrame = "EAS_PriceRequest"
        .MainConfigIndex = 0
        .DetailKey = 2

        .RequestView = "exec EAS_PriceRequest_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_PriceRequest_ins $PRQ_Id$,$CCU_Capkey$,$Cust_Code$,NULL,$Z_creator$"
        .RequestUpd = "exec EAS_PriceRequest_upd $PRQ_Id$,$CCU_Capkey$,$Cust_Code$,NULL,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_PriceRequest_del $PRQ_Id$,$Z_last_upd_user$,$iConcurrency$"
        
        .UseTransaction = False
        .TableName = "EAS_PriceRequest"
        .ToolbarIndex = 1
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_CCU_Desc(1), 2)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(1)
        Set .ListFieldsToDisable(1) = txt_CCU_Desc(1)
        Set .ListFieldsToDisable(2) = txt_Cust_Code(1)
        Set .ListFieldsToDisable(3) = txt_DocTypeDesc(1)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(2)
        .FrameIndex = 2
        .NameFrame = "EAS_CreditMemo"
        .MainConfigIndex = 0
        .DetailKey = 3

        .RequestView = "exec EAS_CreditMemo_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_CreditMemo_ins $CRM_Id$,$CRM_Number$,$CCU_CapKey$,$Cust_Code$,$Z_creator$"
        .RequestUpd = "exec EAS_CreditMemo_upd $CRM_Id$,$CRM_Number$,$CCU_CapKey$,$Cust_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_CreditMemo_del $CRM_Id$,$EAS_DroppedNumber$,$Z_last_upd_user$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT CRM_Id FROM EAS_CreditMemo WHERE CRM_Number=$CRM_Number$"
        .RequestCheckUpdate = "SELECT CRM_Id FROM EAS_CreditMemo WHERE CRM_Number=$CRM_Number$ AND CRM_Id<>$CRM_Id$"
        
        .UseTransaction = False
        .TableName = "EAS_CreditMemo"
        .ToolbarIndex = 2
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(1)
        .ListFieldsMandatory(0) = Array(txt_CRM_Number, 6)
        .ListFieldsMandatory(1) = Array(txt_CCU_Desc(2), 62)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(2)
        Set .ListFieldsToDisable(1) = txt_CCU_Desc(2)
        Set .ListFieldsToDisable(2) = txt_Cust_Code(2)
        Set .ListFieldsToDisable(3) = txt_DocTypeDesc(2)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(3)
        .FrameIndex = 3
        .NameFrame = "EAS_DebitMemo"
        .MainConfigIndex = 0
        .DetailKey = 4

        .RequestView = "exec EAS_DebitMemo_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_DebitMemo_ins $DBM_Id$,$DBM_Number$,$CCU_CapKey$,$Cust_Code$,$Z_creator$"
        .RequestUpd = "exec EAS_DebitMemo_upd $DBM_Id$,$DBM_Number$,$CCU_CapKey$,$Cust_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_DebitMemo_del $DBM_Id$,$EAS_DroppedNumber$,$Z_last_upd_user$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT DBM_Id FROM EAS_DebitMemo WHERE DBM_Number=$DBM_Number$"
        .RequestCheckUpdate = "SELECT DBM_Id FROM EAS_DebitMemo WHERE DBM_Number=$DBM_Number$ AND DBM_Id<>$DBM_Id$"
        
        .UseTransaction = False
        .TableName = "EAS_DebitMemo"
        .ToolbarIndex = 3
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(1)
        .ListFieldsMandatory(0) = Array(txt_DBM_Number, 8)
        .ListFieldsMandatory(1) = Array(txt_CCU_Desc(3), 65)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(3)
        Set .ListFieldsToDisable(1) = txt_CCU_Desc(3)
        Set .ListFieldsToDisable(2) = txt_Cust_Code(3)
        Set .ListFieldsToDisable(3) = txt_DocTypeDesc(3)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(4)
        .FrameIndex = 4
        .NameFrame = "EAS_Return"
        .MainConfigIndex = 0
        .DetailKey = 5

        .RequestView = "exec EAS_Return_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_Return_ins $RET_Id$,$RET_Number$,$CCU_CapKey$,$Cust_Code$,$Z_creator$"
        .RequestUpd = "exec EAS_Return_upd $RET_Id$,$RET_Number$,$CCU_CapKey$,$Cust_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_Return_del $RET_Id$,$EAS_DroppedNumber$,$Z_last_upd_user$,$iConcurrency$"

        .RequestCheckAdd = "SELECT RET_Id FROM EAS_Return WHERE RET_Number=$RET_Number$"
        .RequestCheckUpdate = "SELECT RET_Id FROM EAS_Return WHERE RET_Number=$RET_Number$ AND RET_Id<>$RET_Id$"
        
        .UseTransaction = False
        .TableName = "EAS_Return"
        .ToolbarIndex = 4
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(1)
        .ListFieldsMandatory(0) = Array(txt_RET_Number, 10)
        .ListFieldsMandatory(1) = Array(txt_CCU_Desc(4), 64)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(4)
        Set .ListFieldsToDisable(1) = txt_CCU_Desc(4)
        Set .ListFieldsToDisable(2) = txt_Cust_Code(4)
        Set .ListFieldsToDisable(3) = txt_DocTypeDesc(4)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(5)
        .FrameIndex = 5
        .NameFrame = "EAS_OfficeInvoice"
        .MainConfigIndex = 0
        .DetailKey = 6

        .RequestView = "exec EAS_OfficeInvoice_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_OfficeInvoice_ins $OFI_Id$,$CT_Code$,$COC_Code$,$INV_Code$,$Z_creator$"
        .RequestUpd = "exec EAS_OfficeInvoice_upd $OFI_Id$,$CT_Code$,$COC_Code$,$INV_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_OfficeInvoice_del $OFI_Id$,$Z_last_upd_user$,$iConcurrency$"

        .UseTransaction = False
        .TableName = "EAS_OfficeInvoice"
        .ToolbarIndex = 5
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(2)
        .ListFieldsMandatory(0) = Array(cbo_OFI_Country, 12)
        .ListFieldsMandatory(1) = Array(cbo_OFI_CostCentre, 55)
        .ListFieldsMandatory(2) = Array(cbo_OFI_InvoiceType, 56)
        
        ReDim .ListFieldsToDisable(1)
        Set .ListFieldsToDisable(0) = txt_DetailKey(5)
        Set .ListFieldsToDisable(1) = txt_DocTypeDesc(5)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(6)
        .FrameIndex = 6
        .NameFrame = "EAS_AdminCustomer"
        .MainConfigIndex = 0
        .DetailKey = 7

        .RequestView = "exec EAS_AdminCustomer_sel $Key1$, $Language_Code$"
        .RequestAdd = "exec EAS_AdminCustomer_ins $ACU_Id$,$CCU_Capkey$,$Cust_Code$,$CT_Code$,$Z_creator$"
        .RequestUpd = "exec EAS_AdminCustomer_upd $ACU_Id$,$CCU_Capkey$,$Cust_Code$,$CT_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec EAS_AdminCustomer_del $ACU_Id$,$Z_last_upd_user$,$iConcurrency$"
        
        .UseTransaction = False
        .TableName = "EAS_AdminCustomer"
        .ToolbarIndex = 6
        .ToolbarID = 2815
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_CCU_Desc(6), 57)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(6)
        Set .ListFieldsToDisable(1) = txt_CCU_Desc(6)
        Set .ListFieldsToDisable(2) = txt_Cust_Code(6)
        Set .ListFieldsToDisable(3) = txt_DocTypeDesc(6)
        
        .MainGridColumns = Array( _
            "Id®©0®©1®©Id®©#Id", _
            "DocType®©0®©0®©DocType®©#DocType", _
            "DocTypeDesc®©1400®©0®©DocTypeDesc®©#Document type", _
            "Number®©1000®©0®©Number®©#Number", _
            "CCU_Capkey®©0®©0®©CCU_Capkey®©CCU_Capkey", _
            "Cust_Code®©1000®©0®©Cust_Code®©#Customer Number", _
            "CCU_Desc®©3000®©0®©CCU_Desc®©#Customer desc", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#Country", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creator_Name®©1500®©0®©Z_Creator_Name®©#User", _
            "Z_Creation_Date®©1000®©0®©Z_Creation_Date®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    For ll_Index = 0 To UBound(mt_MainConfig)
        mt_MainConfig(ll_Index).CurrentTvwSelMethod = eTvwSelMethod.etmNode
        ll_frameIndex = mt_MainConfig(ll_Index).FrameIndex
        cmd_TVReLoad(ll_frameIndex).Picture = LoadIconFromA_Icons(ICON_RELOAD)
        Call SetTreeDelayedMode(ll_frameIndex, False)
    Next
        
    For ll_Index = 0 To UBound(mt_DetailConfig)
        
        mt_DetailConfig(ll_Index).DeleteMsg(0, 0) = "7200"
        mt_DetailConfig(ll_Index).DeleteMsg(0, 1) = "#Do you really want to delete this record?"
        mt_DetailConfig(ll_Index).UpdateMsg(0, 0) = "2133"
        mt_DetailConfig(ll_Index).UpdateMsg(0, 1) = "#You can not update this record."
        mt_DetailConfig(ll_Index).CheckAddUpdMsg(0, 0) = "2102"
        mt_DetailConfig(ll_Index).CheckAddUpdMsg(0, 1) = "#You cannot add this item because this record is already in the database."
        mt_DetailConfig(ll_Index).CheckDelMsg(0, 0) = "2103"
        mt_DetailConfig(ll_Index).CheckDelMsg(0, 1) = "#You cannot delete this record because there is some data link to it." & vbCrLf & "You must delete all the records attached to it before being able to delete this record."
        
        mt_DetailConfig(ll_Index).AffectedCount = Array(1, 1, 1)
        If Not mt_DetailConfig(ll_Index).IsMultiDetailFrame Then
            Call InitFrameControls(mt_DetailConfig(ll_Index).InitControls)
        End If
    Next
    
    ReDim mt_SubdetailConfig(6)
    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        mt_SubdetailConfig(ll_Index).DeleteMsg(0, 0) = "7200"
        mt_SubdetailConfig(ll_Index).DeleteMsg(0, 1) = "#Do you really want to delete this record?"
        mt_SubdetailConfig(ll_Index).UpdateMsg(0, 0) = "2133"
        mt_SubdetailConfig(ll_Index).UpdateMsg(0, 1) = "#You can not update this record."
        mt_SubdetailConfig(ll_Index).CheckAddUpdMsg(0, 0) = "2102"
        mt_SubdetailConfig(ll_Index).CheckAddUpdMsg(0, 1) = "#You cannot add this item because this record is already in the database."
        mt_SubdetailConfig(ll_Index).CheckDelMsg(0, 0) = "2103"
        mt_SubdetailConfig(ll_Index).CheckDelMsg(0, 1) = "#You cannot delete this record because there is some data link to it." & vbCrLf & "You must delete all the records attached to it before being able to delete this record."
        
        mt_SubdetailConfig(ll_Index).GridDelayMethod = egmLoadAlways
        ReDim mt_SubdetailConfig(ll_Index).DeletedRows(-1 To -1)
    Next
    
    With mt_SubdetailConfig(0)
        .FrameIndex = 0
        .NameFrame = "EAS_SalesOrderPage"
        .DetailConfigIndex = 0
        .Initialized = False
        
        .RequestView = "exec EAS_SalesOrderPage_grd $Key1$"
        .RequestAdd = "exec EAS_SalesOrderPage_ins $PageId$,$SLO_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_SalesOrderPage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_SalesOrderPage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT SLP_Id FROM EAS_SalesOrderPage WHERE SLO_Id=$SLO_Id$ AND SLP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT SLP_Id FROM EAS_SalesOrderPage WHERE SLO_Id=$SLO_Id$ AND SLP_PageNr=$PageNr$ AND SLP_Id<>$PageId$"
        
        .TableName = "EAS_SalesOrderPage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 0
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©0®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    With mt_SubdetailConfig(1)
        .FrameIndex = 1
        .NameFrame = "EAS_PriceRequestPage"
        .DetailConfigIndex = 1
        .Initialized = False
        
        .RequestView = "exec EAS_PriceRequestPage_grd $Key1$"
        .RequestAdd = "exec EAS_PriceRequestPage_ins $PageId$,$PRQ_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_PriceRequestPage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_PriceRequestPage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT PRP_Id FROM EAS_PriceRequestPage WHERE PRQ_Id=$PRQ_Id$ AND PRP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT PRP_Id FROM EAS_PriceRequestPage WHERE PRQ_Id=$PRQ_Id$ AND PRP_PageNr=$PageNr$ AND PRP_Id<>$PageId$"
        
        .TableName = "EAS_PriceRequestPage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 1
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©0®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    With mt_SubdetailConfig(2)
        .FrameIndex = 2
        .NameFrame = "EAS_CreditMemoPage"
        .DetailConfigIndex = 2
        .Initialized = False
        
        .RequestView = "exec EAS_CreditMemoPage_grd $Key1$"
        .RequestAdd = "exec EAS_CreditMemoPage_ins $PageId$,$CRM_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_CreditMemoPage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_CreditMemoPage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT CRP_Id FROM EAS_CreditMemoPage WHERE CRM_Id=$CRM_Id$ AND CRP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT CRP_Id FROM EAS_CreditMemoPage WHERE CRM_Id=$CRM_Id$ AND CRP_PageNr=$PageNr$ AND CRP_Id<>$PageId$"
        
        .TableName = "EAS_CreditMemoPage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 2
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©0®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    With mt_SubdetailConfig(3)
        .FrameIndex = 3
        .NameFrame = "EAS_DebitMemoPage"
        .DetailConfigIndex = 3
        .Initialized = False
        
        .RequestView = "exec EAS_DebitMemoPage_grd $Key1$"
        .RequestAdd = "exec EAS_DebitMemoPage_ins $PageId$,$DBM_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_DebitMemoPage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_DebitMemoPage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT DBP_Id FROM EAS_DebitMemoPage WHERE DBM_Id=$DBM_Id$ AND DBP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT DBP_Id FROM EAS_DebitMemoPage WHERE DBM_Id=$DBM_Id$ AND DBP_PageNr=$PageNr$ AND DBP_Id<>$PageId$"
        
        .TableName = "EAS_DebitMemoPage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 3
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©0®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    With mt_SubdetailConfig(4)
        .FrameIndex = 4
        .NameFrame = "EAS_ReturnPage"
        .DetailConfigIndex = 4
        .Initialized = False
        
        .RequestView = "exec EAS_ReturnPage_grd $Key1$"
        .RequestAdd = "exec EAS_ReturnPage_ins $PageId$,$RET_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_ReturnPage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_ReturnPage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT REP_Id FROM EAS_ReturnPage WHERE RET_Id=$RET_Id$ AND REP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT REP_Id FROM EAS_ReturnPage WHERE RET_Id=$RET_Id$ AND REP_PageNr=$PageNr$ AND REP_Id<>$PageId$"
        
        .TableName = "EAS_ReturnPage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 4
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©0®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    With mt_SubdetailConfig(5)
        .FrameIndex = 5
        .NameFrame = "EAS_OfficeInvoicePage"
        .DetailConfigIndex = 5
        .Initialized = False
        
        .RequestView = "exec EAS_OfficeInvoicePage_grd $Key1$"
        .RequestAdd = "exec EAS_OfficeInvoicePage_ins $PageId$,$OFI_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_OfficeInvoicePage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_OfficeInvoicePage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT OFP_Id FROM EAS_OfficeInvoicePage WHERE OFI_Id=$OFI_Id$ AND OFP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT OFP_Id FROM EAS_OfficeInvoicePage WHERE OFI_Id=$OFI_Id$ AND OFP_PageNr=$PageNr$ AND OFP_Id<>$PageId$"
        
        .TableName = "EAS_OfficeInvoicePage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 5
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©0®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    With mt_SubdetailConfig(6)
        .FrameIndex = 6
        .NameFrame = "EAS_AdminCustomerPage"
        .DetailConfigIndex = 6
        .Initialized = False
        
        .RequestView = "exec EAS_AdminCustomerPage_grd $Key1$"
        .RequestAdd = "exec EAS_AdminCustomerPage_ins $PageId$,$ACU_Id$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$ZipTableIndex$,$Status$,$U_Code$"
        .RequestUpd = "exec EAS_AdminCustomerPage_upd $PageId$,$PageNr$,$NetworkBoardID$,$UserName$,$ComputerName$,$Status$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec EAS_AdminCustomerPage_del $PageId$,$DroppedPageNr$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = "SELECT ACP_Id FROM EAS_AdminCustomerPage WHERE ACU_Id=$ACU_Id$ AND ACP_PageNr=$PageNr$"
        .RequestCheckUpdate = "SELECT ACP_Id FROM EAS_AdminCustomerPage WHERE ACU_Id=$ACU_Id$ AND ACP_PageNr=$PageNr$ AND ACP_Id<>$PageId$"
        
        .TableName = "EAS_AdminCustomerPage"
        .TableOrder = ""
        
        .ToolbarID = 2816
        .ToolbarIndex = 6
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PageId®©0®©1®©PageId®©PageId", _
            "PageNr®©800®©0®©PageNr®©#Page nr", _
            "DroppedPageNr®©0®©0®©DroppedPageNr®©#DroppedPageNr", _
            "UserName®©1000®©0®©UserName®©#User name", _
            "ComputerName®©1000®©0®©ComputerName®©#Computer", _
            "NetworkBoardID®©1000®©0®©NetworkBoardID®©#Network board", _
            "ZipTableIndex®©600®©0®©ZipTableIndex®©#Zip table", _
            "Status®©600®©0®©Status®©#Status", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "FileName®©0®©0®©FileName®©#FileName", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(0)
        .ListFieldsMandatory(0) = Array(txt_PageNr(.FrameIndex), 16)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_Status(.FrameIndex)
        Set .ListFieldsToDisable(1) = txt_Computer(.FrameIndex)
        Set .ListFieldsToDisable(2) = txt_NetworkBoardID(.FrameIndex)
        Set .ListFieldsToDisable(3) = txt_UserName(.FrameIndex)
    End With
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Load_ConfigInfo")
End Sub

Private Function tlb_Main_CustomAction(Index As Integer, ByVal as_Role As String, as_Language As String) As Boolean
On Error GoTo ErrHandler
    
    Dim ll_MainIndex As Long
    
    ll_MainIndex = FindMainConfigByFrameIndex(Index)
    
    tlb_Main_CustomAction = False
    Select Case as_Role
    Case "A"
        Call LockScreen(False)
        Call tlb_Main(0).ShowPopup(mnu_EAS, "A")
        Call LockScreen(True)
        tlb_Main_CustomAction = True
    Case "B", "C"
        If StrComp(mt_MainConfig(ll_MainIndex).NameFrame, "EAS_Viewer", vbTextCompare) = 0 Then
            If grd_Main(Index).SelectedCount = 1 Then
                mt_MainConfig(ll_MainIndex).CurrentDetailIndex = FindDetailConfigByDocumentType(Val(grd_Main(Index).SelectedLine(0, "DocType")))
            End If
        End If
    End Select
    Exit Function
ErrHandler:
    Call ErrorHandler("tlb_Main_CustomAction")
End Function

Private Function tlb_detail_CustomAction(Index As Integer, ByVal as_Role As String, as_Language As String) As Boolean
On Error GoTo ErrHandler
    
Dim ll_FDA_Code As Long
Dim ll_DetailIndex As Long

    tlb_detail_CustomAction = False
    ll_DetailIndex = FindDetailConfigByFrameIndex(Index)
    Select Case as_Role
    End Select
    Exit Function
ErrHandler:
    Call ErrorHandler("tlb_detail_CustomAction")
End Function

Private Function tlb_Subdetail_CustomAction(Index As Integer, ByVal as_Role As String, as_Language As String) As Boolean
On Error GoTo ErrHandler
    
    Dim ll_SubdetailIndex As Long
    Dim le_DocumentType As eDocumentType
    Dim ll_ZipTableIndex As Long
    Dim ll_PageId As Long
    
    tlb_Subdetail_CustomAction = False
    ll_SubdetailIndex = FindSubDetailConfigByFrameIndex(Index)
    le_DocumentType = mt_DetailConfig(mt_SubdetailConfig(ll_SubdetailIndex).DetailConfigIndex).DetailKey
    If as_Role = "O" Or as_Role = "P" Or as_Role = "g" Then
        tlb_Subdetail_CustomAction = True
        If grd_Subdetail(Index).SelectedCount <> 1 Then Exit Function
        ll_ZipTableIndex = Val(grd_Subdetail(Index).SelectedLine(0, "ZipTableIndex"))
        ll_PageId = Val(grd_Subdetail(Index).SelectedLine(0, "PageId"))
        
        Select Case as_Role
        Case "P"
            If grd_Subdetail(Index).SelectedLine(0, "Status") = eZipDocumentStatus.Uploaded Then
                Call DownloadPDF(le_DocumentType, ll_ZipTableIndex, ll_PageId)
            Else
                Call MsgBox(MsgText(C_MSG_ID_BASE, ms_Language_Code, "Document page is waiting for upload"))
            End If
        Case "g"
            If grd_Subdetail(Index).SelectedLine(0, "Status") = eZipDocumentStatus.Uploaded Then
                Call ShowPDF(le_DocumentType, ll_ZipTableIndex, ll_PageId)
            Else
                Call MsgBox(MsgText(C_MSG_ID_BASE, ms_Language_Code, "Document page is waiting for upload"))
            End If
        End Select
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("tlb_Subdetail_CustomAction")
End Function

Private Function FindDetailConfigByDocumentType(ByVal ae_DocumentType As eDocumentType) As Long
On Error GoTo ErrHandler

    Select Case ae_DocumentType
    Case eDocumentType.dtSalesOrder
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_SalesOrder")
    Case eDocumentType.dtPriceRequest
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_PriceRequest")
    Case eDocumentType.dtCreditMemo
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_CreditMemo")
    Case eDocumentType.dtDebitMemo
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_DebitMemo")
    Case eDocumentType.dtReturn
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_Return")
    Case eDocumentType.dtOfficeInvoice
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_OfficeInvoice")
    Case eDocumentType.dtAdminCustomer
        FindDetailConfigByDocumentType = FindDetailConfigByName("EAS_AdminCustomer")
    Case Else
        Err.Raise ArmErr.CompFncFailed, "ae_DocumentType", "Unknown document type : " & ae_DocumentType
    End Select
    Exit Function
ErrHandler:
    Call ErrorHandler("FindDetailConfigByDocumentType")
End Function

Private Function grd_Main_CustomAction(Index As Integer, ByVal ae_Action As eControlAction) As Boolean
On Error GoTo ErrHandler

Dim ll_MainIndex As Long
Dim ll_FDA_Code As Long

    grd_Main_CustomAction = False
    ll_MainIndex = FindMainConfigByFrameIndex(Index)
    If StrComp(mt_MainConfig(ll_MainIndex).NameFrame, "EAS_Viewer", vbTextCompare) = 0 Then
        If grd_Main(Index).SelectedCount = 1 Then
            mt_MainConfig(ll_MainIndex).CurrentDetailIndex = FindDetailConfigByDocumentType(Val(grd_Main(Index).SelectedLine(0, "DocType")))
        End If
    End If
    grd_Main_CustomAction = False
    Exit Function
ErrHandler:
    Call ErrorHandler("grd_Main_CustomAction")
End Function

Private Function Resize_Custom() As Boolean
On Error GoTo ErrHandler

    Resize_Custom = False
    Exit Function
ErrHandler:
    Call ErrorHandler("Resize_Custom")
End Function

Private Sub Item_CustomInit(ByVal al_DetailIndex As Long, ByVal av_Key As Variant, ByVal ae_Mode As eMode)
On Error GoTo ErrHandler

    Dim ll_DetailFrameIndex As Long
    
    ll_DetailFrameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    If ae_Mode = emAdd Then
        txt_DocType(ll_DetailFrameIndex).Text = al_DetailIndex + 1
        txt_DocTypeDesc(ll_DetailFrameIndex).Text = mo_DocumentType(al_DetailIndex + 1)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_CustomInit")
End Sub

Private Sub Item_CustomLoad(ByVal al_DetailIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler

Dim ls_Request As String
Dim lo_Tree As ArmTreeView
Dim ll_MainConfigIndex As Long
Dim lsa_path() As String

    ll_MainConfigIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    
    If StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_CustomLoad")
End Sub

Private Function FormatSAPNumber(ByVal as_Number As String) As String
On Error GoTo ErrHandler

    FormatSAPNumber = right("0000000000" & as_Number, 10)
    Exit Function
ErrHandler:
    Call ErrorHandler("FormatSAPNumber")
End Function

Private Function Item_CustomCheck(ByVal al_DetailIndex As Long, ByVal ae_Mode As eMode) As Boolean
On Error GoTo ErrHandler
    Dim ll_MainConfigIndex As Long
    Dim ll_MainFrameIndex As Long
    
    Item_CustomCheck = False
    ll_MainConfigIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
    If StrComp(mt_MainConfig(ll_MainConfigIndex).NameFrame, "EAS_Viewer", vbTextCompare) = 0 Then
        If (ae_Mode = emAdd) Or (ae_Mode = emUpdate) Then
            Select Case al_DetailIndex + 1
            Case eDocumentType.dtSalesOrder
                If Not isNumeric(txt_SLO_Number.Text) Then
                    Call MsgBox(MsgText(C_MSG_ID_BASE + 1, ms_Language_Code, "#Invalid document number"))
                    Item_CustomCheck = False
                    Exit Function
                End If
                txt_SLO_Number.Text = FormatSAPNumber(txt_SLO_Number.Text)
            Case eDocumentType.dtCreditMemo
                If Not isNumeric(txt_CRM_Number.Text) Then
                    Call MsgBox(MsgText(C_MSG_ID_BASE + 1, ms_Language_Code, "#Invalid document number"))
                    Item_CustomCheck = False
                    Exit Function
                End If
                txt_CRM_Number.Text = FormatSAPNumber(txt_CRM_Number.Text)
            Case eDocumentType.dtDebitMemo
                If Not isNumeric(txt_DBM_Number.Text) Then
                    Call MsgBox(MsgText(C_MSG_ID_BASE + 1, ms_Language_Code, "#Invalid document number"))
                    Item_CustomCheck = False
                    Exit Function
                End If
                txt_DBM_Number.Text = FormatSAPNumber(txt_DBM_Number.Text)
            Case eDocumentType.dtReturn
                If Not isNumeric(txt_RET_Number.Text) Then
                    Call MsgBox(MsgText(C_MSG_ID_BASE + 1, ms_Language_Code, "#Invalid document number"))
                    Item_CustomCheck = False
                    Exit Function
                End If
                txt_RET_Number.Text = FormatSAPNumber(txt_RET_Number.Text)
            End Select
        End If
    End If
    Item_CustomCheck = True
    Exit Function
ErrHandler:
    Call ErrorHandler("Item_CustomCheck")
End Function

Private Sub Item_CustomLoadDefaultValue(ByVal al_DetailIndex As Long, ByRef av_ListFieldsDefaultValue As Variant)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long, ll_MainConfigIndex As Long
Dim lo_Tree As ArmTreeView
Dim ls_Code As String, ls_Desc As String

Dim ll_SubdetailConfig As Long
Dim ll_SubdetailFrame As Long
Dim ll_Idx As Long

    ll_MainConfigIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    
    If StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_CustomLoadDefaultValue")
End Sub

Private Function Item_CustomAddDB(ByVal al_DetailIndex As Long, ByVal ab_InTransaction As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    Item_CustomAddDB = True
    Exit Function
ErrHandler:
    Item_CustomAddDB = False
    Call ErrorHandler("Item_CustomAddDB")
End Function

Private Function Item_CustomUpdateDB(ByVal al_DetailIndex As Long, ByVal ab_InTransaction As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
Dim ls_Request As String

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    If StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    
    Item_CustomUpdateDB = True
    Exit Function
ErrHandler:
    Item_CustomUpdateDB = False
    Call ErrorHandler("Item_CustomUpdateDB")
End Function

Private Function Item_CustomDeleteDB(ByVal al_DetailIndex As Long, ByVal ab_InTransaction As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    If Not ab_InTransaction Then
        If (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_SalesOrder", vbTextCompare) = 0) Then
            txt_SLO_DroppedNumber.Text = -Val(GetNextID("EAS_DroppedNumber"))
        ElseIf (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_CreditMemo", vbTextCompare) = 0) Then
            txt_CRM_DroppedNumber.Text = -Val(GetNextID("EAS_DroppedNumber"))
        ElseIf (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_DebitMemo", vbTextCompare) = 0) Then
            txt_DBM_DroppedNumber.Text = -Val(GetNextID("EAS_DroppedNumber"))
        ElseIf (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_Return", vbTextCompare) = 0) Then
            txt_RET_DroppedNumber.Text = -Val(GetNextID("EAS_DroppedNumber"))
        End If
    End If
    Item_CustomDeleteDB = True
    Exit Function
ErrHandler:
    Item_CustomDeleteDB = False
    Call ErrorHandler("Item_CustomDeleteDB")
End Function

Private Sub Item_CustomLocal(ByVal al_DetailIndex As Long, ByVal ae_Mode As eMode)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
Dim ll_MainIndex As Long
Dim ll_MainFrame As Long

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrame = mt_MainConfig(ll_MainIndex).FrameIndex
    
    If ae_Mode = emAdd Then
        grd_Main(ll_MainFrame).SelectedLine(0, "Z_Creation_Date") = Now
        grd_Main(ll_MainFrame).SelectedLine(0, "Z_Creator") = ml_U_Code
        grd_Main(ll_MainFrame).SelectedLine(0, "Z_Creator_Name") = ms_UserName
    End If
        
    If (ae_Mode = emAdd) Or (ae_Mode = emUpdate) Then
        grd_Main(ll_MainFrame).SelectedLine(0, "Id") = txt_DetailKey(ll_frameIndex).Text
        Select Case al_DetailIndex + 1
        Case eDocumentType.dtPriceRequest
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_DetailKey(ll_frameIndex).Text
        Case eDocumentType.dtSalesOrder
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_SLO_Number.Text
        Case eDocumentType.dtCreditMemo
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_CRM_Number.Text
        Case eDocumentType.dtDebitMemo
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_DBM_Number.Text
        Case eDocumentType.dtReturn
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_RET_Number.Text
        Case eDocumentType.dtOfficeInvoice
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_DetailKey(ll_frameIndex).Text
        Case eDocumentType.dtAdminCustomer
            grd_Main(ll_MainFrame).SelectedLine(0, "Number") = txt_DetailKey(ll_frameIndex).Text
        End Select
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_CustomLocal")
End Sub

Private Sub SubItem_CustomInit(ByVal al_SubDetailIndex As Long, ByVal av_Key As Variant, ByVal ae_Mode As eMode)
On Error GoTo ErrHandler
    Dim ll_frameIndex As Long
    Dim ll_DetailIndex As Long
    Dim le_DocumentType As eDocumentType
    Dim ll_Count As Long
    
    ll_DetailIndex = mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    If (ae_Mode = eMode.emAdd) Or (ae_Mode = eMode.emUpdate) Then
        txt_Computer(ll_frameIndex).Text = ms_ComputerName
        txt_UserName(ll_frameIndex).Text = ms_LoginName
        txt_NetworkBoardID(ll_frameIndex).Text = ms_NetworkBoardID
    End If
    If (ae_Mode = eMode.emAdd) Then
        txt_Status(ll_frameIndex).Text = eZipDocumentStatus.Waiting
        le_DocumentType = ll_DetailIndex + 1
        If ml_ZipTableIndex(le_DocumentType) = 0 Then
            ml_ZipTableIndex(le_DocumentType) = GetDocumentZipTableIndexMax(le_DocumentType)
        End If
        
        ll_Count = GetDocumentPageCount(le_DocumentType, ml_ZipTableIndex(le_DocumentType))
        If ll_Count >= ml_MaxZipRecordCount Then
            ml_ZipTableIndex(le_DocumentType) = ml_ZipTableIndex(le_DocumentType) + 1
        End If
        txt_ZipTableIndex(ll_frameIndex).Text = ml_ZipTableIndex(le_DocumentType)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_CustomInit")
End Sub

Private Sub SubItem_CustomLoadDefaultValue(ByVal al_SubDetailIndex As Long, ByRef av_ListFieldsDefaultValue As Variant)
On Error GoTo ErrHandler

    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_CustomLoadDefaultValue")
End Sub

Private Function SubItem_CustomCheck(ByVal al_SubDetailIndex As Long, ByVal ae_Mode As eMode) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
Dim ll_PageNr As Long
Dim ll_RowIdx As Long
Dim ls_Filename As String
Dim lv_MsgReplaceInfo(0, 1) As String
    
    SubItem_CustomCheck = True
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    
    If Not isNumeric(txt_PageNr(ll_frameIndex).Text) Then
        Call MsgBox(MsgText(C_MSG_ID_BASE + 2, ms_Language_Code, "#Invalid page number"), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        SubItem_CustomCheck = False
        Exit Function
    End If
    
    ll_PageNr = Val(txt_PageNr(ll_frameIndex).Text)
    If ll_PageNr <= 0 Then
        Call MsgBox(MsgText(C_MSG_ID_BASE + 2, ms_Language_Code, "#Invalid page number"), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        SubItem_CustomCheck = False
        Exit Function
    End If
    
    ls_Filename = txt_FileName(ll_frameIndex).Text
    If ls_Filename <> "" Then
        If Not mo_FSO.FileExists(ls_Filename) Then
            lv_MsgReplaceInfo(0, 0) = "$FileName$"
            lv_MsgReplaceInfo(0, 1) = ls_Filename
            Call MsgBox(MsgText(C_MSG_ID_BASE + 3, ms_Language_Code, "#The file '" & lv_MsgReplaceInfo(0, 1) & "' does not exists.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            SubItem_CustomCheck = False
            Exit Function
        End If
    End If
    If (ae_Mode = eMode.emAdd) Then
        If ls_Filename = "" Then
            lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
            lv_MsgReplaceInfo(0, 1) = lbl_Label(14).Caption
            Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            SubItem_CustomCheck = False
            Exit Function
        End If
        For ll_RowIdx = 0 To grd_Subdetail(ll_frameIndex).Rows - 1
            If Val(grd_Subdetail(ll_frameIndex).Data(ll_RowIdx, "PageNr")) = ll_PageNr Then
                Call MsgBox(MsgText(mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 0), ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 1)))
                SubItem_CustomCheck = False
                Exit Function
            End If
        Next
    ElseIf (ae_Mode = eMode.emUpdate) Then
        For ll_RowIdx = 0 To grd_Subdetail(ll_frameIndex).Rows - 1
            If (Val(grd_Subdetail(ll_frameIndex).Data(ll_RowIdx, "PageNr")) = ll_PageNr) And _
               (Val(grd_Subdetail(ll_frameIndex).Data(ll_RowIdx, "PageId")) <> Val(txt_SubDetailKey(ll_frameIndex))) Then
                Call MsgBox(MsgText(mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 0), ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 1)))
                SubItem_CustomCheck = False
                Exit Function
            End If
        Next
    End If
    
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_CustomCheck")
End Function

Private Function SubItem_CustomCheckDB(ByVal al_SubDetailIndex As Long, ByVal ae_Mode As eMode)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    If StrComp(mt_SubdetailConfig(al_SubDetailIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    SubItem_CustomCheckDB = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_CustomCheckDB")
End Function

Private Function SubItem_CustomAdd(ByVal al_SubDetailIndex As Long, ByRef ab_CustomSaved As Boolean) As Boolean
On Error GoTo ErrHandler

Dim lb_OldInternalInit As Boolean
Dim ll_frameIndex As Long
Dim ll_Count As Long
Dim ll_DetailIndex As Long
Dim le_DocumentType As eDocumentType

    ab_CustomSaved = False
    lb_OldInternalInit = mb_InternalInit
    mb_InternalInit = True
    
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailIndex = mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex
    If StrComp(mt_SubdetailConfig(al_SubDetailIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    mb_InternalInit = lb_OldInternalInit
    SubItem_CustomAdd = True
    Exit Function
ErrHandler:
    mb_InternalInit = lb_OldInternalInit
    Call ErrorHandler("SubItem_CustomAdd")
End Function

Private Function SubItem_CustomUpdate(ByVal al_SubDetailIndex As Long, ByRef ab_CustomSaved As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ab_CustomSaved = False
    SubItem_CustomUpdate = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_CustomUpdate")
End Function

Private Function SubItem_CustomDelete(ByVal al_SubDetailIndex As Long, ByRef ab_CustomSaved As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ls_Request As String
Dim ll_frameIndex As Long
Dim ll_DetailConfig As Long
Dim ll_DetailFrame As Long
Dim ll_RowIdx As Long, ll_ColIdx As Long

    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailConfig = mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex
    ll_DetailFrame = mt_DetailConfig(ll_DetailConfig).FrameIndex
    
    ab_CustomSaved = False
    SubItem_CustomDelete = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_CustomDelete")
End Function

Private Function SubItem_CustomDBBefore(ByVal al_SubDetailIndex As Long, ByVal ae_Mode As eMode, ByVal al_Index As Long, ByRef ab_CustomSaved As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ls_Request As String
Dim ll_frameIndex As Long
Dim ll_DetailConfig As Long
Dim ll_DetailFrame As Long
Dim ll_RowIdx As Long, ll_ColIdx As Long

    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailConfig = mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex
    ll_DetailFrame = mt_DetailConfig(ll_DetailConfig).FrameIndex
    
    If ae_Mode = eMode.emDelete Then
        ll_ColIdx = grd_Subdetail(ll_frameIndex).Columns("DroppedPageNr").ColumnIndex
        mt_SubdetailConfig(al_SubDetailIndex).DeletedRows(al_Index)(ll_ColIdx) = -Val(GetNextID("EAS_DroppedPageNr"))
    End If
    SubItem_CustomDBBefore = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_CustomDBBefore")
End Function

Private Function SubItem_CustomDBAfter(ByVal al_SubDetailIndex As Long, ByVal ae_Mode As eMode, ByVal al_Index As Long, ByRef ab_CustomSaved As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
Dim ll_DetailConfig As Long
Dim ll_DetailFrame As Long
Dim ll_PageId As Long, ll_ZipTableIndex As Long
Dim le_DocumentType As eDocumentType
Dim ls_Filename As String

    SubItem_CustomDBAfter = False
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailConfig = mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex
    ll_DetailFrame = mt_DetailConfig(ll_DetailConfig).FrameIndex
    ll_PageId = Val(txt_SubDetailKey(ll_frameIndex).Text)
    ll_ZipTableIndex = grd_Subdetail(ll_frameIndex).Data(al_Index, "ZipTableIndex")
    ls_Filename = grd_Subdetail(ll_frameIndex).Data(al_Index, "FileName")
    le_DocumentType = ll_DetailConfig + 1
    If (ae_Mode = eMode.emAdd) Or (ae_Mode = eMode.emUpdate) Then
        If ls_Filename <> "" Then
            If grd_Subdetail(ll_frameIndex).Data(al_Index, "Status") = eZipDocumentStatus.Uploaded Then
                Call UploadPDF(le_DocumentType, ls_Filename, ll_ZipTableIndex, ll_PageId)
            Else
                Call Document_Copy(ls_Filename, le_DocumentType, ll_PageId)
            End If
        End If
    End If
    SubItem_CustomDBAfter = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_CustomDBAfter")
End Function

Private Function IsItemInFilterCustom(ByVal al_DetailIndex As Long, ByRef ab_CheckDone As Boolean) As Boolean
On Error GoTo ErrHandler

    IsItemInFilterCustom = False
    ab_CheckDone = False
    Exit Function
ErrHandler:
    Call ErrorHandler("IsItemInFilterCustom")
End Function

Private Function IsItemSelectedInTreeCustom(ByVal al_DetailIndex As Long, ByRef ao_Tree As ArmTreeView, ByVal av_PathData As Variant, ByRef ab_CheckDone As Boolean) As Boolean
Dim ll_MainIndex As Long
Dim ll_MainFrameIndex As Long

    ab_CheckDone = False
    IsItemSelectedInTreeCustom = False
    
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    
    If FindDetailConfigByName("") = al_DetailIndex Then
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("IsItemSelectedInTreeCustom")
End Function

Private Sub SetDisabledDetailControls()
On Error GoTo ErrHandler

Dim ll_MainIndex As Long
Dim ll_DetailIndex As Long

    ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    
    Select Case UCase(mt_MainConfig(ll_MainIndex).NameFrame)
    End Select
    Exit Sub
ErrHandler:
    Call ErrorHandler("SetDisabledDetailControls")
End Sub

' parameter is nothing if all driven combo request should be set,
'it is control reference, if just driven controls request for specific control should be set
Private Sub SetDrivenDetailControls(ByRef ao_Control As Object)
On Error GoTo ErrHandler

Dim ll_MainIndex As Long
Dim ll_DetailIndex As Long
Dim ls_Request As String

    ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    
    Select Case UCase(mt_MainConfig(ll_MainIndex).NameFrame)
    End Select
    Call SetDisabledDetailControls
    Exit Sub
ErrHandler:
    Call ErrorHandler("SetDrivenDetailControls")
End Sub

Private Sub UpdateMainToolbarCustom(ByVal al_MainIndex As Long)
On Error GoTo ErrHandler
Dim ll_frameIndex As Long
    
    ll_frameIndex = mt_MainConfig(al_MainIndex).FrameIndex
    
    If StrComp(mt_MainConfig(al_MainIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateMainToolbarCustom")
End Sub

Private Sub UpdateDetailToolbarCustom(ByVal al_Detailndex As Long)
On Error GoTo ErrHandler
Dim ll_DetailFrameIndex As Long
Dim ll_MainFrameIndex As Long
Dim ll_MainIndex As Long

    ll_DetailFrameIndex = mt_DetailConfig(al_Detailndex).FrameIndex
    ll_MainIndex = mt_DetailConfig(al_Detailndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    
    If StrComp(mt_MainConfig(ll_MainIndex).NameFrame, "", vbTextCompare) = 0 Then
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateDetailToolbarCustom")
End Sub

Private Sub UpdateSubdetailToolbarCustom(ByVal al_Subdetailndex As Long)
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateSubdetailToolbarCustom")
End Sub

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK 1.0
' please DO NOT change anything in this part of code
'**********************************************************************************************************************************
'**********************************************************************************************************************************

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK PROPERTIES
' please DO NOT change anything in this part of code
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Public Property Let Visible(ByVal aVisible As Boolean)
    UserControl.Extender.Visible = aVisible
End Property

Public Property Get Visible() As Boolean
    Visible = UserControl.Extender.Visible
End Property

Public Property Let Top(ByVal aTop As Single)
    UserControl.Extender.Top = aTop
End Property
Public Property Get Top() As Single
    Top = UserControl.Extender.Top
End Property

Public Property Let Height(ByVal aHeight As Single)
    UserControl.Extender.Height = aHeight
End Property
Public Property Get Height() As Single
    Height = UserControl.Extender.Height
End Property

Public Property Let Left(ByVal aLeft As Single)
    UserControl.Extender.Left = aLeft
End Property
Public Property Get Left() As Single
    Left = UserControl.Extender.Left
End Property

Public Property Let Width(ByVal aWidth As Single)
    UserControl.Extender.Width = aWidth
End Property
Public Property Get Width() As Single
    Width = UserControl.Extender.Width
End Property

Public Sub Move(ByVal aLeft As Single, ByVal aTop As Single, ByVal aWidth As Single, ByVal aHeight As Single)
    Call UserControl.Extender.Move(aLeft, aTop, aWidth, aHeight)
End Sub

Public Property Get Initialized() As Boolean
    Initialized = mb_Initialized
End Property

Property Get ConnectString() As String
    ConnectString = m_ConnectString
End Property

Property Let LoginName(as_Login As String)
ms_LoginName = as_Login
End Property

Property Let U_Code(al_Code As Long)
ml_U_Code = al_Code
End Property

Property Let Language_Code(AString As String)
ms_Language_Code = AString
End Property

Public Property Set ArmDb(ByRef local_connection As Object)
    If Not (local_connection Is Nothing) Then
        Set mo_Db = local_connection
    End If
End Property

Private Sub cmd_BrowseFile_Click(Index As Integer)
On Error GoTo ErrHandler
    
Dim ls_Filename As String
   
    dlg_Common.Filter = "PDF files (*.PDF)|*.PDF"
    dlg_Common.CancelError = False
    Call dlg_Common.ShowOpen
    ls_Filename = dlg_Common.FileName
    If ls_Filename <> "" Then
        txt_FileName(Index).Text = ls_Filename
    End If
    Exit Sub
ErrHandler:
    Call ErrorMessage("cmd_BrowseFile_Click Index=" & Index)
End Sub

Private Sub cmd_CustomerSeek_Click(Index As Integer)
On Error GoTo ErrHandler
    
Dim ls_CCUCapKey As String
Dim lo_SeekForm As SeekForm
Dim lv_Code As Variant
Dim lv_Desc As String
    
    gs_CaptureCountry = "GB"
    Set lo_SeekForm = New SeekForm
    Load lo_SeekForm
    lo_SeekForm.Language = ms_Language_Code
    Set lo_SeekForm.ArmDb = mo_Db
    lo_SeekForm.ComponentType = "CUSTOMER"
    lo_SeekForm.TreeViewFiltersDesc = ""
    lo_SeekForm.TreeViewFilters = "" & SEP & "" & SEP & "" & SEP & "NULL"
    lo_SeekForm.TreeView_DateType = "0"
    lo_SeekForm.Load_A_COM
    lo_SeekForm.SYS_code = 1
    
    Call lo_SeekForm.show(vbModal)
    
    If lo_SeekForm.SelectedData = True Then
        txt_CCU_Desc(Index).Text = lo_SeekForm.SelectedItemDesc
        txt_Cust_Code(Index).Text = GetSeparatedStringElement(lo_SeekForm.SelectedItemFull, "CUST_Code")
        txt_CCU_Capkey(Index).Text = GetSeparatedStringElement(lo_SeekForm.SelectedItemFull, "CCU_Capkey")
        If Not lo_SeekForm.cbo_country.SelectedItem Is Nothing Then
            txt_CT_Code(Index).Text = lo_SeekForm.cbo_country.SelectedItem.Key
            txt_CT_Desc(Index).Text = lo_SeekForm.cbo_country.Text
        End If
    End If
    
    Call lo_SeekForm.Unload_A_COM
    Unload lo_SeekForm
    Set lo_SeekForm = Nothing
    Exit Sub
ErrHandler:
    Call ErrorMessage("cmd_CustomerSeek_Click Index=" & Index)
End Sub

Private Function GetSeparatedStringElement(ByVal as_SeparatedString As String, ByVal as_Name As String) As String
On Error GoTo ErrHandler
    
    Dim lsa_Array() As String
    Dim ll_Idx As Long
    
    GetSeparatedStringElement = ""
    lsa_Array = Split(as_SeparatedString, SEP)
    ll_Idx = 0
    While ll_Idx < UBound(lsa_Array)
        If StrComp(as_Name, lsa_Array(ll_Idx), vbTextCompare) = 0 Then
            GetSeparatedStringElement = lsa_Array(ll_Idx + 1)
            Exit Function
        End If
        ll_Idx = ll_Idx + 3
    Wend
    Exit Function
ErrHandler:
    Call ErrorHandler("GetSeparatedStringElement")
End Function


Private Sub UploadPDF(ByVal ae_DocumentType As eDocumentType, ByVal as_FileName As String, ByVal al_ZipTableIndex As Long, ByVal al_PageId As Long)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ls_RequestDel As String
Dim ls_RequestIns As String
Dim ls_RequestUpd As String
Dim ls_Filename As String

    Select Case ae_DocumentType
    Case eDocumentType.dtSalesOrder
        ls_RequestDel = "DELETE FROM EAS_SalesOrderPageZip$ZipTableIndex$ WHERE SLP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_SalesOrderPageZip$ZipTableIndex$ (SLP_Id,SLPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_SalesOrderPage_upd2 $PageId$,$Status$"
    Case eDocumentType.dtPriceRequest
        ls_RequestDel = "DELETE FROM EAS_PriceRequestPageZip$ZipTableIndex$ WHERE PRP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_PriceRequestPageZip$ZipTableIndex$ (PRP_Id,PRPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_PriceRequestPage_upd2 $PageId$,$Status$"
    Case eDocumentType.dtCreditMemo
        ls_RequestDel = "DELETE FROM EAS_CreditMemoPageZip$ZipTableIndex$ WHERE CRP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_CreditMemoPageZip$ZipTableIndex$ (CRP_Id,CRPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_CreditMemoPage_upd2 $PageId$,$Status$"
    Case eDocumentType.dtDebitMemo
        ls_RequestDel = "DELETE FROM EAS_DebitMemoPageZip$ZipTableIndex$ WHERE DBP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_DebitMemoPageZip$ZipTableIndex$ (DBP_Id,DBPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_DebitMemoPage_upd2 $PageId$,$Status$"
    Case eDocumentType.dtReturn
        ls_RequestDel = "DELETE FROM EAS_ReturnPageZip$ZipTableIndex$ WHERE REP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_ReturnPageZip$ZipTableIndex$ (REP_Id,REPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_ReturnPage_upd2 $PageId$,$Status$"
    Case eDocumentType.dtOfficeInvoice
        ls_RequestDel = "DELETE FROM EAS_OfficeInvoicePageZip$ZipTableIndex$ WHERE OFP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_OfficeInvoicePageZip$ZipTableIndex$ (OFP_Id,OFPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_OfficeInvoicePage_upd2 $PageId$,$Status$"
    Case eDocumentType.dtAdminCustomer
        ls_RequestDel = "DELETE FROM EAS_AdminCustomerPageZip$ZipTableIndex$ WHERE ACP_Id=$PageId$"
        ls_RequestIns = "INSERT INTO EAS_AdminCustomerPageZip$ZipTableIndex$ (ACP_Id,ACPZ_Data) VALUES ($PageId$,?)"
        ls_RequestUpd = "exec EAS_AdminCustomerPage_upd2 $PageId$,$Status$"
    Case Else
        Err.Raise ArmErr.CompFncFailed, "GetDocumentType", "Unknown document type : " & ae_DocumentType
    End Select
    ls_RequestDel = ReplacePlaceHolder(ls_RequestDel, "$ZipTableIndex$", right("000" & al_ZipTableIndex, 3))
    ls_RequestDel = ReplacePlaceHolder(ls_RequestDel, "$PageId$", al_PageId)
    
    ls_RequestIns = ReplacePlaceHolder(ls_RequestIns, "$ZipTableIndex$", right("000" & al_ZipTableIndex, 3))
    ls_RequestIns = ReplacePlaceHolder(ls_RequestIns, "$PageId$", al_PageId)
    
    ls_RequestUpd = ReplacePlaceHolder(ls_RequestUpd, "$PageId$", al_PageId)
    ls_RequestUpd = ReplacePlaceHolder(ls_RequestUpd, "$Status$", eZipDocumentStatus.Uploaded)
    
    Call ExecuteSQLSafe(mo_Db, ls_RequestDel)
    If Not mo_Db.FileToBlobSQL(ls_RequestIns, as_FileName, 9) Then
        Err.Raise ArmErr.SQLFailure, "FileToBlobSQL", mo_Db.LastErrorMessage & " Error writing blob: " & ls_RequestIns & " File: " & ls_Filename
    End If
    Call ExecuteSQLSafe(mo_Db, ls_RequestUpd)
    Exit Sub
ErrHandler:
    Call ErrorHandler("UploadPDF as_FileName=" & as_FileName & _
                               " ae_DocumentType=" & ae_DocumentType & _
                               " al_ZipTableIndex=" & al_ZipTableIndex & _
                               " al_PageId=" & al_PageId)
End Sub

Private Function DownloadPDF(ByVal ae_DocumentType As eDocumentType, ByVal al_ZipTableIndex As Long, ByVal al_PageId As Long) As Boolean
On Error GoTo ErrHandler

Dim ls_Filename As String

    DownloadPDF = False
    
    If MsgBox(MsgText(C_MSG_ID_BASE + 4, ms_Language_Code, "#Are you sure to download PDF file ? Operation can take long time"), vbYesNo) = vbNo Then Exit Function
    dlg_Common.Filter = "PDF files (*.PDF)|*.PDF"
    dlg_Common.CancelError = False
    dlg_Common.FileName = "File_" & ae_DocumentType & "_" & al_PageId & ".PDF"
    Call dlg_Common.ShowSave
    ls_Filename = dlg_Common.FileName
    If ls_Filename <> "" Then
        DownloadPDF = DownloadPDFToFile(ae_DocumentType, al_ZipTableIndex, al_PageId, ls_Filename)
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("DownloadPDF")
End Function

Private Function ShowPDF(ByVal ae_DocumentType As eDocumentType, ByVal al_ZipTableIndex As Long, ByVal al_PageId As Long) As Boolean
On Error GoTo ErrHandler

Dim ls_TempDir As String
Dim ls_Filename As String
Dim lo_shell As Object

    ShowPDF = False
    If MsgBox(MsgText(C_MSG_ID_BASE + 4, ms_Language_Code, "Are you sure to download PDF file ? Operation can take long time"), vbYesNo) = vbNo Then Exit Function
    ls_TempDir = GetTempDir()
    If Not mo_FSO.FolderExists(ls_TempDir) Then
      Call mo_FSO.CreateFolder(ls_TempDir)
    End If
    ls_Filename = "File_" & ae_DocumentType & "_" & al_PageId & ".PDF"
    If DownloadPDFToFile(ae_DocumentType, al_ZipTableIndex, al_PageId, ls_TempDir & "\" & ls_Filename) Then
        Set lo_shell = CreateObject("Shell.Application")
        Call lo_shell.ShellExecute(ls_TempDir & "\" & ls_Filename, "", "", "open", 1)
        Set lo_shell = Nothing
        ShowPDF = True
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("ShowPDF")
End Function

Private Sub Launch_File(ByVal as_Key As String)
Dim ls_TempDir As String
Dim lo_Fld As Object
Dim lo_File As Object
Dim lo_shell As Object

On Error GoTo ErrHandler
  If as_Key = "" Then Exit Sub
  ls_TempDir = GetTempDir & "\$DFA$\" & as_Key
  Set lo_shell = CreateObject("Shell.Application")

  Set lo_Fld = mo_FSO.GetFolder(ls_TempDir)
  For Each lo_File In lo_Fld.Files
    Call lo_shell.ShellExecute(lo_File.Path, "", "", "open", 1)
  Next
  Set lo_shell = Nothing
  Exit Sub
ErrHandler:
  Set lo_shell = Nothing
  Call ErrorHandler("Launch_Report_File:" & as_Key)
End Sub

Private Function DownloadPDFToFile(ByVal ae_DocumentType As eDocumentType, ByVal al_ZipTableIndex As Long, ByVal al_PageId As Long, ByVal as_FileName As String) As Boolean
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ls_RequestSel As String
Dim ls_RequestIns As String
Dim ls_Filename As String

    DownloadPDFToFile = False
    If mo_FSO.FileExists(as_FileName) Then
        If Not DeleteFile(as_FileName) Then
            Exit Function
        End If
    End If
    
    Select Case ae_DocumentType
    Case eDocumentType.dtSalesOrder
        ls_RequestSel = "SELECT SLPZ_Data FROM EAS_SalesOrderPageZip$ZipTableIndex$ WHERE SLP_Id=$PageId$"
    Case eDocumentType.dtPriceRequest
        ls_RequestSel = "SELECT PRPZ_Data FROM EAS_PriceRequestPageZip$ZipTableIndex$ WHERE PRP_Id=$PageId$"
    Case eDocumentType.dtCreditMemo
        ls_RequestSel = "SELECT CRPZ_Data FROM EAS_CreditMemoPageZip$ZipTableIndex$ WHERE CRP_Id=$PageId$"
    Case eDocumentType.dtDebitMemo
        ls_RequestSel = "SELECT DBPZ_Data FROM EAS_DebitMemoPageZip$ZipTableIndex$ WHERE DBP_Id=$PageId$"
    Case eDocumentType.dtReturn
        ls_RequestSel = "SELECT REPZ_Data FROM EAS_ReturnPageZip$ZipTableIndex$ WHERE REP_Id=$PageId$"
    Case eDocumentType.dtOfficeInvoice
        ls_RequestSel = "SELECT OFPZ_Data FROM EAS_OfficeInvoicePageZip$ZipTableIndex$ WHERE OFP_Id=$PageId$"
    Case eDocumentType.dtAdminCustomer
        ls_RequestSel = "SELECT ACPZ_Data FROM EAS_AdminCustomerPageZip$ZipTableIndex$ WHERE ACP_Id=$PageId$"
    Case Else
        Err.Raise ArmErr.CompFncFailed, "ae_DocumentType", "Unknown document type : " & ae_DocumentType
    End Select
    ls_RequestSel = ReplacePlaceHolder(ls_RequestSel, "$ZipTableIndex$", right("000" & al_ZipTableIndex, 3))
    ls_RequestSel = ReplacePlaceHolder(ls_RequestSel, "$PageId$", al_PageId)
    
    If Not mo_Db.BlobToFileSQL(ls_RequestSel, as_FileName, True, False) Then
        Err.Raise ArmErr.SQLFailure, "FileToBlobSQL", mo_Db.LastErrorMessage & " Error writing blob: " & ls_RequestSel & " File: " & ls_Filename
    End If
    DownloadPDFToFile = True
    Exit Function
ErrHandler:
    Call ErrorHandler("DownloadPDFToFile as_FileName=" & as_FileName & _
                               " ae_DocumentType=" & ae_DocumentType & _
                               " al_ZipTableIndex=" & al_ZipTableIndex & _
                               " al_PageId=" & al_PageId)
End Function

Private Function GetDocumentZipTableIndexMax(ByVal ae_DocumentType As eDocumentType) As Long
Const REQ_PRICEREQUESTPAGE_MAX  As String = "exec EAS_PriceRequestPage_max"
Const REQ_SALESORDERPAGE_MAX  As String = "exec EAS_SalesOrderPage_max"
Const REQ_DEBITMEMOPAGE_MAX  As String = "exec EAS_DebitMemoPage_max"
Const REQ_CREDITMEMOPAGE_MAX  As String = "exec EAS_CreditMemoPage_max"
Const REQ_RETURNPAGE_MAX  As String = "exec EAS_ReturnPage_max"
Const REQ_OFFICEINVOICEPAGE_MAX  As String = "exec EAS_OfficeInvoicePage_max"
Const REQ_ADMINCUSTOMERPAGE_MAX  As String = "exec EAS_AdminCustomerPage_max"
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim lc_Cursor As Long
    Dim ll_Index As Long
    
    Select Case ae_DocumentType
    Case eDocumentType.dtPriceRequest
        ls_Request = REQ_PRICEREQUESTPAGE_MAX
    Case eDocumentType.dtSalesOrder
        ls_Request = REQ_SALESORDERPAGE_MAX
    Case eDocumentType.dtDebitMemo
        ls_Request = REQ_DEBITMEMOPAGE_MAX
    Case eDocumentType.dtCreditMemo
        ls_Request = REQ_CREDITMEMOPAGE_MAX
    Case eDocumentType.dtReturn
        ls_Request = REQ_RETURNPAGE_MAX
    Case eDocumentType.dtOfficeInvoice
        ls_Request = REQ_OFFICEINVOICEPAGE_MAX
    Case eDocumentType.dtAdminCustomer
        ls_Request = REQ_ADMINCUSTOMERPAGE_MAX
    Case Else
        Err.Raise ArmErr.CompFncFailed, "ae_DocumentType", "Unknown document type : " & ae_DocumentType
    End Select
    
    lc_Cursor = OpenSQLSafe(mo_Db, ls_Request, 1)
    ll_Index = mo_Db.GetFields(lc_Cursor, 0)
    If ll_Index = 0 Then ll_Index = 1
    GetDocumentZipTableIndexMax = ll_Index
    Call mo_Db.Close(lc_Cursor)
    Exit Function
ErrHandler:
    Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("GetDocumentZipTableIndexMax")
End Function

Private Function GetDocumentPageCount(ByVal ae_DocumentType As eDocumentType, ByVal al_ZipTableIndex As Long) As Long
Const REQ_PRICEREQUESTPAGE_COUNT  As String = "exec EAS_PriceRequestPage_cnt $ZipTableIndex$"
Const REQ_SALESORDERPAGE_COUNT  As String = "exec EAS_SalesOrderPage_cnt $ZipTableIndex$"
Const REQ_DEBITMEMOPAGE_COUNT  As String = "exec EAS_DebitMemoPage_cnt $ZipTableIndex$"
Const REQ_CREDITMEMOPAGE_COUNT  As String = "exec EAS_CreditMemoPage_cnt $ZipTableIndex$"
Const REQ_RETURNPAGE_COUNT  As String = "exec EAS_ReturnPage_cnt $ZipTableIndex$"
Const REQ_OFFICEINVOICEPAGE_COUNT  As String = "exec EAS_OfficeInvoicePage_cnt $ZipTableIndex$"
Const REQ_ADMINCUSTOMERPAGE_COUNT  As String = "exec EAS_AdminCustomerPage_cnt $ZipTableIndex$"
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim lc_Cursor As Long
    
    Select Case ae_DocumentType
    Case eDocumentType.dtPriceRequest
        ls_Request = REQ_PRICEREQUESTPAGE_COUNT
    Case eDocumentType.dtSalesOrder
        ls_Request = REQ_SALESORDERPAGE_COUNT
    Case eDocumentType.dtDebitMemo
        ls_Request = REQ_DEBITMEMOPAGE_COUNT
    Case eDocumentType.dtCreditMemo
        ls_Request = REQ_CREDITMEMOPAGE_COUNT
    Case eDocumentType.dtReturn
        ls_Request = REQ_RETURNPAGE_COUNT
    Case eDocumentType.dtOfficeInvoice
        ls_Request = REQ_OFFICEINVOICEPAGE_COUNT
    Case eDocumentType.dtAdminCustomer
        ls_Request = REQ_ADMINCUSTOMERPAGE_COUNT
    Case Else
        Err.Raise ArmErr.CompFncFailed, "ae_DocumentType", "Unknown document type : " & ae_DocumentType
    End Select
    
    ls_Request = ReplacePlaceHolder(ls_Request, "$ZipTableIndex$", al_ZipTableIndex)
    lc_Cursor = OpenSQLSafe(mo_Db, ls_Request, 1)
    GetDocumentPageCount = mo_Db.GetFields(lc_Cursor, 0)
    Call mo_Db.Close(lc_Cursor)
    Exit Function
ErrHandler:
    Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("GetDocumentPageCount")
End Function

Private Function GetDocumentPrefix(ByVal ae_DocumentType As eDocumentType) As String
On Error GoTo ErrHandler

    Select Case ae_DocumentType
    Case eDocumentType.dtPriceRequest
        GetDocumentPrefix = "PR"
    Case eDocumentType.dtSalesOrder
        GetDocumentPrefix = "SO"
    Case eDocumentType.dtCreditMemo
        GetDocumentPrefix = "CM"
    Case eDocumentType.dtDebitMemo
        GetDocumentPrefix = "DM"
    Case eDocumentType.dtReturn
        GetDocumentPrefix = "RE"
    Case eDocumentType.dtOfficeInvoice
        GetDocumentPrefix = "OI"
    Case eDocumentType.dtAdminCustomer
        GetDocumentPrefix = "AC"
    Case Else
        Err.Raise ArmErr.CompFncFailed, "ae_DocumentType", "Unknown document type : " & ae_DocumentType
    End Select
    Exit Function
ErrHandler:
    Call ErrorHandler("GetDocumentPrefix")
End Function

Private Function GetNewPDFDocumentName(ByVal ae_DocumentType As eDocumentType, ByVal al_PageId As Long) As String
On Error GoTo ErrHandler

    GetNewPDFDocumentName = GetDocumentPrefix(ae_DocumentType) & "_" & _
                    al_PageId & "_" & _
                    right("00" & ml_ZipTableIndex(ae_DocumentType), 3) & "_" & _
                    eZipDocumentStatus.Waiting & "_" & _
                    ms_LoginName & "_" & _
                    ms_ComputerName & ".PDF"
    Exit Function
ErrHandler:
    Call ErrorHandler("GetNewPDFDocumentName")
End Function

Private Sub Document_Copy(ByVal as_LocalFileName As String, ByVal ae_DocumentType As eDocumentType, ByVal al_PageId As Long)
On Error GoTo ErrHandler
    
    Dim ls_NewFileName As String
    ls_NewFileName = GetNewPDFDocumentName(ae_DocumentType, al_PageId)
    Call mo_FSO.CopyFile(as_LocalFileName, ms_DocumentServerDir & ls_NewFileName)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Document_Copy")
End Sub

Private Sub mnu_EAS_Document_Click(Index As Integer)
On Error GoTo ErrHandler
    Dim ll_MainConfigIndex As Long
        
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    mt_MainConfig(ll_MainConfigIndex).CurrentDetailIndex = FindDetailConfigByFrameIndex(Index)
    Call Item_AddInit(Index)
    Exit Sub
ErrHandler:
    Call ErrorMessage("mnu_EAS_Document_Click")
End Sub

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK CONTROL EVENTS
' please DO NOT change anything in this part of code
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Private Sub tlb_main_action(Index As Integer, ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler
    
    Dim ll_MainConfigIndex As Long, ll_frameIndex As Long, ll_DetailConfigIndex As Long, ll_MainFrameIndex As Long
    
    If Not tlb_Main(Index).Enabled Then Exit Sub
    
    Call LockScreen(True)
    
    If Not tlb_Main_CustomAction(Index, as_Role, as_Language) Then
        ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        ll_frameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
        ll_DetailConfigIndex = FindDetailConfigByMainConfig(ll_MainConfigIndex)
        ll_MainFrameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
        Select Case as_Role
            Case "A"
            ' Want to Add
            Call Item_AddInit(ll_DetailConfigIndex)
                
            Case "B"
            ' Want to Update
                If grd_Main(ll_MainFrameIndex).SelectedCount = 1 Then
                    Call Item_UpdateInit(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex).CurrentKey)
                End If
            Case "C"
            ' Want to delete
                If grd_Main(ll_MainFrameIndex).SelectedCount = 1 Then
                    Call Item_DeleteInit(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex).CurrentKey)
                End If
            Case "L"
            ' Want to reload treeview and refresh the grid
                Call ReloadMainGrid
            Case "F"
                ' Want to reload grid according to treeview selection
                Call ReloadMainTreeview
            Case "Q"
                Call cbo_View_ComboItemSelected(Index)
            Case "T"
                RaiseEvent quit
            Case Else
                Err.Raise ArmErr.InvalidArgument, "tlb_Main_action(" & Index & ")", "Unknown main toolbar role as_Role=" & as_Role
        End Select
    End If
    
    Call LockScreen(False)
    
    Exit Sub
ErrHandler:
    Call UpdateError(True)
    Call LockScreen(False)

    Select Case Err.Number
    Case 202
        MsgBox MsgText(202, ms_Language_Code, "#The item you have added/updated couldn't be displayed with the current criteria set."), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case ArmErr.SQLBadRowExpectedCount
        MsgBox MsgText(2138, ms_Language_Code, "#The record you try to open has been deleted by an other user. Please refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case ArmErr.SQLBadRowAffectedCount
        MsgBox MsgText(2144, ms_Language_Code, "#This record has been, modified by an other.Please exit from this screen and refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case Else
        Call LogMessage("tlb_list_action")
        ' user interface can be inconsistent, better to close application
        Call UpdateError(False)
        Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & Err.Source & vbCrLf & "Description: " & Err.Description, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        End
    End Select
End Sub

Private Sub tlb_detail_action(Index As Integer, ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler
    
    Dim ll_MainConfigIndex As Long, ll_MainFrameIndex As Long, ll_DetailConfigIndex As Long
    
    If Not tlb_Detail(Index).Enabled Then Exit Sub
    
    Call LockScreen(True)
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_MainFrameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
    ll_DetailConfigIndex = FindDetailConfigByMainConfig(ll_MainConfigIndex)
    
    If Not tlb_detail_CustomAction(Index, as_Role, as_Language) Then
        Select Case as_Role
            Case "A"
                ' Want to Add
                Call Item_AddInit(ll_DetailConfigIndex)
            Case "B"
                ' Want to Update
                Call Item_UpdateInit(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex).CurrentKey)
            Case "C"
                ' Want to delete
                Call Item_DeleteInit(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex).CurrentKey)
            Case "Y"
                Call GotoNextItem(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex))
            Case "Z"
                Call GotoPreviousItem(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex))
            Case "H"
                Select Case me_DetailMode
                Case emAdd
                    Call Item_Add(ll_DetailConfigIndex)
                Case emUpdate
                    Call Item_Update(ll_DetailConfigIndex)
                Case emDelete
                    If MsgBox(MsgText(mt_DetailConfig(ll_DetailConfigIndex).DeleteMsg(0, 0), ms_Language_Code, mt_DetailConfig(ll_DetailConfigIndex).DeleteMsg(0, 1)), vbExclamation + vbDefaultButton2 + vbYesNo) = vbYes Then
                        Call Item_Delete(ll_DetailConfigIndex)
                    End If
                End Select
            Case "I"
                Call Item_ReInit(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex).CurrentKey)
            Case "F"
                Call Item_ViewInit(ll_DetailConfigIndex, grd_Main(ll_MainFrameIndex).CurrentKey)
            Case "T"
                Call SetMode(emList)
            Case Else
                Err.Raise ArmErr.InvalidArgument, "tlb_detail_action(" & Index & ")", "Unknown detail toolbar role as_Role=" & as_Role
        End Select
    End If
    Call LockScreen(False)
    Exit Sub
ErrHandler:
    Call UpdateError(True)
    Call LockScreen(False)

    Select Case Err.Number
    Case 202
        MsgBox MsgText(202, ms_Language_Code, "#The item you have added/updated couldn't be displayed with the current criteria set."), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case ArmErr.SQLBadRowExpectedCount
        MsgBox MsgText(2138, ms_Language_Code, "#The record you try to open has been deleted by an other user. Please refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case ArmErr.SQLBadRowAffectedCount
        MsgBox MsgText(2144, ms_Language_Code, "#This record has been, modified by an other.Please exit from this screen and refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case Else
        Call LogMessage("tlb_Detail_action")
        Call UpdateError(False)
        Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & Err.Source & vbCrLf & "Description: " & Err.Description, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        End
    End Select
End Sub

Private Sub tlb_Subdetail_action(Index As Integer, ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler
    
    Dim ll_SubdetailIndex As Long
    
    If Not tlb_SubDetail(Index).Enabled Then Exit Sub
    
    Call LockScreen(True)
    
    ll_SubdetailIndex = FindSubDetailConfigByFrameIndex(Index)
    
    If Not tlb_Subdetail_CustomAction(Index, as_Role, as_Language) Then
        Select Case as_Role
            Case "A"
            ' Want to Add
                Call SubItem_AddInit(ll_SubdetailIndex)
            Case "B"
            ' Want to Update
                Call SubItem_UpdateInit(ll_SubdetailIndex)
            Case "C"
            ' Want to delete
                Call SubItem_DeleteInit(ll_SubdetailIndex)
            Case "Y"
                Call SwapRows(Index, True)
            Case "Z"
                Call SwapRows(Index, False)
            Case "H"
                Select Case me_SubDetailMode
                Case emAdd
                    If SubItem_Add(ll_SubdetailIndex) Then
                        Call SubItem_AddInit(ll_SubdetailIndex)
                    End If
                Case emUpdate
                    If SubItem_Update(ll_SubdetailIndex) Then
                        'go back to the detail screen
                        Call SetModeSubDetail(ll_SubdetailIndex, emList)
                    End If
                Case emDelete
                    If SubItem_Delete(ll_SubdetailIndex) Then
                        'go back to the detail screen
                        Call SetModeSubDetail(ll_SubdetailIndex, emList)
                    End If
                End Select
            Case "F"
                Call grd_Subdetail(Index).Refresh
            Case "T"
                Call SetModeSubDetail(Index, emList)
            Case "I"
                Select Case me_SubDetailMode
                Case emAdd
                    Call SubItem_AddInit(ll_SubdetailIndex)
                Case emUpdate
                    Call SubItem_UpdateInit(ll_SubdetailIndex)
                End Select
            Case Else
                Err.Raise ArmErr.InvalidArgument, "tlb_Subdetail_action(" & Index & ")", "Unknown subdetail toolbar role as_Role=" & as_Role
        End Select
    End If
    Call LockScreen(False)
    Exit Sub
ErrHandler:
    Call UpdateError(True)
    Call LockScreen(False)

    Select Case Err.Number
    Case 202
        MsgBox MsgText(202, ms_Language_Code, "#The item you have added/updated couldn't be displayed with the current criteria set."), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case ArmErr.SQLBadRowExpectedCount
        MsgBox MsgText(2138, ms_Language_Code, "#The record you try to open has been deleted by an other user. Please refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case ArmErr.SQLBadRowAffectedCount
        MsgBox MsgText(2144, ms_Language_Code, "#This record has been, modified by an other.Please exit from this screen and refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    Case Else
        Call LogMessage("tlb_Detail_action")
        Call UpdateError(False)
        Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & Err.Source & vbCrLf & "Description: " & Err.Description, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        End
    End Select
End Sub

Private Sub tbs_Main_Click()
On Error GoTo ErrHandler

Dim ll_Index As Long

    If tbs_Main.SelectedItem Is Nothing Then Exit Sub
    
    Call LockScreen(True)
    
    ll_Index = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    Call InitMainFrame(ll_Index)
    Call SetMode(emList)
    
    Call LockScreen(False)
    Exit Sub
ErrHandler:
    Call LockScreen(False)
    Call ErrorMessage("tbs_Main_Click")
End Sub

Private Sub cbo_View_ComboItemSelected(Index As Integer)
On Error GoTo ErrHandler

Dim ll_Index As Long

    Call LockScreen(True)
    
     If Not cbo_View(Index).SelectedItem Is Nothing Then
        ll_Index = FindMainConfigByFrameIndex(Index)
        Call LoadTreeView(ll_Index, tvw_Main(Index), GetTreeViewInfo(mt_MainConfig(ll_Index).mTreeViewInfos, mt_MainConfig(ll_Index).ViewCode, cbo_View(Index).SelectedItem.Key))
        If tvw_Main(Index).Count > 0 Then
            Set tvw_Main(Index).SelectedItem = tvw_Main(Index).Nodes(1)
            Call tvw_Main_NodeClick(Index, tvw_Main(Index).SelectedItem)
        Else
            Call tvw_Main_NodeClick(Index, Nothing)
        End If
        Call SetTreeDelayedMode(Index, False)
    End If
    
CleanUp:
    Call LockScreen(False)
    Exit Sub
    
ErrHandler:
    Call LogMessage("cbo_Views_ComboItemSelected")
    Call LockScreen(False)
    MsgBox MsgText(2116, ms_Language_Code, "#Unable to load the combo " & " type of view."), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
End Sub

Private Sub cmd_TVReLoad_Click(Index As Integer)
On Error GoTo ErrHandler
    
    Call cbo_View_ComboItemSelected(Index)
    Exit Sub
ErrHandler:
    Call ErrorMessage("cmd_TVReLoad_Click")
End Sub

Private Sub tvw_Main_NodeClick(Index As Integer, ByVal Node As MSComctlLib.Node)
On Error GoTo ErrHandler
    
    Dim ll_DetailIndex As Long, ll_MainIndex As Long
    
    If mb_InternalInit Then Exit Sub
    
    'Call LockScreen(True)
    Screen.MousePointer = vbHourglass
    
    Dim lv_Requests As Variant, lb_DelayedLoad As Boolean
    
    Call grd_Main(Index).ClearGrid
    ll_MainIndex = FindMainConfigByFrameIndex(Index)
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    
    lv_Requests = ApplyTVFilters(ll_MainIndex, tvw_Main(Index).SelectedNodeRequest)
    
    If (Node Is Nothing) Then
        mt_MainConfig(ll_MainIndex).CurrentTvwSelMethod = etmNone
    Else
        If (tvw_Main(Index).NodeInfo(Node).ml_Level = tvw_Main(Index).Levels - 1) Then
            mt_MainConfig(ll_MainIndex).CurrentTvwSelMethod = eTvwSelMethod.etmNode
        Else
            mt_MainConfig(ll_MainIndex).CurrentTvwSelMethod = eTvwSelMethod.etmBranch
        End If
    End If
    
    Select Case mt_MainConfig(ll_MainIndex).GridDelayMethod
    Case egmDelayedAlways
        lb_DelayedLoad = True
    Case egmDelayedExceptLastLevel
        If Node Is Nothing Then
            lb_DelayedLoad = True
        Else
            lb_DelayedLoad = (tvw_Main(Index).NodeInfo(Node).ml_Level < tvw_Main(Index).Levels - 1)
        End If
    Case egmLoadAlways
        lb_DelayedLoad = False
    Case Else
        lb_DelayedLoad = True
    End Select
    
    If grd_Main(Index).Cols = 0 Then
        If Not grd_Main(Index).SetColumns(mt_DetailConfig(ll_DetailIndex).MainGridColumns) Then
            Err.Raise ArmErr.CompFncFailed, "grd_Main", "Method SetColumns failed."
        End If
        Call LoadLabels(mo_Db, fra_MainItem(Index), SCREEN_NAME, ms_Language_Code)
    ElseIf mt_MainConfig(ll_MainIndex).IsMultiDetailView Then
        If Not grd_Main(Index).SetColumns(mt_DetailConfig(ll_DetailIndex).MainGridColumns) Then
            Err.Raise ArmErr.CompFncFailed, "grd_Main", "Method SetColumns failed."
        End If
        Call LoadLabels(mo_Db, fra_MainItem(Index), SCREEN_NAME, ms_Language_Code)
    End If
    
    mt_MainConfig(ll_MainIndex).GridDelayed = lb_DelayedLoad
    
    If Not grd_Main(Index).Load(lv_Requests, False, , , lb_DelayedLoad) Then
        Err.Raise ArmErr.CompFncFailed, "grd_Main", "Method Load failed: " & lv_Requests(0)
    End If
    Call UpdateMainToolbarCustom(ll_MainIndex)
    'Call LockScreen(False)
    Screen.MousePointer = vbDefault
    Exit Sub

ErrHandler:
    Call LogMessage("tvw_Main_NodeClick")
    'Call LockScreen(False)
    Screen.MousePointer = vbDefault
    MsgBox MsgText(2142, ms_Language_Code, "#There is a problem while loading data."), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
End Sub

Private Sub tbs_MainTabFilter_Click(Index As Integer)
On Error GoTo ErrHandler
    
    Call SetTreeDelayedMode(Index, True)
    Exit Sub
ErrHandler:
    Call ErrorMessage("tbs_MainTabFilter_Click")
End Sub


Private Sub grd_Main_ItemSelected(Index As Integer)
On Error GoTo ErrHandler
    
    Dim ll_MainIndex As Long
    Dim ll_DetailIndex As Long
    Dim lb_Locked As Boolean
    
    If grd_Main(Index).SelectedCount <> 1 Then Exit Sub
    
    Call LockScreen(True)
    lb_Locked = True
    
    If grd_Main_CustomAction(Index, eControlAction.caDoubleClick) Then
        Call LockScreen(False)
        lb_Locked = False
        Exit Sub
    End If
    
    ll_MainIndex = FindMainConfigByFrameIndex(Index)
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    Call Item_ViewInit(ll_DetailIndex, grd_Main(Index).CurrentKey)
    Call LockScreen(False)
    lb_Locked = False
    Exit Sub
ErrHandler:
    If lb_Locked Then
        Call LockScreen(False)
    End If
    Select Case Err.Number
        Case ArmErr.SQLBadRowExpectedCount
            MsgBox MsgText(2138, ms_Language_Code, "#The record you try to open has been deleted by an other user. Please refresh the grid."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
        Case Else
            Call LogMessage("grd_Main_ItemSelected")
            'MsgBox MsgText(2143, ms_Language_Code, "#There is a problem while doing this action. Please double check your entry."), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
            Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & Err.Source & vbCrLf & "Description: " & Err.Description, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            End
    End Select
End Sub

Private Sub grd_Main_RowColChange(Index As Integer)
On Error GoTo ErrHandler
Dim ll_MainIndex As Long

    ll_MainIndex = FindMainConfigByFrameIndex(Index)
    mt_MainConfig(ll_MainIndex).GridDelayed = False
    Call UpdateMainToolbarCustom(ll_MainIndex)
    Exit Sub
ErrHandler:
    Call ErrorMessage("grd_Main_RowColChange")
End Sub

Private Sub grd_Subdetail_ItemSelected(Index As Integer)
On Error GoTo ErrHandler
        
    If (me_SubDetailMode = emList) And tlb_SubDetail(Index).Visible And tlb_SubDetail(Index).Enabled Then
        Call tlb_Subdetail_action(Index, "B", ms_Language_Code)
    End If
    Exit Sub
ErrHandler:
    Call ErrorMessage("grd_Subdetail_ItemSelected")
End Sub

Private Sub grd_Subdetail_RowColChange(Index As Integer)
On Error GoTo ErrHandler
Dim ll_SubdetailIndex As Long

    ll_SubdetailIndex = FindSubDetailConfigByFrameIndex(Index)
    Call UpdateSubdetailToolbarCustom(ll_SubdetailIndex)
    Exit Sub
ErrHandler:
    Call ErrorMessage("grd_Main_RowColChange")
End Sub

Private Sub grd_Subdetail_RowLoaded(Index As Integer, ByVal al_Row As Long)
On Error GoTo ErrHandler
Dim lv_Row As Variant
Dim ll_Idx As Long, ll_Count As Long
Dim ll_SubdetailIndex As Long

    ll_Count = grd_Subdetail(Index).Cols - 1
    ReDim lv_Row(ll_Count)
    For ll_Idx = 0 To ll_Count
        lv_Row(ll_Idx) = grd_Subdetail(Index).Data(al_Row, ll_Idx)
    Next
    ll_SubdetailIndex = FindSubDetailConfigByFrameIndex(Index)
    'MS REDIMM
    Call SafeRedimPreserve(mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows, al_Row)
    'ReDim Preserve mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows(al_Row)
    
    mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows(al_Row) = lv_Row
    
    Dim lo_Column As ArmColumn
    Set lo_Column = grd_Subdetail(Index).Columns("Status")
    If Not lo_Column Is Nothing Then
        If lo_Column.GetData(al_Row) = 1 Then
            grd_Subdetail(Index).LineColor(al_Row) = &H1111FF
        ElseIf lo_Column.GetData(al_Row) = 2 Then
            grd_Subdetail(Index).LineColor(al_Row) = &H11FFC0
        End If
    End If
    Exit Sub
ErrHandler:
    Call ErrorMessage("grd_Main_RowColChange")
End Sub


'**********************************************************************************************************************************
'**********************************************************************************************************************************
' FRAMEWORK METHODS
' please DO NOT change anything in this part of code
'**********************************************************************************************************************************
'**********************************************************************************************************************************

Public Function Load_A_COM() As Boolean

Dim ll_Index As Long
Dim lo_Control As Object

On Error GoTo ErrHandler
    
    Load_A_COM = False
    
    If mb_Initialized Then
        Call Err.Raise(ArmErr.CPTAlreadyInitialized)
    End If
    
    mb_InternalInit = False
    ms_DecimalSeparator = Format(0, ".")
    mc_ScreenLabels = 0
    mc_Toolbars = 0
    mc_Item = 0
    
    ReDim mt_MainConfig(-1 To -1)
    ReDim mt_DetailConfig(-1 To -1)
    ReDim mt_SubdetailConfig(-1 To -1)
    
    Dim sBuffer As String
    Dim nBufferLen As Long
    nBufferLen = 255
    sBuffer = String$(nBufferLen, vbNullChar)
    nBufferLen = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, sBuffer, nBufferLen)
    If nBufferLen > 0 Then
        ms_ThousandSeparator = Left$(sBuffer, nBufferLen - 1)
    End If
    
    For Each lo_Control In UserControl.Controls
        Select Case UCase(TypeName(lo_Control))
        Case "ARMCOMBOBOX"
            Set lo_Control.ArmDb = mo_Db
            Call lo_Control.Load_A_COM
        Case "ARMPICKER"
            Set lo_Control.ArmDb = mo_Db
            Call lo_Control.Load_A_COM
        Case "TOOLBARCONTROL"
            lo_Control.Language = ms_Language_Code
            lo_Control.Load_A_COM
        Case "ARMGRID"
            Set lo_Control.ArmDb = mo_Db
            Call lo_Control.Load_A_COM
        Case "ARMTREEVIEW"
            Set lo_Control.ArmDb = mo_Db
            lo_Control.Language = ms_Language_Code
            Call lo_Control.Load_A_COM
        Case "ARMCHECKVIEW"
            Set lo_Control.ArmDb = mo_Db
            Call lo_Control.Load_A_COM
        Case "A_CALOCX"
            lo_Control.Language = ms_Language_Code
            Call lo_Control.reinit_cal
        End Select
    Next
    
    Set mo_FSO = CreateObject("Scripting.FileSystemObject")
    
#If ENV = LIVE Then
    Set mo_Sys = CreateObject("ArmSYSCOM.ArmSys")
#Else
    Set mo_Sys = New ARMSYSCOMLib.ArmSYS
#End If
    
    Set mo_WshNetwork = CreateObject("WScript.Network")
    ms_ComputerName = mo_WshNetwork.ComputerName
    ms_NetworkBoardID = GetMACAddress()
    
    mb_Initialized = Load_A_COM_Custom
    Load_A_COM = mb_Initialized
    Exit Function
ErrHandler:
    Load_A_COM = False
    Call ErrorMessage("Load_A_COM")
End Function

Public Function Unload_A_COM() As Boolean
    
On Error GoTo ErrHandler
    
    Dim lo_Control As Object
    Dim ll_Index As Long
    
    Call UnLoad_A_COM_Custom
    
    If mc_ScreenLabels <> 0 Then mo_Db.Close (mc_ScreenLabels)
    mc_ScreenLabels = 0
    If mc_Toolbars <> 0 Then mo_Db.Close (mc_Toolbars)
    mc_Toolbars = 0
    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        ReDim mt_SubdetailConfig(ll_Index).DeletedRows(-1 To -1)
    Next
    
    For Each lo_Control In UserControl.Controls
        Select Case UCase(TypeName(lo_Control))
        Case "ARMCOMBOBOX", "TOOLBARCONTROL", "ARMGRID", "ARMTREEVIEW", "ARMCHECKVIEW", "ARMPICKER"
            Call lo_Control.Unload_A_COM
        End Select
    Next
    
    Set mo_Db = Nothing
    Set mo_FSO = Nothing
    mb_Initialized = False
    Unload_A_COM = True
    Exit Function
ErrHandler:
    Unload_A_COM = False
    Call ErrorMessage("Unload_A_Com")
End Function

Public Sub Resize()
On Error GoTo ErrHandler

Dim ll_Index As Long

    If Not Resize_Custom Then
        For ll_Index = 0 To UBound(mt_MainConfig)
            Call ResizeMain(ll_Index)
        Next
        For ll_Index = 0 To UBound(mt_DetailConfig)
            Call ResizeDetail(ll_Index)
        Next
        For ll_Index = 0 To UBound(mt_SubdetailConfig)
            Call ResizeSubdetail(ll_Index)
        Next
    End If
    Exit Sub
ErrHandler:
    Call ErrorMessage("Resize")
End Sub

Private Sub ResizeMain(ByVal al_MainIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    If Width < 0 Or Height < 0 Then Exit Sub
    
    ll_frameIndex = mt_MainConfig(al_MainIndex).FrameIndex
    Call tbs_Main.Move(0, 0, Width)
    
    Call fra_MainItem(ll_frameIndex).Move(0, tbs_Main.Height, Width, Height)
    Call tlb_Main(ll_frameIndex).Move(tvw_Main(ll_frameIndex).Left + tvw_Main(ll_frameIndex).Width + FRM_SPACE_HOR, 2 * FRM_SPACE_VER)
    Call grd_Main(ll_frameIndex).Move(tvw_Main(ll_frameIndex).Left + tvw_Main(ll_frameIndex).Width + FRM_SPACE_HOR, tlb_Main(ll_frameIndex).Top + tlb_Main(ll_frameIndex).Height + FRM_SPACE_VER)
    'Call fra_MainFilter(ll_FrameIndex).Move(0, 0, fra_MainFilter(ll_FrameIndex).Width, fra_MainItem(ll_FrameIndex).Height - 3 * FRM_SPACE_VER)
    
    If fra_MainItem(ll_frameIndex).Height - tvw_Main(ll_frameIndex).Top - 3 * FRM_SPACE_VER > 0 Then
        tvw_Main(ll_frameIndex).Height = fra_MainItem(ll_frameIndex).Height - tvw_Main(ll_frameIndex).Top - 3 * FRM_SPACE_VER
    End If
    
    If tbs_MainTabFilter(ll_frameIndex).Tabs.Count > 1 Then
        If Height - tbs_MainTabFilter(ll_frameIndex).Height - 2 * FRM_SPACE_VER > 0 Then
            tvw_Main(ll_frameIndex).Height = Height - tbs_MainTabFilter(ll_frameIndex).Height - 2 * FRM_SPACE_VER
        End If
        Call tbs_MainTabFilter(ll_frameIndex).Move(0, fra_MainFilter(ll_frameIndex).Height - tbs_MainTabFilter(ll_frameIndex).Height, fra_MainFilter(ll_frameIndex).Width)
    Else
        tbs_MainTabFilter(ll_frameIndex).Visible = False
    End If
    If fra_MainItem(ll_frameIndex).Height - grd_Main(ll_frameIndex).Top - 3 * FRM_SPACE_VER > 0 Then
        grd_Main(ll_frameIndex).Height = fra_MainItem(ll_frameIndex).Height - grd_Main(ll_frameIndex).Top - 3 * FRM_SPACE_VER
    End If
    If fra_MainItem(ll_frameIndex).Width - grd_Main(ll_frameIndex).Left - FRM_SPACE_HOR > 0 Then
        grd_Main(ll_frameIndex).Width = fra_MainItem(ll_frameIndex).Width - grd_Main(ll_frameIndex).Left - FRM_SPACE_HOR
    End If
    Call cmd_TVReLoad(ll_frameIndex).Move(tvw_Main(ll_frameIndex).Left, tvw_Main(ll_frameIndex).Top)
    Exit Sub
ErrHandler:
    Call ErrorHandler("ResizeMain")
End Sub

Private Sub ResizeDetail(ByVal al_DetailIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    If Width < 0 Or Height < 0 Then Exit Sub
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    Call fra_DetailItem(ll_frameIndex).Move(0, tbs_Main.Top + tbs_Main.Height + FRM_SPACE_VER, UserControl.Width, UserControl.Height)
    Exit Sub
ErrHandler:
    Call ErrorHandler("ResizeDetail")
End Sub

Private Sub ResizeSubdetail(ByVal al_SubDetailIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long

    If Width < 0 Or Height < 0 Then Exit Sub
    
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    Call tlb_SubDetail(ll_frameIndex).Move(fra_SubDetail(ll_frameIndex).Width - tlb_SubDetail(ll_frameIndex).Width - FRM_SPACE_HOR, 2 * FRM_SPACE_VER)
    Call fra_SubDetailItem(ll_frameIndex).Move(FRM_SPACE_HOR, FRM_SPACE_VER, tlb_SubDetail(ll_frameIndex).Left - 2 * FRM_SPACE_HOR)
    Call grd_Subdetail(ll_frameIndex).Move(FRM_SPACE_HOR, 2 * FRM_SPACE_VER, tlb_SubDetail(ll_frameIndex).Left - 2 * FRM_SPACE_HOR, fra_SubDetail(ll_frameIndex).Height - 3 * FRM_SPACE_VER)
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("ResizeSubdetail")
End Sub

Public Function Init_control() As Boolean
Dim ll_Index As Long

On Error GoTo ErrHandler

    Call Load_ConfigInfo
    Call Init_Custom
    
    Call ChangeCharset(UserControl.Controls, GetCodePageFromLanguage(mo_Db, ms_Language_Code))
    Call LoadLabels(mo_Db, Me, SCREEN_NAME, ms_Language_Code)
    ms_UserName = LoadUserInfo(mo_Db, ml_U_Code)
    
    If tbs_Main.Tabs.Count > 1 Then
        Call tbs_Main.Move(0, 0, Width)
        tbs_Main.Visible = True
    End If
    Set tbs_Main.SelectedItem = tbs_Main.Tabs(1)
    
    Init_control = True
    Exit Function
ErrHandler:
    Init_control = False
    Call ErrorMessage("Init_control")
End Function

Private Sub InitMainFrame(ByVal al_ConfigIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
Dim ls_ToolbarInfo As String

    If al_ConfigIndex < 0 Then Exit Sub
    If mt_MainConfig(al_ConfigIndex).Initialized Then Exit Sub
    
    ll_frameIndex = mt_MainConfig(al_ConfigIndex).FrameIndex
    
    Call ResizeMain(al_ConfigIndex)
    
    Call LoadToolbar(tlb_Main(ll_frameIndex), mt_MainConfig(al_ConfigIndex).ToolbarID)
    Call tlb_Main(ll_frameIndex).DisplayFace(mt_MainConfig(al_ConfigIndex).ToolbarFace)
    
    Call InitTreeView(al_ConfigIndex)
    mt_MainConfig(al_ConfigIndex).Initialized = True
    Exit Sub
ErrHandler:
    Call ErrorMessage("InitMainFrame")
End Sub

Private Sub InitTreeView(ByVal al_ConfigIndex As Long)
On Error GoTo ErrHandler

Const VIEW_REQUEST = "exec TreeView_View_t_lst $ViewCode$,$Language_Code$"
    
    Dim ls_Request As String
    Dim ll_frameIndex As Long
    
    If al_ConfigIndex < 0 Then Exit Sub
    ll_frameIndex = mt_MainConfig(al_ConfigIndex).FrameIndex
    
    ls_Request = ReplacePlaceHolder(VIEW_REQUEST, "$ViewCode$", SQLStr(mt_MainConfig(al_ConfigIndex).ViewCode))
    ls_Request = ReplacePlaceHolder(ls_Request, "$Language_Code$", SQLStr(ms_Language_Code))
    
    cbo_View(ll_frameIndex).Request = ls_Request
    Call cbo_View(ll_frameIndex).Load
    
    If cbo_View(ll_frameIndex).Count = 0 Then
        cbo_View(ll_frameIndex).Visible = False
        If mt_MainConfig(ll_frameIndex).GridDelayMethod = egmDelayedAlways Then
            grd_Main(ll_frameIndex).Visible = False
        Else
            Call ReloadMainGrid
        End If
    Else
        Dim ll_Idx As Long, ll_Count As Long
        ll_Count = cbo_View(ll_frameIndex).Count - 1
        ReDim mt_MainConfig(al_ConfigIndex).mTreeViewInfos(ll_Count)
        For ll_Idx = 0 To ll_Count
            mt_MainConfig(al_ConfigIndex).mTreeViewInfos(ll_Idx).Loaded = False
            mt_MainConfig(al_ConfigIndex).mTreeViewInfos(ll_Idx).TreeViewCode = cbo_View(ll_frameIndex).ComboItems(ll_Idx + 1).Key
        Next
        
        Call cbo_View(ll_frameIndex).SearchItem("X", "TV_Default", 0)
    End If
    Exit Sub
ErrHandler:
    Call ErrorMessage("InitMainFrame")
End Sub

Private Sub InitDetailFrame(ByVal al_DetailConfigIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long, ll_Index As Long, ll_TlbIndex As Long

    If mt_DetailConfig(al_DetailConfigIndex).IsMultiDetailFrame Then
        Call InitMultiDetailFrame(al_DetailConfigIndex)
    End If
    
    If mt_DetailConfig(al_DetailConfigIndex).Initialized Then Exit Sub
    
    Call ResizeDetail(al_DetailConfigIndex)
    ll_frameIndex = mt_DetailConfig(al_DetailConfigIndex).FrameIndex
    ll_TlbIndex = mt_DetailConfig(al_DetailConfigIndex).ToolbarIndex
        
    Call InitMandatoryLabels(mt_DetailConfig(al_DetailConfigIndex).ListFieldsMandatory)
    
    If tlb_Detail(ll_TlbIndex).ButtonsString = "" Then
        Call LoadToolbar(tlb_Detail(ll_TlbIndex), mt_DetailConfig(al_DetailConfigIndex).ToolbarID)
    End If
    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If mt_SubdetailConfig(ll_Index).DetailConfigIndex = al_DetailConfigIndex Then
            Call InitSubdetailFrame(ll_Index)
        End If
    Next
    If Not IsArray(mt_DetailConfig(al_DetailConfigIndex).RequestAdd) Then mt_DetailConfig(al_DetailConfigIndex).RequestAdd = Array(mt_DetailConfig(al_DetailConfigIndex).RequestAdd)
    If Not IsArray(mt_DetailConfig(al_DetailConfigIndex).RequestUpd) Then mt_DetailConfig(al_DetailConfigIndex).RequestUpd = Array(mt_DetailConfig(al_DetailConfigIndex).RequestUpd)
    If Not IsArray(mt_DetailConfig(al_DetailConfigIndex).RequestDel) Then mt_DetailConfig(al_DetailConfigIndex).RequestDel = Array(mt_DetailConfig(al_DetailConfigIndex).RequestDel)
    mt_DetailConfig(al_DetailConfigIndex).Initialized = True
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitDetailFrame")
End Sub

Private Sub InitSubdetailFrame(ByVal al_SubDetailIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long, ll_Index As Long
Dim lo_Label As Label

    If mt_SubdetailConfig(al_SubDetailIndex).Initialized Then Exit Sub
    
    Call ResizeSubdetail(al_SubDetailIndex)
    
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
        
    Call ResizeSubdetail(al_SubDetailIndex)
    
    fra_SubDetailItem(ll_frameIndex).Visible = False
    
    Call InitMandatoryLabels(mt_SubdetailConfig(al_SubDetailIndex).ListFieldsMandatory)
    
    Call LoadToolbar(tlb_SubDetail(ll_frameIndex), mt_SubdetailConfig(al_SubDetailIndex).ToolbarID)
    
    If Not IsEmpty(mt_SubdetailConfig(al_SubDetailIndex).GridColumns) Then
        If Not grd_Subdetail(ll_frameIndex).SetColumns(mt_SubdetailConfig(al_SubDetailIndex).GridColumns) Then
            Err.Raise ArmErr.InvalidValue, "SetColumns failed for main grid in " & mt_SubdetailConfig(al_SubDetailIndex).NameFrame
        End If
        Call LoadLabels(mo_Db, fra_SubDetail(ll_frameIndex), SCREEN_NAME, ms_Language_Code)
    End If
    mt_SubdetailConfig(al_SubDetailIndex).Initialized = True
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitSubdetailFrame")
End Sub

Private Function GetInitControlProperty(ByVal al_DetailIndex As Long, ByRef ao_Control As Object, ByVal ae_ControlIndex As eControlPropertyIndex) As Variant
On Error GoTo ErrHandler

Dim lv_InitControls As Variant
Dim ll_Idx As Long

    lv_InitControls = mt_DetailConfig(al_DetailIndex).InitControls
    For ll_Idx = 0 To UBound(lv_InitControls)
        If lv_InitControls(ll_Idx)(0) Is ao_Control Then
            GetInitControlProperty = lv_InitControls(ll_Idx)(ae_ControlIndex)
        End If
    Next
    Exit Function
ErrHandler:
    Call ErrorHandler("GetInitControlProperty")
End Function

Private Sub InitFrameControls(ByRef av_InitControls As Variant)
On Error GoTo ErrHandler

Dim lo_Control As Control
Dim ll_Index As Long
Dim ls_Request As String

    If Not IsArray(av_InitControls) Then Exit Sub
    mb_InternalInit = True
    For ll_Index = 0 To UBound(av_InitControls)
        Set lo_Control = av_InitControls(ll_Index)(0)
        
        lo_Control.Tag = av_InitControls(ll_Index)(1)
        lo_Control.Visible = av_InitControls(ll_Index)(2)
        Select Case UCase(TypeName(lo_Control))
            Case "ARMCOMBOBOX"
                If UBound(av_InitControls(ll_Index)) >= 3 Then
                    ls_Request = av_InitControls(ll_Index)(3)
                    ls_Request = ReplaceCommonPlaceholders(ls_Request)
                    lo_Control.Request = ls_Request
                End If
            Case "TEXTBOX", "ARMPICKER"
                If UBound(av_InitControls(ll_Index)) >= 4 Then
                    lo_Control.MaxLength = av_InitControls(ll_Index)(4)
                End If
            Case "A_CALOCX"
            Case "LABEL", "CHECKBOX"
                lo_Control.Caption = "#" & lo_Control.Tag
        End Select
    Next
    mb_InternalInit = False
    Exit Sub
ErrHandler:
    mb_InternalInit = False
    Call ErrorHandler("InitFrameControls")
End Sub

Private Sub InitMultiDetailFrame(ByVal al_DetailConfigIndex As Long)
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
    
    ll_frameIndex = mt_DetailConfig(al_DetailConfigIndex).FrameIndex
    
    Call ResetFrameControls(fra_DetailItem(ll_frameIndex))
    Call InitFrameControls(mt_DetailConfig(al_DetailConfigIndex).InitControls)
    Call LoadLabels(mo_Db, fra_DetailItem(ll_frameIndex), SCREEN_NAME, ms_Language_Code)
    Call InitMandatoryLabels(mt_DetailConfig(al_DetailConfigIndex).ListFieldsMandatory)
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitMultiDetailFrame")
End Sub

Private Sub InitMandatoryLabels(ByRef av_ListFieldsMandatory As Variant)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim lo_Label As Label

    For ll_Index = 0 To UBound(av_ListFieldsMandatory)
        If av_ListFieldsMandatory(ll_Index)(1) >= 0 Then
            Set lo_Label = lbl_Label(av_ListFieldsMandatory(ll_Index)(1))
            lo_Label.FontBold = True
        End If
    Next
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitMandatoryLabels")
End Sub

Private Function GetSelectedRootNode(ByRef ao_Tree As ArmTreeView) As MSComctlLib.Node
On Error GoTo ErrHandler

Dim lo_Node  As Object

    Set GetSelectedRootNode = Nothing
    Set lo_Node = ao_Tree.SelectedItem
    If Not (lo_Node Is Nothing) Then
        While Not (lo_Node.Parent Is Nothing)
            Set lo_Node = lo_Node.Parent
        Wend
    End If
    Set GetSelectedRootNode = lo_Node
    Exit Function
ErrHandler:
    Call ErrorHandler("GetSelectedRootNode")
End Function

Private Sub SetMode(ByVal ae_Mode As eMode)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ll_MainFrameIndex As Long
Dim ll_DetailFrameIndex As Long
Dim ll_DetailConfigIndex As Long
Dim ll_MainConfigIndex As Long
Dim ll_TlbIndex As Long
Dim le_SubdetailMode As eMode
Dim ls_ToolbarFace As String

    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_MainFrameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
    ll_DetailConfigIndex = FindDetailConfigByMainConfig(ll_MainConfigIndex)
    ll_DetailFrameIndex = mt_DetailConfig(ll_DetailConfigIndex).FrameIndex
    ll_TlbIndex = mt_DetailConfig(ll_DetailConfigIndex).ToolbarIndex
    
    Select Case ae_Mode
    Case emView
        ls_ToolbarFace = mt_DetailConfig(ll_DetailConfigIndex).ToolbarFaces(0)
        le_SubdetailMode = emView
    Case emAdd
        ls_ToolbarFace = mt_DetailConfig(ll_DetailConfigIndex).ToolbarFaces(1)
        le_SubdetailMode = emList
    Case emUpdate
        ls_ToolbarFace = mt_DetailConfig(ll_DetailConfigIndex).ToolbarFaces(2)
        le_SubdetailMode = emList
    Case emDelete
        ls_ToolbarFace = mt_DetailConfig(ll_DetailConfigIndex).ToolbarFaces(3)
        le_SubdetailMode = emView
    Case Else
        le_SubdetailMode = emNone
        ls_ToolbarFace = ""
        ll_TlbIndex = -1
    End Select
    
    If ls_ToolbarFace <> "" Then
        If Not tlb_Detail(ll_TlbIndex).DisplayFace(ls_ToolbarFace) Then
            Err.Raise ArmErr.CompFncFailed, "tlb_Detail", "DisplayFace method failed for face: '" & ls_ToolbarFace & "'"
        End If
    End If
    
    For ll_Index = 0 To tlb_Detail.Count - 1
        tlb_Detail(ll_Index).Visible = (ll_Index = ll_TlbIndex)
        tlb_Detail(ll_Index).Enabled = (ll_Index = ll_TlbIndex)
    Next
    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If mt_SubdetailConfig(ll_Index).DetailConfigIndex = ll_DetailConfigIndex Then
            Call SetModeSubDetail(mt_SubdetailConfig(ll_Index).FrameIndex, le_SubdetailMode)
        End If
    Next
    
    Select Case ae_Mode
    Case emList
        tbs_Main.Enabled = True
        For ll_Index = 0 To fra_DetailItem.Count - 1
            fra_DetailItem(ll_Index).Visible = False
        Next
        For ll_Index = 0 To fra_MainItem.Count - 1
            If ll_Index = ll_MainFrameIndex Then
                fra_MainItem(ll_Index).Zorder
                fra_MainItem(ll_Index).Visible = True
            Else
                fra_MainItem(ll_Index).Visible = False
            End If
        Next
    Case Else
        tbs_Main.Enabled = False
        For ll_Index = 0 To fra_MainItem.Count - 1
            fra_MainItem(ll_Index).Visible = False
        Next
        For ll_Index = 0 To fra_DetailItem.Count - 1
            If ll_Index = ll_DetailFrameIndex Then
                fra_DetailItem(ll_Index).Zorder
                fra_DetailItem(ll_Index).Visible = True
            Else
                fra_DetailItem(ll_Index).Visible = False
            End If
        Next
    End Select
    me_OldDetailMode = me_DetailMode
    me_DetailMode = ae_Mode
    Exit Sub
ErrHandler:
    Call ErrorHandler("SetMode")
End Sub

Private Sub SetModeSubDetail(ByVal al_SubDetailIndex As Long, ByVal ae_Mode As eMode)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ll_frameIndex As Long
Dim ll_DetailIndex As Long
Dim ls_ToolbarFace As String

    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailIndex = mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex
    
    If (ae_Mode = emList) Or (ae_Mode = emView) Then
        fra_SubDetailItem(ll_frameIndex).Visible = False
        grd_Subdetail(ll_frameIndex).Top = 2 * FRM_SPACE_VER
        grd_Subdetail(ll_frameIndex).Height = fra_SubDetail(ll_frameIndex).Height - 3 * FRM_SPACE_VER
    Else
        grd_Subdetail(ll_frameIndex).Top = fra_SubDetailItem(ll_frameIndex).Top + fra_SubDetailItem(ll_frameIndex).Height + FRM_SPACE_VER
        grd_Subdetail(ll_frameIndex).Height = fra_SubDetail(ll_frameIndex).Height - fra_SubDetailItem(ll_frameIndex).Height - 4 * FRM_SPACE_VER
        fra_SubDetailItem(ll_frameIndex).Visible = True
    End If
    
    ls_ToolbarFace = ""
    If UBound(mt_SubdetailConfig(al_SubDetailIndex).ToolbarFaces) = 4 Then
        Select Case ae_Mode
        Case emView
            ls_ToolbarFace = mt_SubdetailConfig(al_SubDetailIndex).ToolbarFaces(0)
        Case emList
            ls_ToolbarFace = mt_SubdetailConfig(al_SubDetailIndex).ToolbarFaces(1)
        Case emAdd
            ls_ToolbarFace = mt_SubdetailConfig(al_SubDetailIndex).ToolbarFaces(2)
        Case emUpdate
            ls_ToolbarFace = mt_SubdetailConfig(al_SubDetailIndex).ToolbarFaces(3)
        Case emDelete
            ls_ToolbarFace = mt_SubdetailConfig(al_SubDetailIndex).ToolbarFaces(4)
        End Select
    End If
    
    If ls_ToolbarFace = "" Then
        tlb_SubDetail(ll_frameIndex).Visible = False
    Else
        Call tlb_SubDetail(ll_frameIndex).DisplayFace(ls_ToolbarFace)
        tlb_SubDetail(ll_frameIndex).Visible = True
    End If
    
    grd_Subdetail(ll_frameIndex).Enabled = (ae_Mode = emAdd) Or (ae_Mode = emView) Or (ae_Mode = emList)
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If mt_SubdetailConfig(ll_Index).DetailConfigIndex = ll_DetailIndex Then
            tlb_SubDetail(ll_Index).Enabled = (ll_Index = ll_frameIndex) Or ((ae_Mode = emView) Or (ae_Mode = emList))
        End If
    Next
    tlb_Detail(mt_DetailConfig(ll_DetailIndex).ToolbarIndex).Enabled = (ae_Mode = emView) Or (ae_Mode = emList)
    Call fra_SubDetail(ll_frameIndex).Refresh
    me_SubDetailMode = ae_Mode
    Exit Sub
ErrHandler:
    Call ErrorHandler("SetModeSubDetail")
End Sub

Private Sub ResetFrameControls(ByRef ao_Frame As Frame)
On Error GoTo ErrHandler

Dim lo_Control As Control

    mb_InternalInit = True
    For Each lo_Control In UserControl.Controls
    
        If HasContainer(lo_Control, ao_Frame) Then
            If StrComp(lo_Control.Name, "chk_Repositioning", vbTextCompare) <> 0 Then
                Select Case UCase(TypeName(lo_Control))
                    Case "ARMCOMBOBOX"
                        Call lo_Control.Clear
                        lo_Control.Tag = ""
                        lo_Control.Request = ""
                        lo_Control.Visible = False
                    Case "ARMPICKER"
                        Call lo_Control.Clear
                        lo_Control.Tag = ""
                        lo_Control.Visible = False
                    Case "CHECKBOX"
                        lo_Control.Value = Unchecked
                        lo_Control.Tag = ""
                        lo_Control.Caption = ""
                        lo_Control.Visible = False
                    Case "TEXTBOX"
                        lo_Control.Tag = ""
                        lo_Control.Text = ""
                        lo_Control.Visible = False
                    Case "A_CALOCX"
                        Call lo_Control.reinit_cal
                        lo_Control.Tag = ""
                        lo_Control.Visible = False
                    Case "LABEL"
                        lo_Control.Tag = ""
                        lo_Control.Caption = ""
                        lo_Control.FontBold = False
                        lo_Control.Visible = False
                End Select
            End If
        End If
    Next
    mb_InternalInit = False
    Exit Sub
ErrHandler:
    mb_InternalInit = False
    Call ErrorHandler("ResetFrameControls")
End Sub

Private Sub UpdateDrivenComboRequest(ByRef ao_Combo As Object, ByVal al_DetailIndex As Long, ByVal ab_ForceClear As Boolean)
On Error GoTo ErrHandler

Dim ls_Request As String

    If ab_ForceClear Then Call ao_Combo.Clear
    
    ls_Request = GetInitControlProperty(al_DetailIndex, ao_Combo, eControlPropertyIndex.cpiRequest)
    ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(mt_DetailConfig(al_DetailIndex).FrameIndex))
    ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    ao_Combo.Request = ls_Request
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateDrivenComboRequest")
End Sub

Private Sub LoadToolbar(ByRef ao_Toolbar As Object, ByVal al_Id As Long)
On Error GoTo ErrHandler

Dim ls_Request As String
Dim ls_ToolbarInfo As String

    ' no toolbar definition ID, do not load anything
    If (al_Id = 0) Or (ms_ToolbarRequest = "") Then Exit Sub
    'load all definition strings only once and keep it in cursor
    If mc_Toolbars = 0 Then
        ls_Request = ReplacePlaceHolder(ms_ToolbarRequest, "$Module$", SQLStr(SCREEN_NAME))
        mc_Toolbars = OpenSQLSafe(mo_Db, ls_Request)
    End If
    
    If mo_Db.Find(mc_Toolbars, "Id", al_Id) < 0 Then
        Err.Raise ArmErr.InvalidValue, ao_Toolbar.Name, "Toolbar not found in toolbars_definitions ID:" & al_Id
    End If
    
    ls_ToolbarInfo = mo_Db.GetFields(mc_Toolbars, "info")
    If Not ao_Toolbar.SetToolbarInfoStringParameters(ls_ToolbarInfo, Left(ls_ToolbarInfo, 3)) Then
        Err.Raise ArmErr.InvalidValue, ao_Toolbar.Name, "SetToolbarInfoStringParameters failed for toolbar ID:" & al_Id
    End If
    Call ao_Toolbar.DisplayFace("0")
    Exit Sub
ErrHandler:
    Call ErrorHandler("LoadToolbar")
End Sub

Private Function FindSubDetailConfigByName(ByVal as_SubdetailName As String) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long

    FindSubDetailConfigByName = -1
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If StrComp(mt_SubdetailConfig(ll_Index).NameFrame, as_SubdetailName, vbTextCompare) = 0 Then
            FindSubDetailConfigByName = ll_Index
            Exit Function
        End If
    Next
    Exit Function
ErrHandler:
    Call ErrorHandler("FindSubDetailConfigByName")
End Function

Private Function FindSubDetailConfigByFrameIndex(ByVal al_FrameIndex As Long) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long

    FindSubDetailConfigByFrameIndex = -1
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If mt_SubdetailConfig(ll_Index).FrameIndex = al_FrameIndex Then
            FindSubDetailConfigByFrameIndex = ll_Index
            Exit Function
        End If
    Next
    Exit Function
ErrHandler:
    Call ErrorHandler("FindSubDetailConfigByFrameIndex")
End Function


Private Function FindMainConfigByFrameIndex(ByVal al_FrameIndex As Long) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long

    FindMainConfigByFrameIndex = -1
    For ll_Index = 0 To UBound(mt_MainConfig)
        If mt_MainConfig(ll_Index).FrameIndex = al_FrameIndex Then
            FindMainConfigByFrameIndex = ll_Index
            Exit Function
        End If
    Next
    Exit Function
ErrHandler:
    Call ErrorHandler("FindMainConfigByFrameIndex")
End Function

Private Function FindMainConfigByName(ByVal as_Name As String) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long

    FindMainConfigByName = -1
    For ll_Index = 0 To UBound(mt_MainConfig)
        If StrComp(mt_MainConfig(ll_Index).NameFrame, as_Name, vbTextCompare) = 0 Then
            FindMainConfigByName = ll_Index
            Exit Function
        End If
    Next
    Exit Function
ErrHandler:
    Call ErrorHandler("FindMainConfigByName")
End Function

Private Function FindDetailConfigByFrameIndex(ByVal al_FrameIndex As Long) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long

    FindDetailConfigByFrameIndex = -1
    For ll_Index = 0 To UBound(mt_DetailConfig)
        If mt_DetailConfig(ll_Index).FrameIndex = al_FrameIndex Then
            FindDetailConfigByFrameIndex = ll_Index
            Exit Function
        End If
    Next
    Err.Raise ArmErr.InvalidValue, "al_FrameIndex=" & al_FrameIndex, "Detail config index not found."
    Exit Function
ErrHandler:
    Call ErrorHandler("FindDetailConfigByFrameIndex")
End Function

Private Function FindDetailConfigByName(ByVal as_Name As String) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long

    FindDetailConfigByName = -1
    For ll_Index = 0 To UBound(mt_DetailConfig)
        If StrComp(mt_DetailConfig(ll_Index).NameFrame, as_Name, vbTextCompare) = 0 Then
            FindDetailConfigByName = ll_Index
            Exit Function
        End If
    Next
    Err.Raise ArmErr.InvalidValue, "as_Name=" & as_Name, "Detail config index not found."
    Exit Function
ErrHandler:
    Call ErrorHandler("FindDetailConfigByName")
End Function

Private Function FindDetailConfigByMainConfig(ByVal al_MainIndex As Long) As Long
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim lo_ComboItem As Object
Dim ll_frameIndex As Long
Dim le_DocumentType  As eDocumentType

    FindDetailConfigByMainConfig = -1
    ll_frameIndex = mt_MainConfig(al_MainIndex).FrameIndex
    If mt_MainConfig(al_MainIndex).IsMultiDetailView Then
        FindDetailConfigByMainConfig = mt_MainConfig(al_MainIndex).CurrentDetailIndex
        Exit Function
    Else
        For ll_Index = 0 To UBound(mt_DetailConfig)
            If mt_DetailConfig(ll_Index).MainConfigIndex = al_MainIndex Then
                FindDetailConfigByMainConfig = ll_Index
                Exit Function
            End If
        Next
    End If
    Err.Raise ArmErr.InvalidValue, "al_MainIndex=" & al_MainIndex, "Detail config index not found."
    Exit Function
ErrHandler:
    Call ErrorHandler("FindDetailConfigByMainConfig")
End Function

'to check if our current position in treeview will allow us to display added/updated item in grid
Private Function IsItemSelectedInTree(ByVal al_DetailIndex As Long, ByRef ao_Tree As ArmTreeView, ByVal av_PathData As Variant) As Boolean
On Error GoTo ErrHandler
    
Dim ll_SelLevel As Long, ll_IdxLvl As Long
Dim lo_Node As Object
Dim lb_CheckDone As Boolean


    IsItemSelectedInTree = IsItemSelectedInTreeCustom(al_DetailIndex, ao_Tree, av_PathData, lb_CheckDone)
    If lb_CheckDone Then Exit Function
    
    IsItemSelectedInTree = False
    
    Set lo_Node = ao_Tree.SelectedItem
    If lo_Node Is Nothing Then Exit Function
    If Not IsArray(av_PathData) Then Exit Function
    
    ll_SelLevel = lo_Node.Tag.ml_Level
    
    If ll_SelLevel > UBound(av_PathData) Then
        IsItemSelectedInTree = False
        Exit Function
    End If
    
    For ll_IdxLvl = ll_SelLevel To 0 Step -1
        If lo_Node Is Nothing Then Exit Function
        If Not IsArray(av_PathData(ll_IdxLvl)) Then
            Err.Raise ArmErr.InvalidValue, "av_PathData(ll_IdxLvl)", "Path data element is not an array: " & ll_IdxLvl
        End If
        If StrComp(lo_Node.Tag.IDValue, av_PathData(ll_IdxLvl)(0), vbTextCompare) <> 0 Then
            Exit Function
        End If
        Set lo_Node = lo_Node.Parent
    Next
    IsItemSelectedInTree = True
    Exit Function
ErrHandler:
    Call ErrorHandler("IsItemSelectedInTree")
End Function

' Return true if have created the node
' TODO : Manage the third parameter...
Private Function FindInTreeView(ByRef ao_Tree As ArmTreeView, ByVal av_PathData As Variant, ByVal ab_AutoCreate As Boolean, ByVal ab_Expand As Boolean) As Node
On Error GoTo ErrHandler

Dim lb_Internal As Boolean
Dim lo_Node As Object
Dim ll_LvlIdx As Long, ll_DataIdx As Long
Dim ls_Key As String, ls_Desc As String
    
    Set FindInTreeView = Nothing
    lb_Internal = mb_InternalInit
    mb_InternalInit = True
    Set lo_Node = Nothing
    For ll_LvlIdx = 0 To UBound(av_PathData)
        If Not IsArray(av_PathData(ll_LvlIdx)) Then
            Err.Raise ArmErr.InvalidValue, "av_PathData(ll_LvlIdx)", "Path data element is not an array"
        End If
        
        If UBound(av_PathData(ll_LvlIdx)) = 1 Then
            ls_Key = av_PathData(ll_LvlIdx)(0)
            ls_Desc = av_PathData(ll_LvlIdx)(1)
        ElseIf UBound(av_PathData(ll_LvlIdx)) > 1 Then
            ls_Key = av_PathData(ll_LvlIdx)(0)
            ls_Desc = av_PathData(ll_LvlIdx)(2)
        Else
            Err.Raise ArmErr.InvalidValue, "av_PathData(ll_LvlIdx)", "Invalid count of path data elements"
        End If
        
        If ao_Tree.Find(ls_Key, 0, lo_Node, ll_LvlIdx) Then
            Set lo_Node = ao_Tree.SelectedItem
        Else
            If ab_AutoCreate Then
                'TODO add additional data from detail tree into main tree data
                Set lo_Node = ao_Tree.AddNode(lo_Node, ls_Key, ls_Desc, 1, 2, LoadTypeChildsDemand)
                If lo_Node Is Nothing Then
                    Err.Raise ArmErr.CompFncFailed, "ao_Tree.AddNode", "Function failed to create node"
                End If
                For ll_DataIdx = 1 To UBound(av_PathData(ll_LvlIdx))
                    Call lo_Node.Tag.SetData(ll_DataIdx, av_PathData(ll_LvlIdx)(ll_DataIdx))
                Next
                lo_Node.Selected = True
            Else
                GoTo CleanUp
            End If
        End If
        If (Not lo_Node.Expanded) And (ll_LvlIdx <> UBound(av_PathData)) Then
            If Not ab_Expand Then GoTo CleanUp
            Call ao_Tree.ExpandNode(lo_Node)
        End If
    Next
    
    Set FindInTreeView = lo_Node
        
CleanUp:
    Set lo_Node = Nothing
    mb_InternalInit = lb_Internal
    Exit Function
ErrHandler:
    Set lo_Node = Nothing
    mb_InternalInit = lb_Internal
    Call ErrorHandler("FindInTreeView")
End Function

Private Function GetCurrentPathData(ByRef ao_Controls As Variant, ByVal as_Path As String) As Variant
On Error GoTo ErrHandler

    Dim ls_Pattern As String, las_Tag() As String, las_Paths() As String, lv_pathData As Variant, lv_CheckData As Variant
    Dim ll_IdxPath As Long, ll_CountPath As Long, ll_Idx As Long, ll_ItemIdx As Long
    Dim lo_Control As Control
    Dim ll_Pos As Long, ls_PatternIndex As String, ls_ControlIndex As String
    
        las_Paths = Split(as_Path, SEP)
        ll_CountPath = UBound(las_Paths) + 1
        ReDim lv_pathData(ll_CountPath - 1)
        
        For Each lo_Control In ao_Controls
            For ll_IdxPath = 0 To ll_CountPath - 1
                ls_Pattern = las_Paths(ll_IdxPath)
                ' hardcoded first node of tree contain node all
                If StrComp(ls_Pattern, "ALL", vbTextCompare) = 0 Then
                    lv_pathData(ll_IdxPath) = Array(-1, "#All")
                End If
                ' hardcoded key value for tree search (maybe when data loaded from A_Reference)
                If isNumeric(ls_Pattern) Then
                    lv_pathData(ll_IdxPath) = Array(ls_Pattern, "#Unknown")
                End If
                
                ls_PatternIndex = ""
                ll_Pos = InStr(1, ls_Pattern, "(")
                If ll_Pos > 0 Then
                    ls_PatternIndex = Mid(ls_Pattern, ll_Pos + 1, Len(ls_Pattern) - ll_Pos - 1)
                    ls_Pattern = Left(ls_Pattern, ll_Pos - 1)
                End If
                ls_ControlIndex = ""
On Error Resume Next    ' is there other way how correctly retrieve index of control if it is in control array ?
                ls_ControlIndex = CStr(lo_Control.Index)
On Error GoTo ErrHandler
                If (StrComp(ls_Pattern, lo_Control.Name, vbTextCompare) = 0) And _
                   (StrComp(ls_PatternIndex, ls_ControlIndex, vbTextCompare) = 0) Then
                    Select Case UCase(TypeName(lo_Control))
                        Case "ARMCOMBOBOX"
                            lv_pathData(ll_IdxPath) = Array(GetComboKey(lo_Control), lo_Control.Text)
                            Exit For
                        Case "ARMPICKER"
                            lv_pathData(ll_IdxPath) = Array(lo_Control.ItemCode, lo_Control.ItemDescription)
                            Exit For
                        Case "TEXTBOX"
                            lv_pathData(ll_IdxPath) = Array(lo_Control.Text, lo_Control.Text)
                            Exit For
                        Case "ARMTREEVIEW"
                            Dim ll_LevelCount As Long
                            Dim ll_LevelIndex As Long
                            Dim ll_DataIndex As Long
                            Dim lv_LevelData As Variant
                            Dim lv_NodeData As Variant
                            Dim lo_Node As Object
                            
                            If Not (lo_Control.SelectedItem Is Nothing) Then
                                ll_LevelCount = lo_Control.SelectedItem.Tag.ml_Level + 1
                                ReDim lv_LevelData(ll_LevelCount - 1)
                                Set lo_Node = lo_Control.SelectedItem
                                ll_LevelIndex = ll_LevelCount - 1
                                While (Not (lo_Node Is Nothing)) And (ll_LevelIndex >= 0)
                                    If lo_Node.Tag.Length >= 0 Then
                                        ReDim lv_NodeData(lo_Node.Tag.Length)
                                        For ll_DataIndex = 0 To UBound(lv_NodeData)
                                            lv_NodeData(ll_DataIndex) = lo_Node.Tag.GetData(ll_DataIndex)
                                        Next
                                        lv_LevelData(ll_LevelIndex) = lv_NodeData
                                    Else
                                        lv_LevelData(ll_LevelIndex) = Array(lo_Node.Tag.IDValue, "", lo_Node.Tag.TextValue)
                                    End If
                                    Set lo_Node = lo_Node.Parent
                                    ll_LevelIndex = ll_LevelIndex - 1
                                Wend
                                'MS REDIMM
                                Call SafeRedimPreserve(lv_pathData, SafeUbound(lv_pathData) + ll_LevelCount - 1)
                                'ReDim Preserve lv_pathData(UBound(lv_pathData) + ll_LevelCount - 1)
                                For ll_LevelIndex = 0 To UBound(lv_LevelData)
                                    lv_pathData(ll_IdxPath + ll_LevelIndex) = lv_LevelData(ll_LevelIndex)
                                Next
                                ll_IdxPath = ll_IdxPath + ll_LevelCount - 1
                            End If
                        Case "ARMCHECKVIEW"
                            lv_CheckData = Array("", "")
                            If lo_Control.RoleList("EDIT").CheckedCount > 0 Then
                                ReDim lv_CheckData(lo_Control.RoleList("EDIT").CheckedCount * 2 - 1)
                                ll_ItemIdx = 0
                                For ll_Idx = 1 To lo_Control.RoleList("EDIT").Count
                                    If lo_Control.RoleList("EDIT").Items(ll_Idx).CurrentChecked Then
                                        lv_CheckData(ll_ItemIdx * 2) = lo_Control.RoleList("EDIT").Items(ll_Idx).GetData(0)
                                        lv_CheckData(ll_ItemIdx * 2 + 1) = lo_Control.RoleList("EDIT").Items(ll_Idx).GetData(1)
                                        ll_ItemIdx = ll_ItemIdx + 1
                                    End If
                                Next
                            End If
                            lv_pathData(ll_IdxPath) = lv_CheckData
                            Exit For
                    End Select
                End If
            Next ll_IdxPath
        Next lo_Control
        Set lo_Control = Nothing
        GetCurrentPathData = lv_pathData
    Exit Function

ErrHandler:
    Set lo_Control = Nothing
    Call ErrorHandler("GetCurrentPathData")

End Function

Private Sub InitItemDetailKey(ByVal al_DetailIndex As Long)
On Error GoTo ErrHandler

    Dim ll_frameIndex As Long
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    'replace the holders (from the frame record)
    If mt_DetailConfig(al_DetailIndex).TableName <> "" Then
        txt_DetailKey(ll_frameIndex).Text = GetNextID(mt_DetailConfig(al_DetailIndex).TableName)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitItemDetailKey")
End Sub

Private Function Item_CheckMandatory(ByVal av_ListFieldsMandatory As Variant) As Boolean
On Error GoTo ErrHandler
    
    Dim lIdx As Long, lCount As Long
    Dim lv_MsgReplaceInfo(0, 1) As String
    Dim lo_Control As Object
    Dim ls_LabelCaption As String
    Dim ll_CtrlIndex As Long
    Dim lb_Found As Boolean
    
    If Not IsArray(av_ListFieldsMandatory) Then
        Item_CheckMandatory = True
        Exit Function
    End If
    
    lCount = UBound(av_ListFieldsMandatory, 1)
    
    For lIdx = 0 To lCount
            Set lo_Control = av_ListFieldsMandatory(lIdx)(0)
            If av_ListFieldsMandatory(lIdx)(1) >= 0 Then
                ls_LabelCaption = lbl_Label(av_ListFieldsMandatory(lIdx)(1)).Caption
            Else
                ls_LabelCaption = ""
            End If
            Select Case UCase(TypeName(lo_Control))
                Case "FRAME", "LABEL", "MSFLEXGRID", "TOOLBARCONTROL"
                    ' Do nothing !
                
                Case "TEXTBOX"
                    If lo_Control.Visible And (lo_Control.Text = "") Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Exit Function
                    End If
                Case "ARMCHECKVIEW"
                     If lo_Control.Visible And (lo_Control.RoleList("EDIT").CheckedCount = 0) Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Call lo_Control.SetFocus
                        Exit Function
                      End If
                Case "A_CALOCX"
                    If lo_Control.Visible And (lo_Control.date_courte = "") Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Exit Function
                    End If
                Case "ARMGRID", "ARMCHECKVIEW", "COMMANDBUTTON", "ARMTREEVIEW", "LISTBOX", "PICTUREBOX", "TABSTRIP"
                Case "OPTIONBUTTON", "CHECKBOX"
                    'probably array of controls
                Case "OBJECT"
                    lb_Found = False
                    For ll_CtrlIndex = 0 To lo_Control.Count - 1
                        If UCase(TypeName(lo_Control(ll_CtrlIndex))) = "CHECKBOX" Then
                            If lo_Control(ll_CtrlIndex).Value = vbChecked Then
                                lb_Found = True
                                Exit For
                            End If
                        ElseIf UCase(TypeName(lo_Control(ll_CtrlIndex))) = "OPTIONBUTTON" Then
                            If lo_Control(ll_CtrlIndex).Value Then
                                lb_Found = True
                                Exit For
                            End If
                        Else
                            ' unknown array ???
                            lb_Found = True
                            Exit For
                        End If
                    Next
                    If Not lb_Found Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Exit Function
                    End If
                Case "ARMCOMBOBOX"
                    If lo_Control.Visible And (lo_Control.SelectedItem Is Nothing) Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Exit Function
                    End If
                Case "ARMPICKER"
                    If lo_Control.Visible And (CStr(lo_Control.ItemCode) = "") Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Exit Function
                    End If
                Case "LISTVIEW"
                     If lo_Control.Visible And (GetCheckedCount(lo_Control) = 0) Then
                        lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                        lv_MsgReplaceInfo(0, 1) = ls_LabelCaption
                        Call MsgBox(MsgText(2120, ms_Language_Code, "The field " & lv_MsgReplaceInfo(0, 1) & " is mandatory.", lv_MsgReplaceInfo), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
                        Exit Function
                      End If
                Case Else
                    Debug.Print "Item_CheckMandatory " & UCase(TypeName(lo_Control))
            End Select
    Next

    Item_CheckMandatory = True

    Exit Function
ErrHandler:
    Call ErrorHandler("Item_CheckMandatory")
    
End Function

Private Sub Item_Clear(ByVal al_DetailIndex As Long)
On Error GoTo ErrHandler

Dim ll_Index As Long

    Call ClearFrame(UserControl.Controls, fra_DetailItem(mt_DetailConfig(al_DetailIndex).FrameIndex))
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If (mt_SubdetailConfig(ll_Index).DetailConfigIndex = al_DetailIndex) And (mt_SubdetailConfig(ll_Index).RequestView <> "") Then
            ReDim mt_SubdetailConfig(ll_Index).DeletedRows(-1 To -1)
        End If
    Next
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_Clear")
End Sub

Private Sub Item_Load(ByVal al_DetailIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler

Dim ls_req As String
Dim ll_frameIndex As Long

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    ls_req = mt_DetailConfig(al_DetailIndex).RequestView
    ls_req = ReplaceKeyPlaceholders(ls_req, av_Key)
    ls_req = ReplaceLanguagePlaceholderFromToolbar(ls_req)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    'load data
    If mc_Item > 0 Then
        Call mo_Db.Close(mc_Item)
        mc_Item = 0
    End If
    
    mc_Item = OpenSQLSafe(mo_Db, ls_req, 1)
   
    Call LoadFrameDataFromCursor(mo_Db, mc_Item, fra_DetailItem(ll_frameIndex))
    
    Call Item_CustomLoad(al_DetailIndex, av_Key)
    Exit Sub
ErrHandler:
    If mc_Item <> 0 Then Call mo_Db.Close(mc_Item)
    mc_Item = 0
    Call ErrorHandler("Item_Load")
End Sub

Private Sub Item_ViewInit(ByVal al_DetailIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler
    
    Dim ll_frameIndex As Long
    Dim ls_req As String
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    Call InitDetailFrame(al_DetailIndex)
        
    'clear the frame record and disable frames
    Call ClearFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex))
    
    
    Call Item_Load(al_DetailIndex, av_Key)
    Call SubItem_Load(al_DetailIndex, av_Key)
    
    Call EnableFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex), False)
    
    'change screen mode
    Call SetMode(emView)
    
    Call UpdateDetailToolbarCustom(al_DetailIndex)
    
    Call Item_CustomInit(al_DetailIndex, av_Key, emView)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_ViewInit")
End Sub

Private Sub Item_ReInit(ByVal al_DetailConfigIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler

    Dim ll_frameIndex As Integer
    
    ll_frameIndex = mt_DetailConfig(al_DetailConfigIndex).FrameIndex
    Select Case me_DetailMode
    Case emAdd
        Call Item_AddInit(al_DetailConfigIndex)
    Case emUpdate
        Call Item_UpdateInit(al_DetailConfigIndex, av_Key)
    Case Else
        Err.Raise ArmErr.InvalidArgument, "me_DetailMode", "Invalid mode: " & me_DetailMode
    End Select
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_ReInit")
End Sub

Private Sub Item_AddInit(ByVal al_DetailConfigIndex As Long)
On Error GoTo ErrHandler

    Dim ll_frameIndex As Integer
    
    ll_frameIndex = mt_DetailConfig(al_DetailConfigIndex).FrameIndex
    
    Call InitDetailFrame(al_DetailConfigIndex)
    
    'clear the frame record
    Call Item_Clear(al_DetailConfigIndex)
    
    Call EnableFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex), True)
    
    Call DisableFrameParts(mt_DetailConfig(al_DetailConfigIndex).ListFieldsToDisable)
    
    'load default values
    Call Item_LoadDefaultValue(al_DetailConfigIndex, mt_DetailConfig(al_DetailConfigIndex).ListFieldsDefaultValue)
    
    Call SetDrivenDetailControls(Nothing)

    'Change screen mode
    Call SetMode(emAdd)
    
    Call Item_CustomInit(al_DetailConfigIndex, Empty, emAdd)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_AddInit")
End Sub

Private Function Item_Add(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler
    
    Dim ll_frameIndex As Long
    Dim ll_MainIndex As Long
    Dim ll_MainFrameIndex As Long
    
    Item_Add = False
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    'check the data validity -> Item_Check
    If Not Item_CheckMandatory(mt_DetailConfig(al_DetailIndex).ListFieldsMandatory) Then Exit Function
    
    'check the custom data validity -> Item_CheckCustom
    If Not Item_CustomCheck(al_DetailIndex, eMode.emAdd) Then Exit Function
    
    'update data on the db ->
    If Not Item_AddDB(al_DetailIndex) Then Exit Function

    Call Item_AddLocal(UserControl.Controls, fra_DetailItem(ll_frameIndex), tvw_Main(ll_MainFrameIndex), grd_Main(ll_MainFrameIndex), chk_Repositioning(ll_frameIndex).Value = vbChecked)
    
    Call Item_CustomLocal(al_DetailIndex, eMode.emAdd)
    'go back to the detail screen
    Call Item_ExitToGrid(ll_MainIndex, al_DetailIndex)
    Call SetMode(emList)
    Item_Add = True
    
    Exit Function
ErrHandler:
    Call ErrorHandler("Item_Add")
End Function

Private Function Item_CheckAddDB(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler
    
    Dim lc_Cursor As Long
    Dim ls_Request As String
    Dim ll_Index As Long, ll_Count As Long, ll_frameIndex As Long
    
    Item_CheckAddDB = False
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ls_Request = mt_DetailConfig(al_DetailIndex).RequestCheckAdd
    If ls_Request <> "" Then
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        ' HERE WE CHECK THE DATA INTEGRITY (UNICITY)
        ' ll_Count indicates if the data already  exists
        lc_Cursor = OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If ll_Count > 0 Then
            Call MsgBox(MsgText(mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 0), ms_Language_Code, mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 1)), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            Exit Function
        End If
    End If
    Item_CheckAddDB = True
    Exit Function
ErrHandler:
    If lc_Cursor <> 0 Then Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("Item_CheckAddDB")
End Function

Private Function Item_AddDB(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_Index As Long, ll_frameIndex As Long, ll_Count As Long
    Dim lb_inTransaction As Boolean
    
    Item_AddDB = False
    lb_inTransaction = False
    
    If Not Item_CheckAddDB(al_DetailIndex) Then Exit Function
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    'replace the holders (from the frame record)
    Call InitItemDetailKey(al_DetailIndex)
    
    'handle transaction
    If mt_DetailConfig(al_DetailIndex).UseTransaction Then
        Call BeginTran("Item_AddDB")
        lb_inTransaction = True
    End If
    
    ll_Count = UBound(mt_DetailConfig(al_DetailIndex).RequestAdd)
    For ll_Index = 0 To ll_Count
        'get the request from the ClassInfo
        ls_Request = mt_DetailConfig(al_DetailIndex).RequestAdd(ll_Index)
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        Call ExecuteSQLSafe(mo_Db, ls_Request, IIf(ll_Index = ll_Count, mt_DetailConfig(al_DetailIndex).AffectedCount(0), -1))
    Next
    
    If lb_inTransaction Then Call Item_CustomAddDB(al_DetailIndex, lb_inTransaction)
    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If mt_SubdetailConfig(ll_Index).DetailConfigIndex = al_DetailIndex Then
            Call SaveSubDetailGrid(ll_Index)
        End If
    Next
    
    If lb_inTransaction Then
        Call CommitTran("Item_AddDB")
        lb_inTransaction = False
    End If
    
    Call Item_CustomAddDB(al_DetailIndex, lb_inTransaction)
    
    Item_AddDB = True
    Exit Function
    
ErrHandler:
    If lb_inTransaction Then
        Call RollbackTran("Item_AddDB")
    End If
    Call ErrorHandler("Item_AddDB")
End Function

Private Function Item_AddLocal(ByRef aControls As Variant, ByRef aContainer As Object, ByRef ao_Tree As ArmTreeView, ByRef ao_grid As ArmGrid, ByVal ab_Repositioning As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_MainIndex As Long, ll_DetailIndex As Long
Dim ll_MainFrame As Long, ll_DetailFrame As Long
Dim av_PathData As Variant
Dim ls_path As String
Dim lo_Node As Object

    Item_AddLocal = False
    'change the data locally
    ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_MainFrame = mt_MainConfig(ll_MainIndex).FrameIndex
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    ll_DetailFrame = mt_DetailConfig(ll_DetailIndex).FrameIndex
    

    If mt_MainConfig(ll_MainIndex).CurrentTvwSelMethod = eTvwSelMethod.etmNone Then
        Call UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emAdd, False, "", False)
        Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emAdd)
        Item_AddLocal = True
        Exit Function
    End If
    ls_path = Trim(cbo_View(ll_MainFrame).SelectedItem.GetData(2))
    If ls_path = "" Then
        Call UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emAdd, False, "", False)
        Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emAdd)
        Item_AddLocal = True
        Exit Function
    End If
    av_PathData = GetCurrentPathData(UserControl.Controls, ls_path)
    If Not IsItemInFilter(ll_DetailIndex) Then
        Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emAdd)
        Call MsgBox(MsgText(7204, ms_Language_Code, "#Updated item cannot be displayed with current filter"), , App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        'Err.Raise 202, "Item_AddLocal", "Updated item cannot be displayed with current filter"
        Item_AddLocal = False
        Exit Function
    End If
    If IsItemSelectedInTree(ll_DetailIndex, tvw_Main(ll_MainFrame), av_PathData) Then
        ' item is in current filter do not need to reposition just update grid
        If UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emAdd, False, "", False) Then
            Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emAdd)
            Item_AddLocal = True
            Exit Function
        End If
    End If
    If ab_Repositioning And IsArray(av_PathData) Then
        Set lo_Node = FindInTreeView(ao_Tree, av_PathData, True, True)
        If Not (lo_Node Is Nothing) Then
            Call tvw_Main_NodeClick(CInt(ll_MainFrame), lo_Node)
            If mt_MainConfig(ll_MainIndex).GridDelayed Then
                If Not ao_grid.Execute Then
                    Err.Raise ArmErr.CompFncFailed, "grd_Main(" & ll_MainFrame & ").Execute", "Method Execute failed: " & ao_grid.Requests(0)
                End If
                 mt_MainConfig(ll_MainIndex).GridDelayed = False
            End If
            Call ao_grid.SearchKey(True, txt_DetailKey(ll_DetailFrame).Text)
        End If
    Else
        Set lo_Node = ao_Tree.SelectedItem
        Call FindInTreeView(ao_Tree, av_PathData, True, False)
        Set ao_Tree.SelectedItem = lo_Node
        'don't do anything, item is not added localy to tree because tree do not filter it
    End If
    Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emAdd)
    Item_AddLocal = True
    Exit Function
ErrHandler:
    Call ErrorHandler("Item_AddLocal")
End Function

Private Sub Item_UpdateInit(ByVal al_DetailIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler

    Dim ll_frameIndex As Long
    
    If IsEmpty(av_Key) Then Exit Sub
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    If me_DetailMode <> emView Then
        Call InitDetailFrame(al_DetailIndex)
    End If
    
    Call EnableFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex), True)
    
    Call DisableFrameParts(mt_DetailConfig(al_DetailIndex).ListFieldsToDisable)
        
    If me_DetailMode = emView Then
        ' do nothing, data are already in controls we are going from view to update
    ElseIf me_DetailMode = emUpdate Then
        ' ml_Cursor contain already loaded data, this means reinit, from update to update
        Call LoadFrameDataFromCursor(mo_Db, mc_Item, fra_DetailItem(ll_frameIndex))
        Call Item_CustomLoad(al_DetailIndex, av_Key)
        ' reload subgrid, this cannot be redo locally
        Call SubItem_Load(al_DetailIndex, av_Key)
    Else
        'clear the frame record and disable frames
        Call ClearFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex))
        Call Item_Load(al_DetailIndex, av_Key)
        Call SubItem_Load(al_DetailIndex, av_Key)
    End If
    
    Call SetDrivenDetailControls(Nothing)
    
    'Change screen mode
    Call SetMode(emUpdate)
    
    Call Item_CustomInit(al_DetailIndex, av_Key, emUpdate)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_UpdateInit")
End Sub

Private Function Item_Update(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Integer, ll_MainFrameIndex As Long
Dim ll_MainIndex As Long
    
    Item_Update = False
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    
    'check the data validity -> Item_Check
    If Not Item_CheckMandatory(mt_DetailConfig(al_DetailIndex).ListFieldsMandatory) Then Exit Function
    
    'check the custom data validity -> Item_CheckCustom
    If Not Item_CustomCheck(al_DetailIndex, eMode.emUpdate) Then Exit Function
    
    'update data on the db ->
    If Not Item_UpdateDB(al_DetailIndex) Then Exit Function
    'if success then update the data locally ->
    Call Item_UpdateLocal(UserControl.Controls, fra_DetailItem(ll_frameIndex), tvw_Main(ll_MainFrameIndex), grd_Main(ll_MainFrameIndex), chk_Repositioning(ll_frameIndex).Value = vbChecked)
    Call Item_CustomLocal(al_DetailIndex, eMode.emUpdate)
    
    'go back to the detail screen
    Call Item_ExitToGrid(ll_MainIndex, al_DetailIndex)
    Call SetMode(emList)
    Item_Update = True
    Exit Function
ErrHandler:
    Call ErrorHandler("Item_Update")
End Function

Private Function Item_CheckUpdateDB(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler

    'START Check unicity ************
    Dim ls_Request As String
    Dim lc_Cursor As Long
    Dim ll_Count As Long
    Dim ll_frameIndex As Long
    
    Item_CheckUpdateDB = False
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ls_Request = mt_DetailConfig(al_DetailIndex).RequestCheckUpdate
    If ls_Request <> "" Then
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        lc_Cursor = OpenSQLSafe(mo_Db, ls_Request)
        
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If ll_Count > 0 Then
            Call MsgBox(MsgText(mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 0), ms_Language_Code, mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 1)), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            Exit Function
        End If
    End If
    'END Check unicity ************
    Item_CheckUpdateDB = True
    Exit Function
ErrHandler:
    Item_CheckUpdateDB = False
    If lc_Cursor <> 0 Then Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("Item_CheckUpdateDB")
End Function

Private Function Item_UpdateDB(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long
    Dim ll_Index As Long, ll_Count As Long
    Dim lb_inTransaction As Boolean
    
    Item_UpdateDB = False
    
    lb_inTransaction = False
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    If Not Item_CheckUpdateDB(al_DetailIndex) Then Exit Function
    
    'handle transaction
    If mt_DetailConfig(al_DetailIndex).UseTransaction Then
        Call BeginTran("Item_UpdateDB")
        lb_inTransaction = True
    End If
    
    ll_Count = UBound(mt_DetailConfig(al_DetailIndex).RequestUpd)
    For ll_Index = 0 To ll_Count
        'get the request from the ClassInfo
        ls_Request = mt_DetailConfig(al_DetailIndex).RequestUpd(ll_Index)
        'replace the holders (from the frame record)
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplacePlaceHolder(ls_Request, "$iConcurrency$", mo_Db.GetFields(mc_Item, "iConcurrency"))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        ' first sql request should affect just 1 row from main table, other may update linked tables - 0..N records
        Call ExecuteSQLSafe(mo_Db, ls_Request, IIf(ll_Index = 0, mt_DetailConfig(al_DetailIndex).AffectedCount(1), -1))
    Next
    
    If lb_inTransaction Then Call Item_CustomUpdateDB(al_DetailIndex, lb_inTransaction)
    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If mt_SubdetailConfig(ll_Index).DetailConfigIndex = al_DetailIndex Then
            Call SaveSubDetailGrid(ll_Index)
        End If
    Next
    
    If lb_inTransaction Then
        Call CommitTran("Item_UpdateDB")
        lb_inTransaction = False
    End If
    
    Call Item_CustomUpdateDB(al_DetailIndex, lb_inTransaction)
    
    Item_UpdateDB = True
    
    Exit Function
ErrHandler:
    Item_UpdateDB = False
    If lb_inTransaction Then
        Call RollbackTran("Item_UpdateDB")
    End If
    Call ErrorHandler("Item_UpdateDB")
End Function

Private Function Item_UpdateLocal(ByRef aControls As Variant, ByRef aContainer As Object, ByRef ao_Tree As ArmTreeView, ByRef ao_grid As ArmGrid, ByVal ab_Repositioning As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_MainIndex As Long, ll_DetailIndex As Long
Dim ll_MainFrame As Long, ll_DetailFrame As Long
Dim av_PathData As Variant
Dim ls_path As String
Dim lo_Node As Object

    Item_UpdateLocal = False
    'change the data locally
    ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_MainFrame = mt_MainConfig(ll_MainIndex).FrameIndex
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    ll_DetailFrame = mt_DetailConfig(ll_DetailIndex).FrameIndex
    

    If mt_MainConfig(ll_MainIndex).CurrentTvwSelMethod = eTvwSelMethod.etmNone Then
        Call UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emUpdate, False, "", False)
        Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emUpdate)
        Item_UpdateLocal = True
        Exit Function
    End If
    
    ls_path = Trim(cbo_View(ll_MainFrame).SelectedItem.GetData(2))
    If ls_path = "" Then
        Call UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emUpdate, False, "", False)
        Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emUpdate)
        Item_UpdateLocal = True
        Exit Function
    End If
    av_PathData = GetCurrentPathData(UserControl.Controls, ls_path)
    If Not IsItemInFilter(ll_DetailIndex) Then
        Call UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emDelete, False, "", False)
        Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emUpdate)
        Call MsgBox(MsgText(7204, ms_Language_Code, "Updated item cannot be displayed with current filter"), , App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        Item_UpdateLocal = False
        Exit Function
    End If
    If IsItemSelectedInTree(ll_DetailIndex, tvw_Main(ll_MainFrame), av_PathData) Then
        ' item is in current filter do not need to reposition just update grid
        If UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emUpdate, False, "", False) Then
            Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emUpdate)
            Item_UpdateLocal = True
            Exit Function
        End If
    End If
    If ab_Repositioning And IsArray(av_PathData) Then
        Set lo_Node = FindInTreeView(ao_Tree, av_PathData, True, True)
        Call tvw_Main_NodeClick(CInt(ll_MainFrame), lo_Node)
        If mt_MainConfig(ll_MainIndex).GridDelayed Then
            If Not ao_grid.Execute Then
                Err.Raise ArmErr.CompFncFailed, "grd_Main(" & ll_MainFrame & ").Execute", "Method Execute failed: " & ao_grid.Requests(0)
            End If
             mt_MainConfig(ll_MainIndex).GridDelayed = False
        End If
        Call ao_grid.SearchKey(True, txt_DetailKey(ll_DetailFrame).Text)
    Else
        Set lo_Node = ao_Tree.SelectedItem
        Call FindInTreeView(ao_Tree, av_PathData, True, False)
        Set ao_Tree.SelectedItem = lo_Node
        ' do not reposition tree, just delete item from grid
        Call UpdateGridByFrame(ao_grid, fra_DetailItem(ll_DetailFrame), emDelete, False, "", False)
    End If
    Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), txt_DetailKey(ll_DetailFrame).Text, emUpdate)
    Item_UpdateLocal = True
    Exit Function
ErrHandler:
    Call ErrorHandler("Item_UpdateLocal")
End Function


Private Sub Item_DeleteInit(ByVal al_DetailIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler

    If IsEmpty(av_Key) Then Exit Sub
    
    Dim ll_frameIndex As Integer
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    If me_DetailMode <> emView Then
        Call InitDetailFrame(al_DetailIndex)
    End If
    
    
    If me_DetailMode <> emView Then
        'clear the frame record and disable frames
        Call ClearFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex))
        Call Item_Load(al_DetailIndex, av_Key)
        Call SubItem_Load(al_DetailIndex, av_Key)
    End If
    
    If Not Item_CheckDeleteDB(al_DetailIndex) Then Exit Sub
    
    Call EnableFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex), False)
        
    'change screen mode
    Call SetMode(emDelete)
    
    Call Item_CustomInit(al_DetailIndex, av_Key, emDelete)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_DeleteInit")
End Sub

Private Function Item_Delete(ByVal al_DetailIndex As Long) As Boolean

On Error GoTo ErrHandler

    Dim ll_frameIndex As Long
    Dim ll_MainFrameIndex As Long
    Dim ll_MainIndex As Long
    
    Item_Delete = False
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    
    'check the custom data validity -> Item_CheckCustom
    If Not Item_CustomCheck(al_DetailIndex, eMode.emDelete) Then Exit Function
    
    'delete data on the db
    If Not Item_DeleteDB(al_DetailIndex) Then Exit Function
    
    'if success then delete the data locally ->
    Call Item_DeleteLocal(UserControl.Controls, fra_DetailItem(ll_frameIndex), tvw_Main(ll_MainFrameIndex), grd_Main(ll_MainFrameIndex), chk_Repositioning(ll_frameIndex).Value = vbChecked)
    Call Item_CustomLocal(al_DetailIndex, eMode.emDelete)
    'go back to the detail screen
    Call Item_ExitToGrid(ll_MainIndex, al_DetailIndex)
    Call SetMode(emList)
    Item_Delete = True
    Exit Function
ErrHandler:
    Call ErrorHandler("Item_Delete")
End Function

Private Function Item_CheckDeleteDB(ByVal al_DetailConfigIndex As Long) As Boolean
On Error GoTo ErrHandler
    
    Dim ls_Request As String
    Dim lc_Cursor As Long
    Dim ll_Count As Long
    Dim ll_frameIndex As Long
    
    Item_CheckDeleteDB = False
    
    ll_frameIndex = mt_DetailConfig(al_DetailConfigIndex).FrameIndex
    ls_Request = mt_DetailConfig(al_DetailConfigIndex).RequestCheckDelete
    
    If ls_Request <> "" Then
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        ' THIS IS NOT AN ERROR
        ' WE CHECK IS USER IS ALLOWED TO DELETE THIS DATA
        ' A DATA CAN'T BE DELETE IF IT HAVE SOME DEPENDANCIES, LIKE ATTACHMENT
        ' Li_Count is the count of dependancies
        lc_Cursor = OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        If ll_Count > 0 Then
            MsgBox MsgText(mt_DetailConfig(al_DetailConfigIndex).CheckDelMsg(0, 0), ms_Language_Code, mt_DetailConfig(al_DetailConfigIndex).CheckDelMsg(0, 1)), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
            Exit Function
        End If
    End If
    Item_CheckDeleteDB = True
    Exit Function
ErrHandler:
    If lc_Cursor <> 0 Then Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("Item_CheckDelete")
End Function

Private Function Item_DeleteDB(ByVal al_DetailIndex As Long) As Boolean

On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long, ll_Count As Long
    Dim ll_Index As Long
    Dim lb_inTransaction As Boolean
    
    Item_DeleteDB = False
    
    lb_inTransaction = False
    
    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex

    Call Item_CustomDeleteDB(al_DetailIndex, lb_inTransaction)
    
    'handle transaction
    If mt_DetailConfig(al_DetailIndex).UseTransaction Then
        Call BeginTran("Item_DeleteDB")
        lb_inTransaction = True
    End If

    If lb_inTransaction Then Call Item_CustomDeleteDB(al_DetailIndex, lb_inTransaction)
    
    ll_Count = UBound(mt_DetailConfig(al_DetailIndex).RequestDel)
    For ll_Index = 0 To ll_Count
    
        'get the request from the al_DetailIndex
        ls_Request = mt_DetailConfig(al_DetailIndex).RequestDel(ll_Index)
        'replace the holders (from the frame record)
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplacePlaceHolder(ls_Request, "$iConcurrency$", mo_Db.GetFields(mc_Item, "iConcurrency"))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        ' last delete commant should delete (mark deleted) 1 row from main table, other sql request delete 0..N links
        Call ExecuteSQLSafe(mo_Db, ls_Request, IIf(ll_Index = ll_Count, mt_DetailConfig(al_DetailIndex).AffectedCount(2), -1))
    Next
    
    If lb_inTransaction Then
        Call CommitTran("Item_DeleteDB")
        lb_inTransaction = False
    End If
    
    Item_DeleteDB = True
    Exit Function
    
ErrHandler:
    Item_DeleteDB = False
    If lb_inTransaction Then
        Call RollbackTran("Item_DeleteDB")
    End If
    Call ErrorHandler("Item_DeleteDB")
End Function

Private Function Item_DeleteLocal(ByRef aControls As Variant, ByRef aContainer As Object, ByRef ao_Tree As ArmTreeView, ByVal ao_grid As ArmGrid, ByVal ab_Repositioning As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_MainIndex As Long, ll_DetailIndex As Long
Dim ll_MainFrame As Long, ll_DetailFrame As Long
Dim ls_Key As String

    'change the data locally
    ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_MainFrame = mt_MainConfig(ll_MainIndex).FrameIndex
    ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainIndex)
    ll_DetailFrame = mt_DetailConfig(ll_DetailIndex).FrameIndex
    ls_Key = txt_DetailKey(ll_DetailFrame).Text
    
    Call UpdateLocalComboboxes(GetDetailKeyFieldName(ll_DetailIndex), ls_Key, emDelete)
    
    If Not ao_grid.DeleteSelectedLines Then
        Err.Raise ArmErr.CompFncFailed, "ao_grid", "DeleteSelectedLines failed"
    End If
    
    If Not ab_Repositioning Then
        Item_DeleteLocal = True
        Exit Function
    End If
    
    Item_DeleteLocal = True
    Exit Function
    
ErrHandler:
    Call ErrorHandler("Item_DeleteLocal")
End Function

Private Sub SubItem_Load(ByVal al_DetailIndex As Long, ByVal av_Key As Variant)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim lb_DelayedLoad As Boolean
Dim ls_req As String

    
    For ll_Index = 0 To UBound(mt_SubdetailConfig)
        If (mt_SubdetailConfig(ll_Index).DetailConfigIndex = al_DetailIndex) And (mt_SubdetailConfig(ll_Index).RequestView <> "") Then
            ReDim mt_SubdetailConfig(ll_Index).DeletedRows(-1 To -1)
            Call grd_Subdetail(ll_Index).ClearGrid
            lb_DelayedLoad = (mt_SubdetailConfig(ll_Index).GridDelayMethod = egmDelayedAlways)
            ls_req = mt_SubdetailConfig(ll_Index).RequestView
            ls_req = ReplaceKeyPlaceholders(ls_req, av_Key)
            ls_req = ReplaceLanguagePlaceholderFromToolbar(ls_req)
            ls_req = ReplaceCommonPlaceholders(ls_req)
            If Not grd_Subdetail(ll_Index).Load(ls_req, True, , , lb_DelayedLoad) Then
                Err.Raise ArmErr.CompFncFailed, "grd_SubDetail(" & ll_Index & ").Load", "Grid load failed: " & ls_req
            End If
        End If
    Next
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_Load")
End Sub

Private Sub SubItem_AddInit(ByVal al_SubDetaiIndex As Long)
On Error GoTo ErrHandler

    Dim ll_frameIndex As Integer
    
    ll_frameIndex = mt_DetailConfig(al_SubDetaiIndex).FrameIndex
   
    Call InitSubdetailFrame(al_SubDetaiIndex)
    
    'clear the frame record
    Call ClearFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex))
    
    Call EnableFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex), True)
    
    Call DisableFrameParts(mt_SubdetailConfig(al_SubDetaiIndex).ListFieldsToDisable)
    'load default values
    Call SubItem_LoadDefaultValue(al_SubDetaiIndex, mt_SubdetailConfig(al_SubDetaiIndex).ListFieldsDefaultValue)
    
    'Change screen mode
    Call SetModeSubDetail(al_SubDetaiIndex, emAdd)
    
    Call SubItem_CustomInit(al_SubDetaiIndex, "", emAdd)
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_AddInit")
End Sub

Private Function SubItem_Add(ByVal al_SubDetailIndex As Long) As Boolean
On Error GoTo ErrHandler

Dim ll_frameIndex As Long
Dim lb_CustomSaved As Boolean
        
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
        'check the data validity -> Item_Check
    If Not Item_CheckMandatory(mt_SubdetailConfig(al_SubDetailIndex).ListFieldsMandatory) Then Exit Function
    
    If Not SubItem_CustomCheck(al_SubDetailIndex, eMode.emAdd) Then Exit Function
    
    If Not SubItem_CheckAddDB(al_SubDetailIndex) Then Exit Function
    
    If Not SubItem_CustomAdd(al_SubDetailIndex, lb_CustomSaved) Then Exit Function
    
   ' first check if some custom code for database update executed, if yes, then framework do not need to do action
    If Not lb_CustomSaved Then
        'update data on the db ->
        'If me_DetailMode = emUpdate Then
        '    If Not SubItem_AddDB(al_SubdetailIndex) Then Exit Function
        'End If
            
        If Not UpdateGridByFrame(grd_Subdetail(ll_frameIndex), fra_SubDetailItem(ll_frameIndex), emAdd, True, mt_SubdetailConfig(al_SubDetailIndex).TableOrder, True) Then Exit Function
    End If
    
    SubItem_Add = True
    
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_Add")
End Function

Private Function SubItem_CheckAddDB(ByVal al_SubDetailIndex As Long) As Boolean
On Error GoTo ErrHandler
    Dim ls_Request As String
    Dim lc_Cursor As Long, ll_frameIndex As Long, ll_DetailFrameIndex As Long
    Dim ll_Count As Integer
    
    SubItem_CheckAddDB = False
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailFrameIndex = mt_DetailConfig(mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex).FrameIndex
    ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestCheckAdd
    If ls_Request <> "" Then
        ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_SubDetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        
        ' HERE WE CHECK THE DATA INTEGRITY (UNICITY)
        ' li_Count indicates if the data already  exists
        lc_Cursor = OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If ll_Count > 0 Then
            Call MsgBox(MsgText(mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 0), ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 1)), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            Exit Function
        End If
    End If
    SubItem_CheckAddDB = SubItem_CustomCheckDB(al_SubDetailIndex, emAdd)
    Exit Function
ErrHandler:
    If lc_Cursor <> 0 Then Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("SubItem_CheckAddDB")
End Function

Private Function SubItem_AddDB(ByVal al_SubDetailIndex As Long, ByVal al_RowIndex As Long) As Boolean
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long, ll_DetailFrameIndex As Long
    Dim lb_CustomSaved As Boolean
    
    SubItem_AddDB = False
        
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailFrameIndex = mt_DetailConfig(mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex).FrameIndex
    
    If mt_SubdetailConfig(al_SubDetailIndex).TableName <> "" Then
        txt_SubDetailKey(ll_frameIndex).Text = GetNextID(mt_SubdetailConfig(al_SubDetailIndex).TableName)
    Else
        txt_SubDetailKey(ll_frameIndex).Text = ""
    End If
    
    
    lb_CustomSaved = False
    If Not SubItem_CustomDBBefore(al_SubDetailIndex, emAdd, al_RowIndex, lb_CustomSaved) Then Exit Function
    
    If Not lb_CustomSaved Then
        'get the request from the ClassInfo
        ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestAdd
        
        If ls_Request <> "" Then
            ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
            ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_SubDetailKey(ll_frameIndex))
            ls_Request = ReplaceRequestByGridData(grd_Subdetail(ll_frameIndex), ls_Request, al_RowIndex, mt_SubdetailConfig(al_SubDetailIndex).TableName)
            ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
            ls_Request = ReplaceCommonPlaceholders(ls_Request)
            Call ExecuteSQLSafe(mo_Db, ls_Request)
            grd_Subdetail(ll_frameIndex).Data(al_RowIndex, "iConcurrency") = 1
            grd_Subdetail(ll_frameIndex).Data(al_RowIndex, STATUS_COLUMN) = ""    ' reset status flag
        End If
        If Not SubItem_CustomDBAfter(al_SubDetailIndex, emAdd, al_RowIndex, lb_CustomSaved) Then Exit Function
    End If
    
    SubItem_AddDB = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_AddDB")
End Function

Private Sub SubItem_UpdateInit(ByVal al_SubDetailIndex As Long)
On Error GoTo ErrHandler
    
    Dim ll_frameIndex As Long
    
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex

    If grd_Subdetail(ll_frameIndex).SelectedCount <> 1 Then Exit Sub
    
    Call InitSubdetailFrame(al_SubDetailIndex)
        
    Call EnableFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex), True)
    
    Call DisableFrameParts(mt_SubdetailConfig(al_SubDetailIndex).ListFieldsToDisable)
        
    'clear the frame record and disable frames
    Call ClearFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex))
    
    Call LoadFrameDataFromGrid(grd_Subdetail(ll_frameIndex), fra_SubDetailItem(ll_frameIndex))
    
    'Change screen mode
    Call SetModeSubDetail(al_SubDetailIndex, emUpdate)
    
    Call SubItem_CustomInit(al_SubDetailIndex, "", emUpdate)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Subitem_UpdateInit")
End Sub

Private Function SubItem_Update(ByVal al_SubDetailIndex As Long) As Boolean
On Error GoTo ErrHandler
    
    Dim ll_frameIndex As Long
    Dim lb_CustomSaved As Boolean
    
    SubItem_Update = False
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    
    'check the data validity -> Item_Check
    If Not Item_CheckMandatory(mt_SubdetailConfig(al_SubDetailIndex).ListFieldsMandatory) Then Exit Function
    
    If Not SubItem_CustomCheck(al_SubDetailIndex, eMode.emUpdate) Then Exit Function
    
    If Not SubItem_CheckUpdateDB(al_SubDetailIndex) Then Exit Function
    
    If Not SubItem_CustomUpdate(al_SubDetailIndex, lb_CustomSaved) Then Exit Function
    
    If Not lb_CustomSaved Then
        'If me_DetailMode = emUpdate Then
            'update data on the db ->
        '    If Not SubItem_UpdateDB(al_SubdetailIndex) Then Exit Function
        'End If
        
        'if success then Add the data locally ->
        If Not UpdateGridByFrame(grd_Subdetail(ll_frameIndex), fra_SubDetailItem(ll_frameIndex), emUpdate, True, mt_SubdetailConfig(al_SubDetailIndex).TableOrder, True) Then Exit Function
    End If
   
    SubItem_Update = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_Update")
End Function

Private Function SubItem_CheckUpdateDB(ByVal al_SubDetailIndex As Long) As Boolean
On Error GoTo ErrHandler
    Dim ls_Request As String
    Dim lc_Cursor As Long, ll_frameIndex As Long, ll_DetailFrameIndex As Long
    Dim ll_Count As Long
    
    SubItem_CheckUpdateDB = False
    
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailFrameIndex = mt_DetailConfig(mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex).FrameIndex
    ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestCheckUpdate
    If ls_Request <> "" Then
        ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
        ls_Request = ReplaceRequestByFrameData(ls_Request, fra_SubDetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        lc_Cursor = OpenSQLSafe(mo_Db, ls_Request)
        
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If (ll_Count > 0) Then
            Call MsgBox(MsgText(mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 0), ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 1)), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            Exit Function
        End If
    End If
    SubItem_CheckUpdateDB = SubItem_CustomCheckDB(al_SubDetailIndex, emUpdate)
    Exit Function
ErrHandler:
    If lc_Cursor <> 0 Then Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("SubItem_CheckUpdateDB")
End Function

Private Function SubItem_UpdateDB(ByVal al_SubDetailIndex As Long, ByVal al_RowIndex As Long) As Boolean
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long, ll_DetailFrameIndex As Long
    Dim lb_CustomSaved As Boolean
    
    SubItem_UpdateDB = False
            
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailFrameIndex = mt_DetailConfig(mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex).FrameIndex
    
    lb_CustomSaved = False
    If Not SubItem_CustomDBBefore(al_SubDetailIndex, emUpdate, al_RowIndex, lb_CustomSaved) Then Exit Function
    If Not lb_CustomSaved Then
        'get the request from the ClassInfo
        ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestUpd
        If ls_Request <> "" Then
            ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
            ls_Request = ReplaceRequestByGridData(grd_Subdetail(ll_frameIndex), ls_Request, al_RowIndex, mt_SubdetailConfig(al_SubDetailIndex).TableName)
            ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
            ls_Request = ReplaceCommonPlaceholders(ls_Request)
            Call ExecuteSQLSafe(mo_Db, ls_Request, 1)
            grd_Subdetail(ll_frameIndex).Data(al_RowIndex, "iConcurrency") = Val(grd_Subdetail(ll_frameIndex).Data(al_RowIndex, "iConcurrency")) + 1
            grd_Subdetail(ll_frameIndex).Data(al_RowIndex, STATUS_COLUMN) = ""    ' reset status flag
        End If
        If Not SubItem_CustomDBAfter(al_SubDetailIndex, emUpdate, al_RowIndex, lb_CustomSaved) Then Exit Function
    End If
    
    SubItem_UpdateDB = True
    Exit Function
ErrHandler:
    SubItem_UpdateDB = False
    Call ErrorHandler("SubItem_UpdateDB")
End Function

Private Sub SubItem_DeleteInit(ByVal al_SubDetailIndex As Long)
On Error GoTo ErrHandler

    Dim ll_frameIndex As Long
    
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex

    If grd_Subdetail(ll_frameIndex).SelectedCount <> 1 Then Exit Sub
    
    If Not SubItem_CheckDeleteDB(al_SubDetailIndex) Then Exit Sub
    
    'clear the frame record and disable frames
    Call ClearFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex))
    
            
    Call InitSubdetailFrame(al_SubDetailIndex)
        
    Call LoadFrameDataFromGrid(grd_Subdetail(ll_frameIndex), fra_SubDetailItem(ll_frameIndex))
    
    Call EnableFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex), False)
    
    'change screen mode
    Call SetModeSubDetail(al_SubDetailIndex, emDelete)
    
    Call SubItem_CustomInit(al_SubDetailIndex, "", emDelete)
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_DeleteInit")
End Sub

Private Function SubItem_Delete(ByVal al_SubDetailIndex As Long) As Boolean

On Error GoTo ErrHandler

    Dim ll_frameIndex As Long
    Dim lb_CustomSaved As Boolean
    
    SubItem_Delete = False
    'TODO: disable subdetail grid when in add,update,delete mode
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    If grd_Subdetail(ll_frameIndex).SelectedCount = 0 Then Exit Function
    
    If Not SubItem_CustomCheck(al_SubDetailIndex, eMode.emDelete) Then Exit Function
    
    If Not SubItem_CustomDelete(al_SubDetailIndex, lb_CustomSaved) Then Exit Function
    
    If Not lb_CustomSaved Then
        'delete data on the db
        'If me_DetailMode = emUpdate Then
        '    If Not SubItem_DeleteDB(al_SubdetailIndex) Then Exit Function
        'End If
        
        'if success then delete the data locally ->
        If Not UpdateGridByFrame(grd_Subdetail(ll_frameIndex), fra_SubDetailItem(ll_frameIndex), emDelete, False, mt_SubdetailConfig(al_SubDetailIndex).TableOrder, True) Then Exit Function
        
    End If
    
    SubItem_Delete = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubItem_Delete")
End Function

Private Function SubItem_CheckDeleteDB(ByVal al_SubDetailIndex As Long) As Boolean
On Error GoTo ErrHandler
    
    Dim ls_Request As String
    Dim lc_Cursor As Long
    Dim ll_Count As Long, ll_frameIndex As Long
    
    SubItem_CheckDeleteDB = False
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestCheckDelete
    If ls_Request <> "" Then
        ls_Request = ReplaceRequestByGridData(grd_Subdetail(ll_frameIndex), ls_Request, grd_Subdetail(ll_frameIndex).Row, mt_SubdetailConfig(al_SubDetailIndex).TableName)
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        ' THIS IS NOT AN ERROR
        ' WE CHECK IS USER IS ALLOWED TO DELETE THIS DATA
        ' A DATA CAN'T BE DELETE IF IT HAVE SOME DEPENDANCIES
        ' ll_Count is the count of dependancies
        lc_Cursor = OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        If ll_Count > 0 Then
            Call MsgBox(MsgText(mt_SubdetailConfig(al_SubDetailIndex).CheckDelMsg(0, 0), ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckDelMsg(0, 1)), vbInformation + vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
            Exit Function
        End If
    End If
    SubItem_CheckDeleteDB = SubItem_CustomCheckDB(al_SubDetailIndex, emDelete)
    Exit Function
ErrHandler:
    If lc_Cursor <> 0 Then Call mo_Db.Close(lc_Cursor)
    Call ErrorHandler("SubItem_CheckDeleteDB")
End Function

Private Function SubItem_DeleteDB(ByVal al_SubDetailIndex As Long, ByVal al_RowIndex As Long) As Boolean

On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long, ll_DetailFrameIndex As Long
    Dim lb_CustomSaved As Boolean
    Dim ll_KeyIdx As Long
       
    ll_frameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailFrameIndex = mt_DetailConfig(mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex).FrameIndex
    
    lb_CustomSaved = False
    If Not SubItem_CustomDBBefore(al_SubDetailIndex, emDelete, al_RowIndex, lb_CustomSaved) Then Exit Function
    If Not lb_CustomSaved Then
        'get the request from the ClassInfo
        ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestDel
        If ls_Request <> "" Then
            'replace the holders (from the frame record)
            ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
            ls_Request = ReplaceRequestByGridStoredData(grd_Subdetail(ll_frameIndex), mt_SubdetailConfig(al_SubDetailIndex).DeletedRows, ls_Request, al_RowIndex, mt_SubdetailConfig(al_SubDetailIndex).TableName)
            ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
            ls_Request = ReplaceCommonPlaceholders(ls_Request)
            Call ExecuteSQLSafe(mo_Db, ls_Request, 1)
        End If
        If Not SubItem_CustomDBAfter(al_SubDetailIndex, emDelete, al_RowIndex, lb_CustomSaved) Then Exit Function
    End If
    SubItem_DeleteDB = True
    
    Exit Function
ErrHandler:
    SubItem_DeleteDB = False
    Call ErrorHandler("SubItem_DeleteDB")
End Function

Private Function GetDetailKeyFieldName(ByVal al_DetailIndex As Long) As String
On Error GoTo ErrHandler

Dim ll_MainIndex As Long
Dim ll_MainFrameIndex As Long
Dim ll_Idx As Long

    GetDetailKeyFieldName = ""
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    For ll_Idx = 0 To grd_Main(ll_MainFrameIndex).Cols - 1
        If grd_Main(ll_MainFrameIndex).Columns(ll_Idx).Key Then
            GetDetailKeyFieldName = grd_Main(ll_MainFrameIndex).Columns(ll_Idx).FieldName
            Exit Function
        End If
    Next
    Exit Function
ErrHandler:
    Call ErrorHandler("GetDetailKeyFieldName")
End Function

Private Function DeleteNode(ByRef ao_TreeView As ArmTreeView, ByRef ao_Node As Node) As Node
On Error GoTo ErrHandler

    Dim lo_Node As Node, lo_parentNode As Node, lo_PreviousNode As Node

    Set lo_Node = ao_Node
    
    While Not lo_Node Is Nothing
        Call lo_Node.Tag.SetData(3, Val(lo_Node.Tag.GetData(3)) - 1)
        Set lo_Node = lo_Node.Parent
    Wend
    
    Set lo_Node = ao_Node
    Do While (lo_Node.Tag.GetData(3) = 0)
        Set lo_parentNode = lo_Node.Parent
        Set lo_PreviousNode = lo_Node.Previous
        Call ao_TreeView.RemoveNode(lo_Node)
        Set lo_Node = lo_parentNode
        If lo_Node Is Nothing Then Exit Do
    Loop
    Set ao_Node = Nothing

    Set DeleteNode = IIf(lo_parentNode Is Nothing, lo_PreviousNode, lo_parentNode)
    Exit Function
    
ErrHandler:
    If (Not lo_Node Is Nothing) Then Set lo_Node = Nothing
    If (Not lo_parentNode Is Nothing) Then Set lo_parentNode = Nothing
    If (Not lo_PreviousNode Is Nothing) Then Set lo_PreviousNode = Nothing
    Call ErrorHandler("DeleteNode")

End Function

'to check if updated or added item conform filter
'(there is no filter at this time but it is prepared)
Private Function IsItemInFilter(ByVal al_DetailIndex As Long) As Boolean
On Error GoTo ErrHandler

Dim lb_CheckDone As Boolean

    IsItemInFilter = IsItemInFilterCustom(al_DetailIndex, lb_CheckDone)
    If lb_CheckDone Then Exit Function
    
    IsItemInFilter = True
    Exit Function
ErrHandler:
    Call ErrorHandler("IsItemInFilter")
End Function

Private Sub Item_ExitToGrid(ByVal al_MainIndex As Long, ByVal al_DetailIndex As Long)
On Error GoTo ErrHandler
    
    If mc_Item > 0 Then
        Call mo_Db.Close(mc_Item)
        mc_Item = 0
    End If
    Call UpdateMainToolbarCustom(al_MainIndex)
    Exit Sub

ErrHandler:
    Call ErrorHandler("Item_ExitToGrid")
   
End Sub

Private Sub GotoPreviousItem(ByVal al_DetailIndex As Long, ByRef ao_grid As ArmGrid)
On Error GoTo ErrHandler
    
    If ao_grid.PreviousItem Then
        Call UpdateDetailToolbarCustom(al_DetailIndex)
    Else
        Call MsgBox(MsgText(927, ms_Language_Code, "#No more previous item"), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("GotoPreviousItem")
End Sub

Private Sub GotoNextItem(ByVal al_DetailIndex As Long, ByRef ao_grid As ArmGrid)
On Error GoTo ErrHandler

    If ao_grid.NextItem Then
        Call UpdateDetailToolbarCustom(al_DetailIndex)
    Else
        Call MsgBox(MsgText(928, ms_Language_Code, "#No more next item"), vbInformation, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("GotoNextItem")
End Sub

Private Sub Controls_LoadDefaultValue(ByRef av_ListFieldsDefaultValue As Variant)
On Error GoTo ErrHandler

    Dim ll_Idx As Long, ll_Count As Long
    Dim lv_Params As Variant
    Dim lo_Control As Object
    Dim ls_value As String

    ll_Count = UBound(av_ListFieldsDefaultValue)

    For ll_Idx = 0 To ll_Count
            Set lo_Control = av_ListFieldsDefaultValue(ll_Idx)(0)
            Select Case UCase(TypeName(lo_Control))
                Case "FRAME", "LABEL", "MSFLEXGRID", "TOOLBARCONTROL"
                    ' Do nothing !
                Case "TEXTBOX"
                    lo_Control.Text = av_ListFieldsDefaultValue(ll_Idx)(1)
                Case "A_CALOCX"
                    ls_value = av_ListFieldsDefaultValue(ll_Idx)(1)
                    If StrComp(ls_value, "Date") = 0 Then
                        lo_Control.date_courte = Format(Date, "dd\/mm\/yyyy")
                    ElseIf StrComp(Left(ls_value, 5), "Date+") = 0 Then
                        lo_Control.date_courte = Format(Date + CLng(Mid(ls_value, 6)), "dd\/mm\/yyyy")
                    ElseIf StrComp(Left(ls_value, 5), "Date-") = 0 Then
                        lo_Control.date_courte = Format(Date - CLng(Mid(ls_value, 6)), "dd\/mm\/yyyy")
                    Else
                        lo_Control.date_courte = ls_value
                    End If
                Case "ARMGRID", "ARMCHECKVIEW", "COMMANDBUTTON", "ARMTREEVIEW", "LISTBOX", "PICTUREBOX", "TABSTRIP"
                
                Case "OPTIONBUTTON", "CHECKBOX"
                    lo_Control.Value = av_ListFieldsDefaultValue(ll_Idx)(1)
                Case "ARMCOMBOBOX"
                    lv_Params = Split(av_ListFieldsDefaultValue(ll_Idx)(1), SEP)
                    If Not lo_Control.SearchItem(lv_Params(0)) Then
                        If UBound(lv_Params) >= 1 Then
                            Call lo_Control.AddItem(Array(lv_Params(0), lv_Params(1)))
                        Else
                            Call lo_Control.Load ' load only once and remember found default value. Do not use any hardcoded default value
                            If lo_Control.SearchItem(lv_Params(0)) Then
                                av_ListFieldsDefaultValue(ll_Idx)(1) = lv_Params(0) & SEP & lo_Control.Text
                            End If
                        End If
                    End If
                Case "ARMPICKER"
                    lv_Params = Split(av_ListFieldsDefaultValue(ll_Idx)(1), SEP)
                    lo_Control.ItemCode = lv_Params(0)
                    If UBound(lv_Params) >= 1 Then
                        lo_Control.ItemDescription = lv_Params(1)
                    End If
                                    
                Case Else
                    Debug.Print "Controls_LoadDefaultValue " & UCase(TypeName(lo_Control))
            End Select
    Next
    Set lo_Control = Nothing
    Exit Sub
ErrHandler:
    Call ErrorHandler("Controls_LoadDefaultValue")
End Sub

Private Sub Item_LoadDefaultValue(ByVal al_DetailIndex As Long, ByRef av_ListFieldsDefaultValue As Variant)
On Error GoTo ErrHandler

    Call Controls_LoadDefaultValue(av_ListFieldsDefaultValue)
    Call Item_CustomLoadDefaultValue(al_DetailIndex, av_ListFieldsDefaultValue)
    Exit Sub
ErrHandler:
    Call ErrorHandler("Item_LoadDefaultValue")
End Sub

Private Sub SubItem_LoadDefaultValue(ByVal al_SubDetailIndex As Long, ByRef av_ListFieldsDefaultValue As Variant)
On Error GoTo ErrHandler

    Call Controls_LoadDefaultValue(av_ListFieldsDefaultValue)
    Call SubItem_CustomLoadDefaultValue(al_SubDetailIndex, av_ListFieldsDefaultValue)
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_LoadDefaultValue")
End Sub

Private Function GetTreeViewInfo(ByRef aTVInfos() As TTreeViewInfo, ByVal AScreenName As String, ByVal aTVCode As String) As TTreeViewInfo
On Error GoTo ErrHandler
    Dim lIdx As Long, lCount As Long
    Dim lTreeView As TTreeViewInfo, lFound As Boolean
    
    ' Search in the array
    lCount = UBound(aTVInfos)
    lFound = False
    For lIdx = 0 To lCount
        If aTVInfos(lIdx).TreeViewCode = aTVCode Then
            If Not aTVInfos(lIdx).Loaded Then
                aTVInfos(lIdx) = GetTreeViewInfoFromDB(AScreenName, aTVCode)
            End If
            lTreeView = aTVInfos(lIdx)
            lFound = True
            Exit For
        End If
    Next
    
    If Not lFound Then
        Call Err.Raise(ArmErr.InvalidArgument, "TreeviewInfo", "TreeViewInfo not found. AScreenName=" & AScreenName & " aTVCode=" & aTVCode)
    End If
    
    GetTreeViewInfo = lTreeView
    Exit Function
ErrHandler:
    Call ErrorHandler("GetTreeViewInfo")

End Function

Private Function ApplyTVFilters(ByVal al_MainIndex As Long, ByVal av_Request As Variant) As Variant
On Error GoTo ErrHandler
    Dim lv_Requests As Variant
    
    If IsArray(av_Request) Then
        ReDim lv_Requests(UBound(av_Request))
        Dim ll_Idx As Long, ll_Count As Long
        ll_Count = UBound(lv_Requests)
        For ll_Idx = 0 To ll_Count
            lv_Requests(ll_Idx) = ReplaceFiltersHolders(al_MainIndex, av_Request(ll_Idx))
            lv_Requests(ll_Idx) = ReplaceTreeviewHolders(al_MainIndex, lv_Requests(ll_Idx))
            lv_Requests(ll_Idx) = ReplaceLanguagePlaceholderFromToolbar(lv_Requests(ll_Idx))
            lv_Requests(ll_Idx) = ReplaceCommonPlaceholders(lv_Requests(ll_Idx))
        Next
    Else
        ReDim lv_Requests(0)
        lv_Requests(0) = ReplaceFiltersHolders(al_MainIndex, av_Request)
        lv_Requests(0) = ReplaceTreeviewHolders(al_MainIndex, lv_Requests(0))
        lv_Requests(0) = ReplaceLanguagePlaceholderFromToolbar(lv_Requests(0))
        lv_Requests(0) = ReplaceCommonPlaceholders(lv_Requests(0))
    End If

    ApplyTVFilters = lv_Requests
    Exit Function
ErrHandler:
    Call ErrorHandler("ApplyTVFilters")
End Function

Private Function ApplyFilters(ByVal al_MainIndex As Long, ByVal as_Request As String) As Variant
On Error GoTo ErrHandler
    Dim lv_Requests As Variant
    
    ReDim lv_Requests(0)
    lv_Requests(0) = ReplaceFiltersHolders(al_MainIndex, as_Request)
    lv_Requests(0) = ReplaceLanguagePlaceholderFromToolbar(lv_Requests(0))
    lv_Requests(0) = ReplaceCommonPlaceholders(lv_Requests(0))
    ApplyFilters = lv_Requests
    Exit Function
ErrHandler:
    Call ErrorHandler("ApplyFilters")
End Function

Private Function ReplaceFiltersHolders(ByVal al_MainIndex As Long, ByVal as_Request As String) As String
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long

    ll_frameIndex = mt_MainConfig(al_MainIndex).FrameIndex
    ls_Request = ReplaceRequestByFrameData(as_Request, fra_MainFilter(ll_frameIndex))
    ReplaceFiltersHolders = ls_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceFiltersHolders")
End Function

Private Function ReplaceTreeviewHolders(ByVal al_MainIndex As Long, ByVal as_Request As String) As String
On Error GoTo ErrHandler

    Dim ls_Request As String
    Dim ll_frameIndex As Long

    ll_frameIndex = mt_MainConfig(al_MainIndex).FrameIndex
    ls_Request = ReplacePlaceholderByControlValue(as_Request, tbs_MainTabFilter(ll_frameIndex))
    ReplaceTreeviewHolders = ls_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceTreeviewHolders")
End Function

Private Sub ReloadMainGrid()
On Error GoTo ErrHandler

Dim ll_frameIndex As Long, ll_MainConfigIndex As Long

    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_frameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
    
    
    If mt_MainConfig(ll_MainConfigIndex).CurrentTvwSelMethod = eTvwSelMethod.etmNone Then
        grd_Main(ll_frameIndex).Requests = ApplyFilters(ll_MainConfigIndex, mt_MainConfig(ll_MainConfigIndex).RequestGrid)
    Else
        If tvw_Main(ll_frameIndex).Checkboxes = True Then
            grd_Main(ll_frameIndex).Requests = ApplyTVFilters(ll_MainConfigIndex, tvw_Main(ll_frameIndex).CheckedNodesRequests)
        Else
            grd_Main(ll_frameIndex).Requests = ApplyTVFilters(ll_MainConfigIndex, tvw_Main(ll_frameIndex).SelectedNodeRequest)
        End If
        
        mt_MainConfig(ll_frameIndex).CurrentTvwSelMethod = IIf(tvw_Main(ll_frameIndex).Checkboxes, eTvwSelMethod.etmCheckBoxes, eTvwSelMethod.etmBranch)
    End If
    
    If grd_Main(ll_frameIndex).Cols = 0 Then
        Dim ll_DetailIndex As Long
        ll_DetailIndex = FindDetailConfigByMainConfig(ll_MainConfigIndex)
        If Not grd_Main(ll_frameIndex).SetColumns(mt_DetailConfig(ll_DetailIndex).MainGridColumns) Then
            Err.Raise ArmErr.CompFncFailed, "grd_Main", "Method SetColumns failed."
        End If
        Call LoadLabels(mo_Db, fra_MainItem(ll_frameIndex), SCREEN_NAME, ms_Language_Code)
    End If
    
    If grd_Main(ll_frameIndex).Execute = False Then
        Err.Raise ArmErr.CompFncFailed, "grd_Main(" & ll_frameIndex & ").Execute", "Load grid failed"
    End If
    grd_Main(ll_frameIndex).Visible = True
    Call UpdateMainToolbarCustom(ll_MainConfigIndex)
    Exit Sub
ErrHandler:
    Call ErrorHandler("ReloadMainGrid")
    
End Sub

Private Sub ReloadMainTreeview()
On Error GoTo ErrHandler
    
    mb_InternalInit = True
    Dim lb_Grid As Boolean
    Dim ll_frameIndex As Long, ll_MainConfigIndex As Long

    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_frameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
   
    If mt_MainConfig(ll_MainConfigIndex).CurrentTvwSelMethod <> eTvwSelMethod.etmNone Then
        tvw_Main(ll_frameIndex).Refresh
    End If
    Call ReloadMainGrid
    
    mb_InternalInit = False
    
    Exit Sub
ErrHandler:
    mb_InternalInit = False
    Call ErrorHandler("ReloadMainTreeview")
End Sub

Public Sub AddDroppedCheckItems(ByRef ao_chkview As ArmCheckView)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ll_Count As Long
Dim lo_ItemInfo As ArmItemInfo

    ll_Count = ao_chkview.RoleList("VIEW").Count
    For ll_Index = 1 To ll_Count
        If ao_chkview.RoleList("EDIT").GetItem(ao_chkview.RoleList("VIEW").GetKey(ll_Index)) Is Nothing Then
            Set lo_ItemInfo = ao_chkview.RoleList("VIEW").Items(ll_Index)
            Call ao_chkview.RoleList("EDIT").AddItemInfo(Array(lo_ItemInfo.GetData(0), lo_ItemInfo.GetData(1), 1), True, True)
        End If
    Next
    Call ao_chkview.RoleList("EDIT").DisplayList
    Exit Sub
ErrHandler:
    Call ErrorHandler("AddDroppedCheckItems")
End Sub

Public Sub RemoveDroppedCheckItems(ByRef ao_chkview As ArmCheckView)
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ll_Count As Long
Dim lo_ItemInfo As ArmItemInfo

    ll_Count = ao_chkview.RoleList("EDIT").Count
    For ll_Index = ll_Count To 1 Step -1
        Set lo_ItemInfo = ao_chkview.RoleList("EDIT").Items(ll_Index)
        If UBound(lo_ItemInfo.Data) > 1 Then
            Call ao_chkview.RoleList("EDIT").Items.Remove(ll_Index)
        End If
        Set lo_ItemInfo = Nothing
    Next
    Call ao_chkview.RoleList("EDIT").DisplayList
    Exit Sub
ErrHandler:
    Call ErrorHandler("RemoveDroppedCheckItems")
End Sub

Private Sub LoadListView(ByVal ao_ListView As MSComctlLib.ListView, ByVal as_Request As String)
On Error GoTo ErrHandler

Dim ll_cursor As Long
Dim lo_item As MSComctlLib.ListItem
Dim lo_SubItem As MSComctlLib.ListSubItem
Dim ll_Index As Long

    Call ao_ListView.ListItems.Clear
    ll_cursor = mo_Db.OpenSQL(as_Request)
    If ll_cursor > 0 Then
        While Not mo_Db.EOF(ll_cursor)
            Set lo_item = ao_ListView.ListItems.Add(, "KEY" & mo_Db.GetFields(ll_cursor, 0), mo_Db.GetFields(ll_cursor, 1))
            If mo_Db.FieldCount(ll_cursor) > 2 Then
                For ll_Index = 2 To mo_Db.FieldCount(ll_cursor) - 1
                    Set lo_SubItem = lo_item.ListSubItems.Add(, , mo_Db.GetFields(ll_cursor, ll_Index))
                Next
            End If
            Call mo_Db.Next(ll_cursor)
        Wend
        Call mo_Db.Close(ll_cursor)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("LoadListView")
End Sub

Private Sub CheckListView(ByVal ao_ListView As MSComctlLib.ListView, ByVal as_Request As String)
On Error GoTo ErrHandler

Dim ll_cursor As Long
Dim lo_item As MSComctlLib.ListItem
Dim lo_NewItem As MSComctlLib.ListItem
Dim ls_ItemKey As String, ls_ItemText As String

    For Each lo_item In ao_ListView.ListItems
        lo_item.Checked = False
        lo_item.Tag = ""
    Next lo_item
    ll_cursor = mo_Db.OpenSQL(as_Request)
    If ll_cursor > 0 Then
        While Not mo_Db.EOF(ll_cursor)
            For Each lo_item In ao_ListView.ListItems
                If StrComp(lo_item.Key, "KEY" & mo_Db.GetFields(ll_cursor, 0), vbTextCompare) = 0 Then
                    ls_ItemText = lo_item.Text
                    ls_ItemKey = lo_item.Key
                    Call ao_ListView.ListItems.Remove(lo_item.Index)
                    Set lo_NewItem = ao_ListView.ListItems.Add(1, ls_ItemKey, ls_ItemText)
                    lo_NewItem.Checked = True
                    lo_NewItem.Tag = "X"
                    Exit For
                End If
            Next lo_item
            Call mo_Db.Next(ll_cursor)
        Wend
        Call mo_Db.Close(ll_cursor)
    End If
    Call ao_ListView.Refresh
    Exit Sub
ErrHandler:
    Call ErrorHandler("CheckListView")
End Sub

Private Sub SaveListView(ByVal al_DetailIndex As Long, ByVal ao_ListView As MSComctlLib.ListView, ByVal as_CheckRequest As String, ByVal as_UnCheckRequest As String, ByVal as_KeyHolder As String)
On Error GoTo ErrHandler

Dim lo_item As MSComctlLib.ListItem
Dim ls_req As String


    as_CheckRequest = ReplaceRequestByFrameData(as_CheckRequest, fra_DetailItem(mt_DetailConfig(al_DetailIndex).FrameIndex))
    as_CheckRequest = ReplaceLanguagePlaceholderFromToolbar(as_CheckRequest)
    as_CheckRequest = ReplaceCommonPlaceholders(as_CheckRequest)
    
    as_UnCheckRequest = ReplaceRequestByFrameData(as_UnCheckRequest, fra_DetailItem(mt_DetailConfig(al_DetailIndex).FrameIndex))
    as_UnCheckRequest = ReplaceLanguagePlaceholderFromToolbar(as_UnCheckRequest)
    as_UnCheckRequest = ReplaceCommonPlaceholders(as_UnCheckRequest)
    
    For Each lo_item In ao_ListView.ListItems
        If IIf(lo_item.Checked, "X", "") <> lo_item.Tag Then
            If lo_item.Checked Then
                ls_req = as_CheckRequest
            Else
                ls_req = as_UnCheckRequest
            End If
            ls_req = ReplacePlaceHolder(ls_req, as_KeyHolder, SqlInt(Mid(lo_item.Key, 4)))
            Call ExecuteSQLSafe(mo_Db, ls_req)
        End If
    Next
    Exit Sub
ErrHandler:
    Call ErrorHandler("SaveListView")
End Sub

Private Function GetCheckedCount(ByRef ao_ListView As MSComctlLib.ListView) As Long
On Error GoTo ErrHandler

Dim lo_item As MSComctlLib.ListItem
Dim ll_Count As Long

    ll_Count = 0
    For Each lo_item In ao_ListView.ListItems
        If lo_item.Checked Then ll_Count = ll_Count + 1
    Next
    GetCheckedCount = ll_Count
    Exit Function
ErrHandler:
    Call ErrorHandler("GetCheckedCount")
End Function

Private Sub ClearCollection(ByVal ao_Collection As Collection)
On Error GoTo ErrHandler

    While ao_Collection.Count > 0
        Call ao_Collection.Remove(1)
    Wend
    Exit Sub
ErrHandler:
    Call ErrorHandler("ClearCollection")
End Sub


Private Function SqlInt(ByVal av_Data As Variant) As String
On Error GoTo ErrHandler

    SqlInt = "NULL"
    If IsNull(av_Data) Then av_Data = ""
    If Trim(CStr(av_Data)) <> "" Then
        SqlInt = CStr(av_Data)
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("SqlInt")
End Function

Private Function SqlDbl(ByVal av_Data As Variant) As String
On Error GoTo ErrHandler

    SqlDbl = "NULL"
    If IsNull(av_Data) Then av_Data = ""
    If Trim(CStr(av_Data)) <> "" Then
        SqlDbl = Str(av_Data)
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("SqlDbl")
End Function

Private Function SqlDate(ByVal av_Data As Variant) As String
On Error GoTo ErrHandler

    SqlDate = "NULL"
    If IsNull(av_Data) Then av_Data = ""
    If (Trim(CStr(av_Data)) <> "") And (CStr(av_Data) <> "0") Then
        SqlDate = "'" & Format(av_Data, "yyyy-mm-dd") & "'"
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("SqlDate")
End Function

Private Function SQLDateTime(ByVal av_Data As Variant) As String
On Error GoTo ErrHandler

    SQLDateTime = "NULL"
    If IsNull(av_Data) Then av_Data = ""
    If (Trim(CStr(av_Data)) <> "") And (CStr(av_Data) <> "0") Then
        SQLDateTime = "'" & Format(av_Data, "yyyy-mm-dd hh:mm:ss") & "'"
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("SqlDateTime")
End Function

Private Function SQLStr(ByVal as_Data As String) As String
On Error GoTo ErrHandler

    SQLStr = "'" & Replace(as_Data, "'", "''") & "'"
    Exit Function
ErrHandler:
    Call ErrorHandler("SqlStr")
End Function

Private Function GetComboKey(ByVal ao_Combo As ArmCombobox) As String
On Error GoTo ErrHandler

    GetComboKey = ""
    If Not (ao_Combo.SelectedItem Is Nothing) Then
        GetComboKey = Trim(CStr(ao_Combo.SelectedItem.Key))
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("GetComboKey")
End Function

Private Function CustomReplacePlaceholder(ByRef as_Request As String, ByVal as_PlaceHolder As String, ByVal as_DefaultValue As String) As Boolean
On Error GoTo ErrHandler

    CustomReplacePlaceholder = False
    Exit Function
ErrHandler:
    Call ErrorHandler("CustomReplacePlaceholder")
End Function

Private Function ReplacePlaceHolder(ByVal as_Request As String, ByVal as_PlaceHolder As String, ByVal as_DefaultValue As String) As String
On Error GoTo ErrHandler
    
    If Not CustomReplacePlaceholder(as_Request, as_PlaceHolder, as_DefaultValue) Then
        as_Request = Replace(as_Request, as_PlaceHolder, as_DefaultValue, , , vbTextCompare)
    End If
    ReplacePlaceHolder = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplacePlaceholder")
End Function

Private Function ReplaceKeyPlaceholders(ByVal as_Request As String, ByVal av_Key As Variant) As String
On Error GoTo ErrHandler

Dim ll_Index As Long

    If Not IsArray(av_Key) Then av_Key = Array(av_Key)
    
    For ll_Index = 0 To UBound(av_Key)
        as_Request = ReplacePlaceHolder(as_Request, "$Key" & (ll_Index + 1) & "$", SQLStr(av_Key(ll_Index)))
    Next
    ReplaceKeyPlaceholders = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceKeyPlaceholders")
End Function

Private Function ReplaceLanguagePlaceholderFromToolbar(ByVal as_Request As String) As String
On Error GoTo ErrHandler
Dim ll_frameIndex As Long, ll_MainIndex As Long

    ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_frameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    ReplaceLanguagePlaceholderFromToolbar = ReplacePlaceHolder(as_Request, "$toolbar_language_code$", SQLStr(tlb_Main(ll_frameIndex).Language))
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceLanguagePlaceholderFromToolbar")
End Function

Private Function ReplaceCommonPlaceholders(ByVal as_Request As String) As String
On Error GoTo ErrHandler

    as_Request = ReplacePlaceHolder(as_Request, "$language_code$", SQLStr(ms_Language_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$Z_Creator$", SqlInt(ml_U_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$U_Code$", SqlInt(ml_U_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$Z_Last_Upd_User$", SqlInt(ml_U_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$LoginName$", SQLStr(ms_LoginName))
    as_Request = ReplacePlaceHolder(as_Request, "$UserName$", SQLStr(ms_UserName))
    as_Request = ReplacePlaceHolder(as_Request, "$ComputerName$", SQLStr(ms_ComputerName))
    as_Request = ReplacePlaceHolder(as_Request, "$NetworkBoardID$", SQLStr(ms_NetworkBoardID))
    ReplaceCommonPlaceholders = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceCommonPlaceholders")
End Function

Private Function ReplacePlaceholderByControlValue(ByVal as_Request As String, ByRef ao_Control As Object) As String
On Error GoTo ErrHandler

Dim lsa_Columns() As String

    If Trim(ao_Control.Tag) = "" Then
        ReplacePlaceholderByControlValue = as_Request
        Exit Function
    End If
    
    Select Case UCase(TypeName(ao_Control))
        Case "ARMCOMBOBOX"
            lsa_Columns = Split(ao_Control.Tag, SEP)
            
            If UBound(lsa_Columns) >= 0 Then
                If GetComboKey(ao_Control) = "" Then
                    as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", "NULL")
                Else
                    as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(GetComboKey(ao_Control)))
                End If
            End If
            If UBound(lsa_Columns) >= 1 Then
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(1) & "$", SQLStr(ao_Control.Text))
            End If
        Case "ARMPICKER"
            lsa_Columns = Split(ao_Control.Tag, SEP)
            
            If UBound(lsa_Columns) >= 0 Then
                If (Trim(CStr(ao_Control.ItemCode)) = "") Or (CStr(ao_Control.ItemCode) = "0") Then
                    as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", "NULL")
                Else
                    as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(Trim(CStr(ao_Control.ItemCode))))
                End If
            End If
            If UBound(lsa_Columns) >= 1 Then
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(1) & "$", SQLStr(Trim(ao_Control.ItemDescription)))
            End If
        Case "OPTIONBUTTON"
            If ao_Control.Value = True Then
                lsa_Columns = Split(ao_Control.Tag, SEP)
                If UBound(lsa_Columns) > 1 Then
                    Select Case UCase(lsa_Columns(2))
                    Case "N"
                        as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", ao_Control.Index)
                    Case Else
                        as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(lsa_Columns(1)))
                    End Select
                ElseIf UBound(lsa_Columns) = 1 Then
                    as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(lsa_Columns(1)))
                Else
                    as_Request = ReplacePlaceHolder(as_Request, "$" & ao_Control.Name & "$", SQLStr(lsa_Columns(0)))
                End If
            End If
        Case "CHECKBOX"
            lsa_Columns = Split(ao_Control.Tag, SEP)
            If ao_Control.Value = vbChecked Then
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr("X"))
            Else
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(""))
            End If
        Case "TEXTBOX"
            lsa_Columns = Split(ao_Control.Tag, SEP)
            If UBound(lsa_Columns) > 0 Then
                Select Case UCase(lsa_Columns(1))
                Case "N"
                    If ao_Control.Text = "" Then
                       as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", "NULL")
                    Else
                       as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", ao_Control.Text)
                    End If
                Case Else
                    as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(ao_Control.Text))
                End Select
            Else
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(ao_Control.Text))
            End If
        Case "A_CALOCX"
            lsa_Columns = Split(ao_Control.Tag, SEP)
            as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SqlDate(ao_Control.date_dt))
        Case "TABSTRIP"
            lsa_Columns = Split(ao_Control.Tag, SEP)
            If StrComp(ao_Control.SelectedItem.Key, "ALL", vbTextCompare) = 0 Then
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", "NULL")
            Else
                as_Request = ReplacePlaceHolder(as_Request, "$" & lsa_Columns(0) & "$", SQLStr(ao_Control.SelectedItem.Key))
            End If
    End Select
    ReplacePlaceholderByControlValue = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplacePlaceholderByControlValue")
End Function

Private Function HasContainer(ByVal lo_Control As Control, ByRef lo_Container As Object) As Boolean
    Dim ll_Index As Long
    Dim lo_Object As Object

    On Error GoTo CleanUp   'not all controls support Container property
    HasContainer = False
    While Not (lo_Control Is Nothing)
        If lo_Control.Container Is lo_Container Then
            HasContainer = True
            Exit Function
        End If
        Set lo_Control = lo_Control.Container
    Wend

CleanUp:

End Function

Private Function UpdateGridByFrame(ByVal ao_grid As Object, ByVal ao_Frame As Frame, ae_Mode As eMode, ByVal ab_UpdateStatus As Boolean, ByVal as_OrderField As String, ByVal ab_AddToEnd As Boolean) As Boolean
On Error GoTo ErrHandler

Dim lo_Control As Control
Dim lsa_Columns() As String
Dim lsa_Value() As String
    
    UpdateGridByFrame = False
    
    If ae_Mode = emAdd Then
        If (ao_grid.Rows = 0) Or ab_AddToEnd Then
            If Not ao_grid.AddLine("") Then
                Err.Raise ArmErr.CompFncFailed, ao_grid.Name, "Method AddLine failed"
            End If
            ao_grid.Row = ao_grid.Rows - 1
        Else
            If Not ao_grid.InsertLine(0) Then
                Err.Raise ArmErr.CompFncFailed, ao_grid.Name, "Method InsertLine failed"
            End If
            ao_grid.Row = 0
        End If
        If as_OrderField <> "" Then
            For Each lo_Control In UserControl.Controls
                If HasContainer(lo_Control, ao_Frame) And (lo_Control.Tag <> "") Then
                    lsa_Value = Split(lo_Control.Tag, SEP)
                    If (StrComp(TypeName(lo_Control), "TEXTBOX", vbTextCompare) = 0) And _
                       (StrComp(lsa_Value(0), as_OrderField, vbTextCompare) = 0) Then
                        If ao_grid.Row > 0 Then
                            lo_Control.Text = ao_grid.Data(ao_grid.Rows - 2, as_OrderField) + 1
                        Else
                            lo_Control.Text = 1
                        End If
                        Exit For
                    End If
                End If
            Next
        End If
        ao_grid.CurrentLine("iConcurrency") = 1
    End If
    
    ' one row must be selected !
    If ao_grid.SelectedCount <> 1 Then
        Exit Function
    End If
    
    'update iConcurrency automatically
    'If ae_Mode = emUpdate Then
    '    ao_Grid.SelectedLine(0, "iConcurrency") = Val(ao_Grid.SelectedLine(0, "iConcurrency")) + 1
    'End If
    
    If ab_UpdateStatus Then
        If ae_Mode = emAdd Then
            ao_grid.SelectedLine(0, STATUS_COLUMN) = "A"
        ElseIf ae_Mode = emUpdate Then
            If ao_grid.SelectedLine(0, STATUS_COLUMN) <> "A" Then
                ao_grid.SelectedLine(0, STATUS_COLUMN) = "U"
            End If
        ElseIf ae_Mode = emDelete Then
            Call ao_grid.DeleteSelectedLines
        Else
            Exit Function
        End If
    Else
        If ae_Mode = emDelete Then
            Call ao_grid.DeleteSelectedLines
            UpdateGridByFrame = True
            Exit Function
        End If
    End If
    
    For Each lo_Control In UserControl.Controls
    
        If HasContainer(lo_Control, ao_Frame) And (lo_Control.Tag <> "") Then
            lsa_Value = Split(lo_Control.Tag, SEP)
            Select Case UCase(TypeName(lo_Control))
                Case "ARMCOMBOBOX"
                    If UBound(lsa_Value) >= 0 Then ao_grid.SelectedLine(0, lsa_Value(0)) = GetComboKey(lo_Control)
                    If UBound(lsa_Value) >= 1 Then ao_grid.SelectedLine(0, lsa_Value(1)) = lo_Control.Text
                Case "ARMPICKER"
                    If UBound(lsa_Value) >= 0 Then ao_grid.SelectedLine(0, lsa_Value(0)) = lo_Control.ItemCode
                    If UBound(lsa_Value) >= 1 Then ao_grid.SelectedLine(0, lsa_Value(1)) = lo_Control.ItemDescription
                Case "CHECKBOX"
                    Dim lo_Column As ArmColumn
                    Set lo_Column = ao_grid.Columns(lsa_Value(0))
                    If Not (lo_Column Is Nothing) Then
                        If lo_Column.FieldType = DBTYPE_BMP Then
                            If lo_Control.Value = vbChecked Then
                                ao_grid.SelectedLine(0, lsa_Value(0)) = "CHECK"
                            Else
                                ao_grid.SelectedLine(0, lsa_Value(0)) = "UNCHECK"
                            End If
                        Else
                            If lo_Control.Value = vbChecked Then
                                ao_grid.SelectedLine(0, lsa_Value(0)) = "X"
                            Else
                                ao_grid.SelectedLine(0, lsa_Value(0)) = ""
                            End If
                        End If
                    End If
                Case "TEXTBOX"
                    ao_grid.SelectedLine(0, lsa_Value(0)) = lo_Control.Text
                Case "A_CALOCX"
                    ao_grid.SelectedLine(0, lsa_Value(0)) = lo_Control.date_dt
            End Select
        End If
    Next
    UpdateGridByFrame = True
    Exit Function
ErrHandler:
    Call ErrorHandler("UpdateGridByFrame")
End Function

Private Function ReplaceRequestByFrameData(ByVal as_Request As String, ByVal ao_Frame As Frame)
On Error GoTo ErrHandler

Dim lo_Control As Control
   
    For Each lo_Control In UserControl.Controls
        If HasContainer(lo_Control, ao_Frame) Then
            as_Request = ReplacePlaceholderByControlValue(as_Request, lo_Control)
        End If
    Next
    ReplaceRequestByFrameData = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceRequestByFrameData")
End Function

Private Function ReplaceRequestByGridData(ByVal ao_grid As ArmGrid, ByVal as_Request As String, ByVal al_Row As Long, ByVal as_Table As String) As String
On Error GoTo ErrHandler

Dim ll_ColIndex As Long
Dim ls_Data As String
    
    For ll_ColIndex = 0 To ao_grid.Cols - 1
'        If ao_Grid.Columns(ll_ColIndex).Key And (as_Table <> "") And (ao_Grid.Data(al_Row, STATUS_COLUMN) = "A") Then
'            ls_Data = SqlInt(ao_Grid.Data(al_Row, ll_ColIndex))
'            If (ls_Data = "0") Or (ls_Data = "NULL") And (as_Table <> "") Then
'                ls_Data = mo_Db.SQLNextID(as_Table)
'                If ls_Data = "" Then
'                    Err.Raise ArmErr.CompFncFailed, "mo_Db.SQLNextID", "SQLNextID failed for: " & as_Table
'                End If
'            End If
'        Else
        Select Case ao_grid.Columns(ll_ColIndex).FieldType
        Case DBTYPE_I4
            ls_Data = SqlInt(ao_grid.Data(al_Row, ll_ColIndex))
        Case DBTYPE_R4, DBTYPE_R8
            ls_Data = SqlDbl(ao_grid.Data(al_Row, ll_ColIndex))
        Case DBTYPE_DATE
            ls_Data = SqlDate(ao_grid.Data(al_Row, ll_ColIndex))
        Case DBTYPE_BMP
            Select Case UCase(ao_grid.Data(al_Row, ll_ColIndex))
            Case "CHECK"
                ls_Data = SQLStr("X")
            Case "UNCHECK"
                ls_Data = SQLStr("")
            End Select
        Case Else
            ls_Data = SQLStr(ao_grid.Data(al_Row, ll_ColIndex))
        End Select
        as_Request = ReplacePlaceHolder(as_Request, "$" & ao_grid.Columns(ll_ColIndex).Name & "$", ls_Data)
    Next
    ReplaceRequestByGridData = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceRequestByGridData")
End Function

Private Function ReplaceRequestByGridStoredData(ByVal ao_grid As ArmGrid, ByVal ao_data As Variant, ByVal as_Request As String, ByVal al_Row As Long, ByVal as_Table As String) As String
On Error GoTo ErrHandler

Dim ll_ColIndex As Long
Dim ls_Data As String
    
    For ll_ColIndex = 0 To ao_grid.Cols - 1
        Select Case ao_grid.Columns(ll_ColIndex).FieldType
        Case DBTYPE_I4
            ls_Data = SqlInt(ao_data(al_Row)(ll_ColIndex))
        Case DBTYPE_R4, DBTYPE_R8
            ls_Data = SqlDbl(ao_data(al_Row)(ll_ColIndex))
        Case DBTYPE_DATE
            ls_Data = SqlDate(ao_data(al_Row)(ll_ColIndex))
        Case DBTYPE_BMP
            Select Case UCase(ao_data(al_Row)(ll_ColIndex))
            Case "CHECK"
                ls_Data = SQLStr("X")
            Case "UNCHECK"
                ls_Data = SQLStr("")
            End Select
        Case Else
            ls_Data = SQLStr(ao_data(al_Row)(ll_ColIndex))
        End Select
        as_Request = ReplacePlaceHolder(as_Request, "$" & ao_grid.Columns(ll_ColIndex).Name & "$", ls_Data)
    Next
    ReplaceRequestByGridStoredData = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceRequestByGridStoredData")
End Function

Private Sub LoadFrameDataFromCursor(ByVal ao_DB As ArmDb, ByVal al_cursor As Long, ByVal ao_Frame As Frame)
On Error GoTo ErrHandler

Dim lo_Control As Control
Dim lsa_Columns() As String
Dim lv_ComboData As Variant
Dim ll_Index As Long


   mb_InternalInit = True
    For Each lo_Control In UserControl.Controls
    
        If HasContainer(lo_Control, ao_Frame) Then
            Select Case UCase(TypeName(lo_Control))
                Case "ARMCOMBOBOX"
                    If Trim(lo_Control.Tag) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If (StrComp(mo_Db.GetFields(al_cursor, lsa_Columns(0)), "", vbTextCompare) <> 0) And _
                            (StrComp(mo_Db.GetFields(al_cursor, lsa_Columns(0)), "0", vbTextCompare) <> 0) Then
                            If UBound(lsa_Columns) >= 1 Then
                                If Not lo_Control.SearchItem(mo_Db.GetFields(al_cursor, lsa_Columns(0))) Then
                                    ReDim lv_ComboData(UBound(lsa_Columns))
                                    For ll_Index = 0 To UBound(lsa_Columns)
                                        lv_ComboData(ll_Index) = mo_Db.GetFields(al_cursor, lsa_Columns(ll_Index))
                                    Next
                                    If lo_Control.AddItem(lv_ComboData, True) Is Nothing Then
                                        Err.Raise ArmErr.CompFncFailed, lo_Control.Name, "Function AddItem failed"
                                    End If
                                End If
                            Else
                                Call lo_Control.SearchItem(mo_Db.GetFields(al_cursor, lsa_Columns(0)))
                            End If
                        End If
                    End If
                Case "ARMPICKER"
                    If Trim(lo_Control.Tag) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If (StrComp(mo_Db.GetFields(al_cursor, lsa_Columns(0)), "", vbTextCompare) <> 0) And _
                            (StrComp(mo_Db.GetFields(al_cursor, lsa_Columns(0)), "0", vbTextCompare) <> 0) Then
                            If UBound(lsa_Columns) >= 1 Then
                                lo_Control.ItemCode = mo_Db.GetFields(al_cursor, lsa_Columns(0))
                                lo_Control.ItemDescription = mo_Db.GetFields(al_cursor, lsa_Columns(1))
                            End If
                        End If
                    End If
                Case "CHECKBOX"
                    If Trim(lo_Control.Tag) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If UCase(mo_Db.GetFields(al_cursor, lsa_Columns(0))) = "X" Then
                            lo_Control.Value = vbChecked
                        Else
                            lo_Control.Value = vbUnchecked
                        End If
                    End If
                Case "TEXTBOX"
                    If Trim(lo_Control.Tag) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        lo_Control.Text = mo_Db.GetFields(al_cursor, lsa_Columns(0))
                    End If
                Case "A_CALOCX"
                    If Trim(lo_Control.Tag) <> "" Then
                        If CDbl(mo_Db.GetFields(al_cursor, lo_Control.Tag)) = 0 Then
                            Call lo_Control.reinit_cal
                        Else
                            lo_Control.date_courte = Format(mo_Db.GetFields(al_cursor, lo_Control.Tag), "dd\/mm\/yyyy")
                        End If
                    End If
            End Select
        End If
    Next
    mb_InternalInit = False
    Exit Sub
ErrHandler:
    mb_InternalInit = False
    Call ErrorHandler("LoadFrameDataFromCursor")
End Sub

Private Sub SaveSubDetailGrid(ByVal al_SubDetailIndex As Long)
On Error GoTo ErrHandler

Dim ll_Index As Long, ll_KeyIdx As Long
Dim ls_Request As String
Dim ll_SubDetailFrameIndex As Long, ll_DetailFrameIndex As Long, ll_KeyCount As Long
Dim le_Mode As eMode
Dim lv_Key As Variant, lv_Data As Variant

    ll_SubDetailFrameIndex = mt_SubdetailConfig(al_SubDetailIndex).FrameIndex
    ll_DetailFrameIndex = mt_DetailConfig(mt_SubdetailConfig(al_SubDetailIndex).DetailConfigIndex).FrameIndex
    
    If Not grd_Subdetail(ll_SubDetailFrameIndex) Is Nothing Then
        For ll_Index = 0 To grd_Subdetail(ll_SubDetailFrameIndex).Rows - 1
            ls_Request = ""
            Select Case grd_Subdetail(ll_SubDetailFrameIndex).Data(ll_Index, STATUS_COLUMN)
            Case "A"
                ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestAdd
                le_Mode = emAdd
                Call SubItem_AddDB(al_SubDetailIndex, ll_Index)
            Case "U"
                ls_Request = mt_SubdetailConfig(al_SubDetailIndex).RequestUpd
                le_Mode = emUpdate
                Call SubItem_UpdateDB(al_SubDetailIndex, ll_Index)
            'Case "D"
            '    ls_Request = mt_SubdetailConfig(al_SubdetailIndex).RequestDel
            '    le_Mode = emDelete
            Case Else
                le_Mode = emNone
            End Select
            'If le_Mode <> emNone Then Call SubItem_CustomBeforeSave(al_SubdetailIndex, le_Mode, ll_Index)
            'If ls_Request <> "" Then
            '    ls_Request = ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
            '    ls_Request = ReplaceRequestByGridData(grd_Subdetail(ll_SubDetailFrameIndex), ls_Request, ll_Index, mt_SubdetailConfig(al_SubdetailIndex).TableName)
            '    ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
            '    ls_Request = ReplaceCommonPlaceholders(ls_Request)
            '    Call ExecuteSQLSafe(mo_Db, ls_Request, 1)
            '    grd_Subdetail(ll_SubDetailFrameIndex).Data(ll_Index, "iConcurrency") = Val(grd_Subdetail(ll_SubDetailFrameIndex).Data(ll_Index, "iConcurrency")) + 1
            '    'grd_Subdetail(ll_SubDetailFrameIndex).Data(ll_Index, STATUS_COLUMN) = ""    ' reset status flag
            'End If
            'If le_Mode <> emNone Then Call SubItem_CustomAfterSave(al_SubdetailIndex, le_Mode, ll_Index)
        Next
        ' find all records which have been deleted acording key. Compare original stored rows key with key of rows in grid
        If UBound(mt_SubdetailConfig(al_SubDetailIndex).DeletedRows) >= 0 Then
            ' calculate number of key columns
            ll_KeyCount = GetGridKeyCount(grd_Subdetail(ll_SubDetailFrameIndex))
            ' if there is no key, we cannot delete row
            If ll_KeyCount > 0 Then
                lv_Key = GetGridKeyIndexArray(grd_Subdetail(ll_SubDetailFrameIndex))
                ReDim lv_Data(ll_KeyCount - 1)
                ' compare stored rows to grid
                For ll_Index = 0 To UBound(mt_SubdetailConfig(al_SubDetailIndex).DeletedRows)
                    ' fill array of key values for each row in stored rows collection
                    For ll_KeyIdx = 0 To UBound(lv_Key)
                        lv_Data(ll_KeyIdx) = mt_SubdetailConfig(al_SubDetailIndex).DeletedRows(ll_Index)(lv_Key(ll_KeyIdx))
                    Next
                    ' search key in grid, if not found delete record from database
                    If Not SearchGrid(grd_Subdetail(ll_SubDetailFrameIndex), lv_Key, lv_Data, False) Then
                        Call SubItem_DeleteDB(al_SubDetailIndex, ll_Index)
                    End If
                Next
            End If
        End If
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("SaveSubDetailGrid")
End Sub

Private Function GetGridKeyIndexArray(ByVal ao_grid As ArmGrid) As Variant
On Error GoTo ErrHandler

Dim lv_KeyIndex As Variant
Dim ll_Count As Long
Dim ll_Index As Long
Dim ll_KeyIdx As Long

    ll_Count = GetGridKeyCount(ao_grid)
    ReDim lv_KeyIndex(ll_Count - 1)
    ll_KeyIdx = 0
    ' create array of key indexes
    For ll_Index = 0 To ao_grid.Cols - 1
        If ao_grid.Columns(ll_Index).Key Then
            lv_KeyIndex(ll_KeyIdx) = ll_Index
            ll_KeyIdx = ll_KeyIdx + 1
        End If
    Next
    GetGridKeyIndexArray = lv_KeyIndex
    Exit Function
ErrHandler:
    Call ErrorHandler("GetGridKeyIndexArray")
End Function

Private Function GetGridKeyCount(ByVal ao_grid As ArmGrid) As Long
On Error GoTo ErrHandler

Dim ll_KeyCount As Long
Dim ll_Index As Long

    ll_KeyCount = 0
    For ll_Index = 0 To ao_grid.Cols - 1
        If ao_grid.Columns(ll_Index).Key Then
            ll_KeyCount = ll_KeyCount + 1
        End If
    Next
    GetGridKeyCount = ll_KeyCount
    Exit Function
ErrHandler:
    Call ErrorHandler("GetGridKeyCount")
End Function

Private Sub LoadFrameDataFromGrid(ByVal ao_grid As ArmGrid, ByVal ao_Frame As Frame)
On Error GoTo ErrHandler

Dim lo_Control As Control
Dim lsa_Columns() As String
Dim lv_ComboData As Variant
Dim ll_Index As Long
   
   mb_InternalInit = True
    If ao_grid.SelectedCount <> 1 Then
        Debug.Assert True
        mb_InternalInit = False
        Exit Sub
    End If
    
    For Each lo_Control In UserControl.Controls
    
        If HasContainer(lo_Control, ao_Frame) Then
            Select Case UCase(TypeName(lo_Control))
                Case "ARMCOMBOBOX"
                    If Trim(lo_Control.Tag) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If UBound(lsa_Columns) >= 1 Then
                            If Not lo_Control.SearchItem(ao_grid.CurrentLine(lsa_Columns(0))) Then
                                ReDim lv_ComboData(UBound(lsa_Columns))
                                For ll_Index = 0 To UBound(lsa_Columns)
                                    lv_ComboData(ll_Index) = ao_grid.CurrentLine(lsa_Columns(ll_Index))
                                Next
                                If lo_Control.AddItem(lv_ComboData, True) Is Nothing Then
                                    Err.Raise ArmErr.CompFncFailed, lo_Control.Name, "Function AddItem failed"
                                End If
                            End If
                        Else
                            Call lo_Control.SearchItem(ao_grid.CurrentLine(lsa_Columns(0)))
                        End If
                    End If
                Case "ARMPICKER"
                    If Trim(lo_Control.Tag) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If UBound(lsa_Columns) >= 1 Then
                            lo_Control.ItemCode = ao_grid.CurrentLine(lsa_Columns(0))
                            lo_Control.ItemDescription = ao_grid.CurrentLine(lsa_Columns(1))
                        End If
                    End If
                Case "CHECKBOX"
                    If Trim(lo_Control.Tag) <> "" Then
                        If (StrComp(ao_grid.CurrentLine(lo_Control.Tag), "X", vbTextCompare) = 0) Or _
                           (StrComp(ao_grid.CurrentLine(lo_Control.Tag), "CHECK", vbTextCompare) = 0) Then
                            lo_Control.Value = vbChecked
                        Else
                            lo_Control.Value = vbUnchecked
                        End If
                    End If
                Case "TEXTBOX"
                    If Trim(lo_Control.Tag) <> "" Then
                        lo_Control.Text = ao_grid.CurrentLine(lo_Control.Tag)
                    End If
                Case "A_CALOCX"
                    If Trim(lo_Control.Tag) <> "" Then
                        If CDbl(ao_grid.CurrentLine(lo_Control.Tag)) = 0 Then
                            Call lo_Control.reinit_cal
                        Else
                            lo_Control.date_courte = Format(ao_grid.CurrentLine(lo_Control.Tag), "dd\/mm\/yyyy")
                        End If
                    End If
            End Select
        End If
    Next
    mb_InternalInit = False
    Exit Sub
ErrHandler:
    mb_InternalInit = False
    Call ErrorHandler("LoadFrameDataFromGrid")
End Sub

Private Sub SwapRows(ByVal al_FrameIndex As Long, ByVal ab_Down As Boolean)
On Error GoTo ErrHandler

Dim ll_Row1 As Long, ll_Row2 As Long
Dim ls_OrderValue As String, ls_OrderField As String
Dim ll_SubdetailIndex As Long, ll_frameIndex As Long
Dim lo_Grid As ArmGrid

    ll_SubdetailIndex = FindSubDetailConfigByFrameIndex(al_FrameIndex)
    Set lo_Grid = grd_Subdetail(al_FrameIndex)
    ls_OrderField = mt_SubdetailConfig(ll_SubdetailIndex).TableOrder
    
    If lo_Grid.SelectedCount <> 1 Then Exit Sub
    ll_Row1 = lo_Grid.Row
    If ab_Down Then
        If ll_Row1 = lo_Grid.Rows - 1 Then Exit Sub
        ll_Row2 = ll_Row1 + 1
    Else
        If ll_Row1 = 0 Then Exit Sub
        ll_Row2 = ll_Row1 - 1
    End If
    lo_Grid.Row = ll_Row2
    ls_OrderValue = lo_Grid.Data(ll_Row1, ls_OrderField)
    lo_Grid.Data(ll_Row1, ls_OrderField) = lo_Grid.Data(ll_Row2, ls_OrderField)
    lo_Grid.Data(ll_Row2, ls_OrderField) = ls_OrderValue
    Call lo_Grid.SwapLines(ll_Row1, ll_Row2)
    
    If lo_Grid.Data(ll_Row1, STATUS_COLUMN) <> "A" Then lo_Grid.Data(ll_Row1, STATUS_COLUMN) = "U"
    If lo_Grid.Data(ll_Row2, STATUS_COLUMN) <> "A" Then lo_Grid.Data(ll_Row2, STATUS_COLUMN) = "U"
    'if detail is in view mode, save changes immediatelly to database
    If me_DetailMode = emView Then
        Call SaveSubDetailGrid(ll_SubdetailIndex)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("SwapRows")
End Sub


Private Function SelectValue(ByVal as_Request As String) As Variant
On Error GoTo ErrHandler
Dim ll_cursor As Long

  ll_cursor = OpenSQLSafe(mo_Db, as_Request)
  If ll_cursor > 0 Then
    If mo_Db.RowCount(ll_cursor) = 1 Then
      SelectValue = mo_Db.GetFields(ll_cursor, 0)
    End If
    Call mo_Db.Close(ll_cursor)
  End If
  Exit Function
ErrHandler:
  Call mo_Db.Close(ll_cursor)
  Call ErrorHandler("SelectValue as_Request=" & as_Request)
End Function

Private Sub UpdateLocalComboboxes(ByVal as_Key As String, ByVal av_Value As Variant, ByVal ae_Mode As eMode)
On Error GoTo ErrHandler

Dim lo_Control As Object
Dim lsa_Fields() As String

    If as_Key = "" Then Exit Sub
    For Each lo_Control In UserControl.Controls
    
        If StrComp(TypeName(lo_Control), "ArmCombobox", vbTextCompare) = 0 Then
            If lo_Control.Tag <> "" Then
                lsa_Fields = Split(lo_Control.Tag, SEP)
                If StrComp(lsa_Fields(0), as_Key, vbTextCompare) = 0 Then
                    Call lo_Control.Clear
                End If
            End If
        End If
    Next
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateLocalComboboxes")
End Sub

Private Function SearchGrid(ByRef ao_grid As ArmGrid, ByVal av_columns As Variant, ByVal av_Data As Variant, ByVal ab_Select As Boolean) As Boolean
On Error GoTo ErrHandler

Dim ll_RowIdx As Long, ll_ColIdx As Long
Dim lb_Found As Boolean

    lb_Found = False
    For ll_RowIdx = 0 To ao_grid.Rows - 1
        lb_Found = True
        For ll_ColIdx = 0 To UBound(av_columns)
            If StrComp(av_Data(ll_ColIdx), ao_grid.Data(ll_RowIdx, av_columns(ll_ColIdx)), vbTextCompare) <> 0 Then
                lb_Found = False
                Exit For
            End If
        Next
        If lb_Found Then Exit For
    Next
    If lb_Found And ab_Select Then
        ao_grid.Row = ll_RowIdx
    End If
    SearchGrid = lb_Found
    Exit Function
ErrHandler:
    Call ErrorHandler("SearchGrid")
End Function

Private Function GetColIndex(ByRef ao_grid As ArmGrid, ByVal as_ColumnName As String) As Long
On Error GoTo ErrHandler

Dim ll_ColIdx As Long

    For ll_ColIdx = 0 To ao_grid.Cols - 1
        If StrComp(as_ColumnName, ao_grid.Columns(ll_ColIdx).FieldName, vbTextCompare) = 0 Then
            GetColIndex = ll_ColIdx
            Exit Function
        End If
    Next
    GetColIndex = -1
    Exit Function
ErrHandler:
    Call ErrorHandler("GetColIndex")
End Function

Private Function GetTreeViewPath(ByVal ao_Tree As ArmTreeView, ByVal al_dataIndex As Long, ByVal as_Separator As String) As String
On Error GoTo ErrHandler

Dim as_Path As String
Dim lo_Node As MSComctlLib.Node
    
    as_Path = ""
    Set lo_Node = ao_Tree.SelectedItem
    While Not (lo_Node Is Nothing)
    
        If as_Path <> "" Then as_Path = as_Separator & as_Path
        as_Path = lo_Node.Tag.GetData(al_dataIndex) & as_Path
        Set lo_Node = lo_Node.Parent
    Wend
    GetTreeViewPath = as_Path
    Exit Function
ErrHandler:
    Call ErrorHandler("GetTreeViewPath")
End Function

Private Sub ClearFrame(ByRef ao_Controls As Object, ByVal ao_Frame As Frame)
On Error GoTo ErrHandler

Dim ll_Idx As Long, ll_Count As Long, lo_Control As Object

   mb_InternalInit = True
    ll_Count = ao_Controls.Count - 1
    For ll_Idx = 0 To ll_Count
        Set lo_Control = ao_Controls.Item(ll_Idx)
        
        If StrComp(lo_Control.Name, "chk_Repositioning", vbTextCompare) <> 0 Then
        
            If HasContainer(lo_Control, ao_Frame) Then
                Select Case UCase(TypeName(lo_Control))
                    Case "TEXTBOX"
                        lo_Control.Text = ""
                    Case "ARMCOMBOBOX"
                        Set lo_Control.SelectedItem = Nothing
                    Case "ARMPICKER"
                        Call lo_Control.Clear
                    Case "A_CALOCX"
                        lo_Control.reinit_cal
                    Case "CHECKBOX"
                        lo_Control.Value = vbUnchecked
                    Case "ARMCHECKVIEW"
                        Call lo_Control.Init
                        Call RemoveDroppedCheckItems(lo_Control)
                    Case "FRAME", "LABEL", "TOOLBARCONTROL", "PICTUREBOX", "COMMANDBUTTON", _
                         "TABSTRIP", "DRIVELISTBOX", "DIRLISTBOX", "FILELISTBOX", "LISTVIEW"
                        'do nothing
                    Case "ARMGRID"
                        lo_Control.ClearGrid
                        lo_Control.Requests = ""
                    Case "LISTBOX"
                        lo_Control.ListIndex = -1
                    Case "OPTIONBUTTON"
                        Dim lv_Values As Variant
                        lv_Values = Split(lo_Control.Tag, SEP)
                        If UBound(lv_Values) >= 1 Then
                            lo_Control.Value = lv_Values(1)
                        Else
                            lo_Control.Value = False
                        End If
                    Case "ARMTREEVIEW"
                        Call lo_Control.Clear
                    Case Else
                        Debug.Print "ClearFrame " & UCase(TypeName(lo_Control))
                End Select
            End If
        End If
    Next
    Set lo_Control = Nothing
    mb_InternalInit = False
    Exit Sub
ErrHandler:
    Set lo_Control = Nothing
    mb_InternalInit = False
    Call ErrorHandler("ClearFrame")
End Sub

Private Sub EnableFrame(ByRef aControls As Variant, ByRef aContainer As Object, ByVal ab_Enabled As Boolean)
On Error GoTo ErrHandler
    
    Dim lIdx As Long, lCount As Long
    Dim lControl As Control
    
    lCount = aControls.Count - 1
    
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        If HasContainer(lControl, aContainer) Then
            Select Case UCase(TypeName(lControl))
                Case "TOOLBARCONTROL"
                    'lControl.Visible = ab_Enabled
                
                Case "FRAME", "LABEL", "MSFLEXGRID"
                    ' Do nothing !
                
                Case "TEXTBOX"
                    lControl.Locked = Not ab_Enabled
                    lControl.BackColor = IIf(ab_Enabled, CL_COLOR_ENABLED, CL_COLOR_DISABLED)
                
                Case "ARMGRID", "TABSTRIP"
                
                Case "ARMCHECKVIEW"
                    If ab_Enabled Then
                        Call lControl.SetVisibleList("EDIT")
                    Else
                        Call lControl.SetVisibleList("VIEW")
                    End If
                    
                Case "DIRLISTBOX", "DRIVELISTBOX", "FILELISTBOX"
                    lControl.Enabled = ab_Enabled
                    lControl.BackColor = IIf(ab_Enabled, CL_COLOR_ENABLED, CL_COLOR_DISABLED)

                Case "LISTVIEW", "COMMANDBUTTON", "ARMCOMBOBOX", "ARMPICKER", "A_CALOCX", "OPTIONBUTTON", "ARMTREEVIEW", "LISTBOX", "PICTUREBOX", "CHECKBOX"
                    lControl.Enabled = ab_Enabled
                Case Else
                    lControl.Enabled = ab_Enabled
                    Debug.Print "EnableFrame " & UCase(TypeName(lControl))
            End Select
        End If
        Set lControl = Nothing
    Next
    Exit Sub
ErrHandler:
    If Not lControl Is Nothing Then Set lControl = Nothing
    Call ErrorHandler("EnableFrame")
End Sub

Private Sub DisableFrameParts(ByVal av_ListFieldsToDisable As Variant)
On Error GoTo ErrHandler
    
    Dim lIdx As Long, lCount As Long
    Dim lParams As Variant
    
    If Not IsArray(av_ListFieldsToDisable) Then Exit Sub
    lCount = UBound(av_ListFieldsToDisable)
    
    For lIdx = 0 To lCount
            Select Case UCase(TypeName(av_ListFieldsToDisable(lIdx)))
                Case "FRAME", "LABEL", "MSFLEXGRID", "TOOLBARCONTROL"
                    ' Do nothing !
                
                Case "TEXTBOX"
                        av_ListFieldsToDisable(lIdx).Locked = True
                        av_ListFieldsToDisable(lIdx).BackColor = CL_COLOR_DISABLED
                        
                Case "ARMGRID", "ARMCHECKVIEW"
                                    
                Case "OPTIONBUTTON", "COMMANDBUTTON", "ARMCOMBOBOX", "ARMPICKER", "A_CALOCX", "ARMTREEVIEW", "LISTBOX", "PICTUREBOX", "TABSTRIP", "CHECKBOX"
                    av_ListFieldsToDisable(lIdx).Enabled = False
                    
                Case Else
                    Debug.Print "DisableFrameParts " & UCase(TypeName(av_ListFieldsToDisable(lIdx)))
            End Select
    Next
    Exit Sub
ErrHandler:
    Call ErrorHandler("DisableFrameParts")
End Sub

Private Sub SetTreeDelayedMode(ByVal al_FrameIndex As Long, ByVal ab_Delayed As Boolean)
On Error GoTo ErrHandler
Dim ll_MainConfigIndex As Long
    
    ll_MainConfigIndex = FindMainConfigByFrameIndex(al_FrameIndex)
    'If mt_MainConfig(ll_MainConfigIndex).CurrentTvwSelMethod = eTvwSelMethod.etmNone Then
    '    tvw_Main(al_FrameIndex).Visible = False
    '    cmd_TVReLoad(al_FrameIndex).Visible = False
    '    grd_Main(al_FrameIndex).Visible = Not ab_Delayed
    'Else
        tvw_Main(al_FrameIndex).Visible = Not ab_Delayed
        cmd_TVReLoad(al_FrameIndex).Visible = ab_Delayed
        mt_MainConfig(ll_MainConfigIndex).TreeDelayed = ab_Delayed
        grd_Main(al_FrameIndex).Visible = Not ab_Delayed
    'End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("SetTreeDelayedMode")
End Sub

Private Function GetModeFromRole(ByVal as_Role As String) As eMode
On Error GoTo ErrHandler

    GetModeFromRole = emView
    
    Select Case as_Role
    Case "A"
        GetModeFromRole = emAdd
    Case "B"
        GetModeFromRole = emUpdate
    Case "C"
        GetModeFromRole = emDelete
    End Select
    Exit Function
ErrHandler:
    Call ErrorHandler("GetModeFromRole")
End Function

Private Function LoadTreeView(ByVal al_MainIndex As Long, ByRef aTV As ArmTreeView, ByRef aTreeViewInfo As TTreeViewInfo) As Boolean
On Error GoTo ErrorHandler
    
    Call aTV.Clear
    
    If aTreeViewInfo.Levels > 0 Then
      aTV.Levels = aTreeViewInfo.Levels
      aTV.StartDemandLevel = 1
      aTV.SelectedImages = aTreeViewInfo.SelectedImages
      aTV.Images = aTreeViewInfo.Images
      aTV.NodeRequests = ApplyTVFilters(al_MainIndex, aTreeViewInfo.NodeRequest)
      aTV.GridRequests = aTreeViewInfo.GridRequest
      
      If Not aTV.LoadTree(LoadTypeChildsDemand) Then
          Call Err.Raise(ArmErr.CompFncFailed, "aTV.LoadTree", "")
      End If
    End If
    Exit Function
ErrorHandler:
    Call ErrorHandler("LoadTreeView")
End Function

Private Function GetTreeViewInfoFromDB(ByVal AScreenName As String, ByVal aTVCode As String) As TTreeViewInfo
On Error GoTo ErrHandler

    Dim lTreeView As TTreeViewInfo
    Dim lRequest As String
    Dim lCurs As Long, lIdx As Long, lCount As Long
    
    ' Get the data from the DB
    lRequest = "EXEC Treeview_Parameters_lst '" & AScreenName & "', '" & aTVCode & "'"
    lCurs = OpenSQLSafe(mo_Db, lRequest)
    
    lCount = mo_Db.RowCount(lCurs) - 1
    
    If lCount < 0 Then
        Call Err.Raise(ArmErr.InvalidValue, lRequest, "AScreenName=" & AScreenName & " lCount=" & lCount)
    End If
    
    ReDim lTreeView.NodeRequest(lCount)
    ReDim lTreeView.GridRequest(lCount)
    ReDim lTreeView.ExcelRequest(lCount)
    ReDim lTreeView.FindRequest(lCount)
    ReDim lTreeView.CountRequest(lCount)
    ReDim lTreeView.Images(lCount)
    ReDim lTreeView.SelectedImages(lCount)
    
    Dim lLevel As Long
    For lIdx = 0 To lCount
        lLevel = mo_Db.GetFields(lCurs, "TV_Level")
        lTreeView.NodeRequest(lLevel) = ReplaceCommonPlaceholders(mo_Db.GetFields(lCurs, "TV_NodeRequest"))
        lTreeView.GridRequest(lLevel) = mo_Db.GetFields(lCurs, "TV_GridRequest")
        lTreeView.Images(lLevel) = mo_Db.GetFields(lCurs, "TV_Images")
        lTreeView.SelectedImages(lLevel) = mo_Db.GetFields(lCurs, "TV_SelectedImages")
        mo_Db.Next (lCurs)
    Next
    
    lTreeView.TreeViewCode = aTVCode
    lTreeView.Levels = lCount + 1
    lTreeView.Loaded = True
    GetTreeViewInfoFromDB = lTreeView
    
    Call mo_Db.Close(lCurs)
    Exit Function
ErrHandler:
    Call mo_Db.Close(lCurs)
    Call ErrorHandler("GetTreeViewInfoFromDB")
End Function

' ************************************************************************************
' FRAMEWORK DB-ACCESS FUNCTIONS
' please do not change this code
' ************************************************************************************

' Return the result of a SQL request
' Convert SQL runtime errors and process errors to VB Error
#If ENV = LIVE Then
Private Function OpenSQLSafe(ByVal ao_DB As Object, ByVal as_Request As String, Optional ByVal al_RowExpectedCount = -1) As Long
#Else
Private Function OpenSQLSafe(ByVal ao_DB As ARMSYSCOMLib.ArmDb, ByVal as_Request As String, Optional ByVal al_RowExpectedCount = -1) As Long
#End If

On Error GoTo ErrHandler

    Dim lc_Data As Long
    lc_Data = ao_DB.OpenSQL(as_Request)
    
    If lc_Data = 0 Then
        Err.Raise ArmErr.SQLFailure, "SQL : " & as_Request, Join(ao_DB.SQLErrorCodes, SEP2) & SEP1 & Join(ao_DB.SQLErrorMessages, SEP2)
    End If
    
    If al_RowExpectedCount <> -1 Then
        ' Then check the rowcount
        If ao_DB.RowCount(lc_Data) <> al_RowExpectedCount Then
            Err.Raise ArmErr.SQLBadRowExpectedCount, "SQL : " & as_Request, al_RowExpectedCount & "<>" & ao_DB.RowCount(lc_Data)
        End If
    End If

    OpenSQLSafe = lc_Data

    Exit Function

ErrHandler:

    Call ErrorHandler("OpenSQLSafe")

End Function


' Execute a SQL request returning no data
' Convert SQL runtime errors and process errors to VB Error
' Params:
' ao_Db (Object)
' as_Request (String)
' al_RowAffectedCount (String)
#If ENV = LIVE Then
Private Sub ExecuteSQLSafe(ByVal ao_DB As Object, ByVal as_Request As String, Optional ByVal al_RowAffectedCount = -1, Optional ab_DuplicityCheck As Boolean = False)
#Else
Private Sub ExecuteSQLSafe(ByVal ao_DB As ARMSYSCOMLib.ArmDb, ByVal as_Request As String, Optional ByVal al_RowAffectedCount = -1, Optional ab_DuplicityCheck As Boolean = False)
#End If
On Error GoTo ErrHandler

    ' First execute the request
    If Not ao_DB.ExecuteSQL(as_Request) Then
        Err.Raise ArmErr.SQLFailure, "SQL : " & as_Request, Join(ao_DB.SQLErrorCodes, SEP2) & SEP1 & Join(ao_DB.SQLErrorMessages, SEP2)
    End If

    If al_RowAffectedCount <> -1 Then
        ' Then check the rowcount
        If ao_DB.SQLRowsAffected <> al_RowAffectedCount Then
            
            If ab_DuplicityCheck Then
                Err.Raise ArmCusErr.DuplicityDetected, "SQL : " & as_Request, al_RowAffectedCount & "<>" & ao_DB.SQLRowsAffected
            Else
                Err.Raise ArmErr.SQLBadRowAffectedCount, "SQL : " & as_Request, al_RowAffectedCount & "<>" & ao_DB.SQLRowsAffected
            End If
        End If
    End If

    Exit Sub

ErrHandler:
    Call ErrorHandler("ExecuteSQLSafe")
End Sub

Private Function GetDbError(ByVal lo_Db As ARMSYSCOMLib.ArmDb) As String
On Error GoTo ErrHandler
    
    If IsArray(lo_Db.SQLErrorMessages) Then
        Debug.Assert (IsArray(mo_Db.SQLErrorCodes))
        ' Display errors msgBox
        GetDbError = Join(lo_Db.SQLErrorCodes, ",") & vbCrLf & Join(lo_Db.SQLErrorMessages, vbCrLf)
    Else
        ' ExecuteSQL failed but no error message?
        GetDbError = "Unknown error"
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("GetDbError()")
End Function
' Standard error handler
Private Sub ErrorHandler(ByVal as_Fct As String)
  
    Call Err.Raise(Err.Number, as_Fct & SEP1 & Err.Source, Err.Description)
End Sub

' display standard error message
Private Sub ErrorMessage(ByVal as_Fct As String)
    Dim ls_ErrSource As String
    Dim ls_errDescription As String
    ls_ErrSource = as_Fct & SEP1 & Err.Source
    ls_errDescription = Err.Description
    
    Call LogMessage(SCREEN_NAME & " exception raised. Err.Number:" & Err.Number & ", Err.Source:" & ls_ErrSource & ", Err.Description " & ls_errDescription & ".", "E", False)
    Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & ls_ErrSource & vbCrLf & "Description: " & ls_errDescription, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
    End
End Sub

' logs message to database
Private Sub LogMessage(ByVal as_logMsg As String, Optional ByVal as_logType As String = "E", Optional ab_ExitOnException As Boolean = False)
    Dim ll_errNumber As Long
    Dim ls_errDescription As String, ls_ErrSource As String
    
    ll_errNumber = Err.Number
    ls_errDescription = Err.Description
    ls_ErrSource = Err.Source

On Error GoTo ErrHandler

Const LOG_REQUEST As String = "EXEC A_log_ins $UCODE$,$LOGTYPE$,$MSG$,$APP$"
    Dim ls_req As String
    Dim ll_cursor As Long
    Dim ls_Source As String, ls_Msg As String
    
    ls_Source = SCREEN_NAME & " " & App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    ls_Msg = as_logMsg & SEP1 & ll_errNumber & " : " & ls_errDescription & " - " & ls_ErrSource
    
    ls_req = ReplacePlaceHolder(LOG_REQUEST, "$UCODE$", CStr(ml_U_Code))
    ls_req = ReplacePlaceHolder(ls_req, "$LOGTYPE$", SQLStr(as_logType))
    ls_req = ReplacePlaceHolder(ls_req, "$MSG$", Left(Trim(SQLStr(ls_Msg)), 4000))
    ls_req = ReplacePlaceHolder(ls_req, "$APP$", Left(Trim(SQLStr(ls_Source)), 50))
    
    Call ExecuteSQLSafe(mo_Db, ls_req)
    
    Err.Number = ll_errNumber
    Err.Description = ls_errDescription
    Err.Source = ls_ErrSource
    Exit Sub
    
ErrHandler:
    If ab_ExitOnException Then
        Call MsgBox("A fatal error occured. Unable to log error into database, the application will be close. Please report the following message to your IT support: " & vbCrLf & _
            "Number:" & Err.Number & vbCrLf & "Description:" & Err.Description, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        End
    End If
    Err.Number = ll_errNumber
    Err.Description = ls_errDescription
    Err.Source = ls_ErrSource
End Sub

Private Function GetNextID(ByVal as_Key As String) As String
On Error GoTo ErrHandler
Dim ls_Data As String

    ls_Data = mo_Db.SQLNextID(as_Key)
    If ls_Data = "" Then
        Err.Raise ArmErr.CompFncFailed, "mo_Db.SQLNextID", "SQLNextID failed for key: " & as_Key
    End If
    GetNextID = ls_Data
    Exit Function
ErrHandler:
    Call ErrorHandler("GetNextID()")
End Function

' procedure save/restore err object
Private Sub UpdateError(Optional ab_saveError As Boolean = False)
Static ls_ErrDesc As String
Static ls_ErrSource As String
Static ll_errnum As Long
    
    If ab_saveError Then
        ls_ErrDesc = Err.Description
        ls_ErrSource = Err.Source
        ll_errnum = Err.Number
    Else
        Err.Description = ls_ErrDesc
        Err.Source = ls_ErrSource
        Err.Number = ll_errnum
    End If
End Sub

Private Sub LockScreen(ByVal ab_lock As Boolean)

    Dim ll_errNumber As Long, ls_ErrSrc As String, ls_ErrDesc As String
    ll_errNumber = Err.Number
    ls_ErrSrc = Err.Source
    ls_ErrDesc = Err.Description

On Error GoTo ErrHandler
    Static ll_Count As Long
    Static ll_Mousepointer As Long
    Static lb_Locked As Boolean
      
      
    ll_Count = ll_Count + IIf(ab_lock, 1, -1)
    Debug.Assert (ll_Count >= 0)
    
    ' First lock
    If Not lb_Locked And ab_lock Then
        ll_Mousepointer = Screen.MousePointer
        Screen.MousePointer = vbHourglass
        UserControl.Enabled = False
        LockWindowUpdate UserControl.hwnd
        lb_Locked = True
    End If
    
    ' Unlock
    If ll_Count = 0 Then
        DoEvents ' Flush events
        LockWindowUpdate 0
        UserControl.Enabled = True
        UserControl.Refresh ' Repaint immediately
        Screen.MousePointer = ll_Mousepointer
        lb_Locked = False
    End If
    
    Err.Number = ll_errNumber
    Err.Source = ls_ErrSrc
    Err.Description = ls_ErrDesc
    Exit Sub
ErrHandler:
    Call ErrorHandler("LockScreen")
End Sub

Private Function BeginTran(as_Tran As String) As Boolean

On Error GoTo ErrHandler
    BeginTran = False
    ExecuteSQLSafe mo_Db, "BEGIN TRANSACTION " & as_Tran

    BeginTran = True
    Exit Function
    
ErrHandler:
    'try to log error
    Call LogMessage("BeginTran: " & as_Tran)
    Call mo_Db.Disconnect
    Set mo_Db = Nothing
    MsgBox "A Fatal error occured in " & SCREEN_NAME & ".BeginTran, your application will be close. Please contact your IT support", vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    End
End Function

Private Function CommitTran(as_Tran As String) As Boolean

On Error GoTo ErrHandler
    CommitTran = False
    ExecuteSQLSafe mo_Db, "COMMIT TRANSACTION " & as_Tran

    CommitTran = True
    Exit Function
    
ErrHandler:
    'try to log error
    Call LogMessage("CommitTran: " & as_Tran)
    Call mo_Db.Disconnect
    Set mo_Db = Nothing
    MsgBox "A Fatal error occured in " & SCREEN_NAME & ".CommitTran, your application will be close. Please contact your IT support", vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    End

End Function

Private Function RollbackTran(as_Tran As String) As Boolean
    
    Dim ll_errNumber As Long, ls_ErrSource As String, ls_ErrDesc As String
    ll_errNumber = Err.Number
    ls_ErrSource = Err.Source
    ls_ErrDesc = Err.Description

On Error GoTo ErrHandler
    RollbackTran = False
    
    ExecuteSQLSafe mo_Db, "ROLLBACK TRANSACTION " & as_Tran


    Err.Number = ll_errNumber
    Err.Source = ls_ErrSource
    Err.Description = ls_ErrDesc

    RollbackTran = True
    Exit Function
    
ErrHandler:
    'try to log error
    Call LogMessage("RollbackTran: " & as_Tran)
    Call mo_Db.Disconnect
    Set mo_Db = Nothing
    MsgBox "A Fatal error occured in " & SCREEN_NAME & ".RollbackTran, your application will be close. Please contact your IT support", vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision
    End
End Function

' ************************************************************************************
' *************************** INTERNATIONAL FUNCTIONS ********************************
' ************************************************************************************

Private Function GetCodePageFromLanguage(ByRef ao_Armdb As Object, ByVal as_Language As String) As Long
On Error GoTo ErrHandler
Const C_REQ As String = "SELECT Code_Page FROM Language WHERE Language_Code = '$Language_Code$'"
    Dim ls_req As String
    Dim ll_cursor As Long
    Dim ll_codePage As Long
    
    ls_req = ReplacePlaceHolder(C_REQ, "$Language_Code$", as_Language)

    ll_cursor = OpenSQLSafe(ao_Armdb, ls_req)
    Debug.Assert (ll_cursor <> 0)
    
    ll_codePage = CLng(ao_Armdb.GetFields(ll_cursor, "Code_Page"))
    Call ao_Armdb.Close(ll_cursor)
    GetCodePageFromLanguage = ll_codePage
    Exit Function
    
ErrHandler:
    If ll_cursor <> 0 Then Call ao_Armdb.Close(ll_cursor)
    Call ErrorHandler("GetCodePageFromLanguage()")
End Function

'convert code page into charset integer
Private Function GetCharSetFromCodePage(ByVal al_CodePage As Long) As Long

On Error GoTo ErrHandler

    Select Case CStr(al_CodePage)
        Case 932 ' Japanese
            GetCharSetFromCodePage = 128
        Case 936 ' Simplified Chinese
            GetCharSetFromCodePage = 134
        Case 949 ' Korean
            GetCharSetFromCodePage = 129
        Case 950 ' Traditional Chinese
            GetCharSetFromCodePage = 136
        Case 1250 ' Eastern Europe
            GetCharSetFromCodePage = 238
        Case 1251 ' Russian
            GetCharSetFromCodePage = 204
        Case 1252 ' Western European Languages
            GetCharSetFromCodePage = 0
        Case 1253 ' Greek
            GetCharSetFromCodePage = 161
        Case 1254 ' Turkish
            GetCharSetFromCodePage = 162
        Case 1255 ' Hebrew
            GetCharSetFromCodePage = 177
        Case 1256 ' Arabic
            GetCharSetFromCodePage = 178
        Case 1257 ' Baltic
            GetCharSetFromCodePage = 186
        Case Else
            GetCharSetFromCodePage = 0
    End Select
    
    Exit Function
    
ErrHandler:
    Call ErrorHandler("GetCharSetFromCodePage()")
End Function

Private Sub ChangeCharset(ByRef ao_Container As Object, Optional ByVal aCodePage As Long)

On Error GoTo ErrHandler
   
    Dim lc_Control As Control
    Dim ll_Charset As Long
    
    On Error Resume Next
    ll_Charset = GetCharSetFromCodePage(aCodePage)
    
    For Each lc_Control In ao_Container
        Select Case UCase(TypeName(lc_Control))
        Case "TABSTRIP", "TEXTBOX", "LABEL", "FRAME", "COMMANDBUTTON", _
              "LISTVIEW", "CHECKBOX", "OPTIONBUTTON", _
              "ARMCHECKVIEW", "ARMTREEVIEW", "ARMGRID", "ARMCOMBOBOX", "ARMCHECKVIEW0", "ARMPICKER"
            lc_Control.Font.Name = "Arial"
            lc_Control.Font.Charset = ll_Charset
        Case "A_SEEK", "A_SRCHTXT"
            lc_Control.Charset = ll_Charset
        End Select
    Next
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("ChangeCharset")
End Sub

' Load the labels of a containers
Private Sub LoadLabels(ByRef ao_Armdb As ArmDb, ByRef ao_Container As Object, ByVal as_ScreenName As String, ByVal as_Language As String)
Dim lo_Control As Control   ' A control of the container
Dim li_Idx As Integer, li_Count As Integer
Dim li_Label As Integer      ' A label idx
Dim ls_Request As String
Dim lc_Labels As Long
Dim lsa_ControlTag() As String
    
    On Error GoTo Trace_Err

    If mc_ScreenLabels = 0 Then
        ls_Request = "exec screen_csts '" & as_ScreenName & "','" & as_Language & "'"
        mc_ScreenLabels = OpenSQLSafe(ao_Armdb, ls_Request)
    End If
    lc_Labels = mc_ScreenLabels
    
    If lc_Labels = 0 Then
        Exit Sub
    End If
    
    On Error GoTo WithoutTag
    If ao_Container.Tag <> "" Then
        li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", ao_Container.Tag, , 1)
        If li_Label >= 0 Then
            ao_Container.Caption = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
        End If
    End If
WithoutTag:
    
    On Error GoTo Trace_Err
    
    ' Iterate the container for loading the label of each element which has defined a tag
    For Each lo_Control In UserControl.Controls
        
        If HasContainer(lo_Control, ao_Container) Or _
          ((ao_Container Is Me) And (UCase(TypeName(lo_Control)) = "MENU")) Then
            Select Case UCase(TypeName(lo_Control))
                Case UCase("TabStrip") ' Component is a tabstrip, we load the caption of each tab defined
                    Dim lo_Tbs
                    Set lo_Tbs = lo_Control ' Cast for use of intellisense
                    li_Count = lo_Tbs.Tabs.Count
                    For li_Idx = 1 To li_Count
                        If lo_Tbs.Tabs(li_Idx).Tag <> "" Then
                            li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lo_Tbs.Tabs(li_Idx).Tag, , 1)
                            If li_Label >= 0 Then
                                lo_Tbs.Tabs(li_Idx).Caption = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
                            End If
                        End If
                    Next
                    Set lo_Tbs = Nothing
                
                Case UCase("ListView") ' Component is a listview, we load the caption of each columns
                    Dim lo_ListView As ListView
                    Set lo_ListView = lo_Control
                    li_Count = lo_ListView.ColumnHeaders.Count
                    For li_Idx = 1 To li_Count
                        If lo_ListView.ColumnHeaders(li_Idx).Tag <> "" Then
                            li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lo_ListView.ColumnHeaders(li_Idx).Tag, , 1)
                            If li_Label >= 0 Then
                                lo_ListView.ColumnHeaders(li_Idx).Text = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
                            End If
                        End If
                    Next
                    Set lo_ListView = Nothing
            
                Case UCase("TextBox")  ' Component is a textbox
                    Dim lo_TextBox As TextBox
                    Set lo_TextBox = lo_Control
                    If lo_TextBox.Tag <> "" Then
                        lsa_ControlTag = Split(lo_Control.Tag, SEP)
                        li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lsa_ControlTag(0), , 1)
                        If li_Label >= 0 Then
                            lo_TextBox.Text = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
                        End If
                    End If
                    Set lo_TextBox = Nothing
                
                Case UCase("Label"), UCase("Frame"), UCase("CommandButton"), UCase("CheckBox"), UCase("OptionButton")
                    If lo_Control.Tag <> "" Then
                        lsa_ControlTag = Split(lo_Control.Tag, SEP)
                        li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lsa_ControlTag(0), , 1)
                        If li_Label >= 0 Then
                            lo_Control.Caption = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
                        End If
                    End If
                Case UCase("ArmGrid")
                    li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lo_Control.Tag, , 1)
                    If li_Label >= 0 Then
                      Call lo_Control.LoadConstants(ptStatic, ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT"), ctColumns)
                    End If
                    li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lo_Control.Tag & "_Title", , 1)
                    If li_Label >= 0 Then
                      lo_Control.Title = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
                    End If
                Case UCase("Menu")
                    If lo_Control.Tag <> "" Then
                        li_Label = ao_Armdb.Find(lc_Labels, "FIELD_NAME", lo_Control.Tag, , 1)
                        If li_Label >= 0 Then
                            lo_Control.Caption = ao_Armdb.GetFields(lc_Labels, "LOCAL_TEXT")
                        End If
                    End If
            End Select
        End If
    Next
        
Trace_End:
    Exit Sub
    
Trace_Err:
      
End Sub

Function MsgText(ByVal aID As Long, ByVal aLang As String, ByVal aDefault As String, Optional ByVal aInfo As Variant) As String
On Error GoTo ErrHandler

Const DB_REQ As String = "SELECT message_text FROM error_message WHERE msgid = $id$ AND Language_code = '$lang$'"

    MsgText = ""
    
    Dim lRequest As String
    lRequest = ReplacePlaceHolder(DB_REQ, "$id$", aID)
    lRequest = ReplacePlaceHolder(lRequest, "$lang$", aLang)
    Dim lData As Long
    
    lData = OpenSQLSafe(mo_Db, lRequest)
    
    Dim lBuffer As String
    lBuffer = mo_Db.GetFields(lData, "message_text")
    mo_Db.Close (lData)
    If lBuffer = "" Then lBuffer = aDefault
    
    Dim li_Idx As Integer
    If Not IsMissing(aInfo) Then
        For li_Idx = 0 To UBound(aInfo)
            lBuffer = Replace(lBuffer, aInfo(li_Idx, 0), aInfo(li_Idx, 1), , , vbTextCompare)
        Next li_Idx
    End If
    
    
    MsgText = lBuffer
    Exit Function
ErrHandler:
    mo_Db.Close (lData)
    Call MsgBox("Connection failure accessing message information.", vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
    MsgText = aDefault
End Function

Private Function LoadIconFromA_Icons(ai_IconIndex As Integer) As Picture
Dim hIcon As Long
Dim hInst As Long
Dim oNewPic As Picture
Dim tPicConv As PictDesc
Dim IGuid As Guid

On Error GoTo ErrHandler
  
    hInst = LoadLibrary("c:\arm_apps\dll\A_icons.dll")
    If hInst = 0 Then
      Set LoadIconFromA_Icons = Nothing
      Exit Function
    End If
    
    hIcon = LoadIconFromDLL(hInst, ai_IconIndex)
    If hIcon = 0 Then
      Set LoadIconFromA_Icons = Nothing
      Exit Function
    End If
      
    With tPicConv
      .cbSizeofStruct = Len(tPicConv)
      .picType = vbPicTypeIcon
      .hImage = hIcon
    End With
     
    ' Fill in magic IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
    With IGuid
          .Data1 = &H7BF80980
          .Data2 = &HBF32
          .Data3 = &H101A
          .Data4(0) = &H8B
          .Data4(1) = &HBB
          .Data4(2) = &H0
          .Data4(3) = &HAA
          .Data4(4) = &H0
          .Data4(5) = &H30
          .Data4(6) = &HC
          .Data4(7) = &HAB
    End With
    OleCreatePictureIndirect tPicConv, IGuid, True, oNewPic
      
    Set LoadIconFromA_Icons = oNewPic
    Call FreeLibrary(hInst)
    Exit Function
ErrHandler:
    Call FreeLibrary(hInst)
    Call ErrorHandler("LoadIconFromFile")
End Function

Private Function GetTempDir() As String
On Error GoTo ErrHandler

Dim ls_Buff As String, ll_Count As Long

    ls_Buff = Space(4096)
    ll_Count = GetTempPath(4096, ls_Buff)
    
    ls_Buff = Left(ls_Buff, ll_Count)
    'this function can return path with trailing "\" character - strip it
    If ll_Count > 0 Then
      If right(ls_Buff, 1) = "\" Then
       ls_Buff = Left(ls_Buff, ll_Count - 1)
      End If
    End If
    GetTempDir = ls_Buff & "\$" & SCREEN_NAME & "$"
  Exit Function
ErrHandler:
  Call ErrorHandler("GetTempDir")
End Function

Private Function DeleteFile(ByVal as_FileName As String) As Boolean
On Error GoTo ErrHandler

  ' delete all subfolders and files in one go
  Call mo_FSO.DeleteFile(as_FileName, True)
  DeleteFile = True
  Exit Function
ErrHandler:
    DeleteFile = False
End Function

Private Sub DeleteTemporaryFiles()
On Error GoTo ErrHandler

  ' delete all subfolders and files in one go
  Call mo_FSO.DeleteFolder(GetTempDir, True)
  Exit Sub
ErrHandler:
  'do nothing this is not critical error, because some of the temp files can be still open
  'by user, it will be delete next time app start
End Sub

Private Function GetMACAddress() As String
On Error GoTo ErrHandler

    Dim ls_Query As String
    Dim lo_WMIService As Object
    Dim lo_Items As Object
    Dim lo_item As Object
' We're interested in MAC addresses of physical adapters only
    ls_Query = "SELECT * " & _
                "FROM Win32_NetworkAdapter " & _
                "WHERE ConfigManagerErrorCode=0 AND " & _
                "NetConnectionID > '' AND " & _
                "(NetConnectionStatus=2 OR NetConnectionStatus=9)"

    Set lo_WMIService = GetObject("winmgmts://./root/CIMV2")
    Set lo_Items = lo_WMIService.ExecQuery(ls_Query, "WQL", 48)

    For Each lo_item In lo_Items
        If lo_item.MACAddress <> "" Then
            GetMACAddress = Replace(lo_item.MACAddress, ":", "", , , vbTextCompare)
            Exit Function
        End If
    Next
    GetMACAddress = ""
    Exit Function
ErrHandler:
    Call ErrorHandler("GetMACAddress")
End Function

Private Function HasRightInA_Config(ByVal as_CFG_Key As String)
On Error GoTo ErrHandler

Dim ls_CFG_Value As String
Dim lsa_login() As String
Dim ll_Idx As Long

    HasRightInA_Config = False
    ls_CFG_Value = CStr(SelectValue("SELECT CFG_Value FROM A_Config WHERE CFG_Key=" & SQLStr(as_CFG_Key)))
    If ls_CFG_Value <> "" Then
        lsa_login = Split(ls_CFG_Value, SEP)
        For ll_Idx = 0 To UBound(lsa_login)
            If StrComp(ms_LoginName, lsa_login(ll_Idx), vbTextCompare) = 0 Then
                HasRightInA_Config = True
                Exit Function
            End If
        Next
    End If
  Exit Function
ErrHandler:
  Call ErrorHandler("HasRightInA_Config as_CFG_Key=" & as_CFG_Key)
End Function

Private Function GetAConfigDataByCountry(ByRef ao_DB As ArmDb, ByVal as_Key As String) As String
On Error GoTo ErrHandler

    GetAConfigDataByCountry = ""
    
    Const C_REQ As String = "SELECT A.CFG_Value" & vbCrLf & _
                            "FROM security_identity SI" & vbCrLf & _
                            " INNER JOIN A_Config A ON CFG_Key='$KEY$'+'_' + SI.CT_code" & vbCrLf & _
                            "WHERE SI.login_Name = '$LOGIN$'"
    Dim ll_cursor As Long
    Dim ls_req As String
    
    ls_req = Replace(C_REQ, "$KEY$", as_Key, , , vbTextCompare)
    ls_req = Replace(ls_req, "$LOGIN$", ms_LoginName, , , vbTextCompare)
    
    ll_cursor = OpenSQLSafe(ao_DB, ls_req)
    
    If ao_DB.RowCount(ll_cursor) = 1 Then
        GetAConfigDataByCountry = ao_DB.GetFields(ll_cursor, "CFG_Value")
    End If
    Call ao_DB.Close(ll_cursor)
    
    Exit Function
ErrHandler:
    Call ao_DB.Close(ll_cursor)
    Call ErrorHandler("GetAConfigDataByCountry")
End Function

Private Function GetAConfigData(ByRef ao_DB As ArmDb, ByVal as_Key As String) As String
On Error GoTo ErrHandler
    
    Const C_REQ As String = "SELECT CFG_Value FROM A_Config WHERE CFG_Key='$KEY$'"
    Dim ll_cursor As Long
    
    ll_cursor = OpenSQLSafe(ao_DB, Replace(C_REQ, "$KEY$", as_Key, , , vbTextCompare))
    
    If ao_DB.RowCount(ll_cursor) = 1 Then
        GetAConfigData = ao_DB.GetFields(ll_cursor, "CFG_Value")
    Else
        Call ao_DB.Close(ll_cursor)
        Err.Raise ArmErr.CompFncFailed, "OpenSQLSafe", "A_Config value missing : " & as_Key
    End If
    Call ao_DB.Close(ll_cursor)
    
    Exit Function
ErrHandler:
    Call ao_DB.Close(ll_cursor)
    Call ErrorHandler("GetAConfigData")
End Function

Private Function MapNetworkDrive(ByRef ao_WshNetwork As Object, ByVal as_drive As String, ByVal as_remotePath As String, ByVal as_User As String, ByVal as_pass As String) As Boolean
On Error GoTo ErrorHandler
    If Trim(as_User) = "" Then
        Call mo_WshNetwork.MapNetworkDrive(as_drive, as_remotePath, False)
    Else
        Call mo_WshNetwork.MapNetworkDrive(as_drive, as_remotePath, False, as_User, as_pass)
    End If
    MapNetworkDrive = True
    Exit Function
ErrorHandler:
    ' mapping failed
    ReDim ms_MsgInfo(2, 1)
    ms_MsgInfo(0, 0) = "$DRIVE$"
    ms_MsgInfo(0, 1) = as_drive
    ms_MsgInfo(1, 0) = "$PATH$"
    ms_MsgInfo(1, 1) = as_remotePath
    ms_MsgInfo(2, 0) = "$ERROR$"
    ms_MsgInfo(2, 1) = Err.Number & " - " & Err.Description
    Call MsgBox(MsgText(666, ms_Language_Code, "Application cannot map drive $DRIVE$ to $PATH$." & vbCrLf & "$ERROR$" & vbCrLf & "Try it manually or call application support please.", ms_MsgInfo))
End Function

Private Function NetworkDriveExists(ByRef ao_WshNetwork As Object, ByVal as_drive As String) As Boolean
On Error GoTo ErrorHandler

    Dim lo_Drives As Object
    Dim ll_Index As Long
    NetworkDriveExists = False
    
    Set lo_Drives = ao_WshNetwork.EnumNetworkDrives
    For ll_Index = 0 To lo_Drives.Count - 1 Step 2
        If lo_Drives.Item(ll_Index) = as_drive Then
            ' drive exists
            NetworkDriveExists = True
            Exit Function
        End If
    Next

    Exit Function
ErrorHandler:
    Call ErrorHandler("NetworkDriveExists")
End Function


