' 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
Imports System.Text
Imports System.Drawing.Drawing2D
Imports System.Threading

Public Module declarations

#Region "FONCTIONS SESAM VITALE"
    'fonctions SGD techniques
    Public Declare Function SGD_ReserverSession Lib "sgdw32.dll" (ByVal Taille As UInt32, ByRef NumeroSession As UInt16) As UInt16
    Public Declare Function SGD_RedimensionnerBuffer Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal Taille As UInt32) As UInt16
    Public Declare Function SGD_LibererSession Lib "sgdw32.dll" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SGD_InitTrace Lib "sgdw32.dll" (ByVal NomFichier As String, ByVal ModeOuverture As String, ByVal Module_ As UInt16, ByVal niveau As Byte) As UInt16

    'fonctions SGD de constitution des données en entrée
    Public Declare Function SGD_AjouterGroupe Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16) As UInt16
    Public Declare Function SGD_AjouterChamp Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal ValeurChamp As String) As UInt16
    Public Declare Function SGD_AjouterChampBin Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal ValeurChamp As String, ByVal TailleMax As UInt32) As UInt16
    Public Declare Function SGD_AjouterChampFichier Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal NomFichier As String) As UInt16


    'fonctions SGD d’extraction des données restituées
    Public Declare Function SGD_LireGroupeSuivant Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupeCourant As UInt16, ByVal OccurrenceGroupeCourant As UInt16, ByRef IdGroupeSuivant As UInt16, ByRef OccurrenceGroupeSuivant As UInt16) As UInt16
    Public Declare Function SGD_LireChamp Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal OccurrenceGroupe As UInt16, ByVal NumeroChamp As UInt16, ByVal ValeurChamp As String, ByRef TailleMax As UInt32) As UInt16
    Public Declare Function SGD_LireChampBin Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal OccurrenceGroupe As UInt16, ByVal NumeroChamp As UInt16, ByVal ValeurChamp As String, ByRef TailleMax As UInt32) As UInt16
    Public Declare Function SGD_LireChampFichier Lib "sgdw32.dll" (ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal OccurrenceGroupe As UInt16, ByVal NumeroChamp As UInt16, ByVal NomFichier As String) As UInt16


    'fonctions SSV techniques
    Public Declare Function SSV_InitLIB2 Lib "SSVW32.DLL" (ByVal pcRepSesamIni As String) As UInt16
    Public Declare Function SSV_TermLIB Lib "SSVW32.DLL" () As UInt16
    Public Declare Function SSV_AllouerZoneMem Lib "SSVW32.DLL" (ByRef ZDonneesSortie As Integer, ByVal TailleDonneesEntree As UInt32) As UInt16

    'fonctions SIS techniques
    Public Declare Function SIS_InitTrace Lib "SSvW32.DLL" (ByVal NomFichier As String, ByVal ModeOuverture As String, ByVal Module_ As UInt16, ByVal niveau As Byte) As UInt16


    'fonctions SIS d’accès aux données
    Public Declare Function SIS_LireCartePS Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_LireDroitsVitale Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal DateConsultation As String, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_FormaterFactures Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal FacturesACreer As Char, ByVal ModeSecur As Char, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_FormaterLot Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_FormaterFichier Lib "SSvW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_TraduireARL Lib "SSvW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_SecuriserFacture Lib "SSvW32.DLL" (ByVal NomRessourcePS As String, ByVal NomRessourceLecteur As String, ByVal CodePorteurPS As String, ByVal NologSituation As Char, ByVal NumFacturation As String, ByVal NumeroSession As UInt16) As UInt16

    'fonctions STS
    Public Declare Function STS_InitLIB2 Lib "STSW32.DLL" (ByVal pcRepSesamIni As String) As UInt16
    Public Declare Function STS_InitTrace Lib "STSW32.DLL" (ByVal NomFichier As String, ByVal ModeOuverture As String, ByVal Module_ As UInt16, ByVal niveau As Byte) As UInt16
    Public Declare Function STS_Tarification_S Lib "STSW32.DLL" (ByVal MotifAppel As Char, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function STS_Assistance_S Lib "STSW32.DLL" (ByVal MotifAppel As Char, ByVal PorteeAppel As UInt16, ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function STS_LireVersion_S Lib "STSW32.DLL" (ByVal NumeroSession As UInt16) As UInt16

    'fonctions SRT
    Public Declare Function SRT_InitLIB Lib "SRTW32.DLL" () As UInt16
    Public Declare Function SRT_ControleComplet_S Lib "SRTW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SRT_LireVersion_S Lib "SRTW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SRT_ConsulterDonnee_S Lib "SRTW32.DLL" (ByVal Identifiant As String, ByVal DateReference As String, ByVal NumeroSession As UInt16) As UInt16

    'Fonctions de gestion de configuration
    Public Declare Function SIS_LireConfig Lib "SSvW32.DLL" (ByVal NumeroSession As UInt16) As UInt16
    Public Declare Function SIS_LireDateLecteur Lib "SSvW32.DLL" (ByVal NomRessourceLecteur As String, ByVal DateHeure As String) As UInt16
    Public Declare Function SIS_MajDateLecteur Lib "SSvW32.DLL" (ByVal NomRessourceLecteur As String, ByVal DateHeure As String) As UInt16
    Public Declare Function SIS_ChargerAppli Lib "SSvW32.DLL" (ByVal NomRessourceLecteur As String, ByVal NumeroSession As UInt16) As UInt16

#End Region
#Region "MY FONCTIONS SESAM VITALE"
    Public Trace_Compteur_Groupe As Integer
    Public Trace_Compteur_Champs_dans_groupe As Integer
    Public Trace_Compteur_Champs_total As Integer
    Public FichierTrace As String
    Public Sub Trace_Reset_compteur()
        Trace_Compteur_Groupe = 0
        Trace_Compteur_Champs_dans_groupe = 0
        Trace_Compteur_Champs_total = 0
    End Sub


    Public Function SGD_AjouterGroupe_Tracé(ByVal NumeroSession As UInt16, ByVal IdGroupe As UInt16, ByVal Visu_API As Boolean, ByVal Fichier_Trace As String) As UInt16
        Dim rep As String = Mid(Fichier_Trace, 1, InStrRev(Fichier_Trace, "\") - 1)
        If My.Computer.FileSystem.DirectoryExists(rep) = False Then
            My.Computer.FileSystem.CreateDirectory(rep)
        End If
        Trace_Compteur_Groupe = Trace_Compteur_Groupe + 1
        Trace_Compteur_Champs_dans_groupe = 0
        current_Groupe = IdGroupe
        If Visu_API = True Then 'avec trace
            Using sw As New StreamWriter(Fichier_Trace, True, Encoding.Default)
                Dim line As String
                line = "Groupe " + IdGroupe.ToString
                While line.Length < 15
                    line = line + " "
                End While
                line = line + "(" + Trace_Compteur_Groupe.ToString + ")"
                sw.WriteLine()
                sw.WriteLine(line)
                Return SGD_AjouterGroupe(NumeroSession, IdGroupe)
            End Using
        Else 'sans trace
            Return SGD_AjouterGroupe(NumeroSession, IdGroupe)
        End If
    End Function

    Public Function SGD_AjouterChamp_Tracé(ByVal NumeroSession As UInt16, ByRef ValeurChamp As String, ByVal Visu_API As Boolean, ByVal Fichier_Trace As String, Optional ByVal NumPrestation As Integer = 0) As UInt16
        Trace_Compteur_Champs_dans_groupe = Trace_Compteur_Champs_dans_groupe + 1
        Trace_Compteur_Champs_total = Trace_Compteur_Champs_total + 1
        Dim from_sts As Boolean = False
        Dim tops As String = ""
        If Tab_Valeur_STS.Length > 1 Then
            For i = 0 To Tab_Valeur_STS.Length - 1
                If NumPrestation = 0 Then
                    If Tab_Valeur_STS(i).groupe = current_Groupe And Tab_Valeur_STS(i).champ = Trace_Compteur_Champs_dans_groupe Then
                        ValeurChamp = Tab_Valeur_STS(i).valeur
                        from_sts = True
                        tops = Tab_Valeur_STS(i).affichage + Tab_Valeur_STS(i).modification
                        Exit For
                    End If
                Else
                    If Tab_Valeur_STS(i).groupe = current_Groupe And Tab_Valeur_STS(i).champ = Trace_Compteur_Champs_dans_groupe And Tab_Valeur_STS(i).NumPrestation = NumPrestation Then
                        ValeurChamp = Tab_Valeur_STS(i).valeur
                        from_sts = True
                        tops = Tab_Valeur_STS(i).affichage + Tab_Valeur_STS(i).modification
                        Exit For
                    End If
                End If
            Next
        End If

        If Visu_API = True Then 'avec trace
            Using sw As New StreamWriter(Fichier_Trace, True, Encoding.Default)
                Dim line As String
                line = Trace_Compteur_Champs_dans_groupe.ToString
                While line.Length < 2
                    line = " " + line
                End While
                line = line + ": " + ValeurChamp
                While line.Length < 25
                    line = line + " "
                End While
                line = line + "(" + Trace_Compteur_Champs_total.ToString + ")"
                If from_sts = True Then
                    line = line + "(sts)" + tops
                End If
                sw.WriteLine(line)
                Return SGD_AjouterChamp(NumeroSession, ValeurChamp)
            End Using
        Else 'sans trace
            Return SGD_AjouterChamp(NumeroSession, ValeurChamp)
        End If
    End Function
    Public Function SGD_AjouterChampBin_Tracé(ByVal NumeroSession As UInt16, ByRef MyByte As Byte, ByVal Visu_API As Boolean, ByVal Fichier_Trace As String, Optional ByVal NumPrestation As Integer = 0) As UInt16
        Trace_Compteur_Champs_dans_groupe = Trace_Compteur_Champs_dans_groupe + 1
        Trace_Compteur_Champs_total = Trace_Compteur_Champs_total + 1

        If Visu_API = True Then 'avec trace
            Using sw As New StreamWriter(Fichier_Trace, True, Encoding.Default)
                Dim line As String
                line = Trace_Compteur_Champs_dans_groupe.ToString
                While line.Length < 2
                    line = " " + line
                End While
                line = line + ": Binaire"
                While line.Length < 25
                    line = line + " "
                End While
                line = line + "(" + Trace_Compteur_Champs_total.ToString + ")"

                sw.WriteLine(line)
                Return SGD_AjouterChampBin(NumeroSession, MyByte, 1)
            End Using
        Else 'sans trace
            Return SGD_AjouterChampBin(NumeroSession, MyByte, 1)
        End If
    End Function
#End Region

    Declare Function apiBlockInput Lib "user32" Alias "BlockInput" (ByVal fBlock As Integer) As Integer


#Region "Variables"
    Public Structure User
        Dim ID As String
        Dim Locked As Boolean
        Dim image As System.Drawing.Image
        Dim comptage_boite As Boolean
        Public Sub Clear()
            ID = ""
            Locked = False
            image = Nothing
            comptage_boite = False
        End Sub
    End Structure
    Public current_User As User

    Public CodeCPS As String
    'Public ID_user As String
    'Public ID_user_locked As Boolean
    'Public Chemin_application As String 'chemin du repertoire de l'application

    Public Visu_API As Boolean 'issu de CNDA.xml 
    Public Trace_Appel_Fonctions As Boolean 'issu de CNDA.xml 

    Public NomRessourcePS As String
    Public NomRessourceLecteur As String

    Public NumeroSessionCPS As UInt16
    Public Occurence_Grp2 As UInt16
    Public NumeroSessionVitale As UInt16
    Public NumeroSessionFacture As UInt16
    Public NumeroSessionLot As UInt16
    Public NumeroSessionFichier As UInt16
    Public NumeroSessionARL As UInt16
    Public NuméroSessionSTS As UInt16
    Public NuméroSessionSRT As UInt16

    Public ValeurChamp As String
    Public TailleMax As UInt32

    'Tables
    Public FicCodesSpecialités As String

    Public CurrentBenéficiaire As Benéficiaire
    Public CurrentFactureVitale As FactureVitale
    Public CurrentFactureVenteDirecte As FactureVenteDirecte
    Public CurrentConvention As Convention

    Public tab_Lignes_Vente() As Ligne_Vente

    'tableau code spécialité
    Public tabCodeSpécialité() As CodeSpécialité


    'user/password
    Public password_validated As Boolean
    Public LOI_FileStream As System.IO.FileStream

    'Etiquettes
    Public etiquettes As List(Of Etiquettes_produits.etiquette)

    'SCOR
    Public SCOR_show_scanner_interface As Boolean

    Public Honoraires_garde As String

    Public MyDataGridViewPrinter As DataGridViewPrinter.DataGridViewPrinter

  
    Public Last_VitalNum As Integer
#End Region
#Region "DECLARATIONS DE TYPES"
    'type code spécialité
    Public Structure CodeSpécialité
        Dim valeur As String
        Dim signification As String
    End Structure

    'type prestation
    Public Structure Prestation
        Dim Code As String
        Dim Libellé As String
        Dim TauxAMO As Integer
        Dim TauxAMC As Integer
    End Structure

    'type FactureVitale
    Public Structure FactureVitale
        Public Sub Clear(ByVal Clear_DETAIL_Ligne_Vente As Boolean)
            num = 0
            Bénéficiaire = ""
            Assuré = ""
            CRLdeFSE = ""
            CRLdeDRE = ""

            G1110C1 = ""
            G1110C2 = ""
            G1110C3 = ""
            G1110C4 = ""
            G1110C5 = ""
            G1110C6 = ""

            G1120C1 = ""
            G1120C2 = ""
            G1120C3 = ""
            G1120C4 = ""
            G1120C5 = ""
            G1120C6 = ""
            G1120C7 = ""
            G1120C8 = ""
            G1120C9 = ""
            G1120C10 = ""
            G1120C11 = ""
            G1120C12 = ""
            G1120C13 = ""
            G1120C14 = ""

            G1130C1 = ""
            G1130C2 = ""
            G1130C3 = ""
            G1130C4 = ""
            G1130C5 = ""
            G1130C6 = ""
            G1130C7 = ""
            G1130C8 = ""
            G1130C9 = ""

            G1140C1 = ""
            G1140C2 = ""
            G1140C3 = ""

            G1150C1 = ""
            G1150C2 = ""
            G1150C3 = ""
            G1150C4 = ""
            G1150C5 = ""

            G1160C1 = ""
            G1160C2 = ""

            G1170C1 = ""

            G1211C1 = ""
            G1211C2 = ""
            G1211C3 = ""
            G1211C4 = ""
            G1211C5 = ""
            G1211C6 = ""
            G1211C7 = ""

            G1213C1 = ""
            G1213C2 = ""
            G1213C3 = ""
            G1213C4 = ""
            G1213C5 = ""
            G1213C6 = ""
            G1213C7 = ""
            G1213C8 = ""

            G1214C1 = ""
            G1214C2 = ""
            G1214C3 = ""
            G1214C4 = ""
            G1214C5 = ""
            G1214C6 = ""
            G1214C7 = ""
            G1214C8 = ""

            G1230C1 = ""

            G1310C1 = ""
            G1310C2 = ""
            G1310C3 = ""
            G1310C4 = ""
            G1310C5 = ""

            G1321C1 = ""
            G1321C2 = ""
            G1321C3 = ""
            G1321C4 = ""
            G1321C5 = ""
            G1321C6 = ""
            G1321C7 = ""
            G1321C8 = ""
            G1321C9 = ""
            G1321C10 = ""
            G1321C11 = ""
            G1321C12 = ""
            G1321C13 = ""

            G1330C1 = ""
            G1330C2 = ""
            G1330C3 = ""

            G1410C1 = ""
            G1410C2 = ""

            G1420C1 = ""
            G1420C2 = ""
            G1420C3 = ""

            G1440C1 = ""
            G1440C2 = ""
            G1440C3 = ""

            G1511C1 = ""
            G1511C2 = ""

            G1512C1 = ""

            G1513C1 = ""
            G1513C2 = ""
            G1513C3 = ""

            G1514C1 = ""
            G1514C2 = ""
            G1514C3 = ""
            G1514C4 = ""

            G1515C1 = ""

            G1910C1 = 0
            G1910C2 = 0
            G1910C3 = 0
            G1910C4 = 0
            G1910C5 = 0
            G1910C6 = 0

            G3700C1 = ""
            G3700C2 = ""

            G3730C1 = ""

            IDPrescripteur = ""
            FactureAcree = ""
            ModeSecur = ""
            ReDim TabLigneFacture(0)
            TP_AMO = False
            TP_AMC = False
            TOP_CMU = False
            Sortant_CMU = False
            'GestionUnique = False
            Mode_Gestion = ""

            If Clear_DETAIL_Ligne_Vente = True Then
                ReDim G1840(0)
                PEC.clear()
                ReDim G1740C7(0)
                ReDim Forçage_Part_AMO(0)
                ReDim G1741(0)
                ReDim Non_Rembousable_CheckBox(0)
            End If

            Renouvellement_Date_Droits_AMO_est_date_éxécution = False
        End Sub
        Dim num As Integer
        Dim Bénéficiaire As String
        Dim Assuré As String
        Dim CRLdeFSE As String
        Dim CRLdeDRE As String

        Dim G1110C1 As String 'N° de facture
        Dim G1110C2 As String
        Dim G1110C3 As String
        Dim G1110C4 As String
        Dim G1110C5 As String
        Dim G1110C6 As String

        Dim G1120C1 As String
        Dim G1120C2 As String
        Dim G1120C3 As String
        Dim G1120C4 As String
        Dim G1120C5 As String
        Dim G1120C6 As String
        Dim G1120C7 As String
        Dim G1120C8 As String
        Dim G1120C9 As String
        Dim G1120C10 As String
        Dim G1120C11 As String
        Dim G1120C12 As String
        Dim G1120C13 As String
        Dim G1120C14 As String

        Dim G1130C1 As String
        Dim G1130C2 As String
        Dim G1130C3 As String
        Dim G1130C4 As String
        Dim G1130C5 As String
        Dim G1130C6 As String
        Dim G1130C7 As String
        Dim G1130C8 As String
        Dim G1130C9 As String

        Dim G1140C1 As String
        Dim G1140C2 As String
        Dim G1140C3 As String

        Dim G1150C1 As String
        Dim G1150C2 As String
        Dim G1150C3 As String
        Dim G1150C4 As String
        Dim G1150C5 As String

        Dim G1160C1 As String
        Dim G1160C2 As String

        Dim G1170C1 As String

        Dim G1211C1 As String
        Dim G1211C2 As String
        Dim G1211C3 As String
        Dim G1211C4 As String
        Dim G1211C5 As String
        Dim G1211C6 As String
        Dim G1211C7 As String

        Dim G1213C1 As String
        Dim G1213C2 As String
        Dim G1213C3 As String
        Dim G1213C4 As String
        Dim G1213C5 As String
        Dim G1213C6 As String
        Dim G1213C7 As String
        Dim G1213C8 As String

        Dim G1214C1 As String
        Dim G1214C2 As String
        Dim G1214C3 As String
        Dim G1214C4 As String
        Dim G1214C5 As String
        Dim G1214C6 As String
        Dim G1214C7 As String
        Dim G1214C8 As String

        Dim G1230C1 As String

        Dim G1310C1 As String
        Dim G1310C2 As String
        Dim G1310C3 As String
        Dim G1310C4 As String
        Dim G1310C5 As String

        Dim G1321C1 As String
        Dim G1321C2 As String
        Dim G1321C3 As String
        Dim G1321C4 As String
        Dim G1321C5 As String
        Dim G1321C6 As String
        Dim G1321C7 As String
        Dim G1321C8 As String
        Dim G1321C9 As String
        Dim G1321C10 As String
        Dim G1321C11 As String
        Dim G1321C12 As String
        Dim G1321C13 As String

        Dim G1330C1 As String
        Dim G1330C2 As String
        Dim G1330C3 As String

        Dim G1410C1 As String
        Dim G1410C2 As String

        Dim G1420C1 As String
        Dim G1420C2 As String
        Dim G1420C3 As String

        Dim G1440C1 As String
        Dim G1440C2 As String
        Dim G1440C3 As String

        Dim G1450C1 As String
        Dim G1450C2 As String

        Dim G1511C1 As String
        Dim G1511C2 As String

        Dim G1512C1 As String

        Dim G1513C1 As String
        Dim G1513C2 As String
        Dim G1513C3 As String

        Dim G1514C1 As String
        Dim G1514C2 As String
        Dim G1514C3 As String
        Dim G1514C4 As String

        Dim G1515C1 As String

        'Dim G1850C2 As String

        Dim G1910C1 As Single
        Dim G1910C2 As Single
        Dim G1910C3 As Single
        Dim G1910C4 As Single
        Dim G1910C5 As Single
        Dim G1910C6 As Single

        Dim G3700C1 As String
        Dim G3700C2 As String

        Dim G3730C1 As String

        Dim IDPrescripteur As String
        Dim FactureAcree As String
        Dim ModeSecur As String
        Dim TabLigneFacture() As LigneFactureVitale
        Dim G1840 As G1840()
        Dim G1740C7() As String
        Dim TP_AMO As Boolean
        Dim TP_AMC As Boolean
        Dim TOP_CMU As Boolean
        Dim Sortant_CMU As Boolean
        'Dim GestionUnique As Boolean
        Dim Mode_Gestion As String
        Dim PEC As PEC
        Dim Forçage_Part_AMO() As Forçage_Part_AMO
        Dim G1741() As G1741
        Dim Renouvellement_Date_Droits_AMO_est_date_éxécution As Boolean
        Dim Non_Rembousable_CheckBox() As Boolean
    End Structure
    Public Structure LigneFactureVitale

        Dim G1610C1 As String
        Dim G1610C2 As String
        Dim G1610C3 As String
        Dim G1610C4 As String
        Dim G1610C5 As String
        Dim G1610C6 As Single
        Dim G1610C7 As String
        Dim G1610C8 As String
        Dim G1610C9 As String
        Dim G1610C10 As String
        Dim G1610C11 As Single
        Dim G1610C12 As Single
        Dim G1610C13 As Single
        Dim G1610C14 As Single
        Dim G1610C15 As Single
        Dim G1610C16 As Single

        Dim DétailLpp As DétailLpp()
        Dim DétailCodeCIP As DétailCodeCIP

        Dim G1820C2 As String

        Dim G1840C2 As String
        Dim G1840C3 As String
        Dim G1840C4 As String

        Dim G1850C2 As String

        Dim G2000C2 As String

        Dim G2010C2 As String

        Dim G2030C2 As String
        Dim G2030C3 As String

        Dim G3710C2 As String
        Dim G3710C3 As String
        Dim G3710_Paramètes As String
    End Structure
    Public Structure PEC_Montant_Acte
        Dim Num_Acte As Integer
        Dim Montant As Integer
    End Structure
    Public Structure PEC
        Dim MontantGlobal As Integer
        Dim Reste_Ventilation_Montant_Global As Integer
        Dim Reste_Ventilation_Montant_Global_STS As Integer
        Dim Montants_Actes() As PEC_Montant_Acte
        Public Sub clear()
            MontantGlobal = 0
            Reste_Ventilation_Montant_Global = 0
            Reste_Ventilation_Montant_Global_STS = 0
            ReDim Montants_Actes(0)
        End Sub
    End Structure
    Public Structure G1840 'ENTENTE PREALABLE
        Dim G1840C1 As Integer 'N° de la prestation (de rattachement)
        Dim G1840C2 As String 'Code accord entente préalable
        Dim G1840C3 As String 'Date d’envoi de la demande d’entente préalable
    End Structure
    Public Structure Forçage_Part_AMO
        Dim Num_Acte As Integer
        Dim Montant As Integer
    End Structure
    Public Structure G1741
        Dim G1741C1 As Integer
        Dim G1741C2 As Integer
        Dim G1741C3 As String
        Dim G1741C4 As String
        Dim G1741C5 As String
        Dim G1741C6 As String
    End Structure




    'type FactureVenteDirecte
    Public Structure FactureVenteDirecte
        Public Sub Clear()
            NumVenteDirecte = 0
            Nir = ""
            Nom_Complet = ""
            Date_ = ""
            Total = 0
            ReDim lignes(0)
        End Sub
        Dim NumVenteDirecte As Integer
        Dim Nir As String
        Dim Nom_Complet As String
        Dim Date_ As String
        Dim Total As Single
        Dim lignes As LigneFactureVenteDirecte()
    End Structure
    Public Structure LigneFactureVenteDirecte
        Dim NumActe As Integer
        Dim CIP As String
        Dim EAN13 As String
        Dim PrixUnitaire As Double
        Dim Quantité As Integer
        'Dim Remise As Double
        Dim Total As Double

    End Structure

    'type DétailLpp
    Public Structure DétailLpp
        Dim G1730C1 As String
        Dim G1730C2 As String
        Dim G1730C3 As String
        Dim G1730C4 As String
        Dim G1730C5 As String
        Dim G1730C6 As String
        Dim G1730C7 As String
        Dim G1730C8 As String
        Dim G1730C9 As String
        Dim G1730C10 As String
        Dim G1730C11 As String
    End Structure

    'type DétailCodeCIP
    Public Structure DétailCodeCIP

        Dim G1740C1 As String
        Dim G1740C2 As String
        Dim G1740C3 As String
        Dim G1740C4 As Single
        Dim G1740C5 As String
        Dim G1740C6 As String
        Dim G1740C7 As String
        Dim G1740C8 As String
        Dim G1740C9 As String
        Dim G1740C10 As String
        Dim G1740C11 As String
        Dim G1740C12 As String
        Dim G1740C13 As String
        Dim G1740C14 As String
        Dim G1740C15 As String

    End Structure

    'Benéficiaire
    Public Structure Benéficiaire

        Public Sub clear()
            G101C1 = ""
            G101C2 = ""
            G101C3 = ""
            G101C4 = ""
            G101C5 = ""
            G101C6 = ""
            G101C7 = ""
            G101C8 = ""
            G101C9 = ""
            G101C10 = ""
            G101C11 = ""
            G101C12 = ""
            G101C13 = ""
            G101C14 = ""
            G102C1 = ""
            G102C2 = ""
            G102C3 = ""
            G103C1 = ""
            G103C2 = ""
            G103C3 = ""
            G103C4 = ""
            G103C5 = ""
            G103C6 = ""
            G103C7 = ""
            G103C8 = ""
            G103C9 = ""
            G104C1 = ""
            G104C2 = ""
            G104C3 = ""
            G104C4 = ""
            G104C5 = ""
            G104C6 = ""
            G104C7 = ""
            G104C8 = ""
            G104C9 = ""
            G104C10 = ""
            G104C11 = ""
            G104C12 = ""
            G104C13 = ""
            G104C14 = ""
            G104C15 = ""
            G104C16 = ""
            G104C17 = ""
            G104C18 = ""
            G107C1 = ""
            G107C2 = ""
            G107C3 = ""
            G107C4 = ""
            G107C5 = ""
            G107C6 = ""
            G109C1 = ""
            G109C2 = ""
            G109C3 = ""
            G109C4 = ""
            G109C5 = ""
            G109C6 = ""
            G109C7 = ""
            G109C8 = ""
            G109C9 = ""
            G109C10 = ""
            G109C11 = ""
            G109C12 = ""
            G111C1 = ""
            Prescripteur_ID = ""
            Prescripteur_CodeSpécialité = ""
            AMC_NumOrganisme = ""
            AMC_NumAdherent = ""
            AMC_DateDébut = ""
            AMC_DateFin = ""
            AMC_Piecejustificative = ""
            AMC_TypeContrat = ""
            AMC_NumMutuelle = ""
            AMC_Code_Aiguillage_STS = ""
            AMC_Indicateurdetrairement = ""
            AMC_CodeRoutage = ""
            AMC_IdHote = ""
            AMC_NomDomaine = ""
            AMC_Type_Convention = ""
            AMC_Critère_secondaire = ""
            AMC_IdentifiantAMC = ""
            ReDim G105C1(0)
            ReDim G105C2(0)
            ReDim G106C1(0)
            ReDim G106C2(0)
            ReDim G106C3(0)
            ReDim G106C4(0)
            ReDim G108C1(0)
            ReDim G108C2(0)
            Assuré = ""
            G1420C1 = ""
            G1420C2 = ""
            G1420C3 = ""
            G1511C2 = ""
            CMU__assimilation_mode_gestion_unique = False
            CMU_justificatif_papier_droits_CMU_C_délivré_par_organisme_obligatoire = False

            If Not Crédits_en_Cours Is Nothing Then
                Crédits_en_Cours.Clear()
            Else
                Crédits_en_Cours = New List(Of PharmaDataSet.EncaissementsRow)
            End If

            Organisme = ""
            Num = 0
            Chronique_Periode = 0
            Organisme_de_residence = ""
            Chronique_Periode_decalage_jour = 0

            Delivrance_Lieu = ""

            DMP_Statut = ""
        End Sub

        'Groupe 101
        Dim G101C1 As String 'Type de carte Vitale
        Dim G101C2 As String 'N° de série de la carte Vitale
        Dim G101C3 As String 'Date de fin de validité carte Vitale
        Dim G101C4 As String 'Données administration carte RUF1
        Dim G101C5 As String 'Données administration carte RUF2
        Dim G101C6 As String 'Données RUF administration
        Dim G101C7 As String 'Type d'identification du porteur de la carte
        Dim G101C8 As String 'NIR
        Dim G101C9 As String 'Clé du NIR
        Dim G101C10 As String 'Code régime
        Dim G101C11 As String 'Caisse gestionnaire
        Dim G101C12 As String 'Centre gestionnaire
        Dim G101C13 As String 'Code gestion
        Dim G101C14 As String 'Données RUF Famille

        'Groupe 102
        Dim G102C1 As String 'Code service AMO Famille
        Dim G102C2 As String 'Date de début du service AMO Famille
        Dim G102C3 As String 'Date de fin du service AMO Famille

        'Groupe 103
        Dim G103C1 As String 'Organisme gestionnaire du risque AT
        Dim G103C2 As String 'Code AT BGDH
        Dim G103C3 As String 'Identifiant AT
        Dim G103C4 As String 'Organisme gestionnaire AT1
        Dim G103C5 As String 'Code AT1 BGDH
        Dim G103C6 As String 'Identifiant AT1
        Dim G103C7 As String 'Organisme gestionnaire AT2
        Dim G103C8 As String 'Code AT2 BGDH
        Dim G103C9 As String 'Identifiant AT2

        'Groupe 104
        Dim G104C1 As String 'Nom usuel du bénéficiaire
        Dim G104C2 As String 'Nom de famille du bénéficiaire
        Dim G104C3 As String 'Prénom du bénéficiaire
        Dim G104C4 As String 'Adresse ligne 1
        Dim G104C5 As String 'Adresse ligne 2
        Dim G104C6 As String 'Adresse ligne 3
        Dim G104C7 As String 'Adresse ligne 4
        Dim G104C8 As String 'Adresse ligne 5
        Dim G104C9 As String 'NIR certifié
        Dim G104C10 As String 'Clé NIR certifié
        Dim G104C11 As String 'Date de certification du NIR
        Dim G104C12 As String 'Date de naissance du bénéficiaire
        Dim G104C13 As String 'Rang de naissance
        Dim G104C14 As String 'Qualité
        Dim G104C15 As String 'Code service AMO bénéficiaire
        Dim G104C16 As String 'Date de début du service AMO bénéficiaire
        Dim G104C17 As String 'Date de fin du service AMO bénéficiaire
        Dim G104C18 As String 'Données RUF AMO bénéficiaire

        'Groupe 105
        Dim G105C1() As String 'Date de début droits AMO
        Dim G105C2() As String 'Date de fin droits AMO

        'Groupe 106
        Dim G106C1() As String 'Date de début code couverture
        Dim G106C2() As String 'Date de fin code couverture
        Dim G106C3() As String 'Code ALD
        Dim G106C4() As String 'Code situation

        'Groupe 107
        Dim G107C1 As String 'Identification Mutuelle
        Dim G107C2 As String 'Garanties effectives
        Dim G107C3 As String 'Indicateur de traitement mutuelle
        Dim G107C4 As String 'Type de services associés
        Dim G107C5 As String 'Services associés au contrat
        Dim G107C6 As String 'Code aiguillage STS

        'Groupe 108
        Dim G108C1() As String 'Date de début droits mutuelle
        Dim G108C2() As String 'Date de fin droits mutuelle

        'Groupe 109
        Dim G109C1 As String 'N° de complémentaire B2
        Dim G109C2 As String 'N° de complémentaire EDI
        Dim G109C3 As String 'N° d’adhérent AMC
        Dim G109C4 As String 'Indicateur de traitement AMC
        Dim G109C5 As String 'Date de début de validité de présence des données AMC
        Dim G109C6 As String 'Date de fin de validité de présence des données AMC
        Dim G109C7 As String 'Code de routage flux AMC
        Dim G109C8 As String 'Identifiant d’hôte
        Dim G109C9 As String 'Nom de domaine AMC
        Dim G109C10 As String 'Code aiguillage STS
        Dim G109C11 As String 'Type de services associés
        Dim G109C12 As String 'Services associés au contrat

        'Groupe 111
        Dim G111C1 As String 'Données RUF bénéficiaire complémentaire

        'Prescripteur
        Dim Prescripteur_ID As String
        Dim Prescripteur_CodeSpécialité As String

        'données AMC 
        Dim AMC_NumOrganisme As String
        Dim AMC_NumAdherent As String
        Dim AMC_DateDébut As String
        Dim AMC_DateFin As String
        Dim AMC_Piecejustificative As String
        Dim AMC_TypeContrat As String
        Dim AMC_Indicateurdetrairement As String
        Dim AMC_NumMutuelle As String
        Dim AMC_Code_Aiguillage_STS As String
        Dim AMC_CodeRoutage As String
        Dim AMC_IdHote As String
        Dim AMC_NomDomaine As String
        Dim AMC_Type_Convention As String
        Dim AMC_Critère_secondaire As String
        Dim AMC_IdentifiantAMC As String

        Dim CMU__assimilation_mode_gestion_unique As Nullable(Of Boolean)
        Dim CMU_justificatif_papier_droits_CMU_C_délivré_par_organisme_obligatoire As Nullable(Of Boolean)
        'Assuré(nom prénom)
        Dim Assuré As String

        'Groupe1420 Identification de pièce justificative pour l’AMO (pour mode dégradé)
        Dim G1420C1 As String 'Nature de la pièce justificative
        Dim G1420C2 As String 'Date de validité de la pièce
        Dim G1420C3 As String 'Origine de la pièce justificative

        'Indicateur Régime Alsace - Moselle(
        Dim G1511C2 As String

        Dim Crédits_en_Cours As List(Of PharmaDataSet.EncaissementsRow)
     
        Dim Organisme As String

        Dim Num As Integer

        Dim Chronique_Periode As Integer

        Dim Organisme_de_residence As String

        Dim Chronique_Periode_decalage_jour As Int32

        Dim Delivrance_Lieu As String

        Dim DMP_Statut As String
    End Structure

    'ligne vente
    Public Structure Ligne_Vente

        Dim Ligne_traitée As Boolean

        Dim liste As String
        Dim deconditionement As Boolean
        Dim deconditionement_prix_unitaire As Integer
        Dim deconditionement_quantité As Integer
        Dim deconditionement_NmbreBoites As Integer

        'Entente Préalable G1840 optionel
        Dim Entente_Préalable_code_accord As String
        Dim Entente_Préalable_date_envoi_demande As String

    End Structure

    'type convention
    Public Structure Convention
        Public Sub clear()
            selected = False
            Code_action = ""
            Code_catégorie = ""
            Spécialité = ""
            Référence_de_convention = ""
            Message = ""
            Identifiant_org_signataire = ""
            Libellé_org_signataire = ""
            indicateur_convention_groupée = ""
            type_Identifiant_org_signataire = ""
            critère_secondaire = ""
            type_Accord = ""
            Num_AMC = ""
            libellé_Org_complémentaire = ""
            indic_desactivation_STS = ""
            Code_aiguillage_STS = ""
            usage_attestation_papier = ""
            Accepatation_DRE_Annulation = ""
            Acceptation_DRE_Rectification = ""
            Identifiant_Opérateur_règlement = ""
            Code_routage = ""
            identifiant_hôte = ""
            nom_domaine = ""
        End Sub
        Dim selected As Boolean
        Dim Code_action As String
        Dim Code_catégorie As String
        Dim Spécialité As String
        Dim Référence_de_convention As String
        Dim Message As String
        Dim Identifiant_org_signataire As String
        Dim Libellé_org_signataire As String
        Dim indicateur_convention_groupée As String
        Dim type_Identifiant_org_signataire As String
        Dim critère_secondaire As String
        Dim type_Accord As String
        Dim Num_AMC As String
        Dim libellé_Org_complémentaire As String
        Dim indic_desactivation_STS As String
        Dim Code_aiguillage_STS As String
        Dim usage_attestation_papier As String
        Dim Accepatation_DRE_Annulation As String
        Dim Acceptation_DRE_Rectification As String
        Dim Identifiant_Opérateur_règlement As String
        Dim Code_routage As String
        Dim identifiant_hôte As String
        Dim nom_domaine As String


    End Structure


#Region "STS"
    Public current_Groupe As Integer

    Public Structure Valeur_STS
        Dim groupe As Integer
        Dim occurence As Integer
        Dim champ As Integer
        Dim valeur As String
        Dim affichage As String
        Dim modification As String
        Dim NumPrestation As Integer
    End Structure
    Public Tab_Valeur_STS() As Valeur_STS

    Public Structure formule_STS
        Dim selected As Boolean
        Dim Numéro As String
        Dim Libellé As String
        Dim nombre_de_paramètres As Integer
        Dim paramètres() As Paramètre_formule_STS
        Dim num_prestation_de_rattachement As String
        Dim pour_toutes_prestations As Boolean

        Public Structure Paramètre_formule_STS
            Dim numéro As Integer
            Dim Libellé As String
            Dim Type As String
            Dim valeur_par_defaut As String
            Dim valeur_affectée As String
        End Structure

        Public Sub Clear()
            selected = False
            Numéro = ""
            Libellé = ""
            nombre_de_paramètres = 0
            ReDim paramètres(-1)
            num_prestation_de_rattachement = ""
            pour_toutes_prestations = False
        End Sub

    End Structure
    Public current_formule_STS As formule_STS
    Public tab_current_formule_STS() As formule_STS
#End Region


    'Accident Travail g103- As string g1310, g1513
    Public Structure AccidentDuTravail
        Dim DateAT As String
        Dim NumAT As String
        Dim CléAT As String
        Dim CodeRégime, CaisseGest, CentreGest As String
        Dim selected As Boolean
        Public Sub clear()
            DateAT = ""
            NumAT = ""
            CléAT = ""
            CodeRégime = ""
            CaisseGest = ""
            CentreGest = ""
            selected = False
        End Sub
    End Structure
    Public current_AT As AccidentDuTravail


    'CONFIG
    Public Structure Configuration

        Dim typedriverscan As String
        Dim cerfa_debile As Boolean


        Dim LocalNetwork_ServerName As String
        Dim is_local_client As Boolean

        Dim Logiciel_ModeFonctionement As String ' Demo, Test, Réel

        Dim SMTP_From As String
        Dim SMTP_VersionCDC As String
        Dim SMTP_CheminSource As String
        Dim SMTP_CheminDepot As String
        Dim SMTP_CheminSauvegarde As String
        Dim SMTP_Message_ID As String
        Dim SMTP_TypeEmetteurFichier As String
        Dim SMTP_NumEmetteurFichier As String
        Dim SMTP_MessageFormatFichier As String
        Dim SMTP_CompresserDonnees As String
        Dim SMTP_Postmaster As String
        Dim SMTP_Serveur_Externe As String
        Dim SMTP_Serveur_Externe_port As Integer
        Dim SMTP_Serveur_Externe_User As String
        Dim SMTP_Serveur_Externe_Password As String

        Dim POP3_Serveur As String
        Dim POP3_Port As String
        Dim POP3_User As String
        Dim POP3_Password As String
        Dim POP3_RepBAL As String

        Dim OCT_UtilisationOCT As Boolean
        Dim OCT_AdressemailOCT As String
        Dim OCT_TypeDestinataire As String
        Dim OCT_Application As String
        Dim OCT_FSEenrichies As Boolean
        Dim OCT_FSE_FichierUnique As Boolean
        Dim OCT_FSE_Eclatement_Source As Boolean
        Dim OCT_NumDestinataire As String
        Dim OCT_RPH_date_Format_DDMMAA As Boolean

        Dim GALSS_NomRessourcePS As String
        Dim GALSS_NomRessourceLecteur As String

        Dim Configuration_Desynchroniser As Boolean

        Dim Repertoires_RepertoireFactures As String
        Dim Repertoires_RepertoireFichiers As String
        Dim Repertoires_RepertoirePickup As String

        Dim Data_PMSS As String
        Dim Data_ContaceptifUrgence_NIR As String
        Dim Data_ContaceptifUrgence_cle As String
        Dim Data_ContaceptifUrgence_datenaissance As String
        Dim Data_ContaceptifUrgence_NumPrecripteur As String
        Dim Data_ContaceptifUrgence_CleNumPrecripteur As String
        Dim Data_ContaceptifUrgence_ContraceptifCIP As String
        Dim Data_ContaceptifUrgence_CaisseGest As String
        Dim Data_ContaceptifUrgence_CentreGest As String

        Dim Conventions_Activer As Boolean

        Dim STS_Activer As Boolean
        Dim STS_AfficheDiagNiv1 As Boolean

        Dim Titulaire_Num_Id_Nat As String
        Dim Titulaire_Cle_Num_Id_Nat As String
        Dim Titulaire_Num_Id_Facturation As String
        Dim Titulaire_Cle_Num_Id_Facturation As String
        Dim Titulaire_Nom As String
        Dim Titulaire_Prenom As String
        Dim Titulaire_Code_Conventionnel As String
        Dim Titulaire_Code_specialite As String
        Dim Titulaire_Code_Zone_tarifaire As String
        Dim Titulaire_Code_Zone_IK As String
        Dim Titulaire_Code__Agrement_1 As String
        Dim Titulaire_Code__Agrement_2 As String
        Dim Titulaire_Code__Agrement_3 As String
        Dim Titulaire_Condition_Exercice As String
        Dim Titulaire_Num_RPPS As String
        Dim Titulaire_Cle_Num_RPPS As String
        Dim Titulaire_raison_sociale As String
        Dim Titulaire_Num_log_situ_fact As Byte
        Dim Activer_Session_Remplacement As Boolean
        Dim Remplacant_Num_Id_Nat As String
        Dim Remplacant_Cle_Num_Id_Nat As String
        Dim Remplacant_Num_Id_Facturation As String
        Dim Remplacant_Cle_Num_Id_Facturation As String
        Dim Remplacant_Num_log_situ_fact As String

        Dim MessageFormatFichier As String
        Dim Type_émetteur_fichier As String
        Dim num_émetteur_fichier As String

        'LOI
        Dim LOI_Pop3_Serveur As String
        Dim LOI_Pop3_Port As String
        Dim LOI_Pop3_User As String
        Dim LOI_Pop3_Password As String
        Dim LOI_Pop3_BAL As String
        Dim LOI_Pop3_RepBAL As String
        Dim LOI_Distr_OCT As String
        Dim LOI_Distr_horsOCT As String
        Dim LOI_Activer As Boolean
        Dim LOI_Ref As String
        Dim LOI_NB_JOUR_Max As Integer
        Dim LOI_Demande_Auto As Boolean
        Dim LOI_Controle_MAJ_mensuel As Boolean
        Dim LOI_Verif_InReply_To As Boolean
        Dim LOI_Controle_Correspondance As Boolean
        Dim LOI_code_resultat_incr_prec As String
        Dim LOI_smtp_serveur As String
        Dim LOI_smtp_serveur_port As Integer
        Dim LOI_cert_nums As String
        Dim LOI_clé_GIP_CPS As String

        Dim SesamIni As String 'chemin/nom_de_fichier de sesam.ini


        Dim Hono_Disp_Activer As Boolean
        Dim Hono_Disp_HC_tarif As Integer
        Dim Hono_Disp_HDA_tarif As Integer
        Dim Hono_Disp_HDE_tarif As Integer
        Dim Hono_Disp_HDR_tarif As Integer


        Dim DP_Activer As Boolean
        Dim DP_URI As String
        Dim DP_EtaTyp As String
        Dim DP_EtaIdent As String
        Dim DP_LogValid As String
        Dim DP_LogVers As String
        Dim DP_LogVDP As String
        Dim DP_ReqProd As String
        Dim DP_Consulatation_reconnect As Boolean
        Dim DP_is_local_client As Boolean
        Dim DP_Certif As String
        Dim Piam1 As Integer
        Dim Piam2 As Integer
        Dim Piam3 As Integer
        Dim DP_Inciter As Boolean
        Dim DP_Directory As String

        'SCOR
        Dim Scor_from As String
        Dim Scor_TaillMaxLot As Long
        Dim Scor_CodeRégion As Long
        Dim Scor_Adr_OCT As String
        Dim Scor_Dest_ARL As String
        Dim Scor_cdrom As Boolean
        Dim Scor_cdrom_inter As Integer
        Dim Scor_cdrom_lastdate As Date
        Dim Scor_Directory As String
        Dim Scor_Transmission_via_OCT As Boolean
        Dim Scor_hide_VenteForm_WebBrowser_SCOR As Boolean

        'Pharma_ml
        Dim Pharma_ml_Répartiteur_principal As String
        Dim Pharma_ml_Répartiteur_secondaire As String

        Dim Idposte As String
        Dim Ticket_du_default_printer As String
        Dim Ticket_du_lignes_blanches As Integer
        Dim Ticket_pause_default_printer As String
        Dim Ticket_pause_lignes_blanches As Integer
        Dim Windows_Mode As Boolean

        'facilEpharm
        Dim facilEpharm_Activé As Boolean
        Dim facilEpharm_intervalle_Control As Integer
        Dim facilEpharm_Rep_Doc As String

        'Dim Technique_Bandeau_info_bas_show As Boolean









        Public Sub Load_Config_File()


            Dim ConfigXml As New XmlDocument
            Dim ConfigXMLelementliste As XmlNodeList
            ConfigXml.Load(Application.StartupPath & "\config.xml")
            Dim need_to_save = False

            typedriverscan = ""
            Try
                ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Tech")
                typedriverscan = ConfigXMLelementliste.Item(0).Item("typedriverscan").InnerText
            Catch ex As Exception
            End Try
            cerfa_debile = False
            Try
                ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Tech")
                If UCase(ConfigXMLelementliste.Item(0).Item("cerfa_debile").InnerText) = "OUI" Then
                    cerfa_debile = True
                End If
            Catch ex As Exception
            End Try

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("InfoPoste")
            Idposte = ConfigXMLelementliste.Item(0).Item("Idposte").InnerText
            Ticket_du_default_printer = ConfigXMLelementliste.Item(0).Item("Ticket_du_default_printer").InnerText
            Ticket_du_lignes_blanches = CInt(ConfigXMLelementliste.Item(0).Item("Ticket_du_lignes_blanches").InnerText)
            Ticket_pause_default_printer = ConfigXMLelementliste.Item(0).Item("Ticket_pause_default_printer").InnerText
            Ticket_pause_lignes_blanches = CInt(ConfigXMLelementliste.Item(0).Item("Ticket_pause_lignes_blanches").InnerText)
            If UCase(ConfigXMLelementliste.Item(0).Item("Windows_Mode").InnerText) = "OUI" Then
                Windows_Mode = True
            Else
                Windows_Mode = False
            End If


            '<LocalNetwork>
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("LocalNetwork")
            LocalNetwork_ServerName = ConfigXMLelementliste.Item(0).Item("ServerName").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("is_local_client").InnerText) = "OUI" Then
                is_local_client = True
            Else
                is_local_client = False
            End If


            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("SMTP")
            SMTP_From = ConfigXMLelementliste.Item(0).Item("From").InnerText
            SMTP_VersionCDC = ConfigXMLelementliste.Item(0).Item("VersionCDC").InnerText
            SMTP_CheminSource = ConfigXMLelementliste.Item(0).Item("CheminSource").InnerText
            SMTP_CheminDepot = ConfigXMLelementliste.Item(0).Item("CheminDepot").InnerText
            SMTP_CheminSauvegarde = ConfigXMLelementliste.Item(0).Item("CheminSauvegarde").InnerText
            SMTP_Message_ID = ConfigXMLelementliste.Item(0).Item("Message_ID").InnerText
            SMTP_TypeEmetteurFichier = ConfigXMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText
            SMTP_NumEmetteurFichier = ConfigXMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText
            SMTP_MessageFormatFichier = ConfigXMLelementliste.Item(0).Item("MessageFormatFichier").InnerText
            SMTP_CompresserDonnees = ConfigXMLelementliste.Item(0).Item("CompresserDonnees").InnerText
            SMTP_Postmaster = ConfigXMLelementliste.Item(0).Item("Postmaster").InnerText
            MessageFormatFichier = ConfigXMLelementliste.Item(0).Item("MessageFormatFichier").InnerText
            Type_émetteur_fichier = ConfigXMLelementliste.Item(0).Item("TypeEmetteurFichier").InnerText
            num_émetteur_fichier = ConfigXMLelementliste.Item(0).Item("NumEmetteurFichier").InnerText
            SMTP_Serveur_Externe = ConfigXMLelementliste.Item(0).Item("Serveur_Externe").InnerText
            SMTP_Serveur_Externe_port = Val(ConfigXMLelementliste.Item(0).Item("Serveur_Externe_port").InnerText)
       
            Try
                SMTP_Serveur_Externe_User = ConfigXMLelementliste.Item(0).Item("Serveur_Externe_User").InnerText
                SMTP_Serveur_Externe_Password = ConfigXMLelementliste.Item(0).Item("Serveur_Externe_Password").InnerText
            Catch ex As Exception
                SMTP_Serveur_Externe_User = ""
                SMTP_Serveur_Externe_Password = ""
            End Try

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Pop3")
            POP3_Serveur = ConfigXMLelementliste.Item(0).Item("Serveur").InnerText
            POP3_Port = ConfigXMLelementliste.Item(0).Item("Port").InnerText
            POP3_User = ConfigXMLelementliste.Item(0).Item("User").InnerText
            POP3_Password = ConfigXMLelementliste.Item(0).Item("Password").InnerText
            POP3_RepBAL = ConfigXMLelementliste.Item(0).Item("RepBAL").InnerText

            'OCT
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("OCT")
            If UCase(ConfigXMLelementliste.Item(0).Item("UtilisationOCT").InnerText) = "OUI" Then
                OCT_UtilisationOCT = True
            Else
                OCT_UtilisationOCT = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("FSEenrichies").InnerText) = "OUI" Then
                OCT_FSEenrichies = True
            Else
                OCT_FSEenrichies = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("FSE_FichierUnique").InnerText) = "OUI" Then
                OCT_FSE_FichierUnique = True
            Else
                OCT_FSE_FichierUnique = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("FSE_Eclatement_Source").InnerText) = "OUI" Then
                OCT_FSE_Eclatement_Source = True
            Else
                OCT_FSE_Eclatement_Source = False
            End If
            OCT_AdressemailOCT = ConfigXMLelementliste.Item(0).Item("AdressemailOCT").InnerText
            OCT_TypeDestinataire = ConfigXMLelementliste.Item(0).Item("TypeDestinataire").InnerText
            OCT_Application = ConfigXMLelementliste.Item(0).Item("Application").InnerText
            OCT_NumDestinataire = ConfigXMLelementliste.Item(0).Item("OCT_NumDestinataire").InnerText
            OCT_RPH_date_Format_DDMMAA = False
            If Not ConfigXMLelementliste.Item(0).Item("OCT_RPH_date_Format_DDMMAA") Is Nothing Then
                If UCase(ConfigXMLelementliste.Item(0).Item("OCT_RPH_date_Format_DDMMAA").InnerText) = "OUI" Then
                    OCT_RPH_date_Format_DDMMAA = True
                End If
            End If


            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("GALSS")
            GALSS_NomRessourcePS = ConfigXMLelementliste.Item(0).Item("NomRessourcePS").InnerText
            GALSS_NomRessourceLecteur = ConfigXMLelementliste.Item(0).Item("NomRessourceLecteur").InnerText

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Configuration")
            Config.Logiciel_ModeFonctionement = ConfigXMLelementliste.Item(0).Item("ModeFonctionnement").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("Desynchroniser").InnerText) = "OUI" Then
                Configuration_Desynchroniser = True
            Else
                Configuration_Desynchroniser = False
            End If

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Repertoires")
            Repertoires_RepertoireFactures = ConfigXMLelementliste.Item(0).Item("RepertoireFactures").InnerText
            Repertoires_RepertoireFichiers = ConfigXMLelementliste.Item(0).Item("RepertoireFichiers").InnerText
            Repertoires_RepertoirePickup = ConfigXMLelementliste.Item(0).Item("RepertoirePickup").InnerText

            'Data
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Data")
            Data_PMSS = ConfigXMLelementliste.Item(0).Item("PMSS").InnerText

            'ContaceptifUrgence
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("ContaceptifUrgence")
            Data_ContaceptifUrgence_NIR = ConfigXMLelementliste.Item(0).Item("NIR").InnerText
            Data_ContaceptifUrgence_cle = ConfigXMLelementliste.Item(0).Item("cle").InnerText
            Data_ContaceptifUrgence_datenaissance = ConfigXMLelementliste.Item(0).Item("datenaissance").InnerText
            Data_ContaceptifUrgence_NumPrecripteur = ConfigXMLelementliste.Item(0).Item("NumPrecripteur").InnerText
            Data_ContaceptifUrgence_CleNumPrecripteur = ConfigXMLelementliste.Item(0).Item("CleNumPrecripteur").InnerText
            Data_ContaceptifUrgence_ContraceptifCIP = ConfigXMLelementliste.Item(0).Item("ContraceptifCIP").InnerText
            Data_ContaceptifUrgence_CaisseGest = ConfigXMLelementliste.Item(0).Item("CaisseGest").InnerText
            Data_ContaceptifUrgence_CentreGest = ConfigXMLelementliste.Item(0).Item("CentreGest").InnerText


            'Conventions
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Conventions")
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
                Conventions_Activer = True
            Else
                Conventions_Activer = False
            End If

            'STS
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("STS")
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
                STS_Activer = True
            Else
                STS_Activer = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("AfficheDiagNiv1").InnerText) = "OUI" Then
                STS_AfficheDiagNiv1 = True
            Else
                STS_AfficheDiagNiv1 = False
            End If

            'remplacement
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Remplacement")
            Titulaire_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_Id_Nat").InnerText
            Titulaire_Cle_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Titulaire_Cle_Num_Id_Nat").InnerText
            Titulaire_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_Id_Facturation").InnerText
            Titulaire_Cle_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Titulaire_Cle_Num_Id_Facturation").InnerText
            Titulaire_Nom = ConfigXMLelementliste.Item(0).Item("Titulaire_Nom").InnerText
            Titulaire_Prenom = ConfigXMLelementliste.Item(0).Item("Titulaire_Prenom").InnerText
            Titulaire_Code_Conventionnel = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_Conventionnel").InnerText
            Titulaire_Code_specialite = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_specialite").InnerText
            Titulaire_Code_Zone_tarifaire = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_Zone_tarifaire").InnerText
            Titulaire_Code_Zone_IK = ConfigXMLelementliste.Item(0).Item("Titulaire_Code_Zone_IK").InnerText
            Titulaire_Code__Agrement_1 = ConfigXMLelementliste.Item(0).Item("Titulaire_Code__Agrement_1").InnerText
            Titulaire_Code__Agrement_2 = ConfigXMLelementliste.Item(0).Item("Titulaire_Code__Agrement_2").InnerText
            Titulaire_Code__Agrement_3 = ConfigXMLelementliste.Item(0).Item("Titulaire_Code__Agrement_3").InnerText
            Titulaire_Condition_Exercice = ConfigXMLelementliste.Item(0).Item("Titulaire_Condition_Exercice").InnerText
            Titulaire_Num_RPPS = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_RPPS").InnerText
            Titulaire_Cle_Num_RPPS = ConfigXMLelementliste.Item(0).Item("Titulaire_Cle_Num_RPPS").InnerText
            Titulaire_raison_sociale = ConfigXMLelementliste.Item(0).Item("Titulaire_raison_sociale").InnerText
            Titulaire_Num_log_situ_fact = ConfigXMLelementliste.Item(0).Item("Titulaire_Num_log_situ_fact").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer_Session_Remplacement").InnerText) = "OUI" Then
                Activer_Session_Remplacement = True
            Else
                Activer_Session_Remplacement = False
            End If
            Remplacant_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Remplacant_Num_Id_Nat").InnerText
            Remplacant_Cle_Num_Id_Nat = ConfigXMLelementliste.Item(0).Item("Remplacant_Cle_Num_Id_Nat").InnerText
            Remplacant_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Remplacant_Num_Id_Facturation").InnerText
            Remplacant_Cle_Num_Id_Facturation = ConfigXMLelementliste.Item(0).Item("Remplacant_Cle_Num_Id_Facturation").InnerText
            Remplacant_Num_log_situ_fact = ConfigXMLelementliste.Item(0).Item("Remplacant_Num_log_situ_fact").InnerText

            'LOI
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("LOI")
            LOI_Pop3_Serveur = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_Serveur").InnerText
            LOI_Pop3_Port = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_Port").InnerText
            LOI_Pop3_User = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_User").InnerText
            LOI_Pop3_Password = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_Password").InnerText
            LOI_Pop3_BAL = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_BAL").InnerText
            LOI_Pop3_RepBAL = ConfigXMLelementliste.Item(0).Item("LOI_Pop3_RepBAL").InnerText
            LOI_Distr_OCT = ConfigXMLelementliste.Item(0).Item("LOI_Distr_OCT").InnerText
            LOI_Distr_horsOCT = ConfigXMLelementliste.Item(0).Item("LOI_Distr_horsOCT").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Activer").InnerText) = "OUI" Then
                LOI_Activer = True
            Else
                LOI_Activer = False
            End If
            LOI_Ref = ConfigXMLelementliste.Item(0).Item("LOI_Ref").InnerText
            LOI_NB_JOUR_Max = Val(ConfigXMLelementliste.Item(0).Item("LOI_NB_JOUR_Max").InnerText)
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Demande_Auto").InnerText) = "OUI" Then
                LOI_Demande_Auto = True
            Else
                LOI_Demande_Auto = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Controle_MAJ_mensuel").InnerText) = "OUI" Then
                LOI_Controle_MAJ_mensuel = True
            Else
                LOI_Controle_MAJ_mensuel = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Verif_InReply_To").InnerText) = "OUI" Then
                LOI_Verif_InReply_To = True
            Else
                LOI_Verif_InReply_To = False
            End If
            If UCase(ConfigXMLelementliste.Item(0).Item("LOI_Controle_Correspondance").InnerText) = "OUI" Then
                LOI_Controle_Correspondance = True
            Else
                LOI_Controle_Correspondance = False
            End If
            LOI_code_resultat_incr_prec = ConfigXMLelementliste.Item(0).Item("LOI_code_resultat_incr_prec").InnerText
            LOI_smtp_serveur = ConfigXMLelementliste.Item(0).Item("LOI_smtp_serveur").InnerText
            LOI_smtp_serveur_port = Val(ConfigXMLelementliste.Item(0).Item("LOI_smtp_serveur_port").InnerText)
            LOI_cert_nums = ConfigXMLelementliste.Item(0).Item("LOI_cert_nums").InnerText
            LOI_clé_GIP_CPS = ConfigXMLelementliste.Item(0).Item("LOI_cle_GIP_CPS").InnerText

            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("SESAM-VITALE")
            SesamIni = ConfigXMLelementliste.Item(0).Item("SesamIni").InnerText
            If SesamIni = "" Then
                SesamIni = Application.StartupPath & "\sesam.ini"
            End If

            'HONO DISP
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Hono_Disp")
            If UCase(ConfigXMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" And Now.Year >= 2015 Then
                Hono_Disp_Activer = True
            Else
                Hono_Disp_Activer = False
            End If
            '____
            Hono_Disp_HC_tarif = 0
            Dim HC_list = ConfigXMLelementliste.Item(0).SelectNodes("HC")
            If HC_list.Count = 0 Then
                Dim _Node As XmlElement = ConfigXml.CreateElement("HC", ConfigXml.DocumentElement.NamespaceURI)
                'Lien_Type_Node.InnerText = "XML"
                _Node.SetAttribute("Debut", "01/01/2015")
                _Node.SetAttribute("Fin", "31/12/2019")
                _Node.SetAttribute("Cents", "51")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                _Node = ConfigXml.CreateElement("HC", ConfigXml.DocumentElement.NamespaceURI)
                _Node.SetAttribute("Debut", "01/01/2020")
                _Node.SetAttribute("Fin", "31/12/2100")
                _Node.SetAttribute("Cents", "102")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                need_to_save = True
            End If
            For r = 0 To HC_list.Count - 1
                If Now >= CDate(HC_list(r).Attributes("Debut").Value) And Now <= CDate(HC_list(r).Attributes("Fin").Value) Then
                    Hono_Disp_HC_tarif = CInt(HC_list(r).Attributes("Cents").Value)
                End If
            Next
            HC_list = Nothing
            '____
            Hono_Disp_HDA_tarif = 0
            Dim HDA_list = ConfigXMLelementliste.Item(0).SelectNodes("HDA")
            If HDA_list.Count = 0 Then
                Dim _Node As XmlElement = ConfigXml.CreateElement("HDA", ConfigXml.DocumentElement.NamespaceURI)
                'Lien_Type_Node.InnerText = "XML"
                _Node.SetAttribute("Debut", "01/01/2019")
                _Node.SetAttribute("Fin", "31/12/2019")
                _Node.SetAttribute("Cents", "51")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                _Node = ConfigXml.CreateElement("HDA", ConfigXml.DocumentElement.NamespaceURI)
                _Node.SetAttribute("Debut", "01/01/2020")
                _Node.SetAttribute("Fin", "31/12/2100")
                _Node.SetAttribute("Cents", "158")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                need_to_save = True
            End If
            For r = 0 To HDA_list.Count - 1
                If Now >= CDate(HDA_list(r).Attributes("Debut").Value) And Now <= CDate(HDA_list(r).Attributes("Fin").Value) Then
                    Hono_Disp_HDA_tarif = CInt(HDA_list(r).Attributes("Cents").Value)
                    Exit For
                End If
            Next
            HDA_list = Nothing
            '____
            Hono_Disp_HDE_tarif = 0
            Dim HDE_list = ConfigXMLelementliste.Item(0).SelectNodes("HDE")
            If HDE_list.Count = 0 Then
                Dim _Node As XmlElement = ConfigXml.CreateElement("HDE", ConfigXml.DocumentElement.NamespaceURI)
                'Lien_Type_Node.InnerText = "XML"
                _Node.SetAttribute("Debut", "01/01/2019")
                _Node.SetAttribute("Fin", "31/12/2019")
                _Node.SetAttribute("Cents", "204")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                _Node = ConfigXml.CreateElement("HDE", ConfigXml.DocumentElement.NamespaceURI)
                _Node.SetAttribute("Debut", "01/01/2020")
                _Node.SetAttribute("Fin", "31/12/2100")
                _Node.SetAttribute("Cents", "357")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                need_to_save = True
            End If
            For r = 0 To HDE_list.Count - 1
                If Now >= CDate(HDE_list(r).Attributes("Debut").Value) And Now <= CDate(HDE_list(r).Attributes("Fin").Value) Then
                    Hono_Disp_HDE_tarif = CInt(HDE_list(r).Attributes("Cents").Value)
                    Exit For
                End If
            Next
            HDE_list = Nothing
            '____
            Hono_Disp_HDR_tarif = 0
            Dim HDR_list = ConfigXMLelementliste.Item(0).SelectNodes("HDR")
            If HDR_list.Count = 0 Then
                Dim _Node As XmlElement = ConfigXml.CreateElement("HDR", ConfigXml.DocumentElement.NamespaceURI)
                'Lien_Type_Node.InnerText = "XML"
                _Node.SetAttribute("Debut", "01/01/2019")
                _Node.SetAttribute("Fin", "31/12/2100")
                _Node.SetAttribute("Cents", "51")
                ConfigXMLelementliste.Item(0).AppendChild(_Node)
                _Node = Nothing
                need_to_save = True
            End If
            For r = 0 To HDR_list.Count - 1
                If Now >= CDate(HDR_list(r).Attributes("Debut").Value) And Now <= CDate(HDR_list(r).Attributes("Fin").Value) Then
                    Hono_Disp_HDR_tarif = CInt(HDR_list(r).Attributes("Cents").Value)
                    Exit For
                End If
            Next
            HDR_list = Nothing


            'DP
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("DP")
            If UCase(ConfigXMLelementliste.Item(0).Item("DP_Activer").InnerText) = "OUI" Then
                DP_Activer = True
            Else
                DP_Activer = False
            End If

            DP_URI = ConfigXMLelementliste.Item(0).Item("DP_URI").InnerText
            DP_EtaTyp = ConfigXMLelementliste.Item(0).Item("DP_EtaTyp").InnerText
            DP_EtaIdent = ConfigXMLelementliste.Item(0).Item("DP_EtaIdent").InnerText
            DP_LogValid = ConfigXMLelementliste.Item(0).Item("DP_LogValid").InnerText
            If DP_LogValid.Length <> 5 Then
                MyMsg_Box.Presentation("Info DP", "Code de validation du logiciel invalide." + Chr(10) + "Contactez l'administrateur système.", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                DP_LogValid = ""
            End If
            DP_LogVers = ConfigXMLelementliste.Item(0).Item("DP_LogVers").InnerText
            If DP_LogVers.Length > 30 Then
                MyMsg_Box.Presentation("Info DP", " Numéro de version du logiciel invalide." + Chr(10) + "Contactez l'administrateur système.", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                DP_LogVers = ""
            End If
            DP_LogVDP = ConfigXMLelementliste.Item(0).Item("DP_LogVDP").InnerText
            If DP_LogVDP.Length > 30 Then
                MyMsg_Box.Presentation("Info DP", "Numéro de version du module DP invalide." + Chr(10) + "Contactez l'administrateur système.", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                DP_LogVDP = ""
            End If
            DP_ReqProd = ConfigXMLelementliste.Item(0).Item("DP_ReqProd").InnerText

            If UCase(ConfigXMLelementliste.Item(0).Item("DP_is_local_client").InnerText) = "OUI" Then
                DP_is_local_client = True
            Else
                DP_is_local_client = False
            End If

            DP_Certif = ConfigXMLelementliste.Item(0).Item("DP_Certif").InnerText

            'DP_Inciter
            If UCase(ConfigXMLelementliste.Item(0).Item("DP_Inciter").InnerText) = "OUI" Then
                DP_Inciter = True
            Else
                DP_Inciter = False
            End If
            DP_Directory = ConfigXMLelementliste.Item(0).Item("Directory").InnerText

            'IAM
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("IAM")
            Piam1 = ConfigXMLelementliste.Item(0).Item("Piam1").InnerText
            Piam3 = ConfigXMLelementliste.Item(0).Item("Piam3").InnerText

            'SCOR
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("SCOR")
            Scor_from = ConfigXMLelementliste.Item(0).Item("from").InnerText
            Scor_TaillMaxLot = Val(ConfigXMLelementliste.Item(0).Item("TaillMaxLot").InnerText)
            Scor_CodeRégion = ConfigXMLelementliste.Item(0).Item("CodeRégion").InnerText
            Scor_Adr_OCT = ConfigXMLelementliste.Item(0).Item("Adr_OCT").InnerText
            Scor_Dest_ARL = ConfigXMLelementliste.Item(0).Item("Dest_ARL").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("cdrom").InnerText) = "OUI" Then
                Scor_cdrom = True
            Else
                Scor_cdrom = False
            End If
            Scor_cdrom_inter = ConfigXMLelementliste.Item(0).Item("cdrom_inter").InnerText
            Scor_cdrom_lastdate = CDate(ConfigXMLelementliste.Item(0).Item("cdrom_lastdate").InnerText)
            Scor_Directory = ConfigXMLelementliste.Item(0).Item("Directory").InnerText
            If UCase(ConfigXMLelementliste.Item(0).Item("Scor_Transmission_via_OCT").InnerText) = "OUI" Then
                Scor_Transmission_via_OCT = True
            Else
                Scor_Transmission_via_OCT = False
            End If
            Scor_hide_VenteForm_WebBrowser_SCOR = False
            Try
                If UCase(ConfigXMLelementliste.Item(0).Item("Scor_hide_VenteForm_WebBrowser_SCOR").InnerText) = "OUI" Then
                    Scor_hide_VenteForm_WebBrowser_SCOR = True
                End If
            Catch ex As Exception

            End Try

            'Pharma_ml
            ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Pharma_ml")
            Pharma_ml_Répartiteur_principal = ConfigXMLelementliste.Item(0).Item("Répartiteur_principal").InnerText
            Pharma_ml_Répartiteur_secondaire = ConfigXMLelementliste.Item(0).Item("Répartiteur_secondaire").InnerText


            'facilEpharm
            If ConfigXml.GetElementsByTagName("facilEpharm").Count > 0 Then
                ConfigXMLelementliste = ConfigXml.GetElementsByTagName("facilEpharm")
                If UCase(ConfigXMLelementliste.Item(0).Item("Activer").InnerText) = "OUI" Then
                    facilEpharm_Activé = True
                    facilEpharm_intervalle_Control = CInt(ConfigXMLelementliste.Item(0).Item("intervalle_Control").InnerText)
                    facilEpharm_Rep_Doc = ConfigXMLelementliste.Item(0).Item("Rep_Doc").InnerText
                Else
                    facilEpharm_Activé = False
                End If
            Else
                facilEpharm_Activé = False
            End If

            'ConfigXMLelementliste = ConfigXml.GetElementsByTagName("Technique")
            'If UCase(ConfigXMLelementliste.Item(0).Item("Bandeau_info_bas_show").InnerText) = "OUI" Then
            '    Technique_Bandeau_info_bas_show = True
            'Else
            '    Technique_Bandeau_info_bas_show = False
            'End If

            If need_to_save = True Then
                ConfigXml.Save("config.xml")
            End If

        End Sub

    End Structure
    Public Config As Configuration




#End Region
#Region "FONCTIONS"



#Region "Formats des dates"

    Public Function DateString_To_DateVitale(ByVal MyDateString) As String 'date en entrée au format jj/MM/aaaa, date en sortie au format aaaaMMjj0000
        If MyDateString = "" Or MyDateString = "  /  /" Then
            Return ""
        End If
        Return Mid(MyDateString, 7, 4) & Mid(MyDateString, 4, 2) & Mid(MyDateString, 1, 2) & "0000"
    End Function

    Public Function DateVitale_To_DateString(ByVal DateVitale) As String 'date en entrée au format aaaaMMjj0000, date en sortie au format jj/MM/aaaa
        Return Mid(DateVitale, 7, 2) & "/" & Mid(DateVitale, 5, 2) & "/" & Mid(DateVitale, 1, 4)
    End Function

#End Region

    'Clear les GroupBox
    Public Sub ClearGroupBox(ByVal myGroupBox As System.Windows.Forms.GroupBox, ByVal Vider_Combobox As Boolean)
        For Each truc In myGroupBox.Controls
            Select Case truc.GetType.ToString
                Case "System.Windows.Forms.TextBox"
                    truc.Clear()
                Case "OfficineLib.MyCombobox"
                    If truc.name <> "Chronique_Periode_MyCombobox" Then
                        If Vider_Combobox = True Then
                            truc.Items.Clear()
                        End If
                    End If
                   
            End Select

        Next
    End Sub
    Public Sub ClearTabPage(ByVal myTabPage As System.Windows.Forms.TabPage, ByVal Vider_Combobox As Boolean)
        For Each truc In myTabPage.Controls
            Select Case truc.GetType.ToString
                Case "System.Windows.Forms.TextBox"
                    truc.Clear()
                Case "OfficineLib.MyCombobox"
                    If Vider_Combobox = True Then
                        truc.Items.Clear()
                    End If
            End Select

        Next
    End Sub

    'Arrete GALSVW32.EXE
    Public Sub killgalss()
        Dim myProcesses() As Process
        Dim myProcess As Process
        ' Returns array containing all instances of "GALSVW32".
        myProcesses = Process.GetProcessesByName("GALSVW32")
        For Each myProcess In myProcesses
            myProcess.Kill()
        Next
    End Sub

    ' Code Erreur
    Public Sub AfficheErreur(ByVal CodeErreur As UInt16, Optional ByVal message As String = "")
        If message <> "" And CodeErreur <> 0 Then
            MyMsg_Box.Presentation("Officine !", message, False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
        End If
        Select Case CodeErreur
            Case 0
            Case 4
                MyMsg_Box.Presentation("Officine !", "Lerreur lecteur SV" + Chr(10) + CodeErreur.ToString & Chr(10) & "GALLS: Impossible de fermer la session: Exclusivité en cours. Impossible de poser l'exclusivité. Au moins un lad est en exclusivité. Impossible d'effectuer l'échange: LAD pris en exclusivité par une autre application", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 1024
                MyMsg_Box.Presentation("Officine !", "Absence de réponse du lecteur lors d'un échange" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61441
                MyMsg_Box.Presentation("Officine !", "La Carte du Professionnel de Santé est absente du lecteur" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 36912
                MyMsg_Box.Presentation("Officine !", "Verifiez numéro organisme complémentaire" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 36890
                MyMsg_Box.Presentation("Officine !", "Verifiez qualité assuré (assuré, ayant droit...)" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61442
                MyMsg_Box.Presentation("Officine !", "Carte du Professionnel de Santé bloquée" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61443
                MyMsg_Box.Presentation("Officine !", "Le code porteur présenté est erroné" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61444
                MyMsg_Box.Presentation("Officine !", "Carte du Professionnel de Santé est non valide ou inexploitable par le Logiciel Lecteur." + Chr(10) + "• La CPS n’a pas de DAM (Domaine d’Assurance Maladie)." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61445
                MyMsg_Box.Presentation("Officine !", "La Carte du Professionnel de Santé est retirée du lecteur" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61446
                MyMsg_Box.Presentation("Officine !", "Carte du Professionnel de Santé n’est pas habilitée à formater une Facture ou un lot de Factures." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61447
                MyMsg_Box.Presentation("Officine !", "Carte du Professionnel de Santé est inaccessible." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61457
                MyMsg_Box.Presentation("Officine !", "La carte Vitale est absente." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61460
                MyMsg_Box.Presentation("Officine !", "Défaut de communication avec la carte Vitale." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61461
                MyMsg_Box.Presentation("Officine !", "La carte Vitale est retirée du lecteur." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61462
                MyMsg_Box.Presentation("Officine !", "Code du régime d'assurance maladie inscrit sur la carte Vitale non géré par le lecteur." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61463
                MyMsg_Box.Presentation("Officine !", "Anomalie de la date d'exonération du ticket modérateur de l'assuré." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61464
                MyMsg_Box.Presentation("Officine !", "Anomalie de la date d'exonération du ticket modérateur du bénéficiaire." + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61475
                MyMsg_Box.Presentation("Officine !", "Le numéro national d'immatriculation de l'assuré fourni dans la zone de mémoire présentée en entrée diffère de celui qui figure sur sa carte Vitale." + Chr(10) + "VERIFIER CARTE VITALE" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61476
                MyMsg_Box.Presentation("Officine !", "La Carte du Professionnel a été changée, veuillez relire les droits CPS" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 61680
                MyMsg_Box.Presentation("Officine !", "ERREUR Carte Vitale: Présence simultanée de périodes de droits Mutuelles et AMC" + Chr(10) + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 63136
                MyMsg_Box.Presentation("Officine !", "liste d’opposition indisponible", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 63137
                MyMsg_Box.Presentation("Officine !", "carte Vitale en opposition", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case 63217
                MyMsg_Box.Presentation("Officine !", "Le chemin du répertoire de travail est absent du fichier SESAM.INI", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            Case Else
                MyMsg_Box.Presentation("Officine !", "Code Erreur:" + CodeErreur.ToString, False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
        End Select
    End Sub

    'Arrondis
    Public Function Arrondis(ByVal Valeur As Decimal)
        Dim partiedecimale As Decimal
        partiedecimale = Valeur - Int(Valeur)
        If partiedecimale >= 0.5 Then
            Return Int(Valeur) + 1
        Else
            Return Int(Valeur)
        End If
    End Function

    'Code régime
    Public Function TraductionCodeRégime(ByVal CodeRégime As String)
        Select Case CodeRégime
            Case "01"
                Return "Régime général"
            Case "02"
                Return "Régime agricole"
            Case "03"
                Return "Régime des Salariés Indépendants - RSI"
            Case "04"
                Return "Caisses de Prévoyance et de Retraite de la SNCF - CPR SNCF"
            Case "05"
                Return "Régime Spécial de la Régie Autonome des Transports Parisiens- RATP"
            Case "06"
                Return "Etablissement National des Invalides de la Marine - ENIM"
            Case "07"
                Return "Régime minier de Sécurité Sociale"
            Case "08"
                Return "Caisse Nationale Militaire de Sécurité Sociale - CNMSS"
            Case "09"
                Return "Caisse de Prévoyance Maladie de la Banque de France - CPM Banque de France"
            Case "10"
                Return "Caisse de Retraite et de Prévoyance des Clercs et Employés de Notaire - CRPCEN"
            Case "12"
                Return "Chambre de Commerce et d'Industrie de Paris - CCIP"
            Case "14"
                Return "Fonds de sécurité sociale de l'Assemblée Nationale"
            Case "15"
                Return "Caisses autonomes de Sécurité Sociale du Sénat"
            Case "16"
                Return "Caisse de Prévoyance du Personnel titulaire du Port Autonome de Bordeaux"
            Case "17"
                Return "Caisse des français à l'étranger"
            Case "80"
                Return "Ministère des anciens combattants"
            Case "90"
                Return "Caisse d'Assurance Vieillesse, Invalidité et Maladie des Cultes CAVIMAC"
            Case "91"
                Return "Mutuelle Générale de l'Education Nationale - MGEN"
            Case "92"
                Return "Mutuelle Générale des PTT - MGPTT"
            Case "93"
                Return "Mutuelle Générale de la police - MGP"
            Case "94"
                Return "Mutualité de la Fonction Publique - MFP"
            Case "95"
                Return "Mutuelle Nationale des Hospitaliers - MNH"
            Case "96"
                Return "Mutuelle Nationale Aviation Marine - MNAM"
            Case "99"
                Return "Autres mutuelles"
            Case Else
                Return "Code régime Inconnu"
        End Select
    End Function

    'Code gestion
    Public Function TraductionG101C13(ByVal G101C13 As String)
        Select Case G101C13
            Case "A1"
                Return "Salariés assurés obligatoires"
            Case "A2"
                Return "Exploitants assurés obligatoires"
            Case "A3"
                Return "Salariés assurés volontaires"
            Case "A4"
                Return "Exploitants assurés volontaires"
            Case "A5"
                Return "Assurés personnels"
            Case "N1"
                Return "Régime obligatoire"
            Case "N2"
                Return "Gratuit"
            Case "N3"
                Return "Biologistes"
            Case "N5"
                Return "Assurés volontaires"
            Case "N6"
                Return "CEE"
            Case "04"
                Return "SNCF"
            Case "T1"
                Return "Agents actifs"
            Case "M1"
                Return "Agents actifs"
            Case "M2"
                Return "Agents invalides et pensionnés"
            Case "10"
                Return "Régime général"
            Case "11"
                Return "Régime général assurés retraités"
            Case "12"
                Return "Régime général assurés non cotisants"
            Case "13"
                Return "Invalides de guerre"
            Case "18"
                Return "Adultes handicapés"
            Case "20"
                Return "Régime général partiel"
            Case "23"
                Return "Fonctionnaires ouvriers de l'état"
            Case "24"
                Return "EDF-GDF"
            Case "25"
                Return "Etudiants"
            Case "29"
                Return "Collectivités locales"
            Case "34"
                Return "Artistes auteurs"
            Case "40"
                Return "Assurés volontaires"
            Case "70"
                Return "Conventions internationales (CEE et conventions bilatérales)"
            Case "85"
                Return "Assurés personnels"
            Case "86"
                Return "AVIP (Assuré Volontaire Inv. Parental)"
            Case "87"
                Return "RMI (Revenu Minimum d'Insertion)"
            Case "89"
                Return "Assurés bénéficiaires de la Couverture Maladie Universelle"
            Case "90"
                Return "Praticiens sauf biologistes"
            Case Else
                Return "Code Gestion Inconnu"
        End Select
    End Function

#Region "BASE 64"
    Public Function convert_base64file_to_another_file(ByVal Base64File As String, ByVal DestinationFile As String, ByVal DeleteBase64File As Boolean) As Boolean
        Try
            Dim B64string As String = My.Computer.FileSystem.ReadAllText(Base64File)
            While InStr(B64string, "-") <> 0
                B64string = Replace(B64string, "-", "")
            End While
            While B64string.Length Mod 4 <> 0
                B64string = B64string & "="
            End While
            Dim FileBytes() As Byte = Convert.FromBase64String(B64string)
            My.Computer.FileSystem.WriteAllBytes(DestinationFile, FileBytes, True)
            If DeleteBase64File = True Then
                My.Computer.FileSystem.DeleteFile(Base64File)
            End If
            Return True
        Catch ex As Exception
            MyMsg_Box.Presentation("Officine !", ex.ToString, False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End Try
    End Function
#End Region

    'Qualité
    Public Function TraductionG104C14(ByVal G104C14 As String)
        Select Case G104C14
            Case "00" Or "0"
                Return "Assuré"
            Case "01" Or "1"
                Return "Ascendant, descendant, collatéraux ascendants"
            Case "02" Or "2"
                Return "Conjoint"
            Case "03" Or "3"
                Return "Conjoint divorcé"
            Case "04" Or "4"
                Return "Concubin"
            Case "05" Or "5"
                Return "Conjoint séparé"
            Case "06" Or "6"
                Return "Enfant"
            Case "08" Or "8"
                Return "Conjoint veuf"
            Case "09" Or "9"
                Return "Autre ayant-droit"
            Case Else
                Return "Code Qualité Inconnu"
        End Select
    End Function

    'Code service AMO bénéficiaire
    Public Function TraductionG104C15(ByVal G104C15 As String)
        Select Case G104C15
            Case "00" Or "0"
                Return "Le bénéficiaire n'a pas de service AMO spécifique"
            Case "01" Or "1"
                Return "Le bénéficiaire a une CMU complémentaire gérée par une AMO"
            Case "02" Or "2"
                Return "Le bénéficiaire a une CMU complémentaire gérée par une AMC en convention ou en délégation avec une AMO"
            Case "03" Or "3"
                Return "Le bénéficiaire a une CMU complémentaire gérée par une AMC"
            Case "10"
                Return "Le bénéficiaire est sortant de CMU complémentaire"
            Case "11"
                Return "Bénéficiaire du dispositif d’aide à l’acquisition d’une complémentaire"
            Case Else
                Return "Code service AMO bénéficiaire Inconnu"
        End Select
    End Function


    Public Function Traduction_CodeSpécialité_Prescripteur(ByVal CodeSpécialité As String) As String
        Select Case CodeSpécialité
            Case "01"
                Return "Médecine générale"
            Case "02"
                Return "Anesthésie Réanimation"
            Case "03"
                Return "Cardiologie"
            Case "04"
                Return "Chirurgie Générale"
            Case "05"
                Return "Dermato-Vénérologie"
            Case "07"
                Return "Gynécologie-Obstétrique"
            Case "08"
                Return "Gastro-Entéro-Hépatologie"
            Case "09"
                Return "Médecine interne"
            Case "10"
                Return "Neuro-chirurgie"
            Case "11"
                Return "Oto-rhino-laryngologie"
            Case "12"
                Return "Pédiatrie"
            Case "13"
                Return "Pneumologie"
            Case "14"
                Return "Rhumatologie"
            Case "15"
                Return "Ophtalmologie"
            Case "16"
                Return "Chirurgie Urologique"
            Case "17"
                Return "Neuro.Psychiatrie"
            Case "20"
                Return "Réanimation médicale"
            Case "21"
                Return "Sage-femme"
            Case "22"
                Return "Spécialiste en Médecine générale avec diplôme"
            Case "23"
                Return "Spécialiste en Médecine générale reconnu par l’Ordre"
            Case "31"
                Return "Rééducation -Réadaptation fonctionnelle"
            Case "32"
                Return "Neurologie"
            Case "33"
                Return "Psychiatrie"
            Case "34"
                Return "Gériatrie"
            Case "35"
                Return "Néphrologie"
            Case "41"
                Return "Chirurgie orthopédique"
            Case "42"
                Return "Endocrinologie Métabolique"
            Case "43"
                Return "Chirurgie infantile"
            Case "46"
                Return "Chirurgie Plastique et Esthétique"
            Case "47"
                Return "Chirurgie Thoracique et Cardiologie Vasculaire"
            Case "48"
                Return "Chirurgie Vasculaire"
            Case "49"
                Return "Chirurgie Viscérale et Digestive"
            Case "70"
                Return "Gynécologie Médicale"
            Case "71"
                Return "Hématologie"
            Case "72"
                Return "Médecine nucléaire"
            Case "73"
                Return "Oncologie Médicale"
            Case "74"
                Return "Oncologie Radiothérapique"
            Case "75"
                Return "Psychiatrie Infantile"
            Case "77"
                Return "Obstétrique"
            Case "79"
                Return "Gynécologie obstétrique et gynécologie médicale"
            Case "80"
                Return "Santé publique et médecine sociale"
            Case Else
                Return "code spécialité inconnu (" + CodeSpécialité + ")"
        End Select
    End Function
#End Region
#Region "Graphics"
    Public Function GetRoundedRectPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
        Dim diameter As Integer = 2 * radius
        Dim arcRect As New Rectangle(rect.Location, New Size(diameter, diameter))
        Dim path As New GraphicsPath
        path.AddArc(arcRect, 180, 90)
        arcRect.X = rect.Right - diameter
        path.AddArc(arcRect, 270, 90)
        arcRect.Y = rect.Bottom - diameter
        path.AddArc(arcRect, 0, 90)
        arcRect.X = rect.Left
        path.AddArc(arcRect, 90, 90)
        path.CloseFigure()
        Return path
    End Function

    Public Bandeau_info_bas_text As String
    Private Bandeau_bas_ThreadProc As Thread
    Public Bandeau_info_bas_close As Boolean
    Public Sub Bandeau_info_bas_show(ByRef info As String) 'As Thread
        Try

 
        If Bandeau_info_bas2.Visible = True Then
            Bandeau_info_bas2.Close()
            Application.DoEvents()
        End If
        Bandeau_info_bas2.Label1.Text = info
        Bandeau_info_bas2.Visible = True
        Application.DoEvents()
        Catch ex As Exception

        End Try
    End Sub
    Public Sub Bandeau_info_bas_hide() 'ByVal Bandeau_bas_ThreadProc As System.Threading.Thread)
        Try
            If Bandeau_info_bas2.Visible = True Then
                Bandeau_info_bas2.Close()
                Application.DoEvents()
            End If
        Catch ex As Exception

        End Try

    End Sub

    Public Sub Bandeau_info_bas_change_text(ByVal texte As String)
        Try

   
        If Bandeau_info_bas2.Visible = True Then
            Bandeau_info_bas2.Label1.Text = texte
            Application.DoEvents()
        End If
        Catch ex As Exception

        End Try
    End Sub
    Public Sub ResizeControl(ByRef ctl As Control)

        '---------------------------- GET SCALES -------------------------
        Dim DesignScreenWidth As Integer = 1600
        Dim DesignScreenHeight As Integer = 901
        Dim CurrentScreenWidth As Integer = 1280 'Screen.PrimaryScreen.Bounds.Width
        Dim CurrentScreenHeight As Integer = 1024 'Screen.PrimaryScreen.Bounds.Height

        'Ratios
        Dim ratioX As Double = CurrentScreenWidth / DesignScreenWidth        ' e.g.  800/1920
        Dim ratioY As Double = CurrentScreenHeight / DesignScreenHeight

        With ctl
            Dim height As Integer = Math.Min(.Height, CurrentScreenHeight)
            Dim width As Integer = Math.Min(.Width, CurrentScreenWidth)
            'Position
            If (.GetType.GetProperty("Top").CanRead) Then .Top = CInt(.Top * ratioY)
            If (.GetType.GetProperty("Left").CanRead) Then .Left = CInt(.Left * ratioX)
            'Size
            If (.GetType.GetProperty("Width").CanRead) Then .Width = CInt(width * ratioX)
            If (.GetType.GetProperty("Height").CanRead) Then .Height = CInt(height * ratioY)

        End With

    End Sub
#End Region
#Region "DP"
    Public DP_connection_établie As Boolean
    Public X_DP_Sequence_Number As Integer
    'Public PhaIdent_DP As String
    Public DP_Connect_thread As Thread
    Public DP_local_server_thread As Thread
    Public DP_AP_MSG_thread As Thread
    Public DP_objRequest As System.Net.HttpWebRequest
    Public DP_objRequest_has_been_used As Boolean
    Public DP_Missing_Sequence_Numbers() As String
    Public DP_Heartbeat_Debut_envoyé As Boolean
    Public DP_Connection_reseted As Boolean
    Public DP_Carte_Vitale_lue As Boolean
    Public DP_Création_déja_proposée As Boolean
    Public DP_Certif_serial As String


#End Region

#Region "CSV"
    Public Function CSV_Champ(ByVal ligne As String, ByVal Num_Champ As Integer) As String 'récupère le "num_champ"ième chanp dans une ligne csv avec séparateur;
        Dim retour As String = ligne
        For i = 0 To Num_Champ - 2
            retour = Mid(retour, InStr(retour, ";") + 1)
        Next
        If InStr(retour, ";") <> 0 Then
            retour = Mid(retour, 1, InStr(retour, ";") - 1)
        End If
        Return retour
    End Function
#End Region

#Region "Ventes enchainées"

    Public Structure Vente_enchainée_encaissement_en_attente
        Dim num_encaissement As Integer
        Dim montant_à_encaisser As Decimal
    End Structure
    Public Ventes_enchainées_encaissement_en_attente As List(Of Vente_enchainée_encaissement_en_attente)
    Public Ventes_enchainées_Crédits_en_attente As List(Of Decimal)
    ' Public Ventes_enchainées_Last_Bénéficiaire As String 'pour mise en crédit d'une liste d'encaissements d'une vente enchainée, lorsque il n'y a pas de bénéficiaire sur la dernière vente
#End Region

#Region "Scanner"
    Public Function WIA_scan(ByVal scannerId As String, ByVal Show_dialog As Boolean) As Bitmap
        'Const DeviceID = 2
        'Const Manufacturer = 3
        'Const Description = 4
        'Const Type = 5
        'Const Port = 6
        'Const Name = 7
        'Const Server = 8
        'Const RemoteDevID = 9
        'Const UIClassID = 10
        'Const FirmwareVersion = 1026
        'Const ConnectStatus = 1027
        'Const DeviceTime = 1028
        'Const PicturesTaken = 2050
        'Const PicturesRemaining = 2051
        'Const ExposureMode = 2052
        'Const ExposureCompensation = 2053
        'Const ExposureTime = 2054
        'Const FNumber = 2055
        'Const FlashMode = 2056
        'Const FocusMode = 2057
        'Const FocusManualDist = 2058
        'Const ZoomPosition = 2059
        'Const PanPosition = 2060
        'Const TiltPostion = 2061
        'Const TimerMode = 2062
        'Const TimerValue = 2063
        'Const PowerMode = 2064
        'Const BatteryStatus = 2065
        'Const Dimension = 2070
        'Const HorizontalBedSize = 3074
        'Const VerticalBedSize = 3075
        'Const HorizontalSheetFeedSize = 3076
        'Const VerticalSheetFeedSize = 3077
        'Const SheetFeederRegistration = 3078
        'Const HorizontalBedRegistration = 3079
        'Const VerticalBedRegistraion = 3080
        'Const PlatenColor = 3081
        'Const PadColor = 3082
        'Const FilterSelect = 3083
        'Const DitherSelect = 3084
        'Const DitherPatternData = 3085
        'Const DocumentHandlingCapabilities = 3086
        'Const DocumentHandlingStatus = 3087
        'Const DocumentHandlingSelect = 3088
        'Const DocumentHandlingCapacity = 3089
        'Const HorizontalOpticalResolution = 3090
        'Const VerticalOpticalResolution = 3091
        'Const EndorserCharacters = 3092
        'Const EndorserString = 3093
        'Const ScanAheadPages = 3094
        'Const MaxScanTime = 3095
        'Const Pages = 3096
        'Const PageSize = 3097
        'Const PageWidth = 3098
        'Const PageHeight = 3099
        'Const Preview = 3100
        'Const TransparencyAdapter = 3101
        'Const TransparecnyAdapterSelect = 3102
        'Const ItemName = 4098
        'Const FullItemName = 4099
        'Const ItemTimeStamp = 4100
        'Const ItemFlags = 4101
        'Const AccessRights = 4102
        'Const DataType = 4103
        'Const BitsPerPixel = 4104
        'Const PreferredFormat = 4105
        'Const Format = 4106
        'Const Compression = 4107
        'Const MediaType = 4108
        'Const ChannelsPerPixel = 4109
        'Const BitsPerChannel = 4110
        'Const Planar = 4111
        'Const PixelsPerLine = 4112
        'Const BytesPerLine = 4113
        'Const NumberOfLines = 4114
        'Const GammaCurves = 4115
        'Const ItemSize = 4116
        'Const ColorProfiles = 4117
        'Const BufferSize = 4118
        'Const RegionType = 4119
        'Const ColorProfileName = 4120
        'Const ApplicationAppliesColorMapping = 4121
        'Const StreamCompatibilityID = 4122
        'Const ThumbData = 5122
        'Const ThumbWidth = 5123
        'Const ThumbHeight = 5124
        'Const AudioAvailable = 5125
        'Const AudioFormat = 5126
        'Const AudioData = 5127
        'Const PicturesPerRow = 5128
        'Const SequenceNumber = 5129
        'Const TimeDelay = 5130
        'Const CurrentIntent = 6146
        'Const HorizontalResolution = 6147
        'Const VerticalResolution = 6148
        'Const HorizontalStartPostion = 6149
        'Const VerticalStartPosition = 6150
        'Const HorizontalExtent = 6151
        'Const VerticalExtent = 6152
        'Const PhotometricInterpretation = 6153
        'Const Brightness = 6154
        'Const Contrast = 6155
        'Const Orientation = 6156
        'Const Rotation = 6157
        'Const Mirror = 6158
        'Const Threshold = 6159
        'Const Invert = 6160
        'Const LampWarmUpTime = 6161
        Try
            If Show_dialog = False Then
                Dim manager As New WIA.DeviceManager
                Dim device As WIA.Device = Nothing
                For Each info As WIA.DeviceInfo In manager.DeviceInfos
                    If info.DeviceID = scannerId Then
                        device = info.Connect
                        Exit For
                    End If
                Next
                If device Is Nothing Then
                    MyMsg_Box.Presentation("Officine !", "Scanner non détecté", False, "", False, "", True, "OK")
                    MyMsg_Box.ShowDialog()
                    Return Nothing
                End If

                Dim item As WIA.Item = device.Items(1)
                With item
                    .Properties("6146").Value = 4 '4 is Black-white,gray is 2, color 1 (Color Intent)
                    .Properties("6147").Value = 150  'dots per inch/horizontal
                    .Properties("6148").Value = 150 'dots per inch/vertical
                    .Properties("6149").Value = 0 'x point where to start scan
                    .Properties("6150").Value = 0 'y-point where to start scan
                    '.Properties("6154").Value = brightness  'Brightness

                    'Following is A4 paper size. (Not 100% accurate because real A4 Ht errors)
                    '.Properties("6151").Value = 1700 'horizontal exent DPI x inches wide
                    '.Properties("6152").Value = 2196 'vertical extent DPI x inches tall
                    '.Properties("4104").Value = 8 'bits per pixel

                    '.Properties("3098").Value = 1700 'page width
                    '.Properties("3099").Value = 2196 'page height

                    '.Properties("3097").Value = 0


                End With
                Dim wiaCommonDialog = New WIA.CommonDialog
                Dim wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
                Dim image As WIA.ImageFile = wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, False)

                Dim fileName = Path.GetTempFileName

                File.Delete(fileName)
                image.SaveFile(fileName)
                Dim bmp As New Bitmap(fileName)
                Return bmp
            Else
                Dim CD As New WIA.CommonDialog
                Dim image As WIA.ImageFile = CD.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType)
                Dim fileName = Path.GetTempFileName
                File.Delete(fileName)
                image.SaveFile(fileName)
                Dim bmp As New Bitmap(fileName)
                Return bmp
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Function WIA_GetDevices() As List(Of String)
        Dim devices As New List(Of String)
        Dim manager As New WIA.DeviceManager
        If manager.DeviceInfos.Count > 0 Then
            For Each info As WIA.DeviceInfo In manager.DeviceInfos
                devices.Add(info.DeviceID)
            Next
            Return devices
        Else
            MyMsg_Box.Presentation("Officine !", "Aucun Scanner détecté", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return Nothing
        End If

    End Function
#End Region

    Public Sub trace_log(ByVal texte As String)
        Try


            My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\traces\" & Format(Now, "yyyyMMdd") & "trace.log", vbCrLf & "------------------------------------------------" & vbCrLf & Now.ToString & vbCrLf & vbCrLf & _
                                                (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name & vbCrLf & vbCrLf & _
                                                texte & vbCrLf & "------------------------------------------------" & vbCrLf, True)
        Catch ex As Exception

        End Try
    End Sub

    Public Function nombre_en_lettre(ByVal nombre As Integer) As String
        If nombre = 0 Then Return "zéro"
        If nombre > 99999 Then Return " "
        Dim nombres() As String
        ReDim nombres(100)
        nombres(0) = "zéro"
        nombres(1) = "un"
        nombres(2) = "deux"
        nombres(3) = "trois"
        nombres(4) = "quatre"
        nombres(5) = "cinq"
        nombres(6) = "six"
        nombres(7) = "sept"
        nombres(8) = "huit"
        nombres(9) = "neuf"
        nombres(10) = "dix"
        nombres(11) = "onze"
        nombres(12) = "douze"
        nombres(13) = "treize"
        nombres(14) = "quatorze"
        nombres(15) = "quinze"
        nombres(16) = "seize"
        nombres(17) = "dix-sept"
        nombres(18) = "dix-huit"
        nombres(19) = "dix-neuf"
        nombres(20) = "vingt"
        nombres(21) = "vingt-et-un"
        nombres(22) = "vingt-deux"
        nombres(23) = "vingt-trois"
        nombres(24) = "vingt-quatre"
        nombres(25) = "vingt-cinq"
        nombres(26) = "vingt-six"
        nombres(27) = "vingt-sept"
        nombres(28) = "vingt-huit"
        nombres(29) = "vingt-neuf"
        nombres(30) = "trente"
        nombres(31) = "trente-et-un"
        nombres(32) = "trente-deux"
        nombres(33) = "trente-trois"
        nombres(34) = "trente-quatre"
        nombres(35) = "trente-cinq"
        nombres(36) = "trente-six"
        nombres(37) = "trente-sept"
        nombres(38) = "trente-huit"
        nombres(39) = "trente-neuf"
        nombres(40) = "quarante"
        nombres(41) = "quarante-et-un"
        nombres(42) = " quarante-deux"
        nombres(43) = "quarante-trois"
        nombres(44) = "quarante-quatre"
        nombres(45) = "quarante-cinq"
        nombres(46) = "quarante-six"
        nombres(47) = "quarante-sept"
        nombres(48) = "quarante-huit"
        nombres(49) = "quarante-neuf"
        nombres(50) = "cinquante"
        nombres(51) = "cinquante-et-un"
        nombres(52) = "cinquante-deux"
        nombres(53) = "cinquante-trois"
        nombres(54) = "cinquante-quatre"
        nombres(55) = "cinquante-cinq"
        nombres(56) = "cinquante-six"
        nombres(57) = "cinquante-sept"
        nombres(58) = "cinquante-huit"
        nombres(59) = "cinquante-neuf"
        nombres(60) = "soixante"
        nombres(61) = "soixante-et-un"
        nombres(62) = "soixante-deux"
        nombres(63) = "soixante-trois"
        nombres(64) = "soixante-quatre"
        nombres(65) = "soixante-cinq"
        nombres(66) = "soixante-six"
        nombres(67) = "soixante-sept"
        nombres(68) = "soixante-huit"
        nombres(69) = "soixante-neuf"
        nombres(70) = "soixante-dix"
        nombres(71) = "soixante-et-onze"
        nombres(72) = "soixante-douze"
        nombres(73) = "soixante-treize"
        nombres(74) = "soixante-quatorze"
        nombres(75) = "soixante-quinze"
        nombres(76) = "soixante-seize"
        nombres(77) = "soixante-dix-sept"
        nombres(78) = "soixante-dix-huit"
        nombres(79) = "soixante-dix-neuf"
        nombres(80) = "quatre-vingts"
        nombres(81) = "quatre-vingt-un"
        nombres(82) = "quatre-vingt-deux"
        nombres(83) = "quatre-vingt-trois"
        nombres(84) = "quatre-vingt-quatre"
        nombres(85) = "quatre-vingt-cinq"
        nombres(86) = "quatre-vingt-six"
        nombres(87) = "quatre-vingt-sept"
        nombres(88) = "quatre-vingt-huit"
        nombres(89) = "quatre-vingt-neuf"
        nombres(90) = "quatre-vingt-dix"
        nombres(91) = "quatre-vingt-onze"
        nombres(92) = "quatre-vingt-douze"
        nombres(93) = "quatre-vingt-treize"
        nombres(94) = "quatre-vingt-quatorze"
        nombres(95) = "quatre-vingt-quinze"
        nombres(96) = "quatre-vingt-seize"
        nombres(97) = "quatre-vingt-dix-sept"
        nombres(98) = "quatre-vingt-dix-huit"
        nombres(99) = "quatre-vingt-dix-neuf"
        nombres(100) = "cent"

        Dim millier_strg As String = ""
        Dim centaines_strg As String = ""
        Dim dizaines_unités_strg As String = ""

        If nombre >= 1000 Then
            Dim millier As Integer = nombre \ 1000
            If millier > 1 Then
                millier_strg = nombres(millier) & " mille"
            Else
                millier_strg = "mille"
            End If
        End If
        nombre = nombre Mod (1000)
        If nombre >= 100 Then
            Dim centaine As Integer = nombre \ 100
            If centaine > 1 Then
                centaines_strg = nombres(centaine) & " cent"
            Else
                centaines_strg = "cent"
            End If
        End If
        nombre = nombre Mod (100)
        If nombre > 0 Then
            dizaines_unités_strg = nombres(nombre)
        End If
        Return LTrim(millier_strg & " " & centaines_strg & " " & dizaines_unités_strg)
    End Function
    Public Sub round2(ByVal truc As Object)
        Dim taille_arc = 40
        If truc.width < 80 Or truc.height < 80 Then
            'taille_arc = 20
            taille_arc = CInt(Math.Min(truc.width, truc.height))
        End If
        Dim p As New Drawing2D.GraphicsPath()
        p.StartFigure()
        p.AddArc(New Rectangle(0, 0, taille_arc, taille_arc), 180, 90)
        p.AddLine(taille_arc, 0, truc.Width - taille_arc, 0)
        p.AddArc(New Rectangle(truc.Width - taille_arc, 0, taille_arc, taille_arc), -90, 90)
        p.AddLine(truc.Width, taille_arc, truc.Width, truc.Height - taille_arc)
        p.AddArc(New Rectangle(truc.Width - taille_arc, truc.Height - taille_arc, taille_arc, taille_arc), 0, 90)
        p.AddLine(truc.Width - taille_arc, truc.Height, taille_arc, truc.Height)
        p.AddArc(New Rectangle(0, truc.Height - taille_arc, taille_arc, taille_arc), 90, 90)
        p.CloseFigure()
        truc.Region = New Region(p)

    End Sub

    Public Function XML_GetRootNode_CreateIfNotExists(ByVal XmlDoc As XmlDocument, ByVal Xml_File As String, ByVal Node_Name As String) As XmlNode
        'ne s'applique qu'aux nodes racines
        '<?xml version="1.0"?>
        '<InfoPro>
        '   <Impr_Ordo> <---
        '       <EnTete>
        Dim nodeliste = XmlDoc.GetElementsByTagName(Node_Name)
        If nodeliste.Count = 0 Then
            Dim racine = XmlDoc.ChildNodes.Item(1)
            Dim New_Node As XmlElement = XmlDoc.CreateElement(Node_Name, XmlDoc.DocumentElement.NamespaceURI)
            racine.AppendChild(New_Node)
            If Xml_File <> "" Then
                XmlDoc.Save(Xml_File)
            End If
        End If
        Return XmlDoc.GetElementsByTagName(Node_Name).Item(0)
    End Function
    Public Function XML_GetChildnodeInnertext_CreateIfNotExists(ByVal XmlDoc As XmlDocument, ByVal XmlFile As String, ByVal ParentNode As XmlNode, ByVal ChildNodeName As String)
        'ne s'applique qu'aux nodes directement endants de nodes racines
        '<?xml version="1.0"?>
        '<InfoPro>
        '   <Impr_Ordo>
        '       <EnTete> <---
        If Not ParentNode.Item(ChildNodeName) Is Nothing Then
            Return ParentNode.Item(ChildNodeName).InnerText
        Else
            Dim New_Node As XmlElement = XmlDoc.CreateElement(ChildNodeName, XmlDoc.DocumentElement.NamespaceURI)
            New_Node.InnerText = ""
            ParentNode.AppendChild(New_Node)
            XmlDoc.Save(XmlFile)
            Return ""
        End If
    End Function

#Region "InfoPro"

    Public InfoPro As InfoPro_Struct

    Public Structure InfoPro_Struct
        Dim Pharmacie As Pharmacie_Struct
        Dim Impr_Ordo As Impr_Ordo_Struct
        Dim Chèque As Chèque_Struct
        Dim Ticket_Dus As Ticket_Struct
        Dim Ticket_Promis As Ticket_Struct

        Public Sub Load()
            Dim ConfigXml As New XmlDocument
            ConfigXml.Load(Application.StartupPath & "\InfoPro.xml")
            Dim save_at_the_end = False
            Dim node As XmlNode
            node = XML_GetRootNode_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", "Pharmacie")
            Pharmacie.présentation = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "présentation")

            node = XML_GetRootNode_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", "Impr_Ordo")
            Impr_Ordo.EnTete_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "EnTete_Template")
            Impr_Ordo.PiedPage_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "PiedPage_Template")
            Impr_Ordo.Lignes_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "Lignes_Template")
            Impr_Ordo.Font = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "PrintFont")
            Impr_Ordo.FontSize = Val(XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "SizeFont"))
            Impr_Ordo.default_printer = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "default_printer")
            If Impr_Ordo.EnTete_Template = "" And Impr_Ordo.PiedPage_Template = "" And Impr_Ordo.Lignes_Template = "" Then
                Impr_Ordo.EnTete_Template = "@Pharmacie_Présentation " & vbCrLf & "@Num_Facture @Date_Facture" & vbCrLf & "Assuré: @Assuré" & vbCrLf & "Bénéficiaire: @Bénéficiaire" & vbCrLf & "Prescripteur: @Prescripteur @Date_prescription" & vbCrLf & "Renouvellement: @Renouvellement"
                Impr_Ordo.PiedPage_Template = "AMO: @AMO" & vbCrLf & "Org Compl: @AMC" & vbCrLf & "Num adhérent: @Num_adhérent" & vbCrLf & "@Mode_TP" & vbCrLf & "@Mode_Secur " & vbCrLf & "Total:@Total_FSE" & vbCrLf & "AMO:@Total_AMO  AMC:@Total_AMC" & vbCrLf & "Total restant assuré:@Total_restant_assuré"
                Impr_Ordo.Font = "Courier New"
                Impr_Ordo.FontSize = 8
                Impr_Ordo.Lignes_Template = "@Quantité @Désignation @Code_Produit @Prix_Unitaire @Tarif_Remb @Taux_Remb @Code_Acte @LPP "
                save_at_the_end = True
            End If

            node = XML_GetRootNode_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", "CHEQUE")
            Chèque.Lignes_blanches = Val(XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "Lignes_blanches"))
            Chèque.decalage_droite = Val(XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "decalage_droite"))
            Chèque.default_printer = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "default_printer")
            Chèque.Font = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "PrintFont")
            Chèque.FontSize = Val(XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "SizeFont"))
            Chèque.A = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "A")
            Chèque.FAIT_A = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "FAIT_A")

            node = XML_GetRootNode_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", "Ticket_Dus")
            Ticket_Dus.default_printer = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "default_printer")
            Ticket_Dus.EnTete_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "EnTete_Template")
            Ticket_Dus.Font = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "PrintFont")
            Ticket_Dus.FontSize = Val(XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "SizeFont"))
            Ticket_Dus.Lignes_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "Lignes_Template")
            If Ticket_Dus.Lignes_Template = "" And Ticket_Dus.EnTete_Template = "" Then
                Ticket_Dus.Lignes_Template = "@Quantité @Produit @Code"
                Ticket_Dus.EnTete_Template = "TICKET DE DUS" & vbCrLf & "@Pharmacie_Présentation" & vbCrLf & "@Opérateur" & vbCrLf & "Bénéficiaire: @Bénéficiaire" & vbCrLf & "@Date" & vbCrLf & "@Type_Paiement" & vbCrLf
                Ticket_Dus.Font = "Courier New"
                Ticket_Dus.FontSize = 8
                save_at_the_end = True
            End If

            node = XML_GetRootNode_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", "Ticket_Promis")
            Ticket_Promis.default_printer = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "default_printer")
            Ticket_Promis.EnTete_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "EnTete_Template")
            Ticket_Promis.Font = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "PrintFont")
            Ticket_Promis.FontSize = Val(XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "SizeFont"))
            Ticket_Promis.Lignes_Template = XML_GetChildnodeInnertext_CreateIfNotExists(ConfigXml, Application.StartupPath & "\InfoPro.xml", node, "Lignes_Template")
            If Ticket_Promis.Lignes_Template = "" And Ticket_Promis.EnTete_Template = "" Then
                Ticket_Promis.Lignes_Template = "@Quantité @Produit @Code"
                Ticket_Promis.EnTete_Template = "TICKET DE PROMIS" & vbCrLf & "@Pharmacie_Présentation" & vbCrLf & "@Opérateur" & vbCrLf & "Bénéficiaire: @Bénéficiaire" & vbCrLf & "@Date" & vbCrLf
                Ticket_Promis.Font = "Courier New"
                Ticket_Promis.FontSize = 8
                save_at_the_end = True
            End If


            ConfigXml = Nothing
            If save_at_the_end = True Then
                Save()
            End If

        End Sub

        Public Sub Save()
            Dim ConfigXml As New XmlDocument
            ConfigXml.Load(Application.StartupPath & "\InfoPro.xml")

            Dim nodeliste As XmlNodeList

            nodeliste = ConfigXml.GetElementsByTagName("Pharmacie")
            nodeliste.Item(0).Item("présentation").InnerText = Pharmacie.présentation


            nodeliste = ConfigXml.GetElementsByTagName("Impr_Ordo")
            nodeliste.Item(0).Item("EnTete_Template").InnerText = Impr_Ordo.EnTete_Template
            nodeliste.Item(0).Item("PiedPage_Template").InnerText = Impr_Ordo.PiedPage_Template.ToString
            nodeliste.Item(0).Item("Lignes_Template").InnerText = Impr_Ordo.Lignes_Template.ToString
            nodeliste.Item(0).Item("PrintFont").InnerText = Impr_Ordo.Font.ToString
            nodeliste.Item(0).Item("SizeFont").InnerText = Impr_Ordo.FontSize.ToString
            nodeliste.Item(0).Item("default_printer").InnerText = Impr_Ordo.default_printer.ToString

            nodeliste = ConfigXml.GetElementsByTagName("CHEQUE")
            nodeliste.Item(0).Item("Lignes_blanches").InnerText = Chèque.Lignes_blanches.ToString
            nodeliste.Item(0).Item("decalage_droite").InnerText = Chèque.decalage_droite
            nodeliste.Item(0).Item("default_printer").InnerText = Chèque.default_printer
            nodeliste.Item(0).Item("PrintFont").InnerText = Chèque.Font.ToString
            nodeliste.Item(0).Item("SizeFont").InnerText = Chèque.FontSize.ToString
            nodeliste.Item(0).Item("A").InnerText = Chèque.A
            nodeliste.Item(0).Item("FAIT_A").InnerText = Chèque.FAIT_A

            nodeliste = ConfigXml.GetElementsByTagName("Ticket_Dus")
            nodeliste.Item(0).Item("default_printer").InnerText = Ticket_Dus.default_printer
            nodeliste.Item(0).Item("EnTete_Template").InnerText = Ticket_Dus.EnTete_Template
            nodeliste.Item(0).Item("PrintFont").InnerText = Ticket_Dus.Font
            nodeliste.Item(0).Item("SizeFont").InnerText = Ticket_Dus.FontSize
            nodeliste.Item(0).Item("Lignes_Template").InnerText = Ticket_Dus.Lignes_Template

            nodeliste = ConfigXml.GetElementsByTagName("Ticket_Promis")
            nodeliste.Item(0).Item("default_printer").InnerText = Ticket_Promis.default_printer
            nodeliste.Item(0).Item("EnTete_Template").InnerText = Ticket_Promis.EnTete_Template
            nodeliste.Item(0).Item("PrintFont").InnerText = Ticket_Promis.Font
            nodeliste.Item(0).Item("SizeFont").InnerText = Ticket_Promis.FontSize
            nodeliste.Item(0).Item("Lignes_Template").InnerText = Ticket_Promis.Lignes_Template

            ConfigXml.Save(Application.StartupPath & "\InfoPro.xml")
            ConfigXml = Nothing
        End Sub
    End Structure


    Public Structure Pharmacie_Struct
        Dim présentation As String
    End Structure
    Public Structure Impr_Ordo_Struct
        Dim Font As String
        Dim FontSize As Integer
        Dim default_printer As String
        Dim EnTete_Template As String
        Dim PiedPage_Template As String
        Dim Lignes_Template As String
        
    End Structure
    Public Structure Chèque_Struct
        Dim Lignes_blanches As Integer
        Dim decalage_droite As Integer
        Dim default_printer As String
        Dim A As String
        Dim FAIT_A As String
        Dim Font As String
        Dim FontSize As Integer

    End Structure
    Public Structure Ticket_Struct
        Dim Font As String
        Dim FontSize As Integer
        Dim default_printer As String
        Dim EnTete_Template As String
        Dim Lignes_Template As String
    End Structure
#End Region


End Module
