VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl Cap_OfferProd 
   ClientHeight    =   12750
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   18405
   ScaleHeight     =   12750
   ScaleWidth      =   18405
   Begin VB.Frame fra_MainItem 
      Height          =   8700
      Left            =   870
      TabIndex        =   0
      Tag             =   "fra_MainItem"
      Top             =   480
      Width           =   17490
      Begin VB.Frame fra_GridFilter 
         Height          =   975
         Left            =   4380
         TabIndex        =   21
         Tag             =   "fra_GridFilter"
         Top             =   1035
         Width           =   13035
         Begin VB.TextBox txt_Textbox 
            Height          =   345
            Index           =   3
            Left            =   10995
            MaxLength       =   30
            TabIndex        =   26
            Tag             =   "SP_Capkey"
            Top             =   360
            Width           =   1980
         End
         Begin VB.TextBox txt_Textbox 
            Height          =   345
            Index           =   2
            Left            =   8655
            MaxLength       =   30
            TabIndex        =   25
            Tag             =   "COF_CodeCus"
            Top             =   360
            Width           =   1305
         End
         Begin Project1.ArmCombobox cbo_FilterUser 
            Height          =   345
            Left            =   5175
            TabIndex        =   24
            Tag             =   "cbo_FilterUser"
            Top             =   390
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   609
         End
         Begin VB.TextBox txt_Textbox 
            Height          =   345
            Index           =   1
            Left            =   2985
            TabIndex        =   23
            Tag             =   "CCU_B7Konto"
            Top             =   390
            Width           =   1305
         End
         Begin VB.TextBox txt_Textbox 
            Height          =   345
            Index           =   0
            Left            =   870
            TabIndex        =   22
            Tag             =   "COF_Code"
            Top             =   390
            Width           =   1305
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Project ID"
            Height          =   210
            Index           =   6
            Left            =   10005
            TabIndex        =   31
            Tag             =   "lbl_SP_Capkey"
            Top             =   420
            Width           =   945
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Cust. code"
            Height          =   210
            Index           =   5
            Left            =   7665
            TabIndex        =   30
            Tag             =   "lbl_COF_CodeCus"
            Top             =   420
            Width           =   945
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#User"
            Height          =   210
            Index           =   4
            Left            =   4365
            TabIndex        =   29
            Tag             =   "lbl_COF_User"
            Top             =   450
            Width           =   750
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Konto"
            Height          =   210
            Index           =   3
            Left            =   2235
            TabIndex        =   28
            Tag             =   "lbl_LEN_BaeKonto"
            Top             =   450
            Width           =   750
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Code"
            Height          =   210
            Index           =   2
            Left            =   120
            TabIndex        =   27
            Tag             =   "lbl_COF_Code"
            Top             =   450
            Width           =   750
         End
      End
      Begin VB.Frame fra_Detail 
         Height          =   2310
         Left            =   4305
         TabIndex        =   15
         Tag             =   "fra_Detail"
         Top             =   4800
         Width           =   7965
         Begin VB.TextBox txt_Detail 
            Height          =   2070
            Left            =   5880
            TabIndex        =   16
            Tag             =   "txt_Detail"
            Top             =   165
            Width           =   1995
         End
         Begin Project1.ArmGrid grd_Detail 
            Height          =   2040
            Left            =   75
            TabIndex        =   17
            Tag             =   "grd_Detail"
            Top             =   180
            Width           =   5760
            _ExtentX        =   10160
            _ExtentY        =   3598
         End
      End
      Begin VB.CommandButton cmd_TVReLoad 
         Height          =   855
         Left            =   120
         Style           =   1  'Graphical
         TabIndex        =   4
         Top             =   3765
         Width           =   975
      End
      Begin VB.Frame fra_MainFilter 
         Height          =   3150
         Left            =   75
         TabIndex        =   1
         Tag             =   "fra_MainFilter"
         Top             =   135
         Width           =   4170
         Begin VB.CommandButton btn_ResetFilter 
            Caption         =   "#Reset"
            Height          =   315
            Left            =   90
            TabIndex        =   33
            Tag             =   "btn_ResetFilter"
            Top             =   165
            Width           =   765
         End
         Begin VB.Frame fra_DocType 
            BorderStyle     =   0  'None
            Height          =   450
            Left            =   30
            TabIndex        =   18
            Top             =   630
            Width           =   4080
            Begin VB.OptionButton opt_DocType 
               Caption         =   "#All"
               Height          =   255
               Index           =   0
               Left            =   135
               TabIndex        =   32
               Tag             =   "DocAll"
               Top             =   105
               Value           =   -1  'True
               Width           =   1245
            End
            Begin VB.OptionButton opt_DocType 
               Caption         =   "#Order"
               Height          =   255
               Index           =   2
               Left            =   2775
               TabIndex        =   20
               Tag             =   "DocOrder"
               Top             =   105
               Width           =   1335
            End
            Begin VB.OptionButton opt_DocType 
               Caption         =   "#Offer"
               Height          =   255
               Index           =   1
               Left            =   1380
               TabIndex        =   19
               Tag             =   "DocOffer"
               Top             =   105
               Width           =   1395
            End
         End
         Begin VB.OptionButton opt_date 
            Caption         =   "#All"
            Height          =   255
            Index           =   0
            Left            =   75
            TabIndex        =   9
            Tag             =   "dateAll"
            Top             =   2040
            Value           =   -1  'True
            Width           =   1750
         End
         Begin VB.OptionButton opt_date 
            Caption         =   "#Between"
            Height          =   255
            Index           =   1
            Left            =   1815
            TabIndex        =   8
            Tag             =   "dateBetween"
            Top             =   2040
            Width           =   2200
         End
         Begin Project1.ArmCombobox cbo_date 
            Height          =   345
            Left            =   75
            TabIndex        =   7
            Tag             =   "date_type"
            Top             =   2730
            Visible         =   0   'False
            Width           =   3975
            _ExtentX        =   7011
            _ExtentY        =   609
         End
         Begin Project1.A_calocx cal12 
            Height          =   330
            Left            =   2235
            TabIndex        =   10
            Tag             =   "date_till"
            Top             =   2310
            Visible         =   0   'False
            Width           =   1830
            _ExtentX        =   3228
            _ExtentY        =   582
         End
         Begin Project1.A_calocx cal11 
            Height          =   330
            Left            =   75
            TabIndex        =   11
            Tag             =   "date_since"
            Top             =   2310
            Visible         =   0   'False
            Width           =   1830
            _ExtentX        =   3228
            _ExtentY        =   582
         End
         Begin Project1.ArmCombobox cbo_Status 
            Height          =   345
            Left            =   60
            TabIndex        =   13
            Tag             =   "cbo_Status"
            Top             =   1380
            Width           =   4035
            _ExtentX        =   7117
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Offer status"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   75
            TabIndex        =   14
            Tag             =   "lbl_DateRange"
            Top             =   1110
            Width           =   1215
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Date range"
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   238
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   75
            TabIndex        =   12
            Tag             =   "lbl_DateRange"
            Top             =   1785
            Width           =   1215
         End
      End
      Begin Project1.ArmGrid grd_Main 
         Height          =   2610
         Left            =   4380
         TabIndex        =   2
         Tag             =   "grd_Main"
         Top             =   2205
         Width           =   11115
         _ExtentX        =   19606
         _ExtentY        =   4604
      End
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Left            =   4395
         TabIndex        =   3
         Tag             =   "2900"
         Top             =   345
         Width           =   11130
         _ExtentX        =   19632
         _ExtentY        =   1217
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Left            =   75
         TabIndex        =   5
         Tag             =   "cbo_View"
         Top             =   3330
         Width           =   4035
         _ExtentX        =   7117
         _ExtentY        =   609
      End
      Begin Project1.ArmTreeView tvw_Main 
         Height          =   3960
         Left            =   75
         TabIndex        =   6
         Tag             =   "tvw_Main"
         Top             =   3720
         Width           =   3990
         _ExtentX        =   7038
         _ExtentY        =   6985
      End
   End
   Begin MSComctlLib.ImageList iml_Icons 
      Left            =   120
      Top             =   120
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483633
      MaskColor       =   16711935
      _Version        =   393216
   End
