VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Begin VB.UserControl DPC_Packing 
   ClientHeight    =   11025
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   15285
   ScaleHeight     =   11025
   ScaleWidth      =   15285
   Begin VB.Frame fra_Packing 
      Height          =   10155
      Left            =   45
      TabIndex        =   2
      Tag             =   "fra_Packing"
      Top             =   45
      Width           =   15120
      Begin VB.Frame fra_Main 
         Height          =   2280
         Index           =   1
         Left            =   435
         TabIndex        =   34
         Top             =   960
         Width           =   1605
         Begin Project1.ArmGrid grd_BoxSummary 
            Height          =   9315
            Left            =   45
            TabIndex        =   35
            Tag             =   "grd_Main"
            Top             =   180
            Width           =   14835
            _ExtentX        =   26167
            _ExtentY        =   16431
         End
      End
      Begin MSComctlLib.TabStrip tbs_Main 
         Height          =   375
         Left            =   105
         TabIndex        =   33
         Top             =   120
         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         =   "#Group by boxes"
               ImageVarType    =   2
            EndProperty
            BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               Caption         =   "#Summary"
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin VB.Frame fra_Main 
         Height          =   9825
         Index           =   0
         Left            =   120
         TabIndex        =   30
         Top             =   150
         Width           =   15000
         Begin Project1.ArmGrid grd_BoxItemMain 
            Height          =   4860
            Left            =   120
            TabIndex        =   31
            Tag             =   "grd_Main"
            Top             =   4770
            Width           =   14025
            _ExtentX        =   24739
            _ExtentY        =   8573
         End
         Begin Project1.ToolbarControl tlb_BoxMain 
            Height          =   4500
            Left            =   14220
            TabIndex        =   32
            Tag             =   "2924"
            Top             =   165
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   7938
         End
         Begin Project1.ArmGrid grd_BoxMain 
            Height          =   4485
            Left            =   60
            TabIndex        =   36
            Top             =   180
            Width           =   14085
            _ExtentX        =   24844
            _ExtentY        =   7911
         End
         Begin Project1.ToolbarControl tlb_BoxItemsMain 
            Height          =   4890
            Left            =   14205
            TabIndex        =   37
            Tag             =   "2924"
            Top             =   4755
            Width           =   690
            _ExtentX        =   1217
            _ExtentY        =   8625
         End
      End
      Begin VB.Frame fra_PackingDetail 
         Height          =   4650
         Left            =   -30
         TabIndex        =   3
         Tag             =   "fra_PackingDetail"
         Top             =   8175
         Width           =   14940
         Begin VB.Frame fra_PackingItem 
            Caption         =   "#Packing item"
            Height          =   1800
            Left            =   6240
            TabIndex        =   19
            Tag             =   "fra_PackingItem"
            Top             =   2760
            Width           =   8640
            Begin VB.TextBox Text12 
               Height          =   330
               Left            =   2985
               TabIndex        =   28
               Text            =   "Text1"
               Top             =   1545
               Width           =   1395
            End
            Begin VB.TextBox Text11 
               Height          =   330
               Left            =   1515
               TabIndex        =   26
               Text            =   "Text1"
               Top             =   1575
               Width           =   1395
            End
            Begin VB.TextBox Text10 
               Height          =   330
               Left            =   0
               TabIndex        =   24
               Text            =   "Text1"
               Top             =   1575
               Width           =   1395
            End
            Begin VB.TextBox Text9 
               Height          =   330
               Left            =   0
               TabIndex        =   22
               Text            =   "Text1"
               Top             =   1005
               Width           =   8505
            End
            Begin VB.TextBox Text8 
               Height          =   330
               Left            =   60
               TabIndex        =   20
               Text            =   "Text1"
               Top             =   435
               Width           =   1395
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Height"
               Height          =   165
               Index           =   11
               Left            =   3015
               TabIndex        =   29
               Top             =   1335
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Panel B"
               Height          =   165
               Index           =   10
               Left            =   1545
               TabIndex        =   27
               Top             =   1365
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Panel A"
               Height          =   165
               Index           =   9
               Left            =   45
               TabIndex        =   25
               Top             =   1350
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Name"
               Height          =   165
               Index           =   8
               Left            =   0
               TabIndex        =   23
               Top             =   795
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Box item nr"
               Height          =   165
               Index           =   7
               Left            =   60
               TabIndex        =   21
               Top             =   240
               Width           =   1335
            End
         End
         Begin VB.Frame fra_ProductItem 
            Caption         =   "#Panel"
            Height          =   2595
            Left            =   390
            TabIndex        =   4
            Tag             =   "fra_ProductItem"
            Top             =   600
            Width           =   8625
            Begin VB.TextBox Text7 
               Height          =   330
               Left            =   75
               TabIndex        =   17
               Text            =   "Text1"
               Top             =   2115
               Width           =   1395
            End
            Begin VB.TextBox Text6 
               Height          =   330
               Left            =   75
               TabIndex        =   15
               Text            =   "Text1"
               Top             =   420
               Width           =   1395
            End
            Begin VB.TextBox Text5 
               Height          =   330
               Left            =   4560
               TabIndex        =   13
               Text            =   "Text1"
               Top             =   1500
               Width           =   1395
            End
            Begin VB.TextBox Text4 
               Height          =   330
               Left            =   3060
               TabIndex        =   11
               Text            =   "Text1"
               Top             =   1500
               Width           =   1395
            End
            Begin VB.TextBox Text3 
               Height          =   330
               Left            =   1590
               TabIndex        =   9
               Text            =   "Text1"
               Top             =   1530
               Width           =   1395
            End
            Begin VB.TextBox Text2 
               Height          =   330
               Left            =   75
               TabIndex        =   7
               Text            =   "Text1"
               Top             =   1530
               Width           =   1395
            End
            Begin VB.TextBox Text1 
               Height          =   330
               Left            =   75
               TabIndex        =   5
               Text            =   "Text1"
               Top             =   960
               Width           =   8505
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Total quantity [PCS]"
               Height          =   165
               Index           =   6
               Left            =   75
               TabIndex        =   18
               Top             =   1905
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Position"
               Height          =   165
               Index           =   5
               Left            =   75
               TabIndex        =   16
               Top             =   210
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Execution"
               Height          =   165
               Index           =   4
               Left            =   4590
               TabIndex        =   14
               Top             =   1290
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Height"
               Height          =   165
               Index           =   3
               Left            =   3090
               TabIndex        =   12
               Top             =   1290
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Panel B"
               Height          =   165
               Index           =   2
               Left            =   1620
               TabIndex        =   10
               Top             =   1320
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Panel A"
               Height          =   165
               Index           =   1
               Left            =   75
               TabIndex        =   8
               Top             =   1320
               Width           =   1335
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Name"
               Height          =   165
               Index           =   0
               Left            =   75
               TabIndex        =   6
               Top             =   750
               Width           =   1335
            End
         End
      End
   End
   Begin VB.CommandButton btn_Validate 
      Height          =   612
      Left            =   13890
      Style           =   1  'Graphical
      TabIndex        =   1
      Tag             =   "btn_Validate"
      Top             =   10275
      Width           =   612
   End
   Begin VB.CommandButton btn_Quit 
      Height          =   612
      Left            =   14565
      Style           =   1  'Graphical
      TabIndex        =   0
      Tag             =   "btn_Quit"
      Top             =   10275
      Width           =   612
   End
