VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.UserControl DPC_Ref_Prices 
   ClientHeight    =   9600
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   16005
   ScaleHeight     =   9600
   ScaleWidth      =   16005
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_Cost Main"
      Height          =   7095
      Index           =   6
      Left            =   2760
      TabIndex        =   304
      Top             =   1440
      Width           =   10815
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   6
         Left            =   240
         TabIndex        =   320
         Top             =   6720
         Width           =   1095
      End
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   5655
         Index           =   6
         Left            =   0
         TabIndex        =   305
         Top             =   360
         Width           =   2775
         Begin VB.TextBox txt_PRD_Name_Filter 
            Height          =   375
            Index           =   4
            Left            =   120
            TabIndex        =   307
            Tag             =   "PRD_Name"
            Top             =   2040
            Width           =   2535
         End
         Begin VB.TextBox txt_PRD_Code_Filter 
            Height          =   405
            Index           =   4
            Left            =   120
            TabIndex        =   306
            Tag             =   "PRD_Code"
            Top             =   1320
            Width           =   2535
         End
         Begin Project1.ArmCombobox cbo_CURR_Code_Filter 
            Height          =   345
            Index           =   3
            Left            =   120
            TabIndex        =   308
            Tag             =   "CURR_Code®©CURR_Code"
            Top             =   3480
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_Vendor_Filter 
            Height          =   345
            Left            =   120
            TabIndex        =   309
            Tag             =   "VEN_Id®©VEN_Name"
            Top             =   2760
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.A_calocx cal_ToDate 
            Height          =   375
            Index           =   1
            Left            =   840
            TabIndex        =   310
            Tag             =   "ToDate"
            Top             =   4560
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   661
         End
         Begin Project1.A_calocx cal_FromDate 
            Height          =   375
            Index           =   1
            Left            =   840
            TabIndex        =   311
            Tag             =   "FromDate"
            Top             =   4080
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   661
         End
         Begin Project1.ArmCombobox cbo_Category_Filter 
            Height          =   345
            Index           =   3
            Left            =   120
            TabIndex        =   312
            Tag             =   "CAT_Id®©CAT_Name"
            Top             =   600
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Name"
            Height          =   255
            Index           =   61
            Left            =   120
            TabIndex        =   319
            Tag             =   "lbl_PRC_PRD_Name_Fl"
            Top             =   1800
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Code"
            Height          =   255
            Index           =   60
            Left            =   120
            TabIndex        =   318
            Tag             =   "lbl_PRC_PRD_Code_Fl"
            Top             =   1080
            Width           =   975
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CURR Code Filter"
            Height          =   255
            Index           =   59
            Left            =   120
            TabIndex        =   317
            Tag             =   "lbl_PRC_CURR_Code_Fl"
            Top             =   3240
            Width           =   1815
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Vendor Filter"
            Height          =   255
            Index           =   58
            Left            =   120
            TabIndex        =   316
            Tag             =   "lbl_CST_VEN_FIL"
            Top             =   2520
            Width           =   1335
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#To"
            Height          =   255
            Index           =   57
            Left            =   120
            TabIndex        =   315
            Tag             =   "lbl_PRC_VEndDate_Fl"
            Top             =   4680
            Width           =   615
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#From"
            Height          =   255
            Index           =   56
            Left            =   120
            TabIndex        =   314
            Tag             =   "lbl_PRC_VStartDate_Fl"
            Top             =   4200
            Width           =   615
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Category"
            Height          =   255
            Index           =   55
            Left            =   120
            TabIndex        =   313
            Tag             =   "lbl_PRC_Category_Fl"
            Top             =   360
            Width           =   1215
         End
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   6
         Left            =   120
         TabIndex        =   321
         Top             =   6120
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   6
         Left            =   120
         TabIndex        =   322
         Top             =   6600
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   6
         Left            =   3120
         TabIndex        =   323
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1455
         Index           =   6
         Left            =   3120
         TabIndex        =   324
         Tag             =   "grd_M_Prc"
         Top             =   1320
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   2566
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_Cost"
      Height          =   375
      Index           =   8
      Left            =   14280
      TabIndex        =   267
      Top             =   4320
      Width           =   1455
      Begin VB.TextBox txt_Cost_CAT_Name 
         Height          =   375
         Left            =   1800
         TabIndex        =   296
         Tag             =   "CAT_Name"
         Top             =   1200
         Width           =   3855
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   8
         Left            =   11160
         TabIndex        =   295
         TabStop         =   0   'False
         Tag             =   "PCR_Id"
         Top             =   1200
         Visible         =   0   'False
         Width           =   1335
      End
      Begin VB.Frame fra_SubDetail 
         Caption         =   "Frame1"
         Height          =   3855
         Index           =   2
         Left            =   0
         TabIndex        =   271
         Top             =   3840
         Width           =   11895
         Begin VB.Frame fra_SubDetailItem 
            Height          =   1935
            Index           =   2
            Left            =   120
            TabIndex        =   274
            Top             =   120
            Width           =   10815
            Begin VB.TextBox txt_Cost_Cost 
               Height          =   405
               Left            =   8760
               TabIndex        =   288
               Tag             =   "PRC_Cost"
               Top             =   1200
               Width           =   1095
            End
            Begin VB.TextBox txt_Cost_QtyMin 
               Height          =   375
               Left            =   5400
               TabIndex        =   282
               Tag             =   "PRC_QMin"
               Top             =   720
               Width           =   1095
            End
            Begin VB.TextBox txt_Cost_QtyMax 
               Height          =   375
               Left            =   5400
               TabIndex        =   284
               Tag             =   "PRC_QMax"
               Top             =   1200
               Width           =   1095
            End
            Begin Project1.A_calocx cal_Cost_VStart 
               Height          =   375
               Left            =   5400
               TabIndex        =   278
               Tag             =   "PRC_VStart"
               Top             =   240
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   661
            End
            Begin Project1.A_calocx cal_Cost_VEnd 
               Height          =   375
               Left            =   8760
               TabIndex        =   280
               Tag             =   "PRC_VExp"
               Top             =   240
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   661
            End
            Begin Project1.ArmCombobox cbo_Vendor 
               Height          =   345
               Left            =   1320
               TabIndex        =   275
               Tag             =   "VEN_Id®©VEN_Name"
               Top             =   240
               Width           =   2535
               _ExtentX        =   4471
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Currency 
               Height          =   345
               Index           =   1
               Left            =   1320
               TabIndex        =   276
               Tag             =   "CURR_Code®©CURR_Desc"
               Top             =   720
               Width           =   2535
               _ExtentX        =   4471
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_UM_Code 
               Height          =   345
               Index           =   2
               Left            =   1320
               TabIndex        =   277
               Tag             =   "UM_CodeQ®©UM_DescQ"
               Top             =   1200
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_UM_Code 
               Height          =   345
               Index           =   3
               Left            =   8760
               TabIndex        =   286
               Tag             =   "UM_CodeC®©UM_DescC"
               Top             =   720
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   609
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Vendor"
               Height          =   255
               Index           =   51
               Left            =   120
               TabIndex        =   292
               Tag             =   "lbl_PRC_Vendor"
               Top             =   360
               Width           =   1215
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#CURR Code"
               Height          =   255
               Index           =   50
               Left            =   120
               TabIndex        =   291
               Tag             =   "lbl_PRC_CURR_Code"
               Top             =   840
               Width           =   1215
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#UM_Code Q"
               Height          =   255
               Index           =   49
               Left            =   120
               TabIndex        =   290
               Tag             =   "lbl_PRC_UM_CodeQ"
               Top             =   1320
               Width           =   1215
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Qty Min"
               Height          =   255
               Index           =   48
               Left            =   3960
               TabIndex        =   289
               Tag             =   "lbl_PRC_QtyMin"
               Top             =   840
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Qty Max"
               Height          =   255
               Index           =   47
               Left            =   3960
               TabIndex        =   287
               Tag             =   "lbl_PRC_QtyMax"
               Top             =   1320
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#ValidityStartDate"
               Height          =   255
               Index           =   46
               Left            =   3960
               TabIndex        =   285
               Tag             =   "lbl_PRC_VStartDate"
               Top             =   360
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#ExpiryDate"
               Height          =   255
               Index           =   45
               Left            =   7320
               TabIndex        =   283
               Tag             =   "lbl_PRC_ExpiryDate"
               Top             =   360
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Cost"
               Height          =   255
               Index           =   44
               Left            =   7320
               TabIndex        =   281
               Tag             =   "lbl_PRC_Cost"
               Top             =   1320
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#UM_Code Cost"
               Height          =   255
               Index           =   43
               Left            =   7320
               TabIndex        =   279
               Tag             =   "lbl_PRC_UM_CodeC"
               Top             =   840
               Width           =   1335
            End
         End
         Begin VB.TextBox txt_SubDetailKey 
            Height          =   285
            Index           =   2
            Left            =   1080
            TabIndex        =   273
            TabStop         =   0   'False
            Tag             =   "PRC_Id"
            Top             =   0
            Visible         =   0   'False
            Width           =   1335
         End
         Begin VB.TextBox txt_COST_SUB_PRD_Id 
            Height          =   285
            Left            =   2520
            TabIndex        =   272
            TabStop         =   0   'False
            Tag             =   "PRD_Id"
            Top             =   0
            Visible         =   0   'False
            Width           =   1215
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   3450
            Index           =   2
            Left            =   11040
            TabIndex        =   293
            Top             =   240
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   4180
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   1575
            Index           =   2
            Left            =   120
            TabIndex        =   294
            Tag             =   "grd_S_Prc"
            Top             =   2160
            Width           =   10815
            _ExtentX        =   19076
            _ExtentY        =   2778
         End
      End
      Begin VB.TextBox txt_Price_PRD_Name 
         Height          =   375
         Index           =   2
         Left            =   1800
         TabIndex        =   270
         Tag             =   "PRD_Name"
         Top             =   1680
         Width           =   3855
      End
      Begin VB.TextBox txt_Cost_SYS_Name 
         Height          =   405
         Left            =   7200
         TabIndex        =   269
         Tag             =   "SYS_Name"
         Top             =   1200
         Width           =   3735
      End
      Begin VB.TextBox txt_Cost_PRD_Id 
         Height          =   375
         Left            =   11160
         TabIndex        =   268
         TabStop         =   0   'False
         Tag             =   "PRD_Id"
         Top             =   2040
         Visible         =   0   'False
         Width           =   1335
      End
      Begin Project1.ArmGrid grd_PriceCrit 
         Height          =   1455
         Index           =   2
         Left            =   1800
         TabIndex        =   297
         Tag             =   "grd_D_Prc"
         Top             =   2160
         Width           =   9135
         _ExtentX        =   16113
         _ExtentY        =   2566
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   8
         Left            =   240
         TabIndex        =   298
         Top             =   360
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   8
         Left            =   11160
         TabIndex        =   302
         TabStop         =   0   'False
         Top             =   1560
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Category"
         Height          =   255
         Index           =   54
         Left            =   240
         TabIndex        =   301
         Tag             =   "lbl_PRC_Category"
         Top             =   1440
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Product"
         Height          =   255
         Index           =   53
         Left            =   240
         TabIndex        =   300
         Tag             =   "lbl_PRC_Product"
         Top             =   1800
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#System"
         Height          =   255
         Index           =   52
         Left            =   6000
         TabIndex        =   299
         Tag             =   "lbl_PRC_System"
         Top             =   1320
         Width           =   975
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_SysMargin"
      Height          =   252
      Index           =   7
      Left            =   14400
      TabIndex        =   242
      Top             =   3840
      Width           =   1332
      Begin VB.TextBox txt_SMA_SubMin 
         Height          =   405
         Left            =   6120
         TabIndex        =   262
         Tag             =   "SMA_SubMin"
         Top             =   2640
         Width           =   1695
      End
      Begin VB.TextBox txt_SMA_SubGTN 
         Height          =   405
         Left            =   6120
         TabIndex        =   260
         Tag             =   "SMA_SubGTN"
         Top             =   2160
         Width           =   1695
      End
      Begin VB.TextBox txt_SMA_PanMin 
         Height          =   405
         Left            =   1560
         TabIndex        =   247
         Tag             =   "SMA_PanMin"
         Top             =   2640
         Width           =   1695
      End
      Begin VB.TextBox txt_SMA_PanGTN 
         Height          =   405
         Left            =   1560
         TabIndex        =   246
         Tag             =   "SMA_PanGTN"
         Top             =   2160
         Width           =   1695
      End
      Begin VB.TextBox txt_SMA_Country 
         Height          =   375
         Left            =   6120
         TabIndex        =   258
         Tag             =   "CT_Desc"
         Top             =   1200
         Width           =   2895
      End
      Begin VB.TextBox txt_SYS_Id 
         Height          =   372
         Left            =   8520
         TabIndex        =   255
         Tag             =   "SYS_Id"
         Top             =   480
         Visible         =   0   'False
         Width           =   492
      End
      Begin VB.TextBox txt_SMA_SubMargin 
         Height          =   405
         Left            =   6120
         TabIndex        =   259
         Tag             =   "SMA_SubMargin"
         Top             =   1680
         Width           =   1695
      End
      Begin VB.TextBox txt_SMA_PanMargin 
         Height          =   405
         Left            =   1560
         TabIndex        =   245
         Tag             =   "SMA_PanMargin"
         Top             =   1680
         Width           =   1695
      End
      Begin VB.TextBox txt_SMA_Sys_Name 
         Height          =   375
         Left            =   1560
         TabIndex        =   244
         Tag             =   "SYS_Name"
         Top             =   1200
         Visible         =   0   'False
         Width           =   2895
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   7
         Left            =   7200
         TabIndex        =   243
         TabStop         =   0   'False
         Tag             =   "CT_Code"
         Top             =   480
         Visible         =   0   'False
         Width           =   855
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   7
         Left            =   240
         TabIndex        =   249
         Top             =   360
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin Project1.ArmCombobox cbo_SMA_CURR_Code 
         Height          =   345
         Left            =   1560
         TabIndex        =   248
         Tag             =   "CURR_Code®©CURR_Desc"
         Top             =   3240
         Width           =   3255
         _ExtentX        =   5741
         _ExtentY        =   609
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   7
         Left            =   8160
         TabIndex        =   250
         Top             =   360
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Curr code"
         Height          =   252
         Index           =   42
         Left            =   240
         TabIndex        =   266
         Tag             =   "lbl_SMA_CURR_Code"
         Top             =   3240
         Width           =   1332
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#PanMin"
         Height          =   252
         Index           =   41
         Left            =   240
         TabIndex        =   265
         Tag             =   "lbl_SMA_PanMin"
         Top             =   2760
         Width           =   1332
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#PanGTN"
         Height          =   252
         Index           =   40
         Left            =   240
         TabIndex        =   264
         Tag             =   "lbl_SMA_PanGTN"
         Top             =   2280
         Width           =   1332
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#SubMin"
         Height          =   252
         Index           =   39
         Left            =   4560
         TabIndex        =   263
         Tag             =   "lbl_SMA_SubMin"
         Top             =   2760
         Width           =   1212
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#SubGTN"
         Height          =   252
         Index           =   32
         Left            =   4560
         TabIndex        =   261
         Tag             =   "lbl_SMA_SubGTN"
         Top             =   2280
         Width           =   1212
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#PanMargin"
         Height          =   255
         Index           =   38
         Left            =   240
         TabIndex        =   254
         Tag             =   "lbl_SMA_PanMargin"
         Top             =   1800
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#SubMargin"
         Height          =   255
         Index           =   37
         Left            =   4560
         TabIndex        =   253
         Tag             =   "lbl_SMA_SubMargin"
         Top             =   1800
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CT_Desc"
         Height          =   255
         Index           =   36
         Left            =   4560
         TabIndex        =   252
         Tag             =   "lbl_SMA_CT_Desc"
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#System"
         Height          =   255
         Index           =   33
         Left            =   240
         TabIndex        =   251
         Tag             =   "lbl_SMA_System"
         Top             =   1320
         Visible         =   0   'False
         Width           =   1335
      End
   End
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_SysMargin Main"
      Height          =   252
      Index           =   5
      Left            =   120
      TabIndex        =   232
      Top             =   720
      Width           =   1812
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   5
         Left            =   240
         TabIndex        =   237
         Top             =   6720
         Width           =   1095
      End
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   5655
         Index           =   5
         Left            =   0
         TabIndex        =   233
         Top             =   360
         Width           =   2775
         Begin Project1.ArmCombobox cbo_CT_Code_Filter 
            Height          =   345
            Index           =   3
            Left            =   120
            TabIndex        =   234
            Tag             =   "CT_Code®©CT_Desc"
            Top             =   2760
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_SYS_Id_Filter 
            Height          =   345
            Left            =   120
            TabIndex        =   257
            Tag             =   "SYS_Id®©SYS_Name"
            Top             =   2040
            Visible         =   0   'False
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#SYS_Name"
            Height          =   255
            Index           =   35
            Left            =   120
            TabIndex        =   236
            Tag             =   "lbl_HPS_SYS_Name"
            Top             =   1800
            Visible         =   0   'False
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CT Code Filter"
            Height          =   255
            Index           =   5
            Left            =   120
            TabIndex        =   235
            Tag             =   "lbl_PRC_CT_Code_Fl"
            Top             =   2520
            Width           =   1335
         End
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   5
         Left            =   120
         TabIndex        =   238
         Top             =   6120
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   5
         Left            =   120
         TabIndex        =   239
         Top             =   6600
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   5
         Left            =   3120
         TabIndex        =   240
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1455
         Index           =   5
         Left            =   3120
         TabIndex        =   241
         Tag             =   "grd_M_SysMargin"
         Top             =   1320
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   2566
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_HistSysPrice"
      Height          =   252
      Index           =   6
      Left            =   14160
      TabIndex        =   218
      Top             =   3120
      Width           =   1572
      Begin VB.TextBox txt_PRF_Class 
         Height          =   375
         Left            =   9600
         TabIndex        =   231
         Tag             =   "PRF_Class"
         Top             =   1200
         Width           =   615
      End
      Begin VB.TextBox txt_HSP_Price 
         Height          =   405
         Left            =   1560
         TabIndex        =   221
         Tag             =   "HSP_Price"
         Top             =   1680
         Width           =   1695
      End
      Begin VB.TextBox txt_HPP_SYS_Name 
         Height          =   375
         Left            =   1560
         TabIndex        =   220
         Tag             =   "SYS_Name"
         Top             =   1200
         Width           =   2895
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   6
         Left            =   7200
         TabIndex        =   219
         TabStop         =   0   'False
         Tag             =   "SYS_Id"
         Top             =   480
         Width           =   855
      End
      Begin Project1.ArmCombobox cbo_HSP_CT_Code 
         Height          =   345
         Left            =   6120
         TabIndex        =   222
         Tag             =   "CT_Code®©CT_Code"
         Top             =   1200
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_HSP_CURR_Code 
         Height          =   345
         Left            =   6120
         TabIndex        =   223
         Tag             =   "CURR_Code®©CURR_Code"
         Top             =   1680
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   6
         Left            =   240
         TabIndex        =   224
         Top             =   360
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   6
         Left            =   8160
         TabIndex        =   225
         Top             =   360
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#PRF Class"
         Height          =   255
         Index           =   31
         Left            =   8280
         TabIndex        =   230
         Tag             =   "lbl_HPP_PRF_Class"
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#HSP Price"
         Height          =   255
         Index           =   30
         Left            =   240
         TabIndex        =   229
         Tag             =   "lbl_HSP_Price"
         Top             =   1800
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CURR_Code"
         Height          =   255
         Index           =   26
         Left            =   4560
         TabIndex        =   228
         Tag             =   "lbl_HPP_CURR_Code"
         Top             =   1800
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CT_Code"
         Height          =   255
         Index           =   25
         Left            =   4560
         TabIndex        =   227
         Tag             =   "lbl_HPP_CT_Code"
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#System"
         Height          =   255
         Index           =   24
         Left            =   240
         TabIndex        =   226
         Tag             =   "lbl_HPP_System"
         Top             =   1320
         Width           =   1335
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_HistPrdPrice"
      Height          =   252
      Index           =   5
      Left            =   14040
      TabIndex        =   204
      Top             =   3480
      Width           =   1692
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   5
         Left            =   7200
         TabIndex        =   209
         TabStop         =   0   'False
         Tag             =   "PRD_Id"
         Top             =   480
         Visible         =   0   'False
         Width           =   855
      End
      Begin VB.TextBox txt_HPP_PRD_Name 
         Height          =   375
         Left            =   1560
         TabIndex        =   208
         Tag             =   "PRD_Name"
         Top             =   1200
         Width           =   2895
      End
      Begin VB.TextBox txt_HPP_Price 
         Height          =   405
         Left            =   1560
         TabIndex        =   207
         Tag             =   "HPP_Price"
         Top             =   1680
         Width           =   1695
      End
      Begin Project1.ArmCombobox cbo_HPP_CT_Code 
         Height          =   345
         Left            =   6120
         TabIndex        =   205
         Tag             =   "CT_Code®©CT_Code"
         Top             =   1200
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_HPP_CURR_Code 
         Height          =   345
         Left            =   6120
         TabIndex        =   206
         Tag             =   "CURR_Code®©CURR_Code"
         Top             =   1680
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   5
         Left            =   240
         TabIndex        =   210
         Top             =   360
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   5
         Left            =   8160
         TabIndex        =   215
         Top             =   360
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Product"
         Height          =   255
         Index           =   34
         Left            =   240
         TabIndex        =   214
         Tag             =   "lbl_HPP_Product"
         Top             =   1320
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CT_Code"
         Height          =   255
         Index           =   29
         Left            =   4560
         TabIndex        =   213
         Tag             =   "lbl_HPP_CT_Code"
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CURR_Code"
         Height          =   255
         Index           =   28
         Left            =   4560
         TabIndex        =   212
         Tag             =   "lbl_HPP_CURR_Code"
         Top             =   1800
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#HPP Price"
         Height          =   255
         Index           =   27
         Left            =   240
         TabIndex        =   211
         Tag             =   "lbl_HPP_Price"
         Top             =   1800
         Width           =   1335
      End
   End
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_HistSysPrice Main"
      Height          =   372
      Index           =   4
      Left            =   120
      TabIndex        =   191
      Top             =   2520
      Width           =   2052
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   5655
         Index           =   4
         Left            =   0
         TabIndex        =   193
         Top             =   360
         Width           =   2775
         Begin VB.TextBox txt_PRD_Name_Filter 
            Height          =   375
            Index           =   3
            Left            =   120
            TabIndex        =   194
            Tag             =   "SYS_Name"
            Top             =   2040
            Width           =   2535
         End
         Begin Project1.ArmCombobox cbo_CURR_Code_Filter 
            Height          =   345
            Index           =   2
            Left            =   120
            TabIndex        =   195
            Tag             =   "CURR_Code®©CURR_Code"
            Top             =   3480
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_CT_Code_Filter 
            Height          =   345
            Index           =   2
            Left            =   120
            TabIndex        =   196
            Tag             =   "CT_Code®©CT_Desc"
            Top             =   2760
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CT Code Filter"
            Height          =   255
            Index           =   23
            Left            =   120
            TabIndex        =   199
            Tag             =   "lbl_PRC_CT_Code_Fl"
            Top             =   2520
            Width           =   1335
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CURR Code Filter"
            Height          =   255
            Index           =   6
            Left            =   120
            TabIndex        =   198
            Tag             =   "lbl_PRC_CURR_Code_Fl"
            Top             =   3240
            Width           =   1815
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#SYS_Name"
            Height          =   255
            Index           =   4
            Left            =   120
            TabIndex        =   197
            Tag             =   "lbl_HPS_SYS_Name"
            Top             =   1800
            Width           =   1215
         End
      End
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   4
         Left            =   240
         TabIndex        =   192
         Top             =   6720
         Width           =   1095
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   4
         Left            =   120
         TabIndex        =   200
         Top             =   6120
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   4
         Left            =   120
         TabIndex        =   201
         Top             =   6600
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   4
         Left            =   3120
         TabIndex        =   202
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1455
         Index           =   4
         Left            =   3120
         TabIndex        =   203
         Tag             =   "grd_M_HisSPrc"
         Top             =   1320
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   2566
      End
   End
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_HistPrdPrice Main"
      Height          =   252
      Index           =   3
      Left            =   120
      TabIndex        =   176
      Top             =   2160
      Width           =   1572
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   3
         Left            =   240
         TabIndex        =   186
         Top             =   6720
         Width           =   1095
      End
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   5655
         Index           =   3
         Left            =   0
         TabIndex        =   177
         Top             =   360
         Width           =   2775
         Begin VB.TextBox txt_PRD_Name_Filter 
            Height          =   375
            Index           =   2
            Left            =   120
            TabIndex        =   179
            Tag             =   "PRD_Name"
            Top             =   2040
            Width           =   2535
         End
         Begin VB.TextBox txt_PRD_Code_Filter 
            Height          =   405
            Index           =   3
            Left            =   120
            TabIndex        =   178
            Tag             =   "PRD_Code"
            Top             =   1320
            Width           =   2535
         End
         Begin Project1.ArmCombobox cbo_CURR_Code_Filter 
            Height          =   345
            Index           =   1
            Left            =   120
            TabIndex        =   180
            Tag             =   "CURR_Code®©CURR_Code"
            Top             =   3480
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_CT_Code_Filter 
            Height          =   345
            Index           =   1
            Left            =   120
            TabIndex        =   181
            Tag             =   "CT_Code®©CT_Desc"
            Top             =   2760
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Name"
            Height          =   255
            Index           =   22
            Left            =   120
            TabIndex        =   185
            Tag             =   "lbl_PRC_PRD_Name_Fl"
            Top             =   1800
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Code"
            Height          =   255
            Index           =   14
            Left            =   120
            TabIndex        =   184
            Tag             =   "lbl_PRC_PRD_Code_Fl"
            Top             =   1080
            Width           =   975
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CURR Code Filter"
            Height          =   255
            Index           =   10
            Left            =   120
            TabIndex        =   183
            Tag             =   "lbl_PRC_CURR_Code_Fl"
            Top             =   3240
            Width           =   1815
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CT Code Filter"
            Height          =   255
            Index           =   7
            Left            =   120
            TabIndex        =   182
            Tag             =   "lbl_PRC_CT_Code_Fl"
            Top             =   2520
            Width           =   1335
         End
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   3
         Left            =   120
         TabIndex        =   187
         Top             =   6120
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   3
         Left            =   120
         TabIndex        =   188
         Top             =   6600
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   3
         Left            =   3120
         TabIndex        =   189
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1455
         Index           =   3
         Left            =   3120
         TabIndex        =   190
         Tag             =   "grd_M_HisPPrc"
         Top             =   1320
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   2566
      End
   End
   Begin VB.Frame fra_EditPrice 
      Caption         =   "#Edit Price"
      Height          =   255
      Left            =   14760
      TabIndex        =   169
      Top             =   2760
      Width           =   975
      Begin VB.CommandButton btn_Quit 
         Height          =   615
         Left            =   3120
         Style           =   1  'Graphical
         TabIndex        =   172
         Top             =   360
         Width           =   735
      End
      Begin VB.CommandButton btn_Validate 
         Height          =   615
         Left            =   2280
         Style           =   1  'Graphical
         TabIndex        =   171
         Top             =   360
         Width           =   735
      End
      Begin VB.TextBox txt_Price 
         Height          =   375
         Left            =   600
         TabIndex        =   170
         Top             =   480
         Width           =   975
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_Price 2"
      Height          =   252
      Index           =   4
      Left            =   14640
      TabIndex        =   152
      Top             =   2400
      Width           =   1092
      Begin Project1.ArmCombobox cbo_QtyRange 
         Height          =   345
         Left            =   1560
         TabIndex        =   63
         Tag             =   "QtyCode®©QtyCode"
         Top             =   2160
         Width           =   2895
         _ExtentX        =   5106
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_MAT_Id 
         Height          =   345
         Left            =   6120
         TabIndex        =   68
         Tag             =   "MAT_Id®©MAT_Name"
         Top             =   2640
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_CT_Code 
         Height          =   345
         Left            =   6120
         TabIndex        =   67
         Tag             =   "CT_Code®©CT_Code"
         Top             =   2160
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   609
      End
      Begin VB.TextBox txt_CAT_Id 
         Height          =   285
         Left            =   11280
         TabIndex        =   175
         TabStop         =   0   'False
         Tag             =   "CAT_Id"
         Top             =   2160
         Width           =   855
      End
      Begin Project1.ArmCombobox cbo_Thick_Filter 
         Height          =   345
         Left            =   9000
         TabIndex        =   71
         Tag             =   "PCR_Thick®©PCR_Thick"
         Top             =   2640
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_DateRange 
         Height          =   345
         Left            =   1560
         TabIndex        =   62
         Tag             =   "Date_Code®©Date_Desc"
         Top             =   1680
         Width           =   2895
         _ExtentX        =   5106
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_CURR_Code 
         Height          =   345
         Left            =   6120
         TabIndex        =   66
         Tag             =   "CURR_Code®©CURR_Code"
         Top             =   1680
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
      End
      Begin VB.TextBox txt_UM_CodeC 
         Height          =   375
         Left            =   9000
         TabIndex        =   70
         Tag             =   "UM_CodeC"
         Top             =   1680
         Width           =   1095
      End
      Begin VB.TextBox txt_UM_CodeQ 
         Height          =   375
         Left            =   9000
         TabIndex        =   69
         Tag             =   "UM_CodeQ"
         Top             =   1200
         Width           =   1095
      End
      Begin Project1.ArmCombobox cbo_Filter 
         Height          =   345
         Left            =   1560
         TabIndex        =   64
         Top             =   2640
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
      End
      Begin VB.TextBox txt_PRD_NamePar 
         Height          =   405
         Left            =   6120
         TabIndex        =   65
         Tag             =   "PRD_NamePar"
         Top             =   1200
         Width           =   1695
      End
      Begin VB.TextBox txt_Price_PRD_Name 
         Height          =   375
         Index           =   1
         Left            =   1560
         TabIndex        =   61
         Tag             =   "PRD_Name"
         Top             =   1200
         Width           =   2895
      End
      Begin MSFlexGridLib.MSFlexGrid grd_PriceMatrix 
         Height          =   2655
         Left            =   240
         TabIndex        =   72
         Top             =   3240
         Width           =   10455
         _ExtentX        =   18441
         _ExtentY        =   4683
         _Version        =   393216
      End
      Begin VB.TextBox txt_Price_PRD_Id2 
         Height          =   375
         Left            =   10560
         TabIndex        =   155
         TabStop         =   0   'False
         Tag             =   "PRD_IdPar"
         Top             =   1680
         Width           =   1575
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   4
         Left            =   10560
         TabIndex        =   153
         TabStop         =   0   'False
         Tag             =   "PRD_Id"
         Top             =   1200
         Width           =   1575
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   4
         Left            =   240
         TabIndex        =   60
         Top             =   360
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   4
         Left            =   12240
         TabIndex        =   154
         Top             =   1200
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#UM CodeC"
         Height          =   255
         Index           =   21
         Left            =   7920
         TabIndex        =   174
         Top             =   1800
         Width           =   975
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#UM CodeQ"
         Height          =   255
         Index           =   20
         Left            =   7920
         TabIndex        =   173
         Top             =   1320
         Width           =   975
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Filter"
         Height          =   255
         Index           =   19
         Left            =   240
         TabIndex        =   168
         Top             =   2760
         Width           =   855
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Product Par"
         Height          =   255
         Index           =   17
         Left            =   4560
         TabIndex        =   165
         Tag             =   "lbl_PRC_ProductPar"
         Top             =   1320
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CURR_Code"
         Height          =   255
         Index           =   16
         Left            =   4560
         TabIndex        =   164
         Top             =   1800
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CT_Code"
         Height          =   255
         Index           =   15
         Left            =   4560
         TabIndex        =   163
         Top             =   2280
         Width           =   1095
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Date Range"
         Height          =   255
         Index           =   13
         Left            =   240
         TabIndex        =   162
         Top             =   1800
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#MAT Name"
         Height          =   255
         Index           =   12
         Left            =   4560
         TabIndex        =   161
         Top             =   2760
         Width           =   1215
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Thick"
         Height          =   255
         Index           =   11
         Left            =   8040
         TabIndex        =   160
         Top             =   2760
         Width           =   735
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Qty Min-Max"
         Height          =   255
         Index           =   9
         Left            =   240
         TabIndex        =   159
         Tag             =   "lbl_QtyMinMax"
         Top             =   2280
         Width           =   1095
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Product"
         Height          =   255
         Index           =   3
         Left            =   240
         TabIndex        =   156
         Tag             =   "lbl_PRC_Product"
         Top             =   1320
         Width           =   1335
      End
   End
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_Price Main 2"
      Height          =   252
      Index           =   2
      Left            =   120
      TabIndex        =   141
      Top             =   1800
      Width           =   1572
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   2
         Left            =   240
         TabIndex        =   147
         Top             =   7080
         Width           =   1095
      End
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   3975
         Index           =   2
         Left            =   0
         TabIndex        =   142
         Top             =   360
         Width           =   2775
         Begin VB.TextBox txt_PRD_NamePar_Filter 
            Height          =   375
            Left            =   120
            TabIndex        =   166
            Tag             =   "PRD_NamePar"
            Top             =   2640
            Width           =   2535
         End
         Begin VB.TextBox txt_PRD_Name_Filter 
            Height          =   375
            Index           =   1
            Left            =   120
            TabIndex        =   157
            Tag             =   "PRD_Name"
            Top             =   1920
            Width           =   2535
         End
         Begin VB.TextBox txt_PRD_Code_Filter 
            Height          =   315
            Index           =   2
            Left            =   120
            TabIndex        =   143
            Tag             =   "PRD_Code"
            Top             =   1320
            Width           =   2535
         End
         Begin Project1.ArmCombobox cbo_Category_Filter 
            Height          =   345
            Index           =   2
            Left            =   120
            TabIndex        =   144
            Tag             =   "CAT_Id_Filter®©CAT_Name"
            Top             =   600
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_NamePar"
            Height          =   255
            Index           =   18
            Left            =   120
            TabIndex        =   167
            Tag             =   "lbl_PRC_PRD_NamePar_Fl"
            Top             =   2400
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Name"
            Height          =   255
            Index           =   8
            Left            =   120
            TabIndex        =   158
            Tag             =   "lbl_PRC_PRD_Name_Fl"
            Top             =   1680
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Code"
            Height          =   255
            Index           =   2
            Left            =   120
            TabIndex        =   146
            Tag             =   "lbl_PCR_PRD_Code_Fl"
            Top             =   1080
            Width           =   975
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Category"
            Height          =   255
            Index           =   1
            Left            =   120
            TabIndex        =   145
            Tag             =   "lbl_PCR_Category_Fl"
            Top             =   360
            Width           =   1215
         End
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   2
         Left            =   120
         TabIndex        =   148
         Top             =   6480
         Width           =   2775
         _ExtentX        =   4895
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   2
         Left            =   120
         TabIndex        =   149
         Top             =   6840
         Width           =   2775
         _ExtentX        =   4895
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   2
         Left            =   3000
         TabIndex        =   150
         Top             =   600
         Width           =   2175
         _ExtentX        =   3836
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1095
         Index           =   2
         Left            =   3000
         TabIndex        =   151
         Tag             =   "grd_M_Prc2"
         Top             =   1440
         Width           =   2175
         _ExtentX        =   3836
         _ExtentY        =   1931
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_Price"
      Height          =   252
      Index           =   0
      Left            =   14400
      TabIndex        =   119
      Top             =   1680
      Width           =   1332
      Begin VB.TextBox txt_Price_PRD_Id 
         Height          =   375
         Left            =   11160
         TabIndex        =   139
         TabStop         =   0   'False
         Tag             =   "PRD_Id"
         Top             =   2040
         Visible         =   0   'False
         Width           =   1335
      End
      Begin VB.TextBox txt_Price_SYS_Name 
         Height          =   405
         Left            =   7200
         TabIndex        =   12
         Tag             =   "SYS_Name"
         Top             =   1200
         Width           =   3735
      End
      Begin VB.TextBox txt_Price_PRD_Name 
         Height          =   375
         Index           =   0
         Left            =   1800
         TabIndex        =   13
         Tag             =   "PRD_Name"
         Top             =   1680
         Width           =   3855
      End
      Begin VB.Frame fra_SubDetail 
         Caption         =   "Frame1"
         Height          =   3855
         Index           =   0
         Left            =   0
         TabIndex        =   121
         Top             =   3840
         Width           =   11895
         Begin VB.TextBox txt_PRD_Id 
            Height          =   285
            Left            =   2520
            TabIndex        =   132
            TabStop         =   0   'False
            Tag             =   "PRD_Id"
            Top             =   0
            Visible         =   0   'False
            Width           =   1215
         End
         Begin VB.TextBox txt_SubDetailKey 
            Height          =   285
            Index           =   0
            Left            =   1080
            TabIndex        =   131
            TabStop         =   0   'False
            Tag             =   "PRC_Id"
            Top             =   0
            Visible         =   0   'False
            Width           =   1335
         End
         Begin VB.Frame fra_SubDetailItem 
            Height          =   1935
            Index           =   0
            Left            =   120
            TabIndex        =   122
            Top             =   120
            Width           =   10815
            Begin VB.TextBox txt_QtyMax 
               Height          =   375
               Left            =   5400
               TabIndex        =   20
               Tag             =   "PRC_QMax"
               Top             =   1200
               Width           =   1095
            End
            Begin VB.TextBox txt_QtyMin 
               Height          =   375
               Left            =   5400
               TabIndex        =   19
               Tag             =   "PRC_QMin"
               Top             =   720
               Width           =   1095
            End
            Begin VB.TextBox txt_PriceM2 
               Height          =   405
               Left            =   8760
               TabIndex        =   22
               Tag             =   "PRC_Cost"
               Top             =   1200
               Width           =   1095
            End
            Begin Project1.A_calocx cal_Price_VStart 
               Height          =   375
               Left            =   5400
               TabIndex        =   17
               Tag             =   "PRC_VStart"
               Top             =   240
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   661
            End
            Begin Project1.A_calocx cal_Price_VEnd 
               Height          =   375
               Left            =   8760
               TabIndex        =   18
               Tag             =   "PRC_VExp"
               Top             =   240
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   661
            End
            Begin Project1.ArmCombobox cbo_Countries 
               Height          =   345
               Index           =   0
               Left            =   1320
               TabIndex        =   14
               Tag             =   "CT_Code®©CT_Desc"
               Top             =   240
               Width           =   2535
               _ExtentX        =   4471
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Currency 
               Height          =   345
               Index           =   0
               Left            =   1320
               TabIndex        =   15
               Tag             =   "CURR_Code®©CURR_Desc"
               Top             =   720
               Width           =   2535
               _ExtentX        =   4471
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_UM_Code 
               Height          =   345
               Index           =   0
               Left            =   1320
               TabIndex        =   16
               Tag             =   "UM_CodeQ®©UM_DescQ"
               Top             =   1200
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_UM_Code 
               Height          =   345
               Index           =   1
               Left            =   8760
               TabIndex        =   21
               Tag             =   "UM_CodeC®©UM_DescC"
               Top             =   720
               Width           =   1815
               _ExtentX        =   3201
               _ExtentY        =   609
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#UM_Code Cost"
               Height          =   255
               Index           =   0
               Left            =   7320
               TabIndex        =   138
               Tag             =   "lbl_PRC_UM_CodeC"
               Top             =   840
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Cost"
               Height          =   255
               Index           =   88
               Left            =   7320
               TabIndex        =   130
               Tag             =   "lbl_PRC_Cost"
               Top             =   1320
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#ExpiryDate"
               Height          =   255
               Index           =   82
               Left            =   7320
               TabIndex        =   129
               Tag             =   "lbl_PRC_ExpiryDate"
               Top             =   360
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#ValidityStartDate"
               Height          =   255
               Index           =   87
               Left            =   3960
               TabIndex        =   128
               Tag             =   "lbl_PRC_VStartDate"
               Top             =   360
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Qty Max"
               Height          =   255
               Index           =   86
               Left            =   3960
               TabIndex        =   127
               Tag             =   "lbl_PRC_QtyMax"
               Top             =   1320
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Qty Min"
               Height          =   255
               Index           =   89
               Left            =   3960
               TabIndex        =   126
               Tag             =   "lbl_PRC_QtyMin"
               Top             =   840
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#UM_Code Q"
               Height          =   255
               Index           =   81
               Left            =   120
               TabIndex        =   125
               Tag             =   "lbl_PRC_UM_CodeQ"
               Top             =   1320
               Width           =   1215
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#CURR Code"
               Height          =   255
               Index           =   80
               Left            =   120
               TabIndex        =   124
               Tag             =   "lbl_PRC_CURR_Code"
               Top             =   840
               Width           =   1215
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#CT_code"
               Height          =   255
               Index           =   202
               Left            =   120
               TabIndex        =   123
               Tag             =   "lbl_PRC_CT_Code"
               Top             =   360
               Width           =   1215
            End
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   3450
            Index           =   0
            Left            =   11040
            TabIndex        =   24
            Top             =   240
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   4180
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   1575
            Index           =   0
            Left            =   120
            TabIndex        =   23
            Tag             =   "grd_S_Prc"
            Top             =   2160
            Width           =   10815
            _ExtentX        =   19076
            _ExtentY        =   2778
         End
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   0
         Left            =   11160
         TabIndex        =   120
         TabStop         =   0   'False
         Tag             =   "PCR_Id"
         Top             =   1200
         Visible         =   0   'False
         Width           =   1335
      End
      Begin VB.TextBox txt_Price_CAT_Name 
         Height          =   375
         Left            =   1800
         TabIndex        =   11
         Tag             =   "CAT_Name"
         Top             =   1200
         Width           =   3855
      End
      Begin Project1.ArmGrid grd_PriceCrit 
         Height          =   1455
         Index           =   0
         Left            =   1800
         TabIndex        =   133
         Tag             =   "grd_D_Prc"
         Top             =   2160
         Width           =   9135
         _ExtentX        =   16113
         _ExtentY        =   2566
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   0
         Left            =   240
         TabIndex        =   10
         Top             =   360
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   0
         Left            =   11160
         TabIndex        =   134
         TabStop         =   0   'False
         Top             =   1560
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#System"
         Height          =   255
         Index           =   85
         Left            =   6000
         TabIndex        =   137
         Tag             =   "lbl_PRC_System"
         Top             =   1320
         Width           =   975
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Product"
         Height          =   255
         Index           =   84
         Left            =   240
         TabIndex        =   136
         Tag             =   "lbl_PRC_Product"
         Top             =   1800
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Category"
         Height          =   255
         Index           =   76
         Left            =   240
         TabIndex        =   135
         Tag             =   "lbl_PRC_Category"
         Top             =   1440
         Width           =   1215
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "DPC_PriceCrit"
      Height          =   252
      Index           =   1
      Left            =   14400
      TabIndex        =   93
      Top             =   2040
      Width           =   1332
      Begin VB.TextBox txt_PRC_PRD_Code 
         Height          =   375
         Left            =   2400
         TabIndex        =   33
         Tag             =   "PRD_Code"
         Top             =   2400
         Width           =   3255
      End
      Begin VB.TextBox txt_CAT_Name 
         Height          =   375
         Left            =   2400
         TabIndex        =   32
         Tag             =   "CAT_Name"
         Top             =   1920
         Width           =   5295
      End
      Begin VB.TextBox txt_PRC_PRD_Name 
         Height          =   375
         Left            =   2400
         TabIndex        =   31
         Tag             =   "PRD_Name"
         Top             =   1440
         Width           =   5295
      End
      Begin VB.TextBox txt_DetailKey 
         Height          =   375
         Index           =   1
         Left            =   10200
         TabIndex        =   111
         TabStop         =   0   'False
         Tag             =   "PRD_Id"
         Top             =   1320
         Visible         =   0   'False
         Width           =   975
      End
      Begin VB.Frame fra_SubDetail 
         Height          =   4695
         Index           =   1
         Left            =   120
         TabIndex        =   95
         Top             =   3000
         Width           =   11895
         Begin VB.TextBox txt_SubDetailKey 
            Height          =   375
            Index           =   1
            Left            =   960
            TabIndex        =   110
            TabStop         =   0   'False
            Tag             =   "PCR_Id"
            Text            =   "Text1"
            Top             =   240
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.Frame fra_SubDetailItem 
            Height          =   1815
            Index           =   1
            Left            =   120
            TabIndex        =   96
            Top             =   480
            Width           =   10815
            Begin VB.TextBox txt_PCR_TMin 
               Height          =   405
               Left            =   7800
               TabIndex        =   43
               Tag             =   "PCR_TMin"
               Top             =   840
               Width           =   735
            End
            Begin VB.TextBox txt_PCR_BMax 
               Height          =   375
               Left            =   6120
               TabIndex        =   42
               Tag             =   "PCR_BMax"
               Top             =   1320
               Width           =   735
            End
            Begin VB.TextBox txt_PCR_Thick 
               Height          =   375
               Left            =   4200
               TabIndex        =   37
               Tag             =   "PCR_Thick"
               Top             =   360
               Width           =   735
            End
            Begin VB.TextBox txt_PCR_BMin 
               Height          =   375
               Left            =   4200
               TabIndex        =   39
               Tag             =   "PCR_BMin"
               Top             =   1320
               Width           =   735
            End
            Begin VB.TextBox txt_PCR_AMax 
               Height          =   375
               Left            =   6120
               TabIndex        =   41
               Tag             =   "PCR_AMax"
               Top             =   840
               Width           =   735
            End
            Begin VB.TextBox txt_PCR_AMin 
               Height          =   375
               Left            =   4200
               TabIndex        =   38
               Tag             =   "PCR_AMin"
               Top             =   840
               Width           =   735
            End
            Begin VB.TextBox txt_PRD_IdPar 
               Height          =   375
               Left            =   1320
               TabIndex        =   35
               Tag             =   "PRD_IdPar"
               Top             =   840
               Width           =   1695
            End
            Begin VB.TextBox txt_PCR_TMax 
               Height          =   375
               Left            =   7800
               TabIndex        =   44
               Tag             =   "PCR_TMax"
               Top             =   1320
               Width           =   735
            End
            Begin VB.CheckBox chk_PCR_IsPrf 
               Height          =   255
               Left            =   9960
               TabIndex        =   46
               Tag             =   "PCR_IsPrf"
               Top             =   960
               Width           =   375
            End
            Begin VB.TextBox txt_PCR_GaCnt 
               Height          =   375
               Left            =   9960
               TabIndex        =   47
               Tag             =   "PCR_GaCnt"
               Top             =   1320
               Width           =   735
            End
            Begin VB.TextBox txt_PCR_CoSid 
               Height          =   375
               Left            =   9960
               TabIndex        =   45
               Tag             =   "PCR_CoSid"
               Top             =   360
               Width           =   735
            End
            Begin VB.CommandButton cmd_AddExisting 
               Caption         =   "#Add Existing ..."
               Height          =   375
               Left            =   120
               TabIndex        =   34
               Tag             =   "lbl_PCR_AddExisting"
               Top             =   240
               Width           =   2895
            End
            Begin Project1.ArmCombobox cbo_CutArea 
               Height          =   345
               Left            =   1320
               TabIndex        =   36
               Tag             =   "CUA_Id®©CUA_Desc"
               Top             =   1320
               Width           =   1695
               _ExtentX        =   2990
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Material 
               Height          =   345
               Index           =   0
               Left            =   6120
               TabIndex        =   40
               Tag             =   "MAT_Id®©MAT_Name"
               Top             =   360
               Width           =   2415
               _ExtentX        =   4260
               _ExtentY        =   609
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#TMin"
               Height          =   255
               Index           =   184
               Left            =   6960
               TabIndex        =   109
               Tag             =   "lbl_PCR_TMin"
               Top             =   960
               Width           =   495
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PCR_BMax"
               Height          =   255
               Index           =   185
               Left            =   5040
               TabIndex        =   108
               Tag             =   "lbl_PCR_BMax"
               Top             =   1440
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PCR Thick"
               Height          =   255
               Index           =   186
               Left            =   3120
               TabIndex        =   107
               Tag             =   "lbl_PCR_Thick"
               Top             =   480
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PCR_BMin"
               Height          =   255
               Index           =   187
               Left            =   3120
               TabIndex        =   106
               Tag             =   "lbl_PCR_BMin"
               Top             =   1440
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#MAT Id"
               Height          =   255
               Index           =   188
               Left            =   5040
               TabIndex        =   105
               Tag             =   "lbL_MAT_Id"
               Top             =   480
               Width           =   735
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PCR_AMax"
               Height          =   255
               Index           =   189
               Left            =   5040
               TabIndex        =   104
               Tag             =   "lbl_PCR_AMax"
               Top             =   960
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PCR_AMin"
               Height          =   255
               Index           =   190
               Left            =   3120
               TabIndex        =   103
               Tag             =   "lbl_PCR_AMin"
               Top             =   960
               Width           =   975
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#CUA Id"
               Height          =   255
               Index           =   191
               Left            =   120
               TabIndex        =   102
               Tag             =   "lbl_PCR_CUA_Id"
               Top             =   1320
               Width           =   735
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PRD IdPar"
               Height          =   255
               Index           =   192
               Left            =   120
               TabIndex        =   101
               Tag             =   "lbl_PCR_PRD_IdPar"
               Top             =   840
               Width           =   1095
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#TMax"
               Height          =   255
               Index           =   182
               Left            =   6960
               TabIndex        =   100
               Tag             =   "lbl_PCR_TMax"
               Top             =   1440
               Width           =   855
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#IsPrf"
               Height          =   255
               Index           =   193
               Left            =   9000
               TabIndex        =   99
               Tag             =   "lbl_PCR_IsPrf"
               Top             =   960
               Width           =   735
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#GaCnt"
               Height          =   255
               Index           =   194
               Left            =   9000
               TabIndex        =   98
               Tag             =   "lbl_PCR_GaCnt"
               Top             =   1440
               Width           =   735
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#CoSid"
               Height          =   255
               Index           =   195
               Left            =   9000
               TabIndex        =   97
               Tag             =   "lbl_PCR_CoSid"
               Top             =   480
               Width           =   735
            End
         End
         Begin Project1.ToolbarControl tlb_SubDetail 
            Height          =   3450
            Index           =   1
            Left            =   11040
            TabIndex        =   49
            Top             =   600
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   4180
         End
         Begin Project1.ArmGrid grd_Subdetail 
            Height          =   1935
            Index           =   1
            Left            =   120
            TabIndex        =   48
            Tag             =   "grd_S_PrcCrt"
            Top             =   2280
            Width           =   10815
            _ExtentX        =   18230
            _ExtentY        =   3413
         End
      End
      Begin VB.TextBox txt_PCR_CAT_Id 
         Height          =   375
         Left            =   7800
         TabIndex        =   94
         TabStop         =   0   'False
         Tag             =   "CAT_Id"
         Top             =   1920
         Visible         =   0   'False
         Width           =   615
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   1
         Left            =   240
         TabIndex        =   30
         Top             =   480
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   1
         Left            =   10200
         TabIndex        =   112
         TabStop         =   0   'False
         Top             =   1800
         Visible         =   0   'False
         Width           =   495
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#PRD Code"
         Height          =   255
         Index           =   180
         Left            =   360
         TabIndex        =   115
         Tag             =   "lbl_PCR_PRD_Code"
         Top             =   2520
         Width           =   1335
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#CAT Name"
         Height          =   255
         Index           =   181
         Left            =   360
         TabIndex        =   114
         Tag             =   "lbl_PCR_CAT_Name"
         Top             =   2040
         Width           =   1815
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#PRD Name"
         Height          =   255
         Index           =   183
         Left            =   360
         TabIndex        =   113
         Tag             =   "lbl_PCR_PRD_Name"
         Top             =   1560
         Width           =   1935
      End
   End
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_PriceCrit Main"
      Height          =   252
      Index           =   1
      Left            =   120
      TabIndex        =   80
      Top             =   1440
      Width           =   1572
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   4095
         Index           =   1
         Left            =   0
         TabIndex        =   82
         Top             =   480
         Width           =   2775
         Begin VB.TextBox txt_PRD_Code_Filter 
            Height          =   405
            Index           =   1
            Left            =   120
            TabIndex        =   83
            Tag             =   "PRD_Code"
            Top             =   1680
            Width           =   2535
         End
         Begin Project1.ArmCombobox cbo_Category_Filter 
            Height          =   345
            Index           =   1
            Left            =   120
            TabIndex        =   84
            Tag             =   "CAT_Id®©CAT_Name"
            Top             =   720
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Category"
            Height          =   255
            Index           =   196
            Left            =   120
            TabIndex        =   86
            Tag             =   "lbl_PCR_Category_Fl"
            Top             =   480
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Code"
            Height          =   255
            Index           =   197
            Left            =   120
            TabIndex        =   85
            Tag             =   "lbl_PCR_PRD_Code_Fl"
            Top             =   1320
            Width           =   975
         End
      End
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   1
         Left            =   360
         TabIndex        =   81
         Top             =   5280
         Width           =   1095
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   1
         Left            =   0
         TabIndex        =   87
         Top             =   4680
         Width           =   2775
         _ExtentX        =   4895
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   1
         Left            =   0
         TabIndex        =   88
         Top             =   5160
         Width           =   2775
         _ExtentX        =   4895
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   1
         Left            =   3000
         TabIndex        =   90
         Top             =   600
         Width           =   2175
         _ExtentX        =   3836
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1095
         Index           =   1
         Left            =   3000
         TabIndex        =   92
         Tag             =   "grd_M_PrcCr"
         Top             =   1440
         Width           =   2175
         _ExtentX        =   3836
         _ExtentY        =   1931
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "#PriceImport"
      Height          =   255
      Index           =   3
      Left            =   14640
      TabIndex        =   75
      Top             =   1320
      Width           =   1095
      Begin VB.TextBox txt_DetailKey 
         Height          =   285
         Index           =   3
         Left            =   10080
         TabIndex        =   76
         TabStop         =   0   'False
         Top             =   1320
         Width           =   615
      End
      Begin Project1.ArmGrid grd_PriceImport 
         Height          =   3135
         Left            =   240
         TabIndex        =   91
         Tag             =   "grd_PriceImport"
         Top             =   1440
         Width           =   9615
         _ExtentX        =   16960
         _ExtentY        =   5530
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   3
         Left            =   240
         TabIndex        =   89
         Top             =   600
         Width           =   5415
         _ExtentX        =   9551
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   3
         Left            =   10080
         TabIndex        =   78
         TabStop         =   0   'False
         Top             =   1680
         Visible         =   0   'False
         Width           =   495
      End
   End
   Begin VB.Frame fra_DetailItem 
      Caption         =   "#PriceCrit Selection"
      Height          =   252
      Index           =   2
      Left            =   14280
      TabIndex        =   59
      Top             =   720
      Width           =   1572
      Begin VB.TextBox txt_DetailKey 
         Height          =   285
         Index           =   2
         Left            =   9720
         TabIndex        =   73
         TabStop         =   0   'False
         Tag             =   "PCR_Id"
         Top             =   1320
         Visible         =   0   'False
         Width           =   615
      End
      Begin Project1.ArmGrid grd_PriceCrit 
         Height          =   3375
         Index           =   1
         Left            =   240
         TabIndex        =   79
         Tag             =   "grd_PrcCrtSel"
         Top             =   1440
         Width           =   8415
         _ExtentX        =   14843
         _ExtentY        =   5953
      End
      Begin Project1.ToolbarControl tlb_Detail 
         Height          =   690
         Index           =   2
         Left            =   240
         TabIndex        =   77
         Top             =   600
         Width           =   5415
         _ExtentX        =   9551
         _ExtentY        =   1217
      End
      Begin VB.CheckBox chk_Repositioning 
         Height          =   375
         Index           =   2
         Left            =   9720
         TabIndex        =   74
         TabStop         =   0   'False
         Top             =   1680
         Visible         =   0   'False
         Width           =   495
      End
   End
   Begin VB.Frame fra_ProgressBar 
      Caption         =   "Progress"
      Height          =   255
      Left            =   14880
      TabIndex        =   56
      Top             =   960
      Visible         =   0   'False
      Width           =   855
      Begin MSComctlLib.ProgressBar prb_Progress 
         Height          =   255
         Left            =   240
         TabIndex        =   57
         Top             =   720
         Width           =   4455
         _ExtentX        =   7858
         _ExtentY        =   450
         _Version        =   393216
         Appearance      =   1
      End
      Begin VB.Label lbl_ProgressMsg 
         Caption         =   "Msg ..."
         Height          =   255
         Left            =   240
         TabIndex        =   58
         Top             =   360
         Width           =   4455
      End
   End
   Begin VB.Frame fra_MainItem 
      Caption         =   "DPC_Price Main"
      Height          =   252
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   1080
      Width           =   1452
      Begin VB.Frame fra_MainFilter 
         Caption         =   "Frame1"
         Height          =   5655
         Index           =   0
         Left            =   0
         TabIndex        =   2
         Top             =   360
         Width           =   2775
         Begin VB.TextBox txt_PRD_Code_Filter 
            Height          =   405
            Index           =   0
            Left            =   120
            TabIndex        =   4
            Tag             =   "PRD_Code"
            Top             =   1320
            Width           =   2535
         End
         Begin VB.TextBox txt_PRD_Name_Filter 
            Height          =   375
            Index           =   0
            Left            =   120
            TabIndex        =   3
            Tag             =   "PRD_Name"
            Top             =   2040
            Width           =   2535
         End
         Begin Project1.ArmCombobox cbo_CURR_Code_Filter 
            Height          =   345
            Index           =   0
            Left            =   120
            TabIndex        =   5
            Tag             =   "CURR_Code®©CURR_Code"
            Top             =   3480
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_CT_Code_Filter 
            Height          =   345
            Index           =   0
            Left            =   120
            TabIndex        =   6
            Tag             =   "CT_Code®©CT_Desc"
            Top             =   2760
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin Project1.A_calocx cal_ToDate 
            Height          =   375
            Index           =   0
            Left            =   840
            TabIndex        =   7
            Tag             =   "ToDate"
            Top             =   4560
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   661
         End
         Begin Project1.A_calocx cal_FromDate 
            Height          =   375
            Index           =   0
            Left            =   840
            TabIndex        =   8
            Tag             =   "FromDate"
            Top             =   4080
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   661
         End
         Begin Project1.ArmCombobox cbo_Category_Filter 
            Height          =   345
            Index           =   0
            Left            =   120
            TabIndex        =   9
            Tag             =   "CAT_Id®©CAT_Name"
            Top             =   600
            Width           =   2535
            _ExtentX        =   4471
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Category"
            Height          =   255
            Index           =   78
            Left            =   120
            TabIndex        =   51
            Tag             =   "lbl_PRC_Category_Fl"
            Top             =   360
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#From"
            Height          =   255
            Index           =   90
            Left            =   120
            TabIndex        =   50
            Tag             =   "lbl_PRC_VStartDate_Fl"
            Top             =   4200
            Width           =   615
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#To"
            Height          =   255
            Index           =   91
            Left            =   120
            TabIndex        =   29
            Tag             =   "lbl_PRC_VEndDate_Fl"
            Top             =   4680
            Width           =   615
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CT Code Filter"
            Height          =   255
            Index           =   92
            Left            =   120
            TabIndex        =   28
            Tag             =   "lbl_PRC_CT_Code_Fl"
            Top             =   2520
            Width           =   1335
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#CURR Code Filter"
            Height          =   255
            Index           =   93
            Left            =   120
            TabIndex        =   27
            Tag             =   "lbl_PRC_CURR_Code_Fl"
            Top             =   3240
            Width           =   1815
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Code"
            Height          =   255
            Index           =   134
            Left            =   120
            TabIndex        =   26
            Tag             =   "lbl_PRC_PRD_Code_Fl"
            Top             =   1080
            Width           =   975
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#PRD_Name"
            Height          =   255
            Index           =   135
            Left            =   120
            TabIndex        =   25
            Tag             =   "lbl_PRC_PRD_Name_Fl"
            Top             =   1800
            Width           =   1215
         End
      End
      Begin VB.CommandButton cmd_TVReLoad 
         Caption         =   "Command1"
         Height          =   495
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   6720
         Width           =   1095
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Index           =   0
         Left            =   120
         TabIndex        =   52
         Top             =   6120
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   1095
         Index           =   0
         Left            =   120
         TabIndex        =   53
         Top             =   6600
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   1931
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Index           =   0
         Left            =   3120
         TabIndex        =   54
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   1455
         Index           =   0
         Left            =   3120
         TabIndex        =   55
         Tag             =   "grd_M_Prc"
         Top             =   1320
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   2566
      End
   End
   Begin MSComctlLib.TabStrip tbs_Main 
      Height          =   375
      Left            =   480
      TabIndex        =   116
      Top             =   0
      Width           =   3855
      _ExtentX        =   6800
      _ExtentY        =   661
      MultiRow        =   -1  'True
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   5
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab4 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab5 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
   Begin MSComDlg.CommonDialog dlg_Common 
      Left            =   4800
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   375
      Index           =   0
      Left            =   7560
      TabIndex        =   117
      Top             =   120
      Width           =   735
      _ExtentX        =   1296
      _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 MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   375
      Index           =   1
      Left            =   8400
      TabIndex        =   118
      Top             =   120
      Width           =   735
      _ExtentX        =   1296
      _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 MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   375
      Index           =   2
      Left            =   9240
      TabIndex        =   140
      Top             =   120
      Width           =   735
      _ExtentX        =   1296
      _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 MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   375
      Index           =   3
      Left            =   10080
      TabIndex        =   216
      Top             =   120
      Width           =   735
      _ExtentX        =   1296
      _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 MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   375
      Index           =   4
      Left            =   10920
      TabIndex        =   217
      Top             =   120
      Width           =   735
      _ExtentX        =   1296
      _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 MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   372
      Index           =   5
      Left            =   11880
      TabIndex        =   256
      Top             =   120
      Width           =   732
      _ExtentX        =   1296
      _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 MSComctlLib.TabStrip tbs_MainTabFilter 
      Height          =   372
      Index           =   6
      Left            =   12840
      TabIndex        =   303
      Top             =   120
      Width           =   732
      _ExtentX        =   1296
      _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
