VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl CapPrdValOf 
   ClientHeight    =   10320
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   12105
   ScaleHeight     =   10320
   ScaleWidth      =   12105
   Begin VB.TextBox txt_totalSize 
      Height          =   300
      Left            =   11010
      Locked          =   -1  'True
      TabIndex        =   50
      Tag             =   "txt_totalSize"
      Top             =   720
      Width           =   1005
   End
   Begin VB.TextBox txt_size 
      Height          =   330
      Left            =   8280
      Locked          =   -1  'True
      TabIndex        =   48
      Tag             =   "txt_size"
      Top             =   690
      Width           =   975
   End
   Begin VB.Frame fraItem 
      Height          =   5085
      Left            =   30
      TabIndex        =   8
      Top             =   4800
      Width           =   11805
      Begin VB.Frame fraItemTop 
         Height          =   4020
         Left            =   60
         TabIndex        =   10
         Top             =   900
         Width           =   11625
         Begin VB.TextBox txt_spare2 
            Height          =   330
            Left            =   9000
            TabIndex        =   32
            Top             =   1680
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.Frame Frame1 
            Height          =   1155
            Left            =   120
            TabIndex        =   27
            Top             =   600
            Width           =   5000
            Begin VB.OptionButton opt_Alternate 
               Caption         =   "#Alternate"
               Height          =   275
               Left            =   2500
               TabIndex        =   30
               Tag             =   "lbl_alternate"
               Top             =   180
               Width           =   1920
            End
            Begin VB.OptionButton opt_main 
               Caption         =   "#Main"
               Height          =   275
               Left            =   120
               TabIndex        =   29
               Tag             =   "lbl_main"
               Top             =   180
               Value           =   -1  'True
               Width           =   1920
            End
            Begin Project1.ArmCombobox cbo_area 
               Height          =   345
               Left            =   2160
               TabIndex        =   28
               Tag             =   "cbo_area"
               Top             =   720
               Width           =   2715
               _ExtentX        =   4789
               _ExtentY        =   609
            End
            Begin VB.Label lbl_are 
               Caption         =   "#Area "
               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        =   31
               Tag             =   "lbl_area"
               Top             =   720
               Width           =   675
            End
         End
         Begin VB.TextBox txt_qty 
            Height          =   315
            Left            =   2070
            TabIndex        =   26
            Tag             =   "txt_qty"
            Top             =   2580
            Width           =   1095
         End
         Begin VB.TextBox txt_creator 
            Enabled         =   0   'False
            Height          =   330
            Left            =   9345
            TabIndex        =   25
            Tag             =   "txt_creator"
            Text            =   "L. Cockayne"
            Top             =   600
            Width           =   2835
         End
         Begin VB.TextBox txt_Date 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   9330
            TabIndex        =   24
            Tag             =   "txt_Date"
            Text            =   "02/02/2001"
            Top             =   240
            Width           =   1095
         End
         Begin VB.TextBox txt_comment 
            Height          =   975
            Left            =   2100
            MaxLength       =   2000
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   23
            Tag             =   "txt_comment"
            Top             =   2970
            Width           =   5775
         End
         Begin VB.TextBox txt_spare1 
            Height          =   330
            Left            =   8970
            TabIndex        =   22
            Top             =   1260
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare3 
            Height          =   330
            Left            =   8940
            TabIndex        =   21
            Top             =   1920
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare4 
            Height          =   330
            Left            =   8910
            TabIndex        =   20
            Top             =   2160
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare5 
            Height          =   285
            Left            =   8940
            TabIndex        =   19
            Tag             =   "txt_spare5"
            Top             =   2460
            Visible         =   0   'False
            Width           =   975
         End
         Begin VB.TextBox txt_spare6 
            Height          =   285
            Left            =   8970
            TabIndex        =   18
            Tag             =   "txt_spare6"
            Top             =   2730
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.TextBox txt_spare7 
            Height          =   285
            Left            =   9270
            TabIndex        =   17
            Tag             =   "txt_spare7"
            Top             =   3030
            Visible         =   0   'False
            Width           =   615
         End
         Begin VB.TextBox txt_spare8 
            Height          =   285
            Left            =   9420
            TabIndex        =   16
            Tag             =   "txt_spare8"
            Top             =   3360
            Visible         =   0   'False
            Width           =   975
         End
         Begin VB.TextBox txt_SolKey 
            Height          =   330
            Left            =   2100
            Locked          =   -1  'True
            TabIndex        =   12
            Tag             =   "txt_SolKey"
            Top             =   240
            Width           =   3015
         End
         Begin VB.CheckBox chk_SC 
            Caption         =   "#Ceiling"
            Height          =   315
            Index           =   0
            Left            =   5220
            TabIndex        =   11
            Top             =   720
            Value           =   1  'Checked
            Width           =   2630
         End
         Begin Project1.ArmCombobox cbo_UOM 
            Height          =   345
            Left            =   3330
            TabIndex        =   13
            Tag             =   "cbo_UOM"
            Top             =   2580
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_competitor 
            Height          =   345
            Left            =   2070
            TabIndex        =   14
            Tag             =   "cbo_competitor"
            Top             =   1830
            Width           =   5775
            _ExtentX        =   10186
            _ExtentY        =   609
         End
         Begin Project1.cboPrd cbo_product 
            Height          =   315
            Left            =   2070
            TabIndex        =   15
            Tag             =   "cbo_product"
            Top             =   2220
            Width           =   5775
            _ExtentX        =   10186
            _ExtentY        =   556
         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            =   150
            TabIndex        =   47
            Tag             =   "lbl_qty"
            Top             =   2640
            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            =   150
            TabIndex        =   46
            Tag             =   "lbl_product"
            Top             =   2220
            Width           =   1920
         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            =   150
            TabIndex        =   45
            Tag             =   "lbl_competitor"
            Top             =   1950
            Width           =   1920
         End
         Begin VB.Label lbl_Creator 
            Caption         =   "#By"
            Height          =   255
            Left            =   8010
            TabIndex        =   44
            Tag             =   "lbl_creator"
            Top             =   660
            Width           =   1200
         End
         Begin VB.Label lbl_Date 
            Caption         =   "#Creation date"
            Height          =   255
            Left            =   8010
            TabIndex        =   43
            Tag             =   "lbl_date"
            Top             =   300
            Width           =   1920
         End
         Begin VB.Label lbl_comment 
            Caption         =   "#Comments"
            Height          =   255
            Left            =   120
            TabIndex        =   42
            Tag             =   "lbl_comment"
            Top             =   2970
            Width           =   1920
         End
         Begin VB.Label lbl_spare1 
            Caption         =   "#lbl_spare1"
            Height          =   285
            Left            =   8100
            TabIndex        =   41
            Tag             =   "lbl_spare1"
            Top             =   1320
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare2 
            Caption         =   "#lbl_spare2"
            Height          =   195
            Left            =   8100
            TabIndex        =   40
            Tag             =   "lbl_spare2"
            Top             =   1710
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare3 
            Caption         =   "#lbl_spare3"
            Height          =   195
            Left            =   8040
            TabIndex        =   39
            Tag             =   "lbl_spare3"
            Top             =   2010
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare4 
            Caption         =   "#lbl_spare4"
            Height          =   195
            Left            =   7980
            TabIndex        =   38
            Tag             =   "lbl_spare4"
            Top             =   2310
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare5 
            Caption         =   "#lbl_spare5"
            Height          =   255
            Left            =   8100
            TabIndex        =   37
            Tag             =   "lbl_spare5"
            Top             =   2460
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare6 
            Caption         =   "#lbl_spare6"
            Height          =   255
            Left            =   8250
            TabIndex        =   36
            Tag             =   "lbl_spare6"
            Top             =   2730
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare7 
            Caption         =   "#lbl_spare7"
            Height          =   255
            Left            =   8550
            TabIndex        =   35
            Tag             =   "lbl_spare7"
            Top             =   3030
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_spare8 
            Caption         =   "#lbl_spare8"
            Height          =   255
            Left            =   8460
            TabIndex        =   34
            Tag             =   "lbl_spare8"
            Top             =   3360
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.Label lbl_SolCode 
            Caption         =   "#Solution key"
            Height          =   255
            Left            =   120
            TabIndex        =   33
            Tag             =   "lbl_SolCode"
            Top             =   300
            Width           =   1920
         End
      End
      Begin Project1.ToolBr pbItem2 
         Height          =   525
         Left            =   510
         TabIndex        =   9
         Top             =   240
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   1614
      End
   End
   Begin VB.TextBox txt_Desc 
      Height          =   315
      Left            =   1440
      Locked          =   -1  'True
      TabIndex        =   4
      Top             =   720
      Width           =   5475
   End
   Begin VB.CheckBox chk_Ref 
      Height          =   255
      Left            =   3630
      TabIndex        =   2
      Tag             =   "chk_Ref"
      Top             =   4530
      Width           =   1335
   End
   Begin Project1.ArmCombobox cbo_LR 
      Height          =   345
      Left            =   3630
      TabIndex        =   0
      Top             =   4110
      Width           =   4455
      _ExtentX        =   7858
      _ExtentY        =   609
   End
   Begin Project1.ToolBr pbItem 
      Align           =   1  'Align Top
      Height          =   315
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   12105
      _ExtentX        =   21352
      _ExtentY        =   556
   End
   Begin MSComctlLib.ListView lv_Products 
      Height          =   3015
      Left            =   0
      TabIndex        =   3
      Top             =   1080
      Width           =   12015
      _ExtentX        =   21193
      _ExtentY        =   5318
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      Checkboxes      =   -1  'True
      FullRowSelect   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   13
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Object.Tag             =   "c1"
         Text            =   "#WON"
         Object.Width           =   1058
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Object.Tag             =   "c2"
         Text            =   "#M/A"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Object.Tag             =   "c3"
         Text            =   "#Area"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Object.Tag             =   "c4"
         Text            =   "#Short Code"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Object.Tag             =   "c5"
         Text            =   "#Product"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   5
         Object.Tag             =   "c6"
         Text            =   "#Size"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(7) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   6
         Object.Tag             =   "c7"
         Text            =   "#Module"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(8) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   7
         Object.Tag             =   "c8"
         Text            =   "#Measure"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(9) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   8
         Object.Tag             =   "c9"
         Text            =   "#Creator"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(10) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   9
         Object.Tag             =   "c10"
         Text            =   "#Date entered"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(11) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   10
         Object.Tag             =   "C11"
         Text            =   "#Type"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(12) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   11
         Text            =   "#Type code"
         Object.Width           =   2540
      EndProperty
      BeginProperty ColumnHeader(13) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   12
         Text            =   "#CG_Code"
         Object.Width           =   2540
      EndProperty
   End
   Begin VB.Label lbl_selectedSize 
      Alignment       =   1  'Right Justify
      Caption         =   "#Selected Total"
      Height          =   255
      Left            =   9300
      TabIndex        =   51
      Tag             =   "lbl_selectedSize"
      Top             =   750
      Width           =   1665
   End
   Begin VB.Label lbl_size 
      Alignment       =   1  'Right Justify
      Caption         =   "#Project size"
      Height          =   255
      Left            =   6930
      TabIndex        =   49
      Tag             =   "lbl_size"
      Top             =   750
      Width           =   1290
   End
   Begin VB.Label lbl_Desc 
      Alignment       =   1  'Right Justify
      Caption         =   "#Project Name"
      Height          =   255
      Left            =   0
      TabIndex        =   7
      Tag             =   "lbl_Desc"
      Top             =   780
      Width           =   1395
   End
   Begin VB.Label lbl_LR 
      Caption         =   "#Reason why unselect lines were lost"
      Height          =   255
      Left            =   150
      TabIndex        =   6
      Tag             =   "lbl_LR"
      Top             =   4170
      Width           =   3315
   End
   Begin VB.Label lbl_Ref 
      Caption         =   "#Reference Project"
      Height          =   255
      Left            =   150
      TabIndex        =   5
      Tag             =   "lbl_Ref"
      Top             =   4530
      Width           =   3315
   End
