VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.ocx"
Begin VB.Form frmOfferPrdMainAlt 
   Caption         =   "#Main/Alternative Product"
   ClientHeight    =   11670
   ClientLeft      =   120
   ClientTop       =   510
   ClientWidth     =   18705
   LinkTopic       =   "Form2"
   MinButton       =   0   'False
   ScaleHeight     =   11670
   ScaleWidth      =   18705
   StartUpPosition =   1  'CenterOwner
   Tag             =   "frmOfferPrdMainAlt"
   Visible         =   0   'False
   Begin VB.Frame fra_OfferCopy 
      Height          =   6255
      Left            =   15
      TabIndex        =   8
      Tag             =   "fra_OfferCopy"
      Top             =   2610
      Width           =   18675
      Begin VB.Frame fra_Filter 
         Height          =   3255
         Left            =   75
         TabIndex        =   10
         Top             =   210
         Width           =   18585
         Begin VB.CommandButton btn_ResetListView 
            Caption         =   "#Reset"
            Height          =   390
            Left            =   13680
            TabIndex        =   30
            Tag             =   "btn_ResetListView"
            Top             =   120
            Width           =   1035
         End
         Begin MSComctlLib.TabStrip tbs_SearchAttrib 
            Height          =   375
            Left            =   8670
            TabIndex        =   25
            Top             =   165
            Width           =   6075
            _ExtentX        =   10716
            _ExtentY        =   661
            _Version        =   393216
            BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
               NumTabs         =   3
               BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#System"
                  Key             =   "tab_System"
                  Object.Tag             =   "tab_System"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Thickness"
                  Key             =   "tab_Thickness"
                  Object.Tag             =   "tab_Thickness"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Inlay"
                  Key             =   "tab_Inlay"
                  Object.Tag             =   "tab_Inlay"
                  ImageVarType    =   2
               EndProperty
            EndProperty
         End
         Begin VB.Frame fra_AttribList 
            Height          =   2715
            Left            =   8685
            TabIndex        =   50
            Tag             =   "fra_AttribList"
            Top             =   480
            Width           =   6045
            Begin MSComctlLib.ListView lvw_Attrib 
               Height          =   1335
               Index           =   0
               Left            =   465
               TabIndex        =   28
               Tag             =   "tab_System"
               Top             =   1380
               Width           =   2295
               _ExtentX        =   4048
               _ExtentY        =   2355
               View            =   3
               LabelEdit       =   1
               LabelWrap       =   -1  'True
               HideSelection   =   -1  'True
               HideColumnHeaders=   -1  'True
               Checkboxes      =   -1  'True
               _Version        =   393217
               ForeColor       =   -2147483640
               BackColor       =   -2147483643
               BorderStyle     =   1
               Appearance      =   1
               NumItems        =   1
               BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
                  Object.Width           =   2540
               EndProperty
            End
            Begin MSComctlLib.ListView lvw_Attrib 
               Height          =   1335
               Index           =   1
               Left            =   510
               TabIndex        =   27
               Tag             =   "tab_Thickness"
               Top             =   900
               Width           =   2295
               _ExtentX        =   4048
               _ExtentY        =   2355
               View            =   3
               LabelEdit       =   1
               LabelWrap       =   -1  'True
               HideSelection   =   -1  'True
               HideColumnHeaders=   -1  'True
               Checkboxes      =   -1  'True
               _Version        =   393217
               ForeColor       =   -2147483640
               BackColor       =   -2147483643
               BorderStyle     =   1
               Appearance      =   1
               NumItems        =   1
               BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
                  Object.Width           =   2540
               EndProperty
            End
            Begin MSComctlLib.ListView lvw_Attrib 
               Height          =   1335
               Index           =   2
               Left            =   405
               TabIndex        =   26
               Tag             =   "tab_Inlay"
               Top             =   660
               Width           =   2670
               _ExtentX        =   4710
               _ExtentY        =   2355
               View            =   3
               LabelEdit       =   1
               LabelWrap       =   -1  'True
               HideSelection   =   -1  'True
               HideColumnHeaders=   -1  'True
               Checkboxes      =   -1  'True
               _Version        =   393217
               ForeColor       =   -2147483640
               BackColor       =   -2147483643
               BorderStyle     =   1
               Appearance      =   1
               NumItems        =   1
               BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
                  Object.Width           =   4410
               EndProperty
            End
            Begin VB.Label lbl_ListView 
               AutoSize        =   -1  'True
               Caption         =   "list view header"
               Height          =   195
               Left            =   3870
               TabIndex        =   51
               Top             =   630
               Visible         =   0   'False
               Width           =   1095
            End
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   1
            Left            =   1740
            MaxLength       =   30
            TabIndex        =   12
            Tag             =   "PRD_Code"
            Top             =   570
            Width           =   1650
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   2
            Left            =   4830
            MaxLength       =   8
            TabIndex        =   17
            Tag             =   "RPL_ModA"
            Top             =   570
            Width           =   855
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   3
            Left            =   7410
            MaxLength       =   8
            TabIndex        =   18
            Tag             =   "RPL_ModB"
            Top             =   570
            Width           =   855
         End
         Begin VB.CheckBox chk_PlantCalcDone 
            Caption         =   "#Plant calc done"
            Height          =   195
            Left            =   14850
            TabIndex        =   34
            Tag             =   "chk_PlantCalcDone"
            Top             =   1350
            Width           =   1665
         End
         Begin VB.CheckBox chk_BothSides 
            Caption         =   "#Both sides"
            Height          =   195
            Left            =   6900
            TabIndex        =   23
            Tag             =   "chk_BothSides"
            Top             =   2055
            Width           =   1665
         End
         Begin VB.CheckBox chk_VisibleSide 
            Caption         =   "#Visible Side"
            Height          =   195
            Left            =   4845
            TabIndex        =   22
            Tag             =   "chk_VisibleSide"
            Top             =   2055
            Width           =   1665
         End
         Begin VB.CheckBox chk_CostNonZero 
            Caption         =   "#Cost > 0"
            Height          =   195
            Left            =   14850
            TabIndex        =   33
            Tag             =   "chk_CostNonZero"
            Top             =   990
            Width           =   1665
         End
         Begin Project1.A_calocx cal_CreateDateFrom 
            Height          =   360
            Left            =   16710
            TabIndex        =   31
            Top             =   165
            Width           =   1845
            _ExtentX        =   3254
            _ExtentY        =   635
         End
         Begin Project1.A_calocx cal_CreateDateTo 
            Height          =   360
            Left            =   16710
            TabIndex        =   32
            Top             =   510
            Width           =   1845
            _ExtentX        =   3254
            _ExtentY        =   635
         End
         Begin VB.CheckBox chk_SelectAll 
            Caption         =   "#Select all"
            Height          =   195
            Left            =   135
            TabIndex        =   36
            Tag             =   "chk_SelectAll"
            Top             =   2895
            Width           =   1665
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   8
            Left            =   1740
            MaxLength       =   30
            TabIndex        =   15
            Tag             =   "AMCProjectNumber"
            Top             =   1620
            Width           =   1650
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   7
            Left            =   1740
            MaxLength       =   30
            TabIndex        =   14
            Tag             =   "COF_CodeBae"
            Top             =   1275
            Width           =   1650
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   6
            Left            =   1740
            MaxLength       =   30
            TabIndex        =   13
            Tag             =   "COF_CodeSAP"
            Top             =   930
            Width           =   1650
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   4
            Left            =   4815
            MaxLength       =   80
            TabIndex        =   16
            Tag             =   "PRD_Name"
            Top             =   210
            Width           =   3465
         End
         Begin VB.TextBox txt_TextBox 
            Height          =   330
            Index           =   0
            Left            =   1740
            MaxLength       =   10
            TabIndex        =   11
            Tag             =   "COF_Code"
            Top             =   210
            Width           =   1650
         End
         Begin VB.CommandButton btn_LoadGrid 
            Caption         =   "#Load grid"
            Height          =   675
            Left            =   14850
            TabIndex        =   35
            Tag             =   "btn_LoadGrid"
            Top             =   2430
            Width           =   3630
         End
         Begin Project1.ArmCombobox cbo_Material 
            Height          =   345
            Left            =   4830
            TabIndex        =   19
            Tag             =   "MAT_Id"
            Top             =   930
            Width           =   3465
            _ExtentX        =   6112
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_Perforation 
            Height          =   345
            Left            =   4830
            TabIndex        =   20
            Tag             =   "PRF_Id"
            Top             =   1275
            Width           =   3465
            _ExtentX        =   6112
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_Coating 
            Height          =   345
            Left            =   4830
            TabIndex        =   21
            Tag             =   "COA_Id"
            Top             =   1620
            Width           =   3465
            _ExtentX        =   6112
            _ExtentY        =   609
         End
         Begin Project1.ArmCombobox cbo_Qty 
            Height          =   345
            Left            =   4830
            TabIndex        =   24
            Tag             =   "COA_Id"
            Top             =   2355
            Width           =   3465
            _ExtentX        =   6112
            _ExtentY        =   609
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Module A"
            Height          =   255
            Index           =   3
            Left            =   3465
            TabIndex        =   49
            Tag             =   "lbl_ModA"
            Top             =   615
            Width           =   1560
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Module B"
            Height          =   255
            Index           =   4
            Left            =   5835
            TabIndex        =   48
            Tag             =   "lbl_ModB"
            Top             =   608
            Width           =   1560
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Qty"
            Height          =   255
            Index           =   15
            Left            =   3465
            TabIndex        =   47
            Tag             =   "lbl_Qty"
            Top             =   2400
            Width           =   960
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Creation to"
            Height          =   255
            Index           =   14
            Left            =   14850
            TabIndex        =   46
            Tag             =   "lbl_CreatedTo"
            Top             =   585
            Width           =   1740
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Creation from"
            Height          =   255
            Index           =   29
            Left            =   14850
            TabIndex        =   45
            Tag             =   "lbl_CreatedFrom"
            Top             =   225
            Width           =   1740
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#AS Project-no"
            Height          =   255
            Index           =   13
            Left            =   90
            TabIndex        =   44
            Tag             =   "lbl_ASProjectNr"
            Top             =   1665
            Width           =   1620
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#B7 Sales Order"
            Height          =   255
            Index           =   12
            Left            =   90
            TabIndex        =   43
            Tag             =   "lbl_B7SalesOrderCode"
            Top             =   1320
            Width           =   1620
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#SAP Sales Order"
            Height          =   255
            Index           =   11
            Left            =   90
            TabIndex        =   42
            Tag             =   "lbl_SAPSalesOrderCode"
            Top             =   975
            Width           =   1620
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Coating"
            Height          =   255
            Index           =   9
            Left            =   3465
            TabIndex        =   41
            Tag             =   "lbl_Perforation"
            Top             =   1665
            Width           =   1560
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Perforation"
            Height          =   255
            Index           =   8
            Left            =   3465
            TabIndex        =   40
            Tag             =   "lbl_Perforation"
            Top             =   1320
            Width           =   1560
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Material"
            Height          =   255
            Index           =   6
            Left            =   3465
            TabIndex        =   39
            Tag             =   "lbl_Material"
            Top             =   975
            Width           =   1560
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Name"
            Height          =   255
            Index           =   5
            Left            =   3465
            TabIndex        =   38
            Tag             =   "lbl_Name"
            Top             =   255
            Width           =   1560
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Offer code"
            Height          =   255
            Index           =   0
            Left            =   90
            TabIndex        =   37
            Tag             =   "lbl_OfferCode"
            Top             =   255
            Width           =   1620
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Product code"
            Height          =   255
            Index           =   1
            Left            =   90
            TabIndex        =   29
            Tag             =   "lbl_ProductCode"
            Top             =   615
            Width           =   1620
         End
      End
      Begin Project1.ArmGrid grd_PosList 
         Height          =   2475
         Left            =   315
         TabIndex        =   9
         TabStop         =   0   'False
         Tag             =   "grd_PosList"
         Top             =   3435
         Width           =   6315
         _ExtentX        =   11139
         _ExtentY        =   4366
      End
   End
   Begin VB.CommandButton btn_Quit 
      Height          =   612
      Left            =   17130
      Style           =   1  'Graphical
      TabIndex        =   5
      Tag             =   "btn_Quit"
      Top             =   10920
      Width           =   612
   End
   Begin VB.CommandButton btn_Validate 
      Height          =   612
      Left            =   16455
      Style           =   1  'Graphical
      TabIndex        =   4
      Tag             =   "btn_Validate"
      Top             =   10920
      Width           =   612
   End
   Begin VB.Frame fra_MainAlt 
      Height          =   1695
      Left            =   15
      TabIndex        =   0
      Tag             =   "fra_MainAlt"
      Top             =   450
      Width           =   3780
      Begin VB.CheckBox chk_ResetQty 
         Caption         =   "#Reset quantity"
         Height          =   240
         Left            =   3150
         TabIndex        =   6
         Tag             =   "chk_ResetQty"
         Top             =   330
         Value           =   1  'Checked
         Width           =   2040
      End
      Begin Project1.ArmCombobox cbo_Alternative 
         Height          =   345
         Left            =   120
         TabIndex        =   3
         Top             =   1170
         Width           =   10335
         _ExtentX        =   18230
         _ExtentY        =   609
      End
      Begin VB.OptionButton opt_MainAlt 
         Caption         =   "#Alternative product"
         Height          =   285
         Index           =   1
         Left            =   315
         TabIndex        =   2
         Tag             =   "opt_Alternative"
         Top             =   735
         Width           =   2985
      End
      Begin VB.OptionButton opt_MainAlt 
         Caption         =   "#Main product"
         Height          =   285
         Index           =   0
         Left            =   315
         TabIndex        =   1
         Tag             =   "opt_Main"
         Top             =   315
         Width           =   2775
      End
   End
   Begin MSComctlLib.TabStrip tbs_Main 
      Height          =   375
      Left            =   0
      TabIndex        =   7
      Top             =   30
      Width           =   6525
      _ExtentX        =   11509
      _ExtentY        =   661
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   2
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "#From this offer"
            Key             =   "fra_MainAlt"
            Object.Tag             =   "tbs_ThisOffer"
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "#From other Offer"
            Key             =   "fra_OfferCopy"
            Object.Tag             =   "tbs_OtherOffer"
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmOfferPrdMainAlt"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const CL_COLOR_ENABLED As Long = &H80000005
Private Const CL_COLOR_DISABLED As Long = &H8000000F

