VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl capprd 
   ClientHeight    =   10380
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   13710
   ScaleHeight     =   10380
   ScaleWidth      =   13710
   ToolboxBitmap   =   "Capprd.ctx":0000
   Begin VB.Frame fraFilters 
      Height          =   8415
      Left            =   -3315
      TabIndex        =   28
      Top             =   615
      Width           =   4215
      Begin VB.PictureBox pctTvReset 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   240
         Left            =   0
         Picture         =   "Capprd.ctx":0312
         ScaleHeight     =   16
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   16
         TabIndex        =   67
         Top             =   100
         Width           =   240
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Left            =   660
         TabIndex        =   6
         Top             =   2895
         Width           =   3450
         _ExtentX        =   6085
         _ExtentY        =   609
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#Between"
         Height          =   255
         Index           =   1
         Left            =   1930
         TabIndex        =   62
         Tag             =   "lbl_Between"
         Top             =   1560
         Width           =   2200
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#All"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   2
         Tag             =   "lbl_All"
         Top             =   1560
         Value           =   -1  'True
         Width           =   1800
      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        =   57
         Top             =   3360
         Width           =   570
      End
      Begin Project1.ArmTreeView tvitems 
         Height          =   2385
         Left            =   60
         TabIndex        =   7
         Top             =   3360
         Width           =   4050
         _ExtentX        =   7144
         _ExtentY        =   4207
      End
      Begin VB.Frame fra_Active 
         BorderStyle     =   0  'None
         Height          =   510
         Left            =   75
         TabIndex        =   44
         Top             =   720
         Width           =   4100
         Begin VB.OptionButton opt_active 
            Caption         =   "#Archived"
            Height          =   255
            Index           =   2
            Left            =   1860
            TabIndex        =   47
            Tag             =   "lbl_Archived"
            Top             =   105
            Width           =   1050
         End
         Begin VB.OptionButton opt_active 
            Caption         =   "#Active"
            Height          =   255
            Index           =   1
            Left            =   900
            TabIndex        =   46
            Tag             =   "lbl_Active"
            Top             =   105
            Width           =   950
         End
         Begin VB.OptionButton opt_active 
            Caption         =   "#All"
            Height          =   255
            Index           =   0
            Left            =   60
            TabIndex        =   1
            Tag             =   "lbl_All"
            Top             =   105
            Value           =   -1  'True
            Width           =   800
         End
         Begin VB.OptionButton opt_active 
            Caption         =   "#Reference"
            Height          =   255
            Index           =   3
            Left            =   2895
            TabIndex        =   45
            Tag             =   "lbl_Reference"
            Top             =   105
            Width           =   1150
         End
      End
      Begin MSComctlLib.TabStrip tbsFilters 
         Height          =   375
         Left            =   120
         TabIndex        =   56
         Top             =   7890
         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         =   "#Main"
               Key             =   "M"
               Object.Tag             =   "tbs_filtersmain"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Alternate"
               Key             =   "L"
               Object.Tag             =   "tbs_filtersalternate"
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin VB.CheckBox chk_SA 
         Caption         =   "#S.A."
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Tag             =   "chk_sa"
         Top             =   2460
         Width           =   1335
      End
      Begin Project1.A_calocx cal12 
         Height          =   315
         Left            =   2160
         TabIndex        =   4
         Top             =   1980
         Visible         =   0   'False
         Width           =   1815
         _ExtentX        =   3201
         _ExtentY        =   556
      End
      Begin Project1.A_calocx cal11 
         Height          =   315
         Left            =   120
         TabIndex        =   3
         Top             =   1980
         Visible         =   0   'False
         Width           =   1815
         _ExtentX        =   3201
         _ExtentY        =   556
      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        =   69
         Tag             =   "lbl_DateRange"
         Top             =   1260
         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        =   68
         Tag             =   "lbl_ProjectStatus"
         Top             =   420
         Width           =   1935
      End
      Begin VB.Label lbl_view 
         Caption         =   "#View"
         Height          =   195
         Left            =   120
         TabIndex        =   43
         Tag             =   "lbl_view"
         Top             =   2940
         Width           =   495
      End
   End
   Begin VB.Frame fraItem 
      Height          =   9825
      Left            =   1800
      TabIndex        =   25
      Top             =   4560
      Width           =   8595
      Begin Project1.ToolBr pbitem 
         Height          =   915
         Left            =   510
         TabIndex        =   50
         Top             =   240
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   1614
      End
      Begin VB.Frame fraItemBottom 
         Height          =   465
         Left            =   645
         TabIndex        =   48
         Top             =   8445
         Width           =   2220
      End
      Begin MSComctlLib.TabStrip tbsEmbedded 
         Height          =   375
         Left            =   570
         TabIndex        =   19
         Top             =   9105
         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          =   5460
         Left            =   150
         TabIndex        =   27
         Top             =   1200
         Width           =   8175
         Begin VB.CheckBox chk_SC 
            Caption         =   "#Ceiling"
            Height          =   315
            Index           =   0
            Left            =   5160
            TabIndex        =   13
            Top             =   240
            Value           =   1  'Checked
            Width           =   2630
         End
         Begin VB.TextBox txt_SolKey 
            Height          =   330
            Left            =   2100
            Locked          =   -1  'True
            TabIndex        =   64
            Tag             =   "txt_SolKey"
            Top             =   240
            Width           =   3015
         End
         Begin Project1.ArmCombobox cbo_UOM 
            Height          =   345
            Left            =   3300
            TabIndex        =   17
            Tag             =   "cbo_UOM"
            Top             =   2820
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_competitor 
            Height          =   345
            Left            =   2040
            TabIndex        =   14
            Tag             =   "cbo_competitor"
            Top             =   1920
            Width           =   5775
            _ExtentX        =   10186
            _ExtentY        =   609
         End
         Begin Project1.cboPrd cbo_product 
            Height          =   315
            Left            =   2040
            TabIndex        =   15
            Tag             =   "cbo_product"
            Top             =   2400
            Width           =   5775
            _ExtentX        =   10186
            _ExtentY        =   556
         End
         Begin VB.TextBox txt_segmentation 
            Height          =   285
            Left            =   5505
            TabIndex        =   61
            Tag             =   "txt_spare8"
            Top             =   5100
            Visible         =   0   'False
            Width           =   420
         End
         Begin VB.TextBox txt_family 
            Height          =   285
            Left            =   5040
            TabIndex        =   60
            Tag             =   "txt_spare8"
            Top             =   5100
            Visible         =   0   'False
            Width           =   420
         End
         Begin VB.TextBox txt_material 
            Height          =   285
            Left            =   4590
            TabIndex        =   59
            Tag             =   "txt_spare8"
            Top             =   5100
            Visible         =   0   'False
            Width           =   420
         End
         Begin VB.TextBox txt_country 
            Height          =   285
            Left            =   4140
            TabIndex        =   58
            Tag             =   "txt_spare8"
            Top             =   5100
            Visible         =   0   'False
            Width           =   420
         End
         Begin VB.TextBox txt_spare8 
            Height          =   285
            Left            =   6000
            TabIndex        =   0
            Tag             =   "txt_spare8"
            Top             =   3300
            Visible         =   0   'False
            Width           =   975
         End
         Begin VB.TextBox txt_spare7 
            Height          =   285
            Left            =   4440
            TabIndex        =   8
            Tag             =   "txt_spare7"
            Top             =   3300
            Visible         =   0   'False
            Width           =   615
         End
         Begin VB.TextBox txt_spare6 
            Height          =   285
            Left            =   2880
            TabIndex        =   9
            Tag             =   "txt_spare6"
            Top             =   3300
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.TextBox txt_spare5 
            Height          =   285
            Left            =   1200
            TabIndex        =   20
            Tag             =   "txt_spare5"
            Top             =   3300
            Visible         =   0   'False
            Width           =   975
         End
         Begin VB.TextBox txt_spare4 
            Height          =   330
            Left            =   6420
            TabIndex        =   21
            Top             =   3000
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare3 
            Height          =   330
            Left            =   6840
            TabIndex        =   22
            Top             =   3120
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare1 
            Height          =   330
            Left            =   6720
            TabIndex        =   24
            Top             =   2880
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_comment 
            Height          =   975
            Left            =   2100
            MaxLength       =   2000
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   18
            Tag             =   "txt_comment"
            Top             =   3660
            Width           =   5775
         End
         Begin VB.TextBox txt_Date 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   2100
            TabIndex        =   35
            Tag             =   "txt_Date"
            Text            =   "02/02/2001"
            Top             =   4680
            Width           =   1095
         End
         Begin VB.TextBox txt_creator 
            Enabled         =   0   'False
            Height          =   330
            Left            =   5050
            TabIndex        =   34
            Tag             =   "txt_creator"
            Text            =   "L. Cockayne"
            Top             =   4680
            Width           =   2835
         End
         Begin VB.TextBox txt_qty 
            Height          =   315
            Left            =   2040
            TabIndex        =   16
            Tag             =   "txt_qty"
            Top             =   2820
            Width           =   1095
         End
         Begin VB.Frame Frame1 
            Height          =   1155
            Left            =   120
            TabIndex        =   26
            Top             =   660
            Width           =   5000
            Begin Project1.ArmCombobox cbo_area 
               Height          =   345
               Left            =   2160
               TabIndex        =   12
               Tag             =   "cbo_area"
               Top             =   720
               Width           =   2715
               _ExtentX        =   4789
               _ExtentY        =   609
            End
            Begin VB.OptionButton opt_main 
               Caption         =   "#Main"
               Height          =   275
               Left            =   120
               TabIndex        =   10
               Tag             =   "lbl_main"
               Top             =   180
               Value           =   -1  'True
               Width           =   1920
            End
            Begin VB.OptionButton opt_Alternate 
               Caption         =   "#Alternate"
               Height          =   275
               Left            =   2500
               TabIndex        =   11
               Tag             =   "lbl_alternate"
               Top             =   180
               Width           =   1920
            End
            Begin VB.Label lbl_are 
               Caption         =   "#Area "
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Left            =   120
               TabIndex        =   30
               Tag             =   "lbl_area"
               Top             =   720
               Width           =   675
            End
         End
         Begin VB.TextBox txt_spare2 
            Height          =   330
            Left            =   6360
            TabIndex        =   23
            Top             =   3120
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.Label lbl_SolCode 
            Caption         =   "#Solution key"
            Height          =   255
            Left            =   120
            TabIndex        =   65
            Tag             =   "lbl_SolCode"
            Top             =   300
            Width           =   1920
         End
         Begin VB.Label lbl_spare8 
            Caption         =   "#lbl_spare8"
            Height          =   255
            Left            =   5040
            TabIndex        =   55
            Tag             =   "lbl_spare8"
            Top             =   3300
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare7 
            Caption         =   "#lbl_spare7"
            Height          =   255
            Left            =   3720
            TabIndex        =   54
            Tag             =   "lbl_spare7"
            Top             =   3300
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare6 
            Caption         =   "#lbl_spare6"
            Height          =   255
            Left            =   2160
            TabIndex        =   53
            Tag             =   "lbl_spare6"
            Top             =   3300
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare5 
            Caption         =   "#lbl_spare5"
            Height          =   255
            Left            =   360
            TabIndex        =   52
            Tag             =   "lbl_spare5"
            Top             =   3300
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare4 
            Caption         =   "#lbl_spare4"
            Height          =   195
            Left            =   5220
            TabIndex        =   42
            Tag             =   "lbl_spare4"
            Top             =   3000
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare3 
            Caption         =   "#lbl_spare3"
            Height          =   195
            Left            =   5220
            TabIndex        =   41
            Tag             =   "lbl_spare3"
            Top             =   2640
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare2 
            Caption         =   "#lbl_spare2"
            Height          =   195
            Left            =   5220
            TabIndex        =   40
            Tag             =   "lbl_spare2"
            Top             =   2280
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare1 
            Caption         =   "#lbl_spare1"
            Height          =   195
            Left            =   5340
            TabIndex        =   39
            Tag             =   "lbl_spare1"
            Top             =   1920
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_comment 
            Caption         =   "#Comments"
            Height          =   255
            Left            =   120
            TabIndex        =   38
            Tag             =   "lbl_comment"
            Top             =   3660
            Width           =   1920
         End
         Begin VB.Label lbl_Date 
            Caption         =   "#Creation date"
            Height          =   255
            Left            =   120
            TabIndex        =   37
            Tag             =   "lbl_date"
            Top             =   4740
            Width           =   1920
         End
         Begin VB.Label lbl_Creator 
            Caption         =   "#By"
            Height          =   255
            Left            =   3720
            TabIndex        =   36
            Tag             =   "lbl_creator"
            Top             =   4740
            Width           =   1200
         End
         Begin VB.Label lbl_competitor 
            Caption         =   "#Competitor"
            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        =   33
            Tag             =   "lbl_competitor"
            Top             =   2040
            Width           =   1920
         End
         Begin VB.Label lbl_product 
            Caption         =   "#Product"
            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        =   32
            Tag             =   "lbl_product"
            Top             =   2400
            Width           =   1920
         End
         Begin VB.Label lbl_qty 
            Caption         =   "#Quantity"
            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        =   31
            Tag             =   "lbl_qty"
            Top             =   2880
            Width           =   1920
         End
      End
   End
   Begin VB.Frame fraList 
      Height          =   4110
      Left            =   4440
      TabIndex        =   29
      Top             =   1680
      Width           =   6780
      Begin Project1.ArmGrid grdlst 
         Height          =   2055
         Left            =   120
         TabIndex        =   63
         Top             =   1200
         Width           =   3735
         _ExtentX        =   6588
         _ExtentY        =   3625
      End
      Begin VB.PictureBox fill_all_record 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   600
         Left            =   2700
         ScaleHeight     =   600
         ScaleWidth      =   600
         TabIndex        =   51
         Top             =   360
         Visible         =   0   'False
         Width           =   600
      End
      Begin Project1.ToolBr pblst 
         Height          =   675
         Left            =   240
         TabIndex        =   49
         Top             =   300
         Width           =   1995
         _ExtentX        =   3519
         _ExtentY        =   1191
      End
      Begin Project1.ArmGrid grdSummary 
         Height          =   2055
         Left            =   2040
         TabIndex        =   70
         Top             =   1800
         Width           =   3735
         _ExtentX        =   6588
         _ExtentY        =   3625
      End
      Begin VB.Label lbl_ListFilter 
         Alignment       =   2  'Center
         BackColor       =   &H0000FFFF&
         Caption         =   "#All "
         Height          =   375
         Left            =   120
         TabIndex        =   66
         Top             =   840
         Width           =   4935
      End
   End
