VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl Capcus 
   ClientHeight    =   11565
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   13320
   ScaleHeight     =   11565
   ScaleWidth      =   13320
   ToolboxBitmap   =   "Capcus.ctx":0000
   Begin Project1.ArmBusCard BCC 
      Height          =   615
      Left            =   4560
      TabIndex        =   80
      Top             =   0
      Visible         =   0   'False
      Width           =   1935
      _ExtentX        =   3413
      _ExtentY        =   1085
   End
   Begin VB.Frame fraItem 
      Height          =   9405
      Left            =   360
      TabIndex        =   0
      Top             =   480
      Width           =   10755
      Begin VB.Frame fraItemBottom 
         Height          =   2355
         Left            =   240
         TabIndex        =   35
         Top             =   6480
         Width           =   10335
         Begin Project1.ArmCheckView acv_Rep 
            Height          =   1815
            Left            =   5880
            TabIndex        =   34
            Tag             =   "acv_Rep"
            Top             =   480
            Width           =   4335
            _ExtentX        =   7646
            _ExtentY        =   3201
         End
         Begin Project1.ArmCheckView0 CkvMarket 
            Height          =   1815
            Left            =   2955
            TabIndex        =   32
            Tag             =   "CkvMarket"
            Top             =   480
            Width           =   2850
            _extentx        =   5027
            _extenty        =   3201
         End
         Begin Project1.ArmCheckView0 CkvAttribute 
            Height          =   1815
            Left            =   75
            TabIndex        =   31
            Tag             =   "CkvAttribute"
            Top             =   480
            Width           =   2850
            _extentx        =   5027
            _extenty        =   3201
         End
         Begin VB.Label lbl_salesReps 
            Caption         =   "#Sales Reps"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5880
            TabIndex        =   57
            Tag             =   "lbl_salesReps"
            Top             =   180
            Width           =   2000
         End
         Begin VB.Label lbl_role 
            Caption         =   "#Role"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   7935
            TabIndex        =   56
            Tag             =   "lbl_role"
            Top             =   180
            Visible         =   0   'False
            Width           =   2000
         End
         Begin VB.Label lbl_MKS 
            Caption         =   "#Market segment"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   2985
            TabIndex        =   55
            Tag             =   "lbl_MKS"
            Top             =   180
            Width           =   2850
         End
         Begin VB.Label lbl_attribute 
            Caption         =   "#Customer attributes"
            Height          =   255
            Left            =   120
            TabIndex        =   54
            Tag             =   "lbl_attribute"
            Top             =   165
            Width           =   2850
         End
      End
      Begin Project1.ToolBr pbitem 
         Height          =   615
         Left            =   180
         TabIndex        =   70
         Top             =   180
         Width           =   1335
         _extentx        =   2355
         _extenty        =   1085
      End
      Begin VB.Frame fraItemTop 
         Height          =   5700
         Left            =   240
         TabIndex        =   36
         Top             =   840
         Width           =   10335
         Begin Project1.ArmGrid grd_searchZip 
            Height          =   3510
            Left            =   2100
            TabIndex        =   91
            Top             =   1245
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   6191
         End
         Begin VB.CommandButton btn_pickZip 
            Caption         =   ".."
            Height          =   270
            Left            =   1785
            TabIndex        =   90
            Tag             =   "btn_pickZip"
            Top             =   1290
            Width           =   285
         End
         Begin VB.CheckBox chk_opted_out 
            Alignment       =   1  'Right Justify
            BackColor       =   &H80000000&
            Caption         =   "#Opt out communication"
            Height          =   420
            Left            =   5205
            TabIndex        =   89
            Tag             =   "lbl_opted_out"
            Top             =   4065
            Value           =   1  'Checked
            Width           =   1920
         End
         Begin VB.TextBox txt_automaticMargin 
            Height          =   330
            Left            =   2970
            MaxLength       =   5
            TabIndex        =   87
            Top             =   3765
            Visible         =   0   'False
            Width           =   945
         End
         Begin VB.CommandButton btn_Search 
            Caption         =   "..."
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   4845
            TabIndex        =   85
            Top             =   4185
            Width           =   330
         End
         Begin VB.CheckBox chk_DropFlag 
            Alignment       =   1  'Right Justify
            Caption         =   "#Drop flag"
            Enabled         =   0   'False
            Height          =   255
            Left            =   120
            TabIndex        =   25
            Tag             =   "DropFlag"
            Top             =   5355
            Width           =   1845
         End
         Begin VB.TextBox txt_DropDate 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   2100
            Locked          =   -1  'True
            TabIndex        =   26
            Top             =   5310
            Width           =   1400
         End
         Begin VB.CheckBox chk_UpdateTV 
            Caption         =   "Search item in the list after update"
            Height          =   375
            Left            =   11040
            TabIndex        =   82
            Tag             =   "chk_UpdateTV"
            Top             =   240
            Value           =   1  'Checked
            Width           =   3135
         End
         Begin VB.TextBox txt_Email 
            Height          =   330
            Left            =   7200
            MaxLength       =   78
            TabIndex        =   17
            Tag             =   "txt_Email"
            Top             =   2340
            Width           =   3015
         End
         Begin VB.CommandButton bt_Bcc 
            Caption         =   "#Business Card"
            Height          =   450
            Left            =   5640
            TabIndex        =   79
            Tag             =   "lbl_cmdBcc"
            Top             =   4710
            Width           =   1875
         End
         Begin VB.TextBox txt_CstKey 
            Height          =   330
            Left            =   7080
            Locked          =   -1  'True
            TabIndex        =   27
            Tag             =   "txt_CstKey"
            Top             =   5310
            Width           =   3015
         End
         Begin Project1.ArmCombobox cbo_country 
            Height          =   345
            Left            =   2100
            TabIndex        =   12
            Tag             =   "cbo_country"
            Top             =   1620
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_county 
            Height          =   345
            Left            =   7200
            TabIndex        =   13
            Tag             =   "cbo_county"
            Top             =   1620
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_priority 
            Height          =   345
            Left            =   2100
            TabIndex        =   20
            Tag             =   "cbo_priority"
            Top             =   3060
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_type 
            Height          =   345
            Left            =   2100
            TabIndex        =   18
            Tag             =   "cbo_type"
            Top             =   2700
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin VB.CommandButton bt_Address 
            Caption         =   "#Postal Address"
            Height          =   450
            Left            =   3720
            TabIndex        =   30
            Tag             =   "lbl_cmdPostal"
            Top             =   4710
            Width           =   1875
         End
         Begin Project1.ArmCheckView0 ckvStratAccount 
            Height          =   1320
            Left            =   7200
            TabIndex        =   22
            Tag             =   "ckvStratAccount"
            Top             =   3060
            Width           =   3015
            _extentx        =   5318
            _extenty        =   2963
         End
         Begin Project1.A_SrchTxt srch_primcontact 
            Height          =   330
            Left            =   2100
            TabIndex        =   23
            Tag             =   "srch_primcontact"
            Top             =   3405
            Width           =   3015
            _extentx        =   4048
            _extenty        =   582
         End
         Begin VB.TextBox txt_spare4 
            Height          =   330
            Left            =   7800
            TabIndex        =   61
            Top             =   4815
            Visible         =   0   'False
            Width           =   2300
         End
         Begin VB.TextBox txt_spare3 
            Height          =   330
            Left            =   7815
            TabIndex        =   60
            Top             =   4785
            Visible         =   0   'False
            Width           =   2300
         End
         Begin VB.TextBox txt_spare2 
            Height          =   330
            Left            =   7770
            TabIndex        =   59
            Top             =   4770
            Visible         =   0   'False
            Width           =   2300
         End
         Begin VB.TextBox txt_spare1 
            Height          =   330
            Left            =   7830
            TabIndex        =   58
            Top             =   4785
            Visible         =   0   'False
            Width           =   2300
         End
         Begin VB.TextBox txt_zip2 
            BackColor       =   &H00FFFFFF&
            Height          =   330
            Left            =   3490
            MaxLength       =   10
            TabIndex        =   10
            Tag             =   "txt_zip2"
            Top             =   1245
            Width           =   1620
         End
         Begin VB.TextBox txt_zip1 
            BackColor       =   &H00FFFFFF&
            Height          =   330
            Left            =   2100
            MaxLength       =   10
            TabIndex        =   9
            Tag             =   "txt_zip1"
            Top             =   1245
            Width           =   1400
         End
         Begin VB.TextBox txt_address2 
            Height          =   330
            Left            =   2100
            MaxLength       =   80
            TabIndex        =   8
            Tag             =   "txt_address2"
            Top             =   900
            Width           =   8100
         End
         Begin VB.TextBox txt_address1 
            Height          =   330
            Left            =   2100
            MaxLength       =   80
            TabIndex        =   7
            Text            =   "txt_address1"
            Top             =   540
            Width           =   8100
         End
         Begin VB.TextBox txt_town 
            Height          =   330
            Left            =   7200
            MaxLength       =   80
            TabIndex        =   11
            Tag             =   "txt_town"
            Top             =   1260
            Width           =   3015
         End
         Begin VB.TextBox txt_desc 
            Height          =   330
            Left            =   2100
            MaxLength       =   80
            TabIndex        =   6
            Tag             =   "txt_desc"
            Top             =   180
            Width           =   8100
         End
         Begin VB.TextBox txt_SAPCode 
            Enabled         =   0   'False
            Height          =   330
            Left            =   2100
            Locked          =   -1  'True
            TabIndex        =   24
            Tag             =   "txt_SAPCode"
            Top             =   4155
            Width           =   3015
         End
         Begin VB.CheckBox chk_StategicAccount 
            Alignment       =   1  'Right Justify
            BackColor       =   &H80000000&
            Caption         =   "#Strategic account"
            Height          =   315
            Left            =   5220
            TabIndex        =   21
            Tag             =   "lb_SA"
            Top             =   3120
            Value           =   1  'Checked
            Width           =   1920
         End
         Begin VB.TextBox txt_dateEntered 
            Alignment       =   2  'Center
            Height          =   330
            Left            =   2100
            Locked          =   -1  'True
            TabIndex        =   28
            Tag             =   "txt_dateEntered"
            Text            =   "28/2/2001"
            Top             =   4515
            Width           =   1400
         End
         Begin VB.TextBox txt_lastUpdated 
            Alignment       =   2  'Center
            Height          =   330
            Left            =   2100
            Locked          =   -1  'True
            TabIndex        =   29
            Tag             =   "txt_lastUpdated"
            Text            =   "28/2/2001"
            Top             =   4875
            Width           =   1400
         End
         Begin VB.TextBox txt_tel 
            Height          =   330
            Left            =   2100
            MaxLength       =   20
            TabIndex        =   14
            Top             =   1980
            Width           =   3015
         End
         Begin VB.TextBox txt_fax 
            Height          =   330
            Left            =   7200
            MaxLength       =   20
            TabIndex        =   15
            Tag             =   "txt_fax"
            Top             =   1980
            Width           =   3015
         End
         Begin VB.TextBox txt_webSite 
            Height          =   330
            Left            =   2100
            MaxLength       =   160
            TabIndex        =   16
            Top             =   2340
            Width           =   3045
         End
         Begin Project1.ArmCombobox cbo_Loyalty 
            Height          =   345
            Left            =   7200
            TabIndex        =   19
            Tag             =   "cbo_Loyalty"
            Top             =   2700
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin VB.Label lbl_percent 
            Caption         =   "%"
            Height          =   255
            Left            =   4020
            TabIndex        =   88
            Tag             =   "lbl_percent"
            Top             =   3825
            Visible         =   0   'False
            Width           =   345
         End
         Begin VB.Label lbl_autoMargin 
            Caption         =   "#% additional for installation"
            Height          =   255
            Left            =   120
            TabIndex        =   86
            Tag             =   "lbl_autoMargin"
            Top             =   3825
            Visible         =   0   'False
            Width           =   2775
         End
         Begin VB.Label lbl_Loyalty 
            Caption         =   "#Loyalty"
            Height          =   255
            Left            =   5220
            TabIndex        =   84
            Tag             =   "cbo_Loyalty"
            Top             =   2820
            Width           =   1920
         End
         Begin VB.Label lbl_Email 
            Caption         =   "#Email"
            Height          =   255
            Left            =   5220
            TabIndex        =   81
            Tag             =   "lbl_email"
            Top             =   2400
            Width           =   1920
         End
         Begin VB.Label lbl_CstKey 
            Caption         =   "#Customer Key"
            Height          =   255
            Left            =   5400
            TabIndex        =   73
            Tag             =   "lbl_CstKey"
            Top             =   5400
            Width           =   1680
         End
         Begin VB.Label lbl_spare4 
            Caption         =   "#lbl_spare4"
            Height          =   195
            Left            =   7665
            TabIndex        =   65
            Tag             =   "lbl_spare4"
            Top             =   4635
            Visible         =   0   'False
            Width           =   1035
         End
         Begin VB.Label lbl_spare3 
            Caption         =   "#lbl_spare3"
            Height          =   195
            Left            =   7620
            TabIndex        =   64
            Tag             =   "lbl_spare3"
            Top             =   4635
            Visible         =   0   'False
            Width           =   1035
         End
         Begin VB.Label lbl_spare2 
            Caption         =   "#lbl_spare2"
            Height          =   195
            Left            =   7620
            TabIndex        =   63
            Tag             =   "lbl_spare2"
            Top             =   4605
            Visible         =   0   'False
            Width           =   1035
         End
         Begin VB.Label lbl_spare1 
            Caption         =   "#lbl_spare1"
            Height          =   195
            Left            =   7635
            TabIndex        =   62
            Tag             =   "lbl_spare1"
            Top             =   4620
            Visible         =   0   'False
            Width           =   1035
         End
         Begin VB.Label lbl_country 
            Caption         =   "#Country"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   53
            Tag             =   "lbl_country"
            Top             =   1680
            Width           =   1920
         End
         Begin VB.Label lbl_county 
            Caption         =   "#County"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5220
            TabIndex        =   52
            Tag             =   "lbl_county"
            Top             =   1680
            Width           =   1920
         End
         Begin VB.Label lbl_town 
            Caption         =   "#Town"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   5220
            TabIndex        =   51
            Tag             =   "lbl_town"
            Top             =   1320
            Width           =   1920
         End
         Begin VB.Label lbl_address 
            Caption         =   "#Address"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   50
            Tag             =   "lbl_address"
            Top             =   570
            Width           =   1920
         End
         Begin VB.Label lbl_Desc 
            Caption         =   "#Name"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   49
            Tag             =   "lbl_desc"
            Top             =   225
            Width           =   1920
         End
         Begin VB.Label lbl_zip 
            Caption         =   "#Zip code"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   120
            TabIndex        =   48
            Tag             =   "lbl_zip"
            Top             =   1320
            Width           =   1920
         End
         Begin VB.Label lbl_priority 
            Caption         =   "#Customer priority"
            Height          =   255
            Left            =   120
            TabIndex        =   47
            Tag             =   "lbl_priority"
            Top             =   3120
            Width           =   1920
         End
         Begin VB.Label lbl_type 
            Caption         =   "#Customer type"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   46
            Tag             =   "lbl_type"
            Top             =   2760
            Width           =   1920
         End
         Begin VB.Label lbl_primContact 
            Caption         =   "#Primary contact"
            Height          =   255
            Left            =   120
            TabIndex        =   45
            Tag             =   "lbl_primContact"
            Top             =   3480
            Width           =   1920
         End
         Begin VB.Label lbl_SAPCode 
            Caption         =   "#SAP Code"
            Enabled         =   0   'False
            Height          =   255
            Left            =   120
            TabIndex        =   44
            Tag             =   "lbl_SAPCode"
            Top             =   4215
            Width           =   1920
         End
         Begin VB.Label lbl_lastUpdated 
            Caption         =   "#Last Updated"
            Enabled         =   0   'False
            Height          =   255
            Left            =   120
            TabIndex        =   43
            Tag             =   "lbl_lastUpdated"
            Top             =   4935
            Width           =   1920
         End
         Begin VB.Label lbl_dateEntered 
            Caption         =   "#Date Entered"
            Enabled         =   0   'False
            Height          =   255
            Left            =   120
            TabIndex        =   42
            Tag             =   "lbl_dateEntered"
            Top             =   4575
            Width           =   1920
         End
         Begin VB.Label lbl_tel 
            Caption         =   "#Phone"
            Height          =   255
            Left            =   120
            TabIndex        =   41
            Tag             =   "lbl_phone"
            Top             =   2040
            Width           =   1920
         End
         Begin VB.Label lbl_fax 
            Caption         =   "#Fax"
            Height          =   255
            Left            =   5220
            TabIndex        =   40
            Tag             =   "lbl_fax"
            Top             =   2040
            Width           =   1920
         End
         Begin VB.Label lbl_webSite 
            Caption         =   "#Web Site"
            Height          =   255
            Left            =   120
            TabIndex        =   39
            Tag             =   "lbl_webSite"
            Top             =   2400
            Width           =   1920
         End
      End
      Begin MSComctlLib.TabStrip tbsEmbedded 
         Height          =   375
         Left            =   240
         TabIndex        =   33
         Top             =   8880
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   661
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   1
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
   End
   Begin VB.Frame fraFilters 
      Height          =   8415
      Left            =   90
      TabIndex        =   37
      Top             =   105
      Width           =   4206
      Begin VB.CheckBox chk_isInitTV 
         Height          =   285
         Left            =   3870
         TabIndex        =   92
         Tag             =   "chk_isInitTV"
         ToolTipText     =   "#Initial treeview"
         Top             =   2700
         Width           =   225
      End
      Begin VB.PictureBox pctTvReset 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   240
         Left            =   0
         Picture         =   "Capcus.ctx":0312
         ScaleHeight     =   16
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   16
         TabIndex        =   77
         Top             =   110
         Width           =   240
      End
      Begin Project1.ArmCombobox cbo_date 
         Height          =   345
         Left            =   120
         TabIndex        =   3
         Top             =   2160
         Visible         =   0   'False
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Left            =   600
         TabIndex        =   4
         Top             =   2640
         Width           =   3180
         _ExtentX        =   5609
         _ExtentY        =   609
      End
      Begin VB.PictureBox reload_treeview 
         Appearance      =   0  'Flat
         BackColor       =   &H80000000&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   540
         Left            =   120
         ScaleHeight     =   405
         ScaleMode       =   0  'User
         ScaleWidth      =   570
         TabIndex        =   74
         Top             =   3120
         Width           =   570
      End
      Begin Project1.ArmTreeView tvitems 
         Height          =   4170
         Left            =   120
         TabIndex        =   5
         Top             =   3120
         Width           =   975
         _ExtentX        =   1720
         _ExtentY        =   7355
      End
      Begin Project1.A_calocx cal11 
         Height          =   375
         Left            =   120
         TabIndex        =   2
         Top             =   1680
         Visible         =   0   'False
         Width           =   1815
         _ExtentX        =   3201
         _ExtentY        =   661
      End
      Begin Project1.A_calocx cal12 
         Height          =   375
         Left            =   2160
         TabIndex        =   68
         Top             =   1680
         Visible         =   0   'False
         Width           =   1815
         _ExtentX        =   3201
         _ExtentY        =   661
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#Between"
         Height          =   255
         Index           =   1
         Left            =   1920
         TabIndex        =   66
         Tag             =   "opt_between"
         Top             =   1320
         Width           =   2200
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#All"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   1
         Tag             =   "opt_all"
         Top             =   1320
         Value           =   -1  'True
         Width           =   1800
      End
      Begin MSComctlLib.TabStrip tbsFilters 
         Height          =   375
         Left            =   90
         TabIndex        =   72
         Top             =   7830
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   661
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   3
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#All"
               Key             =   "A"
               Object.Tag             =   "tbs_filtersAll"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#S.A"
               Key             =   "X"
               Object.Tag             =   "tbs_filtersSA"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Non S.A"
               Key             =   "N"
               Object.Tag             =   "tbs_filtersNonSA"
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin MSComctlLib.TabStrip tbsArchive 
         Height          =   375
         Left            =   120
         TabIndex        =   83
         Top             =   480
         Width           =   3615
         _ExtentX        =   6376
         _ExtentY        =   661
         MultiRow        =   -1  'True
         Style           =   1
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   3
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#All"
               Key             =   "K"
               Object.Tag             =   "tbsArchivedAll"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Non archived"
               Key             =   "K0"
               Object.Tag             =   "tbsArchivedNA"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Archived"
               Key             =   "K1"
               Object.Tag             =   "tbsArchivedA"
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin VB.Label lbl_DateRange 
         Caption         =   "#Date range"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   78
         Tag             =   "lbl_DateRange"
         Top             =   960
         Width           =   1215
      End
      Begin VB.Label lbl_view 
         Caption         =   "#View"
         Height          =   195
         Left            =   120
         TabIndex        =   67
         Tag             =   "lbl_view"
         Top             =   2760
         Width           =   495
      End
   End
   Begin VB.Frame fraList 
      Height          =   3315
      Left            =   4440
      TabIndex        =   38
      Top             =   720
      Width           =   7470
      Begin Project1.ArmGrid grdlst 
         Height          =   1935
         Left            =   240
         TabIndex        =   75
         Top             =   1080
         Width           =   4455
         _ExtentX        =   7858
         _ExtentY        =   3413
      End
      Begin VB.PictureBox fill_all_record 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   600
         Left            =   3015
         ScaleHeight     =   600
         ScaleWidth      =   600
         TabIndex        =   71
         Top             =   120
         Visible         =   0   'False
         Width           =   600
      End
      Begin Project1.ToolBr pblst 
         Height          =   435
         Left            =   300
         TabIndex        =   69
         Top             =   180
         Width           =   2535
         _extentx        =   4471
         _extenty        =   1402
      End
      Begin VB.Label lbl_ListFilter 
         Alignment       =   2  'Center
         BackColor       =   &H0000FFFF&
         Caption         =   "#All "
         Height          =   375
         Left            =   360
         TabIndex        =   76
         Top             =   720
         Width           =   4935
      End
   End
End
Attribute VB_Name = "Capcus"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

' Reference to the template defined in the table CM_Templates
Private Const C_TEMPLATE_BUSINESS_CARD_CONTRACTOR As Byte = 1
Private Const SEP As String = "®©"
Private Const SEP1 As String = "®"
Private Const SEP2 As String = "©"
Private Const C_ACCOUNTHOLDER As String = "6"

'******** Curseur de connexion
Private mo_ArmDb As Object
Private mb_Created As Boolean
Private mb_use_framework_connection As Boolean
Private ms_ConnectString As String
Private ms_UID As String


'******** Propriétés de Cap_Project

'******** AFFICHAGE ****************************************************************
Private mt_CstValues As Type_CstValues          ' Structure which contains constants value
Private mi_DisplayMode As Variant       ' Current display mode
Private mi_OldDisplayMode As Variant    ' Old display mode, need for know parameters
Private mi_EmbeddedIn As Integer        ' Indicates the tag  of the component which embed this component
Private mi_EmbedTag As Integer          ' Indicates the tag of the last component embedded
Private mi_CptTag As Integer            ' Tag of the component type
Private mb_Root As Boolean              ' Indicates if the component is the focus of the user
Private mb_InternalInit As Boolean      ' set true while loading data into controls to suppress event handlers

'******** Clé en cours (enreg. en cours de visu ou modif ou delete
Private m_CurrentKey1 As String 'ccu_capkey
Private m_CurrentKey2 As String
Private m_CurrentKey3 As String

Private m_Language As String

'******** iConccurency of current Record
Private p_iCon As Integer

'******** Type de l'objet (1=Normal, liste longue; 2=Liste courte)
Private mi_TypeList As Integer
Private mi_TypeParam As Integer

Private m_Project As String 'For the property .Project, display in ShortList
Private m_Contact As String 'For the property .Contact, display in ShortList
Private m_Memo As String 'For the property .Memo, display in ShortList
Private m_Action As String 'For the property .Action, display in ShortList
Private m_Product As String 'For the property .Product, display in ShortList