End
Attribute VB_Name = "DPC_Packing"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

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 CL_COLOR_LOCKED As Long = &H80000018
Private Const SCREEN_NAME As String = "DPC_Packing"

Private Const SW_SHOWNORMAL = 1

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

Private Const FRM_SPACE_VER = 120
Private Const FRM_SPACE_HOR = 100

Public Result As Boolean

#If ENV = LIVE Then
Private mo_Sys As Object
Public mo_Db As Object
#Else
Private mo_Sys As ARMSYSCOMLib.ArmSYS
Public mo_Db As ARMSYSCOMLib.ArmDb
#End If

Private mo_Tools As DPC_Tools

Public CanChangeManualPrice As Boolean
Public CURR_Code As String
Public CT_Code As String
Public ValidityDate As Date
Public ml_U_Code As Long

Private me_Screen As eDPCScreenMode
Private me_SubScreen As eDPCScreenMode

Private mb_InternalInit As Boolean
Private mb_CurrentTextBoxChanged As Boolean
Private ms_Caption As String
Private ms_DPCImageCachePath As String
Private mb_Initialized As Boolean
Private ms_DecimalSeparator As String
Private ms_ThousandSeparator As String
Private mc_ScreenLabels As Long
Private mc_Toolbars As Long
Private mo_FSO As FileSystemObject
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 Enum ArmErr
    DBCnxFailed = C_ERRORRAISE + 1             ' Unable to connect to the database
    CPTAlreadyInitialized = C_ERRORRAISE + 2   ' We try to initialize a component that is already initialized
    CPTNotInitialized = C_ERRORRAISE + 3       ' We try to use or free that is not initialized yet
    InvalidArgument = C_ERRORRAISE + 4
    PropertyNotSet = C_ERRORRAISE + 5
    SQLFailure = C_ERRORRAISE + 6               ' A SQL runtime error has occured : syntax wrong....
    SQLBadRowAffectedCount = C_ERRORRAISE + 7   ' A SQL request has not affected the expected rowcount (ex: one Update do nothing)
    SQLBadRowExpectedCount = C_ERRORRAISE + 8   ' A SQL request does not return the expected rowcount : select an item return nothing...
    DrivingError = C_ERRORRAISE + 9
    CompFncFailed = C_ERRORRAISE + 10           ' when component function fail
    GridLoadFailed = C_ERRORRAISE + 11          ' load function failed ... bad sql
    InvalidValue = C_ERRORRAISE + 12          ' load function failed ... bad sql
