VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Begin VB.Form BI_Test_Mtnc 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   2220
   ClientLeft      =   1755
   ClientTop       =   2655
   ClientWidth     =   5655
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2220
   ScaleWidth      =   5655
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton ssp_quit 
      Height          =   612
      Left            =   4860
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   1500
      Width           =   612
   End
   Begin VB.CommandButton spp_save 
      Default         =   -1  'True
      Height          =   612
      Left            =   4200
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   1500
      Width           =   612
   End
   Begin VB.PictureBox Pic_Dropped 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0C0C0&
      BorderStyle     =   0  'None
      FillColor       =   &H00FFFFFF&
      ForeColor       =   &H80000008&
      Height          =   345
      Left            =   2760
      ScaleHeight     =   345
      ScaleWidth      =   375
      TabIndex        =   12
      Top             =   1800
      Width           =   375
   End
   Begin VB.TextBox txt_dropped 
      ForeColor       =   &H00FF0000&
      Height          =   315
      Left            =   1620
      Locked          =   -1  'True
      TabIndex        =   5
      Top             =   1800
      Width           =   1212
   End
   Begin VB.CheckBox chk_Int 
      Caption         =   "Check1"
      Height          =   252
      Left            =   1620
      TabIndex        =   4
      Top             =   1440
      Width           =   252
   End
   Begin MSForms.ComboBox cbo_Curve 
      Height          =   315
      Left            =   1620
      TabIndex        =   11
      Top             =   960
      Width           =   3975
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "7011;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin MSForms.ComboBox cbo_Value 
      Height          =   315
      Left            =   1620
      TabIndex        =   10
      Top             =   540
      Width           =   2175
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "3836;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin MSForms.ComboBox cbo_Market 
      Height          =   315
      Left            =   1620
      TabIndex        =   9
      Top             =   120
      Width           =   2175
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "3836;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin VB.Label lbl_Curve 
      Caption         =   "Curve"
      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            =   180
      TabIndex        =   8
      Top             =   960
      Width           =   1392
   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            =   180
      TabIndex        =   7
      Top             =   1440
      Width           =   1392
   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            =   180
      TabIndex        =   6
      Top             =   1800
      Width           =   1392
   End
   Begin VB.Label lbl_Value 
      Caption         =   "Value"
      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            =   180
      TabIndex        =   3
      Top             =   540
      Width           =   1392
   End
   Begin VB.Label lbl_Market 
      Caption         =   "Market"
      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            =   180
      TabIndex        =   2
      Top             =   120
      Width           =   1392
   End
End
Attribute VB_Name = "BI_Test_Mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim mi_OldVal As String

Private Sub cbo_Curve_DropButtonClick()
Dim lv_Value As Variant
Dim ls_req As String

    MouseOff
    If cbo_Curve.Tag = UNLOADED Then
        lv_Value = MCombo_GetCode(cbo_Curve)
        cbo_Curve.Clear
        ls_req = "EXEC Tech_Curve_cbo 'E'," & gut_Param.Str14
        MCombo_Fill cbo_Curve, ls_req
        MCombo_CodeSelect(cbo_Curve) = lv_Value
        cbo_Curve.Tag = Loaded
    End If
    MouseOn

End Sub

Private Sub Cbo_market_Click()
    MouseOff
    cbo_Value.ListIndex = -1
    cbo_Value.Tag = UNLOADED
    If cbo_Market.ListIndex = -1 Then
        cbo_Value.Enabled = KO
    Else
        cbo_Value.Enabled = OK
    End If
    MouseOn
End Sub

Private Sub Cbo_market_DropButtonClick()
Dim lv_Value As Variant
    
    MouseOff
    If cbo_Market.Tag = UNLOADED Then
        lv_Value = MCombo_GetCode(cbo_Market)
        cbo_Market.Clear
        Select Case gut_Param.Str14
    '   CAT_code
        Case 4, 15
    '   Fire
            MCombo_Fill cbo_Market, "Exec Test_Market_cbo " & gut_Param.Str14 & ",'" & gut_LangWork.Code & "'"