End
Attribute VB_Name = "Cap_OfferProd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' **************************************************************************************************
' **************************************** USER DEFINED ERRORS *************************************
' **************************************************************************************************
Private Enum ArmErr
    DBCnxFailed = vbObjectError + 1             ' Unable to connect to the database
    CPTAlreadyInitialized = vbObjectError + 2   ' We try to initialize a component that is already initialized
    CPTNotInitialized = vbObjectError + 3       ' We try to use or free that is not initialized yet
    InvalidArgument = vbObjectError + 4
    PropertyNotSet = vbObjectError + 5
    SQLFailure = vbObjectError + 6               ' A SQL runtime error has occured : syntax wrong....
    SQLBadRowAffectedCount = vbObjectError + 7   ' A SQL request has not affected the expected rowcount (ex: one Update do nothing)
    SQLBadRowExpectedCount = vbObjectError + 8   ' A SQL request does not return the expected rowcount : select an item return nothing...
    DrivingError = vbObjectError + 9
    CompFncFailed = vbObjectError + 10           ' when component function fail
    GridLoadFailed = vbObjectError + 11          ' load function failed ... bad sql
    QuietException = vbObjectError + 12          ' do not display error message
    SQLTableReferenceConstraint = vbObjectError + 13 ' A SQL request cannot be executed : Table reference constraint
    DuplicityDetected = vbObjectError + 2301     ' detected row with same unique id
