VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl CapPrj 
   Appearance      =   0  'Flat
   ClientHeight    =   12630
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   17700
   ScaleHeight     =   12630
   ScaleWidth      =   17700
   Tag             =   "#Date range"
   ToolboxBitmap   =   "Capprj.ctx":0000
   Begin VB.Frame frm_JP_Experimental 
      Caption         =   "JP experimental"
      Height          =   825
      Left            =   10560
      TabIndex        =   133
      Top             =   945
      Visible         =   0   'False
      Width           =   1440
      Begin VB.CommandButton cmd_JP_experimental 
         Caption         =   "Create export"
         Height          =   420
         Left            =   180
         TabIndex        =   134
         Top             =   285
         Width           =   1170
      End
   End
   Begin Project1.CapSOMQuoteValOf uc_SOMQuoteValOf 
      Height          =   885
      Left            =   12645
      TabIndex        =   125
      Top             =   10575
      Visible         =   0   'False
      Width           =   2670
      _ExtentX        =   4710
      _ExtentY        =   1561
   End
   Begin VB.Frame fraItem 
      Height          =   10335
      Left            =   4560
      TabIndex        =   35
      Top             =   2040
      Width           =   10815
      Begin VB.Frame fraItemBottom 
         Height          =   2600
         Left            =   240
         TabIndex        =   54
         Top             =   7260
         Width           =   10335
         Begin VB.TextBox txt_Top10EComment 
            Height          =   1560
            Left            =   135
            MaxLength       =   2000
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   131
            Tag             =   "txt_Top10EComment"
            Top             =   495
            Width           =   5235
         End
         Begin Project1.ArmCheckView acv_Rep 
            Height          =   1575
            Left            =   5415
            TabIndex        =   23
            Tag             =   "acv_Rep"
            Top             =   495
            Width           =   4815
            _ExtentX        =   8493
            _ExtentY        =   2778
         End
         Begin VB.TextBox txt_createdBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   3840
            Locked          =   -1  'True
            TabIndex        =   84
            Tag             =   "z_creator"
            Text            =   "txt_createdBy"
            Top             =   2160
            Width           =   1515
         End
         Begin VB.TextBox txt_updatedBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   8700
            Locked          =   -1  'True
            TabIndex        =   31
            Tag             =   "txt_updatedBy"
            Top             =   2160
            Width           =   1515
         End
         Begin VB.TextBox txt_dateEntered 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   315
            Left            =   1620
            TabIndex        =   30
            Tag             =   "txt_dateEntered"
            Text            =   "28/2/2001"
            Top             =   2160
            Width           =   1515
         End
         Begin VB.TextBox txt_lastUpdated 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   315
            Left            =   6840
            TabIndex        =   32
            Tag             =   "txt_lastUpdated"
            Text            =   "28/2/2001"
            Top             =   2160
            Width           =   1100
         End
         Begin VB.TextBox txt_comment 
            Height          =   1560
            Left            =   135
            MaxLength       =   2000
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   22
            Tag             =   "txt_comment"
            Top             =   495
            Width           =   5235
         End
         Begin MSComctlLib.TabStrip tbsComment 
            Height          =   375
            Left            =   135
            TabIndex        =   130
            Top             =   150
            Width           =   5250
            _ExtentX        =   9260
            _ExtentY        =   661
            _Version        =   393216
            BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
               NumTabs         =   2
               BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Comment"
                  Key             =   "tab_Comment"
                  Object.Tag             =   "tab_Comment"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Top 10 Executive Comment"
                  Key             =   "tab_Top10EComment"
                  Object.Tag             =   "tab_Top10EComment"
                  ImageVarType    =   2
               EndProperty
            EndProperty
         End
         Begin VB.Label lbl_comment 
            Caption         =   "#Comment"
            Height          =   255
            Left            =   165
            TabIndex        =   55
            Tag             =   "lbl_comment"
            Top             =   195
            Width           =   885
         End
         Begin VB.Label lbl_role 
            Caption         =   "#Role"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   7455
            TabIndex        =   88
            Tag             =   "lbl_role"
            Top             =   180
            Visible         =   0   'False
            Width           =   1395
         End
         Begin VB.Label lbl_updatedBy 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Left            =   8160
            TabIndex        =   86
            Tag             =   "lbl_updatedby"
            Top             =   2220
            Width           =   615
         End
         Begin VB.Label lbl_createdBy 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Left            =   3240
            TabIndex        =   85
            Tag             =   "lbl_createdBY"
            Top             =   2220
            Width           =   555
         End
         Begin VB.Label lbl_dateEntered 
            Caption         =   "#Date Entered"
            Enabled         =   0   'False
            Height          =   255
            Left            =   105
            TabIndex        =   81
            Tag             =   "lbl_dateEntered"
            Top             =   2220
            Width           =   1455
         End
         Begin VB.Label lbl_lastUpdated 
            Caption         =   "#Last Updated"
            Enabled         =   0   'False
            Height          =   255
            Left            =   5400
            TabIndex        =   80
            Tag             =   "lbl_lastUpdated"
            Top             =   2220
            Width           =   1515
         End
         Begin VB.Label lbl_salesReps 
            Caption         =   "#Sales Reps"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5415
            TabIndex        =   56
            Tag             =   "lbl_salesrep"
            Top             =   180
            Width           =   1575
         End
      End
      Begin Project1.ToolBr pbitem 
         Height          =   825
         Left            =   360
         TabIndex        =   70
         Top             =   240
         Width           =   2295
         _ExtentX        =   4048
         _ExtentY        =   1455
      End
      Begin MSComctlLib.TabStrip tbsEmbedded 
         Height          =   375
         Left            =   1500
         TabIndex        =   24
         Top             =   9780
         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
      Begin VB.Frame fraItemTop 
         Height          =   6105
         Left            =   240
         TabIndex        =   36
         Top             =   1170
         Width           =   10335
         Begin VB.TextBox txt_External_Id 
            Height          =   330
            Left            =   5550
            MaxLength       =   40
            TabIndex        =   117
            Tag             =   "txt_External_Id"
            Top             =   5370
            Width           =   4635
         End
         Begin VB.CheckBox chk_Top10E 
            Caption         =   "#Top 10 Executive"
            Height          =   250
            Left            =   2100
            TabIndex        =   129
            Tag             =   "chk_Top10E"
            Top             =   3480
            Width           =   3030
         End
         Begin VB.CommandButton btn_statHist 
            Caption         =   ".."
            Height          =   270
            Left            =   6855
            TabIndex        =   128
            Tag             =   "btn_statHist"
            ToolTipText     =   "#Show status history"
            Top             =   3172
            Width           =   285
         End
         Begin Project1.ArmGrid grd_searchZip 
            Height          =   3510
            Left            =   1305
            TabIndex        =   127
            Top             =   555
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   6191
         End
         Begin VB.CommandButton btn_pickZip 
            Caption         =   ".."
            Height          =   270
            Left            =   1800
            TabIndex        =   126
            Tag             =   "btn_pickZip"
            ToolTipText     =   "#Select zip according sales rep"
            Top             =   2085
            Width           =   285
         End
         Begin VB.TextBox txt_spare6 
            Height          =   330
            Left            =   2430
            TabIndex        =   124
            Top             =   5835
            Visible         =   0   'False
            Width           =   735
         End
         Begin VB.TextBox txt_spare5 
            Height          =   330
            Left            =   2580
            TabIndex        =   123
            Top             =   5850
            Visible         =   0   'False
            Width           =   735
         End
         Begin VB.OptionButton opt_as 
            Caption         =   "#AS"
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   250
            Left            =   1485
            TabIndex        =   122
            Tag             =   "opt_AS"
            Top             =   660
            Width           =   1260
         End
         Begin VB.CheckBox chk_AMCProjectType 
            Alignment       =   1  'Right Justify
            BackColor       =   &H80000000&
            Height          =   315
            Left            =   5685
            TabIndex        =   120
            Tag             =   "lbl_AMCProjectType"
            Top             =   4710
            Value           =   1  'Checked
            Width           =   225
         End
         Begin Project1.A_calocx cal_orderExpDate 
            Height          =   315
            Left            =   5550
            TabIndex        =   108
            Top             =   5025
            Visible         =   0   'False
            Width           =   1800
            _ExtentX        =   3175
            _ExtentY        =   556
         End
         Begin VB.TextBox txt_AMCProjectNo 
            Height          =   330
            Left            =   8565
            Locked          =   -1  'True
            MaxLength       =   15
            TabIndex        =   119
            Tag             =   "txt_AMCProjectNo"
            Text            =   "WWWW"
            Top             =   4665
            Width           =   1620
         End
         Begin VB.TextBox txt_I5No 
            Height          =   330
            Left            =   8565
            MaxLength       =   20
            TabIndex        =   116
            Tag             =   "txt_I5No"
            Top             =   5385
            Width           =   1620
         End
         Begin VB.TextBox txt_duration 
            Height          =   330
            Left            =   5550
            MaxLength       =   3
            TabIndex        =   111
            Tag             =   "txt_duration"
            Top             =   5385
            Visible         =   0   'False
            Width           =   570
         End
         Begin VB.CheckBox chk_sysSol 
            Alignment       =   1  'Right Justify
            Caption         =   "#System Solution"
            Height          =   285
            Left            =   1680
            TabIndex        =   95
            Tag             =   "lbl_spare2"
            Top             =   240
            Width           =   2235
         End
         Begin VB.CheckBox chk_UpdateTV 
            Caption         =   "Search item in the list after update"
            Height          =   375
            Left            =   11440
            TabIndex        =   92
            Tag             =   "chk_UpdateTV"
            Top             =   360
            Value           =   1  'Checked
            Width           =   3135
         End
         Begin VB.TextBox txt_PrjKey 
            Enabled         =   0   'False
            Height          =   330
            Left            =   7800
            Locked          =   -1  'True
            TabIndex        =   87
            Tag             =   "txt_PrjKey"
            Top             =   210
            Width           =   2415
         End
         Begin Project1.ArmCombobox cbo_UOM 
            Height          =   345
            Left            =   3495
            TabIndex        =   15
            Tag             =   "cbo_UOM"
            Top             =   4080
            Width           =   1620
            _ExtentX        =   2858
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_currencies 
            Height          =   345
            Left            =   8595
            TabIndex        =   17
            Tag             =   "cbo_currencies"
            Top             =   3510
            Width           =   1620
            _ExtentX        =   2858
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_status 
            Height          =   345
            Left            =   7200
            TabIndex        =   12
            Tag             =   "cbo_status"
            Top             =   3135
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_projectDesc 
            Height          =   345
            Left            =   7200
            TabIndex        =   10
            Tag             =   "cbo_projectDesc"
            Top             =   2775
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_country 
            Height          =   345
            Left            =   2100
            TabIndex        =   7
            Tag             =   "cbo_country"
            Top             =   2415
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_county 
            Height          =   345
            Left            =   7200
            TabIndex        =   8
            Tag             =   "cbo_county"
            Top             =   2415
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_newRenovation 
            Height          =   345
            Left            =   2100
            TabIndex        =   13
            Tag             =   "cbo_newRenovation"
            Top             =   3720
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_priority 
            Height          =   345
            Left            =   2100
            TabIndex        =   11
            Tag             =   "cbo_priority"
            Top             =   3135
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_projectType 
            Height          =   345
            Left            =   2100
            TabIndex        =   9
            Tag             =   "cbo_projectType"
            Top             =   2775
            Width           =   3015
            _ExtentX        =   5318
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_SA 
            Height          =   345
            Left            =   4620
            TabIndex        =   27
            Tag             =   "cbo_SA"
            Top             =   600
            Width           =   2040
            _ExtentX        =   3598
            _ExtentY        =   609
         End
         Begin VB.OptionButton opt_sa 
            Caption         =   "#Strat. account"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   250
            Left            =   2790
            TabIndex        =   78
            Tag             =   "opt_SA"
            Top             =   660
            Width           =   1815
         End
         Begin VB.OptionButton opt_std 
            Caption         =   "#Std"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   250
            Left            =   120
            TabIndex        =   0
            Tag             =   "opt_Std"
            Top             =   660
            Width           =   1260
         End
         Begin VB.TextBox txt_spare4 
            Height          =   330
            Left            =   2520
            TabIndex        =   59
            Top             =   5805
            Visible         =   0   'False
            Width           =   735
         End
         Begin VB.TextBox txt_spare3 
            Height          =   330
            Left            =   2625
            TabIndex        =   58
            Top             =   5850
            Visible         =   0   'False
            Width           =   600
         End
         Begin VB.TextBox txt_spare1 
            Height          =   330
            Left            =   2730
            TabIndex        =   57
            Top             =   5775
            Visible         =   0   'False
            Width           =   660
         End
         Begin VB.TextBox txt_zip2 
            BackColor       =   &H00FFFFFF&
            Height          =   330
            Left            =   3490
            MaxLength       =   10
            TabIndex        =   5
            Tag             =   "txt_zip2"
            Top             =   2055
            Width           =   1620
         End
         Begin VB.TextBox txt_zip1 
            BackColor       =   &H00FFFFFF&
            Height          =   330
            Left            =   2100
            MaxLength       =   10
            TabIndex        =   4
            Tag             =   "txt_zip1"
            Top             =   2055
            Width           =   1400
         End
         Begin VB.TextBox txt_address1 
            Height          =   330
            Left            =   2100
            MaxLength       =   80
            TabIndex        =   2
            Tag             =   "txt_address1"
            Top             =   1335
            Width           =   8100
         End
         Begin VB.TextBox txt_town 
            Height          =   330
            Left            =   7200
            MaxLength       =   80
            TabIndex        =   6
            Tag             =   "txt_town"
            Top             =   2055
            Width           =   3015
         End
         Begin VB.TextBox txt_desc 
            Height          =   330
            Left            =   2100
            MaxLength       =   80
            TabIndex        =   1
            Tag             =   "txt_desc"
            Top             =   975
            Width           =   8100
         End
         Begin VB.TextBox txt_projectValue 
            Height          =   330
            Left            =   7200
            TabIndex        =   16
            Tag             =   "txt_projectValue"
            Top             =   3510
            Width           =   1400
         End
         Begin VB.TextBox txt_ClgSpecif 
            Height          =   330
            Left            =   2100
            TabIndex        =   18
            Top             =   4485
            Width           =   1400
         End
         Begin VB.TextBox txt_size 
            Height          =   330
            Left            =   2100
            TabIndex        =   14
            Tag             =   "txt_size"
            Top             =   4080
            Width           =   1400
         End
         Begin Project1.A_calocx cal_startDate 
            Height          =   315
            Left            =   2100
            TabIndex        =   19
            Top             =   4815
            Width           =   1800
            _ExtentX        =   3175
            _ExtentY        =   556
         End
         Begin Project1.A_calocx cal_clgStartDate 
            Height          =   315
            Left            =   2100
            TabIndex        =   20
            Top             =   5115
            Width           =   1800
            _ExtentX        =   3175
            _ExtentY        =   556
         End
         Begin Project1.A_calocx cal_followUpDate 
            Height          =   315
            Left            =   2100
            TabIndex        =   21
            Top             =   5415
            Width           =   1800
            _ExtentX        =   3175
            _ExtentY        =   556
         End
         Begin VB.TextBox txt_address2 
            Height          =   330
            Left            =   2100
            MaxLength       =   80
            TabIndex        =   3
            Tag             =   "txt_address2"
            Top             =   1695
            Width           =   8100
         End
         Begin Project1.ArmCombobox cbo_level 
            Height          =   345
            Left            =   9390
            TabIndex        =   101
            Tag             =   "cbo_level"
            Top             =   3870
            Width           =   825
            _ExtentX        =   1455
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_SAType 
            Height          =   345
            Left            =   8040
            TabIndex        =   104
            Tag             =   "cbo_SAType"
            Top             =   600
            Width           =   2160
            _ExtentX        =   3810
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_SS 
            Height          =   345
            Left            =   4020
            TabIndex        =   105
            Tag             =   "cbo_SS"
            Top             =   210
            Width           =   2040
            _ExtentX        =   3598
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_probability 
            Height          =   345
            Left            =   5430
            TabIndex        =   107
            Tag             =   "cbo_probability"
            Top             =   4365
            Width           =   855
            _ExtentX        =   1508
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_ceilFncType 
            Height          =   345
            Left            =   8820
            TabIndex        =   114
            Tag             =   "cbo_ceilFncType"
            Top             =   5025
            Width           =   1365
            _ExtentX        =   2408
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_datasource 
            Height          =   345
            Left            =   7905
            TabIndex        =   135
            Tag             =   "cbo_datasource"
            Top             =   4275
            Width           =   2310
            _ExtentX        =   4075
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_clgValue 
            Height          =   345
            Left            =   7200
            TabIndex        =   137
            Tag             =   "cbo_clgValue"
            Top             =   3870
            Width           =   1400
            _ExtentX        =   2461
            _ExtentY        =   609
         End
         Begin VB.Label lbl_External_Id 
            Caption         =   "#External ID"
            Height          =   195
            Left            =   4005
            TabIndex        =   138
            Tag             =   "lbl_External_Id"
            Top             =   5460
            Width           =   1560
         End
         Begin VB.Label lbl_datasource 
            Alignment       =   1  'Right Justify
            Caption         =   "#Data source"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   6375
            TabIndex        =   136
            Tag             =   "lbl_datasource"
            Top             =   4365
            Width           =   1425
         End
         Begin VB.Label lbl_AMCProjectType 
            Caption         =   "#AMC project type"
            Height          =   195
            Left            =   3990
            TabIndex        =   121
            Tag             =   "lbl_AMCProjectType"
            Top             =   4815
            Width           =   1680
         End
         Begin VB.Label lbl_AMCProjectNo 
            Alignment       =   1  'Right Justify
            Caption         =   "#AMC project no"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   6870
            TabIndex        =   118
            Tag             =   "lbl_AMCProjectNo"
            Top             =   4755
            Width           =   1605
         End
         Begin VB.Label lbl_I5No 
            Caption         =   "#I5 object no"
            Height          =   195
            Left            =   7440
            TabIndex        =   115
            Tag             =   "lbl_I5No"
            Top             =   5490
            Width           =   1170
         End
         Begin VB.Label lbl_ceilFncType 
            Caption         =   "#Ceil. fnc type"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   7440
            TabIndex        =   113
            Tag             =   "lbl_ceilFncType"
            Top             =   5100
            Width           =   1365
         End
         Begin VB.Label lbl_inWeeks 
            Caption         =   "#in weeks"
            Height          =   195
            Left            =   6195
            TabIndex        =   112
            Tag             =   "lbl_inWeeks"
            Top             =   5475
            Visible         =   0   'False
            Width           =   990
         End
         Begin VB.Label lbl_prjDuration 
            Caption         =   "#Project duration"
            Height          =   195
            Left            =   4005
            TabIndex        =   110
            Tag             =   "lbl_prjDuration"
            Top             =   5490
            Visible         =   0   'False
            Width           =   1560
         End
         Begin VB.Label lbl_orderExpiry 
            Caption         =   "#Ord. expiry date"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   3990
            TabIndex        =   109
            Tag             =   "lbl_orderExpiry"
            Top             =   5130
            Visible         =   0   'False
            Width           =   1560
         End
         Begin VB.Label lbl_probability 
            Caption         =   "#Probability"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   3960
            TabIndex        =   106
            Tag             =   "lbl_probability"
            Top             =   4470
            Width           =   1350
         End
         Begin VB.Label lbl_SAType 
            Caption         =   "#S.A.Type"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   6765
            TabIndex        =   103
            Tag             =   "lbl_SAType"
            Top             =   660
            Width           =   1290
         End
         Begin VB.Label lbl_level 
            Alignment       =   1  'Right Justify
            Caption         =   "#Level"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   8160
            TabIndex        =   102
            Tag             =   "lbl_level"
            Top             =   3945
            Width           =   1110
         End
         Begin VB.Label lbl_PrjKey 
            Caption         =   "#Project Key"
            Enabled         =   0   'False
            Height          =   255
            Left            =   6480
            TabIndex        =   29
            Tag             =   "lbl_PrjKey"
            Top             =   270
            Width           =   1215
         End
         Begin VB.Label lbl_ceilingvalue 
            Caption         =   "#Ceiling value"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   5220
            TabIndex        =   79
            Tag             =   "lbl_ceilingvalue"
            Top             =   3945
            Width           =   1920
         End
         Begin VB.Label lbl_followUpDate 
            Caption         =   "#Follow Up"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   39
            Tag             =   "lbl_followUpDate"
            Top             =   5520
            Width           =   1920
         End
         Begin VB.Label lbl_spare4 
            Caption         =   "#lbl_spare4"
            Height          =   195
            Left            =   1350
            TabIndex        =   62
            Tag             =   "lbl_spare4"
            Top             =   5790
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare3 
            Caption         =   "#lbl_spare3"
            Height          =   195
            Left            =   -360
            TabIndex        =   61
            Tag             =   "lbl_spare3"
            Top             =   6120
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare1 
            Caption         =   "#lbl_spare1"
            Height          =   195
            Left            =   1215
            TabIndex        =   60
            Tag             =   "lbl_spare1"
            Top             =   5775
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_country 
            Caption         =   "#Country"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   53
            Tag             =   "lbl_country"
            Top             =   2475
            Width           =   1920
         End
         Begin VB.Label lbl_town 
            Caption         =   "#Town"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   5220
            TabIndex        =   52
            Tag             =   "lbl_town"
            Top             =   2115
            Width           =   1920
         End
         Begin VB.Label lbl_address 
            Caption         =   "#Address"
            Height          =   195
            Left            =   120
            TabIndex        =   51
            Tag             =   "lbl_address"
            Top             =   1395
            Width           =   1920
         End
         Begin VB.Label lbl_desc 
            Caption         =   "#Name"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   50
            Tag             =   "lbl_desc"
            Top             =   1035
            Width           =   1920
         End
         Begin VB.Label lbl_zip 
            Caption         =   "#Zip code"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   120
            TabIndex        =   49
            Tag             =   "lbl_zip"
            Top             =   2115
            Width           =   1650
         End
         Begin VB.Label lbl_county 
            Caption         =   "#County"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5220
            TabIndex        =   48
            Tag             =   "lbl_county"
            Top             =   2475
            Width           =   1920
         End
         Begin VB.Label lbl_projectDesc 
            Caption         =   "#Project Description"
            Height          =   255
            Left            =   5220
            TabIndex        =   47
            Tag             =   "lbl_projectDesc"
            Top             =   2865
            Width           =   1920
         End
         Begin VB.Label lbl_priority 
            Caption         =   "#Priority"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   46
            Tag             =   "lbl_priority"
            Top             =   3195
            Width           =   1920
         End
         Begin VB.Label lbl_newRenovation 
            Caption         =   "#New or Renovation"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   45
            Tag             =   "lbl_newRenovation"
            Top             =   3780
            Width           =   1920
         End
         Begin VB.Label lbl_status 
            Caption         =   "#Status"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5220
            TabIndex        =   44
            Tag             =   "lbl_status"
            Top             =   3225
            Width           =   1620
         End
         Begin VB.Label lbl_projectType 
            Caption         =   "#Project Type"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   43
            Tag             =   "lbl_projectType"
            Top             =   2835
            Width           =   1920
         End
         Begin VB.Label lbl_ProjectValue 
            Caption         =   "#Project Value"
            Height          =   255
            Left            =   5220
            TabIndex        =   42
            Tag             =   "lbl_projectValue"
            Top             =   3585
            Width           =   1920
         End
         Begin VB.Label lbl_ClgSpecif 
            Caption         =   "#Ceiling specified"
            Height          =   255
            Left            =   120
            TabIndex        =   41
            Tag             =   "lbl_clgSpecif"
            Top             =   4545
            Width           =   1920
         End
         Begin VB.Label lbl_size 
            Caption         =   "#Project size"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   40
            Tag             =   "lbl_size"
            Top             =   4140
            Width           =   1920
         End
         Begin VB.Label lbl_clgStartDate 
            Caption         =   "#First Delivery date"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   38
            Tag             =   "lbl_clgStartDate"
            Top             =   5175
            Width           =   1920
         End
         Begin VB.Label lbl_startDate 
            Caption         =   "#First Order date"
            Height          =   195
            Left            =   120
            TabIndex        =   37
            Tag             =   "lbl_startDate"
            Top             =   4875
            Width           =   1920
         End
      End
   End
   Begin VB.Frame fraFilters 
      Height          =   9105
      Left            =   120
      TabIndex        =   25
      Top             =   240
      Width           =   4206
      Begin VB.CheckBox chk_isInitTV 
         Height          =   285
         Left            =   3870
         TabIndex        =   132
         Tag             =   "chk_isInitTV"
         ToolTipText     =   "#Initial treeview"
         Top             =   3315
         Width           =   225
      End
      Begin VB.Frame fra_SolSys 
         BorderStyle     =   0  'None
         Caption         =   "Frame1"
         Height          =   465
         Left            =   30
         TabIndex        =   97
         Top             =   1260
         Width           =   4100
         Begin MSForms.OptionButton opt_SysSol 
            Height          =   285
            Index           =   2
            Left            =   2490
            TabIndex        =   100
            Tag             =   "Opt_SysSol_N"
            Top             =   90
            Width           =   1575
            BackColor       =   -2147483633
            ForeColor       =   -2147483630
            DisplayStyle    =   5
            Size            =   "2778;503"
            Value           =   "0"
            Caption         =   "#Non Sys Sol"
            FontHeight      =   165
            FontCharSet     =   0
            FontPitchAndFamily=   2
         End
         Begin MSForms.OptionButton opt_SysSol 
            Height          =   285
            Index           =   1
            Left            =   1230
            TabIndex        =   99
            Tag             =   "Opt_SysSol_Y"
            Top             =   90
            Width           =   1155
            BackColor       =   -2147483633
            ForeColor       =   -2147483630
            DisplayStyle    =   5
            Size            =   "2037;503"
            Value           =   "0"
            Caption         =   "#Sys Sol"
            FontHeight      =   165
            FontCharSet     =   0
            FontPitchAndFamily=   2
         End
         Begin MSForms.OptionButton opt_SysSol 
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   98
            Tag             =   "Opt_SysSol_All"
            Top             =   90
            Width           =   855
            BackColor       =   -2147483633
            ForeColor       =   -2147483630
            DisplayStyle    =   5
            Size            =   "1508;450"
            Value           =   "1"
            Caption         =   "#All"
            FontHeight      =   165
            FontCharSet     =   0
            FontPitchAndFamily=   2
         End
      End
      Begin VB.PictureBox pctTvReset 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         FillColor       =   &H8000000F&
         ForeColor       =   &H80000008&
         Height          =   240
         Left            =   0
         Picture         =   "Capprj.ctx":0312
         ScaleHeight     =   16
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   16
         TabIndex        =   91
         Top             =   100
         Width           =   240
      End
      Begin Project1.ArmCombobox cbo_view 
         Height          =   345
         Left            =   600
         TabIndex        =   73
         Top             =   3240
         Width           =   3180
         _ExtentX        =   5609
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_date 
         Height          =   345
         Left            =   120
         TabIndex        =   83
         Top             =   2790
         Visible         =   0   'False
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   609
      End
      Begin VB.PictureBox reload_treeview 
         Appearance      =   0  'Flat
         BackColor       =   &H80000000&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   540
         Left            =   60
         ScaleHeight     =   405
         ScaleMode       =   0  'User
         ScaleWidth      =   570
         TabIndex        =   76
         Top             =   3675
         Width           =   570
      End
      Begin Project1.ArmTreeView tvitems 
         Height          =   2550
         Left            =   60
         TabIndex        =   74
         Tag             =   "tvitems"
         Top             =   3675
         Width           =   2610
         _ExtentX        =   4604
         _ExtentY        =   4498
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#Between"
         Height          =   255
         Index           =   1
         Left            =   1860
         TabIndex        =   72
         Tag             =   "dateBetween"
         Top             =   2010
         Width           =   2200
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#All"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   67
         Tag             =   "dateAll"
         Top             =   2010
         Value           =   -1  'True
         Width           =   1750
      End
      Begin VB.Frame fra_active 
         BorderStyle     =   0  'None
         Caption         =   "Frame1"
         Height          =   465
         Left            =   120
         TabIndex        =   63
         Top             =   600
         Width           =   4100
         Begin VB.OptionButton opt_active 
            Caption         =   "#Reference"
            Height          =   255
            Index           =   3
            Left            =   2865
            TabIndex        =   68
            Tag             =   "Reference"
            Top             =   120
            Width           =   1150
         End
         Begin VB.OptionButton opt_active 
            Caption         =   "#All"
            Height          =   255
            Index           =   0
            Left            =   60
            TabIndex        =   66
            Tag             =   "All"
            Top             =   120
            Value           =   -1  'True
            Width           =   800
         End
         Begin VB.OptionButton opt_active 
            Caption         =   "#Active"
            Height          =   255
            Index           =   1
            Left            =   840
            TabIndex        =   65
            Tag             =   "Active"
            Top             =   120
            Width           =   950
         End
         Begin VB.OptionButton opt_active 
            Caption         =   "#Archived"
            Height          =   255
            Index           =   2
            Left            =   1770
            TabIndex        =   64
            Tag             =   "Archived"
            Top             =   120
            Width           =   1050
         End
      End
      Begin Project1.A_calocx cal12 
         Height          =   330
         Left            =   2280
         TabIndex        =   26
         Top             =   2325
         Visible         =   0   'False
         Width           =   1830
         _ExtentX        =   3228
         _ExtentY        =   582
      End
      Begin Project1.A_calocx cal11 
         Height          =   330
         Left            =   120
         TabIndex        =   69
         Top             =   2325
         Visible         =   0   'False
         Width           =   1830
         _ExtentX        =   3228
         _ExtentY        =   582
      End
      Begin MSComctlLib.TabStrip tbsFilters 
         Height          =   375
         Left            =   90
         TabIndex        =   77
         Top             =   8235
         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 VB.Label lbl_SysSol 
         Caption         =   "#System solution"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   238
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   96
         Tag             =   "fra_SolSys"
         Top             =   1050
         Width           =   1935
      End
      Begin VB.Label lbl_DateRange 
         Caption         =   "#Date range"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   238
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   89
         Tag             =   "lbl_DateRange"
         Top             =   1710
         Width           =   1215
      End
      Begin VB.Label lbl_ProjectStatus 
         Caption         =   "#Project status"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   238
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   90
         Tag             =   "lbl_ProjectStatus"
         Top             =   420
         Width           =   1935
      End
      Begin VB.Label lbl_view 
         Caption         =   "#View"
         Height          =   195
         Left            =   120
         TabIndex        =   33
         Tag             =   "lbl_view"
         Top             =   3330
         Width           =   495
      End
   End
   Begin Project1.CapCustOf CustOf 
      Height          =   7695
      Left            =   2280
      TabIndex        =   94
      Top             =   10320
      Visible         =   0   'False
      Width           =   10215
      _ExtentX        =   18018
      _ExtentY        =   13573
   End
   Begin Project1.CapPrdValOf PrdValOf 
      Height          =   7455
      Left            =   0
      TabIndex        =   93
      Top             =   6360
      Visible         =   0   'False
      Width           =   7695
      _ExtentX        =   13573
      _ExtentY        =   13150
   End
   Begin VB.Frame fraList 
      Height          =   4335
      Left            =   5040
      TabIndex        =   34
      Top             =   840
      Width           =   5475
      Begin Project1.ArmGrid grdlst 
         Height          =   1935
         Left            =   240
         TabIndex        =   82
         Top             =   1440
         Width           =   4935
         _ExtentX        =   8705
         _ExtentY        =   3413
      End
      Begin VB.PictureBox fill_all_record 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   600
         Left            =   3555
         ScaleHeight     =   600
         ScaleWidth      =   600
         TabIndex        =   75
         Top             =   240
         Visible         =   0   'False
         Width           =   600
      End
      Begin Project1.ToolBr pblst 
         Height          =   675
         Left            =   360
         TabIndex        =   71
         Top             =   240
         Width           =   1935
         _ExtentX        =   3413
         _ExtentY        =   1191
      End
      Begin VB.Label lbl_ListFilter 
         Alignment       =   2  'Center
         BackColor       =   &H0000FFFF&
         Caption         =   "#All "
         Height          =   375
         Left            =   240
         TabIndex        =   28
         Tag             =   "lbl_ListFilter"
         Top             =   960
         Width           =   4935
      End
   End