' Ask the application to change the size of component
Public Event SwitchToView(ByVal li_View As Integer)
' Ask the application to simulate encapsulation of a component by resizing it and push it to front
Public Event Catch(ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
' Ask the application to release the encapsulation : hide the component embedded
Public Event Release()
Public Event quit()
Public Event HideGrid(AParentID As Integer)

Public Event Updated() ' Indicates if user update date when it's embedded
Public Event UnlockNavigation()

Private p_DefaultValues(MAX_VALUE) As DefaultValue
Private p_DefaultValuesCount As Integer
Private p_DefaultValuesLoaded As Boolean

Private mb_OriginalAMCExists As Boolean

Public mb_CycleReset As Boolean

Private mv_Old_txt_Zip1 As Variant
Private mv_Old_txt_Zip2 As Variant
Private mv_Old_cbo_Type As Variant
Private mb_ZipCorrect As Boolean        ' Zip is correct or not
Private ms_OldCodeCountry As String
Private ms_View_Key As String
Private ms_initTreeview As String       ' initial treeview defined in DefaultValue or "Vk" if not

' Patch to manage the attribute
Private mAttributes As Long

'For Cust_Code
Private mb_AccountHolder As Boolean

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


Public Property Set ArmDb(ByRef ao_local_connection As Object)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ArmDb_Set"
    #End If
    CapMouseOff
    
    If Not (ao_local_connection Is Nothing) Then
        Set mo_ArmDb = ao_local_connection
        mb_use_framework_connection = True
        Set grdlst.ArmDb = mo_ArmDb
        Set pblst.ArmDb = mo_ArmDb
        Set pbItem.ArmDb = mo_ArmDb
        Set tvitems.ArmDb = mo_ArmDb
        Set srch_primcontact.ArmDb = mo_ArmDb
        Set CkvAttribute.ArmDb = mo_ArmDb
        Set CkvMarket.ArmDb = mo_ArmDb
        Set ckvStratAccount.ArmDb = mo_ArmDb
        'Set ckvSalesRep.ArmDB = mo_ArmDb
        Set Cbo_View.ArmDb = mo_ArmDb
        Set cbo_Type.ArmDb = mo_ArmDb
        Set cbo_Priority.ArmDb = mo_ArmDb
        Set cbo_County.ArmDb = mo_ArmDb
        Set cbo_country.ArmDb = mo_ArmDb
        Set cbo_date.ArmDb = mo_ArmDb
        Set BCC.ArmDb = mo_ArmDb
        Set cbo_Loyalty.ArmDb = mo_ArmDb
        Set grd_searchZip.ArmDb = mo_ArmDb
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ArmDb_Set"
    #End If
    CapMouseOn
End Property

Property Let ConnectString(as_ConnectString As String)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ConnectString_Let", "as_ConnectString=" & as_ConnectString
    #End If
    CapMouseOff
    
    ms_UID = ConnectionStringValidation(as_ConnectString)
    If ms_UID = "" Then GoTo Trace_End
    
    ms_ConnectString = as_ConnectString
    
    'Affectation aux objets
    grdlst.ConnectString = ms_ConnectString
    pblst.ConnectString = ms_ConnectString
    pbItem.ConnectString = ms_ConnectString
    tvitems.ConnectString = ms_ConnectString
    srch_primcontact.ConnectString = ms_ConnectString
    CkvAttribute.ConnectString = ms_ConnectString
    CkvMarket.ConnectString = ms_ConnectString
    ckvStratAccount.ConnectString = ms_ConnectString
    'ckvSalesRep.ConnectString = ms_ConnectString
    Cbo_View.ConnectString = ms_ConnectString
    cbo_Type.ConnectString = ms_ConnectString
    cbo_Priority.ConnectString = ms_ConnectString
    cbo_County.ConnectString = ms_ConnectString
    cbo_country.ConnectString = ms_ConnectString
    cbo_date.ConnectString = ms_ConnectString
    cbo_Loyalty.ConnectString = ms_ConnectString
    grd_searchZip.ConnectString = ms_ConnectString
    BCC.Username = ms_UID
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ConnectString_Let"
    #End If
    CapMouseOn
End Property

Property Let Language(as_Language As String)

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Language_Let", "as_Language=" & as_Language
    #End If
    CapMouseOff
    
    m_Language = as_Language
    
    'ckvSalesRep.Language = m_Language
    CkvAttribute.Language = m_Language
    CkvMarket.Language = m_Language
    ckvStratAccount.Language = m_Language
    tvitems.Language = m_Language
    pbItem.Language = m_Language
    pblst.Language = m_Language
    srch_primcontact.Language = m_Language
    cal11.Language = m_Language
    cal12.Language = m_Language
    BCC.Language_Code = m_Language

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Language_Let"
    #End If
    CapMouseOn
End Property

Private Sub CboView_Resize(ALabel As Label, ACboView As Object, AFrame As Frame)
Dim LMargin As Integer

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CboView_Resize"
    #End If
    
    LMargin = 100
    
    ALabel.AutoSize = True
    ALabel.Left = LMargin
    ACboView.Left = ALabel.Left + ALabel.Width + LMargin
    ACboView.Width = AFrame.Width - ACboView.Left - LMargin - chk_isInitTV.Width - LMargin
    chk_isInitTV.Left = ACboView.Width + ACboView.Left + LMargin
    
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CboView_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CboView_Resize"
    CapMouseOn
End Sub


Private Sub DrawMainGrid()
Dim la_Columns(9) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:DrawMainGrid"
    #End If
    
    mi_TypeList = 1

    pblst.ClearAllIcons
    pblst.TableName = mt_CstValues.SecurityCustomer
    pblst.PictureDisplayed = "P_Refresh=7 P_View=-4 P_Excel=-3 P_Print=-6 P_Quit=-1"

    grdlst.ResetGrid
    grdlst.Title = "Customer"
    grdlst.MultiSelect = True
    
    la_Columns(0) = "ccu_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "ccu_capkey" & CH_LDELIMIT & "ccu_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(2) = "ccu_desc" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ccu_desc" & CH_LDELIMIT & "ccu_desc"
    la_Columns(3) = "zip" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "zip" & CH_LDELIMIT & "zip"
    la_Columns(4) = "ccu_town" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ccu_town" & CH_LDELIMIT & "ccu_town"
    la_Columns(5) = "ccu_tel" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ccu_tel" & CH_LDELIMIT & "ccu_tel"
    la_Columns(6) = "cct_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "cct_desc" & CH_LDELIMIT & "cct_desc"
    la_Columns(7) = "sr_name" & CH_LDELIMIT & "1300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sr_name" & CH_LDELIMIT & "sr_name"
    la_Columns(8) = "cp_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "cp_desc" & CH_LDELIMIT & "cp_desc"
    la_Columns(9) = "LOY_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LOY_desc" & CH_LDELIMIT & "LOY_desc"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_customer_longlist', 'grid', '" & m_Language & "'", ctColumns
    
    
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:DrawMainGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:DrawMainGrid"
    CapMouseOn
End Sub

Public Sub GoToTab1()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:GoToTab1"
    #End If
    
    
    If UserControl.tbsEmbedded.Tabs.Count > 0 Then
        UserControl.tbsEmbedded.Tabs(1).Selected = True
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:GoToTab1"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:GoToTab1"
    CapMouseOn
End Sub

Private Sub SelectFirst()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:SelectFirst"
    #End If
    
    grdlst.FirstLine
    'grdlst.SelectItem
    grdLst_ItemSelected
    'If grdlst.CurrentKey <> "" Then DisplayMode = mt_CstValues.DisplayMode_View

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:SelectFirst"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:SelectFirst"
    CapMouseOn
End Sub

Private Sub InitParentKey()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:InitParentKey"
    #End If
    
    m_Project = ""
    m_Memo = ""
    m_Contact = ""
    m_Product = ""
    m_Action = ""

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:InitParentKey"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:InitParentKey"
    CapMouseOn
End Sub

Private Sub InitView_UK()

    lbl_Town.Top = 1320
    lbl_Town.Left = 120
    txt_Town.Top = 1245
    txt_Town.Left = 2100
    txt_Town.TabIndex = 9
    
    lbl_County.Top = 1320
    lbl_County.Left = 5220
    cbo_County.Top = 1260
    cbo_County.Left = 7200
    cbo_County.TabIndex = 10
    
    lbl_zip.Top = 1680
    lbl_zip.Left = 120
    txt_Zip1.Top = 1620
    txt_Zip1.Left = 2100
    txt_Zip1.TabIndex = 11
    txt_Zip2.Top = 1620
    txt_Zip2.Left = 3490
    txt_Zip2.TabIndex = 12
    
    grd_searchZip.Top = txt_Zip1.Top
    grd_searchZip.Left = txt_Zip1.Left
    
    btn_pickZip.Left = txt_Zip1.Left - btn_pickZip.Width - 25
    btn_pickZip.Top = txt_Zip1.Top + 10
    
    lbl_Country.Top = 1680
    lbl_Country.Left = 5220
    cbo_country.Top = 1620
    cbo_country.Left = 7200
    cbo_country.TabIndex = 13
    
End Sub

Private Sub InitCkvMarket()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:InitCkvMarket"
    #End If
    
    CkvMarket.Clear
      
    Select Case mi_DisplayMode
    
        Case mt_CstValues.DisplayMode_Add
            CkvMarket.EditRequest = "exec Cap_CompanyMarket_lst2 $0$ , '" & m_Language & "'"
            CkvMarket.MasterID = ""
            CkvMarket.Mode = ListLoadMode.ModeEdit
            
        Case mt_CstValues.DisplayMode_Update
            CkvMarket.EditRequest = "exec Cap_CompanyMarket_lst2 $0$ , '" & m_Language & "'"
            CkvMarket.MasterID = m_CurrentKey1
            CkvMarket.Mode = ListLoadMode.ModeEdit
        
        Case mt_CstValues.DisplayMode_Delete, mt_CstValues.DisplayMode_View
            CkvMarket.ViewRequest = "exec Cap_CompanyMarket_lst $0$ , '" & m_Language & "'"
            CkvMarket.MasterID = m_CurrentKey1
            CkvMarket.Mode = ListLoadMode.ModeView
        
    End Select
       
    CkvMarket.LoadList

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:InitCkvMarket"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:InitCkvMarket"
    CapMouseOn
End Sub


Private Sub InitCkvAttribute()
Dim CodeType  As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:InitCkvAttribute"
    #End If
    
    CkvAttribute.Visible = False
    CkvAttribute.Clear
      
    'Cust type
    CodeType = GetCodeFromCombo(cbo_Type)
      
    Select Case mi_DisplayMode
    
        Case mt_CstValues.DisplayMode_Add
            CkvAttribute.EditRequest = "exec Cap_CustomerAttribute_lst2 $0$ , '" & m_Language & "', " & IIf(CodeType = "", "NULL", CodeType)
            CkvAttribute.MasterID = ""
            CkvAttribute.Mode = ListLoadMode.ModeEdit
            
        Case mt_CstValues.DisplayMode_Update
            CkvAttribute.EditRequest = "exec Cap_CustomerAttribute_lst2 $0$ , '" & m_Language & "', " & IIf(CodeType = "", "NULL", CodeType)
            CkvAttribute.MasterID = m_CurrentKey1
            CkvAttribute.Mode = ListLoadMode.ModeEdit
        
        Case mt_CstValues.DisplayMode_Delete, mt_CstValues.DisplayMode_View
            CkvAttribute.ViewRequest = "exec Cap_CustomerAttribute_lst $0$ , '" & m_Language & "'"
            CkvAttribute.MasterID = m_CurrentKey1
            CkvAttribute.Mode = ListLoadMode.ModeView
        
    End Select
       
    
    CkvAttribute.LoadList
    CkvAttribute.Visible = True

'P516
' Is the customer attribute includes 'Account Holder'
    If mi_DisplayMode = mt_CstValues.DisplayMode_Update And CkvAttribute.Count > 0 Then
        InitBtnSearch
    End If
    If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
        btn_Search.Enabled = False
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:InitCkvAttribute"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:InitCkvAttribute"
    CapMouseOn
End Sub

Private Sub InitCkvStratAccount()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:InitCkvStratAccount"
    #End If
    
    ckvStratAccount.Visible = False
    ckvStratAccount.Clear
      
    Select Case mi_DisplayMode
    
        Case mt_CstValues.DisplayMode_Add
            ckvStratAccount.EditRequest = "exec Cap_CustomerSA_lst2 $0$ , '" & m_Language & "'"
            ckvStratAccount.MasterID = ""
            ckvStratAccount.Mode = ListLoadMode.ModeEdit
            
        Case mt_CstValues.DisplayMode_Update
            ckvStratAccount.EditRequest = "exec Cap_CustomerSA_lst2 $0$ , '" & m_Language & "'"
            ckvStratAccount.MasterID = m_CurrentKey1
            ckvStratAccount.Mode = ListLoadMode.ModeEdit
        
        Case mt_CstValues.DisplayMode_Delete, mt_CstValues.DisplayMode_View
            ckvStratAccount.ViewRequest = "exec Cap_CustomerSA_lst $0$ , '" & m_Language & "'"
            ckvStratAccount.MasterID = m_CurrentKey1
            ckvStratAccount.Mode = ListLoadMode.ModeView
        
    End Select
       
    ckvStratAccount.LoadList
    ckvStratAccount.Visible = (chk_StategicAccount.Value = 1)
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:InitCkvStratAccount"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:InitCkvStratAccount"
    CapMouseOn
End Sub

Private Function SaveCkvMarket(ms_CustCode As String) As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:SaveCkvMarket", "ms_CustCode=" & ms_CustCode
    #End If
    
    SaveCkvMarket = False
    
    CkvMarket.CheckRequest = "exec Cap_CompanyMarket_ins $0$ , $1$ , '','',null, null,null,null,null"
    CkvMarket.UnCheckRequest = "exec Cap_CompanyMarket_del $0$ , $1$"
    CkvMarket.MasterID = ms_CustCode

    SaveCkvMarket = CkvMarket.SaveList

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:SaveCkvMarket"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:SaveCkvMarket"
    CapMouseOn
End Function

Private Function SaveCkvAttribute(ms_CustCode As String) As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:SaveCkvAttribute", "ms_CustCode=" & ms_CustCode
    #End If
    
    SaveCkvAttribute = False
    
    CkvAttribute.CheckRequest = "exec Cap_CustomerAttribute_ins $0$ , $1$ , '','',null, null,null,null,null"
    CkvAttribute.UnCheckRequest = "exec Cap_CustomerAttribute_del $0$ , $1$"
    CkvAttribute.MasterID = ms_CustCode

    SaveCkvAttribute = CkvAttribute.SaveList

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:SaveCkvAttribute"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:SaveCkvAttribute"
    CapMouseOn
End Function

Private Function SaveCkvStratAccount(ms_CustCode As String) As Boolean
Dim i As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:SaveCkvStratAccount", "ms_CustCode=" & ms_CustCode
    #End If
    
    SaveCkvStratAccount = False
    
    ckvStratAccount.CheckRequest = "exec Cap_customerSA_ins $0$ , $1$ , '','',null, null,null,null,null"
    ckvStratAccount.UnCheckRequest = "exec Cap_customerSA_del $0$ , $1$"
    ckvStratAccount.MasterID = ms_CustCode
    If chk_StategicAccount.Value = 0 Then
        For i = 0 To ckvStratAccount.Count - 1
            If ckvStratAccount.ListItems(i + 1).Checked = True Then
                ckvStratAccount.ListItems(i + 1).Tag.DataChanged = True
                ckvStratAccount.ListItems(i + 1).Checked = False
                ckvStratAccount.ListItems(i + 1).Tag.Checked = False
            End If
        Next
    End If
    SaveCkvStratAccount = ckvStratAccount.SaveList

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:SaveCkvStratAccount"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:SaveCkvStratAccount"
    CapMouseOn
End Function



Property Let product(AProductKey As String)
Dim TheKeys As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Product_Let", "AProductKey=" & AProductKey
    #End If
    
    'AKey represents the concatenation of several keys separated by '@'
    If AProductKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If

    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Product
   
    TheKeys = Split(AProductKey, CH_LDELIMIT)
    m_Product = CStr(TheKeys(0))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Product_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Product_Let"
    CapMouseOn
End Property

Property Let project(AProjectKey As String)
Dim TheKeys As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Project_Let", "AProjectKey=" & AProjectKey
    #End If
    
    'AProjectKey represents the concatenation of several keys separated by '@'
    If AProjectKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Project
   
    TheKeys = Split(AProjectKey, CH_LDELIMIT)
    m_Project = CStr(TheKeys(0))
    ms_OldCodeCountry = CStr(TheKeys(2))                        ' 02/12/2013 JN - default search country to country of a Project
    ListProjectOf CStr(TheKeys(0)), CStr(TheKeys(1))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Project_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Project_Let"
    CapMouseOn
End Property
Property Let contact(AContactKey As String)
Dim TheKeys As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Contact_Let", "AContactKey=" & AContactKey
    #End If
    
    'AContactKey represents the concatenation of several keys separated by '@'
    If AContactKey = "" Then GoTo Trace_End

    'First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Contact
   
    TheKeys = Split(AContactKey, CH_LDELIMIT)
    m_Contact = CStr(TheKeys(0))
        
    ListContactOf CStr(TheKeys(0)), CStr(TheKeys(1)), CStr(TheKeys(2))
    
    If grdlst.Rows <> 0 Then
        SwapToDisplayMode mt_CstValues.DisplayMode_List
        SelectFirst
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Contact_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Contact_Let"
    CapMouseOn
End Property

Property Let memo(AMemoKey As String)
Dim TheKeys As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Memo_Let", "AMemoKey=" & AMemoKey
    #End If
    
    'AKey represents the concatenation of several keys separated by '@'
    If AMemoKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Memo
   
    TheKeys = Split(AMemoKey, CH_LDELIMIT)
    m_Memo = CStr(TheKeys(0))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Memo_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Memo_Let"
    CapMouseOn
End Property
Property Let action(AActionKey As String)
Dim TheKeys As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:action_Let", "AActionKey=" & AActionKey
    #End If
    
    'AKey represents the concatenation of several keys separated by '@'
    If AActionKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Action
    TheKeys = Split(AActionKey, CH_LDELIMIT)
    m_Action = CStr(TheKeys(0))
    ListActionOf m_Action, CStr(TheKeys(1)), CStr(TheKeys(2))
    
    If grdlst.Rows <> 0 Then
        SwapToDisplayMode mt_CstValues.DisplayMode_List
        SelectFirst
    Else
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        RaiseEvent HideGrid(mi_EmbeddedIn)
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:action_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:action_Let"
    CapMouseOn
End Property
 
Property Let TypeList(AType As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:TypeList_Let", "AType=" & AType
    #End If
    mi_TypeList = AType
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:TypeList_Let"
    #End If
End Property

Property Get TypeList() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:TypeList_Let"
    #End If
    TypeList = mi_TypeList
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:TypeList_Let", "Result=" & TypeList
    #End If
End Property

Property Get CurrentKey(Optional APart As Integer = 0) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CurrentKey_Get", "APart=" & APart
    #End If
    
    If APart = 0 Then
        CurrentKey = m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2
    ElseIf APart = 1 Then
        CurrentKey = m_CurrentKey1
    ElseIf APart = 2 Then
        CurrentKey = m_CurrentKey2
    ElseIf APart = 3 Then
        CurrentKey = m_CurrentKey3
    Else
        CurrentKey = ""
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CurrentKey_Get"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CurrentKey_Get"
    CapMouseOn
End Property



Sub UnCatch()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:UnCatch"
    #End If
    mi_EmbeddedIn = -1
    Call grdlst.DeselectRow
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:UnCatch"
    #End If
End Sub



Property Let CurrentKey(Optional APart As Integer = 0, AKeyValue As String)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CurrentKey_let", "APart=" & APart, "AKeyValue=" & AKeyValue
    #End If
    
    If APart = 0 Then
        m_CurrentKey1 = AKeyValue
        m_CurrentKey2 = ""
        m_CurrentKey3 = ""
    ElseIf APart = 1 Then
        m_CurrentKey1 = AKeyValue
    ElseIf APart = 2 Then
        m_CurrentKey2 = AKeyValue
    ElseIf APart = 3 Then
        m_CurrentKey3 = AKeyValue
    Else
        CurrentKey = ""
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CurrentKey_let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CurrentKey_let"
    CapMouseOn
End Property


Private Sub bt_Address_Click()
Dim TheForm As CustAddr

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:bt_Address_Click"
    #End If
    
    Set TheForm = New CustAddr
    Load TheForm
    TheForm.ConnectString = ms_ConnectString
    If mb_use_framework_connection = True Then
        Set TheForm.ArmDb = mo_ArmDb
    End If
    TheForm.Language = m_Language
    TheForm.DisplayMode = mi_DisplayMode
    TheForm.CCU_CapKey = m_CurrentKey1
    TheForm.CCU_CapDesc = txt_Desc
    
    TheForm.SetCountry GetCodeFromCombo(cbo_country), GetTextFromCombo(cbo_country)
    TheForm.SetCounty GetCodeFromCombo(cbo_County), GetTextFromCombo(cbo_County)
    
    TheForm.Load_A_COM

    CapMouseOn True
    TheForm.show vbModal
    CapMouseOff True
    
    TheForm.Unload_A_COM
    Unload TheForm
    Set TheForm = Nothing

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:bt_Address_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:bt_Address_Click"
    If Not TheForm Is Nothing Then
        TheForm.Unload_A_COM
        Unload TheForm
        Set TheForm = Nothing
    End If
    CapMouseOn
End Sub

Private Sub btn_pickZip_Click()
Const C_REQ As String = "SELECT DISTINCT ZC.Zip_min, CASE WHEN ZC.Zip_min = ZC.Zip_max THEN RTRIM(ZC.Zip_min) ELSE RTRIM(ZC.Zip_min) + '..' + RTRIM(ZC.Zip_max) END + ' - ' + SR.SR_Name AS ZipDesc , DV.DFT_Code " & _
                        "FROM Cap_ZipCode ZC " & _
                        "    INNER JOIN Sales_Reps SR ON SR.SR_Code = ZC.SR_Code AND SR.Language_Code = 'E' " & _
                        "    INNER JOIN Cap_RepRole CRR ON CRR.RR_Code = ZC.RR_Code AND  CRR.BU_GROUPING = '$GROUPING$' AND CRR.Language_Code = 'E' " & _
                        "    LEFT JOIN cap_DefaultValue DV ON DV.dft_fieldName='UseFUllZipRepAssignment' and DV.CT_Code=ZC.CT_code " & _
                        "WHERE ZC.CT_code='$CT_CODE$' " & _
                        "ORDER BY 1"

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:btn_pickZip_Click"
    #End If
    
    If cbo_country.SelectedItem Is Nothing Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 931, "#Please, select a country before !")
        GoTo Trace_End
    End If
    
    If cbo_Type.SelectedItem Is Nothing Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 2438, "#Please, select a customer type before !")
        GoTo Trace_End
    End If


    Debug.Assert (Not cbo_country.SelectedItem Is Nothing)
    Debug.Assert (Not cbo_Type.SelectedItem Is Nothing)
    
    Dim ls_req As String
    
    ls_req = Replace(C_REQ, "$CT_CODE$", cbo_country.SelectedItem.Key, , , vbTextCompare)
    ls_req = Replace(ls_req, "$GROUPING$", GetCurrentRepRole, , , vbTextCompare)

    grd_searchZip.Requests = ls_req
    grd_searchZip.Execute

    If grd_searchZip.Rows > 0 Then
        ' try to search the item
        If grd_searchZip.Data(1, "DFT_Code") = "1" Then
            Call grd_searchZip.SearchKey(True, Trim(txt_Zip1.Text) + Trim(txt_Zip2.Text))
        Else
            Call grd_searchZip.SearchKey(True, Trim(txt_Zip1.Text))
        End If

        ' show zip navigator
        grd_searchZip.Visible = True
        btn_pickZip.Enabled = False
        Call grd_searchZip.Zorder
        
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:btn_pickZip_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:btn_pickZip_Click"
    CapMouseOn
End Sub

Private Sub btn_Search_Click()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:btn_Search_Click"
    #End If
    
    Call CustCode_Search
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:btn_Search_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:btn_Search_Click"
    CapMouseOn
End Sub

Private Sub cal11_datechangee()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cal11_datechangee"
    #End If
    
    tvitems.Visible = False
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    lbl_ListFilter.Caption = GetCurrentFiltersDescription

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cal11_datechangee"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cal11_datechangee"
    CapMouseOn
End Sub

Private Sub cal12_datechangee()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cal12_datechangee"
    #End If
    
    tvitems.Visible = False
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    lbl_ListFilter.Caption = GetCurrentFiltersDescription

    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cal12_datechangee"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cal12_datechangee"
    CapMouseOn
End Sub

Sub UpdateInitFields()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:UpdateInitFields"
    #End If

    'idem
    ViewInitFields

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:UpdateInitFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:UpdateInitFields"
    CapMouseOn
End Sub


Private Sub InitControl(Optional aMode As Integer = 0)
Dim ConnectData As Variant
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:InitControl", "AMode=" & aMode
    #End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
   
    Select Case aMode
        Case 0
    'If No mode then exit
            GoTo Trace_End
   
        Case 1
    'If already initialized then exit
        If mi_TypeList <> 1 Then
            mi_TypeList = 1
        Else
            pblst.PictureDisplayed = "P_Quit=-1"
            GoTo Trace_End
        End If
        Case 2
        If mi_TypeList <> 1 And mi_TypeList <> 2 Then
            mi_TypeList = 2
        End If
    End Select
   
    UserControl.ScaleMode = 1
    
    'Object unvisible
    ObjectVisible False
   
    Select Case aMode
        Case 1
            'Pour la liste longue uniquement
        DrawMainGrid
       
        'Dates
        cal11.Zorder 0
        cal12.Zorder 0
        cal11.Limited_as_embedded = 1
        cal12.Limited_as_embedded = 1
                    
        Case 2
    'Pour la liste courte
    
        'Grille
        grdlst.ResetGrid
        
        'Pour liste longue : Initialisation toolbar
        pblst.ClearAllIcons
        pblst.TableName = mt_CstValues.SecurityCustomer_lst
        pblst.PictureDisplayed = "P_Refresh=7 P_Print=-6"
    
        Case 3
            'Pour détail
