VERSION 5.00
Begin VB.Form frmDPC_MassEntry 
   Caption         =   "#Mass entry"
   ClientHeight    =   11100
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   17640
   LinkTopic       =   "Form2"
   MinButton       =   0   'False
   ScaleHeight     =   11100
   ScaleWidth      =   17640
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Tag             =   "frmDPC_MassEntry"
   WindowState     =   2  'Maximized
   Begin VB.ComboBox cbo_Value 
      BackColor       =   &H0080FF80&
      Height          =   315
      ItemData        =   "frmMassEntry.frx":0000
      Left            =   4440
      List            =   "frmMassEntry.frx":0002
      Style           =   2  'Dropdown List
      TabIndex        =   16
      TabStop         =   0   'False
      Top             =   3690
      Visible         =   0   'False
      Width           =   1245
   End
   Begin Project1.ToolbarControl tlb_Main 
      Height          =   690
      Left            =   0
      TabIndex        =   15
      TabStop         =   0   'False
      Tag             =   "3001"
      Top             =   0
      Width           =   17595
      _ExtentX        =   31036
      _ExtentY        =   1217
   End
   Begin VB.TextBox txt_Value 
      BackColor       =   &H0080FF80&
      BorderStyle     =   0  'None
      Height          =   360
      Left            =   8790
      TabIndex        =   14
      TabStop         =   0   'False
      Top             =   4140
      Visible         =   0   'False
      Width           =   1005
   End
   Begin VB.Frame fra_Filter 
      Caption         =   "#Filter"
      Height          =   645
      Left            =   75
      TabIndex        =   1
      Tag             =   "fra_Filter"
      Top             =   690
      Width           =   17550
      Begin VB.TextBox txt_PosFilter 
         Height          =   360
         Index           =   1
         Left            =   2880
         TabIndex        =   13
         TabStop         =   0   'False
         Top             =   225
         Width           =   855
      End
      Begin VB.TextBox txt_PosFilter 
         Height          =   360
         Index           =   0
         Left            =   1260
         TabIndex        =   11
         TabStop         =   0   'False
         Top             =   225
         Width           =   855
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H00C0E0FF&
         Caption         =   "#Packing"
         Height          =   255
         Index           =   7
         Left            =   14415
         TabIndex        =   9
         TabStop         =   0   'False
         Tag             =   "chk_Packing"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H00FFFFC0&
         Caption         =   "#Cutout"
         Height          =   255
         Index           =   6
         Left            =   12930
         TabIndex        =   8
         TabStop         =   0   'False
         Tag             =   "chk_Cutout"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H000080FF&
         Caption         =   "#Inlay"
         Height          =   255
         Index           =   5
         Left            =   11430
         TabIndex        =   7
         TabStop         =   0   'False
         Tag             =   "chk_Inlay"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H00FF8080&
         Caption         =   "#Gasket"
         Height          =   255
         Index           =   4
         Left            =   9945
         TabIndex        =   6
         TabStop         =   0   'False
         Tag             =   "chk_Gasket"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H00FF80FF&
         Caption         =   "#Coating"
         Height          =   255
         Index           =   3
         Left            =   8460
         TabIndex        =   5
         TabStop         =   0   'False
         Tag             =   "chk_Coating"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H0000FFFF&
         Caption         =   "#Peforation"
         Height          =   255
         Index           =   2
         Left            =   6975
         TabIndex        =   4
         TabStop         =   0   'False
         Tag             =   "chk_Perforation"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H00C0C000&
         Caption         =   "#Bending"
         Height          =   255
         Index           =   1
         Left            =   5475
         TabIndex        =   3
         TabStop         =   0   'False
         Tag             =   "chk_Bending"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.CheckBox chk_ColFilter 
         BackColor       =   &H0000C000&
         Caption         =   "#Panel"
         Height          =   255
         Index           =   0
         Left            =   3990
         TabIndex        =   2
         TabStop         =   0   'False
         Tag             =   "chk_Panel"
         Top             =   270
         Value           =   1  'Checked
         Width           =   1410
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#to"
         Height          =   240
         Index           =   1
         Left            =   2265
         TabIndex        =   12
         Tag             =   "lbl_PosTo"
         Top             =   285
         Width           =   900
      End
      Begin VB.Label lbl_Label 
         Caption         =   "#Pos from"
         Height          =   240
         Index           =   0
         Left            =   180
         TabIndex        =   10
         Tag             =   "lbl_PosFrom"
         Top             =   285
         Width           =   900
      End
   End
   Begin Project1.ArmGrid grd_PosList 
      Height          =   10530
      Left            =   15
      TabIndex        =   0
      TabStop         =   0   'False
      Tag             =   "grd_PosList"
      Top             =   1395
      Width           =   17580
      _ExtentX        =   31009
      _ExtentY        =   18574
   End
End
Attribute VB_Name = "frmDPC_MassEntry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As POINTAPI) As Long
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


Private Const SEP = "®©"
Private Const C_SEP As String = "@@"
Private Const SEP1 As String = "®"
Private Const SEP2 As String = "©"
Private Const CL_COLOR_ENABLED As Long = &H80000005
Private Const CL_COLOR_DISABLED As Long = &H8000000F
Private Const SCREEN_NAME As String = "frmDPC_MassEntry"
Private Const SW_SHOWNORMAL = 1
Private Const PROP_TWIP_PIX = 14.95       'Conversion
Private Const CB_SETDROPPEDWIDTH    As Long = &H160
Private Const CB_SHOWDROPDOWN       As Long = &H14F
Private Const CB_GETDROPPEDSTATE    As Long = &H157
Private Const CB_GETLBTEXTLEN       As Long = &H149

Private Const LOCALE_SDECIMAL = &HE ' Decimal separator
Private Const LOCALE_STHOUSAND = &HF ' Thousand separator
Private Const LOCALE_USER_DEFAULT = &H400
Private Const C_ERRORRAISE As Long = 2500
Private Const C_MSG_ID_BASE As Long = 9700

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


Public COF_Id As String
Private mo_Tools As DPC_Tools

Private ml_U_Code As Long
Private mb_Initialized As Boolean
Private ms_DecimalSeparator As String
Private ms_ThousandSeparator As String
Private mc_ScreenLabels As Long
Private mo_WshNetwork As Object
Private ms_ComputerName As String
Private ms_Language_Code                As String       'current user interface language
Private ms_LoginName                    As String       'contain loginname
Private ms_UserName                     As String       'contain name of logged user as defined in GEN_People
Private mb_Result As Boolean
Private mb_InternalInit As Boolean
Private mla_OrigColWidth() As Long
Private mav_ColFilter() As Variant
Private mav_ColFilterWidth() As Variant
Private ml_Idx As Long
Private mo_Clipboard As Collection
Private mb_HelperChanged As Boolean
Private mc_CursorCombo As Long
Private mc_PrdAttrChange As Long
Private ml_ListIndex As Long
Private ms_ComboFieldDesc As String
Private ms_ComboFieldId As String
Private mb_ComboMandatory As Boolean


Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type RECT
  Left As Long
  Top As Long
  right As Long
  bottom As Long
End Type

Private Type COMBOBOXINFO
  cbSize As Long
  rcItem As RECT
  rcButton As RECT
  stateButton As Long
  hwndCombo As Long
  hwndItem As Long
  hwndList As Long
End Type

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

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 ArmDb(ByRef lo_Db As Object)
  If Not (lo_Db Is Nothing) Then
      Set mo_Db = lo_Db
  End If
End Property

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

Property Let U_Code(al_Code As Long)
  ml_U_Code = al_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 Get Result() As Boolean
  Result = mb_Result
End Property

Private Function Inc() As Long
  Inc = ml_Idx
  ml_Idx = ml_Idx + 1
End Function

Public Function Load_A_COM() As Boolean
On Error GoTo ErrHandler

Dim ll_Idx As Long

  Load_A_COM = False
  
  If mb_Initialized Then
      Call Err.Raise(ArmErr.CPTAlreadyInitialized)
  End If
  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

  mb_InternalInit = True
  Call mo_Tools.Load_A_ComControls(Me.Controls, mo_Db, ms_Language_Code)
  
  ms_ThousandSeparator = mo_Tools.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND)
  ms_DecimalSeparator = Format(0, ".")
  mc_ScreenLabels = 0
  
  
  Set mo_FSO = CreateObject("Scripting.FileSystemObject")