End
Attribute VB_Name = "capprd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
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 mo_Tools As DPC_Tools

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

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

'******** AFFICHAGE ****************************************************************
Private mt_CstValues As Type_CstValues         ' Structure which contains constants value
Private mi_DisplayMode As Variant       ' Current display mode
Private mi_OldDisplayMode As Variant    ' Old display mode, need for know parameters
Private mi_EmbeddedIn As Integer        ' Indicates the tag  of the component which embed this component
Private mi_EmbedTag As Integer          ' Indicates the tag of the last component embedded
Private mi_CptTag As Integer            ' Tag of the component type
Private mb_Root As Boolean              ' Indicates if the component is the focus of the user

'******** 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
Private ml_ProductMtncLevel As Long         ' backup for Cap_System.Spare3_real
Private md_qty As Single                    ' backup for qty

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

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

Private m_Project As String 'For the property .Project, display in ShortList
Private m_Contact As String 'For the property .Contact, display in ShortList
Private m_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 ml_projectStatus As Long 'status of a project recieved via Project property let

' 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

Public mb_CycleReset As Boolean
Private mi_SC_Count As Integer      ' Number of SC code
Private mb_SCChkUse As Boolean      ' Use as flag for recursive call of SC function

Private ms_ProjectCTCode As String


Private ms_View_Key As String

Public Property Set ArmDb(ByRef ao_local_connection As Object)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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 grdSummary.ArmDb = mo_ArmDb
        Set pblst.ArmDb = mo_ArmDb
        Set pbItem.ArmDb = mo_ArmDb
        Set tvitems.ArmDb = mo_ArmDb
        Set cbo_Product.ArmDb = mo_ArmDb
        Set Cbo_View.ArmDb = mo_ArmDb
        Set Cbo_area.ArmDb = mo_ArmDb
        Set cbo_competitor.ArmDb = mo_ArmDb
        Set cbo_UOM.ArmDb = mo_ArmDb
    End If

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

Property Let ConnectString(as_ConnectString As String)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:ConnectString_Let", "as_ConnectString=" & as_ConnectString
    #End If
    CapMouseOff
    
    ms_UID = ConnectionStringValidation(as_ConnectString)
    If ms_UID = "" Then GoTo Trace_End
    
    ms_ConnectString = as_ConnectString
    
    'Affectation aux objets
    grdlst.ConnectString = ms_ConnectString
    grdlst.ConnectString = ms_ConnectString
    pblst.ConnectString = ms_ConnectString
    pbItem.ConnectString = ms_ConnectString
    tvitems.ConnectString = ms_ConnectString
    cbo_Product.ConnectString = ms_ConnectString
    Cbo_View.ConnectString = ms_ConnectString
    Cbo_area.ConnectString = ms_ConnectString
    cbo_competitor.ConnectString = ms_ConnectString
    cbo_UOM.ConnectString = ms_ConnectString
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd:Language_Let", "as_Language=" & as_Language
    #End If
    CapMouseOff
    
    m_Language = as_Language
    
    'grdlst.Language = m_Language
    tvitems.Language = m_Language
    pbItem.Language = m_Language
    pblst.Language = m_Language
    cbo_Product.Language = m_Language
    cal11.Language = m_Language
    cal12.Language = m_Language

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


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

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

    pblst.ClearAllIcons
    pblst.TableName = mt_CstValues.SecurityProduct
    pblst.PictureDisplayed = "P_Delete=3 P_Refresh=7 P_View=-4 P_Excel=-5 P_Quit=-1"
    
    grdlst.ResetGrid
    grdlst.Title = "Products"
    grdlst.MultiSelect = True
    
    la_Columns(0) = "sol_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sol_code" & CH_LDELIMIT & "sol_code"
    la_Columns(1) = "S_code" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "2" & CH_LDELIMIT & "S_code" & CH_LDELIMIT & "S_code"
    la_Columns(2) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "3" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(3) = "mainAlternate" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "mainAlternate" & CH_LDELIMIT & "M/A"
    la_Columns(4) = "s_desc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "s_desc" & CH_LDELIMIT & "s_desc"
    la_Columns(5) = "module" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "pd_desc" & CH_LDELIMIT & "module"
    la_Columns(6) = "ss_qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ss_qty" & CH_LDELIMIT & "ss_qty" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(7) = "UM_code" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_code" & CH_LDELIMIT & "UM_code"
    la_Columns(8) = "SP_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_desc" & CH_LDELIMIT & "sp_desc"
    la_Columns(9) = "sp_town" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_town" & CH_LDELIMIT & "sp_town"
    la_Columns(10) = "z_creator" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "z_creator" & CH_LDELIMIT & "z_creator"
    la_Columns(11) = "z_creation" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "z_creation" & CH_LDELIMIT & "z_creation"
    la_Columns(12) = "S_InstallFlag" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "S_InstallFlag" & CH_LDELIMIT & "S_InstallFlag"
    la_Columns(13) = "LR_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LR_desc" & CH_LDELIMIT & "LR_desc"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_product_longlist', 'grid', '" & m_Language & "'", ctColumns
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:DrawMainGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd: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, "capprd:GoToTab1"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd:InitParentKey"
    #End If
    
    m_Project = ""
    m_Customer = ""
    m_Memo = ""
    m_Contact = ""
    m_Action = ""

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