End
Attribute VB_Name = "CapPrdValOf"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'what is new
'2.6.4 : The products to calculate size of ceiling is now based on CT_Code and in case of AS procut also on CG_Code (JN)

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

'******** 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

Private mb_DoCheck As Boolean

Private m_Language As String

Private ms_SP As String                 ' Sales Project ID
Private mi_Conc As Integer
Private ms_SpCountry As String

Private mb_Validated As Boolean
Private ml_StatusCode As Long

Private p_CountRec As Integer

' task 299.5 constants for initialization of CapPrd control
Private mt_CstValues As Type_CstValues  ' Structure which contains constants value
Private ml_projectSize As Long          ' Project size
' copy from CapPrd
Private mi_DisplayMode As Variant       ' Current display mode
Private mb_SCChkUse As Boolean          ' Use as flag for recursive call of SC function
Private p_DefaultValues(MAX_VALUE) As DefaultValue
Private p_DefaultValuesCount As Integer
Private p_DefaultValuesLoaded As Boolean

'_______________________________FRAMEWORK EVENTS__________________________________________________________
' MANDATORY
' This section describes the events use by the object in order to communicates with the application or
' the other components
Public Event Updated()          ' rerise Updated event from CapProduct user control
' task 299.5 end
Public Event quit()
'_________________________________________________________________________________________________________


