VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFlxGrd.ocx"
Begin VB.Form BaseItemLogistic_detail 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   7725
   ClientLeft      =   1050
   ClientTop       =   1740
   ClientWidth     =   8625
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   7725
   ScaleWidth      =   8625
   ShowInTaskbar   =   0   'False
   Begin VB.TextBox txt_CartC 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   6480
      Locked          =   -1  'True
      TabIndex        =   7
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   1320
      Visible         =   0   'False
      Width           =   852
   End
   Begin VB.ListBox lst_Service 
      ForeColor       =   &H00000000&
      Height          =   1035
      ItemData        =   "BI_LOGIS.frx":0000
      Left            =   2820
      List            =   "BI_LOGIS.frx":0010
      TabIndex        =   43
      Top             =   4440
      Visible         =   0   'False
      Width           =   1452
   End
   Begin VB.TextBox txt_CartW 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   2580
      Locked          =   -1  'True
      TabIndex        =   4
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   1320
      Width           =   852
   End
   Begin VB.ComboBox cbo_Market 
      ForeColor       =   &H00000000&
      Height          =   315
      Left            =   4260
      TabIndex        =   42
      Text            =   "Combo1"
      Top             =   5640
      Visible         =   0   'False
      Width           =   1812
   End
   Begin VB.TextBox txt_Desc 
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   4140
      Locked          =   -1  'True
      TabIndex        =   40
      TabStop         =   0   'False
      Top             =   120
      Width           =   4395
   End
   Begin VB.PictureBox pic_pics 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ClipControls    =   0   'False
      ForeColor       =   &H80000008&
      Height          =   4800
      Left            =   7920
      ScaleHeight     =   4770
      ScaleWidth      =   630
      TabIndex        =   31
      Top             =   2880
      Width           =   665
      Begin VB.PictureBox pic_cancel 
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   39
         TabStop         =   0   'False
         Top             =   660
         Visible         =   0   'False
         Width           =   480
      End
      Begin VB.PictureBox pic_Calc 
         Appearance      =   0  'Flat
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   47
         TabStop         =   0   'False
         Top             =   4200
         Visible         =   0   'False
         Width           =   480
      End
      Begin VB.PictureBox pic_quit 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DragIcon        =   "BI_LOGIS.frx":0027
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   38
         TabStop         =   0   'False
         Top             =   3000
         Width           =   480
      End
      Begin VB.PictureBox pic_upd 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DragIcon        =   "BI_LOGIS.frx":0331
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   37
         TabStop         =   0   'False
         Top             =   60
         Width           =   480
      End
      Begin VB.PictureBox pic_delete 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   36
         TabStop         =   0   'False
         Top             =   660
         Width           =   480
      End
      Begin VB.PictureBox pic_print 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   35
         TabStop         =   0   'False
         Top             =   1200
         Width           =   480
      End
      Begin VB.PictureBox pic_log 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DragIcon        =   "BI_LOGIS.frx":063B
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   34
         TabStop         =   0   'False
         Top             =   1800
         Width           =   480
      End
      Begin VB.PictureBox pic_refresh 
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   33
         TabStop         =   0   'False
         Top             =   2400
         Width           =   480
      End
      Begin VB.PictureBox pic_help 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         DragIcon        =   "BI_LOGIS.frx":0945
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   32
         TabStop         =   0   'False
         Top             =   3600
         Width           =   480
      End
      Begin VB.PictureBox pic_ok 
         Appearance      =   0  'Flat
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   48
         Top             =   60
         Visible         =   0   'False
         Width           =   480
      End
   End
   Begin VB.TextBox txt_SPPiece 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   6480
      Locked          =   -1  'True
      TabIndex        =   9
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   2040
      Width           =   852
   End
   Begin VB.TextBox txt_SPPal 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   6480
      Locked          =   -1  'True
      TabIndex        =   8
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   1680
      Width           =   852
   End
   Begin VB.TextBox txt_SPCart 
      Alignment       =   1  'Right Justify
      Height          =   288
      Left            =   6480
      Locked          =   -1  'True
      TabIndex        =   10
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   1320
      Width           =   852
   End
   Begin VB.TextBox txt_PalV 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   6480
      Locked          =   -1  'True
      TabIndex        =   1
      Text            =   "0"
      Top             =   960
      Width           =   852
   End
   Begin VB.TextBox txt_CartV 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   6480
      Locked          =   -1  'True
      TabIndex        =   0
      Text            =   "0"
      Top             =   600
      Width           =   852
   End
   Begin VB.TextBox txt_PieceW 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   2580
      Locked          =   -1  'True
      TabIndex        =   6
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   2040
      Width           =   852
   End
   Begin VB.TextBox txt_PalW 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   2580
      Locked          =   -1  'True
      TabIndex        =   5
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   1680
      Width           =   852
   End
   Begin VB.TextBox txt_CPPal 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   2580
      Locked          =   -1  'True
      TabIndex        =   3
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   960
      Width           =   852
   End
   Begin VB.TextBox txt_PPCart 
      Alignment       =   1  'Right Justify
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   2580
      Locked          =   -1  'True
      TabIndex        =   2
      TabStop         =   0   'False
      Text            =   "0"
      Top             =   600
      Width           =   852
   End
   Begin VB.TextBox txt_SAP 
      ForeColor       =   &H00000000&
      Height          =   288
      Left            =   1260
      Locked          =   -1  'True
      TabIndex        =   22
      TabStop         =   0   'False
      Top             =   120
      Width           =   1512
   End
   Begin MSFlexGridLib.MSFlexGrid Grid 
      Height          =   4755
      Left            =   240
      TabIndex        =   49
      Top             =   2880
      Width           =   7455
      _ExtentX        =   13150
      _ExtentY        =   8387
      _Version        =   393216
      FixedCols       =   0
      SelectionMode   =   1
      AllowUserResizing=   1
   End
   Begin VB.Label lbl_Info 
      Caption         =   "Datas not entered yet, please enter them now."
      ForeColor       =   &H000000C0&
      Height          =   255
      Left            =   240
      TabIndex        =   46
      Top             =   2580
      Visible         =   0   'False
      Width           =   7455
   End
   Begin VB.Label lbl_CartC 
      Caption         =   "Carton content :"
      Height          =   255
      Left            =   4860
      TabIndex        =   45
      Top             =   1380
      Visible         =   0   'False
      Width           =   1575
   End
   Begin VB.Label lbl_unit9 
      Caption         =   "lm"
      Height          =   255
      Left            =   7380
      TabIndex        =   44
      Top             =   1380
      Visible         =   0   'False
      Width           =   255
   End
   Begin VB.Label lbl_Desc 
      Caption         =   "Description :"
      Height          =   255
      Left            =   2880
      TabIndex        =   41
      Top             =   180
      Width           =   1215
   End
   Begin VB.Label lbl_Unit8 
      Caption         =   "m²"
      Height          =   255
      Left            =   7380
      TabIndex        =   30
      Top             =   2100
      Width           =   255
   End
   Begin VB.Label lbl_Unit7 
      Caption         =   "m²"
      Height          =   255
      Left            =   7380
      TabIndex        =   29
      Top             =   1740
      Width           =   255
   End
   Begin VB.Label lbl_Unit6 
      Caption         =   "m²"
      Height          =   255
      Left            =   7380
      TabIndex        =   28
      Top             =   1365
      Width           =   255
   End
   Begin VB.Label lbl_Unit5 
      Caption         =   "m³"
      Height          =   255
      Left            =   7380
      TabIndex        =   27
      Top             =   1020
      Width           =   255
   End
   Begin VB.Label lbl_unit4 
      Caption         =   "m³"
      Height          =   255
      Left            =   7380
      TabIndex        =   26
      Top             =   660
      Width           =   255
   End
   Begin VB.Label lbl_Unit3 
      Caption         =   "g"
      Height          =   255
      Left            =   3540
      TabIndex        =   25
      Top             =   2100
      Width           =   255
   End
   Begin VB.Label lbl_Unit2 
      Caption         =   "Kg"
      Height          =   255
      Left            =   3540
      TabIndex        =   24
      Top             =   1740
      Width           =   255
   End
   Begin VB.Label lbl_Unit1 
      Caption         =   "Kg"
      Height          =   255
      Left            =   3540
      TabIndex        =   23
      Top             =   1380
      Width           =   255
   End
   Begin VB.Label lbl_SAP 
      Caption         =   "SAP Code :"
      Height          =   255
      Left            =   120
      TabIndex        =   21
      Top             =   180
      Width           =   1695
   End
   Begin VB.Label lbl_SPPiece 
      Caption         =   "Surface per piece :"
      Height          =   255
      Left            =   4860
      TabIndex        =   20
      Top             =   2100
      Width           =   1575
   End
   Begin VB.Label lbl_SPPal 
      Caption         =   "Surface per Palette :"
      Height          =   255
      Left            =   4860
      TabIndex        =   19
      Top             =   1740
      Width           =   1575
   End
   Begin VB.Label lbl_SPCart 
      Caption         =   "Surface per carton :"
      Height          =   255
      Left            =   4860
      TabIndex        =   18
      Top             =   1365
      Width           =   1575
   End
   Begin VB.Label lbl_PalV 
      Caption         =   "Palette volume :"
      Height          =   255
      Left            =   4860
      TabIndex        =   17
      Top             =   1020
      Width           =   1575
   End
   Begin VB.Label lbl_CartV 
      Caption         =   "Carton volume :"
      Height          =   255
      Left            =   4860
      TabIndex        =   16
      Top             =   660
      Width           =   1575
   End
   Begin VB.Label lbl_PieceW 
      Caption         =   "Piece weight :"
      Height          =   255
      Left            =   900
      TabIndex        =   15
      Top             =   2100
      Width           =   1575
   End
   Begin VB.Label lbl_PalW 
      Caption         =   "Palette weight :"
      Height          =   255
      Left            =   900
      TabIndex        =   14
      Top             =   1740
      Width           =   1575
   End
   Begin VB.Label lbl_CartW 
      Caption         =   "Carton weight :"
      Height          =   255
      Left            =   900
      TabIndex        =   13
      Top             =   1380
      Width           =   1575
   End
   Begin VB.Label lbl_CPPal 
      Caption         =   "Cartons per palette :"
      Height          =   255
      Left            =   900
      TabIndex        =   12
      Top             =   1020
      Width           =   1575
   End
   Begin VB.Label lbl_PPCart 
      Caption         =   "Pieces per carton :"
      Height          =   255
      Left            =   900
      TabIndex        =   11
      Top             =   660
      Width           =   1575
   End