Function RecordAdd() As Boolean
Dim ls_ProdCode As String
Dim ls_Request As String
Dim lb_Result As Boolean
Dim ls_MEMCode As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:RecordAdd"
    #End If
    
    RecordAdd = False
    
    ErrorOFF
    
    ls_ProdCode = mo_ArmDb.SQLNextID("Cap_SolutionSystem")
    If ls_ProdCode = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Cap_SolutionSystem"") 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.")
    
    ls_Request = "Cap_SolutionSystem_ins"
    
    ls_Request = ls_Request & "  " & CorrectCboPrd(mo_ArmDb, m_Language, cbo_Product, True) '@S_code    CHAR(20),
    ls_Request = ls_Request & ", " & "'" & m_Project & "'"          '@SP_CapKey char(16),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_competitor, True) '@CPT_code int,
    ls_Request = ls_Request & ", " & "''"                           '@SOL_desc   VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Qty, True)      '@SS_Qty real,
    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_Comment)     '@SS_Comment VARCHAR(250),   'task299.3
    If opt_main.Value = True Then
        ls_Request = ls_Request & ", " & "1"                        '@MA_code    INT,
    Else
        ls_Request = ls_Request & ", " & "2"                        '@MA_code    INT,
    End If
    ls_Request = ls_Request & ", " & "NULL"                         '@LR_code int,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, Cbo_area, True) '@AR_code    INT,
    ls_Request = ls_Request & ", " & "''"                           '@Install_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "''"                           '@drop_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "NULL"                         '@drop_date  CHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1)      '@spare1_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2)      '@spare2_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3)         '@spare3_varchar    REAL,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Spare4)         '@spare4_varchar    REAL,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Spare5)      '@spare5_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare6)      '@spare6_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare7)         '@spare7_varchar    REAL,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare8)         '@spare8_varchar    REAL,
    ls_Request = ls_Request & ", '" & ls_ProdCode & "'"
    
        'Execution
    If ErrorFound Then GoTo Trace_End
    
    ' get Level of maintenace of selected product
    Dim ll_Cursor As Long
    ll_Cursor = mo_ArmDb.OpenSQL("EXEC Sales_Project_ASProductLevel '" & cbo_Product.SelectedItemCode & "'")
    Debug.Assert (ll_Cursor <> 0)
    ml_ProductMtncLevel = mo_ArmDb.GetFields(ll_Cursor, "Spare3_real")
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0
        
    
    If (SelSC = 4) And (Trim(txt_Comment.Text) = "") And (GetDefaultConfigCode("Product_Cfg", "ASCommentWarning") = "X") Then
            If ASC_SendMessage(mo_ArmDb, m_Language, 8731, "It's recommended to enter a comment for the AS Product. Would you like to continue ?", , vbYesNo, "Capture") = vbNo Then
                GoTo Trace_End
            End If
    End If
    
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    Dim lb_Transaction As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_Transaction = True
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_ProdCode)
    
    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, '$SOL_CODE$', '', 3, 0, '$MEM_Code$'"
    Dim ls_Result As String
    
    ' insert into cap_memo only 'E' language record, memo type=3(spare3_real)
        ls_Request = Replace(REQins, "$Comment_desc$", FormatSqlStringParameter(Left(txt_Comment.Text, 80)))
        ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Comment.Text))
        ls_Request = Replace(ls_Request, "$SOL_CODE$", ls_ProdCode)
        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

    ' update project Metal product counter which depends on ml_ProductMtncLevel and SelSC
    If Not UpdateProjectCounters(m_Project, ml_ProductMtncLevel, SelSC, 1) 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
        
    ' JN 20.3.2012 update z_last_upd for a project
    If Not UpdateProjectLastUpdate(m_Project) 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

    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, "capprd:RecordAdd", "Result=" & RecordAdd
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If ll_Cursor <> 0 Then
        mo_ArmDb.Close (ll_Cursor)
        ll_Cursor = 0
    End If
    If lb_Transaction Then
        ASC_RollBackTransaction mo_ArmDb
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:RecordAdd"
    CapMouseOn
End Function

Private Function UpdateProjectCounters(ByVal as_SP_Capkey As String, ByVal al_ProductMtncLevel As Long, ByVal as_SelSC As String, ByVal al_Value As Long) As Boolean
    Dim ls_req As String
    UpdateProjectCounters = False
    ls_req = ""
    Select Case al_ProductMtncLevel
        Case 1
                ls_req = "Exec Sales_Project_ASProductCounterUpdate '$SP_Capkey$', $Counter$"
        Case 2
                ls_req = "Exec Sales_Project_ASProductCounter2Update '$SP_Capkey$', $Counter$"
        Case 3, 4
                ls_req = "Exec Sales_Project_ASProductCounter3Update '$SP_Capkey$', $Counter$"
        Case Else
            ' non leveled AS products count as level 1
            If as_SelSC = 4 Then
                ls_req = "Exec Sales_Project_ASProductCounterUpdate '$SP_Capkey$', $Counter$"
            End If
    End Select
    If ls_req <> "" Then
        Dim ls_Dummy As String
        ls_req = Replace(ls_req, "$SP_Capkey$", as_SP_Capkey)
        ls_req = Replace(ls_req, "$Counter$", al_Value)
        If Not ASC_RecordExec(mo_ArmDb, ls_req, ls_Dummy) Then
            Exit Function
        End If
    End If
    UpdateProjectCounters = True
End Function

Function RecordAddAndDelete(ACode1 As String, ACode2 As String) As Boolean
Dim ls_ProdCode As String
Dim ls_Request As String
Dim lb_Result As Boolean
Dim ls_MEMCode As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:RecordAdd"
    #End If
    
    RecordAddAndDelete = False
    
    ErrorOFF
    
    ls_ProdCode = mo_ArmDb.SQLNextID("Cap_SolutionSystem")
    If ls_ProdCode = "" Then Call Err.Raise(SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Cap_SolutionSystem"") 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.")
    
    ls_Request = "Cap_SolutionSystem_ins"
    
    ls_Request = ls_Request & "  " & CorrectCboPrd(mo_ArmDb, m_Language, cbo_Product, True) '@S_code    CHAR(20),
    ls_Request = ls_Request & ", " & "'" & m_Project & "'"          '@SP_CapKey char(16),
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_competitor, True) '@CPT_code int,
    ls_Request = ls_Request & ", " & "''"                           '@SOL_desc   VARCHAR(80),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Qty, True)      '@SS_Qty real,
    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_Comment)     '@SS_Comment VARCHAR(250),   'task299.3
    If opt_main.Value = True Then
        ls_Request = ls_Request & ", " & "1"                        '@MA_code    INT,
    Else
        ls_Request = ls_Request & ", " & "2"                        '@MA_code    INT,
    End If
    ls_Request = ls_Request & ", " & "NULL"                         '@LR_code int,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, Cbo_area, True) '@AR_code    INT,
    ls_Request = ls_Request & ", " & "''"                           '@Install_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "''"                           '@drop_flag  CHAR(1),
    ls_Request = ls_Request & ", " & "NULL"                         '@drop_date  CHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1)      '@spare1_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2)      '@spare2_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3)         '@spare3_varchar    REAL,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Spare4)         '@spare4_varchar    REAL,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Spare5)      '@spare5_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare6)      '@spare6_varchar    CHAR(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare7)         '@spare7_varchar    REAL,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare8)         '@spare8_varchar    REAL,
    ls_Request = ls_Request & ", '" & ls_ProdCode & "'"
    
        'Execution
    If ErrorFound Then GoTo Trace_End
    
    ' get Level of maintenace of selected product
    Dim ll_Cursor As Long
    ll_Cursor = mo_ArmDb.OpenSQL("EXEC Sales_Project_ASProductLevel '" & cbo_Product.SelectedItemCode & "'")
    Debug.Assert (ll_Cursor <> 0)
    ml_ProductMtncLevel = mo_ArmDb.GetFields(ll_Cursor, "Spare3_real")
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0
        
    
    If (SelSC = 4) And (Trim(txt_Comment.Text) = "") And (GetDefaultConfigCode("Product_Cfg", "ASCommentWarning") = "X") Then
            If ASC_SendMessage(mo_ArmDb, m_Language, 8731, "It's recommended to enter a comment for the AS Product. Would you like to continue ?", , vbYesNo, "Capture") = vbNo Then
                GoTo Trace_End
            End If
    End If
    
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    Dim lb_Transaction As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_Transaction = True
    
    ' delete current record
    Dim ll_errNum As Long
    ll_errNum = RecordDeleteDB(ACode1, ACode2)
    If ll_errNum <> 0 Then
        ASC_RollBackTransaction mo_ArmDb
        Select Case ll_errNum
            Case 916
                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 True
            Case 891
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
            Case Else
                Call ASC_SendMessage(mo_ArmDb, m_Language, ll_errNum, "Error #" & ll_errNum)
        End Select
        GoTo Trace_End
    End If
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_ProdCode)
    
    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, '$SOL_CODE$', '', 3, 0, '$MEM_Code$'"
    Dim ls_Result As String
    
    ' insert into cap_memo only 'E' language record, memo type=3(spare3_real)
    ls_Request = Replace(REQins, "$Comment_desc$", FormatSqlStringParameter(Left(txt_Comment.Text, 80)))
    ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Comment.Text))
    ls_Request = Replace(ls_Request, "$SOL_CODE$", ls_ProdCode)
    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
    
    ' JN 20.3.2012 update z_last_upd for a project
    If Not UpdateProjectLastUpdate(m_Project) 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


    ASC_CommitTransaction mo_ArmDb
    lb_Transaction = False
    RecordAddAndDelete = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:RecordAdd", "Result=" & RecordAdd
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If ll_Cursor <> 0 Then
        mo_ArmDb.Close (ll_Cursor)
        ll_Cursor = 0
    End If
    If lb_Transaction Then
        ASC_RollBackTransaction mo_ArmDb
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:RecordAdd"
    CapMouseOn
End Function