End
Attribute VB_Name = "CapPrj"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'what is new
'2.6.4 : Added AMC project number into list of projects (JN)
'2.6.9 : Is Init treeview filter marked with checkbox (JN)
'2.6.9 : fixes with decimal point and exponential format of the value in project size and project value fieds (JN)
'2.7.7 : Updated description for checkinkg possibility to delete project (JN)
'2.8.1 : intems into export support (JN)

' SOM_Project copy - begin
Private Const LOCALE_USER_DEFAULT = &H400
Private ms_DecimalSeparator  As String
Private ms_ThousandSeparator As String
Private Declare Function GetLocaleInfo Lib "Kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long

'Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

Private Const LOCALE_SDECIMAL = &HE ' Decimal separator
Private Const LOCALE_STHOUSAND = &HF ' Thousand separator
' SOM_Project copy - end

Private Type UserRights_t
    Executive As Boolean
    CapOfferView As Boolean
End Type

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
    QuietException = vbObjectError + 12          ' do not display error message
    SQLTableReferenceConstraint = vbObjectError + 13 ' A SQL request cannot be executed : Table reference constraint
    DuplicityDetected = vbObjectError + 2301     ' detected row with same unique id
End Enum

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

'******** 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 mt_DefaultValues As Object      ' Structure which contains default values
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
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_SPA As String 'For the property .Project, display in ShortList
Private m_Product As String 'For the property .Project, display in ShortList
Private m_Contact As String 'For the property .Contact, display in ShortList
Private m_Customer As String 'For the property .Customer, display in ShortList
Private m_Action As String 'For the property .Action, display in ShortList
Private m_Memo As String 'For the property .Product, display in ShortList
Private mb_EmbeddedIsDropped As Boolean '298.2
Private mb_gridInitializedForFollowUP As Boolean    ' indicate grid is initialized after start of control

Private mb_UseRepsFilter As Boolean

' 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()

Public Event CreateOffer(ByVal al_EmbeddedIn As Long, ByVal al_OfferType As Long, ByVal as_SPR_Id As String, ByVal as_SPR_Name As String)


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

Private p_OldCodeStatus As String
Private ml_OriginalStatusCode As Long
Private mb_OriginalAMCExists As Boolean
Private ms_CreationDate As String
Private ms_lastBeforeAS As String       ' indicate what was selected type project before user click on AS optionbutton
Private ml_SOM_QUOTE_COUNT As Long      ' number of quotes on the project
Private mb_quoteValOfInitialized As Boolean

Public mb_CycleReset As Boolean

Private mb_StatusNotCheck As Boolean

Private ms_OldZip1 As String
Private ms_OldZip2 As String
Private mb_ZipCorrect As Boolean        ' Zip is correct or not
Private ms_OldCodeCountry As String

Private mb_HaveSolSys As Boolean        ' enable/disable solution system for user
' task 299.2 begin
Private mb_HaveLevel As Boolean         ' enable/disable Level combobox for user
Private mb_HaveProbability As Boolean   ' enable/disable cbo_probability
Private md_folowUpMaxDate As Date       ' task 298.8 date until which porojects are selected
Private ms_expiredMsg As String         ' description for special message task 298.8
Private ms_initTreeview As String       ' initial treeview defined in DefaultValue or "Vk" if not
Private mb_top10ExecVisible As Boolean  ' manage visibility of comment for non authorised users
Private ms_MEMCodeExec As String        ' top 10 execute comment mem_code for update
Dim m_userRights As UserRights_t
' task 299.2 end
Private ms_View_Key As String

Private Type Demand_t
    Id  As Integer
    Desc As String
    Min As Integer
    Max As Integer
End Type

Dim m_demand() As Demand_t

Private Const REQ_SALES_PROJECT_STATHIST_INS = "exec Sales_Project_StatusHist_ins $SH_CapKey$, $SP_CapKey$,'E',$SS_Code$,$StatusDate$,$LoginName$,$Z_Creator$"

Public Property Set ArmDb(ByRef ao_local_connection As Object)

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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 ckvSalesRep.ArmDB = mo_ArmDb
        Set cbo_date.ArmDb = mo_ArmDb
        Set Cbo_View.ArmDb = mo_ArmDb
        Set cbo_SA.ArmDb = mo_ArmDb
        Set cbo_clgValue.ArmDb = mo_ArmDb
        Set cbo_projectType.ArmDb = mo_ArmDb
        Set cbo_Priority.ArmDb = mo_ArmDb
        Set cbo_newRenovation.ArmDb = mo_ArmDb
        Set cbo_County.ArmDb = mo_ArmDb
        Set cbo_country.ArmDb = mo_ArmDb
        Set grd_searchZip.ArmDb = mo_ArmDb
        Set cbo_projectDesc.ArmDb = mo_ArmDb
        Set cbo_Status.ArmDb = mo_ArmDb
        Set cbo_currencies.ArmDb = mo_ArmDb
        Set cbo_UOM.ArmDb = mo_ArmDb
' task 299.2 begin
        Set cbo_SAType.ArmDb = mo_ArmDb
        Set cbo_Level.ArmDb = mo_ArmDb
' task 299.2 end
' task 299.7 begin
        Set cbo_SS.ArmDb = mo_ArmDb
' task 299.7 end
        Set cbo_Probability.ArmDb = mo_ArmDb
        Set cbo_ceilFncType.ArmDb = mo_ArmDb
        Set cbo_datasource.ArmDb = mo_ArmDb

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

Property Let ConnectString(as_ConnectString As String)
Dim ConnectData As Variant

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:ConnectString_Let", "as_ConnectString=" & as_ConnectString
    #End If
    CapMouseOff
    
    'Check if the connection string is valid
    ms_UID = ConnectionStringValidation(as_ConnectString)
    If ms_UID = "" Then GoTo Trace_End
    
    ms_ConnectString = as_ConnectString
    
    'Connection of objects
    grdlst.ConnectString = ms_ConnectString
    pblst.ConnectString = ms_ConnectString
    pbItem.ConnectString = ms_ConnectString
    tvitems.ConnectString = ms_ConnectString
'    ckvSalesRep.ConnectString = ms_ConnectString
    cbo_date.ConnectString = ms_ConnectString
    Cbo_View.ConnectString = ms_ConnectString
    cbo_SA.ConnectString = ms_ConnectString
    cbo_clgValue.ConnectString = ms_ConnectString
    cbo_projectType.ConnectString = ms_ConnectString
    cbo_Priority.ConnectString = ms_ConnectString
    cbo_newRenovation.ConnectString = ms_ConnectString
    cbo_County.ConnectString = ms_ConnectString
    cbo_country.ConnectString = ms_ConnectString
    grd_searchZip.ConnectString = ms_ConnectString
    cbo_projectDesc.ConnectString = ms_ConnectString
    cbo_Status.ConnectString = ms_ConnectString
    cbo_currencies.ConnectString = ms_ConnectString
    cbo_UOM.ConnectString = ms_ConnectString
' task 299.2 begin
    cbo_SAType.ConnectString = ms_ConnectString
    cbo_Level.ConnectString = ms_ConnectString
' task 299.2 end
' task 299.7 begin
    cbo_SS.ConnectString = ms_ConnectString
' task 299.7 end
    cbo_Probability.ConnectString = ms_ConnectString
    cbo_ceilFncType.ConnectString = ms_ConnectString
    cbo_datasource.ConnectString = ms_ConnectString

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:Language_Let", "as_Language=" & as_Language
    #End If
    CapMouseOff
    
    m_Language = as_Language
    
    'ckvSalesRep.Language = m_Language
    'grdlst.Language = m_Language
    tvitems.Language = m_Language
    pbItem.Language = m_Language
    pblst.Language = m_Language
    cal_clgStartDate.Language = m_Language
    cal_followUpDate.Language = m_Language
    cal_StartDate.Language = m_Language
    cal11.Language = m_Language
    cal12.Language = m_Language
    cal_orderExpDate.Language = m_Language

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj: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, "capprj:CboView_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:CboView_Resize"
    CapMouseOn
End Sub

Private Sub DrawMainGrid()
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, "capprj:DrawMainGrid"
    #End If
    
    mi_TypeList = 1

    pblst.ClearAllIcons
    pblst.TableName = mt_CstValues.SecurityProject
    pblst.PictureDisplayed = "P_Refresh=7 P_Memo=-6 P_Patent=-5 P_View=-4 P_Print=-7 P_Excel=-3 P_Quit=-1"
    
    'Grille

    grdlst.ResetGrid
    grdlst.Title = "Projects"
    grdlst.MultiSelect = True
    
    la_Columns(0) = "sp_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sp_capkey" & CH_LDELIMIT & "sp_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(2) = "sp_desc" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_desc" & CH_LDELIMIT & "sp_desc"
    la_Columns(3) = "sp_zip" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_zip" & CH_LDELIMIT & "sp_zip date"
    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 & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_size" & CH_LDELIMIT & "sp_size" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "CUSTOM"
    la_Columns(6) = "ss_desc" & CH_LDELIMIT & "1300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ss_desc" & CH_LDELIMIT & "ss_desc"
    la_Columns(7) = "cust_rep" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "cust_rep" & CH_LDELIMIT & "cust_rep"
    la_Columns(8) = "spec_rep" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "spec_rep" & CH_LDELIMIT & "spec_rep"
    la_Columns(9) = "SP_ceilingStartingDate" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_ceilingStartingDate" & CH_LDELIMIT & "SP_ceilingStartingDate"
    la_Columns(10) = "SP_dateFollowUp" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_dateFollowUp" & CH_LDELIMIT & "SP_dateFollowUp"
    la_Columns(11) = "AMCProjectNum" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "AMCProjectNumber" & CH_LDELIMIT & "AMCProjectNumber"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_project_longlist', 'grid', '" & m_Language & "'", ctColumns

        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:DrawMainGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj: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, "capprj:GoToTab1"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:GoToTab1"
    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, "capprj:InitParentKey"
    #End If
    
    m_Customer = ""
    m_Memo = ""
    m_Contact = ""
    m_Product = ""
    m_Action = ""
    m_SPA = ""
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:InitParentKey"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:InitParentKey"
    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, "capprj:WithParent"
    #End If
    
    If m_Customer = "" And m_Memo = "" And m_Contact = "" And m_Product = "" And m_Action = "" And m_SPA = "" Then
        WithParent = False
    Else
        WithParent = True
    End If

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

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, "capprj:CurrentKey_Get", "APart=" & APart
    #End If
    
    If APart = 0 Then
        CurrentKey = m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2 & CH_LDELIMIT & m_CurrentKey3
    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, "capprj:CurrentKey_Get"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:CurrentKey_Get"
    CapMouseOn
End Property

Property Get FraFilterLeft() As Long
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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, "capprj:FraFilterLeft_Get", "Result=" & FraFilterLeft
    #End If
    
End Property

Public Sub CreateOffer(ByVal al_OfferType As Long, ByVal as_SPR_Id As String, ByVal as_SPR_Name As String)
    
    Call SelectTab(tbsEmbedded, mt_CstValues.Tag_Offer)
    RaiseEvent CreateOffer(mi_EmbedTag, al_OfferType, as_SPR_Id, as_SPR_Name)
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, "capprj: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, "capprj:ObjectVisible"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ObjectVisible"
    CapMouseOn
End Sub


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

Property Let TypeList(AType As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:TypeList_Let", "AType=" & AType
    #End If
    mi_TypeList = AType
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:TypeList_Get"
    #End If
    TypeList = mi_TypeList
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:TypeList_Get", "Result=" & TypeList
    #End If
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, "capprj: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, "capprj:Memo_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj: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))
    mb_EmbeddedIsDropped = False
    
    If grdlst.Rows <> 0 Then
        SwapToDisplayMode mt_CstValues.DisplayMode_List
        SelectFirst
    Else
        Call ASC_SendMessage(mo_ArmDb, m_Language, 925, "#This action is not linked to a project")
        RaiseEvent HideGrid(mi_EmbeddedIn)
    End If

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

Property Let contact(AKey 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, "capprj:Contact_Let", "AKey=" & AKey
    #End If
    
    'AKey represents the concatenation of several keys separated by '@'
    If AKey = "" 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(AKey, CH_LDELIMIT)
    m_Contact = CStr(TheKeys(0))
    m_Customer = CStr(TheKeys(1))
    mb_EmbeddedIsDropped = (TheKeys(3) = "1") ' TAKS 298.2
    ListContactOf CStr(TheKeys(0)), CStr(TheKeys(1)), CStr(TheKeys(2))

    
    SwapToDisplayMode mt_CstValues.DisplayMode_List

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

Property Let Customer(ACustomerKey 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, "capprj:Customer_Let", "ACustomerKey=" & ACustomerKey
    #End If
    
    'ACustomerKey represents the concatenation of several keys separated by '@'
    If ACustomerKey = "" 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_Customer
   
    TheKeys = Split(ACustomerKey, CH_LDELIMIT)
    m_Customer = CStr(TheKeys(0))
    mb_EmbeddedIsDropped = (TheKeys(2) = "1") ' TASK 298.2
    ms_OldCodeCountry = CStr(TheKeys(3))                ' 02/12/2013 JN - default search country to country of a Customer
    
    ListCustomerOf 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, "capprj:Customer_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Customer_Let"
    CapMouseOn
End Property

Property Let SPA(ByVal SPA_Id As String)

    On Error GoTo Trace_Err
    
    CapMouseOff
    
    'SPA_Id
    If SPA_Id = "" 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_SPA
    mi_EmbedTag = mt_CstValues.Tag_SPA

    m_SPA = SPA_Id
    
    mb_EmbeddedIsDropped = True
    
    SwapToDisplayMode mt_CstValues.DisplayMode_Add

Trace_End:
    CapMouseOn
    Exit Property
    
Trace_Err:
    CapMouseOn
End Property


Private Sub SelectFirst()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:SelectFirst"
    #End If
    
    grdlst.FirstLine
    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, "capprj:SelectFirst"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:SelectFirst"
    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, "capprj: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 mi_TypeList <> 1 Then
                mi_TypeList = 1
                'ckvSalesRep.RequestScreenCstString = "exec screen_csts 'Cap_ckv_SR','" & m_Language & "'"
                'Default values
                'SetDefaultValues "Cap_Project_Detail"
            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
                'ckvSalesRep.RequestScreenCstString = "exec screen_csts 'Cap_ckv_SR','" & m_Language & "'"
            End If
    End Select
   
    UserControl.ScaleMode = 1
    
    'Object unvisble
    ObjectVisible False
    
    Select Case aMode
        Case 1
            'Pour la liste longue uniquement
            DrawMainGrid
            ' bug55, fix 22.12.2006 JULO begin
            ' call to fill grid when initialized for the first time
            If Not mb_gridInitializedForFollowUP Then
                Debug.Assert (UCase(GetCodeFromCombo(Cbo_View)) = "VK")
                Call RefreshFollowUp
                mb_gridInitializedForFollowUP = True
            End If
            ' bug55, fix 22.12.2006 JULO end
            
            'Dates
            cal11.Zorder 0
            cal12.Zorder 0
            cal11.Limited_as_embedded = 1
            cal12.Limited_as_embedded = 1
              
            'Initialization of treeview and  filters

                
        Case 2, 0
            'Pour la liste courte
            'Grille
               grdlst.ResetGrid
            
            'Pour liste courte : Initialisation toolbar
            pblst.ClearAllIcons
            pblst.TableName = mt_CstValues.SecurityProject_lst
            pblst.PictureDisplayed = "P_Memo=-5 P_Patent=-4 P_Refresh=7 P_Print=-6"
        
        Case 3
            'Pour détail
            
            pbItem.ClearAllIcons
            pbItem.TableName = ""
            If mi_EmbeddedIn = -1 Then
                pbItem.PictureDisplayed = "P_Update=2 P_Previous=4 P_Next=5 P_ToolBox=-2 P_Quit=-1"
            Else
                pbItem.PictureDisplayed = "P_Update=2 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, "capprj:InitControl"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:InitControl"
    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, "capprj:UpdateInitFields"
    #End If
    
    'idem
    ViewInitFields

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

Function RecordAdd() As Boolean
Dim ls_Request As String
Dim ls_ProjCode As String
Dim ls_MEMCode As String                ' task 299.3
Dim ls_SH_CapKey As String
Dim lb_Result As Boolean
Dim ls_Result As String
Dim ll_Count As Long
Dim ll_FollowUpIncrement As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:RecordAdd"
    #End If
    
    RecordAdd = False
    
    If Not cbo_projectDesc.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_projectDesc) <> "" Then
            ls_Request = "Exec Cap_ProjectDescription_chk " & GetCodeFromCombo(cbo_projectDesc) & ",'" & 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_projectDesc.Caption & " : " & cbo_projectDesc.SelectedItem.DisplayText)
                    cbo_projectDesc.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    End If
    
    If Not cbo_projectType.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ProjectType_chk " & GetCodeFromCombo(cbo_projectType) & ",'" & 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_projectType.Caption & " : " & cbo_projectType.SelectedItem.DisplayText)
                cbo_projectType.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
' task 299.2 begin
    ' product level
    If Not cbo_Level.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ProjectLevel_chk " & GetCodeFromCombo(cbo_Level) & ",'" & 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_level.Caption & " : " & cbo_Level.SelectedItem.DisplayText)
                cbo_Level.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    ' system solution type
    If Not cbo_SS.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_SystemSolutionType_chk " & GetCodeFromCombo(cbo_SS) & ",'" & 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_sysSol.Caption & " : " & cbo_SS.SelectedItem.DisplayText)
                cbo_SS.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    ' SA type
    If Not cbo_SAType.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_SAType_chk " & GetCodeFromCombo(cbo_SAType) & ",'" & 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_SAType.Caption & " : " & cbo_SAType.SelectedItem.DisplayText)
                cbo_SAType.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
' task 299.2 end

    If Not cbo_Status.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_SalesStatus_chk " & GetCodeFromCombo(cbo_Status) & ",'" & 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")
                cbo_Status.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If Not cbo_SA.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_StratAccount_chk " & GetCodeFromCombo(cbo_SA) & ",'" & 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")
                cbo_SA.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If IsDate(cal_StartDate.date_courte) Then
        If Not ErrorFound And CDate(cal_clgStartDate.date_courte) < CDate(cal_StartDate.date_courte) Then
            cal_clgStartDate.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 270, "#Start date must be less that Ceilings Start date")
            GoTo Trace_End
        End If
    End If
    
    If IsDate(cal_followUpDate.date_courte) And Not ErrorFound Then
        
        ll_FollowUpIncrement = Val(GetDefaultConfigCode("Project_Cfg", "FollowUpIncrement"))
        
        If CDate(cal_followUpDate.date_courte) <= (Date + ll_FollowUpIncrement) Then
            cal_followUpDate.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 271, "#follow up must be greater than: ", Format(Date + ll_FollowUpIncrement, "dd/mm/yyyy"))
            GoTo Trace_End
        End If
    End If
    
    
    If Not cbo_currencies.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_currencies) <> "" Then
            ls_Request = "Exec Currencies_chk " & GetCodeFromCombo(cbo_currencies) & ",'" & 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")
                    cbo_currencies.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    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", 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
    
    ErrorOFF

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

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

    ms_MEMCodeExec = ""
    If chk_Top10E.Value = vbChecked And Trim(txt_Top10EComment.Text) <> "" Then
        ms_MEMCodeExec = mo_ArmDb.SQLNextID("Cap_Memo")
        If ms_MEMCodeExec = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Cap_Memo"") return nothing.")
    End If

    ls_SH_CapKey = mo_ArmDb.SQLNextID("Sales_Project_StatusHist")
    If ls_SH_CapKey = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Sales_Project_StatusHist"") return nothing.")
    
    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
    
    
    ls_Request = "Exec sales_project_ins2 "
    
    ls_Request = ls_Request & "  " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_country, True) '@CT_code    CHAR(4),
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_UOM, True) '@UM_code    CHAR(5),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Desc, True) '@SP_Desc    VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_StartDate) '@SP_StartDate   DATETIME,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Address1) '@SP_Addr1   VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_address2) '@SP_Addr2   VARCHAR(80),
    ls_Request = ls_Request & ", " & UCaseInternational(CorrectString(mo_ArmDb, m_Language, txt_Town, True), GetCodePageFromLCID(gl_LocalID))   '@SP_Town    VARCHAR(80),
    ls_Request = ls_Request & ", " & "'capture'" '@SP_System  CHAR(20),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Size, True) '@SP_Size    REAL,