'            If m_Contact <> "" Then
'                pbItem.TableName = mt_CstValues.SecurityCustomer_lst2
'            ElseIf WithParent Then
'                pbItem.TableName = mt_CstValues.SecurityCustomer_lst
'            Else
'                pbItem.TableName = mt_CstValues.SecurityCustomer
'            End If
            pbItem.ClearAllIcons
            If mi_EmbeddedIn = -1 Then
               pbItem.PictureDisplayed = "P_Update=2 P_Delete=3 P_Previous=4 P_Next=5 P_ToolBox=-2 P_Quit=-1"
            Else
               pbItem.PictureDisplayed = "P_Update=2 P_Delete=3 P_Previous=4 P_Next=5 P_Quit=-1"
            End If
    
        Case 4
    'Pour màj
    
        'Toolbar
        pbItem.ClearAllIcons
        If DisplayMode = mt_CstValues.DisplayMode_Delete Then
            pbItem.PictureDisplayed = "P_Valid=1 P_Quit=-1"
        Else
            pbItem.PictureDisplayed = "P_Valid=1 P_UnDo=2 P_Quit=-1"
        End If
            
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:InitControl"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:InitControl"
    CapMouseOn
End Sub

Private Sub ObjectVisible(Optional aVisible As Boolean = True)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ObjectVisible", "AVisible=" & aVisible
    #End If
    
    UserControl.fraFilters.Visible = aVisible
    UserControl.fraItem.Visible = aVisible
    UserControl.fraList.Visible = aVisible

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ObjectVisible"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ObjectVisible"
    CapMouseOn
End Sub

Private Sub cbo_county_ComboBeforeDropDown()
Dim CodeCountry As String

    'On charge les county
    CodeCountry = GetCodeFromCombo(cbo_country)
    If CodeCountry <> "" Then
        If ms_OldCodeCountry <> CodeCountry Then
            cbo_County.FirstBlankItem = False
            cbo_County.Request = "exec cap_county_cbo  '" & CodeCountry & "', " & "'" & m_Language & "'"
            ms_OldCodeCountry = CodeCountry
        End If
    End If

End Sub

Private Sub cbo_type_ComboItemSelected()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cbo_type_ComboItemSelected"
    #End If
    
    'ckvSalesRep.ZipCode Trim$(txt_Zip1.Text) & Trim$(txt_Zip2.Text), GetCodeFromCombo(cbo_type)
    If GetCodeFromCombo(cbo_Type) <> mv_Old_cbo_Type Then
        mv_Old_cbo_Type = GetCodeFromCombo(cbo_Type)
        Call Update_SalesReps
        InitCkvAttribute
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cbo_type_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cbo_type_ComboItemSelected"
    CapMouseOn

End Sub

Private Sub cbo_type_GotFocus()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cbo_type_GotFocus"
    #End If
    
    mv_Old_cbo_Type = GetCodeFromCombo(cbo_Type)
    mv_Old_txt_Zip1 = txt_Zip1.Text
    mv_Old_txt_Zip2 = txt_Zip2.Text
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cbo_type_GotFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cbo_type_GotFocus"
    CapMouseOn

End Sub

Private Sub cbo_type_LostFocus()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cbo_type_LostFocus"
    #End If
    
    'ckvSalesRep.ZipCode Trim$(txt_Zip1.Text) & Trim$(txt_Zip2.Text), GetCodeFromCombo(cbo_type)
    If GetCodeFromCombo(cbo_Type) <> mv_Old_cbo_Type Then
        mv_Old_cbo_Type = GetCodeFromCombo(cbo_Type)
        Call Update_SalesReps
        InitCkvAttribute
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cbo_type_LostFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cbo_type_LostFocus"
    CapMouseOn
End Sub

Private Sub cbo_View_ComboItemSelected()
Dim ls_Key As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cbo_view_ComboItemSelected"
    #End If
    
    If reload_treeview.Visible = True Then GoTo Trace_End
    
    Dim lb_internalInitBck As Boolean
    lb_internalInitBck = mb_InternalInit
    mb_InternalInit = True
    chk_isInitTV.Value = IIf(GetCodeFromCombo(Cbo_View) = ms_initTreeview, vbChecked, vbUnchecked)
    mb_InternalInit = lb_internalInitBck

    ls_Key = ""
    If reload_treeview.Visible = False Then
        If grdlst.Row >= 0 Then
            ls_Key = grdlst.CurrentKey(0)
        End If
    End If
    ReinitTreeview GetCodeFromCombo(Cbo_View)
    If ls_Key <> "" Then
        SearchTreeView ls_Key, False
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cbo_view_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cbo_view_ComboItemSelected"
    CapMouseOn
End Sub



Private Sub chk_isInitTV_Click()
    On Error GoTo Trace_Err
    If mb_InternalInit Then Exit Sub
    
    
    If chk_isInitTV.Value = 1 Then
        Call UpdateUserDefaultValue("InitTreeview", GetCodeFromCombo(Cbo_View), GetTextFromCombo(Cbo_View))
        ms_initTreeview = GetCodeFromCombo(Cbo_View)
    Else
        Call DeleteUserDefaultValue("InitTreeview")
        'check if it is Default = 'X'
        If Cbo_View.SelectedItem.GetData(3) <> "X" Then
            ms_initTreeview = "Vg"              ' default 2.4.2013
        Else
            ' Default cannot be removed
            mb_InternalInit = True
            chk_isInitTV.Value = 1
            mb_InternalInit = False
        End If
    End If
    
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:chk_isInitTV_Click"
End Sub

Private Sub DeleteUserDefaultValue(ByVal as_Key As String)
    On Error GoTo Trace_Err
    Const REQ_DEL = "EXEC Cap_DefaultValueUser_del $LOGIN$, '$SCREEN$', $KEY$"
    
    ' check if value exist in database
    Dim ls_req As String
    ls_req = Replace(REQ_DEL, "$LOGIN$", SqlStr(ms_UID), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SCREEN$", "Capture_cfg", , , vbTextCompare)
    ls_req = Replace(ls_req, "$KEY$", SqlStr(as_Key), , , vbTextCompare)
    
    Call ExecuteSQLSafe(mo_ArmDb, ls_req)

    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:DeleteUserDefaultValue"
End Sub



Private Sub UpdateUserDefaultValue(ByVal as_Key As String, ByVal as_Value As String, ByVal as_desc As String)
    On Error GoTo Trace_Err
    Const REQ_SEL = "EXEC Cap_DefaultValueUser_sel $LOGIN$, '$SCREEN$', $KEY$"
    Const REQ_INS = "EXEC Cap_DefaultValueUser_ins $LOGIN$, '$SCREEN$', $KEY$, $VALUE$, $VALUE_DESC$"
    Const REQ_UPD = "EXEC Cap_DefaultValueUser_upd $LOGIN$, '$SCREEN$', $KEY$, $VALUE$, $VALUE_DESC$"
    
    ' check if value exist in database
    Dim ls_req As String
    ls_req = Replace(REQ_SEL, "$LOGIN$", SqlStr(ms_UID), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SCREEN$", "Capture_cfg", , , vbTextCompare)
    ls_req = Replace(ls_req, "$KEY$", SqlStr(as_Key), , , vbTextCompare)
    
    Dim ll_Cursor As Long
    ll_Cursor = OpenSQLSafe(mo_ArmDb, ls_req)
    If mo_ArmDb.RowCount(ll_Cursor) >= 1 Then
        ' update
        ls_req = Replace(REQ_UPD, "$LOGIN$", SqlStr(ms_UID), , , vbTextCompare)
    Else
        'insert
        ls_req = Replace(REQ_INS, "$LOGIN$", SqlStr(ms_UID), , , vbTextCompare)
    End If
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0
    
    ls_req = Replace(ls_req, "$SCREEN$", "Capture_cfg", , , vbTextCompare)
    ls_req = Replace(ls_req, "$KEY$", SqlStr(as_Key), , , vbTextCompare)
    ls_req = Replace(ls_req, "$VALUE$", SqlStr(as_Value), , , vbTextCompare)
    ls_req = Replace(ls_req, "$VALUE_DESC$", SqlStr(as_desc), , , vbTextCompare)
    
    Call ExecuteSQLSafe(mo_ArmDb, ls_req)

    Exit Sub
Trace_Err:
    If ll_Cursor > 0 Then
        Call mo_ArmDb.Close(ll_Cursor)
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:UpdateUserDafaultValue"
End Sub

Private Sub chk_StategicAccount_Click()
    If mb_InternalInit Then Exit Sub
    
    ckvStratAccount.Visible = chk_StategicAccount.Value
    If chk_StategicAccount.Value = 0 Then
        ckvStratAccount.UnCheckAll
    End If
End Sub

Private Sub CkvAttribute_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    Call InitBtnSearch
End Sub

Private Sub fill_all_record_Click()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:fill_all_record_Click"
    #End If
    
    grdlst.Requests = ""
    If tvitems.Checkboxes = True Then
        grdlst.Requests = tvitems.CheckedNodesRequests
    Else
        grdlst.Requests = tvitems.SelectedNodeRequest
    End If
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapCus:fill_all_record_click", "Requests=", grdlst.Requests
    End If

    fill_all_record.Visible = False

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:fill_all_record_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:fill_all_record_Click"
    CapMouseOn
End Sub



Private Sub fraItem_Click()
    Call grd_searchZip_LostFocus
End Sub


Private Sub fraItemTop_Click()
    Call grd_searchZip_LostFocus
End Sub

Private Sub grd_searchZip_DblClick()

    If grd_searchZip.SelectedCount > 0 Then
        If grd_searchZip.SelectedLine(0, "DFT_Code") = "1" Then
            txt_Zip1.Text = Left(grd_searchZip.SelectedKey(0)(0), 2)
            If Len(grd_searchZip.SelectedKey(0)(0)) > 2 Then
                txt_Zip2.Text = right(grd_searchZip.SelectedKey(0)(0), Len(grd_searchZip.SelectedKey(0)(0)) - 2)
            End If
        Else
            txt_Zip1.Text = grd_searchZip.SelectedKey(0)(0)
        End If
    End If
    
    mv_Old_txt_Zip1 = ""
    mv_Old_txt_Zip2 = ""
    mv_Old_cbo_Type = ""

    grd_searchZip.Visible = False
    btn_pickZip.Enabled = True
    
    Call txt_Zip1_LostFocus

End Sub

Private Sub grd_searchZip_LostFocus()
    If grd_searchZip.Visible Then
        grd_searchZip.Visible = False
        btn_pickZip.Enabled = (Not cbo_country.SelectedItem Is Nothing)
    End If
End Sub

Private Sub pctTvReset_Click()
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:pctTvReset_Click"
    #End If
    opt_date(0).Value = True
    tbsFilters.Tabs(1).Selected = True
    Cbo_View.SearchItem "X", "TV_Default", 0 ', "TV_Default"
    ' TASK 298.2
    tbsArchive.Tabs(2).Selected = True
    reload_treeview_Click
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:pctTvReset_Click"
    #End If
    CapMouseOn
End Sub

Private Sub reload_treeview_Click()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:grdlst_Click"
    #End If
    
    If opt_date(1) Then
        If Len(cal11.date_courte) <> 10 Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 267, "#Invalid data")
            GoTo Trace_End
        End If
    
        If Len(cal12.date_courte) <> 10 Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 267, "#Invalid data")
            GoTo Trace_End
        End If
    
        If CDate(cal12.date_courte) < CDate(cal11.date_courte) Then
            cal12.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 930, "#Start date must be less than end date")
            GoTo Trace_End
        End If
    
        If cbo_date.SelectedItem Is Nothing Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
            cbo_date.SetFocus
            GoTo Trace_End
        End If
    End If
    
    ReinitTreeview GetCodeFromCombo(Cbo_View)
    tvitems.Visible = True
    reload_treeview.Visible = False

    lbl_ListFilter.Caption = GetCurrentFiltersDescription

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:grdlst_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:grdlst_Click"
    CapMouseOn
End Sub

Private Sub tbsArchive_Click()
    CapMouseOff
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = False
    ' TASK 298.2
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    CapMouseOn
End Sub

Private Sub tbsFilters_Click()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:tbsFilters_Click"
    #End If
    
'    reload_treeview.Visible = False
'    ReinitTreeview GetCodeFromCombo(cbo_view)
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    lbl_ListFilter.Caption = GetCurrentFiltersDescription

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:tbsFilters_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:tbsFilters_Click"
    CapMouseOn
End Sub

Private Sub txt_zip1_GotFocus()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:txt_zip1_GotFocus"
    #End If
    
    mv_Old_cbo_Type = GetCodeFromCombo(cbo_Type)
    mv_Old_txt_Zip1 = txt_Zip1.Text
    mv_Old_txt_Zip2 = txt_Zip2.Text
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:txt_zip1_GotFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:txt_zip1_GotFocus"
    CapMouseOn
    
End Sub

Private Sub txt_Zip1_LostFocus()
     
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:txt_Zip1_LostFocus"
    #End If
    
    'ckvSalesRep.ZipCode Trim$(txt_Zip1.Text) & Trim$(txt_Zip2.Text), GetCodeFromCombo(cbo_type)
    
    'CHECK IF CUSTOMER TYPE OR ZIP HAS CHANGED
    txt_Zip1.Text = UCase(txt_Zip1.Text)
    If txt_Zip1.Text <> mv_Old_txt_Zip1 Then
        'If GetDefaultConfigCode("Capture_Cfg", "UseFUllZipRepAssignment") = "1" And txt_Zip2.Text = "" Then
            'txt_Zip2.Text = GetDefaultConfigCode("Capture_Cfg", "UseDefaultZip2")
        'End If
        ' TO DO : please update this for select the county for spain
        'Call SearchAndSelectComboItem(cbo_County, txt_Zip1.Text)
        Call Update_SalesReps
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:txt_Zip1_LostFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:txt_Zip1_LostFocus"
    CapMouseOn
End Sub


Private Sub txt_zip2_GotFocus()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:txt_zip2_GotFocus"
    #End If
    
    mv_Old_cbo_Type = GetCodeFromCombo(cbo_Type)
    mv_Old_txt_Zip1 = txt_Zip1.Text
    mv_Old_txt_Zip2 = txt_Zip2.Text
    
    'txt_Zip2.SelStart = 0
    'txt_Zip2.SelLength = Len(txt_Zip2.Text)
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:txt_zip2_GotFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:txt_zip2_GotFocus"
    CapMouseOn
    
End Sub


Private Sub txt_zip2_LostFocus()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:txt_zip2_LostFocus"
    #End If
    
        'CHECK IF CUSTOMER TYPE OR ZIP HAS CHANGED
    txt_Zip2.Text = UCase(txt_Zip2.Text)
    If txt_Zip2.Text <> mv_Old_txt_Zip2 Then
        ' TO DO : please update this for select the county for spain
        'Call SearchAndSelectComboItem(cbo_County, txt_Zip1.Text)
        Call Update_SalesReps
    End If

    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:txt_zip2_LostFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:txt_zip2_LostFocus"
    CapMouseOn
End Sub


' Initialization of the component
Public Sub Load_A_COM(ab_root As Boolean)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Load_A_Com", "ab_root = " & ab_root
    #End If
    
    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    If gs_CaptureCountry = mt_CstValues.CT_UK Then
        InitView_UK
    Else
        grd_searchZip.Top = txt_Zip1.Top
        grd_searchZip.Left = txt_Zip1.Left
    
        btn_pickZip.Left = txt_Zip1.Left - btn_pickZip.Width - 25
        btn_pickZip.Top = txt_Zip1.Top + 10
    End If
    
    mi_EmbeddedIn = -1  '   Component is not embedded by someone
    mi_EmbedTag = -1    '   Component embed none component
    
    mb_Root = False     ' Component is not the default focus
    
    ms_initTreeview = GetDefaultConfigCode("Capture_Cfg", "InitTreeview")


    grdlst.Load_A_COM
    srch_primcontact.Load_A_COM
    tvitems.Load_A_COM
    CkvAttribute.Load_A_COM
    CkvMarket.Load_A_COM
    ckvStratAccount.Load_A_COM
    pblst.Load_A_COM
    pbItem.Load_A_COM
    
    pblst.DrivenByCapture = True
    pbItem.DrivenByCapture = True
    
    'ckvSalesRep.Load_A_COM
    Cbo_View.Load_A_COM
    cbo_Type.Load_A_COM
    cbo_Priority.Load_A_COM
    cbo_County.Load_A_COM
    cbo_country.Load_A_COM
    cbo_date.Load_A_COM
    cbo_Loyalty.Load_A_COM
    grd_searchZip.Load_A_COM

    cbo_Type.FirstBlankItem = False
    cbo_Type.SearchPrefix = " "
    cbo_Type.Request = "exec cap_companytype_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    cbo_Priority.FirstBlankItem = True
    cbo_Priority.Request = "exec cap_companypriority_cbo " & "'" & m_Language & "'"
    cbo_country.FirstBlankItem = False
    cbo_country.Request = "exec countries_cbo7 " & "'" & m_Language & "' ,'" & ms_UID & "'"

    cbo_Loyalty.FirstBlankItem = True
    cbo_Loyalty.SearchPrefix = " "
    cbo_Loyalty.Request = "Cap_CustomerLoyalty_Cbo" & "'" & ms_UID & "', '" & m_Language & "'"
    
    grd_searchZip.Title = ""
    grd_searchZip.AllowMultiSort = True
    grd_searchZip.AllowExcelExport = False
    grd_searchZip.AutoColumnWidth = True
    grd_searchZip.MultiSelect = False
    
    Dim la_Columns(2) As String
    
    la_Columns(0) = "Zip_min" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Zip_min" & CH_LDELIMIT & "Zip_min"
    la_Columns(1) = "ZipDesc" & CH_LDELIMIT & "2700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ZipDesc" & CH_LDELIMIT & ""
    la_Columns(2) = "DFT_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DFT_Code" & CH_LDELIMIT & "DFT_Code"
    
    grd_searchZip.SetColumns la_Columns
    
    
    ' The checkview !
    Set acv_Rep.ArmDb = mo_ArmDb
    acv_Rep.Driven_By = "Customer"
    
    'Screen csts
    LoadLabels mo_ArmDb, UserControl.Controls, "Cap_Customer_Detail", m_Language

    acv_Rep.Common_List_Load = True
    acv_Rep.Type_Of_Key = tkDependant
    acv_Rep.Calling_Key_Fields = "CCU_CAPKEY"
    acv_Rep.Link_Key_Fields = "SR_CODE®©RR_CODE"
    
    Call acv_Rep.Load_A_COM
    
    Call InitAcvRepsRole
    
    tbsArchive.Tabs(2).Selected = True ' 298.2
    
    reload_treeview.Picture = LoadResPicture(116, vbResIcon)
    reload_treeview.Visible = False

    
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    
    If ab_root = True Then
        'Initialisation treeview et filtres
        mb_InternalInit = True
        Cbo_View.Clear
        Cbo_View.FirstBlankItem = False
        Cbo_View.Request = "exec TreeView_View_t_lst 'Capture_Customer'," & "'" & m_Language & "'"
        Cbo_View.Load
        If ms_initTreeview = "" Then
            Cbo_View.SearchItem "X", "TV_Default", 0
            If Not Cbo_View.SelectedItem Is Nothing Then
                ms_initTreeview = Cbo_View.SelectedItem.Key
                chk_isInitTV.Value = vbChecked
            Else
                 ms_initTreeview = "Vg"             ' current default on 2.4.2013
            End If
        Else
            Cbo_View.SearchItem ms_initTreeview, "TV_Code", 0
        End If
        mb_InternalInit = False
    End If
    
    BCC.Codepage = GetCodePageFromLCID(gl_LocalID)
    
    If BCC.Codepage = 1250 Then
        BCC.Language_Code = "W"
    End If
    
    BCC.StyleSheet = App.Path & "\bpowebsite.css"
    BCC.DownloadFolder = App.Path & "\download"
    
   
    Dim ls_Request As String, lc_Cursor As Long
    ls_Request = "select Local_Text from screen_constants where screen_name = 'buscard' and language_code = '" & m_Language & "'"
    lc_Cursor = mo_ArmDb.OpenSQL(ls_Request)
    BCC.Labels = mo_ArmDb.GetFields(lc_Cursor, "Local_Text")
    mo_ArmDb.Close (lc_Cursor)
    
    Call BCC.Load_A_COM
    
    
    mAttributes = mo_ArmDb.OpenSQL("SELECT DISTINCT CTA_Code, A_Code FROM Cap_CompanyTypeAttribute")
    
Trace_End:
    mo_ArmDb.Close (lc_Cursor)
    mb_InternalInit = False
 
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Load_A_Com"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close (lc_Cursor)
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Load_A_Com"
    CapMouseOn
End Sub

Public Function cas_all(ByVal parm As String)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cas_all", "parm=" & parm
    #End If
    
    Select Case UCase(parm)
        Case "'ALL'", "''", Len(parm) = 0, "'A'":            cas_all = "Null"
        Case "'N'":  cas_all = "''"
        Case Else: cas_all = parm
    End Select

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cas_all", "Result=" & cas_all
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cas_all"
    CapMouseOn
End Function

Private Sub opt_date_Click(Index As Integer)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:opt_date_Click", "Index=" & Index
    #End If
    
    'ReinitTreeview GetCodeFromCombo(cbo_View)
    If Index = 1 Then
        cal11.Visible = True
        cal12.Visible = True
        cbo_date.Visible = True
    
        If cbo_date.SelectedItem Is Nothing Then
            cbo_date.FirstBlankItem = False
            cbo_date.Request = "exec captv_date_cbo 'TV_Customer_date','" & m_Language & "'"
            cbo_date.Load
            cbo_date.SearchItem "1", 2, 0
        End If
    Else
        cal11.reinit_cal
        cal12.reinit_cal
        cal11.Visible = False
        cal12.Visible = False
        cbo_date.Visible = False
        
    End If
        
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = False
    lbl_ListFilter.Caption = GetCurrentFiltersDescription

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:opt_date_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:opt_date_Click"
    CapMouseOn
End Sub


Private Sub grdLst_ItemSelected()

    On Error GoTo Trace_Err
    
    Dim a As Double, b As Double
    a = timer
    
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:grdlst_ItemSelected"
    #End If
    
    m_CurrentKey1 = grdlst.CurrentKey(0)
    m_CurrentKey2 = grdlst.CurrentKey(1)
    
    
    If grdlst.Row >= 0 Then DisplayMode = mt_CstValues.DisplayMode_View
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:grdlst_ItemSelected"
    #End If
    CapMouseOn
    b = timer - a
    Call AddToTimeLog(6, b)

    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:grdlst_ItemSelected"
    CapMouseOn
End Sub

' Initialization for the framework
Public Sub FrameWorkInit(ByRef lt_CstValues As Type_CstValues, ByVal ls_InstanceName As String, Optional ATypeList As Integer = 0)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:FrameWorkInit", "ls_InstanceName=" & ls_InstanceName, "ATypeList=" & ATypeList
    #End If
    
    'Restriction of initialsation
    mi_TypeParam = ATypeList
    
    Set mt_CstValues = lt_CstValues
    
        
    mi_CptTag = mt_CstValues.Tag_Customer
    
    ' Add the tabulation for the embedded controls
    With UserControl
        .tbsEmbedded.Tabs.Clear
        .tbsEmbedded.TabFixedWidth = 150
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Customer), "#Customer")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Project), "#Project")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Action), "#Actiojhlkhn")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Contact), "#Contact")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Memo), "#Memo")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_File), "#File")
        
        .tbsEmbedded.Tabs.Item(1).Tag = "tbs_Customer"
        .tbsEmbedded.Tabs.Item(2).Tag = "tbs_Project"
        .tbsEmbedded.Tabs.Item(3).Tag = "tbs_Action"
        .tbsEmbedded.Tabs.Item(4).Tag = "tbs_Contact"
        .tbsEmbedded.Tabs.Item(5).Tag = "tbs_Memo"
        .tbsEmbedded.Tabs.Item(6).Tag = "tbs_File"

    End With
    
    mi_DisplayMode = mt_CstValues.DisplayMode_None
    mi_OldDisplayMode = mi_DisplayMode
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:FrameWorkInit"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:FrameWorkInit"
    CapMouseOn
End Sub


' Release the memory used
Public Sub Unload_A_COM()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Unload_A_COM"
    #End If
    
    grdlst.Unload_A_COM
    pblst.Unload_A_COM
    pbItem.Unload_A_COM
    tvitems.Unload_A_COM
    srch_primcontact.Unload_A_COM
    CkvAttribute.Unload_A_COM
    CkvMarket.Unload_A_COM
    ckvStratAccount.Unload_A_COM
    'ckvSalesRep.Unload_A_COM
    Cbo_View.Unload_A_COM
    cbo_Type.Unload_A_COM
    cbo_Priority.Unload_A_COM
    cbo_County.Unload_A_COM
    cbo_country.Unload_A_COM
    cbo_Loyalty.Unload_A_COM
    cbo_date.Unload_A_COM
    
    Call BCC.Unload_A_COM
    
    grd_searchZip.Unload_A_COM
    
    Call mo_ArmDb.Close(mAttributes)
    
    ASC_DisconnectFromDB mo_ArmDb, ms_UID, mb_Created

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Unload_A_COM"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Unload_A_COM"
    CapMouseOn