End Enum

Private Const CL_COLOR_ENABLED  As Long = &H80000005
Private Const CL_COLOR_DISABLED As Long = &H8000000F
Private Const CL_COLOR_Expired  As Long = 10066414          ' # EE9999
Private Const CL_COLOR_Requested    As Long = 10066414      ' # EE9999
Private Const CL_COLOR_Delivered    As Long = 10088089      ' # 99EE99
Private Const FRM_SPACE_VER = 120
Private Const FRM_SPACE_HOR = 100
Private Const ICON_RELOAD = 115

Private Const LOCALE_SDECIMAL = &HE ' Decimal separator
Private Const LOCALE_STHOUSAND = &HF ' Thousand separator
Private Const LOCALE_USER_DEFAULT = &H400
Private Const SCREEN_NAME As String = "Cap_OfferProd"

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


Private mo_Tools As DPC_Tools
Private WithEvents mo_CapOffer As CapOffer
Attribute mo_CapOffer.VB_VarHelpID = -1

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

Private ml_U_Code As Long
Private ms_LoginName As String
Private ms_Language_Code As String
Private mb_InternalInit As Boolean
Private ms_DecimalSeparator As String
Private ms_ThousandSeparator As String
Private mc_ScreenLabels As Long
Private mo_WshNetwork As Object
Private ms_ComputerName As String
Private mv_TreeviewInfo As Variant
Private ml_iConcurrency As Long
Private mt_CstValues As type_CstValues
Private ms_Caption As String
Private mb_Initialized As Boolean

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Public Sub Zorder()
On Error GoTo ErrHandler

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

Public Sub Refresh()
On Error GoTo ErrHandler

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

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

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

Public Property Set CstValues(ByRef at_CstValues As Object)
On Error GoTo ErrorHandler

  Set mt_CstValues = at_CstValues
  Exit Property
ErrorHandler:
  Call ErrorHandler("CstValues.Set")
End Property

' Initialization of the component
Public Sub Load_A_COM()
On Error GoTo ErrHandler

Dim la_Columns() As Variant
Dim ls_req As String

  If mo_Db Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  If mo_Tools Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  'Set mo_Tools = New DPC_Tools
  'Set mo_Tools.ArmDb = mo_Db
  'Call mo_Tools.Load_A_COM
  
  Call mo_Tools.Load_A_ComControls(UserControl.Controls, mo_Db, ms_Language_Code)
    
  ms_ThousandSeparator = mo_Tools.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND)
  ms_DecimalSeparator = Format(0, ".")
  
  Set mo_FSO = CreateObject("Scripting.FileSystemObject")
  
#If ENV = LIVE Then
  Set mo_Sys = CreateObject("ArmSYSCOM.ArmSys")
#Else
  Set mo_Sys = New ARMSYSCOMLib.ArmSYS