' task 299.5 begin property for constants
Public Property Set CstValues(ByRef ao_val As Type_CstValues)
    Set mt_CstValues = ao_val
End Property

Public Property Let ProjectSize(ByVal al_Size As Long)
    ml_projectSize = al_Size
End Property
' task 299.5 end

Public Property Set ArmDb(ByRef ao_local_connection As Object)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf: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 cbo_LR.ArmDb = mo_ArmDb
        Set pbItem.ArmDb = mo_ArmDb
' task299.5 begin - copy from CapPrd
        Set pbItem2.ArmDb = mo_ArmDb
        Set cbo_Product.ArmDb = mo_ArmDb
        Set Cbo_area.ArmDb = mo_ArmDb
        Set cbo_competitor.ArmDb = mo_ArmDb
        Set cbo_UOM.ArmDb = mo_ArmDb
' task 299.5 end
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf: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, "PrdValOf: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
    cbo_LR.ConnectString = ms_ConnectString
    pbItem.ConnectString = ms_ConnectString
' task 299.5 begin -- copy from CapPrd
    pbItem2.ConnectString = ms_ConnectString
    cbo_Product.ConnectString = ms_ConnectString
    Cbo_area.ConnectString = ms_ConnectString
    cbo_competitor.ConnectString = ms_ConnectString
    cbo_UOM.ConnectString = ms_ConnectString
' task 299.5 end

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