'    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Top10EComment) '@SP_Comment VARCHAR(250),   ' task299.3
    ls_Request = ls_Request & ", " & "''" '@Internet_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "''" '@drop_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "NULL" '@drop_date  CHAR(1),
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_clgStartDate, True) '@SP_ceilingStartingDate DATETIME,
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_followUpDate, True) '@SP_dateFollowUp    DATETIME,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_projectDesc, False) '@PD_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_newRenovation, True) '@NR_code    INT,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_projectValue) '@SP_ProjectValue    REAL,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_currencies, IIf(Trim$(txt_projectValue.Text) = "", False, True)) '@CURR_code  CHAR(5),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_County, True) '@CTY_code   INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Status, True) '@SS_code    INT,
    ls_Request = ls_Request & ", " & "NULL" '@Ens_projectid  CHAR(20),
    ls_Request = ls_Request & ", " & "NULL" '@Ens_compid CHAR(10),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip1, True) '@SP_zip1    CHAR(10),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip2, lb_usefullZip) '@SP_Zip2    CHAR(10),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_projectType, True) '@PT_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Priority, True) '@PP_code    INT,
    If opt_std.Value Then
        ls_Request = ls_Request & ", " & "NULL" '@SA_code    INT,
        ls_Request = ls_Request & ", " & "''" '@SP_SAFlag  CHAR(1),
    ElseIf opt_as.Value Then
        ls_Request = ls_Request & ", " & "NULL" '@SA_code    INT,
        ls_Request = ls_Request & ", " & "'A'" '@SP_SAFlag  CHAR(1),
    Else
        Debug.Assert (opt_sa.Value)
        ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_SA, True) '@SA_code    INT,
        ls_Request = ls_Request & ", " & "'X'" '@SP_SAFlag  CHAR(1),
    End If
'    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_ceilingvalue)  '@SP_clgValue    REAL,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_clgValue, True)    '@PSZ_code     int,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1) '@spare1     varchar(1),
    ls_Request = ls_Request & ", " & CorrectBool(chk_sysSol)  '@spare2     varchar(1),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Probability, mb_HaveProbability)    '@spare3     real,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare4) '@spare4     real
' task 299.2 begin
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_SAType, opt_sa.Value) '@SAT_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Level, mb_HaveLevel) '@LEV_code    INT,
' task 299.2 end
' task 299.7 begin
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_SS, (chk_sysSol.Value = vbChecked)) '@SST_code    INT,
' task 299.7 end
    ls_Request = ls_Request & ", '" & ls_ProjCode & "'"
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Spare5) '@spare5     varchar(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare6) '@spare6     varchar(80),
    ls_Request = ls_Request & ", " & CorrectBool(chk_Top10E, "1", "0") '@spare7     real
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_datasource, True) '@LSRC_Code    TINYINT,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_External_Id) '@external_id     varchar(40),

    
    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
    ls_RequestAMC = ""
    If chk_AMCProjectType.Value = vbChecked Then
        If Not Item_Check Then GoTo Trace_End

        ls_RequestAMC = "Sales_ProjectAMC_ins '" & ls_ProjCode & "'"
        ls_RequestAMC = ls_RequestAMC & ", '$AMCProjectNo$'"                                                '@AMCProjectNumber   VARCHAR(15),
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectDate(mo_ArmDb, m_Language, cal_orderExpDate, False)    '@AMCExpiryOrderDate DATETIME,
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectDec(mo_ArmDb, m_Language, txt_duration, False)        '@AMCProjDuration    SMALLINT,
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectString(mo_ArmDb, m_Language, txt_I5No, False)         '@AMCI5Ref           VARCHAR(20),
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_ceilFncType, True)  '@AMCCF_Code         INT,
        
        If Not ErrorFound Then
            ' generate AMC project number
            Dim ll_NextCountryID  As Long
            ll_NextCountryID = mo_ArmDb.SQLNextID("SOM_" & cbo_country.SelectedItem.Key)
        
            txt_AMCProjectNo.Text = cbo_country.SelectedItem.Key & Format(Now, "YY") & Format(ll_NextCountryID, "0000")
        
            ls_RequestAMC = Replace(ls_RequestAMC, "$AMCProjectNo$", txt_AMCProjectNo.Text, , , vbTextCompare)
        Else
            ls_RequestAMC = ""
        End If
    End If
    

    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    'Execution
    If ErrorFound 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_ProjCode)
    If lb_Result Then
        acv_Rep.Calling_Key_Values = ls_ProjCode
        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
' task 299.3 begin
Const REQins = "EXEC Cap_Memo_ins 'E', $Comment_desc$, $Comment$, 'N', 'N', Null, '$SP_CAPKEY$', '', $spare3$, 0, '$MEM_Code$'"
    ' insert into cap_memo only 'E' language record, memo type=1(spare3_real)
        ' create memo
        ls_Request = Replace(REQins, "$Comment_desc$", FormatSqlStringParameter(Left(txt_Comment.Text, 80)))
        ls_Request = Replace(ls_Request, "$spare3$", 1, , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Comment.Text))
        ls_Request = Replace(ls_Request, "$SP_CAPKEY$", ls_ProjCode)
        ls_Request = Replace(ls_Request, "$MEM_Code$", ls_MEMCode)
    
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_MEMCode)
        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
' task 299.3 end

       If ms_MEMCodeExec <> "" Then
            ls_Request = Replace(REQins, "$Comment_desc$", FormatSqlStringParameter(Left(txt_Top10EComment.Text, 80)))
            ls_Request = Replace(ls_Request, "$spare3$", 4, , , vbTextCompare)
            ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Top10EComment.Text))
            ls_Request = Replace(ls_Request, "$SP_CAPKEY$", ls_ProjCode)
            ls_Request = Replace(ls_Request, "$MEM_Code$", ms_MEMCodeExec)
        
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ms_MEMCodeExec)
            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
        End If
    
        If ls_RequestAMC <> "" Then
            Call ExecuteSQLSafe(mo_ArmDb, ls_RequestAMC, 1)
        End If
        
    
        ' create sales project status history
        ls_Request = REQ_SALES_PROJECT_STATHIST_INS
        ls_Request = Replace(ls_Request, "$SH_CapKey$", SqlStr(ls_SH_CapKey), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$SP_CapKey$", SqlStr(ls_ProjCode), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$SS_Code$", Val(GetCodeFromCombo(cbo_Status)), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$StatusDate$", "NULL", , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$LoginName$", SqlStr(ms_UID), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$Z_Creator$", SqlStr(ms_UID), , , vbTextCompare)
    
        lb_Result = mo_ArmDb.ExecuteSQL(ls_Request)
        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

    m_CurrentKey1 = ls_ProjCode
    ASC_CommitTransaction mo_ArmDb
    lb_Transaction = False
    RecordAdd = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:RecordAdd"
    CapMouseOn
End Function

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

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

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:RecordUpdate", "ACode=" & ACode
    #End If
    
    RecordUpdate = 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 cbo_projectDesc.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_projectDesc) <> "" Then
            ls_Request = "Exec Cap_ProjectDescription_chk " & GetCodeFromCombo(cbo_projectDesc) & ",'" & 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_projectDesc.Caption & " : " & cbo_projectDesc.SelectedItem.DisplayText)
                    cbo_projectDesc.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    End If
    
    If Not cbo_projectType.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ProjectType_chk " & GetCodeFromCombo(cbo_projectType) & ",'" & 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_projectType.Caption & " : " & cbo_projectType.SelectedItem.DisplayText)
                cbo_projectType.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
' task 299.2 begin
    ' product level
    If Not cbo_Level.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ProjectLevel_chk " & GetCodeFromCombo(cbo_Level) & ",'" & 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_level.Caption & " : " & cbo_Level.SelectedItem.DisplayText)
                cbo_Level.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    ' system solution type
    If Not cbo_SS.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_SystemSolutionType_chk " & GetCodeFromCombo(cbo_SS) & ",'" & 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_sysSol.Caption & " : " & cbo_SS.SelectedItem.DisplayText)
                cbo_SS.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    ' SA type
    If Not cbo_SAType.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_SAType_chk " & GetCodeFromCombo(cbo_SAType) & ",'" & 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_SAType.Caption & " : " & cbo_SAType.SelectedItem.DisplayText)
                cbo_SAType.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
' task 299.2 end

    If Not cbo_Status.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_SalesStatus_chk " & GetCodeFromCombo(cbo_Status) & ",'" & 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")
                cbo_Status.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If Not cbo_SA.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_StratAccount_chk " & GetCodeFromCombo(cbo_SA) & ",'" & 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")
                cbo_SA.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If Not cbo_currencies.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_currencies) <> "" Then
            ls_Request = "Exec Currencies_chk " & GetCodeFromCombo(cbo_currencies) & ",'" & 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")
                    cbo_currencies.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    End If
    
' task
    If Not opt_as.Value Then
        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", 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
    End If
    
    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 sales_project_upd2 "
    
    ls_Request = ls_Request & "  " & "'" & ACode & "'" '@SP_CapKey  CHAR(16),
    ls_Request = ls_Request & ",  " & p_iCon '@iConc      SMALLINT,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_country, True) '@CT_code    CHAR(4),
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_UOM, True) '@UM_code    CHAR(5),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Desc, True) '@SP_Desc    VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_StartDate) '@SP_StartDate   DATETIME,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Address1) '@SP_Addr1   VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_address2) '@SP_Addr2   VARCHAR(80),
    ls_Request = ls_Request & ", " & UCaseInternational(CorrectString(mo_ArmDb, m_Language, txt_Town, True), GetCodePageFromLCID(gl_LocalID)) '@SP_Town    VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Size, True) '@SP_Size    REAL,
'    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Top10EComment) '@SP_Comment VARCHAR(250),   ' task 299.3
    ls_Request = ls_Request & ", " & "''" '@Internet_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "''" '@drop_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "NULL" '@drop_date  CHAR(1),
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_clgStartDate, True) '@SP_ceilingStartingDate DATETIME,
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_followUpDate, True) '@SP_dateFollowUp    DATETIME,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_projectDesc)  '@PD_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_newRenovation, True) '@NR_code    INT,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_projectValue) '@SP_ProjectValue    REAL,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_currencies, IIf(Trim$(txt_projectValue.Text) = "", False, True)) '@CURR_code  CHAR(5),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_County, True) '@CTY_code   INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Status, True) '@SS_code    INT,
    ls_Request = ls_Request & ", " & "NULL" '@Ens_projectid  CHAR(20),
    ls_Request = ls_Request & ", " & "NULL" '@Ens_compid CHAR(10),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip1, True) '@SP_zip1    CHAR(10),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Zip2, lb_usefullZip) '@SP_Zip2    CHAR(10),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_projectType, True) '@PT_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Priority, True) '@PP_code    INT,
    If opt_std.Value Then
        ls_Request = ls_Request & ", " & "NULL" '@SA_code    INT,
        ls_Request = ls_Request & ", " & "''" '@SP_SAFlag  CHAR(1),
    ElseIf opt_as.Value Then
        ls_Request = ls_Request & ", " & "NULL" '@SA_code    INT,
        ls_Request = ls_Request & ", " & "'A'" '@SP_SAFlag  CHAR(1),
    Else
        Debug.Assert (opt_sa.Value)
        ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_SA, True) '@SA_code    INT,
        ls_Request = ls_Request & ", " & "'X'" '@SP_SAFlag  CHAR(1),
    End If
'    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_ceilingvalue) '@SP_clgValue    REAL,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_clgValue, True)    '@PSZ_code     int,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1)    '@spare1     varchar(1),
    ls_Request = ls_Request & ", " & CorrectBool(chk_sysSol)    '@spare2     varchar(1),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Probability, mb_HaveProbability)    '@spare3     real,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare4) '@spare4     real
' task 299.2 begin
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_SAType, opt_sa.Value) '@SAT_code    INT,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Level, mb_HaveLevel) '@LEV_code    INT,   ' --FIX
' task 299.2 end
' task 299.7 begin
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_SS, (chk_sysSol.Value = vbChecked)) '@SST_code    INT,
' task 299.7 end
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Spare5) '@spare5     varchar(80),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare6) '@spare6     varchar(80),
    ls_Request = ls_Request & ", " & CorrectBool(chk_Top10E, "1", "0")   '@spare7     real
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_datasource, True) '@LSRC_Code    TINYINT,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_External_Id) '@external_id     varchar(40),
    
    ' TO DO : Rajouter le flag update_rep manually
    
    If Not ErrorFound And CDate(cal_followUpDate.date_courte) < CDate(ms_CreationDate) Then
        cal_followUpDate.SetFocus
        Call ASC_SendMessage(mo_ArmDb, m_Language, 890, "#Follow up date must be great than entered date")
        cal_followUpDate.SetFocus
        GoTo Trace_End
    End If
    If IsDate(cal_StartDate.date_courte) Then
        If Not ErrorFound And CDate(cal_clgStartDate.date_courte) < CDate(cal_StartDate.date_courte) Then
            cal_clgStartDate.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 270, "#Start date must be less that Ceilings Start date")
            GoTo Trace_End
        End If
    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
    ls_RequestAMC = ""
    If chk_AMCProjectType.Value = vbChecked Then
        If Not Item_Check Then GoTo Trace_End
        
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectDate(mo_ArmDb, m_Language, cal_orderExpDate, False)    '@AMCExpiryOrderDate DATETIME,
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectDec(mo_ArmDb, m_Language, txt_duration, True)         '@AMCProjDuration    SMALLINT,
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectString(mo_ArmDb, m_Language, txt_I5No, False)         '@AMCI5Ref           VARCHAR(20),
        ls_RequestAMC = ls_RequestAMC & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_ceilFncType, True)  '@AMCCF_Code         INT,
        If mb_OriginalAMCExists Then
            ls_RequestAMC = "Sales_ProjectAMC_upd '" & ACode & "', " _
                            & CorrectString(mo_ArmDb, m_Language, txt_AMCProjectNo, True) & ls_RequestAMC   '@AMCProjectNumber   VARCHAR(15),
        Else
            If Not ErrorFound Then
                ' generate AMC project number
                Dim ll_NextCountryID  As Long
                ll_NextCountryID = mo_ArmDb.SQLNextID("SOM_" & cbo_country.SelectedItem.Key)
            
                txt_AMCProjectNo.Text = cbo_country.SelectedItem.Key & Format(Now, "YY") & Format(ll_NextCountryID, "0000")
            
                ls_RequestAMC = "Sales_ProjectAMC_ins '" & ACode & "', '" & txt_AMCProjectNo.Text & "'" & ls_RequestAMC        '@AMCProjectNumber   VARCHAR(15),
            Else
                ls_RequestAMC = ""
            End If

        End If
    ElseIf mb_OriginalAMCExists Then
        ls_RequestAMC = "Sales_ProjectAMC_del '" & ACode & "'"
    End If
    
    'Execution
    If ErrorFound Then GoTo Trace_End

    Dim lb_memoCreated As Boolean
    lb_memoCreated = False
    If chk_Top10E.Value = vbChecked And ms_MEMCodeExec = "" And Trim(txt_Top10EComment.Text) <> "" Then
        ms_MEMCodeExec = mo_ArmDb.SQLNextID("Cap_Memo")
        If ms_MEMCodeExec = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Cap_Memo"") return nothing.")
        lb_memoCreated = True
    End If


    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ll_NewStatusCode = Val(GetCodeFromCombo(cbo_Status))
    If ml_OriginalStatusCode <> ll_NewStatusCode Then
        ls_SH_CapKey = mo_ArmDb.SQLNextID("Sales_Project_StatusHist")
        If ls_SH_CapKey = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Sales_Project_StatusHist"") return nothing.")
    End If
    
    ASC_BeginTransaction mo_ArmDb
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result Then lb_Result = acv_Rep.SaveList
    If lb_Result Then
        If PrdValOf.Validated Then
            PrdValOf.iConc = p_iCon
            lb_Result = PrdValOf.Save
            If PrdValOf.StatusCode <> 0 Then
              ll_NewStatusCode = PrdValOf.StatusCode
            End If
            If lb_Result Then
                CustOf.iConc = p_iCon
                lb_Result = CustOf.Save
            End If
        End If
    End If
    
    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
        

' task 299.3 begin
Const REQupd = "EXEC Cap_Memo_Comment_upd '$SP_CAPKEY$', $Comment$, 'N', Null, $spare3$, $uid$"

    ' update cap_memo
    ls_Request = Replace(REQupd, "$SP_CAPKEY$", ACode, , , vbTextCompare)
    ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Comment.Text), , , vbTextCompare)
    ls_Request = Replace(ls_Request, "$spare3$", 1, , , vbTextCompare)
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'", , , vbTextCompare)
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If
' task 299.3 end
    If lb_memoCreated Then
        Debug.Assert (ms_MEMCodeExec <> "")
        Const REQins = "EXEC Cap_Memo_ins 'E', $Comment_desc$, $Comment$, 'N', 'N', Null, '$SP_CAPKEY$', '', $spare3$, 0, '$MEM_Code$'"
        ls_Request = Replace(REQins, "$Comment_desc$", FormatSqlStringParameter(Left(txt_Top10EComment.Text, 80)))
        ls_Request = Replace(ls_Request, "$spare3$", 4, , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Top10EComment.Text))
        ls_Request = Replace(ls_Request, "$SP_CAPKEY$", ACode)
        ls_Request = Replace(ls_Request, "$MEM_Code$", ms_MEMCodeExec)
    
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ms_MEMCodeExec)
        If lb_Result = False Then
            ASC_RollBackTransaction mo_ArmDb
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
            GoTo Trace_End
        End If
    Else
        If ms_MEMCodeExec <> "" Then
            ls_Request = Replace(REQupd, "$SP_CAPKEY$", ACode, , , vbTextCompare)
            ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Top10EComment.Text), , , vbTextCompare)
            ls_Request = Replace(ls_Request, "$spare3$", 4, , , vbTextCompare)
            ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'", , , vbTextCompare)
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
            If lb_Result = False Then
                ASC_RollBackTransaction mo_ArmDb
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                GoTo Trace_End
            End If
        End If
    End If

    If ls_RequestAMC <> "" Then
        Call ExecuteSQLSafe(mo_ArmDb, ls_RequestAMC, 1)
    End If
    
    If ml_OriginalStatusCode <> ll_NewStatusCode Then
        ' create sales project status history
        ls_Request = REQ_SALES_PROJECT_STATHIST_INS
        ls_Request = Replace(ls_Request, "$SH_CapKey$", SqlStr(ls_SH_CapKey), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$SP_CapKey$", SqlStr(ACode), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$SS_Code$", ll_NewStatusCode, , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$StatusDate$", "NULL", , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$LoginName$", SqlStr(ms_UID), , , vbTextCompare)
        ls_Request = Replace(ls_Request, "$Z_Creator$", SqlStr(ms_UID), , , vbTextCompare)
    
        lb_Result = mo_ArmDb.ExecuteSQL(ls_Request)
        If lb_Result = False Then
            ASC_RollBackTransaction mo_ArmDb
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
            GoTo Trace_End
        End If
    End If
    
    
    If (CStr(GetCodeFromCombo(cbo_Status)) = "15" And opt_as.Value) Then    ' 15 .. not build
        ' we cancel the quotes
        Call SOMQuotesCancel
    End If

    ASC_CommitTransaction mo_ArmDb
    RecordUpdate = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:RecordUpdate"
    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, "capprj:Product_Let", "AProductKey=" & AProductKey
    #End If
    
    'AProductKey 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(1))
    ListProductOf CStr(TheKeys(0)), CStr(TheKeys(1)), CStr(TheKeys(2))
    mb_EmbeddedIsDropped = False
    
    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, "capprj:Product_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Product_Let"
    CapMouseOn
End Property

Function RecordDelete(ACode As String) As Boolean
Dim ls_Request As String
Dim ll_Cursor As Long
Dim lb_Result As Boolean
Dim ls_Result As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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

    ErrorOFF

    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 '" & ACode & "', NULL, NULL", ls_ResultCode) Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 8717, "#You cannot delete this project, because one or more SPA exists for this project")
        GoTo Trace_End
    End If
    
    
    If Not CheckProjectClaim Then GoTo Trace_End
    
    ls_Request = "Exec sales_project_chk "
    ls_Request = ls_Request & "  '" & ACode & "'" '@SP_CapKey char (16)
    
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "capprj:RecordDelete", "Request=" & ls_Request
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, "ActionCount") <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 262, "#You cannot delete this project because it have one or more actions !")
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, "MemoCount") <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 264, "#You cannot delete this project because it have one or more memos !")
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, "ProductCount") <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 263, "You cannot delete this project because it have one or more solutions !")
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, "CustomerCount") <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 261, "#You cannot delete this project because it have one or more links with customers !")
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, "QuoteCount") <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 293, "#You cannot delete this project because it have one or more links with quotes !")
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, "OfferCount") <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 294, "#You cannot delete this project because it have one or more links with offers !")
        GoTo Trace_End
    End If
    mo_ArmDb.Close ll_Cursor

    ls_Request = "Exec sales_project_del2 "

    ls_Request = ls_Request & "  " & "'" & ACode & "'" '@SP_CapKey char (16),
    ls_Request = ls_Request & ", " & p_iCon '@iConcurrency   SMALLINT

    'Execution
    If ErrorFound Then GoTo Trace_End
    
    If DeleteConfirmation(mo_ArmDb, m_Language) = False Then GoTo Trace_End
    
    ASC_BeginTransaction mo_ArmDb
    
    Call ExecuteSQLSafe(mo_ArmDb, "Sales_ProjectAMC_del '" & ACode & "'")
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        If ls_Result = "-2" 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
            chk_Top10E.Enabled = False          ' disable control
            cbo_Priority.Enabled = False
        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
    
' task 299.3 begin
Const REQdel = "EXEC Cap_Memo_Comment_del '$SP_CAPKEY$', $spare3$"
    ' delete memo
    ls_Request = Replace(REQdel, "$SP_CAPKEY$", ACode)
    ls_Request = Replace(ls_Request, "$spare3$", 1)
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If
' task 299.3 end
    
    If ms_MEMCodeExec <> "" Then
        ' delete memo
        ls_Request = Replace(REQdel, "$SP_CAPKEY$", ACode)
        ls_Request = Replace(ls_Request, "$spare3$", 4)
        
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
        If lb_Result = False Then
            ASC_RollBackTransaction mo_ArmDb
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
            GoTo Trace_End
        End If
    End If

    ASC_CommitTransaction mo_ArmDb
    RecordDelete = True
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:RecordDelete", "Result=" & RecordDelete
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    ASC_RollBackTransaction mo_ArmDb
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:RecordDelete"
    CapMouseOn
End Function

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, "capprj: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, "capprj:CurrentKey_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:CurrentKey_Let"
    CapMouseOn
