VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl Capact 
   ClientHeight    =   12000
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   15360
   LockControls    =   -1  'True
   ScaleHeight     =   12000
   ScaleWidth      =   15360
   ToolboxBitmap   =   "Capact.ctx":0000
   Begin VB.Frame fraList 
      Height          =   4935
      Left            =   11880
      TabIndex        =   25
      Top             =   120
      Width           =   9015
      Begin Project1.ArmGrid grdLst 
         Height          =   3135
         Left            =   240
         TabIndex        =   86
         Top             =   1440
         Width           =   5655
         _ExtentX        =   9975
         _ExtentY        =   5530
      End
      Begin VB.PictureBox fill_all_record 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   600
         Left            =   3375
         ScaleHeight     =   600
         ScaleWidth      =   600
         TabIndex        =   82
         Top             =   225
         Width           =   600
      End
      Begin Project1.ToolBr pblst 
         Height          =   1095
         Left            =   240
         TabIndex        =   80
         Top             =   240
         Width           =   2715
         _extentx        =   4789
         _extenty        =   1931
      End
      Begin VB.Label lbl_ListFilter 
         Alignment       =   2  'Center
         BackColor       =   &H0000FFFF&
         Caption         =   "#All "
         Height          =   375
         Left            =   360
         TabIndex        =   87
         Tag             =   "lbl_ListFilter"
         Top             =   960
         Width           =   4935
      End
   End
   Begin VB.Frame fraItem 
      Height          =   11415
      Left            =   945
      TabIndex        =   0
      Top             =   210
      Width           =   12000
      Begin VB.Frame fraItemBottom 
         Height          =   980
         Left            =   480
         TabIndex        =   8
         Top             =   8940
         Width           =   10335
         Begin VB.TextBox txt_ActionRep 
            Enabled         =   0   'False
            Height          =   330
            Left            =   7740
            Locked          =   -1  'True
            TabIndex        =   89
            Top             =   180
            Width           =   2355
         End
         Begin VB.TextBox txt_ActCode 
            Enabled         =   0   'False
            Height          =   330
            Left            =   7740
            Locked          =   -1  'True
            TabIndex        =   88
            Tag             =   "txt_ActCode"
            Top             =   540
            Width           =   2355
         End
         Begin VB.TextBox txt_updatedBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   3690
            TabIndex        =   46
            Text            =   "txt_updatedBy"
            Top             =   540
            Width           =   2355
         End
         Begin VB.TextBox txt_createdBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   3690
            TabIndex        =   45
            Tag             =   "txt_createdBy"
            Top             =   180
            Width           =   2355
         End
         Begin VB.TextBox txt_dateEntered 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   1350
            TabIndex        =   40
            Tag             =   "txt_dateEntered"
            Text            =   "28/2/2001"
            Top             =   180
            Width           =   1100
         End
         Begin VB.TextBox txt_lastUpdated 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   1350
            TabIndex        =   39
            Tag             =   "txt_lastUpdated"
            Text            =   "28/2/2001"
            Top             =   540
            Width           =   1100
         End
         Begin VB.TextBox txt_RaisedBy 
            Height          =   315
            Left            =   3180
            TabIndex        =   92
            Tag             =   "txt_RaisedBy"
            Top             =   180
            Visible         =   0   'False
            Width           =   555
         End
         Begin VB.Label lbl_ActionRep 
            Caption         =   "#Action rep"
            Enabled         =   0   'False
            Height          =   255
            Left            =   6180
            TabIndex        =   91
            Tag             =   "lbl_ActionRep"
            Top             =   240
            Width           =   1500
         End
         Begin VB.Label lbl_ActionCode 
            Caption         =   "#Action code"
            Enabled         =   0   'False
            Height          =   255
            Left            =   6180
            TabIndex        =   90
            Tag             =   "lbl_ActionCode"
            Top             =   600
            Width           =   1500
         End
         Begin VB.Label lbl_updatedBy 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Left            =   2730
            TabIndex        =   44
            Tag             =   "lbl_updatedBy"
            Top             =   600
            Width           =   900
         End
         Begin VB.Label lbl_createdBy 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   315
            Left            =   2715
            TabIndex        =   43
            Tag             =   "lbl_createdBy"
            Top             =   240
            Width           =   900
         End
         Begin VB.Label lbl_lastUpdated 
            Caption         =   "#Last Updated"
            Enabled         =   0   'False
            Height          =   255
            Left            =   150
            TabIndex        =   42
            Tag             =   "lbl_lastUpdated"
            Top             =   600
            Width           =   1140
         End
         Begin VB.Label lbl_dateEntered 
            Caption         =   "#Date Entered"
            Enabled         =   0   'False
            Height          =   255
            Left            =   150
            TabIndex        =   41
            Tag             =   "lbl_dateEntered"
            Top             =   240
            Width           =   1140
         End
      End
      Begin Project1.ToolBr pbitem 
         Height          =   675
         Left            =   120
         TabIndex        =   81
         Top             =   180
         Width           =   2595
         _extentx        =   4577
         _extenty        =   1191
      End
      Begin MSComctlLib.TabStrip tbsEmbedded 
         Height          =   345
         Left            =   180
         TabIndex        =   24
         Top             =   10860
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   609
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   1
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin VB.Frame fraItemTop 
         Height          =   7695
         Left            =   480
         TabIndex        =   26
         Top             =   900
         Width           =   11415
         Begin Project1.ArmTreeView tvw_Sample 
            Height          =   3135
            Left            =   120
            TabIndex        =   96
            Top             =   2220
            Width           =   5010
            _ExtentX        =   8837
            _ExtentY        =   5530
         End
         Begin VB.CheckBox chk_UpdateTV 
            Caption         =   "Search item in the list after update"
            Height          =   375
            Left            =   11040
            TabIndex        =   95
            Tag             =   "chk_UpdateTV"
            Top             =   240
            Value           =   1  'Checked
            Width           =   3135
         End
         Begin VB.TextBox txt_spare3 
            Height          =   330
            Left            =   8790
            TabIndex        =   72
            Top             =   1710
            Visible         =   0   'False
            Width           =   1500
         End
         Begin Project1.ArmCombobox cbo_UOM 
            Height          =   345
            Left            =   8640
            TabIndex        =   22
            Top             =   5040
            Width           =   1620
            _ExtentX        =   2725
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_Reason 
            Height          =   345
            Left            =   7200
            TabIndex        =   17
            Tag             =   "cbo_Reason"
            Top             =   930
            Width           =   3015
            _ExtentX        =   4048
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_letterType 
            Height          =   345
            Left            =   7200
            TabIndex        =   16
            Tag             =   "cbo_letterType"
            Top             =   585
            Width           =   3015
            _ExtentX        =   4048
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_status 
            Height          =   345
            Left            =   7200
            TabIndex        =   15
            Tag             =   "cbo_status"
            Top             =   240
            Width           =   3015
            _ExtentX        =   4048
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_raisedFor 
            Height          =   345
            Left            =   2100
            TabIndex        =   11
            Tag             =   "cbo_raisedFor"
            Top             =   585
            Width           =   3015
            _ExtentX        =   4048
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_actionType 
            Height          =   345
            Left            =   2100
            TabIndex        =   9
            Tag             =   "cbo_actionType"
            Top             =   240
            Width           =   3015
            _ExtentX        =   4048
            _ExtentY        =   609
         End
         Begin Project1.ArmCheckView0 ckv_Sample 
            Height          =   3135
            Left            =   120
            TabIndex        =   10
            Tag             =   "ckv_Sample"
            Top             =   2220
            Width           =   4995
            _extentx        =   8811
            _extenty        =   5530
         End
         Begin VB.TextBox txt_country 
            Height          =   330
            Left            =   9600
            TabIndex        =   84
            Top             =   1380
            Visible         =   0   'False
            Width           =   435
         End
         Begin Project1.ArmCheckView0 CkvProduct 
            Height          =   1335
            Left            =   5205
            TabIndex        =   20
            Tag             =   "CkvProduct"
            Top             =   3600
            Width           =   4995
            _extentx        =   5265
            _extenty        =   5424
         End
         Begin VB.TextBox txt_Size 
            Height          =   345
            Left            =   7200
            TabIndex        =   21
            Top             =   5040
            Width           =   1400
         End
         Begin Project1.A_SrchTxt srch_project 
            Height          =   330
            Left            =   2100
            TabIndex        =   14
            Tag             =   "srch_project"
            Top             =   1635
            Width           =   3015
            _extentx        =   4048
            _extenty        =   582
         End
         Begin Project1.A_SrchTxt srch_contact 
            Height          =   325
            Left            =   2100
            TabIndex        =   13
            Tag             =   "srch_contact"
            Top             =   1290
            Width           =   3015
            _extentx        =   4048
            _extenty        =   582
         End
         Begin Project1.A_SrchTxt srch_Customer 
            Height          =   330
            Left            =   2100
            TabIndex        =   12
            Tag             =   "srch_Customer"
            Top             =   930
            Width           =   3015
            _extentx        =   4048
            _extenty        =   582
         End
         Begin Project1.A_calocx cal_dueDate 
            Height          =   375
            Left            =   7200
            TabIndex        =   18
            Tag             =   "cal_dueDate"
            Top             =   1320
            Width           =   1815
            _ExtentX        =   3201
            _ExtentY        =   661
         End
         Begin VB.TextBox txt_comment 
            Height          =   975
            Left            =   5200
            MaxLength       =   2000
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   19
            Tag             =   "txt_comment"
            Top             =   2280
            Width           =   4995
         End
         Begin VB.TextBox txt_spare4 
            Height          =   330
            Left            =   8730
            TabIndex        =   73
            Top             =   1830
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare2 
            Height          =   330
            Left            =   6330
            TabIndex        =   71
            Top             =   1770
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.TextBox txt_spare1 
            Height          =   330
            Left            =   6210
            TabIndex        =   70
            Top             =   1650
            Visible         =   0   'False
            Width           =   1500
         End
         Begin VB.Frame fra_project 
            Caption         =   "#Project"
            Height          =   1920
            Left            =   5160
            TabIndex        =   58
            Tag             =   "fra_project"
            Top             =   5700
            Width           =   4995
            Begin VB.TextBox txt_pro_SA 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   67
               Tag             =   "txt_pro_SA"
               Top             =   1500
               Width           =   2780
            End
            Begin VB.TextBox txt_pro_Project 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   62
               Tag             =   "txt_pro_Project"
               Top             =   240
               Width           =   2780
            End
            Begin VB.TextBox txt_pro_town 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   61
               Tag             =   "txt_pro_town"
               Top             =   555
               Width           =   2780
            End
            Begin VB.TextBox txt_pro_size 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   60
               Tag             =   "txt_pro_size"
               Top             =   870
               Width           =   2780
            End
            Begin VB.TextBox txt_pro_status 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   59
               Tag             =   "txt_pro_status"
               Top             =   1185
               Width           =   2780
            End
            Begin VB.Label lbl_SA 
               Caption         =   "#S.A."
               Enabled         =   0   'False
               Height          =   255
               Left            =   120
               TabIndex        =   68
               Tag             =   "lbl_SPSA"
               Top             =   1560
               Width           =   1920
            End
            Begin VB.Label Label5 
               Caption         =   "#Project"
               Enabled         =   0   'False
               Height          =   315
               Left            =   120
               TabIndex        =   66
               Tag             =   "lbl_SPName"
               Top             =   300
               Width           =   1920
            End
            Begin VB.Label Label6 
               Caption         =   "#Town"
               Enabled         =   0   'False
               Height          =   315
               Left            =   105
               TabIndex        =   65
               Tag             =   "lbl_SPTown"
               Top             =   600
               Width           =   1920
            End
            Begin VB.Label Label7 
               Caption         =   "#Size"
               Enabled         =   0   'False
               Height          =   255
               Left            =   120
               TabIndex        =   64
               Tag             =   "lbl_SPSize"
               Top             =   930
               Width           =   1920
            End
            Begin VB.Label Label8 
               Caption         =   "#Status"
               Enabled         =   0   'False
               Height          =   255
               Left            =   120
               TabIndex        =   63
               Tag             =   "lbl_SPStatus"
               Top             =   1245
               Width           =   1920
            End
         End
         Begin VB.Frame fra_customer 
            Caption         =   "#Customer"
            Height          =   1920
            Left            =   120
            TabIndex        =   47
            Tag             =   "fra_customer"
            Top             =   5700
            Width           =   4995
            Begin VB.CheckBox chk_SA 
               Caption         =   "#S.A."
               Enabled         =   0   'False
               Height          =   315
               Left            =   3700
               TabIndex        =   69
               Tag             =   "chk_SA"
               Top             =   1500
               Width           =   1080
            End
            Begin VB.TextBox txt_zip 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   53
               Tag             =   "txt_zip"
               Top             =   1185
               Width           =   1095
            End
            Begin VB.TextBox txt_Name 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   52
               Tag             =   "txt_Name"
               Top             =   240
               Width           =   2780
            End
            Begin VB.TextBox txt_Address 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   51
               Tag             =   "txt_Address"
               Top             =   555
               Width           =   2780
            End
            Begin VB.TextBox txt_town 
               Enabled         =   0   'False
               Height          =   315
               Left            =   3200
               TabIndex        =   50
               Tag             =   "txt_town"
               Top             =   1185
               Width           =   1680
            End
            Begin VB.TextBox txt_phone 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   49
               Tag             =   "txt_phone"
               Top             =   1500
               Width           =   1515
            End
            Begin VB.TextBox txt_address2 
               Enabled         =   0   'False
               Height          =   315
               Left            =   2100
               TabIndex        =   48
               Tag             =   "txt_address2"
               Top             =   870
               Width           =   2780
            End
            Begin VB.Label lbl_CCUName 
               Caption         =   "#Name"
               Enabled         =   0   'False
               Height          =   255
               Left            =   120
               TabIndex        =   57
               Tag             =   "lbl_CCUname"
               Top             =   300
               Width           =   1920
            End
            Begin VB.Label lbl_CCUAddress 
               Caption         =   "#Address"
               Enabled         =   0   'False
               Height          =   255
               Left            =   120
               TabIndex        =   56
               Tag             =   "lbl_CCUaddress"
               Top             =   630
               Width           =   1920
            End
            Begin VB.Label lbl_CCUZip 
               Caption         =   "#Zip/Town"
               Enabled         =   0   'False
               Height          =   255
               Index           =   0
               Left            =   120
               TabIndex        =   55
               Tag             =   "lbl_CCUZip"
               Top             =   1245
               Width           =   1920
            End
            Begin VB.Label lbl_CCUPhone 
               Caption         =   "#Phone"
               Enabled         =   0   'False
               Height          =   255
               Left            =   120
               TabIndex        =   54
               Tag             =   "lbl_CCUPhone"
               Top             =   1545
               Width           =   1920
            End
         End
         Begin VB.Label lbl_spare3 
            Caption         =   "#lbl_spare3"
            Height          =   195
            Left            =   7860
            TabIndex        =   76
            Tag             =   "lbl_spare3"
            Top             =   1740
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_status 
            Caption         =   "#Status"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5220
            TabIndex        =   30
            Tag             =   "lbl_status"
            Top             =   345
            Width           =   1920
         End
         Begin VB.Label lbl_size 
            AutoSize        =   -1  'True
            Caption         =   "#Size"
            Height          =   195
            Left            =   5205
            TabIndex        =   83
            Tag             =   "lbl_size"
            Top             =   5040
            Width           =   1920
         End
         Begin VB.Label lbl_spare4 
            Caption         =   "#lbl_spare4"
            Height          =   195
            Left            =   7755
            TabIndex        =   77
            Tag             =   "lbl_spare4"
            Top             =   1890
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare2 
            Caption         =   "#lbl_spare2"
            Height          =   195
            Left            =   6960
            TabIndex        =   75
            Tag             =   "lbl_spare2"
            Top             =   1440
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_spare1 
            Caption         =   "#lbl_spare1"
            Height          =   195
            Left            =   6600
            TabIndex        =   74
            Tag             =   "lbl_spare1"
            Top             =   1695
            Visible         =   0   'False
            Width           =   1005
         End
         Begin VB.Label lbl_product 
            AutoSize        =   -1  'True
            Caption         =   "#Products"
            Height          =   195
            Left            =   5205
            TabIndex        =   38
            Tag             =   "lbl_products"
            Top             =   3360
            Width           =   4995
         End
         Begin VB.Label lbl_comment 
            Caption         =   "#Comment"
            Height          =   255
            Left            =   5160
            TabIndex        =   37
            Tag             =   "lbl_comment"
            Top             =   2040
            Width           =   4995
         End
         Begin VB.Label lbl_sample 
            Caption         =   "#Sample"
            Height          =   255
            Left            =   120
            TabIndex        =   36
            Tag             =   "lbl_sample"
            Top             =   2025
            Width           =   4995
         End
         Begin VB.Label lbl_dueDate 
            Caption         =   "#Due date"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5200
            TabIndex        =   35
            Tag             =   "lbl_dueDate"
            Top             =   1380
            Width           =   1920
         End
         Begin VB.Label lbl_project 
            Caption         =   "#Project"
            Height          =   195
            Left            =   120
            TabIndex        =   34
            Tag             =   "lbl_project"
            Top             =   1680
            Width           =   1920
         End
         Begin VB.Label lbl_contact 
            Caption         =   "#Contact"
            Height          =   255
            Left            =   120
            TabIndex        =   33
            Tag             =   "lbl_contact"
            Top             =   1335
            Width           =   1920
         End
         Begin VB.Label lbl_customer 
            Caption         =   "#Customer"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   32
            Tag             =   "lbl_customer"
            Top             =   975
            Width           =   1920
         End
         Begin VB.Label lbl_actionType 
            Caption         =   "#Action type"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   31
            Tag             =   "lbl_actionType"
            Top             =   300
            Width           =   1920
         End
         Begin VB.Label lbl_reason 
            Caption         =   "#Reason"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5200
            TabIndex        =   29
            Tag             =   "lbl_reason"
            Top             =   1005
            Width           =   1920
         End
         Begin VB.Label lbl_raisedFor 
            Caption         =   "#Raised for"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   28
            Tag             =   "lbl_raisedFor"
            Top             =   645
            Width           =   1920
         End
         Begin VB.Label lbl_letterType 
            Caption         =   "#Letter type"
            Height          =   255
            Left            =   5220
            TabIndex        =   27
            Tag             =   "lbl_letterType"
            Top             =   690
            Width           =   1920
         End
      End
   End
   Begin VB.Frame fraFilters 
      Height          =   9360
      Left            =   180
      TabIndex        =   23
      Top             =   1140
      Width           =   4206
      Begin VB.PictureBox pctTvReset 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   240
         Left            =   0
         Picture         =   "Capact.ctx":0312
         ScaleHeight     =   16
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   16
         TabIndex        =   93
         Top             =   110
         Width           =   240
      End
      Begin Project1.ArmCombobox cbo_Date 
         Height          =   345
         Left            =   60
         TabIndex        =   4
         Top             =   1440
         Visible         =   0   'False
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   609
      End
      Begin Project1.ArmCombobox cbo_View 
         Height          =   345
         Left            =   660
         TabIndex        =   5
         Top             =   1980
         Width           =   3135
         _ExtentX        =   5530
         _ExtentY        =   609
      End
      Begin VB.PictureBox reload_treeview 
         Appearance      =   0  'Flat
         BackColor       =   &H80000000&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   540
         Left            =   60
         ScaleHeight     =   405
         ScaleMode       =   0  'User
         ScaleWidth      =   570
         TabIndex        =   85
         Top             =   2460
         Width           =   570
      End
      Begin Project1.ArmTreeView tvitems 
         Height          =   4125
         Left            =   60
         TabIndex        =   6
         Top             =   2460
         Width           =   2220
         _ExtentX        =   3916
         _ExtentY        =   7276
      End
      Begin Project1.A_calocx cal11 
         Height          =   375
         Left            =   60
         TabIndex        =   2
         Top             =   960
         Visible         =   0   'False
         Width           =   1830
         _ExtentX        =   3519
         _ExtentY        =   661
      End
      Begin Project1.A_calocx cal12 
         Height          =   375
         Left            =   2190
         TabIndex        =   3
         Top             =   960
         Visible         =   0   'False
         Width           =   1830
         _ExtentX        =   3413
         _ExtentY        =   661
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#Between"
         Height          =   255
         Index           =   1
         Left            =   1920
         TabIndex        =   78
         Tag             =   "opt_between"
         Top             =   645
         Width           =   2200
      End
      Begin VB.OptionButton opt_date 
         Caption         =   "#All"
         Height          =   255
         Index           =   0
         Left            =   75
         TabIndex        =   1
         Tag             =   "opt_all"
         Top             =   645
         Value           =   -1  'True
         Width           =   1800
      End
      Begin MSComctlLib.TabStrip tbsFilters 
         Height          =   375
         Left            =   135
         TabIndex        =   7
         Top             =   8700
         Width           =   3045
         _ExtentX        =   5371
         _ExtentY        =   661
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   3
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#All"
               Key             =   "A"
               Object.Tag             =   "tbs_filtersAll"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Complete"
               Key             =   "C"
               Object.Tag             =   "tbs_filtersComp"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Outstanding"
               Key             =   "O"
               Object.Tag             =   "tbs_filtersOut"
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin VB.Label lbl_DateRange 
         Caption         =   "#Date range"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   94
         Tag             =   "lbl_DateRange"
         Top             =   370
         Width           =   1215
      End
      Begin VB.Label lbl_view 
         Caption         =   "#View"
         Height          =   195
         Left            =   60
         TabIndex        =   79
         Tag             =   "lbl_view"
         Top             =   2070
         Width           =   495
      End
   End
End
Attribute VB_Name = "Capact"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Enum ArmErr
    DBCnxFailed = vbObjectError + 1             ' Unable to connect to the database
    CPTAlreadyInitialized = vbObjectError + 2   ' We try to initialize a component that is already initialized
    CPTNotInitialized = vbObjectError + 3       ' We try to use or free that is not initialized yet
    InvalidArgument = vbObjectError + 4
    PropertyNotSet = vbObjectError + 5
    SQLFailure = vbObjectError + 6               ' A SQL runtime error has occured : syntax wrong....
    SQLBadRowAffectedCount = vbObjectError + 7   ' A SQL request has not affected the expected rowcount (ex: one Update do nothing)
    SQLBadRowExpectedCount = vbObjectError + 8   ' A SQL request does not return the expected rowcount : select an item return nothing...
    DrivingError = vbObjectError + 9
    CompFncFailed = vbObjectError + 10           ' when component function fail
    GridLoadFailed = vbObjectError + 11          ' load function failed ... bad sql
    QuietException = vbObjectError + 12          ' do not display error message
    SQLTableReferenceConstraint = vbObjectError + 13 ' A SQL request cannot be executed : Table reference constraint
    DuplicityDetected = vbObjectError + 2301     ' detected row with same unique id
End Enum

Private Const SEP As String = "®©"

Private Const FollowUpColor As Long = 10088089            ' # 99EE99
Private Const FollowUpColorExpired As Long = 10066414     ' # EE9999

' BEGIN T298.WP7
Private Const TVI_STATE_NONE As Long = 0
Private Const TVI_STATE_UNCHECKED As Long = 7
Private Const TVI_STATE_CHECKED As Long = 8
Private Const TVI_STATE_GRAYED As Long = 9
' BEGIN T298.WP7

Private Enum ActionStatus
    AS_COMPLETE = 1
    AS_OUTSTANDING = 2
End Enum

Const C_CKV_CATEGORY_COL As Long = 1
Const C_CKV_GROUP_COL As Long = 2
Const C_CKV_QTY_COL As Long = 3
Const C_CKV_QTY_SENT_COL As Long = 4
Const C_CKV_HF_COL As Long = 5
Const C_CKV_EdgeDetailCode_COL As Long = 6
Const C_CKV_EdgeDetailDesc_COL As Long = 7
Const C_CKV_Comment_COL As Long = 8
Const C_CKV_QTY_STOCK_COL As Long = 9


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

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

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

'298.8_Isa Begin1
Private ml_FollowUpDateIncrement As Long 'Number of days for the grid My Action to follow up
Private ms_lbl_ListFilter As String 'label list filters for the My actions follow up
Private md_DateUntil As Date  'label list filters for the My actions follow up
'298.8_Isa End1