Private Const C_ERRORRAISE As Long = 2500
Private Const SEP = "®©"
Private Const C_SEP As String = "@@"
Private Const SEP1 As String = "®"
Private Const SEP2 As String = "©"
Private Const SCREEN_NAME As String = "frmOfferPrdMainAlt"

'checkview messages for driving checkview behaviour
Private Const LVM_FIRST = &H1000
Private Const LVM_GETCOLUMNWIDTH = LVM_FIRST + 29
Private Const LVM_SETCOLUMNWIDTH = LVM_FIRST + 30
Private Const LVSCW_AUTOSIZE = -1
Private Const LVSCW_AUTOSIZE_USEHEADER = -2

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 me_PriceBookType As eDPCPriceBookType
Private ml_U_Code As Long
Private ms_Language_Code As String
Private mc_ScreenLabels As Long
Private mb_InternalInit As Boolean
Private ml_ActiveRow As Long
Private mo_Tools As DPC_Tools

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

Public Result As Boolean
Public COF_Id As String
'Public COF_IdSrc As String
Public OFD_Id As String
Public ResetQty As Boolean
Public IsAlt As Boolean
Public AltParent As String
Public AltParentName As String
                           
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
                           
Property Let Language_Code(AString As String)
  ms_Language_Code = AString
End Property