'789 bis        Case 5, 16, 17
        Case 5, 16, 17, 26, 25
    '   Acoustic
            MCombo_AddItemCode cbo_Market, "0", ""
            MCombo_Fill cbo_Market, "EXEC Tech_Acoustic_Option_cbo '" & gut_LangWork.Code & "'"
        End Select
        MCombo_CodeSelect(cbo_Market) = lv_Value
        cbo_Market.Tag = Loaded
    End If
    MouseOn
End Sub

Private Sub cbo_value_DropButtonClick()
Dim lv_Value As Variant
Dim ls_req As String

    MouseOff
    If cbo_Value.Tag = UNLOADED Then
        lv_Value = MCombo_GetCode(cbo_Value)
        cbo_Value.Clear
        ls_req = "EXEC Tech_value_cbo 'E'," & MCombo_GetCode(cbo_Market) & "," & gut_Param.Str14 & "," & gut_Param.Str15
        MCombo_Fill cbo_Value, ls_req
        MCombo_CodeSelect(cbo_Value) = lv_Value
        cbo_Value.Tag = Loaded
    End If
    MouseOn

End Sub

Private Sub Form_Load()
Dim ls_req As String

    On Error GoTo Form_Load_Err
    
    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_Dropped.Picture = LoadResPicture(RES_COMBOCOPY, 1)
    GetScCsts
    MCombo_AddItemCode cbo_Market, gut_Param.Str12, gut_Param.Str13
    Select Case gut_Param.Str14
    ' CAT_code
    Case 4, 15
    ' Market is visible for fire
        cbo_Market.Tag = UNLOADED
        If gut_Param.Str12 = "0" And (gut_Param.Str14 = "4" Or gut_Param.Str14 = "15") Then
            cbo_Value.Enabled = KO
        End If
        If gut_Param.Str16 <> "" Then
            cbo_Market.Enabled = KO
            mi_OldVal = gut_Param.Str16
        End If
        lbl_Curve.Visible = KO
        cbo_Curve.Visible = KO
'789 bis    Case 5, 16, 17
    Case 5, 16, 17, 25, 26
    ' Market and Curve is visible for acoustic
        cbo_Market.Tag = UNLOADED
        If gut_Param.Str16 <> "" Then
            cbo_Market.Enabled = KO
        End If
        cbo_Curve.Tag = UNLOADED
    Case Else
        lbl_Market.Visible = KO
        cbo_Market.Visible = KO
        lbl_Curve.Visible = KO
        cbo_Curve.Visible = KO
    End Select
    cbo_Value.Tag = UNLOADED
    If gut_Param.Str16 <> "" Then MCombo_AddItemCode cbo_Value, gut_Param.Str16, gut_Param.Str17
    If gut_Param.Str28 <> "" Then MCombo_AddItemCode cbo_Curve, gut_Param.Str28, gut_Param.Str29
    If gut_Param.Str19 = "X" Then
        chk_Int.Value = 1
    End If
    txt_dropped = gut_Param.Str20
    If gut_Param.Str10 = "Delete" Then
        cbo_Market.Enabled = KO
        cbo_Value.Enabled = KO
        cbo_Curve.Enabled = KO
        chk_Int.Enabled = KO
        Pic_Dropped.Enabled = KO
    End If
    MouseOn
    Exit Sub
    
Form_Load_Err:
    StdError
End Sub

Private Sub Pic_Dropped_Click()

    On Error GoTo Pic_dropped_Click_Err
    
    MouseOff
    gb_Return = KO
    gs_Date = txt_dropped
    Dates.show 1
    If gb_Return Then
        txt_dropped = gs_Date
    End If
    MouseOn
    Exit Sub
    
Pic_dropped_Click_Err:
    StdError
End Sub