End
Attribute VB_Name = "DPC_Ref_Prices"
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 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 LockWindowUpdate Lib "user32" (ByVal hwnd 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_Tools                        As DPC_Tools
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 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

Private ms_PicPath                      As String       'used to save images from database
Private mi_ActiveImageButtonIndex       As Integer      'used to store index of active cmd_ImageInfo button

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

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

Private Const MODULE_NAME As String = "DPC_Ref"
Private Const SCREEN_NAME As String = "DPC_Ref_Prices"
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 = 9800

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"

Private Const IMAGE_CLICK_MSG = "Image clicked"
Private Const IMAGE_INFO_CONFIG_INDEX = 2

Private Const PRICE_CRIT_SELECTION_CONFIG_INDEX = 2
Private Const PRICE_IMPORT_CONFIG_INDEX = 0


'**********************************************************************************************************************************
'**********************************************************************************************************************************
' 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
    PreviousDetailIndex             As Long         'new
    ClearControlsBeforeInit         As Boolean      'new
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 eTableType
    ttNone = 0
    ttDPC_Price = 1
    ttDPC_PriceCrit = 2
    ttDPC_Price2 = 3
    ttDPC_HistPrdPrice = 4
    ttDPC_HistSysPrice = 5
    ttDPC_SysMargin = 6
    ttDPC_Cost = 7
End Enum

Private Type tFlexGridData
    PRC_Id As Long
    PCR_Id As Long
    QMin As Double
    QMax As Double
    Cost As Double
    iConcurrency As Long
End Type

Private mt_PriceCritForCategory() As tPriceCritForCategory

Private mt_FlexGridData() As tFlexGridData
Private ml_EditedRow As Long
Private ml_EditedCol As Long

'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 = mo_Tools.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 Sub DrawSelImage(ByVal ao_Image As StdPicture, ByVal ao_Canvas As PictureBox, Optional ByVal as_Message As String = IMAGE_CLICK_MSG)
Dim lf_AspectRatioX As Double
Dim lf_AspectRatioY As Double
Dim lf_Width As Double
Dim lf_Height As Double

  Set ao_Canvas.Picture = Nothing
  If ao_Image Is Nothing Then
    If as_Message <> "" Then
      'Call PrintMessage(ao_Canvas, as_Message)
    End If
    Exit Sub
  End If
  
  lf_Width = ao_Canvas.ScaleX(ao_Image.Width, vbHimetric, vbTwips)
  lf_Height = ao_Canvas.ScaleY(ao_Image.Height, vbHimetric, vbTwips)
  
  If (lf_Height > ao_Canvas.ScaleHeight) Or (lf_Width > ao_Canvas.ScaleWidth) Then
    lf_AspectRatioX = ao_Canvas.ScaleWidth / lf_Width
    lf_AspectRatioY = ao_Canvas.ScaleHeight / lf_Height
    If lf_AspectRatioX < lf_AspectRatioY Then
      lf_Width = lf_Width * lf_AspectRatioX
      lf_Height = lf_Height * lf_AspectRatioX
    Else
      lf_Width = lf_Width * lf_AspectRatioY
      lf_Height = lf_Height * lf_AspectRatioY
    End If
  End If
  Call ao_Canvas.PaintPicture(ao_Image, (ao_Canvas.ScaleWidth - lf_Width) / 2, (ao_Canvas.ScaleHeight - lf_Height) / 2, lf_Width, lf_Height)
  'Call ao_Canvas.PaintPicture(ao_Image, 0, 0)
  'ao_Canvas.Picture = ao_Canvas.Image
  
End Sub

Private Function DeleteImage(ByVal al_IMG_Id As Long) As Boolean
Dim ls_PicName As String

  DeleteImage = False
  If al_IMG_Id = 0 Then Exit Function
  ls_PicName = ms_PicPath & "IMG" & al_IMG_Id & ".jpg"
  If mo_FSO.FileExists(ls_PicName) Then
        Call mo_Tools.DeleteFile(mo_FSO, ls_PicName)
  End If
  DeleteImage = True
End Function

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' 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_DPC_RefRight As String
'ls_DPC_RefRight = Trim(GetAConfigData(mo_Db, "DPC_RefRight"))
   ' If InStr(1, SEP & ls_DPC_RefRight & SEP, SEP & ml_U_code & SEP) <= 0 Then
   '     Load_A_COM_Custom = False
   '     Exit Function
   ' End If
   
   ms_PicPath = App.Path & "\PICS\"
    
    btn_Validate.Picture = LoadResPicture(RES_OK, 1)
    btn_Quit.Picture = LoadResPicture(RES_QUIT, 1)
  
    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

    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
    Dim ll_Index As Integer
    
    ms_ToolbarRequest = "exec Toolbar_sel $Module$"
    'Set lo_Tab = tbs_Main.Tabs(1)
    'lo_Tab.Caption = "#DPC_Price"
    'lo_Tab.Key = "DPC_Price"
    'lo_Tab.Tag = "lbl_TAB_DPC_Price"
           
    Set lo_Tab = tbs_Main.Tabs(1)
    lo_Tab.Caption = "#DPC_PriceCrit"
    lo_Tab.Key = "DPC_PriceCrit"
    lo_Tab.Tag = "lbl_TAB_DPC_PriceCrit"
                                       
    'Set lo_Tab = tbs_Main.Tabs(3)
    'lo_Tab.Caption = "#DPC_Price2"
    'lo_Tab.Key = "DPC_Price2"
    'lo_Tab.Tag = "lbl_TAB_DPC_Price2"
                                       
    Set lo_Tab = tbs_Main.Tabs(2)
    lo_Tab.Caption = "#DPC_HistPrdPrice"
    lo_Tab.Key = "DPC_HistPrdPrice"
    lo_Tab.Tag = "lbl_TAB_DPC_HistPrdPrice"
                                       
    Set lo_Tab = tbs_Main.Tabs(3)
    lo_Tab.Caption = "#DPC_HistSysPrice"
    lo_Tab.Key = "DPC_HistSysPrice"
    lo_Tab.Tag = "lbl_TAB_DPC_HistSysPrice"
                                       
    Set lo_Tab = tbs_Main.Tabs(4)
    lo_Tab.Caption = "#DPC_SysMargin"
    lo_Tab.Key = "DPC_SysMargin"
    lo_Tab.Tag = "lbl_TAB_DPC_SysMargin"
                                       
    Set lo_Tab = tbs_Main.Tabs(5)
    lo_Tab.Caption = "#DPC_Cost"
    lo_Tab.Key = "DPC_Cost"
    lo_Tab.Tag = "lbl_TAB_DPC_Cost"
                                       
    For ll_Index = 0 To 0
        cbo_Countries(ll_Index).Request = ReplacePlaceHolder("exec countries_cbo $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    Next
    
    cbo_Vendor.Request = ReplacePlaceHolder("exec dpc_vendor_lst $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    
    For ll_Index = 0 To 1
        cbo_Currency(ll_Index).Request = ReplacePlaceHolder("exec currencies_cbo $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    Next
    
    cbo_SMA_CURR_Code.Request = ReplacePlaceHolder("exec currencies_cbo $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    
    cbo_SYS_Id_Filter.Request = ReplacePlaceHolder("exec dpc_system_cbo $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    
    For ll_Index = 0 To 3
        cbo_CT_Code_Filter(ll_Index).Request = ReplacePlaceHolder("exec countries_cbo $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
        cbo_CT_Code_Filter(ll_Index).FirstBlankItem = True
    Next
    
    cbo_Vendor_Filter.Request = ReplacePlaceHolder("exec dpc_vendor_lst $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    cbo_Vendor_Filter.FirstBlankItem = True
    
    For ll_Index = 0 To 3
        cbo_CURR_Code_Filter(ll_Index).Request = ReplacePlaceHolder("exec currencies_cbo $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    Next
    
    For ll_Index = 0 To 1
        cal_FromDate(ll_Index).date_courte = Format(DateSerial(Year(Now), Month(Now) - 1, 1), "dd\/mm\/yyyy")
        cal_FromDate(ll_Index).Zorder
        
        cal_ToDate(ll_Index).date_courte = Format(DateSerial(Year(Now), Month(Now), 1), "dd\/mm\/yyyy")
    Next
    
    cal_Price_VStart.date_courte = Format(DateSerial(Year(Now), Month(Now) - 1, 1), "dd\/mm\/yyyy")
    cal_Price_VStart.Zorder
    cal_Price_VEnd.date_courte = Format(DateSerial(Year(Now), Month(Now) - 1, 1), "dd\/mm\/yyyy")
    cal_Price_VEnd.Zorder
        
    cal_Cost_VStart.date_courte = Format(DateSerial(Year(Now), Month(Now) - 1, 1), "dd\/mm\/yyyy")
    cal_Cost_VStart.Zorder
    cal_Cost_VEnd.date_courte = Format(DateSerial(Year(Now), Month(Now) - 1, 1), "dd\/mm\/yyyy")
    cal_Cost_VEnd.Zorder
        
    For ll_Index = 0 To 3
        cbo_Category_Filter(ll_Index).Request = ReplacePlaceHolder("exec DPC_Category_lst $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    Next
    
    For ll_Index = 0 To 3
        cbo_UM_Code(ll_Index).Request = ReplacePlaceHolder("exec DPC_Unit_of_measure_cbo2 $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    Next
    
    For ll_Index = 0 To 1
        cbo_Material(0).Request = ReplacePlaceHolder("exec DPC_Material_lst2 $Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    Next
    
    cbo_CutArea.Request = ReplacePlaceHolder("exec DPC_CutArea_lst2 $CUT_Id$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    
    cbo_filter.Clear
    
    cbo_DateRange.Request = ReplacePlaceHolder("exec DPC_Price_lst6 $Key1$,$Key2$,$Language_code$", "$Language_code$", mo_Tools.SqlStr(ms_Language_Code))
    
    'cbo_CURR_Code.Request = ReplaceLanguagePlaceholderFromToolbar("exec DPC_Price_lst6 $toolbar_language_code$")
    
    For ll_Index = 0 To 2
        If Not grd_PriceCrit(ll_Index).SetColumns(Array( _
            "PCR_Id®©0®©1®©PCR_Id®©#PCR_Id", _
            "PRD_Code®©1000®©0®©PRD_Code®©#PRD_Code", _
            "PRD_IdPar®©0®©0®©PRD_IdPar®©#PRD_IdPar", _
            "CUA_Id®©0®©0®©CUA_Id®©#CUA_Id", _
            "CUA_Desc®©1000®©0®©CUA_Desc®©#CUA_Desc", _
            "MAT_Id®©0®©0®©MAT_Id®©#MAT_Id", _
            "MAT_Name®©1000®©0®©MAT_Name®©#MAT_Name", _
            "PCR_AMin®©1000®©0®©PCR_AMin®©#PCR_AMin", _
            "PCR_AMax®©1000®©0®©PCR_AMax®©#PCR_AMax", _
            "PCR_BMin®©1000®©0®©PCR_BMin®©#PCR_BMin", _
            "PCR_BMax®©1000®©0®©PCR_BMax®©#PCR_BMax", _
            "PCR_Thick®©1000®©0®©PCR_Thick®©#PCR_Thick", _
            "PCR_TMin®©1000®©0®©PCR_TMin®©#PCR_TMin", _
            "PCR_TMax®©1000®©0®©PCR_TMax®©#PCR_TMax", _
            "PCR_IsPrf®©1000®©0®©PCR_IsPrf®©#PCR_IsPrf", _
            "PCR_GaCnt®©1000®©0®©PCR_GaCnt®©#PCR_GaCnt", _
            "PCR_CoSid®©1000®©0®©PCR_CoSid®©#PCR_CoSid", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")) Then
                Err.Raise ArmErr.CompFncFailed, "grd_PriceCrit", "Method SetColumns failed."
        End If
    Next
        
    grd_PriceImport.SetColumns (Array( _
        "MSG_Id®©0®©1®©MSG_Id®©#MSG_Id", _
        "MSG_Text®©4500®©0®©MSG_Text®©#MSG_Text"))
            
    'toolbar position fix
    For ll_Index = 0 To 1
        tlb_SubDetail(ll_Index).Width = 672
    Next
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Init_Custom")
End Sub

Private Sub SetPriceCritForCategory(al_Index As Long, al_CAT_Id As Long, ab_PRD_IdPar As Boolean, ab_CUA_Id As Boolean, ab_PCR_AMin As Boolean, ab_PCR_AMax As Boolean, ab_PCR_BMin As Boolean, ab_PCR_BMax As Boolean, ab_MAT_Id As Boolean, ab_PCR_Thick As Boolean, ab_PCR_TMin As Boolean, ab_PCR_TMax As Boolean, ab_PCR_IsPrf As Boolean, ab_PCR_GaCnt As Boolean, ab_PCR_CoSid As Boolean)
    
    With mt_PriceCritForCategory(al_Index)
        .CAT_Id = al_CAT_Id
        .PRD_IdPar = ab_PRD_IdPar
        .CUA_Id = ab_CUA_Id
        .PCR_AMin = ab_PCR_AMin
        .PCR_AMax = ab_PCR_AMax
        .PCR_BMin = ab_PCR_BMin
        .PCR_BMax = ab_PCR_BMax
        .MAT_Id = ab_MAT_Id
        .PCR_Thick = ab_PCR_Thick
        .PCR_TMin = ab_PCR_TMin
        .PCR_TMax = ab_PCR_TMax
        .PCR_IsPrf = ab_PCR_IsPrf
        .PCR_GaCnt = ab_PCR_GaCnt
        .PCR_CoSid = ab_PCR_CoSid
    End With
    
End Sub

Private Function UpdatePrice(ByVal ad_Price As Double, ByVal al_Row As Long, ByVal al_Col As Long) As Boolean
On Error GoTo ErrHandler

Dim ll_Cursor As Long
Dim ls_req As String
Dim ll_CatId As Long
Dim ls_val As String
Dim la_Dates() As String

  UpdatePrice = 0
  
  la_Dates = Split(Trim(cbo_DateRange.SelectedItem.Key), "-")
  ll_CatId = cbo_Category_Filter(2).SelectedItem.Key
  
  ls_req = "exec DPC_Price_upd $PRC_Id$, $PCR_Id$, $PRD_Id$, $CT_Code$, $CURR_Code$, $VDateStart$, $VDateExp$, $QtyMin$, $QtyMax$," & _
            "$UM_CodeQ$,$PRC_Cost$,$UM_CodeC$,$U_Code$, $iConcurrency$"
      
  ls_req = Replace(ls_req, "$PRC_Id$", mo_Tools.SqlInt(mt_FlexGridData(al_Col, al_Row).PRC_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PCR_Id$", mo_Tools.SqlInt(mt_FlexGridData(al_Col, al_Row).PCR_Id), , , vbTextCompare)
      
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStr(txt_DetailKey(4)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CT_Code$", mo_Tools.SqlStr(cbo_CT_Code.SelectedItem.Key), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CURR_Code$", mo_Tools.SqlStr(cbo_CURR_Code.SelectedItem.Key), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
         
  ls_req = Replace(ls_req, "$QtyMin$", mo_Tools.SqlDbl(mt_FlexGridData(al_Col, al_Row).QMin), , , vbTextCompare)
  ls_req = Replace(ls_req, "$QtyMax$", mo_Tools.SqlDbl(mt_FlexGridData(al_Col, al_Row).QMax), , , vbTextCompare)
  
  ls_req = Replace(ls_req, "$UM_CodeQ$", mo_Tools.SqlStr(txt_UM_CodeQ), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRC_Cost$", mo_Tools.SqlDbl(ad_Price), , , vbTextCompare)
  ls_req = Replace(ls_req, "$UM_CodeC$", mo_Tools.SqlStr(txt_UM_CodeC), , , vbTextCompare)
  ls_req = Replace(ls_req, "$iConcurrency$", mo_Tools.SqlInt(mt_FlexGridData(al_Col, al_Row).iConcurrency), , , vbTextCompare)

  ls_req = ReplaceCommonPlaceholders(ls_req)
  ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  mo_Db.Close (ll_Cursor)
  
  mt_FlexGridData(al_Col, al_Row).Cost = ad_Price
  mt_FlexGridData(al_Col, al_Row).iConcurrency = mt_FlexGridData(al_Col, al_Row).iConcurrency + 1
  
  UpdatePrice = True
  Exit Function
  
ErrHandler:
  Call ErrorHandler("UpdatePrice")
End Function

Private Function InsertPrice(ByVal ad_Price As Double, ByVal al_Row As Long, ByVal al_Col As Long) As Boolean
On Error GoTo ErrHandler

Dim ll_Cursor As Long
Dim ls_req As String
Dim ll_CatId As Long
Dim ls_val As String
Dim ll_PRC_Id As Long
Dim la_Dates() As String

  InsertPrice = 0
  
  la_Dates = Split(Trim(cbo_DateRange.SelectedItem.Key), "-")
  ll_PRC_Id = mo_Tools.GetNextID(mo_Db, "DPC_Price")
    
  ll_CatId = cbo_Category_Filter(2).SelectedItem.Key
  
  ls_req = "exec DPC_Price_ins $PRC_Id$, $PCR_Id$, $PRD_Id$, $CT_Code$, $CURR_Code$, $VDateStart$, $VDateExp$, $QtyMin$, $QtyMax$," & _
            "$UM_CodeQ$,$PRC_Cost$,$UM_CodeC$,$U_Code$"
    
  ls_req = Replace(ls_req, "$PRC_Id$", mo_Tools.SqlInt(ll_PRC_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PCR_Id$", mo_Tools.SqlInt(mt_FlexGridData(al_Col, al_Row).PCR_Id), , , vbTextCompare)
      
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStr(txt_DetailKey(4)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CT_Code$", mo_Tools.SqlStr(cbo_CT_Code.SelectedItem.Key), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CURR_Code$", mo_Tools.SqlStr(cbo_CURR_Code.SelectedItem.Key), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
         
  ls_req = Replace(ls_req, "$QtyMin$", mo_Tools.SqlDbl(mt_FlexGridData(al_Col, al_Row).QMin), , , vbTextCompare)
  ls_req = Replace(ls_req, "$QtyMax$", mo_Tools.SqlDbl(mt_FlexGridData(al_Col, al_Row).QMax), , , vbTextCompare)
  
  ls_req = Replace(ls_req, "$UM_CodeQ$", mo_Tools.SqlStr(txt_UM_CodeQ), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRC_Cost$", mo_Tools.SqlDbl(ad_Price), , , vbTextCompare)
  ls_req = Replace(ls_req, "$UM_CodeC$", mo_Tools.SqlStr(txt_UM_CodeC), , , vbTextCompare)

  ls_req = ReplaceCommonPlaceholders(ls_req)
  ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  mo_Db.Close (ll_Cursor)
  
  mt_FlexGridData(al_Col, al_Row).PRC_Id = ll_PRC_Id
  mt_FlexGridData(al_Col, al_Row).Cost = ad_Price
  mt_FlexGridData(al_Col, al_Row).iConcurrency = 1

  InsertPrice = True
  Exit Function
  
ErrHandler:
  Call ErrorHandler("InsertPrice")
End Function

Private Function DeletePrice(ByVal al_Row As Long, ByVal al_Col As Long) As Boolean
On Error GoTo ErrHandler

Dim ll_Cursor As Long
Dim ls_req As String
Dim ll_CatId As Long
Dim ls_val As String

  DeletePrice = 0
    
  ll_CatId = cbo_Category_Filter(2).SelectedItem.Key
  
  ls_req = "exec DPC_Price_del $PRC_Id$,$U_Code$, $iConcurrency$"
    
  ls_req = Replace(ls_req, "$PRC_Id$", mo_Tools.SqlInt(mt_FlexGridData(al_Col, al_Row).PRC_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$iConcurrency$", mo_Tools.SqlInt(mt_FlexGridData(al_Col, al_Row).iConcurrency), , , vbTextCompare)

  ls_req = ReplaceCommonPlaceholders(ls_req)
  ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  mo_Db.Close (ll_Cursor)
  
  mt_FlexGridData(al_Col, al_Row).PRC_Id = -1
  mt_FlexGridData(al_Col, al_Row).Cost = -1

  DeletePrice = True
  Exit Function
  
ErrHandler:
  Call ErrorHandler("DeletePrice")
End Function

Public Function GetPriceMatrix() As Long
On Error GoTo ErrHandler

Dim ll_Cursor As Long
Dim ls_req As String
Dim ll_CatId As Long
Dim ls_val As String
Dim la_Dates() As String
Dim la_Qty() As String

  GetPriceMatrix = 0
  'If PanelQtyM2 <= 0 Then Exit Function
  'If MAT_Id = 0 Then Exit Function
  ll_CatId = cbo_Category_Filter(2).SelectedItem.Key
  la_Dates = Split(Trim(cbo_DateRange.SelectedItem.Key), "-")
  la_Qty = Split(Trim(cbo_QtyRange.SelectedItem.Key), "-")
  
  ls_req = "exec DPC_Price_lst4 $PRD_Id$, $PRD_IdPar$, $MAT_Id$, $PCR_Thick$, $CT_Code$, $CURR_Code$, $VDateStart$, $VDateExp$, $QtyMin$, $QtyMax$, $IsPrf$,$CoSid$,$GaCnt$, $Language_Code$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStr(txt_DetailKey(4)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_IdPar$", mo_Tools.SqlStr(txt_Price_PRD_Id2), , , vbTextCompare)
  If cbo_MAT_Id.SelectedItem Is Nothing Then
    ls_req = Replace(ls_req, "$MAT_Id$", "NULL", , , vbTextCompare)
  Else
    ls_req = Replace(ls_req, "$MAT_Id$", IIf(mo_Tools.SqlInt(cbo_MAT_Id.SelectedItem.Key) = 0, "NULL", mo_Tools.SqlInt(cbo_MAT_Id.SelectedItem.Key)), , , vbTextCompare)
  End If
  If cbo_Thick_Filter.SelectedItem Is Nothing Then
    ls_req = Replace(ls_req, "$PCR_Thick$", "NULL", , , vbTextCompare)
  Else
    ls_req = Replace(ls_req, "$PCR_Thick$", IIf(mo_Tools.SqlDbl(cbo_Thick_Filter.SelectedItem.Key) = 0, "NULL", mo_Tools.SqlDbl(cbo_Thick_Filter.SelectedItem.Key)), , , vbTextCompare)
  End If
  ls_req = Replace(ls_req, "$CT_Code$", mo_Tools.SqlStr(cbo_CT_Code.SelectedItem.Key), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CURR_Code$", mo_Tools.SqlStr(cbo_CURR_Code.SelectedItem.Key), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
  
  If ll_CatId = eDPCCategory.cgSurcharge Then
      ls_req = Replace(ls_req, "$IsPrf$", mo_Tools.SqlBool(cbo_filter.SelectedItem.Key = 2), , , vbTextCompare)
  Else
      ls_req = Replace(ls_req, "$IsPrf$", "NULL", , , vbTextCompare)
  End If
     
  If ll_CatId = eDPCCategory.cgCoating Then
      ls_req = Replace(ls_req, "$CoSid$", mo_Tools.SqlInt(cbo_filter.SelectedItem.Key), , , vbTextCompare)
  Else
      ls_req = Replace(ls_req, "$CoSid$", "NULL", , , vbTextCompare)
  End If
     
  If ll_CatId = eDPCCategory.cgGasket Then
      ls_req = Replace(ls_req, "$GaCnt$", mo_Tools.SqlInt(cbo_filter.SelectedItem.Key), , , vbTextCompare)
  Else
      ls_req = Replace(ls_req, "$GaCnt$", "NULL", , , vbTextCompare)
  End If
       
  If ll_CatId = eDPCCategory.cgMetalCustomPanelTemplate Then
      ls_req = Replace(ls_req, "$QtyMin$", mo_Tools.SqlDbl(la_Qty(0)), , , vbTextCompare)
      ls_req = Replace(ls_req, "$QtyMax$", mo_Tools.SqlDbl(la_Qty(1)), , , vbTextCompare)
  Else
      ls_req = Replace(ls_req, "$QtyMin$", "NULL", , , vbTextCompare)
      ls_req = Replace(ls_req, "$QtyMax$", "NULL", , , vbTextCompare)
  End If
  
  ls_req = ReplaceCommonPlaceholders(ls_req)
  ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  GetPriceMatrix = ll_Cursor
  Exit Function
ErrHandler:
  Call ErrorHandler("GetPriceMatrix")
End Function

Private Sub ShowPriceMatrix()
On Error GoTo ErrHandler

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

Private Sub LoadPriceMatrix(ByVal al_Cursor As Long)
On Error GoTo ErrHandler

Dim ls_ColName As String
Dim ls_RowName As String
Dim lo_Collection As New Collection
Dim ll_Idx As Long
Dim lv_Columns As Variant
Dim lb_Found As Boolean
Dim ll_RowIdx As Long, ll_ColIdx As Long
Dim ll_CatId As Long
Dim ll_NrOfRows As Long
Dim la_RowName() As String
Dim la_Qty() As String

Dim ls_Col_Part1, ls_Col_Part2, ls_Row_Part1, ls_Row_Part2 As String

  ReDim mt_FlexGridData(0, 0)
  
  ll_CatId = cbo_Category_Filter(2).SelectedItem.Key
  ReDim lv_Columns(0)
  lv_Columns(0) = "B \ A"

  If ll_CatId = eDPCCategory.cgMetalCustomPanelTemplate Then
    ls_Col_Part1 = "PCR_AMin"
    ls_Col_Part2 = "PCR_AMax"
    ls_Row_Part1 = "PCR_BMin"
    ls_Row_Part2 = "PCR_BMax"
  Else
    lv_Columns(0) = "QTY \ B"
    ls_Col_Part1 = "PCR_BMin"
    ls_Col_Part2 = "PCR_BMax"
    ls_Row_Part1 = "PRC_QMin"
    ls_Row_Part2 = "PRC_QMax"
  End If
  
  grd_PriceMatrix.Cols = 2
  grd_PriceMatrix.Rows = 2
  grd_PriceMatrix.RowHeight(0) = 2 * grd_PriceMatrix.RowHeight(1)
  Call grd_PriceMatrix.Clear
  grd_PriceMatrix.WordWrap = True
  mo_Db.SortFields(al_Cursor) = ls_Col_Part1
  Call mo_Db.First(al_Cursor)
  While Not mo_Db.EOF(al_Cursor)
    ls_ColName = mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Col_Part1)) & vbCrLf & mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Col_Part2))
    lb_Found = False
    For ll_Idx = 1 To UBound(lv_Columns)
      If lv_Columns(ll_Idx) = ls_ColName Then
        lb_Found = True
        Exit For
      End If
    Next
    If Not lb_Found Then
        If SafeUbound(lv_Columns) = -1 Then 'MW REDIM
            ReDim lv_Columns(UBound(lv_Columns) + 1)
        Else
            ReDim Preserve lv_Columns(UBound(lv_Columns) + 1)
        End If
      lv_Columns(UBound(lv_Columns)) = ls_ColName
    End If
    Call mo_Db.Next(al_Cursor)
  Wend
  
  grd_PriceMatrix.Cols = UBound(lv_Columns) + 1
  For ll_Idx = 0 To UBound(lv_Columns)
    grd_PriceMatrix.TextMatrix(0, ll_Idx) = lv_Columns(ll_Idx)
    If ll_Idx = 0 Then
      grd_PriceMatrix.ColWidth(ll_Idx) = 1500
    Else
      grd_PriceMatrix.ColWidth(ll_Idx) = 1000
    End If
    grd_PriceMatrix.ColAlignment(ll_Idx) = MSFlexGridLib.flexAlignCenterCenter
  Next
  
  ReDim mt_FlexGridData(UBound(lv_Columns), 0)  'MW REDIM
  ll_NrOfRows = 0
  
  mo_Db.SortFields(al_Cursor) = ls_Row_Part1
  Call mo_Db.First(al_Cursor)
  While Not mo_Db.EOF(al_Cursor)
  
    If mo_Db.GetFields(al_Cursor, ls_Row_Part1) <> 0 Or mo_Db.GetFields(al_Cursor, ls_Row_Part2) <> 0 Then
        ls_RowName = mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Row_Part1)) & " - " & mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Row_Part2))
        ls_ColName = mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Col_Part1)) & vbCrLf & mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Col_Part2))
        ll_RowIdx = SearchPriceMatrixRow(ls_RowName)
        ll_ColIdx = SearchPriceMatrixCol(ls_ColName)
        If ll_RowIdx < 0 Then
          If grd_PriceMatrix.TextMatrix(1, 0) <> "" Then
            Call grd_PriceMatrix.AddItem("")
          End If
          ll_RowIdx = grd_PriceMatrix.Rows - 1
          grd_PriceMatrix.TextMatrix(ll_RowIdx, 0) = ls_RowName
          ll_NrOfRows = ll_NrOfRows + 1
          
          'If UBound(mt_FlexGridData, 2) = -1 Then  'MW REDIM - this test is not needed, because the array is redimmed above with 0
          '  ReDim mt_FlexGridData(UBound(lv_Columns), ll_NrOfRows)
          'Else
            ReDim Preserve mt_FlexGridData(UBound(lv_Columns), ll_NrOfRows)
          'End If
    
        Else
        End If
        
        'this can happend for custom metal panels where no price is defined for some cell
        If mo_Db.GetFields(al_Cursor, "PRC_Id") = 0 Or mo_Db.GetFields(al_Cursor, "Drop_flag") = "X" Then
            la_Qty = Split(Trim(cbo_QtyRange.SelectedItem.Key), "-")
            grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) = "X"
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).PRC_Id = -1
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).Cost = -1
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).QMin = la_Qty(0)
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).QMax = la_Qty(1)
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).iConcurrency = 0
        Else
            grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) = mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, "PRC_Cost")) '& " (" & mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, "PCR_Thick")) & ")"
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).PRC_Id = mo_Db.GetFields(al_Cursor, "PRC_Id")
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).Cost = mo_Db.GetFields(al_Cursor, "PRC_Cost")
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).QMin = mo_Db.GetFields(al_Cursor, "PRC_QMin")
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).QMax = mo_Db.GetFields(al_Cursor, "PRC_QMax")
            mt_FlexGridData(ll_ColIdx, ll_RowIdx).iConcurrency = mo_Db.GetFields(al_Cursor, "iConcurrency")
        End If
        mt_FlexGridData(ll_ColIdx, ll_RowIdx).PCR_Id = mo_Db.GetFields(al_Cursor, "PCR_Id")
    End If
    Call mo_Db.Next(al_Cursor)
  Wend

  'we need to go trough loop one more time to fill in info for fields
  'which does not have any price defined
  Call mo_Db.First(al_Cursor)
  While Not mo_Db.EOF(al_Cursor)
  
    If mo_Db.GetFields(al_Cursor, ls_Row_Part1) = 0 And mo_Db.GetFields(al_Cursor, ls_Row_Part2) = 0 Then
        ls_ColName = mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Col_Part1)) & vbCrLf & mo_Tools.DblToScreen(mo_Db.GetFields(al_Cursor, ls_Col_Part2))
        ll_ColIdx = SearchPriceMatrixCol(ls_ColName)
        
        For ll_RowIdx = 1 To grd_PriceMatrix.Rows - 1
            la_RowName = Split(Trim(grd_PriceMatrix.TextMatrix(ll_RowIdx, 0)), "-")
            If grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) = "" And UBound(la_RowName) = 1 Then
                grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) = "X"
                mt_FlexGridData(ll_ColIdx, ll_RowIdx).Cost = -1
                mt_FlexGridData(ll_ColIdx, ll_RowIdx).PRC_Id = -1
                mt_FlexGridData(ll_ColIdx, ll_RowIdx).PCR_Id = mo_Db.GetFields(al_Cursor, "PCR_Id")
                mt_FlexGridData(ll_ColIdx, ll_RowIdx).QMin = la_RowName(0)
                mt_FlexGridData(ll_ColIdx, ll_RowIdx).QMax = la_RowName(1)
                mt_FlexGridData(ll_ColIdx, ll_RowIdx).iConcurrency = 0
            End If
        Next
    End If

    'If (mo_PrdConfig.RPL_A > Round(mo_Db.GetFields(al_Cursor, "PCR_AMin"), 2)) And _
    '   (mo_PrdConfig.RPL_A <= Round(mo_Db.GetFields(al_Cursor, "PCR_AMax"), 2)) And _
    '   (mo_PrdConfig.RPL_B > Round(mo_Db.GetFields(al_Cursor, "PCR_BMin"), 2)) And _
    '   (mo_PrdConfig.RPL_B <= Round(mo_Db.GetFields(al_Cursor, "PCR_BMax"), 2)) Then
    '   grd_PriceMatrix.Row = ll_RowIdx
    '   grd_PriceMatrix.Col = ll_ColIdx
    '   grd_PriceMatrix.CellBackColor = vbGreen
    'End If
    Call mo_Db.Next(al_Cursor)
  Wend
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadPriceMatrix")
End Sub

