VERSION 5.00
Begin VB.Form Territo_mtnc 
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   4710
   ClientLeft      =   1515
   ClientTop       =   1410
   ClientWidth     =   6030
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4710
   ScaleWidth      =   6030
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton spp_save 
      Default         =   -1  'True
      Height          =   612
      Left            =   4620
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   3936
      Width           =   612
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   612
      Left            =   5280
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   3936
      Width           =   612
   End
   Begin VB.CommandButton SSC_dropped 
      Height          =   276
      Left            =   3120
      Style           =   1  'Graphical
      TabIndex        =   16
      Top             =   4320
      Width           =   252
   End
   Begin VB.CheckBox chk_Int 
      Caption         =   "Check1"
      Height          =   252
      Left            =   1920
      TabIndex        =   4
      Top             =   3960
      Width           =   252
   End
   Begin VB.TextBox txt_dropped 
      ForeColor       =   &H00FF0000&
      Height          =   288
      Left            =   1920
      Locked          =   -1  'True
      TabIndex        =   5
      Top             =   4320
      Width           =   1212
   End
   Begin VB.TextBox txt_code 
      Height          =   285
      Left            =   240
      MaxLength       =   4
      TabIndex        =   0
      Top             =   480
      Width           =   1095
   End
   Begin VB.TextBox Txt_descr 
      Height          =   285
      Left            =   1440
      MaxLength       =   40
      TabIndex        =   1
      Top             =   480
      Width           =   3135
   End
   Begin VB.TextBox txt_info 
      Height          =   2055
      Left            =   240
      MaxLength       =   240
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   1740
      Width           =   5655
   End
   Begin VB.ComboBox cbo_country 
      Height          =   288
      Left            =   240
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   1080
      Width           =   2532
   End
   Begin VB.ComboBox cbo_CountryCode 
      Height          =   288
      Left            =   2160
      Style           =   2  'Dropdown List
      TabIndex        =   6
      Top             =   1080
      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        =   15
      Top             =   4320
      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             =   3960
      Width           =   1452
   End
   Begin VB.Label lbl_screen 
      Caption         =   "Territo3"
      Height          =   252
      Left            =   300
      TabIndex        =   11
      Top             =   2340
      Visible         =   0   'False
      Width           =   852
   End
   Begin VB.Label Lbl_descr 
      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            =   1440
      TabIndex        =   10
      Top             =   240
      Width           =   3132
   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            =   240
      TabIndex        =   9
      Top             =   240
      Width           =   1092
   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        =   8
      Top             =   1500
      Width           =   5652
   End
   Begin VB.Label lbl_country 
      Alignment       =   2  'Center
      Caption         =   "Country"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   228
      Left            =   240
      TabIndex        =   7
      Top             =   876
      Width           =   2532
   End
End
Attribute VB_Name = "Territo_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim mi_concurrency As Integer

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

spp_save.Picture = LoadResPicture(RES_OK, 1)
ssp_quit.Picture = LoadResPicture(RES_QUIT, 1)
SSC_dropped.Picture = LoadResPicture(RES_DOWN2, vbResIcon)

mtnc_territo_cst
Select Case gs_Action
Case "MoreInfo"
    txt_code.Locked = OK
    Txt_descr.Locked = OK
    cbo_country.Enabled = KO
    txt_info.Locked = OK
    spp_save.Visible = KO
    txt_code = gs_TableCode
    Txt_descr = gs_TableCode2
    cbo_country.AddItem gs_TableCode4
    cbo_country.ListIndex = 0
    txt_info = gs_TableCode3
    If gs_TableCode5 = "X" Then
        chk_Int.value = 1
    End If
    txt_dropped = gs_TableCode6
    SSC_dropped.Visible = KO
    chk_Int.Enabled = KO
Case "Add"
    FillCbo "Countries", cbo_CountryCode, cbo_country
Case "Update"
    FillCbo "Countries", cbo_CountryCode, cbo_country
    txt_code.Enabled = KO
    txt_code = gs_TableCode
    Txt_descr = gs_TableCode2
    cbo_country.ListIndex = ComboFindItem(cbo_CountryCode, gs_TableCode7)
    txt_info = gs_TableCode3
    If gs_TableCode5 = "X" Then
        chk_Int.value = 1
    End If
    txt_dropped = gs_TableCode6