Function RecordUpdate(ACode1 As String, ACode2 As String) As Boolean
Dim ls_Request As String
Dim ls_Result 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, "capprd:RecordUpdate", "ACode1=" & ACode1, "ACode2=" & ACode2
    #End If
    
    RecordUpdate = False
    
    If Trim$(ACode1) = "" Or Trim$(ACode2) = "" 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
    
    Dim ls_Qty As String
    ls_Qty = CorrectDec(mo_ArmDb, m_Language, txt_Qty, True)
    If ErrorFound Then GoTo Trace_End
    
    If Round(Val(ls_Qty) * 10000) <> Round(md_qty * 10000) Then
        RecordUpdate = RecordAddAndDelete(ACode1, ACode2)
        GoTo Trace_End
    Else
        ls_Request = "Cap_SolutionSystem_upd"
        ls_Request = ls_Request & " " & "'" & ACode1 & "'"  '@SOL_code char(16) ,
        ls_Request = ls_Request & ", " & "'" & m_Project & "'"    '@SP_CapKey char (16),
        ls_Request = ls_Request & ", " & CorrectCboPrd(mo_ArmDb, m_Language, cbo_Product, True) '@S_code char(20) ,
        ls_Request = ls_Request & ", '" & ACode2 & "'" '@S_Code char(20)
        ls_Request = ls_Request & ", " & ls_Qty        '@SS_Qty real,
        ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_competitor, True) '@CPT_code int,
        ls_Request = ls_Request & ", " & "''"                           '@SOL_desc   VARCHAR(80),
        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_comment)     '@SS_Comment VARCHAR(250),   ' task299.3
        If opt_main.Value = True Then
            ls_Request = ls_Request & ", " & "1"                        '@MA_code    INT,
        Else
            ls_Request = ls_Request & ", " & "2"                        '@MA_code    INT,
        End If
        ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, Cbo_area, True) '@AR_code    INT,
        ls_Request = ls_Request & ", " & p_iCon                         '@iConcurrency SMALLINT,
        ls_Request = ls_Request & ", " & "''"                           '@Install_flag  CHAR(1),
        ls_Request = ls_Request & ", " & "''"                           '@drop_flag  CHAR(1),
        ls_Request = ls_Request & ", " & "NULL"                         '@drop_date  CHAR(1),
        ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1)      '@spare1_varchar    CHAR(1),
        ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2)      '@spare2_varchar    CHAR(1),
        ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3)         '@spare3_varchar    REAL,
        ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_Spare4)         '@spare4_varchar    REAL,
        ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Spare5)      '@spare5_varchar    CHAR(1),
        ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare6)      '@spare6_varchar    CHAR(1),
        ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare7)         '@spare7_varchar    REAL,
        ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare8)         '@spare8_varchar    REAL,
    End If
    

    'Execution
    If ErrorFound Then GoTo Trace_End
    
        If (SelSC = 4) And (Trim(txt_Comment.Text) = "") And (GetDefaultConfigCode("Product_Cfg", "ASCommentWarning") = "X") Then
            If ASC_SendMessage(mo_ArmDb, m_Language, 8731, "It's recommended to enter a comment for the AS Product. Would you like to continue ?", , vbYesNo, "Capture") = vbNo Then
                GoTo Trace_End
            End If
    End If
    
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    Dim lb_Transaction As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_Transaction = True
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        lb_Transaction = False
        Select Case ls_Result
            Case "-2"
                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 True
            Case Else
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        End Select
        GoTo Trace_End
    End If


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

    ' update cap_memo
    ls_Request = Replace(REQupd, "$SOL_CODE$", ACode1)
        ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_Comment.Text))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
            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
    
    ' JN 20.3.2012 update z_last_upd for a project
    If Not UpdateProjectLastUpdate(m_Project) 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
    
    ASC_CommitTransaction mo_ArmDb
    lb_Transaction = False
    RecordUpdate = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:RecordUpdate", "Result=" & RecordUpdate
    #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, "capprd:RecordUpdate"
    CapMouseOn
End Function

Function RecordDeleteDB(ACode1 As String, ACode2 As String) As Long
Dim ls_Request As String
Dim lb_Result As Boolean
Dim ls_Result As String
Const REQdel = "EXEC Cap_Memo_Comment_del '$SOL_CODE$', 3"

    On Error GoTo Trace_Err
    CapMouseOff
    
    RecordDeleteDB = 0
    
    ls_Request = "Cap_SolutionSystem_del"
    ls_Request = ls_Request & " " & "'" & ACode1 & "'"              '@SOL_code char(16) ,
    ls_Request = ls_Request & ", " & "'" & ACode2 & "'"             '@SP_CapKey char (16),
    ls_Request = ls_Request & ", " & p_iCon                         '@iConcurrency SMALLINT,
    'Execution
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        Select Case ls_Result
            Case "-1", "-2"
                RecordDeleteDB = 916
            Case Else
                RecordDeleteDB = 891
        End Select
        GoTo Trace_End
    End If
    
    ' delete cap_memo
    ls_Request = Replace(REQdel, "$SOL_CODE$", ACode1)
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        RecordDeleteDB = 891
        GoTo Trace_End
    End If

Trace_End:
    CapMouseOn
    Exit Function
Trace_Err:
    RecordDeleteDB = Err.Number
    CapMouseOn
End Function

Function RecordDelete(ACode1 As String, ACode2 As String) As Boolean

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:RecordDelete", "ACode1=" & ACode1, "ACode2=" & ACode2
    #End If
    
    RecordDelete = False
    
    ' IMPLEMENT PROCESS T298.4-A.PR_001
    If StrComp(txt_creator.Text, ms_UID, vbTextCompare) <> 0 Then
      Call Tools.ASC_SendMessage(mo_ArmDb, m_Language, 799, "#You are unable to delete this specification as you are NOT the creator of it.")
      GoTo Trace_End
    End If
    ' END PROCESS T298.4-A.PR_001
    
    If Trim$(ACode1) = "" Or Trim$(ACode2) = "" 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 DeleteConfirmation(mo_ArmDb, m_Language) = False Then GoTo Trace_End

    Dim lb_Transaction As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_Transaction = True
    
    Dim ll_errNum As Long
    ll_errNum = RecordDeleteDB(ACode1, ACode2)
    
    If ll_errNum = 0 Then
        ' update project Metal product counter which depends on ml_ProductMtncLevel and SelSC
        If Not UpdateProjectCounters(m_Project, ml_ProductMtncLevel, SelSC, -1) Then
            ll_errNum = 891
        End If
    End If
    
    If ll_errNum <> 0 Then
        ASC_RollBackTransaction mo_ArmDb
        lb_Transaction = False
        Select Case ll_errNum
            Case 916
                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 True
            Case 891
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
            Case Else
                Call ASC_SendMessage(mo_ArmDb, m_Language, ll_errNum, "Error #" & ll_errNum)
        End Select
        GoTo Trace_End
    End If
    
    ' JN 20.3.2012 update z_last_upd for a project
    If Not UpdateProjectLastUpdate(m_Project) 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

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

' JN 20.3.2012 update z_last_upd for a project
Private Function UpdateProjectLastUpdate(ByVal as_SP_Capkey As String) As Boolean
Const C_REQ As String = "EXEC Sales_Project_LastUpd '$SP_CAPKEY$'"
On Error GoTo ErrHandler
    UpdateProjectLastUpdate = False
    Dim ls_req As String
    ls_req = Replace(C_REQ, "$SP_CAPKEY$", as_SP_Capkey)
    If mo_ArmDb.ExecuteSQL(ls_req) Then
        UpdateProjectLastUpdate = True
    End If
    Exit Function
ErrHandler:
' just return false
End Function