Private Function SearchPriceMatrixCol(ByVal as_colName As String) As Long
On Error GoTo ErrHandler

Dim ll_Idx As Long

  For ll_Idx = 1 To grd_PriceMatrix.Cols - 1
    If StrComp(grd_PriceMatrix.TextMatrix(0, ll_Idx), as_colName, vbTextCompare) = 0 Then
      SearchPriceMatrixCol = ll_Idx
      Exit Function
    End If
  Next
  SearchPriceMatrixCol = -1
  Exit Function
ErrHandler:
  Call ErrorHandler("SearchPriceMatrixCol")
End Function

Private Function SearchPriceMatrixRow(ByVal as_RowName As String) As Long
On Error GoTo ErrHandler

Dim ll_Idx As Long

  For ll_Idx = 1 To grd_PriceMatrix.Rows - 1
    If StrComp(grd_PriceMatrix.TextMatrix(ll_Idx, 0), as_RowName, vbTextCompare) = 0 Then
      SearchPriceMatrixRow = ll_Idx
      Exit Function
    End If
  Next
  SearchPriceMatrixRow = -1
  Exit Function
ErrHandler:
  Call ErrorHandler("SearchPriceMatrixRow")
End Function

Private Sub Load_ConfigInfo()
On Error GoTo ErrHandler

