VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl A_Capture 
   ClientHeight    =   5490
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   9825
   ScaleHeight     =   5490
   ScaleWidth      =   9825
   Begin Project1.CapFile CapFile 
      Height          =   720
      Index           =   1
      Left            =   375
      TabIndex        =   19
      Top             =   4125
      Visible         =   0   'False
      Width           =   1500
      _ExtentX        =   2646
      _ExtentY        =   1270
   End
   Begin VB.CheckBox chk_isInitTab 
      Height          =   225
      Left            =   9420
      TabIndex        =   16
      Tag             =   "chk_isInitTab"
      ToolTipText     =   "#Default tab when Capture starts"
      Top             =   300
      Width           =   270
   End
   Begin Project1.CapSOMQuote CapSOMQuote 
      Height          =   555
      Index           =   1
      Left            =   7350
      TabIndex        =   15
      Top             =   4245
      Visible         =   0   'False
      Width           =   675
      _ExtentX        =   1191
      _ExtentY        =   979
   End
   Begin Project1.CapSubProject CapSubProject 
      Height          =   765
      Index           =   1
      Left            =   4545
      TabIndex        =   17
      Top             =   4125
      Visible         =   0   'False
      Width           =   885
      _ExtentX        =   1561
      _ExtentY        =   1349
   End
   Begin Project1.CapOffer CapOffer 
      Height          =   930
      Index           =   1
      Left            =   6540
      TabIndex        =   18
      Top             =   1215
      Visible         =   0   'False
      Width           =   1260
      _ExtentX        =   2223
      _ExtentY        =   1640
   End
   Begin VB.Frame frm_Outstanding 
      Height          =   930
      Left            =   3810
      TabIndex        =   7
      Tag             =   "frm_Outstanding"
      Top             =   2475
      Visible         =   0   'False
      Width           =   2400
      Begin Project1.ToolbarControl tlb_Outstanding 
         Height          =   690
         Left            =   4770
         TabIndex        =   14
         Top             =   150
         Width           =   735
         _ExtentX        =   1296
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grd_Actions 
         Height          =   780
         Left            =   105
         TabIndex        =   13
         Top             =   2940
         Width           =   4080
         _ExtentX        =   7197
         _ExtentY        =   1376
      End
      Begin Project1.ArmGrid grd_Projects 
         Height          =   675
         Left            =   105
         TabIndex        =   12
         Top             =   1335
         Width           =   4035
         _ExtentX        =   7117
         _ExtentY        =   1191
      End
      Begin VB.Label lbl_FollowUpProjects 
         Caption         =   "#Your Projects to Follow up"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   12
            Charset         =   238
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   15
         TabIndex        =   11
         Tag             =   "lbl_FollowUpProjects"
         Top             =   480
         Width           =   3615
      End
      Begin VB.Label lbl_ProjectInfo 
         Caption         =   "#You have $expired$ Projects where the Follow up Date has expired and $follow$ Projects to follow up in th next $days$ days"
         Height          =   375
         Left            =   45
         TabIndex        =   10
         Tag             =   "lbl_ProjectInfo"
         Top             =   870
         Width           =   5625
      End
      Begin VB.Label lbl_ActionInfo 
         Caption         =   $"A_Capture.ctx":0000
         Height          =   375
         Left            =   45
         TabIndex        =   9
         Tag             =   "lbl_ActionInfo"
         Top             =   2385
         Width           =   5715
      End
      Begin VB.Label lbl_OutstandingActions 
         Caption         =   "#Actions which are outstanding and need your attention"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   12
            Charset         =   238
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   60
         TabIndex        =   8
         Tag             =   "lbl_OutstandingActions"
         Top             =   2055
         Width           =   3615
      End
   End
   Begin MSComctlLib.TabStrip tbsNavBar 
      Height          =   360
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   9060
      _ExtentX        =   15981
      _ExtentY        =   635
      TabWidthStyle   =   2
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   3
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
   Begin Project1.CapPrj project 
      Height          =   1155
      Index           =   1
      Left            =   7005
      TabIndex        =   1
      Top             =   1530
      Visible         =   0   'False
      Width           =   1155
      _ExtentX        =   10927
      _ExtentY        =   15372
   End
   Begin Project1.capprd product 
      Height          =   795
      Index           =   1
      Left            =   1440
      TabIndex        =   2
      Top             =   720
      Visible         =   0   'False
      Width           =   1095
      _ExtentX        =   1931
      _ExtentY        =   1402
   End
   Begin Project1.Capact action 
      Height          =   1020
      Index           =   1
      Left            =   240
      TabIndex        =   3
      Top             =   1920
      Visible         =   0   'False
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   1799
   End
   Begin Project1.Capcon contact 
      Height          =   735
      Index           =   1
      Left            =   1680
      TabIndex        =   4
      Top             =   1680
      Visible         =   0   'False
      Width           =   1155
      _ExtentX        =   2037
      _ExtentY        =   1296
   End
   Begin Project1.Capcus Customer 
      Height          =   975
      Index           =   1
      Left            =   1800
      TabIndex        =   5
      Top             =   2880
      Visible         =   0   'False
      Width           =   1035
      _ExtentX        =   1826
      _ExtentY        =   1720
   End
   Begin Project1.Capmem memo 
      Height          =   915
      Index           =   1
      Left            =   3720
      TabIndex        =   6
      Top             =   1200
      Visible         =   0   'False
      Width           =   855
      _ExtentX        =   1508
      _ExtentY        =   1614
   End
End
Attribute VB_Name = "A_Capture"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'*****************************************
'*** PARAMETERS OF CONNECTION ************
Private Const USE_FRAME_CONNECTION = True

'*****************************************
'******** Curseur de connexion ***********
Private mo_ArmDb As Object

Private mo_Tools As DPC_Tools
'Indicates if the connection was created at this level
Private mb_Created As Boolean

Private ms_ConnectString As String

Private m_Language As String
Private mUCode As Long

Private FirstDisplayDone As Boolean

Dim mt_CstValues As New Type_CstValues          ' Contains all constants shared with component

Dim mo_Cpts(4, 9) As Object 'This array contains organize component for simulating the embed action
Dim mi_SelNavTag As Integer 'Indicates the main navigation tag

Dim tab_loaded(4, 5)

Private ms_Connect_Server As String
Private ms_Connect_Database As String
Private ms_Connect_Login As String
Private ms_Connect_Password As String
Private ms_Connect_Application As String

Private ms_initTab As String       ' initial tab defined in DefaultValue or "tbs_Project" if not
Private mb_InternalInit As Boolean      ' set true while loading data into controls to suppress event handlers

Private mb_Initialized As Boolean
Private WithEvents mSeminar As CapSeminar
Attribute mSeminar.VB_VarHelpID = -1
Private WithEvents mSampleDoc As CapSample
Attribute mSampleDoc.VB_VarHelpID = -1
Private WithEvents mo_SPA As SPA_Navig
Attribute mo_SPA.VB_VarHelpID = -1

Private mo_LastSwitchToCpt As Object
Private mi_LastSwitchToView As Integer

Public Event Unload()
Public Event IsOfferLocked(ByRef ab_IsLocked As Boolean)

Public Property Let Ucode(ByVal aValue As Long)
    mUCode = aValue
End Property

Public Property Set Tools(ByRef ao_Tools As Object)

  Set mo_Tools = ao_Tools
End Property

Public Property Let Visible(ByVal aVisible As Boolean)
    UserControl.Extender.Visible = aVisible
End Property
Public Property Get Visible() As Boolean
    Visible = UserControl.Extender.Visible
End Property

Public Property Let Top(ByVal aTop As Single)
    UserControl.Extender.Top = aTop
End Property
Public Property Get Top() As Single
    Top = UserControl.Extender.Top
End Property

Public Property Let Height(ByVal aHeight As Single)
    UserControl.Extender.Height = aHeight
End Property
Public Property Get Height() As Single
    Height = UserControl.Extender.Height
End Property

Public Property Let Left(ByVal aLeft As Single)
    UserControl.Extender.Left = aLeft
End Property
Public Property Get Left() As Single
    Left = UserControl.Extender.Left
End Property

Public Property Let Width(ByVal aWidth As Single)
    UserControl.Extender.Width = aWidth
End Property
Public Property Get Width() As Single
    Width = UserControl.Extender.Width
End Property

Public Sub Move(ByVal aLeft As Single, ByVal aTop As Single, ByVal aWidth As Single, ByVal aHeight As Single)
    Call UserControl.Extender.Move(aLeft, aTop, aWidth, aHeight)
End Sub


Public Property Get Initialized() As Boolean
    Initialized = mb_Initialized
End Property

