VERSION 5.00
Begin VB.Form PFG_PE_mtnc 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "PFGroup Edges"
   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.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        =   "Pfg_pe.frx":0000
      Left            =   4500
      List            =   "Pfg_pe.frx":0002
      TabIndex        =   3
      Top             =   420
      Width           =   3012
   End
   Begin VB.ListBox lst_NotSelected 
      Height          =   2595
      ItemData        =   "Pfg_pe.frx":0004
      Left            =   300
      List            =   "Pfg_pe.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 = "PFG_PE_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public mb_Return As Boolean


Public ms_ScreenName As String
Public ms_LanguageCode As String

'collections pour les Edges selectionnés
Public mo_lst_Selected_code As New Collection
Public mo_lst_Selected_desc As New Collection
Public mo_lst_Selected_conc As New Collection
'collections pour les Edges non selectionnés
Public mo_lst_NotSelected_code As New Collection
Public mo_lst_NotSelected_desc As New Collection
Public mo_lst_NotSelected_conc As New Collection
'collections pour les Edges à selectionner
Public mo_lst_ToInsert_code As New Collection
'collections pour les Edges à déselectionner
Public mo_lst_ToDelete_code As New Collection
Public mo_lst_ToDelete_conc As New Collection
Public ma_Collection As New Collection


Public Sub CountCollItems()
    MsgBox "(NotSelected) code: " + Str(mo_lst_NotSelected_code.Count) + " iconc: " + Str(mo_lst_NotSelected_conc.Count) + Chr(13) _
    + "(Selected) code: " + Str(mo_lst_Selected_code.Count) + " iconc: " + Str(mo_lst_Selected_conc.Count)
End Sub

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": Me.Caption = ls_Text
                Case "lbl_selected": lbl_Selected.Caption = ls_Text
                Case "lbl_notselected": lbl_NotSelected.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

Public Sub ClearCollections()
Dim i As Integer

    For i = mo_lst_Selected_code.Count To 1 Step -1
        mo_lst_Selected_code.Remove i
        mo_lst_Selected_desc.Remove i
        mo_lst_Selected_conc.Remove i
    Next
    For i = mo_lst_NotSelected_code.Count To 1 Step -1
        mo_lst_NotSelected_code.Remove i
        mo_lst_NotSelected_desc.Remove i
        mo_lst_NotSelected_conc.Remove i
    Next
    For i = mo_lst_ToInsert_code.Count To 1 Step -1
        mo_lst_ToInsert_code.Remove i
    Next
    For i = mo_lst_ToDelete_code.Count To 1 Step -1
        mo_lst_ToDelete_code.Remove i
        mo_lst_ToDelete_conc.Remove i
    Next

End Sub

Private Sub FillSelectedList()
Dim i As Integer
    lst_Selected.Clear
    For i = 1 To PFG_PE_mtnc.mo_lst_Selected_desc.Count
        lst_Selected.AddItem PFG_PE_mtnc.mo_lst_Selected_desc.Item(i)
    Next
End Sub

Private Sub FillNotSelectedList()
Dim i As Integer
    lst_NotSelected.Clear
    For i = 1 To PFG_PE_mtnc.mo_lst_NotSelected_desc.Count
        lst_NotSelected.AddItem PFG_PE_mtnc.mo_lst_NotSelected_desc.Item(i)
    Next
End Sub

Private Sub UpdNotSelectedList()
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim i As Integer
    
    ls_Req = "EXEC PFGroup_Edges_t_sel3 '" & QuoteParam(gs_TableCode) & "','" & gut_LangLogin.Code & "','C001'"
    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
            PFG_PE_mtnc.mo_lst_NotSelected_code.Add ODBCData(ll_Statement, 1)
            PFG_PE_mtnc.mo_lst_NotSelected_desc.Add ODBCData(ll_Statement, 2)
            PFG_PE_mtnc.mo_lst_NotSelected_conc.Add 1
        End If
    Loop
End Sub

Private Sub UpdToInsertList()
Dim i As Integer
Dim lb_removed As Boolean

    i = 0
    lb_removed = False
    
    'parcours de la liste des objets à effacer
    While i <> mo_lst_ToDelete_code.Count And lb_removed = False
        'si présent dans la liste, on l'efface...
        If mo_lst_ToDelete_code.Item(i + 1) = mo_lst_NotSelected_code.Item(lst_NotSelected.ListIndex + 1) Then
            mo_lst_ToDelete_code.Remove i + 1
            mo_lst_ToDelete_conc.Remove i + 1
            lb_removed = True
        End If
        i = i + 1
    Wend
    '...sinon on l'ajoute dans la liste des objets à inserer
    If lb_removed = False Then
        mo_lst_ToInsert_code.Add mo_lst_NotSelected_code.Item(lst_NotSelected.ListIndex + 1)
    End If
        
End Sub