End Property

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, "capprj:acv_Rep_ItemCheck", "Item=" & Item.Key
    #End If
    
    txt_spare1.Text = "Y"   ' set flag to indicate manual change of a sales rep

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:acv_Rep_ItemCheck"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:cal_clgStartDate_changeposition"
    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


    Debug.Assert (Not cbo_country.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$", mt_CstValues.RRGRP_Cust, , , 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_statHist_Click()
On Error GoTo Trace_Err
    If mb_InternalInit Then Exit Sub
    
    CapMouseOff
    
    Call ShowStatusHistory

    CapMouseOn
    Exit Sub
Trace_Err:
    CapMouseOn
End Sub


Private Sub cal_clgStartDate_changeposition(y As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cal_clgStartDate_changeposition", "y=" & y
    #End If
    
    cal_clgStartDate.Zorder 0
    cal_clgStartDate.Top = cal_clgStartDate.Top + y

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

Private Sub cal_clgStartDate_datechangee()
    
On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cal_clgStartDate_datechangee"
    #End If
    
    If IsDate(cal_StartDate.date_courte) And IsDate(cal_clgStartDate.date_courte) Then
        If Not ErrorFound And CDate(cal_clgStartDate.date_courte) < CDate(cal_StartDate.date_courte) Then
            cal_clgStartDate.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 270, "#Start date must be less that Ceilings Start date")
            GoTo Trace_End
        End If
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:cal_clgStartDate_datechangee"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:cal_clgStartDate_datechangee"
    CapMouseOn

End Sub

Private Sub cal_followUpDate_changeposition(y As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cal_followUpDate_changeposition", "y=" & y
    #End If
    
    cal_followUpDate.Zorder 0
    cal_followUpDate.Top = cal_followUpDate.Top + y

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

Private Sub cal_orderExpDate_changeposition(y As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cal_orderExpDate_changeposition", "y=" & y
    #End If
    
    cal_orderExpDate.Zorder 0
    cal_orderExpDate.Top = cal_orderExpDate.Top + y

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

Private Sub cal_startDate_changeposition(y As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cal_startDate_changeposition", "y=" & y
    #End If
    
    cal_StartDate.Zorder 0
    cal_StartDate.Top = cal_StartDate.Top + y

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

Private Sub cal_startDate_datechangee()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cal_startDate_datechangee"
    #End If
    
    If IsDate(cal_StartDate.date_courte) And IsDate(cal_clgStartDate.date_courte) Then
        If Not ErrorFound And CDate(cal_clgStartDate.date_courte) < CDate(cal_StartDate.date_courte) Then
            cal_StartDate.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 270, "#Start date must be less that Ceilings Start date")
            GoTo Trace_End
        End If
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:cal_startDate_datechangee"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:cal_startDate_datechangee"
    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, "capprj:cal11_datechangee"
    #End If
    
    tvitems.Visible = 0
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006


Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:cal11_datechangee"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:cal12_datechangee"
    #End If
    
    tvitems.Visible = 0
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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


Private Sub cbo_country_ComboItemSelected()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cbo_country_Click"
    #End If
    
    cbo_County.Clear
    
    txt_Zip1.Text = ""
    txt_Zip2.Text = ""
    'Call RefreshSalesReps

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:cbo_country_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:cbo_country_Click"
    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 = True
            cbo_County.Request = "exec cap_county_cbo  '" & CodeCountry & "', " & "'" & m_Language & "'"
            ms_OldCodeCountry = CodeCountry
        End If
    End If

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, "capprj: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           ' bugfix 19.10.2006

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

Private Sub cbo_status_ComboDropDown()

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

    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_Add
            cbo_Status.DeleteItemKey "13" 'Complete
            cbo_Status.DeleteItemKey "16" 'Reference
        Case mt_CstValues.DisplayMode_Update
            cbo_Status.DeleteItemKey "16" ' Reference

    End Select
    
    If opt_std.Value Or opt_sa.Value Then
        ' remove AS statuses
        cbo_Status.DeleteItemKey "23" 'Quotation AS
        cbo_Status.DeleteItemKey "24" 'Complete AS
        cbo_Status.DeleteItemKey "25" '#Order AS
        cbo_Status.DeleteItemKey "26" 'On site AS
        cbo_Status.DeleteItemKey "27" 'Specification AS
    End If
    
    If opt_as.Value Then
        ' remove all non AS statuses -> leave (15, 23, 24, 25, 26, 27 )
        cbo_Status.DeleteItemKey "1" '~Project Conception
        cbo_Status.DeleteItemKey "2" ' Outline Planning
        cbo_Status.DeleteItemKey "3" ' Detailed Planning
        cbo_Status.DeleteItemKey "4" ' Working Drawings
        cbo_Status.DeleteItemKey "5" ' Specification
        cbo_Status.DeleteItemKey "6" ' Tender
        cbo_Status.DeleteItemKey "7" '~Tender to Ceiling Contractor
        cbo_Status.DeleteItemKey "8" '~Ceiling Contractor awarded
        cbo_Status.DeleteItemKey "9" ' On Site
        cbo_Status.DeleteItemKey "10" '~Order placed at distributor
        cbo_Status.DeleteItemKey "11" '~Order placed at COS
        cbo_Status.DeleteItemKey "12" '~Delivery
        cbo_Status.DeleteItemKey "13" ' Complete
        cbo_Status.DeleteItemKey "14" ' On Hold
        cbo_Status.DeleteItemKey "16" ' Reference
        cbo_Status.DeleteItemKey "17" ' Data Not in Ensure
        cbo_Status.DeleteItemKey "18" ' Automatic Project database clean
        cbo_Status.DeleteItemKey "19" '~Main contractor awarded
        cbo_Status.DeleteItemKey "20" '~SPA Lead
        cbo_Status.DeleteItemKey "21" '~Lead
        cbo_Status.DeleteItemKey "22" '~Contractor Sales
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:cbo_status_ComboDropDown"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:cbo_status_ComboDropDown"
    CapMouseOn
End Sub

' task 298.8. begin
Private Property Let AllowAddNewProject(ByVal ab_Allow As Boolean)
    If ab_Allow Then
        'pblst.PictureDisplayed = "P_Add=1"
        If InStr(1, pblst.PictureDisplayed, "P_Add", vbTextCompare) > 0 Then
            pblst.PictureDisplayed = Replace(pblst.PictureDisplayed, "P_Add=0", "P_Add=1", , , vbTextCompare)
        Else
          If InStr(1, pblst.Permissions, "P_Add", vbTextCompare) > 0 Then
            pblst.PictureDisplayed = "P_Add=1 " & pblst.PictureDisplayed
          End If
        End If
    Else
        'pblst.PictureDisplayed = "P_Add=0"
        If InStr(1, pblst.PictureDisplayed, "P_Add", vbTextCompare) > 0 Then
            pblst.PictureDisplayed = Replace(pblst.PictureDisplayed, "P_Add=1", "P_Add=0", , , vbTextCompare)
        Else
          If InStr(1, pblst.Permissions, "P_Add", vbTextCompare) > 0 Then
            pblst.PictureDisplayed = "P_Add=0 " & pblst.PictureDisplayed
          End If
        End If
    End If
End Property

Private Property Get FiltersEnabled() As Boolean
    Dim lb_retVal As Boolean
    lb_retVal = True
    If Not Cbo_View.SelectedItem Is Nothing Then
        lb_retVal = (GetCodeFromCombo(Cbo_View) <> "Vk")
    End If
    FiltersEnabled = lb_retVal
End Property

Private Sub EnableFilters(ByVal ab_Enabled As Boolean)
    Dim lb_enabledFinal As Boolean
    lb_enabledFinal = ab_Enabled And FiltersEnabled
    Call ControlsEnable(UserControl.Controls, fraFilters, lb_enabledFinal)
    Call ControlsEnable(UserControl.Controls, UserControl.fra_active, lb_enabledFinal)
    Call ControlsEnable(UserControl.Controls, UserControl.fra_SolSys, lb_enabledFinal)
    
    If ab_Enabled Then
        ' enable controls that affect FiltersEnabled property
        Cbo_View.Enabled = ab_Enabled
        reload_treeview.Enabled = ab_Enabled
        pctTvReset.Enabled = ab_Enabled     ' bug70, fix 06.12.2006 JULO
    End If
    chk_isInitTV.Enabled = ab_Enabled     ' checkbox is allways disabled
End Sub



Private Sub chk_AMCProjectType_Click()
    On Error GoTo Trace_Err
    
    Call showAMC(chk_AMCProjectType.Value = vbChecked)
    
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:chk_AMCProjectType_Click"
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 Vk
        If GetCodeFromCombo(Cbo_View) <> "Vk" Then
            ms_initTreeview = "Vk"
        Else
            ' Vk 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, "capprj: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$", "Project_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$", "Project_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$", "Project_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 cmd_JP_experimental_Click()
    Call PLL_ProjectsInfo_JP_EXPERIMENTAL
End Sub

Private Sub fraItem_Click()
    Call grd_searchZip_LostFocus
End Sub

Private Sub fraItemTop_Click()
    Call grd_searchZip_LostFocus
End Sub

Private Sub frm_JP_Experimental_DblClick()
    frm_JP_Experimental.Visible = False
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
    
    ms_OldZip1 = ""
    ms_OldZip2 = ""

    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 grdlst_CustomFormatValue(av_Value As Variant, ao_Column As ArmColumn, as_Result As String)
    If ao_Column.Name = "sp_size" Then
        as_Result = Round(CDbl(av_Value), 1)
    End If
End Sub

Private Sub grdlst_RowLoaded(ByVal al_Row As Long)
    If mi_EmbeddedIn = -1 Then
    If GetCodeFromCombo(Cbo_View) = "Vk" Then
        grdlst.LineColor(al_Row) = IIf(grdlst.Data(al_Row, "SP_dateFollowUp") < Date, mt_CstValues.FollowUpColorExpired, mt_CstValues.FollowUpColor)
    End If
    End If
End Sub

Private Sub RefreshFollowUpInfo()
    Dim ll_Cursor As Long
    
    ' init title to display number of expired and folllowUp projects
    ll_Cursor = mo_ArmDb.OpenSQL(ParamReqReplace1("CapTVA_Project_gridk1_count $today$, $folowUpMaxDate$, $uid$"))  'tvitems.CountRequests)
    Dim ll_expired As Long
    Dim ll_toFollow As Long
    If Not mo_ArmDb.EOF(ll_Cursor) Then
        ll_expired = mo_ArmDb.GetFields(ll_Cursor, "expired")
        ll_toFollow = mo_ArmDb.GetFields(ll_Cursor, "toFollow")
    End If
    Call mo_ArmDb.Close(ll_Cursor)
    Dim ls_Msg As String
    ls_Msg = Replace(ms_expiredMsg, "$expired$", CStr(ll_expired))
    ls_Msg = Replace(ls_Msg, "$follow$", CStr(ll_toFollow))
    ls_Msg = Replace(ls_Msg, "$days$", (md_folowUpMaxDate - Date))
    lbl_ListFilter.Caption = ls_Msg

End Sub

Private Sub RefreshFollowUp()
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:RefreshFollowUp"
    #End If
    If GetCodeFromCombo(Cbo_View) = "Vk" Then
        ' My Projects to followup? => load data into grid if possible
        Call RefreshFollowUpInfo
        grdlst.Requests = tvitems.GridRequests(0)
        If grdlst.Execute = False Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:RefreshFollowUp", "Requests=", grdlst.Requests
        End If
    Else
        lbl_ListFilter.Caption = GetCurrentFiltersDescription
    End If
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:RefreshFollowUp"
    #End If
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:RefreshFollowUp"
End Sub

' test if project is visible for user after changes in detail
Private Function ProjectVisibleForUser(ByVal as_spKey As String, ByVal as_viewFilterType As String) As Boolean
    Dim ls_Request As String
    Dim ls_Result As String
    Dim lb_retVal As Boolean
    lb_retVal = True
    If as_viewFilterType = "Vk" Then
        ls_Request = ParamReqReplace1("CapTvA_Project_gridk1_test '" & as_spKey & "', $folowUpMaxDate$, $uid$")
        If ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False) Then
            lb_retVal = (CLng(ls_Result) > 0)
        End If
    End If
    ProjectVisibleForUser = lb_retVal
End Function

' tak 298.8 end

Private Sub cbo_View_ComboItemSelected()
Dim ls_Key As String

    On Error GoTo Trace_Err
    Call LockScreen(True)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cbo_view_Click"
    #End If
    
    ' mark if this is InitTreeview
    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
' task 298.8. begin
    ' disable/enable filters
    Call EnableFilters(True)
    ' dis/allow to add new project
    AllowAddNewProject = (GetCodeFromCombo(Cbo_View) <> "Vk")
' task 298.8 end
    If reload_treeview.Visible = True Then GoTo Trace_End
    
    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)
' task 298.8. begin
    If ls_Key <> "" Then
        If GetCodeFromCombo(Cbo_View) = "Vk" Then
            SearchTreeView ls_Key, False, True          ' true will suppress reseting filters is ls_key not in grig
            Call RefreshFollowUpInfo
        Else
            SearchTreeView ls_Key, False, False
            lbl_ListFilter.Caption = GetCurrentFiltersDescription
    End If
    Else
    Call RefreshFollowUp
' tak 298.8 end
    End If


Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:cbo_view_Click"
    #End If
    Call LockScreen(False)
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:cbo_view_Click"
    Call LockScreen(False)
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, "capprj: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, "CapPrj: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, "capprj: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, "capprj:fill_all_record_Click"
    CapMouseOn
End Sub

Sub UnCatch()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:UnCatch"
    #End If
    
    mi_EmbeddedIn = -1
    Call grdlst.DeselectRow

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:UnCatch"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:UnCatch"
    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, "capprj: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, "capprj: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, "capprj:grdlst_ItemSelected"
    CapMouseOn
End Sub


Private Sub opt_active_Click(Index As Integer)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:opt_active_Click", "Index=" & Index
    #End If
    
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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



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, "capprj:opt_date_Click", "Index=" & Index
    #End If
    
    'xyz
    If Index = 0 Then
        cal11.Visible = 0
        cal12.Visible = 0
        cal11.reinit_cal
        cal12.reinit_cal
        cbo_date.Visible = 0
    Else
        cal11.Visible = -1
        cal12.Visible = -1
        cbo_date.Visible = -1
                
        If cbo_date.SelectedItem Is Nothing Then
            cbo_date.FirstBlankItem = False
            cbo_date.Request = "exec captv_date_cbo 'TV_Project_date','" & m_Language & "'"
            cbo_date.Load
            cbo_date.SearchItem "1", 2, 0
        End If
    End If
    
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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

Private Sub opt_sa_Click()

    On Error GoTo Trace_Err
    If mb_InternalInit Then Exit Sub

    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:opt_sa_Click"
    #End If
    
    Call ManageSAType
    
    ms_lastBeforeAS = "X"

    If cbo_Status.SelectedItem Is Nothing Then
        Call ResetStatus(False)
    Else
        Call ResetStatus(cbo_Status.SelectedItem.Key < 23)
    End If

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

Private Sub opt_std_Click()
    
    On Error GoTo Trace_Err
    If mb_InternalInit Then Exit Sub

    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:opt_std_Click"
    #End If
    
    Call ManageSAType
    
    Call Update_SalesReps(True)
    
    ms_lastBeforeAS = ""
    
    If cbo_Status.SelectedItem Is Nothing Then
        Call ResetStatus(False)
    Else
        Call ResetStatus(cbo_Status.SelectedItem.Key < 23)
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:opt_std_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:opt_std_Click"
    CapMouseOn
End Sub

' clear cbo_status and keep selection
Private Sub ResetStatus(ByVal ab_keepSelection As Boolean)
On Error GoTo ErrorHandler
    Dim ll_ss_code As Long
    Dim ls_SS_desc As String
    
    If Not cbo_Status.SelectedItem Is Nothing And ab_keepSelection Then
        ll_ss_code = cbo_Status.SelectedItem.Key
        ls_SS_desc = cbo_Status.SelectedItem.DisplayText
    Else
        ll_ss_code = 0
    End If
    
    Call cbo_Status.Clear
    
    If ll_ss_code <> 0 Then Call cbo_Status.AddItem(Array(ll_ss_code, ls_SS_desc), True)
    
    Exit Sub
ErrorHandler:
    Call ErrorHandler("ResetStatus")
End Sub

Private Sub ManageSAType()
    If opt_std.Value Or opt_as.Value Then
        cbo_SA.Visible = False
        Set cbo_SA.SelectedItem = Nothing
' task 299.2 begin
        cbo_SAType.Visible = False
        lbl_SAType.Visible = False
        Set cbo_SAType.SelectedItem = Nothing
' task 299.2 end
    Else
        cbo_SA.Visible = True
' task 299.2 begin
        cbo_SAType.Visible = True
        lbl_SAType.Visible = True
' task 299.2 end
    End If
End Sub


Private Sub opt_as_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
On Error GoTo Trace_Err
    If cbo_country.SelectedItem Is Nothing Then Exit Sub
    If Not opt_as.Value Then Exit Sub
    
    ' display GEMA reps
    Call ShowGEMARepLink
    
    Exit Sub
Trace_Err:
    CapMouseOn
End Sub

Private Sub opt_As_Click()
On Error GoTo Trace_Err
    If mb_InternalInit Then Exit Sub
    
    CapMouseOff
    
    Call ManageSAType

    CapMouseOn
    Exit Sub
Trace_Err:
    CapMouseOn
End Sub

Private Sub CancelGEMARep()
On Error GoTo Trace_Err
    CapMouseOff
    
    ' restore AS flag into previous state
    If ms_lastBeforeAS = "" Then
        opt_std.Value = True
    ElseIf ms_lastBeforeAS = "X" Then
        opt_sa.Value = True
    End If
    
    CapMouseOn
    Exit Sub
Trace_Err:
    CapMouseOn
End Sub

Private Sub SelectGEMARep(ByVal as_SR_Code As String)
On Error GoTo Trace_Err
    CapMouseOff
    
    ' 1. make curent sales rep (customer) as copy to
    Dim ll_Count As Long
    For ll_Count = 0 To acv_Rep.RoleList("CUST").CheckedCount - 1
        If as_SR_Code <> acv_Rep.RoleList("CUST").CheckedKeys(ll_Count)(0) Then
            If Not acv_Rep.SetItemState("COPY", acv_Rep.RoleList("CUST").CheckedKeys(ll_Count)(0), True) Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 2433, "#Current Sales rep not set as 'Copy to'.")
            End If
        End If
    Next
    
    ' 2. search selected row in chceckview
    If Not acv_Rep.SetItemState("CUST", as_SR_Code, True) Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 2432, "#Selected rep not set as 'Customer'.")
    Else
        txt_spare1.Text = "Y"   ' set flag to indicate manual change of a sales rep
    End If
    
    ms_lastBeforeAS = "A"
    
    If cbo_Status.SelectedItem Is Nothing Then
        Call ResetStatus(False)
    Else
        Dim ll_ss_code As Long
        ll_ss_code = cbo_Status.SelectedItem.Key
        Call ResetStatus(ll_ss_code = 15 Or (ll_ss_code >= 23 And ll_ss_code <= 27)) ' not build is shared between AS and STD
    End If

    CapMouseOn
    Exit Sub
Trace_Err:
    CapMouseOn
End Sub


Private Sub opt_SysSol_Click(Index As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:opt_SysSol_Click", "Index=" & Index
    #End If
    
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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

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, "capprj: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
        
        Case UCase$("Delete")
            If grdlst.Row >= 0 Then DisplayMode = mt_CstValues.DisplayMode_Delete
        
        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
            
            If Not (m_Product = "" 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 Or GetCodeFromCombo(Cbo_View) = "Vk" Then     ' task 298.8
                                Call Item_LocalUpdate
                            Else
                                ReinitTreeViewAfterDelete grdlst, tvitems
                                'tvitems.Refresh
                            End If
                        Case Else
                            Call Item_LocalUpdate
                    End Select

                End If
            
                DisplayMode = mt_CstValues.DisplayMode_List
                If Not (m_Product = "" And m_Action = "") Then RaiseEvent HideGrid(mi_EmbeddedIn)
                b = timer - a
                Call AddToTimeLog(mi_OldDisplayMode, b)
            End If
        
        Case UCase$("Undo")
            'DisplayMode = mt_CstValues.DisplayMode_List
            BlankFields
            If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
                AddInitFields
            Else
                ViewInitFields
                acv_Rep.ComboVisible = True
                acv_Rep.SetVisibleList ("CUST")
                If Not opt_as.Value Then Call Update_SalesReps(True)        ' JN SOM task ... to suppres rep reselection when AS project
            End If
        
        Case UCase$("Tool")
            TransfertProject
            
        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
                chk_Top10E.Enabled = False          ' disable control
                cbo_Priority.Enabled = False
                CheckMemoProject
                CheckCustomerPriority
            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
                chk_Top10E.Enabled = False          ' disable control
                cbo_Priority.Enabled = False
                CheckMemoProject
                CheckCustomerPriority
            End If
        
        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, "capprj:pbItem_action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:pbItem_action"
    CapMouseOn
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, "capprj:pbLst_Action", "as_ActionType=" & as_ActionType
    #End If
    
    Select Case UCase$(as_ActionType)
        ' TASK 298.2
        Case UCase$("Add")
            Select Case mi_EmbeddedIn
                Case -1 ' Main list
                    DisplayMode = mt_CstValues.DisplayMode_Add
                Case mt_CstValues.Tag_Customer
                    If mb_EmbeddedIsDropped Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 2503, "#You are unable to create a link to a Project from a Deleted Customer")
                    Else
                        showProjectLink as_ActionType
                    End If
                Case mt_CstValues.Tag_Contact
                    If mb_EmbeddedIsDropped Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 2504, "#You are unable to link a Deleted Contact to a Project")
                    Else
                        showProjectLink as_ActionType
                    End If
            End Select
            
        Case UCase$("Update")
            If grdlst.Row >= 0 Then
                Select Case mi_EmbeddedIn
                    Case -1 ' Main list
                        DisplayMode = mt_CstValues.DisplayMode_Update
                    
                    Case Else
                        showProjectLink as_ActionType
                End Select
            End If
            
        Case UCase$("Delete")
            If grdlst.Row >= 0 Then
                If mi_EmbeddedIn = -1 Then
                    DisplayMode = mt_CstValues.DisplayMode_Delete
                ElseIf m_Customer <> "" Or m_Contact <> "" Then
                    'liste courte
                    showProjectLink as_ActionType
                End If
            End If
        
        Case UCase$("Refresh")
            If mi_EmbeddedIn <> -1 Then
                grdlst.Refresh
            Else
'  task298.8 begin
                If GetCodeFromCombo(Cbo_View) = "Vk" Then
                    Call RefreshFollowUp
                Else
                grdlst.ClearGrid
                grdlst.Requests = ""
                tvitems.Refresh
            End If
'  task298.8 end
            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.project
            
        Case UCase$("Quit")
            RaiseEvent quit
            
        Case UCase$("Print")
            If grdlst.SelectedCount = 0 Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 921, "#Please, select a line")
            Else
                Report mo_ArmDb, mb_use_framework_connection, ms_ConnectString, m_Language, grdlst, DataTypeEnum.project
            End If
        
        Case UCase$("Patent")
            If grdlst.Rows <> 0 Then
                If Not PLL_ProjectsInfo Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                End If
            End If
        Case UCase$("Memo")
            If grdlst.Rows <> 0 Then
                If Not PLL_ProjectsList Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                End If
            End If
        
        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, "capprj:pbLst_Action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:pbLst_Action"
    CapMouseOn
End Sub

Private Sub pctTvReset_Click()
    
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:pctTvReset_Click"
    #End If
    
    opt_active(0).Value = True
    opt_date(0).Value = True
    opt_SysSol(0).Value = True
    tbsFilters.Tabs(1).Selected = True
    Call Cbo_View.SearchItem("X", "TV_Default", 0, True) ' "TV_Default"
    reload_treeview_Click

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:pctTvReset_Click"
    #End If
    CapMouseOn
End Sub


Private Sub reload_treeview_Click()
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, "capprj:reload_treeview_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")
            GoTo Trace_End
        End If
    End If
    
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    
    ReinitTreeview GetCodeFromCombo(Cbo_View)
    tvitems.Visible = -1
    reload_treeview.Visible = 0
    
    
' task 298.8. begin
    Call RefreshFollowUp
' tak 298.8 end

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

Private Sub cbo_priority_ComboItemSelected()
    If mb_InternalInit Then Exit Sub
    
    Dim ll_PP_Code As Long
    ll_PP_Code = Val(GetCodeFromCombo(cbo_Priority))
    
    If ll_PP_Code = mt_CstValues.PRIORITY_TOP10 Then
        Call SelectCommentTab(chk_Top10E.Value = vbChecked, ll_PP_Code)
    Else
        Call SelectCommentTab(False, ll_PP_Code)
    End If
End Sub

Private Sub chk_Top10E_Click()
    If mb_InternalInit Then Exit Sub
    
    Call cbo_priority_ComboItemSelected
End Sub

Private Sub tbsComment_Click()
    If mb_InternalInit Then Exit Sub
    
    If StrComp(tbsComment.SelectedItem.Key, "tab_Comment", vbTextCompare) = 0 Then
        txt_Top10EComment.Visible = False
        txt_Comment.Visible = True
    Else
        txt_Comment.Visible = False
        txt_Top10EComment.Visible = True
    End If
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, "capprj: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           ' bugfix 19.10.2006

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:tbsFilters_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:tbsFilters_Click"
    CapMouseOn
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, "capprj: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 = False
        grdlst.Requests = tvitems.SelectedNodeRequest
        If grdlst.Execute = False Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:tvItems_NodeClick", "Requests=", 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, "capprj:tvItems_NodeClick"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:tvItems_NodeClick"
    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, "capprj:txt_Zip1_GotFocus"
    #End If
    
    ms_OldZip1 = txt_Zip1.Text
    ms_OldZip2 = txt_Zip2.Text
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:txt_Zip1_GotFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:txt_Zip1_LostFocus"
    #End If
        
    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_Add, mt_CstValues.DisplayMode_Update
                txt_Zip1.Text = UCase(txt_Zip1.Text)
                'If GetDefaultConfigCode("Capture_Cfg", "UseFUllZipRepAssignment") = "1" And txt_zip2.Text = "" Then
                '    txt_zip2.Text = GetDefaultConfigCode("Capture_Cfg", "UseDefaultZip2")
                'End If
                If txt_Zip1.Text <> ms_OldZip1 Then
                    ' TO DO : it's for choose automatically the county in spain
                    'Call SearchAndSelectComboItem(cbo_County, txt_Zip1.Text)
                    Call RefreshSalesReps
                End If
    End Select
    'ckvSalesRep.ZipCode Trim$(txt_Zip1.Text) & Trim$(txt_Zip2.Text)
    
    

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:txt_Zip1_LostFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:txt_Zip2_GotFocus"
    #End If
    
    ms_OldZip1 = txt_Zip1.Text
    ms_OldZip2 = 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, "capprj:txt_Zip2_GotFocus"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:txt_zip2_LostFocus"
    #End If
    
    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_Add, mt_CstValues.DisplayMode_Update
                txt_Zip2.Text = UCase(txt_Zip2.Text)
                If txt_Zip2.Text <> ms_OldZip2 Then
                    Call RefreshSalesReps
                End If
    End Select

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