'******** Clé en cours (enreg. en cours de visu ou modif ou delete
Private m_CurrentKey1 As String
Private m_CurrentKey2 As String
Private m_CurrentKey3 As String

Private ms_CustomerCountry As String

Private m_Language As String

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

'******** Type of object to limit initialization and connection of tree view
'******** when opening short list list for ex. (1=Normal, liste longue; 2=Liste courte)
Private mi_TypeList As Integer
Private mi_TypeParam As Integer

Private m_Project As String 'For the property .Project, display in ShortList
Private m_Customer As String 'For the property .Customer, display in ShortList
Private m_Memo As String 'For the property .Memo, display in ShortList
Private m_Contact As String 'For the property .Contact, display in ShortList
Private m_Product As String 'For the property .Product, display in ShortList
Private mb_EmbeddedIsDropped As Boolean ' Task  298.2
Private mb_gridInitializedForFollowUP As Boolean    ' indicate grid is initialized after start of control


' Ask the application to change the size of component
Public Event SwitchToView(ByVal li_View As Integer)

' Ask the application to simulate encapsulation of a component by resizing it and push it to front
Public Event Catch(ByVal li_TagEmbedded As Integer, ByVal ls_Param As String)
' Ask the application to release the encapsulation : hide the component embedded
Public Event Release()
Public Event quit()
Public Event HideGrid(AParentID As Integer)

Public Event Updated() ' Indicates if user update date when it's embedded
Public Event UnlockNavigation()


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

Private m_CCU_CT_Code As String
Private m_CCU_CT_Desc As String
Private m_CCU_CCT_Code As String
Private m_CCU_CCT_Desc As String
Private m_CCU_SR_Code As String
Private m_CCU_SR_Name As String

Public mb_CycleReset As Boolean

Private ms_View_Key As String


Public Property Set ArmDb(ByRef lo_local_connection As Object)
    
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ArmDb_Set"
    #End If
    CapMouseOff
    
    If Not (lo_local_connection Is Nothing) Then
        Set mo_ArmDb = lo_local_connection
        mb_use_framework_connection = True
        
        
            Set grdlst.ArmDb = mo_ArmDb
        
        Set pblst.ArmDb = mo_ArmDb
        Set pbitem.ArmDb = mo_ArmDb
        Set tvitems.ArmDb = mo_ArmDb
        Set srch_customer.ArmDb = mo_ArmDb
        Set srch_contact.ArmDb = mo_ArmDb
        Set srch_project.ArmDb = mo_ArmDb
        Set CkvProduct.ArmDb = mo_ArmDb
        Set ckv_Sample.ArmDb = mo_ArmDb
        ' BEGIN T298.WP7
        Set tvw_Sample.ArmDb = mo_ArmDb
        ' END T298.WP7

        Set cbo_actionType.ArmDb = mo_ArmDb
        Set cbo_raisedFor.ArmDb = mo_ArmDb
        Set cbo_status.ArmDb = mo_ArmDb
        Set cbo_letterType.ArmDb = mo_ArmDb
        Set cbo_Reason.ArmDb = mo_ArmDb
        Set cbo_UOM.ArmDb = mo_ArmDb
        Set cbo_View.ArmDb = mo_ArmDb
        Set cbo_date.ArmDb = mo_ArmDb
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ArmDb_Set"
    #End If
    CapMouseOn
End Property

Property Let ConnectString(as_ConnectString As String)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ConnectString_Set", "as_ConnectString=" & as_ConnectString
    #End If
    CapMouseOff
    
    ms_UID = ConnectionStringValidation(as_ConnectString)
    If ms_UID = "" Then GoTo Trace_End
    
    ms_ConnectString = as_ConnectString
    
    'Affectation aux objets
    grdlst.ConnectString = ms_ConnectString
    pblst.ConnectString = ms_ConnectString
    pbitem.ConnectString = ms_ConnectString
    tvitems.ConnectString = ms_ConnectString
    
    srch_customer.ConnectString = ms_ConnectString
    srch_contact.ConnectString = ms_ConnectString
    srch_project.ConnectString = ms_ConnectString
    
    CkvProduct.ConnectString = ms_ConnectString
    
    ckv_Sample.ConnectString = ms_ConnectString
    ' BEGIN T298.WP7
    tvw_Sample.ConnectString = ms_ConnectString
    ' END T298.WP7
    
    cbo_actionType.ConnectString = ms_ConnectString
    cbo_raisedFor.ConnectString = ms_ConnectString
    cbo_status.ConnectString = ms_ConnectString
    cbo_letterType.ConnectString = ms_ConnectString
    cbo_Reason.ConnectString = ms_ConnectString
    cbo_UOM.ConnectString = ms_ConnectString
    cbo_View.ConnectString = ms_ConnectString
    cbo_date.ConnectString = ms_ConnectString
        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ConnectString_Set"
    #End If
    CapMouseOn
End Property

Property Let Language(as_Language As String)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Language_Set", "as_Language=" & as_Language
    #End If
    CapMouseOff
    
    m_Language = as_Language
    
    CkvProduct.Language = m_Language
    ckv_Sample.Language = m_Language
    ' BEGIN T298.WP7
    tvw_Sample.Language = m_Language
    ' END T298.WP7

    'grdlst.Language = m_Language
    tvitems.Language = m_Language
    pbitem.Language = m_Language
    pblst.Language = m_Language
    srch_contact.Language = m_Language
    srch_customer.Language = m_Language
    srch_project.Language = m_Language
    cal_dueDate.Language = m_Language
    cal11.Language = m_Language
    cal12.Language = m_Language
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Language_Set"
    #End If
    CapMouseOn
End Property

Private Sub CboView_Resize(ALabel As Label, ACboView As Object, AFrame As Frame)
Dim LMargin As Integer

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:CboView_Resize", "ALabel=" & ALabel
    #End If
    
    LMargin = 100
    
    ALabel.AutoSize = True
    ALabel.Left = LMargin
    ACboView.Left = ALabel.Left + ALabel.Width + LMargin
    ACboView.Width = AFrame.Width - ACboView.Left - LMargin
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:CboView_Resize"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:CboView_Resize"
    CapMouseOn
End Sub

Private Sub cbo_date_ComboItemSelected()

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

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

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

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

    pblst.ClearAllIcons
    pblst.TableName = mt_CstValues.SecurityAction
    pblst.PictureDisplayed = "P_Refresh=7 P_Excel=-3 P_View=-4 P_Quit=-1"
    
    'Grille
    grdlst.ResetGrid
    grdlst.Title = "Action"
    grdlst.MultiSelect = True
    
    'Dates
    cal11.Zorder 0
    cal12.Zorder 0
    cal11.Limited_as_embedded = 1
    cal12.Limited_as_embedded = 1
    
    'Grille
    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"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_action_longlist', 'grid', '" & m_Language & "'", ctColumns
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:DrawMainGrid"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:DrawMainGrid"
    CapMouseOn
End Sub

Public Sub GoToTab1()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:GoToTab1"
    #End If
    
    If UserControl.tbsEmbedded.Tabs.Count > 0 Then
        UserControl.tbsEmbedded.Tabs(1).Selected = True
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:GoToTab1"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:GoToTab1"
    CapMouseOn
End Sub

Private Sub InitCkvProduct()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:InitCkvProduct"
    #End If
    
    CkvProduct.Visible = False
    
    Dim a As Double, b As Double
    
    a = timer
    
    CkvProduct.Clear
      
    Select Case mi_DisplayMode
    
        Case mt_CstValues.DisplayMode_Add
            CkvProduct.EditRequest = "exec Cap_ActionProduct_lst2 '" & m_Language & "'" & ", '" & ms_CustomerCountry & "'"
            CkvProduct.MasterID = ""
            CkvProduct.Mode = ListLoadMode.ModeEdit
            
        Case mt_CstValues.DisplayMode_Update
            CkvProduct.ViewRequest = "exec Cap_ActionProduct_lst $0$ , '" & srch_customer.Key1 & "', '" & m_Language & "'"
            CkvProduct.MasterID = m_CurrentKey1
            CkvProduct.Mode = ListLoadMode.ModeView
        
        Case mt_CstValues.DisplayMode_Delete, mt_CstValues.DisplayMode_View
            CkvProduct.ViewRequest = "exec Cap_ActionProduct_lst $0$ , '" & srch_customer.Key1 & "', '" & m_Language & "'"
            CkvProduct.MasterID = m_CurrentKey1
            CkvProduct.Mode = ListLoadMode.ModeView
        
    End Select
       
    CkvProduct.Columns = 3
    CkvProduct.ShowHeader = True
    CkvProduct.HeaderNames = Array("Code", "", "Description")
    CkvProduct.HeaderSizes = Array(1000, 0, 5000)
       
    CkvProduct.LoadList
    
    b = timer - a
    Call AddToTimeLog(8, b)

Trace_End:
    CkvProduct.Visible = True
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:InitCkvProduct"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    CkvProduct.Visible = True
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:InitCkvProduct"
    CapMouseOn
End Sub

Private Sub RefreshCKV_StockSample(ByVal al_SDP_Code As Long)
    On Error GoTo Trace_Err
    Const C_REQ As String = "EXEC Cap_SampleDoc_Department_lst2 $SDP_CODE$"
    
    Dim ll_Cursor As Long
    ll_Cursor = mo_ArmDb.OpenSQL(Replace(C_REQ, "$SDP_CODE$", al_SDP_Code, , , vbTextCompare))
    
    Dim ll_i As Long
    For ll_i = 0 To ckv_Sample.Count - 1
    
        If mo_ArmDb.Find(ll_Cursor, "SD_Code", ckv_Sample.ItemInfo(ll_i).Id, 0) >= 0 Then
            Call ckv_Sample.ItemInfo(ll_i).SetData(C_CKV_QTY_STOCK_COL, mo_ArmDb.GetFields(ll_Cursor, "SD_Qty"))
        Else
            Call ckv_Sample.ItemInfo(ll_i).SetData(C_CKV_QTY_STOCK_COL, 0)
        End If
        
        ' update subitem
        ckv_Sample.ListItems(ll_i + 1).ListSubItems(C_CKV_QTY_STOCK_COL + 1).Text = ckv_Sample.ItemInfo(ll_i).GetData(C_CKV_QTY_STOCK_COL)
    Next
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0
    
    Exit Sub
Trace_Err:
    If ll_Cursor <> 0 Then
        Call mo_ArmDb.Close(ll_Cursor)
        ll_Cursor = 0
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:RefreshCKV_StockSample"
End Sub

Private Sub InitCkvSample()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:InitCkvSample"
    #End If
    
    ckv_Sample.Visible = False
    ' BEGIN T298.WP7
    tvw_Sample.Visible = False
    ' END T298.WP7
    
    Dim a As Double, b As Double
    
    a = timer
    
    ckv_Sample.Clear
    ' BEGIN T298.WP7
    tvw_Sample.Clear
      
    Select Case mi_DisplayMode
    
        Case mt_CstValues.DisplayMode_Add
            ckv_Sample.EditRequest = "exec Cap_ActionSampleDoc_t_lst2 " & GetCodeFromCombo(cbo_actionType) & ", '" & m_Language & "'" & ", " & IIf(RaisedByStockDepartment() <> 0, "null", "'" & ms_CustomerCountry & "'") & ", " & RaisedForStockDepartment()
            ckv_Sample.MasterID = ""
            ckv_Sample.Mode = ListLoadMode.ModeEdit
            ckv_Sample.Columns = 11
        Case mt_CstValues.DisplayMode_Update
            ckv_Sample.ViewRequest = "exec Cap_ActionSampleDoc_t_lst $0$ , '" & srch_customer.Key1 & "', " & RaisedForStockDepartment() & ",'" & m_Language & "'"
            ckv_Sample.MasterID = m_CurrentKey1
            ckv_Sample.Mode = ListLoadMode.ModeView
            ckv_Sample.Columns = 11
        Case mt_CstValues.DisplayMode_Delete, mt_CstValues.DisplayMode_View
            ckv_Sample.ViewRequest = "exec Cap_ActionSampleDoc_t_lst $0$ , '" & srch_customer.Key1 & "', " & RaisedForStockDepartment() & ", '" & m_Language & "'"
            ckv_Sample.MasterID = m_CurrentKey1
            ckv_Sample.Mode = ListLoadMode.ModeView
            ckv_Sample.Columns = 11
    End Select
       
    ckv_Sample.ShowHeader = True
    ckv_Sample.HeaderNames = Array("Description", "", "Category", "Group", "Quantity", "Quantity sent", "Hand/Full", "", "Edge", "Comment", "Stock dpt " & RaisedForStockDepartment())
    
    If Tools.GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeSample) Then
        ckv_Sample.HeaderSizes = Array(100, 0, 0, 0, 800, 800, 900, 0, 1000, 4000, 10)
    ElseIf UCase$(GetBUGroupFromCombo(cbo_actionType)) = "DISPATCH" Then
        ckv_Sample.HeaderSizes = Array(100, 0, 0, 0, 800, 800, 0, 0, 1000, 4000, 10)
    Else
        ckv_Sample.HeaderSizes = Array(1800, 0, 0, 0, 800, 800, 0, 0, 0, 4000, 10)
    End If
    ' END T298.WP7
    
    ckv_Sample.LoadList
    b = timer - a
    Call AddToTimeLog(7, b)
    
Trace_End:
    ckv_Sample.Visible = True
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:InitCkvSample"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    ckv_Sample.Visible = True
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:InitCkvSample"
    CapMouseOn
End Sub

' BEGIN T298.WP7
Private Sub InitTvwSample()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:InitTvwSample"
    #End If
    
    tvw_Sample.Visible = False
    ckv_Sample.Visible = False
    
    Dim a As Double, b As Double
    
    a = timer
    
    tvw_Sample.Clear
    ckv_Sample.Clear
      
    Select Case mi_DisplayMode
    
        Case mt_CstValues.DisplayMode_Add
            tvw_Sample.Levels = 3
            tvw_Sample.Images = Array(1, 1, 3)
            tvw_Sample.SelectedImages = Array(2, 2, 3)
            tvw_Sample.UseImages = True
            tvw_Sample.Checkboxes = True
            tvw_Sample.NodeRequests = Array("exec CapTv_ActionSampleDoc_a1 '" & m_Language & "','" & ms_CustomerCountry & "'", _
                                            "exec CapTv_ActionSampleDoc_a2 $0$, '" & m_Language & "'" & ", '" & ms_CustomerCountry & "'", _
                                            "exec CapTv_ActionSampleDoc_a3 $0@0$, $0$," & RaisedForStockDepartment() & " ,'" & m_Language & "'" & ", '" & ms_CustomerCountry & "'")
    End Select
       
    Call tvw_Sample.LoadTree(LoadTypeChildsDemand)
    b = timer - a
    Call AddToTimeLog(7, b)
    
Trace_End:
    tvw_Sample.Visible = True
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:InitTvwSample"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    tvw_Sample.Visible = True
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:InitTvwSample"
    CapMouseOn
End Sub
' END T298.WP7

Private Sub InitParentKey()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:InitParentKey"
    #End If
    
    m_Project = ""
    m_Customer = ""
    m_Memo = ""
    m_Contact = ""
    m_Product = ""
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:InitParentKey"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:InitParentKey"
    CapMouseOn
End Sub

Private Function SaveCkvProduct(ms_ActionCode As String) As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:SaveCkvProduct", "ms_ActionCode=" & ms_ActionCode
    #End If
    
    SaveCkvProduct = False
    
    CkvProduct.CheckRequest = "exec Cap_ActionProduct_ins $0$, '" & srch_customer.Key1 & "', $1$ , '','',null, null,null,null,null"
    CkvProduct.UnCheckRequest = "exec Cap_ActionProduct_del $0$, '" & srch_customer.Key1 & "', $1$ "
    CkvProduct.MasterID = ms_ActionCode

    SaveCkvProduct = CkvProduct.SaveList

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

' BEGIN T298.WP7
Private Function SaveTvwSample(as_ActionCode As String) As Boolean
Dim ll_Index As Long
Dim ls_Request As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    
    SaveTvwSample = False
    For ll_Index = 1 To tvw_Sample.Count
        If (tvw_Sample.Nodes(ll_Index).Tag.ml_Level = 2) And (tvw_Sample.Nodes(ll_Index).Tag.ml_State = 8) Then
            ls_Request = "exec Cap_ActionSampleDoc_ins "
            ls_Request = ls_Request & Tools.FormatSqlStringParameter(as_ActionCode) & ","
            ls_Request = ls_Request & Tools.FormatSqlStringParameter(srch_customer.Key1) & ","
            ls_Request = ls_Request & tvw_Sample.Nodes(ll_Index).Tag.GetData(0) & ","
            ls_Request = ls_Request & Tools.FormatSqlStringParameter(tvw_Sample.Nodes(ll_Index).Tag.GetData(5)) & ","
            ls_Request = ls_Request & tvw_Sample.Nodes(ll_Index).Tag.GetData(3) & ","
            ls_Request = ls_Request & Tools.FormatSqlStringParameter(tvw_Sample.Nodes(ll_Index).Tag.GetData(4)) & ","
            ls_Request = ls_Request & Tools.FormatSqlStringParameter(tvw_Sample.Nodes(ll_Index).Tag.GetData(7)) & ","
            ls_Request = ls_Request & tvw_Sample.Nodes(ll_Index).Tag.GetData(8)
            If Not mo_ArmDb.ExecuteSQL(ls_Request) Then
                CapMouseOn
                Exit Function
            End If
        End If
    Next

    SaveTvwSample = True

Trace_End:
    CapMouseOn
    Exit Function
    
Trace_Err:
    SaveTvwSample = False
    CapMouseOn
End Function
' END T298.WP7

Private Function SaveCkvSample(as_ActionCode As String, ByVal al_stockCursor As Long) As Boolean
    
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:SaveCkvSample", "as_ActionCode=" & as_ActionCode
    #End If
    
    SaveCkvSample = False
    
    ' END T298.WP7
    ckv_Sample.UnCheckRequest = ""
    ckv_Sample.MasterID = as_ActionCode
    
    If ckv_Sample.Mode = ModeEdit Then
    ' BEGIN T298.WP7
        ckv_Sample.CheckRequest = "exec Cap_ActionSampleDoc_ins $0$, '" & srch_customer.Key1 & "', $1$,$7$,$4$,$6$,$9$,$5$"
        SaveCkvSample = ckv_Sample.SaveList
    Else
        ' have to update manually row by row
        Dim ll_Count As Long
        Dim ls_Request As String
        For ll_Count = 0 To ckv_Sample.Count - 1
            If ckv_Sample.ItemInfo(ll_Count).DataChanged Then
                ls_Request = "exec Cap_ActionSampleDoc_upd '" & as_ActionCode & "','" & srch_customer.Key1 & "'," & ckv_Sample.ItemInfo(ll_Count).Id & "," & FormatSqlStringParameter(ckv_Sample.ItemInfo(ll_Count).GetData(C_CKV_Comment_COL)) & "," & ckv_Sample.ItemInfo(ll_Count).GetData(C_CKV_QTY_SENT_COL)
                Dim ls_Result As String
                If Not ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False) Then
                    GoTo Trace_Err
                End If
            End If
                
                If al_stockCursor <> 0 Then
                    ' remove from stock + generate new transaction
                    Dim ld_qtyToAdd As Double
                    ld_qtyToAdd = -ckv_Sample.ItemInfo(ll_Count).GetData(C_CKV_QTY_SENT_COL)
                    
                    ' chcek in transaction if there was some adding before
                    If mo_ArmDb.Find(al_stockCursor, Array("SD_code"), Array(ckv_Sample.ItemInfo(ll_Count).Id)) >= 0 Then
                        ld_qtyToAdd = ld_qtyToAdd - mo_ArmDb.GetFields(al_stockCursor, "Tran_Qty")
                    End If
                    
                    ' if there is a change then update stock into database + generate new transaction
                    If ld_qtyToAdd <> 0 Then
                        Dim ll_rep_U_Code As Long
                        ll_rep_U_Code = cbo_raisedFor.SelectedItem.GetData(3)
                        
                        Dim ll_SPD_Code As Long
                        ll_SPD_Code = RaisedForStockDepartment()
                        Debug.Assert (ll_SPD_Code <> 0)             ' if we are here we have to know stock departemnt of a raiserFor
                        
                        mo_ArmDb.ExecuteSQL ("EXEC Cap_SampleDoc_Department_upd2 " & ckv_Sample.ItemInfo(ll_Count).Id & "," & ll_SPD_Code & "," & ld_qtyToAdd & ", " & ll_rep_U_Code)
                        
                        ' add transaction
                        mo_ArmDb.ExecuteSQL ("EXEC Cap_SampleDoc_Transaction_ins '" & as_ActionCode & "'," & ckv_Sample.ItemInfo(ll_Count).Id & ", " & ll_SPD_Code & "," & ld_qtyToAdd & "," & (ckv_Sample.ItemInfo(ll_Count).GetData(C_CKV_QTY_STOCK_COL) + ld_qtyToAdd) & "," & ll_rep_U_Code)
                        
                        ' update local data
                        Call ckv_Sample.ItemInfo(ll_Count).SetData(C_CKV_QTY_STOCK_COL, ckv_Sample.ItemInfo(ll_Count).GetData(C_CKV_QTY_STOCK_COL) + ld_qtyToAdd)
                        ckv_Sample.ListItems(ll_Count + 1).ListSubItems(C_CKV_QTY_STOCK_COL + 1).Text = ckv_Sample.ItemInfo(ll_Count).GetData(C_CKV_QTY_STOCK_COL)
                    End If

                End If
        Next
        SaveCkvSample = True
    End If


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

Private Sub cbo_actionType_ComboItemSelected()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:cbo_actionType_ComboItemSelected"
    #End If
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeReportedM2MSC) Then
        lbl_product.FontBold = True
        lbl_size.FontBold = True
    Else
        lbl_product.FontBold = False
        lbl_size.FontBold = False
    End If
    
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
        Debug.Assert (DisplayMode = mt_CstValues.DisplayMode_Add)
        InitTvwSample
        lbl_sample.FontBold = tvw_Sample.Count > 0
    Else

        InitCkvSample
        lbl_sample.FontBold = ckv_Sample.ListItems.Count > 0
    End If
    ' END T298.WP7
    
    If UCase$(GetBUGroupFromCombo(cbo_actionType)) = "DISPATCH" Then
        LetterTypeVisible True
    Else
        LetterTypeVisible False
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:cbo_actionType_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:cbo_actionType_ComboItemSelected"
    CapMouseOn
End Sub

Private Sub LetterTypeVisible(ab_Visible As Boolean)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:LetterTypeVisible", "ab_visible=" & ab_Visible
    #End If
    
    lbl_letterType.Enabled = ab_Visible
    cbo_letterType.Enabled = ab_Visible
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:LetterTypeVisible"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:LetterTypeVisible"
    CapMouseOn
End Sub

