VERSION 5.00
Begin VB.Form Salrepa_mtnc 
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   4410
   ClientLeft      =   1650
   ClientTop       =   1320
   ClientWidth     =   5640
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4410
   ScaleWidth      =   5640
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton spp_save 
      Default         =   -1  'True
      Height          =   612
      Left            =   4200
      Style           =   1  'Graphical
      TabIndex        =   17
      Top             =   3660
      Width           =   612
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   612
      Left            =   4860
      Style           =   1  'Graphical
      TabIndex        =   16
      Top             =   3660
      Width           =   612
   End
   Begin VB.CommandButton SSC_dropped 
      Height          =   288
      Left            =   3240
      Style           =   1  'Graphical
      TabIndex        =   20
      Top             =   3960
      Width           =   252
   End
   Begin VB.CommandButton ssc_end 
      Height          =   288
      Left            =   5160
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   1440
      Width           =   252
   End
   Begin VB.TextBox Txt_end 
      Height          =   285
      Left            =   3060
      Locked          =   -1  'True
      TabIndex        =   19
      Top             =   1440
      Width           =   2055
   End
   Begin VB.CommandButton ssc_start 
      Height          =   288
      Left            =   2280
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   1440
      Width           =   252
   End
   Begin VB.CheckBox chk_Int 
      Caption         =   "Check1"
      Height          =   252
      Left            =   2040
      TabIndex        =   4
      Top             =   3600
      Width           =   252
   End
   Begin VB.TextBox txt_dropped 
      ForeColor       =   &H00FF0000&
      Height          =   288
      Left            =   2040
      Locked          =   -1  'True
      TabIndex        =   5
      Top             =   3960
      Width           =   1212
   End
   Begin VB.ComboBox Cbo_territory 
      Height          =   288
      Left            =   3060
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   600
      Width           =   2352
   End
   Begin VB.ComboBox Cbo_code 
      Height          =   288
      Left            =   180
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   600
      Width           =   2412
   End
   Begin VB.TextBox Txt_start 
      Height          =   285
      Left            =   180
      Locked          =   -1  'True
      TabIndex        =   2
      Top             =   1440
      Width           =   2055
   End
   Begin VB.TextBox Txt_info 
      Height          =   1215
      Left            =   180
      MaxLength       =   240
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   2220
      Width           =   5295
   End
   Begin VB.ComboBox cbo_CodeCode 
      Height          =   288
      Left            =   1980
      Style           =   2  'Dropdown List
      TabIndex        =   7
      Top             =   600
      Visible         =   0   'False
      Width           =   396
   End
   Begin VB.ComboBox cbo_TerritoryCode 
      Height          =   288
      Left            =   4800
      Style           =   2  'Dropdown List
      TabIndex        =   6
      Top             =   600
      Visible         =   0   'False
      Width           =   396
   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        =   18
      Top             =   3960
      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        =   15
      Top             =   3600
      Width           =   1452
   End
   Begin VB.Label Lbl_code 
      Alignment       =   2  'Center
      Caption         =   "Code"
      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        =   14
      Top             =   240
      Width           =   2412
   End
   Begin VB.Label Lbl_territory 
      Alignment       =   2  'Center
      Caption         =   "Territory"
      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            =   3060
      TabIndex        =   13
      Top             =   240
      Width           =   2412
   End
   Begin VB.Label Lbl_start 
      Alignment       =   2  'Center
      Caption         =   "Start"
      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        =   12
      Top             =   1080
      Width           =   2412
   End
   Begin VB.Label Lbl_end 
      Alignment       =   2  'Center
      Caption         =   "End"
      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            =   3060
      TabIndex        =   11
      Top             =   1080
      Width           =   2412
   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            =   120
      TabIndex        =   8
      Top             =   1920
      Width           =   5412
   End
End
Attribute VB_Name = "Salrepa_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'what is new
'2.7.1 View selection for sales rep assignement (JN)

Private Sub Cbo_code_Click()

MouseOff
If Cbo_code.ListIndex <> -1 And Cbo_code.Visible Then
    If cbo_CodeCode.ItemData(Cbo_code.ListIndex) = 1 Then
        SendMessage 70, "Inactive item", gut_LangLogin.Code
    End If
End If
MouseOn

End Sub
Private Sub Cbo_territory_Click()

MouseOff
If Cbo_territory.ListIndex <> -1 And Cbo_territory.Visible Then
    If cbo_TerritoryCode.ItemData(Cbo_territory.ListIndex) = 1 Then
        SendMessage 70, "Inactive item", gut_LangLogin.Code
    End If
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)
ssc_start.Picture = LoadResPicture(RES_DOWN2, vbResIcon)
ssc_end.Picture = LoadResPicture(RES_DOWN2, vbResIcon)

GetConstants
Select Case gs_Action
Case "Add"
    FillCbo "Sales_Reps", cbo_CodeCode, Cbo_code
    FillCbo "Territory", cbo_TerritoryCode, Cbo_territory
