VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Begin VB.Form Salreps_mtnc 
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   4950
   ClientLeft      =   1455
   ClientTop       =   1260
   ClientWidth     =   7035
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4950
   ScaleWidth      =   7035
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton spp_save 
      Default         =   -1  'True
      Height          =   612
      Left            =   5580
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   4140
      Width           =   612
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   612
      Left            =   6240
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   4140
      Width           =   612
   End
   Begin VB.CommandButton SSC_dropped 
      Height          =   276
      Left            =   3240
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   4440
      Width           =   252
   End
   Begin VB.CheckBox chk_Int 
      Caption         =   "Check1"
      Height          =   252
      Left            =   2040
      TabIndex        =   4
      Top             =   4080
      Width           =   252
   End
   Begin VB.TextBox txt_dropped 
      ForeColor       =   &H00FF0000&
      Height          =   288
      Left            =   2040
      Locked          =   -1  'True
      TabIndex        =   7
      Top             =   4440
      Width           =   1212
   End
   Begin VB.TextBox txt_info 
      Height          =   1575
      Left            =   240
      MaxLength       =   240
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   2400
      Width           =   6615
   End
   Begin VB.TextBox Txt_tel 
      Height          =   285
      Left            =   240
      MaxLength       =   20
      TabIndex        =   0
      Top             =   1440
      Width           =   2055
   End
   Begin VB.TextBox Txt_fax 
      Height          =   285
      Left            =   2520
      MaxLength       =   20
      TabIndex        =   1
      Top             =   1440
      Width           =   2055
   End
   Begin VB.TextBox Txt_mobile 
      Height          =   285
      Left            =   4800
      MaxLength       =   20
      TabIndex        =   2
      Top             =   1440
      Width           =   2055
   End
   Begin MSForms.ComboBox cbo_Name 
      Height          =   315
      Left            =   240
      TabIndex        =   16
      Top             =   600
      Width           =   3135
      VariousPropertyBits=   679479323
      DisplayStyle    =   7
      Size            =   "5530;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   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        =   15
      Top             =   4440
      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        =   14
      Top             =   4080
      Width           =   1452
   End
   Begin VB.Label Lbl_name 
      Alignment       =   2  'Center
      Caption         =   "Name"
      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             =   300
      Width           =   3132
   End
   Begin VB.Label Lbl_info 
      Alignment       =   2  'Center
      Caption         =   "Info"
      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             =   2040
      Width           =   5652
   End
   Begin VB.Label Lbl_tel 
      Alignment       =   2  'Center
      Caption         =   "Phone"
      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        =   9
      Top             =   1080
      Width           =   2052
   End
   Begin VB.Label Lbl_fax 
      Alignment       =   2  'Center
      Caption         =   "Fax"
      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            =   2520
      TabIndex        =   8
      Top             =   1080
      Width           =   2052
   End
   Begin VB.Label Lbl_mobile 
      Alignment       =   2  'Center
      Caption         =   "Mobile"
      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            =   4800
      TabIndex        =   5
      Top             =   1080
      Width           =   2052
   End
End
Attribute VB_Name = "Salreps_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cbo_Name_DropButtonClick()
Dim lv_Value As Variant
    
MouseOff

If cbo_Name.Tag = UNLOADED Then
    lv_Value = MCombo_GetCode(cbo_Name)
    cbo_Name.Clear
    MCombo_Fill cbo_Name, "Exec Security_Identity_cbo3 "
    MCombo_CodeSelect(cbo_Name) = lv_Value
    cbo_Name.Tag = Loaded
End If

MouseOn

End Sub
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)
SSC_dropped.Picture = LoadResPicture(RES_DOWN2, vbResIcon)

GetConstants
cbo_Name.Clear
cbo_Name.Tag = UNLOADED

Select Case gs_Action
Case "Delete", "MoreInfo"
    cbo_Name.Enabled = KO
    Txt_tel.Enabled = KO
    Txt_fax.Enabled = KO
    Txt_mobile.Enabled = KO
    txt_info.Enabled = KO
    SSC_dropped.Visible = KO
    chk_Int.Enabled = KO