End
Attribute VB_Name = "BaseItemLogistic_detail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim mb_DelVisible As Boolean
Dim mb_Perm As Boolean
Dim mb_Led As Boolean
Dim mi_Concurr As Integer

Private Function Control() As Boolean
Dim i As Integer

    Control = KO
    If cbo_Market.ListCount = 0 Then
        Control = OK
        Exit Function
    End If
    Grid.Col = 1
    For i = 1 To Grid.Rows - 1
        Grid.Row = i
        If Grid.Text = "" Then
            Exit Function
        End If
    Next i
    Control = OK

End Function

Private Sub FillTxtBoxes()
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_Text As String
Dim i As Integer

    On Error GoTo FillTxtBoxes_Err
    
    txt_SAP = gs_SAPCode
    mi_Concurr = 0
    ls_req = "EXEC Base_Item_Desc_t_sel '" _
            & QuoteParam(txt_SAP) & "','" _
            & gut_LangWork.Code & "'"
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQL_SUCCESS
        Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                txt_Desc = ODBCData(ll_Statement, 1)
            End If
        Loop
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        Exit Sub
    End If
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    txt_PPCart = "0"
    txt_CPPal = "0"
    txt_CartW = "0.000"
    txt_PalW = "0.000"
    txt_PieceW = "0"
    txt_SPCart = "0.000"
    txt_SPPal = "0.000"
    txt_SPPiece = "0.000"
    txt_CartV = "0.000"
    txt_PalV = "0.000"
    txt_CartC = "0.000"
    mb_DelVisible = KO
    ls_req = "EXEC logistic_item_t_sel '" _
            & QuoteParam(txt_SAP) _
            & "','E'"
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
       li_Status = SQL_SUCCESS
       Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
          li_Status = SQLFetch(ll_Statement)
          If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
             txt_PPCart = ODBCData(ll_Statement, 1)
             txt_CPPal = ODBCData(ll_Statement, 2)
             txt_CartW = Formatage(ODBCDataSingle(ll_Statement, 3), 3)
             txt_PalW = Formatage(ODBCDataSingle(ll_Statement, 4), 3)
             txt_PieceW = ODBCData(ll_Statement, 5)
             txt_SPCart = Formatage(ODBCDataSingle(ll_Statement, 6), 3)
             txt_SPPal = Formatage(ODBCDataSingle(ll_Statement, 7), 3)
             txt_SPPiece = Formatage(ODBCDataSingle(ll_Statement, 8), 3)
             txt_CartV = Formatage(ODBCDataSingle(ll_Statement, 9), 3)
             txt_PalV = Formatage(ODBCDataSingle(ll_Statement, 10), 3)
             txt_CartC = Formatage(ODBCDataSingle(ll_Statement, 11), 3)
             mi_Concurr = ODBCData(ll_Statement, 12)
             mb_DelVisible = OK
          End If
       Loop
    End If
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
    