Property Let TypeList(AType As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:TypeList_Let", "AType=" & AType
    #End If
    mi_TypeList = AType
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd:TypeList_Get"
    #End If
    TypeList = mi_TypeList
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:TypeList_Get", "Result=" & TypeList
    #End If
End Property

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

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:CurrentKey_Get", "APart=" & APart
    #End If
    CapMouseOff
    
    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

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:CurrentKey_Get", "Result=" & CurrentKey
    #End If
    CapMouseOn
End Property


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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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, "capprd:Memo_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd: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
   
    m_Action = CStr(TheKeys(0))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:action_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd: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
   
    m_Contact = CStr(TheKeys(0))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Contact_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Contact_Let"
    CapMouseOn
End Property

Property Let Customer(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, "capprd:Customer_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_Customer
   
    TheKeys = Split(AKey, CH_LDELIMIT)
   
    m_Customer = CStr(TheKeys(0))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Customer_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Customer_Let"
    CapMouseOn
End Property

Property Let project(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, "capprd:Project_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_Project
   
    TheKeys = Split(AKey, CH_LDELIMIT)
    Debug.Assert (UBound(TheKeys) = 3)
    m_Action = ""
    m_Customer = ""
    m_Contact = ""
    m_Project = CStr(TheKeys(0))
    ml_projectStatus = CLng(TheKeys(3))
    cbo_Product.CT_Code = TheKeys(2)
    ListProjectOf CStr(TheKeys(0)), CStr(TheKeys(1))
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Project_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Project_Let"
    CapMouseOn
End Property

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

Private Sub cal11_datechangee()

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

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

Private Sub ReinitTreeview(as_View As String)
Dim li_rowCount As Integer
Dim TheRequest As String
Dim li_CurrentRow As Integer
Dim li_level As Integer
Dim ls_nodesRequest() As String
Dim ls_gridRequest() As String
Dim ls_countRequest() As String
Dim ls_findRequest() As String
Dim li_images() As Integer
Dim li_selectedImages() As Integer
Dim ll_Cursor As Long
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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 'Product', '" & 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, "CapPrd:ReinitTreeView", "Request=" & TheRequest
        GoTo Trace_End
    End If
    
    li_rowCount = mo_ArmDb.RowCount(ll_Cursor)
    
    If li_rowCount = 0 Then
        'zzMsgBox "error in Treeview_Parameters_lst : no rows returned"
        tvitems.Visible = True
        GoTo Trace_End
    End If
    
    ReDim ls_nodesRequest(0 To li_rowCount)
    ReDim ls_gridRequest(0 To li_rowCount)
    ReDim ls_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_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.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, "capprd: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, "capprd:ReinitTreeview"
    CapMouseOn
End Sub

Private Function ParamReqReplace(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, "capprd:ParamReqReplace", "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$", "'" & PatchTag & "'")
    
    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, "$MA$", "0")
    'If ls_request <> "" Then zzMsgBox ls_request
    ParamReqReplace = ls_Request
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:ParamReqReplace", "Result=" & ParamReqReplace
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:ParamReqReplace"
    CapMouseOn
End Function


Private Function ParamReqReplace2(as_Request As String) As String
Dim ls_Request As String
Dim PatchTag As String
Dim sa_check As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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"
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    If opt_active(0).Value Then ls_Request = Replace(ls_Request, "$opt$", "NULL")
    If opt_active(1).Value Then ls_Request = Replace(ls_Request, "$opt$", "'ACTIVE'")
    If opt_active(2).Value Then ls_Request = Replace(ls_Request, "$opt$", "'ARCHIVE'")
    If opt_active(3).Value Then ls_Request = Replace(ls_Request, "$opt$", "'REFERENCE'")

    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$", "0")
        ls_Request = Replace(ls_Request, "$dd$", cas_all("'" & cal11.date_us & "'"))
        ls_Request = Replace(ls_Request, "$df$", cas_all("'" & cal12.date_us & "'"))
    End If
    
    If chk_SA Then sa_check = "X" Else sa_check = "NULL"
    ls_Request = Replace(ls_Request, "$SA$", sa_check)
    ls_Request = Replace(ls_Request, "$MA$", 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, "capprd:ParamReqReplace2", "Result=" & ParamReqReplace2
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:ParamReqReplace2"
    CapMouseOn
End Function


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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:ParamReqReplace1", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    If opt_active(0).Value Then ls_Request = Replace(ls_Request, "$opt$", "NULL")
    If opt_active(1).Value Then ls_Request = Replace(ls_Request, "$opt$", "'ACTIVE'")
    If opt_active(2).Value Then ls_Request = Replace(ls_Request, "$opt$", "'ARCHIVE'")
    If opt_active(3).Value Then ls_Request = Replace(ls_Request, "$opt$", "'REFERENCE'")
    
    If opt_date(1) Then
        ls_Request = Replace(ls_Request, "$dd_ent$", cas_all("'" & cal11.date_us & "'"))
        ls_Request = Replace(ls_Request, "$df_ent$", cas_all("'" & cal12.date_us & "'"))
        ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV1_")
    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")
    
    If chk_SA Then sa_check = "X" Else sa_check = "NULL"
    
    ls_Request = Replace(ls_Request, "$SA$", sa_check)
    ls_Request = Replace(ls_Request, "$MA$", cas_all("'" & tbsFilters.SelectedItem.Key & "'"))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ParamReqReplace1 = ls_Request

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:ParamReqReplace1", "Result=" & ParamReqReplace1
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:ParamReqReplace1"
    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, "capprd: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, "capprd:WhichOptIsTrue", "Result=" & WhichOptIsTrue
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:WhichOptIsTrue"
    CapMouseOn
End Function


Private Sub cal12_datechangee()

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

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

Private Sub cbo_competitor_ComboItemSelected()
Dim ls_CompetitorCode As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:cbo_competitor_ComboItemSelected"
    #End If
    
    ls_CompetitorCode = GetCodeFromCombo(cbo_competitor)
    If ls_CompetitorCode <> "" Then
        cbo_Product.CompetitorCode = CInt(ls_CompetitorCode)
    End If

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



Private Sub cbo_View_ComboItemSelected()
Dim ls_Key1 As String
Dim ls_Key2 As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:cbo_view_ComboItemSelected"
    #End If
    
    If reload_treeview.Visible = True Then GoTo Trace_End
    
    ls_Key1 = ""
    ls_Key2 = ""
    If reload_treeview.Visible = False Then
        If grdlst.Row >= 0 Then
            ls_Key1 = grdlst.CurrentKey(0)
            ls_Key2 = grdlst.CurrentKey(1)
        End If
    End If
    ReinitTreeview GetCodeFromCombo(Cbo_View)
    If ls_Key1 <> "" Then
        SearchTreeView ls_Key1 & CH_LDELIMIT & ls_Key2, False
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:cbo_view_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:cbo_view_ComboItemSelected"
    CapMouseOn
End Sub

' Get the selected SC type
Private Property Get SelSC() As String
Dim li_idx As Integer
Dim li_Count As Integer
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, "capprd:SelSC_Get"
    #End If
    
    ls_Code = "-1"
    li_Count = mi_SC_Count - 1
    For li_idx = 0 To li_Count
        If chk_SC(li_idx).Value = 1 Then
            ls_Code = chk_SC(li_idx).Tag
            Exit For
        End If
    Next
    SelSC = ls_Code
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:SelSC_Get", "Result=" & SelSC
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:SelSC_Get"
    CapMouseOn
End Property

' Select the SC
Private Property Let SelSC(ByVal ls_Code As String)
Dim li_idx As Integer, li_Count As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:SelSC_Let", "ls_Code=" & ls_Code
    #End If
    
    li_Count = mi_SC_Count - 1
    For li_idx = 0 To li_Count
        chk_SC(li_idx).Value = IIf(chk_SC(li_idx).Tag = ls_Code, 1, 0)
    Next
  
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:SelSC_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:SelSC_Let"
    CapMouseOn
End Property

Private Sub chk_SA_Click()
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
End Sub

Private Sub chk_SC_Click(Index As Integer)
Dim li_idx As Integer
Dim li_Count As Integer
Dim li_Value As Integer

    If mb_SCChkUse Then
        'No Trace in this case
        Exit Sub
    End If
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:chk_SC_Click", "Index=" & Index
    #End If
    
    mb_SCChkUse = True
    li_Value = chk_SC(Index).Value
    ' Only one checked !
    ' Be careful, li_count should not be hard coded
    li_Count = mi_SC_Count - 1
    For li_idx = 0 To li_Count
        chk_SC(li_idx).Value = 0
    Next
    chk_SC(Index).Value = li_Value
    mb_SCChkUse = False
    
    li_idx = SelSC
    cbo_Product.SysClassifCode = li_idx
    txt_Qty.Text = ""

    Select Case li_idx
    Case 1, 2, 5
        SquareMeter True
    Case 3, 4
        SquareMeter False
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:chk_SC_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:chk_SC_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, "capprd: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, "capprd:UnCatch"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd:grdlst_ItemSelected"
    #End If
    
    If DisplayMode <> mt_CstValues.DisplayMode_List Then GoTo Trace_End
    
    m_CurrentKey1 = grdlst.CurrentKey(0)
    m_CurrentKey2 = grdlst.CurrentKey(1)
    m_CurrentKey3 = grdlst.CurrentKey(2)

    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, "capprd: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, "capprd: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, "capprd:opt_active_Click", "Index=" & Index
    #End If
    
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:opt_active_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd:opt_date_Click", "Index=" & Index
    #End If
    
    If Index = 0 Then
        cal11.Visible = False
        cal12.Visible = False
        cal11.reinit_cal
        cal12.reinit_cal
    Else
        cal11.Visible = True
        cal12.Visible = True
    End If
    
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:opt_date_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:opt_date_Click"
    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, "capprd:pbLst_Action", "as_ActionType=" & as_ActionType
    #End If
    
    Select Case UCase$(as_ActionType)
    
        Case UCase$("Add")
          If mo_Tools.HasSecurityAlias(ms_UID, "Cap_Offer") Then
            Dim mo_OfferSpecType As frmOfferSpecType
            
            Set mo_OfferSpecType = New frmOfferSpecType
            Load mo_OfferSpecType
            Set mo_OfferSpecType.ArmDb = mo_ArmDb
            mo_OfferSpecType.SP_CapKey = m_Project
            mo_OfferSpecType.U_Code = prg.U_Code
            Set mo_OfferSpecType.Tools = mo_Tools
            Call mo_OfferSpecType.Load_A_COM
            CapMouseOn
            Call mo_OfferSpecType.show(1)
            CapMouseOff
            If mo_OfferSpecType.Result Then
              If mo_OfferSpecType.opt_ProdSpecType(0).Value = True Then
                DisplayMode = mt_CstValues.DisplayMode_Add
              Else
                RaiseEvent CreateOffer(mi_EmbeddedIn, mo_OfferSpecType.OfferType, mo_OfferSpecType.SPR_Id, mo_OfferSpecType.SPR_Name)
              End If
            End If
            Unload mo_OfferSpecType
          Else
            DisplayMode = mt_CstValues.DisplayMode_Add
          End If
            
        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$("Refresh")
            If mi_EmbeddedIn <> -1 Then
                grdlst.Refresh
            Else
                grdlst.ClearGrid
                grdlst.Requests = ""
                tvitems.Refresh
            End If
            
        Case UCase$("Print")
        
        Case ("COMPUTE")
            Call ShowSummary
        
        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.product
            
        Case UCase$("Quit")
            If mi_EmbeddedIn <> -1 Then
                Call ShowDetail
            Else
                RaiseEvent quit
            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, "capprd:pbLst_Action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:pbLst_Action"
    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, "capprd: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 DisplayMode = mt_CstValues.DisplayMode_Add Then
                'grdlst.Refresh
                'RaiseEvent Updated
            End If
                DisplayMode = mt_CstValues.DisplayMode_List
            
        Case UCase$("Valid")
            
            Dim a As Double, b As Double
            a = timer

            If DisplayMode = mt_CstValues.DisplayMode_Add Then
                If RecordAdd = True Then
                    BlankFields
                    AddInitFields
                    ListProjectOf m_Project, m_Language
                    RaiseEvent Updated
                End If
            Else
                If mb_Root And mi_DisplayMode = mt_CstValues.DisplayMode_View Then
                    ' We stay on the same...
                    RaiseEvent UnlockNavigation
                    GoTo Trace_End
                End If
    
                                
                'Valid Update
                If DisplayMode = mt_CstValues.DisplayMode_Update Then
                    lb_Result = RecordUpdate(m_CurrentKey1, m_CurrentKey2)
                    If Not WithParent Then
                        ' NEVER HAPPEND, NO USER INTERFACE FOR THAT
                        'Call Item_LocalUpdate
                    Else
                        grdlst.Refresh
                        RaiseEvent Updated
                    End If
                End If
                'Valid Del
                If DisplayMode = mt_CstValues.DisplayMode_Delete Then
                    
                    lb_Result = RecordDelete(m_CurrentKey1, m_CurrentKey2)
                    If lb_Result Then
                        If Not WithParent Then
                            ReinitTreeViewAfterDelete grdlst, tvitems
                          Else
                            grdlst.Refresh
                            RaiseEvent Updated
                        End If
                    End If
                End If
                
                'If error found you stay on screen
                If lb_Result = True Then
                    DisplayMode = mt_CstValues.DisplayMode_List
                    b = timer - a
                    Call AddToTimeLog(mi_OldDisplayMode, b)
                End If
                
            End If
            
        Case UCase$("Undo")
            BlankFields
            'DisplayMode = mt_CstValues.DisplayMode_List
            If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
                AddInitFields
            Else
                ViewInitFields True
            End If
        
        Case UCase$("Previous")
            If grdlst.Row = 0 Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 927, "#No more previous item.")
            Else
                grdlst.Row = grdlst.Row - 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                m_CurrentKey2 = grdlst.CurrentKey(1)
                BlankFields
                ViewInitFields
            End If
        
        Case UCase$("Next")
            If grdlst.Rows = 0 Or (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
            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, "capprd:pbItem_action"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:pbItem_action"
    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, "capprd:InitControl", "AMode=" & aMode
    #End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
   
    Select Case aMode
        Case 0
            GoTo Trace_End
   
        Case 1
    'If already initialized then exit

        If mi_TypeList <> 1 Then
            mi_TypeList = 1
        Else
            pblst.PictureDisplayed = "P_Quit=-1"
            GoTo Trace_End
        End If
            
        Case 2
        
        If mi_TypeList <> 1 And mi_TypeList <> 2 Then
            mi_TypeList = 2
        End If
    End Select
   
    UserControl.ScaleMode = 1
    
    'Object unvisble
    ObjectVisible False
    
    Select Case aMode
        Case 1
    'Pour la liste longue uniquement

        DrawMainGrid
                
        'Dates
        cal11.Zorder 0
        cal12.Zorder 0
        cal11.Limited_as_embedded = 1
        cal12.Limited_as_embedded = 1
        
        Case 2
    'Pour la liste courte
       
        'Grille
        grdlst.ResetGrid
        
        'Pour liste longue : Initialisation toolbar
        'pblst.ClearAllIcons
        'pblst.TableName = mt_CstValues.SecurityProduct_lst
        'pblst.PictureDisplayed = "P_Refresh=7"
        
        Case 3
        
    'Pour détail
    
            pbItem.ClearAllIcons
'            If WithParent Then
'                pbItem.TableName = mt_CstValues.SecurityProduct_lst
'            Else
'                pbItem.TableName = mt_CstValues.SecurityProduct
'            End If
'            pbItem.PictureDisplayed = "P_Print=5 P_Quit=-1"
            pbItem.TableName = ""
            If EmbeddedIn = -1 Then
                pbItem.PictureDisplayed = "P_Previous=4 P_Next=5 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, "capprd:InitControl"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:InitControl"
    CapMouseOn
End Sub

Private Sub ObjectVisible(Optional aVisible As Boolean = True)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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, "capprd:ObjectVisible"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:ObjectVisible"
    CapMouseOn
End Sub

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

Private Sub reload_treeview_Click()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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
    
    End If
    
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    
    ReinitTreeview GetCodeFromCombo(Cbo_View)
    tvitems.Visible = -1
    reload_treeview.Visible = 0

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

Private Sub tbsFilters_Click()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:tbsFilters_Click"
    #End If
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, "capprd:tvItems_NodeClick"
    #End If

    If tvitems.Checkboxes = True Then
        fill_all_record.Visible = True
        GoTo Trace_End
    End If

    grdlst.Requests = ""
    grdlst.ClearGrid
    
    If tvitems.NodeInfo(Node).ml_Level = tvitems.Levels - 1 Then
        fill_all_record.Visible = 0
        grdlst.Requests = tvitems.SelectedNodeRequest
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrd: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, "capprd:tvItems_NodeClick"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:tvItems_NodeClick"
    CapMouseOn
End Sub

Public Sub Load_A_COM(ab_root As Boolean)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:Load_A_Com", "ab_root = " & ab_root
    #End If

    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    Set mo_Tools = New DPC_Tools
    Set mo_Tools.ArmDb = mo_ArmDb
    Call mo_Tools.Load_A_COM
    
    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
    
    grdlst.Load_A_COM
    tvitems.Load_A_COM
    pblst.Load_A_COM
    pbItem.Load_A_COM
    
    pblst.DrivenByCapture = True
    pbItem.DrivenByCapture = True
    
    Cbo_View.Load_A_COM
    Cbo_area.Load_A_COM
    cbo_competitor.Load_A_COM
    cbo_UOM.Load_A_COM
    cbo_Product.Load_A_COM
    
    Cbo_area.FirstBlankItem = False
    Cbo_area.Request = "exec cap_area_cbo " & "'" & m_Language & "'"
    cbo_competitor.FirstBlankItem = False
    cbo_competitor.Request = "exec cap_competitor_cbo " & "'" & m_Language & "'"
    cbo_UOM.FirstBlankItem = False
    cbo_UOM.Request = "exec unit_of_measure_cbo " & "'" & m_Language & "'"

    chk_SC(0).Value = 1

    Load_SCLst

    UserControl.ScaleMode = vbPixels
    
    grdSummary.Load_A_COM
    grdSummary.UnBound = True
    
    'Screen csts
    LoadLabels mo_ArmDb, UserControl.Controls, "Cap_Product_Detail", m_Language
    
    If ab_root = True Then
        'Initialisation treeview et filtres
        Cbo_View.Clear
        Cbo_View.FirstBlankItem = False
        Cbo_View.Request = "exec TreeView_View_t_lst 'Capture_Product'," & "'" & m_Language & "'"
        Cbo_View.Load
        Cbo_View.SearchItem "X", "TV_Default", 0
    End If

    'To do anyway
    reload_treeview.Picture = LoadResPicture(116, vbResIcon)
    reload_treeview.Visible = 0

    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Load_A_Com"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Load_A_Com"
    CapMouseOn
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, "capprd: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, "CapPrd: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, "capprd: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, "capprd:fill_all_record_Click"
    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, "capprd:cas_all", "parm=" & parm
    #End If

    Select Case UCase(parm)
        Case "'ALL'", "''", Len(parm) = 0, "'A'":            cas_all = "Null"
        Case "'M'":  cas_all = "1"
        Case "'L'":  cas_all = "2"
        Case Else: cas_all = parm
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd:cas_all"
    CapMouseOn
End Function
' 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, "capprd: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_Product
    
    ' 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_Product), "#Product")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Project), "#Project")
        
        .tbsEmbedded.Tabs.Item(1).Tag = "tbs_Product"
        .tbsEmbedded.Tabs.Item(2).Tag = "tbs_Project"
        
    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, "capprd:FrameWorkInit"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:FrameWorkInit"
    CapMouseOn
End Sub

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, "capprd:Unload_A_COM"
    #End If

    grdlst.Unload_A_COM
    pblst.Unload_A_COM
    pbItem.Unload_A_COM
    tvitems.Unload_A_COM
    cbo_Product.Unload_A_COM
    Cbo_View.Unload_A_COM
    Cbo_area.Unload_A_COM
    cbo_competitor.Unload_A_COM
    cbo_UOM.Unload_A_COM
    grdSummary.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, "capprd:Unload_A_COM"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Unload_A_COM"
    CapMouseOn
End Sub


' Properties for let application access to critical data
Public Property Get CptTag()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:CptTag_Get"
    #End If
    CptTag = mi_CptTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd:EmbeddedIn_Get"
    #End If
    EmbeddedIn = mi_EmbeddedIn
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd:EmbedTag_Get"
    #End If
    EmbedTag = mi_EmbedTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd:Root_Get"
    #End If
    Root = mb_Root
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd: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, "capprd: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, "capprd:DisplayMode_Get"
    #End If
    DisplayMode = mi_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd: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, "capprd: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, "capprd: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, "capprd: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
            If mi_EmbeddedIn = -1 Then
                LongListDisplay
            Else
                ShortListDisplay ls_Params
            End If
        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, "capprd:SwapToDisplayMode"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:SwapToDisplayMode"
    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, "capprd: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

    cbo_competitor.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:AddDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:AddDisplay"
    CapMouseOn
End Sub
Sub Add_Enablecontrols()

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

    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    ControlsEnable UserControl.Controls, Frame1, True
    
    lbl_Creator.Enabled = False
    txt_creator.Enabled = False
    lbl_Date.Enabled = False
    txt_Date.Enabled = False
    txt_Comment.Locked = False
    Dim lCount As Long, lIdx As Long
    lCount = chk_SC.Count
    For lIdx = 1 To lCount
        chk_SC(lIdx - 1).Enabled = True
    Next
    txt_Qty.Locked = False
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Add_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Add_EnableControls"
    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, "capprd:UpdateDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    '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
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then
        UpdateInitFields
    ElseIf ml_projectStatus <> 13 Then
        Select Case SelSC
        Case 1, 2, 5
            SquareMeter True
        Case 3, 4
            SquareMeter False
        End Select
    End If
    ' disable to update qty if project status is Completed
    txt_Qty.Locked = IIf(ml_projectStatus = 13, True, False)
    
    Update_Resize
    
    cbo_competitor.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:UpdateDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:UpdateDisplay"
    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, "capprd:UpdateInitFields"
    #End If
    
    'idem
    ViewInitFields
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:UpdateInitFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:UpdateInitFields"
    CapMouseOn
End Sub
Sub Update_EnableControls()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:Update_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    ControlsEnable UserControl.Controls, Frame1, True
    
    lbl_Creator.Enabled = False
    txt_creator.Enabled = False
    lbl_Date.Enabled = False
    txt_Date.Enabled = False
    opt_main.Enabled = False
    opt_Alternate.Enabled = False
    cbo_competitor.Enabled = False
    cbo_Product.Enabled = False
    cbo_UOM.Enabled = False
    txt_Comment.Locked = False
    
    Dim lCount As Long, lIdx As Long
    lCount = chk_SC.Count
    For lIdx = 1 To lCount
        chk_SC(lIdx - 1).Enabled = False
    Next
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Update_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Update_EnableControls"
    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, "capprd:DeleteDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
    
    BlankFields
    Delete_EnableControls
    ViewInitFields
    Delete_Resize
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:DeleteDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:DeleteDisplay"
    CapMouseOn
End Sub

Sub Delete_EnableControls()

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

    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    ControlsEnable UserControl.Controls, Frame1, False
    lbl_SolCode.Enabled = True
    txt_SolKey.Enabled = True
    
    txt_Comment.Enabled = True
    txt_Comment.Locked = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Delete_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Delete_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, "capprd: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 does appear now in long list
    InitControl 3
    
    If IsArray(grdlst.CurrentKey) Then
        BlankFields
        View_EnableControls
        ViewLoad
        ViewInitFields
        View_Resize
        ms_View_Key = txt_SolKey.Text & CH_LDELIMIT & cbo_Product.SelectedItemCode
    Else
        View_EnableControls
        View_Resize
        DrawMainGrid
        Call SearchTreeView(ms_View_Key, False)
        If ms_View_Key <> (txt_SolKey.Text & CH_LDELIMIT & cbo_Product.SelectedItemCode) Then
            Call ViewLoad
            Call ViewInitFields
        End If
    End If

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

Sub View_EnableControls(Optional ATag As Boolean = True)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:View_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    ControlsEnable UserControl.Controls, Frame1, False
    lbl_SolCode.Enabled = True
    txt_SolKey.Enabled = True
    
    txt_Comment.Enabled = True
    txt_Comment.Locked = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:View_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:View_EnableControls"
    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, "capprd: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, "capprd:ViewLoad"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd:ShortListDisplay", "ls_Params=" & ls_Params
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Embedded)
   
    ShortList_Resize
    Call ShowDetail
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:ShortListDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd: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
            If mi_EmbeddedIn <> -1 Then
                 RaiseEvent SwitchToView(mt_CstValues.View_Medium)
            End If
            .fraItemBottom.Visible = True
        Else
            .fraItemBottom.Visible = False
            If mi_EmbeddedIn <> -1 Then
                If li_Key = mt_CstValues.Tag_Memo 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 & CH_LDELIMIT & m_CurrentKey3)
        End If
    End With

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

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


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

Private Sub Add_Resize()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:Add_Resize"
    #End If
    
    With UserControl
        
        
        .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
        
        .fraList.Left = .fraItem.Left + mt_CstValues.Frm_Spacing
        .fraList.Top = .fraItemTop.Top + .fraItemTop.Height + mt_CstValues.Frm_Spacing
        .fraList.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
   
        .grdlst.Top = mt_CstValues.Frm_Spacing * 4
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .pblst.Top - (2 * mt_CstValues.Frm_Spacing)
        .grdlst.Zorder 0
        
        .fraList.Visible = True
        .fraList.Zorder 0
    End With

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

Private Sub Update_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:Update_Resize"
    #End If
    
    With UserControl
        
        .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
        
        .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
        
        .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, "capprd:Update_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Update_Resize"
    CapMouseOn
End Sub

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

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

Private Sub Delete_Resize()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:Delete_Resize"
    #End If
    
    With UserControl
        
        
        .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
        
        .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, "capprd:Delete_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Delete_Resize"
    CapMouseOn
End Sub


Private Sub View_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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
        .fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Visible = True
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
        
    End With
    Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, False)
    Call ControlsEnable(UserControl.Controls, UserControl.fra_active, False)

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:View_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd:ShortList_Resize"
    #End If
    
    With UserControl
    
        .fraList.Left = mt_CstValues.Frm_Spacing
        .fraList.Top = mt_CstValues.Frm_Spacing
        .fraList.Width = .Width - .fraList.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
   
        .pblst.Height = mt_CstValues.View_ToolBar_Height
        .pblst.Top = mt_CstValues.Frm_Spacing * 4
        .pblst.Left = mt_CstValues.Frm_Spacing
        .pblst.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
        .pblst.Refresh
        
        .grdlst.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .pblst.Height - .pblst.Top - (2 * mt_CstValues.Frm_Spacing)
        
        Call .grdSummary.Move(grdlst.Left, grdlst.Top, grdlst.Width, grdlst.Height)
        
        .fraFilters.Visible = False
        .fraList.Visible = True
        .fraList.Enabled = True
        .fill_all_record.Visible = 0
        
    End With
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:ShortList_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd: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, "capprd:Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:Resize"
    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, "capprd: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, "capprd:DisplayMode_None"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:DisplayMode_None"
    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, "capprd:AddInitFields"
    #End If
    
    DisplayDefaultValues
               
    SelSC = 1
    
    'initialize the cbo_product
    cbo_Product.SysClassifCode = SelSC
    If Not cbo_competitor.SelectedItem Is Nothing Then
        cbo_Product.CompetitorCode = GetCodeFromCombo(cbo_competitor)
    End If
               
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:AddInitFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd: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, "capprd:BlankFields"
    #End If
    
    opt_main.Value = True
    opt_Alternate.Value = False
    
    cbo_competitor.Clear
    cbo_Product.Clear
    cbo_Product.CompetitorCode = 0
    cbo_Product.SysClassifCode = 0
    
    cbo_UOM.Clear
    Cbo_area.Clear
    
    SelSC = 0
    
    txt_SolKey.Text = ""
    txt_Qty.Text = ""
    txt_spare1.Text = ""
    txt_spare2.Text = ""
    txt_spare3.Text = ""
    txt_Spare4.Text = ""
    txt_Spare5.Text = ""
    txt_spare6.Text = ""
    txt_spare7.Text = ""
    txt_spare8.Text = ""
    txt_Comment.Text = ""
    txt_Date.Text = Format$(Date, "DD/MM/YYYY")
    txt_creator.Text = ""
    'txt_creator.Visible = False
    
    lbl_Spare1.Visible = False
    lbl_Spare2.Visible = False
    lbl_Spare3.Visible = False
    lbl_Spare4.Visible = False
    lbl_Spare5.Visible = False
    lbl_spare6.Visible = False
    lbl_spare7.Visible = False
    lbl_spare8.Visible = False
    txt_spare1.Visible = False
    txt_spare2.Visible = False
    txt_spare3.Visible = False
    txt_Spare4.Visible = False
    txt_Spare5.Visible = False
    txt_spare6.Visible = False
    txt_spare7.Visible = False
    txt_spare8.Visible = False
    
    ml_ProductMtncLevel = -1
    md_qty = 0
               
    If mi_DisplayMode = mt_CstValues.DisplayMode_View Then
        GoToTab1
    End If

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

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:DisplayDefaultValues"
    #End If
    
    If p_DefaultValuesLoaded = False Then
        p_DefaultValuesCount = GetScreenDefaultValues(mo_ArmDb, ms_UID, m_Language, "Cap_Product_Detail", p_DefaultValues)
        p_DefaultValuesLoaded = True
        End If
    DisplayScreenDefaultValues UserControl.Controls, p_DefaultValues, p_DefaultValuesCount

    'Defaulted dates
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    If DisplayMode = mt_CstValues.DisplayMode_Add Then
        
        ls_req = "exec Cap_Date 'Getdate'"
        ll_Cursor = mo_ArmDb.OpenSQL(ls_req, -1, 0)
        If ll_Cursor = 0 Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capprj:DisplayDefaultValues", "Request=" & ls_req
            GoTo Trace_End
        End If

        txt_Date.Text = mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")

        txt_creator.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, "capprd: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, "capprd:DisplayDefaultValues"
    CapMouseOn
