' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Imports System.Xml
Imports System.IO

Public Class Configuration
    'load

    Private Sub Configuration_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim ConfigXml As New XmlDocument
        ConfigXml.Load(Application.StartupPath + "\config.xml")
        Dim XMLelementliste As XmlNodeList



        'Sesam-Vitale
        XMLelementliste = ConfigXml.GetElementsByTagName("SESAM-VITALE")
        Label_Version_CDC_SV.Text = "Agrément Sesam Vitale: " + XMLelementliste.Item(0).Item("VersionCDCSV").InnerText

        'STS
        XMLelementliste = ConfigXml.GetElementsByTagName("STS")
        If UCase(XMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
            CheckBox_STS_Activer.Checked = True
        End If
        If UCase(XMLelementliste.Item(0).Item("AfficheDiagNiv1").InnerText) = "OUI" Then
            CheckBox_STS_Afficheniveau1.Checked = True
        End If

        'SMTP
        XMLelementliste = ConfigXml.GetElementsByTagName("SMTP")
        Dim TypeEmetteurFichier As String
        TypeEmetteurFichier = XMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText
        For i = 0 To ComboBox_Type_émetteur_fichier.Items.Count - 1
            If Mid(ComboBox_Type_émetteur_fichier.Items.Item(i).ToString, 1, 2) = TypeEmetteurFichier Then
                ComboBox_Type_émetteur_fichier.Text = ComboBox_Type_émetteur_fichier.Items.Item(i).ToString
            End If
        Next
        TextBox_Num_émetteur_fichier.Text = XMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText
        SMTP_Serv_ext_TextBox.Text = XMLelementliste.Item(0).Item("Serveur_Externe").InnerText
        SMTP_Serv_ext_port_TextBox.Text = XMLelementliste.Item(0).Item("Serveur_Externe_port").InnerText

        'Pop3
        XMLelementliste = ConfigXml.GetElementsByTagName("Pop3")
        Pop3_Serveur_TextBox.Text = XMLelementliste.Item(0).Item("Serveur").InnerText
        Pop3_Port_TextBox.Text = XMLelementliste.Item(0).Item("Port").InnerText
        Pop3_User_TextBox.Text = XMLelementliste.Item(0).Item("User").InnerText
        Pop3_Password_MaskedTextBox.Text = XMLelementliste.Item(0).Item("Password").InnerText
        Pop3_RepBAL.Text = XMLelementliste.Item(0).Item("RepBAL").InnerText

        'TRANSMISSION
        XMLelementliste = ConfigXml.GetElementsByTagName("SMTP")
        TextBox_G14C3_G94C3.Text = XMLelementliste.Item(0).Item("MessageFormatFichier").InnerText
        ComboBox_Type_émetteur_fichier.Text = XMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText
        TextBox_Num_émetteur_fichier.Text = XMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText
        If UCase(XMLelementliste.Item(0).Item("CompresserDonnees").InnerText) = "OUI" Then
            CheckBox_compression.Checked = True
        End If

        'modefonctionement
        XMLelementliste = ConfigXml.GetElementsByTagName("Configuration")
        ComboBoxModeFonctionnement.Text = XMLelementliste.Item(0).Item("ModeFonctionnement").InnerText
        If XMLelementliste.Item(0).Item("Desynchroniser").InnerText = "oui" Then
            CheckBox_Desynchroniser.Checked = True
        Else
            CheckBox_Desynchroniser.Checked = False
        End If

        'pmss
        XMLelementliste = ConfigXml.GetElementsByTagName("Data")
        TextBoxPMSS.Text = XMLelementliste.Item(0).Item("PMSS").InnerText

        'contaceptif urgence
        XMLelementliste = ConfigXml.GetElementsByTagName("ContaceptifUrgence")
        TextBoxContraceptifUrgNIR.Text = XMLelementliste.Item(0).Item("NIR").InnerText
        TextBoxContraceptifUrgClé.Text = XMLelementliste.Item(0).Item("cle").InnerText
        TextBoxContraceptifUrgDateNaissance.Text = XMLelementliste.Item(0).Item("datenaissance").InnerText
        TextBoxContraceptifUrgPrescr.Text = XMLelementliste.Item(0).Item("NumPrecripteur").InnerText
        TextBoxContraceptifUrgPrescrClé.Text = XMLelementliste.Item(0).Item("CleNumPrecripteur").InnerText
        TextBoxContraceptifUrgCIP.Text = XMLelementliste.Item(0).Item("ContraceptifCIP").InnerText

        'OCT
        XMLelementliste = ConfigXml.GetElementsByTagName("OCT")
        If UCase(XMLelementliste.Item(0).Item("UtilisationOCT").InnerText) = "OUI" Then
            OCT_CheckBox.Checked = True
        End If
        If UCase(XMLelementliste.Item(0).Item("FSE_FichierUnique").InnerText) = "OUI" Then
            OCT_FSE_FichierUnique_CheckBox1.Checked = True
        End If
        If UCase(XMLelementliste.Item(0).Item("FSE_Eclatement_Source").InnerText) = "OUI" Then
            OCT_FSE_Eclatement_Source_CheckBox.Checked = True
        End If
        If UCase(XMLelementliste.Item(0).Item("FSEenrichies").InnerText) = "OUI" Then
            OCT_FSE_Enrichies_CheckBox1.Checked = True
        End If

        OCT_TextBox_Adresse_Destinataire.Text = XMLelementliste.Item(0).Item("AdressemailOCT").InnerText
        OCT_TextBox_Adresse_TypeDestinataire.Text = XMLelementliste.Item(0).Item("TypeDestinataire").InnerText
        OCT_TextBox_Application.Text = XMLelementliste.Item(0).Item("Application").InnerText

        'Conventions
        XMLelementliste = ConfigXml.GetElementsByTagName("Conventions")
        If UCase(XMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
            Conventions_CheckBox.Checked = True
        End If

        'LOI
        XMLelementliste = ConfigXml.GetElementsByTagName("LOI")
        If UCase(XMLelementliste.Item(0).Item("LOI_Activer").InnerText) = "OUI" Then
            LOI_Activer_CheckBox.Checked = True
        End If
        LOI_serveurPOP_TextBox.Text = XMLelementliste.Item(0).Item("LOI_Pop3_Serveur").InnerText
        LOI_PortPOP_TextBox.Text = XMLelementliste.Item(0).Item("LOI_Pop3_Port").InnerText
        LOI_User_TextBox.Text = XMLelementliste.Item(0).Item("LOI_Pop3_User").InnerText
        LOI_Password_MaskedTextBox.Text = XMLelementliste.Item(0).Item("LOI_Pop3_Password").InnerText
        LOI_Rep_Bal_TextBox.Text = XMLelementliste.Item(0).Item("LOI_Pop3_RepBAL").InnerText
        LOI_Distr_OCT_TextBox.Text = XMLelementliste.Item(0).Item("LOI_Distr_OCT").InnerText
        LOI_Distr_horsOCT_TextBox.Text = XMLelementliste.Item(0).Item("LOI_Distr_horsOCT").InnerText
        LOI_Ref_Label.Text = "Ref: " + XMLelementliste.Item(0).Item("LOI_Ref").InnerText
        LOI_NB_JOUR_Max_TextBox.Text = XMLelementliste.Item(0).Item("LOI_NB_JOUR_Max").InnerText
        If UCase(XMLelementliste.Item(0).Item("LOI_Controle_MAJ_mensuel").InnerText) = "OUI" Then
            LOI_Controle_MAJ_mensuel_CheckBox.Checked = True
        End If
        If UCase(XMLelementliste.Item(0).Item("LOI_Demande_Auto").InnerText) = "OUI" Then
            LOI_Demande_Auto_CheckBox.Checked = True
        End If
        LOI_serveurSMTP_TextBox.Text = XMLelementliste.Item(0).Item("LOI_smtp_serveur").InnerText
        LOI_PortSMTP_TextBox.Text = XMLelementliste.Item(0).Item("LOI_smtp_serveur_port").InnerText
        LOI_BAL.Text = XMLelementliste.Item(0).Item("LOI_Pop3_BAL").InnerText
    End Sub

    'save
    Private Sub Button_Fermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Fermer.Click
        Select Case MsgBox("Voulez-vous Sauvegarder les modifications?", MsgBoxStyle.YesNoCancel)
            Case MsgBoxResult.Yes
                SaveConfig()
                Config.Load_Config_File()
                Me.Dispose()
            Case MsgBoxResult.No
                Me.Dispose()
        End Select
    End Sub
    Private Sub SaveConfig()
        Dim ConfigXml As New XmlDocument
        ConfigXml.Load(Application.StartupPath + "\config.xml")
        Dim XMLelementliste As XmlNodeList


        'SMTP
        XMLelementliste = ConfigXml.GetElementsByTagName("SMTP")
        XMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText = Mid(ComboBox_Type_émetteur_fichier.Text, 1, 2)
        XMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText = TextBox_Num_émetteur_fichier.Text
        XMLelementliste.Item(0).Item("Serveur_Externe").InnerText = SMTP_Serv_ext_TextBox.Text
        XMLelementliste.Item(0).Item("Serveur_Externe_port").InnerText = SMTP_Serv_ext_port_TextBox.Text

        'STS
        XMLelementliste = ConfigXml.GetElementsByTagName("STS")
        If CheckBox_STS_Activer.Checked = True Then
            XMLelementliste.Item(0).Item("Activer").InnerText = "OUI"
        Else
            XMLelementliste.Item(0).Item("Activer").InnerText = "NON"
        End If
        If CheckBox_STS_Afficheniveau1.Checked = True Then
            XMLelementliste.Item(0).Item("AfficheDiagNiv1").InnerText = "OUI"
        Else
            XMLelementliste.Item(0).Item("AfficheDiagNiv1").InnerText = "NON"
        End If

        'Pop3
        XMLelementliste = ConfigXml.GetElementsByTagName("Pop3")
        XMLelementliste.Item(0).Item("Serveur").InnerText = Pop3_Serveur_TextBox.Text
        XMLelementliste.Item(0).Item("Port").InnerText = Pop3_Port_TextBox.Text
        XMLelementliste.Item(0).Item("User").InnerText = Pop3_User_TextBox.Text
        XMLelementliste.Item(0).Item("Password").InnerText = Pop3_Password_MaskedTextBox.Text
        XMLelementliste.Item(0).Item("RepBAL").InnerText = Pop3_RepBAL.Text

        'TRANSMISSION
        XMLelementliste = ConfigXml.GetElementsByTagName("SMTP")
        XMLelementliste.Item(0).Item("MessageFormatFichier").InnerText = TextBox_G14C3_G94C3.Text
        If CheckBox_compression.Checked = True Then
            XMLelementliste.Item(0).Item("CompresserDonnees").InnerText = "OUI"
        Else
            XMLelementliste.Item(0).Item("CompresserDonnees").InnerText = "NON"
        End If
        'modefonctionement
        XMLelementliste = ConfigXml.GetElementsByTagName("Configuration")
        XMLelementliste.Item(0).Item("ModeFonctionnement").InnerText = ComboBoxModeFonctionnement.Text
        If CheckBox_Desynchroniser.Checked = True Then
            XMLelementliste.Item(0).Item("Desynchroniser").InnerText = "oui"
        Else
            XMLelementliste.Item(0).Item("Desynchroniser").InnerText = "non"
        End If
        'pmss
        XMLelementliste = ConfigXml.GetElementsByTagName("Data")
        XMLelementliste.Item(0).Item("PMSS").InnerText = TextBoxPMSS.Text

        'contaceptif urgence
        XMLelementliste = ConfigXml.GetElementsByTagName("ContaceptifUrgence")
        XMLelementliste.Item(0).Item("NIR").InnerText = TextBoxContraceptifUrgNIR.Text
        XMLelementliste.Item(0).Item("cle").InnerText = TextBoxContraceptifUrgClé.Text
        XMLelementliste.Item(0).Item("datenaissance").InnerText = TextBoxContraceptifUrgDateNaissance.Text
        XMLelementliste.Item(0).Item("ContraceptifCIP").InnerText = TextBoxContraceptifUrgCIP.Text
        XMLelementliste.Item(0).Item("NumPrecripteur").InnerText = TextBoxContraceptifUrgPrescr.Text
        XMLelementliste.Item(0).Item("CleNumPrecripteur").InnerText = TextBoxContraceptifUrgPrescrClé.Text

        'OCT
        XMLelementliste = ConfigXml.GetElementsByTagName("OCT")
        If OCT_CheckBox.Checked = True Then
            XMLelementliste.Item(0).Item("UtilisationOCT").InnerText = "OUI"
            Config.OCT_UtilisationOCT = True
        Else
            XMLelementliste.Item(0).Item("UtilisationOCT").InnerText = "NON"
            Config.OCT_UtilisationOCT = False
        End If

        If OCT_FSE_Enrichies_CheckBox1.Checked = True Then
            XMLelementliste.Item(0).Item("FSEenrichies").InnerText = "OUI"
            Config.OCT_FSEenrichies = True
        Else
            XMLelementliste.Item(0).Item("FSEenrichies").InnerText = "NON"
            Config.OCT_FSEenrichies = False
        End If

        If OCT_FSE_Eclatement_Source_CheckBox.Checked = True Then
            XMLelementliste.Item(0).Item("FSE_Eclatement_Source").InnerText = "OUI"
            Config.OCT_FSE_Eclatement_Source = True
        Else
            XMLelementliste.Item(0).Item("FSE_Eclatement_Source").InnerText = "NON"
            Config.OCT_FSEenrichies = False
        End If

        If OCT_FSE_FichierUnique_CheckBox1.Checked = True Then
            XMLelementliste.Item(0).Item("FSE_FichierUnique").InnerText = "OUI"
            Config.OCT_FSEenrichies = True
        Else
            XMLelementliste.Item(0).Item("FSE_FichierUnique").InnerText = "NON"
            Config.OCT_FSEenrichies = False
        End If

        XMLelementliste.Item(0).Item("AdressemailOCT").InnerText = OCT_TextBox_Adresse_Destinataire.Text
        XMLelementliste.Item(0).Item("TypeDestinataire").InnerText = OCT_TextBox_Adresse_TypeDestinataire.Text
        XMLelementliste.Item(0).Item("Application").InnerText = OCT_TextBox_Application.Text

        'Conventions
        XMLelementliste = ConfigXml.GetElementsByTagName("Conventions")
        If Conventions_CheckBox.Checked = True Then
            XMLelementliste.Item(0).Item("Activer").InnerText = "OUI"
        Else
            XMLelementliste.Item(0).Item("Activer").InnerText = "NON"
        End If

        'LOI
        XMLelementliste = ConfigXml.GetElementsByTagName("LOI")
        XMLelementliste.Item(0).Item("LOI_Pop3_Serveur").InnerText = LOI_serveurPOP_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_Pop3_Port").InnerText = LOI_PortPOP_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_Pop3_User").InnerText = LOI_User_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_Pop3_Password").InnerText = LOI_Password_MaskedTextBox.Text
        XMLelementliste.Item(0).Item("LOI_Pop3_RepBAL").InnerText = LOI_Rep_Bal_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_Distr_OCT").InnerText = LOI_Distr_OCT_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_Distr_horsOCT").InnerText = LOI_Distr_horsOCT_TextBox.Text
        If LOI_Activer_CheckBox.Checked = True Then
            XMLelementliste.Item(0).Item("LOI_Activer").InnerText = "OUI"
            Dim sr As New StreamReader("c:\windows\sesam.ini")
            Dim sw As New StreamWriter("c:\windows\sesam.initemp")
            Dim line As String
            line = sr.ReadLine
            While Not line Is Nothing
                sw.WriteLine(line)
                line = sr.ReadLine
            End While
            sw.WriteLine("[LOI]")
            sw.WriteLine("FichierLOI=" + Config.LOI_Pop3_RepBAL + "loi.loi")
            sr.Close()
            sw.Close()
            My.Computer.FileSystem.DeleteFile("c:\windows\sesam.ini")
            My.Computer.FileSystem.RenameFile("c:\windows\sesam.initemp", "sesam.ini")
        Else
            XMLelementliste.Item(0).Item("LOI_Activer").InnerText = "NON"
            Dim sr As New StreamReader("c:\windows\sesam.ini")
            Dim sw As New StreamWriter("c:\windows\sesam.initemp")
            Dim line As String
            line = sr.ReadLine
            While Not line Is Nothing
                If InStr(line, "[LOI]") = 0 And InStr(line, "FichierLOI=") = 0 Then
                    sw.WriteLine(line)
                End If
                line = sr.ReadLine
            End While
            sr.Close()
            sw.Close()
            My.Computer.FileSystem.DeleteFile("c:\windows\sesam.ini")
            My.Computer.FileSystem.RenameFile("c:\windows\sesam.initemp", "sesam.ini")
        End If
        XMLelementliste.Item(0).Item("LOI_NB_JOUR_Max").InnerText = LOI_NB_JOUR_Max_TextBox.Text
        If LOI_Demande_Auto_CheckBox.Checked = True Then
            XMLelementliste.Item(0).Item("LOI_Demande_Auto").InnerText = "OUI"
        Else
            XMLelementliste.Item(0).Item("LOI_Demande_Auto").InnerText = "NON"
        End If
        If LOI_Controle_MAJ_mensuel_CheckBox.Checked = True Then
            XMLelementliste.Item(0).Item("LOI_Controle_MAJ_mensuel").InnerText = "OUI"
        Else
            XMLelementliste.Item(0).Item("LOI_Controle_MAJ_mensuel").InnerText = "NON"
        End If
        XMLelementliste.Item(0).Item("LOI_smtp_serveur").InnerText = LOI_serveurSMTP_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_smtp_serveur_port").InnerText = LOI_PortSMTP_TextBox.Text
        XMLelementliste.Item(0).Item("LOI_Pop3_BAL").InnerText = LOI_BAL.Text
        'save
        ConfigXml.Save("config.xml")
    End Sub
 
    'AMO
    Private Sub Button_AMO_03_99_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_AMO_03_99.Click
        AMO_03_99.ShowDialog()
        AMO_03_99.Dispose()
    End Sub
    Private Sub AMO_Button_Import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AMO_Button_Import.Click
        Dim file As String
        OpenFileDialog1.ShowDialog()
        file = OpenFileDialog1.FileName
        If file <> "" Then
            Dim sr As New StreamReader(file)
            Dim line As String = sr.ReadLine
            Do
                Dim CodeRégime As String = Mid(line, 1, 2)
                Dim CaisseGestionnaire As String = Mid(line, 4, 3)
                Dim CentreGestionnaire As String = Mid(line, 8, 4)
                line = Mid(line, 13)
                Dim libellé = Mid(line, 1, InStr(line, ";") - 1)
                line = Mid(line, libellé.Length + 2)
                Dim OrganismeDestinataire = Mid(line, 1, 3)
                Dim CentreInformatique = Mid(line, 5, 3)
                Select Case Me.AMOTableAdapter.SelectCount(CodeRégime, CaisseGestionnaire, CentreGestionnaire)
                    Case 0
                        Me.AMOTableAdapter.Insert(CodeRégime, CaisseGestionnaire, CentreGestionnaire, OrganismeDestinataire, CentreInformatique, libellé)
                    Case 1
                        Me.AMOTableAdapter.UpdateQuery(CodeRégime, CaisseGestionnaire, CentreGestionnaire, OrganismeDestinataire, CentreInformatique, libellé)
                    Case Else
                        MsgBox("PLUSIEURS ENREGISTREMENTS POUR:" + Chr(10) + "Code Régime:" + CodeRégime + Chr(10) + "Caisse Gestionnaire:" + CaisseGestionnaire + Chr(10) + "Centre Gestionnaire:" + CentreGestionnaire, MsgBoxStyle.Critical)
                End Select
                line = sr.ReadLine
            Loop Until line Is Nothing
        End If
    End Sub


    Private Sub TextBox_G14C3_G94C3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox_G14C3_G94C3.KeyPress
        Select Case Asc(e.KeyChar)
            Case Asc("a") To Asc("z"), Asc("A") To Asc("Z"), 32, 8, Asc("1") To Asc("9")
            Case Else
                Beep()
                e.KeyChar = Nothing
        End Select
    End Sub