End Enum

Private Enum ArmCusErr
    DuplicityDetected = C_ERRORRAISE + 2301                ' detected row with same unique id
End Enum

Public Event quit()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Public Sub Zorder()
On Error GoTo ErrHandler

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

Public Sub Refresh()
On Error GoTo ErrHandler

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

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

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

Public Function Load_A_COM() As Boolean
On Error GoTo ErrHandler

Dim ll_Idx As Integer
Dim ls_Request As String
Dim lsa_PKG_Id() As String

    
  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(UserControl.Controls, mo_Db, ms_Language_Code)
  
  ms_DecimalSeparator = Format(0, ".")
  ms_ThousandSeparator = mo_Tools.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND)
  mc_Toolbars = 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
    
  'ls_Request = "exec A_References_ML_lst $GR_Code$,$Language_Code$"
  'ls_Request = Replace(ls_Request, "$Language_Code$", mo_Tools.SqlStr(ms_Language_Code), , , vbTextCompare)
  'ls_Request = Replace(ls_Request, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfSubHangAlignment), , , vbTextCompare)
  'cbo_HangerAlignment.Request = ls_Request
  
  Call tlb_BoxMain.SetToolbarInfoStringParameters("001EE®01760®QESFGIDR/BAC®AAABBBCCC", "001")
  Call tlb_BoxMain.DisplayFace("0")
  tlb_BoxMain.Visible = True

  Call tlb_BoxItemsMain.SetToolbarInfoStringParameters("001EE®01760®QESFGIDR/BAC®AAABBBCCC", "001")
  Call tlb_BoxItemsMain.DisplayFace("0")
  tlb_BoxItemsMain.Visible = True
