VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl CapSubProject 
   ClientHeight    =   10830
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   18030
   ScaleHeight     =   10830
   ScaleWidth      =   18030
   Tag             =   "CapSubProject"
   Begin VB.Frame fraItem 
      Height          =   10395
      Left            =   675
      TabIndex        =   0
      Tag             =   "fraItem"
      Top             =   2445
      Width           =   16455
      Begin Project1.ToolbarControl tlb_Item 
         Height          =   690
         Left            =   90
         TabIndex        =   27
         Tag             =   "2908"
         Top             =   195
         Width           =   16215
         _ExtentX        =   28601
         _ExtentY        =   1217
      End
      Begin VB.Frame fraItemBottom 
         Height          =   585
         Left            =   1440
         TabIndex        =   9
         Tag             =   "fraItemBottom"
         Top             =   9720
         Width           =   13950
         Begin VB.TextBox txt_DropDate 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   12480
            Locked          =   -1  'True
            TabIndex        =   24
            Top             =   150
            Width           =   1400
         End
         Begin VB.CheckBox chk_DropFlag 
            Alignment       =   1  'Right Justify
            Caption         =   "#Drop flag"
            Enabled         =   0   'False
            Height          =   255
            Left            =   10590
            TabIndex        =   23
            Tag             =   "chk_DropFlag"
            Top             =   240
            Width           =   1845
         End
         Begin VB.TextBox txt_dateUpdated 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   6495
            TabIndex        =   5
            TabStop         =   0   'False
            Tag             =   "txt_lastUpdated"
            Top             =   165
            Width           =   1100
         End
         Begin VB.TextBox txt_dateEntered 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   1275
            TabIndex        =   3
            TabStop         =   0   'False
            Tag             =   "txt_dateEntered"
            Top             =   165
            Width           =   1100
         End
         Begin VB.TextBox txt_createdBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   3375
            TabIndex        =   4
            TabStop         =   0   'False
            Tag             =   "txt_createdBy"
            Top             =   150
            Width           =   1875
         End
         Begin VB.TextBox txt_updatedBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   8595
            TabIndex        =   6
            TabStop         =   0   'False
            Top             =   165
            Width           =   1875
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Date Entered"
            Enabled         =   0   'False
            Height          =   255
            Index           =   10
            Left            =   75
            TabIndex        =   17
            Tag             =   "lbl_dateEntered"
            Top             =   210
            Width           =   1140
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Last Updated"
            Enabled         =   0   'False
            Height          =   255
            Index           =   11
            Left            =   5295
            TabIndex        =   16
            Tag             =   "lbl_lastUpdated"
            Top             =   210
            Width           =   1140
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Index           =   12
            Left            =   2400
            TabIndex        =   15
            Tag             =   "lbl_createdBy"
            Top             =   210
            Width           =   900
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Index           =   13
            Left            =   7635
            TabIndex        =   14
            Tag             =   "lbl_updatedBy"
            Top             =   210
            Width           =   900
         End
      End
      Begin VB.Frame fraItemTop 
         Height          =   8250
         Left            =   885
         TabIndex        =   7
         Tag             =   "fraItemTop"
         Top             =   1095
         Width           =   14790
         Begin VB.TextBox txt_SPR_Name 
            Height          =   360
            Left            =   1620
            MaxLength       =   80
            TabIndex        =   26
            Top             =   615
            Width           =   8265
         End
         Begin VB.TextBox txt_SPR_ID 
            Height          =   360
            Left            =   11940
            TabIndex        =   21
            Top             =   150
            Visible         =   0   'False
            Width           =   2655
         End
         Begin VB.Frame fraSubItemMain 
            Height          =   5880
            Left            =   135
            TabIndex        =   18
            Tag             =   "fraItemSubdetail"
            Top             =   2325
            Width           =   14535
            Begin Project1.ToolbarControl tlb_Subitem 
               Height          =   5610
               Left            =   13770
               TabIndex        =   29
               Tag             =   "2909"
               Top             =   165
               Width           =   690
               _ExtentX        =   1217
               _ExtentY        =   9895
            End
            Begin Project1.ArmGrid grd_Offer 
               Height          =   3765
               Left            =   135
               TabIndex        =   20
               TabStop         =   0   'False
               Tag             =   "grd_Offer"
               Top             =   2010
               Width           =   13590
               _ExtentX        =   23971
               _ExtentY        =   6641
            End
            Begin VB.Frame fraSubitemDetail 
               Height          =   1815
               Left            =   150
               TabIndex        =   19
               Tag             =   "fraSubitemDetail"
               Top             =   150
               Width           =   13620
            End
         End
         Begin VB.TextBox txt_SP_Desc 
            Height          =   360
            Left            =   1620
            TabIndex        =   1
            Top             =   195
            Width           =   8265
         End
         Begin VB.TextBox txt_SPR_Desc 
            Height          =   795
            Left            =   1635
            MaxLength       =   150
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   2
            Top             =   1440
            Width           =   8265
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Sub project"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   120
            TabIndex        =   25
            Tag             =   "lbl_customer"
            Top             =   675
            Width           =   1470
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Id"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   22
            Left            =   10170
            TabIndex        =   22
            Tag             =   "lbl_COF_ID"
            Top             =   210
            Visible         =   0   'False
            Width           =   1710
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Project"
            Height          =   255
            Index           =   0
            Left            =   105
            TabIndex        =   13
            Tag             =   "lbl_Project"
            Top             =   255
            Width           =   1470
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Comment"
            Height          =   255
            Index           =   2
            Left            =   120
            TabIndex        =   8
            Tag             =   "lbl_comment"
            Top             =   1485
            Width           =   1470
         End
      End
      Begin MSComctlLib.TabStrip tbsEmbedded 
         Height          =   375
         Left            =   120
         TabIndex        =   10
         Tag             =   "tbsEmbedded"
         Top             =   9360
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   661
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   1
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
   End
   Begin VB.Frame fraList 
      Height          =   4935
      Left            =   825
      TabIndex        =   11
      Tag             =   "fraList"
      Top             =   570
      Width           =   9015
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Left            =   75
         TabIndex        =   28
         Tag             =   "2907"
         Top             =   120
         Width           =   8685
         _ExtentX        =   15319
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grdlst 
         Height          =   2775
         Left            =   240
         TabIndex        =   12
         Tag             =   "grdlst"
         Top             =   1200
         Width           =   5175
         _ExtentX        =   9128
         _ExtentY        =   4895
      End
   End
End
Attribute VB_Name = "CapSubProject"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' **************************************************************************************************
' **************************************** USER DEFINED ERRORS *************************************
' **************************************************************************************************
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 LOCALE_SDECIMAL = &HE ' Decimal separator
Private Const LOCALE_STHOUSAND = &HF ' Thousand separator
Private Const LOCALE_USER_DEFAULT = &H400
Private Const SCREEN_NAME As String = "CapSubProject"

Private Const CL_COLOR_ENABLED  As Long = &H80000005
Private Const CL_COLOR_DISABLED As Long = &H8000000F
Private Const CL_COLOR_Expired  As Long = 10066414          ' # EE9999
Private Const CL_COLOR_Requested    As Long = 10066414      ' # EE9999
Private Const CL_COLOR_Delivered    As Long = 10088089      ' # 99EE99
'******** Curseur de connexion

#If ENV = LIVE Then
Private mo_Sys As Object
Private mo_Db As Object
Private mo_FSO As Object
#Else
Private mo_Sys As ARMSYSCOMLib.ArmSYS
Private mo_Db As ARMSYSCOMLib.ArmDb
Private mo_FSO As Scripting.FileSystemObject
#End If


Private mo_Tools As DPC_Tools

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