#Region "CONVENTIONS"
    Private Sub Button_Convention_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Convention.Click
        Convention_form.Visible = True
    End Sub
    Private Sub Button_Regroupement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Regroupement.Click
        Regroupement.Visible = True
    End Sub
    Private Sub Button_Correspondance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Correspondance.Click
        Correspondance.Visible = True
    End Sub
#End Region
  
#Region "OCT"

    Private Sub OCT_TextBox_Application_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles OCT_TextBox_Application.Validated
        If OCT_TextBox_Application.TextLength <> 2 Then
            OCT_TextBox_Application.Text = "TO"
        Else
            OCT_TextBox_Application.Text = UCase(OCT_TextBox_Application.Text)
        End If
    End Sub

    Private Sub OCT_FSE_FichierUnique_CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OCT_FSE_FichierUnique_CheckBox1.CheckedChanged
        If OCT_FSE_FichierUnique_CheckBox1.Checked = True Then
            OCT_FSE_Eclatement_Source_CheckBox.Checked = False
            OCT_FSE_Enrichies_CheckBox1.Checked = False
        End If
    End Sub
    Private Sub OCT_FSE_Eclatement_Source_CheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OCT_FSE_Eclatement_Source_CheckBox.CheckedChanged
        If OCT_FSE_Eclatement_Source_CheckBox.Checked = True Then
            OCT_FSE_FichierUnique_CheckBox1.Checked = False
            OCT_FSE_Enrichies_CheckBox1.Checked = False
        End If
    End Sub
    Private Sub OCT_FSE_Enrichies_CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OCT_FSE_Enrichies_CheckBox1.CheckedChanged
        If OCT_FSE_Enrichies_CheckBox1.Checked = True Then
            OCT_FSE_FichierUnique_CheckBox1.Checked = False
            OCT_FSE_Eclatement_Source_CheckBox.Checked = False
        End If
    End Sub