Property Let Language(ALng As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Language_Let", "ALng=" & ALng
    #End If
    CapMouseOff
    
    m_Language = ALng
    pbItem.Language = m_Language
' task 299.5 - copy from CapPrd
    pbItem2.Language = m_Language
    cbo_Product.Language = m_Language
' task 299.5 - end
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Language_Let"
    #End If
    CapMouseOn
End Property

Public Property Get Validated() As Boolean
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Validated_Get"
    #End If
    CapMouseOff
    
    Validated = mb_Validated
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Validated_Get", "Result=" & Validated
    #End If
    CapMouseOn
End Property

Public Property Get StatusCode() As Long
    
    StatusCode = ml_StatusCode
End Property

Property Get CountRec() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:CountRec_Get"
    #End If
    CapMouseOff
    
    CountRec = p_CountRec
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:CountRec_Get", "Result=" & CountRec
    #End If
    CapMouseOn
End Property

Property Let iConc(AiConc As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:iConc_Let", "AiConc=" & AiConc
    #End If
    CapMouseOff
    
    mi_Conc = AiConc
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:iConc_Let"
    #End If
    CapMouseOn
End Property

Public Property Get project() As String
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Project_Get"
    #End If
    CapMouseOff
    
    project = ms_SP
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Project_Get", "Result=" & project
    #End If
    CapMouseOn
End Property

Public Property Let project(ByVal as_ProjectKey As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Project_Let", "as_ProjectKey=" & as_ProjectKey
    #End If
    CapMouseOff
    
    ms_SP = as_ProjectKey
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Project_Let"
    #End If
    CapMouseOn
End Property

Public Property Let projectCountry(ByVal as_ProjectCountry As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:projectCountry", "as_ProjectCountry=" & as_ProjectCountry
    #End If
    CapMouseOff
    
    ms_SpCountry = as_ProjectCountry
    cbo_Product.CT_Code = as_ProjectCountry     ' bug61:fix 06.12.2006 JULO
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:projectCountry"
    #End If
    CapMouseOn
End Property

Public Sub Display()
Dim TheRequest As String
Dim ll_cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Display"
    #End If
      
'task 299.5 begin
    txt_Size.Text = ml_projectSize
'task 299.5 end

    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    TheRequest = "exec sales_project_t_sel4 " & "'" & ms_SP & "', 'E'"
    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, "PrdValOf:Display", "Request=" & TheRequest
        GoTo Trace_End
    End If
    txt_Desc = mo_ArmDb.GetFields(ll_cursor, "SP_desc")
    LoadListView
    
Trace_End:
    mo_ArmDb.Close ll_cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Display"
    #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, "PrdValOf:Display"
    CapMouseOn
End Sub

Public Function Save() As Boolean
Dim ll_Idx As Long
Dim ll_Count As Long
Dim ls_SOL_Code As String
Dim li_conc As String
Dim ls_S_code As String
Dim lv_Key As Variant
Dim ls_LR_code As String
Dim ls_S_install As String
Dim ls_req As String
Dim li_concp    As Integer
Dim ls_LFlag As String
Dim lb_Result As Boolean
Dim ls_Result As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Save"
    #End If
      
    Save = False
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ll_Count = lv_Products.ListItems.Count
    
    ls_LFlag = "L"
    If Not mb_DoCheck Then
        ls_LFlag = "N"
        For ll_Idx = 1 To ll_Count
            If lv_Products.ListItems.Item(ll_Idx).Checked Then
                ls_LFlag = "L"
                Exit For
            End If
        Next
    End If

    lb_Result = True
    
    Dim lSelLRCode As String
    If cbo_LR.SelectedItem Is Nothing Then
        lSelLRCode = "NULL"
    Else
        lSelLRCode = "'" & GetCodeFromCombo(cbo_LR) & "'"
    End If
    
    For ll_Idx = 1 To ll_Count
        lv_Key = Split(lv_Products.ListItems.Item(ll_Idx).Tag, CH_LDELIMIT)
        ls_SOL_Code = lv_Key(0)
        ls_S_code = lv_Key(1)
        li_conc = CInt(lv_Key(2))
        
        If lv_Products.ListItems.Item(ll_Idx).Checked Then
            ls_LR_code = "NULL"
            ls_S_install = "W"
        Else
            ls_LR_code = lSelLRCode
            ls_S_install = ls_LFlag
        End If
            
        ls_req = "exec Cap_SolutionSystem_upd2 " & "'" & ls_SOL_Code & "', '" & ls_S_code & "', " & ls_LR_code & ", '" & ls_S_install & "', '" & li_conc & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_req, ls_Result)
        If lb_Result = False Then GoTo Trace_End
    Next
    
    If chk_Ref.Value = 1 Then
        li_concp = mi_Conc + 1
        ls_req = "exec Sales_Project_upd3 " & "'" & ms_SP & "', '" & li_concp & "' , '16'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_req, ls_Result)
        ml_StatusCode = 16
    End If

    Save = lb_Result

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

Private Function Check() As Boolean
Dim ll_Idx As Long
Dim ll_Count As Long
Dim lb_Check As Boolean
Dim lb_UnCheck As Boolean
Dim lb_Result As String
Dim ls_Result As String
Dim ls_Request As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Check"
    #End If
     
    If Not cbo_LR.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_LR) <> "" Then
            ls_Request = "Exec Cap_LooseReason_chk " & GetCodeFromCombo(cbo_LR) & ",'" & ms_SpCountry & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_LR.Caption & " : " & cbo_LR.SelectedItem.DisplayText)
                    cbo_LR.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    End If
    
    If Not mb_DoCheck Then
        Check = True
        GoTo Trace_End
    End If
     
    lb_UnCheck = False
    lb_Check = False
    'task 299.5 begin
    Dim ll_sizeSumm As Long
    ll_sizeSumm = 0
    'task 299.5 end
   
    ' if one item is not checked, user must choose a loose reason
    ll_Count = lv_Products.ListItems.Count
    
    For ll_Idx = 1 To ll_Count
        If Not lv_Products.ListItems.Item(ll_Idx).Checked Then
            lb_UnCheck = True
        Else
            'task 299.5 begin
            If isNumeric(lv_Products.ListItems.Item(ll_Idx).SubItems(6)) And _
                         ((lv_Products.ListItems.Item(ll_Idx).SubItems(11) = 1) Or _
                         (lv_Products.ListItems.Item(ll_Idx).SubItems(11) = 4 And lv_Products.ListItems.Item(ll_Idx).SubItems(12) = "C001") Or _
                         (lv_Products.ListItems.Item(ll_Idx).SubItems(11) = 5 And lv_Products.ListItems.Item(ll_Idx).SubItems(12) = "C006")) Then    '1...ceilings OR 4.. AS procuct of category 'C001' OR 5.. WALLS of category 'C006'
                
                ll_sizeSumm = ll_sizeSumm + CLng(lv_Products.ListItems.Item(ll_Idx).SubItems(6))
            End If
            'task 299.5 end
            lb_Check = True
        End If
    Next
    
    If lb_UnCheck And (GetCodeFromCombo(cbo_LR) = "") Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 203, "#You must choose a loose reason")
        Check = False
        GoTo Trace_End
    End If
    
    'task 299.5 begin
    If Not lb_Check Or ll_sizeSumm <> ml_projectSize Then
        Dim ls_perc As String
        ls_perc = Get_A_Config("CAP_PRJ_VALID_TOLERANCE")
        If isNumeric(ls_perc) And ml_projectSize > 0 Then
            ' we also chcek tolerance to display alternative message (warning)
            If (1 - (ll_sizeSumm / ml_projectSize)) * 100 <= CLng(ls_perc) Then
                ' yes the difference is within tolerance or ll_sizeSumm > ml_projectSize
                If ASC_SendMessage(mo_ArmDb, m_Language, 294, "Warning: total sum of selected products do not match project size. Continue?", "", vbYesNo Or vbExclamation) = vbYes Then
                    Check = True
                    GoTo Trace_End
                Else
                    Check = False
                    GoTo Trace_End
                End If
            End If
        End If
        
        Call ASC_SendMessage(mo_ArmDb, m_Language, 204, "You must confirm at least one product")
        Check = False
        GoTo Trace_End
    End If
    'task 299.5 end
    
    Check = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Check", "Result=" & Check
    #End If
    CapMouseOn
    Exit Function
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:Check"
    CapMouseOn