Private Sub UpdToDeleteList()
Dim i As Integer
Dim lb_inserted As Boolean

    i = 0
    lb_inserted = False
    
    'parcours de la liste des objets à inserer
    While i <> mo_lst_ToInsert_code.Count And lb_inserted = False
        'si présent dans la liste, on l'efface...
        If mo_lst_ToInsert_code.Item(i + 1) = mo_lst_Selected_code.Item(lst_Selected.ListIndex + 1) Then
            mo_lst_ToInsert_code.Remove i + 1
            lb_inserted = True
        End If
        i = i + 1
    Wend
    '...sinon on l'ajoute dans la liste des objets à effacer
    If lb_inserted = False Then
        mo_lst_ToDelete_code.Add mo_lst_Selected_code.Item(lst_Selected.ListIndex + 1)
        mo_lst_ToDelete_conc.Add mo_lst_Selected_conc.Item(lst_Selected.ListIndex + 1)
    End If
End Sub

Private Sub ClearToInsertList()
Dim i As Integer
    For i = mo_lst_ToInsert_code.Count - 1 To 1 Step -1
        mo_lst_ToInsert_code.Remove i
    Next
End Sub

Private Sub ClearToDeleteList()
Dim i As Integer
    For i = mo_lst_ToDelete_code.Count - 1 To 1 Step -1
        mo_lst_ToDelete_code.Remove i
        mo_lst_ToDelete_conc.Remove i
    Next
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
    
    If ms_ScreenName = "" Then
        ms_ScreenName = "PFG_PE_mtnc"
    End If
    If ms_LanguageCode = "" Then
        ms_LanguageCode = gut_LangLogin.Code
    End If
    
    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)
    
    GetCaptions
    
    UpdNotSelectedList
    FillSelectedList
    FillNotSelectedList
    ClearToInsertList
    ClearToDeleteList
    
    MouseOn
    
End Sub

Private Sub pic_In_Click()
Dim li_Index As Integer

    li_Index = lst_NotSelected.ListIndex
    If li_Index <> -1 Then
        'ajout dans les collections Selected
        mo_lst_Selected_code.Add mo_lst_NotSelected_code(li_Index + 1)
        mo_lst_Selected_desc.Add mo_lst_NotSelected_desc(li_Index + 1)
        mo_lst_Selected_conc.Add mo_lst_NotSelected_conc(li_Index + 1)
        'ajout dans la listbox Selected
        lst_Selected.AddItem mo_lst_NotSelected_desc(li_Index + 1)
        
        'ajout dans la colection ToInsert
        UpdToInsertList
        
        'suppression dans les collections NotSelected
        mo_lst_NotSelected_code.Remove li_Index + 1
        mo_lst_NotSelected_desc.Remove li_Index + 1
        mo_lst_NotSelected_conc.Remove li_Index + 1
        'suppression dans la listbox NotSelected
        lst_NotSelected.RemoveItem li_Index
    End If
End Sub

Private Sub pic_Out_Click()
Dim li_Index As Integer
    
    li_Index = lst_Selected.ListIndex
    If li_Index <> -1 Then
        'ajout dans les collections NotSelected
        mo_lst_NotSelected_code.Add mo_lst_Selected_code(li_Index + 1)
        mo_lst_NotSelected_desc.Add mo_lst_Selected_desc(li_Index + 1)
        mo_lst_NotSelected_conc.Add mo_lst_Selected_conc(li_Index + 1)
        'ajout dans la listbox NotSelected
        lst_NotSelected.AddItem mo_lst_Selected_desc(li_Index + 1)
        
        'ajout dans la colection ToDelete
        UpdToDeleteList
        
        'suppression dans les collections Selected
        mo_lst_Selected_code.Remove li_Index + 1
        mo_lst_Selected_desc.Remove li_Index + 1
        mo_lst_Selected_conc.Remove li_Index + 1
        'suppression dans la listbox Selected
        lst_Selected.RemoveItem li_Index
       
    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()
Dim i As Integer

    'on remet les elements à inserer dans la liste des non séléctionnés
    If mo_lst_ToInsert_code.Count <> 0 Then
        For i = 1 To mo_lst_ToInsert_code.Count
            mo_lst_NotSelected_code.Add mo_lst_Selected_code(i)
            mo_lst_NotSelected_desc.Add mo_lst_Selected_desc(i)
            mo_lst_NotSelected_conc.Add mo_lst_Selected_conc(i)
        Next
    End If
    'on remet les elements à effacer dans la liste des séléctionnés
    If mo_lst_ToDelete_code.Count <> 0 Then
        For i = 1 To mo_lst_ToInsert_code.Count
            mo_lst_Selected_code.Add mo_lst_NotSelected_code(i)
            mo_lst_Selected_desc.Add mo_lst_NotSelected_desc(i)
            mo_lst_Selected_conc.Add mo_lst_NotSelected_conc(i)
        Next
    End If
    
    mb_Return = KO
    Unload Me
End Sub