Function RecordAdd() As Boolean
Dim ls_Request As String
Dim ls_Request2 As String
Dim ls_ActionCode As String
Dim ll_Cursor As Long
Dim lb_size As Boolean
Dim lb_Result As Boolean
Dim ls_Result As String
Dim ll_Count As Long
Dim ls_MEM_Code As String


    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:RecordAdd"
    #End If
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeReportedM2MSC) Then
    ' END T298.WP7
        If CkvProduct.CheckedCount = 0 Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
            CkvProduct.SetFocus
            GoTo Trace_End
        End If
        lb_size = True
    Else
        lb_size = False
    End If
    
    If Not cbo_actionType.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ActionType_chk " & GetCodeFromCombo(cbo_actionType) & ",'" & ms_CustomerCountry & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_actionType.Caption & " : " & cbo_actionType.SelectedItem.DisplayText)
                cbo_actionType.SetFocus
            GoTo Trace_End
        End If
        End If
            End If
            
    If Not cbo_Reason.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ActionReason_chk " & GetCodeFromCombo(cbo_Reason) & ",'" & ms_CustomerCountry & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_reason.Caption & " : " & cbo_Reason.SelectedItem.DisplayText)
                cbo_Reason.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If Not cbo_letterType.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_letterType) <> "" Then
            ls_Request = "Exec Cap_LetterType_chk " & GetCodeFromCombo(cbo_letterType) & ",'" & ms_CustomerCountry & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_letterType.Caption & " : " & cbo_letterType.SelectedItem.DisplayText)
                    cbo_letterType.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    End If
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
        For ll_Count = 0 To tvw_Sample.Count - 1
            If (tvw_Sample.Nodes(ll_Count + 1).Tag.ml_Level = 2) And (tvw_Sample.Nodes(ll_Count + 1).Tag.ml_State = 8) Then
                ls_Request = "Exec Cap_ActionSampleDoc_chk " & tvw_Sample.Nodes(ll_Count + 1).Tag.IDValue & ",'" & ms_CustomerCountry & "'"
                lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
                If lb_Result Then
                    If Mid(ls_Result, 1, 1) = "~" Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_sample.Caption & " : " & tvw_Sample.Nodes(ll_Count + 1).Text)
                        tvw_Sample.Nodes(ll_Count + 1).Selected = True
                        tvw_Sample.Nodes(ll_Count + 1).EnsureVisible
                        tvw_Sample.SetFocus
                        GoTo Trace_End
                    End If
                End If
            End If
        Next
    Else
    For ll_Count = 1 To ckv_Sample.Count
        If ckv_Sample.ListItems(ll_Count).Checked = True Then
            ls_Request = "Exec Cap_ActionSampleDoc_chk " & ckv_Sample.ListItems(ll_Count).Tag.Id & ",'" & ms_CustomerCountry & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_sample.Caption & " : " & ckv_Sample.ListItems(ll_Count).Text)
                    ckv_Sample.ListItems(ll_Count).Selected = True
                    ckv_Sample.SelectedItem.EnsureVisible
                    ckv_Sample.SelectedItem.Ghosted = True
                    ckv_Sample.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    Next
    End If
    ' END T298.WP7
            
' IMPLEMENT PROCESS T298.5-A.PR_003
' CALL PROCESS T298.5-A.PR_001
    If Not ValidateActionDate Then
        Call cal_dueDate.SetFocus
        GoTo Trace_End
    End If
' END PROCESS T298.5-A.PR_003
            
    ErrorOFF
    
    ls_ActionCode = mo_ArmDb.SQLNextID("Cap_Action")
    If ls_ActionCode = "" Then Call Err.Raise(ArmErr.SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Cap_Action"") return nothing.")
    
    ls_MEM_Code = mo_ArmDb.SQLNextID("Cap_Memo")
    If ls_MEM_Code = "" Then Call Err.Raise(ArmErr.SQLFailure, "", "SQL Error: mo_ArmDb.SQLNextID(""Cap_Memo"") return nothing.")
    
    ls_Request = "Exec Cap_Action_ins "
                
    ls_Request = ls_Request & "  " & CorrectKeyStr(mo_ArmDb, m_Language, srch_customer, True) '@CCU_CapKey char (16),
    ls_Request = ls_Request & ", " & CorrectKeyStr(mo_ArmDb, m_Language, srch_contact) '
    ls_Request = ls_Request & ", " & CorrectKeyStr(mo_ArmDb, m_Language, srch_project) '
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_actionType, True) '@AT_code int ,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_status, True) '@AS_code int ,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_letterType, False) '@LT_code int ,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_raisedFor, True) '@ACT_raisedFor char (30),
'    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_Comment) '@ACT_comment varchar (255),     ' task 299.3
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Reason, True) '@AR_code int ,
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_dueDate, True) '@ACT_dueDate datetime ,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_size, lb_size) '@ACT_size real ,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_UOM, IIf(Trim$(txt_size.Text) = "", False, True)) '@UM_code char (5),
    ls_Request = ls_Request & ", " & "NULL" 'Correct() '@AC_desc varchar (80),
    ls_Request = ls_Request & ", " & "''" '@Internet CHAR(1),
    ls_Request = ls_Request & ", " & "''" '@Drop CHAR(1),
    ls_Request = ls_Request & ", " & "NULL" '@Drop_date DATETIME,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1) '@spare1_varchar VARCHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2) '@spare2_varchar VARCHAR(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3) '@spare3_real REAL,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare4) '@spare4_real REAL
    ls_Request = ls_Request & ", " & "'" & ls_ActionCode & "'"
    
    ' BEGIN T298.WP7
    If Not ErrorFound Then
        If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
            If tvw_Sample.Count > 0 And GetCheckedNodesCount(tvw_Sample, 2) = 0 Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 274, "#You must choose at least one sample")
                tvw_Sample.SetFocus
                GoTo Trace_End
            End If
        Else
            If ckv_Sample.Count > 0 And ckv_Sample.CheckedCount = 0 Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 274, "#You must choose at least one sample")
        ckv_Sample.SetFocus
        GoTo Trace_End
    End If
        End If
    End If
    ' END T298.WP7
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    'Execution
    If ErrorFound Then GoTo Trace_End
    
    Dim lb_Transaction As Boolean
    ASC_BeginTransaction mo_ArmDb
    lb_Transaction = True

    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_ActionCode)
    
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        lb_Transaction = False
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support", "DB insert")
        GoTo Trace_Err
    End If
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
        If tvw_Sample.Count > 0 Then lb_Result = SaveTvwSample(ls_ActionCode)
    Else
        If ckv_Sample.Count > 0 Then lb_Result = SaveCkvSample(ls_ActionCode, 0)
    End If
    
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        lb_Transaction = False
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support", "DB sample insert")
        GoTo Trace_Err
    End If
    ' END T298.WP7
    
    lb_Result = SaveCkvProduct(ls_ActionCode)
    
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        lb_Transaction = False
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support", "DB product insert")
        GoTo Trace_Err
    End If
    
' task 299.3 begin
Const REQins = "EXEC Cap_Memo_ins 'E', $Comment_desc$, $Comment$, 'N', 'N', Null, '$AC_CODE$', '', 2, 0, '$MEM_Code$'"
    ' insert into cap_memo only 'E' language record, memo type=2(spare3_real)
        ls_Request = Replace(REQins, "$Comment_desc$", FormatSqlStringParameter(Left(txt_comment.Text, 80)))
        ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_comment.Text))
        ls_Request = Replace(ls_Request, "$AC_CODE$", ls_ActionCode)
        ls_Request = Replace(ls_Request, "$MEM_Code$", ls_MEM_Code)
        
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_MEM_Code)
        If lb_Result = False Then
            ASC_RollBackTransaction mo_ArmDb
            lb_Transaction = False
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support", "DB memo insert")
            GoTo Trace_Err
        End If
' task 299.3 end

'ISA_TASK 298.12 BEGIN
    Const REQCapRepSel = "EXEC Cap_CompanyRepCopy_chk '$SR_code$','$CCU_CapKey$'"
    Const REQCapRepIns = "EXEC Cap_CompanyRep_Ins '$CCU_Capkey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0"
    Dim ls_req As String
    Dim ll_curs As Long
    Dim ll_NbRec As Long
    If GetCodeFromCombo(cbo_raisedFor) <> "" Then
        If cbo_raisedFor.SelectedItem.GetData(2) <> "" Then
            ls_req = REQCapRepSel
            ls_req = Replace(ls_req, "$SR_code$", cbo_raisedFor.SelectedItem.GetData(2), , , vbTextCompare)
            ls_req = Replace(ls_req, "'$CCU_CapKey$'", CorrectKeyStr(mo_ArmDb, m_Language, srch_customer, True), , , vbTextCompare)
            
            ll_curs = mo_ArmDb.OpenSQL(ls_req)
            
            If ll_curs = 0 Then
                ASC_RollBackTransaction mo_ArmDb
                lb_Transaction = False
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support", "cap Rep selection")
                GoTo Trace_Err
            End If
            ll_NbRec = mo_ArmDb.RowCount(ll_curs)
            mo_ArmDb.Close (ll_curs)
            If ll_NbRec = 0 Then
                ls_req = REQCapRepIns
                ls_req = Replace(ls_req, "'$CCU_CapKey$'", CorrectKeyStr(mo_ArmDb, m_Language, srch_customer, True), , , vbTextCompare)
                ls_req = Replace(ls_req, "$SR_code$", cbo_raisedFor.SelectedItem.GetData(2), , , vbTextCompare)
                ls_req = Replace(ls_req, "$RR_code$", "3", , , vbTextCompare)

                If Not mo_ArmDb.ExecuteSQL(ls_req) Then
                    ASC_RollBackTransaction mo_ArmDb
                    lb_Transaction = False
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support", "cap Rep insertion")
                    GoTo Trace_Err
                End If
            End If
        End If
    End If
'ISA_TASK 298.12 BEGIN

    m_CurrentKey1 = ls_ActionCode
    m_CurrentKey2 = srch_customer.Key1
    
    ASC_CommitTransaction mo_ArmDb
    lb_Transaction = False
    RecordAdd = True
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:RecordAdd", "Result=" & RecordAdd
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If lb_Transaction Then
        ASC_RollBackTransaction mo_ArmDb
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:RecordAdd"
    CapMouseOn
End Function

Function RecordUpdate(ACode1 As String, ACode2 As String) As Boolean
Dim ls_Request As String
Dim ls_ReturnCode As String
Dim lb_size As Boolean
Dim lb_Result As Boolean
Dim ls_Result As String
Dim ll_Count As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:RecordUpdate"
    #End If
    
    RecordUpdate = False

    If Not (Trim$(ACode1) <> "" And Trim$(ACode2) <> "") Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If

    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeReportedM2MSC) Then
        lb_size = True
    Else
        lb_size = False
    End If
    ' END T298.WP7
    
    If Not cbo_actionType.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ActionType_chk " & GetCodeFromCombo(cbo_actionType) & ",'" & ms_CustomerCountry & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_actionType.Caption & " : " & cbo_actionType.SelectedItem.DisplayText)
                cbo_actionType.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If Not cbo_Reason.SelectedItem Is Nothing Then
        ls_Request = "Exec Cap_ActionReason_chk " & GetCodeFromCombo(cbo_Reason) & ",'" & ms_CustomerCountry & "'"
        lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
        If lb_Result Then
            If Mid(ls_Result, 1, 1) = "~" Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_reason.Caption & " : " & cbo_Reason.SelectedItem.DisplayText)
                cbo_Reason.SetFocus
                GoTo Trace_End
            End If
        End If
    End If
    
    If Not cbo_letterType.SelectedItem Is Nothing Then
        If GetCodeFromCombo(cbo_letterType) <> "" Then
            ls_Request = "Exec Cap_LetterType_chk " & GetCodeFromCombo(cbo_letterType) & ",'" & ms_CustomerCountry & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_letterType.Caption & " : " & cbo_letterType.SelectedItem.DisplayText)
                    cbo_letterType.SetFocus
                    GoTo Trace_End
                End If
            End If
        End If
    End If
    
    Dim ls_samplesReport As String
    ls_samplesReport = ""
    Dim lb_stockCompletition As Boolean
    Dim ll_SPD_Code As Long
    ll_SPD_Code = RaisedForStockDepartment()
    lb_stockCompletition = (GetCodeFromCombo(cbo_status) = ActionStatus.AS_COMPLETE And (ll_SPD_Code <> 0))
    
    Dim ll_stockCursor As Long
    ll_stockCursor = 0
    ' check if sample is on stock
    If lb_stockCompletition Then
        ll_stockCursor = mo_ArmDb.OpenSQL("EXEC Cap_SampleDoc_Transaction_lst '" & ACode1 & "'")
        If ll_stockCursor = 0 Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 992, "#Failed to execute the transaction list")
            GoTo Trace_End
        End If
        
        
        ' check if action was not completing by another stock department
        While Not mo_ArmDb.EOF(ll_stockCursor)
            If ll_SPD_Code <> mo_ArmDb.GetFields(ll_stockCursor, "SDP_Code") Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 993, "#This action was completed by different Stock department!", "", vbCritical)
                GoTo Trace_End
            End If
            Call mo_ArmDb.Next(ll_stockCursor)
        Wend
        
        Call mo_ArmDb.First(ll_stockCursor)
    End If
    
    Dim lo_ItemInfo As ItemInfo
    Dim ll_qtyToSent As Long
    For ll_Count = 1 To ckv_Sample.Count
        If ckv_Sample.ListItems(ll_Count).Checked = True Then
            ls_Request = "Exec Cap_ActionSampleDoc_chk " & ckv_Sample.ListItems(ll_Count).Tag.Id & ",'" & ms_CustomerCountry & "'"
            lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result, False)
            If lb_Result Then
                If Mid(ls_Result, 1, 1) = "~" Then
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 926, "#This data is not authorized for this country", lbl_sample.Caption & " : " & ckv_Sample.ListItems(ll_Count).Text)
                    ckv_Sample.ListItems(ll_Count).Selected = True
                    ckv_Sample.SelectedItem.EnsureVisible
                    ckv_Sample.SelectedItem.Ghosted = True
                    ckv_Sample.SetFocus
                    GoTo Trace_End
                End If
            End If
            
            If lb_stockCompletition Then
                Set lo_ItemInfo = ckv_Sample.ListItems(ll_Count).Tag
                ' if qty requested is not on the stock
                If CLng(lo_ItemInfo.GetData(C_CKV_QTY_STOCK_COL)) < CLng(lo_ItemInfo.GetData(C_CKV_QTY_COL)) Then
                    ls_samplesReport = ls_samplesReport & vbCrLf & ASC_MsgText(mo_ArmDb, m_Language, 975, "#Requested qty is not on the stock.") & " (" & lo_ItemInfo.Caption & ")"
                End If
                
                If CLng(lo_ItemInfo.GetData(C_CKV_QTY_SENT_COL)) <> CLng(lo_ItemInfo.GetData(C_CKV_QTY_COL)) Then
                    ls_samplesReport = ls_samplesReport & vbCrLf & ASC_MsgText(mo_ArmDb, m_Language, 976, "#Requested qty is not equal to qty sent.") & " (" & lo_ItemInfo.Caption & ")"
                End If
                
                ' get the transaction numbers from previouse completition
                ll_qtyToSent = CLng(lo_ItemInfo.GetData(C_CKV_QTY_SENT_COL))
                If mo_ArmDb.Find(ll_stockCursor, Array("SD_code"), Array(lo_ItemInfo.Id)) >= 0 Then
                    ll_qtyToSent = ll_qtyToSent + mo_ArmDb.GetFields(ll_stockCursor, "Tran_Qty")
                End If

                ' error mssage when qty sent is not on stock
                If ll_qtyToSent > CLng(lo_ItemInfo.GetData(C_CKV_QTY_STOCK_COL)) Then
                    
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 977, "#Qty to send is more than qty on stock!", lo_ItemInfo.Caption)
                    ckv_Sample.ListItems(ll_Count).Selected = True
                    ckv_Sample.SelectedItem.EnsureVisible
                    ckv_Sample.SelectedItem.Ghosted = True
                    ckv_Sample.SetFocus
                    GoTo Trace_End
                ElseIf CLng(lo_ItemInfo.GetData(C_CKV_QTY_SENT_COL)) = 0 Then
                    ls_samplesReport = IIf(ls_samplesReport = "", "", ls_samplesReport & vbCrLf) & ASC_MsgText(mo_ArmDb, m_Language, 978, "#Qty to sent is zero.") & " (" & lo_ItemInfo.Caption & ")"
                End If
            
            End If
        End If
    Next
    
    If ls_samplesReport <> "" Then
        Dim ll_msgResult As VbMsgBoxResult
        ll_msgResult = ASC_SendMessage(mo_ArmDb, m_Language, 979, "#Some warnings detected! Do you want to send action back to requestor?", ls_samplesReport, vbYesNoCancel)
        If ll_msgResult = vbCancel Then
            GoTo Trace_End
        End If
        
        If ll_msgResult = vbYes Then
            ' add warnings into comment field
            txt_comment.Text = txt_comment.Text & vbCrLf & ls_samplesReport
            
            ' move back to status outstanding
            If Not cbo_status.SearchItem(ActionStatus.AS_OUTSTANDING) Then
                cbo_status.Load
                Call cbo_status.SearchItem(ActionStatus.AS_OUTSTANDING)
            End If
            
            ' change raisedfor to requestor
            If Not cbo_raisedFor.SearchItem(txt_RaisedBy.Text) Then
                ' Try to load the combobox
                Call cbo_raisedFor.Load
                If Not cbo_raisedFor.SearchItem(txt_RaisedBy.Text) Then
                    ' User not found in the list!
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 980, "#Requestor not found inside pepole listed in Raised for.")
                End If
            End If
            
            ' change stock completition to false
            lb_stockCompletition = False
            Call mo_ArmDb.Close(ll_stockCursor)
            ll_stockCursor = 0
        End If
    End If
    
' IMPLEMENT PROCESS T298.5-A.PR_004
' CALL PROCESS T298.5-A.PR_001
    If Not ValidateActionDate Then
        Call cal_dueDate.SetFocus
        GoTo Trace_End
    End If
' END PROCESS T298.5-A.PR_004
    
    ' check if sample is on stock
    If lb_stockCompletition Then
        If ASC_SendMessage(mo_ArmDb, m_Language, 981, "#Do you want to remove selected quantity from the stock? (" & GetStockDptDesc(RaisedForStockDepartment()) & ")", , vbYesNo) = vbNo Then
            ' cancel saving the action
            GoTo Trace_End
        End If
    End If

    ErrorOFF

    ls_Request = "Exec Cap_Action_upd "
    
    ls_Request = ls_Request & "  " & "'" & ACode1 & "'" '@AC_code char(16) ,
    ls_Request = ls_Request & ", " & "'" & ACode2 & "'" '@CCU_CapKey char (16),
    ls_Request = ls_Request & ", " & p_iCon '@iConcurrency SMALLINT,
    ls_Request = ls_Request & ", " & CorrectKeyStr(mo_ArmDb, m_Language, srch_contact) '
    ls_Request = ls_Request & ", " & CorrectKeyStr(mo_ArmDb, m_Language, srch_project) '
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_actionType, True) '@AT_code int ,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_status, True) '@AS_code int ,
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_letterType, False) '@LT_code int ,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_raisedFor, True) '@ACT_raisedFor char (30),
'    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_comment) '@ACT_comment varchar (255),         ' task 299.3
    ls_Request = ls_Request & ", " & CorrectCodeInt(mo_ArmDb, m_Language, cbo_Reason, True) '@AR_code int ,
    ls_Request = ls_Request & ", " & CorrectDate(mo_ArmDb, m_Language, cal_dueDate, True) '@ACT_dueDate datetime ,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_size, lb_size) '@ACT_size real ,
    ls_Request = ls_Request & ", " & CorrectCodeStr(mo_ArmDb, m_Language, cbo_UOM, IIf(txt_size.Visible, IIf(Trim$(txt_size.Text) = "", False, True), False)) '@UM_code char (5),
    ls_Request = ls_Request & ", " & "NULL" 'Correct() '@AC_desc varchar (80),
    ls_Request = ls_Request & ", " & "''" '@Internet CHAR(1),
    ls_Request = ls_Request & ", " & "''" '@Drop CHAR(1),
    ls_Request = ls_Request & ", " & "NULL" '@Drop_date DATETIME,
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare1) '@spare1_varchar VARCHAR(1),
    ls_Request = ls_Request & ", " & CorrectString(mo_ArmDb, m_Language, txt_spare2) '@spare2_varchar VARCHAR(1),
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare3) '@spare3_real REAL,
    ls_Request = ls_Request & ", " & CorrectDec(mo_ArmDb, m_Language, txt_spare4) '@spare4_real REAL
    
    'Execution
    If ErrorFound Then GoTo Trace_End
        
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    ASC_BeginTransaction mo_ArmDb
        
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_ReturnCode)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        If ls_ReturnCode = "-3" Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.")
            ViewInitFields
        Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        End If
        GoTo Trace_End
    End If
    
' task 299.3 begin
Const REQupd = "EXEC Cap_Memo_Comment_upd '$AC_CODE$', $Comment$, 'N', Null, 2, $uid$"

    ' update cap_memo
    ls_Request = Replace(REQupd, "$AC_CODE$", ACode1)
    ls_Request = Replace(ls_Request, "$Comment$", FormatSqlStringParameter(txt_comment.Text))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
        If lb_Result = False Then
            ASC_RollBackTransaction mo_ArmDb
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
            GoTo Trace_End
        End If
' task 299.3 end


'ISA_TASK 298.12 BEGIN
    Const REQCapRepSel = "EXEC Cap_CompanyRepCopy_chk '$SR_code$','$CCU_CapKey$'"
    Const REQCapRepIns = "EXEC Cap_CompanyRep_Ins '$CCU_Capkey$','$SR_CODE$',$RR_Code$,'Y','N',NULL,'','',0,0"
    Dim ls_req As String
    Dim ll_curs As Long
    Dim ll_NbRec As Long
    If GetCodeFromCombo(cbo_raisedFor) <> "" Then
        If cbo_raisedFor.SelectedItem.GetData(2) <> "" Then
            ls_req = REQCapRepSel
            ls_req = Replace(ls_req, "$SR_code$", cbo_raisedFor.SelectedItem.GetData(2), , , vbTextCompare)
            ls_req = Replace(ls_req, "$CCU_CapKey$", ACode2, , , vbTextCompare)
            
            ll_curs = mo_ArmDb.OpenSQL(ls_req)
            
            If ll_curs = 0 Then
                ASC_RollBackTransaction mo_ArmDb
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                GoTo Trace_End
            End If
            ll_NbRec = mo_ArmDb.RowCount(ll_curs)
            mo_ArmDb.Close (ll_curs)
            ll_curs = 0
            If ll_NbRec = 0 Then
                ls_req = REQCapRepIns
                ls_req = Replace(ls_req, "$CCU_CapKey$", ACode2, , , vbTextCompare)
                ls_req = Replace(ls_req, "$SR_code$", cbo_raisedFor.SelectedItem.GetData(2), , , vbTextCompare)
                ls_req = Replace(ls_req, "$RR_code$", "3", , , vbTextCompare)

                If Not mo_ArmDb.ExecuteSQL(ls_req) Then
                    ASC_RollBackTransaction mo_ArmDb
                    Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                    GoTo Trace_End
                End If
            End If
        End If
    End If

    If UCase$(GetBUGroupFromCombo(cbo_actionType)) = "DISPATCH" Then
        If ckv_Sample.Count > 0 Then
            If Not SaveCkvSample(ACode1, ll_stockCursor) Then
                ASC_RollBackTransaction mo_ArmDb
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                GoTo Trace_End
            End If
        End If
    End If

'ISA_TASK 298.12 BEGIN

    ASC_CommitTransaction mo_ArmDb
    
    If lb_stockCompletition Then
        ' Check if stock quantity is not less than min
        ll_curs = mo_ArmDb.OpenSQL("EXEC Cap_SampleDoc_Department_lst3 '" & ACode1 & "','" & m_Language & "'")
        
        If mo_ArmDb.RowCount(ll_curs) > 0 Then
            ' there is something on the stock less than min
            Dim ls_Msg As String
            Dim ls_msgTmpl As String
            ls_msgTmpl = ASC_MsgText(mo_ArmDb, m_Language, 982, "#Stock ($STOCKDPT$) quantity ($QTY$) of item $ITEM$ is less than Min ($MIN$).")
            ls_Msg = ""
            While Not mo_ArmDb.EOF(ll_curs)
                Dim ls_auxmsg As String
                ls_auxmsg = Replace(ls_msgTmpl, "$STOCKDPT$", mo_ArmDb.GetFields(ll_curs, "SDP_Desc"), , , vbTextCompare)
                ls_auxmsg = Replace(ls_auxmsg, "$QTY$", mo_ArmDb.GetFields(ll_curs, "SD_Qty"), , , vbTextCompare)
                ls_auxmsg = Replace(ls_auxmsg, "$ITEM$", mo_ArmDb.GetFields(ll_curs, "SD_Desc"), , , vbTextCompare)
                ls_auxmsg = Replace(ls_auxmsg, "$MIN$", mo_ArmDb.GetFields(ll_curs, "SD_Min"), , , vbTextCompare)
                ls_Msg = IIf(ls_Msg = "", ls_Msg, ls_Msg & vbCrLf) & ls_auxmsg
                
                Call mo_ArmDb.Next(ll_curs)
            Wend
            
            Call ASC_SendMessage(mo_ArmDb, m_Language, 983, "#Warning!", ls_Msg, vbInformation & vbOKOnly)
            
        End If
        Call mo_ArmDb.Close(ll_curs)
        ll_curs = 0
        
    End If
    
    RecordUpdate = True
    