Property Get Language_Code() As String
  Language_Code = ms_Language_Code
End Property

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

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

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

Property Let U_Code(al_Code As Long)
  ml_U_Code = al_Code
End Property

Public Sub Load_A_COM()
On Error GoTo ErrHandler
    
Dim ls_Req As String
Dim la_Columns As Variant
Dim ll_Idx As Long
Dim lvw_Listview As MSComctlLib.ListView

  If mo_Db Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  If mo_Tools Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  btn_Validate.Picture = LoadResPicture(RES_OK, 1)
  btn_Quit.Picture = LoadResPicture(RES_QUIT, 1)
  Set mo_FSO = New FileSystemObject
  
  Result = False
  
  Call mo_Tools.Load_A_ComControls(Me.Controls, mo_Db, ms_Language_Code)
  
  ls_Req = "exec Cap_OfferDetail_cbo $COF_Id$, $Language_Code$, $OFD_Main$, $OFD_IsAlt$"
  'ls_Req = "SELECT OFD_Id,PRD_Code + ' - ' + PRD_Name FROM Cap_OfferDetail WHERE COF_Id=$COF_Id$ AND OFD_Main=1 AND OFD_IsAlt=0"
  ls_Req = Replace(ls_Req, "$COF_Id$", mo_Tools.SQLStr(COF_Id), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$OFD_Main$", mo_Tools.SqlInt(eDPCOfferDetailMain.odMain), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$OFD_IsAlt$", mo_Tools.SqlInt(0), , , vbTextCompare)
  ls_Req = ReplaceCommonPlaceholders(ls_Req)
  cbo_Alternative.Request = ls_Req
  
  'cbo_System.FirstBlankItem = True
  'cbo_System.Request = ReplaceCommonPlaceholders("exec DPC_System_cbo $Language_Code$")
  cbo_Material.FirstBlankItem = True
  cbo_Material.Request = ReplaceCommonPlaceholders("exec DPC_Material_lst2 $Language_Code$")
  
  cbo_Perforation.FirstBlankItem = True
  cbo_Perforation.Request = ReplaceCommonPlaceholders("exec DPC_Perforation_lst2 $Language_Code$, NULL, NULL")
  cbo_Coating.FirstBlankItem = True
  ls_req = "exec DPC_BOM_Search_cbo $Language_Code$, $BOM_Categ$"
  ls_req = Replace(ls_req, "$BOM_Categ$", mo_Tools.SqlInt(eDPCBOMMaterial.bcCoating), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_Coating.Request = ls_req
  
  cbo_Qty.FirstBlankItem = True
  cbo_Qty.Request = ReplaceCommonPlaceholders("exec A_Referencies_Cus_lst 21, NULL")
  
  'cbo_Inlay.FirstBlankItem = True
  'cbo_Inlay.Request = ReplaceCommonPlaceholders("exec DPC_Inlay_lst $Language_Code$")
  
  Call Resize
  Call tbs_Main_Click
  
  ReDim la_Columns(140) As Variant
  'la_Columns(0) = "OFD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "OFD_Id" & CH_LDELIMIT & ""
  'la_Columns(1) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  'la_Columns(2) = "Selected" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Selected" & CH_LDELIMIT & "#Sel" & CH_LDELIMIT & "BITMAP"
  'la_Columns(3) = "OFD_Pos" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  'la_Columns(4) = "OFD_PosCus" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosCus" & CH_LDELIMIT & "#Pos cus."
  'la_Columns(5) = "LEV_IdBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_IdBMP" & CH_LDELIMIT & "#Level" & CH_LDELIMIT & "BITMAP"
  'la_Columns(6) = "Err_TypeBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Err_TypeBMP" & CH_LDELIMIT & "#Err" & CH_LDELIMIT & "BITMAP"
 '
 ' la_Columns(7) = "RPL_DrwNr" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_DrwNr" & CH_LDELIMIT & "#Drawing Nr."
 ' la_Columns(8) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#AMC Code"
 ' la_Columns(9) = "PRD_Name" & CH_LDELIMIT & "1900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
 ' la_Columns(10) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Quantity"
 ' la_Columns(11) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#Unit of measure"
 ' la_Columns(12) = "UM_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#Unit of measure"
 '
 ' la_Columns(13) = "RPL_ModA" & CH_LDELIMIT & "750" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_ModA" & CH_LDELIMIT & "#Module (L)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
 ' la_Columns(14) = "RPL_ModB" & CH_LDELIMIT & "750" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_ModB" & CH_LDELIMIT & "#Module (W)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
 ' la_Columns(15) = "RPL_PanA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanA" & CH_LDELIMIT & "#Panel (L)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
 ' la_Columns(16) = "RPL_PanB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanB" & CH_LDELIMIT & "#Panel (W)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
 '
 ' la_Columns(17) = "RPL_StdMa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_StdMa" & CH_LDELIMIT & "#Std. mat." & CH_LDELIMIT & "BITMAP"
 ' la_Columns(18) = "MAT_Name" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MAT_Name" & CH_LDELIMIT & "#Material"
 ' la_Columns(19) = "RPL_MatTyp" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MatTyp" & CH_LDELIMIT & "#Mat.type"
 ' la_Columns(20) = "RPL_Thick" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_Thick" & CH_LDELIMIT & "#Thickness" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  
  
  la_Columns(0) = "OFD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "OFD_Id" & CH_LDELIMIT & ""
  la_Columns(1) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "Selected" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Selected" & CH_LDELIMIT & "#Sel" & CH_LDELIMIT & "BITMAP"
  la_Columns(3) = "COF_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Id" & CH_LDELIMIT & ""
  la_Columns(4) = "COF_Code" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Code" & CH_LDELIMIT & "#Offer code"
  la_Columns(5) = "OFD_Pos" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(6) = "OFD_PosCus" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosCus" & CH_LDELIMIT & "#Pos cus."
  la_Columns(7) = "LEV_IdBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_IdBMP" & CH_LDELIMIT & "#Level" & CH_LDELIMIT & "BITMAP"
  la_Columns(8) = "Err_TypeBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Err_TypeBMP" & CH_LDELIMIT & "#Err" & CH_LDELIMIT & "BITMAP"
  la_Columns(9) = "STA_BOMBMP" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_BOMBMP" & CH_LDELIMIT & "#BOM" & CH_LDELIMIT & "BITMAP"
  la_Columns(10) = "STA_BORBMP" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_BORBMP" & CH_LDELIMIT & "#BOR" & CH_LDELIMIT & "BITMAP"
  la_Columns(11) = "STA_Desc" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_Desc" & CH_LDELIMIT & "#Status"
  
  la_Columns(12) = "RPL_DrwNr" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_DrwNr" & CH_LDELIMIT & "#Drawing Nr."
  la_Columns(13) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#AMC Code"
  la_Columns(14) = "PRD_Name" & CH_LDELIMIT & "1900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(15) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Quantity" & CH_LDELIMIT & "FLOAT"
  la_Columns(16) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#Unit of measure"
  la_Columns(17) = "UM_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#Unit of measure"
  
  la_Columns(18) = "OFD_CostPCS" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_CostPCS" & CH_LDELIMIT & "#Cost [pcs]" & CH_LDELIMIT & "FLOAT"
  la_Columns(19) = "OFD_CostM2" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_CostM2" & CH_LDELIMIT & "#Cost [m2]" & CH_LDELIMIT & "FLOAT"
  
  la_Columns(20) = "RPL_ModA" & CH_LDELIMIT & "750" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_ModA" & CH_LDELIMIT & "#Module (L)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(21) = "RPL_ModB" & CH_LDELIMIT & "750" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_ModB" & CH_LDELIMIT & "#Module (W)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(22) = "RPL_PanA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanA" & CH_LDELIMIT & "#Panel (L)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(23) = "RPL_PanB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanB" & CH_LDELIMIT & "#Panel (W)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  la_Columns(24) = "RPL_StdMa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_StdMa" & CH_LDELIMIT & "#Std. mat." & CH_LDELIMIT & "BITMAP"
  la_Columns(25) = "MAT_Name" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MAT_Name" & CH_LDELIMIT & "#Material"
  la_Columns(26) = "RPL_MatTyp" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MatTyp" & CH_LDELIMIT & "#Mat.type"
  la_Columns(27) = "RPL_Thick" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_Thick" & CH_LDELIMIT & "#Thickness" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(28) = "RPL_SBndA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SBndA" & CH_LDELIMIT & "#St.A" & CH_LDELIMIT & "BITMAP"
  la_Columns(29) = "RPL_SUZA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SUZA" & CH_LDELIMIT & "#St.UZA" & CH_LDELIMIT & "BITMAP"
  la_Columns(30) = "RPL_SBndB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SBndB" & CH_LDELIMIT & "#St.B" & CH_LDELIMIT & "BITMAP"
  la_Columns(31) = "RPL_SUZB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SUZB" & CH_LDELIMIT & "#St.UZB" & CH_LDELIMIT & "BITMAP"
  
  la_Columns(32) = "BND_NameC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameC" & CH_LDELIMIT & "#Side C"
  la_Columns(33) = "RPL_HC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HC" & CH_LDELIMIT & "#HC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(34) = "RPL_UMinC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMinC" & CH_LDELIMIT & "#Min.UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(35) = "RPL_UMaxC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMaxC" & CH_LDELIMIT & "#Max.UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(36) = "RPL_UC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UC" & CH_LDELIMIT & "#UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(37) = "RPL_NCloC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloC" & CH_LDELIMIT & "#Notch closed C" & CH_LDELIMIT & "BITMAP"
  la_Columns(38) = "RPL_BVisC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisC" & CH_LDELIMIT & "#Bend.vis. C" & CH_LDELIMIT & "BITMAP"

  la_Columns(39) = "BND_NameD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameD" & CH_LDELIMIT & "#Side D"
  la_Columns(40) = "RPL_HD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HD" & CH_LDELIMIT & "#HD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(41) = "RPL_UMinD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMinD" & CH_LDELIMIT & "#Min.UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(42) = "RPL_UMaxD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMaxD" & CH_LDELIMIT & "#Max.UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(43) = "RPL_UD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UD" & CH_LDELIMIT & "#UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(44) = "RPL_NCloD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloD" & CH_LDELIMIT & "#Notch closed D" & CH_LDELIMIT & "BITMAP"
  la_Columns(45) = "RPL_BVisD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisD" & CH_LDELIMIT & "#Bend.vis. D" & CH_LDELIMIT & "BITMAP"

  la_Columns(46) = "RPL_CoWMin" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoWMin" & CH_LDELIMIT & "#Coil min." & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(47) = "RPL_CoWMax" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoWMax" & CH_LDELIMIT & "#Coil max." & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(48) = "RPL_CoilW" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoilW" & CH_LDELIMIT & "#Coil used" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(49) = "RPL_IsCoCut" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_IsCoCut" & CH_LDELIMIT & "#Coil cut" & CH_LDELIMIT & "BITMAP"
  la_Columns(50) = "RPL_CutA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CutA" & CH_LDELIMIT & "#Cut Length" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(51) = "RPL_CutB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CutB" & CH_LDELIMIT & "#Cut Width" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(52) = "RPL_SC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SC" & CH_LDELIMIT & "#SC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(53) = "RPL_SD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SD" & CH_LDELIMIT & "#SD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(54) = "RPL_IsCoF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_IsCoF" & CH_LDELIMIT & "#Coil found" & CH_LDELIMIT & "BITMAP"
  la_Columns(55) = "BND_NameE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameE" & CH_LDELIMIT & "#Side E"
  la_Columns(56) = "RPL_HE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HE" & CH_LDELIMIT & "#HE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(57) = "RPL_UE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UE" & CH_LDELIMIT & "#UZE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(58) = "RPL_SE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SE" & CH_LDELIMIT & "#SE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(59) = "RPL_NCloE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloE" & CH_LDELIMIT & "#Notch closed E" & CH_LDELIMIT & "BITMAP"
  la_Columns(60) = "RPL_BVisE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisE" & CH_LDELIMIT & "#Bend.vis. E" & CH_LDELIMIT & "BITMAP"
  la_Columns(61) = "BND_NameF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameF" & CH_LDELIMIT & "#Side F"
  la_Columns(62) = "RPL_HF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HF" & CH_LDELIMIT & "#HF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(63) = "RPL_UF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UF" & CH_LDELIMIT & "#UZF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(64) = "RPL_SF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SF" & CH_LDELIMIT & "#SF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(65) = "RPL_NCloF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloF" & CH_LDELIMIT & "#Notch closed F" & CH_LDELIMIT & "BITMAP"
  la_Columns(66) = "RPL_BVisF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisF" & CH_LDELIMIT & "#Bend.vis. F" & CH_LDELIMIT & "BITMAP"
  
  
  la_Columns(67) = "PRF_Name" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Name" & CH_LDELIMIT & "#Perforation"
  la_Columns(68) = "PRF_Class" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Class" & CH_LDELIMIT & "#Perf.class"
  la_Columns(69) = "RPL_PBordDesc" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PBordDesc" & CH_LDELIMIT & "#Perf.bord"
  la_Columns(70) = "RPL_PSpTypDesc" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PStepDesc" & CH_LDELIMIT & "#Step type"
  la_Columns(71) = "RPL_PStep" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PStep" & CH_LDELIMIT & "#Step"

  la_Columns(72) = "RPL_UBoWC" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWC" & CH_LDELIMIT & "#W-C" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(73) = "RPL_UBoWD" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWD" & CH_LDELIMIT & "#W-D" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(74) = "RPL_UBoWE" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWE" & CH_LDELIMIT & "#W-E" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(75) = "RPL_UBoWF" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWF" & CH_LDELIMIT & "#W-F" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(76) = "RPL_UBorC" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorC" & CH_LDELIMIT & "#R-C" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(77) = "RPL_UBorD" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorD" & CH_LDELIMIT & "#R-D" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(78) = "RPL_UBorE" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorE" & CH_LDELIMIT & "#R-E" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(79) = "RPL_UBorF" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorF" & CH_LDELIMIT & "#R-F" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(80) = "CUT_Name1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name1" & CH_LDELIMIT & "#Cut 1"
  la_Columns(81) = "PCT_SizeJ1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ1" & CH_LDELIMIT & "#J1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(82) = "PCT_SizeK1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK1" & CH_LDELIMIT & "#K1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(83) = "PCT_SizeD1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD1" & CH_LDELIMIT & "#D1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(84) = "PCT_SizeL1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL1" & CH_LDELIMIT & "#L1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(85) = "PCT_SizeM1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM1" & CH_LDELIMIT & "#M1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(86) = "CUT_Name2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name2" & CH_LDELIMIT & "#Cut 2"
  la_Columns(87) = "PCT_SizeJ2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ2" & CH_LDELIMIT & "#J2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(88) = "PCT_SizeK2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK2" & CH_LDELIMIT & "#K2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(89) = "PCT_SizeD2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD2" & CH_LDELIMIT & "#D2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(90) = "PCT_SizeL2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL2" & CH_LDELIMIT & "#L2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(91) = "PCT_SizeM2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM2" & CH_LDELIMIT & "#M2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(92) = "CUT_Name3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name3" & CH_LDELIMIT & "#Cut 3"
  la_Columns(93) = "PCT_SizeJ3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ3" & CH_LDELIMIT & "#J3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(94) = "PCT_SizeK3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK3" & CH_LDELIMIT & "#K3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(95) = "PCT_SizeD3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD3" & CH_LDELIMIT & "#D3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(96) = "PCT_SizeL3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL3" & CH_LDELIMIT & "#L3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(97) = "PCT_SizeM3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM3" & CH_LDELIMIT & "#M3"
  la_Columns(98) = "CUT_Name4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name4" & CH_LDELIMIT & "#Cut 4"
  la_Columns(99) = "PCT_SizeJ4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ4" & CH_LDELIMIT & "#J4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(100) = "PCT_SizeK4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK4" & CH_LDELIMIT & "#K4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(101) = "PCT_SizeD4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD4" & CH_LDELIMIT & "#D4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(102) = "PCT_SizeL4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL4" & CH_LDELIMIT & "#L4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(103) = "PCT_SizeM4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM4" & CH_LDELIMIT & "#M4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(104) = "COA_Name" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_Name" & CH_LDELIMIT & "#Coating"
  la_Columns(105) = "RPL_CoSidDesc" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoSidDesc" & CH_LDELIMIT & "#Coating side"
  la_Columns(106) = "RPL_BVisC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisC" & CH_LDELIMIT & "#Vis.C" & CH_LDELIMIT & "BITMAP"
  la_Columns(107) = "RPL_BVisD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisD" & CH_LDELIMIT & "#Vis.D" & CH_LDELIMIT & "BITMAP"
  la_Columns(108) = "RPL_BVisE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisE" & CH_LDELIMIT & "#Vis.E" & CH_LDELIMIT & "BITMAP"
  la_Columns(109) = "RPL_BVisF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisF" & CH_LDELIMIT & "#Vis.F" & CH_LDELIMIT & "BITMAP"
  la_Columns(110) = "GSK_Exist" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Exist" & CH_LDELIMIT & "#Gasket" & CH_LDELIMIT & "BITMAP"
  la_Columns(111) = "GSK_NameC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameC" & CH_LDELIMIT & "#Gsk C"
  la_Columns(112) = "GSK_NameD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameD" & CH_LDELIMIT & "#Gsk D"
  la_Columns(113) = "GSK_NameE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameE" & CH_LDELIMIT & "#Gsk E"
  la_Columns(114) = "GSK_NameF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameF" & CH_LDELIMIT & "#Gsk F"
  la_Columns(115) = "GSK_Exist2" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Exist2" & CH_LDELIMIT & "#Spacer" & CH_LDELIMIT & "BITMAP"
  la_Columns(116) = "GSK_Name2C" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2C" & CH_LDELIMIT & "#Spc C"
  la_Columns(117) = "GSK_Name2D" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2D" & CH_LDELIMIT & "#Spc D"
  la_Columns(118) = "GSK_Name2E" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2E" & CH_LDELIMIT & "#Spc E"
  la_Columns(119) = "GSK_Name2F" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2F" & CH_LDELIMIT & "#Spc F"
  
  la_Columns(120) = "INL_Name1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name1" & CH_LDELIMIT & "#Inlay1"
  la_Columns(121) = "INL_Code1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code1" & CH_LDELIMIT & "#Inlay code1"
  la_Columns(122) = "PIN_PurchDesc1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc1" & CH_LDELIMIT & "#Purchase1"
  la_Columns(123) = "PIN_DelivDesc1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc1" & CH_LDELIMIT & "#Delivery1"

  la_Columns(124) = "INL_Name2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name2" & CH_LDELIMIT & "#Inlay2"
  la_Columns(125) = "INL_Code2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code2" & CH_LDELIMIT & "#Inlay code2"
  la_Columns(126) = "PIN_PurchDesc2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc2" & CH_LDELIMIT & "#Purchase2"
  la_Columns(127) = "PIN_DelivDesc2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc2" & CH_LDELIMIT & "#Delivery2"
  
  la_Columns(128) = "INL_Name3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name3" & CH_LDELIMIT & "#Inlay3"
  la_Columns(129) = "INL_Code3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code3" & CH_LDELIMIT & "#Inlay code3"
  la_Columns(130) = "PIN_PurchDesc3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc3" & CH_LDELIMIT & "#Purchase3"
  la_Columns(131) = "PIN_DelivDesc3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc3" & CH_LDELIMIT & "#Delivery3"

  la_Columns(132) = "PKG_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PKG_Name" & CH_LDELIMIT & "#Packing"
  la_Columns(133) = "LAB_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LAB_Name" & CH_LDELIMIT & "#Label"
  la_Columns(134) = "RPL_PU" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PU" & CH_LDELIMIT & "#Packing unit"

  la_Columns(135) = "RPL_AGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_AGroup" & CH_LDELIMIT & "#Art grp"
  la_Columns(136) = "RPL_MGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MGroup" & CH_LDELIMIT & "#Good grp"
  la_Columns(137) = "RPL_PGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PGroup" & CH_LDELIMIT & "#Prd grp"
  la_Columns(138) = "RPL_OGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_OGroup" & CH_LDELIMIT & "#Obj grp"
  la_Columns(139) = "RPL_WghPnt" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_WghPnt" & CH_LDELIMIT & "#Wgh pnt"
  la_Columns(140) = "PRD_InternalComm" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_InternalComment" & CH_LDELIMIT & "#Int.comment"
  
  
  grd_PosList.AllowExcelExport = True
  Call grd_PosList.SetColumns(la_Columns)
  grd_PosList.ExportOnlyVisibleColumns = True
  
  'Screen csts
  mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, Me.Controls, Me, SCREEN_NAME, ms_Language_Code)
  Call mo_Tools.ChangeCharset(Me.Controls, gl_CodePage, gl_CodePage, Me)

  Set lvw_Listview = GetListView("tab_System", lvw_Attrib)
  ls_Req = "exec DPC_System_lst2 $Language_Code$, NULL, NULL, NULL"
  ls_Req = ReplaceCommonPlaceholders(ls_Req)
  Call LoadListView(lvw_Listview, ls_Req)
  Call SetAutoSize(lvw_Listview)
  
  Set lvw_Listview = GetListView("tab_Thickness", lvw_Attrib)
  ls_Req = "exec A_Referencies_Cus_lst 20, NULL"
  Call LoadListView(lvw_Attrib(1), ls_Req)
  Call SetAutoSize(lvw_Listview)
  
  Set lvw_Listview = GetListView("tab_Inlay", lvw_Attrib)
  ls_Req = "exec DPC_Inlay_lst $Language_Code$"
  ls_Req = ReplaceCommonPlaceholders(ls_Req)
  Call LoadListView(lvw_Attrib(2), ls_Req)
  Call SetAutoSize(lvw_Listview)
  
  Call SetListViewVisibility(tbs_SearchAttrib, lvw_Attrib)
  For ll_Idx = 1 To tbs_SearchAttrib.Tabs.Count
    Call MarkTabWithCheckedCount(tbs_SearchAttrib.Tabs(ll_Idx), lvw_Attrib)
  Next
  
  Result = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("Load_A_COM")
