VERSION 5.00
Begin VB.Form FillEmpty_Mtnc 
   ClientHeight    =   6540
   ClientLeft      =   195
   ClientTop       =   465
   ClientWidth     =   9135
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   6540
   ScaleWidth      =   9135
   ShowInTaskbar   =   0   'False
   Begin VB.Frame frm_button 
      Height          =   972
      Left            =   0
      TabIndex        =   18
      Top             =   5520
      Width           =   9132
      Begin VB.CommandButton spp_media 
         Height          =   612
         Left            =   6660
         Style           =   1  'Graphical
         TabIndex        =   21
         Top             =   300
         Visible         =   0   'False
         Width           =   612
      End
      Begin VB.CommandButton SSC_dropped 
         Height          =   276
         Left            =   3060
         Style           =   1  'Graphical
         TabIndex        =   24
         Top             =   480
         Width           =   252
      End
      Begin VB.CommandButton spp_save 
         Height          =   612
         Left            =   7620
         Style           =   1  'Graphical
         TabIndex        =   25
         Top             =   300
         Width           =   612
      End
      Begin VB.CommandButton ssp_quit 
         Height          =   612
         Left            =   8280
         Style           =   1  'Graphical
         TabIndex        =   26
         Top             =   300
         Width           =   612
      End
      Begin VB.CheckBox chk_Int 
         Caption         =   "Check1"
         Height          =   252
         Left            =   1800
         TabIndex        =   20
         Top             =   120
         Width           =   252
      End
      Begin VB.TextBox txt_dropped 
         ForeColor       =   &H00FF0000&
         Height          =   288
         Left            =   1800
         Locked          =   -1  'True
         TabIndex        =   19
         Top             =   480
         Width           =   1212
      End
      Begin VB.Label lbl_Drop 
         Caption         =   "Drop date"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   252
         Left            =   240
         TabIndex        =   23
         Top             =   480
         Width           =   1452
      End
      Begin VB.Label lbl_Int 
         Caption         =   "Internet flag"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   252
         Left            =   240
         TabIndex        =   22
         Top             =   120
         Width           =   1452
      End
   End
   Begin VB.Frame frm_Main 
      Height          =   3492
      Left            =   0
      TabIndex        =   8
      Top             =   1980
      Width           =   9132
      Begin VB.ListBox lst_ToInsert 
         Height          =   645
         Left            =   3780
         Sorted          =   -1  'True
         TabIndex        =   12
         Top             =   480
         Visible         =   0   'False
         Width           =   1530
      End
      Begin VB.ListBox lst_ToDelete 
         Height          =   645
         Left            =   3840
         Sorted          =   -1  'True
         TabIndex        =   11
         Top             =   2820
         Visible         =   0   'False
         Width           =   1530
      End
      Begin VB.PictureBox pic_In 
         AutoSize        =   -1  'True
         Height          =   408
         Left            =   4320
         ScaleHeight     =   345
         ScaleWidth      =   345
         TabIndex        =   10
         TabStop         =   0   'False
         Top             =   1620
         Width           =   408
      End
      Begin VB.PictureBox pic_Out 
         AutoSize        =   -1  'True
         Height          =   408
         Left            =   4320
         ScaleHeight     =   345
         ScaleWidth      =   345
         TabIndex        =   9
         TabStop         =   0   'False
         Top             =   2340
         Width           =   408
      End
      Begin VB.ListBox lst_Selected 
         Appearance      =   0  'Flat
         Height          =   2565
         ItemData        =   "FILLEMPT.frx":0000
         Left            =   4920
         List            =   "FILLEMPT.frx":0007
         TabIndex        =   30
         Top             =   720
         Width           =   4095
      End
      Begin VB.ListBox lst_NotSelected 
         Appearance      =   0  'Flat
         Height          =   2565
         ItemData        =   "FILLEMPT.frx":0019
         Left            =   180
         List            =   "FILLEMPT.frx":0020
         TabIndex        =   31
         Top             =   720
         Width           =   4095
      End
      Begin VB.Label lbl_NotSelected 
         Alignment       =   2  'Center
         Caption         =   "Not selected"
         Height          =   252
         Left            =   660
         TabIndex        =   15
         Top             =   360
         Width           =   3012
      End
      Begin VB.Label lbl_Recommended 
         Alignment       =   2  'Center
         Height          =   252
         Left            =   1260
         TabIndex        =   13
         Top             =   120
         Width           =   6672
      End
      Begin VB.Label lbl_Selected 
         Alignment       =   2  'Center
         Caption         =   "Selected"
         Height          =   252
         Left            =   5520
         TabIndex        =   14
         Top             =   360
         Width           =   3012
      End
   End
   Begin VB.Frame frm_Description 
      Height          =   972
      Left            =   0
      TabIndex        =   16
      Top             =   0
      Width           =   9132
      Begin VB.TextBox txt_Desc 
         Height          =   288
         Left            =   2880
         MaxLength       =   79
         TabIndex        =   0
         Top             =   540
         Width           =   3312
      End
      Begin VB.Label lbl_Mks 
         Alignment       =   2  'Center
         Caption         =   "Description"
         Height          =   252
         Left            =   2880
         TabIndex        =   17
         Top             =   240
         Width           =   3312
      End
   End
   Begin VB.Frame frm_Combo 
      ForeColor       =   &H00000000&
      Height          =   972
      Left            =   0
      TabIndex        =   3
      Top             =   960
      Width           =   9132
      Begin VB.ComboBox cbo_Code3 
         Height          =   315
         Left            =   7080
         TabIndex        =   29
         Text            =   "cbo_Code3"
         Top             =   240
         Visible         =   0   'False
         Width           =   615
      End
      Begin VB.ComboBox cbo_Description3 
         Height          =   315
         Left            =   6240
         Style           =   2  'Dropdown List
         TabIndex        =   28
         Top             =   240
         Visible         =   0   'False
         Width           =   2775
      End
      Begin VB.ComboBox cbo_Description2 
         Height          =   315
         Left            =   1920
         Style           =   2  'Dropdown List
         TabIndex        =   2
         Top             =   600
         Width           =   2772
      End
      Begin VB.ComboBox cbo_Description1 
         Height          =   315
         Left            =   1920
         Style           =   2  'Dropdown List
         TabIndex        =   1
         Top             =   240
         Width           =   2772
      End
      Begin VB.ComboBox cbo_Code1 
         Height          =   288
         Left            =   2880
         Style           =   2  'Dropdown List
         TabIndex        =   5
         Top             =   240
         Visible         =   0   'False
         Width           =   492
      End
      Begin VB.ComboBox cbo_Code2 
         Height          =   288
         Left            =   2640
         Style           =   2  'Dropdown List
         TabIndex        =   4
         Top             =   600
         Visible         =   0   'False
         Width           =   492
      End
      Begin VB.Label lbl_combo3 
         Caption         =   "C. tee end details"
         Height          =   255
         Left            =   4800
         TabIndex        =   27
         Top             =   240
         Visible         =   0   'False
         Width           =   1455
      End
      Begin VB.Label lbl_combo1 
         Caption         =   "Category"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   1815
      End
      Begin VB.Label lbl_Combo2 
         Caption         =   "Type"
         Height          =   255
         Left            =   120
         TabIndex        =   6
         Top             =   600
         Width           =   1815
      End
   End