Trace_End:
    If ll_stockCursor <> 0 Then
        Call mo_ArmDb.Close(ll_stockCursor)
        ll_stockCursor = 0
    End If
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:RecordUpdate", "Result=" & RecordUpdate
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    ASC_RollBackTransaction mo_ArmDb
    If ll_stockCursor <> 0 Then
        Call mo_ArmDb.Close(ll_stockCursor)
        ll_stockCursor = 0
    End If
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:RecordUpdate"
    CapMouseOn
End Function


Function RecordDelete(ACode1 As String, ACode2 As String) As Boolean
Dim ls_Request As String
Dim ls_Result As String
Dim lb_Result As Boolean
Dim ll_Cursor As Long       'task299.3

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:RecordDelete", "ACode1=" & ACode1, "ACode2=" & ACode2
    #End If
    
    RecordDelete = False

    If Not (Trim$(ACode1) <> "" And Trim$(ACode2) <> "") Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        GoTo Trace_End
    End If

    ErrorOFF

    ls_Request = "Exec Cap_Action_del "

    ls_Request = ls_Request & "  " & "'" & ACode1 & "'" '@AC_code char(16),
    ls_Request = ls_Request & ", " & "'" & ACode2 & "'" '@CCU_CapKey char (16),
    ls_Request = ls_Request & ", " & p_iCon '@iConcurrency   SMALLINT
    
    If ErrorFound Then GoTo Trace_End
        
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    If DeleteConfirmation(mo_ArmDb, m_Language) = False Then GoTo Trace_End
    
    ASC_BeginTransaction mo_ArmDb
    
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
    If lb_Result = False Then
        ASC_RollBackTransaction mo_ArmDb
        If ls_Result = "-6" Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.")
            ViewInitFields
        Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
        End If
        GoTo Trace_End
    End If
        
' task 299.3 begin
Const REQdel = "EXEC Cap_Memo_Comment_del '$AC_CODE$', 2"
            ' delete memo
    ls_Request = Replace(REQdel, "$AC_CODE$", ACode1)
    lb_Result = ASC_RecordExec(mo_ArmDb, ls_Request, ls_Result)
            If lb_Result = False Then
                ASC_RollBackTransaction mo_ArmDb
                Call ASC_SendMessage(mo_ArmDb, m_Language, 891, "#An error occured during this manipulation, please contact your IT support")
                GoTo Trace_End
            End If
' task 299.3 end

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

Private Sub ListCustomerOf(ACustomerkey1 As String, ACustomerkey2 As String)
Dim la_Columns(8) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ListCustomerOf", "ACustomerkey1=" & ACustomerkey1, "ACustomerkey2=" & ACustomerkey2
    #End If

    If Not (ACustomerkey1 <> "" And ACustomerkey2 <> "") Then GoTo Trace_End

    'Grille
    grdlst.ResetGrid
    grdlst.MultiSelect = 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) = "due_date" & 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 & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "as_desc" & CH_LDELIMIT & "as desc"
    la_Columns(6) = "raised_for" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "raisedfor" & CH_LDELIMIT & "raised for"
    la_Columns(7) = "CNT_lastName" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CNT_lastName" & CH_LDELIMIT & "CNT_lastName"
    la_Columns(8) = "SP_desc" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_desc" & CH_LDELIMIT & "SP_desc"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ActionOfCustomer_Short', 'grid', '" & m_Language & "'", ctColumns

    grdlst.Requests = "exec Cap_Action_t_lst2 '" & ACustomerkey1 & "','" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapAct:ListCustomerOf", "Requests=", grdlst.Requests
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ListCustomerOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ListCustomerOf"
    CapMouseOn
End Sub

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

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ListProjectOf", "AProjectKey1=" & AProjectKey1, "AProjectKey2=" & AProjectKey2
    #End If

    If Not (AProjectKey1 <> "" And AProjectKey2 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = 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) = "due_date" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DueDate" & CH_LDELIMIT & "due date"
    la_Columns(4) = "at_desc" & CH_LDELIMIT & "1300" & CH_LDELIMIT & "0" & CH_LDELIMIT & "at_desc" & CH_LDELIMIT & "at desc"
    la_Columns(5) = "as_desc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "as_desc" & CH_LDELIMIT & "as desc"
    la_Columns(6) = "raised_for" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "raisedfor" & CH_LDELIMIT & "raised for"
    la_Columns(7) = "CNT_lastName" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CNT_lastName" & CH_LDELIMIT & "CNT_lastName"
    la_Columns(8) = "CCU_desc" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_desc" & CH_LDELIMIT & "CCU_desc"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ActionOfProject_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_ActionProject_t_lst '" & AProjectKey1 & "', '" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapAct:ListProjectOf", "Requests=", grdlst.Requests
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ListProjectOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ListProjectOf"
    CapMouseOn
End Sub

Private Sub ListContactOf(AContactKey1 As String, AContactKey2 As String, AContactKey3 As String)
Dim la_Columns(8) As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ListContactOf", "AContactKey1=" & AContactKey1, "AContactKey2=" & AContactKey2, "AContactKey3=" & AContactKey3
    #End If


    If Not (AContactKey1 <> "" And AContactKey2 <> "" And AContactKey3 <> "") Then GoTo Trace_End

    grdlst.ResetGrid
    grdlst.MultiSelect = 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) = "due_date" & 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 & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "as_desc" & CH_LDELIMIT & "as desc"
    la_Columns(6) = "raised_for" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "raisedfor" & CH_LDELIMIT & "raised for"
    la_Columns(7) = "CNT_lastName" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CNT_lastName" & CH_LDELIMIT & "CNT_lastName"
    la_Columns(8) = "SP_desc" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SP_desc" & CH_LDELIMIT & "SP_desc"
    
    grdlst.SetColumns la_Columns
    grdlst.LoadConstants ptSQL, "EXEC screen_csts_lst2 'cap_ActionOfContact_Short', 'grid', '" & m_Language & "'", ctColumns
    
    grdlst.Requests = "exec Cap_ActionContact_t_lst '" & AContactKey1 & "', '" & AContactKey2 & "','" & m_Language & "'"
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapAct:ListContactOf", "Requests=", grdlst.Requests
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ListContactOf"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ListContactOf"
    CapMouseOn
End Sub
Property Let project(AKey As String)
Dim TheKeys As Variant

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Project_Let", "AKey=" & AKey
    #End If
    CapMouseOff

    'AKey represents the concatenation of several keys separated by '@'
    If AKey = "" Then GoTo Trace_End
    
    'First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Project
   
    TheKeys = Split(AKey, CH_LDELIMIT)
    m_Project = CStr(TheKeys(0))
    m_Contact = ""
    m_Customer = ""
    mb_EmbeddedIsDropped = False
    ListProjectOf CStr(TheKeys(0)), CStr(TheKeys(1))
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Project_Let"
    #End If
    CapMouseOn
End Property
Property Let Customer(AKey As String)
Dim TheKeys As Variant

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Customer_Let", "AKey=" & AKey
    #End If
    CapMouseOff

    'AKey represents the concatenation of several keys separated by '@'
    If AKey = "" Then GoTo Trace_End
    
    'First, we hide all elements
    DisplayMode_None
    
    If Not mb_Root And Not mi_TypeList = 1 Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Customer
   
    TheKeys = Split(AKey, CH_LDELIMIT)
    m_Project = ""
    m_Contact = ""
    m_Customer = CStr(TheKeys(0))
    ListCustomerOf CStr(TheKeys(0)), CStr(TheKeys(1))
    mb_EmbeddedIsDropped = (TheKeys(2) = "1") ' TASK 298.2
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Customer_Let"
    #End If
    CapMouseOn
End Property

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

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Memo_Let", "AMemoKey=" & AMemoKey
    #End If
    CapMouseOff
    
    'AKey represents the concatenation of several keys separated by '@'
    If AMemoKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Memo

    TheKeys = Split(AMemoKey, CH_LDELIMIT)
    m_Memo = CStr(TheKeys(0))

    SwapToDisplayMode mt_CstValues.DisplayMode_List
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Memo_Let"
    #End If
    CapMouseOn
End Property

Property Let contact(AKey As String)
Dim TheKeys As Variant

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Contact_Let", "AKey=" & AKey
    #End If
    CapMouseOff
    
    'AKey represents the concatenation of several keys separated by '@'
    If AKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Contact
   
    TheKeys = Split(AKey, CH_LDELIMIT)
    m_Project = ""
    m_Contact = CStr(TheKeys(0))
    m_Customer = CStr(TheKeys(1))
    ListContactOf CStr(TheKeys(0)), CStr(TheKeys(1)), CStr(TheKeys(2))
    mb_EmbeddedIsDropped = (TheKeys(3) = "1") ' TAKS 298.2
    
    SwapToDisplayMode mt_CstValues.DisplayMode_List

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Contact_Let"
    #End If
    CapMouseOn
End Property
Property Let product(AProductKey As String)
Dim TheKeys As Variant

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Product_Let", "AProductKey=" & AProductKey
    #End If
    CapMouseOff
    
    'AKey represents the concatenation of several keys separated by '@'
    If AProductKey = "" Then GoTo Trace_End

    ' First, we hide all elements
    DisplayMode_None
    
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    InitControl 2
    
    mi_EmbeddedIn = mt_CstValues.Tag_Product

    TheKeys = Split(AProductKey, CH_LDELIMIT)
    m_Product = CStr(TheKeys(0))

    SwapToDisplayMode mt_CstValues.DisplayMode_List

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

Property Let TypeList(AType As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:TypeList_Let", "AType=" & AType
    #End If
    mi_TypeList = AType
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:TypeList_Let"
    #End If
End Property

Property Get TypeList() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:TypeList_Get"
    #End If
    TypeList = mi_TypeList
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:TypeList_Get", "TypeList=" & TypeList
    #End If
End Property

Sub UnCatch()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:UnCatch"
    #End If
    mi_EmbeddedIn = -1
    Call grdlst.DeselectRow
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:UnCatch"
    #End If
End Sub


Private Sub cbo_raisedFor_ComboItemSelected()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:cbo_view_ComboItemSelected"
    #End If
    
    If (DisplayMode = mt_CstValues.DisplayMode_Add) And (GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch)) Then
        
        InitTvwSample
        lbl_sample.FontBold = tvw_Sample.Count > 0
    Else
        Call RefreshCKV_StockSample(RaisedForStockDepartment())
    End If
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:cbo_view_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:cbo_view_ComboItemSelected"
    CapMouseOn
End Sub

Private Sub cbo_View_ComboItemSelected()
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, "Capact:cbo_view_ComboItemSelected"
    #End If
    
    If reload_treeview.Visible = True Then GoTo Trace_End
    
    ls_Key = ""
    If reload_treeview.Visible = False Then
        If grdlst.Row >= 0 Then
            ls_Key = grdlst.CurrentKey(0)
        End If
    End If
    ReinitTreeview GetCodeFromCombo(cbo_View)
    If ls_Key <> "" Then
        SearchTreeView ls_Key, False
    End If
    
    
'298.8_Isa Begin4
    If UCase(GetCodeFromCombo(cbo_View)) = "VH" Then
        Call DisableFilters
        tvitems.Nodes(1).Selected = True
        Call RefreshFollowUp
    Else
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
        opt_date(0).Enabled = True
        opt_date(1).Enabled = True
        tbsFilters.Enabled = True
    End If
    
'298.8_Isa End4
    
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:cbo_view_ComboItemSelected"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:cbo_view_ComboItemSelected"
    CapMouseOn
End Sub
Private Sub RefreshFollowUp()
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:RefreshFollowUp"
    #End If
    
    grdlst.Requests = tvitems.SelectedNodeRequest
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "Capact:RefreshFollowUp", "Requests=", grdlst.Requests
    End If
    lbl_ListFilter.Caption = GetCurrentFiltersDescriptionFollowUp

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

Private Sub ckv_Sample_ItemLoaded(ByVal Item As MSComctlLib.ListItem)
    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ckv_Sample_ItemLoaded"
    #End If
    
    If Item.Tag.GetData(C_CKV_QTY_COL) <> Item.Tag.GetData(C_CKV_QTY_SENT_COL) Then
        Item.ForeColor = COLOR_DELLINE                      ' Highlight row where Qty <> qty sent
    Else
        Item.ForeColor = vbBlack
    End If

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

' BEGIN T298.WP7
Private Sub tvw_Sample_DblClick()

    On Error GoTo Trace_Err
    
    If mi_DisplayMode <> mt_CstValues.DisplayMode_Add Then Exit Sub

    If tvw_Sample.SelectedItem Is Nothing Then Exit Sub
    If tvw_Sample.SelectedItem.Tag.ml_Level <> 2 Then Exit Sub
    Call CapMouseOff
    If UpdateSampleNodeInfo(tvw_Sample.NodeInfo(tvw_Sample.SelectedItem)) = True Then
        Call tvw_Sample.SetNodeState(tvw_Sample.SelectedItem, TVI_STATE_CHECKED)
        Call tvw_Sample.SetParentState(tvw_Sample.SelectedItem)
    End If
    Call CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:tvw_Sample_DblClick"
    Call CapMouseOn
End Sub
' END T298.WP7


Private Sub ckv_Sample_DblClick()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ckv_Sample_DblClick"
    #End If
    
    If mi_DisplayMode <> mt_CstValues.DisplayMode_Add And _
        Not (mi_DisplayMode = mt_CstValues.DisplayMode_Update And (RaisedForStockDepartment() <> 0)) Then GoTo Trace_End
    
    If ckv_Sample.SelectedItem Is Nothing Then GoTo Trace_End

' BEGIN T298.WP7
    If UpdateSampleListItem(ckv_Sample.SelectedItem) = True Then
        ckv_Sample.SelectedItem.Checked = True
        Call ckv_Sample_ItemLoaded(ckv_Sample.SelectedItem)
    End If
 ' END T298.WP7
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ckv_Sample_DblClick"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ckv_Sample_DblClick"
    CapMouseOn
End Sub

Private Function RaisedForStockDepartment() As Long
Static ls_configValue  As String
    
    RaisedForStockDepartment = 0
    
    ' Only completed action can check the stock
'    If GetCodeFromCombo(cbo_Status) <> ActionStatus.COMPLETE Then Exit Function
    
    If GetCodeFromCombo(cbo_raisedFor) = "" Then Exit Function
    
    If ls_configValue = "" Then
        ls_configValue = SEP & Get_A_Config("CAP_SAMPLE_STOCKMNGR") & SEP
    End If
    
    Dim ll_Idx As Long
    
    ll_Idx = InStr(1, ls_configValue, SEP & cbo_raisedFor.SelectedItem.GetData(3) & Left(SEP, 1))
    
    If ll_Idx > 0 Then
        ll_Idx = InStr(ll_Idx + Len(SEP), ls_configValue, Left(SEP, 1))
        RaisedForStockDepartment = CLng(Mid(ls_configValue, ll_Idx + 1, InStr(ll_Idx + 2, ls_configValue, SEP) - ll_Idx - 1))
    End If
End Function

Private Function RaisedByStockDepartment() As Long
Static ls_configValue  As String
    
    RaisedByStockDepartment = 0
    
    ' Only completed action can check the stock
'    If GetCodeFromCombo(cbo_Status) <> ActionStatus.COMPLETE Then Exit Function
    
    If ms_UID = "" Then Exit Function
    
    If ls_configValue = "" Then
        ls_configValue = SEP & Get_A_Config("CAP_SAMPLE_STOCKMNGR") & SEP
    End If
    
    Dim ll_Idx As Long
    
    ll_Idx = InStr(1, ls_configValue, SEP & prg.U_Code & Left(SEP, 1))
    
    If ll_Idx > 0 Then
        ll_Idx = InStr(ll_Idx + Len(SEP), ls_configValue, Left(SEP, 1))
        RaisedByStockDepartment = CLng(Mid(ls_configValue, ll_Idx + 1, InStr(ll_Idx + 2, ls_configValue, SEP) - ll_Idx - 1))
    End If
End Function

Private Function GetStockDptDesc(ByVal al_SDP_Code As Long) As String
    On Error GoTo Trace_Err
    
Static ll_SDP_Code As Long
Static ls_SDP_Desc As String
    
    GetStockDptDesc = ""
    If ll_SDP_Code = al_SDP_Code Then
        GetStockDptDesc = ls_SDP_Desc
        Exit Function
    End If
    
    Dim ll_Cursor As Long
    Dim ls_req As String
    
    ls_req = "SELECT SDP_Desc FROM Cap_SampleDepartment WHERE SDP_Code=" & al_SDP_Code & " AND Language_Code='" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(ls_req)
    
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capact:GetStockDptDesc", "Request=" & ls_req
        GoTo Trace_Err
    End If
    
    ls_SDP_Desc = mo_ArmDb.GetFields(ll_Cursor, "SDP_Desc")
    ll_SDP_Code = al_SDP_Code
    
    Call mo_ArmDb.Close(ll_Cursor)
    ll_Cursor = 0

    GetStockDptDesc = ls_SDP_Desc

    Exit Function
Trace_Err:
    If ll_Cursor <> 0 Then
        Call mo_ArmDb.Close(ll_Cursor)
        ll_Cursor = 0
    End If

    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:GetStockDptDesc"
End Function

' BEGIN T298.WP7
Private Sub tvw_Sample_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim lb_UpdateResult As Boolean
Dim ll_Index As Long
Dim lo_ChildNode As MSComctlLib.Node

    On Error GoTo Trace_Err
    
    If Node.Tag.ml_State <> TVI_STATE_CHECKED Then Exit Sub
    
    Call CapMouseOff
    If Not Node.Tag.mb_ChildrenLoaded Then Call tvw_Sample.ExpandNode(Node)
    
    ' in case user try to check node on root level, do not allow. Force uncheck in this case
    If Node.Tag.ml_Level <= 1 Then
        ' this is root level
        If Node.children = 0 Then
            ' no children loaded, uncheck parent and exit
            Call tvw_Sample.SetNodeState(Node, TVI_STATE_UNCHECKED, True)
            Call CapMouseOn
            Exit Sub
        End If
    
        ' JN 15/12/2014 uncheck all childs
'        lb_UpdateResult = true
        
        Set lo_ChildNode = Node.Child
        While Not (lo_ChildNode Is Nothing)
        
'            If lb_UpdateResult Then
'                lb_UpdateResult = UpdateSampleNodeInfo(tvw_Sample.NodeInfo(lo_ChildNode))
'            End If
            
'            If lb_UpdateResult Then
'                Call tvw_Sample.SetNodeState(lo_ChildNode, TVI_STATE_CHECKED, True)
'                Call tvw_Sample.SetParentState(lo_ChildNode)
'            Else
                Call tvw_Sample.SetNodeState(lo_ChildNode, TVI_STATE_UNCHECKED, True)
                Call tvw_Sample.SetParentState(lo_ChildNode)
'            End If
            
            Set lo_ChildNode = lo_ChildNode.Next
        Wend
    Else
      'children level
        If Not UpdateSampleNodeInfo(tvw_Sample.NodeInfo(Node)) Then
            Call tvw_Sample.SetNodeState(Node, TVI_STATE_UNCHECKED)
            Call tvw_Sample.SetParentState(Node)
        End If
    End If
    Call CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:tvw_Sample_NodeCheck"
    Call CapMouseOn
End Sub
' END T298.WP7


Private Sub ckv_Sample_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ckv_Sample_ItemCheck"
    #End If
    
    If Item.Checked = False Then GoTo Trace_End

' BEGIN T298.WP7
    If Not UpdateSampleListItem(Item) Then
        Item.Checked = False
    End If
 ' END T298.WP7
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ckv_Sample_ItemCheck"
    #End If
End Sub


Private Sub grdLst_ItemSelected()

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:grdlst_ItemSelected"
    #End If
    CapMouseOff
    
    Dim a As Double, b As Double
    
    a = timer
    
    m_CurrentKey1 = grdlst.CurrentKey(0)
    m_CurrentKey2 = grdlst.CurrentKey(1)
    m_CurrentKey3 = grdlst.CurrentKey(2)

    DisplayMode = mt_CstValues.DisplayMode_View
    
    b = timer - a
    Call AddToTimeLog(6, b)
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:grdlst_ItemSelected"
    #End If
    CapMouseOn
    
End Sub


Private Sub grdlst_RowLoaded(ByVal al_Row As Long)

    'If UCase(GetCodeFromCombo(Cbo_View)) = "VH" And Not WithParent Then
    If UCase(GetCodeFromCombo(cbo_View)) = "VH" And (mi_EmbeddedIn = -1) Then
        If grdlst.Data(al_Row, 3) >= Date Then
            grdlst.LineColor(al_Row) = FollowUpColor
        Else
            grdlst.LineColor(al_Row) = FollowUpColorExpired
        End If
    End If

End Sub

Private Sub opt_date_Click(Index As Integer)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:opt_date_Click", "Index=" & Index
    #End If
    'ReinitTreeview GetCodeFromCombo(cbo_View)
    
    If Index = 1 Then
        cal11.Visible = True
        cal12.Visible = True
        cbo_date.Visible = True
        If cbo_date.SelectedItem Is Nothing Then
            cbo_date.FirstBlankItem = False
            cbo_date.Request = "exec captv_date_cbo 'TV_Action_date','" & m_Language & "'"
            cbo_date.Load
            cbo_date.SearchItem "1", 2, 0
        End If
        
    Else
        cal11.reinit_cal
        cal12.reinit_cal
        cal11.Visible = False
        cal12.Visible = False
        cbo_date.Visible = False
        
    End If
        
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = False
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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

Private Sub pbItem_action(ByVal as_ActionType As String)
Dim lb_Result As Boolean

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:pbItem_action", "as_ActionType=" & as_ActionType
    #End If
    
    Select Case UCase$(as_ActionType)
        Case UCase$("Add")
            DisplayMode = mt_CstValues.DisplayMode_Add
            
        Case UCase$("Update")
        
            If grdlst.Row >= 0 Then
                If isUpdatable Then
                    DisplayMode = mt_CstValues.DisplayMode_Update
                End If
            End If
        
        Case UCase$("Delete")
            If grdlst.Row >= 0 Then DisplayMode = mt_CstValues.DisplayMode_Delete
        
        Case UCase$("Excel")

        
        Case UCase$("Quit")
            
            If mb_Root And mi_DisplayMode = mt_CstValues.DisplayMode_View Then
                ' We stay on the same...
                RaiseEvent UnlockNavigation
                GoTo Trace_End
            End If
        
                DisplayMode = mt_CstValues.DisplayMode_List
        
            
        Case UCase$("Valid")
        
            Dim a As Double, b As Double
            a = timer
        
            Select Case DisplayMode
                Case mt_CstValues.DisplayMode_Add
                    lb_Result = RecordAdd
                Case mt_CstValues.DisplayMode_Update
                    lb_Result = RecordUpdate(m_CurrentKey1, m_CurrentKey2)
                Case mt_CstValues.DisplayMode_Delete
                    lb_Result = RecordDelete(m_CurrentKey1, m_CurrentKey2)
            End Select
            
            If lb_Result Then
                If WithParent Then
                    grdlst.Refresh
                    RaiseEvent Updated
                Else
                    Select Case DisplayMode
                        Case mt_CstValues.DisplayMode_Delete
                            ReinitTreeViewAfterDelete grdlst, tvitems
                            lb_Result = False
                        Case mt_CstValues.DisplayMode_Update
                            If chk_UpdateTV.Value Then
                                Call Item_LocalUpdate
                            Else
                                ReinitTreeViewAfterDelete grdlst, tvitems
                            End If
                        Case Else
                            Call Item_LocalUpdate
                    End Select
                
                End If
                DisplayMode = mt_CstValues.DisplayMode_List
                b = timer - a
                Call AddToTimeLog(mi_OldDisplayMode, b)

            End If
        
        Case UCase$("Undo")
            BlankFields
            If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
                AddInitFields
            Else
                ViewInitFields
            End If
        
        Case UCase$("Previous")
            If grdlst.Row = 0 Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 927, "#No more previous item.")
            Else
                grdlst.Row = grdlst.Row - 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                m_CurrentKey2 = grdlst.CurrentKey(1)
                BlankFields
                ViewInitFields
            End If
        
        Case UCase$("Next")
            If grdlst.Row = grdlst.Rows - 1 And grdlst.AllDataLoaded = True Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 928, "#No more next item.")
            Else
                grdlst.Row = grdlst.Row + 1
                m_CurrentKey1 = grdlst.CurrentKey(0)
                m_CurrentKey2 = grdlst.CurrentKey(1)
                BlankFields
                ViewInitFields
            End If
        
        Case Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 929, "#Invalid option :", as_ActionType)
    
    End Select

    If UCase(GetCodeFromCombo(cbo_View)) = "VH" And Not WithParent Then
        If lb_Result = True Then Call Item_LocalUpdateFollowUp
        lbl_ListFilter.Caption = GetCurrentFiltersDescriptionFollowUp
    End If
    

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

