VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.ocx"
Begin VB.Form frmOfferManual 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "#Offer Manual Line"
   ClientHeight    =   9240
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   15210
   ControlBox      =   0   'False
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   9240
   ScaleWidth      =   15210
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Tag             =   "frmOfferManual"
   Visible         =   0   'False
   Begin Project1.A_calocx cal_WishDate 
      Height          =   360
      Left            =   13275
      TabIndex        =   11
      Top             =   15
      Width           =   1845
      _ExtentX        =   3254
      _ExtentY        =   635
   End
   Begin Project1.A_calocx cal_ShipDate 
      Height          =   360
      Left            =   13275
      TabIndex        =   12
      Top             =   390
      Width           =   1845
      _ExtentX        =   3254
      _ExtentY        =   635
   End
   Begin Project1.A_calocx cal_DeliveryDate 
      Height          =   360
      Left            =   13275
      TabIndex        =   13
      Top             =   765
      Width           =   1845
      _ExtentX        =   3254
      _ExtentY        =   635
   End
   Begin VB.TextBox txt_Textbox 
      Height          =   330
      Index           =   2
      Left            =   6375
      MaxLength       =   30
      TabIndex        =   2
      Tag             =   "OFD_PosCus"
      Top             =   30
      Width           =   1710
   End
   Begin VB.TextBox txt_Textbox 
      Height          =   375
      Index           =   3
      Left            =   6375
      TabIndex        =   7
      Tag             =   "PRD_ModA"
      Top             =   765
      Width           =   810
   End
   Begin VB.TextBox txt_Textbox 
      Height          =   375
      Index           =   4
      Left            =   9000
      TabIndex        =   8
      Tag             =   "PRD_ModB"
      Top             =   765
      Width           =   810
   End
   Begin VB.TextBox txt_Textbox 
      Height          =   375
      Index           =   5
      Left            =   6375
      TabIndex        =   10
      Tag             =   "PRD_NWgh"
      Top             =   1155
      Width           =   810
   End
   Begin VB.Frame fra_Detail 
      Height          =   6750
      Left            =   1290
      TabIndex        =   27
      Tag             =   "fra_Detail"
      Top             =   2025
      Width           =   12795
      Begin VB.Frame fra_Comment 
         Height          =   1725
         Left            =   45
         TabIndex        =   28
         Tag             =   "fra_Comment"
         Top             =   4875
         Visible         =   0   'False
         Width           =   14940
         Begin VB.Frame fra_PriceQty 
            Height          =   975
            Left            =   90
            TabIndex        =   34
            Tag             =   "fra_PriceQty"
            Top             =   630
            Width           =   14775
            Begin VB.TextBox txt_PU 
               Height          =   315
               Left            =   1515
               TabIndex        =   42
               Top             =   540
               Visible         =   0   'False
               Width           =   1335
            End
            Begin VB.TextBox txt_Cost 
               Height          =   315
               Left            =   7215
               TabIndex        =   41
               Top             =   525
               Width           =   1335
            End
            Begin VB.TextBox txt_CURR_CodeCost 
               BackColor       =   &H8000000F&
               Height          =   300
               Left            =   8670
               Locked          =   -1  'True
               TabIndex        =   40
               TabStop         =   0   'False
               Top             =   525
               Width           =   1140
            End
            Begin VB.TextBox txt_CURR_Code2 
               BackColor       =   &H8000000F&
               Height          =   300
               Left            =   12990
               Locked          =   -1  'True
               TabIndex        =   39
               TabStop         =   0   'False
               Top             =   195
               Width           =   1140
            End
            Begin VB.TextBox txt_Total 
               BackColor       =   &H8000000F&
               Height          =   315
               Left            =   11535
               Locked          =   -1  'True
               TabIndex        =   38
               TabStop         =   0   'False
               Top             =   195
               Width           =   1335
            End
            Begin VB.TextBox txt_CURR_CodePrice 
               BackColor       =   &H8000000F&
               Height          =   300
               Left            =   8670
               Locked          =   -1  'True
               TabIndex        =   37
               TabStop         =   0   'False
               Top             =   195
               Width           =   1140
            End
            Begin VB.TextBox txt_Price 
               Height          =   315
               Left            =   7215
               TabIndex        =   36
               Top             =   195
               Width           =   1335
            End
            Begin VB.TextBox txt_Qty 
               Height          =   315
               Left            =   1515
               TabIndex        =   35
               Top             =   195
               Width           =   1335
            End
            Begin Project1.ArmCombobox cbo_UOM 
               Height          =   345
               Left            =   2970
               TabIndex        =   43
               Top             =   195
               Width           =   1140
               _ExtentX        =   2011
               _ExtentY        =   609
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Packing unit"
               Height          =   225
               Index           =   8
               Left            =   75
               TabIndex        =   50
               Tag             =   "lbl_PackingUnit"
               Top             =   585
               Visible         =   0   'False
               Width           =   1290
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Cost"
               Height          =   225
               Index           =   7
               Left            =   5760
               TabIndex        =   49
               Tag             =   "lbl_Cost"
               Top             =   570
               Width           =   1290
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Total"
               Height          =   225
               Index           =   5
               Left            =   10080
               TabIndex        =   48
               Tag             =   "lbl_Total"
               Top             =   240
               Width           =   1290
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Price"
               Height          =   225
               Index           =   4
               Left            =   5760
               TabIndex        =   47
               Tag             =   "lbl_Price"
               Top             =   240
               Width           =   1290
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Quantity"
               Height          =   225
               Index           =   3
               Left            =   75
               TabIndex        =   46
               Tag             =   "lbl_Quantity"
               Top             =   240
               Width           =   1290
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Description"
               Height          =   225
               Index           =   1
               Left            =   4140
               TabIndex        =   45
               Tag             =   "lbl_Description"
               Top             =   270
               Visible         =   0   'False
               Width           =   1290
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Value"
               Height          =   225
               Index           =   2
               Left            =   4110
               TabIndex        =   44
               Tag             =   "lbl_Value"
               Top             =   630
               Visible         =   0   'False
               Width           =   1290
            End
         End
         Begin VB.TextBox txt_Description 
            BackColor       =   &H8000000F&
            Height          =   300
            Left            =   90
            Locked          =   -1  'True
            TabIndex        =   30
            TabStop         =   0   'False
            Top             =   195
            Width           =   4935
         End
         Begin VB.TextBox txt_Value 
            Height          =   375
            Left            =   5235
            TabIndex        =   29
            Top             =   180
            Width           =   8985
         End
      End
      Begin Project1.ArmGrid grd_Offer 
         Height          =   4740
         Left            =   45
         TabIndex        =   31
         Tag             =   "grd_Offer"
         Top             =   135
         Width           =   14925
         _ExtentX        =   26326
         _ExtentY        =   8361
      End
   End
   Begin VB.Frame fra_Files 
      Height          =   2835
      Left            =   9345
      TabIndex        =   24
      Tag             =   "fra_Files"
      Top             =   2340
      Width           =   5670
      Begin Project1.ArmGrid grd_File 
         Height          =   2640
         Left            =   90
         TabIndex        =   25
         Tag             =   "grd_File"
         Top             =   210
         Width           =   14220
         _ExtentX        =   25083
         _ExtentY        =   4657
      End
      Begin Project1.ToolbarControl tlb_File 
         Height          =   2775
         Left            =   14355
         TabIndex        =   26
         Tag             =   "2964"
         Top             =   105
         Width           =   690
         _ExtentX        =   1217
         _ExtentY        =   4895
      End
   End
   Begin VB.CheckBox chk_FreeOfCharge 
      Caption         =   "#Free of charge"
      Height          =   225
      Left            =   9945
      TabIndex        =   9
      Tag             =   "chk_FreeOfCharge"
      Top             =   855
      Width           =   1755
   End
   Begin VB.CheckBox chk_ASFlag 
      Caption         =   "#AS Item"
      Height          =   225
      Left            =   9945
      TabIndex        =   5
      Tag             =   "chk_ASFlag"
      Top             =   465
      Width           =   1500
   End
   Begin VB.TextBox txt_Textbox 
      Height          =   375
      Index           =   0
      Left            =   1425
      TabIndex        =   0
      TabStop         =   0   'False
      Tag             =   "PRD_Code"
      Top             =   8
      Width           =   1500
   End
   Begin VB.TextBox txt_Textbox 
      Height          =   375
      Index           =   1
      Left            =   3990
      TabIndex        =   1
      Tag             =   "OFD_Pos"
      Top             =   8
      Width           =   810
   End
   Begin VB.CommandButton btn_Validate 
      Height          =   612
      Left            =   13815
      Style           =   1  'Graphical
      TabIndex        =   16
      Tag             =   "btn_Validate"
      Top             =   8610
      Width           =   612
   End
   Begin VB.CommandButton btn_Quit 
      Height          =   612
      Left            =   14490
      Style           =   1  'Graphical
      TabIndex        =   15
      Tag             =   "btn_Quit"
      Top             =   8610
      Width           =   612
   End
   Begin Project1.ArmCombobox cbo_Vendor 
      Height          =   345
      Left            =   1425
      TabIndex        =   3
      Top             =   405
      Width           =   3405
      _ExtentX        =   6006
      _ExtentY        =   609
   End
   Begin Project1.ArmCombobox cbo_ShipPoint 
      Height          =   345
      Left            =   6375
      TabIndex        =   4
      Top             =   405
      Width           =   3435
      _ExtentX        =   6059
      _ExtentY        =   609
   End
   Begin MSComctlLib.TabStrip tbs_OfferDetail 
      Height          =   405
      Left            =   15
      TabIndex        =   14
      Tag             =   "tbs_OfferDetail"
      Top             =   1575
      Width           =   15165
      _ExtentX        =   26749
      _ExtentY        =   714
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   2
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "#Detail"
            Key             =   "tab_Detail"
            Object.Tag             =   "tab_Detail"
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "#Files"
            Key             =   "tab_Files"
            Object.Tag             =   "tab_Files"
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
   Begin Project1.ArmCombobox cbo_Material 
      Height          =   345
      Left            =   1425
      TabIndex        =   6
      Tag             =   "cbo_Material"
      Top             =   780
      Width           =   3405
      _ExtentX        =   6006
      _ExtentY        =   609
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Delivery date"
      Height          =   255
      Index           =   6
      Left            =   11745
      TabIndex        =   18
      Tag             =   "lbl_OFD_DeliveryDate"
      Top             =   825
      Width           =   1500
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Ship date"
      Height          =   255
      Index           =   10
      Left            =   11805
      TabIndex        =   23
      Tag             =   "lbl_OFD_ShipDate"
      Top             =   450
      Width           =   1470
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Wish date"
      Height          =   255
      Index           =   185
      Left            =   11760
      TabIndex        =   19
      Tag             =   "lbl_OFD_WishDate"
      Top             =   68
      Width           =   1470
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Customer position"
      Height          =   255
      Index           =   63
      Left            =   4860
      TabIndex        =   53
      Tag             =   "lbl_PanelCodeC"
      Top             =   68
      Width           =   1500
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Module A [mm]"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   225
      Index           =   15
      Left            =   4860
      TabIndex        =   52
      Tag             =   "lbl_ModA"
      Top             =   840
      Width           =   1500
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Module B [mm]"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   225
      Index           =   14
      Left            =   7350
      TabIndex        =   51
      Tag             =   "lbl_ModB"
      Top             =   840
      Width           =   1620
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Weight [kg]"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   225
      Index           =   13
      Left            =   4860
      TabIndex        =   33
      Tag             =   "lbl_Weight"
      Top             =   1230
      Width           =   1410
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Material"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   12
      Left            =   15
      TabIndex        =   32
      Tag             =   "lbl_Material"
      Top             =   825
      Width           =   1470
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Code"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   225
      Index           =   9
      Left            =   15
      TabIndex        =   22
      Tag             =   "lbl_Code"
      Top             =   83
      Width           =   1395
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Plant/Vendor"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   11
      Left            =   15
      TabIndex        =   21
      Tag             =   "lbl_PlantVendor"
      Top             =   450
      Width           =   1470
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Shipping point"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   30
      Left            =   4860
      TabIndex        =   20
      Tag             =   "lbl_ShipPoint"
      Top             =   450
      Width           =   1470
   End
   Begin VB.Label lbl_Label 
      Caption         =   "#Position"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   238
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   225
      Index           =   0
      Left            =   2925
      TabIndex        =   17
      Tag             =   "lbl_Position"
      Top             =   83
      Width           =   1035
   End