End Sub

Public Sub Unload_A_COM()
On Error GoTo ErrHandler

  Call mo_Tools.Unload_A_ComControls(Me.Controls)
  Call mo_Db.Close(mc_ScreenLabels)
  Set mo_Db = Nothing
  Set mo_FSO = Nothing
  Exit Sub
ErrHandler:
  Call ErrorHandler("Unload_A_COM")
End Sub

Private Sub btn_Quit_Click()
On Error GoTo ErrHandler
  
  Result = False
  Hide
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_Quit_Click")
End Sub

Private Sub btn_Validate_Click()
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  
  If StrComp(tbs_Main.SelectedItem.Key, fra_MainAlt.Name, vbTextCompare) = 0 Then
    ResetQty = (chk_ResetQty.Value = vbChecked)
    If opt_MainAlt(0).Value Then
      IsAlt = False
      AltParent = ""
      AltParentName = ""
    Else
      If cbo_Alternative.SelectedItem Is Nothing Then
        Call mo_Tools.LockScreen(Me, False)
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9724, "#Please, select main product")
        Exit Sub
      End If
      IsAlt = True
      AltParent = cbo_Alternative.SelectedItem.Key
      AltParentName = cbo_Alternative.Text
    End If
  Else
    If GetSelectedCount = 0 Then
      Call mo_Tools.LockScreen(Me, False)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9724, "#Please, select main product")
      Exit Sub
    End If
  End If
  Result = True
  Hide
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_Validate_Click")
End Sub