Private Function isUpdatable() As Boolean
Dim ls_LastUpdated As String
Dim ls_DateLimit As String
Dim ls_Request As String
Dim ll_Cursor As Long
Dim ll_ActionStatus As Long


    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:isUpdatable"
    #End If
    
    isUpdatable = False
    
    ls_DateLimit = GetDefaultConfigCode("Action_Cfg", "DateLimitEdition")
    If ls_DateLimit <> "" Then
        ls_Request = "Select as_code, Z_last_upd From Cap_Action Where AC_Code = '" & grdlst.CurrentKey(0) & "' and Language_Code = 'E'"
        ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
        If ll_Cursor = 0 Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capact:isUpdatable", "Request=" & ls_Request
            GoTo Trace_End
        End If
        ll_ActionStatus = mo_ArmDb.GetFields(ll_Cursor, "as_code")
        ls_LastUpdated = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "Z_last_upd"))
        mo_ArmDb.Close ll_Cursor
        If ll_ActionStatus = 1 Then
            If CDate(ls_LastUpdated) < CDate(Date - CInt(ls_DateLimit)) Then
                ASC_SendMessage mo_ArmDb, m_Language, 290, "#This action is too old and cannot be updated"
                GoTo Trace_End
            End If
        End If
    End If

    isUpdatable = True

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

Private Sub pbLst_Action(ByVal as_ActionType As String)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:pbLst_Action", "as_ActionType=" & as_ActionType
    #End If
    
    Select Case UCase$(as_ActionType)
    
        Case UCase$("Add")
            Select Case mi_EmbeddedIn
                Case mt_CstValues.Tag_Customer
                    If mb_EmbeddedIsDropped Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 2505, "#You are unable to create an action for a Deleted Customer")
                    Else
                        DisplayMode = mt_CstValues.DisplayMode_Add
                    End If
                
                Case mt_CstValues.Tag_Contact
                    If mb_EmbeddedIsDropped Then
                        Call ASC_SendMessage(mo_ArmDb, m_Language, 2506, "#You are unable to create an action for a Deleted Contact")
                    Else
                        DisplayMode = mt_CstValues.DisplayMode_Add
                    End If
                
                Case Else
                    DisplayMode = mt_CstValues.DisplayMode_Add
            End Select
            
        Case UCase$("Update")
            If grdlst.Row >= 0 Then
                If isUpdatable Then
                    DisplayMode = mt_CstValues.DisplayMode_Update
                End If
            End If
            
        Case UCase$("Delete")
            If grdlst.Row >= 0 Then DisplayMode = mt_CstValues.DisplayMode_Delete
        
        Case UCase$("Refresh")
            If mi_EmbeddedIn <> -1 Then
                grdlst.Refresh
            Else
                grdlst.ClearGrid
                grdlst.Requests = ""
                If tvitems.Count = 0 And UCase(GetCodeFromCombo(cbo_View)) = "VH" And Not WithParent Then
                tvitems.Refresh
                    tvitems.Nodes(1).Selected = True
                    grdlst.Requests = tvitems.GridRequests
                    grdlst.Refresh
                Else
                    tvitems.Refresh
                End If

                If UCase(GetCodeFromCombo(cbo_View)) = "VH" And Not WithParent Then
                    lbl_ListFilter.Caption = GetCurrentFiltersDescriptionFollowUp
                End If
                
            End If
        
        Case UCase$("Print")
        
        Case UCase$("View")
            OwlSearch
        
        Case UCase$("Excel")
            If grdlst.Rows <> 0 Then ExportExcel mo_ArmDb, mb_use_framework_connection, ms_ConnectString, m_Language, grdlst, DataTypeEnum.action
            
        Case UCase$("Quit")
            RaiseEvent quit
        
        Case Else
            Call ASC_SendMessage(mo_ArmDb, m_Language, 929, "#Invalid option :", as_ActionType)
    
    End Select

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



Private Sub pctTvReset_Click()
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:pctTvReset_Click"
    #End If
    opt_date(0).Value = True
    tbsFilters.Tabs(1).Selected = True
    
    cbo_View.SearchItem "X", "TV_Default", 0 ', "TV_Default"
    
    opt_date(0).Enabled = (UCase(GetCodeFromCombo(cbo_View)) <> "VH")
    opt_date(1).Enabled = (UCase(GetCodeFromCombo(cbo_View)) <> "VH")
    tbsFilters.Enabled = (UCase(GetCodeFromCombo(cbo_View)) <> "VH")
    
    reload_treeview_Click
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:pctTvReset_Click"
    #End If
    CapMouseOn
End Sub

Private Sub reload_treeview_Click()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:reload_treeview_Click"
    #End If
    
    If opt_date(1) Then
        If Len(cal11.date_courte) <> 10 Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
            cal11.SetFocus
            GoTo Trace_End
        End If
    
        If Len(cal12.date_courte) <> 10 Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
            cal12.SetFocus
            GoTo Trace_End
        End If
    
        If CDate(cal12.date_courte) < CDate(cal11.date_courte) Then
            cal12.SetFocus
            Call ASC_SendMessage(mo_ArmDb, m_Language, 267, "#Invalid data")
            GoTo Trace_End
        End If
    
        If cbo_date.SelectedItem Is Nothing Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
            cbo_date.SetFocus
            GoTo Trace_End
        End If
    End If
    
    ReinitTreeview GetCodeFromCombo(cbo_View)
    
    tvitems.Visible = True
    reload_treeview.Visible = False

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

Private Sub srch_contact_OnClick()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:srch_contact_OnClick"
    #End If
    
    srch_contact.CodeCustomer = srch_customer.Key1
    srch_contact.CodeProject = srch_project.Key1
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:srch_contact_OnClick"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:srch_contact_OnClick"
    CapMouseOn
End Sub

Private Sub srch_Customer_OnDelete()

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:srch_Customer_OnDelete"
    #End If
    srch_contact.Clear
    srch_contact.CodeProject = srch_project.Key1
    srch_contact.TypeSearch = "Contact"
    Txt_name.Text = ""
    txt_Address.Text = ""
    txt_address2.Text = ""
    txt_ZIP.Text = ""
    txt_town.Text = ""
    txt_Phone.Text = ""
    ms_CustomerCountry = ""
    chk_SA.Value = Unchecked
    txt_ActionRep.Text = ""
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
        InitTvwSample
    Else
    InitCkvSample
     End If
    ' END T298.WP7
       
    InitCkvProduct
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:srch_Customer_OnDelete"
    #End If

End Sub

Private Sub srch_customer_OnValid()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:srch_customer_OnValid"
    #End If
    
    srch_contact.Clear
    srch_contact.CodeCustomer = srch_customer.Key1
    srch_contact.CodeProject = srch_project.Key1
    srch_contact.TypeSearch = "Contact"
    
    Load_CustomerInfo srch_customer.Key1
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
        InitTvwSample
    Else
    InitCkvSample
    End If
    ' END T298.WP7

    InitCkvProduct

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


Private Sub srch_project_OnClick()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:srch_project_OnClick"
    #End If
    
    srch_project.CodeCustomer = srch_customer.Key1
    srch_project.CodeContact = srch_contact.Key1
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:srch_project_OnClick"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:srch_project_OnClick"
    CapMouseOn
End Sub

Private Sub srch_project_OnDelete()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:srch_project_OnDelete"
    #End If
    
    txt_pro_Project.Text = ""
    txt_pro_town.Text = ""
    txt_pro_size.Text = ""
    txt_pro_status.Text = ""
    txt_pro_SA.Text = ""
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:srch_project_OnDelete"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:srch_project_OnDelete"
    CapMouseOn

End Sub

Private Sub srch_project_OnValid()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:srch_project_OnValid"
    #End If
    
    Load_ProjectInfo srch_project.Key1
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:srch_project_OnValid"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:srch_project_OnValid"
    CapMouseOn

End Sub

Private Sub tbsFilters_Click()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:tbsFilters_Click"
    #End If
    reload_treeview.Visible = -1
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.Visible = 0
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:tbsFilters_Click"
    #End If
End Sub

Private Sub tvItems_NodeClick(ByVal Node As MSComctlLib.INode)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:tvItems_NodeClick"
    #End If
    
    If tvitems.Checkboxes = True Then
        fill_all_record.Visible = True
        GoTo Trace_End
    End If

    grdlst.ClearGrid
    grdlst.Requests = ""
    
    If tvitems.NodeInfo(Node).ml_Level = tvitems.Levels - 1 Then
        fill_all_record.Visible = 0
        grdlst.Requests = tvitems.SelectedNodeRequest
        If grdlst.Execute = False Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapAct:tvItems_NodeClick", "Requests=", grdlst.Requests
        End If
    Else
    fill_all_record.Visible = -1
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:tvItems_NodeClick"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:tvItems_NodeClick"
    CapMouseOn
End Sub

Private Sub InitControl(Optional aMode As Integer = 0)
Dim ConnectData As Variant
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:InitControl", "AMode=" & aMode
    #End If
    
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
   
    'If already initialized then exit
    Select Case aMode
        Case 0
            GoTo Trace_End
        Case 1
        If mi_TypeList <> 1 Then
            mi_TypeList = 1
        Else
            pblst.PictureDisplayed = "P_Quit=-1"
            GoTo Trace_End
        End If
        Case 2
        If mi_TypeList <> 1 And mi_TypeList <> 2 Then
            mi_TypeList = 2
        End If
    End Select
   
    UserControl.ScaleMode = 1
    
    'Object unvisble
    ObjectVisible False
    
    Select Case aMode
        Case 1
    'Pour la liste longue uniquement
   
        DrawMainGrid
        ' bug55, fix 22.12.2006 JULO begin
        ' call to fill grid when initialized for the first time
        If Not mb_gridInitializedForFollowUP Then
            Debug.Assert (UCase(GetCodeFromCombo(cbo_View)) = "VH")
            If tvitems.Count > 0 Then tvitems.Nodes(1).Selected = True
            Call RefreshFollowUp
            mb_gridInitializedForFollowUP = True
        End If
        ' bug55, fix 22.12.2006 JULO end
        Case 2
    'Pour la liste courte
                  
        'Grille
        grdlst.ResetGrid
      
        'Pour liste longue : Initialisation toolbar
        pblst.ClearAllIcons
        pblst.TableName = mt_CstValues.SecurityAction_lst
        pblst.PictureDisplayed = "P_Refresh=7"
            
        Case 3
    'Pour détail
            
            pbitem.ClearAllIcons
    '        If WithParent Then
    '            pbItem.TableName = mt_CstValues.SecurityAction_lst
    '        Else
    '            pbItem.TableName = mt_CstValues.SecurityAction
    '        End If
    '        pbItem.PictureDisplayed = "P_Print=5  P_Quit=-1"
            pbitem.TableName = ""
            pbitem.PictureDisplayed = "P_Update=2 P_Previous=4 P_Next=5 P_Quit=-1"
        
        Case 4
    'Pour màj
    
        'Toolbar
        pbitem.ClearAllIcons
        If DisplayMode = mt_CstValues.DisplayMode_Delete Then
            pbitem.PictureDisplayed = "P_Valid=1 P_Quit=-1"
        Else
            pbitem.PictureDisplayed = "P_Valid=1 P_UnDo=2 P_Quit=-1"
        End If
        
    End Select
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:InitControl"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:InitControl"
    CapMouseOn
End Sub

Private Sub ObjectVisible(Optional aVisible As Boolean = True)

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ObjectVisible", "AVisible=" & aVisible
    #End If
    
    UserControl.fraFilters.Visible = aVisible
    UserControl.fraItem.Visible = aVisible
    UserControl.fraList.Visible = aVisible

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


Sub UpdateInitFields()
Dim ls_DateLimit As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:UpdateInitFields"
    #End If
    
    'idem
    ViewInitFields

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

Sub View_EnableControls()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:View_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    lbl_ActionCode.Enabled = True
    txt_ActCode.Enabled = True
    
    ckv_Sample.Enabled = True

    ' BEGIN T298.WP7
    tvw_Sample.Enabled = True
    ' END T298.WP7
    CkvProduct.Enabled = True
    txt_comment.Locked = True
    txt_comment.Enabled = True
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:View_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:View_EnableControls"
    CapMouseOn
End Sub
Sub Add_Enablecontrols()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Add_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    
    lbl_actionType.Enabled = True
    cbo_actionType.Enabled = True

    lbl_dateEntered.Enabled = False
    txt_dateEntered.Enabled = False
    lbl_lastUpdated.Enabled = False
    txt_lastUpdated.Enabled = False
    lbl_createdBy.Enabled = False
    txt_createdBy.Enabled = False
    lbl_updatedBy.Enabled = False
    txt_updatedBy.Enabled = False
    lbl_ActionRep.Enabled = False
    txt_ActionRep.Enabled = False

    If m_Customer <> "" Then
        srch_customer.Locked = True
        Lbl_Customer.Enabled = False
    Else
        srch_customer.Locked = False
    End If
    
    If m_Contact <> "" Then
        srch_contact.Locked = True
        lbl_Contact.Enabled = False
    Else
        srch_contact.Locked = False
    End If
    
    If m_Project <> "" Then
        srch_project.Locked = True
        lbl_Project.Enabled = False
    Else
        srch_project.Locked = False
    End If
    
    cbo_UOM.Enabled = False
    txt_comment.Locked = False
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Add_EnableControls"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Add_EnableControls"
    CapMouseOn
End Sub

Private Function ParamReqReplace1(as_Request As String) As String
Dim ls_Request As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ParamReqReplace1", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    If opt_date(1) Then
        ls_Request = Replace(ls_Request, "$dd_ent$", cas_all("'" & cal11.date_us & "'"))
        ls_Request = Replace(ls_Request, "$df_ent$", cas_all("'" & cal12.date_us & "'"))
        Select Case cbo_date.SelectedItem.Key
            Case 1:
                ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV2_")
            Case 2:
                ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV1_")
            Case 3:
                ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV3_")
        End Select
    Else
        ls_Request = Replace(UCase(Mid(ls_Request, 1, 6)) & Mid(ls_Request, 7), "CAPTV_", "CAPTV0_")
    End If
    
    ls_Request = Replace(ls_Request, "$Current_Date$", "'" & Format(Date, "MM\/DD\/YYYY") & "'")
    ls_Request = Replace(ls_Request, "$Date_Until$", "'" & Format(md_DateUntil, "MM\/DD\/YYYY") & "'")
   
    
    ls_Request = Replace(ls_Request, "$dd_ent$", "Null")
    ls_Request = Replace(ls_Request, "$df_ent$", "Null")
    
    ls_Request = Replace(ls_Request, "$SA$", cas_all("'" & tbsFilters.SelectedItem.Key & "'"))
       
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ParamReqReplace1 = ls_Request
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ParamReqReplace1", "Result=" & ParamReqReplace1
    #End If
    CapMouseOn
    Exit Function
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ParamReqReplace1"
    CapMouseOn
End Function



Private Function ParamReqReplace2(as_Request As String) As String
Dim ls_Request As String
Dim PatchTag As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "capact:ParamReqReplace2", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    If opt_date(0) Then
        ls_Request = Replace(ls_Request, "$datetype$", "0")
        ls_Request = Replace(ls_Request, "$dd$", "NULL")
        ls_Request = Replace(ls_Request, "$df$", "NULL")
    Else
        ls_Request = Replace(ls_Request, "$datetype$", GetCodeFromCombo(cbo_date))
        ls_Request = Replace(ls_Request, "$dd$", cas_all("'" & cal11.date_us & "'"))
        ls_Request = Replace(ls_Request, "$df$", cas_all("'" & cal12.date_us & "'"))
    End If
    
    ls_Request = Replace(ls_Request, "$SA$", cas_all("'" & tbsFilters.SelectedItem.Key & "'"))
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ParamReqReplace2 = ls_Request
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "capact:ParamReqReplace2", "Result=" & ParamReqReplace2
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "capact:ParamReqReplace2"
    CapMouseOn
End Function


Sub Update_EnableControls()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Update_EnableControls"
    #End If
    
    ControlsEnable UserControl.Controls, fraItemTop, True
    ControlsEnable UserControl.Controls, fraItemBottom, True
    
    lbl_dateEntered.Enabled = False
    txt_dateEntered.Enabled = False
    lbl_lastUpdated.Enabled = False
    txt_lastUpdated.Enabled = False
    lbl_createdBy.Enabled = False
    txt_createdBy.Enabled = False
    lbl_updatedBy.Enabled = False
    txt_updatedBy.Enabled = False
    lbl_ActionRep.Enabled = False
    txt_ActionRep.Enabled = False
    
    srch_customer.Locked = True 'Always in update
    Lbl_Customer.Enabled = False
    
    If m_Contact <> "" Then
        srch_contact.Locked = True
        lbl_Contact.Enabled = False
    Else
        srch_contact.Locked = False
    End If
    
    If m_Project <> "" Then
        srch_project.Locked = True
        lbl_Project.Enabled = False
    Else
        srch_project.Locked = False
    End If
        
    lbl_sample.Enabled = False
    lbl_product.Enabled = False
    
    lbl_actionType.Enabled = False
    cbo_actionType.Enabled = False
    cbo_UOM.Enabled = False
    
    txt_comment.Locked = False

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

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

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:CurrentKey_Get", "APart=" & APart
    #End If
    CapMouseOff
    
    If APart = 0 Then
        CurrentKey = m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2 & CH_LDELIMIT & m_CurrentKey3
    ElseIf APart = 1 Then
        CurrentKey = m_CurrentKey1
    ElseIf APart = 2 Then
        CurrentKey = m_CurrentKey2
    ElseIf APart = 3 Then
        CurrentKey = m_CurrentKey3
    Else
        CurrentKey = ""
    End If

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

Property Let CurrentKey(Optional APart As Integer = 0, AKeyValue As String)

    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:CurrentKey_Let", "APart=" & APart, "AKeyValue=" & AKeyValue
    #End If
    CapMouseOff
    
    If APart = 0 Then
        m_CurrentKey1 = AKeyValue
        m_CurrentKey2 = ""
        m_CurrentKey3 = ""
    ElseIf APart = 1 Then
        m_CurrentKey1 = AKeyValue
    ElseIf APart = 2 Then
        m_CurrentKey2 = AKeyValue
    ElseIf APart = 3 Then
        m_CurrentKey3 = AKeyValue
    Else
        CurrentKey = ""
    End If

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:CurrentKey_Let"
    #End If
    CapMouseOn
End Property
Private Sub cal11_datechangee()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:cal11_datechangee"
    #End If
    
    tvitems.Visible = False
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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

Private Sub cal12_datechangee()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:cal12_datechangee"
    #End If
    
    tvitems.Visible = False
    reload_treeview.Visible = True
    fill_all_record.Visible = False
    grdlst.ClearGrid
    grdlst.Requests = ""
    lbl_ListFilter.Caption = GetCurrentFiltersDescription           ' bugfix 19.10.2006

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

' Initialization of the component
Public Sub Load_A_COM(ab_root As Boolean)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Load_A_Com", "ab_root = " & ab_root
    #End If
    
    VerifyInitialization mo_ArmDb, ms_ConnectString, m_Language, Me
    
    grdlst.Load_A_COM
    pblst.Load_A_COM
    pbitem.Load_A_COM
    tvitems.Load_A_COM
    srch_customer.Load_A_COM
    srch_contact.Load_A_COM
    srch_project.Load_A_COM
    CkvProduct.Load_A_COM
    ckv_Sample.Load_A_COM
    ' BEGIN T298.WP7
    tvw_Sample.Load_A_COM
    ' END T298.WP7
    cbo_actionType.Load_A_COM
    cbo_raisedFor.Load_A_COM
    cbo_status.Load_A_COM
    cbo_letterType.Load_A_COM
    cbo_Reason.Load_A_COM
    cbo_UOM.Load_A_COM
    cbo_View.Load_A_COM
    cbo_date.Load_A_COM
    
    pblst.DrivenByCapture = True
    pbitem.DrivenByCapture = True
   
    cbo_actionType.FirstBlankItem = False
    cbo_actionType.SearchPrefix = " "
    cbo_actionType.Request = "exec cap_actiontype_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    cbo_raisedFor.FirstBlankItem = False
    cbo_raisedFor.Request = "exec cap_actionraisedfor_cbo"
    cbo_status.FirstBlankItem = False
    cbo_status.Request = "exec cap_actionstatus_cbo " & "'" & m_Language & "'"
    cbo_letterType.FirstBlankItem = True
    cbo_letterType.SearchPrefix = " "
    cbo_letterType.Request = "exec cap_lettertype_cbo " & "'" & ms_UID & "', '" & m_Language & "'"
    cbo_Reason.FirstBlankItem = False
    cbo_Reason.SearchPrefix = " "
    cbo_Reason.Request = "exec cap_actionreason_cbo " & "'" & m_Language & "'"
    cbo_UOM.FirstBlankItem = False
    cbo_UOM.Request = "exec unit_of_measure_cbo " & "'" & m_Language & "'"

    mi_EmbeddedIn = -1  '   Component is not embedded by someone
    mi_EmbedTag = -1    '   Component embed none component
    
    mb_Root = False     ' Component is not the default focus
     
     
    'Screen csts
    LoadLabels mo_ArmDb, UserControl.Controls, "Cap_Action_Detail", m_Language
    
    reload_treeview.Picture = LoadResPicture(116, vbResIcon)
    reload_treeview.Visible = False

    
'298.8_Isa Begin2
    Dim ls_follow As String
    ls_follow = GetDefaultConfigCode("Action_Cfg", "FollowUpDateIncrement")
    If isNumeric(ls_follow) Then
        ml_FollowUpDateIncrement = GetDefaultConfigCode("Action_Cfg", "FollowUpDateIncrement")
    Else
        ml_FollowUpDateIncrement = 7
    End If
    md_DateUntil = Date + ml_FollowUpDateIncrement + 1
    ms_lbl_ListFilter = lbl_ListFilter.Caption
    lbl_ListFilter.Caption = ""
'298.8_Isa End2
     
    lbl_ListFilter.Caption = GetCurrentFiltersDescription
    
    If ab_root = True Then
        'Initialisation treeview et filtres
        cbo_View.Clear
        cbo_View.FirstBlankItem = False
        cbo_View.Request = "exec TreeView_View_t_lst 'Capture_Action'," & "'" & m_Language & "'"
        cbo_View.Load
        cbo_View.SearchItem "Vh", "TV_Code", 0  ' "X", "TV_Default", 0 ' bug55, fix 21.12.2006 JULO
        mb_gridInitializedForFollowUP = False
    Else
        mb_gridInitializedForFollowUP = True
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Load_A_Com"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Load_A_Com"
    CapMouseOn
End Sub

Private Sub fill_all_record_Click()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:fill_all_record_Click"
    #End If
    
    If tvitems.Checkboxes = True Then
        grdlst.Requests = tvitems.CheckedNodesRequests
    Else
        grdlst.Requests = tvitems.SelectedNodeRequest
    End If
    If grdlst.Execute = False Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError grdlst.ArmDb, "CapAct:fill_all_record_Click", "Requests=", grdlst.Requests
    End If

    fill_all_record.Visible = False

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

Public Function cas_all(ByVal parm As String)
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:cas_all", "parm=" & parm
    #End If
    
    Select Case UCase(parm)
        Case "'ALL'", "''", Len(parm) = 0, "'A'":            cas_all = "Null"
        Case "'O'":  cas_all = "2"
        Case "'C'":  cas_all = "1"
        Case Else: cas_all = parm
    End Select

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