End Function

Private Sub LoadListView()
Dim ln_Node As ListItem
Dim ls_LRcode As String
Dim ls_req As String
Dim ls_LRdesc As String
Dim ll_cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:LoadListView"
    #End If
      
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ls_req = "exec Cap_ProjectProduct_t_lst2 " & "'" & ms_SP & "', '" & m_Language & "'"
    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, "PrdValOf:LoadListView", "Request=" & ls_req
        GoTo Trace_End
    End If
    
    p_CountRec = mo_ArmDb.RowCount(ll_cursor)
    
'task 299.5 reset items ( undo now works )
    cbo_LR.Clear
    chk_Ref.Value = False       ' is this field loaded somewhere?
    lv_Products.ListItems.Clear
'task 299.5 change column 11, 12 .. SC_CODE, CG_CODE to 0
    lv_Products.ColumnHeaders.Item(12).Width = 0      ' set column 11 to zero width
    lv_Products.ColumnHeaders.Item(13).Width = 0      ' set column 12 to zero width
    mo_ArmDb.First ll_cursor
       
    Call AppendListView(lv_Products, ll_cursor, cbo_LR) ' task 299.5
    txt_totalSize.Text = CStr(GetSelectedSize(lv_Products))     ' task 299.5
    
Trace_End:
    mo_ArmDb.Close ll_cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:LoadListView"
    #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, "PrdValOf:LoadListView"
    CapMouseOn
End Sub

Private Sub UserControl_Initialize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:UserControl_Initialize"
    #End If
      
    ms_SP = ""
    mb_Validated = False
    ml_StatusCode = 0

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

Public Sub Load_A_COM()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:Load_A_Com"
    #End If
      
    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    pbItem.Load_A_COM
    pbItem.DrivenByCapture = True
    cbo_LR.Load_A_COM
' task 299.5 begin - copy from CapPrd
    pbItem2.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
    
' task 299.5 end
    
    cbo_LR.FirstBlankItem = False
    cbo_LR.SearchPrefix = " "
    cbo_LR.Request = "exec cap_loosereason_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    
    pbItem.ClearAllIcons