Private mb_Created As Boolean
Dim mb_use_framework_connection As Boolean
Private ms_ConnectString As String
Private ms_UID As String
Private ml_U_Code As Long
Private ms_LoginName As String
Private ml_iConcurrency As Long

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

'******** 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 ms_Language_Code As String

'******** iConccurency of current Record
Private p_iCon As Integer
Private prj_iConc As Long                       ' iConc of project - valid after ViewInitFields and AddInitFields
Private m_projectStatus As Variant

'******** 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_Product As String 'For the property .Product, display in ShortList
Private mb_EmbeddedIsDropped As Boolean '298.2

'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 ProjectStatusChanged(ByVal as_project As String, ByVal ae_newStatus As Variant)

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

Private mb_InternalInit As Boolean
Private mb_TemplateDownloaded As Boolean
Private mb_grd_ProductsLoaded As Boolean
Private ms_DecimalSeparator As String
Private ms_ThousandSeparator As String
Private mc_ScreenLabels As Long
Private mc_Toolbars As Long
Private mo_WshNetwork As Object
Private ms_ComputerName As String
Private ms_Caption As String
Private mb_Initialized As Boolean

Private Const REQ_CONTACT = "exec Cap_Offer_Contact_cbo $SP_CapKey$,$CCU_CapKey$,'E'"
Private Const VALUE_FORMAT As String = "###0.00"
Private Const MONEY_FORMAT As String = "###0.00"

Private Enum eOfferStatus
    osNew = 1
    osSentToCustomer = 2
    osDeleted = 3
    osApproved = 4
    osRejected = 5
    osConfirmedToUser = 6
End Enum

Private Enum eFrameContractStatus
    csRequested = 1
    csDelivered = 2
    csUnknown = 3
End Enum

Public Property Set ArmDb(ByRef ao_Db As Object)
On Error GoTo ErrorHandler

  Set mo_Db = ao_Db
  Exit Property
ErrorHandler:
  Call ErrorHandler("ArmDb.Set")
End Property

Public Property Get ArmDb() As Object
On Error GoTo ErrorHandler

  Set ArmDb = mo_Db
  Exit Property
ErrorHandler:
  Call ErrorHandler("ArmDb.Get")
End Property

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

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

Public Property Let Language(as_Language As String)
On Error GoTo ErrHandler
  
  ms_Language_Code = as_Language
  Exit Property
ErrHandler:
  Call ErrorHandler("Language.Let")
End Property

Public Property Get Language() As String
On Error GoTo ErrHandler
  
  Language = ms_Language_Code
  Exit Property
ErrHandler:
  Call ErrorHandler("Language.Get")
End Property

Public Property Let U_Code(ByVal al_U_Code As Long)
On Error GoTo ErrorHandler

  ml_U_Code = al_U_Code
  Exit Property
ErrorHandler:
  Call ErrorHandler("U_Code.Let")
End Property

Public Property Let LoginName(ByVal as_Value As String)
On Error GoTo ErrorHandler

  ms_LoginName = as_Value
  Exit Property
ErrorHandler:
  Call ErrorHandler("LoginName.Let")
End Property