#If ENV = LIVE Then
  Set mo_Sys = CreateObject("ArmSYSCOM.ArmSys")
#Else
  Set mo_Sys = New ARMSYSCOMLib.ArmSYS
#End If
  
  Set mo_WshNetwork = CreateObject("WScript.Network")
  ms_ComputerName = mo_WshNetwork.ComputerName
  
  Dim la_Columns(183) As Variant
  Dim i As Long
  
  ml_Idx = 0
  la_Columns(Inc) = "OFD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "OFD_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PRD_IdPar" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_IdPar" & CH_LDELIMIT & ""
  la_Columns(Inc) = "SYS_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SYS_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "LEN_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEN_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "RowStatus" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RowStatus" & CH_LDELIMIT & "#Stat" & CH_LDELIMIT & "INT"
  la_Columns(Inc) = "Selected" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Selected" & CH_LDELIMIT & "#Sel" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "OFD_Pos" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(Inc) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#AMC Code"
  la_Columns(Inc) = "LEV_IdBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_IdBMP" & CH_LDELIMIT & "#Level" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "Err_TypeBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Err_TypeBMP" & CH_LDELIMIT & "#Err" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "STA_BOMBMP" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_BOMBMP" & CH_LDELIMIT & "#BOM" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "STA_BORBMP" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_BORBMP" & CH_LDELIMIT & "#BOR" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "STA_Desc" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_Desc" & CH_LDELIMIT & "#Status"
  
  la_Columns(Inc) = "OFD_PosCus" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosCus" & CH_LDELIMIT & "#Pos cus."
  la_Columns(Inc) = "RPL_DrwNr" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_DrwNr" & CH_LDELIMIT & "#Drawing Nr."
  la_Columns(Inc) = "PRD_Name" & CH_LDELIMIT & "1900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(Inc) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Quantity"
  la_Columns(Inc) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#Unit of measure"
  la_Columns(Inc) = "UM_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#Unit of measure"
  la_Columns(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "RPL_StdMa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_StdMa" & CH_LDELIMIT & "#Std. mat." & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "MAT_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MAT_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "MAT_Name" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MAT_Name" & CH_LDELIMIT & "#Material"
  la_Columns(Inc) = "RPL_MatTyp" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MatTyp" & CH_LDELIMIT & "#Mat.type"
  la_Columns(Inc) = "RPL_Thick" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_Thick" & CH_LDELIMIT & "#Thickness" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "MTH_Thick_H" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MTH_Thick_H" & CH_LDELIMIT & ""
  la_Columns(Inc) = "RPL_BaeType" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BaeType" & CH_LDELIMIT & "#B7 BaseType" & CH_LDELIMIT & "INT"
  '24
  la_Columns(Inc) = "BND_IdC" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_IdC" & CH_LDELIMIT & ""
  la_Columns(Inc) = "BND_IdD" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_IdD" & CH_LDELIMIT & ""
  la_Columns(Inc) = "BND_IdE" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_IdE" & CH_LDELIMIT & ""
  la_Columns(Inc) = "BND_IdF" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_IdF" & CH_LDELIMIT & ""
  la_Columns(Inc) = "RPL_SBndA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SBndA" & CH_LDELIMIT & "#St.A" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_SUZA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SUZA" & CH_LDELIMIT & "#St.UZA" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_SBndB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SBndB" & CH_LDELIMIT & "#St.B" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_SUZB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SUZB" & CH_LDELIMIT & "#St.UZB" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "BND_NameC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameC" & CH_LDELIMIT & "#Side C"
  la_Columns(Inc) = "RPL_HC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HC" & CH_LDELIMIT & "#HC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "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(Inc) = "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(Inc) = "RPL_UC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UC" & CH_LDELIMIT & "#UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_NCloC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloC" & CH_LDELIMIT & "#Notch closed C" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisC" & CH_LDELIMIT & "#Bend.vis. C" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "BND_NameD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameD" & CH_LDELIMIT & "#Side D"
  la_Columns(Inc) = "RPL_HD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HD" & CH_LDELIMIT & "#HD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "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(Inc) = "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(Inc) = "RPL_UD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UD" & CH_LDELIMIT & "#UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_NCloD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloD" & CH_LDELIMIT & "#Notch closed D" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisD" & CH_LDELIMIT & "#Bend.vis. D" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "RPL_IsCoCut" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_IsCoCut" & CH_LDELIMIT & "#Coil cut" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "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(Inc) = "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(Inc) = "RPL_SC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SC" & CH_LDELIMIT & "#SC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_SD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SD" & CH_LDELIMIT & "#SD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_IsCoF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_IsCoF" & CH_LDELIMIT & "#Coil found" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "BND_NameE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameE" & CH_LDELIMIT & "#Side E"
  la_Columns(Inc) = "RPL_HE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HE" & CH_LDELIMIT & "#HE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_UE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UE" & CH_LDELIMIT & "#UZE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_SE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SE" & CH_LDELIMIT & "#SE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_NCloE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloE" & CH_LDELIMIT & "#Notch closed E" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisE" & CH_LDELIMIT & "#Bend.vis. E" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "BND_NameF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameF" & CH_LDELIMIT & "#Side F"
  la_Columns(Inc) = "RPL_HF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HF" & CH_LDELIMIT & "#HF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_UF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UF" & CH_LDELIMIT & "#UZF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_SF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SF" & CH_LDELIMIT & "#SF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "RPL_NCloF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloF" & CH_LDELIMIT & "#Notch closed F" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisF" & CH_LDELIMIT & "#Bend.vis. F" & CH_LDELIMIT & "BITMAP"
  '66
  la_Columns(Inc) = "PRF_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PRF_Name" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Name" & CH_LDELIMIT & "#Perforation"
  la_Columns(Inc) = "PRF_Class" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Class" & CH_LDELIMIT & "#Perf.class"
  la_Columns(Inc) = "RPL_PBord" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PBord" & CH_LDELIMIT & ""
  la_Columns(Inc) = "RPL_PBordDesc" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PBordDesc" & CH_LDELIMIT & "#Perf.bord"
  la_Columns(Inc) = "PRF_IsCorrStep" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_IsCorrStep" & CH_LDELIMIT & "#Step corrected" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_SCorr" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SCorr" & CH_LDELIMIT & "#Step"
  la_Columns(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "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(Inc) = "RPL_UBorF" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorF" & CH_LDELIMIT & "#R-F" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  '80
  la_Columns(Inc) = "COA_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "COA_Code" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_Code" & CH_LDELIMIT & "#Coating Code"
  la_Columns(Inc) = "COA_Name" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_Name" & CH_LDELIMIT & "#Coating"
  la_Columns(Inc) = "COA_App" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_App" & CH_LDELIMIT & ""
  la_Columns(Inc) = "COA_AppDesc" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_AppDesc" & CH_LDELIMIT & "#Coating application"
  la_Columns(Inc) = "RPL_CoSid" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoSid" & CH_LDELIMIT & ""
  la_Columns(Inc) = "RPL_CoSidDesc" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoSidDesc" & CH_LDELIMIT & "#Coating side"
  la_Columns(Inc) = "RPL_BVisC_Coa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisC" & CH_LDELIMIT & "#Vis.C" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisD_Coa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisD" & CH_LDELIMIT & "#Vis.D" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisE_Coa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisE" & CH_LDELIMIT & "#Vis.E" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "RPL_BVisF_Coa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisF" & CH_LDELIMIT & "#Vis.F" & CH_LDELIMIT & "BITMAP"
  '115
  la_Columns(Inc) = "GSK_IdC" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_IdC" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_IdD" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_IdD" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_IdE" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_IdE" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_IdF" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_IdF" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_Exist" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Exist" & CH_LDELIMIT & "#Gasket" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "GSK_NameC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameC" & CH_LDELIMIT & "#Gsk C"
  la_Columns(Inc) = "GSK_NameD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameD" & CH_LDELIMIT & "#Gsk D"
  la_Columns(Inc) = "GSK_NameE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameE" & CH_LDELIMIT & "#Gsk E"
  la_Columns(Inc) = "GSK_NameF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameF" & CH_LDELIMIT & "#Gsk F"
  la_Columns(Inc) = "GSK_Id2C" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Id2C" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_Id2D" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Id2D" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_Id2E" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Id2E" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_Id2F" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Id2F" & CH_LDELIMIT & ""
  la_Columns(Inc) = "GSK_Exist2" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Exist2" & CH_LDELIMIT & "#Spacer" & CH_LDELIMIT & "BITMAP"
  la_Columns(Inc) = "GSK_Name2C" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2C" & CH_LDELIMIT & "#Spc C"
  la_Columns(Inc) = "GSK_Name2D" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2D" & CH_LDELIMIT & "#Spc D"
  la_Columns(Inc) = "GSK_Name2E" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2E" & CH_LDELIMIT & "#Spc E"
  la_Columns(Inc) = "GSK_Name2F" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2F" & CH_LDELIMIT & "#Spc F"
  '133
  la_Columns(Inc) = "INL_Id1" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Id1" & CH_LDELIMIT & ""
  la_Columns(Inc) = "INL_Id2" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Id2" & CH_LDELIMIT & ""
  la_Columns(Inc) = "INL_Id3" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Id3" & CH_LDELIMIT & ""
  la_Columns(Inc) = "INL_Name1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name1" & CH_LDELIMIT & "#Inlay1"
  la_Columns(Inc) = "INL_Code1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code1" & CH_LDELIMIT & "#Inlay code1"
  la_Columns(Inc) = "PIN_Purch1" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_Purch1" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PIN_Deliv1" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_Deliv1" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PIN_PurchDesc1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc1" & CH_LDELIMIT & "#Purchase1"
  la_Columns(Inc) = "PIN_DelivDesc1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc1" & CH_LDELIMIT & "#Delivery1"
  la_Columns(Inc) = "INL_Name2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name2" & CH_LDELIMIT & "#Inlay2"
  la_Columns(Inc) = "INL_Code2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code2" & CH_LDELIMIT & "#Inlay code2"
  la_Columns(Inc) = "PIN_Purch2" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_Purch2" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PIN_Deliv2" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_Deliv2" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PIN_PurchDesc2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc2" & CH_LDELIMIT & "#Purchase2"
  la_Columns(Inc) = "PIN_DelivDesc2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc2" & CH_LDELIMIT & "#Delivery2"
  la_Columns(Inc) = "INL_Name3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name3" & CH_LDELIMIT & "#Inlay3"
  la_Columns(Inc) = "INL_Code3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code3" & CH_LDELIMIT & "#Inlay code3"
  la_Columns(Inc) = "PIN_Purch3" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_Purch3" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PIN_Deliv3" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_Deliv3" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PIN_PurchDesc3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc3" & CH_LDELIMIT & "#Purchase3"
  la_Columns(Inc) = "PIN_DelivDesc3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc3" & CH_LDELIMIT & "#Delivery3"
  
  la_Columns(Inc) = "CUT_Id1" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Id1" & CH_LDELIMIT & ""
  la_Columns(Inc) = "CUT_Id2" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Id2" & CH_LDELIMIT & ""
  la_Columns(Inc) = "CUT_Id3" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Id3" & CH_LDELIMIT & ""
  la_Columns(Inc) = "CUT_Id4" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Id4" & CH_LDELIMIT & ""
  la_Columns(Inc) = "CUT_Name1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name1" & CH_LDELIMIT & "#Cut 1"
  la_Columns(Inc) = "PCT_SizeJ1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ1" & CH_LDELIMIT & "#J1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeK1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK1" & CH_LDELIMIT & "#K1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeD1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD1" & CH_LDELIMIT & "#D1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeL1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL1" & CH_LDELIMIT & "#L1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeM1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM1" & CH_LDELIMIT & "#M1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "CUT_Name2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name2" & CH_LDELIMIT & "#Cut 2"
  la_Columns(Inc) = "PCT_SizeJ2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ2" & CH_LDELIMIT & "#J2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeK2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK2" & CH_LDELIMIT & "#K2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeD2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD2" & CH_LDELIMIT & "#D2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeL2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL2" & CH_LDELIMIT & "#L2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeM2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM2" & CH_LDELIMIT & "#M2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "CUT_Name3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name3" & CH_LDELIMIT & "#Cut 3"
  la_Columns(Inc) = "PCT_SizeJ3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ3" & CH_LDELIMIT & "#J3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeK3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK3" & CH_LDELIMIT & "#K3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeD3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD3" & CH_LDELIMIT & "#D3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeL3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL3" & CH_LDELIMIT & "#L3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeM3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM3" & CH_LDELIMIT & "#M3"
  la_Columns(Inc) = "CUT_Name4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name4" & CH_LDELIMIT & "#Cut 4"
  la_Columns(Inc) = "PCT_SizeJ4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ4" & CH_LDELIMIT & "#J4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeK4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK4" & CH_LDELIMIT & "#K4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeD4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD4" & CH_LDELIMIT & "#D4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeL4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL4" & CH_LDELIMIT & "#L4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "PCT_SizeM4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM4" & CH_LDELIMIT & "#M4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  la_Columns(Inc) = "PKG_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PKG_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "PKG_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PKG_Name" & CH_LDELIMIT & "#Packing"
  la_Columns(Inc) = "LAB_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LAB_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "LAB_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LAB_Name" & CH_LDELIMIT & "#Label"
  la_Columns(Inc) = "RPL_PU" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PU" & CH_LDELIMIT & "#Packing unit"
  la_Columns(Inc) = "RPL_AGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_AGroup" & CH_LDELIMIT & "#Art grp"
  la_Columns(Inc) = "RPL_MGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MGroup" & CH_LDELIMIT & "#Good grp"
  la_Columns(Inc) = "RPL_PGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PGroup" & CH_LDELIMIT & "#Prd grp"
  la_Columns(Inc) = "RPL_OGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_OGroup" & CH_LDELIMIT & "#Obj grp"
  la_Columns(Inc) = "RPL_WghPnt" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_WghPnt" & CH_LDELIMIT & "#Wgh pnt"
  la_Columns(Inc) = "PRD_InternalComm" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_InternalComment" & CH_LDELIMIT & "#Int.comment"
  la_Columns(Inc) = "VEN_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "VEN_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "VEN_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "VEN_Name" & CH_LDELIMIT & "#Vendor"
  la_Columns(Inc) = "SHP_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SHP_Id" & CH_LDELIMIT & ""
  la_Columns(Inc) = "SHP_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SHP_Name" & CH_LDELIMIT & "#Shipment point"
  la_Columns(Inc) = "RPL_NWgh" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NWgh" & CH_LDELIMIT & "#Weight" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(Inc) = "Empty" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Empty" & CH_LDELIMIT & ""
  '163


  Set grd_PosList.ArmDb = mo_Db
  Call grd_PosList.Load_A_COM
  
  grd_PosList.ExportOnlyVisibleColumns = True
  grd_PosList.AllowExcelExport = True
  grd_PosList.AllowSort = False
  grd_PosList.FreeSelect = True
  Call grd_PosList.SetColumns(la_Columns)
  grd_PosList.FixedCols = "OFD_PosCus"
  
  Call mo_Tools.LoadToolbars(mo_Db, Me.Controls, "DPC", SCREEN_NAME)
  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)
  
  Call Form_Resize
  ReDim mav_ColFilterWidth(7)
  ReDim mav_ColFilter(7)
  mav_ColFilter(0) = Array("PRD_Name", "OFD_PosCus", "RPL_DrwNr", "OFD_Qty", "UM_Name", "RPL_ModA", "RPL_ModB", "RPL_PanA", "RPL_PanB", "RPL_StdMa", "MAT_Name", "RPL_MatTyp", "RPL_Thick", "RPL_BaeType")
  mav_ColFilter(1) = Array("RPL_SBndA", "RPL_SUZA", "RPL_SBndB", "RPL_SUZB", "BND_NameC", "RPL_HC", "RPL_UMinC", "RPL_UMaxC", "RPL_UC", "RPL_NCloC", "RPL_BVisC", "BND_NameD", "RPL_HD", _
                            "RPL_UMinD", "RPL_UMaxD", "RPL_UD", "RPL_NCloD", "RPL_BVisD", "RPL_CoWMin", "RPL_CoWMax", "RPL_CoilW", "RPL_IsCoCut", "RPL_CutA", "RPL_CutB", "RPL_SC", "RPL_SD", _
                            "RPL_IsCoF", "BND_NameE", "RPL_HE", "RPL_UE", "RPL_SE", "RPL_NCloE", "RPL_BVisE", "BND_NameF", "RPL_HF", "RPL_UF", "RPL_SF", "RPL_NCloF", "RPL_BVisF")
  mav_ColFilter(2) = Array("PRF_Name", "PRF_Class", "RPL_PBordDesc", "PRF_IsCorrStep", "RPL_SCorr", "RPL_UBoWC", "RPL_UBoWD", "RPL_UBoWE", "RPL_UBoWF", "RPL_UBorC", "RPL_UBorD", _
                            "RPL_UBorE", "RPL_UBorF")
  mav_ColFilter(3) = Array("COA_Name", "COA_Code", "COA_AppDesc", "RPL_CoSidDesc", "RPL_BVisC_Coa", "RPL_BVisD_Coa", "RPL_BVisE_Coa", "RPL_BVisF_Coa")
  mav_ColFilter(4) = Array("GSK_Exist", "GSK_NameC", "GSK_NameD", "GSK_NameE", "GSK_NameF", "GSK_Exist2", "GSK_Name2C", "GSK_Name2D", "GSK_Name2E", "GSK_Name2F")
  mav_ColFilter(5) = Array("INL_Name1", "INL_Code1", "PIN_PurchDesc1", "PIN_DelivDesc1", "INL_Name2", "INL_Code2", "PIN_PurchDesc2", "PIN_DelivDesc2", "INL_Name3", "INL_Code3", _
                           "PIN_PurchDesc3", "PIN_DelivDesc3")
  mav_ColFilter(6) = Array("CUT_Name1", "PCT_SizeJ1", "PCT_SizeK1", "PCT_SizeD1", "PCT_SizeL1", "PCT_SizeM1", "CUT_Name2", "PCT_SizeJ2", "PCT_SizeK2", "PCT_SizeD2", "PCT_SizeL2", _
                           "PCT_SizeM2", "CUT_Name3", "PCT_SizeJ3", "PCT_SizeK3", "PCT_SizeD3", "PCT_SizeL3", "PCT_SizeM3", "CUT_Name4", "PCT_SizeJ4", "PCT_SizeK4", "PCT_SizeD4", _
                           "PCT_SizeL4", "PCT_SizeM4")
  mav_ColFilter(7) = Array("PKG_Name", "LAB_Name", "RPL_PU", "RPL_AGroup", "RPL_MGroup", "RPL_PGroup", "RPL_OGroup", "RPL_WghPnt", "PRD_InternalComm", "VEN_Name", "SHP_Name", "RPL_NWgh")
  Set mo_Clipboard = New Collection
  Call SetHeaderColor(mav_ColFilter)
  Call ClearEditHelpers
  Call HideEditHelpers
  Call LoadGrid
  mc_PrdAttrChange = mo_Tools.OpenSQLSafe(mo_Db, "exec DPC_PrdAttrChange_lst")

  mc_CursorCombo = 0
  ml_ListIndex = -1
  ms_ComboFieldDesc = ""
  ms_ComboFieldId = ""
  mb_ComboMandatory = False
  
  mb_Result = False
  mb_InternalInit = False
  mb_Initialized = True
  Load_A_COM = mb_Initialized
  Exit Function
ErrHandler:
  Call ErrorMessage("Load_A_COM")
End Function

Public Function Unload_A_COM() As Boolean
On Error GoTo ErrHandler

  Call Hide
  If mb_Initialized Then
    Call mo_Tools.ClearCollection(mo_Clipboard)
    Set mo_Clipboard = Nothing
    Call mo_Tools.Unload_A_ComControls(Me.Controls)
    Call mo_Db.Close(mc_PrdAttrChange)
    Call mo_Db.Close(mc_ScreenLabels)
    Call mo_Db.Close(mc_CursorCombo)
    Set mo_Sys = Nothing
    Set mo_FSO = Nothing
    Set mo_Db = Nothing
    mb_Initialized = False
  End If
  Exit Function
ErrHandler:
  Call ErrorMessage("Unload_A_COM")
End Function

Private Sub cbo_Value_Click()
  
  If cbo_Value.ListIndex <> ml_ListIndex Then
    mb_HelperChanged = True
  End If
End Sub

Public Function AutoDroppedWidth(ByRef ao_Combo As ComboBox) As Boolean
On Error GoTo ErrHandler

Dim ll_DC As Long, ll_PrevMapMode As Long
Dim TextSize As POINTAPI
Dim lu_ComboInfo As COMBOBOXINFO
Dim ll_MaxWidth As Long, ll_Index As Long, ll_TextWidth As Long
Dim ls_Text As String
Dim ll_Result As Long

    ll_DC = GetWindowDC(txt_Value.hwnd)
    ll_MaxWidth = 0
    For ll_Index = 1 To ao_Combo.ListCount
    
      ll_Result = GetTextExtentPoint32(ll_DC, ao_Combo.List(ll_Index), Len(ao_Combo.List(ll_Index)), TextSize)
      If TextSize.x > ll_MaxWidth Then
        ll_MaxWidth = TextSize.x
      End If
    Next
    ll_Result = ReleaseDC(Me.hwnd, ll_DC)
    'll_MaxWidth = ScaleX(ll_MaxWidth, vbPoints, vbPixels)
    Call SendMessage(ao_Combo.hwnd, CB_SETDROPPEDWIDTH, ll_MaxWidth, 0)
  Exit Function
ErrHandler:
    Call ErrorHandler("AutoDroppedWidth")
End Function

Private Sub cbo_Value_DropDown()
On Error GoTo ErrHandler
  
  Dim ls_req As String
  Dim ls_Value As String
  Dim ll_Idx As Long
  Dim ls_Text As String
  Dim ll_ItemIndex As Long

  Screen.MousePointer = vbHourglass

  ls_req = cbo_Value.Tag
  ls_req = ReplaceCommonPlaceholders(ls_req)
  If (mc_CursorCombo = 0) And (ls_req <> "") Then
    ls_Text = cbo_Value.Text
    ll_ItemIndex = -1
    ml_ListIndex = -1
    ll_Idx = 0
    Call cbo_Value.Clear
    If Not mb_ComboMandatory Then
      Call cbo_Value.AddItem("")
      If ls_Text = "" Then ll_ItemIndex = ll_Idx
      ll_Idx = ll_Idx + 1
    End If
    mc_CursorCombo = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    While Not mo_Db.EOF(mc_CursorCombo)
      Call cbo_Value.AddItem(mo_Db.GetFields(mc_CursorCombo, 1))
      If ls_Text = mo_Db.GetFields(mc_CursorCombo, 1) Then ll_ItemIndex = ll_Idx
      Call mo_Db.Next(mc_CursorCombo)
      ll_Idx = ll_Idx + 1
    Wend
    If ll_ItemIndex >= 0 Then
      cbo_Value.ListIndex = ll_ItemIndex
      ml_ListIndex = ll_ItemIndex
    End If
  End If
  Call AutoDroppedWidth(cbo_Value)
  Screen.MousePointer = vbDefault
  Exit Sub
ErrHandler:
    Call ErrorMessage("cbo_Value_DropDown")
End Sub

Private Sub cbo_Value_LostFocus()
  Call HideEditHelpers
End Sub

Private Sub cbo_Value_Validate(Cancel As Boolean)
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  If mb_HelperChanged Then
      Call UpdateGridFromComboHelper
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
    Call ErrorMessage("cbo_Value_Validate")
End Sub

Private Sub Form_Resize()
On Error GoTo ErrHandler
  
  Call tlb_Main.Move(0, 0, Me.Width)
  Call fra_Filter.Move(0, tlb_Main.Height, Me.Width)
  If (Me.Height > tlb_Main.Height + fra_Filter.Height + 800) Then
    Call grd_PosList.Move(0, tlb_Main.Height + fra_Filter.Height, Me.Width - 150, Me.Height - tlb_Main.Height - fra_Filter.Height - 550)
  End If
  Exit Sub
ErrHandler:
    Call ErrorMessage("Form_Resize")
End Sub

Private Sub Copy()
On Error GoTo ErrHandler

Dim lv_Line As Variant
Dim lv_CellColors As Variant
Dim ll_Idx As Long
Dim ll_Col As Long

  Call mo_Tools.ClearCollection(mo_Clipboard)
  ReDim lv_Line(grd_PosList.Cols - 1)
  ReDim lv_CellColors(grd_PosList.Cols - 1)
  
  grd_PosList.Redraw = False
  
  For ll_Idx = 0 To grd_PosList.SelectedCount - 1
    ' we can't copy paste system row
    If (grd_PosList.SelectedLine(ll_Idx, "RowStatus") <> eDPCRowStatus.rsSystem) Then
      For ll_Col = 0 To grd_PosList.Cols - 1
        lv_Line(ll_Col) = grd_PosList.SelectedLine(ll_Idx, ll_Col)
        lv_CellColors(ll_Col) = grd_PosList.CellColor(grd_PosList.GetSelectedRowIndex(ll_Idx), ll_Col)
      Next
      Call mo_Clipboard.Add(lv_Line)
      Call mo_Clipboard.Add(lv_CellColors)
    End If
  Next
  grd_PosList.Redraw = True
  Exit Sub
ErrHandler:
    Call ErrorHandler("Copy")
End Sub

Private Sub Paste()
On Error GoTo ErrHandler

Dim lv_Line As Variant
Dim lv_CellColors As Variant
Dim ll_Idx As Long
Dim ll_Col As Long
  
  grd_PosList.Redraw = False
  Call HideEditHelpers
  If grd_PosList.SelectedCount = 1 Then
    For ll_Idx = 1 To mo_Clipboard.Count Step 2
      lv_Line = mo_Clipboard(ll_Idx)
      lv_CellColors = mo_Clipboard(ll_Idx + 1)
      Call grd_PosList.InsertLine(grd_PosList.Row, lv_Line)
      
      grd_PosList.Data(grd_PosList.Row - 1, "STA_BOMBMP") = "LIGHTRED"
      grd_PosList.Data(grd_PosList.Row - 1, "STA_BORBMP") = "LIGHTRED"
      grd_PosList.Data(grd_PosList.Row - 1, "PRD_Code") = "NEW"
      grd_PosList.Data(grd_PosList.Row - 1, "OFD_Pos") = ""
      grd_PosList.Data(grd_PosList.Row - 1, "OFD_Qty") = 0
      grd_PosList.Data(grd_PosList.Row - 1, "RowStatus") = eDPCRowStatus.rsAdd
      
      For ll_Col = 0 To UBound(lv_CellColors)
        grd_PosList.CellColor(grd_PosList.Row - 1, ll_Col) = lv_CellColors(ll_Col)
      Next
      grd_PosList.CellColor(grd_PosList.Row - 1, "PRD_Code") = DPC_GRID_CHANGEDCELLCOLOR
    Next
  End If
  grd_PosList.Redraw = True
  Exit Sub
ErrHandler:
    Call ErrorHandler("Paste")
End Sub

Private Sub SetHeaderColor(ByRef av_ColumnsArray() As Variant)
On Error GoTo ErrHandler

Dim ll_Idx As Long
Dim ll_ColIdx As Long
Dim lv_Columns As Variant

  For ll_Idx = 0 To UBound(av_ColumnsArray)
    lv_Columns = av_ColumnsArray(ll_Idx)
    For ll_ColIdx = 0 To UBound(lv_Columns)
      grd_PosList.CellColor(-1, lv_Columns(ll_ColIdx)) = chk_ColFilter(ll_Idx).BackColor
    Next
  Next
  Exit Sub
ErrHandler:
    Call ErrorHandler("SetHeaderColor")
End Sub

Private Sub SaveAndHideColumns(ByVal al_FilterIdx As Long)
On Error GoTo ErrHandler

Dim ll_ColIdx As Long
Dim lv_ColumnWidths As Variant
Dim lv_Columns As Variant
  
  lv_Columns = mav_ColFilter(al_FilterIdx)
      
  ReDim lv_ColumnWidths(UBound(lv_Columns))
  
  grd_PosList.Redraw = False
  For ll_ColIdx = 0 To UBound(lv_Columns)
    lv_ColumnWidths(ll_ColIdx) = grd_PosList.Columns(lv_Columns(ll_ColIdx)).Width
    grd_PosList.Columns(lv_Columns(ll_ColIdx)).Width = 0
    Call FixIconCol(lv_Columns(ll_ColIdx))
  Next
  grd_PosList.Redraw = True
  mav_ColFilterWidth(al_FilterIdx) = lv_ColumnWidths
  Exit Sub
ErrHandler:
    Call ErrorHandler("SaveAndHideColumns")
End Sub

Private Sub RestoreColumns(ByVal al_FilterIdx As Long)
On Error GoTo ErrHandler

Dim ll_ColIdx As Long
Dim lv_ColumnWidths As Variant
Dim lv_Columns As Variant
  
  lv_Columns = mav_ColFilter(al_FilterIdx)
  lv_ColumnWidths = mav_ColFilterWidth(al_FilterIdx)
      
  grd_PosList.Redraw = False
  For ll_ColIdx = 0 To UBound(lv_Columns)
    grd_PosList.Columns(lv_Columns(ll_ColIdx)).Width = lv_ColumnWidths(ll_ColIdx)
    Call FixIconCol(lv_Columns(ll_ColIdx))
  Next
  grd_PosList.Redraw = True
  Exit Sub
ErrHandler:
    Call ErrorHandler("RestoreColumns")
End Sub

Private Sub ClearEditHelpers()
On Error GoTo ErrHandler
  
  Call ClearTextHelper
  Call ClearComboHelper
  Exit Sub
ErrHandler:
  Call ErrorHandler("ClearEditHelpers")
End Sub

Private Sub HideEditHelpers()
On Error GoTo ErrHandler
  
  cbo_Value.Visible = False
  txt_Value.Visible = False
  'If grd_PosList.Visible Then
    'grd_PosList.SetFocus
  'End If
  'DoEvents
  Exit Sub
ErrHandler:
  Call ErrorHandler("HideEditHelpers")
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error GoTo ErrHandler
  
  Call Unload_A_COM
  Exit Sub
ErrHandler:
  Call ErrorMessage("Form_Unload")
End Sub

Private Sub grd_PosList_Scroll()
On Error GoTo ErrHandler
  
  Screen.MousePointer = vbHourglass
  Call UpdateGridFromHelper
  Screen.MousePointer = vbDefault
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_Scroll")
End Sub

Private Sub InitTextHelper(ByVal al_MaxLength As Long)
On Error GoTo ErrHandler
  
  txt_Value.MaxLength = al_MaxLength
  txt_Value.Text = grd_PosList.Data(grd_PosList.Row, grd_PosList.Col)
  txt_Value.SelStart = Len(txt_Value.Text)
  mb_HelperChanged = False
  Call grd_PosList.EditCell(txt_Value)
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitTextHelper")
End Sub

Private Sub InitComboHelper(ByVal FieldNameId As String, ByVal FieldNameDesc As String, ByVal as_Request As String, ByVal ab_Mandatory As Boolean)
On Error GoTo ErrHandler
  
  If mc_CursorCombo <> 0 Then
    Call mo_Db.Close(mc_CursorCombo)
    mc_CursorCombo = 0
  End If
  Call cbo_Value.Clear
  Call cbo_Value.AddItem(grd_PosList.Data(grd_PosList.Row, grd_PosList.Col))
  cbo_Value.ListIndex = 0
  ml_ListIndex = 0
  cbo_Value.Tag = as_Request
  ms_ComboFieldDesc = FieldNameDesc
  ms_ComboFieldId = FieldNameId
  mb_ComboMandatory = ab_Mandatory
  
  mb_HelperChanged = False
  Call grd_PosList.EditCell(cbo_Value)
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitComboHelper")
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

Dim lo_Column As ArmColumn

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  
  Call HideEditHelpers
  
  If (al_Row >= 0) And (grd_PosList.Data(grd_PosList.Row, "RowStatus") <> eDPCRowStatus.rsSystem) Then
    Set lo_Column = grd_PosList.Columns(al_Col)
    If Not (lo_Column Is Nothing) Then
      If (lo_Column.FieldType = DBTYPE_BMP) Then
        If mo_Db.Find(mc_PrdAttrChange, "PAC_Field", lo_Column.Name) >= 0 Then
          If StrComp(mo_Db.GetFields(mc_PrdAttrChange, "PAC_DataType"), "BOOL", vbTextCompare) = 0 Then
            Call UpdateCheckHelper(al_Row, lo_Column)
          End If
        End If
      Else
        If mo_Db.Find(mc_PrdAttrChange, "PAC_Field", lo_Column.Name) >= 0 Then
            Call InitTextHelper(mo_Db.GetFields(mc_PrdAttrChange, "PAC_MaxLen"))
        ElseIf mo_Db.Find(mc_PrdAttrChange, "PAC_FieldDesc", lo_Column.Name) >= 0 Then
          Call InitComboHelper(mo_Db.GetFields(mc_PrdAttrChange, "PAC_Field"), _
                               mo_Db.GetFields(mc_PrdAttrChange, "PAC_FieldDesc"), _
                               mo_Db.GetFields(mc_PrdAttrChange, "PAC_SQL"), _
                               mo_Db.GetFields(mc_PrdAttrChange, "PAC_Mandatory") = "X")
        End If
      End If
    End If
  End If
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_MouseDown")
End Sub

Private Sub grd_PosList_SelChange()
On Error GoTo ErrHandler
  
  If grd_PosList.SelectedCount > 1 Then
    Call HideEditHelpers
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_SelChange")
End Sub

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

  Call UpdateGridFromHelper
  If chk_ColFilter(Index).Value = vbChecked Then
    Call RestoreColumns(Index)
  Else
    Call SaveAndHideColumns(Index)
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("chk_ColFilter_Click")
End Sub

Private Sub LoadGrid()
On Error GoTo ErrHandler

Dim ls_req As String
Dim ll_RowIdx As Long
Dim ld_Thick As Double
Dim ld_Height As Double
Dim ls_Value As String
Dim lsa_Values() As String
  
  cbo_Value.Visible = False
  txt_Value.Visible = False
  Call ClearEditHelpers
  ls_req = "exec Cap_OfferPosList_lst $COF_Id$, $COF_Lang$, 0, 0, $PosListLevelFrom$, 0, '', '', '', '', 0, 0, 0, 0"
  ls_req = Replace(ls_req, "$PosListLevelFrom$", mo_Tools.SqlInt(eDPCLevel.lvCustom), , , vbTextCompare)
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(COF_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$COF_Lang$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  Call grd_PosList.Load(ls_req, True)
  ' add empty system line to be able to paste after end of grid, user is not able to edit it
  
  For ll_RowIdx = 0 To grd_PosList.Rows - 1
    ls_Value = grd_PosList.Data(ll_RowIdx, "MTH_Thick_H")
    lsa_Values = Split(ls_Value, ";")
    If UBound(lsa_Values) = 1 Then
      ld_Thick = Round(Val(lsa_Values(0)), 2)
      ld_Height = Round(Val(lsa_Values(1)), 2)
    Else
      ld_Thick = 0
      ld_Height = 0
    End If
    Call CheckThickHeight(ll_RowIdx, ld_Thick, ld_Height)
  Next
  Call grd_PosList.AddLine
  grd_PosList.Data(grd_PosList.Rows - 1, "RowStatus") = eDPCRowStatus.rsSystem
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadGrid")
End Sub

Private Sub CheckThickHeight(ByVal al_RowIdx As Long, ByVal ad_Thick As Double, ByVal ad_Height As Double)
On Error GoTo ErrHandler

  If (ad_Thick = 0) Or (ad_Height = 0) Then Exit Sub
  
  If grd_PosList.CellColor(al_RowIdx, "RPL_Thick") <> DPC_GRID_CHANGEDCELLCOLOR Then
    grd_PosList.CellColor(al_RowIdx, "RPL_Thick") = IIf(ad_Thick = grd_PosList.Data(al_RowIdx, "RPL_Thick"), vbWindowBackground, DPC_GRID_WARNINGCELLCOLOR)
  End If
  If grd_PosList.CellColor(al_RowIdx, "RPL_HC") <> DPC_GRID_CHANGEDCELLCOLOR Then
    grd_PosList.CellColor(al_RowIdx, "RPL_HC") = IIf(ad_Height = grd_PosList.Data(al_RowIdx, "RPL_HC"), vbWindowBackground, DPC_GRID_WARNINGCELLCOLOR)
  End If
  If grd_PosList.CellColor(al_RowIdx, "RPL_HD") <> DPC_GRID_CHANGEDCELLCOLOR Then
    grd_PosList.CellColor(al_RowIdx, "RPL_HD") = IIf(ad_Height = grd_PosList.Data(al_RowIdx, "RPL_HD"), vbWindowBackground, DPC_GRID_WARNINGCELLCOLOR)
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("CheckThickHeight")
End Sub

Private Sub RefilterGrid()
On Error GoTo ErrHandler

Dim ll_From As Long
Dim ll_To As Long
Dim ll_Idx As Long

  Call UpdateGridFromHelper
  ll_From = 0
  ll_To = 99999999
  If Trim(txt_PosFilter(0).Text) <> "" Then ll_From = mo_Tools.ScreenToLong(txt_PosFilter(0).Text)
  If Trim(txt_PosFilter(1).Text) <> "" Then ll_To = mo_Tools.ScreenToLong(txt_PosFilter(1).Text)
  
  grd_PosList.Redraw = False
  For ll_Idx = 0 To grd_PosList.Rows - 1
    If (grd_PosList.Data(ll_Idx, "RowStatus") <> eDPCRowStatus.rsSystem) Then
      If (grd_PosList.Data(ll_Idx, "OFD_Pos") < ll_From) Or (grd_PosList.Data(ll_Idx, "OFD_Pos") > ll_To) Then
        grd_PosList.RowHeight(ll_Idx) = 0
        Call FixIconRow(ll_Idx)
      Else
        grd_PosList.RowHeight(ll_Idx) = 255
        Call FixIconRow(ll_Idx)
      End If
    End If
  Next
  grd_PosList.Redraw = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefilterGrid")
End Sub

Private Sub FixIconRow(ByVal al_RowIdx As Long)
On Error GoTo ErrHandler

Dim ll_ColIdx As Long
  For ll_ColIdx = 0 To grd_PosList.Cols - 1
    If grd_PosList.Columns(ll_ColIdx).FieldType = DBTYPE_BMP Then
      Call FixIcon(al_RowIdx, ll_ColIdx)
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("FixIconRow")
End Sub

Private Sub FixIconCol(ByVal av_Column As Variant)
On Error GoTo ErrHandler

Dim ll_RowIdx As Long

  If grd_PosList.Columns(av_Column).FieldType = DBTYPE_BMP Then
    For ll_RowIdx = 0 To grd_PosList.Rows - 1
      Call FixIcon(ll_RowIdx, av_Column)
    Next
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("FixIconCol")
End Sub

Private Sub FixIcon(ByVal al_RowIndex As Long, ByVal av_Column As Variant)
On Error GoTo ErrHandler

  If (grd_PosList.Columns(av_Column).Width = 0) Or (grd_PosList.RowHeight(al_RowIndex) = 0) Then
    If right(grd_PosList.Data(al_RowIndex, av_Column), 1) <> "_" Then
      grd_PosList.Data(al_RowIndex, av_Column) = grd_PosList.Data(al_RowIndex, av_Column) & "_"
    End If
  Else
    If right(grd_PosList.Data(al_RowIndex, av_Column), 1) = "_" Then
      grd_PosList.Data(al_RowIndex, av_Column) = Left(grd_PosList.Data(al_RowIndex, av_Column), Len(grd_PosList.Data(al_RowIndex, av_Column)) - 1)
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("FixIcon")
End Sub

Private Sub EditColumn(ByVal ab_Next As Boolean)
On Error GoTo ErrHandler
  
Dim ll_ColIdx As Long
Dim ll_Step As Long
Dim lo_Column As ArmColumn


  ll_Step = IIf(ab_Next, 1, -1)
  ll_ColIdx = grd_PosList.Col + ll_Step
  Do While ((ll_ColIdx >= grd_PosList.FixedCols) And (ll_ColIdx < grd_PosList.Cols))
    Set lo_Column = grd_PosList.Columns(ll_ColIdx)
    If Not (lo_Column Is Nothing) Then
      If lo_Column.Width > 0 Then
        If lo_Column.FieldType = DBTYPE_BMP Then
          grd_PosList.Col = ll_ColIdx
          Exit Do
        End If
        If mo_Db.Find(mc_PrdAttrChange, "PAC_Field", lo_Column.Name) >= 0 Then
          grd_PosList.Col = ll_ColIdx
          Call InitTextHelper(mo_Db.GetFields(mc_PrdAttrChange, "PAC_MaxLen"))
          Exit Do
        ElseIf mo_Db.Find(mc_PrdAttrChange, "PAC_FieldDesc", lo_Column.Name) >= 0 Then
          grd_PosList.Col = ll_ColIdx
          Call InitComboHelper(mo_Db.GetFields(mc_PrdAttrChange, "PAC_Field"), _
                               mo_Db.GetFields(mc_PrdAttrChange, "PAC_FieldDesc"), _
                               mo_Db.GetFields(mc_PrdAttrChange, "PAC_SQL"), _
                               mo_Db.GetFields(mc_PrdAttrChange, "PAC_Mandatory") = "X")
          Exit Do
        End If
      End If
    End If
    ll_ColIdx = ll_ColIdx + ll_Step
  Loop
  Exit Sub
ErrHandler:
  Call ErrorHandler("EditColumn")
End Sub


Private Sub txt_Value_Change()
On Error GoTo ErrHandler
  
  mb_HelperChanged = True
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Value_Change")
End Sub

Private Sub grd_PosList_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler

Dim lo_Column As ArmColumn

  Screen.MousePointer = vbHourglass
  If Shift = 2 And KeyCode = 67 Then 'CTRL - C
    Call Copy
  ElseIf Shift = 2 And KeyCode = 86 Then 'CTRL - V
    Call Paste
  ElseIf KeyCode = 32 Then ' SPACE
    If (grd_PosList.Row >= 0) And (grd_PosList.Data(grd_PosList.Row, "RowStatus") <> eDPCRowStatus.rsSystem) Then
      Set lo_Column = grd_PosList.Columns(grd_PosList.Col)
      If Not (lo_Column Is Nothing) Then
        If (lo_Column.FieldType = DBTYPE_BMP) Then
          If mo_Db.Find(mc_PrdAttrChange, "PAC_Field", lo_Column.Name) >= 0 Then
            If StrComp(mo_Db.GetFields(mc_PrdAttrChange, "PAC_DataType"), "BOOL", vbTextCompare) = 0 Then
              Call UpdateCheckHelper(grd_PosList.Row, lo_Column)
            End If
          End If
        End If
      End If
    End If
  ElseIf (KeyCode = 9) And (Shift = 0) Then 'TAB
    Call HideEditHelpers
    Call EditColumn(True)
  ElseIf (KeyCode = 9) And (Shift = 1) Then 'Shift - TAB
    Call HideEditHelpers
    Call EditColumn(False)
  End If
  Screen.MousePointer = vbDefault
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_KeyDown")
End Sub

Private Sub cbo_Value_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler
  
  Screen.MousePointer = vbHourglass
  If (KeyCode = vbKeyTab) And (Shift = 0) Then 'TAB
    If mb_HelperChanged Then
      UpdateGridFromComboHelper
    End If
    Call HideEditHelpers
    Call EditColumn(True)
  ElseIf (KeyCode = vbKeyTab) And (Shift = 1) Then 'Shift - TAB
    If mb_HelperChanged Then
      UpdateGridFromComboHelper
    End If
    Call HideEditHelpers
    Call EditColumn(False)
  ElseIf KeyCode = vbKeyEscape Then 'ESC
    Call ClearComboHelper
    Call HideEditHelpers
  ElseIf KeyCode = vbKeyReturn Then
    Call UpdateGridFromComboHelper
  ElseIf KeyCode = vbKeyDown Then
    Call cbo_Value_DropDown
  End If
  Screen.MousePointer = vbDefault
  Exit Sub
ErrHandler:
    Call ErrorMessage("cbo_Value_KeyDown")
End Sub

Private Sub txt_Value_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler

  Screen.MousePointer = vbHourglass
  If (KeyCode = vbKeyTab) And (Shift = 0) Then 'TAB
    If mb_HelperChanged Then
      UpdateGridFromTextHelper
    End If
    Call HideEditHelpers
    Call EditColumn(True)
  ElseIf (KeyCode = vbKeyTab) And (Shift = 1) Then 'TAB
    If mb_HelperChanged Then
      UpdateGridFromTextHelper
    End If
    Call HideEditHelpers
    Call EditColumn(False)
  ElseIf KeyCode = vbKeyEscape Then 'ESC
    Call ClearTextHelper
    Call HideEditHelpers
  ElseIf KeyCode = vbKeyReturn Then 'Enter
    If mb_HelperChanged Then
      UpdateGridFromTextHelper
    End If
    Call HideEditHelpers
  End If
  Screen.MousePointer = vbDefault
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Value_KeyPress")
End Sub


Private Sub ClearTextHelper()
On Error GoTo ErrHandler
  
  txt_Value.Text = ""
  mb_HelperChanged = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("ClearTextHelper")
End Sub

Private Sub ClearComboHelper()
On Error GoTo ErrHandler
  
  If mc_CursorCombo <> 0 Then
    Call mo_Db.Close(mc_CursorCombo)
    mc_CursorCombo = 0
  End If
  Call cbo_Value.Clear
  ml_ListIndex = -1
  ms_ComboFieldDesc = ""
  ms_ComboFieldId = ""
  mb_HelperChanged = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("ClearComboHelper")
End Sub

Private Sub UpdateGridFromHelper()
On Error GoTo ErrHandler
  
  If txt_Value.Visible Then
    Call UpdateGridFromTextHelper
  ElseIf cbo_Value.Visible Then
    Call UpdateGridFromComboHelper
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateGridFromHelper")
End Sub

Private Sub SetChangedCellRowStatus(ByVal al_Row As Long, ByVal av_Column As Variant)
On Error GoTo ErrHandler
    
    grd_PosList.CellColor(al_Row, av_Column) = DPC_GRID_CHANGEDCELLCOLOR
    grd_PosList.CellColor(al_Row, "PRD_Code") = DPC_GRID_CHANGEDCELLCOLOR
    If grd_PosList.Data(al_Row, "RowStatus") = eDPCRowStatus.rsNone Then
      grd_PosList.Data(al_Row, "RowStatus") = eDPCRowStatus.rsUpdate
    End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("SetChangedCellRowStatus")
End Sub

Private Sub UpdateGridFromTextHelper()
On Error GoTo ErrHandler
  
  If mb_HelperChanged Then
    Select Case grd_PosList.Columns(grd_PosList.Col).FieldType
    Case DBTYPE_BSTR, DBTYPE_STR
      grd_PosList.Data(grd_PosList.Row, grd_PosList.Col) = txt_Value.Text
    Case DBTYPE_I4
      grd_PosList.Data(grd_PosList.Row, grd_PosList.Col) = mo_Tools.ScreenToLong(txt_Value.Text)
    Case DBTYPE_R4, DBTYPE_R8
      grd_PosList.Data(grd_PosList.Row, grd_PosList.Col) = mo_Tools.ScreenToDbl(txt_Value.Text)
    Case Else
      grd_PosList.Data(grd_PosList.Row, grd_PosList.Col) = txt_Value.Text
    End Select
    Call SetChangedCellRowStatus(grd_PosList.Row, grd_PosList.Col)
    If (StrComp(grd_PosList.Columns(grd_PosList.Col).FieldName, "RPL_PanA", vbTextCompare) = 0) Or _
       (StrComp(grd_PosList.Columns(grd_PosList.Col).FieldName, "RPL_PanB", vbTextCompare) = 0) Then
       Call LoadCheckThickHeight(grd_PosList.Row)
    End If
    
  End If
  Call ClearTextHelper
  Call HideEditHelpers
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateGridFromTextHelper")
End Sub

Private Sub UpdateGridFromComboHelper()
On Error GoTo ErrHandler

Dim ll_CursorIndex As Long

  If mb_HelperChanged And (cbo_Value.ListIndex >= 0) Then
    If mb_ComboMandatory Then
      ll_CursorIndex = cbo_Value.ListIndex
    Else
      ll_CursorIndex = cbo_Value.ListIndex - 1
    End If
    
    If ll_CursorIndex >= 0 Then
      grd_PosList.Data(grd_PosList.Row, grd_PosList.Col) = cbo_Value.Text
      grd_PosList.Data(grd_PosList.Row, ms_ComboFieldId) = mo_Db.GetFieldsAt(mc_CursorCombo, ll_CursorIndex, 0)
    Else
      grd_PosList.Data(grd_PosList.Row, grd_PosList.Col) = cbo_Value.Text
      grd_PosList.Data(grd_PosList.Row, ms_ComboFieldId) = ""
    End If
    Call SetChangedCellRowStatus(grd_PosList.Row, grd_PosList.Col)
    Call SetChangedCellRowStatus(grd_PosList.Row, ms_ComboFieldId)
  End If
  Call ClearComboHelper
  Call HideEditHelpers
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateGridFromComboHelper")
End Sub

Private Sub UpdateCheckHelper(ByVal al_Row As Long, ByVal ao_Column As ArmColumn)
On Error GoTo ErrHandler
  
  If StrComp(ao_Column.GetData(al_Row), "UNCHECK", vbTextCompare) = 0 Then
    Call ao_Column.SetData(al_Row, "CHECK")
    Call SetChangedCellRowStatus(al_Row, ao_Column.Name)
  ElseIf StrComp(ao_Column.GetData(al_Row), "CHECK", vbTextCompare) = 0 Then
    Call ao_Column.SetData(al_Row, "UNCHECK")
    Call SetChangedCellRowStatus(al_Row, ao_Column.Name)
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateCheckHelper")
End Sub

Private Sub txt_Value_LostFocus()

  Call HideEditHelpers
End Sub

Private Sub txt_Value_Validate(Cancel As Boolean)
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  If mb_HelperChanged Then
    Call UpdateGridFromTextHelper
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Value_Validate")
End Sub

Private Sub txt_PosFilter_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  If KeyCode = 13 Then
    Call RefilterGrid
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_PosListFilter_KeyDown")
End Sub

Private Sub txt_PosFilter_Validate(Index As Integer, Cancel As Boolean)
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  Call RefilterGrid
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_PosFilter_Validate")
End Sub

Private Function GetNextOFD_Pos() As Long
On Error GoTo ErrHandler

Dim ls_req As String
Dim ll_Pos As Long

  ls_req = "exec Cap_OfferDetail_NextOFD_Pos $COF_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(COF_Id), , , vbTextCompare)
  ll_Pos = Val(mo_Tools.SelectValue(mo_Db, ls_req))
  If (ll_Pos Mod 100) > 0 Then
    ll_Pos = 100 * (ll_Pos \ 100)
  End If
  GetNextOFD_Pos = ll_Pos
  Exit Function
ErrHandler:
  Call ErrorHandler("GetNextOFD_Pos")
End Function

Private Function ValidateGrid() As Boolean
On Error GoTo ErrHandler

Dim ll_RowIdx As Long
Dim ll_NewRowCount As Long
  
  ll_NewRowCount = 0
  ValidateGrid = False
  For ll_RowIdx = 0 To grd_PosList.Rows - 1
    If (grd_PosList.Data(ll_RowIdx, "INL_Id1") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "INL_Id2") <> "") Or (grd_PosList.Data(ll_RowIdx, "INL_Id3") <> "")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong inlay configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "INL_Id2") = "") And _
       (grd_PosList.Data(ll_RowIdx, "INL_Id3") <> "") Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong inlay configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "INL_Id1") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "PIN_Purch1") <> "0") Or (grd_PosList.Data(ll_RowIdx, "PIN_Deliv1") <> "0")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong inlay configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "INL_Id2") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "PIN_Purch2") <> "0") Or (grd_PosList.Data(ll_RowIdx, "PIN_Deliv2") <> "0")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong inlay configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "INL_Id3") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "PIN_Purch3") <> "0") Or (grd_PosList.Data(ll_RowIdx, "PIN_Deliv3") <> "0")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong inlay configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "CUT_Id1") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "CUT_Id2") <> "") Or _
        (grd_PosList.Data(ll_RowIdx, "CUT_Id3") <> "") Or _
        (grd_PosList.Data(ll_RowIdx, "CUT_Id4") <> "")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong cutout configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "CUT_Id2") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "CUT_Id3") <> "") Or _
        (grd_PosList.Data(ll_RowIdx, "CUT_Id4") <> "")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong cutout configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "CUT_Id3") = "") And _
       ((grd_PosList.Data(ll_RowIdx, "CUT_Id4") <> "")) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Line: $Line$, Article: $PRD_Code$. Wrong cutout configuration", _
        Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
      Exit Function
    End If
    If (grd_PosList.Data(ll_RowIdx, "RowStatus") = eDPCRowStatus.rsAdd) Then
      ll_NewRowCount = ll_NewRowCount + 1
    End If
  Next
  
  If (ll_NewRowCount * 100 + GetNextOFD_Pos > MAX_OFD_POS) Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#There is too much new position, maximum position count allowed is 99", _
      Array("$Line$", ll_RowIdx + 1, "$PRD_Code$", grd_PosList.Data(ll_RowIdx, "PRD_Code")))
    Exit Function
  End If
  ValidateGrid = True
  Exit Function