End Sub


Private Sub cbo_date_ComboItemSelected()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cbo_date_Click"
    #End If
    
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    lbl_ListFilter.Caption = GetCurrentFiltersDescription

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cbo_date_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cbo_date_Click"
    CapMouseOn
End Sub


' Properties for let application access to critical data
Public Property Get CptTag()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CptTag_Get"
    #End If
    CptTag = mi_CptTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CptTag_Get", "Result=" & CptTag
    #End If
End Property

' Give the tag of the component which embed this instance
Public Property Get EmbeddedIn() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:EmbeddedIn_Get"
    #End If
    EmbeddedIn = mi_EmbeddedIn
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:EmbeddedIn_Get", "Result=" & EmbeddedIn
    #End If
End Property

' Give the tag of the component embed by this
Public Property Get EmbedTag() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:EmbedTag_Get"
    #End If
    EmbedTag = mi_EmbedTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:EmbedTag_Get", "Result=" & EmbedTag
    #End If
End Property

' Get the root state
Public Property Get Root() As Boolean
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Root_Get"
    #End If
    Root = mb_Root
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Root_Get", "Result=" & Root
    #End If
End Property

Public Property Let Root(ByVal ab_root As Boolean)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Root_Let", "ab_Root=" & ab_root
    #End If
    mb_Root = ab_root
    If mb_Root = True Then
        mi_EmbeddedIn = -1
    End If
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Root_Let"
    #End If
End Property

' Give the actual display mode
Public Property Get DisplayMode() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:DisplayMode_Get"
    #End If
    DisplayMode = mi_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:DisplayMode_Get", "Result=" & DisplayMode
    #End If
End Property

' Change the actual display mode
Public Property Let DisplayMode(ByVal li_DisplayMode As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:DisplayMode_Let", "li_DisplayMode=" & li_DisplayMode
    #End If
    CapMouseOff
    SwapToDisplayMode li_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:DisplayMode_Let"
    #End If
    CapMouseOn
End Property



' Change the display mode
Private Sub SwapToDisplayMode(li_DisplayMode As Integer, Optional ls_Params As String = "")
 
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:SwapToDisplayMode", "li_DisplayMode=" & li_DisplayMode, "ls_Params=" & ls_Params
    #End If
    
    mi_OldDisplayMode = mi_DisplayMode
   
    'When a component is root, it can't select the list mode
    If mb_Root And (li_DisplayMode = mt_CstValues.DisplayMode_List) And (EmbeddedIn = -1) Then
        li_DisplayMode = mt_CstValues.DisplayMode_View
    End If
    mi_DisplayMode = li_DisplayMode
   
    'We should hide all graphics frames before resize and move it
    DisplayMode_None
    
    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_List
            'The list mode is different if the component is embedded
            Select Case mi_EmbeddedIn
                Case -1
                    LongListDisplay
                Case Else
                    ShortListDisplay ls_Params
            End Select
            
        Case mt_CstValues.DisplayMode_View
                ViewDisplay
            
        Case mt_CstValues.DisplayMode_Update
                UpdateDisplay
            
        Case mt_CstValues.DisplayMode_Add
                AddDisplay
            
        Case mt_CstValues.DisplayMode_Delete
                DeleteDisplay
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:SwapToDisplayMode"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:SwapToDisplayMode"
    CapMouseOn
End Sub

' Hide all graphics elements
Private Sub DisplayMode_None()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:DisplayMode_None"
    #End If
    
    With UserControl
        .fraFilters.Visible = False
        .fraItem.Visible = False
        .fraList.Visible = False
        .fraItemBottom.Visible = False
        .lbl_ListFilter.Visible = False

    End With
    DoEvents

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:DisplayMode_None"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:DisplayMode_None"
    CapMouseOn
End Sub
Private Sub LongListDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:LongListDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    InitControl 1
    InitParentKey
        
    Call LongList_Resize
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:LongListDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:LongListDisplay"
    CapMouseOn
End Sub
Private Function WithParent() As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:WithParent"
    #End If
    
    If m_Project = "" And m_Memo = "" And m_Contact = "" And m_Product = "" And m_Action = "" Then
        WithParent = False
    Else
        WithParent = True
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:WithParent", "Result=" & WithParent
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:WithParent"
    CapMouseOn
End Function

Private Sub LongList_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:LongList_Resize"
    #End If
    
    With UserControl
    
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .fraList.Left = .fraFilters.Left + fraFilters.Width + mt_CstValues.Frm_Spacing
        .fraList.Top = mt_CstValues.Frm_Spacing
        .fraList.Width = .Width - .fraList.Left - mt_CstValues.Frm_Spacing
        .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .pblst.Height = mt_CstValues.View_ToolBar_Height
        .pblst.Top = mt_CstValues.Frm_Spacing * 4
        .pblst.Left = mt_CstValues.Frm_Spacing
        .pblst.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
        .pblst.Refresh
        .fill_all_record.Left = mt_CstValues.Frm_Spacing + 5000
        .fill_all_record.Top = (mt_CstValues.Frm_Spacing * 4) + 60
        .fill_all_record.Zorder 0
        .fill_all_record.Picture = LoadResPicture(116, vbResIcon)
        .fill_all_record.Visible = 0
              
        lbl_ListFilter.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height + 50
        lbl_ListFilter.Left = mt_CstValues.Frm_Spacing
        lbl_ListFilter.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
        
        .grdlst.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height + 500
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .grdlst.Top - mt_CstValues.Frm_Spacing
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = True
        .fraList.Visible = True
        .lbl_ListFilter.Visible = True
        
        CboView_Resize lbl_View, Cbo_View, fraFilters
        
        
    End With
        
    Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, True)
        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:LongList_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:LongList_Resize"
    CapMouseOn
End Sub

Private Sub Add_Resize()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Add_Resize"
    #End If
    
    With UserControl
        
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        '.fraFilters.Left = 0
        '.fraFilters.Width = 0
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        BCC.Height = fraItem.Height
        BCC.Top = fraItem.Top
        BCC.Width = fraItem.Width
        BCC.Left = fraItem.Left
        
        .pbItem.Height = mt_CstValues.View_ToolBar_Height
        .pbItem.Top = mt_CstValues.Frm_Spacing * 4
        .pbItem.Left = mt_CstValues.Frm_Spacing
        .pbItem.Width = .fraItem.Width - .pbItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbItem.Refresh
        
        .tbsEmbedded.Visible = False
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbItem.Top + .pbItem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = False
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.Visible = True
        .fraItemBottom.BorderStyle = 0
        
    End With

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Add_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Add_Resize"
    CapMouseOn
End Sub

Private Sub Update_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Update_Resize"
    #End If
    
    With UserControl
    
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        '.fraFilters.Left = 0
        '.fraFilters.Width = 0
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        BCC.Height = fraItem.Height
        BCC.Top = fraItem.Top
        BCC.Width = fraItem.Width
        BCC.Left = fraItem.Left
        
        .pbItem.Height = mt_CstValues.View_ToolBar_Height
        .pbItem.Top = mt_CstValues.Frm_Spacing * 4
        .pbItem.Left = mt_CstValues.Frm_Spacing
        .pbItem.Width = .fraItem.Width - .pbItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbItem.Refresh
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbItem.Top + .pbItem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        .fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Visible = False
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = False
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.Visible = True
        .fraItemBottom.BorderStyle = 0
    
    End With

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Update_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Update_Resize"
    CapMouseOn
End Sub

Property Get FraFilterLeft() As Long
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:FraFilterLeft_Get"
    #End If
    FraFilterLeft = UserControl.fraFilters.Left + UserControl.fraFilters.Width
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:FraFilterLeft_Get", "Result=" & FraFilterLeft
    #End If
    
End Property
Property Get UserControlWidth() As Long
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:UserControlWidth_Get"
    #End If
    UserControlWidth = UserControl.Width
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:UserControlWidth_Get", "Result=" & UserControlWidth
    #End If
    
End Property


Private Sub AddDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:AddDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
        
    BlankFields
    Add_Enablecontrols
    AddInitFields
    Add_Resize
    
    
    txt_Desc.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:AddDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:AddDisplay"
    CapMouseOn
End Sub

Private Sub Add_Enablecontrols()

    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True

    srch_primcontact.Locked = True
    lbl_DateEntered.Enabled = False
    txt_dateEntered.Enabled = False
    lbl_LastUpdated.Enabled = False
    txt_lastUpdated.Enabled = False
    ' TASK 298.2
    chk_DropFlag.Enabled = False
    
    bt_Address.Visible = False
    bt_Bcc.Visible = False
    
'P516
    lbl_SAPCode.Enabled = False
    txt_SapCode.Enabled = False
    btn_Search.Enabled = False
'P516

    acv_Rep.Calling_Key_Values = ""
    acv_Rep.ComboVisible = True
    acv_Rep.Init
    Call acv_Rep.SetVisibleList("CUST")
    
    grd_searchZip.Visible = False
    btn_pickZip.Enabled = True


End Sub

Private Sub UpdateDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:UpdateDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    mi_DisplayMode = mt_CstValues.DisplayMode_Update
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
    
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then BlankFields
    
    Update_EnableControls
    Update_Resize
    
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then
        UpdateInitFields
    Else
        'CkvAttribute.Clear
        'CkvMarket.Clear
        'ckvStratAccount.Clear
        
        InitCkvAttribute
        InitCkvMarket
        InitCkvStratAccount
        
    acv_Rep.Calling_Key_Values = m_CurrentKey1
        
    End If
    
    acv_Rep.Visible = False
    acv_Rep.ComboVisible = True
    Call Update_SalesReps(True)
    acv_Rep.Visible = True

    txt_Desc.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:UpdateDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:UpdateDisplay"
    CapMouseOn
End Sub

Private Sub Update_EnableControls()
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    
    srch_primcontact.Locked = False
    lbl_DateEntered.Enabled = False
    txt_dateEntered.Enabled = False
    lbl_LastUpdated.Enabled = False
    txt_lastUpdated.Enabled = False
    chk_DropFlag.Enabled = False

    bt_Address.Visible = True
    bt_Address.Enabled = True
    
    bt_Bcc.Visible = True
    
    grd_searchZip.Visible = False
    btn_pickZip.Enabled = True

'P516
    lbl_SAPCode.Enabled = False
    txt_SapCode.Enabled = False
    btn_Search.Enabled = False
End Sub

Private Sub DeleteDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:DeleteDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
    
    BlankFields
    Delete_EnableControls
    
    ViewInitFields
    Delete_Resize
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:DeleteDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:DeleteDisplay"
    CapMouseOn
End Sub

Private Sub Delete_EnableControls()
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False

    lbl_CstKey.Enabled = True
    txt_CstKey.Enabled = True
    
    ckvStratAccount.Enabled = True
    CkvMarket.Enabled = True
    CkvAttribute.Enabled = True
    
    grd_searchZip.Visible = False

End Sub

Private Sub pbItem_action(ByVal as_ActionType As String)
Dim lb_Result As Boolean

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:pbItem_action", "as_ActionType=" & as_ActionType
    #End If
    
    Select Case UCase$(as_ActionType)
        Case UCase$("Add")
            DisplayMode = mt_CstValues.DisplayMode_Add
            
        Case UCase$("Update")
            'If grdlst.Row >= 0 Then DisplayMode = mt_CstValues.DisplayMode_Update
            Item_UpdateInit
        
        Case UCase$("Delete")
            If grdlst.Row >= 0 Then Call Item_DeleteInit
        
        Case UCase$("Excel")

        
        Case UCase$("Quit")
            If mb_Root And mi_DisplayMode = mt_CstValues.DisplayMode_View Then
                ' We stay on the same...
                RaiseEvent UnlockNavigation
                GoTo Trace_End
            End If

            If mi_EmbedTag <> -1 Then
                RaiseEvent Release
                mi_EmbedTag = -1
            End If
            
            'Customer of contact
            If Not (m_Contact = "" And m_Action = "") Then
                RaiseEvent HideGrid(mi_EmbeddedIn)
            Else
                DisplayMode = mt_CstValues.DisplayMode_List
            End If

            
        Case UCase$("Valid")
            
            Dim a As Double, b As Double
            a = timer
            grd_searchZip.Visible = False
            btn_pickZip.Enabled = True
            
            Select Case DisplayMode
                Case mt_CstValues.DisplayMode_Add
                    lb_Result = RecordAdd
                Case mt_CstValues.DisplayMode_Update
                    lb_Result = RecordUpdate(m_CurrentKey1)
                Case mt_CstValues.DisplayMode_Delete
                    lb_Result = RecordDelete(m_CurrentKey1)
            End Select
        
            If lb_Result Then
                If WithParent Then
                    grdlst.Refresh
                    RaiseEvent Updated
                Else
                    Select Case DisplayMode
                        Case mt_CstValues.DisplayMode_Delete
                           ReinitTreeViewAfterDelete grdlst, tvitems
                        Case mt_CstValues.DisplayMode_Update
                            If chk_UpdateTV.Value Then
                                Call Item_LocalUpdate
                            Else
                                ReinitTreeViewAfterDelete grdlst, tvitems
                            End If
                        Case Else
                            Call Item_LocalUpdate
                    End Select

                End If
                
                DisplayMode = mt_CstValues.DisplayMode_List
                'Customer of contact
                If Not (m_Contact = "" And m_Action = "") Then RaiseEvent HideGrid(mi_EmbeddedIn)
                b = timer - a
                Call AddToTimeLog(mi_OldDisplayMode, b)
                
            End If
            
        Case UCase$("Undo")
            BlankFields
            'DisplayMode = mt_CstValues.DisplayMode_List
            If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
                AddInitFields
            Else
                ViewInitFields
                acv_Rep.ComboVisible = True
                acv_Rep.SetVisibleList ("MAIN")
                Call Update_SalesReps(True)
            End If
            
        Case UCase$("Previous")
            If grdlst.Row = 0 Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 927, "#No more previous item.")
            Else
                grdlst.Row = grdlst.Row - 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                m_CurrentKey2 = grdlst.CurrentKey(1)
                BlankFields
                ViewInitFields
                CheckMemoClaim
            End If
        
        Case UCase$("Next")
            If grdlst.Row = grdlst.Rows - 1 And grdlst.AllDataLoaded = True Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 928, "#No more next item.")
            Else
                grdlst.Row = grdlst.Row + 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                m_CurrentKey2 = grdlst.CurrentKey(1)
                BlankFields
                ViewInitFields
                CheckMemoClaim
            End If
        
        Case UCase$("Tool")
            TransfertCustomer
            
        Case Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 929, "#Invalid option :", as_ActionType)
    
    End Select

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:pbItem_action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:pbItem_action"
    CapMouseOn
End Sub


Private Sub ViewDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ViewDisplay"
    #End If
    
    If mi_EmbeddedIn = -1 Then
        RaiseEvent SwitchToView(mt_CstValues.View_Full)
    Else
        RaiseEvent SwitchToView(mt_CstValues.View_Medium)
    End If
    
    If mb_CycleReset Then
        mb_CycleReset = False
        GoTo Trace_End
    End If
    
    'If the component was on short list, it doues appear now in long list
    InitControl 3
    
    If IsArray(grdlst.CurrentKey) Then
        BlankFields
        View_EnableControls
        ViewLoad
        View_Resize
        ViewInitFields
        ms_View_Key = txt_CstKey.Text
        CheckMemoClaim
    Else
        View_EnableControls
        View_Resize
        DrawMainGrid
        Call SearchTreeView(ms_View_Key, False)
        If ms_View_Key <> txt_CstKey.Text Then
            ViewLoad
            ViewInitFields
            CheckMemoClaim
        End If
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ViewDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ViewDisplay"
    CapMouseOn
End Sub

Private Sub View_EnableControls()
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    
    lbl_CstKey.Enabled = True
    txt_CstKey.Enabled = True
    bt_Address.Enabled = True
    bt_Address.Visible = True
    
    bt_Bcc.Enabled = True
    bt_Bcc.Visible = True

    ckvStratAccount.Enabled = True
    CkvMarket.Enabled = True
    CkvAttribute.Enabled = True
    
    grd_searchZip.Visible = False
    btn_pickZip.Enabled = False
    
End Sub

Private Sub tvItems_NodeClick(ByVal Node As MSComctlLib.INode)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:tvItems_NodeClick"
    #End If
    
    If tvitems.Checkboxes = True Then
        fill_all_record.Visible = True
        GoTo Trace_End
    End If
    
    grdlst.Requests = ""
    grdlst.ClearGrid
    
    If tvitems.NodeInfo(Node).ml_Level = tvitems.Levels - 1 Then
        fill_all_record.Visible = 0
        grdlst.Requests = tvitems.SelectedNodeRequest
        If grdlst.Execute = False Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapCus:tvitems_NodeClick", "Request=", grdlst.Requests
        End If
    Else
        fill_all_record.Visible = -1
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:tvItems_NodeClick"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:tvItems_NodeClick"
    CapMouseOn
End Sub


Private Sub Item_UpdateInit()

    ' Get current key
    Dim ls_Key As String
    ls_Key = grdlst.CurrentKey(0)

    ' Retrieve the drop flag
    Dim ls_Request As String
    ls_Request = "SELECT DROP_Flag FROM Claim_Customer WHERE CCU_Capkey = '" & ls_Key & "'"
    
    Dim lc_Cursor As Long
    lc_Cursor = OpenSQLSafe(mo_ArmDb, ls_Request)
    Dim ls_DropFlag As String
    ls_DropFlag = mo_ArmDb.GetFields(lc_Cursor, "DROP_Flag")
    
    If (ls_DropFlag <> "X") Then
        ' Not drop, we can go to update screen
        DisplayMode = mt_CstValues.DisplayMode_Update
    Else
        ' Drop, just display a message
        Call ASC_SendMessage(mo_ArmDb, m_Language, 2510, "#You are unable to create an action for a Deleted Customer")
    End If
    
End Sub


Private Sub Item_DeleteInit()

    ' Get current key
    Dim ls_Key As String
    ls_Key = grdlst.CurrentKey(0)

    ' Retrieve the drop flag
    Dim ls_Request As String
    ls_Request = "SELECT DROP_Flag FROM Claim_Customer WHERE CCU_Capkey = '" & ls_Key & "'"
    
    Dim lc_Cursor As Long
    lc_Cursor = OpenSQLSafe(mo_ArmDb, ls_Request)
    Dim ls_DropFlag As String
    ls_DropFlag = mo_ArmDb.GetFields(lc_Cursor, "DROP_Flag")
    Call mo_ArmDb.Close(lc_Cursor)
    
    If (ls_DropFlag <> "X") Then
        ' Not drop, we can go to delete screen
        DisplayMode = mt_CstValues.DisplayMode_Delete
    Else
        ' Drop, just display a message
        Call ASC_SendMessage(mo_ArmDb, m_Language, 2512, "#This customer is already deleted")
    End If
    
End Sub

Private Sub pbLst_Action(ByVal as_ActionType As String)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:pbLst_Action", "as_ActionType=" & as_ActionType
    #End If
    
    Select Case UCase$(as_ActionType)
    
        Case UCase$("Add")
            If mi_EmbeddedIn = -1 Then
                'liste longue
                DisplayMode = mt_CstValues.DisplayMode_Add
            ElseIf m_Project <> "" Then
                'liste courte
                ShowLink as_ActionType
            End If
            
        Case UCase$("Update")
            If grdlst.Row >= 0 Then
                If mi_EmbeddedIn = -1 Then
                    Call Item_UpdateInit
                ElseIf m_Project <> "" Then
                    'liste courte
                    ShowLink as_ActionType
                End If
            End If
            
        Case UCase$("Delete")
            If grdlst.Row >= 0 Then
                If mi_EmbeddedIn = -1 Then
                    Call Item_DeleteInit
                ElseIf m_Project <> "" Then
                    'liste courte
                    ShowLink as_ActionType
                End If
            End If
        
        Case UCase$("Refresh")
            If mi_EmbeddedIn <> -1 Then
                grdlst.Refresh
            Else
                grdlst.ClearGrid
                grdlst.Requests = ""
                tvitems.Refresh
            End If
            
        Case UCase$("View")
            OwlSearch
            
        Case UCase$("Excel")
            If grdlst.Rows <> 0 Then ExportExcel mo_ArmDb, mb_use_framework_connection, ms_ConnectString, m_Language, grdlst, DataTypeEnum.Customer
            
        Case UCase$("Quit")
            RaiseEvent quit
        
        Case UCase$("Print")
            If grdlst.SelectedCount = 0 Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 936, "#You must at least select one line")
            Else
                Report mo_ArmDb, mb_use_framework_connection, ms_ConnectString, m_Language, grdlst, DataTypeEnum.Customer
            End If
        
        
        Case Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
    
    End Select

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:pbLst_Action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:pbLst_Action"
    CapMouseOn
End Sub

Private Sub ViewLoad()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ViewLoad"
    #End If
    
    If (mb_Root And mi_OldDisplayMode <> mt_CstValues.DisplayMode_List) Or mi_EmbedTag = -1 Then
        With UserControl
                .tbsEmbedded.Tabs.Item(1).Selected = True
        End With
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ViewLoad"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ViewLoad"
    CapMouseOn
End Sub



Private Sub ShortListDisplay(Optional ls_Params As String = "")
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ShortListDisplay", "ls_Params=" & ls_Params
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Embedded)
    
    ShortList_Resize
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ShortListDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ShortListDisplay"
    CapMouseOn
End Sub

' Embed a component
Private Sub tbsEmbedded_Click()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:tbsEmbedded_Click"
    #End If
    
    Dim ls_CstKey As String
    
    With UserControl
        Dim li_Key As Integer
        li_Key = GetLstKey(.tbsEmbedded.SelectedItem.Key)
        
        If (li_Key = mi_EmbedTag) Or (mi_EmbedTag = -1 And .tbsEmbedded.SelectedItem.Index = 1) Then GoTo Trace_End
        
        If mi_EmbedTag <> -1 Then
            RaiseEvent Release
            mi_EmbedTag = -1
        End If
        
        If .tbsEmbedded.SelectedItem.Index = 1 Then
            If mi_EmbeddedIn <> -1 Then
                 RaiseEvent SwitchToView(mt_CstValues.View_Medium)
            End If
            .fraItemBottom.Visible = True

        Else
            .fraItemBottom.Visible = False
            If mi_EmbeddedIn <> -1 Then
                If (li_Key = mt_CstValues.Tag_Memo) Or (li_Key = mt_CstValues.Tag_File) Then
                     RaiseEvent SwitchToView(mt_CstValues.View_Medium)
                Else
                    RaiseEvent SwitchToView(mt_CstValues.View_Full) 'JBP
                End If
            End If
            mi_EmbedTag = li_Key
            
            
            ls_CstKey = m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2 & CH_LDELIMIT & chk_DropFlag.Value & CH_LDELIMIT & GetCodeFromCombo(cbo_country)
            
            
            RaiseEvent Catch(mi_EmbedTag, ls_CstKey)
        End If
        
    End With

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:tbsEmbedded_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:tbsEmbedded_Click"
    CapMouseOn
End Sub



Private Sub Delete_Resize()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Delete_Resize"
    #End If
    
    With UserControl
        
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        '.fraFilters.Left = 0
        '.fraFilters.Width = 0
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        BCC.Height = fraItem.Height
        BCC.Top = fraItem.Top
        BCC.Width = fraItem.Width
        BCC.Left = fraItem.Left
        
        .pbItem.Height = mt_CstValues.View_ToolBar_Height
        .pbItem.Top = mt_CstValues.Frm_Spacing * 4
        .pbItem.Left = mt_CstValues.Frm_Spacing
        .pbItem.Width = .fraItem.Width - .pbItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbItem.Refresh
        
        .tbsEmbedded.Visible = False
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbItem.Top + .pbItem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        .fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = False
        
        .fraItem.Visible = True
        .fraItemTop.Visible = True
        .fraItemBottom.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
        
    End With
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Delete_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Delete_Resize"
    CapMouseOn
End Sub

Private Sub View_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:View_Resize"
    #End If
    
    With UserControl
        
        If mi_EmbeddedIn = -1 And Not mb_Root Then
        
            .fraFilters.Width = mt_CstValues.View_Frame_Width
            .fraFilters.Left = mt_CstValues.Frm_Spacing
            .fraFilters.Top = mt_CstValues.Frm_Spacing
            .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
            '.fraItem.Left = mt_CstValues.Frm_Spacing
            .fraItem.Left = .fraFilters.Left + fraFilters.Width + mt_CstValues.Frm_Spacing
            
            .fraFilters.Visible = True
            .fraFilters.Enabled = True
            
            .tbsEmbedded.Visible = True
            .tbsEmbedded.Zorder 0
            
        Else
            .fraItem.Left = mt_CstValues.Frm_Spacing
            
            .tbsEmbedded.Visible = True
            .tbsEmbedded.Zorder 0
            
        End If
        
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        BCC.Height = fraItem.Height
        BCC.Top = fraItem.Top
        BCC.Width = fraItem.Width
        BCC.Left = fraItem.Left

        '.tvitems.left = mt_CstValues.Frm_Spacing
        '.tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
        '.tvitems.Height = .tbsFilters.top - .tvitems.top
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .pbItem.Height = mt_CstValues.View_ToolBar_Height
        .pbItem.Top = mt_CstValues.Frm_Spacing * 4
        .pbItem.Left = mt_CstValues.Frm_Spacing
        .pbItem.Width = .fraItem.Width - .pbItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbItem.Refresh
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbItem.Top + .pbItem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        .fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Visible = True
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
        
    End With

    Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, False)

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:View_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    Resume
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:View_Resize"
    CapMouseOn