End Select
If gs_Action <> "Add" Then
    cbo_Name.Enabled = KO
    MCombo_AddItemCode cbo_Name, gs_TableCode, gs_TableCode2
    Txt_tel = gs_TableCode3
    Txt_fax = gs_TableCode4
    Txt_mobile = gs_TableCode5
    txt_info = gs_TableCode6
    txt_dropped = gs_TableCode9
    If gs_TableCode8 = "X" Then
        chk_Int.value = 1
    End If
End If
If gs_Action = "MoreInfo" Then
    spp_save.Visible = KO
End If
MouseOn
Exit Sub

suite:
StdError
End Sub

Private Sub spp_save_Click()

MouseOff
gb_Return = OK
Select Case gs_Action
Case "Add"
    If AddRow Then
        cbo_Name.Clear
        cbo_Name.Tag = UNLOADED
        Txt_tel = ""
        Txt_fax = ""
        Txt_mobile = ""
        txt_info = ""
        chk_Int.value = 0
        txt_dropped = ""
        If gl_NbLineDisplay < 2 Then
            C_main.FillGrid
        End If
    End If
Case "Update"
    If UpdateRow Then
        Unload Me
    End If
Case "Delete"
    If DeleteRow Then
        Unload Me
    End If
End Select
MouseOn

End Sub
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()

MouseOff
Unload Me

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_dropped <> "" Then
        ls_DropFlag = "X"
        ls_DropDate = FormatD(txt_dropped, "mm/dd/yyyy")
    End If
    ls_Req = "EXEC Sales_Reps_upd '" & QuoteParam(gs_TableCode) & "', '" & QuoteParam(Txt_tel) & "','" _
        & QuoteParam(Txt_fax) & "','" & QuoteParam(Txt_mobile) & "','" _
        & QuoteParam(txt_info) & "', " & gs_TableCode7 & ",'" _
        & ls_IntFlag & "','" & ls_DropFlag & "','" & ls_DropDate & "'"
    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 3, "Update failed", gut_LangLogin.Code
            C_main.FillGrid
        Else
            UpdateRow = OK
            C_main.Grid.RemoveItem C_main.Grid.Row
            ls_Line = gs_TableCode & Chr(9) & cbo_Name.Text & Chr(9) & Txt_tel & Chr(9) & Txt_fax & Chr(9) & Txt_mobile & Chr(9) & txt_info & Chr(9) & CInt(gs_TableCode7) + 1 & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
            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
Dim ls_IntFlag As String
Dim ls_DropFlag As String
Dim ls_DropDate As String
Dim ls_Code As String

AddRow = KO

On Error GoTo suite

If Control Then
    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

    ls_Req = "EXEC Sales_Reps_ins '" & QuoteParam(cbo_Name.Text) & "', '" _
        & QuoteParam(Txt_tel) & "', '" & QuoteParam(Txt_fax) & "', '" & QuoteParam(Txt_mobile) & "', '" & QuoteParam(txt_info) & "', '" _
        & 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
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                ls_Code = ODBCData(ll_Statement, 1)
                AddRow = OK
            End If
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        
            ls_Line = ls_Code & Chr(9) & cbo_Name.Text & Chr(9) & Txt_tel & Chr(9) & Txt_fax & Chr(9) & Txt_mobile & Chr(9) & txt_info & Chr(9) & 1 & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped
            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
    ls_Req = "EXEC Sales_Reps_del '" _
      & QuoteParam(gs_TableCode) & "', " & gs_TableCode7
    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 : concurency 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
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

ls_Req = "EXEC Screen_Csts 'mtnc_salreps', '" & 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 "titleI": If gs_Action = "MoreInfo" Then Caption = Caption & " - " & ls_Text
        Case "lbl_name": Lbl_name = ls_Text
        Case "lbl_info": Lbl_info = ls_Text
        Case "lbl_tel": Lbl_tel.Caption = ls_Text
        Case "lbl_fax": Lbl_fax = ls_Text
        Case "lbl_mobile": Lbl_mobile = ls_Text
        Case "lbl_int": lbl_Int = ls_Text
        Case "lbl_drop": lbl_Drop = 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 MCombo_GetCode(cbo_Name) = "" Then
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    cbo_Name.SetFocus
    Exit Function
End If
Control = OK

End Function