Dim ll_Index As Long
Dim ll_frameIndex As Long
    
    ReDim mt_MainConfig(6)
    ReDim mt_DetailConfig(8)
    ReDim mt_PriceCritForCategory(16)
    
    Call SetPriceCritForCategory(0, eDPCCategory.cgMetalCustomRectPanel, False, False, True, True, True, True, True, True, False, False, False, False, False)
    Call SetPriceCritForCategory(1, eDPCCategory.cgPerforation, False, False, False, False, True, True, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(2, eDPCCategory.cgGasket, False, False, False, False, True, True, False, False, False, False, False, True, False)
    Call SetPriceCritForCategory(3, eDPCCategory.cgPacking, False, False, False, False, False, False, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(4, eDPCCategory.cgInlay, False, False, False, False, False, False, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(5, eDPCCategory.cgCoating, False, False, False, False, False, False, False, False, False, False, False, False, True)
    Call SetPriceCritForCategory(6, eDPCCategory.cgVentilation, False, True, False, False, True, True, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(7, eDPCCategory.cgLoudspeaker, False, True, False, False, True, True, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(8, eDPCCategory.cgCutout, False, True, True, True, True, True, True, False, True, True, False, False, False)
    Call SetPriceCritForCategory(9, eDPCCategory.cgSubconstruction, False, False, False, False, True, True, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(10, eDPCCategory.cgSurcharge, True, False, False, False, False, False, False, False, False, False, True, False, False)
    Call SetPriceCritForCategory(11, eDPCCategory.cgBending, False, False, False, False, True, True, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(12, eDPCCategory.cgOption, False, False, False, False, True, True, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(13, eDPCCategory.cgSubconstructionArticle, False, False, False, False, False, False, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(14, eDPCCategory.cgMetalCustomPanelTemplate, True, False, True, True, True, True, True, True, False, False, False, False, False)
    Call SetPriceCritForCategory(15, eDPCCategory.cgLabeling, False, False, False, False, False, False, False, False, False, False, False, False, False)
    Call SetPriceCritForCategory(16, eDPCCategory.cgMetalPanelSKU, False, False, False, False, False, False, False, False, False, False, False, False, False)
        
    
    With mt_MainConfig(0)
        .FrameIndex = 0
        .IsMultiDetailView = True
        .CurrentDetailIndex = 0
        .Initialized = False
        .NameFrame = "DPC_Price"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 0
        .ToolbarID = 2835
        .RequestGrid = ""
    End With
    
    With mt_MainConfig(1)
        .FrameIndex = 1
        .IsMultiDetailView = True
        .CurrentDetailIndex = 1
        .Initialized = False
        .NameFrame = "DPC_PriceCrit"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 1
        .ToolbarID = 2848
        .RequestGrid = "exec DPC_PrdCommon_lst $Language_code$,$CAT_Id$,$PRD_Code$"
    End With
        
    With mt_MainConfig(2)
        .FrameIndex = 2
        .IsMultiDetailView = True
        .CurrentDetailIndex = 4
        .Initialized = False
        .NameFrame = "DPC_Price2"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 2
        .ToolbarID = 2934
        .RequestGrid = ""
    End With
        
    With mt_MainConfig(3)
        .FrameIndex = 3
        .IsMultiDetailView = True
        .CurrentDetailIndex = 5
        .Initialized = False
        .NameFrame = "DPC_HistPrdPrice"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 3
        .ToolbarID = 2958
        .RequestGrid = "exec DPC_HistPrdPrice_lst $Language_code$,$CT_Code$,$CURR_Code$,$PRD_Code$,$PRD_Name$"
    End With
    
    With mt_MainConfig(4)
        .FrameIndex = 4
        .IsMultiDetailView = True
        .CurrentDetailIndex = 6
        .Initialized = False
        .NameFrame = "DPC_HistSysPrice"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 4
        .ToolbarID = 2960
        .RequestGrid = "exec DPC_HistSysPrice_lst $Language_code$, $CT_Code$,$CURR_Code$,$SYS_Name$"
    End With
        
    With mt_MainConfig(5)
        .FrameIndex = 5
        .IsMultiDetailView = True
        .CurrentDetailIndex = 7
        .Initialized = False
        .NameFrame = "DPC_SysMargin"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 5
        .ToolbarID = 2966
        .RequestGrid = "exec DPC_SysMargin_lst $CT_Code$,$SYS_Id$,$Language_code$"
    End With
        
    With mt_MainConfig(6)
        .FrameIndex = 6
        .IsMultiDetailView = True
        .CurrentDetailIndex = 8
        .Initialized = False
        .NameFrame = "DPC_Cost"
        .ViewCode = ""
        .GridDelayMethod = eGridLoadMethod.egmDelayedExceptLastLevel
        .CurrentTvwSelMethod = etmNone
        .ToolbarFace = "0"
        .ToolbarIndex = 6
        .ToolbarID = 2971
        .RequestGrid = ""
    End With
        
    With mt_DetailConfig(0)
        .FrameIndex = 0
        .NameFrame = "DPC_Price"
        .MainConfigIndex = 0
        .DetailKey = 0
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_Price_sel $Key1$, $Language_code$"
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "" 'we do not want insert detail, only subdetails
        .ToolbarIndex = 0
        .ToolbarID = 2836
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        '.ListFieldsDefaultValue(0) = Array(txt_CUT_MinJ, 0)
        '.ListFieldsDefaultValue(1) = Array(txt_CUT_MinK, 0)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        '.ListFieldsMandatory(0) = Array(txt_CUT_Name, 67)
        '.ListFieldsMandatory(1) = Array(txt_CUT_Desc, 69)
        '.ListFieldsMandatory(2) = Array(txt_CUT_Order, 68)
        '.ListFieldsMandatory(3) = Array(cbo_Shape(2), 70)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(0)
        Set .ListFieldsToDisable(1) = txt_Price_CAT_Name
        Set .ListFieldsToDisable(2) = txt_Price_PRD_Name(0)
        Set .ListFieldsToDisable(3) = txt_Price_SYS_Name
        
        .MainGridColumns = Array( _
            "PRD_Id®©0®©0®©PRD_Id®©#PRD_Id", "PCR_Id®©0®©1®©PCR_Id®©#PCR_Id", _
            "PRD_Code®©1000®©0®©PRD_Code®©#PRD_Code", _
            "PRD_Name®©1000®©0®©PRD_Name®©#PRD_Name", _
            "PRD_IdPar®©0®©0®©PRD_IdPar®©#PRD_IdPar", _
            "CUA_Id®©0®©0®©CUA_Id®©#CUA_Id", _
            "CUA_Desc®©1000®©0®©CUA_Desc®©#CUA_Desc", _
            "MAT_Id®©0®©0®©MAT_Id®©#MAT_Id", "MAT_Name®©1000®©0®©MAT_Name®©#MAT_Name", _
            "SYS_Name®©1000®©0®©SYS_Name®©#SYS_Name", _
            "PCR_AMin®©1000®©0®©PCR_AMin®©#PCR_AMin", "PCR_AMax®©1000®©0®©PCR_AMax®©#PCR_AMax", _
            "PCR_BMin®©1000®©0®©PCR_BMin®©#PCR_BMin", "PCR_BMax®©1000®©0®©PCR_BMax®©#PCR_BMax", _
            "PCR_Thick®©1000®©0®©PCR_Thick®©#PCR_Thick", _
            "PCR_TMin®©1000®©0®©PCR_TMin®©#PCR_TMin", "PCR_TMax®©1000®©0®©PCR_TMax®©#PCR_TMax", _
            "PCR_IsPrf®©1000®©0®©PCR_IsPrf®©#PCR_IsPrf", _
            "PCR_GaCnt®©1000®©0®©PCR_GaCnt®©#PCR_GaCnt", _
            "PCR_CoSid®©1000®©0®©PCR_CoSid®©#PCR_CoSid", _
            "CT_Code®©700®©0®©CT_Code®©#CT_Code", _
            "CURR_Code®©700®©0®©CURR_Code®©#CURR_Code", _
            "PRC_QMin®©800®©0®©PRC_QMin®©#PRC_QMin", "PRC_QMax®©800®©0®©PRC_QMax®©#PRC_QMax", "UM_CodeQ®©800®©0®©UM_CodeQ®©#UM_CodeQ", _
            "PRC_VStart®©1000®©0®©PRC_VStart®©#PRC_VStart", "PRC_VExp®©1000®©0®©PRC_VExp®©#PRC_VExp", _
            "PRC_Cost®©1000®©0®©PRC_Cost®©#PRC_Cost", "UM_CodeC®©800®©0®©UM_CodeC®©#UM_CodeC", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")

        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(1)
        .FrameIndex = 1
        .NameFrame = "DPC_PriceCrit"
        .MainConfigIndex = 1
        .DetailKey = 1
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_PrdCommon_sel $Key1$, $Language_Code$"

        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "DPC_PriceCrit"
        .ToolbarIndex = 1
        .ToolbarID = 2849
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(1)
        Set .ListFieldsToDisable(1) = txt_PRC_PRD_Name
        Set .ListFieldsToDisable(2) = txt_CAT_Name
        Set .ListFieldsToDisable(3) = txt_PRC_PRD_Code
        
        .MainGridColumns = Array( _
            "PRD_Id®©0®©1®©PRD_Id®©#PRD_Id", _
            "PRD_Code®©1000®©0®©PRD_Code®©#PRD_Code", _
            "PRD_Name®©1000®©0®©PRD_Name®©#PRD_Name", _
            "CAT_Name®©2000®©0®©CAT_Name®©#CAT_Name", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")

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

        .RequestView = ""
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "DPC_PriceCrit"
        .ToolbarIndex = 2
        .ToolbarID = 2821
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(0)
        Set .ListFieldsToDisable(0) = txt_DetailKey(2)
        
        .MainGridColumns = Null
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(3)
        .FrameIndex = 3
        .NameFrame = "DPC_PriceImport"
        .MainConfigIndex = 3
        .DetailKey = 3
        .ClearControlsBeforeInit = False

        .RequestView = ""
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "DPC_PriceImport"
        .ToolbarIndex = 3
        .ToolbarID = 2856
        .ToolbarFaces = Array("0", "1", "2", "3")
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(0)
        Set .ListFieldsToDisable(0) = txt_DetailKey(3)
        
        .MainGridColumns = Array( _
            "MSG_Id®©0®©1®©MSG_Id®©#MSG_Id", _
            "MSG_Text®©3500®©0®©MSG_Text®©#MSG_Text", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")
        
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(4)
        .FrameIndex = 4
        .NameFrame = "DPC_Price2"
        .MainConfigIndex = 2
        .DetailKey = 4
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_Price_sel3 $Language_code$,$Key1$,$Key2$,$Key4$"
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "" 'we do not want insert detail, only subdetails
        .ToolbarIndex = 4
        .ToolbarID = 2935
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        '.ListFieldsDefaultValue(0) = Array(txt_CUT_MinJ, 0)
        '.ListFieldsDefaultValue(1) = Array(txt_CUT_MinK, 0)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(7)
        Set .ListFieldsToDisable(0) = txt_DetailKey(4)
        Set .ListFieldsToDisable(1) = txt_PRD_NamePar
        Set .ListFieldsToDisable(2) = txt_Price_PRD_Name(1)
        Set .ListFieldsToDisable(3) = txt_UM_CodeQ
        Set .ListFieldsToDisable(4) = txt_UM_CodeC
        Set .ListFieldsToDisable(5) = txt_Price_PRD_Id2
        Set .ListFieldsToDisable(6) = txt_CAT_Id
        
        .MainGridColumns = Array( _
            "CAT_Id®©0®©1®©CAT_Id®©#CAT_Id", _
            "PRD_Id®©0®©1®©PRD_Id®©#PRD_Id", _
            "PRD_Code®©1000®©1®©PRD_Code®©#PRD_Code", _
            "PRD_IdPar®©0®©1®©PRD_IdPar®©#PRD_IdPar", _
            "PRD_Name®©2000®©0®©PRD_Name®©#PRD_Name", _
            "PRD_NamePar®©2000®©0®©PRD_NamePar®©#PRD_NamePar", _
            "SYS_Name®©1000®©0®©SYS_Name®©#SYS_Name", _
            "RPL_ModA®©1000®©0®©RPL_ModA®©#RPL_ModA", _
            "RPL_ModB®©1000®©0®©RPL_ModB®©#RPL_ModB", _
            "RPL_A®©1000®©0®©RPL_A®©#RPL_A", _
            "RPL_B®©1000®©0®©RPL_B®©#RPL_B", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")
                
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(5)
        .FrameIndex = 5
        .NameFrame = "DPC_HistPrdPrice"
        .MainConfigIndex = 3
        .DetailKey = 5
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_HistPrdPrice_sel $Key1$,$Key2$,$Language_code$"
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "" 'we do not want insert detail, only subdetails
        .ToolbarIndex = 5
        .ToolbarID = 2959
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        '.ListFieldsDefaultValue(0) = Array(txt_CUT_MinJ, 0)
        '.ListFieldsDefaultValue(1) = Array(txt_CUT_MinK, 0)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(5)
        Set .ListFieldsToDisable(1) = txt_HPP_PRD_Name
        Set .ListFieldsToDisable(2) = cbo_HPP_CT_Code
        Set .ListFieldsToDisable(3) = cbo_HPP_CURR_Code
        
        .MainGridColumns = Array( _
            "CT_Code®©1500®©1®©CT_Code®©#CT_Code", _
            "PRD_Id®©0®©1®©PRD_Id®©#PRD_Id", _
            "PRD_Name®©2000®©0®©PRD_Name®©#PRD_Name", _
            "CURR_Code®©1500®©0®©CURR_Code®©#CURR_Code", _
            "HPP_Price®©1500®©0®©HPP_Price®©#HPP_Price", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")
                
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(6)
        .FrameIndex = 6
        .NameFrame = "DPC_HistSysPrice"
        .MainConfigIndex = 4
        .DetailKey = 6
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_HistSysPrice_sel $Key1$,$Key2$,$Key3$,$Language_code$"
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "" 'we do not want insert detail, only subdetails
        .ToolbarIndex = 6
        .ToolbarID = 2961
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        '.ListFieldsDefaultValue(0) = Array(txt_CUT_MinJ, 0)
        '.ListFieldsDefaultValue(1) = Array(txt_CUT_MinK, 0)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(4)
        Set .ListFieldsToDisable(0) = txt_DetailKey(6)
        Set .ListFieldsToDisable(1) = txt_HPP_SYS_Name
        Set .ListFieldsToDisable(2) = cbo_HSP_CT_Code
        Set .ListFieldsToDisable(3) = cbo_HSP_CURR_Code
        Set .ListFieldsToDisable(4) = txt_PRF_Class
        
        .MainGridColumns = Array( _
            "CT_Code®©0®©1®©CT_Code®©#CT_Code", _
            "SYS_Id®©0®©1®©SYS_Id®©#SYS_Id", _
            "SYS_Name®©2000®©0®©SYS_Name®©#SYS_Name", _
            "PRF_Class®©1000®©1®©PRF_Class®©#PRF_Class", _
            "CURR_Code®©1500®©0®©CURR_Code®©#CURR_Code", _
            "HSP_Price®©1500®©0®©HSP_Price®©#HSP_Price", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")
                
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(7)
        .FrameIndex = 7
        .NameFrame = "DPC_SysMargin"
        .MainConfigIndex = 5
        .DetailKey = 7
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_SysMargin_sel $Key1$,$Language_code$"
        .RequestAdd = "exec DPC_SysMargin_ins $CT_Code$,$SYS_Id$,$SMA_PanMargin$,$SMA_PanGTN$,$SMA_PanMin$,$SMA_SubMargin$,$SMA_SubGTN$,$SMA_SubMin$,$CURR_Code$,$Z_creator$"
        .RequestUpd = "exec DPC_SysMargin_upd $CT_Code$,$SYS_Id$,$SMA_PanMargin$,$SMA_PanGTN$,$SMA_PanMin$,$SMA_SubMargin$,$SMA_SubGTN$,$SMA_SubMin$,$CURR_Code$,$Z_last_upd_user$,$iConcurrency$"
        .RequestDel = "exec DPC_SysMargin_del $CT_Code$,$Z_last_upd_user$,$iConcurrency$"
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "" 'we do not want insert detail, only subdetails
        .ToolbarIndex = 7
        .ToolbarID = 2967
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(6)
        .ListFieldsMandatory(0) = Array(txt_SMA_PanMargin, 38)
        .ListFieldsMandatory(1) = Array(txt_SMA_PanGTN, 40)
        .ListFieldsMandatory(2) = Array(txt_SMA_PanMin, 41)
        .ListFieldsMandatory(3) = Array(txt_SMA_SubMargin, 37)
        .ListFieldsMandatory(4) = Array(txt_SMA_SubGTN, 32)
        .ListFieldsMandatory(5) = Array(txt_SMA_SubMin, 39)
        .ListFieldsMandatory(6) = Array(cbo_SMA_CURR_Code, 42)
        
        ReDim .ListFieldsToDisable(2)
        Set .ListFieldsToDisable(0) = txt_DetailKey(7)
        Set .ListFieldsToDisable(1) = txt_SMA_Sys_Name
        Set .ListFieldsToDisable(2) = txt_SMA_Country
        
        .MainGridColumns = Array( _
            "CT_Code®©0®©1®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#CT_Desc", _
            "SYS_Id®©0®©0®©SYS_Id®©#SYS_Id", _
            "SYS_Name®©0®©0®©SYS_Name®©#SYS_Name", _
            "SMA_PanMargin®©1000®©0®©SMA_PanMargin®©#SMA_PanMargin", _
            "SMA_SubMargin®©1000®©0®©SMA_SubMargin®©#SMA_SubMargin", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#Creation date")
                
        ReDim .InitControls(-1 To -1)
        'control, tag, visible, request, maxlength
    End With
    
    With mt_DetailConfig(8)
        .FrameIndex = 8
        .NameFrame = "DPC_Cost"
        .MainConfigIndex = 6
        .DetailKey = 8
        .ClearControlsBeforeInit = True

        .RequestView = "exec DPC_Price_sel $Key1$, $Language_code$"
        .RequestAdd = ""
        .RequestUpd = ""
        .RequestDel = ""
        
        .AffectedCount = Array(-1, -1, -1, -1)
        
        .UseTransaction = True
        .TableName = "" 'we do not want insert detail, only subdetails
        .ToolbarIndex = 8
        .ToolbarID = 2972
        .ToolbarFaces = Array("0", "1", "2", "3")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        
        ReDim .ListFieldsToDisable(3)
        Set .ListFieldsToDisable(0) = txt_DetailKey(8)
        Set .ListFieldsToDisable(1) = txt_Cost_CAT_Name
        Set .ListFieldsToDisable(2) = txt_Price_PRD_Name(2)
        Set .ListFieldsToDisable(3) = txt_Cost_SYS_Name
        
        .MainGridColumns = Array( _
            "PRD_Id®©0®©0®©PRD_Id®©#PRD_Id", "PCR_Id®©0®©1®©PCR_Id®©#PCR_Id", _
            "PRD_Code®©1000®©0®©PRD_Code®©#PRD_Code", _
            "PRD_Name®©1000®©0®©PRD_Name®©#PRD_Name", _
            "PRD_IdPar®©0®©0®©PRD_IdPar®©#PRD_IdPar", _
            "CUA_Id®©0®©0®©CUA_Id®©#CUA_Id", _
            "CUA_Desc®©1000®©0®©CUA_Desc®©#CUA_Desc", _
            "MAT_Id®©0®©0®©MAT_Id®©#MAT_Id", "MAT_Name®©1000®©0®©MAT_Name®©#MAT_Name", _
            "SYS_Name®©1000®©0®©SYS_Name®©#SYS_Name", _
            "PCR_AMin®©1000®©0®©PCR_AMin®©#PCR_AMin", "PCR_AMax®©1000®©0®©PCR_AMax®©#PCR_AMax", _
            "PCR_BMin®©1000®©0®©PCR_BMin®©#PCR_BMin", "PCR_BMax®©1000®©0®©PCR_BMax®©#PCR_BMax", _
            "PCR_Thick®©1000®©0®©PCR_Thick®©#PCR_Thick", _
            "PCR_TMin®©1000®©0®©PCR_TMin®©#PCR_TMin", "PCR_TMax®©1000®©0®©PCR_TMax®©#PCR_TMax", _
            "PCR_IsPrf®©1000®©0®©PCR_IsPrf®©#PCR_IsPrf", _
            "PCR_GaCnt®©1000®©0®©PCR_GaCnt®©#PCR_GaCnt", _
            "PCR_CoSid®©1000®©0®©PCR_CoSid®©#PCR_CoSid", _
            "VEN_Id®©0®©0®©VEN_Id®©#VEN_Id", _
            "VEN_Name®©1200®©0®©VEN_Name®©#VEN_Name", _
            "CURR_Code®©700®©0®©CURR_Code®©#CURR_Code", _
            "PRC_QMin®©800®©0®©PRC_QMin®©#PRC_QMin", "PRC_QMax®©800®©0®©PRC_QMax®©#PRC_QMax", "UM_CodeQ®©800®©0®©UM_CodeQ®©#UM_CodeQ", _
            "PRC_VStart®©1000®©0®©PRC_VStart®©#PRC_VStart", "PRC_VExp®©1000®©0®©PRC_VExp®©#PRC_VExp", _
            "PRC_Cost®©1000®©0®©PRC_Cost®©#PRC_Cost", "UM_CodeC®©800®©0®©UM_CodeC®©#UM_CodeC", _
            "Z_Creator®©0®©0®©Z_Creator®©#Z_Creator", _
            "Z_Creation®©1000®©0®©Z_Creation®©#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.etmNone
        ll_frameIndex = mt_MainConfig(ll_Index).FrameIndex
        cmd_TVReLoad(ll_frameIndex).Picture = mo_Tools.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(2)
    
    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 = "DPC_Price"
        .DetailConfigIndex = 0
        .Initialized = False
        
        .RequestView = "exec DPC_Price_lst2 $Key1$,$Language_Code$,NULL,NULL"
        .RequestAdd = "exec DPC_Price_ins $PRC_Id$,$PCR_Id$,$PRD_Id$,$CT_Code$,$CURR_Code$,$PRC_VStart$,$PRC_VExp$,$PRC_QMin$,$PRC_QMax$,$UM_CodeQ$,$PRC_Cost$,$UM_CodeC$,$U_Code$"
        .RequestUpd = "exec DPC_Price_upd $PRC_Id$,$PCR_Id$,$PRD_Id$,$CT_Code$,$CURR_Code$,$PRC_VStart$,$PRC_VExp$,$PRC_QMin$,$PRC_QMax$,$UM_CodeQ$,$PRC_Cost$,$UM_CodeC$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec DPC_Price_del $PRC_Id$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = ""
        .RequestCheckUpdate = ""
        
        .TableName = "DPC_Price"
        .TableOrder = ""
        
        .ToolbarID = 2851
        .ToolbarIndex = 0
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PRC_Id®©0®©1®©PRC_Id®©PRC_Id", _
            "PCR_Id®©0®©0®©PCR_Id®©#PCR_Id", _
            "PRD_Id®©0®©0®©PRD_Id®©#PRD_Id", _
            "CT_Code®©0®©0®©CT_Code®©#CT_Code", _
            "CT_Desc®©1000®©0®©CT_Desc®©#CT_Desc", _
            "CURR_Code®©0®©0®©CURR_Code®©#CURR_Code", _
            "CURR_Desc®©1000®©0®©CURR_Desc®©#CURR_Desc", _
            "PRC_VStart®©1000®©0®©PRC_VStart®©#PRC_VStart", _
            "PRC_VExp®©1000®©0®©PRC_VExp®©#PRC_VExp", _
            "PRC_QMin®©1000®©0®©PRC_QMin®©#PRC_QMin", _
            "PRC_QMax®©1000®©0®©PRC_QMax®©#PRC_QMax", _
            "UM_CodeQ®©0®©0®©UM_CodeQ®©#UM_CodeQ", _
            "UM_DescQ®©1000®©0®©UM_DescQ®©#UM_DescQ", _
            "PRC_Cost®©1000®©0®©PRC_Cost®©#PRC_Cost", _
            "UM_CodeC®©0®©0®©UM_CodeC®©#UM_CodeC", _
            "UM_DescC®©1000®©0®©UM_DescC®©#UM_DescC", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(8)
        .ListFieldsMandatory(0) = Array(cbo_Countries(0), 202)
        .ListFieldsMandatory(1) = Array(cbo_Currency(0), 80)
        .ListFieldsMandatory(2) = Array(cbo_UM_Code(0), 81)
        .ListFieldsMandatory(3) = Array(cal_Price_VStart, 87)
        .ListFieldsMandatory(4) = Array(cal_Price_VEnd, 82)
        .ListFieldsMandatory(5) = Array(txt_QtyMin, 89)
        .ListFieldsMandatory(6) = Array(txt_QtyMax, 86)
        .ListFieldsMandatory(7) = Array(cbo_UM_Code(1), 0)
        .ListFieldsMandatory(8) = Array(txt_PriceM2, 88)
        
        ReDim .ListFieldsToDisable(-1 To -1)
    End With

    With mt_SubdetailConfig(1)
        .FrameIndex = 1
        .NameFrame = "DPC_PriceCrit"
        .DetailConfigIndex = 1
        .Initialized = False
        
        .RequestView = "exec DPC_PriceCrit_lst2 $Key1$,NULL,$Language_Code$"
        .RequestAdd = "exec DPC_PriceCrit_ins $PCR_Id$,$PRD_Id$,$PRD_IdPar$,$CUA_Id$,$PCR_AMin$,$PCR_AMax$,$PCR_BMin$,$PCR_BMax$,$MAT_Id$,$PCR_Thick$,$PCR_TMin$,$PCR_TMax$,$PCR_IsPrf$,$PCR_GaCnt$,$PCR_CoSid$,$U_Code$"
        .RequestUpd = "exec DPC_PriceCrit_upd $PCR_Id$,$PRD_Id$,$PRD_IdPar$,$CUA_Id$,$PCR_AMin$,$PCR_AMax$,$PCR_BMin$,$PCR_BMax$,$MAT_Id$,$PCR_Thick$,$PCR_TMin$,$PCR_TMax$,$PCR_IsPrf$,$PCR_GaCnt$,$PCR_CoSid$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec DPC_PriceCrit_del $PCR_Id$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = ""
        .RequestCheckUpdate = ""
        
        .TableName = "DPC_PriceCrit"
        .TableOrder = ""
        
        .ToolbarID = 2850
        .ToolbarIndex = 1
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PCR_Id®©1000®©1®©PCR_Id®©#PCR_Id", _
            "PRD_Code®©0®©0®©PRD_Code®©#PRD_Code", _
            "PRD_IdPar®©800®©0®©PRD_IdPar®©#PRD_IdPar", _
            "CUA_Id®©0®©0®©CUA_Id®©#CUA_Id", _
            "CUA_Desc®©800®©0®©CUA_Desc®©#CUA_Desc", _
            "PCR_AMin®©800®©0®©PCR_AMin®©#PCR_AMin", _
            "PCR_AMax®©800®©0®©PCR_AMax®©#PCR_AMax", _
            "PCR_BMin®©800®©0®©PCR_BMin®©#PCR_BMin", _
            "PCR_BMax®©800®©0®©PCR_BMax®©#PCR_BMax", _
            "MAT_Id®©0®©0®©MAT_Id®©#MAT_Id", _
            "MAT_Name®©1000®©0®©MAT_Name®©#MAT_Name", _
            "PCR_Thick®©800®©0®©PCR_Thick®©#PCR_Thick", _
            "PCR_TMin®©800®©0®©PCR_TMin®©#PCR_TMin", _
            "PCR_TMax®©800®©0®©PCR_TMax®©#PCR_TMax", _
            "PCR_IsPrf®©800®©0®©PCR_IsPrf®©#PCR_IsPrf", _
            "PCR_GaCnt®©800®©0®©PCR_GaCnt®©#PCR_GaCnt", _
            "PCR_CoSid®©800®©0®©PCR_CoSid®©#PCR_CoSid", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(-1 To -1)
        '.ListFieldsMandatory(0) = Array(txt_PRD_IdPar, 192)
        '.ListFieldsMandatory(1) = Array(cbo_CutArea, 191)
        '.ListFieldsMandatory(2) = Array(txt_PCR_Thick, 186)
        '.ListFieldsMandatory(3) = Array(txt_PCR_AMin, 190)
        '.ListFieldsMandatory(4) = Array(txt_PCR_AMax, 187)
        '.ListFieldsMandatory(5) = Array(txt_PCR_TMin, 184)
        '.ListFieldsMandatory(6) = Array(txt_PCR_TMax, 182)
        '.ListFieldsMandatory(7) = Array(cbo_Material(0), 188)
        
        ReDim .ListFieldsToDisable(-1 To -1)
    End With

    With mt_SubdetailConfig(2)
        .FrameIndex = 2
        .NameFrame = "DPC_Cost"
        .DetailConfigIndex = 8
        .Initialized = False
        
        .RequestView = "exec DPC_Cost_lst2 $Key1$,$Language_Code$,NULL,NULL"
        .RequestAdd = "exec DPC_Cost_ins $PRC_Id$,$PCR_Id$,$PRD_Id$,$VEN_Id$,$CURR_Code$,$PRC_VStart$,$PRC_VExp$,$PRC_QMin$,$PRC_QMax$,$UM_CodeQ$,$PRC_Cost$,$UM_CodeC$,$U_Code$"
        .RequestUpd = "exec DPC_Cost_upd $PRC_Id$,$PCR_Id$,$PRD_Id$,$VEN_Id$,$CURR_Code$,$PRC_VStart$,$PRC_VExp$,$PRC_QMin$,$PRC_QMax$,$UM_CodeQ$,$PRC_Cost$,$UM_CodeC$,$U_Code$,$iConcurrency$"
        .RequestDel = "exec DPC_Cost_del $PRC_Id$,$U_Code$,$iConcurrency$"
        
        .RequestCheckAdd = ""
        .RequestCheckUpdate = ""
        
        .TableName = "DPC_Cost"
        .TableOrder = ""
        
        .ToolbarID = 2973
        .ToolbarIndex = 2
        .ToolbarFaces = Array("0", "1", "2", "3", "4")
        
        .GridColumns = Array( _
            "PRC_Id®©0®©1®©PRC_Id®©PRC_Id", _
            "PCR_Id®©0®©0®©PCR_Id®©#PCR_Id", _
            "PRD_Id®©0®©0®©PRD_Id®©#PRD_Id", _
            "VEN_Id®©0®©0®©VEN_Id®©#VEN_Id", _
            "VEN_Name®©1000®©0®©VEN_Name®©#VEN_Name", _
            "CURR_Code®©0®©0®©CURR_Code®©#CURR_Code", _
            "CURR_Desc®©1000®©0®©CURR_Desc®©#CURR_Desc", _
            "PRC_VStart®©1000®©0®©PRC_VStart®©#PRC_VStart", _
            "PRC_VExp®©1000®©0®©PRC_VExp®©#PRC_VExp", _
            "PRC_QMin®©1000®©0®©PRC_QMin®©#PRC_QMin", _
            "PRC_QMax®©1000®©0®©PRC_QMax®©#PRC_QMax", _
            "UM_CodeQ®©0®©0®©UM_CodeQ®©#UM_CodeQ", _
            "UM_DescQ®©1000®©0®©UM_DescQ®©#UM_DescQ", _
            "PRC_Cost®©1000®©0®©PRC_Cost®©#PRC_Cost", _
            "UM_CodeC®©0®©0®©UM_CodeC®©#UM_CodeC", _
            "UM_DescC®©1000®©0®©UM_DescC®©#UM_DescC", _
            "RowStatus®©0®©0®©RowStatus®©#RowStatus", _
            "iConcurrency®©0®©0®©iConcurrency®©iConcurrency")
        
        ReDim .ListFieldsDefaultValue(-1 To -1)
        
        ReDim .ListFieldsMandatory(8)
        .ListFieldsMandatory(0) = Array(cbo_Vendor, 51)
        .ListFieldsMandatory(1) = Array(cbo_Currency(1), 50)
        .ListFieldsMandatory(2) = Array(cbo_UM_Code(2), 49)
        .ListFieldsMandatory(3) = Array(cal_Cost_VStart, 46)
        .ListFieldsMandatory(4) = Array(cal_Cost_VEnd, 45)
        .ListFieldsMandatory(5) = Array(txt_QtyMin, 48)
        .ListFieldsMandatory(6) = Array(txt_QtyMax, 47)
        .ListFieldsMandatory(7) = Array(cbo_UM_Code(3), 43)
        .ListFieldsMandatory(8) = Array(txt_PriceM2, 44)
        
        ReDim .ListFieldsToDisable(-1 To -1)
    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"
    Case "B", "C"
    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
    
    tlb_Subdetail_CustomAction = False
    ll_SubdetailIndex = FindSubDetailConfigByFrameIndex(Index)
    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
        
        Select Case as_Role
        Case "P"
        Case "g"
        End Select
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("tlb_Subdetail_CustomAction")
End Function

Private Function FindDetailConfigByTableType(ByVal ae_TableType As eTableType) As Long
On Error GoTo ErrHandler

    Select Case ae_TableType
    Case eTableType.ttDPC_Price
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_Price")
    Case eTableType.ttDPC_PriceCrit
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_PriceCrit")
    Case eTableType.ttDPC_Price2
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_Price2")
    Case eTableType.ttDPC_HistPrdPrice
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_HistPrdPrice")
    Case eTableType.ttDPC_HistSysPrice
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_HistSysPrice")
    Case eTableType.ttDPC_SysMargin
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_SysMargin")
    Case eTableType.ttDPC_Cost
        FindDetailConfigByTableType = FindDetailConfigByName("DPC_Cost")
    Case Else
        Err.Raise ArmErr.CompFncFailed, "ae_TableType", "Unknown table type : " & ae_TableType
    End Select
    Exit Function
ErrHandler:
    Call ErrorHandler("FindDetailConfigByTableType")
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, "DPC_Ref", vbTextCompare) = 0 Then
        If grd_Main(Index).SelectedCount = 1 Then
            mt_MainConfig(ll_MainIndex).CurrentDetailIndex = FindDetailConfigByTableType(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
    Dim ls_Request As String
    Dim ll_Cursor As Long
    Dim lv_FilterVal As Variant
    Dim ls_Dates() As String
    Dim ls_Key As String
    
    ll_DetailFrameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    
    If ae_Mode <> emAdd Then
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_Price" Then
            ls_Request = ReplaceCommonPlaceholders("exec DPC_PriceCrit_sel $Key1$, $Language_code$")
            'ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(0))
            ls_Request = ReplaceKeyPlaceholders(ls_Request, av_Key)

            Call RefreshPriceCritGrid(0, ls_Request, cbo_Category_Filter(0).SelectedItem.Key)
            
        End If
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_Cost" Then
            ls_Request = ReplaceCommonPlaceholders("exec DPC_PriceCrit_sel $Key1$, $Language_code$")
            'ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(0))
            ls_Request = ReplaceKeyPlaceholders(ls_Request, av_Key)

            Call RefreshPriceCritGrid(2, ls_Request, cbo_Category_Filter(3).SelectedItem.Key)
            
        End If
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_PriceCrit_Sel" Then
            ls_Request = ReplaceCommonPlaceholders("exec DPC_PriceCrit_lst3 $CAT_Id$ $Language_code$")
            ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(1))

            Call RefreshPriceCritGrid(0, ls_Request, txt_DetailKey(1).Text)
        End If
        
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_Price2" Then
            mb_InternalInit = True
            If cbo_Category_Filter(2).SelectedItem.Key = eDPCCategory.cgMetalCustomPanelTemplate Then
                cbo_QtyRange.Visible = True
                lbl_Label(9).Visible = True
                
                cbo_MAT_Id.Visible = True
                lbl_Label(12).Visible = True
                
                cbo_Thick_Filter.Visible = True
                lbl_Label(11).Visible = True
            Else
                cbo_QtyRange.Visible = False
                lbl_Label(9).Visible = False
            
                cbo_MAT_Id.Visible = False
                lbl_Label(12).Visible = False
            
                cbo_Thick_Filter.Visible = False
                lbl_Label(11).Visible = False
            End If
            
            cbo_filter.Clear
            
            If cbo_Category_Filter(2).SelectedItem.Key = eDPCCategory.cgSurcharge Then
                cbo_filter.Enabled = True
                lv_FilterVal = Array(1, "No Perf")
                Call cbo_filter.AddItem(lv_FilterVal)
                lv_FilterVal = Array(2, "Perf")
                Call cbo_filter.AddItem(lv_FilterVal)
                Call cbo_filter.SearchItem(1)
            ElseIf cbo_Category_Filter(2).SelectedItem.Key = eDPCCategory.cgCoating Then
                cbo_filter.Enabled = True
                lv_FilterVal = Array(1, "CoSid = 1")
                Call cbo_filter.AddItem(lv_FilterVal)
                lv_FilterVal = Array(1, "CoSid = 2")
                Call cbo_filter.AddItem(lv_FilterVal)
                lv_FilterVal = Array(1, "CoSid = 3")
                Call cbo_filter.AddItem(lv_FilterVal)
                Call cbo_filter.SearchItem(1)
            ElseIf cbo_Category_Filter(2).SelectedItem.Key = eDPCCategory.cgGasket Then
                cbo_filter.Enabled = True
                lv_FilterVal = Array(1, "GaCnt = 1")
                Call cbo_filter.AddItem(lv_FilterVal)
                lv_FilterVal = Array(2, "GaCnt = 2")
                Call cbo_filter.AddItem(lv_FilterVal)
                lv_FilterVal = Array(3, "GaCnt = 3")
                Call cbo_filter.AddItem(lv_FilterVal)
                lv_FilterVal = Array(4, "GaCnt = 4")
                Call cbo_filter.AddItem(lv_FilterVal)
                Call cbo_filter.SearchItem(1)
            Else
                cbo_filter.Enabled = False
            End If
                        
            ls_Key = ""
            
            If Not cbo_DateRange.SelectedItem Is Nothing Then
                ls_Key = cbo_DateRange.SelectedItem.Key
            End If
            
            cbo_DateRange.Enabled = True
            cbo_DateRange.Request = ReplaceKeyPlaceholders("exec DPC_Price_lst6 $Key1$,$Key2$", av_Key)
            cbo_DateRange.Load
            If cbo_DateRange.Count > 0 Then
            
                If cbo_DateRange.SearchItem(ls_Key) = False Then
                    Call cbo_DateRange.SearchItem(cbo_DateRange.ComboItems(1).Key)
                End If
                
                ls_Dates = Split(Trim(cbo_DateRange.SelectedItem.Key), "-")
            
                ls_Request = "SELECT DISTINCT UM_CodeQ,UM_CodeC FROM DPC_Price WHERE PRD_Id=$Key2$ and " & _
                             "PRC_VStart='" & ls_Dates(0) & "' AND PRC_VExp='" & ls_Dates(1) & "'"
                ls_Request = ReplaceKeyPlaceholders(ls_Request, av_Key)
                ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
                
                If mo_Db.RowCount(ll_Cursor) <> 1 Then
                    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9849, "#Record not found")
                    Exit Sub
                End If
                txt_UM_CodeQ.Text = mo_Db.GetFields(ll_Cursor, "UM_CodeQ")
                txt_UM_CodeC.Text = mo_Db.GetFields(ll_Cursor, "UM_CodeC")
                
                Call mo_Db.Close(ll_Cursor)
                
                cbo_Thick_Filter.Enabled = True
                If Not cbo_Thick_Filter.SelectedItem Is Nothing Then
                    ls_Key = cbo_Thick_Filter.SelectedItem.Key
                End If
                ls_Request = ReplaceKeyPlaceholders("exec DPC_Price_Thick_lst $Key1$,$Key2$,$VDateStart$,$VDateExp$", av_Key)
                ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(ls_Dates(0)), , , vbTextCompare)
                ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(ls_Dates(1)), , , vbTextCompare)
                cbo_Thick_Filter.Request = ls_Request
                cbo_Thick_Filter.Load
                If cbo_Thick_Filter.Count = 1 Then
                    If cbo_Thick_Filter.ComboItems(1).Key = 0 Then
                        cbo_Thick_Filter.Clear
                    End If
                End If
                If cbo_Thick_Filter.Count > 0 Then
                    If cbo_Thick_Filter.SearchItem(ls_Key) = False Then
                        Call cbo_Thick_Filter.SearchItem(cbo_Thick_Filter.ComboItems(1).Key)
                    End If
                End If

                cbo_CURR_Code.Enabled = True
                If Not cbo_CURR_Code.SelectedItem Is Nothing Then
                    ls_Key = cbo_CURR_Code.SelectedItem.Key
                End If
                ls_Request = ReplaceKeyPlaceholders("exec DPC_Price_CurrCode_lst $Key1$,$Key2$,$VDateStart$,$VDateExp$", av_Key)
                ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(ls_Dates(0)), , , vbTextCompare)
                ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(ls_Dates(1)), , , vbTextCompare)
                cbo_CURR_Code.Request = ls_Request
                cbo_CURR_Code.Load
                If cbo_CURR_Code.SearchItem(ls_Key) = False Then
                    Call cbo_CURR_Code.SearchItem(cbo_CURR_Code.ComboItems(1).Key)
                End If

                cbo_CT_Code.Enabled = True
                If Not cbo_CT_Code.SelectedItem Is Nothing Then
                    ls_Key = cbo_CT_Code.SelectedItem.Key
                End If
                ls_Request = ReplaceKeyPlaceholders("exec DPC_Price_CTCode_lst $Key1$,$Key2$,$VDateStart$,$VDateExp$", av_Key)
                ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(ls_Dates(0)), , , vbTextCompare)
                ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(ls_Dates(1)), , , vbTextCompare)
                cbo_CT_Code.Request = ls_Request
                cbo_CT_Code.Load
                If cbo_CT_Code.SearchItem(ls_Key) = False Then
                    Call cbo_CT_Code.SearchItem(cbo_CT_Code.ComboItems(1).Key)
                End If

                cbo_MAT_Id.Enabled = True
                If Not cbo_Thick_Filter.SelectedItem Is Nothing Then
                    ls_Key = cbo_Thick_Filter.SelectedItem.Key
                End If
                ls_Request = ReplaceKeyPlaceholders("exec DPC_Price_MAT_Id_lst $Key1$,$Key2$,$VDateStart$,$VDateExp$,$Language_code$", av_Key)
                ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(ls_Dates(0)), , , vbTextCompare)
                ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(ls_Dates(1)), , , vbTextCompare)
                ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
                cbo_MAT_Id.Request = ls_Request
                cbo_MAT_Id.Load
                If cbo_MAT_Id.Count > 0 Then
                    If cbo_MAT_Id.SearchItem(ls_Key) = False Then
                        Call cbo_MAT_Id.SearchItem(cbo_MAT_Id.ComboItems(1).Key)
                    End If
                End If

                cbo_QtyRange.Enabled = True
                If Not cbo_Thick_Filter.SelectedItem Is Nothing Then
                    ls_Key = cbo_Thick_Filter.SelectedItem.Key
                End If
                ls_Request = ReplaceKeyPlaceholders("exec DPC_Price_QtyRange_lst $Key1$,$Key2$,$VDateStart$,$VDateExp$", av_Key)
                ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(ls_Dates(0)), , , vbTextCompare)
                ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(ls_Dates(1)), , , vbTextCompare)
                ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
                cbo_QtyRange.Request = ls_Request
                cbo_QtyRange.Load
                If cbo_QtyRange.SearchItem(ls_Key) = False Then
                    Call cbo_QtyRange.SearchItem(cbo_QtyRange.ComboItems(1).Key)
                End If

                Call RefreshPriceMatrix
            Else
                cbo_filter.Enabled = False
                cbo_DateRange.Enabled = False
                cbo_Thick_Filter.Enabled = False
                cbo_CURR_Code.Enabled = False
                cbo_CT_Code.Enabled = False
                cbo_MAT_Id.Enabled = False
                cbo_QtyRange.Enabled = False
            End If
        End If
    End If
    
    If ae_Mode = emUpdate Then
            cbo_filter.Enabled = False
            cbo_DateRange.Enabled = False
            cbo_Thick_Filter.Enabled = False
            cbo_CURR_Code.Enabled = False
            cbo_CT_Code.Enabled = False
            cbo_MAT_Id.Enabled = False
            cbo_QtyRange.Enabled = False
    End If

    If ae_Mode = emAdd Then
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_PriceCrit_Sel" Then
            ls_Request = ReplaceCommonPlaceholders("exec DPC_PriceCrit_lst3 $CAT_Id$,$Language_code$")
            ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(1))

            Call RefreshPriceCritGrid(1, ls_Request, txt_PCR_CAT_Id.Text)
        End If
    End If
    
    mb_InternalInit = False

    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 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
    If ll_MainConfigIndex <> -1 Then
        ll_MainFrameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
    Else
        Select Case al_DetailIndex
        Case IMAGE_INFO_CONFIG_INDEX
        'custom checks for imageinfo
        Case Else
        End Select
    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
Dim ls_Filename As String

    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
Dim ll_RowIdx, ll_ColIdx As Long

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
        
    If StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "DPC_Price2", vbTextCompare) = 0 And ab_InTransaction = True Then
    
        For ll_RowIdx = 1 To grd_PriceMatrix.Rows - 1
          For ll_ColIdx = 1 To grd_PriceMatrix.Cols - 1
                            
              If mt_FlexGridData(ll_ColIdx, ll_RowIdx).PRC_Id = -1 Then
                  
                  If grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) <> "X" Then
                        Call InsertPrice(grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx), ll_RowIdx, ll_ColIdx)
                  End If
              Else
                  If grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) = "X" Then
                        Call DeletePrice(ll_RowIdx, ll_ColIdx)
                  ElseIf mt_FlexGridData(ll_ColIdx, ll_RowIdx).Cost <> grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx) Then
                        Call UpdatePrice(grd_PriceMatrix.TextMatrix(ll_RowIdx, ll_ColIdx), ll_RowIdx, ll_ColIdx)
                  End If
              End If
          Next
        Next
        
    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(mo_Tools.GetNextID(mo_Db,"EAS_DroppedNumber"))
      '  ElseIf (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_CreditMemo", vbTextCompare) = 0) Then
      '      txt_CRM_DroppedNumber.Text = -Val(mo_Tools.GetNextID(mo_Db,"EAS_DroppedNumber"))
      '  ElseIf (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_DebitMemo", vbTextCompare) = 0) Then
      '      txt_DBM_DroppedNumber.Text = -Val(mo_Tools.GetNextID(mo_Db,"EAS_DroppedNumber"))
      '  ElseIf (StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "EAS_Return", vbTextCompare) = 0) Then
      '      txt_RET_DroppedNumber.Text = -Val(mo_Tools.GetNextID(mo_Db,"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