Private Sub Form_Activate()
Dim lvw_Listview As MSComctlLib.ListView
Dim ls_Req As String
Dim ll_Idx As Long

  Set lvw_Listview = GetListView("tab_System", lvw_Attrib)
  ls_Req = "exec DPC_System_lst2 $Language_Code$, NULL, 'X', NULL"
  ls_Req = ReplaceCommonPlaceholders(ls_Req)
  Call LoadListView(lvw_Listview, ls_Req)
  Call SetAutoSize(lvw_Listview)
  
  Set lvw_Listview = GetListView("tab_Thickness", lvw_Attrib)
  ls_Req = "exec A_Referencies_Cus_lst 20, NULL"
  Call LoadListView(lvw_Attrib(1), ls_Req)
  Call SetAutoSize(lvw_Listview)
  
  Set lvw_Listview = GetListView("tab_Inlay", lvw_Attrib)
  ls_Req = "exec DPC_Inlay_lst $Language_Code$"
  ls_Req = ReplaceCommonPlaceholders(ls_Req)
  Call LoadListView(lvw_Attrib(2), ls_Req)
  Call SetAutoSize(lvw_Listview)
  
  Call SetListViewVisibility(tbs_SearchAttrib, lvw_Attrib)
  For ll_Idx = 1 To tbs_SearchAttrib.Tabs.Count
    Call MarkTabWithCheckedCount(tbs_SearchAttrib.Tabs(ll_Idx), lvw_Attrib)
  Next