Case Else
    Cbo_code.Enabled = KO
    Cbo_territory.Enabled = KO
    Cbo_code.AddItem gs_TableCode2
    Cbo_code.ListIndex = 0
    Cbo_territory.AddItem gs_TableCode4
    Cbo_territory.ListIndex = 0
    Txt_start = gs_TableCode5
    Txt_end = gs_TableCode6
    Txt_info = gs_TableCode7
    If gs_TableCode9 = "X" Then
        chk_Int.value = 1
    End If
    txt_dropped = gs_TableCode10
    If gs_Action = "MoreInfo" Then
        ssc_start.Visible = KO
        ssc_end.Visible = KO
        Txt_info.Locked = OK
        SSC_dropped.Visible = KO
        chk_Int.Enabled = KO
        spp_save.Visible = KO
    ElseIf gs_Action = "Delete" Then
        ssc_start.Visible = KO
        ssc_end.Visible = KO
        Txt_info.Enabled = KO
        SSC_dropped.Visible = KO
        chk_Int.Enabled = KO
    End If
End Select

Cbo_territory.Visible = (gs_TableCode11 = "1")        ' 11/07/2013 JN territory visible only for Claim view
Lbl_territory.Visible = (gs_TableCode11 = "1")

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_code.ListIndex = -1
        Cbo_territory.ListIndex = -1
        Txt_start = ""
        Txt_end = ""
        Txt_info = ""
        chk_Int.value = 0
        txt_dropped = ""
        If gl_NbLineDisplay < 2 Then
            C_main.FillGrid
        End If
        Cbo_code.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 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 ssc_end_Click()

On Error GoTo suite

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

Exit Sub

suite:
StdError
End Sub
Private Sub ssc_start_Click()

On Error GoTo suite

MouseOff
gb_Return = KO
gs_Date = Txt_start
Dates.show 1
If gb_Return Then
    Txt_start = 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_Assignement_upd '" _
        & QuoteParam(gs_TableCode) & "', '" & QuoteParam(gs_TableCode3) & "', '" _
        & FormatD(Txt_start, "mm/dd/yyyy") & "', '" _
        & FormatD(Txt_end, "mm/dd/yyyy") & "', '" _
        & QuoteParam(Txt_info) & "', " _
        & gs_TableCode8 & ",'" _
        & ls_IntFlag & "','" & ls_DropFlag & "','" & ls_DropDate & "'," & gs_TableCode11
    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) & gs_TableCode2 & Chr(9) & gs_TableCode3 & Chr(9) & gs_TableCode4 & Chr(9) & Txt_start & Chr(9) & Txt_end & Chr(9) & Txt_info & Chr(9) & CInt(gs_TableCode8) + 1 & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped & Chr(9) & gs_TableCode11
            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

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_Assignement_ins '" _
        & QuoteParam(cbo_CodeCode.List(Cbo_code.ListIndex)) & "', '" _
        & QuoteParam(cbo_TerritoryCode.List(Cbo_territory.ListIndex)) & "', '" _
        & FormatD(Txt_start, "mm/dd/yyyy") & "', '" _
        & FormatD(Txt_end, "mm/dd/yyyy") & "', '" _
        & QuoteParam(Txt_info) & "','" _
        & ls_IntFlag & "','" & ls_DropFlag & "','" & ls_DropDate & "'," & gs_TableCode11
    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
            ls_Line = cbo_CodeCode.List(Cbo_code.ListIndex) & Chr(9) & Cbo_code & Chr(9) & cbo_TerritoryCode.List(Cbo_territory.ListIndex) & Chr(9) & Cbo_territory & Chr(9) & Txt_start & Chr(9) & Txt_end & Chr(9) & Txt_info & Chr(9) & 1 & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped & Chr(9) & gs_TableCode11
            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
        C_main.FillGrid
    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_Assignement_del '" _
        & QuoteParam(gs_TableCode) & "', '" _
        & QuoteParam(gs_TableCode3) & "', " _
        & gs_TableCode8 & "," & gs_TableCode11
    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
Dim ls_Text As String

On Error GoTo suite

ls_req = "EXEC Screen_Csts 'mtnc_salrepa', '" & 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_code": lbl_Code.Caption = ls_Text
        Case "lbl_territory": Lbl_territory = ls_Text
        Case "lbl_start": Lbl_start = ls_Text
        Case "lbl_end": Lbl_end = ls_Text
        Case "lbl_info": Lbl_info = 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 Cbo_code = "" Then
    Cbo_code.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If Cbo_territory = "" Then
    If gs_TableCode11 = "1" Then     ' JN 11/07/2013 - for claim view TER_Code is mandatory
        Cbo_territory.SetFocus
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Exit Function
    End If
End If
If Txt_start = "" Then
    Txt_start.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If Txt_end = "" Then
    Txt_end.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If IsDateGreater(Txt_start, Txt_end) Then
    SendMessage 23, "Ending date must be greather than starting date", gut_LangLogin.Code
    Exit Function
End If
Control = OK

End Function