Dim ll_PrevDetailIndex As Long
Dim ls_ImgId As String
Dim ls_Array() As String
Dim ll_Index As Long

    ll_frameIndex = mt_DetailConfig(al_DetailIndex).FrameIndex
    ll_MainIndex = mt_DetailConfig(al_DetailIndex).MainConfigIndex
    
    If ll_MainIndex <> -1 Then
       ll_MainFrame = mt_MainConfig(ll_MainIndex).FrameIndex
       
       If ae_Mode = emAdd Then
           grd_Main(ll_MainFrame).SelectedLine(0, "Z_Creation") = 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
       End If
    Else
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_ImageInfo" Then
            If ae_Mode = emAdd Or ae_Mode = emUpdate Then
                ll_PrevDetailIndex = mt_DetailConfig(al_DetailIndex).PreviousDetailIndex
            End If
        End If
        If mt_DetailConfig(al_DetailIndex).NameFrame = "DPC_PriceCrit_Sel" Then
            ReDim lv_Data(grd_PriceCrit(1).Cols)
            lv_Data(0) = ""         ' this is new
            If grd_SubDetail(1).AddLine(lv_Data) Then
                      
                For ll_Index = 1 To grd_PriceCrit(1).Cols
                    grd_SubDetail(1).SelectedLine(0, ll_Index) = grd_PriceCrit(1).SelectedLine(0, ll_Index)
                Next
                
                grd_SubDetail(1).SelectedLine(0, STATUS_COLUMN) = "A"
            
            End If

        End If
    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 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
         If mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_PriceCrit" Then
            cbo_CutArea.Request = ReplaceKeyPlaceholders("exec DPC_CutArea_lst2 $Key1$", txt_DetailKey(1))
            Call cbo_CutArea.Load
         
            Call DisableFrameParts(GetListFieldsToDisable(txt_PCR_CAT_Id.Text))
         End If
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubItem_CustomInit")
End Sub

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