' Initialization of the component
Public Sub Load_A_COM(ab_root As Boolean)
    
    Dim ll_Cursor, ll_Idx As Integer
    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, "capprj:Load_A_Com", "ab_root = " & ab_root
    #End If
    
    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    frm_JP_Experimental.Visible = (ms_UID = "JPTROVO")
    
    
    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
    
    'to handle Decimal with the local settings
    Dim sBuffer As String
    Dim nBufferLen As Long

    ms_DecimalSeparator = Format(0, ".")

    nBufferLen = 255
    sBuffer = String$(nBufferLen, vbNullChar)
    nBufferLen = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, sBuffer, nBufferLen)
    If nBufferLen > 0 Then
        ms_ThousandSeparator = Left$(sBuffer, nBufferLen - 1)
    End If
    
    Call GetUserRight(m_userRights)

    If (Not m_userRights.CapOfferView) And (tbsEmbedded.Tabs.Count > 4) Then
      Call tbsEmbedded.Tabs.Remove(6)
      Call tbsEmbedded.Tabs.Remove(5)
    End If

    ' init solution system filter and solSys checkbox
    mb_HaveSolSys = (GetDefaultConfigCode("Project_Cfg", "HaveSolSys") = "X")
    fra_SolSys.Visible = mb_HaveSolSys
    chk_sysSol.Visible = mb_HaveSolSys
    lbl_SysSol.Visible = mb_HaveSolSys
' task 299.7 and 299.2 begin
    ' combobox cbo_SS unvisible by default
    cbo_SS.Visible = False
    mb_HaveLevel = (GetDefaultConfigCode("Project_Cfg", "HaveLevel") = "X")
    cbo_Level.Visible = mb_HaveLevel
    lbl_level.Visible = mb_HaveLevel
' task 299.7 and 299.2 end
' task 298.8 begin
    md_folowUpMaxDate = Date + Val(GetDefaultConfigCode("Project_Cfg", "FollowUpDateIncrement"))
' task 298.8 end
    mb_HaveProbability = (GetDefaultConfigCode("Project_Cfg", "HaveProbability") = "X")
    cbo_Probability.Visible = mb_HaveProbability
    lbl_probability.Visible = mb_HaveProbability
    
    ' 24.4.2012 JN to 10 executive comment visible
    mb_top10ExecVisible = (GetDefaultConfigCode("Project_Cfg", "CAP_PRJ_TOP10ECOM_VIS") = "X")
    
    reload_treeview.Picture = LoadResPicture(116, vbResIcon)
    reload_treeview.Visible = False
    
    ms_initTreeview = GetDefaultConfigCode("Project_Cfg", "InitTreeview")
    If ms_initTreeview = "" Then
        ms_initTreeview = "Vk"
    End If
    
    grdlst.Load_A_COM
    tvitems.Load_A_COM
    pblst.Load_A_COM
    pbItem.Load_A_COM
    
    'pblst.DrivenByCapture = True
    'pbitem.DrivenByCapture = True
    
    'ckvSalesRep.Load_A_COM
    cbo_date.Load_A_COM
    Cbo_View.Load_A_COM
    cbo_SA.Load_A_COM
    cbo_clgValue.Load_A_COM
    cbo_projectType.Load_A_COM
    cbo_Priority.Load_A_COM
    cbo_newRenovation.Load_A_COM
    cbo_County.Load_A_COM
    cbo_country.Load_A_COM
    grd_searchZip.Load_A_COM
    cbo_projectDesc.Load_A_COM
    cbo_Status.Load_A_COM
    cbo_currencies.Load_A_COM
    cbo_UOM.Load_A_COM
' task 299.2 begin
    cbo_SAType.Load_A_COM
    cbo_Level.Load_A_COM
' task 299.2 end
' task 299.7 begin
    cbo_SS.Load_A_COM
' task 299.7 end
    cbo_Probability.Load_A_COM
    cbo_ceilFncType.Load_A_COM
    cbo_datasource.Load_A_COM
        
    cbo_SA.FirstBlankItem = False
    cbo_SA.SearchPrefix = " "
    cbo_SA.Request = "cap_strataccount_cbo " & "'" & m_Language & "'"
    cbo_clgValue.FirstBlankItem = False
    cbo_clgValue.SearchPrefix = " "
    cbo_clgValue.Request = "exec Cap_ProjectSize_cbo '" + m_Language + "'"
    cbo_projectType.FirstBlankItem = False
    cbo_projectType.SearchPrefix = " "
    cbo_projectType.Request = "exec cap_projecttype_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    cbo_Priority.FirstBlankItem = False
    cbo_Priority.Request = "exec cap_projectpriority_cbo " & "'" & m_Language & "'"
    cbo_newRenovation.FirstBlankItem = False
    cbo_newRenovation.Request = "exec cap_newrenovation_cbo " & "'" & m_Language & "'"
    cbo_country.FirstBlankItem = False
    cbo_country.Request = "exec countries_cbo7 " & "'" & m_Language & "' ,'" & ms_UID & "'"
    cbo_projectDesc.FirstBlankItem = True
    cbo_projectDesc.SearchPrefix = " "
    cbo_projectDesc.Request = "exec cap_projectdescription_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    cbo_Status.FirstBlankItem = False
    cbo_Status.SearchPrefix = " "
    cbo_Status.Request = "exec cap_salesstatus_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    cbo_currencies.FirstBlankItem = False
    cbo_currencies.SearchPrefix = " "
    cbo_currencies.Request = "exec currencies_cbo " & "'" & m_Language & "'"
    cbo_UOM.FirstBlankItem = False
    cbo_UOM.Request = "exec unit_of_measure_cbo " & "'" & m_Language & "'"
' task 299.2 begin
    cbo_SAType.FirstBlankItem = False
    cbo_SAType.Request = "EXEC Cap_SAType_Lst " & "'" & ms_UID & "','" & m_Language & "'"
    cbo_Level.FirstBlankItem = False
    cbo_Level.Request = "EXEC Cap_ProjectLevel_Lst " & "'" & ms_UID & "','" & m_Language & "'"
' task 299.2 end
' task 299.7 begin
    cbo_SS.FirstBlankItem = False
    cbo_SS.Request = " EXEC Cap_SystemSolutionType_Lst " & "'" & ms_UID & "','" & m_Language & "'"
' task 299.7 end
    cbo_Probability.FirstBlankItem = False
    cbo_Probability.Request = "EXEC Cap_ProjectProbability_cbo '" & ms_UID & "','" & m_Language & "'"
    
    cbo_ceilFncType.FirstBlankItem = False      ' mandatory
    cbo_ceilFncType.Request = "EXEC SOM_ClgFunction_cbo '" & m_Language & "'"
    
    cbo_datasource.Request = "EXEC Cap_Lead_Source_Lst"
    
    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
    
    
    UserControl.ScaleMode = vbPixels
    
    cal_StartDate.opening_toward_top = 1
    cal_clgStartDate.opening_toward_top = 1
    cal_followUpDate.opening_toward_top = 1
    cal_orderExpDate.opening_toward_top = 1

    
    
    PrdValOf.Language = m_Language
' task 299.5 set constantst into PrdValOf
    Set PrdValOf.CstValues = mt_CstValues
    PrdValOf.ConnectString = ms_ConnectString
    Set PrdValOf.ArmDb = mo_ArmDb
    
    Call PrdValOf.Load_A_COM
    
    Set uc_SOMQuoteValOf.CstValues = mt_CstValues
    uc_SOMQuoteValOf.Language_Code = m_Language
    uc_SOMQuoteValOf.U_Code = prg.U_Code
    uc_SOMQuoteValOf.LoginName = prg.LoginName
    Set uc_SOMQuoteValOf.ArmDb = mo_ArmDb
    Call uc_SOMQuoteValOf.Load_A_COM
    mb_quoteValOfInitialized = False
    
    CustOf.Language = m_Language
    Set CustOf.mt_CstValues = mt_CstValues
    CustOf.ConnectString = ms_ConnectString
    Set CustOf.ArmDb = mo_ArmDb
    
    Call CustOf.Load_A_COM
    
    Call acv_Rep.Load_A_COM
    
    ' The checkview !
    Set acv_Rep.ArmDb = mo_ArmDb
    acv_Rep.Driven_By = "Project"
    
    acv_Rep.Common_List_Load = True
    acv_Rep.Type_Of_Key = tkDependant
    acv_Rep.Calling_Key_Fields = "SP_CAPKEY"
    acv_Rep.Link_Key_Fields = "SR_CODE®©RR_CODE"
  
    'Screen csts
    LoadLabels mo_ArmDb, UserControl.Controls, "Cap_Project_Detail", m_Language
    ms_expiredMsg = lbl_ListFilter.Caption      'store message for expired projects task 298.8
    lbl_ListFilter.Caption = ""                 ' default value for filter description task 298.8
    
    Call InitAcvRepsRole
   
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    
    If ab_root = True Then
        'Initialization of treeview and  filters
        Cbo_View.Clear
        Cbo_View.FirstBlankItem = False
        Cbo_View.Request = "exec TreeView_View_t_lst 'Capture_Project'," & "'" & m_Language & "'"
        Cbo_View.Load
        
        Cbo_View.SearchItem ms_initTreeview, "TV_Code", 0 ', "TV_Default"  ' bug55, fix 21.12.2006 JULO
        mb_gridInitializedForFollowUP = (ms_initTreeview <> "Vk")
    Else
        mb_gridInitializedForFollowUP = True
    End If
    
    'init demand
    ls_Request = "exec Cap_ProjectDemand_lst " & "'" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request)
    If ll_Cursor <> 0 Then
        
        If mo_ArmDb.RowCount(ll_Cursor) > 0 Then
            ll_Idx = 0
            ReDim m_demand(mo_ArmDb.RowCount(ll_Cursor) - 1)
            
            While Not mo_ArmDb.EOF(ll_Cursor)
                m_demand(ll_Idx).Id = mo_ArmDb.GetFields(ll_Cursor, "PDE_ID")
                m_demand(ll_Idx).Desc = mo_ArmDb.GetFields(ll_Cursor, "PDE_Desc")
                m_demand(ll_Idx).Min = mo_ArmDb.GetFields(ll_Cursor, "PDE_Min")
                m_demand(ll_Idx).Max = mo_ArmDb.GetFields(ll_Cursor, "PDE_Max")
                
                ll_Idx = ll_Idx + 1
                mo_ArmDb.Next ll_Cursor
            Wend
        End If
    End If
    
    mo_ArmDb.Close (ll_Cursor)
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:Load_A_Com"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Load_A_Com"
    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, "capprj: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_Project
    
    ' 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_Project), "#Project")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Action), "#Action")
        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_Product), "#Product")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_SubProject), "#Sub project")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Offer), "#Offer")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_CapSOMQuote), "#SOM Quote")
        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_Project"
        .tbsEmbedded.Tabs.Item(2).Tag = "tbs_Action"
        .tbsEmbedded.Tabs.Item(3).Tag = "tbs_Customer"
        .tbsEmbedded.Tabs.Item(4).Tag = "tbs_Product"
        .tbsEmbedded.Tabs.Item(5).Tag = "tbs_SubProject"
        .tbsEmbedded.Tabs.Item(6).Tag = "tbs_Offer"
        .tbsEmbedded.Tabs.Item(7).Tag = "tbs_Quote"
        .tbsEmbedded.Tabs.Item(8).Tag = "tbs_Memo"
        .tbsEmbedded.Tabs.Item(8).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, "capprj:FrameWorkInit"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:Unload_A_COM"
    #End If
    
    grdlst.Unload_A_COM
    pblst.Unload_A_COM
    pbItem.Unload_A_COM
    tvitems.Unload_A_COM
    Call acv_Rep.Unload_A_COM
    cbo_date.Unload_A_COM
    Cbo_View.Unload_A_COM
    cbo_SA.Unload_A_COM
    cbo_clgValue.Unload_A_COM
    cbo_projectType.Unload_A_COM
    cbo_Priority.Unload_A_COM
    cbo_newRenovation.Unload_A_COM
    cbo_County.Unload_A_COM
    cbo_country.Unload_A_COM
    grd_searchZip.Unload_A_COM
    
    cbo_projectDesc.Unload_A_COM
    cbo_Status.Unload_A_COM
    cbo_currencies.Unload_A_COM
    cbo_UOM.Unload_A_COM
' task 299.2 begin
    cbo_SAType.Unload_A_COM
    cbo_Level.Unload_A_COM
' task 299.2 end
' task 299.7 begin
    cbo_SS.Unload_A_COM
' task 299.7 end
    cbo_Probability.Unload_A_COM
    cbo_ceilFncType.Unload_A_COM
    

    Call PrdValOf.Unload_A_COM
    Call CustOf.Unload_A_COM
    Call cbo_datasource.Unload_A_COM
    
    ASC_DisconnectFromDB mo_ArmDb, ms_UID, mb_Created

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

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

' 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, "capprj:CptTag_Get"
    #End If
    CptTag = mi_CptTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:EmbeddedIn_Get"
    #End If
    EmbeddedIn = mi_EmbeddedIn
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:EmbedTag_Get"
    #End If
    EmbedTag = mi_EmbedTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:Root_Get"
    #End If
    Root = mb_Root
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj: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, "capprj: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, "capprj:DisplayMode_Get"
    #End If
    DisplayMode = mi_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:DisplayMode_Let", "li_DisplayMode=" & li_DisplayMode
    #End If
    SwapToDisplayMode li_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:DisplayMode_Let"
    #End If
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, "capprj: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, "capprj:SwapToDisplayMode"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:DisplayMode_None"
    #End If
    
   With UserControl
        .fraFilters.Visible = False
        .fraItem.Visible = False
        .fraList.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, "capprj:DisplayMode_None"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:DisplayMode_None"
    CapMouseOn
End Sub
Private Sub AddDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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, "capprj:AddDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:AddDisplay"
    CapMouseOn
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, "capprj: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
        
    acv_Rep.Visible = False
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then
        UpdateInitFields
    Else
        acv_Rep.Calling_Key_Values = m_CurrentKey1
        Call acv_Rep.LoadList
        
        If chk_AMCProjectType.Value = vbChecked Then
            ' refresh counter of a quotes on the project
            Dim ll_Cursor As Long
            ll_Cursor = OpenSQLSafe(mo_ArmDb, "SELECT COUNT(SQT_ID) from Cap_SOM_Quote WHERE drop_flag <> 'X' AND SP_Capkey = '" & m_CurrentKey1 & "'")
            ml_SOM_QUOTE_COUNT = mo_ArmDb.GetFields(ll_Cursor, 0)
            Call mo_ArmDb.Close(ll_Cursor)
            ll_Cursor = 0
        End If
        
        Call SelectCommentTab(chk_Top10E.Value = vbChecked, Val(GetCodeFromCombo(cbo_Priority)))
    End If
    Update_Resize
' task 299.5 begin
    txt_Size.Locked = (CStr(Tools.GetCodeFromCombo(cbo_Status)) = "13")      ' it depends of status
' task 299.5 end
    
    If ml_SOM_QUOTE_COUNT > 0 Then
        opt_std.Enabled = False
        opt_as.Enabled = False
        opt_sa.Enabled = False
    End If

    
    Call acv_Rep.SetVisibleList("CUST")
    acv_Rep.ComboVisible = True
    
    If Not opt_as.Value Then Call Update_SalesReps(True)        ' JN SOM task ... to suppres rep reselection when AS project
    acv_Rep.Visible = True
    
    txt_Desc.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:UpdateDisplay"
    #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:UpdateDisplay"
    CapMouseOn
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, "capprj: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
    chk_Top10E.Enabled = False          ' diable control
    cbo_Priority.Enabled = False
    Delete_Resize

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

Private Sub View_EnableControls()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:View_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    
    btn_statHist.Enabled = True

    txt_PrjKey.Enabled = True
    lbl_PrjKey.Enabled = True
' task 299.3 begin
    txt_Comment.Enabled = True
    txt_Comment.Locked = True
' task 299.3 end

    tbsComment.Enabled = True
    txt_Top10EComment.Enabled = True
    txt_Top10EComment.Locked = True
    
' task 299.5 begin
    txt_Size.Locked = False     ' it should depend of status
' task 299.5 end
    grd_searchZip.Visible = False
    btn_pickZip.Enabled = False


Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:View_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:View_EnableControls"
    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, "capprj: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
        ViewInitFields
        chk_Top10E.Enabled = False          ' disable control
        cbo_Priority.Enabled = False
        ViewLoad
        View_Resize
        
        ms_View_Key = txt_PrjKey.Text
        CheckMemoProject
        CheckCustomerPriority
    Else
        View_EnableControls
        View_Resize
        DrawMainGrid
        Call SearchTreeView(ms_View_Key, False)
        If ms_View_Key <> ms_View_Key Then
            ViewLoad
            ViewInitFields
            chk_Top10E.Enabled = False          ' disable control
            cbo_Priority.Enabled = False
            CheckMemoProject
            CheckCustomerPriority
        End If
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ViewDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ViewDisplay"
    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, "capprj: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, "capprj:ViewLoad"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ViewLoad"
    CapMouseOn
End Sub

Private Sub ShortListDisplay(ByVal ls_Params As String)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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, "capprj:ShortListDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:tbsEmbedded_Click"
    #End If
    
    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 ' We watch the item info
            If mi_EmbeddedIn <> -1 Then
                 RaiseEvent SwitchToView(mt_CstValues.View_Medium)
            End If
            .fraItemBottom.Visible = True
        Else    ' We watch link
            .fraItemBottom.Visible = False
            If mi_EmbeddedIn <> -1 Then
                If (li_Key = mt_CstValues.Tag_Memo) Or (li_Key = mt_CstValues.Tag_File) Or (li_Key = mt_CstValues.Tag_SubProject) Or (li_Key = mt_CstValues.Tag_Offer) Or (li_Key = mt_CstValues.Tag_CapSOMQuote) Then
                    RaiseEvent SwitchToView(mt_CstValues.View_Medium)
                Else
                    RaiseEvent SwitchToView(mt_CstValues.View_Full)
                End If
            End If
            mi_EmbedTag = li_Key
            RaiseEvent Catch(mi_EmbedTag, m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2 & IIf(mi_EmbedTag = mt_CstValues.Tag_Product Or mi_EmbedTag = mt_CstValues.Tag_CapSOMQuote Or mi_EmbedTag = mt_CstValues.Tag_Customer, CH_LDELIMIT & cbo_country.SelectedItem.Key & CH_LDELIMIT & cbo_Status.SelectedItem.Key, ""))
        End If
    End With

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:tbsEmbedded_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:tbsEmbedded_Click"
    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, "capprj: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, "capprj:LongListDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:LongListDisplay"
    CapMouseOn
End Sub
Private Sub LongList_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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 - (4 * mt_CstValues.Frm_Spacing)
        .pblst.Refresh
        If GetCodeFromCombo(Cbo_View) = "Vk" Then AllowAddNewProject = False    ' task 298.8 end
        
        .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 + 60
        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 EnableFilters(True)    ' task 298.8
    'Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, true) task 298.8
    'Call ControlsEnable(UserControl.Controls, UserControl.fra_active, True) task 298.8
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:LongList_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:LongList_Resize"
    CapMouseOn
End Sub

Private Sub Add_Enablecontrols()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:Add_Enablecontrols"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    
    btn_statHist.Enabled = False

    txt_ClgSpecif.Enabled = False
    
    lbl_dateEntered.Enabled = False
    txt_DateEntered.Enabled = False
    lbl_CreatedBy.Enabled = False
    txt_CreatedBy.Enabled = False
    lbl_lastUpdated.Enabled = False
    txt_lastUpdated.Enabled = False
    lbl_UpdatedBy.Enabled = False
    txt_updatedBy.Enabled = False
    cbo_UOM.Enabled = False
    opt_as.Enabled = False
' task 299.3 begin
    txt_Comment.Locked = False
    txt_Top10EComment.Locked = False
' task 299.3 end
' task 299.5 begin
    txt_Size.Locked = False     ' it should depend of status
' task 299.5 end
    grd_searchZip.Visible = False
    btn_pickZip.Enabled = True

    chk_Top10E.Enabled = False
    tbsComment.Visible = False
    
    txt_Top10EComment.Visible = False
    txt_Comment.Visible = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:Add_Enablecontrols"
    #End If
    CapMouseOn
    Exit Sub

Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Add_Enablecontrols"
    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, "capprj: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)
        
        
        .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
        fraItem.Zorder
        
    End With

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


Private Sub Update_EnableControls()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:Update_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    
    txt_ClgSpecif.Enabled = False
    lbl_dateEntered.Enabled = False
    txt_DateEntered.Enabled = False
    lbl_CreatedBy.Enabled = False
    txt_CreatedBy.Enabled = False
    lbl_lastUpdated.Enabled = False
    txt_lastUpdated.Enabled = False
    lbl_UpdatedBy.Enabled = False
    txt_updatedBy.Enabled = False
    cbo_UOM.Enabled = False
    opt_as.Enabled = False
' task 299.3 begin
    txt_Comment.Locked = False
' task 299.3 end
    txt_Top10EComment.Locked = False
' task 299.5 begin
    txt_Size.Locked = False     ' it should depend of status
' task 299.5 end
    grd_searchZip.Visible = False
    btn_pickZip.Enabled = True
    

'    chk_AMCProjectType.Enabled = False      ' disable to edit type of project

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:Update_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Update_EnableControls"
    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, "capprj: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)
        
        .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
        
        .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 = False
        .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, "capprj:Update_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Update_Resize"
    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, "capprj: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)
        
        .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, "capprj:Delete_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Delete_Resize"
    CapMouseOn
End Sub

Private Sub Delete_EnableControls()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:Delete_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    
    btn_statHist.Enabled = True
    
    txt_PrjKey.Enabled = True
    lbl_PrjKey.Enabled = True
    
' task 299.3 begin
    txt_Comment.Enabled = True
    txt_Comment.Locked = True
' task 299.3 end
    tbsComment.Enabled = True
    txt_Top10EComment.Enabled = True
    txt_Top10EComment.Locked = True
' task 299.5 begin
    txt_Size.Locked = False     ' it should depend of status
' task 299.5 end
    grd_searchZip.Visible = False


Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:Delete_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Delete_EnableControls"
    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, "capprj: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)
        
        .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
        
        .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
                    
        'If .Height > mt_CstValues.View_Full_Height Then
        '    .fraItemBottom.Height = .Height - mt_CstValues.View_Emb_Top - mt_CstValues.View_ToolBar_Height
        'Else
            .fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        'End If
        
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Visible = True
        
        .fraItem.Visible = True
        .fraItem.Zorder
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
        
    End With
    Call EnableFilters(False)    ' task 298.8
    'Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, False)   task 298.8
    'Call ControlsEnable(UserControl.Controls, UserControl.fra_active, False)   task 298.8

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

Private Sub ShortList_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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
        If GetCodeFromCombo(Cbo_View) = "Vk" Then AllowAddNewProject = False    ' task 298.8 end
        
        .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, "capprj:ShortList_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj: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, "capprj:Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj: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
    
    chk_Top10E.Value = vbUnchecked
    
    opt_std.Value = True
    opt_as.Value = False
    opt_sa.Value = False
    cbo_SA.Visible = False
    cbo_SAType.Visible = False
    lbl_SAType.Visible = False
        
    acv_Rep.Calling_Key_Values = ""
    acv_Rep.ComboVisible = True
    acv_Rep.Init
    
    txt_duration.Text = "0"
    
    Call acv_Rep.SetVisibleList("CUST")
    
    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
    
    If txt_Zip1.Text <> "" Then
        Update_SalesReps (False)
    End If
    
    Call SelectCommentTab(chk_Top10E.Value = vbChecked, Val(GetCodeFromCombo(cbo_Priority)))
            
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj: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, "capprj:BlankFields"
    #End If
    mb_InternalInit = True

    'Ici on vire le contenu des champs
    opt_std.Value = False
    opt_as.Value = False
    opt_sa.Value = False
    
    txt_DateEntered = ""
    txt_lastUpdated = ""
    
    txt_Desc.Text = ""
    txt_Address1.Text = ""
    txt_address2.Text = ""
    txt_Town.Text = ""
    txt_Zip1.Text = ""
    txt_Zip2.Text = ""
    txt_Size.Text = ""
    txt_ClgSpecif.Text = ""
    txt_projectValue.Text = ""
    txt_spare1.Text = ""
    chk_sysSol.Value = vbUnchecked
    chk_AMCProjectType.Value = vbUnchecked
    txt_spare3.Text = ""
    txt_spare4.Text = ""
    txt_PrjKey.Text = ""
    txt_CreatedBy.Text = ""
    txt_updatedBy.Text = ""
'    txt_ceilingvalue.Text = ""
    txt_Comment.Text = ""
    txt_Top10EComment.Text = ""
    ms_MEMCodeExec = ""
    txt_AMCProjectNo.Text = ""
    txt_duration.Text = ""
    txt_I5No.Text = ""
    cal_StartDate.reinit_cal
    cal_clgStartDate.reinit_cal
    cal_followUpDate.reinit_cal
    cal_orderExpDate.reinit_cal
    
    cbo_County.Clear
    ms_OldCodeCountry = ""
    cbo_County.Request = ""
    cbo_country.Clear
    Call grd_searchZip.ClearGrid
    cbo_clgValue.Clear
    cbo_projectType.Clear
    cbo_projectDesc.Clear
    cbo_Priority.Clear
    cbo_Status.Clear
    cbo_newRenovation.Clear
    cbo_UOM.Clear
    cbo_currencies.Clear
    cbo_SA.Clear
' task 299.2 begin
    cbo_SAType.Clear
    cbo_Level.Clear
' task 299.2 end
' task 299.7 begin
    cbo_SS.Clear