FillTxtBoxes_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Sub FillGrid()
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long

    On Error GoTo FillGrid_Err
    
    Grid.Rows = 2
    Grid.Row = 1
    Grid.Col = 0
    Grid.Text = ""
    Grid.Col = 1
    Grid.Text = ""
    cbo_Market.Clear
    If gs_CGCode = "C001" Or gs_CGCode = "C006" Then
        ls_req = "EXEC Logistic_Markets_cbo '" _
            & gut_LangWork.Code & "','Serv_lvl_Ceil','" _
            & gs_SAPCode & "'"
    Else
        ls_req = "EXEC Logistic_Markets_cbo '" _
            & gut_LangWork.Code & "','Serv_lvl_Grid','" _
            & gs_SAPCode & "'"
    End If
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQL_SUCCESS
        Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                cbo_Market.AddItem ODBCData(ll_Statement, 1), cbo_Market.ListCount
                Grid.Row = Grid.Rows - 1
                Grid.Col = 0
                Grid.Text = ODBCData(ll_Statement, 2)
                Grid.Col = 1
                Grid.Text = ODBCData(ll_Statement, 3)
                Grid.Rows = Grid.Rows + 1
            End If
        Loop
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        Exit Sub
    End If
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Grid.Row = 0
    If Grid.Text <> "" And Grid.Rows > 2 Then
        Grid.RemoveItem Grid.Rows - 1
    End If
    Exit Sub
    
