VERSION 5.00
Begin VB.Form ExchangeRate_mtnc 
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   1665
   ClientLeft      =   1575
   ClientTop       =   2565
   ClientWidth     =   6705
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   1665
   ScaleWidth      =   6705
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton ssp_quit 
      Height          =   612
      Left            =   6000
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   960
      Width           =   612
   End
   Begin VB.CommandButton spp_save 
      Default         =   -1  'True
      Height          =   612
      Left            =   5340
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   960
      Width           =   612
   End
   Begin VB.TextBox txt_rate 
      Height          =   285
      Left            =   3180
      TabIndex        =   4
      Top             =   600
      Width           =   1695
   End
   Begin VB.ComboBox Cbo_year 
      Height          =   288
      Left            =   120
      Style           =   2  'Dropdown List
      TabIndex        =   3
      Top             =   1140
      Width           =   1092
   End
   Begin VB.ComboBox Cbo_curr 
      Height          =   288
      Left            =   120
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   420
      Width           =   2292
   End
   Begin VB.ComboBox Cbo_month 
      Height          =   288
      ItemData        =   "C_EXRATE.frx":0000
      Left            =   1320
      List            =   "C_EXRATE.frx":0028
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   1140
      Width           =   1092
   End
   Begin VB.ComboBox cbo_CurrencyCode 
      Height          =   288
      Left            =   1560
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   420
      Visible         =   0   'False
      Width           =   396
   End
   Begin VB.Label Lbl_curr 
      Alignment       =   2  'Center
      Caption         =   "Currency"
      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            =   120
      TabIndex        =   8
      Top             =   120
      Width           =   2292
   End
   Begin VB.Label Lbl_year 
      Alignment       =   2  'Center
      Caption         =   "Year"
      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            =   120
      TabIndex        =   7
      Top             =   840
      Width           =   1092
   End
   Begin VB.Label Lbl_rate 
      Alignment       =   2  'Center
      Caption         =   "Rate"
      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            =   3180
      TabIndex        =   6
      Top             =   300
      Width           =   1692
   End
   Begin VB.Label Lbl_month 
      Alignment       =   2  'Center
      Caption         =   "Month"
      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            =   1320
      TabIndex        =   5
      Top             =   840
      Width           =   1092
   End
End
Attribute VB_Name = "ExchangeRate_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Form_Load()

On Error GoTo suite

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)
GetConstants
Select Case gs_TableName
Case "Exchange_Rates"
    Lbl_month.Visible = OK
    cbo_month.Visible = OK
Case "Budgeted_Exchange_Rates"
    Lbl_month.Visible = KO
    cbo_month.Visible = KO
End Select
Select Case gs_Action
Case "Add"
    FillCbo "Currencies", cbo_CurrencyCode, Cbo_curr
    FillCboYear
Case Else
    Cbo_curr.Enabled = KO
    cbo_year.Enabled = KO
    cbo_month.Enabled = KO
    If gs_Action = "Delete" Then
        txt_rate.Enabled = KO
    End If
    Cbo_curr.AddItem gs_TableCode2
    Cbo_curr.ListIndex = 0
    cbo_year.AddItem gs_TableCode3
    cbo_year.ListIndex = 0
    Select Case gs_TableName
    Case "Exchange_Rates"
        cbo_month.AddItem gs_TableCode4
        cbo_month.ListIndex = 0
        txt_rate = gs_TableCode5
    Case "Budgeted_Exchange_Rates"
        txt_rate = gs_TableCode4
    End Select
End Select
MouseOn
Exit Sub

suite:
StdError
End Sub
Private Sub spp_save_Click()

On Error GoTo suite

MouseOff
gb_Return = OK
Select Case gs_Action
Case "Add"
    If AddRow Then
        Cbo_curr.ListIndex = -1
        cbo_year.ListIndex = -1
        cbo_month.ListIndex = -1
        txt_rate = ""
        If gl_NbLineDisplay < 2 Then
            C_main.FillGrid
        End If
        Cbo_curr.SetFocus
      End If
Case "Update"
    If UpdateRow Then
        Unload Me
    End If
Case "Delete"
    If DeleteRow Then
        Unload Me
    End If
End Select
MouseOn

Exit Sub

suite:
StdError
End Sub
Private Sub ssp_quit_Click()

MouseOff
Unload Me
MouseOn

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_Line As String

UpdateRow = KO

On Error GoTo suite

If Control Then
    Select Case gs_TableName
    Case "Exchange_Rates"
        ls_Req = "EXEC Exchange_Rates_upd '" _
            & gs_TableCode & "', '" _
            & gs_TableCode3 & "', '" _
            & gs_TableCode4 & "', " _
            & txt_rate & ", " _
            & gs_TableCode6
    Case "Budgeted_Exchange_Rates"
        ls_Req = "EXEC Budgeted_Exchange_Rates_upd '" _
            & QuoteParam(gs_TableCode) & "', '" _
            & gs_TableCode3 & "', " _
            & txt_rate & ", " _
            & gs_TableCode5
    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
            SendMessage 2, "Another user change the record", gut_LangLogin.Code
            C_main.FillGrid
        Else
            UpdateRow = OK
            C_main.Grid.RemoveItem C_main.Grid.Row
            Select Case gs_TableName
            Case "Exchange_Rates"
                ls_Line = gs_TableCode & Chr(9) & gs_TableCode2 & Chr(9) & gs_TableCode3 & Chr(9) & gs_TableCode4 & Chr(9) & txt_rate & Chr(9) & gs_TableCode6 + 1
            Case "Budgeted_Exchange_Rates"
                ls_Line = gs_TableCode & Chr(9) & gs_TableCode2 & Chr(9) & gs_TableCode3 & Chr(9) & txt_rate & Chr(9) & gs_TableCode5 + 1
            End Select
            C_main.Grid.AddItem ls_Line, C_main.Grid.Row
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 3, "Update failed", gut_LangLogin.Code
    End If