Dim ll_Index, ll_Index2 As Long
Dim la_BendingArray() As String
Dim la_CurrentBending() As String
Dim ls_Request As String
Dim ll_Cursor As Long
Dim ld_Dict As Dictionary
Dim lb_DelayedLoad As Boolean
         
    If mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_Price" Then
    '    lb_DelayedLoad = (mt_SubdetailConfig(al_SubDetailIndex).GridDelayMethod = egmDelayedAlways)
    '
    '    ls_Request = "exec DPC_Price_lst2 $PRD_Id$,$Language_Code$,$PCR_Id$, NULL,NULL"
    '    ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(0))
    '    ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
    '    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    '    If Not grd_SubDetail(al_SubDetailIndex).Load(ls_Request, True, , , lb_DelayedLoad) Then
    '        Err.Raise ArmErr.CompFncFailed, "grd_SubDetail(" & 0 & ").Load", "Grid load failed: " & ls_Request
    '    End If
    End If

    If mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_PriceCrit" Then
        Call SetColumnsForCategory(grd_SubDetail(al_SubDetailIndex), txt_PCR_CAT_Id.Text)
    End If
    
    Set ld_Dict = Nothing
    
    Exit Sub
ErrHandler:
    Set ld_Dict = Nothing

    If ll_Cursor > 0 Then
        Call mo_Db.Close(ll_Cursor)
    End If
    Call ErrorHandler("SubItem_CustomLoad")
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
        
    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
    
    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 mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_Price" Then
        If ae_Mode = eMode.emAdd Or ae_Mode = emUpdate Then
            grd_SubDetail(ll_frameIndex).Data(al_Index, "PRD_Id") = txt_PRD_Id.Text
        End If
    End If
    If mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_Cost" Then
        If ae_Mode = eMode.emAdd Or ae_Mode = emUpdate Then
            grd_SubDetail(ll_frameIndex).Data(al_Index, "PRD_Id") = txt_Cost_PRD_Id.Text
        End If
    End If
    If mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_PriceCrit" Then
        If ae_Mode = eMode.emAdd Then
            mt_SubdetailConfig(al_SubDetailIndex).RequestAdd = ReplacePlaceholdersForCategorey(Val(txt_PCR_CAT_Id.Text), mt_SubdetailConfig(al_SubDetailIndex).RequestAdd)
        ElseIf ae_Mode = eMode.emUpdate Then
            mt_SubdetailConfig(al_SubDetailIndex).RequestUpd = ReplacePlaceholdersForCategorey(Val(txt_PCR_CAT_Id.Text), mt_SubdetailConfig(al_SubDetailIndex).RequestUpd)
        End If
    End If
    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(mo_Tools.GetNextID(mo_Db,"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 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
    
    If mt_SubdetailConfig(al_SubDetailIndex).NameFrame = "DPC_PriceCrit" Then
        If ae_Mode = eMode.emAdd Then
            mt_SubdetailConfig(al_SubDetailIndex).RequestAdd = "exec DPC_PriceCrit_ins $PRD_Id$,$PRD_IdPar$,$CUA_Id$,$PCR_AMin$,$PCR_AMax$,$PCR_BMin$,$PCR_BMax$,$MAT_Id$,$PCR_Thick$,$PCR_TMin$,$PCR_TMax$,$PCR_IsPrf$,$PCR_GaCnt$,$PCR_CoSid$,$U_Code$"
        ElseIf ae_Mode = eMode.emUpdate Then
            mt_SubdetailConfig(al_SubDetailIndex).RequestUpd = "exec DPC_PriceCrit_upd $PCR_Id$,$PRD_Id$,$PRD_IdPar$,$CUA_Id$,$PCR_AMin$,$PCR_AMax$,$PCR_BMin$,$PCR_BMax$,$MAT_Id$,$PCR_Thick$,$PCR_TMin$,$PCR_TMax$,$PCR_IsPrf$,$PCR_GaCnt$,$PCR_CoSid$,$U_Code$,$iConcurrency$"
        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
        If tlb_Main(mt_MainConfig(al_MainIndex).ToolbarIndex).Language = "E" Then
            tlb_Main(mt_MainConfig(al_MainIndex).ToolbarIndex).ButtonEnabled("B") = True
        Else
            tlb_Main(mt_MainConfig(al_MainIndex).ToolbarIndex).ButtonEnabled("B") = True
            tlb_Main(mt_MainConfig(al_MainIndex).ToolbarIndex).ButtonEnabled("C") = True
        End If
    
    '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
    If ll_MainIndex >= 0 Then
        ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    
        If StrComp(mt_MainConfig(ll_MainIndex).NameFrame, "", vbTextCompare) = 0 Then
        End If
    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 Let Enabled(ByVal ab_Value As Boolean)
On Error GoTo ErrHandler

  UserControl.Enabled = ab_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Enabled.Let")
End Property

Public Property Get Enabled() As Boolean
 On Error GoTo ErrHandler

  Enabled = UserControl.Enabled
  Exit Property
ErrHandler:
  Call ErrorHandler("Enabled.Get")
End Property

Public Sub Zorder()
On Error GoTo ErrHandler

  Call UserControl.Extender.Zorder
  Exit Sub
ErrHandler:
  Call ErrorHandler("Zorder")
End Sub

Public Sub Refresh()
On Error GoTo ErrHandler

  Call UserControl.Refresh
  Exit Sub
ErrHandler:
  Call ErrorHandler("Refresh")
End Sub

Public Property Get hwnd() As Long
On Error GoTo ErrHandler
  
  hwnd = UserControl.hwnd
  Exit Property
ErrHandler:
  Call ErrorHandler("hwnd.Get")
End Property

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

Public Property Set Tools(ByRef ao_Tools As Object)
On Error GoTo ErrorHandler

  Set mo_Tools = ao_Tools
  Exit Property
ErrorHandler:
  Call ErrorHandler("Tools.Set")
End Property

Private Sub btn_Quit_Click()
On Error GoTo ErrHandler
    
    Call EditPriceHide
    
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("btn_Validate_Click")
    Call mo_Tools.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 Sub

Private Sub btn_Validate_Click()
On Error GoTo ErrHandler

    If grd_PriceMatrix.TextMatrix(ml_EditedRow, ml_EditedCol) <> txt_Price.Text Then
                
        If IsNumeric(txt_Price.Text) Then
            grd_PriceMatrix.TextMatrix(ml_EditedRow, ml_EditedCol) = mo_Tools.DblToScreen(txt_Price.Text)
        ElseIf txt_Price.Text = "X" Then
            grd_PriceMatrix.TextMatrix(ml_EditedRow, ml_EditedCol) = "X"
        Else
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, C_MSG_ID_BASE + 6, "#Entered value must be number or 'X'.", , vbInformation)
        End If
    
    End If
    Call EditPriceHide
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("btn_Validate_Click")
    Call mo_Tools.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 Sub


Private Sub cbo_CT_Code_Filter_ComboItemSelected(Index As Integer)
On Error GoTo ErrorHandler
    
    Dim ll_MainConfigIndex As Long
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        
    grd_Main(ll_MainConfigIndex).ClearGrid
                
    ReloadMainGrid
    
    Exit Sub
ErrorHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_CT_Code_Filter_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_SYS_Id_Filter_ComboItemSelected()
On Error GoTo ErrorHandler
    
    Dim ll_MainConfigIndex As Long
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        
    grd_Main(ll_MainConfigIndex).ClearGrid
                
    ReloadMainGrid
    
    Exit Sub
ErrorHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_SYS_Id_Filter_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_Vendor_Filter_ComboItemSelected()
On Error GoTo ErrorHandler
    
    Dim ll_MainConfigIndex As Long
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        
    grd_Main(ll_MainConfigIndex).ClearGrid
                
    ReloadMainGrid
    
    Exit Sub
ErrorHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_Vendor_Filter_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub txt_Price_KeyPress(KeyAscii As Integer)
On Error GoTo ErrorHandler
    If KeyAscii = 13 Then
        Call btn_Validate_Click
    ElseIf KeyAscii = 27 Then
        Call btn_Quit_Click
    End If

    Exit Sub
ErrorHandler:
    Call ErrorHandler("txt_Price_KeyPress")
End Sub


Private Sub cbo_Category_Filter_ComboItemSelected(Index As Integer)
On Error GoTo ErrHandler
    
    Dim ll_Columns As Variant
    Dim ls_Request As String
    Dim ll_Category_Id As Integer
    Dim ll_MainConfigIndex As Long
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    
    If Not cbo_Category_Filter(Index).SelectedItem Is Nothing Then
        ll_Category_Id = cbo_Category_Filter(Index).SelectedItem.Key
        
        If mt_MainConfig(ll_MainConfigIndex).NameFrame = "DPC_Price2" Then
            ls_Request = "exec DPC_Price_lst5 $Language_code$,$CAT_Id_Filter$,$PRD_Code$,$PRD_Name$,$PRD_NamePar$"
            mt_MainConfig(ll_MainConfigIndex).RequestGrid = ls_Request
        ElseIf mt_MainConfig(ll_MainConfigIndex).NameFrame = "DPC_Price" Then
            ls_Request = "exec DPC_Price_lst $Language_code$,$CT_Code$,$CURR_Code$,$FromDate$,$ToDate$,$CAT_Id$,$PRD_Code$,$PRD_Name$"
            mt_MainConfig(ll_MainConfigIndex).RequestGrid = ls_Request
            Call SetColumnsForCategory(grd_Main(ll_MainConfigIndex), ll_Category_Id)
        ElseIf mt_MainConfig(ll_MainConfigIndex).NameFrame = "DPC_Cost" Then
            ls_Request = "exec DPC_Cost_lst $Language_code$,$VEN_Id$,$CURR_Code$,$FromDate$,$ToDate$,$CAT_Id$,$PRD_Code$,$PRD_Name$"
            mt_MainConfig(ll_MainConfigIndex).RequestGrid = ls_Request
            Call SetColumnsForCategory(grd_Main(ll_MainConfigIndex), ll_Category_Id)
        End If
    
        grd_Main(ll_MainConfigIndex).ClearGrid
                
        ReloadMainGrid
    
    End If
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_Category_Filter_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Function ReplacePlaceholdersForCategorey(ByVal al_CAT_Id As Long, ByVal as_Request As String) As String
On Error GoTo ErrHandler
    
    Dim ll_Index As Long
    Dim ls_Request As String
                
    For ll_Index = 0 To UBound(mt_PriceCritForCategory)
        If mt_PriceCritForCategory(ll_Index).CAT_Id = al_CAT_Id Then
            If mt_PriceCritForCategory(ll_Index).PRD_IdPar = False Then
                ls_Request = ReplacePlaceHolder(as_Request, "$PRD_IdPar$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).CUA_Id = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$CUA_Id$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).MAT_Id = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$MAT_Id$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_AMin = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_AMin$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_AMax = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_AMax$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_BMin = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_BMin$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_BMax = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_BMax$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_Thick = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_Thick$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_TMin = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_TMin$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_TMax = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_TMax$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_IsPrf = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_IsPrf$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_GaCnt = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_GaCnt$", "NULL")
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_CoSid = False Then
                ls_Request = ReplacePlaceHolder(ls_Request, "$PCR_CoSid$", "NULL")
            End If
                            
            ReplacePlaceholdersForCategorey = ls_Request
            Exit Function

        End If
    Next
    
    ReplacePlaceholdersForCategorey = as_Request
    Exit Function
    
ErrHandler:
    Call ErrorHandler("ReplacePlaceholdersForCategorey")
End Function

Private Function GetListFieldsToDisable(ByVal al_CAT_Id As Long) As Variant
On Error GoTo ErrHandler
    Dim lv_ListFieldsToDisable() As Variant
    Dim ll_Index As Long
    Dim ll_Count As Integer
    
    ll_Count = 0

    For ll_Index = 0 To UBound(mt_PriceCritForCategory)
        If mt_PriceCritForCategory(ll_Index).CAT_Id = al_CAT_Id Then
            If mt_PriceCritForCategory(ll_Index).PRD_IdPar = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then 'MW REDIM - SafeUbound in whole function >>
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PRD_IdPar
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).CUA_Id = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = cbo_CutArea
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).MAT_Id = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = cbo_Material(0)
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_AMin = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_AMin
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_AMax = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_AMax
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_BMin = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_BMin
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_BMax = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_BMax
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_Thick = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_Thick
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_TMin = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_TMin
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_TMax = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                   ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_TMax
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_IsPrf = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = chk_PCR_IsPrf
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_GaCnt = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_GaCnt
                ll_Count = ll_Count + 1
            End If
            If mt_PriceCritForCategory(ll_Index).PCR_CoSid = False Then
                If SafeUbound(lv_ListFieldsToDisable) = -1 Then
                    ReDim lv_ListFieldsToDisable(ll_Count)
                Else
                    ReDim Preserve lv_ListFieldsToDisable(ll_Count)
                End If
                Set lv_ListFieldsToDisable(ll_Count) = txt_PCR_CoSid
                ll_Count = ll_Count + 1
            End If
                            
            GetListFieldsToDisable = lv_ListFieldsToDisable
            Exit Function

        End If
    Next

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