End Sub

Private Sub Form_Resize()
On Error GoTo ErrHandler

  Call Resize
  Exit Sub
ErrHandler:
  Call ErrorMessage("Form_Resize")
End Sub

Private Function GetListViewCheckedCount(ByRef ao_Listview As MSComctlLib.ListView)
On Error GoTo ErrHandler
  Dim ll_Idx As Long
  Dim ll_Count As Long
  
  ll_Count = 0
  For ll_Idx = 1 To ao_Listview.ListItems.Count
    If ao_Listview.ListItems(ll_Idx).Checked Then
      ll_Count = ll_Count + 1
    End If
  Next
  GetListViewCheckedCount = ll_Count
  Exit Function
ErrHandler:
  Call ErrorHandler("GetListViewCheckedCount")
End Function

Private Sub chk_SelectAll_Click()
On Error GoTo ErrHandler

  Call SetCheckUncheck
  Exit Sub
ErrHandler:
  Call ErrorMessage("chk_SelectAll_Click")
End Sub

Private Sub lvw_Attrib_ItemCheck(Index As Integer, ByVal Item As MSComctlLib.ListItem)
On Error GoTo ErrHandler
    
  Call MarkTabWithCheckedCount(tbs_SearchAttrib.SelectedItem, lvw_Attrib)
  Exit Sub
ErrHandler:
  Call ErrorMessage("lvw_Attrib_ItemCheck")
End Sub

Private Sub MarkTabWithCheckedCount(ByRef ao_Tab As MSComctlLib.Tab, ao_Listview As Object)
On Error GoTo ErrHandler

  Dim lvw_Listview As MSComctlLib.ListView
  Dim ll_Count, ll_Pos As Long
  Dim ls_Text As String
  
  Set lvw_Listview = GetListView(ao_Tab.Tag, ao_Listview)
  If Not (lvw_Listview Is Nothing) Then
    ll_Count = GetListViewCheckedCount(lvw_Listview)
    ll_Pos = InStr(1, ao_Tab.Caption, "[", vbTextCompare)
    If ll_Pos > 0 Then
      ls_Text = Left(ao_Tab.Caption, ll_Pos)
    Else
      ls_Text = ao_Tab.Caption + " ["
    End If
    ao_Tab.Caption = ls_Text & ll_Count & "]"
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("MarkTabWithCheckedCount")
End Sub

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

  Call mo_Tools.LockScreen(Me, True)
  cbo_Alternative.Visible = (opt_MainAlt(1).Value = True)
  If opt_MainAlt(1).Value Then
    If cbo_Alternative.Count = 0 Then
      Call cbo_Alternative.Load
      Call cbo_Alternative.SearchItem(OFD_Id)
    End If
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("opt_MainAlt_Click")
End Sub

Private Sub tbs_Main_Click()
On Error GoTo ErrHandler

  fra_MainAlt.Visible = StrComp(tbs_Main.SelectedItem.Key, fra_MainAlt.Name, vbTextCompare) = 0
  fra_OfferCopy.Visible = StrComp(tbs_Main.SelectedItem.Key, fra_OfferCopy.Name, vbTextCompare) = 0
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_Main_Click")
End Sub

Private Sub tbs_SearchAttrib_Click()
On Error GoTo ErrHandler

  Call SetListViewVisibility(tbs_SearchAttrib, lvw_Attrib)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_SearchAttrib_Click")