'
'  Call tlb_SubconstDetail.SetToolbarInfoStringParameters("002EE®014835®QESFGIDR/BAC®®114835®QESFGIDR/BAC®AHHBTT®214835®QESFGIDR/BAC®AHHBTT®314835®QESFGIDR/BAC®AHHBTT", "002")
'  Call tlb_SubconstDetail.DisplayFace("0")
  
  ReDim la_Columns(5) As Variant
  la_Columns(0) = "PPG_Nr" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "1" & CH_LDELIMIT & "PPG_Nr" & CH_LDELIMIT & "#Nr"
  la_Columns(1) = "BPK_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "BPK_Name" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Name" & CH_LDELIMIT & "#Name"
  la_Columns(3) = "BPK_Length" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Length" & CH_LDELIMIT & "#Length"
  la_Columns(4) = "BPK_Width" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Width" & CH_LDELIMIT & "#Width"
  la_Columns(5) = "BPK_Height" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Height" & CH_LDELIMIT & "#Height"
  grd_BoxMain.SetColumns la_Columns
  
  ReDim la_Columns(9) As Variant
  la_Columns(0) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "BPK_Nr" & CH_LDELIMIT & "#"
  la_Columns(1) = "OFD_Pos" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(2) = "PRD_Code" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#Code"
  la_Columns(3) = "PRD_Name" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(4) = "PPG_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPG_Qty" & CH_LDELIMIT & "#Qty"
  la_Columns(5) = "RPL_PanA" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanA" & CH_LDELIMIT & "#Panel A"
  la_Columns(6) = "RPL_PanB" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanB" & CH_LDELIMIT & "#Panel B"
  la_Columns(7) = "RPL_H" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_H" & CH_LDELIMIT & "#Panel H"
  la_Columns(8) = "RPL_Exec" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_Exec" & CH_LDELIMIT & "#Execution"
  la_Columns(9) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Total"
  grd_BoxItemMain.SetColumns la_Columns
  
  ReDim la_Columns(16) As Variant
  la_Columns(0) = "PPG_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "PPG_Nr" & CH_LDELIMIT & ""
  la_Columns(1) = "PPG_Nr" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPG_Nr" & CH_LDELIMIT & "#Nr"
  la_Columns(2) = "BPK_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Id" & CH_LDELIMIT & ""
  la_Columns(3) = "BPK_Name" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Name" & CH_LDELIMIT & "#Name"
  la_Columns(4) = "BPK_Length" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Length" & CH_LDELIMIT & "#Length"
  la_Columns(5) = "BPK_Width" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Width" & CH_LDELIMIT & "#Width"
  la_Columns(6) = "BPK_Height" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Height" & CH_LDELIMIT & "#Height"
  la_Columns(7) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BPK_Nr" & CH_LDELIMIT & "#"
  la_Columns(8) = "OFD_Pos" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(9) = "PRD_Code" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#Code"
  la_Columns(10) = "PRD_Name" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(11) = "PPG_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPG_Qty" & CH_LDELIMIT & "#Qty"
  la_Columns(12) = "RPL_PanA" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanA" & CH_LDELIMIT & "#Panel A"
  la_Columns(13) = "RPL_PanB" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanB" & CH_LDELIMIT & "#Panel B"
  la_Columns(14) = "RPL_H" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_H" & CH_LDELIMIT & "#Panel H"
  la_Columns(15) = "RPL_Exec" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_Exec" & CH_LDELIMIT & "#Execution"
  la_Columns(16) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Total"
  grd_BoxSummary.SetColumns la_Columns
  
  ms_DPCImageCachePath = App.Path & DPC_IMAGE_CACHE
  ms_Caption = "#Packing definition"
  btn_Validate.Picture = LoadResPicture(RES_OK, 1)
  btn_Quit.Picture = LoadResPicture(RES_QUIT, 1)

  'Call mo_Tools.EnableFrame(UserControl.Controls, fra_Data, False)
  
  'Call mo_Tools.LoadToolbars(mo_Db, UserControl.Controls, "DPC", SCREEN_NAME)
  'Screen csts
  mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, UserControl.Controls, Me, SCREEN_NAME, ms_Language_Code)
  Call mo_Tools.ChangeCharset(UserControl.Controls, gl_CodePage)
  
  Call LoadBox
  
  Result = False
  mb_InternalInit = False
  mb_Initialized = True
  Load_A_COM = mb_Initialized
  Exit Function
ErrHandler:
  Call ErrorHandler("Load_A_COM")
End Function

Public Sub Unload_A_COM()
On Error GoTo ErrHandler

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

Private Sub LoadBox()
Dim ls_req As String

  ls_req = "SELECT DISTINCT PPG.BPK_Id, PPG.PPG_Nr, BPK.BPK_Name, BPK.BPK_Length, BPK.BPK_Width, BPK.BPK_Height "
  ls_req = ls_req & "FROM Cap_OfferDetail OFD "
  ls_req = ls_req & "INNER JOIN DPC_PrdCommon PRC ON (OFD.PRD_Id=PRC.PRD_Id) "
  ls_req = ls_req & "INNER JOIN DPC_PrdPacking PPG ON (PRC.PRD_Id=PPG.PRD_Id) "
  ls_req = ls_req & "INNER JOIN DPC_BOM_Packing BPK ON (PPG.BPK_Id=BPK.BPK_Id) "
  ls_req = ls_req & "WHERE OFD.COF_Id='0000000000000166' AND OFD.CAT_Id=$CAT_Id$ AND OFD.OFD_Main=$OFD_Main$"
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$CAT_Id$", mo_Tools.SqlInt(eDPCCategory.cgMetalCustomRectPanel))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$OFD_Main$", mo_Tools.SqlInt(eDPCOfferDetailMain.odMain))
  Call grd_BoxMain.Load(ls_req, True)