' taks299.5 begin init
    pbItem2.ClearAllIcons
    'add new icon into toolbar
    pbItem.PictureDisplayed = "P_Valid=1 P_Undo=2 P_Quit=-1 P_Add=3"
    pbItem2.PictureDisplayed = "P_Valid=1 P_Undo=2 P_Quit=-1"
    
' disable some controls by default
    Lbl_Creator.Enabled = False
    Txt_Creator.Enabled = False
    lbl_date.Enabled = False
    txt_Date.Enabled = False
    fraItem.Visible = False
' task 299.5 end

    Call LoadLabels(mo_ArmDb, UserControl.Controls, "Cap_Product_Validation", m_Language)
    
    Call RAZ
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:Load_A_Com"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:Load_A_Com"
    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, "PrdValOf:Unload_A_Com"
    #End If
      
    pbItem.Unload_A_COM
    cbo_LR.Unload_A_COM
'task 299.5 begib  -- copy from CapPrd
    pbItem2.Unload_A_COM
    cbo_Product.Unload_A_COM
    Cbo_area.Unload_A_COM
    cbo_competitor.Unload_A_COM
    cbo_UOM.Unload_A_COM
'task 299.5 end
    ASC_DisconnectFromDB mo_ArmDb, ms_UID, mb_Created
    
    Set mo_ArmDb = Nothing

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

Private Sub pbItem_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, "PrdValOf:pbItem_action", "as_ActionType=" & as_ActionType
    #End If
      
    Select Case as_ActionType
        Case "Quit"
            RaiseEvent quit

        Case "Undo"
            LoadListView
            
        Case "Valid"
            If Check = True Then
                mb_Validated = True
                RaiseEvent quit
            End If
' task 299.5 begin handler for add icon click event
        Case "Add"
            DisplayMode = mt_CstValues.DisplayMode_Add
'            CapProduct.project = Me.project & CH_LDELIMIT & m_Language & CH_LDELIMIT & ms_SpCountry
'            CapProduct.DisplayMode = mt_CstValues.DisplayMode_Add
' task 299.5 end
        Case Else
            RaiseEvent quit
    End Select

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

Public Property Let DoCheck(ByVal ab_DoCheck As Boolean)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:DoCheck_Let", "ab_DoCheck =" & ab_DoCheck
    #End If
    CapMouseOff
    
    mb_DoCheck = ab_DoCheck
    lbl_LR.FontBold = mb_DoCheck
'    cbo_LR.Clear                           ' moved to loadTreeView task 299.5
    cbo_LR.FirstBlankItem = Not mb_DoCheck
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:DoCheck_Let"
    #End If
    CapMouseOn
End Property

Public Property Get DoCheck() As Boolean
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:DoCheck_Get"
    #End If
    CapMouseOff
    
    DoCheck = mb_DoCheck
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:DoCheck_Get", "Result =" & mb_DoCheck
    #End If
    CapMouseOn
End Property


Public Sub RAZ()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:RAZ"
    #End If
    CapMouseOff
    
    mb_Validated = False
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:RAZ"
    #End If
    CapMouseOn
End Sub


Public Sub Refresh()
    pbItem.Refresh
End Sub

Private Sub AppendListView(ByRef ao_ListView As ListView, ByVal al_cursor As Long, Optional ByRef ao_LR As ArmCombobox = Nothing)
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:AppendListViewLocal"
    #End If
    
    Dim ln_Node     As ListItem
    Dim ls_LRcode   As String
    Dim ls_LRdesc   As String
    
    Do Until mo_ArmDb.EOF(al_cursor)
        Set ln_Node = ao_ListView.ListItems.Add
        ln_Node.Text = ""
        ln_Node.Tag = mo_ArmDb.GetFields(al_cursor, "SOL_CODE") & CH_LDELIMIT & mo_ArmDb.GetFields(al_cursor, "S_CODE") & CH_LDELIMIT & CStr(mo_ArmDb.GetFields(al_cursor, "iConcurrency"))
        ln_Node.Checked = IIf(mo_ArmDb.GetFields(al_cursor, "S_InstallFlag") = "W", 1, 0)
        ln_Node.SubItems(1) = mo_ArmDb.GetFields(al_cursor, "MA_desc")
        ln_Node.SubItems(2) = mo_ArmDb.GetFields(al_cursor, "AR_DESC")
        ln_Node.SubItems(3) = mo_ArmDb.GetFields(al_cursor, "S_CODE")
        ln_Node.SubItems(4) = mo_ArmDb.GetFields(al_cursor, "S_DESC")
        ln_Node.SubItems(5) = mo_ArmDb.GetFields(al_cursor, "PD_DESC")
        ln_Node.SubItems(6) = mo_ArmDb.GetFields(al_cursor, "SS_QTY")
        ln_Node.SubItems(7) = mo_ArmDb.GetFields(al_cursor, "UM_code")
        ln_Node.SubItems(8) = mo_ArmDb.GetFields(al_cursor, "Z_creator")
        ln_Node.SubItems(9) = mo_ArmDb.GetFields(al_cursor, "Z_creation")
        ' task 299.5 begin
        ln_Node.SubItems(10) = mo_ArmDb.GetFields(al_cursor, "SC_desc")
        ln_Node.SubItems(11) = mo_ArmDb.GetFields(al_cursor, "SC_code")
        ln_Node.SubItems(12) = mo_ArmDb.GetFields(al_cursor, "CG_code")     ' fix
        ' task 299.5 end
        If mo_ArmDb.GetFields(al_cursor, "LR_CODE") <> "" And mo_ArmDb.GetFields(al_cursor, "LR_CODE") <> "0" Then
            ls_LRcode = mo_ArmDb.GetFields(al_cursor, "LR_CODE")
            ls_LRdesc = mo_ArmDb.GetFields(al_cursor, "LR_desc")
        End If
       
        mo_ArmDb.Next al_cursor
    Loop
    If Not ao_LR Is Nothing And ls_LRcode <> "" And ls_LRcode <> "0" Then
        ao_LR.AddItem Array(ls_LRcode, ls_LRdesc), True
    End If
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:AppendListViewLocal"
    #End If
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:AppendListViewLocal"
End Sub