End Sub

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

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


    grdlst.ResetGrid
    grdlst.MultiSelect = False
    
    la_Columns(0) = "SOL_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "SOL_code" & CH_LDELIMIT & "SOL_code"
    la_Columns(1) = "S_code" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "2" & CH_LDELIMIT & "S_code" & CH_LDELIMIT & "S_code"
    la_Columns(2) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "3" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(3) = "ma_desc" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ma_desc" & CH_LDELIMIT & "ma_desc"
    la_Columns(4) = "AR_desc" & CH_LDELIMIT & "1700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "AR_desc" & CH_LDELIMIT & "AR_desc"
    la_Columns(5) = "S_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "S_desc" & CH_LDELIMIT & "S_desc"
    la_Columns(6) = "module" & CH_LDELIMIT & "1700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PD_desc" & CH_LDELIMIT & "module"
    la_Columns(7) = "ss_qty" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ss_qty" & CH_LDELIMIT & "ss_qty" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(8) = "um_code" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "um_code" & CH_LDELIMIT & "um_code"
    la_Columns(9) = "z_creator" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "z_creator" & CH_LDELIMIT & "z_creator"
    la_Columns(10) = "z_creation" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "z_creation" & CH_LDELIMIT & "z_creation"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ProductOfProject_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_ProjectProduct_t_lst '" & AProjectKey1 & "', '" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapPrd:ListProjectOf", "Requests=", grdlst.Requests
    End If

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