#End If
  
  Set mo_WshNetwork = CreateObject("WScript.Network")
  ms_ComputerName = mo_WshNetwork.ComputerName
  
  mb_InternalInit = True
  
  Call iml_Icons.ListImages.Clear
  Call iml_Icons.ListImages.Add(, , LoadResPicture("ERRORTYPE1", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("ERRORTYPE2", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("ERRORTYPE3", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("LEVEL1", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("LEVEL2", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("LEVEL3", vbResBitmap))
  
  If mo_CapOffer Is Nothing Then
  
    ' init CapPrj embeded component >>
    'Set mt_CstValues = New type_CstValues
    
    Set mo_CapOffer = UserControl.Controls.Add("Project1.CapOffer", "CapOffer", Me)
    mo_CapOffer.Visible = False
    Call mo_CapOffer.Move(0, 0, Extender.Width, Extender.Height)
    mo_CapOffer.Language = ms_Language_Code
    mo_CapOffer.U_Code = ml_U_Code
    mo_CapOffer.LoginName = ms_LoginName
    mo_CapOffer.ConnectString = prg.CurrentServerIP & prg.ServerInstance & CH_LDELIMIT & prg.DBName & CH_LDELIMIT & prg.LoginName & CH_LDELIMIT & prg.U_PWD & CH_LDELIMIT & "Cap_OfferProd"
    Set mo_CapOffer.ArmDb = mo_Db
    Set mo_CapOffer.Tools = mo_Tools
    mo_CapOffer.IsProduction = True
    Set mo_CapOffer.ExternalGrid = grd_Main
    Call mo_CapOffer.FrameWorkInit(mt_CstValues, "CapOffer")
    Call mo_CapOffer.Load_A_COM(True)
    If Not mo_CapOffer.Initialized Then
        Call Err.Raise(ArmErr.CompFncFailed, "mo_CapOffer.Initialized", "CapOffer cannot was not initialised")
    End If
    Call mo_CapOffer.Zorder
  End If
    
  cbo_Status.FirstBlankItem = True
  ls_req = "exec A_References_ML_Lst $GR_Code$, $Language_Code$"
  
  ls_req = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferStatus), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_Status.Request = ls_req
  'Call cbo_Status.Load
  'Call cbo_Status.SearchItem(eOfferStatus.osUnderApprovalProcess)
  
  ls_req = _
    "SELECT GSU.U_Code,GSU.U_Login_Name " & _
    "FROM GEN_Systems_Users GSU " & _
    "WHERE GSU.Drop_Flag='N'"
  cbo_FilterUser.Request = ls_req
  cbo_FilterUser.FirstBlankItem = True
  
  Set cmd_TVReLoad.Picture = mo_Tools.LoadIconFromA_Icons(ICON_RELOAD)
  cal11.opening_toward_top = 1
  cal12.opening_toward_top = 1
  Call SetTreeDelayedMode(False)
  Call mo_Tools.LoadComboView(mo_Db, cbo_View, SCREEN_NAME, ms_Language_Code)
  If Not cbo_View.SelectedItem Is Nothing Then
    mv_TreeviewInfo = mo_Tools.LoadTreeViewInfo(mo_Db, SCREEN_NAME, cbo_View.SelectedItem.Key)
    Call LoadTreeView(tvw_Main, mv_TreeviewInfo)
    Call LoadGrid(True)
  End If
   
  ReDim la_Columns(25)
  la_Columns(0) = "COF_ID" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "COF_ID" & CH_LDELIMIT & ""
  la_Columns(1) = "SP_CapKey" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_CapKey" & CH_LDELIMIT & ""
  la_Columns(2) = "I" & CH_LDELIMIT & "200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "I" & CH_LDELIMIT & "#I"
  la_Columns(3) = "V" & CH_LDELIMIT & "200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "V" & CH_LDELIMIT & "#V"
  la_Columns(4) = "COF_Code" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Code" & CH_LDELIMIT & "#Code"
  la_Columns(5) = "COF_CodeCus" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_CodeCus" & CH_LDELIMIT & "#Cust.code"
  la_Columns(6) = "COF_DocDat" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_DocDat" & CH_LDELIMIT & "#Doc.date"
  la_Columns(7) = "CCU_B7Konto" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_B7Konto" & CH_LDELIMIT & "#Konto"
  la_Columns(8) = "CCU_Desc" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_Desc" & CH_LDELIMIT & "#Company"
  la_Columns(9) = "LEN_BaeKonto" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEN_BaeKonto" & CH_LDELIMIT & "#Konto"
  la_Columns(10) = "LEN_BaeKontoDesc" & CH_LDELIMIT & "1600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEN_BaeKontoDesc" & CH_LDELIMIT & "#Company"
  la_Columns(11) = "Z_CreatorDesc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_CreatorDesc" & CH_LDELIMIT & "#User"
  la_Columns(12) = "COF_PriorDesc" & CH_LDELIMIT & "200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_PriorDesc" & CH_LDELIMIT & "#A"
  la_Columns(13) = "COF_WshDat" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_WshDat" & CH_LDELIMIT & "#Req.date"
  la_Columns(14) = "COF_Desc" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Desc" & CH_LDELIMIT & "#Comment"
  la_Columns(15) = "COF_StaSal" & CH_LDELIMIT & "300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_StaSal" & CH_LDELIMIT & "#S" & CH_LDELIMIT & "BITMAP"
  la_Columns(16) = "COF_StaTec" & CH_LDELIMIT & "300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_StaTec" & CH_LDELIMIT & "#T" & CH_LDELIMIT & "BITMAP"
  la_Columns(17) = "COF_StaCal" & CH_LDELIMIT & "300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_StaCal" & CH_LDELIMIT & "#C" & CH_LDELIMIT & "BITMAP"
  la_Columns(18) = "COF_StaPla" & CH_LDELIMIT & "300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_StaPla" & CH_LDELIMIT & "#P" & CH_LDELIMIT & "BITMAP"
  la_Columns(19) = "COF_Prior" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Prior" & CH_LDELIMIT & "#Prior"
  la_Columns(20) = "COF_PosQty" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_PosQty" & CH_LDELIMIT & "#PosQty"
  la_Columns(21) = "COF_SumM2" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_SumM2" & CH_LDELIMIT & "#Sum M2" & CH_LDELIMIT & "" & CH_LDELIMIT & "0.0" & CH_LDELIMIT & "RIGHT"
  la_Columns(22) = "COF_SumWpt" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_SumWpt" & CH_LDELIMIT & "#Sum points"
  la_Columns(23) = "Z_Last_Upd" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Last_Upd" & CH_LDELIMIT & "#Last update"
  la_Columns(24) = "Z_Last_Upd_UserDesc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Last_Upd_UserDesc" & CH_LDELIMIT & "#User last update"
  la_Columns(25) = "COF_FreDat" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_FreDat" & CH_LDELIMIT & "#Free dat"
  Call grd_Main.SetColumns(la_Columns)

  ReDim la_Columns(4)
  la_Columns(0) = "FIL_ID" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "FIL_ID" & CH_LDELIMIT & ""
  la_Columns(1) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "OFD_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(3) = "PRD_Name" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(4) = "FIL_FileName" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "FIL_FileName" & CH_LDELIMIT & "#File"
  Call grd_Detail.SetColumns(la_Columns)
  
  Call mo_Tools.EnableControl(txt_Detail, False)
  'Screen csts
  Call mo_Tools.LoadToolbars(mo_Db, UserControl.Controls, SCREEN_NAME)
  mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, UserControl.Controls, Me, SCREEN_NAME, ms_Language_Code)
  Call mo_Tools.ChangeCharset(UserControl.Controls, gl_CodePage)
  
  mb_InternalInit = False
  mb_Initialized = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("Load_A_Com")
End Sub

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

Public Property Get DisplayMode()

  If mo_CapOffer Is Nothing Then
    DisplayMode = mt_CstValues.DisplayMode_None
  Else
    DisplayMode = mo_CapOffer.DisplayMode
  End If
End Property
Private Sub InitOfferComponent()
On Error GoTo ErrHandler


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

Private Sub SetTreeDelayedMode(ByVal ab_Delayed As Boolean)
On Error GoTo ErrHandler
    
  tvw_Main.Visible = Not ab_Delayed
  cmd_TVReLoad.Visible = ab_Delayed
  grd_Main.Visible = (Not ab_Delayed) And (Not tvw_Main.SelectedItem Is Nothing)
  fra_Detail.Visible = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("SetTreeDelayedMode")
End Sub

Private Sub LoadTreeView(ByVal ao_Tree As ArmTreeView, ByVal av_TreeviewInfo As Variant)
On Error GoTo ErrHandler

  Dim lv_NodeReq As Variant
  Dim lv_GridReq As Variant
  Dim lv_Images As Variant
  Dim lv_SelectedImages As Variant
  Dim ll_Levels As Long, ll_Idx As Long
  
  lv_NodeReq = av_TreeviewInfo(0)
  lv_GridReq = av_TreeviewInfo(1)
  lv_Images = av_TreeviewInfo(2)
  lv_SelectedImages = av_TreeviewInfo(3)
  
  ll_Levels = UBound(lv_NodeReq) + 1
  If ll_Levels > 0 Then
    ao_Tree.Levels = ll_Levels
    For ll_Idx = 0 To ll_Levels - 1
      lv_NodeReq(ll_Idx) = mo_Tools.ReplaceRequestByFrameData(lv_NodeReq(ll_Idx), UserControl.Controls, fra_MainFilter)
      lv_NodeReq(ll_Idx) = ReplaceCommonPlaceholders(lv_NodeReq(ll_Idx))
    Next
    ao_Tree.NodeRequests = lv_NodeReq
    ao_Tree.GridRequests = lv_GridReq
    ao_Tree.Images = lv_Images
    ao_Tree.SelectedImages = lv_SelectedImages
    If Not ao_Tree.LoadTree(LoadTypeChildsDemand) Then
      Err.Raise ArmErr.CompFncFailed, "ao_Tree.LoadTree(LoadTypeChildsDemand)", "Tree load failed: " & lv_NodeReq(0)
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadTreeView")
End Sub

Private Sub LoadGrid(ByVal ab_DelayedLoad As Boolean)
On Error GoTo ErrHandler

Dim lv_Requests As Variant

  If tvw_Main.SelectedItem Is Nothing Then
    grd_Main.Visible = False
    fra_Detail.Visible = False
  Else
    lv_Requests = ApplyTVFilters(tvw_Main.SelectedNodeRequest)
    If Not grd_Main.Load(lv_Requests, False, , , ab_DelayedLoad) Then
      Err.Raise ArmErr.CompFncFailed, "grd_Main.Load", "Method Load failed: " & lv_Requests(0)
    End If
    grd_Main.Visible = True
    fra_Detail.Visible = False
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadGrid")
End Sub

Private Sub btn_ResetFilter_Click()

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  mb_InternalInit = True
  opt_DocType(0).Value = True
  Set cbo_Status.SelectedItem = Nothing
  opt_date(0).Value = True
  Call SetTreeDelayedMode(False)
  Call tvw_Main.Refresh
  Set tvw_Main.SelectedItem = tvw_Main.Nodes(0)
  mb_InternalInit = False
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ResetFilter_Click")
End Sub

Private Sub cal11_changeposition(y As Integer)
On Error GoTo ErrHandler
  
  Call cal11.Zorder
  cal11.Top = cal11.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal11_changeposition")
End Sub

Private Sub cal12_changeposition(y As Integer)
On Error GoTo ErrHandler
  
  Call cal12.Zorder
  cal12.Top = cal12.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal12_changeposition")
End Sub

Private Sub cal11_datechangee()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  Call SetTreeDelayedMode(True)
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal11_datechangee")
End Sub

Private Sub cal12_datechangee()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  Call SetTreeDelayedMode(True)
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal12_datechangee")
End Sub

Private Sub cbo_status_ComboItemSelected()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  
  Call SetTreeDelayedMode(True)
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_Status_ComboItemSelected")
End Sub

Private Sub cbo_View_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  
  If Not cbo_View.SelectedItem Is Nothing Then
    mv_TreeviewInfo = mo_Tools.LoadTreeViewInfo(mo_Db, SCREEN_NAME, cbo_View.SelectedItem.Key)
    Call LoadTreeView(tvw_Main, mv_TreeviewInfo)
    Call SetTreeDelayedMode(False)
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_Views_ComboItemSelected")
End Sub

Private Sub grd_Detail_ItemSelected()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  
  Call Launch_File(grd_Detail.SelectedLine(0, "FIL_Id"), grd_Detail.SelectedLine(0, "FIL_FileName"))
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Detail_ItemSelected")
End Sub

Private Sub grd_Main_Click()
On Error GoTo ErrHandler

Dim ls_req As String

  If mb_InternalInit Then Exit Sub
  'Call mo_Tools.LockScreen(Me, True)
  fra_Detail.Visible = False
  If grd_Main.SelectedCount = 1 Then
    ls_req = "exec Cap_OfferProdFile_lst $Language_Code$, $COF_Id$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(grd_Main.SelectedLine(0, "COF_Id")), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    Call grd_Detail.Load(ls_req, True)
    txt_Detail.Text = grd_Main.SelectedLine(0, "COF_Desc")
    fra_Detail.Visible = True
  End If
  'Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Main_Click")
End Sub

Private Sub grd_Main_ItemSelected()
On Error GoTo ErrHandler

'  Call mo_Tools.LockScreen(Me, True)
  mo_CapOffer.CurrentKey = grd_Main.CurrentKey(0)
  mo_CapOffer.DisplayMode = mt_CstValues.DisplayMode_View
  mo_CapOffer.Visible = True
  mo_CapOffer.Zorder
'  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Main_ItemSelected")
End Sub

Private Sub Launch_File(ByVal al_FIL_Id As Long, ByVal as_FileName As String)
Dim ls_TempPath As String
Dim lo_shell As Object

On Error GoTo ErrHandler
  If as_FileName = "" Then Exit Sub
  
  ls_TempPath = mo_Tools.GetAndCreateTempDir(mo_FSO, SCREEN_NAME, True) & "\" & as_FileName
  Set lo_shell = CreateObject("Shell.Application")
        
  If Not mo_Db.BlobToFileSQL("SELECT FIL_File FROM DPC_File WHERE FIL_Id=" & al_FIL_Id, ls_TempPath, True, False) Then
    Call MsgBox(mo_Tools.MsgText(mo_Db, ms_Language_Code, 9843, "#Cannot download the file from db - FIL_Id: $FIL_Id$ Filename: $FileName$", Array("$FIL_Id$", al_FIL_Id, "$FileName$", as_FileName)))
    Exit Sub
  End If
  
  Call lo_shell.ShellExecute(ls_TempPath, "", "", "open", 1)
  Set lo_shell = Nothing
  Exit Sub
ErrHandler:
  Set lo_shell = Nothing
  Call ErrorHandler("Launch_Report_File:" & al_FIL_Id & " FileName: " & as_FileName)
End Sub

Private Sub mo_CapOffer_IsOfferLocked(ab_IsLocked As Boolean)
On Error GoTo ErrHandler

  RaiseEvent IsOfferLocked(ab_IsLocked)
  Exit Sub
ErrHandler:
  Call ErrorMessage("mo_CapOffer_IsOfferLocked")
End Sub

Private Sub mo_CapOffer_OfferGridMove(ByVal al_Direction As Long)
On Error GoTo ErrHandler
 
Dim ls_CurrentKey As String

  If al_Direction < 0 Then
    If grd_Main.Row = 0 Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 927, "#No more previous item.")
      Exit Sub
    Else
      grd_Main.Row = grd_Main.Row - 1
      ls_CurrentKey = grd_Main.CurrentKey(0)
    End If
  Else
    If grd_Main.Row = grd_Main.Rows - 1 And grd_Main.AllDataLoaded = True Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 928, "#No more next item.")
      Exit Sub
    Else
      grd_Main.Row = grd_Main.Row + 1
      ls_CurrentKey = grd_Main.CurrentKey(0)
    End If
  End If
  
  mo_CapOffer.CurrentKey = ls_CurrentKey
  mo_CapOffer.DisplayMode = mt_CstValues.DisplayMode_View
  mo_CapOffer.Visible = True
  mo_CapOffer.Zorder
  Exit Sub
ErrHandler:
  Call ErrorMessage("mo_CapOffer_OfferGridMove")
End Sub

Private Sub mo_CapOffer_Release()
On Error GoTo ErrHandler

  mo_CapOffer.Visible = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("mo_CapOffer_Release")
End Sub

Private Sub mo_CapOffer_SwitchToView(ByVal li_View As Integer)
On Error GoTo ErrHandler

  If li_View = mt_CstValues.View_Embedded Then
    mo_CapOffer.Visible = False
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("mo_CapOffer_SwitchToView")
End Sub

Private Sub opt_date_Click(Index As Integer)
On Error GoTo ErrHandler

  If Index = 0 Then
    cal11.Visible = False
    cal12.Visible = False
    Call cal11.reinit_cal
    Call cal12.reinit_cal
    cbo_date.Visible = False
  Else
    cal11.Visible = True
    cal12.Visible = True
    cbo_date.Visible = True
  End If
  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  If Index = 1 Then
    If cbo_date.SelectedItem Is Nothing Then
      cbo_date.FirstBlankItem = False
      cbo_date.Request = "exec captv_date_cbo 'TV_Cap_OfferProd_date','" & ms_Language_Code & "'"
      Call cbo_date.Load
      Call cbo_date.SearchItem("1", 2, 0)
    End If
  End If
  Call SetTreeDelayedMode(True)
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("opt_date_Click")
End Sub

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

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  Select Case as_Role
  Case "B"  'update
    If grd_Main.SelectedCount = 1 Then
      mo_CapOffer.CurrentKey = grd_Main.CurrentKey(0)
      If mo_CapOffer.CanUpdateOffer(grd_Main.SelectedLine(0, "SP_CapKey"), mo_CapOffer.CurrentKey(1)) Then
        Call mo_Tools.LockScreen(Me, False)
        mo_CapOffer.DisplayMode = mt_CstValues.DisplayMode_Update
        mo_CapOffer.Visible = True
        Call mo_CapOffer.Zorder
        Exit Sub
      Else
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9705, "You cannot update this offer")
      End If
    Else
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9723, "#Please, select one row")
    End If
  Case "F"  'refresh
    Call tvw_Main.Refresh
    Call LoadGrid(False)
  Case "L"  'refresh
    Call LoadGrid(False)
  Case "D"
    If grd_Main.SelectedCount = 1 Then
      Call mo_CapOffer.PrintOffer(grd_Main.CurrentKey(0), False)
    Else
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9723, "#Please, select one row")
    End If
  Case "T"
      Call mo_Tools.LockScreen(Me, False)
      RaiseEvent quit
      Exit Sub
  Case Else
    Err.Raise ArmErr.InvalidArgument, "as_Role", "Unknown role: " & as_Role
  End Select
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tlb_Main_action")
End Sub