End
Attribute VB_Name = "frmOfferManual"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

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

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

Private me_PriceBookType                As eDPCPriceBookType
Private ml_U_Code                       As Long
Private ms_Language_Code                As String
Private ms_COF_Lang                     As String       'current user data language
Private mc_ScreenLabels                 As Long
Private mb_InternalInit                 As Boolean
Private mb_Initialized                  As Boolean
Private ml_ActiveRow                    As Long
Private mo_Tools                        As DPC_Tools
Private ml_Idx                          As Long
Private mb_CurrentTextBoxChanged        As Boolean

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

Public Result As Boolean
Public PRD_Id As String
Public CURR_Code As String
Public PRD_Code As String
Public PRD_CodeC As String
Public CT_Code As String
Public COF_Id As String
Public LEN_Id As Long
Public OFD_WshDat As Date
Public OFD_ShpDat As Date
Public OFD_DelDat As Date
Public OFD_Pos As Long
Public OFD_PosCus As String
Public OFD_PU As Long
Public SAE_Id As Long
Public SHP_Id As Long
Public VEN_Id As String
Public SAE_Name As String
Public SHP_Name As String
Public VEN_Name As String
Public OFD_IsAsItem As Boolean
Public OFD_IsFree As Boolean
Public PRD_ModA As Double
Public PRD_ModB As Double
Public PRD_NWgh As Double
Public MAT_Id As Long
Public MAT_Name As String
Public STA_Id As Long


Public OfferPrice As New Collection
Public Files As New Collection

Private me_PrdScreen As eDPCScreenMode
Private ml_iConcurrency As Long

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

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

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

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

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

Property Let COF_Lang(as_Value As String)
On Error GoTo ErrHandler

  ms_COF_Lang = as_Value
  Exit Property
ErrHandler:
  Call ErrorMessage("COF_Lang.Let")
End Property

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

Public Property Get ModuleSurface() As Double
On Error GoTo ErrHandler
  
  ModuleSurface = (PRD_ModA * PRD_ModB) / 1000000
  Exit Property
ErrHandler:
  Call ErrorHandler("ModuleSurface.Get")
End Property

Public Property Get PanelSurface() As Double
On Error GoTo ErrHandler
  
  PanelSurface = (PRD_ModA * PRD_ModB) / 1000000
  Exit Property
ErrHandler:
  Call ErrorHandler("PanelSurface.Get")
End Property