Private Sub ViewInitFields(Optional ab_UseCurrentKey As Boolean = False)
Dim TheRequest As String
Dim Thekey1 As String
Dim Thekey2 As String
Dim Thekey3 As String
Dim ll_Cursor As Long
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, "capprd:ViewInitFields"
    #End If
    
    If ab_UseCurrentKey = False Then
        'On construit la requête
        Thekey1 = grdlst.CurrentKey(0)
        Thekey2 = grdlst.CurrentKey(1)
        Thekey3 = grdlst.CurrentKey(2)
        
        'Si pas de clé en cours, ie pas de ligne en grille sélectionnée alors bye
        If Thekey1 = "" Or Thekey2 = "" Or Thekey3 = "" Then GoTo Trace_End
        
        'Affectation aux clés membres
        CurrentKey(1) = Thekey1
        CurrentKey(2) = Thekey2
        CurrentKey(3) = Thekey3
    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
        
    TheRequest = "exec cap_solutionsystem_t_sel " & "'" & CurrentKey(1) & "', '" & CurrentKey(2) & "', '" & 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, "CapPrd:ViewInitFields", "Request=" & TheRequest
        GoTo Trace_End
    End If
  
    p_iCon = mo_ArmDb.GetFields(ll_Cursor, "iConcurrency")
    
    opt_main.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "ma_code") = 1, True, False)
    opt_Alternate.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "ma_code") = 2, True, False)
    
    SelSC = mo_ArmDb.GetFields(ll_Cursor, "sc_code")
    
    cbo_competitor.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "cpt_code"), mo_ArmDb.GetFields(ll_Cursor, "cpt_desc")), True
    cbo_competitor_ComboItemSelected
    cbo_Product.Clear
    cbo_Product.CompetitorCode = GetCodeFromCombo(cbo_competitor)
    ls_Code = mo_ArmDb.GetFields(ll_Cursor, "s_code")
    If SelSC = 2 Then
        cbo_Product.LetSelectedItem ls_Code, mo_ArmDb.GetFields(ll_Cursor, "s_desc")
    Else
        cbo_Product.LetSelectedItem ls_Code, Trim(ls_Code) & " - " & mo_ArmDb.GetFields(ll_Cursor, "s_desc")
    End If
    
    cbo_UOM.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "um_code"), mo_ArmDb.GetFields(ll_Cursor, "um_desc")), True
    Cbo_area.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "ar_code"), mo_ArmDb.GetFields(ll_Cursor, "ar_desc")), True
    
    txt_SolKey.Text = CurrentKey(1)
    txt_Qty.Text = mo_ArmDb.GetFields(ll_Cursor, "ss_qty")
    txt_spare1.Text = mo_ArmDb.GetFields(ll_Cursor, "spare1_varchar")
    txt_spare2.Text = mo_ArmDb.GetFields(ll_Cursor, "spare2_varchar")
    txt_spare3.Text = mo_ArmDb.GetFields(ll_Cursor, "spare3_real")
    txt_Spare4.Text = mo_ArmDb.GetFields(ll_Cursor, "spare4_real")
    txt_Spare5.Text = mo_ArmDb.GetFields(ll_Cursor, "spare5_varchar")
    txt_spare6.Text = mo_ArmDb.GetFields(ll_Cursor, "spare6_varchar")
    txt_spare7.Text = mo_ArmDb.GetFields(ll_Cursor, "spare7_real")
    txt_spare8.Text = mo_ArmDb.GetFields(ll_Cursor, "spare8_real")
    txt_Comment.Text = mo_ArmDb.GetFields(ll_Cursor, "ss_comment")
    txt_Date.Text = mo_ArmDb.GetFields(ll_Cursor, "z_creation")
    txt_creator.Text = mo_ArmDb.GetFields(ll_Cursor, "z_creator")
    'txt_creator.Visible = True
    
    'Coming from other
    txt_country.Text = mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
    txt_material.Text = mo_ArmDb.GetFields(ll_Cursor, "PE_desc")
    txt_Family.Text = mo_ArmDb.GetFields(ll_Cursor, "PF_desc")
    txt_segmentation.Text = mo_ArmDb.GetFields(ll_Cursor, "PS_desc")
    ml_ProductMtncLevel = mo_ArmDb.GetFields(ll_Cursor, "ProductMtncLevel")
    md_qty = mo_ArmDb.GetFields(ll_Cursor, "ss_qty")
    

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

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:OwlSearch"
    #End If
    
    ls_ProductKeys = ""
    
    If GetCodeFromCombo(Cbo_View) = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        Cbo_View.SetFocus
        GoTo Trace_End
    End If
        
    Set lo_SearchForm = New SeekForm
    Load lo_SearchForm
    If mb_use_framework_connection = True Then Set lo_SearchForm.ArmDb = mo_ArmDb
    lo_SearchForm.ConnectString = ms_ConnectString
    lo_SearchForm.Language = m_Language
    lo_SearchForm.ComponentType = "PRODUCT"
    
    If (opt_date(1).Value) Then
        lo_SearchForm.TreeView_DateType = "1"
        
    Else
        lo_SearchForm.TreeView_DateType = "0"
    End If
 
    ' Put here the treeview filter desc and the treeview filter !
    lo_SearchForm.TreeViewFiltersDesc = GetCurrentFiltersDescription()
    lo_SearchForm.TreeViewFilters = GetCurrentFilters()

    
    lo_SearchForm.Load_A_COM
    CapMouseOn True
    lo_SearchForm.show 1
    CapMouseOff True
    
    If lo_SearchForm.SelectedData = True Then
        ls_ProductKeys = lo_SearchForm.SelectedItemCode
    End If

    lo_SearchForm.Unload_A_COM
    Unload lo_SearchForm
    Set lo_SearchForm = Nothing
    
    If ls_ProductKeys <> "" Then
        SearchTreeView ls_ProductKeys
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:OwlSearch"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:OwlSearch"
    If Not lo_SearchForm Is Nothing Then
        lo_SearchForm.Unload_A_COM
        Unload lo_SearchForm
        Set lo_SearchForm = Nothing
    End If
    CapMouseOn