Public Property Let Connect_Server(as_Server As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Connect_Server_Let", "as_Server=" & as_Server
    #End If
    ms_Connect_Server = as_Server
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Connect_Server_Let", "ms_Connect_Server=" & ms_Connect_Server
    #End If
End Property

Public Property Let Connect_Database(as_Database As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Connect_Database_Let", "as_Database=" & as_Database
    #End If
    ms_Connect_Database = as_Database
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Connect_Database_Let", "ms_ConnectDabase=" & ms_Connect_Database
    #End If
End Property

Public Property Let Connect_Login(as_Login As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Connect_Login_Let", "as_Login=" & as_Login
    #End If
    ms_Connect_Login = as_Login
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Connect_Login_Let", "ms_Connect_Login=" & ms_Connect_Login
    #End If
End Property

Public Property Let Connect_Password(as_Password As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Connect_Password_Let", "as_Password=" & as_Password
    #End If
    ms_Connect_Password = as_Password
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Connect_Password_Let", "ms_Connect_Password=" & ms_Connect_Password
        #End If
End Property

Public Property Let Connect_Application(as_Application As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Connect_Application_Let", "as_Application=" & as_Application
    #End If
    ms_Connect_Application = as_Application
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Connect_Application_Let", "ms_Connect_Application=" & ms_Connect_Application
    #End If
End Property

Public Property Let Connect_Language(as_Language As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Connect_Language_Let", "as_Language=" & as_Language
    #End If
    m_Language = as_Language
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Connect_Language_Let", "m_Language=" & m_Language
    #End If
End Property

' Indicates if a variable is a valid object
Private Function isValid(ByRef lo_Object As Variant)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:IsValid"
    #End If
    
    Dim lb_Result
    If IsObject(lo_Object) Then
        lb_Result = Not (lo_Object Is Nothing)
    Else
        lb_Result = False
    End If
    
    isValid = lb_Result

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

Private Sub project_CreateOffer(Index As Integer, ByVal al_EmbeddedIn As Long, ByVal al_OfferType As Long, ByVal as_SPR_Id As String, ByVal as_SPR_Name As String)
Dim lo_ParentObject As Object

    Set lo_ParentObject = GetCpt(mi_SelNavTag, mt_CstValues.Tag_Offer)
    If Not lo_ParentObject Is Nothing Then
        If TypeOf lo_ParentObject Is CapOffer Then
            Call lo_ParentObject.CreateOffer(al_OfferType, as_SPR_Id, as_SPR_Name)
        End If
    End If
End Sub

Private Sub product_CreateOffer(Index As Integer, ByVal al_EmbeddedIn As Long, ByVal al_OfferType As Long, ByVal as_SPR_Id As String, ByVal as_SPR_Name As String)
Dim lo_ParentObject As Object

    If (al_EmbeddedIn <> -1) Then
        Set lo_ParentObject = GetCpt(mi_SelNavTag, al_EmbeddedIn)
        If TypeOf lo_ParentObject Is CapPrj Then
            Call lo_ParentObject.CreateOffer(al_OfferType, as_SPR_Id, as_SPR_Name)
        End If
    End If
  
End Sub

Private Sub MoveToFirstTab(AParentID As Integer)
Dim ParentObject As Object
Dim lo_Root As Object
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:MoveToFirstTab", "AParentID=" & AParentID
    #End If
    
    If (AParentID <> -1) Then
        Set ParentObject = GetCpt(mi_SelNavTag, AParentID)
        Set lo_Root = GetRoot(mi_SelNavTag)
        ParentObject.GoToTab1
        Set ParentObject = Nothing
        Set lo_Root = Nothing
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:MoveToFirstTab"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:MoveToFirstTab"
    CapMouseOn
End Sub

Private Sub SetSizeAndPosition()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:SetSizeAndPosition"
    #End If
    
    mt_CstValues.View_Med_Left = mo_Cpts(0, 0).FraFilterLeft
    mt_CstValues.View_Med_Width = mo_Cpts(0, 0).UserControlWidth - mo_Cpts(0, 0).FraFilterLeft - mt_CstValues.Frm_Margin
    
    'mt_CstValues.View_Emb_Left = mo_Cpts(0, 0).FraFilterLeft + (2 * mt_CstValues.Frm_Margin)
    'mt_CstValues.View_Emb_Width = mo_Cpts(0, 0).UserControlWidth - mo_Cpts(0, 0).FraFilterLeft - mt_CstValues.Frm_Margin - (4 * mt_CstValues.Frm_Margin)

    mt_CstValues.View_Emb_Left = (2 * mt_CstValues.Frm_Margin)
    mt_CstValues.View_Emb_Width = mo_Cpts(0, 0).UserControlWidth - mt_CstValues.Frm_Margin - (4 * mt_CstValues.Frm_Margin)

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

Private Sub CapSubProject_HideGrid(Index As Integer, AParentID As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    
    MoveToFirstTab AParentID
    
Trace_End:
    CapMouseOn
    Exit Sub
    
Trace_Err:
    CapMouseOn
End Sub

Private Sub CapSubProject_SwitchToView(Index As Integer, ByVal li_View As Integer)
    Call SwitchToView(CapSubProject(Index), li_View)
End Sub

Private Sub CapSubProject_Updated(Index As Integer)
    Call Updated(CapSubProject(Index))
End Sub

Private Sub CapFile_HideGrid(Index As Integer, AParentID As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    
    MoveToFirstTab AParentID
    
Trace_End:
    CapMouseOn
    Exit Sub
    
Trace_Err:
    CapMouseOn
End Sub

Private Sub CapFile_SwitchToView(Index As Integer, ByVal li_View As Integer)
    Call SwitchToView(CapFile(Index), li_View)
End Sub

Private Sub CapFile_Updated(Index As Integer)
    Call Updated(CapFile(Index))
End Sub

Private Sub CapSOMQuote_HideGrid(Index As Integer, AParentID As Integer)
    On Error GoTo Trace_Err
    CapMouseOff
    
    MoveToFirstTab AParentID
    
Trace_End:
    CapMouseOn
    Exit Sub
    
Trace_Err:
    CapMouseOn
End Sub

Private Sub CapSOMQuote_SwitchToView(Index As Integer, ByVal li_View As Integer)
    Call SwitchToView(CapSOMQuote(Index), li_View)
End Sub

Private Sub CapSOMQuote_Updated(Index As Integer)
    Call Updated(CapSOMQuote(Index))
End Sub

Private Sub chk_isInitTab_Click()
    On Error GoTo Trace_Err
    If mb_InternalInit Then Exit Sub
    
    
    If chk_isInitTab.Value = 1 Then
        Call UpdateUserDefaultValue("InitTabOnline", Left(tbsNavBar.SelectedItem.Tag, 10), tbsNavBar.SelectedItem.Tag)
        ms_initTab = tbsNavBar.SelectedItem.Tag
    Else
        Call DeleteUserDefaultValue("InitTabOnline")
        'check if it is tbs_Customer
        If tbsNavBar.SelectedItem.Tag <> "tbs_Customer" Then
            ms_initTab = "tbs_Customer"
        Else
            ' Vk cannot be removed
            mb_InternalInit = True
            chk_isInitTab.Value = 1
            mb_InternalInit = False
        End If
    End If
    
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:chk_isInitTab_Click"
End Sub

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

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


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

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

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

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

Private Sub contact_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:contact_HideGrid", "Index=" & Index, "AParentID=" & AParentID
    #End If
    
    MoveToFirstTab AParentID

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

Private Sub Customer_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Customer_HideGrid", "Index=" & Index, "AParentID=" & AParentID
    #End If
    
    MoveToFirstTab AParentID

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

Private Sub memo_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:memo_HideGrid", "Index=" & Index, "AParentID=" & AParentID
    #End If
    
    MoveToFirstTab AParentID
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:memo_HideGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:memo_HideGrid"
    CapMouseOn
End Sub

Private Sub mo_SPA_quit()
    Call ExitOfCapture
End Sub

Private Sub mSampleDoc_quit()
    Call ExitOfCapture
End Sub

Private Sub mSeminar_Quit()
    Call ExitOfCapture
End Sub

Private Sub CapOffer_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff

    MoveToFirstTab AParentID

Trace_End:
    CapMouseOn
    Exit Sub

Trace_Err:
    CapMouseOn
End Sub

Private Sub product_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:product_HideGrid", "Index=" & Index, "AParentID=" & AParentID
    #End If
    
    MoveToFirstTab AParentID
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:product_HideGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:product_HideGrid"
    CapMouseOn
End Sub

Private Sub project_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:project_HideGrid", "Index=" & Index, "AParentID=" & AParentID
    #End If
    
    MoveToFirstTab AParentID
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:project_HideGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:project_HideGrid"
    CapMouseOn
End Sub

Private Sub action_HideGrid(Index As Integer, AParentID As Integer)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:action_HideGrid", "Index=" & Index, "AParentID=" & AParentID
    #End If
    
    MoveToFirstTab AParentID
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:action_HideGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:action_HideGrid"
    CapMouseOn
End Sub

' This function initialize the navigation bar
Private Sub Init_NavBar()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Init_NavBar"
    #End If
    
    ' Position and size
    tbsNavBar.Left = 0
    tbsNavBar.Top = 0
    
    'If Me.Width > mt_CstValues.View_Full_Width Then
    '    tbsNavBar.Width = Me.Width - chk_isInitTab.Width - 200
    '    chk_isInitTab.Left = Me.Width - chk_isInitTab.Width - 100
    'Else
    '    tbsNavBar.Width = mt_CstValues.View_Full_Width - chk_isInitTab.Width - 100
    '    chk_isInitTab.Left = mt_CstValues.View_Full_Width - chk_isInitTab.Width
    'End If
    
    chk_isInitTab.Top = tbsNavBar.Height - chk_isInitTab.Height
    
    'tbsNavBar.TabFixedWidth = tbsNavBar.Width / 7 - 50
    
    Call ResizeNavBar
    
    ' Clear all tabs
    Call tbsNavBar.Tabs.Clear
    
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Project), "#Project")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Action), "#Action")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Customer), "#Customer")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Contact), "#Contact")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Product), "#Product")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_SPA), "#SPA")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Seminar), "#Seminar")
    Call tbsNavBar.Tabs.Add(tbsNavBar.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_SampleDoc), "#SampleDoc")
        'Call SetTabWidth(tbsNavBar)
    tbsNavBar.Tabs.Item(1).Tag = "tbs_Project"
    tbsNavBar.Tabs.Item(2).Tag = "tbs_Action"
    tbsNavBar.Tabs.Item(3).Tag = "tbs_Customer"
    tbsNavBar.Tabs.Item(4).Tag = "tbs_Contact"
    tbsNavBar.Tabs.Item(5).Tag = "tbs_Product"
    tbsNavBar.Tabs.Item(6).Tag = "tbs_SPA"
    tbsNavBar.Tabs.Item(7).Tag = "tbs_Seminar"
    tbsNavBar.Tabs.Item(8).Tag = "tbs_SampleDoc"

    LoadLabels mo_ArmDb, UserControl.Controls, "Capture", m_Language

    mi_SelNavTag = -1
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Init_NavBar"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Init_NavBar"
    CapMouseOn
End Sub


' Initialize all processing components
Private Sub Init_Cpts()
Dim li_IdxX As Integer, li_IdxY As Integer, li_CountX As Integer, li_CountY As Integer

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Init_Cpts"
    #End If
    
    'BEGIN T298.WP8
    tbsNavBar.Visible = True
    'END T298.WP8
    Dim ll_Idx  As Long
    For ll_Idx = 1 To tbsNavBar.Tabs.Count
        If tbsNavBar.Tabs.Item(ll_Idx).Tag = ms_initTab Then
            tbsNavBar.SelectedItem = tbsNavBar.Tabs(ll_Idx)
        Exit For
        End If
    Next ll_Idx
    'SetSizeAndPosition
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Init_Cpts"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Init_Cpts"
    CapMouseOn
End Sub
 