Private Sub cmd_TVReLoad_Click()
On Error GoTo ErrHandler
    
  If mb_InternalInit Then Exit Sub
  
  Call mo_Tools.LockScreen(Me, True)
  Call LoadTreeView(tvw_Main, mv_TreeviewInfo)
  Call SetTreeDelayedMode(False)
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cmd_TVReLoad_Click")
End Sub

Private Sub tvw_Main_NodeClick(ByVal Node As MSComctlLib.Node)
On Error GoTo ErrHandler

Dim lb_DelayedLoad As Boolean

  If mb_InternalInit Then Exit Sub
  If Node Is Nothing Then Exit Sub
  
  Call mo_Tools.LockScreen(Me, True)
  
  lb_DelayedLoad = (tvw_Main.NodeInfo(Node).ml_Level < tvw_Main.Levels - 1)
  Call LoadGrid(lb_DelayedLoad)
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tvw_Main_NodeClick")
End Sub

Private Sub txt_Textbox_KeyPress(Index As Integer, KeyAscii As Integer)
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  If KeyAscii = 13 Then
    Call tlb_Main_action("L", ms_Language_Code)
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Textbox_KeyPress")
End Sub

Private Function ApplyTVFilters(ByVal av_Request As Variant) As Variant
On Error GoTo ErrHandler
    Dim lv_Requests As Variant
    
    If IsArray(av_Request) Then
      ReDim lv_Requests(UBound(av_Request))
      Dim ll_Idx As Long, ll_Count As Long
      ll_Count = UBound(lv_Requests)
      For ll_Idx = 0 To ll_Count
        lv_Requests(ll_Idx) = mo_Tools.ReplaceRequestByFrameData(av_Request(ll_Idx), UserControl.Controls, fra_MainFilter)
        lv_Requests(ll_Idx) = mo_Tools.ReplaceRequestByFrameData(lv_Requests(ll_Idx), UserControl.Controls, fra_GridFilter)
        lv_Requests(ll_Idx) = mo_Tools.ReplacePlaceholderByControlValue(lv_Requests(ll_Idx), tvw_Main)
        lv_Requests(ll_Idx) = mo_Tools.ReplaceLanguagePlaceholderFromToolbar(lv_Requests(ll_Idx), tlb_Main)
        lv_Requests(ll_Idx) = ReplaceCommonPlaceholders(lv_Requests(ll_Idx))
      Next
    Else
      ReDim lv_Requests(0)
      lv_Requests(0) = mo_Tools.ReplaceRequestByFrameData(av_Request, UserControl.Controls, fra_MainFilter)
      lv_Requests(0) = mo_Tools.ReplaceRequestByFrameData(lv_Requests(0), UserControl.Controls, fra_GridFilter)
      lv_Requests(0) = mo_Tools.ReplacePlaceholderByControlValue(lv_Requests(0), tvw_Main)
      lv_Requests(0) = mo_Tools.ReplaceLanguagePlaceholderFromToolbar(lv_Requests(0), tlb_Main)
      lv_Requests(0) = ReplaceCommonPlaceholders(lv_Requests(0))
    End If

    ApplyTVFilters = lv_Requests
    Exit Function