' task 299.7 end
    cbo_Probability.Clear
    cbo_ceilFncType.Clear
    cbo_datasource.Clear
    txt_External_Id.Text = ""
    
    acv_Rep.Init
    acv_Rep.SetVisibleList "Main"
    acv_Rep.ComboVisible = False
    
    If mi_DisplayMode = mt_CstValues.DisplayMode_View Then
        GoToTab1
    End If

    PrdValOf.RAZ
    CustOf.RAZ
    
    txt_spare1.Text = "N"
    'clear highlight
    Call UpdateTabInfo(tbsEmbedded, SetLstKey(mt_CstValues.Tag_Memo), False, 0)
    Call UpdateTabInfo(tbsEmbedded, SetLstKey(mt_CstValues.Tag_Customer), False)
    '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, "capprj: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, "capprj: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, "capprj:DisplayDefaultValues"
    #End If
    
    If p_DefaultValuesLoaded = False Then
        If mi_EmbedTag = mt_CstValues.Tag_SPA Then
            p_DefaultValuesCount = GetScreenDefaultValues(mo_ArmDb, ms_UID, m_Language, "Cap_Project_Detail_SPA", p_DefaultValues)
        Else
        p_DefaultValuesCount = GetScreenDefaultValues(mo_ArmDb, ms_UID, m_Language, "Cap_Project_Detail", p_DefaultValues)
        End If
        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, "Capprj:DisplayDefaultValues", "Request=" & ls_req
            GoTo Trace_End
        End If
        
        If mi_EmbedTag = mt_CstValues.Tag_SPA Then
            cal_clgStartDate.date_courte = CDate(mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")) + Val(GetDefaultConfigCode("Project_Cfg", "CeilingStartDateIncrement_SPA"))
            cal_followUpDate.date_courte = CDate(mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")) + Val(GetDefaultConfigCode("Project_Cfg", "FollowUpIncrement_SPA"))
        Else
        cal_followUpDate.date_courte = CDate(mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")) + Val(GetDefaultConfigCode("Project_Cfg", "FollowUpIncrement"))
        End If
        
        mo_ArmDb.Close ll_Cursor
            
        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, "Capprj:DisplayDefaultValues", "Request=" & ls_req
            GoTo Trace_End
        End If
            
        ms_CreationDate = mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")
        txt_DateEntered.Text = ms_CreationDate
        txt_lastUpdated.Text = ms_CreationDate
    
        txt_CreatedBy.Text = ms_UID
        txt_updatedBy.Text = ms_UID
    
    End If

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:DisplayDefaultValues"
    CapMouseOn
End Sub

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:ViewInitFields"
    #End If
    
    mb_InternalInit = True
    
    mb_ZipCorrect = 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
    
    'Affectation aux clés membres
    CurrentKey(1) = Thekey1
    CurrentKey(2) = Thekey2
    
    'Try connexion
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
        
    TheRequest = "exec sales_project_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, "CapPrj:ViewInitFields", "Request=" & TheRequest
        GoTo Trace_End
    End If
    p_iCon = mo_ArmDb.GetFields(ll_Cursor, "iConcurrency")

    ms_lastBeforeAS = mo_ArmDb.GetFields(ll_Cursor, "SP_SAFlag")

    If mo_ArmDb.GetFields(ll_Cursor, "SP_SAFlag") = "X" Then
        opt_std.Value = False
        opt_as.Value = False
        opt_sa.Value = True
    ElseIf mo_ArmDb.GetFields(ll_Cursor, "SP_SAFlag") = "A" Then
        opt_std.Value = False
        opt_as.Value = True
        opt_sa.Value = False
    Else
        Debug.Assert (mo_ArmDb.GetFields(ll_Cursor, "SP_SAFlag") = "")
        opt_std.Value = True
        opt_as.Value = False
        opt_sa.Value = False
    End If
    
    If opt_sa.Value = True Then
        cbo_SA.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "SA_code")), mo_ArmDb.GetFields(ll_Cursor, "SA_desc")), True
        cbo_SA.Visible = True
' task 299.2 begin
        cbo_SAType.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "SAT_code")), mo_ArmDb.GetFields(ll_Cursor, "SAT_desc")), True
        cbo_SAType.Visible = True
        lbl_SAType.Visible = True
' task 299.2 end
    Else
        cbo_SA.Clear
        cbo_SA.Visible = False
' task 299.2 begin
        cbo_SAType.Clear
        cbo_SAType.Visible = False
        lbl_SAType.Visible = False
' task 299.2 end
    End If
    
    txt_PrjKey.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_CapKey")
    txt_Desc.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_desc")
    txt_Address1.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_addr1")
    txt_address2.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_addr2")
    txt_Town.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_town")
    txt_Zip1.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_zip1")
    txt_Zip2.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_zip2")
    txt_Size.Text = Round(CDbl(mo_ArmDb.GetFields(ll_Cursor, "SP_size")), 1)
'    txt_ceilingvalue.Text = Round(CDbl(mo_ArmDb.GetFields(ll_Cursor, "SP_clgValue")), 1)
    txt_Comment.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_Comment")
    txt_spare1.Text = mo_ArmDb.GetFields(ll_Cursor, "spare1_varchar")
    chk_sysSol.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "spare2_varchar") = "X", vbChecked, vbUnchecked)
    chk_AMCProjectType.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "AMCProjectNumber") = "", vbUnchecked, vbChecked)
' task 299.7 begin
    cbo_SS.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "SST_code")), mo_ArmDb.GetFields(ll_Cursor, "SST_desc")), True
' task 299.7 end
'    txt_spare3.Text = mo_ArmDb.GetFields(ll_Cursor, "spare3_real")
    txt_spare4.Text = mo_ArmDb.GetFields(ll_Cursor, "spare4_real")
    txt_AMCProjectNo.Text = mo_ArmDb.GetFields(ll_Cursor, "AMCProjectNumber")
    txt_duration.Text = mo_ArmDb.GetFields(ll_Cursor, "AMCProjDuration")
    txt_I5No.Text = mo_ArmDb.GetFields(ll_Cursor, "AMCI5Ref")
    
    cal_StartDate.date_courte = mo_ArmDb.GetFields(ll_Cursor, "sp_startdate")
    cal_clgStartDate.date_courte = mo_ArmDb.GetFields(ll_Cursor, "sp_ceilingstartingdate")
    cal_followUpDate.date_courte = mo_ArmDb.GetFields(ll_Cursor, "sp_datefollowup")
    cal_orderExpDate.date_courte = mo_ArmDb.GetFields(ll_Cursor, "AMCExpiryOrderDate")
    
    cbo_country.AddItem Array(CStr(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(CStr(mo_ArmDb.GetFields(ll_Cursor, "CTY_code")), CStr(mo_ArmDb.GetFields(ll_Cursor, "CTY_desc"))), True
    
    cbo_clgValue.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "PSZ_code")), mo_ArmDb.GetFields(ll_Cursor, "PSZ_desc")), True
    cbo_projectType.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "PT_code")), mo_ArmDb.GetFields(ll_Cursor, "PT_desc")), True
    cbo_projectDesc.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "PD_code")), mo_ArmDb.GetFields(ll_Cursor, "PD_desc")), True
    cbo_Priority.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "PP_code")), mo_ArmDb.GetFields(ll_Cursor, "PP_desc")), True
'task 18/4/12
'    chk_Top10E.value = IIf(mo_ArmDb.GetFields(ll_Cursor, "spare7_real") = 1, vbChecked, vbUnchecked)
    txt_Top10EComment.Text = mo_ArmDb.GetFields(ll_Cursor, "Top10E_Comment")
    ms_MEMCodeExec = mo_ArmDb.GetFields(ll_Cursor, "Top10E_MEM_Code")
    Call SelectCommentTab(mo_ArmDb.GetFields(ll_Cursor, "spare7_real") = 1, mo_ArmDb.GetFields(ll_Cursor, "PP_code"))
'task 18/4/12

    cbo_Status.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "SS_code")), mo_ArmDb.GetFields(ll_Cursor, "SS_desc")), True
    cbo_newRenovation.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "NR_code")), mo_ArmDb.GetFields(ll_Cursor, "NR_desc")), True
    cbo_UOM.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "UM_code")), mo_ArmDb.GetFields(ll_Cursor, "UM_desc")), True
    cbo_currencies.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "CURR_code")), mo_ArmDb.GetFields(ll_Cursor, "CURR_desc")), True
' task 299.2 begin
    cbo_Level.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "LEV_code")), mo_ArmDb.GetFields(ll_Cursor, "LEV_desc")), True
' task 299.2 end
    cbo_Probability.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "spare3_real")), mo_ArmDb.GetFields(ll_Cursor, "PPB_Desc")), True

    cbo_ceilFncType.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "AMCCF_Code")), mo_ArmDb.GetFields(ll_Cursor, "Cf_desc")), True
    
    cbo_datasource.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "LSRC_Code")), mo_ArmDb.GetFields(ll_Cursor, "LSRC_Desc")), True

    txt_projectValue.Text = Round(CDbl(mo_ArmDb.GetFields(ll_Cursor, "SP_projectvalue")), 1)     ' JN 26.11.2012 rounding
    If txt_projectValue.Text = "0" And (cbo_currencies.SelectedItem.DisplayText = "") Then txt_projectValue.Text = ""
    txt_External_Id.Text = mo_ArmDb.GetFields(ll_Cursor, "external_id")
    
    p_OldCodeStatus = mo_ArmDb.GetFields(ll_Cursor, "SS_code")
    ml_OriginalStatusCode = Val(p_OldCodeStatus)
    mb_OriginalAMCExists = (mo_ArmDb.GetFields(ll_Cursor, "AMCProjectNumber") <> "")

    txt_DateEntered.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "Z_Creation"))
    ms_CreationDate = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "Z_Creation"))
    txt_lastUpdated.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "Z_Last_Upd"))
    txt_CreatedBy.Text = mo_ArmDb.GetFields(ll_Cursor, "Z_Creator")
    txt_updatedBy.Text = mo_ArmDb.GetFields(ll_Cursor, "Z_last_upd_user")
    
    Load_ClgSpecief

    acv_Rep.Visible = False
    acv_Rep.Calling_Key_Values = Thekey1
    acv_Rep.ComboVisible = False
    Call acv_Rep.LoadList
    Call acv_Rep.SetVisibleList("main")
    acv_Rep.Visible = True
    
    Call showAMC(chk_AMCProjectType.Value = vbChecked)
    ml_SOM_QUOTE_COUNT = mo_ArmDb.GetFields(ll_Cursor, "SOM_QUOTE_COUNT")

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj: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, "capprj:ViewInitFields"
    CapMouseOn
End Sub


Private Sub showAMC(ByVal ab_Visible As Boolean)
    On Error GoTo Trace_Err
        
    lbl_AMCProjectNo.Visible = ab_Visible
    txt_AMCProjectNo.Visible = ab_Visible
'    lbl_orderExpiry.Visible = ab_Visible
'    cal_orderExpDate.Visible = ab_Visible
    lbl_ceilFncType.Visible = ab_Visible
    cbo_ceilFncType.Visible = ab_Visible
'    lbl_prjDuration.Visible = ab_Visible
'    txt_duration.Visible = ab_Visible
'    lbl_inWeeks.Visible = ab_Visible
    lbl_I5No.Visible = ab_Visible
    txt_I5No.Visible = ab_Visible

    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:showAMC"
End Sub
Private Sub cbo_status_ComboItemSelected()

    On Error GoTo Trace_Err
    'CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:cbo_status_Click"
    #End If
    
    ' It seems that somes events are not fired at the good time
    If mb_StatusNotCheck Then
        mb_StatusNotCheck = False
        GoTo Trace_End
    End If
    
    If m_CurrentKey1 <> "" Then     ' also filter add mode
' task 299.5    fixed if go from completed to completed
        If CStr(GetCodeFromCombo(cbo_Status)) = "13" And p_OldCodeStatus <> "13" Then  ' complete
           
           Call ProjectValidation
           'CHANGE TODAY
             'If Not ProjectValidation Then
             '   mb_StatusNotCheck = True
             '   cbo_status.SearchItem p_OldCodeStatus, 0, 0
             '   GoTo Trace_End
            'End If
            'End If
        ElseIf (CStr(GetCodeFromCombo(cbo_Status)) = "24" And p_OldCodeStatus <> "24") Or _
                (CStr(GetCodeFromCombo(cbo_Status)) = "25" And p_OldCodeStatus <> "25") Or _
                (CStr(GetCodeFromCombo(cbo_Status)) = "26" And p_OldCodeStatus <> "26") Then   ' 24 .. complete AS, 25 .. order AS, 26 .. onSite AS
            
            If ml_SOM_QUOTE_COUNT > 0 Then
                Call SOMQuoteValidation
            Else
                Call ASC_SendMessage(mo_ArmDb, m_Language, 2435, "#No qoute is linked to a project!")
                cbo_Status.SearchItem p_OldCodeStatus, 0, 0
            End If
        Else
            p_OldCodeStatus = GetCodeFromCombo(cbo_Status)
        End If
' task 299.5 begin
        ' disable to change project size if status is "Completed"
        txt_Size.Locked = (CStr(GetCodeFromCombo(cbo_Status)) = "13")
' task 299.5 end
    End If
    'p_OldCodeStatus = GetCodeFromCombo(cbo_status)

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

Private Sub ReinitTreeview(as_View As String)
Dim ll_Cursor As Long
Dim TheRequest As String
Dim li_rowCount As Integer
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
   
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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 'Project', '" & 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, "CapPrj: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"
        mo_ArmDb.Close ll_Cursor
        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, "capprj: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, "capprj: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, "capprj:ParamReqReplace", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    'ls_Request = Replace(ls_Request, "$opt$", "'" & opt_active(WhichOptIsTrue(opt_active, 3)).Tag & "'")
    
    ' replace solution system - not used in count requests fo the moment
    If opt_SysSol(0).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "NULL")
    If opt_SysSol(1).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "'X'")
    If opt_SysSol(2).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "''")
    
    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 & "'")
    
    ParamReqReplace = ls_Request
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ParamReqReplace", "Result=" & ParamReqReplace
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ParamReqReplace"
    CapMouseOn
End Function

Private Function ParamReqReplace1(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, "capprj:ParamReqReplace1", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ PATCH JBP
    PatchTag = opt_active(WhichOptIsTrue(opt_active, 3)).Tag
    If UCase$(PatchTag) = UCase$("Archived") Then PatchTag = "Archive"
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    ls_Request = Replace(ls_Request, "$opt$", cas_all("'" & PatchTag & "'"))
    
    ' replace solution system
    If opt_SysSol(0).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "NULL")
    If opt_SysSol(1).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "'X'")
    If opt_SysSol(2).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "''")

    Dim ls_Code
    
    ls_Code = GetCodeFromCombo(Cbo_View)
    
    If opt_date(1).Value = True Then
        Select Case cbo_date.SelectedItem.Key
            Case 1:
                ls_Request = Replace(ls_Request, "$dd_ent$", cas_all("'" & cal11.date_us & "'"))
                ls_Request = Replace(ls_Request, "$df_ent$", cas_all("'" & cal12.date_us & "'"))
                If (ls_Code = "Vs" Or ls_Code = "Vr") Then
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV0_")
                Else
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV1_")
                End If
            Case 2:
                ls_Request = Replace(ls_Request, "$dd_upd$", cas_all("'" & cal11.date_us & "'"))
                ls_Request = Replace(ls_Request, "$df_upd$", cas_all("'" & cal12.date_us & "'"))
                If (ls_Code = "Vs" Or ls_Code = "Vr") Then
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV0_")
                Else
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV2_")
                End If
            Case 3:
                ls_Request = Replace(ls_Request, "$dd_fol$", cas_all("'" & cal11.date_us & "'"))
                ls_Request = Replace(ls_Request, "$df_fol$", cas_all("'" & cal12.date_us & "'"))
                If (ls_Code = "Vs" Or ls_Code = "Vr") Then
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV0_")
                Else
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV3_")
                End If
            Case 4:
                ls_Request = Replace(ls_Request, "$dd_clg$", cas_all("'" & cal11.date_us & "'"))
                ls_Request = Replace(ls_Request, "$df_clg$", cas_all("'" & cal12.date_us & "'"))
                If (ls_Code = "Vs" Or ls_Code = "Vr") Then
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV0_")
                Else
                    ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV4_")
                End If
        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, "$dd_upd$", "Null")
    ls_Request = Replace(ls_Request, "$df_upd$", "Null")
    ls_Request = Replace(ls_Request, "$dd_fol$", "Null")
    ls_Request = Replace(ls_Request, "$df_fol$", "Null")
    ls_Request = Replace(ls_Request, "$dd_clg$", "Null")
    ls_Request = Replace(ls_Request, "$df_clg$", "Null")
    ls_Request = Replace(ls_Request, "$SA$", cas_all("'" & tbsFilters.SelectedItem.Key & "'"))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
'task 298.8 begin
    ' new placeholder for special grid
    ls_Request = Replace(ls_Request, "$folowUpMaxDate$", "'" & Format(md_folowUpMaxDate, "MM\/DD\/YYYY") & "'")
    ls_Request = Replace(ls_Request, "$today$", "'" & Format(Date, "MM\/DD\/YYYY") & "'")
'task 298.8 end
    
    ParamReqReplace1 = ls_Request
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ParamReqReplace1", "Result=" & ParamReqReplace1
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj: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, "capprj:ParamReqReplace2", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ PATCH JBP
    PatchTag = opt_active(WhichOptIsTrue(opt_active, 3)).Tag
    If UCase$(PatchTag) = UCase$("Archived") Then PatchTag = "Archive"
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    ls_Request = Replace(ls_Request, "$opt$", cas_all("'" & PatchTag & "'"))
    
    ' replace solution system
    If opt_SysSol(0).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "NULL")
    If opt_SysSol(1).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "'X'")
    If opt_SysSol(2).Value Then ls_Request = Replace(ls_Request, "$sys_sol$", "''")
    
    
    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 & "'")
    
    
    ParamReqReplace2 = ls_Request
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ParamReqReplace2", "Result=" & ParamReqReplace2
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ParamReqReplace2"
    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, "capprj: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, "capprj:WhichOptIsTrue", "Result=" & WhichOptIsTrue
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:WhichOptIsTrue"
    CapMouseOn
End Function

Private Sub ListCustomerOf(ACustomerkey1 As String, ACustomerkey2 As String)
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, "capprj:ListCustomerOf", "ACustomerkey1=" & ACustomerkey1, "ACustomerkey2=" & ACustomerkey2
    #End If
    
    If Not (ACustomerkey1 <> "" And ACustomerkey2 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = False
    
    la_Columns(0) = "sp_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sp_capkey" & CH_LDELIMIT & "sp_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(2) = "sp_desc" & CH_LDELIMIT & "2200" & 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 & "1000" & 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"
    la_Columns(8) = "SA" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_SAFlag" & CH_LDELIMIT & "SA"
    la_Columns(9) = "PC_installatorFlag" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PC_installatorFlag" & CH_LDELIMIT & "PC_installatorFlag"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ProjectOfCustomer_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_ProjectCompany_t_lst '" & ACustomerkey1 & "','" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:ListCustomerOf", "Requests=", grdlst.Requests
    End If

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

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj: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) = "sp_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sp_capkey" & CH_LDELIMIT & "sp_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"
    
    grdlst.SetColumns la_Columns
    
'    grdlst.ColMapString = "FIELD=00 COL=0 WIDTH=0 KEY1=YES" 'sp_capkey
'    grdlst.ColMapString = "FIELD=01 COL=1 WIDTH=0 KEY2=YES"  'language_code
'    grdlst.ColMapString = "FIELD=02 COL=2 WIDTH=1500"  'sp_desc
    
    grdlst.Requests = "exec Cap_ProjectAction_t_lst '" & AActionKey1 & "','" & AActionKey2 & "','" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:ListActionOf", "Requests=", grdlst.Requests
    End If

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