#End Region



    Private Sub Button_Remplacement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Remplacement.Click

        SGD_LibererSession(NumeroSessionCPS)
        If SGD_ReserverSession(0, NumeroSessionCPS) <> 0 Then
            MsgBox("ERREUR POUR LA RESERVATION DE SESSION CPS")
            Me.Close()
        End If
        AfficheErreur(SIS_LireCartePS(NomRessourcePS, NomRessourceLecteur, "", NumeroSessionCPS))
        Dim num_titulaire As String = "123456789012345678901234567890"
        TailleMax = 30
        SGD_LireChamp(NumeroSessionCPS, 1, 1, 3, num_titulaire, TailleMax)
        num_titulaire = Mid(num_titulaire, 1, TailleMax)
        If Config.Activer_Session_Remplacement = True And num_titulaire.ToString <> Config.Titulaire_Num_Id_Nat.ToString Then
            MsgBox("Insérez la carte PS déclarée Titulaire pour accéder à la configuration ou la désactivation du remplaçant.", MsgBoxStyle.Information)
            Exit Sub
        End If
        Config_Remplacement.Visible = True
    End Sub

    Private Sub Button_Lecteur_SV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Lecteur_SV.Click
        Config_Lecteur.Visible = True
    End Sub


    Private Sub Button_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Clear.Click
        RichTextBox1.Clear()
    End Sub

    Private Sub Button_LireVersion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_LireVersion.Click
        Dim numerosession As Integer
        AfficheErreur(SGD_ReserverSession(10000, numerosession), "SGD_ReserverSession")
        STS_InitLIB()
        AfficheErreur(STS_LireVersion_S(numerosession), "STS_LireVersion")
        Me.UseWaitCursor = True
        Dim IdGroupeSuivant As UInt16
        Dim OccurrenceGroupeSuivant As UInt16
        Dim IdGroupeCourant As UInt16 = 0
        Dim OccurrenceGroupeCourant As UInt16 = 0
        While SGD_LireGroupeSuivant(numerosession, IdGroupeCourant, OccurrenceGroupeCourant, IdGroupeSuivant, OccurrenceGroupeSuivant) = 0
            IdGroupeCourant = IdGroupeSuivant
            OccurrenceGroupeCourant = OccurrenceGroupeSuivant
            Dim i As UInt16 = 1
            Dim ValeurChamp As String = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
            Dim TailleMax As Integer = 200
            While SGD_LireChamp(numerosession, IdGroupeCourant, OccurrenceGroupeCourant, i, ValeurChamp, TailleMax) = 0
                Select Case i
                    Case 1
                        RichTextBox1.AppendText(Chr(10) + "Identification du module STS: " + Mid(ValeurChamp, 1, TailleMax))
                    Case 2
                        RichTextBox1.AppendText("  |  Version du module: " + Mid(ValeurChamp, 1, TailleMax))
                    Case 3
                        RichTextBox1.AppendText("  |  Version du fichier de tables STS: " + Mid(ValeurChamp, 1, TailleMax))
                    Case 4
                        RichTextBox1.AppendText("  |  Variante: " + Mid(ValeurChamp, 1, TailleMax))
                    Case 5
                        RichTextBox1.AppendText("  |  Commentaire: " + Mid(ValeurChamp, 1, TailleMax))

                End Select
                ValeurChamp = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
                TailleMax = 200
                i = i + 1
            End While
        End While
        Me.UseWaitCursor = False
        SGD_LibererSession(numerosession)
    End Sub

    Private Sub OCT_CheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OCT_CheckBox.CheckedChanged
        MsgBox("ATTENTION, le changement de mode de transmission peut entrainer la perte de données." + Chr(10) + "Il est conseillé de vider la BAL Sesam-Vitale avant le changement.", MsgBoxStyle.Exclamation)
    End Sub



    Private Sub LOI_NB_JOUR_Max_TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles LOI_NB_JOUR_Max_TextBox.Validated
        If IsNumeric(LOI_NB_JOUR_Max_TextBox.Text) = False Then
            LOI_NB_JOUR_Max_TextBox.Text = "7"
        End If
    End Sub





End Class