Public Property Let Caption(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  ms_Caption = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Caption.Let")
End Property

Public Property Get Caption() As String
On Error GoTo ErrHandler
    
  Caption = ms_Caption
  Exit Property
ErrHandler:
  Call ErrorHandler("Caption.Get")
End Property

Public Property Let Name(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  UserControl.Extender.Name = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Name.Let")
End Property

Public Property Get Name() As String
On Error GoTo ErrHandler
    
  Name = UserControl.Extender.Name
  Exit Property
ErrHandler:
  Call ErrorHandler("Name.Get")
End Property

Public Property Let Tag(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  UserControl.Tag = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Tag.Let")
End Property

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

Public Property Let Visible(ByVal aVisible As Boolean)
On Error GoTo ErrHandler
    
  UserControl.Extender.Visible = aVisible
  Exit Property
ErrHandler:
  Call ErrorHandler("Visible.Let")
End Property

Public Property Get Visible() As Boolean
On Error GoTo ErrHandler
    
  Visible = UserControl.Extender.Visible
  Exit Property
ErrHandler:
  Call ErrorHandler("Visible.Get")
End Property

Public Property Let Top(ByVal aTop As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Top = aTop
  Exit Property
ErrHandler:
  Call ErrorHandler("Top.Let")
End Property

Public Property Get Top() As Single
On Error GoTo ErrHandler
    
  Top = UserControl.Extender.Top
  Exit Property
ErrHandler:
  Call ErrorHandler("Top.Get")
End Property

Public Property Let Height(ByVal aHeight As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Height = aHeight
  Exit Property
ErrHandler:
  Call ErrorHandler("Height.Let")
End Property

Public Property Get Height() As Single
On Error GoTo ErrHandler
    
  Height = UserControl.Extender.Height
  Exit Property
ErrHandler:
  Call ErrorHandler("Height.Get")
End Property

Public Property Let Left(ByVal aLeft As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Left = aLeft
  Exit Property
ErrHandler:
  Call ErrorHandler("Left.Let")
End Property

Public Property Get Left() As Single
On Error GoTo ErrHandler
    
  Left = UserControl.Extender.Left
  Exit Property
ErrHandler:
  Call ErrorHandler("Left.Get")
End Property

Public Property Let Width(ByVal aWidth As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Width = aWidth
  Exit Property
ErrHandler:
  Call ErrorHandler(".Let")
End Property

Public Property Get Width() As Single
On Error GoTo ErrHandler
    
  Width = UserControl.Extender.Width
  Exit Property
ErrHandler:
  Call ErrorHandler("Width.Get")
End Property

Public Sub Move(ByVal aLeft As Single, ByVal aTop As Single, ByVal aWidth As Single, ByVal aHeight As Single)
On Error GoTo ErrHandler
  
  Call UserControl.Extender.Move(aLeft, aTop, aWidth, aHeight)
  Exit Sub
ErrHandler:
  Call ErrorHandler("Move")
End Sub

Public Property Let Enabled(ByVal ab_Value As Boolean)
On Error GoTo ErrHandler

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

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

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

Public Sub Zorder()
On Error GoTo ErrHandler

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

Public Sub Refresh()
On Error GoTo ErrHandler

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

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

Public Property Get Initialized() As Boolean
On Error GoTo ErrHandler
    
  Initialized = mb_Initialized
  Exit Property
ErrHandler:
  Call ErrorHandler("Initialized.Get")
End Property

Public Property Let ConnectString(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  ms_ConnectString = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("ConnectString.Let")
End Property

' Initialization of the component
Public Sub Load_A_COM(ab_root As Boolean)
On Error GoTo ErrHandler
    
  VerifyInitialization mo_Db, ms_ConnectString, ms_Language_Code, Me
  
  If mo_Db Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  If mo_Tools Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  'Set mo_Tools = New DPC_Tools
  'Set mo_Tools.ArmDb = mo_Db
  'Call mo_Tools.Load_A_COM
  
  Call mo_Tools.Load_A_ComControls(UserControl.Controls, mo_Db, ms_Language_Code)
  ms_ThousandSeparator = mo_Tools.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND)
  ms_DecimalSeparator = Format(0, ".")
  
  Set mo_FSO = CreateObject("Scripting.FileSystemObject")
#If ENV = LIVE Then
  Set mo_Sys = CreateObject("ArmSYSCOM.ArmSys")
#Else
  Set mo_Sys = New ARMSYSCOMLib.ArmSYS
#End If
  
  Set mo_WshNetwork = CreateObject("WScript.Network")
  ms_ComputerName = mo_WshNetwork.ComputerName
  
  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
  mb_InternalInit = False

  grdlst.MultiSelect = False
  Dim la_Columns(2) As String        ' mmmm 3. Add town
  la_Columns(0) = "SPR_ID" & CH_LDELIMIT & "500" & CH_LDELIMIT & "1" & CH_LDELIMIT & "SPR_ID" & CH_LDELIMIT & "#Id"
  la_Columns(1) = "SPR_Name" & CH_LDELIMIT & "4000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SPR_Name" & CH_LDELIMIT & "#Name"
  la_Columns(2) = "SPR_Desc" & CH_LDELIMIT & "4000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SPR_Desc" & CH_LDELIMIT & "#Description"
  grdlst.SetColumns la_Columns

  Call mo_Tools.LoadToolbars(mo_Db, UserControl.Controls, SCREEN_NAME)
  Call InitSubitem
  'Screen csts
  mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, UserControl.Controls, Me, SCREEN_NAME, ms_Language_Code)
  Call mo_Tools.ChangeCharset(UserControl.Controls, gl_CodePage)
  Exit Sub
ErrHandler:
  Call ErrorHandler("Load_A_Com")
End Sub

' Release the memory used
Public Sub Unload_A_COM()
On Error GoTo ErrHandler
    
  Call mo_Tools.Unload_A_ComControls(UserControl.Controls)
  'Call mo_Tools.Unload_A_COM
  Call mo_Db.Close(mc_ScreenLabels)
  Set mo_Sys = Nothing
  Set mo_FSO = Nothing
  Set mo_Db = Nothing
  Set mo_Tools = Nothing
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("Unload_A_Com")
End Sub

Public Sub GoToTab1()
On Error GoTo ErrHandler
    
    If UserControl.tbsEmbedded.Tabs.Count > 0 Then
        UserControl.tbsEmbedded.Tabs(1).Selected = True
    End If
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("GoToTab1")
End Sub

Private Sub Add_Resize()
On Error GoTo ErrHandler
    
    With UserControl
        
        .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 - (2 * mt_CstValues.Frm_Spacing)
        
        .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
        .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
        .tlb_Item.Left = mt_CstValues.Frm_Spacing
        .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
        
        .tbsEmbedded.Visible = False
        
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.Visible = True
        .fraItemBottom.BorderStyle = 0
        
    End With

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

Private Sub AddDisplay()
On Error GoTo ErrHandler
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    'InitControl 4
    
    BlankFields
    Call tlb_Item.DisplayFace("1")
    Add_Enablecontrols
    Add_Resize
    AddInitFields
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("AddDisplay")
End Sub

Private Sub Delete_Resize()
On Error GoTo ErrHandler
    With UserControl
        
        .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)
        
        .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
        .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
        .tlb_Item.Left = mt_CstValues.Frm_Spacing
        .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
        
        .tbsEmbedded.Visible = False
        
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItem.Visible = True
        .fraItemTop.Visible = True
        .fraItemBottom.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
    End With
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Delete_Resize")
End Sub

Private Sub DeleteDisplay()
On Error GoTo ErrHandler
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    'InitControl 4
    
    BlankFields
    Call tlb_Item.DisplayFace("3")
    Delete_EnableControls
    Delete_Resize
    ViewInitFields
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_View)

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

Private Sub Delete_EnableControls()
On Error GoTo ErrHandler
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    
    txt_SPR_Desc.Enabled = True
    txt_SPR_Desc.Locked = True
    txt_SPR_Desc.BackColor = CL_COLOR_DISABLED
    
    tlb_Subitem.Enabled = True
    grd_Offer.Enabled = True
    fraSubItemMain.Enabled = True
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Delete_EnableControls")
End Sub

Private Sub Update_Resize()
On Error GoTo ErrHandler
    
    With UserControl
    
        .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)
        
        .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
        .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
        .tlb_Item.Left = mt_CstValues.Frm_Spacing
        .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
        
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Visible = False
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.Visible = True
        .fraItemBottom.BorderStyle = 0
    End With
    Exit Sub
ErrHandler:
    Call ErrorHandler("Update_Resize")
End Sub

Private Sub UpdateDisplay()
On Error GoTo ErrHandler
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    'InitControl 4
    
    Call tlb_Item.DisplayFace("2")
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then BlankFields
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then
        UpdateInitFields
    End If
    Update_EnableControls
    Update_Resize
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
    'Call txt_SPR_Desc.SetFocus
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateDisplay")
End Sub

Function RecordAdd() As Boolean
On Error GoTo ErrHandler
Dim ls_req As String

    ls_req = "exec Cap_Subproject_ins $SPR_Id$, $SP_Capkey$, $SPR_Name$, $SPR_Desc$, $Z_Creator$ "
    
    m_CurrentKey1 = mo_Db.SQLNextID("Cap_Subproject")
    
    ls_req = Replace(ls_req, "$SPR_Id$", mo_Tools.SqlStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SP_Capkey$", mo_Tools.SqlStr(m_Project), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SPR_Name$", mo_Tools.SqlStr(txt_SPR_Name.Text), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SPR_Desc$", mo_Tools.SqlStr(txt_SPR_Desc.Text), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
    
    'The data has been inserted
    RaiseEvent Updated
    RecordAdd = True
    Exit Function
ErrHandler:
    Call ErrorHandler("RecordAdd")
End Function

Function RecordUpdate(ACode As String) As Boolean
On Error GoTo ErrHandler
Dim ls_req As String

    ls_req = "exec Cap_Subproject_upd $SPR_Id$, $SPR_Name$, $SPR_Desc$, $Z_Last_Upd_User$, $iConcurrency$ "
    
    ls_req = Replace(ls_req, "$SPR_Id$", mo_Tools.SqlStr(txt_SPR_ID.Text), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SPR_Name$", mo_Tools.SqlStr(txt_SPR_Name.Text), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SPR_Desc$", mo_Tools.SqlStr(txt_SPR_Desc.Text), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
    
    'The data has been updated
    RaiseEvent Updated
    RecordUpdate = True
    Exit Function
ErrHandler:
    Call ErrorHandler("RecordUpdate")
End Function

Function RecordDelete(ACode As String) As Boolean
On Error GoTo ErrHandler

Dim ls_req As String

    ls_req = "exec Cap_Subproject_del $SPR_Id$, $Z_Last_Upd_User$, $iConcurrency$ "
    
    ls_req = Replace(ls_req, "$SPR_Id$", mo_Tools.SqlStr(txt_SPR_ID.Text), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
    
    'The data has been deleted
    RaiseEvent Updated
    RecordDelete = True
    Exit Function
ErrHandler:
    Call ErrorHandler("RecordDelete")
End Function

Private Sub ViewDisplay()
On Error GoTo ErrHandler
    
    If mi_EmbeddedIn = -1 Then
        RaiseEvent SwitchToView(mt_CstValues.View_Full)
    Else
        RaiseEvent SwitchToView(mt_CstValues.View_Full)
    End If
    
    'If the component was on short list, it doues appear now in long list
    'InitControl 3
    
    BlankFields
    Call tlb_Item.DisplayFace("0")
    View_EnableControls
    ViewLoad
    View_Resize
    ViewInitFields
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_View)
    Exit Sub
ErrHandler:
    Call ErrorHandler("ViewDisplay")
End Sub

Private Sub View_Resize()
On Error GoTo ErrHandler
    
    With UserControl
        
        If mi_EmbeddedIn = -1 And Not mb_Root Then
        
            .fraItem.Left = mt_CstValues.Frm_Spacing
            
            .tbsEmbedded.Visible = False 'true
            .tbsEmbedded.Zorder 0
            
        Else
            .fraItem.Left = mt_CstValues.Frm_Spacing
            
            .tbsEmbedded.Visible = False '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)
        
        .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
        .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
        .tlb_Item.Left = mt_CstValues.Frm_Spacing
        .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
        
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Visible = True
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
    End With
    Exit Sub
ErrHandler:
    Call ErrorHandler("View_Resize")
End Sub

Public Property Get UserControlWidth() As Long
On Error GoTo ErrorHandler
    UserControlWidth = UserControl.Width
    Exit Property
ErrorHandler:
    Call ErrorMessage("UserControlWidth.Get")
End Property

Public Property Get CurrentKey(Optional APart As Integer = 0) As String
On Error GoTo ErrorHandler
    If APart = 0 Then
        CurrentKey = m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2
    ElseIf APart = 1 Then
        CurrentKey = m_CurrentKey1
    ElseIf APart = 2 Then
        CurrentKey = m_CurrentKey2
    Else
        CurrentKey = ""
    End If
    Exit Property
ErrorHandler:
    Call ErrorHandler("CurrentKey.Get")
End Property

Public Property Let CurrentKey(Optional APart As Integer = 0, AKeyValue As String)
On Error GoTo ErrorHandler
    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
    Else
        CurrentKey = ""
    End If
    Exit Property
ErrorHandler:
    Call ErrorHandler("CurrentKey.Let")
End Property

Public Property Let TypeList(AType As Integer)
On Error GoTo ErrorHandler
    
  mi_TypeList = AType

  Exit Property
ErrorHandler:
  Call ErrorHandler("TypeList.Let")
End Property

Property Get TypeList() As Integer
On Error GoTo ErrorHandler
    
  TypeList = mi_TypeList
  
  Exit Property
ErrorHandler:
  Call ErrorHandler("TypeList.Get")
End Property

Private Sub ShortList_Resize()
On Error GoTo ErrHandler
    
    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)
   
        .tlb_Main.Height = mt_CstValues.View_ToolBar_Height
        .tlb_Main.Top = mt_CstValues.Frm_Spacing * 4
        .tlb_Main.Left = mt_CstValues.Frm_Spacing
        .tlb_Main.Width = .fraList.Width - .tlb_Main.Left - (2 * mt_CstValues.Frm_Spacing)
        
        .grdlst.Top = mt_CstValues.Frm_Spacing + .tlb_Main.Top + .tlb_Main.Height
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .tlb_Main.Height - .tlb_Main.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .fraList.Visible = True
        
    End With
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("ShortList_Resize")
End Sub

' Called when application must resize the current view
Public Sub Resize()
On Error GoTo ErrHandler
    
    Call DisplayMode_None
    
    Select Case DisplayMode
        Case mt_CstValues.DisplayMode_List
               Call ShortList_Resize
    End Select
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Resize")
End Sub

Sub UnCatch()
    mi_EmbeddedIn = -1
End Sub

Public Property Let product(AProductKey As String)

    ' no product-offer navigation
End Property

Public Property Let action(AActionKey As String)

    ' no action-offer navigation
End Property

Public Property Let contact(AKey As String)

    ' no contact-offer navigation
End Property
 
Public Property Let Customer(AKey As String)

    ' no customer-offer navigation
End Property

Public Property Let project(AKey As String)
On Error GoTo ErrHandler
    Dim TheKeys     As Variant
    Dim ls_CT_Code  As String
    
    'AKey represents the concatenation of several keys separated by '@'
    If AKey = "" Then Call Err.Raise(InvalidArgument, "", "AKey is empty.")

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    TheKeys = Split(AKey, CH_LDELIMIT)
    'Debug.Assert (UBound(TheKeys) = 3)
    m_Customer = ""
    m_Contact = ""
    m_Project = CStr(TheKeys(0))
    m_projectStatus = "" 'CLng(TheKeys(2))
    ls_CT_Code = "GB" 'TheKeys(3)

    'InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Project

    mb_EmbeddedIsDropped = False
    
    ListProjectOf CStr(TheKeys(0)), CStr(TheKeys(1))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
    Exit Property
ErrHandler:
    Call ErrorHandler("project.Let")
End Property

Private Sub grd_Offer_ItemSelected()
On Error GoTo ErrHandler
    
    Call mo_Tools.LockScreen(Me, True)
    If ml_DisplayModeSubItem = mt_CstValues.DisplayMode_List Then
        'Call tlb_Subitem_action("Update")
    End If
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Call ErrorMessage("grd_Offer_ItemSelected")
End Sub

Private Sub grdLst_ItemSelected()
On Error GoTo ErrHandler
    
    Call mo_Tools.LockScreen(Me, True)
    If (grdlst.SelectedCount = 1) Then
'        If grdlst.SelectedLine(0, "DROP_FLAG") <> "X" Then
            m_CurrentKey1 = grdlst.CurrentKey(0)
            DisplayMode = mt_CstValues.DisplayMode_View
'        End If
    End If
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Call ErrorMessage("grdLst_ItemSelected")
End Sub

' Get the root state
Public Property Get Root() As Boolean
On Error GoTo ErrorHandler
    
    Root = mb_Root

    Exit Property
ErrorHandler:
    Call ErrorHandler("Root.Get")
End Property

Public Property Let Root(ByVal ab_root As Boolean)
On Error GoTo ErrorHandler
    
    mb_Root = ab_root
    If mb_Root = True Then
        mi_EmbeddedIn = -1
    End If

    Exit Property
ErrorHandler:
    Call ErrorHandler("Root.Let")
End Property

Private Sub tlb_Item_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler
    Dim lb_Result   As Boolean
    Dim ls_auxStr   As String
    Dim ls_serialStr As String

    Call mo_Tools.LockScreen(Me, True)
    
    Select Case as_Role
        Case "A"
            CurrentKey = ""
            DisplayMode = mt_CstValues.DisplayMode_Add
        
        Case "B"
            If m_CurrentKey1 <> "" Then
                DisplayMode = mt_CstValues.DisplayMode_Update
            End If
        
        Case "C"
            If m_CurrentKey1 <> "" Then
                DisplayMode = mt_CstValues.DisplayMode_Delete
            End If
        
        Case "T"
            If mi_EmbedTag <> -1 Then
                RaiseEvent Release
                mi_EmbedTag = -1
            End If
            
            DisplayMode = mt_CstValues.DisplayMode_List
            
        Case "H"
        
            lb_Result = False
            Select Case DisplayMode
                Case mt_CstValues.DisplayMode_Add
                    lb_Result = RecordAdd
                Case mt_CstValues.DisplayMode_Update
                    lb_Result = RecordUpdate(m_CurrentKey1)
                Case mt_CstValues.DisplayMode_Delete
                    lb_Result = RecordDelete(m_CurrentKey1)
            End Select
            If lb_Result Then
                Call RefreshGridSafe(grdlst)
                If DisplayMode = mt_CstValues.DisplayMode_Add Then
                    Call grdlst.SearchKey(True, m_CurrentKey1)
                End If
                DisplayMode = mt_CstValues.DisplayMode_List
            End If
            
        Case "I"
            BlankFields
            'DisplayMode = mt_CstValues.DisplayMode_List
            If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
                AddInitFields
            Else
                ViewInitFields
            End If
            
        Case "J"
            If grdlst.Row = 0 Then
                Call ASC_SendMessage(mo_Db, ms_Language_Code, 927, "#No more previous item.")
            Else
                grdlst.Row = grdlst.Row - 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                BlankFields
                ViewInitFields
            End If
        
        Case "K"
            If grdlst.Row = grdlst.Rows - 1 And grdlst.AllDataLoaded = True Then
                Call ASC_SendMessage(mo_Db, ms_Language_Code, 928, "#No more next item.")
            Else
                grdlst.Row = grdlst.Row + 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                BlankFields
                ViewInitFields
            End If
        Case Else
          Err.Raise ArmErr.InvalidArgument, "as_Role", "Invalid role: " & as_Role
    
    End Select

    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Select Case Err.Number
    Case ArmErr.SQLBadRowExpectedCount
        Call ASC_SendMessage(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    Case ArmErr.SQLBadRowAffectedCount
        Call ASC_SendMessage(mo_Db, ms_Language_Code, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.", , vbInformation)
        ViewInitFields
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    End Select

    Call ErrorMessage("tlb_Item_action")
    Call mo_Tools.LockScreen(Me, False)
End Sub

Private Sub tlb_Main_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler

Dim ls_serialStr As String

  Call mo_Tools.LockScreen(Me, True)
  
  ' TASK 298.2
  Select Case as_Role
  
  Case "A"
      CurrentKey = ""
      DisplayMode = mt_CstValues.DisplayMode_Add
      
  Case "B"
      If (grdlst.SelectedCount = 1) Then
          If grdlst.CurrentKey(0) <> "" Then
              CurrentKey = grdlst.CurrentKey(0)
              DisplayMode = mt_CstValues.DisplayMode_Update
          End If
      End If
      
  Case "C"
      If (grdlst.SelectedCount = 1) Then
          If grdlst.CurrentKey(0) <> "" Then
              m_CurrentKey1 = grdlst.CurrentKey(0)
              DisplayMode = mt_CstValues.DisplayMode_Delete
          End If
      End If
  
  Case "F"
      grdlst.Refresh
      
  Case "T"
      Call mo_Tools.LockScreen(Me, False)
      RaiseEvent quit
      Exit Sub
  Case Else
    Err.Raise ArmErr.InvalidArgument, "as_Role", "Invalid role: " & as_Role
  
  End Select
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
    
ErrHandler:
  Call ErrorMessage("tlb_Main_Action")
End Sub

Sub View_EnableControls()
On Error GoTo ErrHandler
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False

    txt_SP_Desc.Locked = True
    txt_SP_Desc.BackColor = CL_COLOR_DISABLED
    txt_SP_Desc.Enabled = True
    
    txt_SPR_Name.Locked = True
    txt_SPR_Name.BackColor = CL_COLOR_DISABLED
    txt_SPR_Name.Enabled = True
    
    txt_SPR_Desc.Locked = True
    txt_SPR_Desc.BackColor = CL_COLOR_DISABLED
    txt_SPR_Desc.Enabled = True
    
    txt_SPR_ID.Locked = True
    txt_SPR_ID.BackColor = CL_COLOR_DISABLED
    txt_SPR_ID.Enabled = True
    
    txt_dateEntered.Locked = True
    txt_dateEntered.BackColor = CL_COLOR_DISABLED
    txt_dateEntered.Enabled = True
    
    txt_dateUpdated.Locked = True
    txt_dateUpdated.BackColor = CL_COLOR_DISABLED
    txt_dateUpdated.Enabled = True
    
    txt_createdBy.Locked = True
    txt_createdBy.BackColor = CL_COLOR_DISABLED
    txt_createdBy.Enabled = True
    
    txt_updatedBy.Locked = True
    txt_updatedBy.BackColor = CL_COLOR_DISABLED
    txt_updatedBy.Enabled = True
    
    txt_DropDate.Locked = True
    txt_DropDate.BackColor = CL_COLOR_DISABLED
    txt_DropDate.Enabled = True
    
    fraSubItemMain.Enabled = True
    grd_Offer.Enabled = True
    tlb_Subitem.Enabled = True
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("View_EnableControls")
End Sub

Sub Add_Enablecontrols()
On Error GoTo ErrHandler
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    
    txt_SP_Desc.Locked = True
    txt_SP_Desc.BackColor = CL_COLOR_DISABLED
    txt_SPR_ID.Locked = True
    txt_SPR_ID.BackColor = CL_COLOR_DISABLED
    
    txt_dateEntered.Locked = True
    txt_dateEntered.BackColor = CL_COLOR_DISABLED
    txt_dateUpdated.Locked = True
    txt_dateUpdated.BackColor = CL_COLOR_DISABLED
    txt_createdBy.Locked = True
    txt_createdBy.BackColor = CL_COLOR_DISABLED
    txt_updatedBy.Locked = True
    txt_updatedBy.BackColor = CL_COLOR_DISABLED
    txt_DropDate.Locked = True
    txt_DropDate.BackColor = CL_COLOR_DISABLED
    chk_DropFlag.Enabled = False
    
    txt_SPR_Desc.Locked = False
    txt_SPR_Desc.BackColor = CL_COLOR_ENABLED
    
    txt_SPR_Name.Locked = False
    txt_SPR_Name.BackColor = CL_COLOR_ENABLED
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Add_Enablecontrols")
End Sub

Sub Update_EnableControls()
On Error GoTo ErrHandler
    
  ControlsEnable UserControl.Controls, fraItemTop, True
  ControlsEnable UserControl.Controls, fraItemBottom, True
  
  txt_SP_Desc.Locked = True
  txt_SP_Desc.BackColor = CL_COLOR_DISABLED
  txt_SPR_ID.Locked = True
  txt_SPR_ID.BackColor = CL_COLOR_DISABLED
  
  txt_dateEntered.Locked = True
  txt_dateEntered.BackColor = CL_COLOR_DISABLED
  txt_dateUpdated.Locked = True
  txt_dateUpdated.BackColor = CL_COLOR_DISABLED
  txt_createdBy.Locked = True
  txt_createdBy.BackColor = CL_COLOR_DISABLED
  txt_updatedBy.Locked = True
  txt_updatedBy.BackColor = CL_COLOR_DISABLED
  txt_DropDate.Locked = True
  txt_DropDate.BackColor = CL_COLOR_DISABLED
  chk_DropFlag.Enabled = False
  
  txt_SPR_Desc.Locked = False
  txt_SPR_Desc.BackColor = CL_COLOR_ENABLED
  
  txt_SPR_Name.Locked = False
  txt_SPR_Name.BackColor = CL_COLOR_ENABLED
  Exit Sub
ErrHandler:
  Call ErrorHandler("Update_EnableControls")
End Sub

Sub UpdateInitFields()
On Error GoTo ErrHandler
    
  'idem
  ViewInitFields
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateInitFields")
End Sub

Private Sub InitControl(Optional aMode As Integer = 0)
On Error GoTo ErrHandler
    Dim ConnectData As Variant
    
    If Not ASC_ConnectToDB(mo_Db, ms_ConnectString, mb_Created) Then Exit Sub
    
    Select Case aMode
        Case 0
    'If No mode then exit
            Exit Sub
   
        Case 1
    'If already initialized then exit
        If mi_TypeList <> 1 Then
            mi_TypeList = 1
        Else
            'tlb_Main.PictureDisplayed = "P_Quit=-1"
            Exit Sub
        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 2
        'Pour la liste courte
        
        'Grille
'        grdlst.ResetGrid
        
        'Pour liste longue : Initialisation toolbar
'        tlb_Main.ClearAllIcons
'        tlb_Main.TableName = "Cap_SubProject"
'        tlb_Main.PictureDisplayed = "P_Refresh=6"
        
        Case 3
    
'            tlb_Item.ClearAllIcons
'            tlb_Item.TableName = ""
'            tlb_Item.PictureDisplayed = "P_Update=2 P_Previous=4 P_Next=5 P_Quit=-1"
    
        Case 4
    
        'Toolbar
'        tlb_Item.ClearAllIcons
'        tlb_Item.PictureDisplayed = "P_Valid=1 P_UnDo=2 P_Quit=-1"
    End Select
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitControl")
End Sub
Private Sub ObjectVisible(Optional aVisible As Boolean = True)
On Error GoTo ErrHandler
    
  UserControl.fraItem.Visible = aVisible
  UserControl.fraList.Visible = aVisible

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

Public Sub FrameWorkInit(ByRef lt_CstValues As Type_CstValues, ByVal ls_InstanceName As String, Optional ATypeList As Integer = 0)
On Error GoTo ErrHandler
    
  'Restriction of initialsation
  mi_TypeParam = ATypeList
      
  Set mt_CstValues = lt_CstValues
  
  
  mi_CptTag = mt_CstValues.Tag_SubProject
  
  ' Add the tabulation for the embedded controls
  With UserControl
    .ScaleMode = 1
    .tbsEmbedded.Tabs.Clear
    .tbsEmbedded.TabFixedWidth = 150
    Dim lt_Tab As Object
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Project", "#Project")
    lt_Tab.Tag = mt_CstValues.Tag_Project
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Action", "#Action")
    lt_Tab.Tag = mt_CstValues.Tag_Action
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Customer", "#Customer")
    lt_Tab.Tag = mt_CstValues.Tag_Customer
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Contact", "#Contact")
    lt_Tab.Tag = mt_CstValues.Tag_Contact
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Product", "#Product")
    lt_Tab.Tag = mt_CstValues.Tag_Product
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Memo", "#Memo")
    lt_Tab.Tag = mt_CstValues.Tag_Memo
    Set lt_Tab = Nothing
  End With
  
  mi_DisplayMode = mt_CstValues.DisplayMode_None
  mi_OldDisplayMode = mi_DisplayMode
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("FrameWorkInit")
End Sub

' Properties for let application access to critical data
Public Property Get CptTag()
    
    CptTag = mi_CptTag
End Property

' Give the tag of the component which embed this instance
Public Property Get EmbeddedIn() As Integer
    
    EmbeddedIn = mi_EmbeddedIn
End Property

' Give the tag of the component embed by this
Public Property Get EmbedTag() As Integer
    
    EmbedTag = mi_EmbedTag
End Property

' Give the actual display mode
Public Property Get DisplayMode() As Integer
    
    DisplayMode = mi_DisplayMode
End Property

' Change the actual display mode
Public Property Let DisplayMode(ByVal li_DisplayMode As Integer)
    
    SwapToDisplayMode li_DisplayMode
End Property

' when a component embed this instance
Public Sub CatchBy(ByVal li_TagCaller, ByVal ls_Params As String)
On Error GoTo ErrHandler
    
    mi_EmbeddedIn = li_TagCaller
    mb_Root = False
    mi_EmbedTag = -1
    
    If mi_EmbeddedIn <> -1 Then
        ' When a component is embedded, it always appears in short list
        SwapToDisplayMode mt_CstValues.DisplayMode_List, ls_Params
    End If
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("CatchBy")
End Sub

Private Function WithParent() As Boolean
On Error GoTo ErrHandler
    
    If m_Project = "" And m_Customer = "" And m_Contact = "" And m_Product = "" And m_Action = "" Then
        WithParent = False
    Else
        WithParent = True
    End If

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

' Change the display mode
Private Sub SwapToDisplayMode(li_DisplayMode As Integer, Optional ls_Params As String = "")
On Error GoTo ErrHandler
    mb_InternalInit = True
    
    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 component is embedded
            ShortListDisplay ls_Params
        
        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
    
    mb_InternalInit = False
    Exit Sub
    
ErrHandler:
    mb_InternalInit = False
    Call ErrorHandler("SwapToDisplayMode")
End Sub

' Hide all graphics elements
Private Sub DisplayMode_None()
On Error GoTo ErrHandler
    
   With UserControl
        .fraItem.Visible = False
        .fraList.Visible = False
    End With
    Exit Sub
ErrHandler:
    Call ErrorHandler("DisplayMode_None")
End Sub

Private Sub ViewLoad()
End Sub

Private Sub ShortListDisplay(ByVal ls_Params As String)
On Error GoTo ErrHandler
    
    RaiseEvent SwitchToView(mt_CstValues.View_Embedded)
   
    ShortList_Resize
        
    Exit Sub
ErrHandler:
    Call ErrorHandler("ShortListDisplay")
End Sub


Private Sub tlb_Subitem_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler
    Dim lb_Result As Boolean

    Call mo_Tools.LockScreen(Me, True)
    
    Select Case as_Role

    Case "A"
        Call AddDisplaySubItem
        
    Case "B"
        If grd_Offer.SelectedCount = 1 Then
            Call UpdateDisplaySubItem
        End If
    
    Case "C"
        If grd_Offer.SelectedCount = 1 Then
            Call DeleteDisplaySubItem
        End If
        
    Case "T"
        Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
        If DisplayMode = mt_CstValues.DisplayMode_Add Then
            Call Add_Enablecontrols
        End If

    Case "F"
        'Call grd_Offer.Refresh
        
    Case "H"
      lb_Result = False

      Select Case ml_DisplayModeSubItem
          Case mt_CstValues.DisplayMode_Add
              lb_Result = SubRecordAdd()
          Case mt_CstValues.DisplayMode_Update
              If grd_Offer.SelectedCount = 1 Then
                  lb_Result = SubRecordUpdate(grd_Offer.CurrentKey(1))
              End If
          Case mt_CstValues.DisplayMode_Delete
              If grd_Offer.SelectedCount = 1 Then
                  lb_Result = SubRecordDelete(grd_Offer.CurrentKey(1))
              End If
      End Select
      If lb_Result Then
          If ml_DisplayModeSubItem = mt_CstValues.DisplayMode_Add Then
              Call BlankFieldsSubItem
          Else
              Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
          End If
      End If
    Case "I"
      Select Case ml_DisplayModeSubItem
          Case mt_CstValues.DisplayMode_Add
              Call AddDisplaySubItem
          Case mt_CstValues.DisplayMode_Update
              Debug.Assert (grd_Offer.SelectedCount = 1)
              Call UpdateDisplaySubItem
          Case Else
              Debug.Assert (False)
      End Select
    Case Else
      Err.Raise ArmErr.InvalidArgument, "as_Role", "Invalid role: " & as_Role
    End Select
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Select Case Err.Number
    Case ArmErr.SQLBadRowExpectedCount
        Call ASC_SendMessage(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    Case ArmErr.SQLBadRowAffectedCount
        Call ASC_SendMessage(mo_Db, ms_Language_Code, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.", , vbInformation)
        Dim lv_Key As Variant
        lv_Key = grd_Offer.SelectedKey(0)
        Call grd_Offer.Refresh
        If grd_Offer.SearchKey(True, lv_Key) Then
            Call ViewInitFieldsSubItem
        Else
            Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
        End If
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    End Select

    Call ErrorMessage("tlb_Subitem_action")
End Sub

' Embed a component
Private Sub tbsEmbedded_Click()
On Error GoTo ErrHandler
    
    If mi_EmbedTag = UserControl.tbsEmbedded.SelectedItem.Tag Then Exit Sub
    
    Call mo_Tools.LockScreen(Me, True)
    With UserControl
        
        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 .tbsEmbedded.SelectedItem.Tag = mt_CstValues.Tag_Memo Then
                     RaiseEvent SwitchToView(mt_CstValues.View_Medium)
                Else
                    RaiseEvent SwitchToView(mt_CstValues.View_Full)
                End If
            End If
            mi_EmbedTag = .tbsEmbedded.SelectedItem.Tag
            RaiseEvent Catch(mi_EmbedTag, m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2)
        End If
    End With

    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
ErrHandler:
    Call ErrorMessage("tbsEmbedded_Click")
End Sub


Private Sub AddInitFields()
On Error GoTo ErrHandler

Dim ls_Request As String
Dim ll_Cursor As Long

  'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
  txt_SPR_ID.Text = grdlst.Rows + 1
  txt_SPR_Desc.Text = ""
  txt_SPR_Name.Text = ""
  
  ls_Request = "SELECT SP_Desc FROM sales_project WHERE SP_Capkey=$SP_Capkey$"
  ls_Request = Replace(ls_Request, "$SP_Capkey$", mo_Tools.SqlStr(m_Project), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
  txt_SP_Desc.Text = mo_Db.GetFields(ll_Cursor, "SP_Desc")
  Call mo_Db.Close(ll_Cursor)
  
  txt_createdBy.Text = ms_UID
  txt_updatedBy.Text = ms_UID
  txt_dateEntered.Text = Format(Date, "dd\/mm\/yyyy")
  txt_dateUpdated.Text = Format(Date, "dd\/mm\/yyyy")
  
  
  chk_DropFlag.Visible = False
  txt_DropDate.Visible = False
  
  DisplayDefaultValues
  
  Exit Sub
  
ErrHandler:
  Call mo_Db.Close(ll_Cursor)
  Call ErrorHandler("AddInitFields")
End Sub

Private Sub BlankFields()
On Error GoTo ErrHandler
    Dim ls_req As String
          
    txt_SP_Desc.Text = ""
    txt_SPR_Name.Text = ""
    txt_SPR_Desc.Text = ""

    chk_DropFlag.Value = 0
    txt_DropDate.Text = ""
    
    Call grd_Offer.ClearGrid
    mb_grd_ProductsLoaded = False
    Exit Sub
ErrHandler:
    Call ErrorHandler("BlankFields")
End Sub

Private Sub DisplayDefaultValues()
On Error GoTo ErrHandler
    Dim i As Integer
    Dim TheControl As Control
    Dim TheControlName As String
    
    If p_DefaultValuesLoaded = False Then
        p_DefaultValuesCount = GetScreenDefaultValues(mo_Db, ms_UID, ms_Language_Code, "Cap_Offer_Detail", p_DefaultValues)
        p_DefaultValuesLoaded = True
    End If
    DisplayScreenDefaultValues UserControl.Controls, p_DefaultValues, p_DefaultValuesCount

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

Private Sub ViewInitFields()
On Error GoTo ErrHandler
    Dim ls_Request As String
    Dim ll_Cursor As Long

    If m_CurrentKey1 = "" Then Exit Sub
    
    ls_Request = "exec Cap_Subproject_sel $SPR_Id$, $Language_Code$"
'    ls_Request = "SELECT SPR.SPR_Id,SPR.SPR_Name,SPR.SPR_Desc "
'    ls_Request = ls_Request & "FROM Cap_Subproject SPR "
'    ls_Request = ls_Request & "WHERE SPR_Id=$SPR_Id$"
    
    ls_Request = Replace(ls_Request, "$SPR_Id$", mo_Tools.SqlStr(m_CurrentKey1), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
    txt_SPR_ID.Text = mo_Db.GetFields(ll_Cursor, "SPR_ID")
    txt_SPR_Name.Text = mo_Db.GetFields(ll_Cursor, "SPR_Name")
    txt_SPR_Desc.Text = mo_Db.GetFields(ll_Cursor, "SPR_Desc")
    txt_SP_Desc.Text = mo_Db.GetFields(ll_Cursor, "SP_Desc")
    ml_iConcurrency = mo_Db.GetFields(ll_Cursor, "iConcurrency")
    
    txt_dateEntered.Text = Format(mo_Db.GetFields(ll_Cursor, "Z_Creation"), "dd\/mm\/yyyy")
    txt_dateUpdated.Text = Format(mo_Db.GetFields(ll_Cursor, "Z_Last_Upd"), "dd\/mm\/yyyy")
    txt_createdBy.Text = mo_Db.GetFields(ll_Cursor, "Z_CreatorDesc")
    txt_updatedBy.Text = mo_Db.GetFields(ll_Cursor, "Z_Last_Upd_UserDesc")
    
    Call mo_Db.Close(ll_Cursor)
    

    chk_DropFlag.Value = IIf(False, 1, 0)
    txt_DropDate.Text = ""

    chk_DropFlag.Visible = chk_DropFlag.Value
    txt_DropDate.Visible = chk_DropFlag.Value
    Dim lv_Data As Variant
    
    ls_Request = "exec Cap_Offer_lst NULL, $SPR_Id$, $Language_Code$"
    ls_Request = Replace(ls_Request, "$SPR_Id$", mo_Tools.SqlStr(txt_SPR_ID.Text), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    If Not grd_Offer.Load(ls_Request, True) Then
        Err.Raise ArmErr.CompFncFailed, "grd_Offer", "Function Load failed"
    End If
    Exit Sub
    
ErrHandler:
    Call mo_Db.Close(ll_Cursor)
    Call ErrorHandler("ViewInitFields")
End Sub

Private Sub ListProjectOf(ByVal AProjectKey1 As String, ByVal AProjectKey2 As String)
On Error GoTo ErrHandler
  Dim ls_req As String
  
    If Not (AProjectKey1 <> "" And AProjectKey2 <> "") Then Exit Sub
    ls_req = "Cap_Subproject_lst $SP_Capkey$, $Language_Code$"
    ls_req = Replace(ls_req, "$SP_Capkey$", mo_Tools.SqlStr(AProjectKey1), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    Call grdlst.Load(ls_req, True)
    'If grdlst.Execute = False Then
        'Call Err.Raise(CompFncFailed, "", "grdlst.Execute failed.")
    'End If

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

Private Sub ListCustomerOf(ACustomerkey1 As String, ACustomerkey2 As String)
    ' no Customer - Offer navigation link
End Sub

Private Sub ListContactOf(AContactKey1 As String, AContactKey2 As String, AContactKey3 As String)
    ' no Contact - Offer navigation link
End Sub

' This function is called by the application when the component embedded is updated
Public Sub Embedded_Updated()
' DO NOTHING
End Sub


Private Sub SwapToDisplayModeSubitem(ByVal al_Mode As Long)
On Error GoTo ErrHandler

    fraSubItemMain.Visible = al_Mode <> mt_CstValues.DisplayMode_None
    
    'update toolbar
    Select Case al_Mode
        Case mt_CstValues.DisplayMode_View, mt_CstValues.DisplayMode_List
            Call tlb_Subitem.DisplayFace("0")
        Case mt_CstValues.DisplayMode_Add
            Call tlb_Subitem.DisplayFace("1")
        Case mt_CstValues.DisplayMode_Update
            Call tlb_Subitem.DisplayFace("2")
        Case mt_CstValues.DisplayMode_Delete
            Call tlb_Subitem.DisplayFace("3")
    End Select
    
    ' update subitem frame
    Select Case al_Mode
        Case mt_CstValues.DisplayMode_View, mt_CstValues.DisplayMode_List
            fraSubitemDetail.Visible = False
            Call grd_Offer.Move(mt_CstValues.Frm_Margin, 4 * mt_CstValues.Frm_Margin, fraSubItemMain.Width - tlb_Subitem.Width - 6 * mt_CstValues.Frm_Spacing, fraSubItemMain.Height - 6 * mt_CstValues.Frm_Spacing)
            tlb_Item.Enabled = True
            grd_Offer.Enabled = True

        Case mt_CstValues.DisplayMode_Add, mt_CstValues.DisplayMode_Update, mt_CstValues.DisplayMode_Delete
            Call grd_Offer.Move(mt_CstValues.Frm_Margin, fraSubitemDetail.Top + fraSubitemDetail.Height + mt_CstValues.Frm_Spacing, fraSubItemMain.Width - tlb_Subitem.Width - 6 * mt_CstValues.Frm_Spacing, fraSubItemMain.Height - fraSubitemDetail.Height - 6 * mt_CstValues.Frm_Spacing)
            fraSubitemDetail.Visible = True
            tlb_Item.Enabled = False
            grd_Offer.Enabled = False
    End Select
    ml_DisplayModeSubItem = al_Mode
    Call fraSubItemMain.Refresh
    Exit Sub
ErrHandler:
    Call ErrorHandler("SwapToDisplayModeSubitem")
End Sub

Private Sub InitSubitem()
On Error GoTo ErrHandler
Dim la_Columns() As String

    grd_Offer.ResetGrid
    grd_Offer.MultiSelect = False
    grd_Offer.AllowSort = False
    
    ReDim la_Columns(10)
    la_Columns(0) = "COF_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "COF_Id" & CH_LDELIMIT & "#Id"
    la_Columns(1) = "Z_Creation" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Creation" & CH_LDELIMIT & "#Date"
    la_Columns(2) = "CCU_Desc" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_Desc" & CH_LDELIMIT & "#Customer"
    la_Columns(3) = "COF_TypeDesc" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_TypeDesc" & CH_LDELIMIT & "#Offer type"
    la_Columns(4) = "COF_StatDesc" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_StatDesc" & CH_LDELIMIT & "#Status"
    la_Columns(5) = "LEV_Name" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_Name" & CH_LDELIMIT & "#Level"
    la_Columns(6) = "COF_ValidTo" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_ValidTo" & CH_LDELIMIT & "#Valid to"
    la_Columns(7) = "COF_Follow" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Follow" & CH_LDELIMIT & "#Follow up"
    la_Columns(8) = "Z_Creator" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Creator" & CH_LDELIMIT & "#Creator"
    la_Columns(9) = "Z_Last_Upd_User" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Last_Upd_User" & CH_LDELIMIT & "#Z_Last_Upd_User"
    la_Columns(10) = "Z_Last_Upd" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Last_Upd" & CH_LDELIMIT & "#Z_Last_Upd"
    Call grd_Offer.SetColumns(la_Columns)
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_None)
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitSubitem")
End Sub


Private Sub AddDisplaySubItem()
On Error GoTo ErrHandler
    
    BlankFieldsSubItem
    
    Call grd_Offer.DeselectRow
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_Add)
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("AddDisplaySubItem")
End Sub

Private Sub RefreshGridSafe(ByRef ao_grd As ArmGrid)
On Error GoTo ErrHandler
    Dim lv_Key As Variant
    If ao_grd.SelectedCount > 0 Then
        lv_Key = ao_grd.SelectedKey(0)
    Else
        lv_Key = Empty
    End If
    Call ao_grd.Refresh
    If Not IsEmpty(lv_Key) Then
        Call ao_grd.SearchKey(True, lv_Key)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("RefreshGridSafe")
End Sub

Private Sub BlankFieldsSubItem()
On Error GoTo ErrHandler
    Dim ls_req As String

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

Private Sub ViewInitFieldsSubItem()
On Error GoTo ErrHandler

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

Private Sub UpdateDisplaySubItem()
On Error GoTo ErrHandler
    
    BlankFieldsSubItem
    
    Call ViewInitFieldsSubItem
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_Update)
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateDisplaySubItem")
End Sub

Private Sub DeleteDisplaySubItem()
On Error GoTo ErrHandler
    
    BlankFieldsSubItem
    
    Call ViewInitFieldsSubItem
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_Delete)

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

Function SubRecordCheck() As Boolean
On Error GoTo ErrHandler
    SubRecordCheck = False
    ErrorOFF
    If ErrorFound Then Exit Function
    
    SubRecordCheck = True
    Exit Function
ErrHandler:
    Call ErrorHandler("SubRecordCheck")
End Function

Private Function SubRecordAdd() As Boolean
On Error GoTo ErrHandler
    
    SubRecordAdd = True
    Exit Function
    
ErrHandler:
    Call ErrorHandler("SubRecordAdd")
End Function

Private Sub SubRecordAddDB(ByRef ao_grd As ArmGrid, ByVal al_line As Long)
On Error GoTo ErrHandler
    
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("SubRecordAddDB")
End Sub


Private Sub SubRecordUpdateDB(ByRef ao_grd As ArmGrid, ByVal al_line As Long)
On Error GoTo ErrHandler
    
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("SubRecordUpdateDB")
End Sub

Private Function SubRecordUpdate(ByVal ACode As String) As Boolean
On Error GoTo ErrHandler
    SubRecordUpdate = False
    
    
    If Not SubRecordCheck() Then Exit Function
    
    SubRecordUpdate = True
    Exit Function
    
ErrHandler:
    Call ErrorHandler("SubRecordUpdate")
End Function

Private Function SubRecordDelete(ByVal ACode As String) As Boolean
On Error GoTo ErrHandler
    SubRecordDelete = False
    
    If Trim$(ACode) = "" Then Call Err.Raise(InvalidArgument, "", "ACode is empty.")
    Debug.Assert (grd_Offer.SelectedCount = 1)
    Debug.Assert (ACode = grd_Offer.SelectedKey(0)(1))
    
    If DeleteConfirmation(mo_Db, ms_Language_Code) = False Then Exit Function
    
    If Not grd_Offer.DeleteLine(Array(m_CurrentKey1, ACode)) Then
        Exit Function
    End If
    
    txt_updatedBy.Text = ms_UID
    txt_dateUpdated.Text = Format(Date, "dd\/mm\/yyyy")

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

Private Function IsTelNum(ByVal as_telNum As String) As Boolean
On Error GoTo ErrHandler
    Dim ll_i  As Long
    IsTelNum = False
    ' must start with 00XXY
    If Len(as_telNum) < 5 Then Exit Function
    If Left(as_telNum, 2) <> "00" Then Exit Function
    
    ' tel number must containt only digits 0..9
    For ll_i = 1 To Len(as_telNum)
        If Mid(as_telNum, ll_i, 1) < "0" Then Exit Function
        If Mid(as_telNum, ll_i, 1) > "9" Then Exit Function
    Next
    IsTelNum = True
    Exit Function
ErrHandler:
    Call ErrorHandler("IsTelNum")
End Function

Private Function ReplaceCommonPlaceholders(ByVal as_Request As String) As String
On Error GoTo ErrHandler

  as_Request = Replace(as_Request, "$Z_Creator$", mo_Tools.SqlInt(ml_U_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$U_Code$", mo_Tools.SqlInt(ml_U_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$Z_Last_Upd_User$", mo_Tools.SqlInt(ml_U_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$Language_Code$", mo_Tools.SqlStr(ms_Language_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$iConcurrency$", mo_Tools.SqlInt(ml_iConcurrency), , , vbTextCompare)
  ReplaceCommonPlaceholders = as_Request
  Exit Function
ErrHandler:
  Call ErrorHandler("ReplaceCommonPlaceholders")
End Function


' display standard error message
Public Sub ErrorMessage(ByVal as_Fct As String)
  Dim ls_ErrSource As String
  Dim ls_errDescription As String
  Dim ls_Message As String
  
  ls_ErrSource = as_Fct & SEP1 & Err.Source
  ls_errDescription = Err.Description
  ls_Message = SCREEN_NAME & " exception. Nr:" & Err.Number & ",Desc: " & ls_errDescription & ",Src:" & ls_ErrSource & "@"
  Call mo_Tools.LogMessage(mo_Db, ml_U_Code, SCREEN_NAME, ls_Message, "E")
  Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & ls_ErrSource & vbCrLf & "Description: " & ls_errDescription, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
  End
End Sub

' Standard error handler
Private Sub ErrorHandler(ByVal as_Fct As String)
  
  Call Err.Raise(Err.Number, UserControl.Name & "." & as_Fct & SEP1 & Err.Source, Err.Description)
End Sub