End Sub

Function RecordAdd() As Boolean
Dim ls_Request As String
Dim ls_CustCode As String
Dim lb_Result As Boolean
Dim ls_Result As String
Dim ll_Count As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:RecordAdd"
    #End If
    
    RecordAdd = False
    
    If Not cbo_Type.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_CompanyType_chk " & GetCodeFromCombo(cbo_Type) & ",'" & GetCodeFromCombo(cbo_country) & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_type.Caption & " : " & cbo_Type.SelectedItem.DisplayText)
                cbo_Type.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    
    ' TASK 298.2
    If GetCodeFromCombo(cbo_Loyalty) <> "" Then
        ls_Request = "Exec Cap_CustomerLoyalty_chk " & GetCodeFromCombo(cbo_Loyalty) & ",'" & GetCodeFromCombo(cbo_country) & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_Loyalty.Caption & " : " & cbo_Loyalty.SelectedItem.DisplayText)
                cbo_Loyalty.SetFocus
                GoTo Trace_End
            End If
        End If
    End If

    
    If ckvStratAccount.CheckedCount > 0 Then
        For ll_Count = 1 To ckvStratAccount.Count
            If ckvStratAccount.ListItems(ll_Count).Checked = True Then
                ls_Request = "Exec Cap_StratAccount_chk " & ckvStratAccount.ListItems(ll_Count).Tag.Id & ",'" & GetCodeFromCombo(cbo_country) & "'"
                lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
                If lb_Result Then
                    If Mid(ls_Result, 1, 1) = "~" Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", chk_StategicAccount.Caption & " : " & ckvStratAccount.ListItems(ll_Count).Text)
                        ckvStratAccount.ListItems(ll_Count).Selected = True
                        ckvStratAccount.SelectedItem.EnsureVisible
                        ckvStratAccount.SelectedItem.Ghosted = True
                        ckvStratAccount.SetFocus
                        GoTo Trace_End
                    End If
                End If
            End If
        Next
    End If
    
    If CkvAttribute.CheckedCount > 0 Then
        For ll_Count = 1 To CkvAttribute.Count
            If CkvAttribute.ListItems(ll_Count).Checked Then
                ls_Request = "Exec Cap_CustomerAttribute_chk " & CkvAttribute.ListItems(ll_Count).Tag.Id & ",'" & GetCodeFromCombo(cbo_country) & "'"
                lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
                If lb_Result Then
                    If Mid(ls_Result, 1, 1) = "~" Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_attribute.Caption & " : " & CkvAttribute.ListItems(ll_Count).Text)
                        CkvAttribute.ListItems(ll_Count).Selected = True
                        CkvAttribute.SelectedItem.EnsureVisible
                        CkvAttribute.SelectedItem.Ghosted = True
                        CkvAttribute.SetFocus
                        GoTo Trace_End
                    End If
                End If
            End If
        Next
    End If
    
    For ll_Count = 0 To acv_Rep.RoleList("Main").CheckedCount - 1
        ls_Request = "Exec Cap_SalesRep_chk " & acv_Rep.RoleList("Main").CheckedKeys(ll_Count)(0) & ",'" & GetCodeFromCombo(cbo_country) & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result = False Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", Lbl_SalesReps.Caption & " : " & acv_Rep.RoleList("Main").GetItem(acv_Rep.RoleList("Main").CheckedKeys(ll_Count)).GetData(1))
            acv_Rep.SetVisibleList "Main"
            acv_Rep.SetFocus
            GoTo Trace_End
        End If
    Next
    
    Dim lb_usefullZip As Boolean
    If Not cbo_country.SelectedItem Is Nothing Then
        lb_usefullZip = cbo_country.SelectedItem.GetData(2) = "1"
    Else
        lb_usefullZip = False
    End If
        
    ErrorOFF

    ls_CustCode = mo_ArmDb.SQLNextID("claim_customer")
    If ls_CustCode = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""claim_customer"") return nothing.")

    ls_Request = "Exec Claim_Customer_ins4 "
    
    ls_Request = ls_Request & "  " & CorrectString(mo_ArmDb, m_Language, txt_Desc, True)  '@Desc       VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Address1, True)  '@Addr1      VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_address2)  '@Addr2      VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_country, True)  '@CT_code    CHAR(4),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_County, True)  '@CTY_code   INT,
    ls_Request = ls_Request & ", " & UCaseInternational(CorrectString(mo_ArmDb, m_Language, txt_Town, True), GetCodePageFromLCID(gl_LocalID))  '@CCU_town   VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip1, True)  '@CCU_zip    CHAR(15),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip2, lb_usefullZip)  '@CCU_zip2   CHAR(15),
'P516 replace Comp_code by Cust_code
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_SapCode)  '@Company    CHAR(4)==> @Cust_code char(10)
    
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Tel)  '@CCU_tel    CHAR(20),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, Txt_fax)  '@CCU_fax    CHAR(20),
    ls_Request = ls_Request & ", " & "NULL"  '@Email      VARCHAR(80),
    
    Call CorrectString(mo_ArmDb, m_Language, txt_webSite)
    Call CorrectEMail(mo_ArmDb, m_Language, txt_Email)
    ls_Request = ls_Request & ", '" & Replace(Left(Left(txt_webSite.Text, 160) & CH_LDELIMIT & Left(txt_Email.Text, 78), 240), "'", "''") & "'"
    
    
    ls_Request = ls_Request & ", " & CorrectBool(chk_StategicAccount)  '@StratFlag  CHAR(1),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Priority, False)  '@CP_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Type, True)  '@CCT_code   int,
    ls_Request = ls_Request & ", " & CorrectKeyStr(mo_ArmDb, m_Language, srch_primcontact)  '@Prim_CNT   char(16),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1)  '@spare1     varchar(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2)  '@spare2     varchar(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3)  '@spare3     real,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare4)  '@spare4     real,
    ' TASK 298.2
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Loyalty, False)  '@LOY_code    INT,
    ls_Request = ls_Request & ", '" & IIf(chk_opted_out.Value, "X", "") & "'"                   ' task 851 JN @CCU_opt_out char(1)
    ls_Request = ls_Request & ", '" & ls_CustCode & "'"
    
    If Not ErrorFound And CkvMarket.CheckedCount = 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        CkvMarket.SetFocus
        GoTo Trace_End
    End If
    
    If chk_StategicAccount.Value = 1 And ckvStratAccount.FirstItem = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        CkvAttribute.SetFocus
        GoTo Trace_End
    End If
    
    If Not mb_ZipCorrect And Not ErrorFound Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Zip code not managed")
        txt_Zip1.SetFocus
        txt_Zip1.SelStart = 0
        txt_Zip1.SelLength = Len(txt_Zip1.Text)
        GoTo Trace_End
    End If
    
    Dim ls_RequestAMC As String
    Dim ls_margin As String
    ls_margin = CorrectDec(mo_ArmDb, m_Language, txt_automaticMargin, False)
    
    'Execution
    If ErrorFound Then GoTo Trace_End
    
    If ls_margin <> "NULL" Then
        ls_RequestAMC = "EXEC Claim_CustomerAMC_ins '" & ls_CustCode & "', " & ls_margin
    End If

    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End


    Dim lb_Transaction As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_Transaction = True

    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_CustCode)
    If lb_Result Then lb_Result = SaveCkvAttribute(ls_CustCode)
    If lb_Result Then lb_Result = SaveCkvMarket(ls_CustCode)
    If lb_Result Then lb_Result = SaveCkvStratAccount(ls_CustCode)
    If lb_Result Then
        acv_Rep.Calling_Key_Values = ls_CustCode
        lb_Result = acv_Rep.SaveList
    End If
    
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        lb_Transaction = False
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If
    
    If ls_RequestAMC <> "" Then Call ExecuteSQLSafe(mo_ArmDb, ls_RequestAMC, 1)
        
    ASC_CommitTransaction mo_ArmDb
    lb_Transaction = False
    m_CurrentKey1 = ls_CustCode
    RecordAdd = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:RecordAdd", "Result=" & RecordAdd
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If lb_Transaction Then
        ASC_RollBackTransaction mo_ArmDb
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:RecordAdd"
    CapMouseOn
End Function

Function RecordUpdate(ACode As String) As Boolean
Dim ls_Request As String
Dim ls_Result As String
Dim lb_Result As Boolean
Dim ll_Count As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:RecordUpdate", "ACode=" & ACode
    #End If
    
    RecordUpdate = False
    
'P516
    If mb_AccountHolder And txt_SapCode = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        btn_Search.SetFocus
        GoTo Trace_End
    End If
'P516
    
    If Trim$(ACode) = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If
    
    If GetBusinessCard(ACode) <> 0 Then
        If Not BusinessCardAllowed Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 950, "#The change cannot be validate because the customer have a business card")
            GoTo Trace_End
        End If
    End If
    
    
    If Not cbo_Type.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_CompanyType_chk " & GetCodeFromCombo(cbo_Type) & ",'" & GetCodeFromCombo(cbo_country) & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_type.Caption & " : " & cbo_Type.SelectedItem.DisplayText)
                cbo_Type.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    ' TASK 298.2
    If GetCodeFromCombo(cbo_Loyalty) <> "" Then
        ls_Request = "Exec Cap_CustomerLoyalty_chk " & GetCodeFromCombo(cbo_Loyalty) & ",'" & GetCodeFromCombo(cbo_country) & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_Loyalty.Caption & " : " & cbo_Loyalty.SelectedItem.DisplayText)
                cbo_Loyalty.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
' CALL PROCESS T298.1-B.PR_004
    If Not CheckField_PrimContact(srch_primcontact) Then GoTo Trace_End
    
    For ll_Count = 1 To ckvStratAccount.Count
        If ckvStratAccount.ListItems(ll_Count).Checked Then
            ls_Request = "Exec Cap_StratAccount_chk " & ckvStratAccount.ListItems(ll_Count).Tag.Id & ",'" & GetCodeFromCombo(cbo_country) & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", chk_StategicAccount.Caption & " : " & ckvStratAccount.ListItems(ll_Count).Text)
                    ckvStratAccount.ListItems(ll_Count).Selected = True
                    ckvStratAccount.SelectedItem.EnsureVisible
                    ckvStratAccount.SelectedItem.Ghosted = True
                    ckvStratAccount.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    Next
    
    For ll_Count = 1 To CkvAttribute.Count
        If CkvAttribute.ListItems(ll_Count).Checked = True Then
            ls_Request = "Exec Cap_CustomerAttribute_chk " & CkvAttribute.ListItems(ll_Count).Tag.Id & ",'" & GetCodeFromCombo(cbo_country) & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_attribute.Caption & " : " & CkvAttribute.ListItems(ll_Count).Text)
                    CkvAttribute.ListItems(ll_Count).Selected = True
                    CkvAttribute.SelectedItem.EnsureVisible
                    CkvAttribute.SelectedItem.Ghosted = True
                    CkvAttribute.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    Next
    
    For ll_Count = 0 To acv_Rep.RoleList("Main").CheckedCount - 1
        ls_Request = "Exec Cap_SalesRep_chk " & acv_Rep.RoleList("Main").CheckedKeys(ll_Count)(0) & ",'" & GetCodeFromCombo(cbo_country) & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result = False Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", Lbl_SalesReps.Caption & " : " & acv_Rep.RoleList("Main").GetItem(acv_Rep.RoleList("Main").CheckedKeys(ll_Count)).GetData(1))
            acv_Rep.SetVisibleList "Main"
            acv_Rep.SetFocus
            GoTo Trace_End
        End If
    Next
    
    Dim lb_usefullZip As Boolean
    If Not cbo_country.SelectedItem Is Nothing Then
        lb_usefullZip = cbo_country.SelectedItem.GetData(2) = "1"
    Else
        lb_usefullZip = False
    End If
    
    ErrorOFF

    ls_Request = "Exec Claim_Customer_upd2 "
    
    ls_Request = ls_Request & "  " & "'" & ACode & "'" '@CCU_CapKey char(16),
    ls_Request = ls_Request & ", " & p_iCon '@iConc      SMALLINT,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Desc, True)  '@Desc       VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Address1, True)  '@Addr1      VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_address2)  '@Addr2      VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_country, True)  '@CT_code    CHAR(4),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_County, True)  '@CTY_code   INT,
    ls_Request = ls_Request & ", " & UCaseInternational(CorrectString(mo_ArmDb, m_Language, txt_Town, True), GetCodePageFromLCID(gl_LocalID))  '@CCU_town   VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip1, True)  '@CCU_zip    CHAR(15),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip2, lb_usefullZip)    '@CCU_zip2   CHAR(15),
'P516 replace the company_code by Cust_code
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_SapCode)  '@Company    CHAR(4) ==> @Cust_code char(10)
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Tel)  '@CCU_tel    CHAR(20),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, Txt_fax)  '@CCU_fax    CHAR(20),
    ls_Request = ls_Request & ", " & "NULL"  '@Email      VARCHAR(80),  ????
    
    Call CorrectString(mo_ArmDb, m_Language, txt_webSite)
    Call CorrectEMail(mo_ArmDb, m_Language, txt_Email)
    ls_Request = ls_Request & ", '" & Replace(Left(Left(txt_webSite.Text, 160) & CH_LDELIMIT & Left(txt_Email.Text, 78), 240), "'", "''") & "'"
    
    ls_Request = ls_Request & ", " & CorrectBool(chk_StategicAccount)  '@StratFlag  CHAR(1),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Priority, False)  '@CP_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Type, True)  '@CCT_code   int,
    ls_Request = ls_Request & ", " & CorrectKeyStr(mo_ArmDb, m_Language, srch_primcontact)  '@Prim_CNT   char(16),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1)  '@spare1     varchar(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2)  '@spare2     varchar(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3)  '@spare3     real,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare4)  '@spare4     real,
    ' TASK 298.2
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Loyalty, False)  '@LOY_code    INT,
    ls_Request = ls_Request & ", '" & IIf(chk_opted_out.Value, "X", "") & "'"                   ' task 851 JN @CCU_opt_out char(1)
    
    If Not mb_ZipCorrect And Not ErrorFound Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Zip code not managed")
        txt_Zip1.SetFocus
        txt_Zip1.SelStart = 0
        txt_Zip1.SelLength = Len(txt_Zip1.Text)
        GoTo Trace_End
    End If
    
    
    If Not ErrorFound And CkvMarket.CheckedCount = 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        CkvMarket.SetFocus
        GoTo Trace_End
    End If
    
    If chk_StategicAccount.Value = 1 And ckvStratAccount.FirstItem = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        chk_StategicAccount.SetFocus
        GoTo Trace_End
    End If
    
    Dim ls_RequestAMC As String
    Dim ls_margin As String
    ls_margin = CorrectDec(mo_ArmDb, m_Language, txt_automaticMargin, False)
    
    'Execution
    If ErrorFound Then GoTo Trace_End
    
    If mb_OriginalAMCExists Then
        ls_RequestAMC = "EXEC Claim_CustomerAMC_upd '" & ACode & "', " & ls_margin
    Else
        If ls_margin <> "0" Then
            ls_RequestAMC = "EXEC Claim_CustomerAMC_ins '" & ACode & "', " & ls_margin
        End If
    End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ASC_BeginTransaction mo_ArmDb
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result Then lb_Result = SaveCkvAttribute(ACode)
    If lb_Result Then lb_Result = SaveCkvMarket(ACode)
    If lb_Result Then lb_Result = SaveCkvStratAccount(ACode)
    If lb_Result Then lb_Result = acv_Rep.SaveList
    If lb_Result Then lb_Result = UpdateSalesProjectRep(ACode)
    
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        If ls_Result = "-1" Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.")
            ViewInitFields
        Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        End If
        GoTo Trace_End
    End If
    
    If ls_RequestAMC <> "" Then Call ExecuteSQLSafe(mo_ArmDb, ls_RequestAMC, 1)
    
    ASC_CommitTransaction mo_ArmDb
    RecordUpdate = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:RecordUpdate", "Result=" & RecordUpdate
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    ASC_RollBackTransaction mo_ArmDb
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:RecordUpdate"
    CapMouseOn
End Function

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

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

'IMPLEMENTATION PROCESS T298.1-A.PR_006
Private Function CheckField_PrimContact(ByRef ao_srchTxt As Object) As Boolean
On Error GoTo onError

    CheckField_PrimContact = False
    
    If ao_srchTxt.Key1 <> "" Then
        CheckField_PrimContact = True
        GoTo Trace_End
    End If
    
    ' check if there is at least one non dropped item in DB
    Dim ls_Request      As String
    Dim ls_Result       As String
    Dim ls_CCU_Capkey   As String
    Dim lb_Result       As Boolean
    
    ' get CCU_CapKey from grid
    ls_CCU_Capkey = grdlst.CurrentKey(0)
    If ls_CCU_Capkey = "" Then Exit Function

    ls_Request = "Exec Cap_ContactGetCount '" & ls_CCU_Capkey & "'"
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, True)
    If lb_Result Then
        Debug.Assert (isNumeric(ls_Result))     ' test is done in ASC_RecordExec
        If CLng(ls_Result) = 0 Then
            CheckField_PrimContact = True
            GoTo Trace_End
        End If
        Call ASC_SendMessage(mo_ArmDb, m_Language, 797, "#You must select one of this companies contacts to be the 'Primary Contact'")
        ao_srchTxt.SetFocus
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CheckField_PrimContact", "Result=" & CheckField_PrimContact
    #End If
    Exit Function
onError:
    ao_srchTxt.SetFocus
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CheckField_PrimContact"
End Function
'END PROCESS T298.1-A.PR_006


Function RecordDelete(ACode As String) As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:RecordDelete", "ACode=" & ACode
    #End If
    
    RecordDelete = False
    
    If Trim$(ACode) = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If

    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    Dim ls_ResultCode As String
        
    If ASC_RecordExec(mo_ArmDb, "exec SPA_Prj_Cust_Cnt_chk NULL,'" & ACode & "', NULL", ls_ResultCode) Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 8718, "#You cannot delete this customer, because one or more SPA exists for this customer")
        GoTo Trace_End
    End If
    
    Dim ll_BusinessCard As Long
    ll_BusinessCard = GetBusinessCard(ACode)
    
    ErrorOFF
    
    Dim ls_Request_CC As String
    ls_Request_CC = "Exec Claim_Customer_del2 "
    ls_Request_CC = ls_Request_CC & "  '" & ACode & "'"  '@CCU_CapKey char(16),
    ls_Request_CC = ls_Request_CC & ", " & p_iCon             '@iConcurrency   SMALLINT

    Dim ls_Request_CNT As String
    ls_Request_CNT = "Claim_Customer_Contacts_Del '" & ACode & "'"   '
    
    Dim ls_Request_BCC As String
    If ll_BusinessCard <> 0 Then
        ls_Request_BCC = "exec CM_Articles_Del " & ll_BusinessCard
    End If
    
    Dim ls_Request_SP As String
    ls_Request_SP = "Claim_Customer_Sales_Project_LastUpd '" & ACode & "'"   '

    'Execution
    If ErrorFound Then GoTo Trace_End
    
    If DeleteConfirmation(mo_ArmDb, m_Language, 2502, "#Do you really want to delete this company and all the contacts linked to it ?") = False Then GoTo Trace_End
    
    Dim lb_InTransaction As Boolean, lb_CompanyDropped As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_InTransaction = True
    
    Call ExecuteSQLSafe(mo_ArmDb, ls_Request_CC, 1)
    lb_CompanyDropped = True
    Call ExecuteSQLSafe(mo_ArmDb, ls_Request_CNT)
    If Len(ls_Request_BCC) > 0 Then
        Call ExecuteSQLSafe(mo_ArmDb, ls_Request_BCC)
    End If
    Call ExecuteSQLSafe(mo_ArmDb, ls_Request_SP)
    
    ASC_CommitTransaction mo_ArmDb
    lb_InTransaction = False
    RecordDelete = True
    
Trace_End:
    CapMouseOn
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:RecordDelete", "Result=" & RecordDelete
    #End If
    Exit Function
    