Private Sub action_Quit(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:action_Quit", "Index=" & Index
    #End If
    If Index = 2 Then Call ExitOfCapture
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:action_Quit"
    #End If
End Sub

Private Sub contact_Quit(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:contact_Quit", "Index=" & Index
    #End If
    If Index = 4 Then Call ExitOfCapture
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:contact_Quit"
    #End If
End Sub

Private Sub customer_Quit(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:customer_Quit", "Index=" & Index
    #End If
    If Index = 3 Then Call ExitOfCapture
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:customer_Quit"
    #End If
End Sub

Private Sub product_Quit(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:product_Quit", "Index=" & Index
    #End If
    If Index = 5 Then Call ExitOfCapture
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:product_Quit"
    #End If
End Sub

Private Sub project_Quit(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:project_Quit", "Index=" & Index
    #End If
    If Index = 1 Then Call ExitOfCapture
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:project_Quit"
    #End If
End Sub

Private Sub Project_SwitchToView(Index As Integer, ByVal li_View As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Project_SwitchToView", "Index=" & Index, "li_View=" & li_View
    #End If
    Call SwitchToView(project(Index), li_View)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Project_SwitchToView"
    #End If
End Sub

Private Sub Action_SwitchToView(Index As Integer, ByVal li_View As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Action_SwitchToView", "Index=" & Index, "li_View=" & li_View
    #End If
    Call SwitchToView(action(Index), li_View)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Action_SwitchToView"
    #End If
End Sub

Private Sub Customer_SwitchToView(Index As Integer, ByVal li_View As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Customer_SwitchToView", "Index=" & Index, "li_View=" & li_View
    #End If
    Call SwitchToView(Customer(Index), li_View)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Customer_SwitchToView"
    #End If
End Sub

Private Sub Contact_SwitchToView(Index As Integer, ByVal li_View As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Contact_SwitchToView", "Index=" & Index, "li_View=" & li_View
    #End If
    Call SwitchToView(contact(Index), li_View)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Contact_SwitchToView"
    #End If
End Sub

Private Sub Product_SwitchToView(Index As Integer, ByVal li_View As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Product_SwitchToView", "Index=" & Index, "li_View=" & li_View
    #End If
    Call SwitchToView(product(Index), li_View)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Product_SwitchToView"
    #End If
End Sub

Private Sub Memo_SwitchToView(Index As Integer, ByVal li_View As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Memo_SwitchToView", "Index=" & Index, "li_View=" & li_View
    #End If
    Call SwitchToView(memo(Index), li_View)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Memo_SwitchToView"
    #End If
End Sub

Private Sub CapOffer_SwitchToView(Index As Integer, ByVal li_View As Integer)
    
    Call SwitchToView(CapOffer(Index), li_View)
End Sub

' Change the size of a component
Private Sub SwitchToView(ByRef lo_Cpt As Object, ByVal li_View As Integer)
Dim lo_CptUp As Object          ' The component that embed
Dim lo_Root As Object           ' The root
Dim ls_EmbeddedIn As Integer    ' Tag of the component embedded
Dim ls_TabKey As String
   
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:SwitchToView", "lo_Cpt=" & TypeName(lo_Cpt), "li_View=" & li_View
    #End If
  
    ls_EmbeddedIn = lo_Cpt.EmbeddedIn
    
    If (ls_EmbeddedIn <> -1) Then
        Set lo_CptUp = GetCpt(mi_SelNavTag, ls_EmbeddedIn)
    End If
    
    Set lo_Root = GetRoot(mi_SelNavTag)
    
    
    If Not tbsNavBar.SelectedItem Is Nothing Then
        ls_TabKey = GetLstKey(tbsNavBar.SelectedItem.Key)
    Else
        ls_TabKey = ""
    End If
    
    ' Cycle detection
    If (ls_EmbeddedIn <> -1) And (CStr(lo_Cpt.CptTag) = ls_TabKey) And (li_View <> mt_CstValues.View_Embedded) Then
        Select Case lo_Cpt.CptTag
            Case mt_CstValues.Tag_Action, mt_CstValues.Tag_Contact, mt_CstValues.Tag_Product
                If lo_Cpt.DisplayMode = mt_CstValues.DisplayMode_View Then
                    Call ResetEmbed
                    GoTo Trace_End
                End If
            Case Else
                Call ResetEmbed
                GoTo Trace_End
        End Select
    End If
    
    
    ' Adjust the view when treeview is not valid
    If (ls_EmbeddedIn <> -1) And (ls_EmbeddedIn <> ls_TabKey) And (li_View <> mt_CstValues.View_Embedded) Then
        li_View = mt_CstValues.View_Full
    End If

   
    ' Adjust the size when treeview is not valid, resize the embedder
    If (ls_EmbeddedIn <> -1) And (ls_EmbeddedIn <> ls_TabKey) And (li_View = mt_CstValues.View_Embedded) Then
        li_View = mt_CstValues.View_Full_Embedded
        If isValid(lo_CptUp) Then
            Call SwitchToView(lo_CptUp, mt_CstValues.View_Full)
            Call lo_CptUp.Resize
            lo_CptUp.Visible = True
        End If
    End If
    
    ' Change the focus
    If (ls_EmbeddedIn <> -1) And (li_View <> mt_CstValues.View_Embedded) And (li_View <> mt_CstValues.View_Full_Embedded) And isValid(lo_CptUp) Then
        If lo_CptUp.Name <> lo_Root.Name And lo_Cpt.Name <> lo_Root.Name Then
            ' Be careful, special case
            Select Case lo_Cpt.CptTag
                Case mt_CstValues.Tag_Contact, mt_CstValues.Tag_Action, mt_CstValues.Tag_Product
                    If lo_Cpt.DisplayMode = mt_CstValues.DisplayMode_View Then
                        lo_Root.Root = False
                        lo_CptUp.Root = True
                   End If
                Case Else   ' GENERAL BEHAVIOR
            lo_Root.Root = False
            lo_CptUp.Root = True
            End Select
        End If
    End If

    
    If (ls_EmbeddedIn <> -1) And ((li_View = mt_CstValues.View_Embedded) Or (li_View = mt_CstValues.View_Full_Embedded)) And isValid(lo_CptUp) Then
        If (lo_CptUp.Name = lo_Root.Name) And (lo_Root.DisplayMode <> mt_CstValues.DisplayMode_View) Then
            lo_Root.DisplayMode = mt_CstValues.DisplayMode_View
            lo_Root.Visible = True
        End If
    End If
    
    ' Change the view for the root
    If lo_Cpt.Root Then
        Select Case li_View
            Case mt_CstValues.View_Medium
                li_View = mt_CstValues.View_Full
            Case mt_CstValues.View_Embedded
                li_View = mt_CstValues.View_Full_Embedded
        End Select
    End If
        
    Set lo_CptUp = Nothing
    Set lo_Root = Nothing
 
    ' Adjust the position and size of a component
    Call ResizeHelper(lo_Cpt, li_View)
        
    lo_Cpt.Zorder 0
    
    Set mo_LastSwitchToCpt = lo_Cpt
    mi_LastSwitchToView = li_View

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

Private Sub ResizeHelper(ByRef lo_Cpt As Object, ByVal li_View As Integer)

    ' Adjust the position and size of a component
    
    If isValid(lo_Cpt) Then
    
        Select Case li_View
        
            Case mt_CstValues.View_Full
                
                lo_Cpt.Left = mt_CstValues.View_Full_Left
                lo_Cpt.Top = mt_CstValues.View_Full_Top
            
                If Me.Width > mt_CstValues.View_Full_Width Then
                    lo_Cpt.Width = Me.Width
                Else
                    lo_Cpt.Width = mt_CstValues.View_Full_Width
                End If
                
                If Me.Height > mt_CstValues.View_Full_Height Then
                    lo_Cpt.Height = Me.Height - mt_CstValues.View_Full_Top
                Else
                    lo_Cpt.Height = mt_CstValues.View_Full_Height
                End If
                
                lo_Cpt.Resize
            
            Case mt_CstValues.View_Medium
            
                lo_Cpt.Left = mt_CstValues.View_Med_Left
                lo_Cpt.Top = mt_CstValues.View_Med_Top
            
                If Me.Width > mt_CstValues.View_Full_Width Then
                    lo_Cpt.Width = Me.Width - (mt_CstValues.View_Full_Width - mt_CstValues.View_Med_Width)
                Else
                    lo_Cpt.Width = mt_CstValues.View_Med_Width
                End If
                
                If Me.Height > mt_CstValues.View_Full_Height Then
                    lo_Cpt.Height = Me.Height - mt_CstValues.View_Full_Top
                Else
                    lo_Cpt.Height = mt_CstValues.View_Med_Height
                End If
                    
                lo_Cpt.Resize
                
            Case mt_CstValues.View_Embedded
                
                lo_Cpt.Left = mt_CstValues.View_Emb_Left
                lo_Cpt.Top = mt_CstValues.View_Emb_Top
            
                If Me.Width > mt_CstValues.View_Full_Width Then
                    lo_Cpt.Width = Me.Width - (mt_CstValues.View_Full_Width - mt_CstValues.View_Emb_Width)
                Else
                    lo_Cpt.Width = mt_CstValues.View_Emb_Width
                End If
                
                If Me.Height > mt_CstValues.View_Full_Height Then
                    lo_Cpt.Height = Me.Height - mt_CstValues.View_Emb_Top - mt_CstValues.View_ToolBar_Height
                Else
                    lo_Cpt.Height = mt_CstValues.View_Emb_Height
                End If
                
                lo_Cpt.Resize
                    
            Case mt_CstValues.View_Full_Embedded
                
                lo_Cpt.Left = mt_CstValues.View_Full_Left
                lo_Cpt.Top = mt_CstValues.View_Emb_Top
            
                If Me.Width > mt_CstValues.View_Full_Width Then
                    lo_Cpt.Width = Me.Width
                Else
                    lo_Cpt.Width = mt_CstValues.View_Full_Width
                End If
                
                If Me.Height > mt_CstValues.View_Full_Height Then
                    lo_Cpt.Height = Me.Height - mt_CstValues.View_Emb_Top - mt_CstValues.View_ToolBar_Height
                Else
                    lo_Cpt.Height = mt_CstValues.View_Emb_Height
                End If
                
                lo_Cpt.Resize
                
        End Select
    End If

  Exit Sub
ErrorHandler:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:ResizeHelper"

End Sub

Private Sub ResizeNavBar()

    If Me.Width > mt_CstValues.View_Full_Width Then
        tbsNavBar.Width = Me.Width - chk_isInitTab.Width - 200
        chk_isInitTab.Left = Me.Width - chk_isInitTab.Width - 100
        
        If Me.Width - mt_CstValues.View_Full_Width > 200 Then
            tbsNavBar.TabFixedWidth = tbsNavBar.Width / 8 - 50
        Else
            tbsNavBar.TabFixedWidth = tbsNavBar.Width / 7 - 50
        End If
    Else
        tbsNavBar.Width = mt_CstValues.View_Full_Width - chk_isInitTab.Width - 100
        chk_isInitTab.Left = mt_CstValues.View_Full_Width - chk_isInitTab.Width
        
        tbsNavBar.TabFixedWidth = tbsNavBar.Width / 7 - 50
    End If
    
  Exit Sub
ErrorHandler:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:ResizeNavBar"

End Sub

Private Sub tbsNavBar_Click()
Dim lo_Root As Object
Dim i As Integer
Dim ls_Key As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:tbsNavBar_Click"
    #End If
    
    tbsNavBar.Enabled = False
    
    ls_Key = ""
    If Not tbsNavBar.SelectedItem Is Nothing Then
        ls_Key = GetLstKey(tbsNavBar.SelectedItem.Key)
    End If
    
    
    If (mi_SelNavTag = ls_Key) Or (ls_Key = "") Then
        GoTo Trace_End
    End If
    
    Debug.Assert (Not tbsNavBar.SelectedItem Is Nothing)
    mb_InternalInit = True
    chk_isInitTab.Value = IIf(tbsNavBar.SelectedItem.Tag = ms_initTab, vbChecked, vbUnchecked)
    mb_InternalInit = False
    
    ' Hide all ancient components
    Dim ll_Count As Long, ll_Idx As Long
    If (mi_SelNavTag <> -1) And _
       (mi_SelNavTag <> mt_CstValues.Tag_Seminar) And _
       (mi_SelNavTag <> mt_CstValues.Tag_SampleDoc) And _
       (mi_SelNavTag <> mt_CstValues.Tag_SPA) Then
        ll_Count = UBound(mo_Cpts, 2)
        For ll_Idx = 0 To ll_Count
            If isValid(mo_Cpts(mi_SelNavTag, ll_Idx)) Then
                mo_Cpts(mi_SelNavTag, ll_Idx).Visible = False
            End If
        Next
    End If
    If Not mSeminar Is Nothing Then
        mSeminar.Visible = False
    End If
    If Not mSampleDoc Is Nothing Then
        mSampleDoc.Visible = False
    End If
    If Not mo_SPA Is Nothing Then
        mo_SPA.Visible = False
    End If
    For i = 1 To tbsNavBar.Tabs.Count
        tbsNavBar.Tabs.Item(i).HighLighted = False
    Next i
    tbsNavBar.SelectedItem.HighLighted = True
        
    mi_SelNavTag = ls_Key
    
    Select Case ls_Key
        Case mt_CstValues.Tag_Seminar
            If mSeminar Is Nothing Then
                If Not CreateSeminar Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 1123, "Unable to create the seminar component")
                    Err.Raise 1123, "Unable to create seminar component"
                End If
                
            End If
            mSeminar.Visible = True
        Case mt_CstValues.Tag_SampleDoc
            If mSampleDoc Is Nothing Then
                If Not CreateSampleDoc Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 2400, "Unable to create the sample component")
                    Err.Raise 2400, "Unable to create sample component"
                End If
                
            End If
            mSampleDoc.Visible = True
        Case mt_CstValues.Tag_SPA
            If mo_SPA Is Nothing Then
                ' TODOC
                If Not CreateSPA Then
                    If Not mo_SPA Is Nothing Then
                        If mo_SPA.Initialized Then
                            Call ASC_SendMessage(mo_ArmDb, m_Language, 8100, "You do not have rights to access this application. Contact the SPA System administrator")
                        End If
                    Else
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 8100, "You do not have rights to access this application. Contact the SPA System administrator")
                        Err.Raise 2400, "Unable to create SPA component"
                End If
                Else
                    mo_SPA.Visible = True
            End If
            Else
            mo_SPA.Visible = True
            End If
        Case Else
            If TypeName(mo_Cpts(mi_SelNavTag, 0)) = "Nothing" Then
                loadComponents mi_SelNavTag, mi_SelNavTag
            End If
            Set lo_Root = GetRoot(mi_SelNavTag)
            If isValid(lo_Root) Then
                If lo_Root.DisplayMode = mt_CstValues.DisplayMode_None Then
                    lo_Root.DisplayMode = mt_CstValues.DisplayMode_List
                End If
                Call ActiveCpt(lo_Root, lo_Root)
                UserControl_Resize
                Set lo_Root = Nothing
            End If
        End Select
Trace_End:
    tbsNavBar.Enabled = True
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:tbsNavBar_Click"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    tbsNavBar.Enabled = True
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:tbsNavBar_Click"
    CapMouseOn
End Sub

Private Sub InitializeComponent(lo_Object As Object, ab_root As Boolean)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:InitializeComponent", "lo_Object = " & TypeName(lo_Object), "ab_root = " & ab_root
    #End If
    
    lo_Object.FrameWorkInit mt_CstValues, lo_Object.Name

    lo_Object.ConnectString = ms_ConnectString
    If USE_FRAME_CONNECTION Then
        Set lo_Object.ArmDb = mo_ArmDb
    End If
    
    If TypeOf lo_Object Is CapSubProject Then
      Set lo_Object.Tools = mo_Tools
    End If
    If TypeOf lo_Object Is CapOffer Then
      Set lo_Object.Tools = mo_Tools
    End If
    If TypeOf lo_Object Is CapFile Then
      Set lo_Object.Tools = mo_Tools
    End If
        
    lo_Object.Language = m_Language
    lo_Object.Load_A_COM ab_root

    lo_Object.Visible = False

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

Private Sub loadComponents(ai_Level As Integer, ai_Component As Integer)
Dim li_level As Integer
Dim li_Component As Integer

    On Error Resume Next
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:loadComponents", "ai_Level=" & ai_Level
    #End If
    
    li_level = ai_Level + 1
'    li_Component = ai_Component + 1
    
    Select Case ai_Component
        Case mt_CstValues.Tag_Project
            If TypeName(project(li_level)) = "Nothing" Then GoTo Trace_End
            Load project(li_level)
            project(li_level).Visible = False
            InitializeComponent project(li_level), (li_level = 1)
        Case mt_CstValues.Tag_Action
            If TypeName(action(li_level)) = "Nothing" Then GoTo Trace_End
            Load action(li_level)
            action(li_level).Visible = False
            InitializeComponent action(li_level), (li_level = 2)
        Case mt_CstValues.Tag_Customer
            If TypeName(Customer(li_level)) = "Nothing" Then GoTo Trace_End
            Load Customer(li_level)
            Customer(li_level).Visible = False
            InitializeComponent Customer(li_level), (li_level = 3)
        Case mt_CstValues.Tag_Contact
            If TypeName(contact(li_level)) = "Nothing" Then GoTo Trace_End
            Load contact(li_level)
            contact(li_level).Visible = False
            InitializeComponent contact(li_level), (li_level = 4)
        Case mt_CstValues.Tag_Product
            If TypeName(product(li_level)) = "Nothing" Then GoTo Trace_End
            Load product(li_level)
            product(li_level).Visible = False
            InitializeComponent product(li_level), (li_level = 5)
        Case mt_CstValues.Tag_Memo
            If TypeName(memo(li_level)) = "Nothing" Then GoTo Trace_End
            Load memo(li_level)
            memo(li_level).Visible = False
            InitializeComponent memo(li_level), (li_level = 6)
        Case mt_CstValues.Tag_SubProject
            If TypeName(CapSubProject(li_level)) = "Nothing" Then GoTo Trace_End
            Load CapSubProject(li_level)
            CapSubProject(li_level).Visible = False
            CapSubProject(li_level).U_Code = prg.U_Code                 ' additional init
            InitializeComponent CapSubProject(li_level), False          ' cannot be root
        Case mt_CstValues.Tag_Offer
            If TypeName(CapOffer(li_level)) = "Nothing" Then GoTo Trace_End
            Load CapOffer(li_level)
            CapOffer(li_level).Visible = False
            CapOffer(li_level).U_Code = prg.U_Code                 ' additional init
            InitializeComponent CapOffer(li_level), False          ' cannot be root
        Case mt_CstValues.Tag_CapSOMQuote
            If TypeName(CapSOMQuote(li_level)) = "Nothing" Then GoTo Trace_End
            Load CapSOMQuote(li_level)
            CapSOMQuote(li_level).Visible = False
            CapSOMQuote(li_level).U_Code = prg.U_Code                 ' additional init
            InitializeComponent CapSOMQuote(li_level), False          ' cannot be root
        Case mt_CstValues.Tag_File
            If TypeName(CapFile(li_level)) = "Nothing" Then GoTo Trace_End
            Load CapFile(li_level)
            CapFile(li_level).Visible = False
            CapFile(li_level).U_Code = prg.U_Code                 ' additional init
            InitializeComponent CapFile(li_level), False          ' cannot be root
    End Select
    
    On Error GoTo Trace_Err
    
    Select Case ai_Level
        Case 0
            Select Case ai_Component
                Case mt_CstValues.Tag_Project
                    Set mo_Cpts(ai_Level, 0) = project(li_level)
                Case mt_CstValues.Tag_Action
                    Set mo_Cpts(ai_Level, 1) = action(li_level)
                Case mt_CstValues.Tag_Customer
                    Set mo_Cpts(ai_Level, 2) = Customer(li_level)
                Case mt_CstValues.Tag_Contact
                    Set mo_Cpts(ai_Level, 3) = contact(li_level)
                Case mt_CstValues.Tag_Product
                    Set mo_Cpts(ai_Level, 4) = product(li_level)
                Case mt_CstValues.Tag_Memo
                    Set mo_Cpts(ai_Level, 5) = memo(li_level)
                Case mt_CstValues.Tag_CapSOMQuote
                    Set mo_Cpts(ai_Level, 6) = CapSOMQuote(li_level)
                Case mt_CstValues.Tag_SubProject
                    Set mo_Cpts(ai_Level, 7) = CapSubProject(li_level)
                Case mt_CstValues.Tag_Offer
                    Set mo_Cpts(ai_Level, 8) = CapOffer(li_level)
                Case mt_CstValues.Tag_File
                    Set mo_Cpts(ai_Level, 9) = CapFile(li_level)
            End Select
        Case 1
            Select Case ai_Component
                Case mt_CstValues.Tag_Action
                    Set mo_Cpts(ai_Level, 0) = action(li_level)
                Case mt_CstValues.Tag_Project
                    Set mo_Cpts(ai_Level, 1) = project(li_level)
                Case mt_CstValues.Tag_Customer
                    Set mo_Cpts(ai_Level, 2) = Customer(li_level)
                Case mt_CstValues.Tag_Contact
                    Set mo_Cpts(ai_Level, 3) = contact(li_level)
                Case mt_CstValues.Tag_Product
                    Set mo_Cpts(ai_Level, 4) = product(li_level)
                Case mt_CstValues.Tag_Memo
                    Set mo_Cpts(ai_Level, 5) = memo(li_level)
                Case mt_CstValues.Tag_CapSOMQuote
                    Set mo_Cpts(ai_Level, 6) = CapSOMQuote(li_level)
                Case mt_CstValues.Tag_SubProject
                    Set mo_Cpts(ai_Level, 7) = CapSubProject(li_level)
                Case mt_CstValues.Tag_Offer
                    Set mo_Cpts(ai_Level, 8) = CapOffer(li_level)
                Case mt_CstValues.Tag_File
                    Set mo_Cpts(ai_Level, 9) = CapFile(li_level)
            End Select
        Case 2
            Select Case ai_Component
                Case mt_CstValues.Tag_Customer
                    Set mo_Cpts(ai_Level, 0) = Customer(li_level)
                Case mt_CstValues.Tag_Project
                    Set mo_Cpts(ai_Level, 1) = project(li_level)
                Case mt_CstValues.Tag_Action
                    Set mo_Cpts(ai_Level, 2) = action(li_level)
                Case mt_CstValues.Tag_Contact
                    Set mo_Cpts(ai_Level, 3) = contact(li_level)
                Case mt_CstValues.Tag_Product
                    Set mo_Cpts(ai_Level, 4) = product(li_level)
                Case mt_CstValues.Tag_Memo
                    Set mo_Cpts(ai_Level, 5) = memo(li_level)
                Case mt_CstValues.Tag_CapSOMQuote
                    Set mo_Cpts(ai_Level, 6) = CapSOMQuote(li_level)
                Case mt_CstValues.Tag_SubProject
                    Set mo_Cpts(ai_Level, 7) = CapSubProject(li_level)
                Case mt_CstValues.Tag_Offer
                    Set mo_Cpts(ai_Level, 8) = CapOffer(li_level)
                Case mt_CstValues.Tag_File
                    Set mo_Cpts(ai_Level, 9) = CapFile(li_level)
            End Select
        Case 3
            Select Case ai_Component
                Case mt_CstValues.Tag_Contact
                    Set mo_Cpts(ai_Level, 0) = contact(li_level)
                Case mt_CstValues.Tag_Project
                    Set mo_Cpts(ai_Level, 1) = project(li_level)
                Case mt_CstValues.Tag_Action
                    Set mo_Cpts(ai_Level, 2) = action(li_level)
                Case mt_CstValues.Tag_Customer
                    Set mo_Cpts(ai_Level, 3) = Customer(li_level)
                Case mt_CstValues.Tag_Product
                    Set mo_Cpts(ai_Level, 4) = product(li_level)
                Case mt_CstValues.Tag_Memo
                    Set mo_Cpts(ai_Level, 5) = memo(li_level)
                Case mt_CstValues.Tag_CapSOMQuote
                    Set mo_Cpts(ai_Level, 6) = CapSOMQuote(li_level)
                Case mt_CstValues.Tag_SubProject
                    Set mo_Cpts(ai_Level, 7) = CapSubProject(li_level)
                Case mt_CstValues.Tag_Offer
                    Set mo_Cpts(ai_Level, 8) = CapOffer(li_level)
                Case mt_CstValues.Tag_File
                    Set mo_Cpts(ai_Level, 9) = CapFile(li_level)
            End Select
        Case 4
            Select Case ai_Component
                Case mt_CstValues.Tag_Product
                    Set mo_Cpts(ai_Level, 0) = product(li_level)
                Case mt_CstValues.Tag_Project
                    Set mo_Cpts(ai_Level, 1) = project(li_level)
                Case mt_CstValues.Tag_Action
                    Set mo_Cpts(ai_Level, 2) = action(li_level)
                Case mt_CstValues.Tag_Customer
                    Set mo_Cpts(ai_Level, 3) = Customer(li_level)
                Case mt_CstValues.Tag_Contact
                    Set mo_Cpts(ai_Level, 4) = contact(li_level)
                Case mt_CstValues.Tag_Memo
                    Set mo_Cpts(ai_Level, 5) = memo(li_level)
                Case mt_CstValues.Tag_CapSOMQuote
                    Set mo_Cpts(ai_Level, 6) = CapSOMQuote(li_level)
                Case mt_CstValues.Tag_SubProject
                    Set mo_Cpts(ai_Level, 7) = CapSubProject(li_level)
                Case mt_CstValues.Tag_Offer
                    Set mo_Cpts(ai_Level, 8) = CapOffer(li_level)
                Case mt_CstValues.Tag_File
                    Set mo_Cpts(ai_Level, 9) = CapFile(li_level)
            End Select
    End Select


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

' Get the root of focus from a navigation sheet
Private Function GetRoot(ByVal li_Tag As Integer) As Object
Dim li_NavIdx As Integer, li_idx As Integer, li_Count As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:GetRoot", "li_Tag=" & li_Tag
    #End If
    
    li_NavIdx = GetNavIdx(li_Tag)
    If li_NavIdx = -1 Then  ' Tag doesn't exists, return nothing for error check
        Set GetRoot = Nothing
        GoTo Trace_End
    End If
        
    li_Count = UBound(mo_Cpts, 2) - 5 ' Memo, CapSubProject, CapOffer, SOM_Product, CapFile can't be root !
    For li_idx = 1 To li_Count
        If isValid(mo_Cpts(li_NavIdx, li_idx)) Then
            If mo_Cpts(li_NavIdx, li_idx).Root Then
                ' Root is found
                Set GetRoot = mo_Cpts(li_NavIdx, li_idx)
                GoTo Trace_End
            End If
        End If
    Next
    ' Default root
    Set GetRoot = mo_Cpts(li_NavIdx, 0)
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:GetRoot"
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:GetRoot"
    CapMouseOn
End Function

Private Function GetNavIdx(ByVal li_Tag As Integer) As Integer
Dim li_Counter, li_idx As Integer

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:GetNavIdx", "li_Tag=" & li_Tag
    #End If
    
    li_idx = -1
    For li_Counter = 0 To UBound(mo_Cpts, 1)
        If isValid(mo_Cpts(li_Counter, 0)) Then
            If mo_Cpts(li_Counter, 0).CptTag = li_Tag Then
                li_idx = li_Counter
                Exit For
            End If
        End If
    Next
    GetNavIdx = li_idx
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:GetNavIdx", "Result=" & GetNavIdx
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:GetNavIdx"
    CapMouseOn
End Function


Private Function GetCpt(ByVal li_NavTag As Integer, ByVal li_Tag As Integer) As Object
Dim li_NavIdx As Integer, li_idx As Integer, li_Count As Integer

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:GetCpt", "li_NavTag=" & li_NavTag, "li_Tag=" & li_Tag
    #End If
    
    li_NavIdx = GetNavIdx(li_NavTag)
    If li_NavIdx <> -1 Then
        li_Count = UBound(mo_Cpts, 2)
        For li_idx = 0 To li_Count
            If isValid(mo_Cpts(li_NavIdx, li_idx)) Then
                If mo_Cpts(li_NavIdx, li_idx).CptTag = li_Tag Then
                    Set GetCpt = mo_Cpts(li_NavIdx, li_idx)
                    GoTo Trace_End
                End If
            End If
        Next
    End If
    
    Set GetCpt = Nothing

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


' Activate a cpt and all cpt embed by it
Private Sub ActiveCpt(ByRef lo_Object As Object, ByRef lo_Root As Object)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:ActiveCpt"
    #End If
    
    Dim l_Emb As Object
    
    If isValid(lo_Object) Then
        lo_Object.Zorder 0 ' Bring to fron
        lo_Object.Visible = True
        
        Select Case lo_Object.DisplayMode
            Case mt_CstValues.DisplayMode_View
              ' The component has embed another one, we must active it also
                If lo_Object.EmbedTag <> -1 Then

                    Set l_Emb = GetCpt(mi_SelNavTag, lo_Object.EmbedTag)
                    If l_Emb.Name <> lo_Root.Name Then
                        Call ActiveCpt(l_Emb, lo_Root)
                    Else
                        l_Emb.Zorder 0
                    End If
                    Set l_Emb = Nothing
                End If
            Case Else
                If (lo_Object.EmbeddedIn <> -1) And (lo_Object Is lo_Root) Then
                    Set l_Emb = GetCpt(mi_SelNavTag, lo_Object.EmbedTag)
                    If l_Emb.Name <> lo_Root.Name Then
                        Call ActiveCpt(l_Emb, lo_Root)
                    Else
                        l_Emb.Zorder 0
                    End If
                    Set l_Emb = Nothing
                End If

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

Private Sub Project_Catch(Index As Integer, ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Project_Catch", "Index=" & Index, "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
    Call Catch(project(Index), li_TagEmbedded, ls_Param)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Project_Catch", "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
End Sub
Private Sub Action_Catch(Index As Integer, ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Action_Catch", "Index=" & Index, "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
    Call Catch(action(Index), li_TagEmbedded, ls_Param)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Action_Catch", "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
End Sub
Private Sub Customer_Catch(Index As Integer, ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Customer_Catch", "Index=" & Index, "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
    Call Catch(Customer(Index), li_TagEmbedded, ls_Param)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Customer_Catch", "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
End Sub
Private Sub Contact_Catch(Index As Integer, ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Contact_Catch", "Index=" & Index, "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
    Call Catch(contact(Index), li_TagEmbedded, ls_Param)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Contact_Catch", "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
End Sub
Private Sub Product_Catch(Index As Integer, ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Product_Catch", "Index=" & Index, "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
    Call Catch(product(Index), li_TagEmbedded, ls_Param)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Product_Catch", "li_TagEmbedded=" & li_TagEmbedded, "ls_Param=" & ls_Param
    #End If
End Sub

Private Sub Catch(ByVal li_MainCpt As Object, ByVal li_EmbTag As Integer, ByVal ls_Param As String)
Dim l_Emb As Object
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Catch", "li_MainCpt=" & TypeName(li_MainCpt), "li_EmbTag=" & li_EmbTag, "ls_Param=" & ls_Param
    #End If
    
    Set l_Emb = GetCpt(mi_SelNavTag, li_EmbTag)
    
    If TypeName(l_Emb) = "Nothing" Then
        loadComponents mi_SelNavTag, li_EmbTag
    End If
    
    Set l_Emb = GetCpt(mi_SelNavTag, li_EmbTag)
    
    If isValid(l_Emb) Then
        l_Emb.Visible = False
        ' When a component is catched, it is set to display mode
        Select Case li_MainCpt.CptTag
            Case mt_CstValues.Tag_Project
                l_Emb.project = ls_Param
            Case mt_CstValues.Tag_Action
                l_Emb.action = ls_Param
            Case mt_CstValues.Tag_Customer
                l_Emb.Customer = ls_Param
            Case mt_CstValues.Tag_Contact
                l_Emb.contact = ls_Param
            Case mt_CstValues.Tag_Product
                l_Emb.product = ls_Param
        End Select
        l_Emb.Visible = True
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Catch"
    #End If
    CapMouseOn
    Exit Sub

Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Catch"
    CapMouseOn
End Sub

' Important : Memo can't release because can't catch !
Private Sub Project_Release(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Project_Release", "Index=" & Index
    #End If
    Call Release(project(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Project_Release"
    #End If
End Sub
Private Sub Action_Release(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Action_Release", "Index=" & Index
    #End If
    Call Release(action(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Action_Release"
    #End If
End Sub
Private Sub Customer_Release(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Customer_Release", "Index=" & Index
    #End If
    Call Release(Customer(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Customer_Release"
    #End If
End Sub
Private Sub Contact_Release(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Contact_Release", "Index=" & Index
    #End If
    Call Release(contact(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Contact_Release"
    #End If
End Sub
Private Sub Product_Release(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Product_Release", "Index=" & Index
    #End If
    Call Release(product(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Product_Release"
    #End If
End Sub

Private Sub Release(ByRef lo_Cpt As Object)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Release", "lo_Cpt=" & TypeName(lo_Cpt)
    #End If
    
    Dim l_Emb As Object
    Set l_Emb = GetCpt(mi_SelNavTag, lo_Cpt.EmbedTag)
    Dim lo_Root As Object
    Set lo_Root = GetRoot(mi_SelNavTag)
    
    If isValid(l_Emb) Then
        l_Emb.Visible = False
        l_Emb.Zorder 1
        l_Emb.UnCatch
        'If l_Emb.CptTag = mi_SelNavTag Then
        If l_Emb Is lo_Root Then
            
            l_Emb.DisplayMode = mt_CstValues.DisplayMode_View
            l_Emb.Zorder 0
            l_Emb.Visible = True
        Else
            l_Emb.Visible = True
        End If
        
        
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Release"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Release"
    CapMouseOn
End Sub

Private Sub ResetEmbed()
Dim li_NavIdx As Integer, li_idx As Integer, li_Count As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:ResetEmbed"
    #End If
    
    li_NavIdx = GetNavIdx(mi_SelNavTag)
    
    If li_NavIdx <> -1 Then
        li_Count = UBound(mo_Cpts, 2)
        For li_idx = 1 To li_Count
            If isValid(mo_Cpts(li_NavIdx, li_idx)) Then
                mo_Cpts(li_NavIdx, li_idx).Visible = False
                Call mo_Cpts(li_NavIdx, li_idx).UnCatch
                If li_idx < (li_Count - 1) Then
                    mo_Cpts(li_NavIdx, li_idx).Root = False '!!!
                End If
            End If
        Next
    End If
    
    Call mo_Cpts(li_NavIdx, 0).UnCatch

    mo_Cpts(li_NavIdx, 0).TypeList = -1
    
    Select Case mi_SelNavTag
        Case mt_CstValues.Tag_Project
           mo_Cpts(li_NavIdx, 0).project = mo_Cpts(li_NavIdx, 0).GetItemSelectedKey()
        Case mt_CstValues.Tag_Action
            mo_Cpts(li_NavIdx, 0).action = mo_Cpts(li_NavIdx, 0).GetItemSelectedKey()
        Case mt_CstValues.Tag_Customer
            mo_Cpts(li_NavIdx, 0).Customer = mo_Cpts(li_NavIdx, 0).GetItemSelectedKey()
        Case mt_CstValues.Tag_Contact
            mo_Cpts(li_NavIdx, 0).contact = mo_Cpts(li_NavIdx, 0).GetItemSelectedKey()
        Case mt_CstValues.Tag_Product
            mo_Cpts(li_NavIdx, 0).product = mo_Cpts(li_NavIdx, 0).GetItemSelectedKey()
    End Select
    mo_Cpts(li_NavIdx, 0).mb_CycleReset = True
    mo_Cpts(li_NavIdx, 0).Visible = True
    'mo_Cpts(li_NavIdx, 0).DisplayMode = mt_CstValues.DisplayMode_List

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

Private Function LoadToolbars() As Boolean
On Error GoTo ErrHandler
    
    Const CL_REQUEST_TB As String = "SELECT Toolbar_Info FROM Toolbars_Users WHERE User_Code=$user_id$ AND App_Id=$App_Id$"
    Dim lc_Toolbar As Long
    Dim ls_ToolbarRequest As String

    ls_ToolbarRequest = Replace(CL_REQUEST_TB, "$user_id$", 0)
    ls_ToolbarRequest = Replace(ls_ToolbarRequest, "$App_Id$", 1)
    lc_Toolbar = mo_ArmDb.OpenSQL(ls_ToolbarRequest)
    
    If (lc_Toolbar = 0) Then
        LoadToolbars = False
        Exit Function
    End If
    
    ' init toolbar
    Call tlb_Outstanding.SetToolbarInfoStringParameters(mo_ArmDb.GetFields(lc_Toolbar, "Toolbar_info"), "071")
    Call tlb_Outstanding.DisplayFace(0)
    
    Call mo_ArmDb.Close(lc_Toolbar)
    LoadToolbars = True
    Exit Function
ErrHandler:
    Call mo_ArmDb.Close(lc_Toolbar)
    LoadToolbars = False
End Function

Public Function Load_A_COM()
Dim lb_Created As Boolean

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Load_A_Com"
    #End If
    
    MousePointer = vbHourglass
    ScaleMode = 1
    'Me.Refresh
    
    ms_ConnectString = ms_Connect_Server & CH_LDELIMIT & ms_Connect_Database & CH_LDELIMIT & ms_Connect_Login & CH_LDELIMIT & ms_Connect_Password & CH_LDELIMIT & ms_Connect_Application

    FirstDisplayDone = False
    mb_InternalInit = False
    
    'Initialize the size of the application
    'Width = mt_CstValues.Appli_Width
    'Height = mt_CstValues.Appli_Height
    
    'Verify if the connection exists.
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then
        Load_A_COM = False
        GoTo Trace_End
    End If
    
    
    If Not go_Trace Is Nothing Then
        go_Trace.ConnectString = ms_ConnectString
        Set go_Trace.ArmDb = mo_ArmDb
    End If
    
    'Initialize user informations
    Call Init_UserInfo(mo_ArmDb, ms_Connect_Login)
    #If CapDebug Then
        'We use the language of the login screen
        m_Language = gs_CaptureLanguage
    #Else
        m_Language = gs_CaptureLanguage
    #End If
    
    
    Dim lo_FSO As Object
    Set lo_FSO = CreateObject("Scripting.FileSystemObject")
   
    If Not lo_FSO.FolderExists(prg.AppCache_Dir & "\") Then
     lo_FSO.CreateFolder (prg.AppCache_Dir & "\")
    End If
   
    If Not lo_FSO.FolderExists(prg.AppCache_Dir & "\Capture\") Then
        lo_FSO.CreateFolder (prg.AppCache_Dir & "\Capture\")
    End If
   
    Dim l_NeededFiles(3) As String
    l_NeededFiles(0) = App.Path & "\" & "ArmPrjInfo.xls"
    l_NeededFiles(1) = App.Path & "\" & "ArmPrjListe.xls"
    l_NeededFiles(2) = App.Path & "\" & "BPOWebsite.css"
    l_NeededFiles(3) = App.Path & "\" & "Capture.xml"
   
    Dim l_Idx As Long, l_Count As Long, l_MissingFiles As String
    
    l_Count = UBound(l_NeededFiles)
    l_MissingFiles = ""
    For l_Idx = 0 To l_Count
        If Not lo_FSO.FileExists(l_NeededFiles(l_Idx)) Then
            l_MissingFiles = l_MissingFiles & IIf(l_MissingFiles <> "", ", ", "") & l_NeededFiles(l_Idx)
        End If
    Next
    Set lo_FSO = Nothing
    
    If l_MissingFiles <> "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 961, "#At least one file needed by capture is missing, please contact IT support", l_MissingFiles)
        Load_A_COM = False
        GoTo Trace_End
    End If

    'BEGIN T298.WP8
    Set tlb_Outstanding.ArmDb = mo_ArmDb
    tlb_Outstanding.Language = m_Language
    tlb_Outstanding.Load_A_COM
    
    If Not LoadToolbars Then
        Load_A_COM = False
        GoTo Trace_End
    End If
    
    Set grd_Projects.ArmDb = mo_ArmDb
    grd_Projects.Load_A_COM
    Set grd_Actions.ArmDb = mo_ArmDb
    grd_Actions.Load_A_COM

    'Initialize the navigation bar
    Call Init_NavBar
    tbsNavBar.Visible = False

    mt_CstValues.ProjectFollowUpIncrement = Val(GetDefaultConfigCode("Project_Cfg", "FollowUpDateIncrement"))
    mt_CstValues.ActionFollowUpIncrement = Val(GetDefaultConfigCode("Action_Cfg", "FollowUpDateIncrement"))
    
    ms_initTab = GetDefaultConfigDesc("Capture_Cfg", "InitTabOnline")
    If ms_initTab = "" Then
        ms_initTab = "tbs_Customer"                  ' tbs_Customer is default tab for online
    End If

    Call InitOutstanding
    'Initialize the components
    'Call Init_Cpts
    'END T298.WP8
    
    
    
    MousePointer = vbDefault
    
    If Not FirstDisplayDone Then
        FirstDisplayDone = True
        TestVersion mo_ArmDb
    End If
       
    mb_Initialized = True
    Load_A_COM = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Load_A_Com"
    #End If
    CapMouseOn
    Set lo_FSO = Nothing
    Exit Function
    
Trace_Err:
    Set lo_FSO = Nothing
    Load_A_COM = False
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Load_A_Com"
    CapMouseOn
End Function

Public Sub Unload_A_COM()
Dim li_IdxX As Integer, li_IdxY As Integer, li_CountX As Integer, li_CountY As Integer

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

    li_CountX = UBound(mo_Cpts, 2)
    li_CountY = UBound(mo_Cpts, 1)
    
    ' We release all components references
    For li_IdxY = 0 To li_CountY
        For li_IdxX = 0 To li_CountX
            If isValid(mo_Cpts(li_IdxY, li_IdxX)) Then
                mo_Cpts(li_IdxY, li_IdxX).Unload_A_COM
            End If
            Set mo_Cpts(li_IdxY, li_IdxX) = Nothing
        Next
    Next
    
    If Not mSeminar Is Nothing Then
        mSeminar.Unload_A_COM
    End If
    
    If Not mSampleDoc Is Nothing Then
        mSampleDoc.Unload_A_COM
    End If

    If Not mo_SPA Is Nothing Then
        mo_SPA.Unload_A_COM
    End If

    'BEGIN T298.WP8
    tlb_Outstanding.Unload_A_COM
    grd_Projects.Unload_A_COM
    grd_Actions.Unload_A_COM
    'END T298.WP8
    
    'Utilitaires
    ASC_DisconnectFromDB mo_ArmDb, ms_Connect_Login, mb_Created
    
    
   mb_Initialized = False
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Unload_A_Com"
    #End If
    CapMouseOn
    If Not go_Trace Is Nothing Then go_Trace.Unload_A_COM
    Set go_Trace = Nothing
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Unload_A_Com"
    CapMouseOn
    If Not go_Trace Is Nothing Then go_Trace.Unload_A_COM
    Set go_Trace = Nothing
End Sub

Public Sub Initialize_Trace()
    Set go_Trace = New Trace
    go_Trace.Load_A_COM
End Sub


Private Sub Project_Updated(Index As Integer)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Project_Updated", "Index=" & Index
    #End If
    Call Updated(project(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Project_Updated"
    #End If
    
End Sub
Private Sub Memo_Updated(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Memo_Updated", "Index=" & Index
    #End If
    Call Updated(memo(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Memo_Updated"
    #End If
End Sub
Private Sub Action_Updated(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Action_Updated", "Index=" & Index
    #End If
    Call Updated(action(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Action_Updated"
    #End If
End Sub
Private Sub Customer_Updated(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Customer_Updated", "Index=" & Index
    #End If
    Call Updated(Customer(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Customer_Updated"
    #End If
End Sub
Private Sub Contact_Updated(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Contact_Updated", "Index=" & Index
    #End If
    Call Updated(contact(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Contact_Updated"
    #End If
End Sub
Private Sub Product_Updated(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Product_Updated", "Index=" & Index
    #End If
    Call Updated(product(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Product_Updated"
    #End If
End Sub

Private Sub CapOffer_Updated(Index As Integer)

    Call Updated(CapOffer(Index))
End Sub

Private Sub CapOffer_IsOfferLocked(Index As Integer, ab_IsLocked As Boolean)

    If IsComponentOpenInEdit(TypeName(CapOffer(Index))) Then
      ab_IsLocked = True
    Else
      RaiseEvent IsOfferLocked(ab_IsLocked)
    End If
End Sub

Public Function IsComponentOpenInEdit(ByVal as_TypeName As String) As Boolean

    Dim li_IdxX As Integer, li_IdxY As Integer, li_CountX As Integer, li_CountY As Integer
    
    li_CountX = UBound(mo_Cpts, 2)
    li_CountY = UBound(mo_Cpts, 1)
    
    IsComponentOpenInEdit = False
    ' We release all components references
    For li_IdxY = 0 To li_CountY
        For li_IdxX = 0 To li_CountX
              If StrComp(TypeName(mo_Cpts(li_IdxY, li_IdxX)), as_TypeName, vbTextCompare) = 0 Then
                Select Case mo_Cpts(li_IdxY, li_IdxX).DisplayMode
                    Case mt_CstValues.DisplayMode_Add, mt_CstValues.DisplayMode_Update, mt_CstValues.DisplayMode_Delete
                      IsComponentOpenInEdit = True
                      Exit Function
                End Select
            End If
        Next
    Next
End Function

Private Sub Updated(ByRef lo_Cpt As Object)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Updated"
    #End If
    
    Dim lo_CptUp As Object          ' The component that embed
    Dim ls_EmbeddedIn As Integer    ' Tag of the component embedded
    
    ls_EmbeddedIn = lo_Cpt.EmbeddedIn
    
    If (ls_EmbeddedIn <> -1) Then
        Set lo_CptUp = GetCpt(mi_SelNavTag, ls_EmbeddedIn)
        lo_CptUp.Embedded_Updated True
        
        Select Case lo_Cpt.CptTag
           Case mt_CstValues.Tag_Contact
                If Not mo_Cpts(3, 0) Is Nothing Then mo_Cpts(3, 0).Embedded_Updated False ' MainContact
            Case mt_CstValues.Tag_Action
                If Not mo_Cpts(1, 0) Is Nothing Then mo_Cpts(1, 0).Embedded_Updated False 'MainAction
            Case mt_CstValues.Tag_Product
                If Not mo_Cpts(4, 0) Is Nothing Then mo_Cpts(4, 0).Embedded_Updated False 'MainContact remplacé par MainProduct
        End Select
        
    End If

    Set lo_CptUp = Nothing
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Updated"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Updated"
    CapMouseOn
    
End Sub


' Important : Memo can't UnlockNavigation because can't catch !
Private Sub Project_UnlockNavigation(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Project_UnlockNavigation", "Index=" & Index
    #End If
    Call UnlockNavigation(project(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Project_UnlockNavigation"
    #End If
End Sub
Private Sub Action_UnlockNavigation(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Project_UnlockNavigation", "Index=" & Index
    #End If
    Call UnlockNavigation(action(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Project_UnlockNavigation"
    #End If
End Sub
Private Sub Customer_UnlockNavigation(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Customer_UnlockNavigation", "Index=" & Index
    #End If
    Call UnlockNavigation(Customer(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Customer_UnlockNavigation"
    #End If
End Sub
Private Sub Contact_UnlockNavigation(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Contact_UnlockNavigation", "Index=" & Index
    #End If
    Call UnlockNavigation(contact(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Contact_UnlockNavigation"
    #End If
End Sub
Private Sub Product_UnlockNavigation(Index As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Product_UnlockNavigation", "Index=" & Index
    #End If
    Call UnlockNavigation(product(Index))
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:Product_UnlockNavigation"
    #End If
End Sub

Private Sub UnlockNavigation(ByRef lo_Cpt As Object)

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


    Dim lo_Root As Object
    Set lo_Root = GetRoot(mi_SelNavTag)
    lo_Root.Root = False
    
    Call ResetEmbed
    
    Set lo_Root = GetRoot(mi_SelNavTag)
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:UnlockNavigation"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:UnlockNavigation"
    CapMouseOn

    
End Sub



Private Sub ExitOfCapture()


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

    Dim lb_ReallyExit As Boolean, lb_AlreadyAsked As Boolean
    
    
    ' Check if a component is in add or update mode
    Dim li_IdxX As Integer, li_IdxY As Integer, li_CountX As Integer, li_CountY As Integer
    
    li_CountX = UBound(mo_Cpts, 2)
    li_CountY = UBound(mo_Cpts, 1)
    
    ' We release all components references
    For li_IdxY = 0 To li_CountY
        For li_IdxX = 0 To li_CountX
            If Not mo_Cpts(li_IdxY, li_IdxX) Is Nothing Then
                Select Case mo_Cpts(li_IdxY, li_IdxX).DisplayMode
                    Case mt_CstValues.DisplayMode_Add
                        If ASC_SendMessage(mo_ArmDb, m_Language, 200, "#Warning, you are currently add at least one item, do you want to exit of capture ?", , vbYesNo) <> vbYes Then
                            GoTo Trace_End
                        Else
                            Exit For
                        End If
                        
                    Case mt_CstValues.DisplayMode_Update
                        If ASC_SendMessage(mo_ArmDb, m_Language, 201, "#Warning, you are currently update at least one item, do you want to exit of capture ?", , vbYesNo) <> vbYes Then
                            GoTo Trace_End
                        Else
                            Exit For
                        End If
                End Select
            End If
        Next
    Next
    
    RaiseEvent Unload
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "A_Capture:ExitOfCapture"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:ExitOfCapture"
    CapMouseOn

End Sub


Private Function CreateSeminar() As Boolean

    Set mSeminar = UserControl.Controls.Add("Project1.CapSeminar", "Seminar")
    Call mSeminar.Move(mt_CstValues.View_Full_Left, mt_CstValues.View_Full_Top, mt_CstValues.View_Full_Width, mt_CstValues.View_Full_Height)
    
    mSeminar.Language_Code = m_Language
    Set mSeminar.Cst = mt_CstValues
    Set mSeminar.Db = mo_ArmDb
    mSeminar.Login = ms_Connect_Login
    mSeminar.ConnectionString = ms_ConnectString
    
    
    CreateSeminar = mSeminar.Load_A_COM
        
End Function

Private Function CreateSampleDoc() As Boolean

    Set mSampleDoc = Controls.Add("Project1.CapSample", "SampleDoc")
    Call mSampleDoc.Move(mt_CstValues.View_Full_Left, mt_CstValues.View_Full_Top, mt_CstValues.View_Full_Width, mt_CstValues.View_Full_Height)

    mSampleDoc.Language_Code = m_Language
    Set mSampleDoc.Db = mo_ArmDb
    ' 200 ... msedlak  ... admin
    ' 201 ... jnagy ... translator
    mSampleDoc.Ucode = mUCode
    mSampleDoc.Login = ms_Connect_Login


    CreateSampleDoc = mSampleDoc.Load_A_COM

End Function


Private Function CreateSPA() As Boolean

    Set mo_SPA = Controls.Add("Project1.SPA_Navig", "SPA")
    mo_SPA.Visible = False
    Call mo_SPA.Move(mt_CstValues.View_Full_Left, mt_CstValues.View_Full_Top, mt_CstValues.View_Full_Width, mt_CstValues.View_Full_Height)

    mo_SPA.Language_Code = m_Language
    Set mo_SPA.Db = mo_ArmDb
    ' 200 mo_SPA msedlak  ... admin
    ' 201 ... jnagy ... translator
    mo_SPA.U_Code = mUCode
    mo_SPA.LoginName = ms_Connect_Login
    

    CreateSPA = mo_SPA.Load_A_COM

End Function


Public Property Set ArmDb(ByRef local_connection As Object)
    If Not (local_connection Is Nothing) Then
    If mo_ArmDb Is Nothing Then
        Set mo_ArmDb = local_connection
        End If
    End If
End Property

' BEGIN T298.WP8

Private Sub ProjectDataGrid_Mapping()
Dim la_Columns(9) As String
    
On Error GoTo Trace_Err
    
    grd_Projects.ResetGrid
    grd_Projects.Title = ""
    grd_Projects.MultiSelect = False
    grd_Projects.AllowSort = False
    
    la_Columns(0) = "sp_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "sp_capkey" & CH_LDELIMIT & "sp_capkey"
    la_Columns(1) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(2) = "sp_desc" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_desc" & CH_LDELIMIT & "sp_desc"
    la_Columns(3) = "sp_zip" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_zip" & CH_LDELIMIT & "sp_zip date"
    la_Columns(4) = "sp_town" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_town" & CH_LDELIMIT & "sp_town"
    la_Columns(5) = "sp_size" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sp_size" & CH_LDELIMIT & "sp_size"
    la_Columns(6) = "ss_desc" & CH_LDELIMIT & "1300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ss_desc" & CH_LDELIMIT & "ss_desc"
    la_Columns(7) = "cust_rep" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "cust_rep" & CH_LDELIMIT & "cust_rep"
    la_Columns(8) = "spec_rep" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "spec_rep" & CH_LDELIMIT & "spec_rep"
    la_Columns(9) = "SP_dateFollowUp" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_dateFollowUp" & CH_LDELIMIT & "SP_dateFollowUp"
    
    grd_Projects.SetColumns la_Columns
    grd_Projects.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_project_longlist', 'grid', '" & m_Language & "'", ctColumns
    Call grd_Projects.Load("exec CapTvA_Project_gridk1 '" & Format(Date + mt_CstValues.ProjectFollowUpIncrement, "yyyy-mm-dd") & "','" & ms_Connect_Login & "','" & m_Language & "'", False)
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:ProjectDataGrid_Mapping"
End Sub

' Defines the grid columns for general grid
Private Sub ActionDataGrid_Mapping()
Dim la_Columns(9) As String
    
On Error GoTo Trace_Err
    
    grd_Actions.ResetGrid
    grd_Actions.Title = ""
    grd_Actions.MultiSelect = False
    grd_Actions.AllowSort = False
    
    la_Columns(0) = "AC_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "AC_Code" & CH_LDELIMIT & "AC_Code"
    la_Columns(1) = "ccu_capkey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "2" & CH_LDELIMIT & "ccu_capkey" & CH_LDELIMIT & "ccu_capkey"
    la_Columns(2) = "language_code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "3" & CH_LDELIMIT & "language_code" & CH_LDELIMIT & "language_code"
    la_Columns(3) = "duedate" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "duedate" & CH_LDELIMIT & "due date"
    la_Columns(4) = "at_desc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "at_desc" & CH_LDELIMIT & "at desc"
    la_Columns(5) = "as_desc" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "as_desc" & CH_LDELIMIT & "as desc"
    la_Columns(6) = "raised_for" & CH_LDELIMIT & "1300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "act_raisedfor" & CH_LDELIMIT & "raised for"
    la_Columns(7) = "contact_name" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "cnt_name" & CH_LDELIMIT & "contact name"
    la_Columns(8) = "ccu_desc" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "ccu_desc" & CH_LDELIMIT & "ccu desc"
    la_Columns(9) = "sa_flag" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "sa_flag" & CH_LDELIMIT & "sa_flag"
    
    grd_Actions.SetColumns la_Columns
    grd_Actions.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_action_longlist', 'grid', '" & m_Language & "'", ctColumns
    Call grd_Actions.Load("exec Cap_TVA_Action_gridh1 '" & Format(Date + mt_CstValues.ActionFollowUpIncrement + 1, "yyyy-mm-dd") & "','" & ms_Connect_Login & "','" & m_Language & "'", False)
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:ActionDataGrid_Mapping"
End Sub


Public Sub InitOutstanding()
Dim ls_Msg As String
Dim ll_ActToFollow As Long, ll_PrjToFollow As Long
Dim ll_ActExpired As Long, ll_PrjExpired As Long
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    ' Apply filters followup filters
    ll_PrjToFollow = 0
    ll_PrjExpired = 0
    ll_ActToFollow = 0
    ll_ActExpired = 0
    'resize grid control before load to correctly initialize number of fetch rows
    Call ResizeOutstanding
    Call ProjectDataGrid_Mapping
    Call ActionDataGrid_Mapping
    If (grd_Projects.Rows > 0) Or (grd_Actions.Rows > 0) Then
        ll_Cursor = mo_ArmDb.OpenSQL("CapTVA_Project_gridk1_count '" & Format(Date, "yyyy-mm-dd") & "','" & Format((Date + mt_CstValues.ProjectFollowUpIncrement), "yyyy-mm-dd") & "','" & ms_Connect_Login & "'")
        If Not mo_ArmDb.EOF(ll_Cursor) Then
            ll_PrjExpired = mo_ArmDb.GetFields(ll_Cursor, "expired")
            ll_PrjToFollow = mo_ArmDb.GetFields(ll_Cursor, "toFollow")
        End If
        Call mo_ArmDb.Close(ll_Cursor)

        ls_Msg = lbl_ProjectInfo.Caption
        ls_Msg = Replace(ls_Msg, "$expired$", CStr(ll_PrjExpired), , , vbTextCompare)
        ls_Msg = Replace(ls_Msg, "$follow$", CStr(ll_PrjToFollow), , , vbTextCompare)
        ls_Msg = Replace(ls_Msg, "$days$", CStr(mt_CstValues.ProjectFollowUpIncrement), , , vbTextCompare)
        lbl_ProjectInfo.Caption = ls_Msg

        ll_Cursor = mo_ArmDb.OpenSQL("exec Cap_TVA_Action_OustandingCounts '" & Format(Date, "yyyy-mm-dd") & "','" & Format((Date + mt_CstValues.ActionFollowUpIncrement + 1), "yyyy-mm-dd") & "'," & "'" & ms_Connect_Login & "','" & m_Language & "'")
        If Not mo_ArmDb.EOF(ll_Cursor) Then
          ll_ActExpired = mo_ArmDb.GetFields(ll_Cursor, "Passed")
          ll_ActToFollow = mo_ArmDb.GetFields(ll_Cursor, "follow")
            End If
        Call mo_ArmDb.Close(ll_Cursor)
        
        ls_Msg = lbl_ActionInfo.Caption
        ls_Msg = Replace(ls_Msg, "$expired$", CStr(ll_ActExpired), , , vbTextCompare)
        ls_Msg = Replace(ls_Msg, "$follow$", CStr(ll_ActToFollow), , , vbTextCompare)
        ls_Msg = Replace(ls_Msg, "$days$", CStr(mt_CstValues.ActionFollowUpIncrement), , , vbTextCompare)
        lbl_ActionInfo.Caption = ls_Msg
        
        frm_Outstanding.Visible = True
    Else
        frm_Outstanding.Visible = False
        Call Init_Cpts
    End If
    ' log transaction about outstanding items quantity
    Call mo_ArmDb.ExecuteSQL("exec Cap_OutstandingItems_Log_Ins " & mUCode & ",'" & Format(Now, "yyyy-mm-dd hh:mm:ss") & "'," & _
                          ll_ActExpired & "," & ll_ActToFollow & "," & mt_CstValues.ActionFollowUpIncrement & "," & _
                          ll_PrjExpired & "," & ll_PrjToFollow & "," & mt_CstValues.ProjectFollowUpIncrement)

    Exit Sub
Trace_Err:
    Call mo_ArmDb.Close(ll_Cursor)
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:InitOutstanding"
    ' in case of error, try to continue with capture online as normal
    frm_Outstanding.Visible = False
    Call Init_Cpts
End Sub

Private Sub ResizeOutstanding()
Dim ll_GridHeight As Long
Dim ll_GridWidth As Long

On Error GoTo ErrorHandler
    
    Call frm_Outstanding.Move(mt_CstValues.Frm_Spacing, 0, mt_CstValues.View_Full_Width - 2 * mt_CstValues.Frm_Spacing, mt_CstValues.View_Full_Height)
    Call frm_Outstanding.Zorder
    
    tlb_Outstanding.Left = frm_Outstanding.Width - tlb_Outstanding.Width - mt_CstValues.Frm_Spacing
    
    lbl_FollowUpProjects.Left = mt_CstValues.Frm_Spacing
    lbl_FollowUpProjects.Width = frm_Outstanding.Width - tlb_Outstanding.Width - 3 * mt_CstValues.Frm_Spacing
    
    ll_GridHeight = (mt_CstValues.View_Full_Height - tbsNavBar.Height - lbl_FollowUpProjects.Height - lbl_OutstandingActions.Height - lbl_ActionInfo.Height - lbl_ProjectInfo.Height) / 2
    ll_GridWidth = mt_CstValues.View_Full_Width - 4 * mt_CstValues.Frm_Spacing
    
    lbl_ProjectInfo.Left = mt_CstValues.Frm_Spacing
    lbl_ProjectInfo.Width = ll_GridWidth
    
    grd_Projects.Left = mt_CstValues.Frm_Spacing
    grd_Projects.Top = lbl_ProjectInfo.Top + lbl_ProjectInfo.Height
    grd_Projects.Width = ll_GridWidth
    grd_Projects.Height = ll_GridHeight
    
    lbl_OutstandingActions.Left = mt_CstValues.Frm_Spacing
    lbl_OutstandingActions.Top = grd_Projects.Top + grd_Projects.Height
    lbl_OutstandingActions.Width = ll_GridWidth
    
    lbl_ActionInfo.Left = mt_CstValues.Frm_Spacing
    lbl_ActionInfo.Top = lbl_OutstandingActions.Top + lbl_OutstandingActions.Height
    lbl_ActionInfo.Width = ll_GridWidth
    
    grd_Actions.Left = mt_CstValues.Frm_Spacing
    grd_Actions.Top = lbl_ActionInfo.Top + lbl_ActionInfo.Height
    grd_Actions.Width = ll_GridWidth
    grd_Actions.Height = ll_GridHeight
  Exit Sub
ErrorHandler:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:ResizeOutstanding"
End Sub

Private Sub grd_Actions_RowLoaded(ByVal al_Row As Long)

On Error GoTo ErrorHandler

  If IsDate(grd_Actions.Data(al_Row, "duedate")) Then
    grd_Actions.LineColor(al_Row) = IIf(grd_Actions.Data(al_Row, "duedate") < Date, mt_CstValues.FollowUpColorExpired, mt_CstValues.FollowUpColor)
  End If
  Exit Sub
ErrorHandler:
End Sub

Private Sub grd_Projects_RowLoaded(ByVal al_Row As Long)
  
On Error GoTo ErrorHandler
  
  If IsDate(grd_Projects.Data(al_Row, "SP_dateFollowUp")) Then
    grd_Projects.LineColor(al_Row) = IIf(grd_Projects.Data(al_Row, "SP_dateFollowUp") < Date, mt_CstValues.FollowUpColorExpired, mt_CstValues.FollowUpColor)
  End If
  Exit Sub
ErrorHandler:
End Sub

Private Sub tlb_Outstanding_action(ByVal as_Role As String, as_Language As String)

On Error GoTo ErrorHandler

  If as_Role = "T" Then
    frm_Outstanding.Visible = False
    'Initialize the components
    Call Init_Cpts
  End If
  Exit Sub
ErrorHandler:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:tlb_Outstanding_action"
End Sub
'END TASK T298.WP8


Private Sub UserControl_Resize()
On Error GoTo ErrorHandler

Dim lo_Root As Object
Dim lo_CptUp As Object          ' The component that embed
Dim ls_EmbeddedIn As Integer    ' Tag of the component embedded


    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "A_Capture:Resize"
    #End If
  
    Call ResizeNavBar
        
    If isValid(mo_LastSwitchToCpt) Then
    
        ls_EmbeddedIn = mo_LastSwitchToCpt.EmbeddedIn
    
        If (ls_EmbeddedIn <> -1) Then
            Set lo_CptUp = GetCpt(mi_SelNavTag, ls_EmbeddedIn)
            Call ResizeHelper(lo_CptUp, mt_CstValues.View_Full)
        End If
        
        If mo_LastSwitchToCpt.Name = "CapOffer" Or _
            mo_LastSwitchToCpt.Name = "CapSubProject" Or _
            mo_LastSwitchToCpt.Name = "memo" Or _
            mo_LastSwitchToCpt.Name = "CapFile" Or _
            mo_LastSwitchToCpt.Name = "CapSOMQuote" Then
            'following call force usercontrol to call SwapToDisplayModeSubitem to resize corectlly
            'it also calls switchtoview function, where also resize is made
            mo_LastSwitchToCpt.DisplayMode = mo_LastSwitchToCpt.DisplayMode
        Else
            Call ResizeHelper(mo_LastSwitchToCpt, mi_LastSwitchToView)
        End If
    End If
    
  Exit Sub
ErrorHandler:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "A_Capture:Resize"
End Sub