' return opened cursor with specified data
Private Function GetProductDataCursor(ByVal as_SOL_code As String) As Long
    On Error GoTo Trace_Err
    
    Dim ll_cursor As Long
    Dim ls_req As String
    
    GetProductDataCursor = 0
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ls_req = "exec Cap_ProjectProduct_t_sel " & "'" & ms_SP & "', '" & as_SOL_code & "', '" & m_Language & "'"
    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, "PrdValOf:GetProductData", "Request=" & ls_req
        GoTo Trace_End
    End If
    GetProductDataCursor = ll_cursor
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:GetProductData"
    #End If
    Exit Function
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:GetProductData"
End Function
' task 299.5 begin new sub routines

'FUNCTIONS COPIED FROM CapPrd
' 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, "CapPrdValOf:DisplayMode_Get"
    #End If
    DisplayMode = mi_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CapPrdValOf: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, "CapPrdValOf: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, "CapPrdValOf: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, "CapPrdValOf:SwapToDisplayMode", "li_DisplayMode=" & li_DisplayMode, "ls_Params=" & ls_Params
    #End If
    
    mi_DisplayMode = li_DisplayMode
   
    'We should hide all graphics frames before resize and move it
    fraItem.Visible = False
    
    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_List
            ' disable all controls
            pbItem.Enabled = True
            lbl_Desc.Enabled = True
            lv_Products.Enabled = True
            lbl_LR.Enabled = True
            cbo_LR.Enabled = True
            lbl_Ref.Enabled = True
            chk_Ref.Enabled = True
            
            fraItem.Enabled = False
            fraItem.Visible = False
        Case mt_CstValues.DisplayMode_Add
            pbItem.Enabled = False
            lbl_Desc.Enabled = False
            lv_Products.Enabled = False
            lbl_LR.Enabled = False
            cbo_LR.Enabled = False
            lbl_Ref.Enabled = False
            chk_Ref.Enabled = False
            
            fraItem.Enabled = True
            fraItem.Visible = True
            AddDisplay
            
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "CapPrdValOf:SwapToDisplayMode"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "CapPrdValOf: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, "PrdValOf:AddDisplay"
    #End If

'    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    BlankFields
    AddInitFields
    Add_Resize

'    cbo_competitor.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:AddDisplay"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:AddDisplay"
    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, "PrdValOf: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, "PrdValOf:AddInitFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf: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, "PrdValOf: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
               
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:BlankFields"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:BlankFields"
    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, "PrdValOf: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, "PrdValOf: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
    
Trace_End:
    mo_ArmDb.Close ll_cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf: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, "PrdValOf:Load_SCLst"
    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, "PrdValOf:Add_Resize"
    #End If
    
    With UserControl
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = 4750
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - mt_CstValues.Frm_Spacing
        
        .pbItem2.Height = mt_CstValues.View_ToolBar_Height
        .pbItem2.Top = mt_CstValues.Frm_Spacing * 4
        .pbItem2.Left = mt_CstValues.Frm_Spacing
        .pbItem2.Width = .fraItem.Width - .pbItem2.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbItem2.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
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        
    End With

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

' Get the selected SC type
Private Property Get SelSC() As String
Dim li_Idx 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, "PrdValOf:SelSC_Get"
    #End If
    
    ls_Code = "-1"
    For li_Idx = chk_SC.LBound To chk_SC.UBound
        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, "PrdValOf: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, "PrdValOf:SelSC_Get"
    CapMouseOn
End Property

' Select the SC
Private Property Let SelSC(ByVal ls_Code As String)
Dim li_Idx As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "PrdValOf:SelSC_Let", "ls_Code=" & ls_Code
    #End If
    
    For li_Idx = chk_SC.LBound To chk_SC.UBound
        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, "PrdValOf:SelSC_Let"
    #End If
    CapMouseOn
    Exit Property
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:SelSC_Let"
    CapMouseOn