End Sub

Private Function GetSelectedCount() As Long
On Error GoTo ErrHandler

Dim ll_Idx As Long
Dim ll_Count As Long

  ll_Count = 0
  For ll_Idx = 0 To grd_PosList.Rows - 1
    If StrComp(grd_PosList.Data(ll_Idx, "Selected"), "CHECK", vbTextCompare) = 0 Then
      ll_Count = ll_Count + 1
    End If
  Next
  GetSelectedCount = ll_Count
  Exit Function
ErrHandler:
  Call ErrorHandler("GetSelectedCount")
End Function

Public Sub InitCollection(ByVal ao_Collection As Collection)
On Error GoTo ErrHandler

Dim ll_Idx As Long

  Call mo_Tools.ClearCollection(ao_Collection)
  For ll_Idx = 0 To grd_PosList.Rows - 1
    If StrComp(grd_PosList.Data(ll_Idx, "Selected"), "CHECK", vbTextCompare) = 0 Then
      Call ao_Collection.Add(grd_PosList.Data(ll_Idx, "COF_Id") & SEP & grd_PosList.Data(ll_Idx, "OFD_Id"))
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitCollection")
End Sub

Private Sub LoadGrid()
On Error GoTo ErrHandler

Dim ls_Req As String
Dim ll_Idx As Long
Dim ls_PRD_Name As String
Dim lvw_Listview As MSComctlLib.ListView

  Call grd_PosList.ClearGrid
 
  ls_Req = "exec Cap_OfferSearchPosList_lst $COF_Lang$, $COF_Code$, $COF_CodeBae$, $COF_CodeSAP$, $AMCProjectNumber$, $PRD_Code$, $PRD_Name$, " & _
  "$RPL_ModA$, $RPL_ModB$, $RPL_Thick$, $SYS_Id$, $MAT_Id$, $PRF_Id$, $COA_Id$, $BothSides$, $VisibleSide$, $INL_Id$, $BOM_IdentNr$," & _
  "$OFD_QtyPCSMin$, $OFD_QtyPCSMax$, $CostNonZero$, $PlantCalcDone$, $Z_CreationFrom$, $Z_CreationTo$"
  
  ls_Req = Replace(ls_Req, "$COF_Lang$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$COF_Code$", mo_Tools.SqlStrKey(Trim(mo_Tools.GetTextValue(txt_Textbox, "COF_Code"))), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$COF_CodeBae$", mo_Tools.SqlStrKey(Trim(mo_Tools.GetTextValue(txt_Textbox, "COF_CodeBae"))), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$COF_CodeSAP$", mo_Tools.SqlStrKey(Trim(mo_Tools.GetTextValue(txt_Textbox, "COF_CodeSAP"))), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$AMCProjectNumber$", mo_Tools.SqlStrKey(Trim(mo_Tools.GetTextValue(txt_Textbox, "AMCProjectNumber"))), , , vbTextCompare)
  
  ls_Req = Replace(ls_Req, "$PRD_Code$", mo_Tools.SqlStrKey(Trim(mo_Tools.GetTextValue(txt_Textbox, "PRD_Code"))), , , vbTextCompare)
  
  ls_PRD_Name = Trim(mo_Tools.GetTextValue(txt_Textbox, "PRD_Name"))
  If ls_PRD_Name <> "" Then
    ls_PRD_Name = "%" & ls_PRD_Name & "%"
  End If
  ls_Req = Replace(ls_Req, "$PRD_Name$", mo_Tools.SqlStrKey(ls_PRD_Name), , , vbTextCompare)
  
  ls_Req = Replace(ls_Req, "$RPL_ModA$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetTextValue(txt_Textbox, "RPL_ModA"))), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$RPL_ModB$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetTextValue(txt_Textbox, "RPL_ModB"))), , , vbTextCompare)
  
  Set lvw_Listview = GetListView("tab_Thickness", lvw_Attrib)
  ls_Req = Replace(ls_Req, "$RPL_Thick$", GetListViewCheckedKeys(lvw_Listview), , , vbTextCompare)
  
  Set lvw_Listview = GetListView("tab_System", lvw_Attrib)
  ls_Req = Replace(ls_Req, "$SYS_Id$", GetListViewCheckedKeys(lvw_Listview), , , vbTextCompare)
  
  
  ls_Req = Replace(ls_Req, "$MAT_Id$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Material)), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$PRF_Id$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_Perforation)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$COA_Id$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$BOM_IdentNr$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_Coating)), , , vbTextCompare)
  
  ls_Req = Replace(ls_Req, "$BothSides$", mo_Tools.SqlBool(chk_BothSides.Value = vbChecked), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$VisibleSide$", mo_Tools.SqlBool(chk_VisibleSide.Value = vbChecked), , , vbTextCompare)
  
  Set lvw_Listview = GetListView("tab_Inlay", lvw_Attrib)
  ls_Req = Replace(ls_Req, "$INL_Id$", GetListViewCheckedKeys(lvw_Listview), , , vbTextCompare)
      
  If Trim(mo_Tools.GetComboKey(cbo_Qty)) = "" Then
    ls_Req = Replace(ls_Req, "$OFD_QtyPCSMin$", "NULL", , , vbTextCompare)
    ls_Req = Replace(ls_Req, "$OFD_QtyPCSMax$", "NULL", , , vbTextCompare)
  Else
    For ll_Idx = 1 To cbo_Qty.Count
      If (cbo_Qty.SelectedItem Is cbo_Qty.ComboItems(ll_Idx)) Then
        ls_Req = Replace(ls_Req, "$OFD_QtyPCSMin$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Qty)), , , vbTextCompare)
        If ll_Idx < cbo_Qty.Count Then
          ls_Req = Replace(ls_Req, "$OFD_QtyPCSMax$", mo_Tools.SqlIntKey(cbo_Qty.ComboItems(ll_Idx + 1).Key), , , vbTextCompare)
        Else
          ls_Req = Replace(ls_Req, "$OFD_QtyPCSMax$", "NULL", , , vbTextCompare)
        End If
        Exit For
      End If
    Next
  End If
  
  ls_Req = Replace(ls_Req, "$CostNonZero$", mo_Tools.SqlBool(chk_CostNonZero.Value = vbChecked), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$PlantCalcDone$", mo_Tools.SqlBool(chk_PlantCalcDone.Value = vbChecked), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$Z_CreationFrom$", mo_Tools.SqlDate(cal_CreateDateFrom.date_dt), , , vbTextCompare)
  ls_Req = Replace(ls_Req, "$Z_CreationTo$", mo_Tools.SqlDate(cal_CreateDateTo.date_dt), , , vbTextCompare)
  
  
  Call grd_PosList.Load(ls_Req, True)
  Call SetCheckUncheck
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadGrid")
End Sub

Private Sub SetCheckUncheck()
On Error GoTo ErrHandler

Dim ll_Idx As Long
  grd_PosList.Redraw = False
  For ll_Idx = 0 To grd_PosList.Rows - 1
    grd_PosList.Data(ll_Idx, "Selected") = IIf(chk_SelectAll.Value = vbChecked, "CHECK", "UNCHECK")
  Next
  grd_PosList.Redraw = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadGrid")
End Sub

Private Sub btn_LoadGrid_Click()
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  Call SetAutoSize(GetListView("tab_Inlay", lvw_Attrib))
  
  Call LoadGrid
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_OfferCode_Validate")
End Sub

Private Sub btn_ResetListView_Click()
On Error GoTo ErrHandler
Dim ll_Idx As Long
Dim lvw_Selected As MSComctlLib.ListView

  Set lvw_Selected = GetListView(tbs_SearchAttrib.SelectedItem.Tag, lvw_Attrib)
  If Not (lvw_Selected Is Nothing) Then
    For ll_Idx = 1 To lvw_Selected.ListItems.Count
      lvw_Selected.ListItems(ll_Idx).Checked = False
    Next
  End If
  Call MarkTabWithCheckedCount(tbs_SearchAttrib.SelectedItem, lvw_Attrib)
  
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ResetListView_Click")
End Sub

Private Sub SetListViewVisibility(ByRef ao_Tab As MSComctlLib.TabStrip, ByRef ao_Listview As Object)
On Error GoTo ErrHandler
Dim ll_Idx As Long
Dim lvw_Selected As MSComctlLib.ListView

  Set lvw_Selected = GetListView(ao_Tab.SelectedItem.Tag, ao_Listview)
  For ll_Idx = 0 To ao_Listview.Count - 1
    ao_Listview(ll_Idx).Visible = (ao_Listview(ll_Idx) Is lvw_Selected)
  Next
  Exit Sub
ErrHandler:
  Call ErrorMessage("SetListViewVisibility")
End Sub

Private Function GetListView(ByVal as_Tag As String, ByRef ao_Listview As Object) As MSComctlLib.ListView
On Error GoTo ErrHandler
Dim ll_Idx As Long

  Set GetListView = Nothing
  For ll_Idx = 0 To ao_Listview.Count - 1
    If (StrComp(ao_Listview(ll_Idx).Tag, as_Tag, vbTextCompare) = 0) Then
      Set GetListView = ao_Listview(ll_Idx)
      Exit Function
    End If
  Next
  Exit Function
ErrHandler:
  Call ErrorHandler("GetListView")
End Function

Private Sub LoadListView(ByVal ao_Listview As MSComctlLib.ListView, ByVal as_Request As String)
On Error GoTo ErrHandler

Dim ll_Cursor As Long
Dim lo_item As MSComctlLib.ListItem
Dim lo_SubItem As MSComctlLib.ListSubItem
Dim ll_Index As Long

    Call ao_Listview.ListItems.Clear
    ll_Cursor = mo_Db.OpenSQL(as_Request)
    If ll_Cursor > 0 Then
        While Not mo_Db.EOF(ll_Cursor)
            Set lo_item = ao_Listview.ListItems.Add(, "KEY" & mo_Db.GetFields(ll_Cursor, 0), mo_Db.GetFields(ll_Cursor, 1))
              lbl_ListView.Caption = mo_Db.GetFields(ll_Cursor, 1) & "  "
              'If ao_Listview.ColumnHeaders(1).Width < lbl_ListView.Width Then
                  'ao_ListView.ColumnHeaders(1).Width = lbl_ListView.Width
                  'Call SendMessage(ao_ListView.hwnd, LVM_SETCOLUMNWIDTH, 0, ByVal lbl_ListView.Width)
              'End If

            Call mo_Db.Next(ll_Cursor)
        Wend
        Call mo_Db.Close(ll_Cursor)
    End If
    Call SetAutoSize(ao_Listview)
    Exit Sub
ErrHandler:
    Call ErrorHandler("LoadListView")
End Sub

Private Function GetListViewCheckedKeys(ao_Listview As MSComctlLib.ListView) As String
On Error GoTo ErrHandler

Dim ll_Idx As Long
Dim ls_Keys As String

    ls_Keys = ""
    
    For ll_Idx = 1 To ao_Listview.ListItems.Count
        If ao_Listview.ListItems(ll_Idx).Checked = True Then
          If (ls_Keys <> "") Then
            ls_Keys = ls_Keys & ","
          End If
          ls_Keys = ls_Keys & right(ao_Listview.ListItems(ll_Idx).Key, Len(ao_Listview.ListItems(ll_Idx).Key) - 3)
        End If
    Next
    
    If ls_Keys = "" Then
      GetListViewCheckedKeys = "NULL"
    Else
      GetListViewCheckedKeys = mo_Tools.SQLStr(ls_Keys)
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("GetListViewCheckedKeys")
End Function

'set auto size fro all columns
Public Sub SetAutoSize(ByRef ao_Listview As MSComctlLib.ListView)
On Error GoTo ErrHandler
Dim ll_Index As Long
Dim ll_Width As Long

  ll_Index = 0
  For ll_Index = 0 To ao_Listview.ColumnHeaders.Count - 1
    If ao_Listview.ColumnHeaders(ll_Index + 1).Width > 0 Then
      'ao_Listview.ColumnHeaders(ll_Index + 1).Width = 3000
      ll_Width = SendMessage(ao_Listview.hwnd, LVM_GETCOLUMNWIDTH, ByVal ll_Index, ByVal 0)
      Call SendMessage(ao_Listview.hwnd, LVM_SETCOLUMNWIDTH, ByVal ll_Index, ByVal LVSCW_AUTOSIZE_USEHEADER) 'ByVal LVSCW_AUTOSIZE_USEHEADER
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("SetAutoSize")
End Sub
Private Sub txt_OfferCode_KeyPress(KeyAscii As Integer)
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  If KeyAscii = 13 Then
    Call LoadGrid
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_OfferCode_KeyPress")
End Sub

Private Sub txt_ProductCode_KeyPress(KeyAscii As Integer)
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  If KeyAscii = 13 Then
    Call LoadGrid
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_ProductCode_KeyPress")
End Sub

Private Sub grd_PosList_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single, ByVal al_Row As Long, ByVal al_Col As Long)
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  
  If al_Row >= 0 And al_Col = grd_PosList.Columns("Selected").ColumnIndex Then
    If StrComp(grd_PosList.Data(al_Row, "Selected"), "UNCHECK", vbTextCompare) = 0 Then
      grd_PosList.Data(al_Row, "Selected") = "CHECK"
    Else
      grd_PosList.Data(al_Row, "Selected") = "UNCHECK"
    End If
  End If
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_MouseDown")
End Sub

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

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

Public Sub Resize()
On Error GoTo ErrHandler
Dim ll_Idx As Long

  If (Me.Width > 5000) And (Me.Height > 5000) Then
    Call tbs_Main.Move(0, 0, Me.Width)
    Call btn_Validate.Move(Me.Width - 2 * btn_Validate.Width - 500, Me.Height - btn_Validate.Height - 700)
    Call btn_Quit.Move(Me.Width - btn_Quit.Width - 500, Me.Height - btn_Quit.Height - 700)
    
    Call fra_MainAlt.Move(0, tbs_Main.Height, Me.Width - 50, btn_Validate.Top - tbs_Main.Height)
    Call fra_OfferCopy.Move(0, tbs_Main.Height, Me.Width - 50, btn_Validate.Top - tbs_Main.Height)
    
    Call fra_Filter.Move(0, 0, fra_OfferCopy.Width)
    Call grd_PosList.Move(0, fra_Filter.Height, fra_OfferCopy.Width - 30, fra_OfferCopy.Height - fra_Filter.Height)
    
    For ll_Idx = 0 To lvw_Attrib.Count - 1
      Call lvw_Attrib(ll_Idx).Move(0, 0, fra_AttribList.Width, fra_AttribList.Height)
    Next
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("Resize")
End Sub

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

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