Private Sub spp_save_Click()
    MouseOff
    If cbo_Value.ListIndex <> -1 Then
        Select Case gut_Param.Str10
        Case "Add", "Update"
            If UpdValue Then
                Unload Me
                Exit Sub
            End If
        Case "Delete"
            If DelValue Then
                Unload Me
                Exit Sub
            End If
        End Select
    End If
    MouseOn
End Sub

Private Sub ssp_quit_Click()
    MouseOff
    Unload Me
    MouseOn
End Sub

Private Function UpdValue() 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_Concurrency As String

    On Error GoTo UpdValue_Err
    
    gb_Return = KO
    UpdValue = KO
    'If gut_Param.Str14 = 4 Or gut_Param.Str14 = 5 Or gut_Param.Str14 = 15 Or gut_Param.Str14 = 16 Or gut_Param.Str14 = 17 Then
'789 bis    If gut_Param.Str14 = 4 Or gut_Param.Str14 = 5 Or gut_Param.Str14 = 16 Or gut_Param.Str14 = 17 Then
    If gut_Param.Str14 = 4 Or gut_Param.Str14 = 5 Or gut_Param.Str14 = 16 Or gut_Param.Str14 = 17 Or gut_Param.Str14 = 25 Or gut_Param.Str14 = 26 Then
        If Not ControlPKPublicValue Then
            If gut_Param.Str14 = 4 Then
                SendMessage 111, "Only one value can be entered !!", gut_LangLogin.Code
            Else
                SendMessage 115, "Only one value can be entered for each type of acoustic correction", gut_LangLogin.Code
            End If
            Exit Function
        End If
    End If
    
    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 cbo_Curve.ListIndex <> -1 Then
        ls_req = gut_Param.Str21 & " '" _
            & QuoteParam(gs_SAPCode) & "', " _
            & MCombo_GetCode(cbo_Market) & ", " _
            & gut_Param.Str14 & ", " & gut_Param.Str15 & ", " _
            & MCombo_GetCode(cbo_Value) & ", " _
            & MCombo_GetCode(cbo_Curve) & ", '" _
            & ls_IntFlag & "', '" _
            & ls_DropFlag & "', '" _
            & ls_DropDate & "', " _
            & gut_Param.Str18
        If gut_Param.Str10 = "Update" And gut_Param.Str21 = "EXEC BI_FireRes_Value_upd2" Then
            ls_req = ls_req & ", " & mi_OldVal
        End If
    Else
        ls_req = gut_Param.Str21 & " '" _
            & QuoteParam(gs_SAPCode) & "', " _
            & MCombo_GetCode(cbo_Market) & ", " _
            & gut_Param.Str14 & ", " & gut_Param.Str15 & ", " _
            & MCombo_GetCode(cbo_Value) & ", 0, '" _
            & ls_IntFlag & "', '" _
            & ls_DropFlag & "', '" _
            & ls_DropDate & "', " _
            & gut_Param.Str18
        If gut_Param.Str10 = "Update" And gut_Param.Str21 = "EXEC BI_FireRes_Value_upd2" Then
            ls_req = ls_req & ", " & mi_OldVal
        End If
    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)
            Select Case gut_Param.Str10
            Case "Add"
                SendMessage 4, "Insert failed", gut_LangLogin.Code
            Case "Update"
                SendMessage 3, "Update failed", gut_LangLogin.Code
            End Select
        Else
            gb_Return = OK
            UpdValue = OK
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                ls_Concurrency = ODBCData(ll_Statement, 1)
            End If
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            gut_Param.Str12 = MCombo_GetCode(cbo_Market)
            gut_Param.Str13 = cbo_Market.Text
            gut_Param.Str16 = MCombo_GetCode(cbo_Value)
            gut_Param.Str17 = cbo_Value.Text
            gut_Param.Str18 = ls_Concurrency
            gut_Param.Str19 = ls_IntFlag
            gut_Param.Str20 = txt_dropped
            gut_Param.Str28 = MCombo_GetCode(cbo_Curve)
            gut_Param.Str29 = cbo_Curve.Text
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        Select Case gut_Param.Str10
        Case "Add"
            SendMessage 4, "Insert failed", gut_LangLogin.Code
        Case "Update"
            SendMessage 3, "Update failed", gut_LangLogin.Code
        End Select
    End If
    Exit Function
    