End Sub

Private Sub grd_BoxMain_Click()
  If grd_BoxMain.SelectedCount = 1 Then
    Call LoadBoxItems("0000000000000166", grd_BoxMain.SelectedLine(0, "PPG_Nr"))
  Else
    Call grd_BoxItemMain.ClearGrid
  End If
End Sub

Private Sub LoadBoxItems(ByVal as_COF_Id As String, ByVal al_PPG_Nr As Long)

Dim ls_req As String

  ls_req = "SELECT PPG.BPK_Id, PPG.PPG_Nr, OFD.OFD_Pos, PRC.PRD_Code, PRD.PRD_Name, PPG.PPG_Qty, RPL.RPL_PanA, RPL.RPL_PanB, RPL.RPL_HC as RPL_H, OFD.OFD_Qty,"
  ls_req = ls_req & "'C'+PRDBNDC.PRD_Name+' D'+PRDBNDD.PRD_Name+' E'+PRDBNDE.PRD_Name+' F'+PRDBNDF.PRD_Name as RPL_Exec "
  ls_req = ls_req & "FROM Cap_OfferDetail OFD "
  ls_req = ls_req & "INNER JOIN DPC_PrdCommon PRC ON (OFD.PRD_Id=PRC.PRD_Id) "
  ls_req = ls_req & "INNER JOIN DPC_PrdDesc PRD ON (PRC.PRD_Id=PRD.PRD_Id AND PRD.Language_Code=$Language_Code$) "
  ls_req = ls_req & "INNER JOIN DPC_RectPanel RPL ON (PRC.PRD_Id=RPL.RPL_Id) "
  ls_req = ls_req & "INNER JOIN DPC_PrdPacking PPG ON (PRC.PRD_Id=PPG.PRD_Id) "
  ls_req = ls_req & "INNER JOIN DPC_BOM_Packing BPK ON (PPG.BPK_Id=BPK.BPK_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDC ON (RPL.BND_IdC=BNDC.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDC ON (BNDC.BND_Id=PRDBNDC.PRD_Id AND PRDBNDC.Language_Code=$Language_Code$) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDD ON (RPL.BND_IdD=BNDD.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDD ON (BNDD.BND_Id=PRDBNDD.PRD_Id AND PRDBNDD.Language_Code=$Language_Code$) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDE ON (RPL.BND_IdE=BNDE.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDE ON (BNDE.BND_Id=PRDBNDE.PRD_Id AND PRDBNDE.Language_Code=$Language_Code$) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDF ON (RPL.BND_IdF=BNDF.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDF ON (BNDF.BND_Id=PRDBNDF.PRD_Id AND PRDBNDF.Language_Code=$Language_Code$) "
  ls_req = ls_req & "WHERE OFD.COF_Id=$COF_Id$ AND OFD.CAT_ID=$CAT_Id$ AND OFD.OFD_Main=$OFD_Main$ AND PPG.PPG_Nr=$PPG_Nr$"
  
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$Language_Code$", mo_Tools.SQLStr("E"))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$PPG_Nr$", mo_Tools.SqlInt(al_PPG_Nr))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$CAT_Id$", mo_Tools.SqlInt(eDPCCategory.cgMetalCustomRectPanel))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$OFD_Main$", mo_Tools.SqlInt(eDPCOfferDetailMain.odMain))
  
  Call grd_BoxItemMain.Load(ls_req, True)
End Sub

Private Sub LoadBoxSummary(ByVal as_COF_Id As String)