Private Sub SetColumnsForCategory(ByRef ag_grid As ArmGrid, ByVal al_CAT_Id As Long)
On Error GoTo ErrHandler
    
    Dim ll_Index As Long
            
    For ll_Index = 0 To UBound(mt_PriceCritForCategory)
        If mt_PriceCritForCategory(ll_Index).CAT_Id = al_CAT_Id Then
           'ag_grid.Columns("PRD_Code").Width = 1000
           ag_grid.Columns("PRD_IdPar").Width = IIf(mt_PriceCritForCategory(ll_Index).PRD_IdPar, 1000, 0)
           ag_grid.Columns("CUA_Desc").Width = IIf(mt_PriceCritForCategory(ll_Index).CUA_Id, 1000, 0)
           ag_grid.Columns("MAT_Name").Width = IIf(mt_PriceCritForCategory(ll_Index).MAT_Id, 1000, 0)
           ag_grid.Columns("PCR_AMin").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_AMin, 1000, 0)
           ag_grid.Columns("PCR_AMax").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_AMax, 1000, 0)
           ag_grid.Columns("PCR_BMin").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_BMin, 1000, 0)
           ag_grid.Columns("PCR_BMax").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_BMax, 1000, 0)
           ag_grid.Columns("PCR_Thick").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_Thick, 1000, 0)
           ag_grid.Columns("PCR_TMin").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_TMin, 1000, 0)
           ag_grid.Columns("PCR_TMax").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_TMax, 1000, 0)
           ag_grid.Columns("PCR_IsPrf").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_IsPrf, 1000, 0)
           ag_grid.Columns("PCR_GaCnt").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_GaCnt, 1000, 0)
           ag_grid.Columns("PCR_CoSid").Width = IIf(mt_PriceCritForCategory(ll_Index).PCR_CoSid, 1000, 0)
            
        End If
    Next
    
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("SetColumnsForCategory")
End Sub

Private Sub cbo_DateRange_ComboItemSelected()
On Error GoTo ErrHandler
    
Dim ls_Request As String
Dim la_Dates() As String

    If mb_InternalInit = False Then
    
        mb_InternalInit = True
        
        Screen.MousePointer = vbHourglass
        LockWindowUpdate 1
        
        la_Dates = Split(Trim(cbo_DateRange.SelectedItem.Key), "-")
        ls_Request = "exec DPC_Price_Thick_lst $CAT_Id$,$PRD_Id$,$VDateStart$,$VDateExp$"
        ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(4))
    
        cbo_Thick_Filter.Request = ls_Request
        cbo_Thick_Filter.Load
        Call cbo_Thick_Filter.SearchItem(cbo_Thick_Filter.ComboItems(1).Key)
    
        ls_Request = "exec DPC_Price_CurrCode_lst $CAT_Id$,$PRD_Id$,$VDateStart$,$VDateExp$"
        ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(4))
        cbo_CURR_Code.Request = ls_Request
        cbo_CURR_Code.Load
        Call cbo_CURR_Code.SearchItem(cbo_CURR_Code.ComboItems(1).Key)
    
        ls_Request = "exec DPC_Price_CTCode_lst $CAT_Id$,$PRD_Id$,$VDateStart$,$VDateExp$"
        ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(4))
        cbo_CT_Code.Request = ls_Request
        cbo_CT_Code.Load
        Call cbo_CT_Code.SearchItem(cbo_CT_Code.ComboItems(1).Key)
    
        ls_Request = "exec DPC_Price_MAT_Id_lst $CAT_Id$,$PRD_Id$,$VDateStart$,$VDateExp$,$Language_code$"
        ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(4))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        cbo_MAT_Id.Request = ls_Request
        cbo_MAT_Id.Load
        If cbo_MAT_Id.Count > 0 Then
            Call cbo_MAT_Id.SearchItem(cbo_MAT_Id.ComboItems(1).Key)
        End If
    
        ls_Request = "exec DPC_Price_QtyRange_lst $CAT_Id$,$PRD_Id$,$VDateStart$,$VDateExp$"
        ls_Request = Replace(ls_Request, "$VDateStart$", mo_Tools.SqlDate(la_Dates(0)), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$VDateExp$", mo_Tools.SqlDate(la_Dates(1)), , , vbTextCompare)
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(4))
        cbo_QtyRange.Request = ls_Request
        cbo_QtyRange.Load
        Call cbo_QtyRange.SearchItem(cbo_QtyRange.ComboItems(1).Key)
    
        mb_InternalInit = False
        
        Call RefreshPriceMatrix
        
        LockWindowUpdate 0
        Screen.MousePointer = vbDefault
    End If
        
    Exit Sub
ErrHandler:
    LockWindowUpdate 0
    Screen.MousePointer = vbDefault
    mb_InternalInit = False
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_CT_Code_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_Thick_Filter_ComboItemSelected()
On Error GoTo ErrHandler
    
    If mb_InternalInit = False Then
        Call RefreshPriceMatrix
    End If
        
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_Thick_Filter_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_CURR_Code_ComboItemSelected()
On Error GoTo ErrHandler
    
    If mb_InternalInit = False Then
        Call RefreshPriceMatrix
    End If
        
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_CURR_Code_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_CT_Code_ComboItemSelected()
On Error GoTo ErrHandler
    
    If mb_InternalInit = False Then
        Call RefreshPriceMatrix
    End If
        
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_CT_Code_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_MAT_Id_ComboItemSelected()
On Error GoTo ErrHandler
    
    If mb_InternalInit = False Then
        Call RefreshPriceMatrix
    End If
        
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_MAT_Id_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_QtyRange_ComboItemSelected()
On Error GoTo ErrHandler
    
    If mb_InternalInit = False Then
        Call RefreshPriceMatrix
    End If
        
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_QtyRange_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cbo_filter_ComboItemSelected()
On Error GoTo ErrHandler

    If mb_InternalInit = False Then
        Call RefreshPriceMatrix
    End If

    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call LogMessage("cbo_Filter_ComboItemSelected")
    Call mo_Tools.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 Sub

Private Sub cmd_AddExisting_Click()
On Error GoTo ErrHandler
Dim ll_DetailConfigIndex As Long
Dim ll_MainConfigIndex As Long
Dim ll_frameIndex As Long

    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_frameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
    ll_DetailConfigIndex = FindDetailConfigByMainConfig(ll_MainConfigIndex)
    
    mt_MainConfig(ll_MainConfigIndex).CurrentDetailIndex = PRICE_CRIT_SELECTION_CONFIG_INDEX
    mt_DetailConfig(PRICE_CRIT_SELECTION_CONFIG_INDEX).PreviousDetailIndex = ll_DetailConfigIndex
    
    Select Case me_SubDetailMode
    Case emAdd
        Call Item_AddInit(PRICE_CRIT_SELECTION_CONFIG_INDEX)
    Case Else
    End Select
    Exit Sub
ErrHandler:
    Call ErrorMessage("cmd_AddExisting_Click")
End Sub

Private Sub RefreshPriceMatrix()
On Error GoTo ErrHandler
    
Dim ll_Cursor

    ll_Cursor = GetPriceMatrix
    If ll_Cursor = 0 Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9859, "#Not enough parameters to show price matrix, please select material and quantity")
      Exit Sub
    End If
    If mo_Db.RowCount(ll_Cursor) > 0 Then
      Call LoadPriceMatrix(ll_Cursor)
      Call ShowPriceMatrix
    Else
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9849, "#Record not found")
    End If
    Call mo_Db.Close(ll_Cursor)
            
    Exit Sub
ErrHandler:
    Call ErrorMessage("RefreshPriceMatrix")
End Sub
        
Private Sub RefreshPriceCritGrid(ByVal al_GridIndex As Integer, ByVal as_Request As String, ByVal al_Category_Id As Long)
On Error GoTo ErrHandler
    
    Dim ll_Columns As Variant
        
        'grd_PriceCrit(al_GridIndex).ClearGrid
        grd_PriceCrit(al_GridIndex).Requests = as_Request
                
        Call SetColumnsForCategory(grd_PriceCrit(al_GridIndex), al_Category_Id)
           
        If Not grd_PriceCrit(al_GridIndex).Load(as_Request, False, , , False) Then
            Err.Raise ArmErr.CompFncFailed, "grd_PriceCrit", "Method Load failed: " & as_Request
        End If
    Exit Sub
ErrHandler:
    Call ErrorMessage("RefreshPriceCritGrid")
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
    
    Call mo_Tools.LockScreen(Me, True)
    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 mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowModalForm(lo_SeekForm)
    Call mo_Tools.LockScreen(Me, True)
    
    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
    Call mo_Tools.LockScreen(Me, False)
    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 UploadImage(ByVal as_FileName As String, ByVal as_IMG_Id As String)
On Error GoTo ErrHandler

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

    ls_RequestIns = "INSERT INTO DPC_Image (IMG_Id,IMG_File) VALUES ($IMG_Id$,?)"
    ls_RequestIns = ReplacePlaceHolder(ls_RequestIns, "$IMG_Id$", as_IMG_Id)
        
    'Call mo_Tools.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 mo_Tools.ExecuteSQLSafe(mo_Db, ls_RequestIns)
    Exit Sub
ErrHandler:
    Call ErrorHandler("UploadImage as_FileName=" & as_FileName & _
                               "")
End Sub

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 = mo_Tools.GetAndCreateTempDir(mo_FSO, SCREEN_NAME, True) & "\$DPC_REf$\" & 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 Sub grd_PriceMatrix_Click()
On Error GoTo ErrHandler
    
    If me_DetailMode = emUpdate Then
        ml_EditedRow = grd_PriceMatrix.MouseRow
        ml_EditedCol = grd_PriceMatrix.MouseCol
        
        If ml_EditedRow > 0 And ml_EditedCol > 0 And grd_PriceMatrix.TextMatrix(ml_EditedRow, ml_EditedCol) <> "" Then
            Call EditPriceShow(grd_PriceMatrix.TextMatrix(ml_EditedRow, ml_EditedCol))
        End If
    End If
    
    Exit Sub
