VERSION 5.00
Begin VB.Form Quot_SalesReps 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "List of sales reps"
   ClientHeight    =   4125
   ClientLeft      =   420
   ClientTop       =   1605
   ClientWidth     =   7815
   ControlBox      =   0   'False
   LinkTopic       =   "Form4"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4125
   ScaleWidth      =   7815
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton spp_save 
      Height          =   615
      Left            =   6300
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   3300
      Width           =   615
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   615
      Left            =   6960
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   3300
      Width           =   615
   End
   Begin VB.CommandButton Btn_AllList 
      Caption         =   "All list"
      Height          =   375
      Left            =   2097
      TabIndex        =   8
      Top             =   3120
      Width           =   1215
   End
   Begin VB.PictureBox pic_Out 
      AutoSize        =   -1  'True
      Height          =   408
      Left            =   3720
      ScaleHeight     =   345
      ScaleWidth      =   345
      TabIndex        =   5
      Top             =   1920
      Width           =   408
   End
   Begin VB.PictureBox pic_In 
      AutoSize        =   -1  'True
      Height          =   408
      Left            =   3720
      ScaleHeight     =   345
      ScaleWidth      =   345
      TabIndex        =   4
      Top             =   1200
      Width           =   408
   End
   Begin VB.ListBox lst_Selected 
      Height          =   2595
      ItemData        =   "Q_SalesReps.frx":0000
      Left            =   4500
      List            =   "Q_SalesReps.frx":0002
      TabIndex        =   3
      Top             =   420
      Width           =   3012
   End
   Begin VB.ListBox lst_NotSelected 
      Height          =   2595
      ItemData        =   "Q_SalesReps.frx":0004
      Left            =   300
      List            =   "Q_SalesReps.frx":0006
      TabIndex        =   2
      Top             =   420
      Width           =   3012
   End
   Begin VB.Label lbl_Selected 
      Alignment       =   2  'Center
      Caption         =   "Selected"
      Height          =   255
      Left            =   4500
      TabIndex        =   7
      Top             =   120
      Width           =   3015
   End
   Begin VB.Label lbl_NotSelected 
      Alignment       =   2  'Center
      Caption         =   "Not selected"
      Height          =   255
      Left            =   300
      TabIndex        =   6
      Top             =   120
      Width           =   3015
   End
End
Attribute VB_Name = "Quot_SalesReps"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public mb_Return As Boolean

Public mo_SelectedCode As New Collection
Public mo_SelectedDesc As New Collection

Public ms_ScreenName As String
Public ms_LanguageCode As String

Public ms_DBRequest As String
Public ms_DBRequestAll As String

Public mb_ShowAll As Boolean

Private mo_lst_SelectedCode As New Collection
Private mo_lst_UnselectedCode As New Collection

Private Sub GetCaptions()
Dim ls_Field As String
Dim ls_Text As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Req As String

    On Error GoTo suite
    ls_Req = "EXEC Screen_Csts '" & ms_ScreenName & "', '" & ms_LanguageCode & "'"
    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 = ODBCData(ll_Statement, 2)
            Select Case ls_Field
                Case "title": Quot_SalesReps.Caption = ls_Text
                Case "lbl_selected": lbl_Selected.Caption = ls_Text
                Case "lbl_notselected": lbl_NotSelected.Caption = ls_Text
                Case "btn_alllist": Btn_AllList.Caption = ls_Text
            End Select
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
suite:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub

Private Sub FillSelectedList()
Dim i As Integer

    lst_Selected.Clear
    For i = mo_lst_SelectedCode.Count To 1 Step -1
        mo_lst_SelectedCode.Remove i
    Next
    For i = 1 To mo_SelectedCode.Count
        lst_Selected.AddItem mo_SelectedDesc.Item(i)
        mo_lst_SelectedCode.Add mo_SelectedCode.Item(i)
    Next
End Sub