Case "Delete"
    txt_code.Enabled = KO
    Txt_descr.Enabled = KO
    cbo_country.Enabled = KO
    txt_info.Enabled = KO
    txt_code = gs_TableCode
    Txt_descr = gs_TableCode2
    cbo_country.AddItem gs_TableCode4
    cbo_country.ListIndex = 0
    txt_info = gs_TableCode3
    SSC_dropped.Visible = KO
    chk_Int.Enabled = KO
    If gs_TableCode5 = "X" Then
        chk_Int.value = 1
    End If
    txt_dropped = gs_TableCode6
End Select
MouseOn
Exit Sub

suite:
StdError
End Sub
Private Sub spp_save_Click()

MouseOff
gb_Return = OK
Select Case gs_Action
Case "Add"
    If Add_Table Then
        txt_code = ""
        Txt_descr = ""
        txt_info = ""
        cbo_country.ListIndex = -1
        txt_dropped = ""
        chk_Int.value = 0
        txt_code.SetFocus
        If gl_NbLineDisplay < 2 Then
            C_main.FillGrid
        End If
      End If
Case "Update"
    If Upd_Table Then
        Unload Me
    End If
Case "Delete"
    If Dlt_Table 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 Upd_Table() 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

Upd_Table = 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 Territories_upd '" _
        & QuoteParam(gs_TableCode) & "', '" _
        & QuoteParam(Txt_descr) & "', '" _
        & QuoteParam(txt_info) & "', '" _
        & QuoteParam(cbo_CountryCode.List(cbo_country.ListIndex)) & "', " _
        & gs_TableCode8 & ",'" _
        & 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 2, "Another user change the record", gut_LangLogin.Code
            C_main.FillGrid
        Else
            Upd_Table = OK
            C_main.Grid.RemoveItem C_main.Grid.Row
            ls_Line = gs_TableCode & Chr(9) & Txt_descr & Chr(9) & txt_info & Chr(9) & cbo_country & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped & Chr(9) & cbo_CountryCode & Chr(9) & CInt(gs_TableCode8) + 1
            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 Add_Table() 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

Add_Table = 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 Territories_ins '" _
        & UCase(QuoteParam(txt_code)) & "', '" _
        & QuoteParam(Txt_descr) & "', '" _
        & QuoteParam(txt_info) & "','" _
        & QuoteParam(cbo_CountryCode.List(cbo_country.ListIndex)) & "','" _
        & 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 4, "Insert failed", gut_LangLogin.Code
            C_main.FillGrid
        Else
            Add_Table = OK
            ls_Line = UCase(txt_code) & Chr(9) & Txt_descr & Chr(9) & txt_info & Chr(9) & cbo_country & Chr(9) & cbo_CountryCode.List(cbo_country.ListIndex) & Chr(9) & 1
            ls_Line = UCase(txt_code) & Chr(9) & Txt_descr & Chr(9) & txt_info & Chr(9) & cbo_country & Chr(9) & ls_IntFlag & Chr(9) & txt_dropped & Chr(9) & cbo_CountryCode.List(cbo_country.ListIndex) & Chr(9) & 1
            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 Dlt_Table() As Boolean

Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long

Dlt_Table = KO

On Error GoTo suite

MouseOn
If SendMessage(5, "Delete record ?", gut_LangLogin.Code, vbQuestion + vbYesNo, "Delete ") = vbYes Then
    MouseOff
    ls_Req = "EXEC Territories_del '" _
        & QuoteParam(gs_TableCode) & "', " & gs_TableCode8
    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
            Dlt_Table = 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 mtnc_territo_cst()

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_territo', '" & 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_descr": Lbl_descr = ls_Text
        Case "lbl_info": Lbl_info = ls_Text
        Case "lbl_country": lbl_country = 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 txt_code = "" Then
    txt_code.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If Txt_descr = "" Then
    Txt_descr.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
If Len(Txt_descr) < 4 Then
    Txt_descr.SetFocus
    SendMessage 11, "Value must be more than 3 characters long", gut_LangLogin.Code
    Exit Function
End If
If cbo_country.Text = "" Then
    cbo_country.SetFocus
    SendMessage 8, "Value must be filled in", gut_LangLogin.Code
    Exit Function
End If
Control = OK

End Function