' Initialization for the framework
Public Sub FrameWorkInit(ByRef lt_CstValues As Object, ls_InstanceName As String, Optional ATypeList As Integer = 0)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:FrameWorkInit", "lt_CstValues=" & TypeName(lt_CstValues), "ls_InstanceName=" & ls_InstanceName, "ATypeList=" & ATypeList
    #End If
    
    'Restriction of initialsation
    mi_TypeParam = ATypeList
   
    Set mt_CstValues = lt_CstValues
    
    
    mi_CptTag = mt_CstValues.Tag_Action
    
    ' Add the tabulation for the embedded controls system
    With UserControl
        .tbsEmbedded.Tabs.Clear
        .tbsEmbedded.TabFixedWidth = 150
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Action), "#Action")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Project), "#Project")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Customer), "#Customer")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_Contact), "#Contact")
        Call .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, SetLstKey(mt_CstValues.Tag_File), "#File")
        
        tbsEmbedded.Tabs.Item(1).Tag = "tbs_Action"
        tbsEmbedded.Tabs.Item(2).Tag = "tbs_Project"
        tbsEmbedded.Tabs.Item(3).Tag = "tbs_Customer"
        tbsEmbedded.Tabs.Item(4).Tag = "tbs_Contact"
        tbsEmbedded.Tabs.Item(5).Tag = "tbs_File"

    End With

    
    mi_DisplayMode = mt_CstValues.DisplayMode_None
    mi_OldDisplayMode = mi_DisplayMode
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:FrameWorkInit"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:FrameWorkInit"
    CapMouseOn
End Sub


' Release the memory used
Public Sub Unload_A_COM()
 
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Unload_A_COM"
    #End If
    
    grdlst.Unload_A_COM
    pblst.Unload_A_COM
    pbitem.Unload_A_COM
    tvitems.Unload_A_COM
    srch_customer.Unload_A_COM
    srch_contact.Unload_A_COM
    srch_project.Unload_A_COM
    CkvProduct.Unload_A_COM
    ckv_Sample.Unload_A_COM
    ' BEGIN T298.WP7
    tvw_Sample.Load_A_COM
    ' END T298.WP7
    cbo_actionType.Unload_A_COM
    cbo_raisedFor.Unload_A_COM
    cbo_status.Unload_A_COM
    cbo_letterType.Unload_A_COM
    cbo_Reason.Unload_A_COM
    cbo_View.Unload_A_COM
    cbo_date.Unload_A_COM
 
    ASC_DisconnectFromDB mo_ArmDb, ms_UID, mb_Created
 
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Unload_A_COM"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Unload_A_COM"
    CapMouseOn
End Sub


' Properties for let application access to critical data
Public Property Get CptTag()
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:CptTag_Get"
    #End If
    CptTag = mi_CptTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:CptTag_Get", "Result=" & CptTag
    #End If
End Property

' Give the tag of the component which embed this instance
Public Property Get EmbeddedIn() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:EmbeddedIn_Get"
    #End If
    EmbeddedIn = mi_EmbeddedIn
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:EmbeddedIn_Get", "Result=" & EmbeddedIn
    #End If
End Property

' Give the tag of the component embed by this
Public Property Get EmbedTag() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:EmbedTag_Get"
    #End If
    EmbedTag = mi_EmbedTag
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:EmbedTag_Get", "Result=" & EmbedTag
    #End If
End Property


' Get the root state
Public Property Get Root() As Boolean
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Root_Get"
    #End If
    Root = mb_Root
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Root_Get", "Result=" & Root
    #End If
End Property

Public Property Let Root(ByVal ab_root As Boolean)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Root_Let", "ab_Root=" & ab_root
    #End If
    mb_Root = ab_root
    If mb_Root = True Then
        mi_EmbeddedIn = -1
    End If
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Root_Let"
    #End If
End Property

' Give the actual display mode
Public Property Get DisplayMode() As Integer
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:DisplayMode_Get"
    #End If
    DisplayMode = mi_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:DisplayMode_Get", "Result=" & DisplayMode
    #End If
End Property

' Change the actual display mode
Public Property Let DisplayMode(ByVal li_DisplayMode As Integer)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:DisplayMode_Let", "li_DisplayMode=" & li_DisplayMode
    #End If
    SwapToDisplayMode li_DisplayMode
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:DisplayMode_Let"
    #End If
End Property

' when a component embed this instance
Public Sub CatchBy(ByVal li_TagCaller, ByVal ls_Params As String)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:CatchBy", "li_TagCaller=" & li_TagCaller, "ls_Params=" & ls_Params
    #End If
    
    mi_EmbeddedIn = li_TagCaller
    'mb_Root = False
    'mi_EmbedTag = -1
    If (Not mb_Root) And (mi_TypeList <> 1) Then
        mi_EmbedTag = -1
    End If
    
    If mi_EmbeddedIn <> -1 Then
        ' When a component is embedded, it always appears in short list
        SwapToDisplayMode mt_CstValues.DisplayMode_List, ls_Params
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:CatchBy"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:CatchBy"
    CapMouseOn
End Sub

' Change the display mode
Private Sub SwapToDisplayMode(li_DisplayMode As Integer, Optional ls_Params As String = "")
 
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:SwapToDisplayMode", "li_DisplayMode=" & li_DisplayMode, "ls_Params=" & ls_Params
    #End If
    
    mi_OldDisplayMode = mi_DisplayMode
   
    'When a component is root, it can't select the list mode
    If mb_Root And (li_DisplayMode = mt_CstValues.DisplayMode_List) And (EmbeddedIn = -1) Then
        li_DisplayMode = mt_CstValues.DisplayMode_View
    End If
    mi_DisplayMode = li_DisplayMode
   
    'We should hide all graphics frames before resize and move it
    DisplayMode_None
    
    Select Case mi_DisplayMode
        Case mt_CstValues.DisplayMode_List
            'The list mode is different if the component is embedded
            Select Case mi_EmbeddedIn
                Case -1
                    Call LongListDisplay
                Case Else
                    ShortListDisplay ls_Params
            End Select
            
        Case mt_CstValues.DisplayMode_View
            ViewDisplay
            
        Case mt_CstValues.DisplayMode_Update
            UpdateDisplay
            
        Case mt_CstValues.DisplayMode_Add
            AddDisplay
            
        Case mt_CstValues.DisplayMode_Delete
            DeleteDisplay
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:SwapToDisplayMode"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:SwapToDisplayMode"
    CapMouseOn
End Sub

' Hide all graphics elements
Private Sub DisplayMode_None()
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:DisplayMode_None"
    #End If
    
    With UserControl
        .fraFilters.Visible = False
        .fraItem.Visible = False
        .fraList.Visible = False
        .lbl_ListFilter.Visible = False
        
    End With
    DoEvents

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


Private Sub LongListDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:LongListDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    InitControl 1
    InitParentKey
    
    Call LongList_Resize
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:LongListDisplay"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:LongListDisplay"
    CapMouseOn
End Sub

Private Function WithParent() As Boolean
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:WithParent"
    #End If
    
    If m_Project = "" And m_Customer = "" And m_Memo = "" And m_Contact = "" And m_Product = "" Then
        WithParent = False
    Else
        WithParent = True
    End If

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



Private Sub LongList_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:LongList_Resize"
    #End If
    
    With UserControl
    
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .fraList.Left = .fraFilters.Left + fraFilters.Width + mt_CstValues.Frm_Spacing
        .fraList.Top = mt_CstValues.Frm_Spacing
        .fraList.Width = .Width - .fraList.Left - mt_CstValues.Frm_Spacing
        .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .pblst.Height = mt_CstValues.View_ToolBar_Height
        .pblst.Top = mt_CstValues.Frm_Spacing * 4
        .pblst.Left = mt_CstValues.Frm_Spacing
        .pblst.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
        .pblst.Refresh
        .fill_all_record.Left = mt_CstValues.Frm_Spacing + 5000
        .fill_all_record.Top = (mt_CstValues.Frm_Spacing * 4) + 60
        .fill_all_record.Zorder 0
        .fill_all_record.Picture = LoadResPicture(116, vbResIcon)
        .fill_all_record.Visible = 0
              
        lbl_ListFilter.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height + 50
        lbl_ListFilter.Left = mt_CstValues.Frm_Spacing
        lbl_ListFilter.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
       
        .grdlst.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height + 500
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .grdlst.Top - mt_CstValues.Frm_Spacing
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = True
        .fraList.Visible = True
        .lbl_ListFilter.Visible = True
        
        CboView_Resize lbl_view, cbo_View, fraFilters
        
        
    End With
    Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, True)
'298.8_Isa Begin5
    If UCase(GetCodeFromCombo(cbo_View)) = "VH" Then
        Call DisableFilters
    End If
'298.8_Isa End5
        
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:LongList_Resize"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:LongList_Resize"
    CapMouseOn
End Sub

Private Sub AddDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:AddDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
    
    BlankFields
    Add_Enablecontrols
    AddInitFields
    Add_Resize
    
    
    cbo_actionType.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:AddDisplay"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:AddDisplay"
    CapMouseOn
End Sub




Private Sub UpdateDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:UpdateDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
    
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then BlankFields
    Update_EnableControls
    
    If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then
        UpdateInitFields
    Else
        If UCase$(GetBUGroupFromCombo(cbo_actionType)) = "DISPATCH" Then
            LetterTypeVisible True
        Else
            LetterTypeVisible False
        End If
    End If
    Update_Resize
    cbo_actionType.SetFocus
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:UpdateDisplay"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:UpdateDisplay"
    CapMouseOn
End Sub

Private Sub DeleteDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:DeleteDisplay"
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Full)
    
    
    'If the component was on short list, it does appear now in long list
    InitControl 4
    
    BlankFields
    Delete_EnableControls
    ViewInitFields
    Delete_Resize
   
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:DeleteDisplay"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:DeleteDisplay"
    CapMouseOn
End Sub

Private Sub Delete_EnableControls()

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

    ControlsEnable UserControl.Controls, fraItemTop, False
    ControlsEnable UserControl.Controls, fraItemBottom, False
    lbl_ActionCode.Enabled = True
    txt_ActCode.Enabled = True
    ckv_Sample.Enabled = True
    ' BEGIN T298.WP7
    tvw_Sample.Enabled = True
    ' END T298.WP7
    CkvProduct.Enabled = True
    txt_comment.Enabled = True
    txt_comment.Locked = True

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

Private Sub ViewDisplay()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ViewDisplay"
    #End If
    
    If mi_EmbeddedIn = -1 Then
        RaiseEvent SwitchToView(mt_CstValues.View_Full)
    Else
        RaiseEvent SwitchToView(mt_CstValues.View_Medium)
    End If
    
    If mb_CycleReset Then
        mb_CycleReset = False
        GoTo Trace_End
    End If

    
    'If the component was on short list, it doues appear now in long list
    InitControl 3
    
    If IsArray(grdlst.CurrentKey) Then
        BlankFields
        View_EnableControls
        ViewLoad
        ViewInitFields
        View_Resize
        ms_View_Key = txt_ActCode.Text
    Else
        View_EnableControls
        View_Resize
        
        DrawMainGrid
        Call SearchTreeView(ms_View_Key, False)
        If ms_View_Key <> txt_ActCode.Text Then
            ViewLoad
            ViewInitFields
        End If
    End If

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


Private Sub ViewLoad()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ViewLoad"
    #End If
    
    If (mb_Root And mi_OldDisplayMode <> mt_CstValues.DisplayMode_List) Or mi_EmbedTag = -1 Then
        With UserControl
                .tbsEmbedded.Tabs.Item(1).Selected = True
        End With
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ViewLoad"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ViewLoad"
    CapMouseOn
End Sub

Private Sub ShortListDisplay(ByVal ls_Params As String)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ShortListDisplay", "ls_Params=" & ls_Params
    #End If
    
    RaiseEvent SwitchToView(mt_CstValues.View_Embedded)
   
    ShortList_Resize
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ShortListDisplay"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ShortListDisplay"
    CapMouseOn
End Sub

' Embed a component
Private Sub tbsEmbedded_Click()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:tbsEmbedded_Click"
    #End If
    
    With UserControl
        Dim li_Key As Integer
        li_Key = GetLstKey(.tbsEmbedded.SelectedItem.Key)
        
        If (li_Key = mi_EmbedTag) Or (mi_EmbedTag = -1 And .tbsEmbedded.SelectedItem.Index = 1) Then GoTo Trace_End
        
        If mi_EmbedTag <> -1 Then
            RaiseEvent Release
            mi_EmbedTag = -1
        End If
        
        If .tbsEmbedded.SelectedItem.Index = 1 Then
        
            If mi_EmbeddedIn <> -1 Then
                 RaiseEvent SwitchToView(mt_CstValues.View_Medium)
            End If
            .fraItemBottom.Visible = True
        Else
            .fraItemBottom.Visible = False
            If mi_EmbeddedIn <> -1 Then
                If (li_Key = mt_CstValues.Tag_Memo) Or (li_Key = mt_CstValues.Tag_File) Then
                     RaiseEvent SwitchToView(mt_CstValues.View_Medium)
                Else
                    RaiseEvent SwitchToView(mt_CstValues.View_Full)
                End If
            End If
            mi_EmbedTag = li_Key
            RaiseEvent Catch(mi_EmbedTag, m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2 & CH_LDELIMIT & m_CurrentKey3)
        End If
        
    End With

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


' Called when application must resize the current view
Public Sub Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Resize"
    #End If
    
    Call DisplayMode_None
    
    Select Case DisplayMode
        Case mt_CstValues.DisplayMode_List
            If mi_EmbeddedIn = -1 Then
                Call LongList_Resize
            Else
                Call ShortList_Resize
            End If
        Case mt_CstValues.DisplayMode_View
            If mi_EmbeddedIn = -1 Then
                Call LongList_Resize
             End If
            Call View_Resize
        Case mt_CstValues.DisplayMode_Update
            Call Update_Resize
        Case mt_CstValues.DisplayMode_Add
            Call Add_Resize
        Case mt_CstValues.DisplayMode_Delete
            Call Delete_Resize
    End Select
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Resize"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Resize"
    CapMouseOn
End Sub


Private Sub Add_Resize()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Add_Resize"
    #End If
    
    With UserControl
        
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        '.fraFilters.Left = 0
        '.fraFilters.Width = 0
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .pbitem.Height = mt_CstValues.View_ToolBar_Height
        .pbitem.Top = mt_CstValues.Frm_Spacing * 4
        .pbitem.Left = mt_CstValues.Frm_Spacing
        .pbitem.Width = .fraItem.Width - .pbitem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbitem.Refresh
        
        .tbsEmbedded.Visible = False
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbitem.Top + .pbitem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = False
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.Visible = True
        .fraItemBottom.BorderStyle = 0
        
    End With

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Add_Resize"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Add_Resize"
    CapMouseOn
End Sub
Private Sub Update_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Update_Resize"
    #End If
    
    With UserControl
    
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        '.fraFilters.Left = 0
        '.fraFilters.Width = 0
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .pbitem.Height = mt_CstValues.View_ToolBar_Height
        .pbitem.Top = mt_CstValues.Frm_Spacing * 4
        .pbitem.Left = mt_CstValues.Frm_Spacing
        .pbitem.Width = .fraItem.Width - .pbitem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbitem.Refresh
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbitem.Top + .pbitem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Visible = False
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = False
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.Visible = True
        .fraItemBottom.BorderStyle = 0
    
    End With

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

Private Sub Delete_Resize()

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Delete_Resize"
    #End If
    
    With UserControl
        
        .fraFilters.Width = mt_CstValues.View_Frame_Width
        .fraFilters.Left = mt_CstValues.Frm_Spacing
        .fraFilters.Top = mt_CstValues.Frm_Spacing
        .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
        '.fraFilters.Left = 0
        '.fraFilters.Width = 0
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .fraItem.Left = mt_CstValues.Frm_Spacing
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .pbitem.Height = mt_CstValues.View_ToolBar_Height
        .pbitem.Top = mt_CstValues.Frm_Spacing * 4
        .pbitem.Left = mt_CstValues.Frm_Spacing
        .pbitem.Width = .fraItem.Width - .pbitem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbitem.Refresh
        
        .tbsEmbedded.Visible = False
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbitem.Top + .pbitem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraFilters.Visible = True
        .fraFilters.Enabled = False
        
        .fraItem.Visible = True
        .fraItemTop.Visible = True
        .fraItemBottom.Visible = True
        .fraItemTop.BorderStyle = 0
        .fraItemBottom.BorderStyle = 0
        
    End With
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Delete_Resize"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Delete_Resize"
    CapMouseOn
End Sub
Property Get FraFilterLeft() As Long
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:FraFilterLeft_Get"
    #End If
    FraFilterLeft = UserControl.fraFilters.Left + UserControl.fraFilters.Width
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:FraFilterLeft_Get", "Result=" & FraFilterLeft
    #End If
    
End Property
Property Get UserControlWidth() As Long
    
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:UserControlWidth_Get"
    #End If
    UserControlWidth = UserControl.Width
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:UserControlWidth_Get", "Result=" & UserControlWidth
    #End If
    
End Property

Private Sub View_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:View_Resize"
    #End If
    
    With UserControl
        
        If mi_EmbeddedIn = -1 And Not mb_Root Then
        
            .fraFilters.Width = mt_CstValues.View_Frame_Width
            .fraFilters.Left = mt_CstValues.Frm_Spacing
            .fraFilters.Top = mt_CstValues.Frm_Spacing
            .fraFilters.Height = .Height - .fraFilters.Top - (2 * mt_CstValues.Frm_Spacing)
            '.fraItem.Left = mt_CstValues.Frm_Spacing
            .fraItem.Left = .fraFilters.Left + fraFilters.Width + mt_CstValues.Frm_Spacing
            
            .fraFilters.Visible = True
            .fraFilters.Enabled = True
            
            .tbsEmbedded.Visible = True
            .tbsEmbedded.Zorder 0
            
        Else
            .fraItem.Left = mt_CstValues.Frm_Spacing
            
            .tbsEmbedded.Visible = True
            .tbsEmbedded.Zorder 0
            
        End If
        
        .fraItem.Top = mt_CstValues.Frm_Spacing
        .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .tvitems.Left = mt_CstValues.Frm_Spacing
        .tvitems.Width = .fraFilters.Width - (2 * mt_CstValues.Frm_Spacing)
                
        .tbsFilters.Left = mt_CstValues.Frm_Spacing
        .tbsFilters.Top = .fraFilters.Height - .tbsFilters.Height - mt_CstValues.Frm_Spacing
        .tbsFilters.Width = .tvitems.Width
        
        .tvitems.Height = .tbsFilters.Top - .tvitems.Top
        
        .pbitem.Height = mt_CstValues.View_ToolBar_Height
        .pbitem.Top = mt_CstValues.Frm_Spacing * 4
        .pbitem.Left = mt_CstValues.Frm_Spacing
        .pbitem.Width = .fraItem.Width - .pbitem.Left - (2 * mt_CstValues.Frm_Spacing)
        .pbitem.Refresh
        
        .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
        .fraItemTop.Left = mt_CstValues.Frm_Spacing
        .fraItemTop.Top = mt_CstValues.Frm_Spacing + .pbitem.Top + .pbitem.Height
        
        .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
        .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
        .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
        '.fraItemBottom.Height = mt_CstValues.Cpt_View_Emb_Height
        .fraItemBottom.Top = .tbsEmbedded.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
        .fraItemBottom.Left = mt_CstValues.Frm_Spacing
        
        .fraItemBottom.Visible = True
        
        .fraItem.Visible = True
        .fraItemTop.BorderStyle = 1
        .fraItemBottom.BorderStyle = 1
        
    End With
    Call ControlsEnable(UserControl.Controls, UserControl.fraFilters, False)

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

Private Sub ShortList_Resize()
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ShortList_Resize"
    #End If
    
    With UserControl
    
        .fraList.Left = mt_CstValues.Frm_Spacing
        .fraList.Top = mt_CstValues.Frm_Spacing
        .fraList.Width = .Width - .fraList.Left - (2 * mt_CstValues.Frm_Spacing)
        .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
   
        .pblst.Height = mt_CstValues.View_ToolBar_Height
        .pblst.Top = mt_CstValues.Frm_Spacing * 4
        .pblst.Left = mt_CstValues.Frm_Spacing
        .pblst.Width = .fraList.Width - .pblst.Left - (2 * mt_CstValues.Frm_Spacing)
        .pblst.Refresh
        
        .grdlst.Top = mt_CstValues.Frm_Spacing + .pblst.Top + .pblst.Height
        .grdlst.Left = mt_CstValues.Frm_Spacing
        .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
        .grdlst.Height = .fraList.Height - .pblst.Height - .pblst.Top - (2 * mt_CstValues.Frm_Spacing)
        
        .fraFilters.Visible = False
        .fraList.Visible = True
        .fill_all_record.Visible = 0
    End With
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ShortList_Resize"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ShortList_Resize"
    CapMouseOn
End Sub

Private Sub AddInitFields()
Dim TheRequest As String
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:AddInitFields"
    #End If
    
    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    TheRequest = "exec Cap_Action_sel2 '" & m_Project & "','" & m_Customer & "','" & m_Contact & "','" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapAct:AddInitFields", "Request=" & TheRequest
        GoTo Trace_End
    End If

    srch_project.Clear
    srch_project.CodeCustomer = m_Customer
    srch_project.CodeContact = m_Contact
    srch_project.TypeSearch = "Project"
    srch_project.Key1 = m_Project
    srch_project.Text = mo_ArmDb.GetFields(ll_Cursor, "SP_Desc")
    
    txt_pro_Project = mo_ArmDb.GetFields(ll_Cursor, "SP_Desc")
    If txt_pro_Project.Text <> "" Then
        txt_pro_SA = mo_ArmDb.GetFields(ll_Cursor, "SA_Desc")
        txt_pro_size = mo_ArmDb.GetFields(ll_Cursor, "SP_Size")
        txt_pro_status = mo_ArmDb.GetFields(ll_Cursor, "SS_Desc")
        txt_pro_town = mo_ArmDb.GetFields(ll_Cursor, "SP_Town")
    End If
    
    
    ms_CustomerCountry = ""
    srch_customer.Clear
    srch_customer.CodeProject = m_Project
    srch_customer.TypeSearch = "Customer"
    srch_customer.Key1 = m_Customer
    srch_customer.Text = mo_ArmDb.GetFields(ll_Cursor, "CCU_Desc")
    
    Txt_name = mo_ArmDb.GetFields(ll_Cursor, "CCU_Desc")
    If Txt_name <> "" Then
        txt_Address = mo_ArmDb.GetFields(ll_Cursor, "CCU_Addr1")
        txt_address2 = mo_ArmDb.GetFields(ll_Cursor, "CCU_Addr2")
        txt_ZIP = mo_ArmDb.GetFields(ll_Cursor, "CCU_Zip")
        txt_town = mo_ArmDb.GetFields(ll_Cursor, "CCU_Town")
        txt_Phone = mo_ArmDb.GetFields(ll_Cursor, "CCU_Tel")
        chk_SA.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "CCU_SAFlag") = "X", True, False)
        ms_CustomerCountry = mo_ArmDb.GetFields(ll_Cursor, "CT_Code")
    End If
    
    srch_contact.Clear
    srch_contact.CodeProject = m_Project
    srch_contact.CodeContact = m_Contact
    srch_contact.CodeCustomer = m_Customer
    srch_contact.TypeSearch = "Contact"
    srch_contact.Key1 = m_Contact
    srch_contact.Text = mo_ArmDb.GetFields(ll_Cursor, "CNT_LastName")

    txt_dateEntered.Text = mo_ArmDb.GetFields(ll_Cursor, "daydate")
    txt_lastUpdated.Text = mo_ArmDb.GetFields(ll_Cursor, "daydate")
    txt_createdBy.Text = mo_ArmDb.GetFields(ll_Cursor, "Z_creator")
    txt_updatedBy.Text = mo_ArmDb.GetFields(ll_Cursor, "Z_creator")
    txt_ActionRep.Text = mo_ArmDb.GetFields(ll_Cursor, "SR_Name")

    LetterTypeVisible False

    DisplayDefaultValues
    
    
    ' BEGIN T298.WP7
    If GetCodeFromCombo(cbo_actionType) = CStr(mt_CstValues.ACT_TypeMultipleDispatch) Then
        InitTvwSample
    Else
    InitCkvSample
    End If
    ' END T298.WP7
    
    InitCkvProduct
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:AddInitFields"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:AddInitFields"
    CapMouseOn
End Sub