End
Attribute VB_Name = "FillEmpty_Mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'P621 begin
' external references and constants
Private Declare Function SendMessageAPI Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Const SM_CYHSCROLL = 3
Private Const SM_CXVSCROLL = 2
Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H115
Private Const SB_BOTTOM = 7
Private Const LB_SETHORIZONTALEXTENT = &H194

Dim ms_Code As String
' for the combo description1 &2
Dim mb_Description1 As Boolean
Dim mb_Description2 As Boolean
Dim mb_Description3 As Boolean
Dim ms_Code2 As String
Dim ms_CodeRecord As String

Dim ms_OldMediaCode As String
Dim mi_OldMediaIc As Integer

Private Function AddLink() 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
Dim li_Lenght As Integer
Dim li_pos As Integer
Dim ls_HBMdesc As String
Dim ls_CGdesc As String
Dim ls_CCdesc As String
Dim ls_CLdesc As String
Dim ls_VATdesc As String
Dim ls_RestList As String

AddLink = KO

On Error GoTo suite

For i = 0 To lst_ToInsert.ListCount - 1
    If gut_Param.Str11 = "Integer" Then
        Select Case gs_TableName
        Case "Criteria_Choice"
            li_Lenght = Len(lst_ToInsert.List(i))
            li_pos = InStr(1, lst_ToInsert.List(i), "/")
            ls_req = gut_Param.Str2 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(Mid(lst_ToInsert.List(i), li_pos + 1, li_Lenght - li_pos)) & "', '" _
                & QuoteParam(Mid(lst_ToInsert.List(i), 1, li_pos - 1)) & "'"
        Case "Criteria_List"
            ls_RestList = lst_ToInsert.List(i)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CGdesc = Mid(lst_ToInsert.List(i), 1, li_pos - 1)
            ls_RestList = Mid(lst_ToInsert.List(i), li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_CCdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            ls_req = gut_Param.Str2 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(ls_HBMdesc) & "', '" _
                & QuoteParam(ls_CGdesc) & "', '" _
                & QuoteParam(ls_CCdesc) & "', " _
                & cbo_Code1.List(cbo_Description1.ListIndex) & ", " _
                & cbo_Code2.List(cbo_Description2.ListIndex) & ""
        Case "Value_Type"
            ls_RestList = lst_ToInsert.List(i)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CGdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CCdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_CLdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            ls_req = gut_Param.Str2 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(ls_HBMdesc) & "', '" _
                & QuoteParam(ls_CGdesc) & "', '" _
                & QuoteParam(ls_CCdesc) & "', '" _
                & QuoteParam(ls_CLdesc) & "', " _
                & cbo_Code1.List(cbo_Description1.ListIndex) & ", " _
                & cbo_Code2.List(cbo_Description2.ListIndex) & ""
        Case "Surfaces", "Products_Edges", "Products_Groups", "Products_Patterns"
            ls_RestList = lst_ToInsert.List(i)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CGdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CCdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CLdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_VATdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            ls_req = gut_Param.Str2 & " 0, " _
                & right(ms_Code, 3) & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(ls_HBMdesc) & "', '" _
                & QuoteParam(ls_CGdesc) & "', '" _
                & QuoteParam(ls_CCdesc) & "', '" _
                & QuoteParam(ls_CLdesc) & "', '" _
                & QuoteParam(ls_VATdesc) & "'"
        Case Else
            ls_req = gut_Param.Str2 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(lst_ToInsert.List(i)) & "'"
        End Select
    Else
        ls_req = gut_Param.Str2 & " '" _
         & ms_Code & "', '" _
         & gut_LangWork.Code & "', '" _
         & QuoteParam(lst_ToInsert.List(i)) & "'"
    End If
    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
            Exit Function
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        Exit Function
    End If
Next i
AddLink = OK
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function
Private Function DeleteLink() 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
Dim li_Lenght As Integer
Dim li_pos As Integer
Dim ls_HBMdesc As String
Dim ls_CGdesc As String
Dim ls_CCdesc As String
Dim ls_CLdesc As String
Dim ls_VATdesc As String
Dim ls_RestList As String

On Error GoTo suite

DeleteLink = KO
For i = 0 To lst_ToDelete.ListCount - 1
    If gut_Param.Str11 = "Integer" Then
        Select Case gs_TableName
        Case "Criteria_Choice"
            li_Lenght = Len(lst_ToDelete.List(i))
            li_pos = InStr(1, lst_ToDelete.List(i), "/")
            ls_req = gut_Param.Str3 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(Mid(lst_ToDelete.List(i), li_pos + 1, li_Lenght - li_pos)) & "', '" _
                & QuoteParam(Mid(lst_ToDelete.List(i), 1, li_pos - 1)) & "'"
        Case "Criteria_List"
            ls_RestList = lst_ToDelete.List(i)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CGdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_CCdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            ls_req = gut_Param.Str3 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(ls_HBMdesc) & "', '" _
                & QuoteParam(ls_CGdesc) & "', '" _
                & QuoteParam(ls_CCdesc) & "', " _
                & cbo_Code1.List(cbo_Description1.ListIndex) & ", " _
                & cbo_Code2.List(cbo_Description2.ListIndex) & ""
        Case "Surfaces", "Products_Edges", "Products_Groups", "Products_Patterns"
            ls_RestList = lst_ToDelete.List(i)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CGdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CCdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CLdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_VATdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            ls_req = gut_Param.Str3 & " 0, " _
                & right(ms_Code, 3) & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(ls_HBMdesc) & "', '" _
                & QuoteParam(ls_CGdesc) & "', '" _
                & QuoteParam(ls_CCdesc) & "', '" _
                & QuoteParam(ls_CLdesc) & "', '" _
                & QuoteParam(ls_VATdesc) & "'"
        Case "Value_Type"
            ls_RestList = lst_ToDelete.List(i)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CGdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            li_Lenght = Len(ls_RestList)
            li_pos = InStr(1, ls_RestList, "/")
            ls_CCdesc = Mid(ls_RestList, 1, li_pos - 1)
            ls_CLdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
            ls_req = gut_Param.Str3 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(ls_HBMdesc) & "', '" _
                & QuoteParam(ls_CGdesc) & "', '" _
                & QuoteParam(ls_CCdesc) & "', '" _
                & QuoteParam(ls_CLdesc) & "', " _
                & cbo_Code1.List(cbo_Description1.ListIndex) & ", " _
                & cbo_Code2.List(cbo_Description2.ListIndex) & ""
        Case Else
            ls_req = gut_Param.Str3 & " " _
                & ms_Code & ", '" _
                & gut_LangWork.Code & "', '" _
                & QuoteParam(lst_ToDelete.List(i)) & "'"
        End Select
    Else
        ls_req = gut_Param.Str3 & " '" _
            & ms_Code & "', '" _
            & gut_LangWork.Code & "', '" _
            & QuoteParam(lst_ToDelete.List(i)) & "'"
    End If
    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
            Exit Function
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        Exit Function
    End If
Next i
DeleteLink = OK
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function
Private Function DeleteRow() As Boolean

Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long

On Error GoTo suite

DeleteRow = KO
Select Case gs_TableName
Case "Test_House_Acred"
    ls_req = "Exec Test_House_Acred_del " & gs_TableCode & ", " _
        & gs_TableCode2 & ", " & gs_TableCode3
Case Else
    If gut_Param.Str11 = "Integer" Then
        ls_req = gut_Param.Str4 & " " _
            & ms_Code & ", " _
            & gut_Param.Str6
    Else
        ls_req = gut_Param.Str4 & " '" _
            & ms_Code & "'," _
            & gut_Param.Str6
    End If
End Select

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
         DeleteRow = OK
    End If
Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function
Private Function Control() As Boolean

Control = KO
' controle de la description (par defaut obligatoire)
If gs_TableName <> "Grid" And gs_TableName <> "Grid_Value" And gs_TableName <> "Country_Link" Then
    If txt_Desc = "" Then
        txt_Desc.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Exit Function
    End If
    If InStr(1, txt_Desc, "\", 1) <> 0 Then
        txt_Desc.SetFocus
        SendMessage 79, "You can't use this character in this field", gut_LangLogin.Code
        Exit Function
    End If
End If
'controle du vidoir devidoir (par defaut un element doit etre dans la partie droite)
'THOA
If gs_TableName <> "Test_House_Acred" Then
    If lst_Selected.ListCount = 0 And gs_TableName <> "Grid_Value" And gs_TableName <> "Surfaces" And gs_TableName <> "Products_Edges" And gs_TableName <> "Products_Patterns" And gs_TableName <> "Value_Type" Then
        lst_Selected.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Exit Function
    End If
End If
'ETHOA
' controle des combos (par defaut pas de combo)
Select Case gs_TableName
Case "Criteria_List"
    ' les 2 combos doivent renseignées
    If cbo_Description1.ListIndex = -1 Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description1.SetFocus
            Exit Function
    End If
    If cbo_Description2.ListIndex = -1 Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description2.SetFocus
            Exit Function
    End If

Case "Super_Base_Material", "Country_Link"
    ' la 1ere combo doit etre renseignée
   If cbo_Description1 = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description1.SetFocus
            Exit Function
    End If
'THOA
Case "Test_House_Acred"
    ' les 2 combos doivent renseignées
    If cbo_Description1 = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description1.SetFocus
            Exit Function
    End If
    If cbo_Description2 = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description2.SetFocus
            Exit Function
    End If
'Products_Groups
Case "Products_Groups"
    If cbo_Description1 = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description1.SetFocus
            Exit Function
    End If
    If cbo_Description2 = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description2.SetFocus
            Exit Function
    End If
    If cbo_Description3 = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Description3.SetFocus
            Exit Function
    End If
End Select
Control = OK

End Function

Private Sub cbo_Description1_Click()

If cbo_Description1.Visible Then
    MouseOff
    Select Case gs_TableName
    Case "Criteria_List"
        ' in this case the combo number 2 is linked with the combo1
        If cbo_Description1.ListIndex <> -1 Then
           mb_Description2 = KO
           cbo_Description2.Enabled = OK
           cbo_Description2.Clear
           cbo_Code2.Clear
        Else
           cbo_Description2.Enabled = KO
        End If
    Case "Value_Type"
        ' in this case the combo number 2 and the lists are linked with the combo1
        If cbo_Description1.ListIndex <> -1 Then
           mb_Description2 = KO
           cbo_Description2.Enabled = OK
           cbo_Description2.Clear
           cbo_Code2.Clear
           lst_NotSelected.Clear
           lst_Selected.Clear
        Else
           cbo_Description2.Enabled = KO
        End If
    End Select
    MouseOn
End If

End Sub

Private Sub cbo_Description1_DropDown()

Dim ls_Svg As String
Dim li_Count As Integer

MouseOff
If mb_Description1 = KO Then
    If cbo_Description1.ListIndex = -1 Then
        ls_Svg = ""
    Else
        ls_Svg = cbo_Code1.List(cbo_Description1.ListIndex)
    End If
    cbo_Description1.Clear
    cbo_Code1.Clear
    ' requete to fill the combo
    Select Case gs_TableName
    Case "Criteria_List", "Value_Type"
        FillCbo "Test_Category2", cbo_Code1, cbo_Description1
    Case "Super_Base_Material"
        FillCbo "EXEC Hyper_Base_Material_cbo '" & gs_CGCode & "','" & gut_LangWork.Code & "'", cbo_Code1, cbo_Description1
    Case "Grid"
        FillCbo "EXEC Products_Families_cbo 'C002','" & gut_LangWork.Code & "'", cbo_Code1, cbo_Description1
    Case "Country_Link"
        FillCbo "EXEC Countries_Int_cbo '" & gut_LangWork.Code & "'", cbo_Code1, cbo_Description1
    Case "Test_House_Acred"
        FillCbo "Test_House", cbo_Code1, cbo_Description1
    Case "Products_Groups"
        FillCbo "DGrid_MainRunner", cbo_Code1, cbo_Description1
    End Select
    cbo_Description1.ListIndex = ComboFindItem(cbo_Code1, ls_Svg)
    mb_Description1 = OK
End If
MouseOn

End Sub
Private Sub cbo_Description2_Click()

Dim ls_req As String

If cbo_Description2.Visible Then
    MouseOff
    Select Case gs_TableName
    Case "Value_Type"
        ' in this case the lists are linked with the combo 2
        lst_NotSelected.Clear
        lst_Selected.Clear
        If cbo_Description2.ListIndex <> -1 Then
            ' ok we show the new list
            ls_req = gut_Param.Str8 & " 0," & cbo_Code1.List(cbo_Description1.ListIndex) & " ," & cbo_Code2.List(cbo_Description2.ListIndex) & ",'" & gut_LangWork.Code & "'"
            FillLstSingle ls_req, lst_NotSelected
        End If
    End Select
    MouseOn
End If

End Sub
Private Sub cbo_Description2_DropDown()

Dim ls_Svg As String
Dim li_Count As Integer

MouseOff
If mb_Description2 = KO Then
    If cbo_Description2.ListIndex = -1 Then
        ls_Svg = ""
    Else
        ls_Svg = cbo_Code2.List(cbo_Description2.ListIndex)
    End If
    cbo_Description2.Clear
    cbo_Code2.Clear
    ' requete to fill the combo
    Select Case gs_TableName
    Case "Criteria_List", "Value_Type"
        FillCbo "EXEC Test_Type_cbo " & cbo_Code1.List(cbo_Description1.ListIndex) & ", '" & gut_LangWork.Code & "'", cbo_Code2, cbo_Description2
    Case "Grid"
        FillCbo "EXEC Products_Edges_cbo 'C002', '" & gut_LangWork.Code & "'", cbo_Code2, cbo_Description2
    Case "Test_House_Acred"
        FillCbo "Test_Category3", cbo_Code2, cbo_Description2
    Case "Products_Groups"
        FillCbo "DGrid_Interface", cbo_Code2, cbo_Description2
    End Select
    cbo_Description2.ListIndex = ComboFindItem(cbo_Code2, ls_Svg)
    mb_Description2 = OK
End If
MouseOn

End Sub



Private Sub cbo_Description3_DropDown()
Dim ls_Svg As String
Dim li_Count As Integer

MouseOff
If mb_Description3 = KO Then
    If cbo_Description3.ListIndex = -1 Then
        ls_Svg = ""
    Else
        ls_Svg = cbo_Code3.List(cbo_Description3.ListIndex)
    End If
    cbo_Description3.Clear
    cbo_Code3.Clear
    ' requete to fill the combo
    Select Case gs_TableName
    Case "Products_Groups"
        FillCbo "DGrid_CrossTee", cbo_Code3, cbo_Description3
    End Select
    cbo_Description3.ListIndex = ComboFindItem(cbo_Code3, ls_Svg)
    mb_Description3 = OK
End If
MouseOn
End Sub

Private Sub Form_Load()

Dim ls_req As String

MouseOff

If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

spp_save.Picture = LoadResPicture(RES_OK, 1)
ssp_quit.Picture = LoadResPicture(RES_QUIT, 1)
pic_In.Picture = LoadResPicture(RES_RIGHT, 1)
pic_Out.Picture = LoadResPicture(RES_LEFT, 1)
SSC_dropped.Picture = LoadResPicture(RES_DOWN2, vbResIcon)

GetConstants
mb_Description1 = KO
mb_Description2 = KO
mb_Description3 = KO
Select Case gs_TableName
Case "Criteria_List", "Value_Type", "Super_Base_Material"
' Description and combos and fillempty
    frm_Combo.Top = 960
    If gs_TableName = "Super_Base_Material" Then
        lbl_Combo2.Visible = KO
        cbo_Description2.Visible = KO
    Else
        cbo_Description2.Enabled = KO
    End If
    frm_Main.Top = 1980
    Me.Height = 6852
'Case "Grid", "Grid_Value"
' Combos and fillempty
'    frm_description.Visible = KO
'    frm_combo.Top = 0
'    frm_Main.Top = 1020
'    Me.Height = 5904

'THOA
Case "Test_House_Acred"
' Two combos, one description, internet flag and drop date
    frm_Description.Visible = OK
    frm_Description.Top = 972
    frm_Combo.Visible = OK
    frm_Combo.Top = 0
    frm_Combo.Height = 972
    cbo_Code2.Visible = OK
    cbo_Description2.Visible = OK
    lbl_Combo2.Visible = OK
    lbl_Int.Visible = OK
    chk_Int.Visible = OK
    lbl_Drop.Visible = OK
    txt_dropped.Visible = OK
    SSC_dropped.Visible = OK
    frm_Main.Visible = KO
    Me.Height = 3453
'ETHOA
Case "Country_Link"
' One Combo and no internet flag and no drop date
    frm_Description.Visible = KO
    frm_Combo.Top = 0
    frm_Combo.Height = 670
    cbo_Code2.Visible = KO
    cbo_Description2.Visible = KO
    lbl_Combo2.Visible = KO
    lbl_Int.Visible = KO
    chk_Int.Visible = KO
    lbl_Drop.Visible = KO
    txt_dropped.Visible = KO
    SSC_dropped.Visible = KO
    frm_Main.Top = 1020
    Me.Height = 5900
Case "Countries_Language"
' One Combo and no internet flag and no drop date
    frm_Description.Visible = KO
    frm_Combo.Top = 0
    frm_Combo.Height = 670
    cbo_Code2.Visible = KO
    cbo_Description2.Visible = KO
    lbl_Combo2.Visible = KO
    lbl_Int.Visible = KO
    chk_Int.Visible = KO
    lbl_Drop.Visible = KO
    txt_dropped.Visible = KO
    SSC_dropped.Visible = KO
    frm_Main.Top = 1020
    Me.Height = 5900
Case "Products_Groups"
    frm_Combo.Visible = OK
    lbl_Combo3.Visible = OK
    cbo_Description3.Visible = OK
Case "Market_Segmentation"
    lbl_Int.Visible = OK
    chk_Int.Visible = OK
    frm_Combo.Visible = KO
    lbl_Drop.Visible = KO
    txt_dropped.Visible = KO
    SSC_dropped.Visible = KO
    frm_Main.Top = 1020
    Me.Height = 5904

Case Else
' Description and fillempty
    frm_Combo.Visible = KO
    frm_Main.Top = 1020
    Me.Height = 5904
End Select

' clear content of listbox
Call lst_NotSelected.Clear
Call lst_Selected.Clear

If gs_Action = "Add" Then
    ms_CodeRecord = ""
    ms_Code2 = ""
    Select Case gs_TableName
    Case "Products_Edges", "Products_Groups", "Products_Patterns", "Surfaces"
        ls_req = gut_Param.Str8 & " 0, 0, '" & gut_LangWork.Code & "'"
        FillLstSingle ls_req, lst_NotSelected
    Case "Value_Type"
    Case "Country_Link"
        ls_req = gut_Param.Str8 & " '', '" & gut_LangWork.Code & "'"
        FillLstSingle ls_req, lst_NotSelected
    Case "Test_House_Acred"
        ' nothing to do
    Case Else
        If gut_Param.Str11 = "Integer" Then
           ls_req = gut_Param.Str8 & " 0, '" & gut_LangWork.Code & "'"
        Else
           ls_req = gut_Param.Str8 & " '', '" & gut_LangWork.Code & "'"
        End If
        FillLstSingle ls_req, lst_NotSelected
    End Select
Else
    Select Case gs_TableName
    Case "Criteria_Choice"
        txt_Desc = gs_TableCode3
        ls_req = " " & gs_TableCode & ", '" & gut_LangWork.Code & "'"
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode4 = "X" Then
           chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode5
    Case "Criteria_List", "Value_Type"
        ' we get the description from the cmain's grid
        txt_Desc = gs_TableCode7
        ' we get the value of the combo1 from the cmain's grid
        cbo_Description1.AddItem gs_TableCode4
        cbo_Description1.ListIndex = 0
        cbo_Description1.Enabled = KO
        cbo_Code1.AddItem gs_TableCode3
        ' we get the value of the combo2 from the cmain's grid
        ms_CodeRecord = gs_TableCode
        ms_Code2 = gs_TableCode5
        cbo_Description2.AddItem gs_TableCode6
        cbo_Description2.ListIndex = 0
        cbo_Description2.Enabled = KO
        cbo_Code2.AddItem gs_TableCode5
        If gs_TableName = "Criteria_List" Then
            ls_req = " " & gs_TableCode & ", '" & gut_LangWork.Code & "'"
        Else
            ls_req = " " & gs_TableCode & ", " & gs_TableCode3 & " , " & gs_TableCode5 & ", '" & gut_LangWork.Code & "'"
        End If
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode8 = "X" Then
            chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode9
    Case "Grid", "Grid_Value"
        ' we get the value of the combo1 from the cmain's grid
        cbo_Description1.AddItem gs_TableCode4
        cbo_Description1.ListIndex = 0
        cbo_Description1.Enabled = KO
        cbo_Code1.AddItem gs_TableCode3
        ' we get the value of the combo2 from the cmain's grid
        cbo_Description2.AddItem gs_TableCode6
        cbo_Description2.ListIndex = 0
        cbo_Description2.Enabled = KO
        cbo_Code2.AddItem gs_TableCode5
        If gs_TableName = "Grid_Value" Then
            ls_req = " " & gs_TableCode & ", 0, '" & gut_LangWork.Code & "'"
        Else
            ls_req = " " & gs_TableCode & ", '" & gut_LangWork.Code & "'"
        End If
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode7 = "X" Then
           chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode8
    Case "Market_Segmentation"
        txt_Desc = gs_TableCode3
        ls_req = " '" & gs_TableCode & "', '" & gut_LangWork.Code & "'"
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode4 = "X" Then
            chk_Int.value = 1
        End If
    Case "Super_Base_Material"
        ' fill the description with the value of the columns description in C_Main
        txt_Desc = gs_TableCode5
        ' fill the combo with the value of the columns HBM in C_Main
        cbo_Description1.AddItem gs_TableCode4
        cbo_Description1.ListIndex = 0
        If gs_Action <> "Update" Then
            cbo_Description1.Enabled = KO
        End If
        cbo_Code1.AddItem gs_TableCode3
        ls_req = " '" & gs_TableCode & "', '" & gut_LangWork.Code & "'"
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode6 = "X" Then
           chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode7
    Case "Surfaces", "Products_Edges", "Products_Patterns"
        txt_Desc = gs_TableCode3
        ls_req = right(gs_TableCode, 3) & ", 0, '" & gut_LangWork.Code & "'"
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode4 = "X" Then
           chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode5
        If gs_Action = "Update" Then
            spp_media.Picture = LoadResPicture(RES_MEDIA, 1)
            spp_media.Visible = OK
        End If
    Case "Products_Groups"
        txt_Desc = gs_TableCode3
        ls_req = right(gs_TableCode, 3) & ", 0, '" & gut_LangWork.Code & "'"
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
        If gs_TableCode4 = "X" Then
           chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode5
        'fill the 3 cbos
        cbo_Description1.AddItem gs_TableCode7
        cbo_Code1.AddItem gs_TableCode6
        cbo_Description1.ListIndex = 0
        cbo_Description2.AddItem gs_TableCode11
        cbo_Code2.AddItem gs_TableCode10
        cbo_Description2.ListIndex = 0
        cbo_Description3.AddItem gs_TableCode9
        cbo_Code3.AddItem gs_TableCode8
        cbo_Description3.ListIndex = 0
    Case "Country_Link"
        cbo_Code1.AddItem gs_TableCode
        cbo_Code1.ListIndex = 0
        cbo_Description1.AddItem gs_TableCode3
        cbo_Description1.ListIndex = 0
        cbo_Description1.Enabled = KO
        ls_req = " '" & gs_TableCode & "', '" & gut_LangWork.Code & "'"
        FillLstSingle gut_Param.Str8 & ls_req, lst_NotSelected
        FillLstSingle gut_Param.Str9 & ls_req, lst_Selected
    Case "Test_House_Acred"
        ' fill the description with the value of the columns description in C_Main
        txt_Desc = gs_TableCode6
        ' fill the combo with the value of the columns Test House in C_Main
        cbo_Description1.AddItem gs_TableCode4
        cbo_Description1.ListIndex = 0
        cbo_Description1.Enabled = KO
        cbo_Code1.AddItem gs_TableCode
        ' fill the combo with the value of the columns Test Category in C_Main
        cbo_Description2.AddItem gs_TableCode5
        cbo_Description2.ListIndex = 0
        cbo_Description2.Enabled = KO
        cbo_Code2.AddItem gs_TableCode2

        If gs_TableCode7 = "X" Then
           chk_Int.value = 1
        End If
        txt_dropped = gs_TableCode8
    End Select
    If gs_Action <> "Update" Then
        txt_Desc.Enabled = KO
        pic_In.Visible = KO
        pic_Out.Visible = KO
        chk_Int.Enabled = KO
        SSC_dropped.Visible = KO
        If gs_Action = "MoreInfo" Then
            spp_save.Visible = KO
        End If
    End If
End If
frm_button.Visible = OK
frm_button.Top = Me.Height - frm_button.Height - 420

'P621 begin
Call lstAddHScroll(lst_NotSelected)
Call lstAddHScroll(lst_Selected)
'P621 end
MouseOn

End Sub
Private Sub GetConstants()

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 suite

ls_req = gut_Param.Str7 & 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
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 "title": Caption = ls_Text
        Case "titleA": If gs_Action = "Add" Then Caption = Caption & " - " & ls_Text
        Case "titleU": If gs_Action = "Update" Then Caption = Caption & " - " & ls_Text
        Case "titleD": If gs_Action = "Delete" Then Caption = Caption & " - " & ls_Text
        Case "lbl_desc": lbl_MKS = ls_Text
        Case "lbl_inout": lbl_Recommended = ls_Text
        Case "lbl_notselect": lbl_NotSelected = ls_Text
        Case "lbl_select": lbl_Selected = ls_Text
        Case "lbl_int": lbl_Int = ls_Text
        Case "lbl_drop": lbl_Drop = ls_Text
        Case "lbl_Combo1": lbl_Combo1 = ls_Text
        Case "lbl_Combo2": lbl_Combo2 = ls_Text
        Case "lbl_Combo3": lbl_Combo3 = ls_Text
        End Select
    End If
Loop
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
Exit Sub

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Sub

Private Sub pic_In_Click()

MouseOff
If lst_NotSelected.ListIndex <> -1 Then
    If Not RemoveItemLst(lst_ToDelete, lst_NotSelected.Text) Then
        lst_ToInsert.AddItem lst_NotSelected.Text
    End If
    lst_Selected.AddItem lst_NotSelected
    lst_NotSelected.RemoveItem lst_NotSelected.ListIndex

'P621 begin
    Call lstAddHScroll(lst_NotSelected)       ' task287 JUNA
    Call lstAddHScroll(lst_Selected)          ' task287 JUNA
'P621 end
End If
MouseOn

End Sub

Private Sub pic_Out_Click()

MouseOff
If lst_Selected.ListIndex <> -1 Then
    If Not RemoveItemLst(lst_ToInsert, lst_Selected.Text) Then
        lst_ToDelete.AddItem lst_Selected.Text
    End If
    lst_NotSelected.AddItem lst_Selected
    lst_Selected.RemoveItem lst_Selected.ListIndex

'P621 begin
    Call lstAddHScroll(lst_NotSelected)       ' task287 JUNA
    Call lstAddHScroll(lst_Selected)          ' task287 JUNA
'P621 end
End If
MouseOn

End Sub

Private Sub spp_media_Click()
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Desc As String
Dim ls_OldMediaCode As String
Dim lb_insert As Boolean

MouseOff
If lst_Selected.ListIndex <> -1 Then
    ls_Desc = GetDescSelected
    gut_Param2.Str1 = "Maintenance"
    gut_Param2.Str2 = "EXEC Media_Product_Classif_cnt "
    gut_Param2.Str3 = "EXEC Media_t_lst '" & gut_LangWork.Code & "', "
    Select Case gs_TableName
    Case "Products_Edges", "Products_Groups"
        gut_Param2.Str2 = gut_Param2.Str2 & "'" & gs_CGCode & "', '', '', '" & gs_TableCode & "', '', '', '', '', '', ''"
        gut_Param2.Str3 = gut_Param2.Str3 & "'" & gs_CGCode & "', '', '', '" & gs_TableCode & "', '', '', '', '', '', ''"
        gut_Param2.Str4 = gs_GridColumn(2)
        gut_Param2.Str5 = gs_TableCode3
    Case "Products_Patterns"
        gut_Param2.Str2 = gut_Param2.Str2 & "'" & gs_CGCode & "', '', '', '', '', '', '" & gs_TableCode & "', '', '', ''"
        gut_Param2.Str3 = gut_Param2.Str3 & "'" & gs_CGCode & "', '', '', '', '', '', '" & gs_TableCode & "', '', '', ''"
        gut_Param2.Str4 = gs_GridColumn(2)
        gut_Param2.Str5 = gs_TableCode3
    Case "Surfaces"
        gut_Param2.Str2 = gut_Param2.Str2 & "'" & gs_CGCode & "', '', '', '', '', '" & gs_TableCode & "', '', '', '', ''"
        gut_Param2.Str3 = gut_Param2.Str3 & "'" & gs_CGCode & "', '', '', '', '', '" & gs_TableCode & "', '', '', '', ''"
        gut_Param2.Str4 = gs_GridColumn(2)
        gut_Param2.Str5 = gs_TableCode3
    End Select
    MediaCodeExist ls_Desc
    gs_MediaCode = ms_OldMediaCode
    
    C_media.ms_Desc = ls_Desc
    C_media.mi_OldMediaIc = mi_OldMediaIc
    
    C_media.show 1
    If gs_MediaCode <> "" And gs_MediaCode <> ms_OldMediaCode Then
        If ms_OldMediaCode = "" Then
            ls_req = "EXEC Int_Media_Ass_ins '" & ls_Desc & ", '" & gs_MediaCode & "', 'E'"
            lb_insert = OK
        Else
            ls_req = "EXEC Int_Media_Ass_upd '" & ls_Desc & ", '" & gs_MediaCode & "', 'E', " & mi_OldMediaIc
            lb_insert = KO
        End If
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                ' Ok
            Else
                If lb_insert Then
                    SendMessage 4, "Insert Failed: an another user have changed the information.", gut_LangLogin.Code
                Else
                    SendMessage 2, "Update Failed: an another user have changed the information.", gut_LangLogin.Code
                End If
            End If
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        End If
    End If
Else
    MsgBox "Select a record first, please"
End If
MouseOn
End Sub

Private Sub spp_save_Click()

Dim ls_Line As String
Dim i As Integer
Dim j As Integer
Dim ls_IntFlag As String
Dim li_return As Integer

On Error GoTo suite

MouseOff
gb_Return = OK
ms_Code = gs_TableCode
If chk_Int.value = 1 Then
    ls_IntFlag = "X"
Else
    ls_IntFlag = ""
End If
Select Case gs_Action
Case "Add"
    If Control Then
        If BeginTran(gl_Environment, gl_Database) Then
            If AddRow Then
                If AddLink Then
                    If CommitTran(gl_Environment, gl_Database) Then
                        Select Case gs_TableName
                        Case "Criteria_List", "Value_Type"
                            ' update the c_main list with the two combo values
                            ls_Line = ms_Code & Chr(9) & 1 & Chr(9) & cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Description1.Text & Chr(9) & cbo_Code2.List(cbo_Description2.ListIndex) & Chr(9) & cbo_Description2.Text & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
'                        Case "Grid"
                            ' update the c_main list with the two combo value but not the description
'                            ls_Line = ms_Code & Chr(9) & 1 & Chr(9) & cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Description1.Text & Chr(9) & cbo_code2.List(cbo_Description2.ListIndex) & Chr(9) & cbo_Description2.Text & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                        Case "Super_Base_Material"
                            ' update the c_main list with the combo value
                            ls_Line = ms_Code & Chr(9) & 1 & Chr(9) & cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Description1.Text & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                        Case "Market_Segmentation"
                            ls_Line = ms_Code & Chr(9) & 1 & Chr(9) & txt_Desc & Chr(9)
                        'THOA
                        Case "Test_House_Acred"
                            ls_Line = cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Code2.List(cbo_Description2.ListIndex) & Chr(9) & 1 & Chr(9) & cbo_Description1 & Chr(9) & cbo_Description2 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                        Case "Products_Groups"
                            ls_Line = ms_Code & Chr(9) & 1 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped & Chr(9) & cbo_Code1 & Chr(9) & cbo_Description1 & Chr(9) & cbo_Code3 & Chr(9) & cbo_Description3 & Chr(9) & cbo_Code2 & Chr(9) & cbo_Description2
                        'ETHOA
                        Case Else
                            ls_Line = ms_Code & Chr(9) & 1 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                        End Select
                        C_main.Grid.AddItem ls_Line
                        C_main.Grid.Row = C_main.Grid.Rows - 1
                        If gl_NbLineDisplay < 2 Then
                            C_main.FillGrid
                        End If
                        gb_Return = OK
                        Unload Me
                    Else
                        RollbackTran gl_Environment, gl_Database
                        SendMessage 4, "Insert failed", gut_LangLogin.Code
                    End If
                Else
                    RollbackTran gl_Environment, gl_Database
                    SendMessage 4, "Insert failed", gut_LangLogin.Code
                End If
            Else
                RollbackTran gl_Environment, gl_Database
                SendMessage 4, "Insert failed", gut_LangLogin.Code
            End If
        Else
            SendMessage 4, "Insert failed", gut_LangLogin.Code
        End If
    End If
Case "Update"
    If Control Then
        If BeginTran(gl_Environment, gl_Database) Then
            If UpdateRow Then
                If DeleteLink Then
                    If AddLink Then
                        If CommitTran(gl_Environment, gl_Database) Then
                            C_main.Grid.RemoveItem C_main.Grid.Row
                            Select Case gs_TableName
                            Case "Criteria_List", "Value_Type"
                                  ' update the c_main list with the two combo values
                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Description1.Text & Chr(9) & cbo_Code2.List(cbo_Description2.ListIndex) & Chr(9) & cbo_Description2.Text & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                                gs_TableCode = txt_Desc
                                gs_TableCode2 = cbo_Description1
                                gs_TableCode3 = cbo_Description2
                            Case "Super_Base_Material"
                                ' update the c_main list with the combo value
                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Description1.Text & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
'                            Case "Grid", "Grid_Value"
                                ' update the c_main list with the two combo value but not the description
'                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & cbo_Code1.List(cbo_Description1.ListIndex) & Chr(9) & cbo_Description1.Text & Chr(9) & cbo_code2.List(cbo_Description2.ListIndex) & Chr(9) & cbo_Description2.Text & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                            Case "Market_Segmentation"
                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                            Case "Surfaces", "Products_Patterns"
                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                                gs_TableCode = txt_Desc
                            Case "Test_House_Acred"
                                ls_Line = ms_Code & Chr(9) & cbo_Code2.List(cbo_Description2.ListIndex) & Chr(9) & CStr(CLng(gs_TableCode3) + 1) & Chr(9) & cbo_Description1 & Chr(9) & cbo_Description2 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                            Case "Products_Groups"
                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped & Chr(9) & cbo_Code1 & Chr(9) & cbo_Description1 & Chr(9) & cbo_Code3 & Chr(9) & cbo_Description3 & Chr(9) & cbo_Code2 & Chr(9) & cbo_Description2
                            Case Else
                                ls_Line = ms_Code & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
                            End Select
                            C_main.Grid.AddItem ls_Line
                            C_main.Grid.Row = C_main.Grid.Rows - 1
                            gb_Return = OK
                            Unload Me
                        Else
                            RollbackTran gl_Environment, gl_Database
                            SendMessage 3, "Update failed", gut_LangLogin.Code
                        End If
                    Else
                        RollbackTran gl_Environment, gl_Database
                        SendMessage 3, "Update failed", gut_LangLogin.Code
                    End If
                Else
                    RollbackTran gl_Environment, gl_Database
                    SendMessage 3, "Update failed", gut_LangLogin.Code
                End If
            Else
                RollbackTran gl_Environment, gl_Database
                SendMessage 3, "Update failed", gut_LangLogin.Code
            End If
        Else
            SendMessage 3, "Update failed", gut_LangLogin.Code
        End If
    End If
Case "Delete"
    
    If gs_TableName = "Value_Type" Then
        li_return = SendMessage(0, ValueTypeDel, gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ")
    Else
        li_return = SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ")
    End If
    MouseOn
    If li_return = vbYes Then
        MouseOff
        If DeleteRow Then
            C_main.Grid.RemoveItem C_main.Grid.Row
        Else
            RollbackTran gl_Environment, gl_Database
            SendMessage 6, "Delete failed", gut_LangLogin.Code
        End If
    End If
    MouseOff
    Unload Me
End Select
MouseOn
Exit Sub

suite:
Select Case Err
Case 30015
    C_main.FillGrid
    Unload Me
Case Else
    StdError
    MouseOn
End Select
End Sub
Private Function UpdateRow() As Boolean

Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String
Dim ls_Code1 As String
Dim ls_Code2 As String
Dim ls_Code3 As String

UpdateRow = KO

On Error GoTo suite

If chk_Int.value = 1 Then ls_IntFlag = "X"
If txt_dropped <> "" Then
    ls_DropFlag = "X"
    ls_DropDate = FormatD(txt_dropped, "mm/dd/yyyy")
End If
If gut_Param.Str11 = "Integer" Then
    Select Case gs_TableName
'    Case "Grid", "Grid_Value"
'         ls_Req = gut_Param.Str5 & " " _
'          & QuoteParam(gs_TableCode) & ", " _
'          & cbo_Code1.List(cbo_Description1.ListIndex) & ", " _
'          & cbo_code2.List(cbo_Description2.ListIndex) & ", '" _
'          & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "', " _
'          & gut_Param.Str6
     Case "Surfaces", "Products_Edges", "Products_Patterns"
        ls_req = gut_Param.Str5 & " " _
        & QuoteParam(gs_TableCode) & ", '" _
        & QuoteParam(txt_Desc) & "', '" _
        & gs_CGCode & "', " _
        & gut_Param.Str6 & ", '" _
        & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
    Case "Products_Groups"
        If cbo_Code1.List(cbo_Description1.ListIndex) = "" Then
            ls_Code1 = "NULL"
        Else
            ls_Code1 = "'" & cbo_Code1.List(cbo_Description1.ListIndex) & "'"
        End If
        If cbo_Code2.List(cbo_Description2.ListIndex) = "" Then
            ls_Code2 = "NULL"
        Else
            ls_Code2 = "'" & cbo_Code2.List(cbo_Description2.ListIndex) & "'"
        End If
        If cbo_Code3.List(cbo_Description3.ListIndex) = "" Then
            ls_Code3 = "NULL"
        Else
            ls_Code3 = "'" & cbo_Code3.List(cbo_Description3.ListIndex) & "'"
        End If
        ls_req = gut_Param.Str5 & " " _
        & QuoteParam(gs_TableCode) & ", '" _
        & QuoteParam(txt_Desc) & "', '" _
        & gs_CGCode & "', " _
        & gut_Param.Str6 & ", '" _
        & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'," _
        & ls_Code1 & "," _
        & ls_Code3 & "," _
        & ls_Code2
    'THOA
    Case "Test_House_Acred"
        ls_req = "Exec Test_House_Acred_upd " & gs_TableCode & ", " _
        & gs_TableCode2 & ", '" _
        & QuoteParam(txt_Desc) & "', '" _
        & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "', " _
        & gs_TableCode3
    'ETHOA
    Case Else
       ls_req = gut_Param.Str5 & " " _
        & QuoteParam(gs_TableCode) & ", '" _
        & QuoteParam(txt_Desc) & "', '" _
        & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "', " _
        & Val(gut_Param.Str6)
    End Select
Else
    Select Case gs_TableName
    Case "Super_Base_Material"
      ls_req = gut_Param.Str5 & " '" _
          & QuoteParam(gs_TableCode) & "', " _
          & cbo_Code1.List(cbo_Description1.ListIndex) & ", '" _
          & QuoteParam(txt_Desc) & "', '" _
          & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "', " _
          & Val(gut_Param.Str6)
    Case "Country_Link"
        UpdateRow = OK
        ms_Code = cbo_Code1.List(cbo_Description1.ListIndex)
        Exit Function
    Case Else
         ls_req = gut_Param.Str5 & " '" _
          & QuoteParam(gs_TableCode) & "', '" _
          & QuoteParam(txt_Desc) & "', '" _
          & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "', " _
          & Val(gut_Param.Str6)
     End Select
End If
If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
    li_Status = SQLRowCount(ll_Statement, ll_lngrows)
    If ll_lngrows = 0 Then
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        UpdateRow = OK
   End If
Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function

Private Function AddRow() As Boolean

Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String

AddRow = KO

On Error GoTo suite

If chk_Int.value = 1 Then
    ls_IntFlag = "X"
Else
    ls_IntFlag = ""
End If
If txt_dropped = "" Then
    ls_DropFlag = ""
    ls_DropDate = ""
Else
    ls_DropFlag = "X"
    ls_DropDate = FormatD(txt_dropped, "mm/dd/yyyy")
End If
Select Case gs_TableName
Case "Criteria_List", "Value_Type"
   ls_req = gut_Param.Str1 & "'" & QuoteParam(txt_Desc) & "', " & cbo_Code1.List(cbo_Description1.ListIndex) & ", " & cbo_Code2.List(cbo_Description2.ListIndex) & ", '" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
Case "Super_Base_Material"
   ls_req = gut_Param.Str1 & cbo_Code1.List(cbo_Description1.ListIndex) & ",'" & QuoteParam(txt_Desc) & "','" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
'Case "Grid"
'   ls_Req = gut_Param.Str1 & "'" & QuoteParam(cbo_Code1.List(cbo_Description1.ListIndex)) & "', '" & QuoteParam(cbo_code2.List(cbo_Description2.ListIndex)) & "', '" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
Case "Surfaces", "Products_Edges", "Products_Patterns"
    ls_req = gut_Param.Str1 & "'" & QuoteParam(txt_Desc) & "', '" & gs_CGCode & "', '" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
Case "Products_Groups"
    ls_req = gut_Param.Str1 & "'" & QuoteParam(txt_Desc) & "', '" & gs_CGCode & "', '" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "', '" & cbo_Code1.List(cbo_Description1.ListIndex) & "', '" & cbo_Code3.List(cbo_Description3.ListIndex) & "', '" & cbo_Code2.List(cbo_Description2.ListIndex) & "'"
Case "Country_Link"
    AddRow = OK
    ms_Code = cbo_Code1.List(cbo_Description1.ListIndex)
    Exit Function
'THOA
Case "Test_House_Acred"
    ls_req = "EXEC Test_House_Acred_ins " & cbo_Code1.List(cbo_Description1.ListIndex) & ", " & cbo_Code2.List(cbo_Description2.ListIndex) & ", '" & QuoteParam(txt_Desc) & "', '" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
'ETHOA
Case Else
   ls_req = gut_Param.Str1 & "'" & QuoteParam(txt_Desc) & "', '" & ls_IntFlag & "', '" & ls_DropFlag & "', '" & ls_DropDate & "'"
End Select
If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
    li_Status = SQLRowCount(ll_Statement, ll_lngrows)
    If ll_lngrows = 0 Then
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Else
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ms_Code = ODBCData(ll_Statement, 1)
            AddRow = OK
        End If
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    End If
End If
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function

Private Sub SSC_dropped_Click()

On Error GoTo suite

MouseOff
gb_Return = KO
gs_Date = txt_dropped
Dates.show 1
If gb_Return Then
    txt_dropped = gs_Date
End If
MouseOn

Exit Sub

suite:
StdError
End Sub


Private Sub ssp_quit_Click()
Unload Me
End Sub


Private Function ValueTypeDel() As String

Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim li_Count As Integer

On Error GoTo suite
ValueTypeDel = ""
    
ls_req = "EXECUTE Value_Type_Count " & ms_Code

If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
    li_Status = SQL_SUCCESS
Else
    li_Status = SQL_ERROR
End If
li_Status = SQLFetch(ll_Statement)
If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
    li_Count = ODBCData(ll_Statement, 1)
End If
If li_Count <> 0 Then
    ValueTypeDel = "This value type is refered by " & li_Count _
        & " value(s)." & Chr(10) & "Are you sure to delete it anyway ?"
End If
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
Exit Function

suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function

Private Function GetDescSelected() As String
Dim li_Lenght As Integer
Dim li_pos As Integer
Dim ls_HBMdesc As String
Dim ls_CGdesc As String
Dim ls_CCdesc As String
Dim ls_CLdesc As String
Dim ls_VATdesc As String
Dim ls_RestList As String

ls_RestList = lst_Selected
li_Lenght = Len(ls_RestList)
li_pos = InStr(1, ls_RestList, "/")
ls_CGdesc = Mid(ls_RestList, 1, li_pos - 1)
ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
li_Lenght = Len(ls_RestList)
li_pos = InStr(1, ls_RestList, "/")
ls_HBMdesc = Mid(ls_RestList, 1, li_pos - 1)
ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
li_Lenght = Len(ls_RestList)
li_pos = InStr(1, ls_RestList, "/")
ls_CCdesc = Mid(ls_RestList, 1, li_pos - 1)
ls_RestList = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)
li_Lenght = Len(ls_RestList)
li_pos = InStr(1, ls_RestList, "/")
ls_CLdesc = Mid(ls_RestList, 1, li_pos - 1)
ls_VATdesc = Mid(ls_RestList, li_pos + 1, li_Lenght - li_pos)

GetDescSelected = QuoteParam(ls_HBMdesc) & "', '" _
    & QuoteParam(ls_CCdesc) & "', '" _
    & QuoteParam(ls_CLdesc) & "', '" _
    & QuoteParam(ls_VATdesc) & "', " _
    & CInt(right(gs_TableCode, 3))

End Function

Private Function MediaCodeExist(ByVal as_Desc As String) As String
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer

On Error GoTo suite

ms_OldMediaCode = ""
mi_OldMediaIc = 0

ls_req = "EXEC Int_Media_Ass_dtl '" & as_Desc & ", 'E'"

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
        ms_OldMediaCode = ODBCData(ll_Statement, 1)
        mi_OldMediaIc = CInt(ODBCData(ll_Statement, 2))
    End If
Loop
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)

Exit Function
suite:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
StdError
End Function

Private Sub lstAddHScroll(ByRef ao_lst As ListBox)
On Error GoTo ErrHandler
    Dim ll_lMaxItemWidth As Long
    Dim ll_i As Long
    ll_lMaxItemWidth = 0
    ' depends on the scalewidth
    ' if scalemode is Twips then Divide M by 15 to get Pixels
    For ll_i = 0 To ao_lst.ListCount - 1
        If ao_lst.Parent.TextWidth(ao_lst.List(ll_i)) > ll_lMaxItemWidth Then ll_lMaxItemWidth = ao_lst.Parent.TextWidth(ao_lst.List(ll_i))
    Next
    Call SendMessageAPI(ao_lst.hwnd, LB_SETHORIZONTALEXTENT, ll_lMaxItemWidth / Screen.TwipsPerPixelX + GetSystemMetrics(SM_CXVSCROLL) + 2, 0)
    Exit Sub
ErrHandler:
    StdError
End Sub