FillGrid_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Sub FillServices(ls_Code As String)
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_Text As String
Dim i As Integer

    On Error GoTo FillServices_Err
    
    '5/5/1999 fill lst_service from Dictionnary instead manually
    'Fill list with service level
    lst_Service.Clear
    If ls_Code = "C001" Or ls_Code = "C006" Then
        ls_req = "EXEC Dictionnary_t_lst 'Serv_lvl_Ceil','" & gut_LangWork.Code & "'"
    Else
        ls_req = "EXEC Dictionnary_t_lst 'Serv_lvl_Grid','" & gut_LangWork.Code & "'"
    End If
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQL_SUCCESS
        Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                'lst_Service.AddItem "A", 0
                lst_Service.AddItem ODBCData(ll_Statement, 1)
            End If
        Loop
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        Exit Sub
    End If
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
    
FillServices_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Function LogisticDel() As Boolean
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim i As Integer

    On Error GoTo LogisticDel_Err
    
    LogisticDel = KO
    If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbNo Then
        Exit Function
    End If
    ls_req = "EXEC Logistic_del '" _
            & Mid(QuoteParam(txt_SAP.Text), 1, 25) & "'," & mi_Concurr
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        If ll_lngrows = 0 Then
            SendMessage 2, "Another user change the record", gut_LangLogin.Code
            Exit Function
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 6, "Delete failed", gut_LangLogin.Code
        Exit Function
    End If
    FillForm
    LogisticDel = OK
    Exit Function
    