ErrHandler:
  Call ErrorHandler("UpdateCheckHelper")
End Function

Private Sub LoadCheckThickHeight(ByVal al_RowIdx As Long)
On Error GoTo ErrHandler

Dim ld_RPL_PanA As Double, ld_RPL_PanB As Double
Dim ld_Thick As Double, ld_Height As Double
Dim ls_req As String
Dim ll_Cursor As Long

  ld_Thick = 0
  ld_Height = 0
  ls_req = "exec DPC_MatThick_sel2 $SYS_Id$, $PRD_Id$, $MAT_Id$, $RPL_PanA$, $RPL_PanB$"
  
  ls_req = Replace(ls_req, "$SYS_Id$", mo_Tools.SqlInt(grd_PosList.Data(al_RowIdx, "SYS_Id")), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(grd_PosList.Data(al_RowIdx, "PRD_IdPar")), , , vbTextCompare)
  ls_req = Replace(ls_req, "$MAT_Id$", mo_Tools.SqlInt(grd_PosList.Data(al_RowIdx, "MAT_Id")), , , vbTextCompare)
  ls_req = Replace(ls_req, "$RPL_PanA$", mo_Tools.SqlDbl(grd_PosList.Data(al_RowIdx, "RPL_PanA")), , , vbTextCompare)
  ls_req = Replace(ls_req, "$RPL_PanB$", mo_Tools.SqlDbl(grd_PosList.Data(al_RowIdx, "RPL_PanB")), , , vbTextCompare)
  ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  If mo_Db.RowCount(ll_Cursor) > 0 Then
    ld_Height = mo_Db.GetFields(ll_Cursor, "MTH_H")
    ld_Thick = mo_Db.GetFields(ll_Cursor, "MTH_Thick")
  End If
  Call mo_Db.Close(ll_Cursor)
  Call CheckThickHeight(al_RowIdx, ld_Thick, ld_Height)
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadCheckThickHeight")
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)
  as_Request = Replace(as_Request, "$SYS_Id$", mo_Tools.SqlInt(grd_PosList.Data(grd_PosList.Row, "SYS_Id")), , , vbTextCompare)
  as_Request = Replace(as_Request, "$LEN_Id$", mo_Tools.SqlInt(grd_PosList.Data(grd_PosList.Row, "LEN_Id")), , , vbTextCompare)
  ReplaceCommonPlaceholders = as_Request
  Exit Function
ErrHandler:
  Call ErrorHandler("ReplaceCommonPlaceholders")
End Function

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

  Call mo_Tools.LockScreen(Me, True)
  mb_InternalInit = True
  Select Case as_Role
  Case "H"
    Call UpdateGridFromHelper
    If ValidateGrid Then
      mb_Result = True
      Hide
    End If
  Case "I"
    Call LoadGrid
  Case "o"
    Call Copy
  Case "g"
    Call Paste
  Case "T"
    mb_Result = False
    Hide
  End Select
  mb_InternalInit = False
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tlb_Main_action")
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