UpdValue_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function

Private Function DelValue() 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 DelValue_Err
    
    gb_Return = KO
    DelValue = KO
    MouseOn
    If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbYes Then
        MouseOff
        ls_req = gut_Param.Str21 & " '" _
            & QuoteParam(gs_SAPCode) & "', " _
            & gut_Param.Str12 & ", " _
            & gut_Param.Str14 & ", " _
            & gut_Param.Str15 & ", " _
            & gut_Param.Str18 & ", " _
            & gut_Param.Str16
        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)
                SendMessage 7, "Delete failed : concurrency problem ?", gut_LangLogin.Code
            Else
                gb_Return = OK
                DelValue = OK
                li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
                gut_Param.Str16 = ""
                gut_Param.Str17 = ""
                gut_Param.Str18 = 0
                gut_Param.Str19 = ""
                gut_Param.Str20 = ""
            End If
        Else
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            SendMessage 6, "Delete failed ", gut_LangLogin.Code
        End If
    End If
    MouseOff
    Exit Function
    
DelValue_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function

Private Sub GetScCsts()
Dim ls_Field As String
Dim ls_Text As String
Dim ll_Statement As Long
Dim li_Status As Integer

    On Error GoTo GetScCsts_Err
    
    Caption = gut_Param.Str11 & " : " & gs_SAPCode
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, gut_Param.Str22) 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 = Left(ODBCData(ll_Statement, 2), 30)
            Select Case ls_Field
            Case "titleA"
                If gut_Param.Str10 = "Add" Then
                    Caption = Caption & " - " & ls_Text
                End If
            Case "titleU"
                If gut_Param.Str10 = "Update" Then
                    Caption = Caption & " - " & ls_Text
                End If
            Case "titleD"
                If gut_Param.Str10 = "Delete" Then
                    Caption = Caption & " - " & ls_Text
                End If
            Case "lbl_Market"
                If gut_Param.Str14 = "4" Or gut_Param.Str14 = "15" Then
                    lbl_Market = ls_Text
                End If
            Case "lbl_Option"
                If gut_Param.Str14 = "5" Or gut_Param.Str14 = "16" Or gut_Param.Str14 = "17" Or gut_Param.Str14 = "25" Then
                    lbl_Market = ls_Text
                End If
            Case "lbl_Value": lbl_Value = ls_Text
            Case "lbl_Int": lbl_Int = ls_Text
            Case "lbl_Drop": lbl_Drop = ls_Text
            Case "lbl_Curve"
                If gut_Param.Str14 = "5" Or gut_Param.Str14 = "16" Or gut_Param.Str14 = "17" Or gut_Param.Str14 = "25" Then
                    lbl_Curve = ls_Text
                End If
            End Select
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
    
GetScCsts_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Function ControlPKPublicValue()
Dim ls_req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim li_ODBCData As Integer

    On Error GoTo ControlPKPublicValue_Err
    
    ControlPKPublicValue = KO
    ls_req = "EXEC BI_Public_Value_PK_Control '" _
            & QuoteParam(gs_SAPCode) & "', " _
            & MCombo_GetCode(cbo_Market) & ", " _
            & gut_Param.Str14 & ", " _
            & gut_Param.Str15
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_req) Then
        li_Status = SQLFetch(ll_Statement)
        li_ODBCData = ODBCData(ll_Statement, 1)
        If li_ODBCData = 0 Or (li_ODBCData = 1 And gut_Param.Str10 = "Update") Then
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            ControlPKPublicValue = OK
        Else
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    End If
    Exit Function
    
ControlPKPublicValue_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function