LogisticDel_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function

Private Function LogisticUpd() As Boolean
Dim ls_req As String
Dim ls_Service As String * 10
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim i As Integer, li_j As Integer

    On Error GoTo LogisticUpd_Err
    
    LogisticUpd = KO
    ls_req = "EXEC logistic_item_upd '" _
        & QuoteParam(txt_SAP) & "'," _
        & txt_PPCart & "," & txt_CPPal & "," _
        & txt_CartW & "," & txt_PalW & "," _
        & txt_PieceW & "," & txt_SPCart & "," _
        & txt_SPPal & "," & txt_SPPiece & "," _
        & txt_CartV & "," & txt_PalV & "," _
        & txt_CartC & "," & mi_Concurr
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        If ll_lngrows = 0 Then
            SendMessage 2, "Another user change the record", gut_LangLogin.Code
            Exit Function
       End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 3, "Update failed", gut_LangLogin.Code
        Exit Function
    End If
    mi_Concurr = mi_Concurr + 1
    ls_req = ""
    ls_Service = ""
    i = 1
    While i < Grid.Rows
        Grid.Row = i
        Grid.Col = 1
        'Find service level
        ls_Service = "Not sold"
        For li_j = 0 To lst_Service.ListCount - 2
            If Grid.Text = lst_Service.List(li_j) Then
                ls_Service = Grid.Text
                Exit For
            End If
        Next li_j
        ls_req = "EXEC BI_logistic_market_ins '" _
            & QuoteParam(txt_SAP) & "','" _
            & QuoteParam(cbo_Market.List(Grid.Row - 1)) & "','" _
            & QuoteParam(ls_Service) & "'"
        i = i + 1
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
            li_Status = SQLRowCount(ll_Statement, ll_lngrows)
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            If ll_lngrows = 0 Then
                SendMessage 48, "Another user change the record", gut_LangLogin.Code
                Exit Function
            End If
        Else
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            SendMessage 48, "Update failed", gut_LangLogin.Code
            Exit Function
        End If
    Wend
    FillForm
    LogisticUpd = OK
    Exit Function
    
LogisticUpd_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function

Private Sub Form_Activate()
    If Not mb_DelVisible And mb_Perm Then
        Lbl_info.Visible = OK
    Else
        Lbl_info.Visible = KO
    End If
End Sub

Private Sub Form_Load()
    MouseOff
    
    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

    pic_Calc.Picture = LoadResPicture(RES_CALC, 1)
    pic_cancel.Picture = LoadResPicture(RES_CANCEL, 1)
    pic_delete.Picture = LoadResPicture(RES_DELETE, 1)
    pic_help.Picture = LoadResPicture(RES_HELP, 1)
    pic_log.Picture = LoadResPicture(RES_LOG, 1)
    pic_ok.Picture = LoadResPicture(RES_OK, 1)
    pic_Print.Picture = LoadResPicture(RES_PRINT, 1)
    pic_quit.Picture = LoadResPicture(RES_QUIT, 1)
    pic_refresh.Picture = LoadResPicture(RES_REFRESH, 1)
    pic_upd.Picture = LoadResPicture(RES_MODIFY, 1)
    Top = 1580 + frmMain.Top
    Left = 3280 + frmMain.Left
    Width = 8650
    Height = 7750
    Grid.ColWidth(0) = 0.795 * Grid.Width    '0.8
    Grid.ColWidth(1) = 0.192 * Grid.Width
    Grid.ColAlignment(0) = flexAlignLeftCenter
    Grid.ColAlignment(1) = flexAlignLeftCenter
    
    FillCsts
    FillForm
    Permission
    MouseOn
End Sub