Private Sub ListProductOf(AProductKey1 As String, AProductKey2 As String, AProductKey3 As String)
Dim TheKeys As Variant
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, "capprj:ListProductOf", "AProductKey1=" & AProductKey1, "AProductKey2=" & AProductKey2, "AProductKey3=" & AProductKey3
    #End If
    
    If Not (AProductKey1 <> "" And AProductKey2 <> "" And AProductKey3 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = False
    
    la_Columns(0) = "sp_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sp_capkey" & CH_LDELIMIT & "sp_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    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 date"
    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"
    
        
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ProjectOfProduct_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_ProductProject_t_lst '" & AProductKey1 & "', '" & AProductKey2 & "', '" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:ListProductOf", "Requests=", grdlst.Requests
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ListProductOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ListProductOf"
    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, "capprj: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) = "sp_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sp_capkey" & CH_LDELIMIT & "sp_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    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 date"
    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"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ProjectOfContact_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_ProjectContact_t_lst '" & AContactKey1 & "', '" & AContactKey2 & "', '" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:ListContactOf", "Requests=", grdlst.Requests
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ListContactOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ListContactOf"
    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, "capprj: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, "capprj: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, "capprj:cas_all"
    CapMouseOn
End Function

Private Sub showProjectLink(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, "capprj:showProjectLink", "as_ActionType=" & as_ActionType
    #End If
    
    Dim ls_Projectkey As String
    Select Case as_ActionType
        Case "Add"
            ls_Projectkey = ""
        Case Else
            ls_Projectkey = grdlst.CurrentKey(0)
            If ls_Projectkey = "" Then GoTo Trace_End
    End Select
    
    Set lo_LinkForm = New LinkForm
    Load lo_LinkForm
    lo_LinkForm.ConnectString = ms_ConnectString
    If mb_use_framework_connection = True Then
        Set lo_LinkForm.ArmDb = mo_ArmDb
    End If
    
    Set lo_LinkForm.mt_CstValues = mt_CstValues
    lo_LinkForm.Language = m_Language
    If as_ActionType <> "Add" Then lo_LinkForm.project = ls_Projectkey
    lo_LinkForm.Customer = m_Customer
    
    lo_LinkForm.contact = m_Contact
    
    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
    
    lo_LinkForm.Unload_A_COM
    Unload lo_LinkForm
    Set lo_LinkForm = Nothing
    grdlst.Refresh
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:showProjectLink"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:showProjectLink"
    If Not lo_LinkForm Is Nothing Then
        lo_LinkForm.Unload_A_COM
        Unload lo_LinkForm
        Set lo_LinkForm = Nothing
    End If
    
    CapMouseOn
End Sub

Private Sub ShowGEMARepLink()
Dim lo_LinkForm As LinkFormGEMARep

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:ShowGEMARepLink", ""
    #End If
    
    Debug.Assert (Not cbo_country.SelectedItem Is Nothing)
    
    Set lo_LinkForm = New LinkFormGEMARep
    Load lo_LinkForm
    Set lo_LinkForm.ArmDb = mo_ArmDb
    lo_LinkForm.Language_Code = m_Language
'    lo_LinkForm.Customer = m_Customer
    
    lo_LinkForm.Load_A_COM
    Call lo_LinkForm.Init_control
    
    CapMouseOn True
    
    Dim ls_SR_Code As String
    
    ls_SR_Code = ""
    If acv_Rep.RoleList("CUST").CheckedCount = 1 Then
        ls_SR_Code = acv_Rep.RoleList("CUST").CheckedKeys(0)(0)
    End If
    
    If lo_LinkForm.Run(cbo_country.SelectedItem.Key, ls_SR_Code) Then
        Call SelectGEMARep(lo_LinkForm.SR_Code)
    Else
        Call CancelGEMARep
    End If
    CapMouseOff True
    
    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, "capprj:ShowGEMARepLink"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ShowGEMARepLink"
    If Not lo_LinkForm Is Nothing Then
        lo_LinkForm.Unload_A_COM
        Unload lo_LinkForm
        Set lo_LinkForm = Nothing
    End If
    
    CapMouseOn

End Sub


Private Sub ShowStatusHistory()
Dim lo_LinkForm As LinkFormSH

    On Error GoTo Trace_Err
    CapMouseOff
    
    Debug.Assert (Not cbo_country.SelectedItem Is Nothing)
    
    Set lo_LinkForm = New LinkFormSH
    Load lo_LinkForm
    Set lo_LinkForm.ArmDb = mo_ArmDb
    lo_LinkForm.Language_Code = m_Language
'    lo_LinkForm.Customer = m_Customer
    
    lo_LinkForm.Load_A_COM
    Call lo_LinkForm.Init_control
    
    CapMouseOn True
    
    Call lo_LinkForm.Run(m_CurrentKey1)
    
    CapMouseOff True
    lo_LinkForm.Unload_A_COM
    Unload lo_LinkForm
    Set lo_LinkForm = Nothing
    
Trace_End:
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not lo_LinkForm Is Nothing Then
        lo_LinkForm.Unload_A_COM
        Unload lo_LinkForm
        Set lo_LinkForm = Nothing
    End If
    
    CapMouseOn

End Sub

Private Function GetCurrentFiltersDescription() As String
    
Dim ls_Buffer       As String
Dim ls_SysSolDesc   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, "capprj:GetCurrentFiltersDescription"
    #End If
    
    If opt_active(0).Value Then ls_Buffer = opt_active(0).Caption
    If opt_active(1).Value Then ls_Buffer = opt_active(1).Caption
    If opt_active(2).Value Then ls_Buffer = opt_active(2).Caption
    If opt_active(3).Value Then ls_Buffer = opt_active(3).Caption

'IMPLEMENT PROCESS T298.3.PR_007
    If mb_HaveSolSys Then
    If opt_SysSol(0).Value Then ls_SysSolDesc = opt_SysSol(0).Caption
    If opt_SysSol(1).Value Then ls_SysSolDesc = opt_SysSol(1).Caption
    If opt_SysSol(2).Value Then ls_SysSolDesc = opt_SysSol(2).Caption
    Else
        ls_SysSolDesc = ""
    End If
'END PROCESS T298.3.PR_007
    
    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
    
'IMPLEMENT PROCESS T298.3.PR_007
    GetCurrentFiltersDescription = ls_Buffer + IIf(mb_HaveSolSys, " , " + ls_SysSolDesc, "") + " , " + ls_Date + " , " + li_SAFlag
'END PROCESS T298.3.PR_007
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:GetCurrentFiltersDescription", "Result=" & GetCurrentFiltersDescription
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:GetCurrentFiltersDescription"
    CapMouseOn
End Function


Private Function GetCurrentFilters() As String
Dim ls_Buffer   As String
Dim ls_SysSol   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, "capprj:GetCurrentFilters"
    #End If
    
    If opt_active(0).Value Then ls_Buffer = ""
    If opt_active(1).Value Then ls_Buffer = "ACTIVE"
    If opt_active(2).Value Then ls_Buffer = "ARCHIVE"
    If opt_active(3).Value Then ls_Buffer = "REFERENCE"
    
    If opt_SysSol(0).Value Then ls_SysSol = "NULL"
    If opt_SysSol(1).Value Then ls_SysSol = "'X'"
    If opt_SysSol(2).Value Then ls_SysSol = "''"
    
    Select Case tbsFilters.SelectedItem.Index
        Case 1
            ls_SA = ""
        Case 2
            ls_SA = "X"
        Case 3
            ls_SA = " "
    End Select
    
    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
    
    GetCurrentFilters = ls_Buffer & CH_LDELIMIT & ls_SA & CH_LDELIMIT & ls_Date1 & CH_LDELIMIT & ls_Date2 & CH_LDELIMIT & ls_SysSol

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


Private Sub OwlSearch()
Dim ls_SPCapKey As String
Dim mo_SearchForm As SeekForm

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:OwlSearch"
    #End If
    
    ls_SPCapKey = ""
    
    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 mo_SearchForm = New SeekForm
    Load mo_SearchForm
    If mb_use_framework_connection = True Then Set mo_SearchForm.ArmDb = mo_ArmDb
    mo_SearchForm.ConnectString = ms_ConnectString
    mo_SearchForm.Language = m_Language
    mo_SearchForm.ComponentType = "PROJECT"
' task 298.8 begin
    mo_SearchForm.ViewTypeSearch = GetCodeFromCombo(Cbo_View)
    mo_SearchForm.FolowUpMaxDate = md_folowUpMaxDate
' task 298.8 end
    
    
    If (opt_date(1).Value = True) And (Not cbo_date.SelectedItem Is Nothing) Then
        mo_SearchForm.TreeView_DateType = CStr(cbo_date.SelectedItem.Key)
        
    Else
        mo_SearchForm.TreeView_DateType = "0"
    End If
    
    
    ' Put here the treeview filter desc and the treeview filter !
    mo_SearchForm.TreeViewFiltersDesc = GetCurrentFiltersDescription()
    mo_SearchForm.TreeViewFilters = GetCurrentFilters()
    
    mo_SearchForm.Load_A_COM
    
    CapMouseOn True
    mo_SearchForm.show 1
    CapMouseOff True
    
    If mo_SearchForm.SelectedData = True Then
        ls_SPCapKey = mo_SearchForm.SelectedItemCode
    End If
    
    mo_SearchForm.Unload_A_COM
    Unload mo_SearchForm
    Set mo_SearchForm = Nothing
    
    If ls_SPCapKey <> "" Then
        SearchTreeView ls_SPCapKey
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:OwlSearch"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:OwlSearch"
    If Not mo_SearchForm Is Nothing Then
        mo_SearchForm.Unload_A_COM
        Unload mo_SearchForm
        Set mo_SearchForm = Nothing
    End If
    CapMouseOn
End Sub

Public Property Let project(ByVal as_SP_Capkey As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:Project"
    #End If
    mb_EmbeddedIsDropped = False
    DisplayMode = mt_CstValues.DisplayMode_List
    SearchTreeView as_SP_Capkey, True
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:Project"
    #End If
End Property


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

Private Sub SearchTreeView(ByVal as_SP_Capkey 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 ll_Cursor As Long
Dim lv_Key As Variant

    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:SearchTreeView", "as_SP_CapKey=" & as_SP_Capkey
    #End If
    
    If as_SP_Capkey = "" 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 sales_project_t_sel6 '" & as_SP_Capkey & "','" & 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, "CapPrj:SearchTreeView", "Request=" & ls_Request
        GoTo Trace_End
    End If

    ls_RepositionInfo = mo_ArmDb.GetFields(ll_Cursor, "SP_CapKey") & mo_ArmDb.GetFields(ll_Cursor, "Language_code")
    lv_Key = Split(mo_ArmDb.GetFields(ll_Cursor, "SP_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, "RR_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, "PP_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, "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, "PP_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, "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, "SS_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, "SS_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, "SP_Zip1")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SS_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, "CTY_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SP_Town")
    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, "SA_desc")
    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, "PP_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, "PT_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, "Z_CREATOR")
' task 298.8 begin
    Case "Vk"
            ' special reposition to search in gridnot in tree
        If Not ProjectVisibleForUser(lv_Key(0), "Vk") And ab_DontReinitialize = False Then
            ls_RepositionInfo = ""
        Else
            grdlst.Requests = tvitems.GridRequests(0)
            If grdlst.Execute = False Then
                If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrj:SearchTreeView", "Requests=", grdlst.Requests
            End If
        End If
' task 298.8 end
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, "SS_desc")
Case "Vm":
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PRDLEVEL_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SS_desc")
Case "Vn":
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PP_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SS_desc")
Case "Vo":
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PP_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SS_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
Case "Vp":
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SS_desc")
Case "Vr"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PDE_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SR_name_Spec")
Case "Vs"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PDE_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SR_name_Spec")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
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_SP_Capkey, 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_SP_Capkey, 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, "capprj: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, "capprj:SearchTreeView"
    CapMouseOn
End Sub

Private Sub InitView_UK()

    lbl_Town.Top = 2160 '1860
    lbl_Town.Left = 120
    txt_Town.Top = 2100 '1800
    txt_Town.Left = 2100
    txt_Town.TabIndex = 4
    
    lbl_County.Top = 2160   '1860
    lbl_County.Left = 5220
    cbo_County.Top = 2100   '1800
    cbo_County.Left = 7200
    cbo_County.TabIndex = 5
    
    lbl_zip.Top = 2520  '2220
    lbl_zip.Left = 120
    txt_Zip1.Top = 2460 '2160
    txt_Zip1.Left = 2100
    txt_Zip1.TabIndex = 6
    txt_Zip2.Top = 2460 '2160
    txt_Zip2.Left = 3490
    txt_Zip2.TabIndex = 7
    
    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 = 2520  '2220
    lbl_Country.Left = 5220
    cbo_country.Top = 2460  '2160
    cbo_country.Left = 7200
    cbo_country.TabIndex = 8
    
End Sub

Private Sub ProjectValidation()

    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:ProjectValidation"
    #End If
    
    Dim lb_Result As Boolean
    Dim lb_Finish As Boolean
    lb_Result = False

    Dim lb_DoCheck As Boolean
    
    Load_ClgSpecief
    
    lb_DoCheck = True   ' CDbl(txt_Size.Text) >= CDbl(GetDefaultConfigCode("Prog001", "clgsVolMin"))     ' task 299.5 check replaced from txt_ceilingvalue
    
    PrdValOf.DoCheck = lb_DoCheck
    CustOf.DoCheck = lb_DoCheck
    
    PrdValOf.project = m_CurrentKey1
    CustOf.project = m_CurrentKey1
    PrdValOf.projectCountry = GetCodeFromCombo(cbo_country)
' task 299.5 begin
    ' provide size for check process
    If isNumeric(txt_Size.Text) Then
        PrdValOf.ProjectSize = CLng(txt_Size.Text)
    Else
        PrdValOf.ProjectSize = 0
    End If
' task 299.5 end
    
    PrdValOf.Left = fraItem.Left
    PrdValOf.Top = fraItem.Top
    PrdValOf.Width = fraItem.Width
    PrdValOf.Height = fraItem.Height
    
    PrdValOf.Refresh
    CustOf.Refresh
    
    CustOf.Left = fraItem.Left
    CustOf.Top = fraItem.Top
    CustOf.Width = fraItem.Width
    CustOf.Height = fraItem.Height

    ' = load the data
    Call PrdValOf.Display
    Call CustOf.Display
    
    PrdValOf.RAZ
    PrdValOf.Visible = True
    PrdValOf.Zorder
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:ProjectValidation"
    #End If
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:ProjectValidation"

End Sub

Private Sub PrdValOf_Quit()
       
       PrdValOf.Visible = False
       If PrdValOf.Validated Then
            CustOf.RAZ
            CustOf.Visible = True
            CustOf.Zorder
       Else
            cbo_Status.SearchItem p_OldCodeStatus, 0, 0
       End If
End Sub

' task 299.5 begin
Private Sub PrdValOf_Updated()
    ' some new products were linked to project
    ' recalculate txt_CeilSpecof
    Call Load_ClgSpecief
    Call RefreshLastUpdate
    
    ' reset DoCheck property with included new product link
    Dim lb_DoCheck As Boolean
    lb_DoCheck = True   ' CDbl(txt_size.Text) >= CDbl(GetDefaultConfigCode("Prog001", "clgsVolMin"))    ' do check always task 299.5
    PrdValOf.DoCheck = lb_DoCheck
    CustOf.DoCheck = lb_DoCheck

End Sub
' task 299.5 end


Private Sub CustOf_Quit()
    CustOf.Visible = False
    If Not CustOf.Validated Then
        PrdValOf.RAZ
        PrdValOf.Visible = True
    End If
    
End Sub



Private Sub RefreshSalesReps()
    
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:RefreshSalesReps"
    #End If
    
    If cbo_country.SelectedItem Is Nothing Then
        Exit Sub
    End If
    
    Dim lb_Update As Boolean
    lb_Update = IIf(cbo_country.SelectedItem.GetData(2) = "1", (txt_Zip1.Text <> "") And (txt_Zip2.Text <> "") And ((txt_Zip1.Text <> ms_OldZip1) Or (txt_Zip2.Text <> ms_OldZip2)), txt_Zip1.Text <> "" And txt_Zip1.Text <> ms_OldZip1)
    If lb_Update Then
        If Not opt_as.Value Then                            ' JN SOM task ... to suppres rep reselection when AS project
            If Not Update_SalesReps(False) Then
                'Call txt_Zip1.SetFocus
                'txt_Zip1.SelStart = 0
                'txt_Zip1.SelLength = Len(txt_Zip1.Text)
            End If
        End If
    End If

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

End Sub

Private Function Update_SalesReps(Optional ByVal NeedConfirmation As Boolean = False) As Boolean

    
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:Update_SalesReps", "NeedConfirmation=" & NeedConfirmation
    #End If
    
    CapMouseOff
    
    Dim ll_Idx As Long, ll_Count As Long
    Dim lo_Node As ListItem
    Dim ls_Zip As String, ls_CTCode As String
    Dim lc_ZipRep As Long
    Dim ls_SR_Name As String
    Dim ls_SR_Code As String
    Dim lb_usefullZip As Boolean
    
    Update_SalesReps = False
    mb_ZipCorrect = True
    
    If Not cbo_country.SelectedItem Is Nothing Then
        ls_CTCode = GetCodeFromCombo(cbo_country)
        lb_usefullZip = cbo_country.SelectedItem.GetData(2) = "1"
    Else
        ' Normaly never called because of default value !
        Call ASC_SendMessage(mo_ArmDb, m_Language, 931, "#Please, select a country before !")
        GoTo Trace_End
    End If
            
            
    ls_Zip = IIf(lb_usefullZip, txt_Zip1.Text + txt_Zip2.Text, txt_Zip1.Text)
    
    
    
    ' Get here the zip code !
    Dim ls_SQLRequest As String
    ls_SQLRequest = "exec Cap_ZipCode_t_lst '" & ls_CTCode & "', " & mt_CstValues.RRGRP_Cust
    
    lc_ZipRep = mo_ArmDb.OpenSQL(ls_SQLRequest)
    
    If lc_ZipRep = 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
    
    
    lc_ZipRep = ZipSearch_Ex(mo_ArmDb, lc_ZipRep, ls_Zip)
    
    Select Case mo_ArmDb.RowCount(lc_ZipRep)
        Case 0
            Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Zip code not managed, please choose another one")
            Call mo_ArmDb.Close(lc_ZipRep)
            mb_ZipCorrect = False
            'Call SelectStrField(txt_Zip1)
            GoTo Trace_End
        Case 1
            ' The normal way !
        Case Else
            ' Two many reps !
            Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Zip code not managed, please choose another one")
            Call mo_ArmDb.Close(lc_ZipRep)
            mb_ZipCorrect = False
            Call SelectStrField(txt_Zip1)
           GoTo Trace_End
    End Select
    ls_SR_Code = mo_ArmDb.GetFields(lc_ZipRep, "SR_CODE")
    ls_SR_Name = mo_ArmDb.GetFields(lc_ZipRep, "SR_NAME")
    Call mo_ArmDb.Close(lc_ZipRep)
    
    ' Let me check it the rep really change
    
    Dim la_CustRep As Variant
    Dim ls_CurrentCustRep As String
    la_CustRep = acv_Rep.CheckedKeys("Cust")
    
    ls_CurrentCustRep = ""
    If IsArray(la_CustRep) Then
        If UBound(la_CustRep) > -1 Then
            ls_CurrentCustRep = la_CustRep(0)(0)
            If ls_CurrentCustRep = ls_SR_Code 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 customer rep of this zip code is not the same, would you like to update it ?", vbCrLf & "(" & ls_SR_Name & ")", vbYesNo) = vbNo Then
            ' Ok man, if you want, keep it !
            Update_SalesReps = True
            GoTo Trace_End
        End If
    End If
    
    Dim lb_OneRepFound As Boolean
    lb_OneRepFound = False
    'FIND NEW DEFAULT SALES REP IN ZIP TABLE ACCORDING AND ZIP CODE
    lb_OneRepFound = acv_Rep.SetItemState("CUST", ls_SR_Code, True)
    
    Call mo_ArmDb.Close(lc_ZipRep)
    
    If Not lb_OneRepFound Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 211, "#Invalid zip code")
        mb_ZipCorrect = False
        Call SelectStrField(txt_Zip1)
        GoTo Trace_End
    Else
        'unselect new rep from copy to
        For ll_Count = 0 To acv_Rep.RoleList("COPY").CheckedCount - 1
            If ls_SR_Code = acv_Rep.RoleList("COPY").CheckedKeys(ll_Count)(0) Then
                Call acv_Rep.SetItemState("COPY", acv_Rep.RoleList("COPY").CheckedKeys(ll_Count)(0), False)
                Exit For
            End If
        Next
    End If
    txt_spare1.Text = "N"
    Call acv_Rep.SetVisibleList("Cust")
    Update_SalesReps = True
    
Trace_End:
    ' In case of
    If Not Update_SalesReps Then Call acv_Rep.UnCheckAll("CUST")
    
    Call mo_ArmDb.Close(lc_ZipRep)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:Update_SalesReps", "Result=" & Update_SalesReps
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not Update_SalesReps Then Call acv_Rep.UnCheckAll("CUST")
    Call mo_ArmDb.Close(lc_ZipRep)
    Update_SalesReps = False
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:Update_SalesReps"
    CapMouseOn
    

End Function


Private Sub InitAcvRepsRole()
    
Dim la_Spec_RoleMain As Variant, la_Spec_RoleSpec As Variant, la_Spec_RoleCust As Variant, la_Spec_RoleCopy As Variant
Dim lb_ReadOnly As Boolean
    
    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
    
    acv_Rep.RoleCount = 4
    
    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_ProjectRep_lst '$SP_CapKey$','" & m_Language & "'", "exec Cap_ProjectRep_Ins '$SP_CapKey$','$SR_CODE$',$RR_Code$,'Y','N', NULL,'','',0,0", "exec Cap_ProjectRep_Del '$SP_CapKey$','$SR_CODE$',$RR_Code$", True, 2, False, True, 0, 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_ProjectRep_lst2 '$SP_CapKey$','" & m_Language & "'", "exec Cap_ProjectRep_Ins '$SP_CapKey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_ProjectRep_Del '$SP_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_ProjectRep_lst2 '$SP_CapKey$','" & m_Language & "'", "exec Cap_ProjectRep_Ins '$SP_CapKey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_ProjectRep_Del '$SP_CapKey$','$SR_CODE$',$RR_Code$", lb_ReadOnly, 1, True, True, 1, 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_ProjectRep_lst2 '$SP_CapKey$', '" & m_Language & "'", "exec Cap_ProjectRep_Ins '$SP_CapKey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0", "exec Cap_ProjectRep_Del '$SP_CapKey$','$SR_CODE$',$RR_Code$", False, 2, False, True, 3, 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

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 TransfertProject()
Dim ls_SPCapKey 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, "capprj:TransfertProject"
    #End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    If Not CheckProjectClaim Then GoTo Trace_End
    
    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 = "PROJECT"
    lo_SearchForm.TreeView_DateType = "0"
    lo_SearchForm.ViewTypeSearch = ""
    
    lo_SearchForm.Load_A_COM
    
    CapMouseOn True
    
    lo_SearchForm.show 1
    CapMouseOff True
    
    ls_SPCapKey = lo_SearchForm.SelectedItemCode
    
    lo_SearchForm.Unload_A_COM
    Unload lo_SearchForm
    Set lo_SearchForm = Nothing
    
    If ls_SPCapKey = "" Then GoTo Trace_End
    
    If StrComp(ls_SPCapKey, m_CurrentKey1, vbTextCompare) = 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 933, "#Unable to transfert a project on himself")
        GoTo Trace_End
    End If
    
    ' JN 23/05/2012 check if project type is the same and if both do not containt quotes - temporary solution!!!
    Dim ls_SAFlagN As String
    Dim ls_SAFlagO As String
    Dim ll_Q_Count_N As Long
    Dim ll_Q_Count_O As Long

    ls_Request = "SELECT SPN.SP_SAFlag AS N_SAFlag, SPO.SP_SAFlag AS O_SAFlag, " & _
                "(SELECT COUNT(*) FROM Cap_SOM_Quote WHERE SP_CapKey = SPN.SP_CapKey AND Drop_flag<>'X') AS N_QCount, " & _
                "(SELECT COUNT(*) FROM Cap_SOM_Quote WHERE SP_CapKey = SPO.SP_CapKey AND Drop_flag<>'X') AS O_QCount " & _
                "From " & _
                "Sales_project SPN, " & _
                "Sales_project SPO " & _
                "WHERE SPN.SP_CapKey = '" & ls_SPCapKey & "' AND SPO.SP_CapKey = '" & m_CurrentKey1 & "'"
    
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
    Debug.Assert (mo_ArmDb.RowCount(ll_Cursor) = 1)
    
    ls_SAFlagN = mo_ArmDb.GetFields(ll_Cursor, "N_SAFlag")
    ls_SAFlagO = mo_ArmDb.GetFields(ll_Cursor, "O_SAFlag")
    
    ll_Q_Count_N = mo_ArmDb.GetFields(ll_Cursor, "N_QCount")
    ll_Q_Count_O = mo_ArmDb.GetFields(ll_Cursor, "O_QCount")
    
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0
    
    If ls_SAFlagN <> ls_SAFlagO Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 971, "#Unable to merge projects of different type.")
        GoTo Trace_End
    End If
    
    If ll_Q_Count_N > 0 And ll_Q_Count_O > 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 972, "#Unable to merge projects where both containt quotes.")
        GoTo Trace_End
    End If
    ' JN/ end
    
    
    If ASC_SendMessage(mo_ArmDb, m_Language, 1025, "#Do you really want to transfert this project ?", , 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 sales_project_transfert '" & ls_SPCapKey & "','" & m_CurrentKey1 & "'"
    
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
    
    If ll_Cursor = 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 934, "#An error occured, and the transfert was not done. Please, contact IT")
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapPrj:TransfertProject", "Request=" & ls_Request
        Call AddToTransfertLog(mo_ArmDb, ms_UID, GetTransfertID(mo_ArmDb, ms_UID, "PRJ"), "PRJ", m_CurrentKey1, ls_SPCapKey, ls_Request, False, mo_ArmDb.LastErrorMessage)
        GoTo Trace_End
    End If
    
    ls_Data = mo_ArmDb.GetFields(ll_Cursor, 0)
    If ls_Data <> "0" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 934, "#An error occured, and the transfert was not done. Please, contact IT")
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "capprj:TransfertProject", "Request=" & ls_Request
        Call AddToTransfertLog(mo_ArmDb, ms_UID, GetTransfertID(mo_ArmDb, ms_UID, "PRJ"), "PRJ", m_CurrentKey1, ls_SPCapKey, ls_Request, False, mo_ArmDb.LastErrorMessage & ", " & ls_Data)
        GoTo Trace_End
    End If
    
    Call AddToTransfertLog(mo_ArmDb, ms_UID, GetTransfertID(mo_ArmDb, ms_UID, "PRJ"), "PRJ", m_CurrentKey1, ls_SPCapKey, 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_SPCapKey
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:TransfertProject"
    #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, "capprj:TransfertProject"
    CapMouseOn
End Sub



' 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, "capprj:Embedded_Updated"
    #End If

    If Not ab_FromEmbedded Then
        ' TO DO
    Else
        Select Case mi_EmbedTag
            Case mt_CstValues.Tag_Customer
                Call acv_Rep.LoadList
                Call CheckCustomerPriority
            Case mt_CstValues.Tag_Product
                Call Load_ClgSpecief
                Call RefreshLastUpdate
            Case mt_CstValues.Tag_Memo
                Call CheckMemoProject
            Case mt_CstValues.Tag_Action
                Call RefreshLastUpdate
        End Select
    End If

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

Private Sub RefreshLastUpdate()

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

' Load the customer information in the bottom frame
Private Sub Load_ClgSpecief()
Dim ls_Request 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, "Capact:Load_ClgSpecief"
    #End If

    ls_Request = "exec cap_solutionsystem_t_sel3 '" & 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, "Capact:Load_ClgSpecief", "Request=" & ls_Request
        GoTo Trace_End
    End If
    txt_ClgSpecif.Text = Round(CDbl(mo_ArmDb.GetFields(ll_Cursor, 0)), 1)     ' JN 21.11.2012 rounding
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Load_ClgSpecief"
    #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, "Capact:Load_ClgSpecief"
    CapMouseOn
    
End Sub


Private Function CheckProjectClaim() As Boolean
Dim ls_SPCapKey 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, "capprj:CheckProjectClaim"
    #End If
    
    CheckProjectClaim = False
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ls_Request = "Select count(*) FROM Claim C, Sales_Project SP Where CPR_Code = SP.SP_Code and SP.SP_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, "capprj:TransfertProject", "Request=" & ls_Request
        GoTo Trace_End
    End If
    If mo_ArmDb.GetFields(ll_Cursor, 0) > 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 935, "#This data is referenced by another application (Claims). You cannot delete it or transferred it.")
        GoTo Trace_End
    End If
    
    CheckProjectClaim = True
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:CheckProjectClaim"
    #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, "capprj:CheckProjectClaim"
    CapMouseOn
End Function


Private Function PLL_ProjectsList() As Boolean

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

    PLL_ProjectsList = False
    
    ' Initialization of the export tools
    Dim lo_ExcLead As ArmExcelLead
    
    Set lo_ExcLead = New ArmExcelLead
    Call lo_ExcLead.Load_A_COM
    Set lo_ExcLead.Type_CstValues = mt_CstValues
    Set lo_ExcLead.ArmDb = mo_ArmDb
    lo_ExcLead.User_ID = ms_UID
    lo_ExcLead.Language_Code = m_Language
    lo_ExcLead.LocalID = GetLCIDFromCodePage(GetCodePageFromLanguage(mo_ArmDb, m_Language))
    
    ' Temp table for Selected items keys
    lo_ExcLead.CreateTempTableRequest = "CREATE TABLE [#Cap_ExcelExport] ([Code] [int] Identity(1,1),[User_ID] [varchar] (30) NULL ,[CapKey1] [varchar] (20) NULL ,    [CapKey2] [varchar] (20) NULL) ON [PRIMARY]"
    lo_ExcLead.DropTempTableRequest = "DROP TABLE [#Cap_ExcelExport]"
    lo_ExcLead.InsertTempKeyRequest = "exec Cap_ExcelExport_ins '$User_ID$','$0$','$1$','$2$','$3$','$4$', '$5$', '$6$', '$7$', '$8$', '$9$'"
    lo_ExcLead.InsertTempKeyCount = 10

    Call lo_ExcLead.SetConstantRequest("exec screen_csts 'Cap_PLL_List','$LangCode$'", "Field_Name", "Local_Text")
    lo_ExcLead.SPRequest = "EXEC Cap_PLLExportSalesProject_lst2 '$User_ID$', '$LangCode$'"
    lo_ExcLead.CompanyRequest = "EXEC Cap_PLLExport_Company_Sel2 '$SP_CapKey$', '$LangCode$'"
    
    
    If IsEmpty(grdlst.MultiSelectedKey) Then
        If ASC_SendMessage(mo_ArmDb, m_Language, 917, "#Warning: this solution can take long time. Would you really export all the grid ?", , vbYesNo) = vbYes Then
            Dim ll_CurrentLine As Long
            ll_CurrentLine = grdlst.Row
            grdlst.LastLine
            If ll_CurrentLine = -1 Then
                grdlst.FirstLine
            Else
                grdlst.Row = ll_CurrentLine
            End If
            lo_ExcLead.MultiKey = grdlst.MultiKey
        Else
            PLL_ProjectsList = True
            GoTo Trace_End
        End If
    Else
        lo_ExcLead.MultiKey = grdlst.MultiSelectedKey
    End If
    Call lo_ExcLead.ExportListe(App.Path & "\ArmPrjListe.xls")
    
    
    PLL_ProjectsList = True
        