Dim ls_req As String

  ls_req = "SELECT PPG.BPK_Id, PPG.PPG_Nr, OFD.OFD_Pos, PRC.PRD_Code, PRD.PRD_Name, PPG.PPG_Qty, RPL.RPL_PanA, RPL.RPL_PanB, RPL.RPL_HC as RPL_H, OFD.OFD_Qty,"
  ls_req = ls_req & "'C'+PRDBNDC.PRD_Name+' D'+PRDBNDD.PRD_Name+' E'+PRDBNDE.PRD_Name+' F'+PRDBNDF.PRD_Name as RPL_Exec,"
  ls_req = ls_req & "BPK.BPK_Name, BPK.BPK_Length, BPK.BPK_Width, BPK.BPK_Height "
  ls_req = ls_req & "FROM Cap_OfferDetail OFD "
  ls_req = ls_req & "INNER JOIN DPC_PrdCommon PRC ON (OFD.PRD_Id=PRC.PRD_Id) "
  ls_req = ls_req & "INNER JOIN DPC_PrdDesc PRD ON (PRC.PRD_Id=PRD.PRD_Id AND PRD.Language_Code=$Language_Code$) "
  ls_req = ls_req & "INNER JOIN DPC_RectPanel RPL ON (PRC.PRD_Id=RPL.RPL_Id) "
  ls_req = ls_req & "INNER JOIN DPC_PrdPacking PPG ON (PRC.PRD_Id=PPG.PRD_Id) "
  ls_req = ls_req & "INNER JOIN DPC_BOM_Packing BPK ON (PPG.BPK_Id=BPK.BPK_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDC ON (RPL.BND_IdC=BNDC.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDC ON (BNDC.BND_Id=PRDBNDC.PRD_Id AND PRDBNDC.Language_Code=$Language_Code$) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDD ON (RPL.BND_IdD=BNDD.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDD ON (BNDD.BND_Id=PRDBNDD.PRD_Id AND PRDBNDD.Language_Code=$Language_Code$) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDE ON (RPL.BND_IdE=BNDE.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDE ON (BNDE.BND_Id=PRDBNDE.PRD_Id AND PRDBNDE.Language_Code=$Language_Code$) "
  ls_req = ls_req & "LEFT JOIN DPC_Bending BNDF ON (RPL.BND_IdF=BNDF.BND_Id) "
  ls_req = ls_req & "LEFT JOIN DPC_PrdDesc PRDBNDF ON (BNDF.BND_Id=PRDBNDF.PRD_Id AND PRDBNDF.Language_Code=$Language_Code$) "
  ls_req = ls_req & "WHERE OFD.COF_Id=$COF_Id$ AND OFD.CAT_Id=$CAT_Id$ AND OFD.OFD_Main=$OFD_Main$ "
  ls_req = ls_req & "ORDER BY PPG.PPG_Nr, PRC.PRD_Code"
  
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$Language_Code$", mo_Tools.SQLStr("E"))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$CAT_Id$", mo_Tools.SqlInt(eDPCCategory.cgMetalCustomRectPanel))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$OFD_Main$", mo_Tools.SqlInt(eDPCOfferDetailMain.odMain))
  
  Call grd_BoxSummary.Load(ls_req, True)
End Sub

Private Sub btn_Quit_Click()
  Result = False
  RaiseEvent quit
End Sub

Private Sub btn_Validate_Click()
  Result = True
  RaiseEvent quit
End Sub

Public Sub Resize()
On Error GoTo ErrHandler

  Call tbs_Main.Move(0, 0, Me.Width)
  Call fra_Main(0).Move(0, tbs_Main.Height, Me.Width, Me.Height - tbs_Main.Height)
  Call fra_Main(1).Move(0, tbs_Main.Height, Me.Width, Me.Height - tbs_Main.Height)
  
  fra_Main(0).Visible = tbs_Main.SelectedItem.Index = 1
  fra_Main(1).Visible = tbs_Main.SelectedItem.Index = 2
  
  'Call grd_BoxSummary.Move(0, 0, fra_Main(0).Width, fra_Main(0).Height)
  'Call grd_BoxMain.Move(0, 0, fra_Main(1).Width - tlb_BoxItemsMain.Width)
  'Call grd_BoxItemMain.Move(0, grd_BoxMain.Top + grd_BoxMain.Height + 200, fra_Main(1).Width - tlb_BoxItemsMain.Width)
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("Resize")
End Sub


Private Sub tbs_Main_Click()

  fra_Main(0).Visible = tbs_Main.SelectedItem.Index = 1
  fra_Main(1).Visible = tbs_Main.SelectedItem.Index = 2
  If tbs_Main.SelectedItem.Index = 2 Then
        Call LoadBoxSummary("0000000000000166")
  End If
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)
  ReplaceCommonPlaceholders = as_Request
  Exit Function
ErrHandler:
  Call ErrorHandler("ReplaceCommonPlaceholders")
End Function

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

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