ErrHandler:
    Call ErrorHandler("ApplyTVFilters")
End Function

Public Sub Resize()
On Error GoTo ErrHandler

Dim ll_Left As Long

  If (Width <= 2 * fra_MainFilter.Width) Or (Height <= 2 * fra_MainFilter.Height) Then Exit Sub
  
  Call fra_MainItem.Move(0, 0, Width, Height)
  Call fra_MainFilter.Move(FRM_SPACE_HOR, FRM_SPACE_VER)
  Call tlb_Main.Move(fra_MainFilter.Left + fra_MainFilter.Width + FRM_SPACE_HOR, 2 * FRM_SPACE_VER, fra_MainItem.Width - (fra_MainFilter.Left + fra_MainFilter.Width + 2 * FRM_SPACE_HOR))
  Call fra_GridFilter.Move(tlb_Main.Left, tlb_Main.Top + tlb_Main.Height, tlb_Main.Width)
  
  Call cbo_View.Move(FRM_SPACE_HOR, fra_MainFilter.Top + fra_MainFilter.Height + FRM_SPACE_VER, fra_MainFilter.Width)
  Call tvw_Main.Move(FRM_SPACE_HOR, cbo_View.Top + cbo_View.Height + FRM_SPACE_VER, fra_MainFilter.Width)
  
  If fra_MainItem.Height - tvw_Main.Top - FRM_SPACE_VER > 0 Then
    tvw_Main.Height = fra_MainItem.Height - tvw_Main.Top - FRM_SPACE_VER
  End If
  Call cmd_TVReLoad.Move(tvw_Main.Left, tvw_Main.Top)
  Call mo_CapOffer.Move(0, 0, Extender.Width, Extender.Height)
  
  Call grd_Main.Move(tlb_Main.Left, fra_GridFilter.Top + fra_GridFilter.Height + FRM_SPACE_VER, tlb_Main.Width, fra_MainItem.Height - tlb_Main.Height - fra_GridFilter.Height - fra_Detail.Height - 6 * FRM_SPACE_VER)
  Call fra_Detail.Move(tlb_Main.Left, grd_Main.Top + grd_Main.Height + FRM_SPACE_VER, tlb_Main.Width)
  Call grd_Detail.Move(0, 0, grd_Detail.Width, fra_Detail.Height)
  Call txt_Detail.Move(grd_Detail.Left + grd_Detail.Width, 0, fra_Detail.Width - grd_Detail.Width, fra_Detail.Height)
  Exit Sub
ErrHandler:
  Call ErrorHandler("Resize")
End Sub

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

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

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

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