Private Sub FillCsts()
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Field As String
Dim ls_Text As String
   
    On Error GoTo FillCsts_Err
    
    ls_req = "EXEC Screen_Csts 'main_log_item','" & gut_LangLogin.Code & "'"
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQL_SUCCESS
    Else
        li_Status = SQL_ERROR
    End If
    Grid.Row = 0
    Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ls_Field = ODBCData(ll_Statement, 1)
            ls_Text = ODBCData(ll_Statement, 2)
            Select Case ls_Field
            Case "sap": lbl_SAP = ls_Text
            Case "desc": lbl_Desc = ls_Text
            Case "ppcart": lbl_PPCart = ls_Text
            Case "cppal": lbl_CPPal = ls_Text
            Case "cartw": lbl_CartW = ls_Text
            Case "palw": lbl_PalW = ls_Text
            Case "piecew": lbl_PieceW = ls_Text
            Case "cartv": lbl_CartV = ls_Text
            Case "palv": lbl_PalV = ls_Text
            Case "spcart": lbl_SPCart = ls_Text
            Case "sppal": lbl_SPPal = ls_Text
            Case "sppiece": lbl_SPPiece = ls_Text
            Case "cartc": lbl_CartC = ls_Text
            Case "info": Lbl_info = ls_Text
            Case "col0": Grid.Col = 0
                Grid.Text = ls_Text
            Case "col1": Grid.Col = 1
                Grid.Text = ls_Text
            End Select
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    If gs_CGCode <> "C001" And gs_CGCode <> "C006" Then
        lbl_PieceW.Visible = KO
        lbl_SPPiece.Visible = KO
        lbl_SPCart.Visible = KO
        lbl_SPPal.Visible = KO
        lbl_CartC.Visible = OK
        txt_PieceW.Visible = KO
        txt_SPPiece.Visible = KO
        txt_SPCart.Visible = KO
        txt_SPPal.Visible = KO
        txt_CartC.Visible = OK
        lbl_Unit3.Visible = KO
        lbl_Unit6.Visible = KO
        lbl_Unit7.Visible = KO
        lbl_Unit8.Visible = KO
        lbl_unit9.Visible = OK
    End If
    Exit Sub
    
FillCsts_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Sub Permission()
Dim ls_Perm As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_req As String

    On Error GoTo Permission_Err
    
    Select Case gs_BIType
    Case "STD": ls_req = "EXEC Check_Security logistic_item_std " & ", " & prg.LoginName
    Case "SPC": ls_req = "EXEC Check_Security logistic_item_spc " & ", " & prg.LoginName
    Case "SSTD": ls_req = "EXEC Check_Security logistic_item_sstd " & ", " & prg.LoginName
    End Select
    pic_delete.Visible = KO
    pic_upd.Visible = KO
    mb_Perm = KO
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQL_SUCCESS
    Else
        li_Status = SQL_ERROR
    End If
    Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ls_Perm = ODBCData(ll_Statement, 1)
            If ls_Perm = "Delete" Then
                mb_Perm = OK
                pic_delete.Visible = mb_DelVisible
            End If
            If ls_Perm = "Update" Then
                pic_upd.Visible = OK
            End If
        End If
    Loop
    DoEvents
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
    
Permission_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Sub Grid_DblClick()
    If mb_Led Then
       lst_Service.Visible = OK
    End If
End Sub

Private Sub Grid_LostFocus()
    lst_Service.Visible = 0
End Sub

Private Sub Grid_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    lst_Service.Visible = 0
End Sub

Private Sub lst_Service_Click()
    Grid.Col = 1
    Grid.Text = lst_Service.List(lst_Service.ListIndex)
    lst_Service.Visible = KO
End Sub