Public Function Load_A_COM() As Boolean
On Error GoTo ErrHandler

  Dim ls_req As String
  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)
  
  btn_Validate.Picture = LoadResPicture(RES_OK, 1)
  btn_Quit.Picture = LoadResPicture(RES_QUIT, 1)
  
  Set mo_FSO = New FileSystemObject

  ls_req = "exec DPC_Unit_Of_Measure_cbo3 $COF_Lang$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_UOM.Request = ls_req
  Call cbo_UOM.Load
  'For ll_Idx = cbo_UOM.Count To 1 Step -1
  '  If (StrComp(cbo_UOM.ComboItems(ll_Idx).Key, DPC_UOM_M2, vbTextCompare) <> 0) And (StrComp(cbo_UOM.ComboItems(ll_Idx).Key, DPC_UOM_PCS, vbTextCompare) <> 0) Then
  '    Call cbo_UOM.DeleteItemIndex(ll_Idx)
  '  End If
  'Next
  Call InitVendorCombo(cbo_Vendor)
  Call InitShipPointCombo(cbo_ShipPoint)
  Call InitMaterialCombo

  grd_Offer.WordWrap = True
  ReDim la_Columns(13) As Variant
  la_Columns(0) = "DOF_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "DOF_Id" & CH_LDELIMIT & ""
  la_Columns(1) = "DOF_IsStp" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DOF_IsStp" & CH_LDELIMIT & ""
  la_Columns(2) = "DOF_IsTxt" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DOF_IsTxt" & CH_LDELIMIT & ""
  la_Columns(3) = "DOF_Order" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DOF_Order" & CH_LDELIMIT & ""
  la_Columns(4) = "DOF_Name" & CH_LDELIMIT & "4000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DOF_Name" & CH_LDELIMIT & "#Description" & CH_LDELIMIT & "String" & CH_LDELIMIT & "" & CH_LDELIMIT & "LEFT"
  la_Columns(5) = "DOF_Value" & CH_LDELIMIT & "4000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DOF_Value" & CH_LDELIMIT & "#Value" & CH_LDELIMIT & "String" & CH_LDELIMIT & "" & CH_LDELIMIT & "LEFT"
  la_Columns(6) = "Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Qty" & CH_LDELIMIT & "#Qty" & "Float" & CH_LDELIMIT & "0.00"
  la_Columns(7) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#UoM"
  la_Columns(8) = "UM_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#UoM"
  la_Columns(9) = "Price" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Price" & CH_LDELIMIT & "#Price per unit" & "Float" & CH_LDELIMIT & "0.00"
  la_Columns(10) = "Total" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Total" & CH_LDELIMIT & "#Total" & "Float" & CH_LDELIMIT & "0.00"
  la_Columns(11) = "CURR_Code" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CURR_Code" & CH_LDELIMIT & "#Currency"
  la_Columns(12) = "PU" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PU" & CH_LDELIMIT & "#PU"
  la_Columns(13) = "Cost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Cost" & CH_LDELIMIT & "#Cost per unit" & "Float" & CH_LDELIMIT & "0.00"
  Call grd_Offer.SetColumns(la_Columns)
  grd_Offer.AllowSort = False
  
  ls_req = "exec DPC_Offer_lst $DOF_Source$, $COF_Lang$"
  ls_req = Replace(ls_req, "$DOF_Source$", mo_Tools.SqlInt(eDPCOffferDetailSource.dsManualPosition), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  If Not grd_Offer.Load(ls_req, True) Then
    Err.Raise ArmErr.CompFncFailed, "grd_Offer.Load", "Load grid failed: " & ls_req
  End If
  Call grd_Offer.SetAutoRowHeight("DOF_Name")
  Call grd_Offer.DeselectRow
  ml_ActiveRow = -1
  Call mo_Tools.SetTextEnabled(txt_Textbox, "PRD_Code", False)
  Call Resize
  
  grd_File.UnBound = True
  ReDim la_Columns(6) As Variant
  la_Columns(0) = "Idx" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Idx" & CH_LDELIMIT & ""
  la_Columns(1) = "PFI_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PFI_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(3) = "FIL_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "FIL_Id" & CH_LDELIMIT & ""
  la_Columns(4) = "FIL_Name" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "FIL_Name" & CH_LDELIMIT & "#Name"
  la_Columns(5) = "FIL_FileName" & CH_LDELIMIT & "7000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "FIL_FileName" & CH_LDELIMIT & "#File"
  la_Columns(6) = "PFI_Order" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PFI_Order" & CH_LDELIMIT & "#Order"
  Call grd_File.SetColumns(la_Columns)
  
  Call mo_Tools.LoadToolbars(mo_Db, Me.Controls, "Cap_Offer", SCREEN_NAME)
  'Screen csts
  mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, Me.Controls, Me, SCREEN_NAME, ms_Language_Code)
  Call mo_Tools.ChangeCharset(Me.Controls, gl_CodePage, mo_Tools.GetCodePageFromLanguage(mo_Db, ms_COF_Lang), Me)
  Result = False
  mb_InternalInit = False
  mb_Initialized = True
  mb_CurrentTextBoxChanged = False
  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(Me.Controls)
  Call mo_Db.Close(mc_ScreenLabels)
  Set mo_Db = Nothing
  Set mo_FSO = Nothing
  Exit Sub
ErrHandler:
  Call ErrorHandler("Unload_A_COM")
End Sub

Public Sub ItemAdd()
On Error GoTo ErrHandler

Dim ll_Idx As Long
  
  mb_InternalInit = True
  me_PrdScreen = eDPCScreenMode.smAdd
  For ll_Idx = 0 To grd_Offer.Rows - 1
    grd_Offer.Data(ll_Idx, "CURR_Code") = CURR_Code
  Next
  Call DisplayHeader
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("ItemAdd")
End Sub

Public Sub ItemUpdate(ByVal as_COF_Id As String, ByVal as_OFD_IdPar As String)
On Error GoTo ErrHandler

Dim lc_Cursor As Long
Dim ls_req As String
Dim ls_PRD_Name  As String, ls_DOF_Value As String, ls_DOF_Name As String
Dim ll_Idx As Long, ll_RowIndex As Long, ll_Order As Long, ll_SepPos As Long
Dim lo_Offer As DPC_OfferPos

  mb_InternalInit = True
  me_PrdScreen = eDPCScreenMode.smUpdate
  ls_req = "exec Cap_OfferDetail_lst2 $COF_Id$, $COF_Lang$, $OFD_Main$, $OFD_IdPar$, $OFD_Valid$, $OFD_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Main$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(as_OFD_IdPar), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Valid$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Id$", "NULL", , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  Call mo_Db.First(lc_Cursor)
  While Not mo_Db.EOF(lc_Cursor)
    Set lo_Offer = New DPC_OfferPos
    Set lo_Offer.Tools = mo_Tools
    Call lo_Offer.Init(0, 0, eDPCQtyType.qtPCS, 1, 0, 0)
    Call lo_Offer.ReadOfferPos(mo_Db, lc_Cursor)
    Call OfferPrice.Add(lo_Offer)
    Call mo_Db.Next(lc_Cursor)
  Wend
  Call mo_Db.Close(lc_Cursor)

  Set lo_Offer = GetOfferPos(eDPCOfferDetail.odManualPosition)
  PRD_Id = lo_Offer.PRD_Id
  OFD_Pos = lo_Offer.OFD_Pos
  OFD_PosCus = lo_Offer.OFD_PosCus
  PRD_Code = lo_Offer.PRD_Code
  PRD_CodeC = lo_Offer.PRD_CodeC
  OFD_WshDat = lo_Offer.OFD_WshDat
  OFD_ShpDat = lo_Offer.OFD_ShpDat
  OFD_DelDat = lo_Offer.OFD_DelDat
  VEN_Id = lo_Offer.VEN_Id
  SHP_Id = lo_Offer.SHP_Id
  VEN_Name = lo_Offer.VEN_Name
  SHP_Name = lo_Offer.SHP_Name
  COF_Id = lo_Offer.COF_Id
  OFD_IsFree = lo_Offer.OFD_IsFree
  OFD_IsAsItem = lo_Offer.OFD_IsAsItem
  OFD_PU = lo_Offer.OFD_PU
  
  For Each lo_Offer In OfferPrice
    If grd_Offer.SearchKey(True, lo_Offer.DOF_Id) Then
      ll_RowIndex = grd_Offer.Row
      ls_PRD_Name = Trim(lo_Offer.PRD_Name)
      ls_DOF_Name = Trim(lo_Offer.DOF_Name)
      ll_SepPos = InStr(1, ls_PRD_Name, ":")
      If ll_SepPos = 0 Then
        If StrComp(Left(ls_PRD_Name, Len(ls_DOF_Name)), ls_DOF_Name, vbTextCompare) = 0 Then
          grd_Offer.Data(ll_RowIndex, "DOF_Value") = Trim(Mid(ls_PRD_Name, Len(ls_DOF_Name) + 1))
        Else
          grd_Offer.Data(ll_RowIndex, "DOF_Value") = ls_PRD_Name
        End If
      Else
        grd_Offer.Data(ll_RowIndex, "DOF_Value") = Trim(right(ls_PRD_Name, Len(ls_PRD_Name) - ll_SepPos))
      End If
    Else
      ll_Order = lo_Offer.OFD_Order
      ll_RowIndex = -1
      For ll_Idx = 0 To grd_Offer.Rows - 1
        If grd_Offer.Data(ll_Idx, "DOF_Order") < ll_Order Then
          ll_RowIndex = ll_Idx
          Exit For
        End If
      Next
      If ll_RowIndex >= 0 Then
        Call grd_Offer.InsertLine(ll_RowIndex)
      Else
        Call grd_Offer.AddLine
        ll_RowIndex = grd_Offer.Rows - 1
      End If
      grd_Offer.Data(ll_RowIndex, "DOF_Id") = lo_Offer.DOF_Id
      grd_Offer.Data(ll_RowIndex, "DOF_Name") = ""
      grd_Offer.Data(ll_RowIndex, "DOF_Value") = Trim(lo_Offer.PRD_Name)
    End If
    grd_Offer.Data(ll_RowIndex, "Qty") = lo_Offer.OFD_Qty
    grd_Offer.Data(ll_RowIndex, "PU") = lo_Offer.OFD_PU
    grd_Offer.Data(ll_RowIndex, "UM_Code") = lo_Offer.UM_Code
    grd_Offer.Data(ll_RowIndex, "UM_Name") = lo_Offer.UM_Name
    grd_Offer.Data(ll_RowIndex, "Price") = lo_Offer.OFD_Price
    grd_Offer.Data(ll_RowIndex, "Cost") = lo_Offer.OFD_Cost
    grd_Offer.Data(ll_RowIndex, "Total") = lo_Offer.OFD_TotalP
    grd_Offer.Data(ll_RowIndex, "CURR_Code") = lo_Offer.CURR_Code
  Next
  Call LoadPrdManual
  Call LoadPrdFile
  Call DisplayHeader
  Call DisplayFile
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("ItemUpdate")
End Sub