Trace_End:
    Call lo_ExcLead.Unload_A_COM
    Set lo_ExcLead = Nothing
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:PLL_ProjectsInfo", "result=" & PLL_ProjectsList
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
   If Not lo_ExcLead Is Nothing Then
        Call lo_ExcLead.Unload_A_COM
    End If
    Set lo_ExcLead = Nothing
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:PLL_ProjectsList"
    CapMouseOn

End Function

Private Function CheckMemoProject() 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, "capprj:CheckMemoProject"
    #End If
    
    CheckMemoProject = False
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ls_Request = "Select count(*) FROM Cap_MemoProject MP Where MP.SP_Capkey = '" & m_CurrentKey1 & "' "
    
    ll_Cursor = mo_ArmDb.OpenSQL(ls_Request)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "capprj:CheckMemoProject", "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)
       
    CheckMemoProject = True
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:CheckMemoProject"
    #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, "capprj:CheckMemoProject"
    CapMouseOn
End Function

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:CheckCustomerPriority"
    #End If
    
    CheckCustomerPriority = False
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ll_Count = 0
    ls_PriorityList = GetDefaultConfigDesc("Project_Cfg", "CustomerPriorityHighlight")
    If Trim(ls_PriorityList) <> "" Then
      ls_Request = "exec cap_projectcompany_prioritycheck '" & m_CurrentKey1 & "','" & ls_PriorityList & "','" & SEP & "'"
      
      ll_Cursor = mo_ArmDb.OpenSQL(ls_Request)
      If ll_Cursor = 0 Then
          If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "capprj:CheckCustomerPriority", "Request=" & ls_Request
          GoTo Trace_End
      End If
      
      
      ll_Count = mo_ArmDb.RowCount(ll_Cursor)
      mo_ArmDb.Close ll_Cursor
    End If
    Call UpdateTabInfo(tbsEmbedded, SetLstKey(mt_CstValues.Tag_Customer), ll_Count > 0)
    
    CheckCustomerPriority = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:CheckCustomerPriority"
    #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, "capprj:CheckCustomerPriority"
    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 SelectTab(ao_TabStrip As MSComctlLib.TabStrip, ByVal al_Tag As Long)
Dim lo_Tab As MSComctlLib.Tab
    
    On Error GoTo Trace_Err
    
    Set lo_Tab = ao_TabStrip.Tabs(SetLstKey(al_Tag))
    If Not lo_Tab Is Nothing Then
        lo_Tab.Selected = True
    End If
    DoEvents
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capcon:SelectTab"
End Sub

Private Function PLL_ProjectsInfo() As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:PLL_ProjectsInfo"
    #End If
    
    PLL_ProjectsInfo = False
    
    ' Initialization of the export tools
    Dim lo_ExcLead As ArmExcelLead
    
    Set lo_ExcLead = New ArmExcelLead
    Call lo_ExcLead.Load_A_COM
    Set lo_ExcLead.Type_CstValues = mt_CstValues
    Set lo_ExcLead.ArmDb = mo_ArmDb
    lo_ExcLead.User_ID = ms_UID
    lo_ExcLead.Language_Code = m_Language
    
    ' Temp table for Selected items keys
    lo_ExcLead.CreateTempTableRequest = "CREATE TABLE [#Cap_ExcelExport] ([Code] [int] Identity(1,1),[User_ID] [varchar] (30) NULL ,[CapKey1] [varchar] (20) NULL ,    [CapKey2] [varchar] (20) NULL) ON [PRIMARY]"
    lo_ExcLead.DropTempTableRequest = "DROP TABLE [#Cap_ExcelExport]"
    lo_ExcLead.InsertTempKeyRequest = "exec Cap_ExcelExport_ins '$User_ID$','$0$','$1$','$2$','$3$','$4$', '$5$', '$6$', '$7$', '$8$', '$9$'"
    lo_ExcLead.InsertTempKeyCount = 10
  
    Call lo_ExcLead.SetConstantRequest("exec screen_csts 'Cap_PLL_Info','$LangCode$'", "Field_Name", "Local_Text")
    lo_ExcLead.SPRequest = "EXEC Cap_PLLExportSalesProject_lst '$User_ID$', '$LangCode$'"
    lo_ExcLead.ActionRequest = "EXEC Cap_PLLExport_Action_Sel '$SP_CapKey$', '$LangCode$'"
    lo_ExcLead.CompanyRequest = "EXEC Cap_PLLExport_Company_Sel '$SP_CapKey$', '$LangCode$'"
    lo_ExcLead.ItemsRequest = "EXEC Cap_PLLExport_Cap_SolutionSystem_Sel '$SP_CapKey$', '$LangCode$'"
    lo_ExcLead.SalesRepRequest = "EXEC Cap_PLLExport_SalesRep_Sel '$SP_CapKey$', '$LangCode$'"
    
    
    If IsEmpty(grdlst.MultiSelectedKey) Then
        If ASC_SendMessage(mo_ArmDb, m_Language, 917, "#Warning: this solution can take long time. Would you really export all the grid ?", , vbYesNo) = vbYes Then
            Dim ll_CurrentLine As Long
            ll_CurrentLine = grdlst.Row
            grdlst.LastLine
            If ll_CurrentLine = -1 Then
                grdlst.FirstLine
            Else
                grdlst.Row = ll_CurrentLine
            End If
            lo_ExcLead.MultiKey = grdlst.MultiKey
        Else
            PLL_ProjectsInfo = True
            GoTo Trace_End
        End If
    Else
        lo_ExcLead.MultiKey = grdlst.MultiSelectedKey
    End If
    
    Call lo_ExcLead.ExportBlatt(App.Path & "\ArmPrjInfo.xls")
    
    PLL_ProjectsInfo = True
    
Trace_End:
    Call lo_ExcLead.Unload_A_COM
    Set lo_ExcLead = Nothing
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:PLL_ProjectsInfo", "result=" & PLL_ProjectsInfo
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
   If Not lo_ExcLead Is Nothing Then
        Call lo_ExcLead.Unload_A_COM
    End If
    Set lo_ExcLead = Nothing
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:PLL_ProjectsInfo"
    CapMouseOn
End Function


Private Function PLL_ProjectsInfo_JP_EXPERIMENTAL() As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:PLL_ProjectsInfo"
    #End If
    
    PLL_ProjectsInfo_JP_EXPERIMENTAL = False
    
    ' Initialization of the export tools
    Dim lo_ExcLead As ArmExcelLead
    
    Set lo_ExcLead = New ArmExcelLead
    Call lo_ExcLead.Load_A_COM
    Set lo_ExcLead.Type_CstValues = mt_CstValues
    Set lo_ExcLead.ArmDb = mo_ArmDb
    lo_ExcLead.User_ID = ms_UID
    lo_ExcLead.Language_Code = m_Language
    
    ' Temp table for Selected items keys
    lo_ExcLead.CreateTempTableRequest = "CREATE TABLE [#Cap_ExcelExport] ([Code] [int] Identity(1,1),[User_ID] [varchar] (30) NULL ,[CapKey1] [varchar] (20) NULL ,    [CapKey2] [varchar] (20) NULL) ON [PRIMARY]"
    lo_ExcLead.DropTempTableRequest = "DROP TABLE [#Cap_ExcelExport]"
    lo_ExcLead.InsertTempKeyRequest = "exec Cap_ExcelExport_ins '$User_ID$','$0$','$1$','$2$','$3$','$4$', '$5$', '$6$', '$7$', '$8$', '$9$'"
    lo_ExcLead.InsertTempKeyCount = 10
  
    Call lo_ExcLead.SetConstantRequest("exec screen_csts 'Cap_PLL_Info','$LangCode$'", "Field_Name", "Local_Text")
    lo_ExcLead.SPRequest = "EXEC Cap_PLLExportSalesProject_lst '$User_ID$', '$LangCode$'"
    lo_ExcLead.ActionRequest = "EXEC Cap_PLLExport_Action_Sel '$SP_CapKey$', '$LangCode$'"
    lo_ExcLead.CompanyRequest = "EXEC Cap_PLLExport_Company_Sel '$SP_CapKey$', '$LangCode$'"
    lo_ExcLead.ItemsRequest = "EXEC Cap_PLLExport_Cap_SolutionSystem_JP_Sel '$SP_CapKey$', '$LangCode$'"
    lo_ExcLead.SalesRepRequest = "EXEC Cap_PLLExport_SalesRep_Sel '$SP_CapKey$', '$LangCode$'"
    
    Dim ll_spList As Long
    
    ll_spList = OpenSQLSafe(mo_ArmDb, "Cap_PLLExport_Projects_JP_lst")
    
    Dim ls_currGrp As String
    ls_currGrp = "-1"
    
    Dim lva_multiKey As Variant
    
    While Not mo_ArmDb.EOF(ll_spList)
        If ls_currGrp <> "-1" And ls_currGrp <> mo_ArmDb.GetFields(ll_spList, "ROW_GRP") Then
            ' do the export
            lo_ExcLead.MultiKey = lva_multiKey
            
            Call lo_ExcLead.ExportBlatt(App.Path & "\ArmPrjInfoItems.xls", App.Path & "\Download\" & ls_currGrp)
            
            lva_multiKey = Empty
        End If
        ls_currGrp = mo_ArmDb.GetFields(ll_spList, "ROW_GRP")
        If IsArray(lva_multiKey) Then
            ' extend the size
            ReDim Preserve lva_multiKey(UBound(lva_multiKey) + 1) As Variant
        Else
            ReDim lva_multiKey(0) As Variant
        End If
        lva_multiKey(UBound(lva_multiKey)) = mo_ArmDb.GetFields(ll_spList, Array("ROW_KEY1", "ROW_KEY2"))
        
        Call mo_ArmDb.Next(ll_spList)
    Wend
    
    Call mo_ArmDb.Close(ll_spList)
    
    
    PLL_ProjectsInfo_JP_EXPERIMENTAL = True
    
Trace_End:
    Call lo_ExcLead.Unload_A_COM
    Set lo_ExcLead = Nothing
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:PLL_ProjectsInfo_JP_EXPERIMENTAL", "result=" & PLL_ProjectsInfo_JP_EXPERIMENTAL
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
   If Not lo_ExcLead Is Nothing Then
        Call lo_ExcLead.Unload_A_COM
    End If
    Set lo_ExcLead = Nothing
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:PLL_ProjectsInfo_JP_EXPERIMENTAL"
    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"
                            If Not lControl.SelectedItem Is Nothing Then
                                lPath(lIdxPattern) = lControl.SelectedItem.Key & SEP & lControl.SelectedItem.DisplayText
                            Else
                                lPath(lIdxPattern) = "" & SEP & ""
                            End If
                        Case "ARMCHECKVIEW0"
                            lc = lControl.ListItems.Count - 1
                            For li = 0 To lc
                                If lControl.ItemInfo(li).Checked = True Then
                                    lPath(lIdxPattern) = lControl.ItemInfo(li).Id & SEP & lControl.ItemInfo(li).Caption
                                    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
    
    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)
        
    ' PUT HERE THE EXCEPTION
    
    'replace spec rep
    If acv_Rep.RoleList("SPEC").CheckedCount <> 0 Then
        lBuffer = Replace(lBuffer, "ckvSalesRep.SpecRep", acv_Rep.RoleList((lRole)).CheckedKeys(0)(0) & SEP & acv_Rep.RoleList((lRole)).GetItem(acv_Rep.RoleList((lRole)).CheckedKeys(0)).GetData(1), , , vbTextCompare)
    Else
        lBuffer = Replace(lBuffer, "ckvSalesRep.SpecRep", "-1" & SEP & "- N/A -", , , vbTextCompare)
    End If
    
    'replace demand
    If InStr(1, lBuffer, "user_type_demand", vbTextCompare) Then
        Dim ll_Idx, ll_Diff As Integer
        
        ll_Diff = DateDiff("d", Now, CDate(cal_clgStartDate.date_courte))
        
        For ll_Idx = 0 To UBound(m_demand)
            If m_demand(ll_Idx).Min <= ll_Diff And m_demand(ll_Idx).Max >= ll_Diff Then
            
                lBuffer = Replace(lBuffer, "user_type_demand", m_demand(ll_Idx).Id & SEP & m_demand(ll_Idx).Desc, , , vbTextCompare)
                Exit For
            End If
        Next
        
    End If
    
    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(ByVal as_viewFilterType As String) As Boolean
    
' task 298.8 begin
    ' general check
    If Not ProjectVisibleForUser(m_CurrentKey1, as_viewFilterType) Then
        Item_Filtered = True
        Exit Function
    End If
' task 298.8 end
    
    ' Project status
    If opt_active(0).Value Then ' ALL
        ' NOTHING TO DO
    End If
    If opt_active(1).Value Then ' ACTIVE
        If cbo_Status.SelectedItem.GetData(2) <> "ACTIVE" Then
            Item_Filtered = True
            Exit Function
        End If
    End If
    If opt_active(2).Value Then ' ARCHIVED
        If cbo_Status.SelectedItem.GetData(2) <> "ARCHIVE" Then
            Item_Filtered = True
            Exit Function
        End If
    End If
    If opt_active(3).Value Then ' REFERENCE
        If cbo_Status.SelectedItem.GetData(2) <> "REFERENCE" Then
            Item_Filtered = True
            Exit Function
        End If

    End If
    
    ' solution system
    If opt_SysSol(0).Value Then
        ' NOTHING TO DO
    End If
    If opt_SysSol(1).Value Then    ' solution system
        If chk_sysSol.Value = vbUnchecked Then
            Item_Filtered = True
            Exit Function
        End If
    End If
    If opt_SysSol(2).Value Then    ' non solution system
        If chk_sysSol.Value = vbChecked Then
            Item_Filtered = True
            Exit Function
        End If
    End If
    
    ' 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
            Case "3" ' Follow up
                lDate = cal_followUpDate.date_courte
            Case "4" ' ceilings start date
                lDate = cal_clgStartDate.date_courte
        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 = Not opt_sa.Value
        Case "tbs_filtersNonSA"
            Item_Filtered = Not opt_std.Value
    End Select
    
End Function

Public Sub Item_LocalUpdate()
    
    If Item_Filtered(GetCodeFromCombo(Cbo_View)) Then       ' task 298.8
        Call AddToTimeLog(mi_OldDisplayMode, 99)
        If GetCodeFromCombo(Cbo_View) = "Vk" Then
            ' remove line from grid
            Call grdlst.DeleteSelectedLines
            Call RefreshFollowUpInfo
            Exit Sub
        Else
        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
    End If
    
    Dim lPath As String
    
    lPath = GetCurrentPath(UserControl.Controls, fraItem, Cbo_View.SelectedItem.GetData(2))
        tvitems.Visible = False
' task 298.8 begin
    If lPath <> "" Then
        If GetCodeFromCombo(Cbo_View) = "Vm" Then
            ' there is a treeview at root
            If tvitems.SelectedItem Is Nothing Then
                lPath = GetNodeRootData(tvitems.Nodes(1)) & SEP & SEP & lPath
            Else
                lPath = GetNodeRootData(tvitems.SelectedItem) & SEP & SEP & lPath
            End If
        End If
    Call FindInTreeView(tvitems, lPath)
    Else
        Debug.Assert (GetCodeFromCombo(Cbo_View) = "Vk")
        Call RefreshFollowUp
    End If
' tak 298.8 end
    tvitems.Visible = True
    Call grdlst.SearchKey(True, Array(m_CurrentKey1, "E"))
            
End Sub

Private Function GetNodeRootData(ByRef ao_Node As Node) As String
    If ao_Node.Parent Is Nothing Then
        GetNodeRootData = ao_Node.Tag.GetData(0) & SEP & ao_Node.Tag.GetData(2)
        Exit Function
    End If
    GetNodeRootData = GetNodeRootData(ao_Node.Parent)
End Function

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 ('P" & aFct & "', GetDate(), '" & lComputer & "', " & Replace(CStr(aTime), ",", ".") & ")")

End Sub


' task 299.7 begin
Private Sub chk_sysSol_Click()
    On Error GoTo Trace_Err
    
    cbo_SS.Visible = ((chk_sysSol.Value = vbChecked) And mb_HaveSolSys)
    If chk_sysSol.Value = vbUnchecked Then
        Set cbo_SS.SelectedItem = Nothing
    End If
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:chk_sysSol_Click"
End Sub
' task 299.7 end
' 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
'    Debug.Print 1 / 0
    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:
    ao_Db.Close (lc_Data)
    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

' SOM_Project functionality
Private Function Item_Check() As Boolean
On Error GoTo ErrHandler
    Dim lv_MsgReplaceInfo() As String
    Dim ll_IsNum As Long 'if 0 then ok
    
    'select case to manage the different records
            ll_IsNum = 0
            
            ll_IsNum = CheckNumericField(txt_duration, 0, 0, 999)
            If ll_IsNum <> 0 Then
                ReDim lv_MsgReplaceInfo(2, 1)
                lv_MsgReplaceInfo(0, 0) = "$LabelCaption$"
                lv_MsgReplaceInfo(0, 1) = lbl_prjDuration.Caption
                lv_MsgReplaceInfo(1, 0) = "$Min$"
                lv_MsgReplaceInfo(1, 1) = 0
                lv_MsgReplaceInfo(2, 0) = "$Max$"
                lv_MsgReplaceInfo(2, 1) = FormatNumber(999, 0)
                GoTo errMessage
            End If
            
    
errMessage:
    Select Case ll_IsNum
        Case 2131
            Call MsgBox(SOMMsgText(ll_IsNum, m_Language, "#The field " & lv_MsgReplaceInfo(0, 1) & " must be numeric.", lv_MsgReplaceInfo), vbInformation)
            Exit Function
        Case 2134
            Call MsgBox(SOMMsgText(ll_IsNum, m_Language, "#The field " & lv_MsgReplaceInfo(0, 1) & " does not accept decimal number.", lv_MsgReplaceInfo), vbInformation)
            Exit Function
        Case 2132
            Call MsgBox(SOMMsgText(ll_IsNum, m_Language, "#The field " & lv_MsgReplaceInfo(0, 1) & " must be a number between " & lv_MsgReplaceInfo(1, 1) & " and " & lv_MsgReplaceInfo(2, 1) & ".", lv_MsgReplaceInfo), vbInformation)
            Exit Function
            
    End Select
    
    Item_Check = True
    Exit Function
    
ErrHandler:
    Call ErrorHandler("Item_Check")


End Function


Private Function CheckNumericField(ByVal ao_value As TextBox, ByVal ai_NbDecimal As Integer, ByVal av_Min As Variant, ByVal av_Max As Variant) As Long
On Error GoTo ErrHandler
    Dim ls_Value As Variant
    
    ls_Value = Replace(ao_value.Text, ".", ms_DecimalSeparator, , , vbTextCompare)
        
    On Error Resume Next
    Dim ld_Number As Double
    Dim ll_errNum As Long
    ld_Number = CDbl(ls_Value)
    ll_errNum = Err.Number
    Err.Clear
    On Error GoTo ErrHandler
    If ll_errNum <> 0 Then
        CheckNumericField = 2131
        GoTo BackToControl
    End If

    If InStr(1, ls_Value, "e", vbTextCompare) Or InStr(1, ls_Value, ms_ThousandSeparator, vbTextCompare) Then
        CheckNumericField = 2131
        GoTo BackToControl
    End If
    
    If ai_NbDecimal = 0 And InStr(1, ls_Value, ms_DecimalSeparator) Then
        CheckNumericField = 2134
        GoTo BackToControl
    End If
    
    If Not (ld_Number >= av_Min And ld_Number <= av_Max) Then
        CheckNumericField = 2132
        GoTo BackToControl
    End If

    ao_value.Text = ls_Value
    CheckNumericField = 0
    
    Exit Function

BackToControl:
    ao_value.SelStart = 0
    ao_value.SelLength = Len(ao_value.Text)
    If ao_value.Visible Then ao_value.SetFocus
    
    Exit Function

ErrHandler:
    Call ErrorHandler("CheckNumericField")
   
End Function

Function SOMMsgText(ByVal aID As Long, ByVal aLang As String, ByVal aDefault As String, Optional ByVal aInfo As Variant) As String

On Error GoTo ErrHandler

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

    SOMMsgText = ""
    
    Dim lRequest As String
    lRequest = Replace(DB_REQ, "$id$", aID)
    lRequest = Replace(lRequest, "$lang$", aLang)
    Dim lData As Long
    
    lData = OpenSQLSafe(mo_ArmDb, lRequest)
    
    Dim lBuffer As String
    lBuffer = mo_ArmDb.GetFields(lData, "message_text")
    mo_ArmDb.Close (lData)
    If lBuffer = "" Then lBuffer = aDefault
    
    Dim li_idx As Integer
    If Not IsMissing(aInfo) Then
        For li_idx = 0 To UBound(aInfo)
            lBuffer = Replace(lBuffer, aInfo(li_idx, 0), aInfo(li_idx, 1), , , vbTextCompare)
        Next li_idx
    End If
    
    
    SOMMsgText = lBuffer
    Exit Function
ErrHandler:
    mo_ArmDb.Close (lData)
    Call ErrorHandler("SOMMsgText")
   
End Function

Private Sub uc_SOMQuoteValOf_quit()
      
    uc_SOMQuoteValOf.Visible = False
    
    If uc_SOMQuoteValOf.Validated Then
'        Call pbItem_action("Valid")
        p_OldCodeStatus = GetCodeFromCombo(cbo_Status)
    Else
        cbo_Status.SearchItem p_OldCodeStatus, 0, 0
    End If
End Sub

Private Sub SOMQuoteValidation()

    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprj:SOMQuoteValidation"
    #End If
    
    If Not mb_quoteValOfInitialized Then
        mb_quoteValOfInitialized = uc_SOMQuoteValOf.Init_control
    End If
    

    uc_SOMQuoteValOf.Left = fraItem.Left
    uc_SOMQuoteValOf.Top = fraItem.Top
    uc_SOMQuoteValOf.Width = fraItem.Width
    uc_SOMQuoteValOf.Height = fraItem.Height
    
    ' = load the data
    uc_SOMQuoteValOf.ProjectStatus = cbo_Status.SelectedItem.Key
    uc_SOMQuoteValOf.ProjectIConc = p_iCon
    Call uc_SOMQuoteValOf.Run(m_CurrentKey1)
    
    uc_SOMQuoteValOf.Visible = True
    uc_SOMQuoteValOf.Zorder
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprj:SOMQuoteValidation"
    #End If
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprj:SOMQuoteValidation"

End Sub

Private Sub SOMQuotesCancel()
On Error GoTo ErrorHandler
Const C_REQ As String = "UPDATE Cap_SOM_Quote " & _
                          "SET SQT_Status = 4, " & _
                            "   SQT_StatusDate = GETDATE(), " & _
                            "    iConcurrency = iConcurrency, " & _
                            "    Z_last_upd_user= $USER$, " & _
                            "    Z_Last_Upd = GetDate() " & _
                            "WHERE SP_CAPKEY = '$SP_CAPKEY$' AND Drop_flag<>'X'"
    Dim ls_req As String

    ls_req = Replace(C_REQ, "$SP_CAPKEY$", m_CurrentKey1, , , vbTextCompare)
    ls_req = Replace(ls_req, "$USER$", prg.U_Code)
    Call ExecuteSQLSafe(mo_ArmDb, ls_req)

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


Private Sub LockScreen(ByVal ab_lock As Boolean)

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

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


' ************************************************************************************
' ***************************** SECURITY FUNCTIONS ***********************************
' ************************************************************************************

Private Sub GetUserRight(ByRef ao_rights As UserRights_t)
Const C_REQ As String = "EXEC Check_Security 'Sales_Project', $LOGINNAME$"
On Error GoTo ErrorHandler
    Dim ll_Cursor As Long
    
' default user rights
    ao_rights.Executive = False
    ao_rights.CapOfferView = False
' check admin
    ll_Cursor = OpenSQLSafe(mo_ArmDb, Replace(C_REQ, "$LOGINNAME$", SqlStr(ms_UID)))
    Debug.Assert (ll_Cursor <> 0)
    
    Call mo_ArmDb.First(ll_Cursor)
    While Not mo_ArmDb.EOF(ll_Cursor)
        Select Case mo_ArmDb.GetFields(ll_Cursor, "Action")
        Case "Executive"
            ao_rights.Executive = True
        Case "CapOfferView"
            ao_rights.CapOfferView = True
        Case Else
'            Debug.Assert (False)
        End Select
        Call mo_ArmDb.Next(ll_Cursor)
    Wend
    
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0
    
    Exit Sub
ErrorHandler:
    If ll_Cursor <> 0 Then Call mo_ArmDb.Close(ll_Cursor)
    Call ErrorHandler("GetUserRight()")
End Sub

' ************************************************************************************
    
Private Sub SelectCommentTab(ByVal ab_executive As Boolean, ByVal al_PP_Code As Long)
On Error GoTo ErrorHandler
    chk_Top10E.Enabled = (al_PP_Code = mt_CstValues.PRIORITY_TOP10) And m_userRights.Executive
    chk_Top10E.Value = IIf(ab_executive, vbChecked, vbUnchecked)
    
    If ab_executive Then
        cbo_Priority.Enabled = m_userRights.Executive
    End If
    
    ' user do not have rights and executive comment must be hidden
    
    ' if executive is checked then display comment if user has rights or system allow it
    tbsComment.Visible = ab_executive And (mb_top10ExecVisible Or m_userRights.Executive)
    If ab_executive And (mb_top10ExecVisible Or m_userRights.Executive) Then
        tbsComment.Tabs("tab_Top10EComment").Selected = True
        txt_Top10EComment.Visible = True
        txt_Comment.Visible = False
    Else
        tbsComment.Tabs("tab_Comment").Selected = True
        txt_Top10EComment.Visible = False
        txt_Comment.Visible = True
    End If
    
    Exit Sub
ErrorHandler:
    Call ErrorHandler("SelectCommentTab()")
End Sub