End Sub


Private Sub SquareMeter(ab_M2 As Boolean)
Dim i As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:SquareMeter", "ab_M2=" & ab_M2
    #End If
    
    If ab_M2 Then
        cbo_UOM.Enabled = False
        If cbo_UOM.Count = 0 Then
        cbo_UOM.Clear
        cbo_UOM.Load
        End If
        
        For i = 0 To p_DefaultValuesCount - 1
            If p_DefaultValues(i).FieldName = "cbo_UOM" Then
                cbo_UOM.SearchItem p_DefaultValues(i).CodeValue, 0, 0
                Exit For
            End If
        Next
    Else
        If mi_DisplayMode <> mt_CstValues.DisplayMode_Delete And mi_DisplayMode <> mt_CstValues.DisplayMode_View Then
        cbo_UOM.Enabled = True
    End If
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:SquareMeter"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:SquareMeter"
    CapMouseOn
End Sub

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

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

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:SearchTreeView", "as_Key=" & as_Key
    #End If
       
    If as_Key = "" Then GoTo Trace_End
    la_Key = Split(as_Key, CH_LDELIMIT)
    
    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 Cap_SolutionSystem_t_sel2 '" & la_Key(0) & "','" & la_Key(1) & "','" & 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, "CapPrd:SearchTreeView", "Request=" & ls_Request
        GoTo Trace_End
    End If

    ls_RepositionInfo = mo_ArmDb.GetFields(ll_Cursor, "SOL_code") & mo_ArmDb.GetFields(ll_Cursor, "S_code") & mo_ArmDb.GetFields(ll_Cursor, "Language_code")
    lv_Key = Split(mo_ArmDb.GetFields(ll_Cursor, "SOL_code") & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code") & 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, "Z_creator")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
    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, "Z_creator")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SBM_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PF_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
        
    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, "Z_creator")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PS_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PF_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
    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, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
    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, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "SBM_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PF_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
    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, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PS_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "PF_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
    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, "CPT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CG_Desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "S_code")
    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, "S_code")
   
        
    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_Key, 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_Key, 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, "capprd: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, "capprd:SearchTreeView"
    CapMouseOn
End Sub

Private Sub Load_SCLst()
Dim ll_Cursor As Long
Dim ls_Request As String
Dim li_Count As Integer

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd:Load_SCLst"
    #End If
    
    'Try connexion
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End

    ls_Request = "exec cap_systemclassif_t_lst '" & 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, "CapPrd:Load_SCLst", "Request=" & ls_Request
        GoTo Trace_End
    End If

    mb_SCChkUse = True
    li_Count = 0
    Do While mo_ArmDb.EOF(ll_Cursor) = False
        ' Only the first is created !
        If li_Count > 0 Then
        
            On Error Resume Next
        
            Load chk_SC(li_Count)
            chk_SC(li_Count).Top = chk_SC(li_Count - 1).Top + 250
            chk_SC(li_Count).Visible = True
            chk_SC(li_Count).Container = fraItemTop
            
            On Error GoTo Trace_Err
        End If
        chk_SC(li_Count).Tag = mo_ArmDb.GetFields(ll_Cursor, "SC_CODE")
        chk_SC(li_Count).Caption = mo_ArmDb.GetFields(ll_Cursor, "SC_DESC")
        chk_SC(li_Count).Value = 0
        li_Count = li_Count + 1
        mo_ArmDb.Next ll_Cursor
    Loop
    mb_SCChkUse = False
    mi_SC_Count = li_Count
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:Load_SCLst"
    #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, "capprd:Load_SCLst"
    CapMouseOn
End Sub

Private Function GetCurrentFiltersDescription() As String
    
Dim ls_Buffer As String
Dim li_SAFlag As String
Dim ls_Date As String
Dim Check As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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
    
    li_SAFlag = tbsFilters.SelectedItem
      
    If chk_SA.Value = 1 Then Check = chk_SA.Caption
    
    If opt_date(0).Value Then ls_Date = opt_date(0).Caption
    If opt_date(1).Value Then
        ls_Date = opt_date(1).Caption & " " & cal11.date_courte & " && " & cal12.date_courte
    End If
     
    GetCurrentFiltersDescription = ls_Buffer + " , " + ls_Date + " , " + IIf(Check <> "", Check + " , ", "") + li_SAFlag
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capprd:GetCurrentFiltersDescription", "Result=" & GetCurrentFiltersDescription
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capprd:GetCurrentFiltersDescription"
    CapMouseOn
End Function


Private Function GetCurrentFilters() As String
Dim ls_Buffer As String
Dim ls_Date1 As String
Dim ls_Date2 As String
Dim ls_SA As String
Dim ls_MA As String
Dim ls_CPT As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capprd: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 chk_SA.Value = 1 Then
        ls_SA = "X"
    Else
        ls_SA = " "
    End If
    
    Select Case tbsFilters.SelectedItem.Index
        Case 1
            ls_MA = ""
        Case 2
            ls_MA = "1"
        Case 3
            ls_MA = "2"
    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
    
    ' Add here the filter for say if we want only armstrong product
    Select Case UCase(GetCodeFromCombo(Cbo_View))
        Case "VG"
            ls_CPT = ""
        Case Else
            ls_CPT = "1"
    End Select
    
    GetCurrentFilters = ls_Buffer & CH_LDELIMIT & ls_MA & CH_LDELIMIT & ls_SA & CH_LDELIMIT & ls_Date1 & CH_LDELIMIT & ls_Date2 & CH_LDELIMIT & ls_CPT

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



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

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

    If Not ab_FromEmbedded Then
        ' TO DO
    Else
        ' NOTHING TO DO
    End If

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


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

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

Private Sub ShowDetail()
    pblst.DrivenByCapture = True
    pblst.ClearAllIcons
    pblst.TableName = mt_CstValues.SecurityProduct_lst
    pblst.PictureDisplayed = "P_Compute=5 P_Refresh=7"
    pblst.Refresh
    grdlst.Visible = True
    grdSummary.Visible = False
End Sub


Private Sub ShowSummary()
    
    pblst.DrivenByCapture = False
    pblst.ClearAllIcons
    pblst.PictureDisplayed = "P_Quit=-1"
    pblst.Refresh
    grdlst.Visible = False
    
    ' Initialize the grid if needed
    If grdSummary.Cols = 0 Then
        Dim la_Columns(5) As String
        la_Columns(0) = "S_code" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "1" & CH_LDELIMIT & "S_code" & CH_LDELIMIT & grdlst.Columns("S_code").Title
        la_Columns(1) = "ma_desc" & CH_LDELIMIT & "800" & CH_LDELIMIT & "2" & CH_LDELIMIT & "ma_desc" & CH_LDELIMIT & grdlst.Columns("ma_desc").Title
        la_Columns(2) = "S_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "S_desc" & CH_LDELIMIT & grdlst.Columns("S_desc").Title
        la_Columns(3) = "module" & CH_LDELIMIT & "1700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PD_desc" & CH_LDELIMIT & grdlst.Columns("module").Title
        la_Columns(4) = "ss_qty" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ss_qty" & CH_LDELIMIT & grdlst.Columns("ss_qty").Title & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
        la_Columns(5) = "um_code" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "um_code" & CH_LDELIMIT & grdlst.Columns("um_code").Title
        grdSummary.SetColumns la_Columns
    End If
    
    
    If grdlst.Rows = 0 Then Exit Sub
    
    grdSummary.ClearGrid
    
    ' Now calculate
    Dim ls_Code As String, lMA_Desc As String
    Dim lIdx As Long, lCount As Long
    lCount = grdlst.Rows - 1
    For lIdx = 0 To lCount
        ls_Code = grdlst.Data(lIdx, "S_CODE")
        lMA_Desc = grdlst.Data(lIdx, "MA_Desc")
        If grdSummary.SearchKey(True, Array(ls_Code, lMA_Desc)) Then
            grdSummary.SelectedLine(0, "SS_Qty") = grdSummary.SelectedLine(0, "SS_Qty") + grdlst.Data(lIdx, "ss_qty")
        Else
            grdSummary.AddLine (Array(ls_Code, lMA_Desc, grdlst.Data(lIdx, "S_Desc"), grdlst.Data(lIdx, "module"), grdlst.Data(lIdx, "ss_qty"), grdlst.Data(lIdx, "UM_Code")))
        End If
        
    Next
    
    Call grdSummary.FirstLine
    grdSummary.Visible = True
    
End Sub





