End Property

Private Sub chk_SC_Click(Index As Integer)
Dim li_Idx 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, "PrdValOf: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
    For li_Idx = chk_SC.LBound To chk_SC.UBound
        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
        SquareMeter True
    Case 3
        SquareMeter False
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:chk_SC_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:chk_SC_Click"
    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, "PrdValOf: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, "PrdValOf:SquareMeter"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:SquareMeter"
    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, "PrdValOf: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, "PrdValOf:cbo_competitor_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:cbo_competitor_ComboItemSelected"
    CapMouseOn
End Sub

Private Sub pbItem2_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, "PrdValOf:pbItem2_action", "as_ActionType=" & as_ActionType
    #End If
    Dim ll_SOL_code As String
    Dim ll_cursor As Long
      
    Select Case UCase$(as_ActionType)
        Case "VALID"
            Debug.Assert (mi_DisplayMode = mt_CstValues.DisplayMode_Add)
            ll_SOL_code = RecordAdd
            If ll_SOL_code <> "" Then
                ll_cursor = GetProductDataCursor(ll_SOL_code)
                If ll_cursor <> 0 Then
                    Call AppendListView(lv_Products, ll_cursor)
                End If
                Call mo_ArmDb.Close(ll_cursor)
                BlankFields
                AddInitFields
                RaiseEvent Updated
            End If
        Case "UNDO"
            Debug.Assert (mi_DisplayMode = mt_CstValues.DisplayMode_Add)
            BlankFields
            AddInitFields
        Case "QUIT"
            DisplayMode = mt_CstValues.DisplayMode_List
    End Select

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:pbItem2_action"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    Call mo_ArmDb.Close(ll_cursor)
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf:pbItem2_action"
    CapMouseOn
End Sub

Function RecordAdd() As String
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, "PrdValOf:RecordAdd"
    #End If
    
    RecordAdd = ""
    
    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 & ", " & "'" & 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),   ' task 299.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
    Dim ll_ProductMtncLevel  As Long
    ll_cursor = mo_ArmDb.OpenSQL("EXEC Sales_Project_ASProductLevel '" & cbo_Product.SelectedItemCode & "'")
    Debug.Assert (ll_cursor <> 0)
    ll_ProductMtncLevel = mo_ArmDb.GetFields(ll_cursor, "Spare3_real")
    Call mo_ArmDb.Close(ll_cursor)
    ll_cursor = 0

    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(project, ll_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(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 = ls_ProdCode
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "PrdValOf:RecordAdd", "Result=" & RecordAdd
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If lb_Transaction Then
        ASC_RollBackTransaction mo_ArmDb
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "PrdValOf: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

' 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


Private Function GetSelectedSize(ByRef ao_lv As ListView) As Long
    Dim lo_lvItem As ListItem
    Dim ll_retVal As Long
    ll_retVal = 0
    For Each lo_lvItem In ao_lv.ListItems
        If lo_lvItem.Checked Then
            If isNumeric(lo_lvItem.SubItems(6)) And _
                         ((lo_lvItem.SubItems(11) = 1) Or _
                         (lo_lvItem.SubItems(11) = 4 And lo_lvItem.SubItems(12) = "C001") Or _
                         (lo_lvItem.SubItems(11) = 5 And lo_lvItem.SubItems(12) = "C006")) Then    '1...ceilings OR 4.. AS procuct of category 'C001' OR 5.. WALLS of category 'C006'
                ll_retVal = ll_retVal + CLng(lo_lvItem.SubItems(6))
            End If
        End If
    Next
    GetSelectedSize = ll_retVal
End Function

Private Sub lv_Products_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    txt_totalSize.Text = CStr(GetSelectedSize(lv_Products))     ' task 299.5
End Sub
' task 299.5 end


Private Function Get_A_Config(ByVal TheKey As String) As String
On Error GoTo Get_A_Config_er
Dim curs As Long
Dim ls_req As String

Get_A_Config = ""
ls_req = "select cfg_value from A_config where cfg_Key ='" & UCase(TheKey) & "'"
curs = mo_ArmDb.OpenSQL(ls_req)
    If curs = 0 Then
        Err.Raise CompFncFailed, "CapPrdValOf.Get_A_Config", "Error executing " & ls_req & mo_ArmDb.LastErrorCode & "  " & mo_ArmDb.LastErrorMessage
    Else
        If mo_ArmDb.RowCount(curs) <> 1 Then
            mo_ArmDb.Close (curs)
            curs = 0
            Err.Raise CompFncFailed, "CapPrdValOf.Get_A_Config", "Executing " & ls_req & " returned " & mo_ArmDb.RowCount(curs) & " record(s) while one was expected"
        Else
            Get_A_Config = mo_ArmDb.GetFields(curs, 0)
            mo_ArmDb.Close (curs)
            curs = 0
        End If
    End If
Exit Function
Get_A_Config_er:
    If curs > 0 Then
        Call mo_ArmDb.Close(curs)
        curs = 0
    End If
'    Call ErrorHandler("CapPrdValOf.Get_A_Config()")
End Function