Public Sub ItemSave()
On Error GoTo ErrHandler

  If PRD_Code = "" Then
    PRD_Code = mo_Tools.GetNextID(mo_Db, "DPC_MAN_PRD_Code")
  End If
  If (me_PrdScreen = eDPCScreenMode.smAdd) Then
     PRD_Id = mo_Tools.GetNextID(mo_Db, "DPC_PrdManual")
     Call InsertPrdCommon
     Call InsertPrdManual
     Call SaveFile
   ElseIf me_PrdScreen = eDPCScreenMode.smUpdate Then
     Call UpdatePrdCommon
     Call UpdatePrdManual
     Call SaveFile
   End If
   Exit Sub
ErrHandler:
   Call ErrorHandler("ItemSave")
End Sub

Private Sub LoadPrdManual()
On Error GoTo ErrHandler

Dim ls_req As String
Dim lc_Cursor As Long

  If PRD_Id <> "" Then
    ls_req = "exec DPC_PrdManual_sel $PRD_Id$, $Language_Code$"
    
    ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    If mo_Db.RowCount(lc_Cursor) = 1 Then
      PRD_ModA = mo_Db.GetFields(lc_Cursor, "PRD_ModA")
      PRD_ModB = mo_Db.GetFields(lc_Cursor, "PRD_ModB")
      PRD_NWgh = mo_Db.GetFields(lc_Cursor, "PRD_NWgh")
      MAT_Id = mo_Db.GetFields(lc_Cursor, "MAT_Id")
      MAT_Name = mo_Db.GetFields(lc_Cursor, "MAT_Name")
      STA_Id = mo_Db.GetFields(lc_Cursor, "STA_Id")
    End If
    Call mo_Db.Close(lc_Cursor)
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadPrdManual")
End Sub