ErrHandler:
    ' user interface can be inconsistent, better to close application
    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 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 mo_Tools.LockScreen(Me, 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 mo_Tools.ChangeCharset(UserControl.Controls, gl_CodePage, mo_Tools.GetCodePageFromLanguage(mo_Db, tlb_Main(ll_frameIndex).Language))
                Call ReloadMainGrid
                Call Init_Custom
                Call cbo_View_ComboItemSelected(Index)
            Case "G"
                Call ImportExcelData(ll_MainConfigIndex)
            Case "T"
                Call mo_Tools.LockScreen(Me, False)
                RaiseEvent quit
                Exit Sub
            Case Else
                Err.Raise ArmErr.InvalidArgument, "tlb_Main_action(" & Index & ")", "Unknown main toolbar role as_Role=" & as_Role
        End Select
    End If
    
    Call mo_Tools.LockScreen(Me, False)
    
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call mo_Tools.LockScreen(Me, False)

    Select Case Err.Number
    Case 202
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 202, "#The item you have added/updated couldn't be displayed with the current criteria set.", , vbInformation + vbOKOnly)
    Case ArmErr.SQLBadRowExpectedCount
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
    Case ArmErr.SQLBadRowAffectedCount
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2144, "#This record has been, modified by an other.Please exit from this screen and refresh the grid.", , vbInformation)
    Case Else
        Call LogMessage("tlb_list_action")
        ' user interface can be inconsistent, better to close application
        Call mo_Tools.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 mo_Tools.LockScreen(Me, 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 mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_DetailConfig(ll_DetailConfigIndex).DeleteMsg(0, 0), 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"
                If mt_DetailConfig(ll_DetailConfigIndex).MainConfigIndex <> -1 Then
                    Call SetMode(emList)
                Else
                    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
                    mt_MainConfig(ll_MainConfigIndex).CurrentDetailIndex = mt_DetailConfig(ll_DetailConfigIndex).PreviousDetailIndex
                    Call SetMode(me_DetailMode)
                End If
                
                If mc_Item <> 0 Then
                    Call mo_Db.Close(mc_Item)
                    mc_Item = 0
                End If
                
            Case Else
                Err.Raise ArmErr.InvalidArgument, "tlb_detail_action(" & Index & ")", "Unknown detail toolbar role as_Role=" & as_Role
        End Select
    End If
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call mo_Tools.LockScreen(Me, False)

    Select Case Err.Number
    Case 202
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 202, "#The item you have added/updated couldn't be displayed with the current criteria set.", , vbInformation + vbOKOnly)
    Case ArmErr.SQLBadRowExpectedCount
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
    Case ArmErr.SQLBadRowAffectedCount
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2144, "#This record has been, modified by an other.Please exit from this screen and refresh the grid.", , vbInformation)
    Case Else
        Call LogMessage("tlb_Detail_action")
        Call mo_Tools.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 mo_Tools.LockScreen(Me, 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 mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Call mo_Tools.UpdateError(True)
    Call mo_Tools.LockScreen(Me, False)

    Select Case Err.Number
    Case 202
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 202, "#The item you have added/updated couldn't be displayed with the current criteria set.", , vbInformation + vbOKOnly)
    Case ArmErr.SQLBadRowExpectedCount
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
    Case ArmErr.SQLBadRowAffectedCount
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2144, "#This record has been, modified by an other.Please exit from this screen and refresh the grid.", , vbInformation)
    Case Else
        Call LogMessage("tlb_Detail_action")
        Call mo_Tools.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 mo_Tools.LockScreen(Me, True)
    
    ll_Index = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    Call InitMainFrame(ll_Index)
    Call SetMode(emList)
    
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Call mo_Tools.LockScreen(Me, 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 mo_Tools.LockScreen(Me, 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 mo_Tools.LockScreen(Me, False)
    Exit Sub
    
ErrHandler:
    Call LogMessage("cbo_Views_ComboItemSelected")
    Call mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2116, "#Unable to load the combo " & " type of view.", , vbInformation + vbOKOnly)
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 mo_Tools.LockScreen(Me,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 mo_Tools.LoadLabelsCursor(mo_Db, mc_ScreenLabels, UserControl.Controls, 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 mo_Tools.LoadLabelsCursor(mo_Db, mc_ScreenLabels, UserControl.Controls, 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 mo_Tools.LockScreen(Me,False)
    Screen.MousePointer = vbDefault
    Exit Sub

ErrHandler:
    Call LogMessage("tvw_Main_NodeClick")
    'Call mo_Tools.LockScreen(Me,False)
    Screen.MousePointer = vbDefault
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2142, "#There is a problem while loading data.", , vbInformation + vbOKOnly)
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 mo_Tools.LockScreen(Me, True)
    lb_Locked = True
    
    If grd_Main_CustomAction(Index, eControlAction.caDoubleClick) Then
        Call mo_Tools.LockScreen(Me, 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 mo_Tools.LockScreen(Me, False)
    lb_Locked = False
    Exit Sub
ErrHandler:
    If lb_Locked Then
        Call mo_Tools.LockScreen(Me, False)
    End If
    Select Case Err.Number
        Case ArmErr.SQLBadRowExpectedCount
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
        Case Else
            Call LogMessage("grd_Main_ItemSelected")
            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)
    
    'MW REDIM >>
    Call SafeRedimPreserve(mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows, al_Row)
    
    'If UBound(mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows) = -1 Then
    '    ReDim mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows(al_Row)
    'Else
    '    ReDim Preserve mt_SubdetailConfig(ll_SubdetailIndex).DeletedRows(al_Row)
    'End If
    'MW <<
    
    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_Subdetail_RowLoaded")
End Sub

Private Sub ImportExcelData(ByVal la_MainConfigIndex As Integer)
On Error GoTo ErrHandler
  
  Dim ll_Index As Long
  Dim lo_frmDPC_Import As frmDPC_Import
  Dim ll_Col As New Collection
  
  If cbo_Category_Filter(3).SelectedItem Is Nothing Then
        Call MsgBox(mo_Tools.MsgText(mo_Db, ms_Language_Code, C_MSG_ID_BASE + 38, "#Category has to be selected first!"), vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        Exit Sub
  End If
  
    If cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgPerforation And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgCoating And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgGasket And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgInlay And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgPacking And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgSurcharge And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgMetalPanelSKU And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgMetalCustomPanelTemplate And _
       cbo_Category_Filter(3).SelectedItem.Key <> eDPCCategory.cgSubconstructionArticle Then
       
        Call MsgBox(mo_Tools.MsgText(mo_Db, ms_Language_Code, C_MSG_ID_BASE + 37, "#Selected category does not support import from excel file."), vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
        Exit Sub
    End If
  
  Set lo_frmDPC_Import = New frmDPC_Import
  Load lo_frmDPC_Import
  Set lo_frmDPC_Import.ArmDb = mo_Db
  Set lo_frmDPC_Import.Tools = mo_Tools
  
    For ll_Index = 0 To UBound(mt_PriceCritForCategory)
         Call ll_Col.Add(VarPtr(mt_PriceCritForCategory(ll_Index)), Str(ll_Index))
    Next
        
  lo_frmDPC_Import.PriceCritForCategory = ll_Col
  lo_frmDPC_Import.Language_Code = ms_Language_Code
  lo_frmDPC_Import.U_Code = ml_U_Code
  lo_frmDPC_Import.CurrCategory = cbo_Category_Filter(3).SelectedItem.Key
  lo_frmDPC_Import.CurrCategoryDesc = cbo_Category_Filter(3).SelectedItem.DisplayText
  Call lo_frmDPC_Import.Load_A_COM
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_frmDPC_Import)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_frmDPC_Import.Result = True Then
  End If
  lo_frmDPC_Import.Unload_A_COM
  Unload lo_frmDPC_Import
  Set lo_frmDPC_Import = Nothing
  Exit Sub
ErrHandler:
    Call ErrorMessage("ImportExcelData")
End Sub


' Omit plngLeft & plngRight; they are used internally during recursion
Public Sub QuickSort(ByRef pvarArray As Variant, ByRef keys() As Long, Optional ByVal plngLeft As Long, Optional ByVal plngRight As Long)
On Error GoTo ErrHandler

    Dim ll_First As Long
    Dim ll_Last As Long
    Dim ll_Mid As Long
    Dim ll_Store, ll_Idx As Integer
    
    If plngRight = 0 Then
        plngLeft = LBound(pvarArray, 1) + 1
        plngRight = UBound(pvarArray, 1)
    End If
    
    If plngLeft >= plngRight Then
        Exit Sub
    End If
    
    ll_First = plngLeft
    ll_Last = plngRight
    
    ll_Mid = (plngLeft + plngRight) \ 2
    Call QS_SwapRows(pvarArray, ll_Mid, ll_Last, keys)
    ll_Store = ll_First
    
    For ll_Idx = ll_First To ll_Last - 1
        If CompareRows(pvarArray, ll_Idx, ll_Last, keys) = True Then
            Call QS_SwapRows(pvarArray, ll_Idx, ll_Store, keys)
            ll_Store = ll_Store + 1
        End If
    Next
    Call QS_SwapRows(pvarArray, ll_Last, ll_Store, keys)
    
    QuickSort pvarArray, keys, plngLeft, ll_Store - 1
    QuickSort pvarArray, keys, ll_Store + 1, plngRight
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("QuickSort")
End Sub

Private Sub QS_SwapRows(ByRef aa_array As Variant, ByVal al_first As Long, ByVal al_second As Long, ByRef keys() As Long)
    Dim varSwap As Variant
    Dim ll_Idx As Integer
    
    For ll_Idx = 1 To UBound(aa_array, 2)
        varSwap = aa_array(al_first, ll_Idx)
        aa_array(al_first, ll_Idx) = aa_array(al_second, ll_Idx)
        aa_array(al_second, ll_Idx) = varSwap
    Next
End Sub

Private Function CompareRows(ByRef aa_array As Variant, ByVal al_first As Long, ByVal al_last As Long, ByRef keys() As Long)
On Error GoTo ErrHandler

    Dim ll_Idx As Integer
    
    For ll_Idx = 0 To UBound(keys)
        If aa_array(al_first, keys(ll_Idx)) < aa_array(al_last, keys(ll_Idx)) Then
            CompareRows = True
            Exit Function
        ElseIf aa_array(al_first, keys(ll_Idx)) > aa_array(al_last, keys(ll_Idx)) Then
            CompareRows = False
            Exit Function
        End If
    Next

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

Private Function CompareRows2(ByRef aa_array As Variant, ByVal al_first As Long, ByVal al_last As Long, ByRef keys() As Long)
On Error GoTo ErrHandler
    
    Dim ll_Idx As Integer
    
    For ll_Idx = 0 To UBound(keys)
        If aa_array(al_first, keys(ll_Idx)) <> aa_array(al_last, keys(ll_Idx)) Then
            CompareRows2 = False
            Exit Function
        End If
    Next

    CompareRows2 = True
    Exit Function
ErrHandler:
    Call ErrorHandler("CompareRows2")
End Function

Private Sub ProgressBarShow(ByVal al_max As Long)
On Error GoTo ErrHandler
    
    Dim ll_MainConfigIndex, ll_Idx As Long
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_Idx = mt_MainConfig(ll_MainConfigIndex).FrameIndex
        
    Call fra_ProgressBar.Move(fra_MainItem(ll_Idx).Width / 2 - fra_ProgressBar.Width / 2, fra_MainItem(ll_Idx).Height / 2)
        
    LockWindowUpdate 0
    
    prb_Progress.Max = al_max
    prb_Progress.Value = 0
    fra_ProgressBar.Zorder
    fra_ProgressBar.Visible = True
    fra_MainItem(ll_Idx).Refresh
    fra_ProgressBar.Refresh
    Exit Sub
ErrHandler:
    Call ErrorHandler("ProgressBarShow")
End Sub

Private Sub ProgressBarStep()
On Error GoTo ErrHandler
    prb_Progress.Value = prb_Progress.Value + 1
    Exit Sub
ErrHandler:
    Call ErrorHandler("ProgressBarStep")
End Sub

Private Sub ProgressBarLabel(ByVal as_Msg As String)
On Error GoTo ErrHandler
    lbl_ProgressMsg.Caption = as_Msg
    lbl_ProgressMsg.Refresh
    Exit Sub
ErrHandler:
    Call ErrorHandler("ProgressBarLabel")
End Sub

Private Sub ProgressBarHide()
On Error GoTo ErrHandler
    fra_ProgressBar.Visible = False
    Exit Sub
ErrHandler:
    Call ErrorHandler("ProgressBarHide")
End Sub

Private Sub EditPriceShow(ByVal as_Price As String)
On Error GoTo ErrHandler
    
    Dim ll_MainConfigIndex, ll_Idx As Long
    
    ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
    ll_Idx = mt_MainConfig(ll_MainConfigIndex).FrameIndex
        
    Call fra_EditPrice.Move(fra_MainItem(ll_Idx).Width / 2 - fra_EditPrice.Width / 2, fra_MainItem(ll_Idx).Height / 2, 4000, 1200)
        
    LockWindowUpdate 0
    fra_EditPrice.Zorder
    fra_EditPrice.Visible = True
    
    txt_Price.Text = as_Price
    txt_Price.SetFocus
    txt_Price.SelStart = 0
    txt_Price.SelLength = Len(txt_Price.Text)

    fra_MainItem(ll_Idx).Refresh
    fra_EditPrice.Refresh
    Exit Sub
ErrHandler:
    Call ErrorHandler("EditPriceShow")
End Sub

Private Sub EditPriceHide()
On Error GoTo ErrHandler
    fra_EditPrice.Visible = False
    LockWindowUpdate 1
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("EditPriceHide")
End Sub

Private Function ConvertDate(ByVal ae_TableType As eTableType, ByVal as_Date As String) As Date
On Error GoTo ErrHandler

Dim ls_Date() As String

    ConvertDate = 0
    If Trim(as_Date) <> "" Then
        Select Case ae_TableType
        Case eTableType.ttDPC_Price
        Case eTableType.ttDPC_Cost
            ls_Date = Split(as_Date, "/")
            If UBound(ls_Date) = 2 Then
                ConvertDate = DateSerial(Val(ls_Date(2)), Val(ls_Date(1)), Val(ls_Date(0)))
            End If
        Case Else
            Err.Raise ArmErr.InvalidValue, "ae_TableType", "Invalid table type value: " & ae_TableType
        End Select
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("ConvertDate")
End Function

'**********************************************************************************************************************************
'**********************************************************************************************************************************
' 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
    
    If mo_Db Is Nothing Then
        Call Err.Raise(ArmErr.PropertyNotSet)
    End If
    If mo_Tools Is Nothing Then
        Call Err.Raise(ArmErr.PropertyNotSet)
    End If
    
    If Not mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_REF_PRICES") Then
        Exit Function
    End If
    
    mb_InternalInit = False
    ms_DecimalSeparator = Format(0, ".")
    mc_ScreenLabels = 0
    mc_Toolbars = 0
    mc_Item = 0
    
    Call mo_Tools.Load_A_ComControls(UserControl.Controls, mo_Db, ms_Language_Code)
    
    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
        
    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 = mo_Tools.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 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
    
    If (Not mt_SubdetailConfig) <> -1 Then 'test if array exists
        For ll_Index = 0 To UBound(mt_SubdetailConfig)
            ReDim mt_SubdetailConfig(ll_Index).DeletedRows(-1 To -1)
        Next
    End If
    
    Call mo_Tools.Unload_A_ComControls(UserControl.Controls)
    
    ReDim mt_MainConfig(-1 To -1)
    ReDim mt_DetailConfig(-1 To -1)
    ReDim mt_SubdetailConfig(-1 To -1)
    ReDim mt_PriceCritForCategory(-1 To -1)
    
    Set mo_Db = Nothing
    Set mo_Tools = Nothing
    Set mo_FSO = Nothing
    Set mo_Sys = Nothing
    Set mo_WshNetwork = 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 - tbs_Main.Top - tbs_Main.Height - FRM_SPACE_VER)
    
    If StrComp(mt_DetailConfig(al_DetailIndex).NameFrame, "DPC_Price2", vbTextCompare) = 0 Then
        Call grd_PriceMatrix.Move(grd_PriceMatrix.Left, grd_PriceMatrix.Top, UserControl.Width - grd_PriceMatrix.Left - 100, UserControl.Height - (grd_PriceMatrix.Top + tbs_Main.Top + tbs_Main.Height))
    End If
    
    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
    
    If StrComp(mt_SubdetailConfig(al_SubDetailIndex).NameFrame, "DPC_PriceCrit", vbTextCompare) = 0 Or _
       StrComp(mt_SubdetailConfig(al_SubDetailIndex).NameFrame, "DPC_Price", vbTextCompare) = 0 Or _
       StrComp(mt_SubdetailConfig(al_SubDetailIndex).NameFrame, "DPC_Cost", vbTextCompare) = 0 Then
        Call fra_SubDetail(ll_frameIndex).Move(fra_SubDetail(ll_frameIndex).Left, fra_SubDetail(ll_frameIndex).Top, UserControl.Width - fra_SubDetail(ll_frameIndex).Left - 100, UserControl.Height - (fra_SubDetail(ll_frameIndex).Top + tbs_Main.Top + tbs_Main.Height))
    End If
    
    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

    If mb_Initialized Then
        Call Load_ConfigInfo
        Call Init_Custom
        
        Call mo_Tools.ChangeCharset(UserControl.Controls, mo_Tools.GetCodePageFromLanguage(mo_Db, ms_Language_Code))
        mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, UserControl.Controls, 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
    End If
    
    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)
    
    tlb_Main(ll_frameIndex).Language = ms_Language_Code
    
    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$", mo_Tools.SqlStr(mt_MainConfig(al_ConfigIndex).ViewCode))
    ls_Request = ReplacePlaceHolder(ls_Request, "$Language_Code$", mo_Tools.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 mo_Tools.LoadLabelsCursor(mo_Db, mc_ScreenLabels, UserControl.Controls, 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 mo_Tools.LoadLabelsCursor(mo_Db, mc_ScreenLabels, UserControl.Controls, 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, Optional al_DetailConfigIndex As Long = -1)
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

    If al_DetailConfigIndex = -1 Then
        ll_MainConfigIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        ll_MainFrameIndex = mt_MainConfig(ll_MainConfigIndex).FrameIndex
        ll_DetailConfigIndex = FindDetailConfigByMainConfig(ll_MainConfigIndex)
    Else
        ll_DetailConfigIndex = al_DetailConfigIndex
    End If
    
    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 mo_Tools.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 = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, 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$", mo_Tools.SqlStr(MODULE_NAME))
        mc_Toolbars = mo_Tools.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(mo_Tools.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
                                If SafeUbound(lv_pathData) = -1 Then    'MW REDIM
                                    ReDim lv_pathData(UBound(lv_pathData) + ll_LevelCount - 1)
                                Else
                                    ReDim Preserve lv_pathData(UBound(lv_pathData) + ll_LevelCount - 1)
                                End If

                                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 = mo_Tools.GetNextID(mo_Db, 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
    Dim ls_Tags() As String
    
    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
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        Exit Function
                    End If
                    ls_Tags = Split(lo_Control.Tag, SEP)
                    If lo_Control.Visible And UBound(ls_Tags) > 0 And (lo_Control.Text <> "") Then
                        If ls_Tags(1) = "F" And IsNumeric(lo_Control.Text) = False Then
                            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2131, "The field $LabelCaption$ must be numeric.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                            Exit Function
                        End If
                        If ls_Tags(1) = "N" And mo_Tools.IsIntValue(lo_Control.Text) = False Then
                            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2121, "The field $LabelCaption$ must be numeric with not decimal.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                            Exit Function
                        End If
                    End If
                Case "ARMCHECKVIEW"
                     If lo_Control.Visible And (lo_Control.RoleList("EDIT").CheckedCount = 0) Then
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        Call lo_Control.SetFocus
                        Exit Function
                      End If
                Case "A_CALOCX"
                    If lo_Control.Visible And (lo_Control.date_courte = "") Then
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        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
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        Exit Function
                    End If
                Case "ARMCOMBOBOX"
                    If lo_Control.Visible And (lo_Control.SelectedItem Is Nothing) Then
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        Exit Function
                    End If
                Case "ARMPICKER"
                    If lo_Control.Visible And (CStr(lo_Control.ItemCode) = "") Then
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        Exit Function
                    End If
                Case "LISTVIEW"
                     If lo_Control.Visible And (GetCheckedCount(lo_Control) = 0) Then
                        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2120, "The field $LabelCaption$ is mandatory.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                        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 Function Item_CheckValues(ByRef ao_Frame As Frame)
On Error GoTo ErrHandler

Dim lo_Control As Control
Dim lsa_Columns() As String
Dim lv_MsgReplaceInfo(0, 1) As String
Dim ls_LabelCaption As String

    Item_CheckValues = False
    
    For Each lo_Control In UserControl.Controls
    
        If mo_Tools.HasContainer(lo_Control, ao_Frame) Then
            Select Case UCase(TypeName(lo_Control))
                Case "TEXTBOX"
                    If Trim(lo_Control.Tag) <> "" And Trim(lo_Control.Text) <> "" Then
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If UBound(lsa_Columns) >= 2 Then
                            
                            ls_LabelCaption = mo_Tools.GetLabelCaption(UserControl.Controls, ao_Frame, lsa_Columns(2))
                            
                            If lsa_Columns(1) = "F" And IsNumeric(lo_Control.Text) = False Then
                                Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2131, "The field $LabelCaption$ must be numeric.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                                Exit Function
                            End If
                            
                            If lsa_Columns(1) = "N" And mo_Tools.IsIntValue(lo_Control.Text) = False Then
                                Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2121, "The field $LabelCaption$ must be numeric with not decimal.", Array("$LabelCaption$", ls_LabelCaption), vbInformation)
                                Exit Function
                            End If
                        End If
                    End If
            End Select
        End If
    Next
    Item_CheckValues = True
    Exit Function
ErrHandler:
    Item_CheckValues = False
    Call ErrorHandler("Item_CheckValues")
End Function

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

Dim ll_Index As Long

    Call mo_Tools.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
    
    If ls_req <> "" Then
        mc_Item = mo_Tools.OpenSQLSafe(mo_Db, ls_req, 1)
    End If
   
    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)
        
    If mt_DetailConfig(al_DetailIndex).ClearControlsBeforeInit = True Then

        'clear the frame record and disable frames
        Call mo_Tools.ClearFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex))
    End If
    
    
    Call Item_Load(al_DetailIndex, av_Key)
    Call SubItem_Load(al_DetailIndex, av_Key)
    
    Call mo_Tools.EnableFrame(UserControl.Controls, fra_DetailItem(ll_frameIndex), False)
    
    'change screen mode
    Call SetMode(emView, al_DetailIndex)
    
    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 mo_Tools.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, al_DetailConfigIndex)
    
    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
    If ll_MainIndex <> -1 Then
        ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    End If
    'check the data validity -> Item_Check
    If Not Item_CheckMandatory(mt_DetailConfig(al_DetailIndex).ListFieldsMandatory) Then Exit Function
    
    If Not Item_CheckValues(fra_DetailItem(ll_frameIndex)) 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
    
    If ll_MainIndex <> -1 Then
        Call Item_AddLocal(UserControl.Controls, fra_DetailItem(ll_frameIndex), tvw_Main(ll_MainFrameIndex), grd_Main(ll_MainFrameIndex), chk_Repositioning(ll_frameIndex).Value = vbChecked)
    End If
    
    Call Item_CustomLocal(al_DetailIndex, eMode.emAdd)
    
    If ll_MainIndex <> -1 Then
        'go back to the detail screen
        Call Item_ExitToGrid(ll_MainIndex, al_DetailIndex)
        Call SetMode(emList)
    Else
        ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        mt_MainConfig(ll_MainIndex).CurrentDetailIndex = mt_DetailConfig(al_DetailIndex).PreviousDetailIndex
        Call SetMode(me_OldDetailMode)
        'Call SetMode(emAdd)
    End If
    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 = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, 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 = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If ll_Count > 0 Then
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 0), mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 1), , vbInformation + vbOKOnly)
            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 mo_Tools.BeginTran(mo_Db, ml_U_Code, SCREEN_NAME, "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)
        If ls_Request <> "" Then
            ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(ll_frameIndex))
            ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
            ls_Request = ReplaceCommonPlaceholders(ls_Request)
            Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request, IIf(ll_Index = ll_Count, mt_DetailConfig(al_DetailIndex).AffectedCount(0), -1))
        End If
    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 mo_Tools.CommitTran(mo_Db, ml_U_Code, SCREEN_NAME, "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 mo_Tools.RollbackTran(mo_Db, ml_U_Code, SCREEN_NAME, "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 mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 7204, "#Updated item cannot be displayed with current filter")
        '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 mo_Tools.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 mo_Tools.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, al_DetailIndex)
    
    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
    If ll_MainIndex <> -1 Then
        ll_MainFrameIndex = mt_MainConfig(ll_MainIndex).FrameIndex
    End If
    
    'check the data validity -> Item_Check
    If Not Item_CheckMandatory(mt_DetailConfig(al_DetailIndex).ListFieldsMandatory) Then Exit Function
    
    If Not Item_CheckValues(fra_DetailItem(ll_frameIndex)) 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 ->
    If ll_MainIndex <> -1 Then
        Call Item_UpdateLocal(UserControl.Controls, fra_DetailItem(ll_frameIndex), tvw_Main(ll_MainFrameIndex), grd_Main(ll_MainFrameIndex), chk_Repositioning(ll_frameIndex).Value = vbChecked)
    End If
    
    Call Item_CustomLocal(al_DetailIndex, eMode.emUpdate)
        
    If ll_MainIndex <> -1 Then
        'go back to the detail screen
        Call Item_ExitToGrid(ll_MainIndex, al_DetailIndex)
        Call SetMode(emList)
    Else
        ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        mt_MainConfig(ll_MainIndex).CurrentDetailIndex = mt_DetailConfig(al_DetailIndex).PreviousDetailIndex
        Call SetMode(me_OldDetailMode)
    End If

    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 = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_DetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
        
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If ll_Count > 0 Then
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 0), mt_DetailConfig(al_DetailIndex).CheckAddUpdMsg(0, 1), , vbInformation + vbOKOnly)
            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 mo_Tools.BeginTran(mo_Db, ml_U_Code, SCREEN_NAME, "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)
        If ls_Request <> "" Then
        'replace the holders (from the frame record)
            ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, 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 mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request, IIf(ll_Index = 0, mt_DetailConfig(al_DetailIndex).AffectedCount(1), -1))
        End If
    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 mo_Tools.CommitTran(mo_Db, ml_U_Code, SCREEN_NAME, "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 mo_Tools.RollbackTran(mo_Db, ml_U_Code, SCREEN_NAME, "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 mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 7204, "Updated item cannot be displayed with current filter")
        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 mo_Tools.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 mo_Tools.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)
    
    If ll_MainIndex <> -1 Then
        'go back to the detail screen
        Call Item_ExitToGrid(ll_MainIndex, al_DetailIndex)
        Call SetMode(emList)
    Else
        ll_MainIndex = FindMainConfigByName(tbs_Main.SelectedItem.Key)
        mt_MainConfig(ll_MainIndex).CurrentDetailIndex = mt_DetailConfig(al_DetailIndex).PreviousDetailIndex
        Call SetMode(me_OldDetailMode)
    End If

    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 = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, 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 = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        If ll_Count > 0 Then
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_DetailConfig(al_DetailConfigIndex).CheckDelMsg(0, 0), mt_DetailConfig(al_DetailConfigIndex).CheckDelMsg(0, 1), , vbInformation + vbOKOnly)
            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 mo_Tools.BeginTran(mo_Db, ml_U_Code, SCREEN_NAME, "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 = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, 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 mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request, IIf(ll_Index = ll_Count, mt_DetailConfig(al_DetailIndex).AffectedCount(2), -1))
    Next
    
    If lb_inTransaction Then
        Call mo_Tools.CommitTran(mo_Db, ml_U_Code, SCREEN_NAME, "Item_DeleteDB")
        lb_inTransaction = False
    End If
    
    Item_DeleteDB = True
    Exit Function
    
ErrHandler:
    Item_DeleteDB = False
    If lb_inTransaction Then
        Call mo_Tools.RollbackTran(mo_Db, ml_U_Code, SCREEN_NAME, "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) Then
        
            ReDim mt_SubdetailConfig(ll_Index).DeletedRows(-1 To -1)
            Call grd_SubDetail(ll_Index).ClearGrid
            lb_DelayedLoad = (mt_SubdetailConfig(ll_Index).GridDelayMethod = egmDelayedAlways)
            
            Call SubItem_CustomLoad(ll_Index)
            
            If (mt_SubdetailConfig(ll_Index).RequestView <> "") Then
                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
        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_SubdetailConfig(al_SubDetaiIndex).FrameIndex
   
    Call InitSubdetailFrame(al_SubDetaiIndex)
    
    'clear the frame record
    Call mo_Tools.ClearFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex))
    
    Call mo_Tools.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 Item_CheckValues(fra_SubDetailItem(ll_frameIndex)) 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 = mo_Tools.ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, 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 = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If ll_Count > 0 Then
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 0), mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 1), , vbInformation + vbOKOnly)
            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 = mo_Tools.GetNextID(mo_Db, 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 = mo_Tools.ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
            ls_Request = mo_Tools.ReplacePlaceholderByControlValue(ls_Request, txt_SubDetailKey(ll_frameIndex))
            'ls_Request = mo_Tools.ReplacePlaceholderByControlValue(ls_Request, txt_Price_PRD_Id)
            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 mo_Tools.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 mo_Tools.EnableFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex), True)
    
    Call DisableFrameParts(mt_SubdetailConfig(al_SubDetailIndex).ListFieldsToDisable)
        
    'clear the frame record and disable frames
    Call mo_Tools.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 = mo_Tools.ReplacePlaceholderByControlValue(ls_Request, txt_DetailKey(ll_DetailFrameIndex))
        ls_Request = mo_Tools.ReplaceRequestByFrameData(ls_Request, UserControl.Controls, fra_SubDetailItem(ll_frameIndex))
        ls_Request = ReplaceLanguagePlaceholderFromToolbar(ls_Request)
        ls_Request = ReplaceCommonPlaceholders(ls_Request)
        lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
        
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        
        If (ll_Count > 0) Then
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 0), mt_SubdetailConfig(al_SubDetailIndex).CheckAddUpdMsg(0, 1), , vbInformation + vbOKOnly)
            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 = mo_Tools.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 mo_Tools.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 mo_Tools.ClearFrame(UserControl.Controls, fra_SubDetailItem(ll_frameIndex))
    
            
    Call InitSubdetailFrame(al_SubDetailIndex)
        
    Call LoadFrameDataFromGrid(grd_SubDetail(ll_frameIndex), fra_SubDetailItem(ll_frameIndex))
    
    Call mo_Tools.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 = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
        ll_Count = mo_Db.RowCount(lc_Cursor)
        Call mo_Db.Close(lc_Cursor)
        If ll_Count > 0 Then
            Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, mt_SubdetailConfig(al_SubDetailIndex).CheckDelMsg(0, 0), mt_SubdetailConfig(al_SubDetailIndex).CheckDelMsg(0, 1), , vbInformation + vbOKOnly)
            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 = mo_Tools.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 mo_Tools.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 mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 927, "#No more previous item", , vbInformation)
    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 mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 928, "#No more next item", , vbInformation)
    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 = mo_Tools.ReplaceRequestByFrameData(as_Request, UserControl.Controls, 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 = mo_Tools.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 mo_Tools.LoadLabelsCursor(mo_Db, mc_ScreenLabels, UserControl.Controls, 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 = mo_Tools.ReplaceRequestByFrameData(as_CheckRequest, UserControl.Controls, fra_DetailItem(mt_DetailConfig(al_DetailIndex).FrameIndex))
    as_CheckRequest = ReplaceLanguagePlaceholderFromToolbar(as_CheckRequest)
    as_CheckRequest = ReplaceCommonPlaceholders(as_CheckRequest)
    
    as_UnCheckRequest = mo_Tools.ReplaceRequestByFrameData(as_UnCheckRequest, UserControl.Controls, 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, mo_Tools.SqlInt(Mid(lo_item.Key, 4)))
            Call mo_Tools.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 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) & "$", mo_Tools.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$", mo_Tools.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$", mo_Tools.SqlStr(ms_Language_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$Z_Creator$", mo_Tools.SqlInt(ml_U_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$U_Code$", mo_Tools.SqlInt(ml_U_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$Z_Last_Upd_User$", mo_Tools.SqlInt(ml_U_Code))
    as_Request = ReplacePlaceHolder(as_Request, "$LoginName$", mo_Tools.SqlStr(ms_LoginName))
    as_Request = ReplacePlaceHolder(as_Request, "$UserName$", mo_Tools.SqlStr(ms_UserName))
    as_Request = ReplacePlaceHolder(as_Request, "$ComputerName$", mo_Tools.SqlStr(ms_ComputerName))
    as_Request = ReplacePlaceHolder(as_Request, "$NetworkBoardID$", mo_Tools.SqlStr(ms_NetworkBoardID))
    ReplaceCommonPlaceholders = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceCommonPlaceholders")
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 mo_Tools.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 mo_Tools.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)) = mo_Tools.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"
                    lsa_Columns = Split(lo_Control.Tag, SEP)
                    If UBound(lsa_Columns) > 0 Then
                      Select Case UCase(lsa_Columns(1))
                      Case "N", "F"
                        ao_grid.SelectedLine(0, lsa_Value(0)) = CDbl(lo_Control.Text)
                      Case Else
                        ao_grid.SelectedLine(0, lsa_Value(0)) = lo_Control.Text
                      End Select
                    Else
                        ao_grid.SelectedLine(0, lsa_Value(0)) = lo_Control.Text
                    End If

                Case "A_CALOCX"
                    ao_grid.SelectedLine(0, lsa_Value(0)) = lo_Control.date_sql
            End Select
        End If
    Next
    UpdateGridByFrame = True
    Exit Function
ErrHandler:
    Call ErrorHandler("UpdateGridByFrame")
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 = mo_Tools.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 = mo_Tools.SqlInt(ao_grid.Data(al_Row, ll_ColIndex))
        Case DBTYPE_R4, DBTYPE_R8
            ls_Data = mo_Tools.SqlDbl(ao_grid.Data(al_Row, ll_ColIndex))
        Case DBTYPE_DATE
            ls_Data = mo_Tools.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 = mo_Tools.SqlStr("X")
            Case "UNCHECK"
                ls_Data = mo_Tools.SqlStr("")
            End Select
        Case Else
            ls_Data = mo_Tools.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 = mo_Tools.SqlInt(ao_data(al_Row)(ll_ColIndex))
        Case DBTYPE_R4, DBTYPE_R8
            ls_Data = mo_Tools.SqlDbl(ao_data(al_Row)(ll_ColIndex))
        Case DBTYPE_DATE
            ls_Data = mo_Tools.SqlDate(ao_data(al_Row)(ll_ColIndex))
        Case DBTYPE_BMP
            Select Case UCase(ao_data(al_Row)(ll_ColIndex))
            Case "CHECK"
                ls_Data = mo_Tools.SqlStr("X")
            Case "UNCHECK"
                ls_Data = mo_Tools.SqlStr("")
            End Select
        Case Else
            ls_Data = mo_Tools.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 mo_Tools.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 = mo_Tools.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 mo_Tools.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 mo_Tools.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
                        lsa_Columns = Split(lo_Control.Tag, SEP)
                        If UBound(lsa_Columns) >= 0 Then
                            lo_Control.Text = ao_grid.CurrentLine(lsa_Columns(0))
                        End If
                    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 = mo_Tools.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 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 = mo_Tools.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
' ************************************************************************************

' 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$", mo_Tools.SqlStr(as_LogType))
    ls_req = ReplacePlaceHolder(ls_req, "$MSG$", Left(Trim(mo_Tools.SqlStr(ls_Msg)), 4000))
    ls_req = ReplacePlaceHolder(ls_req, "$APP$", Left(Trim(mo_Tools.SqlStr(ls_Source)), 50))
    
    Call mo_Tools.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

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


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=" & mo_Tools.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 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
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9855, "#Application cannot map drive $DRIVE$ to $PATH$." & vbCrLf & "$ERROR$" & vbCrLf & "Try it manually or call application support please.", Array("$DRIVE$", as_drive, "$PATH$", as_remotePath, "$ERROR$", Err.Number & " - " & Err.Description))
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