Trace_Err:
    Dim ll_Err As Long
    Dim ls_Err As String
    ll_Err = Err.Number
    ls_Err = Err.Description
    
    If lb_InTransaction Then ASC_RollBackTransaction mo_ArmDb
    
    ' Display error message
    If (ll_Err = ArmErr.SQLBadRowAffectedCount) And (Not lb_CompanyDropped) And (lb_InTransaction) Then
        ' We are in the transaction
        ' The contact has not been dropped yet
        ' We executed a request that don't affect the good count of rows
        ' It's a concurrency issue on the contact !
        Call ASC_SendMessage(mo_ArmDb, m_Language, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.")
        ' We reload the contact to display the change done by the other user
        ViewInitFields
    Else
        ' Display generic message
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:RecordDelete"
    End If
    CapMouseOn


End Function

Private Sub ShortList_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ShortList_Resize"
    #End If
    
    With UserControl
    
        .fraList.Left = mt_CstValues.Frm_Spacing
        .fraList.Top = mt_CstValues.Frm_Spacing
        .fraList.Width = .Width - .fraList.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
   
        .pblst.Height = mt_CstValues.View_ToolBar_Height
        .pblst.Top = mt_CstValues.Frm_Spacing * 4
        .pblst.Left = mt_CstValues.Frm_Spacing
        .pblst.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
        .pblst.Refresh
        
        .grdlst.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .pblst.Height - .pblst.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .fraFilters.Visible = False
        .fraList.Visible = True
        .fill_all_record.Visible = 0
        
    End With
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ShortList_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ShortList_Resize"
    CapMouseOn
End Sub

' Called when application must resize the current view
Public Sub Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Resize"
    #End If
    
    Call DisplayMode_None
    
    Select Case DisplayMode
        Case mt_CstValues.DisplayMode_List
            If mi_EmbeddedIn = -1 Then
                Call LongList_Resize
            Else
               Call ShortList_Resize
            End If
        Case mt_CstValues.DisplayMode_View
             If mi_EmbeddedIn = -1 Then
                Call LongList_Resize
             End If
            Call View_Resize
        Case mt_CstValues.DisplayMode_Update
            Call Update_Resize
        Case mt_CstValues.DisplayMode_Add
            Call Add_Resize
        Case mt_CstValues.DisplayMode_Delete
            Call Delete_Resize
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Resize"
    CapMouseOn
End Sub

Private Sub AddInitFields()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:AddInitFields"
    #End If
    Dim ls_CT_Code As String
    Dim ls_CT_Desc As String
    Dim ll_Cursor As Long
    
    mb_InternalInit = True
    mb_OriginalAMCExists = False
    InitCkvAttribute
    InitCkvMarket
    InitCkvStratAccount
    
    acv_Rep.Visible = False
    acv_Rep.Calling_Key_Values = ""
    acv_Rep.ComboVisible = True
    acv_Rep.Init
    Call acv_Rep.SetVisibleList("CUST")
    acv_Rep.Visible = True
    DisplayDefaultValues
    
    If Not cbo_country.SelectedItem Is Nothing Then
        ' we need to select fullzipAssignment for a country
        ls_CT_Code = cbo_country.SelectedItem.Key
        ls_CT_Desc = cbo_country.SelectedItem.DisplayText
        
        ll_Cursor = OpenSQLSafe(mo_ArmDb, "SELECT DV.DFT_Code FROM cap_DefaultValue DV WHERE DV.DFT_ScreenName='Capture_Cfg' AND DV.dft_fieldName='UseFUllZipRepAssignment' and DV.CT_Code='" & ls_CT_Code & "'")
        Call cbo_country.Clear
        cbo_country.AddItem Array(ls_CT_Code, ls_CT_Desc, mo_ArmDb.GetFields(ll_Cursor, "DFT_Code")), True
        Call mo_ArmDb.Close(ll_Cursor)
        ll_Cursor = 0
    End If

    
Trace_End:

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:AddInitFields"
    #End If
    mb_InternalInit = False
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mb_InternalInit = False
    If ll_Cursor <> 0 Then
        Call mo_ArmDb.Close(ll_Cursor)
        ll_Cursor = 0
    End If
    
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:AddInitFields"
    CapMouseOn
End Sub
Private Sub BlankFields()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:BlankFields"
    #End If
    mb_InternalInit = True
    
    txt_Desc.Text = ""
    txt_Address1.Text = ""
    txt_address2.Text = ""
    txt_Town.Text = ""
    txt_Zip1.Text = ""
    txt_Zip2.Text = ""
    txt_Tel.Text = ""
    Txt_fax.Text = ""
    txt_webSite.Text = ""
    txt_Email.Text = ""
    txt_automaticMargin.Text = ""
    txt_SapCode.Text = ""
    txt_dateEntered.Text = ""
    txt_lastUpdated.Text = ""
    txt_spare1.Text = ""
    txt_spare2.Text = ""
    txt_spare3.Text = ""
    txt_spare4.Text = ""
    txt_CstKey.Text = ""
    Call grd_searchZip.ClearGrid
    
    chk_StategicAccount.Value = Unchecked
    
    cbo_County.Clear
    ms_OldCodeCountry = ""
    cbo_County.Request = ""
    cbo_country.Clear
    cbo_Type.Clear
    cbo_Priority.Clear
    srch_primcontact.Clear
          
    CkvAttribute.Clear
    CkvMarket.Clear
    ckvStratAccount.Clear
    
    acv_Rep.Init
    acv_Rep.SetVisibleList "Main"
    acv_Rep.ComboVisible = False
    
    chk_opted_out.Value = vbUnchecked       ' task 851 JN

    ' 298.2
    chk_DropFlag.Value = 0
    txt_DropDate.Text = ""
    cbo_Loyalty.Clear
    
    txt_spare1.Text = "N"
    
    If mi_DisplayMode = mt_CstValues.DisplayMode_View Then
        GoToTab1
    End If

    'clear highlight
    Call UpdateTabInfo(tbsEmbedded, SetLstKey(mt_CstValues.Tag_Memo), False, 0)
    'tbsEmbedded.Tabs(SetLstKey(mt_CstValues.Tag_Memo)).HighLighted = False
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:BlankFields"
    #End If
    mb_InternalInit = False
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mb_InternalInit = False
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:BlankFields"
    CapMouseOn
End Sub

Public Sub DisplayDefaultValues()
Dim i As Integer
Dim TheControl As Control
Dim TheControlName As String
Dim ls_req As String
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:DisplayDefaultValues"
    #End If
    
    If p_DefaultValuesLoaded = False Then
        p_DefaultValuesCount = GetScreenDefaultValues(mo_ArmDb, ms_UID, m_Language, "Cap_Customer_Detail", p_DefaultValues)
        p_DefaultValuesLoaded = True
        End If
    DisplayScreenDefaultValues UserControl.Controls, p_DefaultValues, p_DefaultValuesCount
        
    'Defaulted dates
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    If DisplayMode = mt_CstValues.DisplayMode_Add Then
        ls_req = "exec Cap_Date 'Getdate'"
        ll_Cursor = mo_ArmDb.OpenSQL(ls_req, -1, 0)
        If ll_Cursor = 0 Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:DisplayDefaultValues", "Request=" & ls_req
            GoTo Trace_End
        End If
        txt_dateEntered = mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")
        txt_lastUpdated = mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")
    End If
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:DisplayDefaultValues"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:DisplayDefaultValues"
    CapMouseOn
End Sub

Private Sub ViewInitFields()
Dim TheRequest As String
Dim Thekey1 As String
Dim Thekey2 As String
Dim ll_Cursor As Long
Dim ls_Buffer As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ViewInitFields"
    #End If
    
    mb_InternalInit = True
    
    'On construit la requête
        Thekey1 = grdlst.CurrentKey(0)
        Thekey2 = grdlst.CurrentKey(1)
    
        m_CurrentKey1 = Thekey1
        m_CurrentKey2 = Thekey2
    
    'Si pas de clé en cours, ie pas de ligne en grille sélectionnée alors bye
    If Thekey1 = "" Or Thekey2 = "" Then GoTo Trace_End
    
    mb_ZipCorrect = True
    
    'Affectation aux clés membres
    CurrentKey(1) = Thekey1
    CurrentKey(2) = Thekey2
    
    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
        
    TheRequest = "exec claim_customer_t_sel3 '" & Thekey1 & "','" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:ViewInitFields", "Request=" & TheRequest
        GoTo Trace_End
    End If
  
    p_iCon = mo_ArmDb.GetFields(ll_Cursor, "iConcurrency")
    mb_OriginalAMCExists = (mo_ArmDb.GetFields(ll_Cursor, "CCU_CapkeyAMC") <> "")
  
    txt_CstKey.Text = CurrentKey(1)
    txt_Desc.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_desc")
    txt_Address1.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_addr1")
    txt_address2.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_addr2")
    txt_Town.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_town")
    txt_Zip1.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_zip1")
    txt_Zip2.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_zip2")
    txt_Tel.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_tel")
    Txt_fax.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_fax")
    txt_automaticMargin.Text = mo_ArmDb.GetFields(ll_Cursor, "AutoMarginInst")
    
    ' TASK 298.2
    chk_DropFlag.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "drop_flag") = "X", 1, 0)
    txt_DropDate.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "drop_date"))

    
    ls_Buffer = Split(mo_ArmDb.GetFields(ll_Cursor, "weburl"), CH_LDELIMIT)
    If UBound(ls_Buffer) >= 0 Then
        txt_webSite.Text = ls_Buffer(0)
    Else
        txt_webSite.Text = ""
    End If
    
    If UBound(ls_Buffer) > 0 Then
        txt_Email.Text = ls_Buffer(1)
    Else
        txt_Email.Text = ""
    End If
    
    chk_opted_out.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "CCU_opt_out") = "X", vbChecked, vbUnchecked)   ' taks 851 JN

    
'P516  replace comp_code by cust_code   was: txt_SapCode.Text = mo_ArmDb.GetFields(ll_Cursor, "comp_code")
    txt_SapCode.Text = mo_ArmDb.GetFields(ll_Cursor, "Cust_Code")
    txt_dateEntered.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "z_creation"))
    txt_lastUpdated.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "z_last_upd"))
    txt_spare1.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_spare1")
    txt_spare2.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_spare2")
    txt_spare3.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_spare3")
    txt_spare4.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_spare4")
    
    srch_primcontact.Clear
    srch_primcontact.Key1 = mo_ArmDb.GetFields(ll_Cursor, "cnt_code")
    srch_primcontact.Text = mo_ArmDb.GetFields(ll_Cursor, "cnt_desc")
    srch_primcontact.CodeCustomer = Thekey1
' IMPLEMENT PROCESS T298.1-A.PR_003
    srch_primcontact.TypeSearch = "PrimContact"
' IMPLEMENT PROCESS T298.1-A.PR_003
    
    chk_StategicAccount.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "ccu_saflag") = "X", Checked, Unchecked)
    
    cbo_country.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "ct_code"), mo_ArmDb.GetFields(ll_Cursor, "ct_desc"), mo_ArmDb.GetFields(ll_Cursor, "DFT_Code")), True
    cbo_County.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "cty_code"), mo_ArmDb.GetFields(ll_Cursor, "cty_desc")), True
    
    cbo_Type.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "cct_code"), mo_ArmDb.GetFields(ll_Cursor, "cct_desc")), True
    cbo_Priority.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "cp_code"), mo_ArmDb.GetFields(ll_Cursor, "cp_desc")), True
    
    
    cbo_Loyalty.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "Loy_code"), mo_ArmDb.GetFields(ll_Cursor, "Loy_desc")), True
    
    mb_ZipCorrect = True
    
    InitCkvAttribute
    InitCkvMarket
    InitCkvStratAccount
    
    acv_Rep.Calling_Key_Values = Thekey1
    acv_Rep.ComboVisible = False
    Call acv_Rep.LoadList
    Call acv_Rep.SetVisibleList("main")

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ViewInitFields"
    #End If
    mb_InternalInit = False
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mb_InternalInit = False
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ViewInitFields"
    CapMouseOn
End Sub

Private Sub ReinitTreeview(as_View As String)
Dim li_rowCount As Integer
Dim TheRequest As String
Dim li_CurrentRow As Integer
Dim li_level As Integer
Dim ls_nodesRequest() As String
Dim ls_gridRequest() As String
Dim ls_excelRequest() As String
Dim ls_countRequest() As String
Dim ls_findRequest() As String
Dim li_images() As Integer
Dim li_selectedImages() As Integer
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ReinitTreeview", "as_View=" & as_View
    #End If
    
    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    tvitems.Visible = False
    
    TheRequest = "EXEC Treeview_Parameters_lst 'Customer', '" & as_View & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:ReinitTreeview", "Request=" & TheRequest
        GoTo Trace_End
    End If
    
    li_rowCount = mo_ArmDb.RowCount(ll_Cursor)
    If li_rowCount = 0 Then
        'zzMsgBox "error in Treeview_Parameters_lst : no rows returned"
        tvitems.Visible = True
        GoTo Trace_End
    End If
    
    ReDim ls_nodesRequest(0 To li_rowCount)
    ReDim ls_gridRequest(0 To li_rowCount)
    ReDim ls_excelRequest(0 To li_rowCount)
    ReDim ls_countRequest(0 To li_rowCount)
    ReDim ls_findRequest(0 To li_rowCount)
    ReDim li_images(0 To li_rowCount)
    ReDim li_selectedImages(0 To li_rowCount)
    
    While Not mo_ArmDb.EOF(ll_Cursor)
        li_level = mo_ArmDb.GetFields(ll_Cursor, "TV_Level")
        ls_nodesRequest(li_level) = ParamReqReplace1(mo_ArmDb.GetFields(ll_Cursor, "TV_NodeRequest"))
        ls_gridRequest(li_level) = ParamReqReplace1(mo_ArmDb.GetFields(ll_Cursor, "TV_GridRequest"))
        ls_excelRequest(li_level) = ParamReqReplace1(mo_ArmDb.GetFields(ll_Cursor, "TV_ExcelRequest"))
        ls_countRequest(li_level) = ParamReqReplace(mo_ArmDb.GetFields(ll_Cursor, "TV_CountRequest"))
        ls_findRequest(li_level) = ParamReqReplace2(mo_ArmDb.GetFields(ll_Cursor, "TV_FindRequest"))
        li_images(li_level) = mo_ArmDb.GetFields(ll_Cursor, "TV_Images")
        li_selectedImages(li_level) = mo_ArmDb.GetFields(ll_Cursor, "TV_SelectedImages")
        
        mo_ArmDb.Next ll_Cursor
    Wend

    tvitems.Levels = li_rowCount                 'set number of levels
    tvitems.StartDemandLevel = 1                 'set level on which we load childs on demand
    tvitems.UseImages = True                     'show icons in treeview
    tvitems.Images = li_images                   'set normal icons
    tvitems.SelectedImages = li_selectedImages   'set selected icons
    tvitems.NodeRequests = ls_nodesRequest
    tvitems.GridRequests = ls_gridRequest
    'tvitems.ExcelRequests = ls_excelRequest
    tvitems.FindRequests = ls_findRequest
    tvitems.CountRequests = ls_countRequest
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.LoadTree LoadTypeChildsDemand
    fill_all_record.Visible = 0
    tvitems.Visible = True

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ReinitTreeview"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ReinitTreeview"
    CapMouseOn
End Sub

Private Function ParamReqReplace(as_Request As String) As String
Dim ls_Request As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ParamReqReplace", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    
    Select Case WhichOptIsTrue(opt_date, 1)
    Case 0
        ls_Request = Replace(ls_Request, "$dt$", "''")
        ls_Request = Replace(ls_Request, "$dd$", "NULL")
        ls_Request = Replace(ls_Request, "$df$", "NULL")
    Case 1
        ls_Request = Replace(ls_Request, "$dt$", "''")
        ls_Request = Replace(ls_Request, "$dd$", "NULL")
        ls_Request = Replace(ls_Request, "$df$", "NULL")
    End Select
        
    ls_Request = Replace(ls_Request, "$SA$", "''")
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ' BEGIN TASK 298.2
    Dim ls_Value As String
    Select Case tbsArchive.SelectedItem.Key
        Case "K"
            ls_Value = "null"
        Case "K0"
            ls_Value = "''"
        Case "K1"
            ls_Value = "'X'"
    End Select
    ls_Request = Replace(ls_Request, "$dropflag$", ls_Value, , , vbTextCompare)
    ParamReqReplace = ls_Request
    ' END TASK 298.2
    
    'If ls_request <> "" Then zzMsgBox ls_request
    ParamReqReplace = ls_Request
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ParamReqReplace", "Result=" & ParamReqReplace
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ParamReqReplace"
    CapMouseOn
End Function

Private Function ParamReqReplace1(as_Request As String) As String
Dim ls_Request As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ParamReqReplace1", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    If opt_date(1) Then
    
        ls_Request = Replace(ls_Request, "$dd_ent$", cas_all("'" & cal11.date_us & "'"))
        ls_Request = Replace(ls_Request, "$df_ent$", cas_all("'" & cal12.date_us & "'"))
        Select Case cbo_date.SelectedItem.Key
            Case 1:
                ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV1_")
            Case 2:
                ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV2_")
        End Select
    Else
        ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV0_")
    End If
    ls_Request = Replace(ls_Request, "$dd_ent$", "Null")
    ls_Request = Replace(ls_Request, "$df_ent$", "Null")
    ls_Request = Replace(ls_Request, "$SA$", cas_all("'" & tbsFilters.SelectedItem.Key & "'"))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ' BEGIN TASK 298.2
    Dim ls_Value As String
    Select Case tbsArchive.SelectedItem.Key
        Case "K"
            ls_Value = "null"
        Case "K0"
            ls_Value = "''"
        Case "K1"
            ls_Value = "'X'"
    End Select
    ls_Request = Replace(ls_Request, "$dropflag$", ls_Value, , , vbTextCompare)
    ' END TASK 298.2
    
    ParamReqReplace1 = ls_Request

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ParamReqReplace1", "Result=" & ParamReqReplace1
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ParamReqReplace1"
    CapMouseOn
End Function

Private Function ParamReqReplace2(as_Request As String) As String
Dim ls_Request As String
Dim PatchTag As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ParamReqReplace2", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    If opt_date(0).Value = True Then
        ls_Request = Replace(ls_Request, "$datetype$", "0")
        ls_Request = Replace(ls_Request, "$dd$", "NULL")
        ls_Request = Replace(ls_Request, "$df$", "NULL")
    Else
        ls_Request = Replace(ls_Request, "$datetype$", GetCodeFromCombo(cbo_date))
        ls_Request = Replace(ls_Request, "$dd$", cas_all("'" & cal11.date_us & "'"))
        ls_Request = Replace(ls_Request, "$df$", cas_all("'" & cal12.date_us & "'"))
    End If
    
    ls_Request = Replace(ls_Request, "$SA$", cas_all("'" & tbsFilters.SelectedItem.Key & "'"))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ' BEGIN TASK 298.2
    Dim ls_Value As String
    Select Case tbsArchive.SelectedItem.Key
        Case "K"
            ls_Value = "null"
        Case "K0"
            ls_Value = "''"
        Case "K1"
            ls_Value = "'X'"
    End Select
    ls_Request = Replace(ls_Request, "$dropflag$", ls_Value, , , vbTextCompare)
    ' END TASK 298.2
    
    ParamReqReplace2 = ls_Request
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ParamReqReplace2", "Result=" & ParamReqReplace2
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcusParamReqReplace2"
    CapMouseOn
End Function



Private Function WhichOptIsTrue(ByRef ao_opt As Object, ai_maxIndex As Integer) As Integer
Dim i As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:WhichOptIsTrue", "ai_maxIndex=" & ai_maxIndex
    #End If
    
    For i = 0 To ai_maxIndex
        If ao_opt(i).Value = True Then
            WhichOptIsTrue = i
            GoTo Trace_End
        End If
    Next i
    WhichOptIsTrue = 0

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:WhichOptIsTrue", "Result=" & WhichOptIsTrue
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:WhichOptIsTrue"
    CapMouseOn
End Function

Private Sub cbo_country_ComboItemSelected()
Dim CodeCountry As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:cbo_country_ComboItemSelected"
    #End If
    
    cbo_County.Clear
    ms_OldCodeCountry = ""

    txt_Zip1.Text = ""
    txt_Zip2.Text = ""
    'Call Update_SalesReps

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:cbo_country_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:cbo_country_ComboItemSelected"
    CapMouseOn
End Sub

Private Sub ListProjectOf(AProjectKey1 As String, AProjectKey2 As String)
Dim la_Columns(11) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ListProjectOf", "AProjectKey1=" & AProjectKey1, "AProjectKey2=" & AProjectKey2
    #End If
    
    If Not (AProjectKey1 <> "" And AProjectKey2 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = False
    
    la_Columns(0) = "ccu_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "ccu_capkey" & CH_LDELIMIT & "ccu_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(2) = "CCU_desc" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_desc" & CH_LDELIMIT & "CCU_desc"
    la_Columns(3) = "SA" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_SAFlag" & CH_LDELIMIT & "SA"
    la_Columns(4) = "CPR_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CPR_desc" & CH_LDELIMIT & "CPR_desc"
    la_Columns(5) = "CCU_zip" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_zip" & CH_LDELIMIT & "CCU_zip"
    la_Columns(6) = "CCU_tel" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_tel" & CH_LDELIMIT & "CCU_tel"
    la_Columns(7) = "TIT_desc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "TIT_desc" & CH_LDELIMIT & "TIT_desc"
    la_Columns(8) = "CNT_name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CNT_name" & CH_LDELIMIT & "CNT_name"
    la_Columns(9) = "CNT_telOffice" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CNT_telOffice" & CH_LDELIMIT & "CNT_telOffice"
    la_Columns(10) = "PC_installatorFlag" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PC_installatorFlag" & CH_LDELIMIT & "PC_installatorFlag"
    la_Columns(11) = "ARCHIVED" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ARCHIVED" & CH_LDELIMIT & "#Deleted"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_CustomerOfProject_Short', 'grid', '" & m_Language & "'", ctColumns

    grdlst.Requests = "exec Cap_ProjectCustomer_t_lst '" & AProjectKey1 & "', '" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapCus:ListProjectOf", "Requests=", grdlst.Requests
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ListProjectOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ListProjectOf"
    CapMouseOn
End Sub

Private Sub ListActionOf(AActionKey1 As String, AActionKey2 As String, AActionKey3 As String)
Dim la_Columns(7) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ListActionOf", "AActionKey1=" & AActionKey1, "AActionKey2=" & AActionKey2, "AActionKey3=" & AActionKey3
    #End If
    
    If Not (AActionKey1 <> "" And AActionKey2 <> "" And AActionKey3 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = False
    
    la_Columns(0) = "CCU_CapKey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "CCU_CapKey" & CH_LDELIMIT & "CCU_CapKey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    'Normalement la procédure stockée ne renvoit qu'une seule ligne au plus et que la clé !
    'On définit ces colonnes seulement si la procédure n'envoit pas de résultat pour que l'utilisateur ait des colonnes visibles
    la_Columns(2) = "SP_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_desc" & CH_LDELIMIT & "SP_desc"
    la_Columns(3) = "SP_zip" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_zip" & CH_LDELIMIT & "SP_zip"
    la_Columns(4) = "SP_town" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_town" & CH_LDELIMIT & "SP_town"
    la_Columns(5) = "SP_size" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_size" & CH_LDELIMIT & "SP_size"
    la_Columns(6) = "SS_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SS_desc" & CH_LDELIMIT & "SS_desc"
    la_Columns(7) = "CPR_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CPR_desc" & CH_LDELIMIT & "CPR_desc"
    
    grdlst.SetColumns la_Columns
   ' grdlst.LoadConstants ptSQL, "EXEC screen_csts_grd ' ', '" & m_Language & "'", ctColumns

    grdlst.Requests = "exec Cap_CustomerAction_t_lst '" & AActionKey1 & "','" & AActionKey2 & "','" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapCus:ListActionOf", "Requests=", grdlst.Requests
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ListActionOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ListActionOf"
    CapMouseOn
End Sub

Private Sub ListContactOf(AContactKey1 As String, AContactKey2 As String, AContactKey3 As String)
Dim la_Columns(6) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ListContactOf", "AContactKey1=" & AContactKey1, "AContactKey2=" & AContactKey2, "AContactKey3=" & AContactKey3
    #End If
    
    If Not (AContactKey1 <> "" And AContactKey2 <> "" And AContactKey3 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = False
    
    la_Columns(0) = "CCU_CapKey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "CCU_CapKey" & CH_LDELIMIT & "CCU_CapKey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(2) = "CCU_desc" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_desc" & CH_LDELIMIT & "CCU_desc"
    la_Columns(3) = "CCT_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCT_desc" & CH_LDELIMIT & "CCT_desc"
    la_Columns(4) = "CCU_zip" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_zip" & CH_LDELIMIT & "CCU_zip"
    la_Columns(5) = "CCU_Town" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_Town" & CH_LDELIMIT & "CCU_Town"
    la_Columns(6) = "CCU_tel" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_tel" & CH_LDELIMIT & "CCU_tel"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_CustomerOfContact_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_CustomerContact_t_lst  '" & AContactKey1 & "', '" & AContactKey2 & "', '" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapCus:ListContactOf", "Requests=", grdlst.Requests
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ListContactOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ListContactOf"
    CapMouseOn
End Sub

Private Sub ShowLink(as_ActionType As String)
Dim lo_LinkForm As LinkForm

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ShowLink", "as_ActionType=" & as_ActionType
    #End If
    
    Dim ls_CustomerKey As String
    Select Case as_ActionType
        Case "Add"
            ls_CustomerKey = ""
        Case Else
            ls_CustomerKey = grdlst.CurrentKey(0)
            If ls_CustomerKey = "" Then GoTo Trace_End
    End Select
    
    Set lo_LinkForm = New LinkForm
    Load lo_LinkForm
    
    lo_LinkForm.Language = m_Language
    lo_LinkForm.ConnectString = ms_ConnectString
    Set lo_LinkForm.mt_CstValues = mt_CstValues
    If mb_use_framework_connection = True Then
        Set lo_LinkForm.ArmDb = mo_ArmDb
    End If
    
    lo_LinkForm.project = m_Project
    
    If as_ActionType <> "Add" Then lo_LinkForm.Customer = ls_CustomerKey
    
    lo_LinkForm.SQLActionType = as_ActionType
    
    If ms_OldCodeCountry <> "" Then
        lo_LinkForm.DefaultCountry = ms_OldCodeCountry
    End If
    
    lo_LinkForm.Load_A_COM
    
    CapMouseOn True
    lo_LinkForm.show 1
    CapMouseOff True
    
    If lo_LinkForm.DataUpdated = True Then
        grdlst.Refresh 'A MODIFIER!!
        RaiseEvent Updated
    End If
    lo_LinkForm.Unload_A_COM
    
    Unload lo_LinkForm
    Set lo_LinkForm = Nothing
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ShowLink"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ShowLink"
    If Not lo_LinkForm Is Nothing Then
        Unload lo_LinkForm
        Set lo_LinkForm = Nothing
    End If

    CapMouseOn
End Sub


Private Sub OwlSearch()
Dim ls_CCUCapKey As String
Dim lo_SearchForm As SeekForm
    

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:OwlSearch"
    #End If
    
    ls_CCUCapKey = ""
    
    If GetCodeFromCombo(Cbo_View) = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        Cbo_View.SetFocus
        GoTo Trace_End
    End If
       
    
    Set lo_SearchForm = New SeekForm
    Load lo_SearchForm
    
    If mb_use_framework_connection = True Then Set lo_SearchForm.ArmDb = mo_ArmDb
    lo_SearchForm.ConnectString = ms_ConnectString
    lo_SearchForm.Language = m_Language
    lo_SearchForm.ComponentType = "CUSTOMER"
    
    If (opt_date(1).Value = True) And (Not cbo_date.SelectedItem Is Nothing) Then
        lo_SearchForm.TreeView_DateType = CStr(cbo_date.SelectedItem.Key)
        
    Else
        lo_SearchForm.TreeView_DateType = "0"
    End If

    lo_SearchForm.TreeViewFiltersDesc = GetCurrentFiltersDescription()
    lo_SearchForm.TreeViewFilters = GetCurrentFilters()
    
    lo_SearchForm.Load_A_COM
    
    CapMouseOn True
    
    lo_SearchForm.show 1
    CapMouseOff True
    
    If lo_SearchForm.SelectedData = True Then
        ls_CCUCapKey = lo_SearchForm.SelectedItemCode
    End If
    
    lo_SearchForm.Unload_A_COM
    
    Unload lo_SearchForm
    Set lo_SearchForm = Nothing
    
    If ls_CCUCapKey <> "" Then
        SearchTreeView ls_CCUCapKey
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:OwlSearch"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:OwlSearch"
    If Not lo_SearchForm Is Nothing Then
        lo_SearchForm.Unload_A_COM
        Unload lo_SearchForm
        Set lo_SearchForm = Nothing
    End If
    CapMouseOn
End Sub

Public Function GetItemSelectedKey() As String
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:GetItemSelectedKey"
    #End If
    GetItemSelectedKey = m_CurrentKey1
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:GetItemSelectedKey"
    #End If
End Function

Public Property Let Customer(ByVal as_CCUCapkey As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Customer"
    #End If
    DisplayMode = mt_CstValues.DisplayMode_List
    SearchTreeView as_CCUCapkey, True
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Customer"
    #End If
End Property

Private Sub SearchTreeView(ByVal as_CCUCapkey As String, Optional ByVal ab_ViewItem As Boolean = True, Optional ByVal ab_DontReinitialize As Boolean = False)
Dim ls_Request As String
Dim ls_RepositionInfo As String
Dim ls_RepositionCode As String
Dim lv_Key As Variant
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:SearchTreeView"
    #End If
    
    If as_CCUCapkey = "" Then GoTo Trace_End
    
    If reload_treeview.Visible Then Call reload_treeview_Click ' TASK 298.2
    
    'Try connexion
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End


    ls_Request = "exec Claim_Customer_t_sel5 '" & as_CCUCapkey & "','" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:SearchTreeView", "Request=" & ls_Request
        GoTo Trace_End
    End If

    ls_RepositionInfo = mo_ArmDb.GetFields(ll_Cursor, "CCU_CapKey") & mo_ArmDb.GetFields(ll_Cursor, "Language_code")
    lv_Key = Split(mo_ArmDb.GetFields(ll_Cursor, "CCU_CapKey") & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "Language_code"), CH_LDELIMIT)
    Select Case GetCodeFromCombo(Cbo_View)
    Case "Va"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCU_Zip1")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
    Case "Vb"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CTY_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCU_Town")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CP_desc")
    Case "Vc"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CTY_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
    Case "Vd"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CP_desc")
    Case "Ve"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CP_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
    Case "Vf"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SA_desc")
    Case "Vg"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCU_Zip1")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCU_Zip2")
    Case "Vh"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SR_name")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "RR_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
    Case "Vi"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "A_desc")
    Case "Vj"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "A_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
    Case "Vk"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CTY_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCU_Town")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "A_desc")
    Case "Vl"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "MKS_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_desc")
    Case "Vm"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "Z_CREATOR")
    End Select
    
    ls_RepositionCode = RepositionAfterSeek(ls_RepositionInfo, tvitems)
    If ls_RepositionCode <> "" Then
        If grdlst.SearchKey(True, lv_Key) Then
            If ab_ViewItem Then
                grdLst_ItemSelected
            End If
        Else
            If ab_DontReinitialize = True Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 202, "#The record you are saving can not be displayed within the current tree view (Record out with your selected tree view criteria)")
            Else
                pctTvReset_Click
                SearchTreeView as_CCUCapkey, ab_ViewItem, True
            End If
        End If
    Else
        If ab_DontReinitialize = True Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 202, "#The record you are saving can not be displayed within the current tree view (Record out with your selected tree view criteria)")
        Else
            pctTvReset_Click
            SearchTreeView as_CCUCapkey, ab_ViewItem, True
        End If
    End If

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:SearchTreeView"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:SearchTreeView"
    CapMouseOn
    
