' 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
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Threading



Public Class MENU_PRINCIPAL

    Private but_list As New List(Of Button)
    Public auto_sender As Thread

    Private Sub start_DP_Relay()
        If Me.Enabled = False Then
            Exit Sub
        End If
        If Config.is_local_client = False Then
            Dim is_already_started = False
            For Each p As Process In Process.GetProcesses
                If String.Compare(p.ProcessName, "DP_Relay", True) = 0 Then
                    is_already_started = True
                    Exit For
                End If
            Next
            If is_already_started = False Then
                If My.Computer.FileSystem.FileExists(Application.StartupPath + "\DP_Relay\DP_Relay.exe") Then
                    Process.Start(Application.StartupPath + "\DP_Relay\DP_Relay.exe")
                End If
            End If
        End If
    End Sub

    Private Sub MENU_PRINCIPAL_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If UCase(e.KeyChar) = "C" Then
            COMPTOIR_MAIN.Visible = True
        End If
    End Sub

    Private Sub resize_form()
        Dim div_height, div_width As Single
        div_height = 1000 / Screen.PrimaryScreen.Bounds.Height
        div_width = 1600 / Screen.PrimaryScreen.Bounds.Width
        If div_height > 1 And div_width > 1 Then
            Me.Height = Int(Me.Height / div_height)
            Me.Width = Int(Me.Width / div_width)
            For Each obj In Controls
                Select Case obj.GetType.FullName.ToString

                    Case "System.Windows.Forms.PictureBox"
                        Dim pict As System.Windows.Forms.PictureBox
                        pict = obj
                        pict.Width = Int(pict.Width / div_width)
                        pict.Height = Int(pict.Height / div_height)
                        pict.Location = New Point(Int(pict.Location.X / div_width), Int(pict.Location.Y / div_height))

                    Case "System.Windows.Forms.PictureBox"
                        Dim lab As System.Windows.Forms.Label
                        lab = obj
                        lab.Width = Int(lab.Width / div_width)
                        lab.Height = Int(lab.Height / div_height)
                        lab.Location = New Point(Int(lab.Location.X / div_width), Int(lab.Location.Y / div_height))

                    Case "System.Windows.Forms.DataGridView"
                        Dim dat As System.Windows.Forms.DataGridView
                        dat = obj
                        dat.Width = Int(dat.Width / div_width)
                        dat.Height = Int(dat.Height / div_height)
                        dat.Location = New Point(Int(dat.Location.X / div_width), Int(dat.Location.Y / div_height))

                    Case "System.Windows.Forms.GroupBox"
                        Dim grp As System.Windows.Forms.GroupBox
                        grp = obj
                        grp.Width = Int(grp.Width / div_width)
                        grp.Height = Int(grp.Height / div_height)
                        grp.Location = New Point(Int(grp.Location.X / div_width), Int(grp.Location.Y / div_height))

                    Case "System.Windows.Forms.Panel"
                        Dim pan As System.Windows.Forms.Panel
                        pan = obj
                        pan.Width = Int(pan.Width / div_width)
                        pan.Height = Int(pan.Height / div_height)
                        pan.Location = New Point(Int(pan.Location.X / div_width), Int(pan.Location.Y / div_height))

                    Case "System.Windows.Forms.Button"
                        Dim but As System.Windows.Forms.Button
                        but = obj
                        but.Width = Int(but.Width / div_width)
                        but.Height = Int(but.Height / div_height)
                        but.Location = New Point(Int(but.Location.X / div_width), Int(but.Location.Y / div_height))

                    Case "System.Windows.Forms.DateTimePicker"
                        Dim dtp As System.Windows.Forms.DateTimePicker
                        dtp = obj
                        dtp.Width = Int(dtp.Width / div_width)
                        dtp.Height = Int(dtp.Height / div_height)
                        dtp.Location = New Point(Int(dtp.Location.X / div_width), Int(dtp.Location.Y / div_height))

                End Select
            Next
        End If
    End Sub

    Private Sub button_style(ByVal but_item As System.Windows.Forms.Button)
        but_item.FlatStyle = FlatStyle.Flat
        but_item.FlatAppearance.BorderSize = 0
        but_item.FlatAppearance.MouseDownBackColor = Color.Green
        but_item.FlatAppearance.MouseOverBackColor = Color.DarkGreen
        If but_item.BackgroundImage Is Nothing Then
            but_item.TextAlign = ContentAlignment.MiddleCenter
        Else
            but_item.TextAlign = ContentAlignment.BottomCenter
        End If

        round2(but_item)
    End Sub

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


        If Not My.Computer.FileSystem.DirectoryExists(Application.StartupPath + "\traces") Then
            My.Computer.FileSystem.CreateDirectory(Application.StartupPath + "\traces")
        End If


        bouton_barre_classe_add_button()
        Dim count = 0
        For Each but As Button In but_list
            but.Size = New Size(75, 75)
            but.Location = New Point((78 * count) + 3, 3)
            count = count + 1
        Next
        For Each panel_ As Control In Me.Controls
            If panel_.GetType.ToString = "System.Windows.Forms.Panel" Then
                For Each item As Control In panel_.Controls
                    If item.GetType.ToString = "System.Windows.Forms.Button" Then
                        button_style(item)
                    ElseIf item.GetType.ToString = "System.Windows.Forms.Panel" Then
                        '
                        For Each item_ As Control In item.Controls
                            If item_.GetType.ToString = "System.Windows.Forms.Button" Then
                                button_style(item_)
                            End If
                        Next

                        '
                    End If
                Next


            End If
        Next
        Hide_Panel.BringToFront()
        Panel1.Width = Screen.PrimaryScreen.Bounds.Width
        user_Button.Location = New Point(Screen.PrimaryScreen.Bounds.Width - user_Button.Width, 0)
        user_Button_unlock.Location = New Point(Screen.PrimaryScreen.Bounds.Width - user_Button_unlock.Width, 0)
        '____________________________________________________________________________________________________
        'Affichache numéro version logiciel
        VersionLabel.Text = "V1." & Format(RetrieveLinkerTimestamp(Application.StartupPath & "\Officine.exe"), "yyyyMMddHHmm")
        If Config.Logiciel_ModeFonctionement = "Test" Then
            VersionLabel.Text = VersionLabel.Text + "  Mode TEST"
        ElseIf Config.Logiciel_ModeFonctionement = "Démonstration" Then
            VersionLabel.Text = VersionLabel.Text + "  Mode DEMO"
        End If
        VersionLabel.Text = VersionLabel.Text & " "

        MyMsg_Box.Presentation("Officine", vbCrLf & "Bonjour," & vbCrLf & vbCrLf & "nous sommes le " & Now.ToLongDateString & ", il est " & Now.ToLongTimeString, True, "OUI", True, "NON", False, "")
        If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
            grand_opening()
        Else
            Me.Close()
        End If

        Me.Enabled = False


        Config.Load_Config_File()

        OfficineUpdate()


        Dim CNDAxml As New XmlDocument
        CNDAxml.Load("CNDA.xml")

        Dim ConfigXml As New XmlDocument
        Dim ConfigXMLelementliste As XmlNodeList
        ConfigXml.Load("config.xml")



        'DP
        ConfigXMLelementliste = ConfigXml.GetElementsByTagName("DP")
        If UCase(ConfigXMLelementliste.Item(0).Item("DP_Activer").InnerText) <> "OUI" Then
            MyMsg_Box.Presentation("Info DP", "Le DP a été automatiquement réactivé.", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            ConfigXMLelementliste.Item(0).Item("DP_Activer").InnerText = "OUI"
            ConfigXml.Save("config.xml")
        End If
        Config.DP_Activer = True


        ConfigXMLelementliste = CNDAxml.GetElementsByTagName("Visu_API")
        If UCase(ConfigXMLelementliste.Item(0).InnerText) = "OUI" Then
            Visu_API = True
        Else
            Visu_API = False
        End If
        ConfigXMLelementliste = CNDAxml.GetElementsByTagName("Trace_Appel_Fonctions")
        If ConfigXMLelementliste.Item(0).InnerText = "oui" Then
            Trace_Appel_Fonctions = True
        Else
            Trace_Appel_Fonctions = False
        End If
        CNDAxml = Nothing
        '--------------------------------------------
        'initialisation
        ReDim Tab_Valeur_STS(0)

        '____________________________________________________________________________________________________
        'initialisation des tableaux de currentuser
        ReDim Preserve CurrentBenéficiaire.G105C1(0)
        ReDim Preserve CurrentBenéficiaire.G105C2(0)
        ReDim Preserve CurrentBenéficiaire.G106C1(0)
        ReDim Preserve CurrentBenéficiaire.G106C2(0)
        ReDim Preserve CurrentBenéficiaire.G106C3(0)
        ReDim Preserve CurrentBenéficiaire.G106C4(0)
        ReDim Preserve CurrentBenéficiaire.G108C1(0)
        ReDim Preserve CurrentBenéficiaire.G108C2(0)
        '____________________________________________________________________________________________________
        'Eclatement des flux par un OCT
        ConfigXMLelementliste = ConfigXml.GetElementsByTagName("UtilisationOCT")
        If UCase(ConfigXMLelementliste.Item(0).InnerText) = "OUI" Then
            Config.OCT_UtilisationOCT = True
        Else
            Config.OCT_UtilisationOCT = False
        End If
        ConfigXMLelementliste = ConfigXml.GetElementsByTagName("FSEenrichies")
        If UCase(ConfigXMLelementliste.Item(0).InnerText) = "OUI" Then
            Config.OCT_FSEenrichies = True
        Else
            Config.OCT_FSEenrichies = False
        End If
        '____________________________________________________________________________________________________
        'Galss.ini
        ConfigXMLelementliste = ConfigXml.GetElementsByTagName("NomRessourcePS")
        NomRessourcePS = ConfigXMLelementliste.Item(0).InnerText
        ConfigXMLelementliste = ConfigXml.GetElementsByTagName("NomRessourceLecteur")
        NomRessourceLecteur = ConfigXMLelementliste.Item(0).InnerText
        '____________________________________________________________________________________________________
        'Fichier Code Spécialités
        FicCodesSpecialités = Application.StartupPath + "\Tables\CodeSpecialites.msk"
        'Remplit tableau Code Spécialités
        Dim line As String
        line = ""
        Dim i = 0
        Try
            Using sr As New StreamReader(FicCodesSpecialités, Encoding.Default)
                line = sr.ReadLine
                While line <> ""
                    ReDim Preserve tabCodeSpécialité(i)
                    tabCodeSpécialité(i).valeur = Mid(line, 1, 2)
                    tabCodeSpécialité(i).signification = Mid(line, 4, line.Length - 3)
                    line = sr.ReadLine
                    i = i + 1
                End While
            End Using
        Catch ex As Exception
            MyMsg_Box.Presentation("Officine", "ERREUR DE CHARGEMENT DE LA TABLE DES CODES SPECIALITES", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
        End Try
        '____________________________________________________________________________________________________
        'RESERVATION DE SESSION CPS
        Dim erreur As Integer = SGD_ReserverSession(0, NumeroSessionCPS)
        If erreur <> 0 Then
            MyMsg_Box.Presentation("Officine", "ERREUR POUR LA RESERVATION DE SESSION CPS: " + vbCrLf + erreur.ToString, False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            'Me.Close()
        End If
        'RESERVATION DE SESSION VITALE
        erreur = SGD_ReserverSession(0, NumeroSessionVitale)
        If erreur <> 0 Then
            MyMsg_Box.Presentation("Officine", "ERREUR POUR LA RESERVATION DE SESSION VITALE: " + vbCrLf + erreur.ToString, False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            'Me.Close()
        End If
        '____________________________________________________________________________________________________
        'SSV_InitLIB
        erreur = SSV_InitLIB2(Config.SesamIni)
        If erreur = 63136 Then
            Config.LOI_Activer = False
        Else
            AfficheErreur(erreur, "ERREUR POUR SSV_InitLib")
        End If
        '____________________________________________________________________________________________________
        'SIS_LireCartePS
        COMPTOIR_MAIN.Lire_CPS()
        '____________________________________________________________________________________________________
        ConfigXml = Nothing
        '____________________________________________________________________________________________________
        If Config.is_local_client = False Then
            'LOI
            If Config.LOI_Demande_Auto = True Then
                If LOI.LOI_DemandeTableAdapter.Select_Count_By_Date(Format(Now, "dd/MM/yyyy")) = 0 Then
                    LOI.Getmail_LOI()
                    LOI.Alerte_Non_Reception()
                    LOI.Demande_Auto_Loi()
                End If
            End If
            'CEPS
            Dim CEPS_files_mensuel As New List(Of String)
            Dim file As String
            file = Dir(Application.StartupPath + "\CEPS\CEPS_mensuel_*.xml")
            While file <> ""
                If Not CEPS_files_mensuel.Contains(file) Then
                    CEPS_files_mensuel.Add(file)
                End If
                file = Dir()
            End While
            If CEPS_files_mensuel.Count > 0 Then
                CEPS_files_mensuel.Sort()
                PRODUITS_bdd.CEPS_import_xml_mensuel(Application.StartupPath + "\CEPS\" & CEPS_files_mensuel(0), False)
            End If
            Dim CEPS_files_quotidien As New List(Of String)
            file = Dir(Application.StartupPath + "\CEPS\CEPS_quotidien_*.xml")
            While file <> ""
                CEPS_files_quotidien.Add(file)
                file = Dir()
            End While
            If CEPS_files_quotidien.Count > 0 Then
                CEPS_files_quotidien.Sort()
                PRODUITS_bdd.CEPS_import_xml_quotidien(Application.StartupPath + "\CEPS\" & CEPS_files_quotidien(CEPS_files_quotidien.Count - 1))
            End If

            PRODUITS_bdd.CEPS_Application_Décisions()


            'LPP
            If Dir(Application.StartupPath & "\LPP\LPPTOT*") <> "" Then
                Configuration.Import_LPP(Application.StartupPath & "\LPP\" & Dir(Application.StartupPath & "\LPP\LPPTOT*"))
            End If
            'PRODUITS_bdd.MAJ_Tarifs_Reglementés(False)
        End If

        '____________________________________________________________________________________________________
        LOI.init_LOI()
        '____________________________________________________________________________________________________
        Me.Enabled = True
        '____________________________________________________________________________________________________
        'DP

        'X_DP_Sequence_Number = Val(My.Computer.FileSystem.ReadAllText(Config.LocalNetwork_ServerName & "\DP\X_DP_Sequence_Number"))
        DP_Connect.HEARTBEAT_variables.MetNbC = 0
        DP_Connect.HEARTBEAT_variables.MetCnx = 0
        DP_Connect.HEARTBEAT_variables.MetNbCr = 0
        DP_Connect.HEARTBEAT_variables.MetCre = 0
        DP_Connect.HEARTBEAT_variables.MetNbCs = 0
        DP_Connect.HEARTBEAT_variables.MetCon = 0
        DP_Connect.HEARTBEAT_variables.MetNbAl = 0
        DP_Connect.HEARTBEAT_variables.MetAli = 0
        DP_Connect.HEARTBEAT_variables.MetNbEd = 0
        DP_Connect.HEARTBEAT_variables.MetEdi = 0
        DP_Connect.HEARTBEAT_variables.MetNbSu = 0
        DP_Connect.HEARTBEAT_variables.MetSup = 0
        If Config.DP_Activer = True Then
            If Config.DP_is_local_client = False Then
                DP.Write_Trace_Tech("", "IDENTIFIANT_ETABLISSEMENT", Config.DP_EtaTyp & "-" & Config.DP_EtaIdent)
                DP.Write_Trace_Tech("", "DENTIFIANT_LOGICIEL", Config.DP_LogValid & "-" & Config.DP_LogVers & "-" & Config.DP_LogVDP)
                DP_Connect_thread = New Thread(New ThreadStart(AddressOf DP_Connect.connect))
                DP_Connect_thread.Start()
            Else
                DP_connection_établie = True
            End If
        End If
        '____________________________________________________________________________________________________

        'PHARMA_ML autosender
        If Config.is_local_client = False Then
            auto_sender = New Thread(New ThreadStart(AddressOf PhML_Auto_Sender.Auto_sender))
            auto_sender.Start()
        End If

        If Config.is_local_client = False Then
            Start_SQL()
        End If
        'DP_relay
        start_DP_Relay()


        COMPTOIR_MAIN.DP_Affiche_Msg()

        Me.Enabled = False
        Bandeau_info_bas_show("     Préparation")

        If Config.Windows_Mode = True Then
            Me.WindowState = FormWindowState.Normal
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Me.ControlBox = True
        End If

        If Config.facilEpharm_Activé = True Then
            Dim Contr As New facilEpharm_Control
            Contr.Timer1.Interval = Config.facilEpharm_intervalle_Control * 1000
            Contr.Location = New Point(210, 580)
            MENU_PRINCIPAL_Panel.Controls.Add(Contr)
            Contr.BringToFront()
            Contr.refresh_()
        End If


        Affiche_info_chronique()
        Chronique_Périodes_Update_Date()

        current_User.Locked = False
        RIGHT_Click_Set_Menus()




        If Not My.Computer.FileSystem.DirectoryExists(Application.StartupPath + "\temp") Then
            My.Computer.FileSystem.CreateDirectory(Application.StartupPath + "\temp")
        End If
        If Config.is_local_client = False Then
            some_debug()
        End If

        InfoPro.Load()

        If Config.facilEpharm_Activé = True Then
            FacilEpharm_Control1.Visible = True
        End If

        Commandes_PharmaML.MAJ_quantités_en_commande()



        Try


            Dim période = BDD.Chronique_PériodeTableAdapter.GetData
            For r = 0 To période.Rows.Count - 1
                If période(r).Date_dernière_commande <= Now And période(r).Date_prochaine_commande >= Now Then
                    Chronique_Période_Label.ForeColor = System.Drawing.ColorTranslator.FromHtml("#" & période(r).Color_hex)
                    Chronique_Période_Label.Text = "Période du " & période(r).Date_dernière_commande.ToShortDateString & " au " & période(r).Date_prochaine_commande.ToShortDateString
                    Chronique_Période_Label.Visible = True
                    COMPTOIR_MAIN.Dates_Label.ForeColor = System.Drawing.ColorTranslator.FromHtml("#" & période(r).Color_hex)
                    Exit For
                End If
            Next
        Catch ex As Exception

        End Try

        Facture_Auto.Facturation_auto = False

        Me.Enabled = True

        Bandeau_info_bas_hide()




    End Sub

    Private Sub PRESCRIPTEURS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Edition_Prescripteurs.Visible = False Then
            Edition_Prescripteurs.Visible = True
        Else
            Edition_Prescripteurs.Select()
        End If
    End Sub

    Private Sub grand_opening()

        Comptoir_Button.Enabled = True
        Produits_Button.Enabled = True
        Commandes_Button.Enabled = True
        Caisse_Button.Enabled = True
        Pharmacie_Button.Enabled = True
        Données_Button.Enabled = True
        Factures_Button.Enabled = True
        If Config.is_local_client = False Then Teletrans_Button.Enabled = True
        Financier_Button.Enabled = True
        Outils_Button.Enabled = True
        Configuration_Button.Enabled = True
        Messagerie_Button.Enabled = True
        Quitter_Button.Enabled = True

        Me.KeyPreview = True

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        TextBox1.Text = Now.ToLongDateString & " " & Now.ToLongTimeString
        If COMPTOIR_MAIN.Visible = True Then
            COMPTOIR_MAIN.Dates_Label.Text = Now.ToLongDateString & "  " & Now.ToLongTimeString
        End If
        If VenteForm.Visible = True Then
            VenteForm.Dates_Label.Text = Now.ToLongDateString & " " & Now.ToLongTimeString
        End If
        If Commandes_PharmaML.Visible = True Then
            Commandes_PharmaML.Dates_Label.Text = Now.ToLongDateString & " " & Now.ToLongTimeString
        End If
        If Config.is_local_client = False Then
            If Now.Minute Mod 5 = 0 Then
                start_DP_Relay()
            End If
        End If
        If Now.Second = 0 Then
            Affiche_info_chronique()
        End If


    End Sub



#Region "COMPTOIR"
    Public Sub COMPTOIR_Button_Click(sender As Object, e As EventArgs) Handles Comptoir_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(Comptoir_Button.Location.X + MENU_PRINCIPAL_Panel.Location.X + Comptoir_Button.Width, Comptoir_Button.Location.Y + MENU_PRINCIPAL_Panel.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Hide_Panel.BringToFront()
            ' Me.WindowState = FormWindowState.Minimized
            If COMPTOIR_MAIN.Visible = False Then
                COMPTOIR_MAIN.Visible = True
                COMPTOIR_MAIN.WindowState = FormWindowState.Maximized
                COMPTOIR_MAIN.affiche_user()
                COMPTOIR_MAIN.Select()
            Else
                COMPTOIR_MAIN.WindowState = FormWindowState.Maximized
                COMPTOIR_MAIN.affiche_user()
                COMPTOIR_MAIN.Select()

            End If

        End If
    End Sub



    Public Sub COMPTOIR_MAIN_ResetForm(ByVal re_open As Boolean)
        COMPTOIR_MAIN.ResetForm()
        COMPTOIR_MAIN.Enabled = True
        COMPTOIR_MAIN.Dispose()
        If re_open = True Then COMPTOIR_MAIN.Visible = True
    End Sub
#End Region
#Region "COMMANDE"
    Private Sub Commandes_Button_Click(sender As Object, e As EventArgs) Handles Commandes_Button.Click

        Commandes_Panel.BringToFront()

    End Sub






    Public Sub Nouvelle_commande_Button_Click(sender As Object, e As EventArgs) Handles Commandes_PharmaML_Button.Click
        Commandes_PharmaML.Visible = True
        Commandes_PharmaML.BringToFront()
    End Sub

    Private Sub Afficher_commandes_Button_Click(sender As Object, e As EventArgs) Handles Commandes_Afficher_commandes_Button.Click
        Afficher_commandes.Visible = True
        Afficher_commandes.BringToFront()
    End Sub

    Private Sub Manuelle_Button_Click(sender As Object, e As EventArgs)
        Commandes_Manuelles.ShowDialog()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Commandes_Produits_hors_commande.Click
        Dim commande As New Commande_réception
        commande.reception_hors_commande = True
        commande.reception_groupée = False
        commande.Visible = True
        commande.BringToFront()
    End Sub

    Private Sub Fournisseurs_Button_Click(sender As Object, e As EventArgs) Handles Commandes_Fournisseurs_Button.Click
        Fournisseurs.Visible = True
        Fournisseurs.BringToFront()
    End Sub


    Private Sub Prog_horaire_Button_Click(sender As Object, e As EventArgs) Handles Commandes_Prog_horaire_Button.Click
        PhML_Auto_Sender.Visible = True
        PhML_Auto_Sender.BringToFront()
    End Sub

#End Region
#Region "CONFIGURATION"
    Private Sub CONFIGURATION_Button_Click(sender As Object, e As EventArgs) Handles Configuration_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(Configuration_Button.Location.X + MENU_PRINCIPAL_Panel.Location.X + Configuration_Button.Width, Configuration_Button.Location.Y + MENU_PRINCIPAL_Panel.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Configuration_Panel.BringToFront()
        End If
    End Sub

    Private Sub Configuration_Configuration_Button_Click(sender As Object, e As EventArgs) Handles Configuration_Configuration_Button.Click
        Configuration.Visible = True
        Configuration.BringToFront()
    End Sub

    Private Sub Configuration_Technique_Button_Click(sender As Object, e As EventArgs) Handles Configuration_Technique_Button.Click
        Technique_MAIN.Visible = True
        Technique_MAIN.BringToFront()
    End Sub

    Private Sub Configuration_CodesActes_Button_Click(sender As Object, e As EventArgs) Handles Configuration_CodesActes_Button.Click
        Codes_Acte.Visible = True
        Codes_Acte.BringToFront()
    End Sub

    Private Sub Configuration_LOI_Button_Click(sender As Object, e As EventArgs) Handles Configuration_LOI_Button.Click
        LOI.Visible = True
        LOI.BringToFront()
    End Sub

    Private Sub Button_Données_LOI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        LOI.Visible = True
        LOI.BringToFront()
    End Sub
#End Region
#Region "Financier"
    Private Sub Financier_Button_Click(sender As Object, e As EventArgs) Handles Financier_Button.Click

        Application.DoEvents()
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(MENU_PRINCIPAL_Panel.Location.X + Financier_Button.Location.X + Financier_Button.Width, MENU_PRINCIPAL_Panel.Location.Y + Financier_Button.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Financier_Panel.BringToFront()
        End If

    End Sub


    Private Sub GESTION_Button_Click(sender As Object, e As EventArgs) Handles GESTION_Button.Click


        If Gestion_Main.Visible = False Then
            Gestion_Main.Visible = True
            Gestion_Main.WindowState = FormWindowState.Maximized
            Gestion_Main.BringToFront()
            Gestion_Main.Select()
        Else
            Gestion_Main.WindowState = FormWindowState.Maximized
            Gestion_Main.BringToFront()
            Gestion_Main.Select()
        End If
    End Sub

    Private Sub Financier_SynthèseComptable_Button_Click(sender As Object, e As EventArgs) Handles Financier_SynthèseComptable_Button.Click
        Dim parameters As String = "&Début=" & Format(Now, "yyyy-MM-dd") & "T00:00:00" & "&Fin=" & Format(Now, "yyyy-MM-dd") & "T23:59:59"
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fAdministratif%2fSynth%c3%a8se+comptable&rs:Command=Render" & parameters)
    End Sub
    Private Sub Financier_Encaissements_Button_Click(sender As Object, e As EventArgs) Handles Financier_Encaissements_Button.Click
        Encaissements.Visible = True
        Encaissements.BringToFront()
    End Sub
    Private Sub Financier_BalanceTVA_Button_Click(sender As Object, e As EventArgs) Handles Financier_BalanceTVA_Button.Click
        Balance_Comptable.Visible = True
        Balance_Comptable.BringToFront()
    End Sub



    Private Sub Financier_HistoriqueRemise_Button_Click(sender As Object, e As EventArgs) Handles Financier_HistoriqueRemise_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fProduits%2fRemise&rs:Command=Render")
    End Sub

    Private Sub Financier_ControlePaiementsAssurances_Button_Click(sender As Object, e As EventArgs) Handles Financier_ControlePaiementsAssurances_Button.Click
        Controle_Paiements_FSE.Visible = True
        Controle_Paiements_FSE.BringToFront()
    End Sub
#End Region
#Region "PHARMACIE"
    Private Sub Pharmacie_Button_Click(sender As Object, e As EventArgs) Handles Pharmacie_Button.Click
        Pharmacie_Panel.BringToFront()
    End Sub


#Region "ORDONNANCIER"
    Private Sub Pharmacie_Ordonnancier_L1_L2_Button_Click(sender As Object, e As EventArgs) Handles Pharmacie_Ordonnancier_L1_L2_Button.Click
        Dim parameters As String = "&deb=" & Format(Now, "yyyy-MM-dd") & "T00:00:00" & "&fin=" & Format(Now, "yyyy-MM-dd") & "T23:59:59"
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fAdministratif%2fOrdonnancier%2fOrdonnancier+Liste+I+et+II&rs:Command=Render" & parameters)
    End Sub

    Private Sub Pharmacie_Ordonnancier_Stupéfiants_Button_Click(sender As Object, e As EventArgs) Handles Pharmacie_Ordonnancier_Stupéfiants_Button.Click
        Dim parameters As String = "&deb=" & Format(Now, "yyyy-MM-dd") & "T00:00:00" & "&fin=" & Format(Now, "yyyy-MM-dd") & "T23:59:59"
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fAdministratif%2fOrdonnancier%2fOrdonnancier+Stup%c3%a9fiants&rs:Command=Render" & parameters)
    End Sub

    Private Sub Pharmacie_BalanceStupéfiants_Button_Click(sender As Object, e As EventArgs) Handles Pharmacie_BalanceStupéfiants_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fAdministratif%2fOrdonnancier%2fBalance_stup&rs:Command=Render")
    End Sub
#End Region
#Region "DP"
    Private Sub DP_Button_Click(sender As Object, e As EventArgs) Handles DP_Button.Click
        DP_Alerte_Historique.Visible = True
        DP_Alerte_Historique.BringToFront()
    End Sub

#End Region
#End Region
#Region "FACTURES"
#Region "MENU"
    Private Sub Factures_Panel_VisibleChanged(sender As Object, e As EventArgs) Handles Factures_Panel.VisibleChanged
        Factures_Main_Panel.Visible = True
        Factures_FSE_Panel.Visible = False
        Factures_VD_Panel.Visible = False
        Factures_sousmenu1_button.Text = ""
    End Sub

    Private Sub Factures_Main_FSE_Button_Click(sender As Object, e As EventArgs) Handles Factures_Main_FSE_Button.Click
        Factures_Main_Panel.Visible = False
        Factures_FSE_Panel.Visible = True
        Factures_VD_Panel.Visible = False
        Factures_sousmenu1_button.Text = Factures_Main_FSE_Button.Text
    End Sub

    Private Sub Factures_Main_VD_Button_Click(sender As Object, e As EventArgs) Handles Factures_Main_VD_Button.Click
        Factures_Main_Panel.Visible = False
        Factures_FSE_Panel.Visible = False
        Factures_VD_Panel.Visible = True
        Factures_sousmenu1_button.Text = Factures_Main_VD_Button.Text
    End Sub



    Private Sub Factures_Panel_Header_Button_Click(sender As Object, e As EventArgs) Handles Factures_Panel_Header_Button.Click
        Factures_Main_Panel.Visible = True
        Factures_FSE_Panel.Visible = False
        Factures_VD_Panel.Visible = False
        Factures_sousmenu1_button.Text = ""
    End Sub
#End Region
#Region "FSE"
    Private Sub Factures_Button_Click(sender As Object, e As EventArgs) Handles Factures_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(Factures_Button.Location.X + MENU_PRINCIPAL_Panel.Location.X + Factures_Button.Width, Factures_Button.Location.Y + MENU_PRINCIPAL_Panel.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
     Factures_Panel.BringToFront()
        End If

    End Sub



    Private Sub Factures_FSE_Liste_Click(sender As Object, e As EventArgs) Handles Factures_FSE_Liste_Button.Click
        Dim parameters As String = "&G1110C3_deb=" & Format(Now, "yyyy-MM-dd") & "T00:00:00" & "&G1110C3_fin=" & Format(Now, "yyyy-MM-dd") & "T23:59:59"
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fFactures%2fFactures+Sesam-Vitale&rs:Command=Render" & parameters)
    End Sub



    Private Sub Factures_FSE_Button_Click(sender As Object, e As EventArgs) Handles Factures_FSE_Détail_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fFactures%2fFacture+Sesam-Vitale&rs:Command=Render")
    End Sub



    Private Sub Factures_Rejets_Button_Click(sender As Object, e As EventArgs) Handles Factures_Rejets_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fFactures%2fRejets&rs:Command=Render")
    End Sub

    Private Sub Factures_FSE_Suppr_Button_Click(sender As Object, e As EventArgs) Handles Factures_FSE_Suppr_Button.Click
        Dim numfacture As Integer = 0
        MyInptBox.my_showdialog("SUPPRESSION FACTURE" & vbCrLf & vbCrLf & "Numéro de la FSE à supprimer definitivement?", VarType(numfacture), 100, "")
        numfacture = MyInptBox.result
        If IsNothing(numfacture) Then Exit Sub
        If Not IsNumeric(numfacture) Then Exit Sub
        MyMsg_Box.Presentation("Officine", "Voulez vous supprimer la facture n° " & numfacture & " definitivement ?", True, "OUI", True, "NON", False, "")
        If MyMsg_Box.ShowDialog() = MsgBoxResult.Yes Then
            Facture.Supprimer_FSE(numfacture, True, True, True, True, False)
        End If
    End Sub

    Private Sub Factures_FSE_dRE_Annulation_Button_Click(sender As Object, e As EventArgs) Handles Factures_FSE_dRE_Annulation_Button.Click
        Dim numfacture As Integer = 0
        MyInptBox.my_showdialog("DRE d'annulation" & vbCrLf & vbCrLf & "Numéro de facture?", VarType(numfacture), 100, "")
        numfacture = MyInptBox.result
        Facture.DRE_d_annulation(numfacture)
    End Sub

    Private Sub Factures_FSE_DonnTech_Button_Click(sender As Object, e As EventArgs) Handles Factures_FSE_DonnTech_Button.Click
        Dim numfacture As Integer = 0
        MyInptBox.my_showdialog("Données techniques:" & vbCrLf & vbCrLf & "Numéro de facture?", VarType(numfacture), 100, "")
        numfacture = MyInptBox.result
        Dim factform As New Facture
        factform.FacturedonnéesTechniques(numfacture)
        factform.Visible = True
    End Sub
#End Region
#Region "VD"
    Private Sub Factures_VD_Liste_Button_Click(sender As Object, e As EventArgs) Handles Factures_VD_Liste_Button.Click
        Dim parameters As String = "&deb=" & Format(Now, "yyyy-MM-dd") & "T00:00:00" & "&fin=" & Format(Now, "yyyy-MM-dd") & "T23:59:59"
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fFactures%2fFactures+Vente+Directe&rs:Command=Render" & parameters)
    End Sub



    Private Sub Factures_VD_Détail_Button_Click(sender As Object, e As EventArgs) Handles Factures_VD_Détail_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fFactures%2fFacture+Vente+Directe&rs:Command=Render")
    End Sub



    Private Sub Factures_VD_Suppr_Button5_Click(sender As Object, e As EventArgs) Handles Factures_VD_Suppr_Button5.Click
        Dim num_facture As Integer = 0
        MyInptBox.my_showdialog("SUPPRESSION FACTURE" & vbCrLf & vbCrLf & "Numéro de facture?", VarType(num_facture), 100, "")
        num_facture = MyInptBox.result
        If Not IsNumeric(num_facture) Then
            MyMsg_Box.Presentation("Officine", "Numéro facture invalide", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Exit Sub
        End If
        Facture.Supprimer_VenteDirecte(CDec(num_facture), True, True, True)
    End Sub
#End Region
#End Region
#Region "OUTILS"
    Private Sub Outils_Button_Click(sender As Object, e As EventArgs) Handles Outils_Button.Click
        Outils_Panel.BringToFront()
    End Sub



    Private Sub Outils_Fréquentation_Button_Click(sender As Object, e As EventArgs) Handles Outils_Fréquentation_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fOutils%2fFrequentation&rs:Command=Render")
    End Sub



    Private Sub Outils_Activité_individuelle_Button_Click(sender As Object, e As EventArgs) Handles Outils_Activité_individuelle_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fOutils%2fActivit%c3%a9_individuelle&rs:Command=Render")
    End Sub


#End Region
#Region "PRODUITS"
    Private Sub Produits_Button_Click(sender As Object, e As EventArgs) Handles Produits_Button.Click
        If Select_user(Produits_Button) = True Then
            Produits_Panel.BringToFront()
        End If

    End Sub



    Private Sub PRODUITS_Fiche_Button_Click(sender As Object, e As EventArgs) Handles PRODUITS_Fiche_Button.Click
        Produits.Visible = True
        Produits.BringToFront()
    End Sub



    Private Sub PRODUITS_Vendus_Button_Click(sender As Object, e As EventArgs) Handles PRODUITS_Ventes_Button.Click
        Dim parameters As String = "&StartDate=" & Format(Now, "yyyy-MM-dd") & "T00:00:00" & "&EndDate=" & Format(Now, "yyyy-MM-dd") & "T23:59:59"
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fProduits%2fProduits+vendus+recherche&rs:Command=Render" & parameters)
    End Sub



    Private Sub Inventaire_Button_Click(sender As Object, e As EventArgs) Handles Inventaire_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = Inventaire_Button.Location
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Choix_inventaire.Visible = True
        End If
    End Sub


    Private Sub PRODUITS_Importer_Button_Click(sender As Object, e As EventArgs) Handles PRODUITS_Importer_Button.Click
        Import_Produit_From_Vidal.ShowDialog()
    End Sub



#End Region
#Region "DONNEES"
    Private Sub Données_Button_Click(sender As Object, e As EventArgs) Handles Données_Button.Click
        Données_Panel.BringToFront()
    End Sub



    Private Sub Données_Prescripteurs_Button_Click(sender As Object, e As EventArgs) Handles Données_Prescripteurs_Button.Click
        Prescripteurs_bdd.Visible = True
        Prescripteurs_bdd.BringToFront()
    End Sub



    Private Sub Comptes_Clients_button_Click(sender As Object, e As EventArgs) Handles Données_Comptes_Clients_Button.Click
        Comptes_Clients.Visible = True
        Comptes_Clients.BringToFront()
    End Sub



#End Region
#Region "QUITTER"
    Private Sub Quitter_Button_Click(sender As Object, e As EventArgs) Handles Quitter_Button.Click
        If Config.DP_is_local_client = False Then

            If Not auto_sender Is Nothing Then
                If auto_sender.ThreadState = ThreadState.Running Then
                    auto_sender.Abort()
                End If
            End If
            If Config.DP_Activer = True Then
                If Not DP_local_server_thread Is Nothing Then
                    DP_local_server_thread.Abort()
                End If
                If Not DP_AP_MSG_thread Is Nothing Then
                    DP_AP_MSG_thread.Abort()
                End If
                DP_Connect_thread.Abort()
                DP_Connect.Heartbeat("FIN")
            End If
        End If
        Environment.Exit(0)
    End Sub


#End Region
#Region "CAISSE"
    Private Sub Caisse_Button_Click(sender As Object, e As EventArgs) Handles Caisse_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(Caisse_Button.Location.X + MENU_PRINCIPAL_Panel.Location.X + Caisse_Button.Width, Caisse_Button.Location.Y + MENU_PRINCIPAL_Panel.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Gestion_Caisse.Visible = True
            Gestion_Caisse.BringToFront()
            Gestion_Caisse.WindowState = FormWindowState.Maximized
        End If
       

    End Sub

#End Region
#Region "TELETRANSMISSION"
    Private Sub Teletrans_Button_Click(sender As Object, e As EventArgs) Handles Teletrans_Button.Click
        If Config.is_local_client Then
            MyMsg_Box.Presentation("Télétransmission", "Les télétransmissions se font depuis le poste principal.", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Exit Sub
        End If
        Teletrans_Panel.BringToFront()
    End Sub


#End Region




#Region "MESSAGERIE"

    Private Sub Messagerie_Button_Click(sender As Object, e As EventArgs) Handles Messagerie_Button.Click
        'Dim my_USERS_Select As New USERS_Select
        'my_USERS_Select.Location = New Point(Messagerie_Button.Location.X + Main_Panel.Location.X + Messagerie_Button.Width, Messagerie_Button.Location.Y + Main_Panel.Location.Y)
        'my_USERS_Select.ShowDialog()
        'If password_validated = True Then
        If Messagerie_Interne.Visible = False Then
            Messagerie_Interne.Visible = True
            Messagerie_Interne.Current_ID_user = current_User.ID
            Messagerie_Interne.WindowState = FormWindowState.Maximized
            Messagerie_Interne.BringToFront()
        Else
            If current_User.ID = Messagerie_Interne.Current_ID_user Then
                Messagerie_Interne.Visible = True
                Messagerie_Interne.WindowState = FormWindowState.Maximized
                Messagerie_Interne.BringToFront()
            Else
                Messagerie_Interne.Close()
                Messagerie_Interne.Visible = True
                Messagerie_Interne.Current_ID_user = current_User.ID
                Messagerie_Interne.WindowState = FormWindowState.Maximized
                Messagerie_Interne.BringToFront()
            End If
        End If

        'End If
    End Sub


#End Region





    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Type_Paiement.Visible = True
        Type_Paiement.BringToFront()
    End Sub

    Private Sub Financier_ControleRetoursAssurances_Button_Click(sender As Object, e As EventArgs) Handles Financier_ControleRetoursAssurances_Button.Click
        Controle_Retours.Visible = True
        Controle_Retours.WindowState = FormWindowState.Maximized
        Controle_Retours.BringToFront()
    End Sub

    Private Sub trait_suppr_vd()
        Dim file = Dir(Config.Repertoires_RepertoireFactures & "Suppr\VD_*.txt")
        While file <> ""
            Dim reader As New StreamReader(Config.Repertoires_RepertoireFactures & "Suppr\" & file)
            Dim line = reader.ReadLine
            Dim id As String = ""
            Dim date_suppr = My.Computer.FileSystem.GetFileInfo(Config.Repertoires_RepertoireFactures & "Suppr\" & file).CreationTime
            Dim numfacture As String = ""
            Dim Action = "VD non aboutie"
            Dim Nom_Complet As String = ""
            Dim NIR As String = ""
            Dim date_fact As String = ""
            Dim line_prod As New List(Of String)
            Dim produits_restockés As String = "PRODUITS NON RESTOCKÉS"
            Dim Encaissement_Supprimé As New List(Of String)
            While Not line Is Nothing
                If InStr(line, "Supression VD") = 1 Then
                    numfacture = Mid(line, 15)
                    line = reader.ReadLine
                    id = line

                ElseIf InStr(line, "Supression manuelle") = 1 Then
                    Action = "Supression VD"

                ElseIf InStr(line, "Nom_Complet :") = 1 Then
                    Nom_Complet = Mid(line, 15)

                ElseIf InStr(line, "Nir :") = 1 Then
                    NIR = Mid(line, 7)

                ElseIf InStr(line, "Date_ :") = 1 Then
                    date_fact = Mid(Mid(line, 9), 7, 2) & "/" & Mid(Mid(line, 9), 5, 2) & "/" & Mid(Mid(line, 9), 1, 4) & " " & Mid(Mid(line, 9), 9, 2) & ":" & Mid(Mid(line, 9), 11, 2)

                ElseIf InStr(line, "ACTE:") = 1 Then
                    line = reader.ReadLine
                    Dim prod As String = ""
                    While InStr(line, "Quantité :") <> 1 And InStr(line, "ACTE:") <> 1 And InStr(line, "FACTURE:") <> 1
                        line = reader.ReadLine
                    End While
                    If InStr(line, "Quantité :") = 1 Then
                        prod = "(" & Mid(line, 12) & ")"
                    End If
                    While InStr(line, "Désignation :") <> 1 And InStr(line, "ACTE:") <> 1 And InStr(line, "FACTURE:") <> 1
                        line = reader.ReadLine
                    End While
                    If InStr(line, "Désignation :") = 1 Then
                        prod = prod & " " & Mid(line, 15)
                        line_prod.Add(prod)
                    End If

                ElseIf InStr(line, "produits restockés") = 1 Then
                    produits_restockés = "PRODUITS RESTOCKÉS"

                ElseIf InStr(line, "Suppresion encaissement:") = 1 Then
                    Dim encaiss As String = ""
                    While InStr(line, "Type :") <> 1
                        line = reader.ReadLine
                    End While
                    encaiss = "Encaissement Supprimé: " & Mid(line, 8)
                    While InStr(line, "Valeur :") <> 1
                        line = reader.ReadLine
                    End While
                    encaiss = encaiss & " " & Mid(line, 10) & "€"
                    Encaissement_Supprimé.Add(encaiss)

                End If




                If InStr(line, "ACTE:") <> 1 Then
                    line = reader.ReadLine
                End If


            End While
            reader.Close()
            Dim info As String = numfacture & Chr(10) & date_fact & Chr(10)
            If Nom_Complet <> "" Then
                info = info & Nom_Complet & Chr(10)
            End If
            If NIR <> "" Then
                info = info & NIR & Chr(10)
            End If
            For Each prod As String In line_prod
                info = info & prod & Chr(10)
            Next

            info = info & produits_restockés & Chr(10)
            For Each encaiss As String In Encaissement_Supprimé
                info = info & encaiss & Chr(10)
            Next
            BDD.Historique_ActionsTableAdapter.Insert(id, date_suppr, Action, info)

            My.Computer.FileSystem.DeleteFile(Config.Repertoires_RepertoireFactures & "Suppr\" & file)
            'file = Dir(Config.Repertoires_RepertoireFactures & "Suppr\VD_*.txt")
            file = Dir()
        End While
    End Sub

    Private Sub trait_suppr_fse()
        Dim file = Dir(Config.Repertoires_RepertoireFactures & "Suppr\FSE_*.txt")
        While file <> ""
            Dim reader As New StreamReader(Config.Repertoires_RepertoireFactures & "Suppr\" & file)
            Dim line = reader.ReadLine
            Dim id As String = ""
            Dim date_suppr = My.Computer.FileSystem.GetFileInfo(Config.Repertoires_RepertoireFactures & "Suppr\" & file).CreationTime
            Dim numfacture As String = ""
            Dim Action = "FSE non aboutie"
            Dim Nom_Complet As String = ""
            Dim NIR As String = ""
            Dim date_fact As String = ""
            Dim line_prod As New List(Of String)
            Dim produits_restockés As String = "PRODUITS NON RESTOCKÉS"
            Dim Encaissement_Supprimé As New List(Of String)
            While Not line Is Nothing
                If InStr(line, "Supression FSE") = 1 Then
                    numfacture = Mid(line, 16)
                    line = reader.ReadLine
                    id = line

                ElseIf InStr(line, "Supression manuelle") = 1 Then
                    Action = "Supression FSE"

                ElseIf InStr(line, "Nom_Complet :") = 1 Then
                    Nom_Complet = Mid(line, 15)

                ElseIf InStr(line, "G1130C2 :") = 1 Then
                    NIR = Mid(line, 11)


                ElseIf InStr(line, "ACTE:") = 1 Then
                    line = reader.ReadLine
                    While InStr(line, "Nom :") <> 1 And InStr(line, "ACTE:") <> 1 And InStr(line, "FACTURE:") <> 1
                        line = reader.ReadLine
                    End While
                    If InStr(line, "Nom :") = 1 Then
                        Nom_Complet = Mid(line, 7)
                        line = reader.ReadLine
                        Nom_Complet = Nom_Complet & " " & Mid(line, 10)
                    End If
                    Dim prod As String = ""
                    While InStr(line, "Date :") <> 1 And InStr(line, "ACTE:") <> 1 And InStr(line, "FACTURE:") <> 1
                        line = reader.ReadLine
                    End While
                    If InStr(line, "Date :") = 1 Then
                        date_fact = Mid(Mid(line, 8), 7, 2) & "/" & Mid(Mid(line, 8), 5, 2) & "/" & Mid(Mid(line, 8), 1, 4) & " " & Mid(Mid(line, 8), 9, 2) & ":" & Mid(Mid(line, 8), 11, 2)
                    End If
                    While InStr(line, "Quantité :") <> 1 And InStr(line, "ACTE:") <> 1 And InStr(line, "FACTURE:") <> 1
                        line = reader.ReadLine
                    End While
                    If InStr(line, "Quantité :") = 1 Then
                        prod = "(" & Mid(line, 12) & ")"
                    End If
                    While InStr(line, "Désignation :") <> 1 And InStr(line, "ACTE:") <> 1 And InStr(line, "FACTURE:") <> 1
                        line = reader.ReadLine
                    End While
                    If InStr(line, "Désignation :") = 1 Then
                        prod = prod & " " & Mid(line, 15)
                        line_prod.Add(prod)
                    End If

                ElseIf InStr(line, "produits restockés") = 1 Then
                    produits_restockés = "PRODUITS RESTOCKÉS"

                ElseIf InStr(line, "Suppresion encaissement:") = 1 Then
                    Dim encaiss As String = ""
                    While InStr(line, "Type :") <> 1
                        line = reader.ReadLine
                    End While
                    encaiss = "Encaissement Supprimé: " & Mid(line, 8)
                    While InStr(line, "Valeur :") <> 1
                        line = reader.ReadLine
                    End While
                    encaiss = encaiss & " " & Mid(line, 10) & "€"
                    Encaissement_Supprimé.Add(encaiss)

                End If




                If InStr(line, "ACTE:") <> 1 Then
                    line = reader.ReadLine
                End If


            End While
            reader.Close()
            Dim info As String = numfacture & Chr(10) & date_fact & Chr(10)
            If Nom_Complet <> "" Then
                info = info & Nom_Complet & Chr(10)
            End If
            If NIR <> "" Then
                info = info & NIR & Chr(10)
            End If
            For Each prod As String In line_prod
                info = info & prod & Chr(10)
            Next

            info = info & produits_restockés & Chr(10)
            For Each encaiss As String In Encaissement_Supprimé
                info = info & encaiss & Chr(10)
            Next
            BDD.Historique_ActionsTableAdapter.Insert(id, date_suppr, Action, info)
            My.Computer.FileSystem.DeleteFile(Config.Repertoires_RepertoireFactures & "Suppr\" & file)
            'file = Dir(Config.Repertoires_RepertoireFactures & "Suppr\FSE_*.txt")
            file = Dir()
        End While
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs)
        trait_suppr_fse()
        trait_suppr_vd()
    End Sub

    Private Function Select_user(ByVal The_button As Button) As Boolean

        Application.DoEvents()
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(MENU_PRINCIPAL_Panel.Location.X + The_button.Location.X + The_button.Width, MENU_PRINCIPAL_Panel.Location.Y + The_button.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Return True
        Else
            Return False
        End If

    End Function

    Private Sub Button7_Click_1(sender As Object, e As EventArgs) Handles Button7.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fProduits%2fCat_Mens_Prix&rs:Command=Render")
    End Sub


    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fProduits%2fProduits_Avanc%c3%a9s&rs:Command=Render")
    End Sub


    Private Sub user_Button_Click(sender As Object, e As EventArgs) Handles user_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(Commandes_Panel.Location.X - 220, user_Button.Location.Y)
        my_USERS_Select.ShowDialog()
        user_Button.Text = current_User.ID
        If Not current_User.image Is Nothing Then
            user_Button.BackgroundImage = current_User.image
            user_Button.Font = New Font("Century Gothic", 10)
            user_Button.TextAlign = ContentAlignment.BottomRight
            user_Button.ForeColor = Color.Black
        Else
            user_Button.BackgroundImage = Nothing
            user_Button.Font = New Font("Century Gothic", 15)
            user_Button.TextAlign = ContentAlignment.MiddleCenter
            user_Button.ForeColor = Color.White

        End If
    End Sub

    Private Sub user_Button_unlock_Click(sender As Object, e As EventArgs) Handles user_Button_unlock.Click
        current_User.ID = ""
        current_User.Locked = False
        user_Button.Visible = False
        user_Button_unlock.Visible = False
    End Sub

#Region "RIGHT Click"
    Private Sub RIGHT_Click_Set_Menus()
        Commandes_Button.Tag = Commandes_Panel

    End Sub


    Private Sub Button_MouseDown(sender As Button, e As MouseEventArgs) Handles Commandes_Button.MouseDown
        If current_User.Locked = False Then
            Exit Sub
        End If

        If e.Button = Windows.Forms.MouseButtons.Right Then
            If sender.Tag.GetType Is GetType(System.Windows.Forms.Panel) Then

                Dim MENU_PRINCIPAL_Right_Click_form As New MENU_PRINCIPAL_Right_Click
                MENU_PRINCIPAL_Right_Click_form.Location = New Point(sender.Parent.Location.X + sender.Location.X, sender.Parent.Location.Y + sender.Location.Y)
                MENU_PRINCIPAL_Right_Click_form.image = sender.BackgroundImage
                MENU_PRINCIPAL_Right_Click_form.Source_Panel = sender.Tag
                MENU_PRINCIPAL_Right_Click_form.Text = sender.Text
                MENU_PRINCIPAL_Right_Click_form.ShowDialog()
            End If
        End If
    End Sub
#End Region

    Private Sub Start_SQL()
        If Config.is_local_client = True Then
            Exit Sub
        End If
        Bandeau_info_bas_show("Demarrage service base de données")
        Dim service As System.ServiceProcess.ServiceController = New System.ServiceProcess.ServiceController("MSSQL$SQLEXPRESS")

        If service.Status <> ServiceProcess.ServiceControllerStatus.Running And service.Status <> ServiceProcess.ServiceControllerStatus.StartPending Then
            service.Start()
            System.Threading.Thread.Sleep(30000)
        End If

        Bandeau_info_bas_hide()
    End Sub

    Private Sub Organismes_Payeurs_Button_Click(sender As Object, e As EventArgs) Handles Organismes_Payeurs_Button.Click
        Organismes_Autres_Gestion.Visible = True

    End Sub

    Private Sub Pharmacie_SuiviTraitement_Button_Click(sender As Object, e As EventArgs) Handles Pharmacie_SuiviTraitement_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(Pharmacie_SuiviTraitement_Button.Location.X + MENU_PRINCIPAL_Panel.Location.X + Pharmacie_SuiviTraitement_Button.Width, Pharmacie_SuiviTraitement_Button.Location.Y + MENU_PRINCIPAL_Panel.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
             Dim sv As New SuiviTraitementList
            sv.Tri_Patient = ""
            sv.Organisme = ""
            sv.RadioButton1.Checked = False
            sv.RadioButton2.Checked = True
            sv.à_commander = True
            sv.ShowDialog()

        End If
       
    End Sub

    Public Sub Affiche_info_chronique()

        Dim tot_commande = BDD.ChroniqueTableAdapter.GetData_Produit_à_commander("", "", CDate(Now), "True", CDate(Now), "False", "", 0, 0).Rows.Count
        Dim tot_renouv = BDD.ChroniqueTableAdapter.GetData_Date_Renouvellement(Now).Rows.Count
        If tot_commande > 0 Or tot_renouv > 0 Then
            Pharmacie_SuiviTraitement_Button.ForeColor = Color.White
            Pharmacie_SuiviTraitement_Button.BackColor = Color.Orange
            If tot_renouv = 1 Then
                Pharmacie_SuiviTraitement_Button.Text = _
               "Suivi patient" & vbCrLf & vbCrLf & "1 renouvellement"
            ElseIf tot_renouv > 1 Then
                Pharmacie_SuiviTraitement_Button.Text = _
               "Suivi patient" & vbCrLf & vbCrLf & tot_renouv.ToString & " renouvellements"
            End If
            If tot_commande = 1 Then
                Pharmacie_SuiviTraitement_Button.Text = Pharmacie_SuiviTraitement_Button.Text & vbCrLf & vbCrLf & "1 produit à commander"
            ElseIf tot_commande > 1 Then
                Pharmacie_SuiviTraitement_Button.Text = Pharmacie_SuiviTraitement_Button.Text & vbCrLf & vbCrLf & tot_commande.ToString & " produits à commander"
            End If

        Else
            Pharmacie_SuiviTraitement_Button.Text = "Suivi patient"
            Pharmacie_SuiviTraitement_Button.ForeColor = Color.White
            Pharmacie_SuiviTraitement_Button.BackColor = Color.Gray
        End If
    End Sub






    Private Sub bouton_barre_classe_focus() Handles Comptoir_Button.GotFocus, Produits_Button.GotFocus, Commandes_Button.GotFocus, Caisse_Button.GotFocus, Pharmacie_Button.GotFocus, Données_Button.GotFocus, _
        Factures_Button.GotFocus, Teletrans_Button.GotFocus, Financier_Button.GotFocus, Outils_Button.GotFocus, Messagerie_Button.GotFocus, Configuration_Button.GotFocus, _
        Pharmacie_SuiviTraitement_Button.GotFocus, Quitter_Button.GotFocus, PDA_Button.GotFocus
        Dim decal As Integer = 0
        Dim count = 0
        For Each but As Button In but_list
            but.Size = New Size(75, 75)
            but.Location = New Point(78 * count + decal, 4)
            If but.Name <> "Pharmacie_SuiviTraitement_Button" And but.Name <> "PDA_Button" Then
                but.Text = ""
            End If

            If but.Focused Then
                but.Size = New Size(150, 150)
                decal = 80 '75
                Try
                    If but.Name <> "Pharmacie_SuiviTraitement_Button" And but.Name <> "PDA_Button" Then
                        but.Text = Mid(but.Name, 1, InStr(but.Name, "_Button") - 1)

                    End If

                Catch ex As Exception
                End Try

            End If
            round2(but)
            count = count + 1
        Next
    End Sub
    Private Sub bouton_barre_classe_moushover(sender As Button, e As EventArgs) Handles Comptoir_Button.MouseHover, Produits_Button.MouseHover, Commandes_Button.MouseHover, Caisse_Button.MouseHover, Pharmacie_Button.MouseHover, Données_Button.MouseHover, _
        Factures_Button.MouseHover, Teletrans_Button.MouseHover, Financier_Button.MouseHover, Outils_Button.MouseHover, Messagerie_Button.MouseHover, Configuration_Button.MouseHover, _
        Pharmacie_SuiviTraitement_Button.MouseHover, Quitter_Button.MouseHover, PDA_Button.MouseHover
        sender.Select()

    End Sub
    Private Sub bouton_barre_classe_add_button()
        but_list.Add(Comptoir_Button)
        but_list.Add(Produits_Button)
        but_list.Add(Commandes_Button)
        but_list.Add(Caisse_Button)
        but_list.Add(Pharmacie_Button)
        but_list.Add(Données_Button)
        but_list.Add(Factures_Button)
        but_list.Add(Teletrans_Button)
        but_list.Add(Financier_Button)
        but_list.Add(Outils_Button)
        but_list.Add(Messagerie_Button)
        but_list.Add(Configuration_Button)
        but_list.Add(Pharmacie_SuiviTraitement_Button)
        but_list.Add(PDA_Button)
        but_list.Add(Quitter_Button)
    End Sub


    Private Sub Factures_sousmenu1_button_Click(sender As Object, e As EventArgs) Handles Factures_sousmenu1_button.Click
        If Factures_sousmenu1_button.Text <> "" Then
            Factures_Main_Panel.Visible = True
            Factures_FSE_Panel.Visible = False
            Factures_VD_Panel.Visible = False
            Factures_sousmenu1_button.Text = ""

        End If
    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Gestion_Users.ShowDialog()

    End Sub

    'Private Sub Button1_MouseDown(sender As Object, e As MouseEventArgs) Handles Button1.MouseDown
    '    If e.Button = Windows.Forms.MouseButtons.Left Then
    '        Dim utilisateur As String = ""
    '        MyInptBox.my_showdialog("Nom de l'utilisateur à créer?", VarType(utilisateur), 100, "")
    '        utilisateur = MyInptBox.result
    '        If utilisateur <> "" And BDD.UsersTableAdapter.GetDataBy_login(utilisateur).Rows.Count = 0 Then
    '            BDD.UsersTableAdapter.Insert(utilisateur, "", "", False)
    '        End If
    '    ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
    '        Dim utilisateur As String = ""
    '        MyInptBox.my_showdialog("Nom de l'utilisateur à supprimer?", VarType(utilisateur), 100, "")
    '        utilisateur = MyInptBox.result
    '        If utilisateur <> "" And BDD.UsersTableAdapter.GetDataBy_login(utilisateur).Rows.Count <> 0 Then
    '            BDD.UsersTableAdapter.Delete_By_Login(utilisateur)
    '        End If
    '    End If
    'End Sub

    Private Sub Teletrans_interface_Click(sender As Object, e As EventArgs) Handles Teletrans_interface.Click
        'If UCase(Config.Logiciel_ModeFonctionement) = "TEST" Then Exit Sub
        Teletransmission_MAIN.Visible = True
        Teletransmission_MAIN.BringToFront()
    End Sub

    Private Sub Teletrans_tout_Click(sender As Object, e As EventArgs) Handles Teletrans_tout.Click
        If UCase(Config.Logiciel_ModeFonctionement) = "TEST" Then Exit Sub
        Teletransmission_MAIN.Visible = True
        Teletransmission_MAIN.BringToFront()
        Teletransmission_MAIN.ConstitutionLots()
        Teletransmission_MAIN.Transmettre_Lots_FSE()
        Teletransmission_MAIN.Close()
        Quitter_Button_Click(Nothing, Nothing)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Ordonnancier_Liste1_2_manuel.ShowDialog()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Ordonnancier_Stup_manuel.ShowDialog()
    End Sub


    Private Sub PDA_Button_Click(sender As Object, e As EventArgs) Handles PDA_Button.Click
        Dim my_USERS_Select As New USERS_Select
        my_USERS_Select.Location = New Point(PDA_Button.Location.X + MENU_PRINCIPAL_Panel.Location.X + PDA_Button.Width, PDA_Button.Location.Y + MENU_PRINCIPAL_Panel.Location.Y)
        my_USERS_Select.ShowDialog()
        If password_validated = True Then
            Me.WindowState = FormWindowState.Minimized
            If PDA_Main.Visible = False Then
                PDA_Main.Visible = True
                PDA_Main.WindowState = FormWindowState.Maximized
                PDA_Main.Select()
            Else
                PDA_Main.WindowState = FormWindowState.Maximized
                PDA_Main.Select()

            End If
        End If

        'Recorder.Visible = True
    End Sub





    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fProduits%2fProduits_dus&rs:Command=Render")
    End Sub

    Private Sub Chronique_Périodes_Update_Date()
        Dim périodes = BDD.Chronique_PériodeTableAdapter.GetData

        For r = 0 To périodes.Rows.Count - 1

            If périodes(r).Id > 0 Then
                If périodes(r).Date_prochaine_commande < Now Then
                    BDD.Chronique_PériodeTableAdapter.Update_date(périodes(r).Date_prochaine_commande, DateAdd(DateInterval.Day, périodes(r).interval_command_jours, périodes(r).Date_prochaine_commande), périodes(r).Id)
                End If

            End If
        Next
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fProduits%2fProduits_Reserves&rs:Command=Render")
    End Sub

    Private Sub Factures_Organismes_Button_Click(sender As Object, e As EventArgs) Handles Factures_Organismes_Button.Click
        Web_browser.Visible = True
        Web_browser.BringToFront()
        Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fFactures%2fFacture+organismes&rs:Command=Render")
    End Sub


    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        impression_Comptoir_Config.Visible = True
    End Sub



    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        Mes_Couleurs.Visible = True

    End Sub

    Private Sub some_debug()


        ''init tables
        'If BDD.ActesTableAdapter.GetDataBy_NumActe(0).Rows.Count = 0 Then
        '    BDD.ActesTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, False, Nothing)
        'End If
        'If Teletransmission_MAIN.AR_PTableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    Teletransmission_MAIN.AR_PTableAdapter.Insert(0, "init", "init", "init", "init")
        'End If
        'Try
        '    Teletransmission_MAIN.ARLTableAdapter.SelectMaxFichierPieceJointe()
        'Catch ex As Exception
        '    Teletransmission_MAIN.ARLTableAdapter.Insert(Nothing, Nothing, Nothing, Nothing, 0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        'End Try

        'If BDD.Avances_ProduitTableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    BDD.Avances_ProduitTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        'End If
        'If BDD.CaisseTableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    BDD.CaisseTableAdapter.Insert(0, Now, "HAL 9000", 0, "i'm sorry dave i'm afraid i can't do that", 0)
        'End If
        'If COMPTOIR_MAIN.CDC_Table7TableAdapter.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT TABLE 7", MsgBoxStyle.Critical)
        'End If
        'If BDD.Chronique_PériodeTableAdapter.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT PERIODE", MsgBoxStyle.Critical)
        'End If
        'If COMPTOIR_MAIN.CodePrestationsTableAdapter.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT Codes Prestation", MsgBoxStyle.Critical)
        'End If
        If BDD.CommandesTableAdapter.GetDataBy_ref(0).Rows.Count = 0 Then
            BDD.CommandesTableAdapter.Insert(0, "", "", "", "", "", "", "")
        End If
        'If COMPTOIR_MAIN.Compatibilités__codes_prestation__qualité_bénéficiaireTableAdapter1.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT Compatibilités__codes_prestation__qualité_bénéficiaire", MsgBoxStyle.Critical)
        'End If
        'If COMPTOIR_MAIN.Compatibilités_codes_prestation_nature_assuranceTableAdapter1.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT Compatibilités__codes_prestation__nature_assurance", MsgBoxStyle.Critical)
        'End If
        'If BDD.EncaissementsTableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    BDD.EncaissementsTableAdapter.Insert(0, "", 0, 0, 0, Now, Now, "", "", 0, False, 0, "", False, 0)
        'End If
        'If COMPTOIR_MAIN.Facture_VenteDirecteTableAdapter1.GetDataBy_Num(0).Rows.Count = 0 Then
        '    COMPTOIR_MAIN.Facture_VenteDirecteTableAdapter1.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing)
        'End If
        'If COMPTOIR_MAIN.FacturesTableAdapter.GetFactureDataByNum1(0).Rows.Count = 0 Then
        '    COMPTOIR_MAIN.FacturesTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        '                                              Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        '                                              Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        '                                            Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        '                                              Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        '                                              Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
        '                                              Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

        'End If
        'If Teletransmission_MAIN.FichiersSVTableAdapter1.GetData.Rows.Count = 0 Then
        '    Teletransmission_MAIN.FichiersSVTableAdapter1.Insert(0, "init", "init", 0, 0, 0)
        'End If
        'If Teletransmission_MAIN.LotsTableAdapter.GetDataByRéférence(0, "").Rows.Count = 0 Then
        '    Teletransmission_MAIN.LotsTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, 0, Nothing, Nothing)
        '    Teletransmission_MAIN.LotsTableAdapter.Insert(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, "AA@", "@AA@", Nothing, Nothing, Nothing)
        'End If
        'If BDD.Messagerie_interneTableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    BDD.Messagerie_interneTableAdapter.Insert(0, "", Now, "", Now, "", Now, "", "", "", "", "", 0, Now, "", False)
        'End If
        'If BDD.OrdoTableAdapter.GetDataBy_Id_Ordo(0).Rows.Count = 0 Then
        '    BDD.OrdoTableAdapter.Insert(0, Now, Now, "", "", "", "", "", "", "", "", "", 0, 0, Now, "")
        'End If
        'If Ordonnancier.Ordonnancier_ListeI_ListeIITableAdapter1.GetData.Rows.Count = 0 Then
        '    Ordonnancier.Ordonnancier_ListeI_ListeIITableAdapter1.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        'End If
        'If Ordonnancier.Ordonnancier_StupéfiantsTableAdapter1.GetData.Rows.Count = 0 Then
        '    Ordonnancier.Ordonnancier_StupéfiantsTableAdapter1.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        'End If
        'If BDD.PDATableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    BDD.PDATableAdapter.Insert(0, Now, "", Now, Now)
        'End If
        'Try
        '    Teletransmission_MAIN.RSP_LIGNE_REJETTableAdapter.Select_Max_num()
        'Catch ex As Exception
        '    Teletransmission_MAIN.RSP_LIGNE_REJETTableAdapter.Insert(0, "", "", "", "", "", "", "", "", "", "", "", "", True, "", "")
        'End Try
        'Try
        '    Teletransmission_MAIN.Service_RejetTableAdapter.SelectMaxNum()
        'Catch ex As Exception
        '    Teletransmission_MAIN.Service_RejetTableAdapter.Insert("0", "init", "init", "init", "", "", 0)
        'End Try
        'Try
        '    Teletransmission_MAIN.SmtpTableAdapter1.SelectMaxCompteur()
        'Catch ex As Exception
        '    Teletransmission_MAIN.SmtpTableAdapter1.Insert(0, "0", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        'End Try
        'If COMPTOIR_MAIN.Taux_CodeRégimeTableAdapter.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT Taux_CodeRégime", MsgBoxStyle.Critical)
        'End If
        'If COMPTOIR_MAIN.Taux_CodeSituationTableAdapter.GetData.Rows.Count = 0 Then
        '    MsgBox("INIT Taux_CodeSituation", MsgBoxStyle.Critical)
        'End If
        'If COMPTOIR_MAIN.VitaleTableAdapter.GetDataBy_Num(0).Rows.Count = 0 Then
        '    COMPTOIR_MAIN.VitaleTableAdapter.Insert("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 0, 0, "", 0, "", "")
        'End If
        '
        BDD.ProduitsTableAdapter.Debug_Répartiteur_principal()
        BDD.ProduitsTableAdapter.Debug_Répartiteur_secondaire()
        BDD.ProduitsTableAdapter.Debug_Datedernierevente()
        BDD.DusTableAdapter.Debug_Prod_NullValue()
        Rename_Chroniques()
        BDD.BDM_TFRTableAdapter.Delete_by_CIP("")
        BDD.ChroniqueTableAdapter.Debug_ALD()
        BDD.ChroniqueTableAdapter.Debug_G1740C7()
        BDD.OrdoTableAdapter.Debug_Type()

        '______________________________________________________________________________________________
        'Suppression des fichiers de facture fantôme
        If Not My.Computer.FileSystem.DirectoryExists(Config.LocalNetwork_ServerName & "\factures\erreur") Then
            My.Computer.FileSystem.CreateDirectory(Config.LocalNetwork_ServerName & "\factures\erreur")
        End If
        Dim file As String = Dir(Config.LocalNetwork_ServerName & "\factures\*.fse")
        Do Until file = ""
            Dim numfact = Mid(file, InStr(file, "@") + 1)
            numfact = Mid(numfact, 1, InStr(numfact, "@") - 1)
            Try
                Dim toto = BDD.FacturesTableAdapter.GetFactureDataByNum1(Val(numfact)).Item(0).G1130C1
            Catch ex As Exception
                My.Computer.FileSystem.MoveFile(Config.LocalNetwork_ServerName & "\factures\" & file, Config.LocalNetwork_ServerName & "\factures\erreur\" & file, True)
            End Try
            file = Dir()
        Loop
        '______________________________________________________________________________________________
        Try
            BDD.ProduitsTableAdapter.Debug_PrixBoironDose()
            BDD.ProduitsTableAdapter.Debug_PrixBoironGranule()
        Catch ex As Exception

        End Try

        insert_Vaccination_Grippe_Pharmacien()
    End Sub
    Private Sub insert_Vaccination_Grippe_Pharmacien()
        Try
            If COMPTOIR_MAIN.CodePrestationsTableAdapter.GetDataBy_CodeActe("VGP").Rows.Count = 0 Then
                COMPTOIR_MAIN.CodePrestationsTableAdapter.Insert("VGP", "Vaccination Grippe Pharmacien", "NGAP", True, True, False)
            End If
            If COMPTOIR_MAIN.Taux_CodeRégimeTableAdapter.Taux("**", "VGP", 19741205) Is Nothing Then
                COMPTOIR_MAIN.Taux_CodeRégimeTableAdapter.Insert("**", "VGP", 70, "99999999", "19741205")
            End If
            If COMPTOIR_MAIN.Taux_CodeRégimeTableAdapter.Taux("10", "VGP", 19741205) Is Nothing Then
                COMPTOIR_MAIN.Taux_CodeRégimeTableAdapter.Insert("10", "VGP", 70, "99999999", "19741205")
            End If
            If BDD.ProduitsTableAdapter.GetDataBY_Cipean13_Or_Cab_Or_Designation("", "", "Vaccination Grippe Pharmacien").Rows.Count = 0 Then
                BDD.ProduitsTableAdapter.Insert("", "", "", "Vaccination Grippe Pharmacien", "6,30", "0", 0, "", "", "", "", "", "", "VGP", "6,30", "2", 0, "", 100, False, 0, "", "VGP", "", 0, False, "", False, "", Now, False, Now, False, "", 0, False, "", False, False, 0, 0, "", "", False, True, False, "", "", 0, True, False, False, Now)
            End If
            If COMPTOIR_MAIN.Compatibilités__codes_prestation__qualité_bénéficiaireTableAdapter1.GetDataBy_Code_Prestation("VGP").Rows.Count = 0 Then
                COMPTOIR_MAIN.Compatibilités__codes_prestation__qualité_bénéficiaireTableAdapter1.Insert("VGP", True, True, True, True, True, True, True, True, 0, 18, 0, 0, True)
            End If
            If COMPTOIR_MAIN.Compatibilités_codes_prestation_nature_assuranceTableAdapter1.GetDataBy_CodePrestation("VGP").Rows.Count = 0 Then
                COMPTOIR_MAIN.Compatibilités_codes_prestation_nature_assuranceTableAdapter1.Insert("VGP", 1, 1, 0, 0)
            End If
            If COMPTOIR_MAIN.CDC_Table7TableAdapter.GetDataBy_Code_Prestation("VGP").Rows.Count = 0 Then
                COMPTOIR_MAIN.CDC_Table7TableAdapter.Insert("VGP", True, False, False, False, True, False, False, False, False, True)
            End If
        Catch ex As Exception

        End Try
    End Sub
 
    Private Sub Rename_Chroniques()
        Dim datas = BDD.ChroniqueTableAdapter.GetData_Designation_Not_In_Produits
        For r = 0 To datas.Rows.Count - 1
            Dim prod As New PharmaDataSet.ProduitsDataTable
            If datas(r).Produit_EAN13 <> "" Then
                prod = BDD.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(datas(r).Produit_EAN13)
            ElseIf datas(r).Produit_CAB <> "" Then
                prod = BDD.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(datas(r).Produit_CAB)
            ElseIf datas(r).Produit_CIP <> "" Then
                prod = BDD.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(datas(r).Produit_CIP)
            End If
            If prod.Rows.Count = 1 Then
                BDD.ChroniqueTableAdapter.Update_Product_Infos(prod.Item(0).Designation, prod.Item(0).CIP, prod.Item(0).EAN13, prod.Item(0).CAB, datas(r).Produit_Désignation, datas(r).Produit_CIP, datas(r).Produit_EAN13, datas(r).Produit_CAB)

            End If

        Next
    End Sub


    Private Sub Button11_Click(sender As Object, e As EventArgs)
        Auto_Réassort_Liste.Visible = True
    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        Variation_Stock.Visible = True
    End Sub

    Private Sub Panel_MouseEnter(sender As Object, e As EventArgs) Handles Produits_Panel.MouseEnter, _
        Commandes_Panel.MouseEnter, Pharmacie_Panel.MouseEnter, Données_Panel.MouseEnter, Factures_Panel.MouseEnter, Teletrans_Panel.MouseEnter, _
        Financier_Panel.MouseEnter, Outils_Panel.MouseEnter, Configuration_Panel.MouseEnter
        If IsControlAtFront(Produits_Panel) Then
            bouton_barre_classe_moushover(Produits_Button, Nothing)
        ElseIf IsControlAtFront(Commandes_Panel) Then
            bouton_barre_classe_moushover(Commandes_Button, Nothing)
        ElseIf IsControlAtFront(Pharmacie_Panel) Then
            bouton_barre_classe_moushover(Pharmacie_Button, Nothing)
        ElseIf IsControlAtFront(Données_Panel) Then
            bouton_barre_classe_moushover(Données_Button, Nothing)
        ElseIf IsControlAtFront(Factures_Panel) Then
            bouton_barre_classe_moushover(Factures_Button, Nothing)
        ElseIf IsControlAtFront(Teletrans_Panel) Then
            bouton_barre_classe_moushover(Teletrans_Button, Nothing)
        ElseIf IsControlAtFront(Financier_Panel) Then
            bouton_barre_classe_moushover(Financier_Button, Nothing)
        ElseIf IsControlAtFront(Outils_Panel) Then
            bouton_barre_classe_moushover(Outils_Button, Nothing)
        ElseIf IsControlAtFront(Configuration_Panel) Then
            bouton_barre_classe_moushover(Configuration_Button, Nothing)
        ElseIf IsControlAtFront(Hide_Panel) Then
            bouton_barre_classe_moushover(Comptoir_Button, Nothing)
        End If
    End Sub

    Private Function IsControlAtFront(control As Control) As Boolean
        Return control.Parent.Controls.GetChildIndex(control) = 0
    End Function


    Private Sub Factures_Main_Locations_Button_Click(sender As Object, e As EventArgs) Handles Factures_Main_Locations_Button.Click


        'Dim data = BDD.Produits_ReservésTableAdapter.GetData_Facturation_Auto(Tri_Produit, Tri_Patient, Organisme, Tri_Patient_période)
        Facture_Auto.list_Produits_Reservés = New List(Of PharmaDataSet.Produits_ReservésRow)


        Dim data As New officine.PharmaDataSet.Produits_ReservésDataTable
        Dim chroniques = BDD.ChroniqueTableAdapter.GetDataBy_DateRenouv_TypeOrdo(Now, "LOCATION")

        For r = 0 To chroniques.Rows.Count - 1
            Dim row As DataRow
            row = data.NewRow
            row("Produit_Désignation") = chroniques.Item(r).Produit_Désignation
            row("Produit_CIP") = chroniques.Item(r).Produit_CIP
            row("Produit_EAN13") = chroniques.Item(r).Produit_EAN13
            row("Produit_CAB") = chroniques.Item(r).Produit_CAB
            row("Quantité_Reservée") = chroniques.Item(r).Commande_Quantité
            row("Date_reservation") = Now
            row("Date_delivrance_prévue") = chroniques.Item(r).Date_Renouvellement
            row("Date_delivrance") = chroniques.Item(r).Date_Renouvellement
            row("Vitale_Num") = chroniques.Item(r).Vitale_Num
            row("ALD") = False

            Facture_Auto.list_Produits_Reservés.Add(row)


        Next
        Facture_Auto.Ordo_Type = "LOCATION"
        Facture_Auto.Visible = True



    End Sub

    Private Sub OfficineUpdate()



        Try
            If Config.is_local_client = False Then
                Exit Sub
            End If

            Dim date_ser = RetrieveLinkerTimestamp(Config.LocalNetwork_ServerName & "\Officine\Officine.exe")
            Dim date_cli = RetrieveLinkerTimestamp(Application.StartupPath & "\Officine.exe")

            If date_ser <> date_cli Then
                MsgBox("Nouvelle version du logiciel détéctée." & vbCrLf & vbCrLf & "L'application va s'arreter et ëtre mise à jour.", MsgBoxStyle.OkOnly, "Update " & date_ser.ToString)
                If My.Computer.FileSystem.FileExists(Application.StartupPath & "\update.bat") Then
                    My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\update.bat")
                End If
                My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\update.bat", vbCrLf & "ping 127.0.0.1 -n 10" & vbCrLf & _
                                                    "Copy " & Config.LocalNetwork_ServerName & "\Officine\Officine.exe " & Application.StartupPath & "\Officine.exe /y" & vbCrLf & _
                                                    "ping 127.0.0.1 -n 3" & vbCrLf, True)
                Process.Start(Application.StartupPath & "\update.bat")
                Environment.Exit(0)
            End If
        Catch ex As Exception
            MsgBox("OfficineUpdate()" & vbCrLf & ex.ToString)
        End Try


    End Sub

    Function RetrieveLinkerTimestamp(ByVal filePath As String) As DateTime
        Const PeHeaderOffset As Integer = 60
        Const LinkerTimestampOffset As Integer = 8
        Dim b(2047) As Byte
        Dim s As Stream
        Try
            s = New FileStream(filePath, FileMode.Open, FileAccess.Read)
            s.Read(b, 0, 2048)
        Finally
            If Not s Is Nothing Then s.Close()
        End Try
        Dim i As Integer = BitConverter.ToInt32(b, PeHeaderOffset)
        Dim SecondsSince1970 As Integer = BitConverter.ToInt32(b, i + LinkerTimestampOffset)
        Dim dt As New DateTime(1970, 1, 1, 0, 0, 0)
        dt = dt.AddSeconds(SecondsSince1970)
        dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours)
        Return dt

    End Function


End Class