Private Sub pic_cancel_Click()
    MouseOff
    pic_delete.Visible = mb_DelVisible
    If pic_delete.Visible = KO And mb_Perm = OK Then
        Lbl_info.Visible = OK
    Else
        Lbl_info.Visible = KO
    End If
    pic_upd.Visible = OK
    pic_Print.Visible = OK
    pic_log.Visible = OK
    pic_refresh.Visible = OK
    pic_quit.Visible = OK
    pic_help.Visible = OK
    pic_ok.Visible = KO
    pic_cancel.Visible = KO
    mb_Led = KO
    txt_CartV.Locked = OK
    txt_PalV.Locked = OK
    txt_PPCart.Enabled = OK
    txt_CPPal.Enabled = OK
    txt_CartW.Enabled = OK
    txt_PalW.Enabled = OK
    txt_PieceW.Enabled = OK
    txt_CartC.Enabled = OK
    txt_SPCart.Enabled = OK
    txt_SPPiece.Enabled = OK
    txt_SPPal.Enabled = OK
    FillTxtBoxes
    FillGrid
    gs_Action = ""
    MouseOn
End Sub
Private Sub pic_delete_Click()
    MouseOff
    gs_Action = "delete"
    pic_delete.Visible = KO
    pic_upd.Visible = KO
    pic_Print.Visible = KO
    pic_log.Visible = KO
    pic_refresh.Visible = KO
    pic_quit.Visible = KO
    pic_help.Visible = KO
    pic_ok.Visible = OK
    pic_cancel.Visible = OK
    MouseOn
End Sub

Private Sub pic_help_Click()
    MouseOff
    gs_TableName = "BI_Logistic"
    MouseOn
    frm_help.show 1
End Sub

Private Sub pic_ok_Click()
Dim lb_Validate As Boolean

    MouseOff
    lb_Validate = KO
    Select Case gs_Action
    Case "delete"
        mb_Led = KO
        If Not LogisticDel Then
            FillForm
        End If
        Lbl_info.Visible = OK
        pic_delete.Visible = mb_DelVisible
        pic_upd.Visible = OK
        pic_Print.Visible = OK
        pic_log.Visible = OK
        pic_refresh.Visible = OK
        pic_quit.Visible = OK
        pic_help.Visible = OK
        pic_ok.Visible = KO
        pic_cancel.Visible = KO
        lb_Validate = OK
    Case "upd"
        If Control Then
            LogisticUpd
            mb_DelVisible = OK
            pic_delete.Visible = mb_DelVisible
            pic_upd.Visible = OK
            pic_Print.Visible = OK
            pic_log.Visible = OK
            pic_refresh.Visible = OK
            pic_quit.Visible = OK
            pic_help.Visible = OK
            pic_ok.Visible = KO
            pic_cancel.Visible = KO
            If pic_delete.Visible = KO And mb_Perm = OK Then
                Lbl_info.Visible = OK
            Else
                Lbl_info.Visible = KO
            End If
            txt_CartV.Locked = OK
            txt_PalV.Locked = OK
            txt_PPCart.Enabled = OK
            txt_CPPal.Enabled = OK
            txt_CartW.Enabled = OK
            txt_PalW.Enabled = OK
            txt_PieceW.Enabled = OK
            txt_CartC.Enabled = OK
            txt_SPCart.Enabled = OK
            txt_SPPiece.Enabled = OK
            txt_SPPal.Enabled = OK
            lb_Validate = OK
            mb_Led = KO
        Else
            SendMessage 73, "You must fill every fields", gut_LangLogin.Code
            MouseOn
            Exit Sub
        End If
    End Select
    If lb_Validate Then
        gs_Action = ""
    End If
    MouseOn
End Sub