Private Sub BlankFields()
Dim TheRequest As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:BlankFields"
    #End If
    
    'Ici on vire le contenu des champs
    srch_customer.Clear
    srch_contact.Clear
    srch_project.Clear
    
    srch_contact.CodeCustomerRequired = True
    
    cbo_actionType.Clear
    cbo_status.Clear
    cbo_raisedFor.Clear
    cbo_letterType.Clear
    cbo_UOM.Clear
    cbo_Reason.Clear
    
    cal_dueDate.reinit_cal
        
    'lst_sample
    txt_comment.Text = ""
    'lst_Product
    Txt_name.Text = ""
    txt_Address.Text = ""
    txt_address2.Text = ""
    txt_ZIP.Text = ""
    txt_town.Text = ""
    txt_Phone.Text = ""
    chk_SA.Value = Unchecked
    
    txt_ActionRep.Text = ""
    txt_ActCode.Text = ""
    txt_pro_Project.Text = ""
    txt_pro_town.Text = ""
    txt_pro_size.Text = ""
    txt_pro_status.Text = ""
    txt_pro_SA.Text = ""
    txt_size.Text = ""
    txt_spare1.Text = ""
    txt_spare2.Text = ""
    txt_spare3.Text = ""
    txt_spare4.Text = ""

    txt_dateEntered.Text = ""
    txt_lastUpdated.Text = ""
    txt_createdBy.Text = ""
    txt_updatedBy.Text = ""

    'Liste à part
    ckv_Sample.Clear
    ' BEGIN T298.WP7
    tvw_Sample.Clear
    ' END T298.WP7

    
    If mi_DisplayMode = mt_CstValues.DisplayMode_View Then
        GoToTab1
    End If
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:BlankFields"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:BlankFields"
    CapMouseOn
End Sub

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

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

    'Defaulted dates
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    If DisplayMode = mt_CstValues.DisplayMode_Add Then
        ls_req = "exec Cap_Date 'Getdate'"
        ll_Cursor = mo_ArmDb.OpenSQL(ls_req, -1, 0)
        If ll_Cursor = 0 Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapAct:DisplayDefaultValues", "Request=" & ls_req
            GoTo Trace_End
        End If
        ls_DueDate = GetDefaultConfigCode("Action_Cfg", "DueDateIncrement")
        If ls_DueDate = "" Then
            cal_dueDate.date_courte = mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")
        Else
            cal_dueDate.date_courte = CDate(mo_ArmDb.GetFields(ll_Cursor, "ReturnedDate")) + CInt(ls_DueDate)
        End If
            
        mo_ArmDb.Close ll_Cursor
    End If

    If GetDefaultConfigCode("Action_Cfg", "DefaultToRaisedFor") = "1" Then
        cbo_raisedFor.Load
        cbo_raisedFor.SearchItem ms_UID, 0
    End If

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

Private Sub ViewInitFields()
Dim TheRequest As String
Dim Thekey1 As String
Dim Thekey2 As String
Dim Thekey3 As String
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ViewInitFields"
    #End If
    
    'On construit la requête
    Thekey1 = grdlst.CurrentKey(0)
    Thekey2 = grdlst.CurrentKey(1)
    Thekey3 = grdlst.CurrentKey(2)
    
    'Si pas de clé en cours, ie pas de ligne en grille sélectionnée alors bye
    If Thekey1 = "" Or Thekey2 = "" Or Thekey3 = "" Then GoTo Trace_End
    
    'Affectation aux clés membres
    CurrentKey(1) = Thekey1
    CurrentKey(2) = Thekey2
    CurrentKey(3) = Thekey3
    
    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    TheRequest = "exec cap_action_t_sel '" & Thekey1 & "','" & Thekey2 & "','" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapAct:ViewInitFields", "Request=" & TheRequest
        GoTo Trace_End
    End If
      
    p_iCon = mo_ArmDb.GetFields(ll_Cursor, "iConcurrency")
  
    txt_ActCode.Text = Thekey1
    srch_customer.Key1 = mo_ArmDb.GetFields(ll_Cursor, "ccu_capkey")
    srch_customer.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_desc")
    srch_customer.CodeProject = mo_ArmDb.GetFields(ll_Cursor, "sp_capkey")
    srch_customer.TypeSearch = "Customer"
    
    srch_contact.Key1 = mo_ArmDb.GetFields(ll_Cursor, "cnt_code")
    srch_contact.Text = mo_ArmDb.GetFields(ll_Cursor, "cnt_name")
    srch_contact.CodeProject = mo_ArmDb.GetFields(ll_Cursor, "sp_capkey")
    srch_contact.CodeCustomer = mo_ArmDb.GetFields(ll_Cursor, "ccu_capkey")
    srch_contact.TypeSearch = "Contact"
    srch_contact.CodeCustomerRequired = True
    
    srch_project.Key1 = mo_ArmDb.GetFields(ll_Cursor, "sp_capkey")
    srch_project.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_desc")
    srch_project.CodeContact = mo_ArmDb.GetFields(ll_Cursor, "cnt_code")
    srch_project.CodeCustomer = mo_ArmDb.GetFields(ll_Cursor, "ccu_capkey")
    srch_project.TypeSearch = "Project"
  
    cbo_actionType.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "at_code"), mo_ArmDb.GetFields(ll_Cursor, "at_desc")), True
    cbo_status.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "as_code"), mo_ArmDb.GetFields(ll_Cursor, "as_desc")), True
    cbo_raisedFor.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "act_raisedfor"), mo_ArmDb.GetFields(ll_Cursor, "act_raisedfor"), mo_ArmDb.GetFields(ll_Cursor, "raisedFor_SR_Code"), mo_ArmDb.GetFields(ll_Cursor, "raisedFor_U_Code")), True
    cbo_letterType.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "lt_code"), mo_ArmDb.GetFields(ll_Cursor, "lt_desc")), True
    cbo_Reason.AddItem Array(mo_ArmDb.GetFields(ll_Cursor, "ar_code"), mo_ArmDb.GetFields(ll_Cursor, "ar_desc")), True
    cbo_UOM.AddItem Array(CStr(mo_ArmDb.GetFields(ll_Cursor, "UM_code")), mo_ArmDb.GetFields(ll_Cursor, "UM_desc")), True
    cal_dueDate.date_courte = Format(mo_ArmDb.GetFields(ll_Cursor, "act_duedate"), "dd\/mm\/yyyy")
        
    'lst_sample
    txt_comment.Text = mo_ArmDb.GetFields(ll_Cursor, "act_comment")
    
    txt_size.Text = mo_ArmDb.GetFields(ll_Cursor, "act_size")
    If txt_size.Text = "0" Then txt_size.Text = ""
    
    'Customer
    Txt_name.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_desc")
    ms_CustomerCountry = ""
    If Txt_name.Text <> "" Then
        txt_Address.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_addr1")
        txt_address2.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_addr2")
        txt_ZIP.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_zip")
        txt_town.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_town")
        txt_Phone.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_tel")
        chk_SA.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "ccu_saflag") = "O", Checked, Unchecked)
        ms_CustomerCountry = mo_ArmDb.GetFields(ll_Cursor, "CT_code")
    End If
    
    'Project
    txt_pro_Project.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_desc")
    If txt_pro_Project.Text <> "" Then
        txt_pro_town.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_town")
        txt_pro_size.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_size")
        txt_pro_status.Text = mo_ArmDb.GetFields(ll_Cursor, "ss_desc")
        txt_pro_SA.Text = mo_ArmDb.GetFields(ll_Cursor, "sa_desc")
    End If
    
    txt_dateEntered.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "z_creation"))
    txt_createdBy.Text = mo_ArmDb.GetFields(ll_Cursor, "Z_creator")
    txt_RaisedBy.Text = mo_ArmDb.GetFields(ll_Cursor, "ACT_RaisedBy")
    txt_lastUpdated.Text = Cap_FormatDate(mo_ArmDb.GetFields(ll_Cursor, "z_last_upd"))
    txt_updatedBy.Text = mo_ArmDb.GetFields(ll_Cursor, "z_last_upd_user")
    
    txt_spare1.Text = mo_ArmDb.GetFields(ll_Cursor, "spare1_varchar")
    txt_spare2.Text = mo_ArmDb.GetFields(ll_Cursor, "spare2_varchar")
    txt_spare3.Text = mo_ArmDb.GetFields(ll_Cursor, "spare3_real")
    txt_spare4.Text = mo_ArmDb.GetFields(ll_Cursor, "spare4_real")
    
    txt_ActionRep.Text = mo_ArmDb.GetFields(ll_Cursor, "SR_Name")
    
    'Fields from customer
    txt_Country.Text = mo_ArmDb.GetFields(ll_Cursor, "CT_Desc")
    m_CCU_CCT_Code = mo_ArmDb.GetFields(ll_Cursor, "CCT_Code")
    m_CCU_CCT_Desc = mo_ArmDb.GetFields(ll_Cursor, "CCT_Desc")
    m_CCU_CT_Code = mo_ArmDb.GetFields(ll_Cursor, "CT_Code")
    m_CCU_CT_Desc = mo_ArmDb.GetFields(ll_Cursor, "CT_Desc")
    m_CCU_SR_Code = mo_ArmDb.GetFields(ll_Cursor, "SR_Code")
    m_CCU_SR_Name = mo_ArmDb.GetFields(ll_Cursor, "SR_Name")
    
    
    cbo_actionType.Load
    If UCase$(GetBUGroupFromCombo(cbo_actionType)) = "DISPATCH" And mi_DisplayMode = mt_CstValues.DisplayMode_Update Then
        LetterTypeVisible True
    Else
        LetterTypeVisible False
    End If
    
    InitCkvProduct
    InitCkvSample
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ViewInitFields"
    #End If
    CapMouseOn
    Exit Sub
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ViewInitFields"
    CapMouseOn
End Sub
Private Sub ReinitTreeview(as_View As String)
Dim li_rowCount As Integer
Dim TheRequest As String
Dim li_CurrentRow As Integer
Dim li_level As Integer
Dim ls_nodesRequest() As String
Dim ls_gridRequest() As String
Dim ls_countRequest() As String
Dim ls_findRequest() As String
Dim li_images() As Integer
Dim li_selectedImages() As Integer
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ReinitTreeview", "as_View=" & as_View
    #End If
    
    'Try connection, 'use_framework_connection' is inside 'ASC_ConnectToDB' !
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End
    
    tvitems.Visible = False
    
    TheRequest = "EXEC Treeview_Parameters_lst 'Action', '" & as_View & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapAct:ReinitTreeview", "Request=" & TheRequest
        GoTo Trace_End
    End If
    
    li_rowCount = mo_ArmDb.RowCount(ll_Cursor)
    
    If li_rowCount = 0 Then
        'zzMsgBox "error in Treeview_Parameters_lst : no rows returned"
        mo_ArmDb.Close ll_Cursor
        tvitems.Visible = True
        GoTo Trace_End
    End If
    
    ReDim ls_nodesRequest(0 To li_rowCount)
    ReDim ls_gridRequest(0 To li_rowCount)
    ReDim ls_countRequest(0 To li_rowCount)
    ReDim ls_findRequest(0 To li_rowCount)
    ReDim li_images(0 To li_rowCount)
    ReDim li_selectedImages(0 To li_rowCount)
    
    While Not mo_ArmDb.EOF(ll_Cursor)
        li_level = mo_ArmDb.GetFields(ll_Cursor, "TV_Level")
        ls_nodesRequest(li_level) = ParamReqReplace1(mo_ArmDb.GetFields(ll_Cursor, "TV_NodeRequest"))
        ls_gridRequest(li_level) = ParamReqReplace1(mo_ArmDb.GetFields(ll_Cursor, "TV_GridRequest"))
        ls_countRequest(li_level) = ParamReqReplace(mo_ArmDb.GetFields(ll_Cursor, "TV_CountRequest"))
        li_images(li_level) = mo_ArmDb.GetFields(ll_Cursor, "TV_Images")
        li_selectedImages(li_level) = mo_ArmDb.GetFields(ll_Cursor, "TV_SelectedImages")
        ls_findRequest(li_level) = ParamReqReplace2(mo_ArmDb.GetFields(ll_Cursor, "TV_FindRequest"))
        
        mo_ArmDb.Next ll_Cursor
    Wend
    mo_ArmDb.Close ll_Cursor
    
    tvitems.Levels = li_rowCount                 'set number of levels
    tvitems.StartDemandLevel = 1                 'set level on which we load childs on demand
    tvitems.UseImages = True                     'show icons in treeview
    tvitems.Images = li_images                   'set normal icons
    tvitems.SelectedImages = li_selectedImages   'set selected icons
    tvitems.NodeRequests = ls_nodesRequest
    tvitems.GridRequests = ls_gridRequest
    tvitems.FindRequests = ls_findRequest
    tvitems.CountRequests = ls_countRequest
    grdlst.ClearGrid
    grdlst.Requests = ""
    tvitems.LoadTree LoadTypeChildsDemand
    
    fill_all_record.Visible = 0
    'tvItems.CloseConnection
    tvitems.Visible = True

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

'298.8 Begin
Private Sub DisableFilters()
    If tbsFilters.SelectedItem.Index <> 1 Then
        tbsFilters.Tabs(1).Selected = True
    End If
    opt_date(0).Value = True
    opt_date(0).Enabled = False
    opt_date(1).Enabled = False
    tbsFilters.Enabled = False
    reload_treeview.Visible = False
End Sub
'298.8 End

Private Function ParamReqReplace(as_Request As String) As String
Dim ls_Request As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:ParamReqReplace", "as_request=" & as_Request
    #End If
    
    ls_Request = Replace(as_Request, "$lang$", "'" & m_Language & "'")
    
    
    Select Case WhichOptIsTrue(opt_date, 1)
    Case 0
        ls_Request = Replace(ls_Request, "$dt$", "''")
        ls_Request = Replace(ls_Request, "$dd$", "NULL")
        ls_Request = Replace(ls_Request, "$df$", "NULL")
    Case 1
        ls_Request = Replace(ls_Request, "$dt$", "''")
        ls_Request = Replace(ls_Request, "$dd$", "NULL")
        ls_Request = Replace(ls_Request, "$df$", "NULL")
    End Select
        
    ls_Request = Replace(ls_Request, "$SA$", "''")
    ls_Request = Replace(ls_Request, "$uid$", "'" & ms_UID & "'")
    
    ParamReqReplace = ls_Request
    
Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:ParamReqReplace", "Result=" & ParamReqReplace
    #End If
    CapMouseOn
    Exit Function
Trace_Err:
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ParamReqReplace"
    CapMouseOn
End Function

Private Function WhichOptIsTrue(ByRef ao_opt As Object, ai_maxIndex As Integer) As Integer
Dim i As Integer
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:WhichOptIsTrue", "ao_opt=" & TypeName(ao_opt), "ai_maxIndex=" & ai_maxIndex
    #End If
    
    For i = 0 To ai_maxIndex
        If ao_opt(i).Value = True Then
            WhichOptIsTrue = i
            GoTo Trace_End
        End If
    Next i
    WhichOptIsTrue = 0

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

Private Sub OwlSearch()
Dim ls_ACCode As String
Dim lo_SearchForm As SeekForm
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:OwlSearch"
    #End If
    
    ls_ACCode = ""
    
    If GetCodeFromCombo(cbo_View) = "" Then
        Call ASC_SendMessage(mo_ArmDb, m_Language, 266, "#Missing Data in compulsory field")
        cbo_View.SetFocus
        GoTo Trace_End
    End If
        
    Set lo_SearchForm = New SeekForm
    Load lo_SearchForm
    
    If mb_use_framework_connection = True Then Set lo_SearchForm.ArmDb = mo_ArmDb
    lo_SearchForm.ConnectString = ms_ConnectString
    lo_SearchForm.Language = m_Language
    lo_SearchForm.ComponentType = "ACTION"
    
    If (opt_date(1)) And (Not cbo_date.SelectedItem Is Nothing) Then
        lo_SearchForm.TreeView_DateType = CStr(cbo_date.SelectedItem.Key)
        
    Else
        lo_SearchForm.TreeView_DateType = "0"
    End If
    
    
    ' Put here the treeview filter desc and the treeview filter !
    If UCase(GetCodeFromCombo(cbo_View)) = "VH" Then
        lo_SearchForm.ComponentType = "ACTION_FOLLOWUP"
        lo_SearchForm.TreeView_DateType = "4"
        lo_SearchForm.TreeViewFiltersDesc = lbl_ListFilter.Caption
        lo_SearchForm.TreeViewFilters = GetCurrentFiltersFollowUp()
    Else
        lo_SearchForm.TreeViewFiltersDesc = GetCurrentFiltersDescription()
        lo_SearchForm.TreeViewFilters = GetCurrentFilters()
    End If
    

    lo_SearchForm.Load_A_COM
    
    CapMouseOn True
    lo_SearchForm.show 1
    CapMouseOff True
    
    If lo_SearchForm.SelectedData = True Then
        ls_ACCode = lo_SearchForm.SelectedItemCode
    End If
    
    lo_SearchForm.Unload_A_COM
    Unload lo_SearchForm
    Set lo_SearchForm = Nothing
    
    If ls_ACCode <> "" Then
        SearchTreeView ls_ACCode
    End If

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

End Sub

Private Function HasSample(as_ActionCode As String) As Boolean
Dim TheRequest As String
Dim ll_Count As Long
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:HasSample", "as_ActionCode=" & as_ActionCode
    #End If
    
    HasSample = False
    
    'Try connexion
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End

    TheRequest = "exec Cap_ActionSampleDoc_cnt '" & as_ActionCode & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapAct:HasSample", "Request=" & TheRequest
        GoTo Trace_End
    End If
    
    ll_Count = mo_ArmDb.GetFields(ll_Cursor, "count")
    
    If ll_Count > 0 Then HasSample = True

Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:HasSample", "Result=" & HasSample
    #End If
    CapMouseOn
    Exit Function
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:HasSample"
    CapMouseOn
End Function

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

Private Sub SearchTreeView(ByVal as_ACCode As String, Optional ByVal ab_ViewItem As Boolean = True, Optional ByVal ab_DontReinitialize As Boolean = False)
Dim TheRequest As String
Dim ls_RepositionInfo As String
Dim ls_RepositionCode As String
Dim lv_Key As Variant
Dim ll_Cursor As Long
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:SearchTreeView", "as_ACCode=" & as_ACCode
    #End If
    
    If as_ACCode = "" Then GoTo Trace_End
    
    If reload_treeview.Visible Then Call reload_treeview_Click ' TASK 298.2
    
    'Try connexion
    If Not ASC_ConnectToDB(mo_ArmDb, ms_ConnectString, mb_Created) Then GoTo Trace_End

    TheRequest = "exec Cap_Action_t_sel2 '" & as_ACCode & "','" & m_Language & "'"
    ll_Cursor = mo_ArmDb.OpenSQL(TheRequest, -1, 0)
    If ll_Cursor = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "CapAct:SearchTreeView", "Request=" & TheRequest
        GoTo Trace_End
    End If

    ls_RepositionInfo = mo_ArmDb.GetFields(ll_Cursor, "AC_code") & mo_ArmDb.GetFields(ll_Cursor, "CCU_CapKey") & mo_ArmDb.GetFields(ll_Cursor, "Language_code")
    lv_Key = Split(mo_ArmDb.GetFields(ll_Cursor, "AC_code") & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCU_CapKey") & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "Language_code"), CH_LDELIMIT)
    Select Case GetCodeFromCombo(cbo_View)
    Case "Va"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "ACT_RaisedBy")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AR_desc")
    Case "Vb"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "ACT_RaisedFor")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AR_desc")
    Case "Vc"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "ACT_RaisedBy")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AR_desc")
    Case "Vd"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AT_desc")
    Case "Ve"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AR_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AT_desc")
    Case "Vf"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "ACT_RaisedFor")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "sr_name")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AT_desc")
    Case "Vg"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "AT_desc")
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "CCT_Desc")
    Case "Vh"
        ls_RepositionInfo = ls_RepositionInfo & CH_LDELIMIT & mo_ArmDb.GetFields(ll_Cursor, "ACT_RaisedFor")
    End Select
    
    ls_RepositionCode = RepositionAfterSeek(ls_RepositionInfo, tvitems)
    If ls_RepositionCode <> "" Then
        'tvItems_NodeClick tvitems.SelectedItem
        If grdlst.SearchKey(True, lv_Key) Then
            If ab_ViewItem Then
                grdLst_ItemSelected
            End If
        Else
            If ab_DontReinitialize = True Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 202, "#The record you are saving can not be displayed within the current tree view (Record out with your selected tree view criteria)")
            Else
                pctTvReset_Click
                SearchTreeView as_ACCode, ab_ViewItem, True
            End If
        End If
    Else
        If ab_DontReinitialize = True Then
            Call ASC_SendMessage(mo_ArmDb, m_Language, 202, "#The record you are saving can not be displayed within the current tree view (Record out with your selected tree view criteria)")
        Else
            pctTvReset_Click
            SearchTreeView as_ACCode, ab_ViewItem, True
        End If
    End If

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

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

Private Function GetCurrentFiltersDescription() As String
Dim li_SAFlag As String
Dim ls_Date As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:GetCurrentFiltersDescription"
    #End If
    
    li_SAFlag = tbsFilters.SelectedItem
    
    If opt_date(0).Value Then ls_Date = opt_date(0).Caption
    If opt_date(1).Value Then
        ls_Date = cbo_date.SelectedItem.DisplayText & " " & LCase(opt_date(1).Caption) & " " & cal11.date_courte & " && " & cal12.date_courte
    End If
    
    GetCurrentFiltersDescription = ls_Date + " , " + li_SAFlag

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

'298.8_Isa Begin3
Private Function GetCurrentFiltersDescriptionFollowUp() As String

Const REQCount = "exec Cap_TVA_Action_OustandingCounts $Current_Date$,$Date_Until$,$uid$,$lang$"

Dim ls_lbl_ListFilter As String
Dim ll_curs As Long
Dim ls_req As String

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:GetCurrentFiltersDescriptionFollowUp"
    #End If
    
    ls_lbl_ListFilter = ms_lbl_ListFilter
    
    ls_req = ParamReqReplace1(REQCount)
    
    ll_curs = mo_ArmDb.OpenSQL(ls_req) 'exec Cap_TVA_Action_OustandingCounts '" & Format(Date, "MM\/DD\/YYYY") & "','" & Format(md_DateUntil, "MM\/DD\/YYYY") & "'," & "'" & ms_UID & "','" & m_Language & "'")
    Dim ll_passed As Long
    Dim ll_follow As Long
    ll_passed = mo_ArmDb.GetFields(ll_curs, "Passed")
    ll_follow = mo_ArmDb.GetFields(ll_curs, "follow")
    mo_ArmDb.Close ll_curs
    
    ls_lbl_ListFilter = Replace(ls_lbl_ListFilter, "$passed$", ll_passed, , , vbTextCompare)
    ls_lbl_ListFilter = Replace(ls_lbl_ListFilter, "$follow$", ll_follow, , , vbTextCompare)
    ls_lbl_ListFilter = Replace(ls_lbl_ListFilter, "$days$", ml_FollowUpDateIncrement, , , vbTextCompare)
    
'    If ll_passed + ll_follow <> grdlst.Rows Then
'        ReinitTreeview GetCodeFromCombo(Cbo_View)
'        RefreshFollowUp
'    End If
    
    
    GetCurrentFiltersDescriptionFollowUp = ls_lbl_ListFilter

Trace_End:
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:GetCurrentFiltersDescriptionFollowUp", "Result=" & GetCurrentFiltersDescriptionFollowUp
    #End If
    CapMouseOn
    Exit Function
     
Trace_Err:
    mo_ArmDb.Close ll_curs
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:GetCurrentFiltersDescriptionFollowUp"
    CapMouseOn
    
End Function


Private Function GetCurrentFiltersFollowUp() As String
Dim ls_Date1 As String
Dim ls_Date2 As String
Dim ls_SA As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:GetCurrentFiltersFollowUp"
    #End If

    ls_Date1 = ""
    ls_Date2 = Format(md_DateUntil, "MM\/DD\/YYYY")

    ls_SA = "2"

    GetCurrentFiltersFollowUp = ls_SA & CH_LDELIMIT & ls_Date1 & CH_LDELIMIT & ls_Date2 & CH_LDELIMIT & ms_UID


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

'298.8_Isa End3