Private Sub FillUnSelectedList(ls_Req As String)
Dim ll_Statement As Long
Dim li_Status As Integer
Dim i As Integer
Dim lb_Found As Boolean
Dim lo_code

    lst_NotSelected.Clear
    For i = mo_lst_UnselectedCode.Count To 1 Step -1
        mo_lst_UnselectedCode.Remove i
    Next
    
    On Error GoTo FillUnSelectedList_Err
        
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        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
                lo_code = ODBCData(ll_Statement, 1)
                lb_Found = KO
                For i = 1 To mo_lst_SelectedCode.Count
                    If mo_SelectedCode.Item(i) = lo_code Then
                        lb_Found = OK
                        Exit For
                    End If
                Next
                If lb_Found = KO Then
                    mo_lst_UnselectedCode.Add lo_code
                    lst_NotSelected.AddItem ODBCData(ll_Statement, 2)
                End If
            End If
        Loop
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    End If
    
    Exit Sub
    
FillUnSelectedList_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError

End Sub

Private Function RemoveCollection(ByRef lo_Collection As Collection, ByVal lo_code As Variant) As Boolean
    RemoveCollection = KO
    
    On Error GoTo RemoveCollection_Err
    
    lo_Collection.Remove CStr(lo_code)
    
    RemoveCollection = OK

    Exit Function
    
RemoveCollection_Err:

End Function

Private Function AddCollection(ByRef lo_Collection As Collection, ByVal lo_code As Variant) As Boolean
    AddCollection = KO
    
    On Error GoTo AddCollection_Err
    
    lo_Collection.Add lo_code, CStr(lo_code)
    
    AddCollection = OK

    Exit Function

AddCollection_Err:

End Function

Private Sub Btn_AllList_Click()
    Btn_AllList.Visible = KO
    DoEvents
    FillUnSelectedList ms_DBRequestAll
End Sub

Private Sub Form_Initialize()
    mb_ShowAll = True
End Sub

Private Sub Form_Load()
Dim i As Integer

    MouseOff
    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me
    
    mb_Return = KO
    
    spp_save.Picture = LoadResPicture(RES_OK, 1)
    ssp_quit.Picture = LoadResPicture(RES_QUIT, 1)
    pic_In.Picture = LoadResPicture(RES_RIGHT, 1)
    pic_Out.Picture = LoadResPicture(RES_LEFT, 1)
    
    If ms_DBRequestAll = "" Then
        Btn_AllList.Visible = KO
    End If
    
    If mb_ShowAll = False Then
        Btn_AllList.Visible = KO
    Else
        Btn_AllList.Visible = OK
    End If
    
    GetCaptions
    
    FillSelectedList
    FillUnSelectedList ms_DBRequest
    
    MouseOn
    
End Sub

Private Sub pic_In_Click()
Dim lo_code
Dim lo_desc
    
    If lst_NotSelected.ListIndex <> -1 Then
        lo_code = mo_lst_UnselectedCode.Item(lst_NotSelected.ListIndex + 1)
        lo_desc = lst_NotSelected.Text
        
        AddCollection mo_SelectedCode, lo_code
        AddCollection mo_SelectedDesc, lo_desc
        
        lst_Selected.AddItem lo_desc
        mo_lst_SelectedCode.Add lo_code

        mo_lst_UnselectedCode.Remove lst_NotSelected.ListIndex + 1
        lst_NotSelected.RemoveItem lst_NotSelected.ListIndex
    End If
End Sub

Private Sub pic_Out_Click()
Dim i As Integer
Dim lo_code
Dim lo_desc
    
    If lst_Selected.ListIndex <> -1 Then
        lo_code = mo_lst_SelectedCode.Item(lst_Selected.ListIndex + 1)
        lo_desc = lst_Selected.Text
        
        For i = mo_SelectedCode.Count To 1 Step -1
            If mo_SelectedCode.Item(i) = lo_code Then
                mo_SelectedCode.Remove i
                mo_SelectedDesc.Remove i
                Exit For
            End If
        Next
                
        lst_NotSelected.AddItem lo_desc
        mo_lst_UnselectedCode.Add lo_code
        
        mo_lst_SelectedCode.Remove lst_Selected.ListIndex + 1
        lst_Selected.RemoveItem lst_Selected.ListIndex
    End If
End Sub

Private Sub spp_save_Click()
Dim i As Integer

    mb_Return = OK
    Unload Me
    
End Sub

Private Sub ssp_quit_Click()
    
    mb_Return = KO
    Unload Me
    
End Sub