End If
Exit Function

suite:
Select Case Err
Case 30015
    C_main.FillGrid
Case Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Select
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_Line As String

AddRow = KO

On Error GoTo suite

If Control Then
    Select Case gs_TableName
    Case "Exchange_Rates"
        ls_Req = "EXEC Exchange_Rates_ins '" _
            & cbo_CurrencyCode.List(Cbo_curr.ListIndex) & "', '" _
            & cbo_year & "', '" _
            & cbo_month & "', " _
            & txt_rate
    Case "Budgeted_Exchange_Rates"
        ls_Req = "EXEC Budgeted_Exchange_Rates_ins '" _
            & cbo_CurrencyCode.List(Cbo_curr.ListIndex) & "', '" _
            & cbo_year & "', " _
            & txt_rate
    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
            SendMessage 4, "Insert failed", gut_LangLogin.Code
            C_main.FillGrid
        Else
            AddRow = OK
            Select Case gs_TableName
            Case "Exchange_Rates"
                ls_Line = cbo_CurrencyCode.List(Cbo_curr.ListIndex) & Chr(9) & Cbo_curr & Chr(9) & cbo_year & Chr(9) & cbo_month & Chr(9) & txt_rate & Chr(9) & 1
            Case "Budgeted_Exchange_Rates"
                ls_Line = cbo_CurrencyCode.List(Cbo_curr.ListIndex) & Chr(9) & Cbo_curr & Chr(9) & cbo_year & Chr(9) & txt_rate & Chr(9) & 1
            End Select
            C_main.Grid.AddItem ls_Line
            C_main.Grid.Row = C_main.Grid.Rows - 1
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 4, "Insert failed", gut_LangLogin.Code
    End If
End If
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

DeleteRow = KO

On Error GoTo suite

MouseOn
If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbYes Then
    MouseOff
    Select Case gs_TableName
    Case "Exchange_Rates"
        ls_Req = "EXEC Exchange_Rates_del '" _
            & QuoteParam(gs_TableCode) & "', '" _
            & gs_TableCode3 & "', '" _
            & gs_TableCode4 & "', " _
            & gs_TableCode6
    Case "Budgeted_Exchange_Rates"
        ls_Req = "EXEC Budgeted_Exchange_Rates_del '" _
            & QuoteParam(gs_TableCode) & "', '" _
            & gs_TableCode3 & "', " _
            & gs_TableCode5
    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
            SendMessage 7, "Delete failed : concurrency problem ?", gut_LangLogin.Code
            C_main.FillGrid
        Else
            DeleteRow = OK
            C_main.Grid.RemoveItem C_main.Grid.Row
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 6, "Delete failed", gut_LangLogin.Code
    End If
End If
MouseOff
Exit Function

suite:
Select Case Err
Case 30015
    C_main.FillGrid
Case Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Select
End Function
Private Sub GetConstants()

Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Field As String, ls_Text As String

On Error GoTo suite

Select Case gs_TableName
Case "Exchange_Rates"
    ls_Req = "EXEC Screen_Csts 'mtnc_exratof', '" & gut_LangLogin.Code & "'"
Case "Budgeted_Exchange_Rates"
    ls_Req = "EXEC Screen_Csts 'mtnc_exratbu', '" & gut_LangLogin.Code & "'"
End Select
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 = left(ODBCData(ll_Statement, 2), 30)
        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_curr": Lbl_curr.Caption = ls_Text
        Case "lbl_year": Lbl_year = ls_Text
        Case "lbl_month": Lbl_month = ls_Text
        Case "lbl_rate": Lbl_rate = 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 FillCboYear()

Dim li_Count As Integer

For li_Count = 1 To 30
    cbo_year.AddItem (1992 + li_Count)
Next li_Count
  
End Sub

Private Function Control() As Boolean

Dim ls_Texte As String

Control = KO
If Cbo_curr = "" Then
    Cbo_curr.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If cbo_year = "" Then
    cbo_year.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
Select Case gs_TableName
Case "Exchange_Rates"
    If cbo_month = "" Then
        cbo_month.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Exit Function
    End If
End Select
If txt_rate = "" Then
    txt_rate.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
ls_Texte = Formatage(txt_rate, 7)
If Not ChkNumeric(ls_Texte, 7) Then
    txt_rate.SetFocus
    SendMessage 12, "Value must be numeric", gut_LangLogin.Code
    Exit Function
End If
txt_rate = ls_Texte
If StringToFloat(txt_rate) > 99999 Then
    txt_rate.SetFocus
    SendMessage 19, "5 digits maximum", gut_LangLogin.Code
    Exit Function
End If
Control = OK

End Function