Private Sub InsertPrdCommon()
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdCommon_ins $PRD_Id$, $CAT_Id$, $PRD_IdPar$, $PRD_Child$, $PRD_Code$, $PRD_CodeC$,"
  ls_req = ls_req & "$Vendor_Id$, $LEV_Id$, $ERR_Type$, $IMG_Id$, $STA_Id$, NULL, $Z_Creator$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CAT_Id$", mo_Tools.SqlIntKey(eDPCCategory.cgManualMetal), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_IdPar$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Child$", mo_Tools.SqlInt(0), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Code$", mo_Tools.SQLStr(PRD_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_CodeC$", mo_Tools.SQLStr(PRD_CodeC), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Vendor_Id$", mo_Tools.SqlStrKey(VEN_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$LEV_Id$", mo_Tools.SqlInt(eDPCLevel.lvEngineered), , , vbTextCompare)
  ls_req = Replace(ls_req, "$ERR_Type$", mo_Tools.SqlInt(eDPCErrorType.etNone), , , vbTextCompare)
  ls_req = Replace(ls_req, "$IMG_Id$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$STA_Id$", mo_Tools.SqlIntKey(STA_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
  Exit Sub
ErrHandler:
  Call ErrorHandler("InsertPrdCommon")
End Sub

Private Sub UpdatePrdCommon()
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdCommon_upd $PRD_Id$, $CAT_Id$, $PRD_IdPar$, $PRD_Child$, $PRD_Code$, $PRD_CodeC$,"
  ls_req = ls_req & "$Vendor_Id$, $LEV_Id$, $ERR_Type$, $IMG_Id$, $STA_Id$, NULL, $Z_Last_Upd_User$, $iConcurrency$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CAT_Id$", mo_Tools.SqlIntKey(eDPCCategory.cgManualMetal), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_IdPar$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Child$", mo_Tools.SqlInt(0), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Code$", mo_Tools.SQLStr(PRD_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_CodeC$", mo_Tools.SQLStr(PRD_CodeC), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Vendor_Id$", mo_Tools.SqlStrKey(VEN_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$LEV_Id$", mo_Tools.SqlInt(eDPCLevel.lvEngineered), , , vbTextCompare)
  ls_req = Replace(ls_req, "$ERR_Type$", mo_Tools.SqlInt(eDPCErrorType.etNone), , , vbTextCompare)
  ls_req = Replace(ls_req, "$IMG_Id$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$STA_Id$", mo_Tools.SqlIntKey(STA_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdatePrdCommon")
End Sub

Private Sub DropPrdCommon()
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdCommon_del $PRD_Id$,$Z_Last_Upd_User$,$iConcurrency$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
  Exit Sub
ErrHandler:
  Call ErrorHandler("DropPrdCommon")
End Sub

Private Sub InsertPrdManual()
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdManual_ins $PRD_Id$, $MAT_Id$, $PRD_ModA$, $PRD_ModB$, $PRD_NWgh$, $Z_Creator$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$MAT_Id$", mo_Tools.SqlIntKey(MAT_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_ModA$", mo_Tools.SqlDbl(PRD_ModA), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_ModB$", mo_Tools.SqlDbl(PRD_ModB), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_NWgh$", mo_Tools.SqlDbl(PRD_NWgh), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
  Exit Sub
ErrHandler:
  Call ErrorHandler("InsertPrdManual")
End Sub

Private Sub UpdatePrdManual()
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdManual_upd $PRD_Id$, $MAT_Id$, $PRD_ModA$, $PRD_ModB$, $PRD_NWgh$, $Z_Last_Upd_User$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$MAT_Id$", mo_Tools.SqlIntKey(MAT_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_ModA$", mo_Tools.SqlDbl(PRD_ModA), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_ModB$", mo_Tools.SqlDbl(PRD_ModB), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_NWgh$", mo_Tools.SqlDbl(PRD_NWgh), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdatePrdCommon")
End Sub

Private Sub DropPrdManual()
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdManual_del $PRD_Id$,$Z_Last_Upd_User$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SqlStrKey(PRD_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
  Exit Sub
ErrHandler:
  Call ErrorHandler("DropPrdManual")
End Sub

Public Sub LoadPrdFile()
On Error GoTo ErrHandler

Dim ls_req As String
Dim lc_Cursor As Long
Dim lo_File As DPC_File

  ls_req = "exec DPC_PrdFile_Lst $PRD_Id$, $Language_code$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(PRD_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  While Not mo_Db.EOF(lc_Cursor)
    Set lo_File = New DPC_File
    Call InitFile(lo_File, eDPCRowStatus.rsNone)
    Call lo_File.ReadFile(mo_Db, lc_Cursor)
    Call Files.Add(lo_File)
    Call mo_Db.Next(lc_Cursor)
  Wend
  Call mo_Db.Close(lc_Cursor)
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadFile")
End Sub

Private Sub SaveFile()
On Error GoTo ErrHandler

Dim lo_File As DPC_File

  'first delete items to avoid add the same unique key
  For Each lo_File In Files
    If lo_File.RowStatus = eDPCRowStatus.rsDrop Then
      Call DropPrdFile(lo_File)
    End If
  Next
  For Each lo_File In Files
    If lo_File.RowStatus = eDPCRowStatus.rsUpdate Then
      Call UpdatePrdFile(lo_File)
    End If
  Next
  For Each lo_File In Files
    If lo_File.RowStatus = eDPCRowStatus.rsAdd Then
      Call InsertPrdFile(lo_File)
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("SaveFile")
End Sub

Private Sub InsertPrdFile(ByVal ao_File As DPC_File)
On Error GoTo ErrHandler

Dim ls_req As String

  ao_File.PFI_Id = mo_Tools.GetNextID(mo_Db, "DPC_PrdFile")
  
  ls_req = "exec DPC_PrdFile_ins $PFI_Id$, $PRD_Id$, $FIL_Id$, $PFI_Order$, $Z_Creator$"
  
  ls_req = Replace(ls_req, "$PFI_Id$", mo_Tools.SQLStr(ao_File.PFI_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$FIL_Id$", mo_Tools.SqlIntKey(ao_File.FIL_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PFI_Order$", mo_Tools.SqlInt(ao_File.PFI_Order), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
  Exit Sub
ErrHandler:
  Call ErrorHandler("InsertPrdFile")
End Sub

Private Sub UpdatePrdFile(ByVal ao_File As DPC_File)
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_PrdFile_upd $PFI_Id$, $PRD_Id$, $FIL_Id$, $PFI_Order$, $Z_Last_Upd_User$"
  
  ls_req = Replace(ls_req, "$PFI_Id$", mo_Tools.SQLStr(ao_File.PFI_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$FIL_Id$", mo_Tools.SqlIntKey(ao_File.FIL_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PFI_Order$", mo_Tools.SqlInt(ao_File.PFI_Order), , , vbTextCompare)
  
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdatePrdFile")
End Sub

Private Sub DropPrdFile(ByVal ao_File As DPC_File)
On Error GoTo ErrHandler

Dim ls_req As String

  If ao_File.RowStatus <> eDPCRowStatus.rsDrop Then
    Err.Raise 0, "DropPrdFile", "DropPrdFile"
  End If
  
  ls_req = "exec DPC_PrdFile_del $PFI_Id$, $Z_Last_Upd_User$"
  
  ls_req = Replace(ls_req, "$PFI_Id$", mo_Tools.SQLStr(ao_File.PFI_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
  Exit Sub
ErrHandler:
  Call ErrorHandler("DropPrdFile")
End Sub

Public Function GetOfferPos(ByVal ae_DOF_Id As eDPCOfferDetail) As DPC_OfferPos
On Error GoTo ErrHandler

Dim lo_Offer As DPC_OfferPos

  Set GetOfferPos = Nothing
  For Each lo_Offer In OfferPrice
    If lo_Offer.DOF_Id = ae_DOF_Id Then
      Set GetOfferPos = lo_Offer
      Exit Function
    End If
  Next
  Exit Function
ErrHandler:
  Call ErrorHandler("GetOfferPos")
End Function

Private Sub InitVendorCombo(ByVal ao_Combo As ArmCombobox)
On Error GoTo ErrHandler

  Dim ls_Request As String
  ls_Request = "exec DPC_Vendor_SAP_View_lst $LEN_Id$, $COF_Lang$"
  ls_Request = Replace(ls_Request, "$LEN_Id$", mo_Tools.SqlInt(LEN_Id), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  ao_Combo.Request = ls_Request
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitVendorCombo")
End Sub

Private Sub InitShipPointCombo(ByVal ao_Combo As ArmCombobox)
On Error GoTo ErrHandler

  Dim ls_Request As String
  ls_Request = "exec DPC_ShipPoint_SAP_View_lst $LEN_Id$, $VEN_Id$, $COF_Lang$"
  ls_Request = Replace(ls_Request, "$LEN_Id$", mo_Tools.SqlInt(LEN_Id), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$VEN_Id$", mo_Tools.SQLStr(mo_Tools.GetComboKey(cbo_Vendor)), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  ao_Combo.Request = ls_Request
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitShipPointCombo")
End Sub

Private Sub InitMaterialCombo()
On Error GoTo ErrHandler
  
Dim ls_Request As String

  ls_Request = "exec DPC_Material_lst2 $COF_Lang$"
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  cbo_Material.Request = ls_Request
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitMaterialCombo")
End Sub

Private Sub DisplayHeader()
On Error GoTo ErrHandler
  
  Call mo_Tools.SetTextBox(txt_Textbox, "OFD_Pos", mo_Tools.LongToScreen(OFD_Pos), False)
  Call mo_Tools.SetTextValue(txt_Textbox, "OFD_PosCus", OFD_PosCus)
  Call mo_Tools.SetTextValue(txt_Textbox, "PRD_Code", PRD_Code)
  
  Call mo_Tools.SetTextValue(txt_Textbox, "PRD_ModA", mo_Tools.DblToScreen(PRD_ModA, 0))
  Call mo_Tools.SetTextValue(txt_Textbox, "PRD_ModB", mo_Tools.DblToScreen(PRD_ModB, 0))
  Call mo_Tools.SetTextValue(txt_Textbox, "PRD_NWgh", mo_Tools.DblToScreen(PRD_NWgh))
  
  Call mo_Tools.SetCalendarDate(cal_WishDate, OFD_WshDat)
  Call mo_Tools.SetCalendarDate(cal_ShipDate, OFD_ShpDat)
  Call mo_Tools.SetCalendarDate(cal_DeliveryDate, OFD_DelDat)
  
  Call InitVendorCombo(cbo_Vendor)
  Call InitShipPointCombo(cbo_ShipPoint)
  If VEN_Id = "" Then
    Set cbo_Vendor.SelectedItem = Nothing
  Else
    If Not cbo_Vendor.SearchItem(VEN_Id) Then
      Call cbo_Vendor.AddItem(Array(VEN_Id, VEN_Name), True)
    End If
  End If
  If SHP_Id = 0 Then
    Set cbo_ShipPoint.SelectedItem = Nothing
  Else
    If Not cbo_ShipPoint.SearchItem(SHP_Id) Then
      Call cbo_ShipPoint.AddItem(Array(SHP_Id, SHP_Name), True)
    End If
  End If
  chk_ASFlag.Value = IIf(OFD_IsAsItem, vbChecked, vbUnchecked)
  chk_FreeOfCharge.Value = IIf(OFD_IsFree, vbChecked, vbUnchecked)
  If MAT_Id = 0 Then
    Set cbo_Material.SelectedItem = Nothing
  Else
    If Not cbo_Material.SearchItem(MAT_Id) Then
      Call cbo_Material.AddItem(Array(MAT_Id, MAT_Name), True)
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("DisplayHeader")
End Sub

Private Function ItemCheck() As Boolean
On Error GoTo ErrHandler

Dim lbl_Field As Label
Dim lo_Offer As DPC_OfferPos

  ItemCheck = False
  If Trim(grd_Offer.Data(0, "DOF_Value")) = "" Then
    Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Description")
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
    Exit Function
  End If
  If grd_Offer.Data(0, "UM_Code") = DPC_UOM_UNKNOWN Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", grd_Offer.Columns("UM_Code").Title))
    Exit Function
  End If
  If mo_Tools.ScreenToDbl(grd_Offer.Data(0, "Qty")) = 0 Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", grd_Offer.Columns("Qty").Title))
    Exit Function
  End If
  If mo_Tools.ScreenToDbl(grd_Offer.Data(0, "Price")) = 0 Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", grd_Offer.Columns("Price").Title))
    Exit Function
  End If
  If mo_Tools.ScreenToDbl(grd_Offer.Data(0, "Cost")) = 0 Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", grd_Offer.Columns("Cost").Title))
    Exit Function
  End If
  If (mo_Tools.GetComboKey(cbo_Vendor) = "") Or (cbo_Vendor.Text = "") Then
    Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_PlantVendor")
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
    Exit Function
  End If
  If (mo_Tools.GetComboKey(cbo_ShipPoint) = "") Or (cbo_ShipPoint.Text = "") Then
    Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_ShipPoint")
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
    Exit Function
  End If
  If (OFD_Pos <= 0) Then
    Set lo_Offer = GetOfferPos(eDPCOfferDetail.odManualPosition)
    If Not (lo_Offer Is Nothing) Then
      If (lo_Offer.OFD_IsAlt = eDPCOfferDetailIsAlt.maMain) Then
        Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Position")
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
        Exit Function
      End If
    End If
  End If
  'If (mo_Tools.GetComboKey(cbo_Material) = "") Or (cbo_Material.Text = "") Then
  '  Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Material")
  '  Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
  '  Exit Function
  'End If
  'If PRD_ModA <= 0 Then
  '  Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_ModA")
  '  Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
  '  Exit Function
  'End If
  'If PRD_ModB <= 0 Then
  '  Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_ModB")
  '  Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
  '  Exit Function
  'End If
  'If PRD_NWgh <= 0 Then
  '  Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Weight")
  '  Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
  '  Exit Function
  'End If
  ItemCheck = True
  Exit Function
ErrHandler:
  Call ErrorHandler("ItemCheck")
End Function

Private Sub cbo_Material_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  MAT_Id = mo_Tools.GetComboKey(cbo_Material)
  MAT_Name = cbo_Material.Text
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_Material_ComboItemSelected")
End Sub

Private Sub grd_File_ItemSelected()
On Error GoTo ErrHandler

Dim lo_frmDPC_File As frmDPC_File
Dim lo_File As DPC_File
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call mo_Tools.LockScreen(Me, True)
  If grd_File.SelectedCount = 1 Then
    
    Set lo_File = GetFile(Val(grd_File.SelectedLine(0, "Idx")))
    If Not lo_File Is Nothing Then
    
      Set lo_frmDPC_File = New frmDPC_File
      Load lo_frmDPC_File
      lo_frmDPC_File.FIL_Id = lo_File.FIL_Id
      lo_frmDPC_File.Mode = eDPCScreenMode.smNone
      Set lo_frmDPC_File.Tools = mo_Tools
      Set lo_frmDPC_File.ArmDb = mo_Db
      lo_frmDPC_File.Language_Code = ms_Language_Code
      Call lo_frmDPC_File.Load_A_COM
    
      Call mo_Tools.LockScreen(Me, False)
      Call mo_Tools.ShowModalForm(lo_frmDPC_File)
      Call mo_Tools.LockScreen(Me, True)
    
      Call lo_frmDPC_File.Unload_A_COM
      Unload lo_frmDPC_File
    End If
  End If
  Call mo_Tools.LockScreen(Me, False)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_File_ItemSelected")
End Sub

Private Sub tbs_OfferDetail_Click()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  fra_Detail.Visible = StrComp(tbs_OfferDetail.SelectedItem.Key, "tab_Detail", vbTextCompare) = 0
  fra_Files.Visible = StrComp(tbs_OfferDetail.SelectedItem.Key, "tab_Files", vbTextCompare) = 0
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_OfferDetail_Click")
End Sub

Private Sub DisplayFile()
On Error GoTo ErrHandler

Dim lo_File As DPC_File

  Call grd_File.ClearGrid
  For Each lo_File In Files
    If lo_File.RowStatus <> eDPCRowStatus.rsDrop Then
      Call grd_File.AddLine
      Call FileObjToGrid(lo_File, grd_File.Rows - 1)
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("DisplayFile")
End Sub

Private Sub FileObjToGrid(ByVal ao_File As DPC_File, ByVal al_Idx As Long)
On Error GoTo ErrHandler

  grd_File.Data(al_Idx, "Idx") = ao_File.Idx
  grd_File.Data(al_Idx, "PFI_Id") = ao_File.PFI_Id
  grd_File.Data(al_Idx, "FIL_Id") = ao_File.FIL_Id
  grd_File.Data(al_Idx, "FIL_Name") = ao_File.FIL_Name
  grd_File.Data(al_Idx, "FIL_FileName") = ao_File.FIL_FileName
  grd_File.Data(al_Idx, "PFI_Order") = ao_File.PFI_Order
  grd_File.Data(al_Idx, "FIL_Ext") = ao_File.FIL_Ext
  Exit Sub
ErrHandler:
  Call ErrorHandler("FileObjToGrid")
End Sub

Public Sub InitFile(ByVal ao_File As DPC_File, ByVal ae_RowStatus As eDPCRowStatus)
On Error GoTo ErrHandler
    
  Set ao_File.Tools = mo_Tools
  ao_File.RowStatus = ae_RowStatus
  ml_Idx = ml_Idx + 1
  ao_File.Idx = ml_Idx
  Call ao_File.Clear
  ao_File.PFI_Order = (Files.Count + 1) * 10
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitFile")
End Sub

Public Function GetFile(ByVal al_Idx_Id As Long) As DPC_File
On Error GoTo ErrHandler

Dim lo_DPC_File As DPC_File

  Set GetFile = Nothing
  For Each lo_DPC_File In Files
    If lo_DPC_File.Idx = al_Idx_Id Then
      Set GetFile = lo_DPC_File
      Exit Function
    End If
  Next
  Exit Function
ErrHandler:
  Call ErrorHandler("GetFile")
End Function

Public Sub FileAdd(ByVal ao_File As DPC_File)
On Error GoTo ErrHandler

Dim ll_Idx As Long

  ao_File.RowStatus = eDPCRowStatus.rsAdd
  Call Files.Add(ao_File)
  Call grd_File.AddLine
  
  ll_Idx = grd_File.Rows - 1
'  grd_File.Data(ll_Idx, "Idx") = ao_File.Idx
'  grd_File.Data(ll_Idx, "PFI_Id") = ao_File.PFI_Id
'  grd_File.Data(ll_Idx, "FIL_Id") = ao_File.FIL_Id
'  grd_File.Data(ll_Idx, "FIL_Name") = ao_File.FIL_Name
'  grd_File.Data(ll_Idx, "FIL_FileName") = ao_File.FIL_FileName
'  grd_File.Data(ll_Idx, "PFI_Order") = ao_File.PFI_Order
  Exit Sub
ErrHandler:
  Call ErrorHandler("FileAdd")
End Sub

Public Sub FileDrop(ByVal ao_File As DPC_File)
On Error GoTo ErrHandler

Dim ll_Idx As Long
Dim lo_File As DPC_File

  For ll_Idx = 1 To Files.Count
    Set lo_File = Files(ll_Idx)
    If lo_File.Idx = ao_File.Idx Then
      If lo_File.RowStatus = eDPCRowStatus.rsAdd Then
        Call Files.Remove(ll_Idx)
      Else
        lo_File.RowStatus = eDPCRowStatus.rsDrop
      End If
      Exit Sub
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("FileDrop")
End Sub

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

Dim lo_frmDPC_File As frmDPC_File
Dim lo_File As DPC_File

  mb_InternalInit = True
  Call mo_Tools.LockScreen(Me, True)
  Select Case as_Role
  Case "A"
    Set lo_frmDPC_File = New frmDPC_File
    Load lo_frmDPC_File
    Set lo_File = New DPC_File
    Call InitFile(lo_File, eDPCRowStatus.rsAdd)
    lo_frmDPC_File.Mode = eDPCScreenMode.smAdd
    Set lo_frmDPC_File.Tools = mo_Tools
    Set lo_frmDPC_File.ArmDb = mo_Db
    lo_frmDPC_File.Language_Code = ms_Language_Code
    Call lo_frmDPC_File.Load_A_COM
  
    Call mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowModalForm(lo_frmDPC_File)
    Call mo_Tools.LockScreen(Me, True)
  
    If lo_frmDPC_File.Result = True Then
      lo_File.FIL_Id = lo_frmDPC_File.FIL_Id
      lo_File.FIL_FileName = lo_frmDPC_File.txt_FileName.Text
      lo_File.FIL_Ext = lo_frmDPC_File.txt_FIL_Ext.Text
      lo_File.FIL_Name = lo_frmDPC_File.txt_FIL_Name.Text
      Call FileAdd(lo_File)
      Call DisplayFile
    End If
    
    Call lo_frmDPC_File.Unload_A_COM
    Unload lo_frmDPC_File
    
  Case "C"
    If grd_File.SelectedCount <> 1 Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9723, "#Please, select one row")
      Call mo_Tools.LockScreen(Me, False)
      mb_InternalInit = False
      Exit Sub
    End If
    If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9735, "#Are you sure to remove this record ?", , VbMsgBoxStyle.vbYesNo) = vbYes Then
      Set lo_File = GetFile(Val(grd_File.SelectedLine(0, "Idx")))
      If Not lo_File Is Nothing Then
        Call FileDrop(lo_File)
        Call DisplayFile
      End If
    End If
  End Select
  Call mo_Tools.LockScreen(Me, False)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("tlb_File_action")
End Sub

Private Sub btn_Validate_Click()
On Error GoTo ErrHandler
  
  If ItemCheck Then
    Result = True
    Hide
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_Validate_Click")
End Sub

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

Private Sub cal_DeliveryDate_datechangee()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  OFD_DelDat = cal_DeliveryDate.date_dt
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_DeliveryDate_datechangee")
End Sub

Private Sub cal_ShipDate_datechangee()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  OFD_ShpDat = cal_ShipDate.date_dt
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_ShipDate_datechangee")
End Sub

Private Sub cal_WishDate_datechangee()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  OFD_WshDat = cal_WishDate.date_dt
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_WishDate_datechangee")
End Sub

Private Sub cbo_Vendor_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  VEN_Id = mo_Tools.GetComboKey(cbo_Vendor)
  VEN_Name = cbo_Vendor.Text
  Call cbo_ShipPoint.Clear
  SHP_Id = 0
  SHP_Name = ""
  Call InitShipPointCombo(cbo_ShipPoint)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_Vendor_ComboItemSelected")
End Sub

Private Sub cbo_ShipPoint_ComboItemSelected()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  SHP_Id = mo_Tools.GetComboKey(cbo_ShipPoint)
  SHP_Name = cbo_ShipPoint.Text
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_ShipPoint_ComboItemSelected")
End Sub

Private Sub grd_Offer_Click()
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  ml_ActiveRow = -1
  fra_Comment.Visible = False
  If grd_Offer.SelectedCount = 1 Then
    mb_InternalInit = True
    txt_Description.Text = grd_Offer.SelectedLine(0, "DOF_Name")
    txt_Value.Text = grd_Offer.SelectedLine(0, "DOF_Value")
    fra_PriceQty.Visible = grd_Offer.SelectedLine(0, "DOF_IsTxt") = ""
    If grd_Offer.SelectedLine(0, "DOF_IsTxt") = "" Then
      txt_Qty.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(grd_Offer.SelectedLine(0, "Qty")))
      txt_PU.Text = grd_Offer.SelectedLine(0, "PU")
      If Not cbo_UOM.SearchItem(grd_Offer.SelectedLine(0, "UM_Code")) Then
        Call cbo_UOM.AddItem(Array(grd_Offer.SelectedLine(0, "UM_Code"), grd_Offer.SelectedLine(0, "UM_Name")), True)
      End If
      txt_Price.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(grd_Offer.SelectedLine(0, "Price")))
      txt_Cost.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(grd_Offer.SelectedLine(0, "Cost")))
      If grd_Offer.SelectedLine(0, "CURR_Code") = "" Then
        txt_CURR_CodePrice.Text = CURR_Code
        txt_CURR_CodeCost.Text = CURR_Code
        txt_CURR_Code2.Text = CURR_Code
      Else
        txt_CURR_CodePrice.Text = grd_Offer.SelectedLine(0, "CURR_Code")
        txt_CURR_CodeCost.Text = grd_Offer.SelectedLine(0, "CURR_Code")
        txt_CURR_Code2.Text = grd_Offer.SelectedLine(0, "CURR_Code")
      End If
      txt_Total.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(grd_Offer.SelectedLine(0, "Total")))
    End If
    fra_Comment.Visible = True
    ml_ActiveRow = grd_Offer.Row
    mb_InternalInit = False
    'Call txt_Value.SetFocus
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Offer_Click")
End Sub

Private Sub txt_Textbox_Change(Index As Integer)
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_CurrentTextBoxChanged = True
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_TextBox_Change")
End Sub

Private Sub txt_Textbox_Validate(Index As Integer, Cancel As Boolean)
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  If Not mb_CurrentTextBoxChanged Then Exit Sub
  
  mb_InternalInit = True
  Call mo_Tools.LockScreen(Me, True)
  Select Case txt_Textbox(Index).Tag
'  Case "OFD_Pos"
'    OFD_Pos = mo_Tools.ScreenToLong(Trim(txt_Textbox(Index).Text))
  Case "PRD_Code"
    PRD_Code = Trim(txt_Textbox(Index).Text)
  Case "OFD_PosCus"
    OFD_PosCus = Trim(txt_Textbox(Index).Text)
  Case "PRD_ModA"
    PRD_ModA = mo_Tools.ScreenToDbl(txt_Textbox(Index).Text, 0)
  Case "PRD_ModB"
    PRD_ModB = mo_Tools.ScreenToDbl(txt_Textbox(Index).Text, 0)
  Case "PRD_NWgh"
    PRD_NWgh = mo_Tools.ScreenToDbl(txt_Textbox(Index).Text)
  Case Else
    Err.Raise 0, "txt_TextBox(" & Index & ").Tag", "Unknown textbox tag:" & txt_Textbox(Index).Tag
  End Select
  mb_CurrentTextBoxChanged = False
  Call mo_Tools.LockScreen(Me, False)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Textbox_Validate " & txt_Textbox(Index).Tag & ":" & txt_Textbox(Index).Text)
End Sub

Private Sub UpdateGrid()
On Error GoTo ErrHandler

  txt_Total.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(txt_Qty.Text) * mo_Tools.ScreenToDbl(txt_Price.Text, 2))
  If ml_ActiveRow >= 0 Then
    grd_Offer.Data(ml_ActiveRow, "Qty") = mo_Tools.ScreenToDbl(txt_Qty.Text)
    grd_Offer.Data(ml_ActiveRow, "Price") = mo_Tools.ScreenToDbl(txt_Price.Text)
    grd_Offer.Data(ml_ActiveRow, "Total") = mo_Tools.ScreenToDbl(txt_Total.Text)
    grd_Offer.Data(ml_ActiveRow, "PU") = mo_Tools.ScreenToLong(txt_PU.Text)
    If grd_Offer.Data(ml_ActiveRow, "CURR_Code") = "" Then
      grd_Offer.Data(ml_ActiveRow, "CURR_Code") = txt_CURR_Code2.Text
    End If
    grd_Offer.Data(ml_ActiveRow, "UM_Code") = mo_Tools.GetComboKey(cbo_UOM)
    grd_Offer.Data(ml_ActiveRow, "UM_Name") = cbo_UOM.Text
    grd_Offer.Data(ml_ActiveRow, "Cost") = mo_Tools.ScreenToDbl(txt_Cost.Text)
    grd_Offer.Data(ml_ActiveRow, "DOF_Value") = txt_Value.Text
    If grd_Offer.Data(ml_ActiveRow, "DOF_Id") = eDPCOfferDetail.odManualPU Then
      OFD_PU = mo_Tools.ScreenToLong(txt_Value.Text)
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateGrid")
End Sub

Private Sub txt_Value_LostFocus()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call UpdateGrid
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Value_LostFocus")
End Sub

Private Sub txt_Qty_Validate(Cancel As Boolean)
On Error GoTo ErrHandler
  
Dim ll_Decimal As Long
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  ll_Decimal = mo_Tools.GetUM_Decimal(mo_Tools.GetComboKey(cbo_UOM), ms_COF_Lang)
  txt_Qty.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(txt_Qty.Text, ll_Decimal), ll_Decimal)
  Call UpdateGrid
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Qty_Validate")
End Sub

'Private Sub txt_Qty_LostFocus()
'On Error GoTo ErrHandler
'
'  If ml_ActiveRow >= 0 Then
'    grd_Offer.Data(ml_ActiveRow, "Qty") = txt_Qty.Text
'    txt_Total.Text = Round(Val(txt_Qty.Text) * Val(txt_Price.Text), 2)
'    Call UpdateGrid
'  End If
'  Exit Sub
'ErrHandler:
'  Call ErrorMessage("txt_Qty_LostFocus")
'End Sub

Private Sub txt_PU_LostFocus()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call UpdateGrid
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Qty_LostFocus")
End Sub

Private Sub cbo_UOM_ComboItemSelected()
On Error GoTo ErrHandler
  
Dim ll_Decimal As Long
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  ll_Decimal = mo_Tools.GetUM_Decimal(mo_Tools.GetComboKey(cbo_UOM), ms_COF_Lang)
  txt_Qty.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(txt_Qty.Text, ll_Decimal), ll_Decimal)
  Call UpdateGrid
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_UOM_ComboItemSelected")
End Sub

Private Sub txt_Price_LostFocus()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call UpdateGrid
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Price_LostFocus")
End Sub

Private Sub txt_Cost_LostFocus()
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call UpdateGrid
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_Cost_LostFocus")
End Sub

Private Sub Resize()
On Error GoTo ErrHandler

  Call tbs_OfferDetail.Move(0, tbs_OfferDetail.Top, Me.Width)
  Call fra_Detail.Move(0, tbs_OfferDetail.Top + tbs_OfferDetail.Height, Me.Width, btn_Validate.Top - tbs_OfferDetail.Top - tbs_OfferDetail.Height)
  Call fra_Files.Move(fra_Detail.Left, fra_Detail.Top, fra_Detail.Width, fra_Detail.Height)
  Call tlb_File.Move(fra_Files.Width - tlb_File.Width, 0, tlb_File.Width, fra_Files.Height)
  Call grd_File.Move(0, 0, fra_Files.Width - tlb_File.Width, fra_Files.Height)
  Exit Sub
ErrHandler:
  Call ErrorHandler("Resize")
End Sub

Public Function GenerateOfferDetail() As Collection
On Error GoTo ErrHandler

Dim ll_RowIdx As Long
Dim lo_Offer As DPC_OfferPos
Dim lo_Collection As New Collection
Dim ll_OFD_Order As Long
Dim ld_Qty As Double, ld_Price As Double, ld_Cost As Double, ls_UM_CodeC As String
Dim ll_SetupCounter As Long, ll_SepPos As Long

  ll_OFD_Order = 1
  For ll_RowIdx = 0 To grd_Offer.Rows - 1
    If Trim(grd_Offer.Data(ll_RowIdx, "DOF_Value")) <> "" Or (mo_Tools.ScreenToDbl(grd_Offer.Data(ll_RowIdx, "Qty")) > 0) Then
      Set lo_Offer = GetOfferPos(grd_Offer.Data(ll_RowIdx, "DOF_Id"))
      If lo_Offer Is Nothing Then
        Set lo_Offer = New DPC_OfferPos
        Set lo_Offer.Tools = mo_Tools
      End If
      ls_UM_CodeC = grd_Offer.Data(ll_RowIdx, "UM_Code")
      ld_Qty = mo_Tools.ScreenToDbl(grd_Offer.Data(ll_RowIdx, "Qty"))
      If OFD_PU = 0 Then OFD_PU = 1
      ld_Price = mo_Tools.ScreenToDbl(grd_Offer.Data(ll_RowIdx, "Price"))
      ld_Cost = mo_Tools.ScreenToDbl(grd_Offer.Data(ll_RowIdx, "Cost"))
      Call lo_Offer.Init(ld_Qty, ld_Qty, eDPCQtyType.qtUnknown, OFD_PU, ModuleSurface, PanelSurface)
      lo_Offer.PRD_Id = PRD_Id
      lo_Offer.UM_Code = ls_UM_CodeC
      lo_Offer.OFD_PU = OFD_PU
      lo_Offer.OFD_Qty = ld_Qty
      lo_Offer.OFD_QtyA = ld_Qty
      lo_Offer.OFD_Price = ld_Price
      lo_Offer.OFD_PriceA = ld_Price
      lo_Offer.OFD_Cost = ld_Cost
      lo_Offer.OFD_CostA = ld_Cost
      lo_Offer.CURR_Code = CURR_Code
      
      lo_Offer.OFD_Type = eDPCPriceBookType.eManualLine
      lo_Offer.DOF_Id = grd_Offer.Data(ll_RowIdx, "DOF_Id")
      lo_Offer.DOF_IsStp = IIf(grd_Offer.Data(ll_RowIdx, "DOF_IsStp") = "X", True, False)
      ll_SepPos = InStr(1, grd_Offer.Data(ll_RowIdx, "DOF_Name"), ":")
      If (ll_SepPos = 0) And (Trim(grd_Offer.Data(ll_RowIdx, "DOF_Name")) <> "") And (Trim(grd_Offer.Data(ll_RowIdx, "DOF_Value")) <> "") Then
        lo_Offer.PRD_Name = grd_Offer.Data(ll_RowIdx, "DOF_Name") & " : " & grd_Offer.Data(ll_RowIdx, "DOF_Value")
      Else
        lo_Offer.PRD_Name = grd_Offer.Data(ll_RowIdx, "DOF_Name") & grd_Offer.Data(ll_RowIdx, "DOF_Value")
      End If
      lo_Offer.OFD_Order = ll_OFD_Order
      lo_Offer.OFD_Valid = True
      lo_Offer.OFD_Type = eDPCPriceBookType.eManualLine
      lo_Offer.ERR_Type = eDPCErrorType.etNone
      lo_Offer.LEV_Id = eDPCLevel.lvEngineered
      lo_Offer.OFD_Order = grd_Offer.Data(ll_RowIdx, "DOF_Order")
      
      If (lo_Offer.DOF_Id = eDPCOfferDetail.odManualPosition) Then
        lo_Offer.SAE_Id = SAE_Id
        lo_Offer.SHP_Id = SHP_Id
        lo_Offer.VEN_Id = VEN_Id
        
        lo_Offer.SAE_Name = SAE_Name
        lo_Offer.SHP_Name = SHP_Name
        lo_Offer.VEN_Name = VEN_Name
        
        lo_Offer.OFD_WshDat = OFD_WshDat
        lo_Offer.OFD_DelDat = OFD_DelDat
        lo_Offer.OFD_ShpDat = OFD_ShpDat
        
        lo_Offer.PRD_Code = PRD_Code
        lo_Offer.OFD_PosCus = OFD_PosCus
        lo_Offer.OFD_IsAsItem = IIf(chk_ASFlag.Value = vbChecked, True, False)
        lo_Offer.OFD_IsFree = IIf(chk_FreeOfCharge.Value = vbChecked, True, False)
      
      End If
      
      
      Call lo_Collection.Add(lo_Offer)
      ll_OFD_Order = ll_OFD_Order + 1
    End If
  Next
  
  ll_SetupCounter = 1
  For Each lo_Offer In lo_Collection
    lo_Offer.COF_Id = COF_Id
    lo_Offer.CAT_Id = eDPCCategory.cgManualMetal
    If (lo_Offer.DOF_Id = eDPCOfferDetail.odManualPosition) Or (lo_Offer.DOF_IsStp) Then
      lo_Offer.OFD_Main = eDPCOfferDetailMain.odMain
      lo_Offer.OFD_HasQty = True
      lo_Offer.OFD_HasPrice = True
      lo_Offer.OFD_HasTotal = True
    Else
      lo_Offer.OFD_Main = eDPCOfferDetailMain.odChild
      lo_Offer.OFD_HasQty = False
      lo_Offer.OFD_HasPrice = False
      lo_Offer.OFD_HasTotal = False
    End If
    If lo_Offer.DOF_IsStp Then
      lo_Offer.OFD_Pos = OFD_Pos + ll_SetupCounter
      ll_SetupCounter = ll_SetupCounter + 1
    Else
      lo_Offer.OFD_Pos = OFD_Pos
    End If
  Next
  
  Set GenerateOfferDetail = lo_Collection
  Exit Function
ErrHandler:
  Call ErrorHandler("GenerateOfferDetail")
End Function

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_COF_Lang), , , vbTextCompare)
    as_Request = Replace(as_Request, "$iConcurrency$", mo_Tools.SqlInt(ml_iConcurrency), , , vbTextCompare)
    ReplaceCommonPlaceholders = as_Request
    Exit Function
ErrHandler:
    Call ErrorHandler("ReplaceCommonPlaceholders")
End Function

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

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