Private Sub pic_print_Click()
    
    If Printers.Count = 0 Then
        SendMessage 135, "No printer is installed on your computer. Please, contact your system administrator.", gut_LangLogin.Code
        Exit Sub
    End If
    
    MouseOff
    InitPrinter 1
    
    'title
    Printer.Font.Italic = 0
    SetBold -1
    SetFontSize 12
    Printer.Print Date;
    Printer.Print " - ";
    Printer.Print Time
    SetFontSize 36
    Printer.Print "Armstrong Ceiling Solutions"
    SetFontSize 24
    Printer.Print BaseItem_main.Caption & " - " & BaseItem_main.cmd_Logistic.Caption
    SetFontSize 12
    Printer.Print Tab(100 - 5);
    Printer.Print Printer.Page
    Printer.Print ""
    SetFontSize 18
    Printer.Print ""
    SetFontSize 12
    Printer.Print ""
            
    'fields
    If gs_CGCode <> "C001" And gs_CGCode <> "C006" Then
        PrintField lbl_SAP, txt_SAP
        PrintField lbl_Desc, txt_Desc
        PrintField lbl_PPCart, txt_PPCart
        PrintField lbl_CPPal, txt_CPPal
        PrintField lbl_CartW, txt_CartW
        PrintField lbl_PalW, txt_PalW
        PrintField lbl_CartV, txt_CartV
        PrintField lbl_PalV, txt_PalV
        PrintField lbl_CartC, txt_CartC
        
    Else
        PrintField lbl_SAP, txt_SAP
        PrintField lbl_Desc, txt_Desc
        PrintField lbl_PPCart, txt_PPCart
        PrintField lbl_CPPal, txt_CPPal
        PrintField lbl_CartW, txt_CartW
        PrintField lbl_PalW, txt_PalW
        PrintField lbl_PieceW, txt_PieceW
        PrintField lbl_CartV, txt_CartV
        PrintField lbl_PalV, txt_PalV
        PrintField lbl_SPCart, txt_SPCart
        PrintField lbl_SPPal, txt_SPPal
        PrintField lbl_SPPiece, txt_SPPiece
    
    
    End If
    Printer.EndDoc
    
    ExPrintGrid 1, 10, "Armstrong Ceiling Solutions", BaseItem_main.Caption & " - " & BaseItem_main.cmd_Logistic.Caption, Grid, Array(75, 25)
    Printer.EndDoc
    MouseOn
End Sub

Private Sub pic_quit_Click()
    MouseOff
    Unload Me
    MouseOn
End Sub

Private Sub pic_refresh_Click()
    MouseOff
    FillForm
    MouseOn
End Sub

Private Sub pic_upd_Click()
    MouseOff
    gs_Action = "upd"
    pic_delete.Visible = KO
    pic_upd.Visible = KO
    pic_Print.Visible = KO
    pic_log.Visible = KO
    pic_refresh.Visible = KO
    pic_quit.Visible = KO
    pic_help.Visible = KO
    pic_ok.Visible = OK
    pic_cancel.Visible = OK
    mb_Led = OK
    txt_CartV.Locked = KO
    txt_PalV.Locked = KO
    txt_PPCart.Enabled = KO
    txt_CPPal.Enabled = KO
    txt_CartW.Enabled = KO
    txt_PalW.Enabled = KO
    txt_PieceW.Enabled = KO
    txt_CartC.Enabled = KO
    txt_SPCart.Enabled = KO
    txt_SPPiece.Enabled = KO
    txt_SPPal.Enabled = KO
    txt_CartV.SetFocus
    MouseOn
End Sub

Private Sub txt_CartV_GotFocus()
    txt_CartV.SelStart = 0
    txt_CartV.SelLength = Len(txt_CartV)
End Sub

Private Sub txt_CartV_LostFocus()
    MouseOff
    If gs_Action = "upd" Then
        If Not ChkNumeric(Formatage(txt_CartV, 3), 3) Then
            txt_CartV.SetFocus
            MouseOn
            Exit Sub
        Else
            txt_CartV = Formatage(txt_CartV, 3)
        End If
    End If
    MouseOn
End Sub

Private Sub txt_PalV_GotFocus()
    txt_PalV.SelStart = 0
    txt_PalV.SelLength = Len(txt_PalV)
End Sub

Private Sub txt_PalV_LostFocus()
    MouseOff
    If gs_Action = "upd" Then
        If Not ChkNumeric(Formatage(txt_PalV, 3), 3) Then
            txt_PalV.SetFocus
            MouseOn
            Exit Sub
        Else
            txt_PalV = Formatage(txt_PalV, 3)
        End If
    End If
    MouseOn
End Sub

Private Sub FillForm()
    FillServices (gs_CGCode)
    FillTxtBoxes
    FillGrid
End Sub