End Sub

Private Function GetCurrentFiltersDescription() As String
Dim li_SAFlag As String
Dim ls_Date As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:GetCurrentFiltersDescription"
    #End If
    
    li_SAFlag = tbsFilters.SelectedItem
    
    If opt_date(0).Value Then ls_Date = opt_date(0).Caption
    If opt_date(1).Value Then
        ls_Date = cbo_date.SelectedItem.DisplayText & " " & LCase(opt_date(1).Caption) & " " & cal11.date_courte & " && " & cal12.date_courte
    End If
     
    GetCurrentFiltersDescription = tbsArchive.SelectedItem.Caption + ", " + ls_Date + " , " + li_SAFlag
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:GetCurrentFiltersDescription", "Result=" & GetCurrentFiltersDescription
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:GetCurrentFiltersDescription"
    CapMouseOn
    
End Function


Private Function GetCurrentFilters() As String
Dim ls_Date1 As String
Dim ls_Date2 As String
Dim ls_SA As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:GetCurrentFilters"
    #End If
    
    If opt_date(0).Value Then
        ls_Date1 = ""
        ls_Date2 = ""
    End If
    
    If opt_date(1).Value Then
        ls_Date1 = cal11.date_us
        ls_Date2 = cal12.date_us
    End If
    
    ' TASK 298.2
    Select Case tbsFilters.SelectedItem.Index
        Case 1
            ls_SA = ""
        Case 2
            ls_SA = "X"
        Case 3
            ls_SA = " "
    End Select
    
    Dim ls_Archived As String
    Select Case tbsArchive.SelectedItem.Key
        Case "K"
            ls_Archived = "NULL"
        Case "K0"
            ls_Archived = "''"
        Case "K1"
            ls_Archived = "'X'"
    End Select
    
    ' TASK 298.2
    GetCurrentFilters = ls_SA & CH_LDELIMIT & ls_Date1 & CH_LDELIMIT & ls_Date2 & CH_LDELIMIT & ls_Archived

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:GetCurrentFilters", "Result=" & GetCurrentFilters
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:GetCurrentFilters"
    CapMouseOn
    
End Function



Private Function GetCurrentRepRole() As String

    Dim ls_SQLRequest As String, lc_Buffer As Long

    'GET DEFAULT SALES REP ROLE FOR THIS CUSTOMER TYPE
    ls_SQLRequest = "SELECT TOP 1 CRR.BU_GROUPING FROM Cap_CompanyType CCT INNER JOIN Cap_RepRole CRR ON CRR.RR_Code = CCT.AD_Code AND CRR.Language_Code = 'E' WHERE CCT_Code = " & GetCodeFromCombo(cbo_Type)
    lc_Buffer = mo_ArmDb.OpenSQL(ls_SQLRequest)
    If lc_Buffer = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capprj:GetCurrentRepRole", "Request=" & ls_SQLRequest
        mo_ArmDb.Close (lc_Buffer)
        'GoTo Trace_End
    End If
    GetCurrentRepRole = mo_ArmDb.GetFields(lc_Buffer, "BU_GROUPING")
    mo_ArmDb.Close (lc_Buffer)
    

End Function




Private Function Update_SalesReps(Optional ByVal NeedConfirmation As Boolean = False) As Boolean
   
    Dim ll_Index As Long, ll_curs As Long
    Dim lv_CustType As Variant
    Dim lv_DefaultRRDesc As Variant
    Dim lv_DefaultRRCode As Variant
    Dim lv_DefaultSRCode As Variant
    Dim ls_SR_Name As String
    Dim ll_RoleCopyToCode As Long
    Dim lv_RoleCopyToDesc As String
    Dim ls_SQLRequest As String
    Dim lc_Buffer As Long
    Dim ls_Zip As String
    Dim ls_CTCode As String
    Dim ls_RRGRPCode As String
    Dim lb_usefullZip As Boolean

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Update_SalesReps", "NeedConfirmation=" & NeedConfirmation
    #End If

    If (DisplayMode <> mt_CstValues.DisplayMode_Add) And (DisplayMode <> mt_CstValues.DisplayMode_Update) Then GoTo Trace_End
    
    If Not cbo_country.SelectedItem Is Nothing Then
        ls_CTCode = GetCodeFromCombo(cbo_country)
        lb_usefullZip = cbo_country.SelectedItem.GetData(2) = "1"
    Else
        Call ASC_SendMessage(mo_ArmDb, m_Language, 931, "#Please, select a country before !")
        GoTo Trace_Err
    End If

    'CHECK IF VALUES CHANGED AND IF THEY ARE CORRECTLY FILLED
    If (GetCodeFromCombo(cbo_Type) = "") Or (IIf(lb_usefullZip, txt_Zip1.Text = "" Or txt_Zip2.Text = "", txt_Zip1.Text = "")) Then
        mb_ZipCorrect = False
        GoTo Trace_End
    End If
    
    ls_Zip = IIf(lb_usefullZip, txt_Zip1.Text + txt_Zip2.Text, txt_Zip1.Text)
         
     'GET DEFAULT SALES REP ROLE FOR THIS CUSTOMER TYPE
     ls_RRGRPCode = GetCurrentRepRole
     
     Call AdjustAcvRepsRole(ls_RRGRPCode)
    
     'SET FILTER ON ZIP TABLE ONLY FOR THIS TYPE
    
     ' Get here the zip code !
     ls_SQLRequest = "exec Cap_ZipCode_t_lst '" & ls_CTCode & "'," & ls_RRGRPCode
     ll_curs = mo_ArmDb.OpenSQL(ls_SQLRequest)
     If ll_curs = 0 Then
         If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capprj:Update_SalesReps", "Request=" & ls_SQLRequest
         GoTo Trace_End
     End If
     'll_Curs = Db.Filter(Cst.c_ZipCode, "CT_Code", "=", ls_CTCode)
     'll_Curs = Db.Filter(ll_Curs, "RR_CODE", "=", lv_DefaultRRCode, , True)
    
     ll_curs = ZipSearch_Ex(mo_ArmDb, ll_curs, ls_Zip)
    
     Select Case mo_ArmDb.RowCount(ll_curs)
         Case 0
             Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Invalid zip code")
             Call mo_ArmDb.Close(ll_curs)
             mb_ZipCorrect = False
             Call SelectStrField(txt_Zip1)
             GoTo Trace_End
         Case 1
             ' The normal way !
             lv_DefaultSRCode = mo_ArmDb.GetFields(ll_curs, "SR_CODE")
             lv_DefaultRRCode = mo_ArmDb.GetFields(ll_curs, "RR_CODE")
             'lv_DefaultRRDesc = Db.GetFields(ll_Curs, "RR_DESC")
             ls_SR_Name = mo_ArmDb.GetFields(ll_curs, "SR_NAME")
         Case Else
             ' Two many reps !
             Call ASC_SendMessage(mo_ArmDb, m_Language, 276, "#Invalid zip code")
             Call mo_ArmDb.Close(ll_curs)
             mb_ZipCorrect = False
             Call SelectStrField(txt_Zip1)
             GoTo Trace_End
     End Select
    
    
     ' Let me check if the rep really change
     Dim la_CustRep As Variant
     Dim ls_CurrentCustRep As String
     Dim ls_View As String
     
     ls_View = IIf(ls_RRGRPCode = mt_CstValues.RRGRP_Cust, "CUST", "SPEC")
     
     la_CustRep = acv_Rep.CheckedKeys(ls_View)
     ls_CurrentCustRep = ""
     
     If IsArray(la_CustRep) Then
         If UBound(la_CustRep) > -1 Then
             ls_CurrentCustRep = la_CustRep(0)(0)
             If ls_CurrentCustRep = lv_DefaultSRCode Then
                 Update_SalesReps = True
                 GoTo Trace_End
             End If
         End If
     End If
    
    
     ' Hum.. Perhaps it's because the user has force manually,
     If NeedConfirmation And ls_CurrentCustRep <> "" Then
         If ASC_SendMessage(mo_ArmDb, m_Language, 801, "#The special rep of this zip code is not the same, would you like to update it ?", vbCrLf & "(" & mo_ArmDb.GetFields(ll_curs, "SR_NAME") & ")", vbYesNo) = vbNo Then
             ' Ok man, if you want, keep it !
             Call mo_ArmDb.Close(ll_curs)
             mb_ZipCorrect = True
             GoTo Trace_End
         End If
     End If
     
     Call mo_ArmDb.Close(ll_curs)
    
    Dim lb_OneRepFound As Boolean
    lb_OneRepFound = False
    'FIND NEW DEFAULT SALES REP IN ZIP TABLE ACCORDING AND ZIP CODE
    Select Case ls_RRGRPCode
        Case mt_CstValues.RRGRP_Cust
            lb_OneRepFound = acv_Rep.SetItemState("CUST", lv_DefaultSRCode, True)
            Call acv_Rep.UnCheckAll("SPEC")
        Case mt_CstValues.RRGRP_Spec
            lb_OneRepFound = acv_Rep.SetItemState("SPEC", lv_DefaultSRCode, True)
            Call acv_Rep.UnCheckAll("CUST")
    End Select
    txt_spare1.Text = "N"
    
    mb_ZipCorrect = lb_OneRepFound
    If Not lb_OneRepFound Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Invalid zip code")
        Call SelectStrField(txt_Zip1)
    End If

Trace_End:

     If Not mb_ZipCorrect Then
        Select Case ls_RRGRPCode
                Case mt_CstValues.RRGRP_Cust
                    Call acv_Rep.UnCheckAll("CUST")
                Case mt_CstValues.RRGRP_Spec
                    Call acv_Rep.UnCheckAll("SPEC")
            End Select
     End If

    Call mo_ArmDb.Close(ll_curs)
    Call mo_ArmDb.Close(lc_Buffer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Update_SalesReps"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:

     If Not mb_ZipCorrect Then
        Select Case ls_RRGRPCode
                Case mt_CstValues.RRGRP_Cust
                    Call acv_Rep.UnCheckAll("CUST")
                Case mt_CstValues.RRGRP_Spec
                    Call acv_Rep.UnCheckAll("SPEC")
            End Select
     End If

    Call mo_ArmDb.Close(ll_curs)
    Call mo_ArmDb.Close(lc_Buffer)
    mb_ZipCorrect = False
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Update_SalesReps"
    CapMouseOn

  
End Function


Private Sub InitAcvRepsRole(Optional ByVal as_RepRoleGrp As String = "")
    
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:InitAcvRepsRole"
    #End If
    
        ' load descriptino translation for roles
    Dim ll_Cursor As Long
    Dim ls_speDesc As String
    Dim ll_custDesc As String
    Dim ll_copyDesc As String
    
    
    ll_Cursor = OpenSQLSafe(mo_ArmDb, "select RR_Code, RR_Desc from Cap_RepRole where language_code='" & m_Language & "'")
    If mo_ArmDb.Find(ll_Cursor, "RR_Code", 1) >= 0 Then
        ls_speDesc = mo_ArmDb.GetFields(ll_Cursor, "RR_Desc")
    Else
        ls_speDesc = "#Specifier"
    End If
    
    If mo_ArmDb.Find(ll_Cursor, "RR_Code", 2) >= 0 Then
        ll_custDesc = mo_ArmDb.GetFields(ll_Cursor, "RR_Desc")
    Else
        ll_custDesc = "#Customer"
    End If
    
    If mo_ArmDb.Find(ll_Cursor, "RR_Code", 3) >= 0 Then
        ll_copyDesc = mo_ArmDb.GetFields(ll_Cursor, "RR_Desc")
    Else
        ll_copyDesc = "#Copy to"
    End If
    
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0



    Dim ls_RepRoleGrp As String, lb_ReadOnly As Boolean
    ls_RepRoleGrp = as_RepRoleGrp
    
    acv_Rep.RoleCount = 4
    
    Dim la_Spec_RoleMain As Variant, la_Spec_RoleSpec As Variant, la_Spec_RoleCust As Variant, la_Spec_RoleCopy As Variant
    
    lb_ReadOnly = (GetDefaultConfigCode("Capture_Cfg", "CanUpdateRepManually") <> "1")
    
    la_Spec_RoleMain = Array("MAIN", "VIEW", "", "", "Main view", "SR_code®©SR_name®©RR_desc®©RR_code", "SR_name®©RR_desc", "1700®©1000", "SR_code®©RR_code", "exec Cap_CompanyRep_lst '$CCU_Capkey$','" & m_Language & "'", "exec Cap_CompanyRep_Ins '$CCU_Capkey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_CompanyRep_Del '$CCU_Capkey$','$SR_CODE$',$RR_Code$", True, 2, False, True, 0, 0)
    la_Spec_RoleCopy = Array("COPY", "EDIT", "rr_code®©rr_desc", "3®©" & ll_copyDesc, ll_copyDesc, "SR_code®©SR_name", "SR_name®©RR_desc", "1700®©1000", "SR_code", "exec Cap_CompanyRep_lst2 '$CCU_Capkey$', '" & m_Language & "'", "exec Cap_CompanyRep_Ins '$CCU_Capkey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_CompanyRep_Del '$CCU_Capkey$','$SR_CODE$',$RR_Code$", False, 2, False, True, 3, 0)
    la_Spec_RoleSpec = Array("SPEC", "EDIT", "rr_code®©rr_desc", "1®©" & ls_speDesc, ls_speDesc, "SR_code®©SR_name", "SR_name®©RR_desc", "1700®©1000", "SR_code", "exec Cap_CompanyRep_lst2 '$CCU_Capkey$','" & m_Language & "'", "exec Cap_CompanyRep_Ins '$CCU_Capkey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_CompanyRep_Del '$CCU_Capkey$','$SR_CODE$',$RR_Code$", lb_ReadOnly, 1, True, True, 1, 0)
    la_Spec_RoleCust = Array("CUST", "EDIT", "rr_code®©rr_desc", "2®©" & ll_custDesc, ll_custDesc, "SR_code®©SR_name", "SR_name®©RR_desc", "1700®©1000", "SR_code", "exec Cap_CompanyRep_lst2 '$CCU_Capkey$','" & m_Language & "'", "exec Cap_CompanyRep_Ins '$CCU_Capkey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_CompanyRep_Del '$CCU_Capkey$','$SR_CODE$',$RR_Code$", lb_ReadOnly, 1, True, True, 2, 0)
  
    If Not acv_Rep.SetRoleList(Array(la_Spec_RoleMain, la_Spec_RoleSpec, la_Spec_RoleCust, la_Spec_RoleCopy)) Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 932, "#Critical error, please contact it")
        End
    End If
    
    acv_Rep.Synchronize_View = True
    acv_Rep.HideColumnHeaders = False
    acv_Rep.LoadConstants CVptStatic, "SR_Name" & CH_LDELIMIT & Lbl_SalesReps.Caption & CH_LDELIMIT & "RR_Desc" & CH_LDELIMIT & lbl_role.Caption, CVctColumns
    
    Call acv_Rep.SetVisibleList("MAIN")
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:InitAcvRepsRole"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If ll_Cursor > 0 Then Call mo_ArmDb.Close(ll_Cursor)
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:InitAcvRepsRole"
    CapMouseOn

End Sub

Private Sub TransfertCustomer()
Dim ls_CCUCapKey As String
Dim lo_SearchForm As SeekForm
Dim ls_Request As String
Dim ll_Cursor As Long
Dim ls_Data As String
Dim lo_Node As Node
Dim lo_NodeParent As Node

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:TransfertCustomer"
    #End If
    
    Set lo_SearchForm = New SeekForm
    Load lo_SearchForm
    If mb_use_framework_connection = True Then Set lo_SearchForm.ArmDb = mo_ArmDb
    lo_SearchForm.ConnectString = ms_ConnectString
    lo_SearchForm.Language = m_Language
    lo_SearchForm.ComponentType = "CUSTOMER"
    lo_SearchForm.TreeView_DateType = "0"
    lo_SearchForm.TreeViewFilters = Join(Array("", "", "", "NULL"), CH_LDELIMIT)
    
    lo_SearchForm.Load_A_COM
    
    CapMouseOn True
    
    lo_SearchForm.show 1
    CapMouseOff True
    
    ls_CCUCapKey = lo_SearchForm.SelectedItemCode
    
    lo_SearchForm.Unload_A_COM
    Unload lo_SearchForm
    
    Set lo_SearchForm = Nothing
    
    If ls_CCUCapKey = "" Then GoTo Trace_End
    
    If StrComp(ls_CCUCapKey, m_CurrentKey1, vbTextCompare) = 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 937, "#Unable to transfert a customer on himself")
        GoTo Trace_End
    End If
    
   If ASC_SendMessage(mo_ArmDb, m_Language, 1026, "#Do you really want to transfert this customer ?", , vbYesNo) = vbNo Then GoTo Trace_End
    
    'Try connexion
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End

    ls_Request = "exec claim_customer_transfert '" & ls_CCUCapKey & "','" & m_CurrentKey1 & "'"
    
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
    
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:TransfertCustomer", "Request=" & ls_Request
        Call ASC_SendMessage(mo_ArmDb, m_Language, 934, "#An error occured, and the transfert was not done. Please, contact IT")
        Call AddToTransfertLog(mo_ArmDb, ms_UID, GetTransfertID(mo_ArmDb, ms_UID, "CST"), "CST", m_CurrentKey1, ls_CCUCapKey, ls_Request, False, mo_ArmDb.LastErrorMessage)
        GoTo Trace_End
    End If
    
    ls_Data = mo_ArmDb.GetFields(ll_Cursor, 0)
    If ls_Data <> "0" Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:TransfertCustomer", "Request=" & ls_Request
        Call ASC_SendMessage(mo_ArmDb, m_Language, 934, "#An error occured, and the transfert was not done. Please, contact IT")
        Call AddToTransfertLog(mo_ArmDb, ms_UID, GetTransfertID(mo_ArmDb, ms_UID, "CST"), "CST", m_CurrentKey1, ls_CCUCapKey, ls_Request, False, mo_ArmDb.LastErrorMessage & ", " & ls_Data)
        GoTo Trace_End
    End If
    Call AddToTransfertLog(mo_ArmDb, ms_UID, GetTransfertID(mo_ArmDb, ms_UID, "CST"), "CST", m_CurrentKey1, ls_CCUCapKey, ls_Request, True, mo_ArmDb.LastErrorMessage)
    
    pbItem_action "Quit"

    grdlst.DeleteLine
    If grdlst.Rows = 0 Then
        Set lo_Node = tvitems.SelectedItem
        Set lo_NodeParent = tvitems.SelectedItem.Parent
        tvitems.RemoveNode lo_Node
        If Not lo_NodeParent Is Nothing Then
            Do While lo_NodeParent.children = 0
                Set lo_Node = lo_NodeParent
                Set lo_NodeParent = lo_Node.Parent
                tvitems.RemoveNode lo_Node
                If lo_NodeParent Is Nothing Then Exit Do
            Loop
        End If
    End If
    
    grdlst.Requests = ""
    fill_all_record.Visible = 0
    grdlst.ClearGrid

    SearchTreeView ls_CCUCapKey
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:TransfertCustomer"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:TransfertCustomer"
    If Not lo_SearchForm Is Nothing Then
        lo_SearchForm.Unload_A_COM
        Unload lo_SearchForm
        Set lo_SearchForm = Nothing
    End If

    mo_ArmDb.Close ll_Cursor
    
    CapMouseOn
End Sub



Private Sub AdjustAcvRepsRole(Optional ByVal as_RepRoleGrp As String = "")
    
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:AdjustAcvRepsRole"
    #End If
    CapMouseOff
    
    Dim ls_RepRoleGrp As String, lb_ReadOnly As Boolean
    ls_RepRoleGrp = as_RepRoleGrp
    
    
    lb_ReadOnly = (GetDefaultConfigCode("Capture_Cfg", "CanUpdateRepManually") <> "1")
    
    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_Update, mt_CstValues.DisplayMode_Add
            If ls_RepRoleGrp = "" Then
                ls_RepRoleGrp = GetCurrentRepRole
            End If
            Select Case ls_RepRoleGrp
                Case mt_CstValues.RRGRP_Cust
                    acv_Rep.RoleList("CUST").Priority = 1
                    acv_Rep.RoleList("CUST").ReadOnly = lb_ReadOnly
                   
                    acv_Rep.RoleList("SPEC").Priority = 2
                    acv_Rep.RoleList("SPEC").ReadOnly = True
                    acv_Rep.UnCheckAll ("SPEC")
                    
                    Call acv_Rep.SetVisibleList("CUST")
                    
                Case mt_CstValues.RRGRP_Spec
                    
                    acv_Rep.RoleList("SPEC").Priority = 1
                    acv_Rep.RoleList("SPEC").ReadOnly = lb_ReadOnly
                   
                    acv_Rep.RoleList("CUST").Priority = 2
                    acv_Rep.RoleList("CUST").ReadOnly = True
                    acv_Rep.UnCheckAll ("CUST")
                   
                    Call acv_Rep.SetVisibleList("SPEC")
            End Select
                
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:AdjustAcvRepsRole"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:AdjustAcvRepsRole"
    CapMouseOn

End Sub


