VERSION 5.00
Begin VB.Form Letclai_mtnc 
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   1695
   ClientLeft      =   1710
   ClientTop       =   2550
   ClientWidth     =   5730
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   1695
   ScaleWidth      =   5730
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton cmd_Save 
      Default         =   -1  'True
      Height          =   612
      Left            =   4320
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   960
      Width           =   612
   End
   Begin VB.CommandButton cmd_Quit 
      Height          =   612
      Left            =   4980
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   960
      Width           =   612
   End
   Begin VB.CommandButton cmd_Drop 
      Height          =   276
      Left            =   3000
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   1200
      Width           =   252
   End
   Begin VB.TextBox txt_Drop 
      ForeColor       =   &H00FF0000&
      Height          =   288
      Left            =   1800
      Locked          =   -1  'True
      TabIndex        =   8
      Top             =   1200
      Width           =   1212
   End
   Begin VB.CheckBox chk_Int 
      Height          =   252
      Left            =   1800
      TabIndex        =   7
      Top             =   900
      Width           =   252
   End
   Begin VB.TextBox txt_Desc 
      Height          =   288
      Left            =   2820
      MaxLength       =   80
      TabIndex        =   1
      Top             =   420
      Width           =   2772
   End
   Begin VB.ComboBox cbo_NatureCode 
      Height          =   288
      Left            =   2040
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   420
      Visible         =   0   'False
      Width           =   396
   End
   Begin VB.ComboBox cbo_Nature 
      Height          =   288
      Left            =   240
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   420
      Width           =   2412
   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        =   11
      Top             =   900
      Width           =   1572
   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        =   10
      Top             =   1200
      Width           =   1572
   End
   Begin VB.Label lbl_Nature 
      Alignment       =   2  'Center
      Caption         =   "Nature"
      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        =   4
      Top             =   120
      Width           =   2412
   End
   Begin VB.Label lbl_Desc 
      Alignment       =   2  'Center
      Caption         =   "Description"
      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            =   2820
      TabIndex        =   3
      Top             =   120
      Width           =   2772
   End
End
Attribute VB_Name = "Letclai_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim mb_NatureNotLoaded As Boolean

Private Sub Cbo_nature_DropDown()

Dim ls_Nature As String

MouseOff
If mb_NatureNotLoaded Then
    mb_NatureNotLoaded = KO
    If cbo_Nature.ListIndex <> -1 Then
        ls_Nature = cbo_NatureCode.List(cbo_Nature.ListIndex)
    Else
        ls_Nature = ""
    End If
    cbo_NatureCode.Clear
    cbo_Nature.Clear
    FillCbo "Claim_Nature", cbo_NatureCode, cbo_Nature
    If ls_Nature <> "" Then
        cbo_Nature.ListIndex = ComboFindItem(cbo_NatureCode, ls_Nature)
    End If
End If
MouseOn

End Sub

Private Sub Form_Load()

Dim li_Count As Integer

On Error GoTo suite

MouseOff

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

cmd_Save.Picture = LoadResPicture(RES_OK, 1)
cmd_Quit.Picture = LoadResPicture(RES_QUIT, 1)
cmd_Drop.Picture = LoadResPicture(RES_DOWN2, vbResIcon)

GetCaptions
mb_NatureNotLoaded = OK
If gs_Action <> "Add" Then
    cbo_Nature.Enabled = KO
    cbo_NatureCode.AddItem gs_TableCode3
    cbo_Nature.AddItem gs_TableCode4
    cbo_Nature.ListIndex = 0
    txt_Desc = gs_TableCode5
    If gs_TableCode6 = "X" Then
        chk_Int.value = 1
    End If
    txt_Drop = gs_TableCode7
End If
If gs_Action = "Delete" Then
    txt_Desc.Enabled = KO
    chk_Int.Enabled = KO
    txt_Drop.Enabled = KO
    cmd_Drop.Visible = KO
End If
MouseOn
Exit Sub

suite:
StdError
End Sub
Private Sub cmd_save_Click()

On Error GoTo suite

MouseOff
gb_Return = OK
Select Case gs_Action
Case "Add"
    If InsertRow Then
        cbo_Nature.ListIndex = -1
        txt_Desc = ""
        chk_Int.value = 0
        txt_Drop = ""
        If gl_NbLineDisplay < 2 Then
            C_main.FillGrid
        End If
        cbo_Nature.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:
MouseOn
StdError
End Sub
Private Sub cmd_Drop_Click()

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

End Sub
Private Sub cmd_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
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String

UpdateRow = KO

On Error GoTo suite

If Control Then
    If chk_Int.value = 1 Then ls_IntFlag = "X"
    If txt_Drop <> "" Then
        ls_DropFlag = "X"
        ls_DropDate = FormatD(txt_Drop, "mm/dd/yyyy")
    End If
    ls_Req = "EXEC Claim_Letter_upd " _
     & gs_TableCode & ", '" _
     & QuoteParam(txt_Desc) & "', '" _
     & ls_IntFlag & "', '" _
     & ls_DropFlag & "', '" _
     & ls_DropDate & "', " _
     & gs_TableCode2
    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
            ls_Line = gs_TableCode & Chr(9) & CInt(gs_TableCode2) + 1 & Chr(9) & gs_TableCode3 & Chr(9) & gs_TableCode4 & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_Drop
            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 InsertRow() 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
Dim ls_Code As String
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String

InsertRow = KO

On Error GoTo suite

If Control Then
    If chk_Int.value = 1 Then ls_IntFlag = "X"
    If txt_Drop <> "" Then
        ls_DropFlag = "X"
        ls_DropDate = FormatD(txt_Drop, "mm/dd/yyyy")
    End If
    ls_Req = "EXEC Claim_Letter_ins " _
     & cbo_NatureCode.List(cbo_Nature.ListIndex) & ", '" _
     & QuoteParam(txt_Desc) & "', '" _
     & ls_IntFlag & "', '" _
     & ls_DropFlag & "', '" _
     & ls_DropDate & "'"
    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 4, "Insert failed", gut_LangLogin.Code
            C_main.FillGrid
        Else
            InsertRow = OK
        'Ajout dans la ligne
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                ls_Code = ODBCData(ll_Statement, 1)
                li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
                ls_Line = ls_Code & Chr(9) & 1 & Chr(9) & cbo_NatureCode.List(cbo_Nature.ListIndex) & Chr(9) & cbo_Nature & Chr(9) & txt_Desc & Chr(9) & ls_IntFlag & Chr(9) & txt_Drop
                C_main.Grid.AddItem ls_Line
                C_main.Grid.Row = C_main.Grid.Rows - 1
            End If
        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
    ls_Req = "EXEC Claim_Letter_del " _
        & gs_TableCode & ", " _
        & gs_TableCode2
    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
        C_main.FillGrid
    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 GetCaptions()

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

ls_Req = "EXEC Screen_Csts 'mtnc_letclai', '" & 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 = 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_Nature": lbl_Nature.Caption = ls_Text
        Case "lbl_Desc": lbl_Desc = 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 Function Control() As Boolean

Control = KO
If cbo_Nature = "" Then
    cbo_Nature.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If txt_Desc = "" Then
    txt_Desc.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
Control = OK

End Function