Private Function GetCurrentFilters() As String
Dim ls_Date1 As String
Dim ls_Date2 As String
Dim ls_SA As String
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:GetCurrentFiltersDescription"
    #End If

    If opt_date(0).Value Then
        ls_Date1 = ""
        ls_Date2 = ""
    End If
    If opt_date(1).Value Then
        ls_Date1 = cal11.date_us
        ls_Date2 = cal12.date_us
    End If

    Select Case tbsFilters.SelectedItem.Index
        Case 1
            ls_SA = ""
        Case 2
            ls_SA = "1"
        Case 3
            ls_SA = "2"
    End Select

    GetCurrentFilters = ls_SA & CH_LDELIMIT & ls_Date1 & CH_LDELIMIT & ls_Date2


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

' BEGIN T298.WP7
'get number of checked items in treeview on particular level. Levels are zero based, root is level 0
Private Function GetCheckedNodesCount(ByRef ao_TreeView As ArmTreeView, ByVal al_Level As Long) As Long
Dim ll_Index As Long
Dim ll_Count As Long

    ll_Count = 0
    For ll_Index = 1 To ao_TreeView.Count
        If (ao_TreeView.NodeInfo(ao_TreeView.Nodes(ll_Index)).ml_Level = al_Level) And (ao_TreeView.NodeInfo(ao_TreeView.Nodes(ll_Index)).ml_State = 8) Then
            ll_Count = ll_Count + 1
        End If
    Next
    GetCheckedNodesCount = ll_Count

End Function
' END T298.WP7

' This function is called by the application when the component embedded is updated
Public Sub Embedded_Updated(ByVal ab_FromEmbedded As Boolean)
    
    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Embedded_Updated"
    #End If

    If Not ab_FromEmbedded Then
        ' TO DO
        
    Else
        Select Case mi_EmbedTag
            Case mt_CstValues.Tag_Customer
                Load_CustomerInfo srch_customer.Key1
                
            Case mt_CstValues.Tag_Project
                Load_ProjectInfo srch_project.Key1
        End Select
    End If

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

' Load the customer information in the bottom frame
Private Sub Load_CustomerInfo(ByVal as_CCU_Capkey As String)
Dim ls_Request As String
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Load_CustomerInfo", "as_CCU_Capkey=" & as_CCU_Capkey
    #End If

    If as_CCU_Capkey <> "" Then
        ls_Request = "exec claim_customer_t_sel3 '" & as_CCU_Capkey & "', '" & m_Language & "'"
        ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
        If ll_Cursor = 0 Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capact:Load_CustomerInfo", "Request=" & ls_Request
            GoTo Trace_End
        End If
        Txt_name.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_desc")
        txt_Address.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_addr1")
        txt_address2.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_addr2")
        txt_ZIP.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_zip")
        txt_town.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_town")
        txt_Phone.Text = mo_ArmDb.GetFields(ll_Cursor, "ccu_tel")
        ms_CustomerCountry = mo_ArmDb.GetFields(ll_Cursor, "CT_code")
        chk_SA.Value = IIf(mo_ArmDb.GetFields(ll_Cursor, "ccu_saflag") = "O", Checked, Unchecked)
        txt_ActionRep.Text = mo_ArmDb.GetFields(ll_Cursor, "SR_Name")
    End If
    mo_ArmDb.Close ll_Cursor
    
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Load_CustomerInfo"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Load_CustomerInfo"
    CapMouseOn
    
End Sub

' Load the project information in the bottom frame
Private Sub Load_ProjectInfo(ByVal as_SP_Capkey As String)
Dim ls_Request As String
Dim ll_Cursor As Long

    On Error GoTo Trace_Err
    CapMouseOff
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Capact:Load_ProjectInfo", "as_SP_Capkey=" & as_SP_Capkey
    #End If

    If as_SP_Capkey <> "" Then
        ls_Request = "exec sales_project_t_sel3 '" & as_SP_Capkey & "', '" & m_Language & "'"
        ll_Cursor = mo_ArmDb.OpenSQL(ls_Request, -1, 0)
        If ll_Cursor = 0 Then
            If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError mo_ArmDb, "Capact:Load_ProjectInfo", "Request=" & ls_Request
            GoTo Trace_End
        End If
        txt_pro_Project.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_desc")
        txt_pro_town.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_town")
        txt_pro_size.Text = mo_ArmDb.GetFields(ll_Cursor, "sp_size")
        txt_pro_status.Text = mo_ArmDb.GetFields(ll_Cursor, "ss_desc")
        txt_pro_SA.Text = mo_ArmDb.GetFields(ll_Cursor, "sa_desc")
    End If
    
    mo_ArmDb.Close ll_Cursor
    
    
Trace_End:
    mo_ArmDb.Close ll_Cursor
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Capact:Load_ProjectInfo"
    #End If
    CapMouseOn
    Exit Sub
    
Trace_Err:
    mo_ArmDb.Close ll_Cursor
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:Load_ProjectInfo"
    CapMouseOn
    
End Sub

' BEGIN T298.WP7
Private Function UpdateSampleListItem(ao_Sample As MSComctlLib.ListItem) As Boolean
Dim lo_Sample_Upd As Sample_Upd

    UpdateSampleListItem = False
    
    On Error GoTo onError:

    Set lo_Sample_Upd = New Sample_Upd
    Load lo_Sample_Upd
    
    lo_Sample_Upd.ConnectString = ms_ConnectString
    If mb_use_framework_connection = True Then
        Set lo_Sample_Upd.ArmDb = mo_ArmDb
    End If
    lo_Sample_Upd.Language = m_Language
    
    lo_Sample_Upd.ActionType = GetCodeFromCombo(cbo_actionType)
    lo_Sample_Upd.QuantitySentEdit = (mi_DisplayMode = mt_CstValues.DisplayMode_Update)
    
    lo_Sample_Upd.ActionSample = ao_Sample.Tag.Caption
    lo_Sample_Upd.Quantity = IIf(ao_Sample.Tag.GetData(C_CKV_QTY_COL) <> "", ao_Sample.Tag.GetData(C_CKV_QTY_COL), "0")
    lo_Sample_Upd.HF = ao_Sample.Tag.GetData(C_CKV_HF_COL)
    lo_Sample_Upd.EdgeDetailCode = ao_Sample.Tag.GetData(C_CKV_EdgeDetailCode_COL)
    lo_Sample_Upd.EdgeDetailDesc = ao_Sample.Tag.GetData(C_CKV_EdgeDetailDesc_COL)
    
    If mi_DisplayMode = mt_CstValues.DisplayMode_Update Then
        lo_Sample_Upd.QuantitySent = IIf(ao_Sample.Tag.GetData(C_CKV_QTY_SENT_COL) = 0, ao_Sample.Tag.GetData(C_CKV_QTY_COL), ao_Sample.Tag.GetData(C_CKV_QTY_SENT_COL))
    Else
        lo_Sample_Upd.QuantitySent = ao_Sample.Tag.GetData(C_CKV_QTY_SENT_COL)
    End If
    lo_Sample_Upd.Comment = ao_Sample.Tag.GetData(C_CKV_Comment_COL)
    
'    lo_Sample_Upd.ActionSample = ao_Sample.Text
'    lo_Sample_Upd.Quantity = IIf(ao_Sample.ListSubItems(3).Text <> "", ao_Sample.ListSubItems(3).Text, "0")
'    lo_Sample_Upd.HF = ao_Sample.ListSubItems(4).Text
'    lo_Sample_Upd.EdgeDetailCode = ao_Sample.ListSubItems(5).Text
'    lo_Sample_Upd.EdgeDetailDesc = ao_Sample.ListSubItems(6).Text
'    lo_Sample_Upd.QuantitySent = ao_Sample.ListSubItems(7).Text
'    lo_Sample_Upd.Comment = ao_Sample.ListSubItems(8).Text
    
    lo_Sample_Upd.Load_A_COM
    
    CapMouseOn True
    lo_Sample_Upd.show vbModal
    CapMouseOff True
    
    If lo_Sample_Upd.Valid = True Then
    
        Call ao_Sample.Tag.SetData(C_CKV_QTY_COL, lo_Sample_Upd.Quantity)
        Call ao_Sample.Tag.SetData(C_CKV_HF_COL, lo_Sample_Upd.HF)
        Call ao_Sample.Tag.SetData(C_CKV_EdgeDetailCode_COL, lo_Sample_Upd.EdgeDetailCode)
        Call ao_Sample.Tag.SetData(C_CKV_EdgeDetailDesc_COL, lo_Sample_Upd.EdgeDetailDesc)
        Call ao_Sample.Tag.SetData(C_CKV_QTY_SENT_COL, lo_Sample_Upd.QuantitySent)
        Call ao_Sample.Tag.SetData(C_CKV_Comment_COL, lo_Sample_Upd.Comment)

        ' fix .. 21/03/2018 JN .. set DataChanged only in case we are in update mode
        If ckv_Sample.Mode = ModeView Then
            ao_Sample.Tag.DataChanged = True
        End If

        ' update subitems
        Dim ll_Index As Long
        If ao_Sample.Tag.length >= 0 Then
            For ll_Index = 0 To ao_Sample.Tag.length
              ao_Sample.ListSubItems(ll_Index + 1).Text = ao_Sample.Tag.GetData(ll_Index)
            Next
        End If
        
        ' if the raised for is selected then check also qty on the stock
        If RaisedForStockDepartment() <> 0 Then
            If CLng(ao_Sample.Tag.GetData(C_CKV_QTY_STOCK_COL)) < CLng(ao_Sample.Tag.GetData(C_CKV_QTY_COL)) Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 975, "#Requested qty is not on the stock.", "", vbInformation, "")
            End If
        End If
        
        UpdateSampleListItem = True
    End If
    
    'Call lo_Sample_Upd.Unload_A_Com
    Unload lo_Sample_Upd
    Set lo_Sample_Upd = Nothing
    Exit Function
onError:
    If Not lo_Sample_Upd Is Nothing Then
        Unload lo_Sample_Upd
        Set lo_Sample_Upd = Nothing
    End If
    UpdateSampleListItem = False

End Function
' END T298.WP7

' BEGIN T298.WP7
Private Function UpdateSampleNodeInfo(ao_Sample As NodeInfo) As Boolean
Dim lo_Sample_Upd As Sample_Upd

    UpdateSampleNodeInfo = False
    
    On Error GoTo onError:

    Debug.Assert Not (ao_Sample Is Nothing)
    Debug.Assert Not (ao_Sample.mo_Node.Parent Is Nothing)

    Set lo_Sample_Upd = New Sample_Upd
    Load lo_Sample_Upd
    
    lo_Sample_Upd.ConnectString = ms_ConnectString
    If mb_use_framework_connection = True Then
        Set lo_Sample_Upd.ArmDb = mo_ArmDb
    End If
    lo_Sample_Upd.Language = m_Language
    
    ' AT_Code of the action for selected SampleDocGroup parent in treeview
    lo_Sample_Upd.Caption = ao_Sample.mo_Node.Parent.Text
    lo_Sample_Upd.ActionType = ao_Sample.mo_Node.Parent.Tag.GetData(3)
    lo_Sample_Upd.ActionSample = ao_Sample.TextValue
    lo_Sample_Upd.Quantity = IIf(CStr(ao_Sample.GetData(3)) <> "", ao_Sample.GetData(3), "0")
    lo_Sample_Upd.QuantitySent = ao_Sample.GetData(8)
    lo_Sample_Upd.HF = CStr(ao_Sample.GetData(4))
    lo_Sample_Upd.EdgeDetailCode = CStr(ao_Sample.GetData(5))
    lo_Sample_Upd.EdgeDetailDesc = CStr(ao_Sample.GetData(6))
    lo_Sample_Upd.Comment = CStr(ao_Sample.GetData(7))
    
    lo_Sample_Upd.Load_A_COM

    CapMouseOn True
    lo_Sample_Upd.show vbModal
    CapMouseOff True
    
    If lo_Sample_Upd.Valid = True Then
        Call ao_Sample.SetData(3, lo_Sample_Upd.Quantity)
        Call ao_Sample.SetData(4, lo_Sample_Upd.HF)
        Call ao_Sample.SetData(5, lo_Sample_Upd.EdgeDetailCode)
        Call ao_Sample.SetData(6, lo_Sample_Upd.EdgeDetailDesc)
        Call ao_Sample.SetData(7, lo_Sample_Upd.Comment)
        Call ao_Sample.SetData(8, lo_Sample_Upd.QuantitySent)
        
        ' if the raised for is selected then check also qty on the stock
        If RaisedForStockDepartment() <> 0 Then
            If CLng(ao_Sample.GetData(9)) < CLng(ao_Sample.GetData(3)) Then
                Call ASC_SendMessage(mo_ArmDb, m_Language, 975, "#Requested qty is not on the stock.", "", vbInformation, "")
            End If
        End If

        UpdateSampleNodeInfo = True
    End If
    
    'Call lo_Sample_Upd.Unload_A_Com
    Unload lo_Sample_Upd
    Set lo_Sample_Upd = Nothing
    Exit Function
onError:
    If Not lo_Sample_Upd Is Nothing Then
        Unload lo_Sample_Upd
        Set lo_Sample_Upd = Nothing
    End If
    UpdateSampleNodeInfo = False

End Function
' END T298.WP7

' Return true if have created the node
Private Function FindInTreeView(ByVal aTV As ArmTreeView, ByVal aPath As String) As Boolean

    On Error GoTo onError:
    Dim lValues As Variant
    lValues = Split(aPath, SEP & SEP)

    Dim lIdx As Long, lCount As Long, lFoundedCount As Long
    lCount = UBound(lValues)
    Dim lData As Variant, lKey As String, lValue As String
    
    lData = Split(lValues(0), SEP)
    lKey = lData(0)
    lValue = lData(1)
    
    
    If Not aTV.Find(lKey, 0, , 0) Then
        aTV.AddNode(, lKey, lValue, 1, 2).Selected = True
        FindInTreeView = True
    End If
    
    lFoundedCount = 1
    Call aTV.ExpandNode(aTV.SelectedItem)

    For lIdx = 1 To lCount
        lData = Split(lValues(lIdx), SEP)
        lKey = lData(0)
        lValue = lData(1)
        If Not aTV.Find(lKey, 0, aTV.SelectedItem, lIdx) Then
            aTV.AddNode(aTV.SelectedItem, lKey, lValue, 1, 2).Selected = True
            Call tvItems_NodeClick(aTV.SelectedItem)
            FindInTreeView = True
            
        End If
        Call aTV.ExpandNode(aTV.SelectedItem)
        lFoundedCount = lFoundedCount + 1
    Next

    Exit Function
onError:
    'debug.print "Error in findintreeview"
End Function


Private Function GetCurrentPath(ByRef aControls As Variant, ByRef aContainer As Object, ByVal aPattern As String) As String

    Dim lPattern() As String
    lPattern = Split(aPattern, SEP)

    Dim lPath() As String
    lPath = lPattern

    Dim lIdxPattern As Long, lCountPattern As Long, lIdxPath As Long
    Dim lIdx As Long, lCount As Long, lIdxLbl As Long
    Dim lControl As Control, li As Long, lc As Long

    lCountPattern = UBound(lPattern)
    lCount = aControls.Count - 1
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        If HasContainer(lControl, aContainer) Then
            If lControl.Tag <> "" Then
            lIdxPath = -1
            For lIdxPattern = 0 To lCountPattern
                If StrComp(lControl.Tag, lPattern(lIdxPattern), vbTextCompare) = 0 Then
                    Select Case UCase(TypeName(lControl))
                        Case "TEXTBOX"
                            lPath(lIdxPattern) = lControl.Text & SEP & lControl.Text
                        Case "ARMCOMBOBOX"
                            lPath(lIdxPattern) = lControl.SelectedItem.Key & SEP & lControl.SelectedItem.DisplayText
                        Case "ARMCHECKVIEW0"
                            lc = lControl.ListItems.Count - 1
                            For li = 0 To lc
                                If lControl.ItemInfo(li).Checked = True Then
                                    lPath(lIdxPattern) = lControl.ItemInfo(li).Id & SEP & lControl.ItemInfo(li).Caption
                                    Exit For
                                End If
                            Next
                        Case "ARMCHECKVIEW"
                                If lControl.RoleList(lControl.GetVisibleList).CheckedCount Then
                                    lPath(lIdxPattern) = Trim(lControl.RoleList(lControl.GetVisibleList).CheckedKeys(0)(0))
                                Else
                                    lPath(lIdxPattern) = ""
                                End If
                        Case Else
                            'debug.print "GetCurrentPath" & UCase(TypeName(lControl))
                    End Select
                Exit For
                End If
            Next
            End If
        End If
        Set lControl = Nothing
    Next

    Dim lBuffer As String
    lBuffer = Join(lPath, SEP & SEP)
    
    
    ' PUT HERE THE EXCEPTION
    lBuffer = Replace(lBuffer, "txt_CustomerType", m_CCU_CCT_Code & SEP & m_CCU_CCT_Desc, , , vbTextCompare)
    lBuffer = Replace(lBuffer, "txt_country", m_CCU_CT_Code & SEP & m_CCU_CT_Desc, , , vbTextCompare)
    lBuffer = Replace(lBuffer, "txt_ActionRep", m_CCU_SR_Code & SEP & m_CCU_SR_Name, , , vbTextCompare)
    
    GetCurrentPath = lBuffer

End Function

Private Function HasContainer(ByRef aControl As Control, ByRef aContainer As Object) As Boolean
    
    HasContainer = False
    Dim lControl As Control
    
    Set lControl = aControl
    While Not (lControl Is Nothing)
        On Error GoTo NotFound
        If lControl.Container Is aContainer Then
            Set lControl = Nothing
            HasContainer = True
            Exit Function
        End If
        Set lControl = lControl.Container
    Wend

NotFound:
    Set lControl = Nothing
    HasContainer = False
End Function


Public Function Item_Filtered() As Boolean

   
    ' Check date
    If opt_date(1).Value = True Then
        Dim lDate As Date
        Select Case CStr(cbo_date.SelectedItem.Key)
            Case "1" ' Due date
                lDate = cal_dueDate.date_courte
            Case "2" ' Date entered
                lDate = txt_dateEntered.Text
            Case "3" ' Date last updated
                lDate = txt_lastUpdated.Text
            
        End Select
        
        ' CHECK
        If DateDiff("d", cal11.date_courte, lDate) < 0 Then
            Item_Filtered = True
            Exit Function
        End If
        
        If DateDiff("d", cal12.date_courte, lDate) > 0 Then
            Item_Filtered = True
            Exit Function
        End If
    End If
        
    Select Case tbsFilters.SelectedItem.Tag
        Case "tbs_filtersAll"
            ' DO NOTHING
        Case "tbs_filtersComp"
            Item_Filtered = (cbo_status.SelectedItem.Key <> ActionStatus.AS_COMPLETE)
        Case "tbs_filtersOut"
            Item_Filtered = (cbo_status.SelectedItem.Key <> ActionStatus.AS_OUTSTANDING)
    End Select
    
End Function

Public Sub Item_LocalUpdate()
    
    If Item_Filtered Then
        Call AddToTimeLog(mi_OldDisplayMode, 99)
        If ASC_SendMessage(mo_ArmDb, m_Language, 1006, "#The item you have added/updated couldn't be displayed with the current criteria set. Would you like to reset the filters to their original values ?", "", vbQuestion Or vbYesNo, "") = vbYes Then
            pctTvReset_Click
        Else
            Exit Sub
        End If
    End If
    
    Dim lPath As String
    
    lPath = GetCurrentPath(UserControl.Controls, fraItem, cbo_View.SelectedItem.GetData(2))
    tvitems.Visible = False
    Call FindInTreeView(tvitems, lPath)
    tvitems.Visible = True
    Call grdlst.SearchKey(True, Array(m_CurrentKey1, m_CurrentKey2, m_CurrentKey3))
            
End Sub

Public Sub Item_LocalUpdateFollowUp()

    Dim ll_curs As Long
    Dim ls_req As String
    Dim i As Long
    
    If cal_dueDate.date_courte >= md_DateUntil Then
        ReinitTreeViewAfterDelete grdlst, tvitems
    Else
        
        ls_req = "exec Cap_TVA_Action_gridh1 Null,'" & ms_UID & "',$lang$,'" & m_CurrentKey1 & "'"
        ls_req = ParamReqReplace1(ls_req)
        ll_curs = mo_ArmDb.OpenSQL(ls_req, -1, 0)
        If ll_curs <> 0 Then
            
            If mo_ArmDb.RowCount(ll_curs) <> 0 Then
                For i = 0 To grdlst.Cols - 1
                    grdlst.SelectedLine(0, i) = mo_ArmDb.GetFields(ll_curs, i)
                Next i
                
                If grdlst.SelectedLine(0, "DueDate") > Date Then
                    grdlst.LineColor(grdlst.Row) = FollowUpColor
                Else
                    grdlst.LineColor(grdlst.Row) = FollowUpColorExpired
                End If
            Else
                ReinitTreeViewAfterDelete grdlst, tvitems
            End If
    
        End If
        End If
        mo_ArmDb.Close (ll_curs)
            
End Sub

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

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

End Sub

' IMPLEMENT PROCESS T298.5-A.PR_001
Private Function ValidateActionDate()
    Dim ls_dateDiff As String    ' date defference
    Dim ls_Msg      As String
    
    ValidateActionDate = False
    
    ' If the action date is empty, the function return true to leave the normal process dealing with the error (action date is mandatory).
    If cal_dueDate.date_courte = "" Or Not IsDate(cal_dueDate.date_courte) Then
        ValidateActionDate = True
        Exit Function
    End If
    
    ls_dateDiff = Cap_Common.GetDefaultConfigCode("Action_Cfg", "ActionDateOffset")
    If isNumeric(ls_dateDiff) Then
        If Date - CLng(ls_dateDiff) > CDate(cal_dueDate.date_courte) Then
            ls_Msg = ASC_MsgText(mo_ArmDb, m_Language, 798, "#You are unable to create an action with a date ealier than $date$")
            ' replace placeholder
            ls_Msg = Replace(ls_Msg, "$date$", Format(Date - CLng(ls_dateDiff), "dd\/mm\/yyyy"))
            
            'set arrow mouse pointer
            Dim li_mouse As Integer
            li_mouse = Screen.MousePointer
            Screen.MousePointer = vbArrow
            
            Call MsgBox(ls_Msg, vbOKOnly, "Capture Online")
        
            'restore mouse pointer
            Screen.MousePointer = li_mouse
        Else
            ValidateActionDate = True
        End If
    Else
        ' default value not defined or containt wrong data
        Debug.Assert (False)
        ' to keep behaviour of old version we return true
        ValidateActionDate = True
    End If
    
End Function
' END PROCESS T298.5-A.PR_001

' IMPLEMENT PROCESS T298.5-A.PR_002
' COPY of Tools.ASC_MsgText
' Get an error message
Private Function ASC_MsgText(ByRef ao_Armdb As Object, ByVal as_LG_Code As String, ByVal ai_MsgID As Integer, Optional ByVal as_MsgDefault As String = "")
Dim lc_Msg As Long
Dim ls_Msg As String, ls_Request As String

    On Error GoTo Trace_Err
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc True, "Tools:ASC_MsgText", "LG_Code=" & as_LG_Code & ", ai_MsgID=" & ai_MsgID & ", as_MsgDefault=" & as_MsgDefault
    #End If
    CapMouseOff
    
    ls_Request = "SELECT Message_Text FROM Error_Message WHERE Language_Code = '" & as_LG_Code & "' AND MsgID = " & ai_MsgID
    lc_Msg = ao_Armdb.OpenSQL(ls_Request)
    If lc_Msg = 0 Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceSQLError ao_Armdb, "Tools:ASC_MsgText", "Request=" & ls_Request
        GoTo Trace_End
    End If
    
    ls_Msg = ao_Armdb.GetFields(lc_Msg, "MESSAGE_TEXT")
    
Trace_End:
    Call ao_Armdb.Close(lc_Msg)
    ASC_MsgText = IIf(Len(ls_Msg) <> 0, ls_Msg, as_MsgDefault)
    #If CapDebug Then
        If Not go_Trace Is Nothing Then go_Trace.WriteTraceProc False, "Tools:ASC_MsgText", "Result=" & ASC_MsgText
    #End If
    CapMouseOn
    Exit Function
    
Trace_Err:
    ASC_MsgText = ""
    Call ao_Armdb.Close(lc_Msg)
    If Not go_Trace Is Nothing Then go_Trace.WriteTraceError Err.Number, Err.Description, "Capact:ASC_MsgText"
    CapMouseOn
End Function
' END PROCESS T298.5-A.PR_002

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

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