' This function is called after
Public Function UpdateSalesProjectRep(ByVal as_CCU_Capkey As String) As Boolean
Dim ls_Request As String
Dim ll_Cursor As Long
Dim ls_Result As String

    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:UpdateSalesProjectrep"
    #End If
    CapMouseOff

    ls_Request = "EXEC Cap_CustSPToUpdate " & FormatSqlStringParameter(as_CCU_Capkey)
    
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request)
    
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then Call go_Trace.WriteTraceSQLError(mo_ArmDb, "capprj:UpdateSalesProjectrep", "Request=" & ls_Request)
        UpdateSalesProjectRep = False
        GoTo Trace_End
    End If

    Dim ll_Count As Long, ll_Idx As Long
    Dim ls_SP_Capkey As String, ls_SP_SR_Code As String, ls_SP_RR_Code As String
    Dim ls_CCU_Capkey As String, ls_CCU_SR_Code As String, ls_CCU_RR_Code As String
    Dim ls_CCUSP_RR_Code As String, ls_CCUSP_BU_GROUPING As String
    
    ll_Count = mo_ArmDb.RowCount(ll_Cursor) - 1
    
    
    UpdateSalesProjectRep = False
    
    For ll_Idx = 0 To ll_Count
        ls_SP_Capkey = mo_ArmDb.GetFields(ll_Cursor, 0)
        ls_SP_SR_Code = mo_ArmDb.GetFields(ll_Cursor, 1)
        ls_SP_RR_Code = mo_ArmDb.GetFields(ll_Cursor, 2)
        ls_CCU_SR_Code = mo_ArmDb.GetFields(ll_Cursor, 4)
        ls_CCU_RR_Code = mo_ArmDb.GetFields(ll_Cursor, 5)
        ls_CCUSP_RR_Code = mo_ArmDb.GetFields(ll_Cursor, 6)
        ls_CCUSP_BU_GROUPING = mo_ArmDb.GetFields(ll_Cursor, 7)
        
        If ls_CCUSP_RR_Code = "0" Then
            ' we delete the old one
            If Not Delete_ProjectRep(mo_ArmDb, ls_SP_Capkey, ls_SP_SR_Code, ls_SP_RR_Code, ls_Result) Then GoTo Trace_End
            ' We add the new rep
            If Not Add_ProjectRep(mo_ArmDb, ls_SP_Capkey, ls_CCU_SR_Code, mt_CstValues.RR_Spec, ls_Result) Then GoTo Trace_End
        Else
            Select Case ls_CCUSP_BU_GROUPING
                
                Case mt_CstValues.RRGRP_Spec
                    ' Do nothing, normaly nether happend
                Case mt_CstValues.RRGRP_Cust
                    ' we delete the old one
                    If Not Delete_ProjectRep(mo_ArmDb, ls_SP_Capkey, ls_SP_SR_Code, ls_SP_RR_Code, ls_Result) Then GoTo Trace_End
                    ' We add the new rep
                    If Not Add_ProjectRep(mo_ArmDb, ls_SP_Capkey, ls_CCU_SR_Code, mt_CstValues.RR_Spec, ls_Result) Then GoTo Trace_End
                
                Case mt_CstValues.RRGRP_Copied
                    ' we delete the old one
                    If Not Delete_ProjectRep(mo_ArmDb, ls_SP_Capkey, ls_SP_SR_Code, ls_SP_RR_Code, ls_Result) Then GoTo Trace_End
                    ' We update an old one
                    If Not Update_ProjectRep(mo_ArmDb, ls_SP_Capkey, ls_CCU_SR_Code, ls_CCUSP_RR_Code, mt_CstValues.RR_Spec, ls_Result) Then GoTo Trace_End
            End Select
        End If
        mo_ArmDb.Next (ll_Cursor)
    Next

    UpdateSalesProjectRep = True

Trace_End:
    Call mo_ArmDb.Close(ll_Cursor)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:UpdateSalesProjectrep"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    Call mo_ArmDb.Close(ll_Cursor)
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:UpdateSalesProjectrep"
    CapMouseOn
    UpdateSalesProjectRep = False

End Function


' This function is called by the application when the component embedded is updated
Public Sub Embedded_Updated(ByVal ab_FromEmbedded As Boolean)
Dim ls_Code As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Embedded_Updated"
    #End If

    If Not ab_FromEmbedded Then
        ' TO DO
    Else
        Select Case mi_EmbedTag
        Case mt_CstValues.Tag_Memo
            Call CheckMemoClaim
        Case mt_CstValues.Tag_Contact
            Call RefreshLastUpdate
        Case mt_CstValues.Tag_Action
            Call RefreshLastUpdate
            Call acv_Rep.LoadList
        End Select
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Embedded_Updated"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Embedded_Updated"
    CapMouseOn
    
End Sub

Private Sub RefreshLastUpdate()

  txt_lastUpdated.Text = Format(Date, "dd/mm/yyyy")
End Sub


Private Function CheckMemoClaim() As Boolean
Dim ls_Request As String
Dim ll_Cursor As Long
Dim ll_Count As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CheckMemoClaim"
    #End If
    
    CheckMemoClaim = False
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ls_Request = "Select count(*) FROM Cap_MemoCompany MC Where MC.CCU_Capkey = '" & m_CurrentKey1 & "' "
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "capcus:CheckMemoClaim", "Request=" & ls_Request
        GoTo Trace_End
    End If
    
    ll_Count = mo_ArmDb.GetFields(ll_Cursor, 0)
    Call UpdateTabInfo(tbsEmbedded, SetLstKey(mt_CstValues.Tag_Memo), ll_Count > 0, ll_Count)
        
    CheckMemoClaim = True
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CheckMemoClaim"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CheckMemoClaim"
    CapMouseOn
End Function

Private Sub UpdateTabInfo(ao_TabStrip As MSComctlLib.TabStrip, av_TabKey As Variant, ab_HighLight As Boolean, Optional al_RecordCount As Long = -1)
Dim ls_Caption As String
Dim ll_Index As Long
Dim lo_Tab As MSComctlLib.Tab
Dim lv_TabHighlight As Variant
    
    On Error GoTo Trace_Err
    
    
    Set lo_Tab = ao_TabStrip.Tabs(av_TabKey)
        
    If al_RecordCount >= 0 Then
      'first I must store highlight for all tabs, because it will be destroyed
      'by setting caption for tab (seems to be VB issue)
      ReDim lv_TabHighlight(ao_TabStrip.Tabs.Count - 1)
      For ll_Index = 1 To ao_TabStrip.Tabs.Count
        lv_TabHighlight(ll_Index - 1) = ao_TabStrip.Tabs(ll_Index).HighLighted
      Next
      
      ls_Caption = lo_Tab.Caption
      ll_Index = InStr(1, ls_Caption, " [")
      If ll_Index > 0 Then ls_Caption = Left(ls_Caption, ll_Index - 1)
      ls_Caption = ls_Caption & " [" & al_RecordCount & "]"
      
      lo_Tab.Caption = ls_Caption
      DoEvents
      For ll_Index = 1 To ao_TabStrip.Tabs.Count
        ao_TabStrip.Tabs(ll_Index).HighLighted = lv_TabHighlight(ll_Index - 1)
      Next
      DoEvents
    End If
    DoEvents
    lo_Tab.HighLighted = ab_HighLight
    DoEvents
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcon:UpdateTab"
End Sub

Private Sub acv_Rep_ItemCheck(ByVal Item As MSComctlLib.ListItem)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:acv_Rep_ItemCheck", "Item=" & Item.Key
    #End If
    
    txt_spare1.Text = "Y"

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:acv_Rep_ItemCheck"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:acv_Rep_ItemCheck"
    CapMouseOn


End Sub


' Process the business card
Private Sub bt_Bcc_Click()
    Call Process_BusinessCard
End Sub


Private Function GetBusinessCard(ByVal as_CCU_Capkey As String) As Long


    Const C_L_DB_GETARTICLE As String = "SELECT CA.Art_ID" & vbCrLf & _
                                        "FROM CM_Articles CA" & vbCrLf & _
                                        "INNER JOIN CM_ArticlesLinks CAL ON CAL.Art_ID = CA.Art_ID" & vbCrLf & _
                                        "           AND CCU_Capkey = '$ccu_capkey$'" & vbCrLf & _
                                        "WHERE CA.Tplt_ID = $tplt_id$" & vbCrLf & _
                                        "AND CA.Language_Code ='$language_code$'" & vbCrLf & _
                                        "AND CA.Drop_Flag = ''" & vbCrLf

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:GetBusinessCard"
    #End If

    Dim ls_Request As String, lc_Art As Long
    ls_Request = Replace(C_L_DB_GETARTICLE, "$ccu_capkey$", m_CurrentKey1)
    ls_Request = Replace(ls_Request, "$language_code$", m_Language)
    ls_Request = Replace(ls_Request, "$tplt_id$", C_TEMPLATE_BUSINESS_CARD_CONTRACTOR)

    lc_Art = mo_ArmDb.OpenSQL(ls_Request)
    
    If mo_ArmDb.LastErrorCode <> 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "capcus:GetBusinessCard", "Request=" & ls_Request
        GoTo Trace_End
    End If

    GetBusinessCard = mo_ArmDb.GetFields(lc_Art, "Art_ID")
    
Trace_End:
    Call mo_ArmDb.Close(lc_Art)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:GetBusinessCard"
    #End If
    CapMouseOn
    Exit Function

Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:GetBusinessCard"
    CapMouseOn


End Function


Private Sub Process_BusinessCard()
    
    Const C_L_DB_GETARTICLE As String = "SELECT CA.Art_ID" & vbCrLf & _
                                        "FROM CM_Articles CA" & vbCrLf & _
                                        "INNER JOIN CM_ArticlesLinks CAL ON CAL.Art_ID = CA.Art_ID" & vbCrLf & _
                                        "           AND CCU_Capkey = '$ccu_capkey$'" & vbCrLf & _
                                        "WHERE CA.Tplt_ID = $tplt_id$" & vbCrLf & _
                                        "AND CA.Language_Code ='$language_code$'" & vbCrLf & _
                                        "AND CA.Drop_Flag = ''" & vbCrLf

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:Process_BusinessCard"
    #End If

    Dim ll_Art_ID As Long
    ll_Art_ID = GetBusinessCard(m_CurrentKey1)

    If ll_Art_ID <> 0 Then
        If Not BCC.View(ll_Art_ID) Then
            Err.Raise -1, , "Cannot display the following business card:" & ll_Art_ID
        End If
    Else
        If BusinessCardAllowed Then
            If Not BCC.Add(m_CurrentKey1) Then
                Err.Raise -1, "Cannot create business card for customer: " & m_CurrentKey1
            End If
        Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 949, "#This customer don't have all criteria required to create a business card")
            GoTo Trace_End
        End If
    End If
    BCC.Visible = True
    
Trace_End:
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:Process_BusinessCard"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    BCC.Visible = False
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:Process_BusinessCard"
    CapMouseOn

End Sub

Private Sub BCC_evQuit()
    BCC.Visible = False
End Sub

Private Sub BCC_evItemAdded(ByVal al_Art_ID As Long)
    BCC.Visible = False
    BCC.View
    BCC.Visible = True
End Sub

Private Sub BCC_evItemDeleted(ByVal al_Art_ID As Long)
    BCC.Visible = False
End Sub

Private Sub BCC_evItemUpdated(ByVal al_Art_ID As Long)
    BCC.Visible = False
    BCC.View
    BCC.Visible = True
End Sub


Private Function BusinessCardAllowed() As Boolean

    Const C_L_DB_BCC_CHECKALLOWED As String = "exec BCC_CheckAllowed '$ct_code$', $cct_code$, '$cta_code_lst$'"

    BusinessCardAllowed = False
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:BusinessCardAllowed"
    #End If

    ' First criteria is the country
    Dim ls_Request As String, ls_Buffer As String
    ls_Buffer = GetCodeFromCombo(cbo_country)
    If ls_Buffer = "" Then GoTo Trace_End
    ls_Request = Replace(C_L_DB_BCC_CHECKALLOWED, "$ct_code$", ls_Buffer)
    
    ' Then it's the customer type
    ls_Buffer = GetCodeFromCombo(cbo_Type)
    If ls_Buffer = "" Then GoTo Trace_End
    ls_Request = Replace(ls_Request, "$cct_code$", ls_Buffer)
    
    ' Then it's the attribute
    Dim ll_Idx As Long, ll_Count As Long
    ll_Count = CkvAttribute.ListItems.Count
    ls_Buffer = ""
    For ll_Idx = 1 To ll_Count
        If CkvAttribute.ListItems(ll_Idx).Checked Then
            ls_Buffer = ls_Buffer & CH_LDELIMIT & CkvAttribute.ListItems(ll_Idx).Tag.Id
        End If
    Next
    If ls_Buffer = "" Then GoTo Trace_End
    ls_Buffer = ls_Buffer & CH_LDELIMIT
    ls_Request = Replace(ls_Request, "$cta_code_lst$", ls_Buffer)
    
    Dim lc_Curs As Long
    lc_Curs = mo_ArmDb.OpenSQL(ls_Request)
    
    BusinessCardAllowed = (mo_ArmDb.GetFields(lc_Curs, 0) = "OK")

Trace_End:
    mo_ArmDb.Close (lc_Curs)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:BusinessCardAllowed"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    mo_ArmDb.Close (lc_Curs)
    BusinessCardAllowed = False
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:BusinessCardAllowed"
    CapMouseOn

End Function



' Return true if have created the node
Private Function FindInTreeView(ByVal aTV As ArmTreeView, ByVal aPath As String) As Boolean

    On Error GoTo onError:
    Dim lValues As Variant
    lValues = Split(aPath, SEP & SEP)

    Dim lIdx As Long, lCount As Long, lFoundedCount As Long
    lCount = UBound(lValues)
    Dim lData As Variant, lKey As String, lValue As String
    
    lData = Split(lValues(0), SEP)
    lKey = lData(0)
    lValue = lData(1)
    
    
    If Not aTV.Find(lKey, 0, , 0) Then
        aTV.AddNode(, lKey, lValue, 1, 2).Selected = True
        FindInTreeView = True
    End If
    
    lFoundedCount = 1
    Call aTV.ExpandNode(aTV.SelectedItem)

    For lIdx = 1 To lCount
        lData = Split(lValues(lIdx), SEP)
        lKey = lData(0)
        lValue = lData(1)
        If Not aTV.Find(lKey, 0, aTV.SelectedItem, lIdx) Then
            aTV.AddNode(aTV.SelectedItem, lKey, lValue, 1, 2).Selected = True
            Call tvItems_NodeClick(aTV.SelectedItem)
            FindInTreeView = True
            
        End If
        Call aTV.ExpandNode(aTV.SelectedItem)
        lFoundedCount = lFoundedCount + 1
    Next

    Exit Function
onError:
    'debug.print "Error in findintreeview"
End Function


Private Function GetCurrentPath(ByRef aControls As Variant, ByRef aContainer As Object, ByVal aPattern As String) As String

    Dim lPattern() As String
    lPattern = Split(aPattern, SEP)

    Dim lPath() As String
    lPath = lPattern

    Dim lIdxPattern As Long, lCountPattern As Long, lIdxPath As Long
    Dim lIdx As Long, lCount As Long, lIdxLbl As Long
    Dim lControl As Control, li As Long, lc As Long

    lCountPattern = UBound(lPattern)
    lCount = aControls.Count - 1
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        If HasContainer(lControl, aContainer) Then
            If lControl.Tag <> "" Then
            lIdxPath = -1
            For lIdxPattern = 0 To lCountPattern
                If StrComp(lControl.Tag, lPattern(lIdxPattern), vbTextCompare) = 0 Then
                    Select Case UCase(TypeName(lControl))
                        Case "TEXTBOX"
                            lPath(lIdxPattern) = lControl.Text & SEP & lControl.Text
                        Case "ARMCOMBOBOX"
                            lPath(lIdxPattern) = lControl.SelectedItem.Key & SEP & lControl.SelectedItem.DisplayText
                        Case "ARMCHECKVIEW0"
                            lc = lControl.ListItems.Count - 1
                            For li = 0 To lc
                                If lControl.ItemInfo(li).Checked = True Then
                                    If UCase(lControl.Tag) = "CKVATTRIBUTE" Then
                                        If mo_ArmDb.Find(mAttributes, "CTA_CODE", lControl.ItemInfo(li).Id, , 1) > -1 Then
                                            lPath(lIdxPattern) = mo_ArmDb.GetFields(mAttributes, "A_Code") & SEP & lControl.ItemInfo(li).Caption
                                        End If
                                    Else
                                        lPath(lIdxPattern) = lControl.ItemInfo(li).Id & SEP & lControl.ItemInfo(li).Caption
                                    End If
                                    Exit For
                                End If
                            Next
                        Case "ARMCHECKVIEW"
                                If lControl.RoleList(lControl.GetVisibleList).CheckedCount Then
                                    lPath(lIdxPattern) = Trim(lControl.RoleList(lControl.GetVisibleList).CheckedKeys(0)(0))
                                Else
                                    lPath(lIdxPattern) = ""
                                End If
                        Case Else
                            'debug.print "GetCurrentPath" & UCase(TypeName(lControl))
                    End Select
                Exit For
                End If
            Next
            End If
        End If
        Set lControl = Nothing
    Next

    Dim lBuffer As String
    lBuffer = Join(lPath, SEP & SEP)
    
    Dim lRole As String, lRoleIdx As Long
    If acv_Rep.RoleList("SPEC").CheckedCount <> 0 Then
        lRoleIdx = 1
        lRole = "SPEC"
    Else
        lRoleIdx = 2
        lRole = "CUST"
    End If
    
    ' PUT HERE THE EXCEPTION
    lBuffer = Replace(lBuffer, "ckvSalesRep.SalesRep", acv_Rep.RoleList((lRole)).CheckedKeys(0)(0) & SEP & acv_Rep.RoleList((lRole)).GetItem(acv_Rep.RoleList((lRole)).CheckedKeys(0)).GetData(1), , , vbTextCompare)
    lBuffer = Replace(lBuffer, "ckvSalesRep.Division", lRoleIdx & SEP & Replace(acv_Rep.RoleList((lRole)).Caption, "#", "", , vbTextCompare), , , vbTextCompare)
        
    GetCurrentPath = lBuffer

End Function

Private Function HasContainer(ByRef aControl As Control, ByRef aContainer As Object) As Boolean
    
    HasContainer = False
    Dim lControl As Control
    
    Set lControl = aControl
    While Not (lControl Is Nothing)
        On Error GoTo NotFound
        If lControl.Container Is aContainer Then
            Set lControl = Nothing
            HasContainer = True
            Exit Function
        End If
        Set lControl = lControl.Container
    Wend

NotFound:
    Set lControl = Nothing
    HasContainer = False
End Function


Public Function Item_Filtered() As Boolean
    
    ' BEGIN TASK 298.2
    Select Case tbsArchive.SelectedItem.Key
        Case "K"
            ' NO Filters
        Case "K0"
            ' Only non archived,
            Item_Filtered = (chk_DropFlag.Value = 1)
            Exit Function
        Case "K1"
            ' Only archived
            Item_Filtered = (chk_DropFlag.Value <> 1)
            Exit Function
    End Select
    'END TASK 298.2

    
    ' Check date
    If opt_date(1).Value = True Then
        Dim lDate As Date
        Select Case CStr(cbo_date.SelectedItem.Key)
            Case "1" ' Date entered
                lDate = txt_dateEntered.Text
            Case "2" ' Date last updated
                lDate = txt_lastUpdated.Text
        End Select
        
        ' CHECK
        If DateDiff("d", cal11.date_courte, lDate) < 0 Then
            Item_Filtered = True
            Exit Function
        End If
        
        If DateDiff("d", cal12.date_courte, lDate) > 0 Then
            Item_Filtered = True
            Exit Function
        End If
    End If

        
    Select Case tbsFilters.SelectedItem.Tag
        Case "tbs_filtersAll"
            ' DO NOTHING
        Case "tbs_filtersSA"
            Item_Filtered = (chk_StategicAccount.Value = 0)
        Case "tbs_filtersNonSA"
            Item_Filtered = (chk_StategicAccount.Value = 1)
    End Select
    
End Function

Public Sub Item_LocalUpdate()
    
    If Item_Filtered Then
        Call AddToTimeLog(mi_OldDisplayMode, 99)
        If ASC_SendMessage(mo_ArmDb, m_Language, 1006, "#The item you have added/updated couldn't be displayed with the current criteria set. Would you like to reset the filters to their original values ?", "", vbQuestion Or vbYesNo, "") = vbYes Then
            pctTvReset_Click
        Else
            Exit Sub
        End If
    End If
    
    Dim lPath As String
    lPath = GetCurrentPath(UserControl.Controls, fraItem, Cbo_View.SelectedItem.GetData(2))
    tvitems.Visible = False
    Call FindInTreeView(tvitems, lPath)
    tvitems.Visible = True
    Call grdlst.SearchKey(True, Array(m_CurrentKey1, "E"))
            
End Sub

Public Sub AddToTimeLog(ByVal aFct As Long, ByVal aTime As Double)

    Static lComputer As String
    
    If lComputer = "" Then
        Dim loNetObject
        Set loNetObject = CreateObject("WScript.Network")
        lComputer = loNetObject.ComputerName
        Set loNetObject = Nothing
    End If
    
    Call mo_ArmDb.ExecuteSQL("insert into Log_Esther values ('F" & aFct & "', GetDate(), '" & lComputer & "', " & Replace(CStr(aTime), ",", ".") & ")")

End Sub

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

On Error GoTo ErrHandler

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

    OpenSQLSafe = lc_Data

    Exit Function

ErrHandler:
    Call ErrorHandler("OpenSQLSafe")

End Function


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

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

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

    ExecuteSQLSafe = ao_Db.SQLRowsAffected
    Exit Function

ErrHandler:
    Call ErrorHandler("ExecuteSQLSafe")
End Function


' Standard error handler
Private Sub ErrorHandler(ByVal as_Fct As String)
    Err.Raise Err.Number, as_Fct & SEP1 & Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Sub

Private Sub CustCode_Search()
'P516 SAP needs cust_code
Dim ls_CCUCapKey As String
Dim lo_SearchForm As SeekForm
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CustCodeSearch"
    #End If
    
    ls_CCUCapKey = ""
    
    Set lo_SearchForm = New SeekForm
    Load lo_SearchForm
    
    If mb_use_framework_connection = True Then Set lo_SearchForm.ArmDb = mo_ArmDb
    lo_SearchForm.ConnectString = ms_ConnectString
    lo_SearchForm.Language = m_Language
    lo_SearchForm.ComponentType = "CUSTOMER"
    
    If (opt_date(1).Value = True) And (Not cbo_date.SelectedItem Is Nothing) Then
        lo_SearchForm.TreeView_DateType = CStr(cbo_date.SelectedItem.Key)
    Else
        lo_SearchForm.TreeView_DateType = "0"
    End If

    lo_SearchForm.TreeViewFiltersDesc = GetCurrentFiltersDescription()
    lo_SearchForm.TreeViewFilters = GetCurrentFilters()
    
    lo_SearchForm.Load_A_COM
    lo_SearchForm.SYS_code = 1
    
    CapMouseOn True
    
    lo_SearchForm.show 1
    CapMouseOff True
    
    If lo_SearchForm.SelectedData = True Then
        GetCustCode (lo_SearchForm.SelectedItemCode)
    End If
    
    lo_SearchForm.Unload_A_COM
    
    Unload lo_SearchForm
    Set lo_SearchForm = Nothing
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CustCodeSearch"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CustCodeSearch"
    If Not lo_SearchForm Is Nothing Then
        lo_SearchForm.Unload_A_COM
        Unload lo_SearchForm
        Set lo_SearchForm = Nothing
    End If
    CapMouseOn
End Sub

Private Sub GetCustCode(ByVal as_CapKey As String)
'P516 SAP needs cust_code
Dim TheRequest As String
Dim ll_Cursor As Long
Dim ls_Buffer As Variant

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:ViewInitFields"
    #End If
    
    If as_CapKey = "" Then GoTo Trace_End
    
    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
        
    TheRequest = "exec claim_customer_sel3 '" & as_CapKey & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:ViewInitFields", "Request=" & TheRequest
        GoTo Trace_End
    End If

    txt_SapCode.Text = mo_ArmDb.GetFields(ll_Cursor, "Cust_Code")

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ViewInitFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ViewInitFields"
    CapMouseOn
End Sub

Private Sub IsAccountHolder(ByVal al_CTA As Long)
Dim ll_Cursor As Long
Dim ls_req As String

On Error GoTo Trace_Err
CapMouseOff
#If CapDebug Then
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:IsAccountHolder"
#End If
    
If al_CTA = 0 Then GoTo Trace_End

'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
ls_req = "exec Cap_CustomerAttribute_chk2 " & al_CTA
ll_Cursor = mo_ArmDb.OpenSQL(ls_req, -1, 0)
If ll_Cursor = 0 Then
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapCus:ViewInitFields", "Request=" & ls_req
    GoTo Trace_End
Else
    If mo_ArmDb.RowCount(ll_Cursor) > 0 Then
        mb_AccountHolder = True
    End If
End If
  
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:ViewInitFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:ViewInitFields"
    CapMouseOn
End Sub

Private Sub InitBtnSearch()
Dim ll_Count, ll_Idx As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capcus:CkvAttribute_ItemCheck"
    #End If

    mb_AccountHolder = False
    btn_Search.Enabled = False

    If CkvAttribute.CheckedCount > 0 Then
        For ll_Count = 1 To CkvAttribute.Count
            If CkvAttribute.ListItems(ll_Count).Checked Then
                'Check if 'Account holder'; if yes ==> stop loop
                Call IsAccountHolder(CkvAttribute.ListItems(ll_Count).Tag.Id)
                
'                For ll_Idx = 0 To CkvAttribute.Count - 1
'                    If (CkvAttribute.ItemInfo(ll_Idx).Caption) = CkvAttribute.ListItems(ll_Count + 1).Text Then
'                        IsAccountHolder (CkvAttribute.ItemInfo(ll_Idx).Id)
'                        Exit For
'                    End If
'                Next

                If mb_AccountHolder Then Exit For
            End If
        Next
    End If
    
    If mb_AccountHolder Then
        btn_Search.Enabled = True
        mb_AccountHolder = True
    Else
        txt_SapCode.Text = ""
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capcus:CkvAttribute_ItemCheck"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcus:CkvAttribute_ItemCheck"
    CapMouseOn
End Sub

