' 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.Drawing
Imports System.Drawing.Printing
Imports System.Xml
Imports System.IO
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing.Layout

Public Class VenteForm

    Public Total_des_Montants_Facturés As Double
    Public Total_FSE As Double

    Public drawString As String
    Private X As Integer
    Private Y As Integer
    Private LigneCERFA As Integer
    Private PrintFont As String
    Private SizeFont As Integer
    Private PrintColor As Color
    Private total_restant_assuré As Single
    Private reste_à_payer As Single
    Public is_opened_for_print_only As Boolean
    Public SCOR_Documents_Externes_list As List(Of String)
    Public Structure du
        Dim cip7 As String
        Dim cip13 As String
        Dim désignation As String
        Dim Quantité_Du As Integer
        Dim Note As String

    End Structure
    Public liste_du As List(Of du)
    Private Dus_drawString As String

    Private reste_à_payer_plus_crédits_plus_encaissements_en_attente As Decimal

    Public Reprise_dif_à_encaisser As Decimal

    Public Encaissement_partiel_montant_crédit As Decimal
    Public Encaissement_partiel_montant_remise As Decimal

    Private nombre_produits As Integer

    Public Sub afficheinfovente()

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If
        RichTextBox1.Clear()
        If CurrentFactureVitale.num > 0 Then
            RichTextBox1.AppendText("FACTURE VITALE:")
            RichTextBox1.AppendText(Chr(10) + "Montant facturé:  " + (Total_des_Montants_Facturés / 100).ToString)
            RichTextBox1.AppendText(Chr(10) + "Montant FSE:  " + (Total_FSE / 100).ToString)
            RichTextBox1.AppendText(Chr(10) + "Total remboursable par l’AMO:  " + (CurrentFactureVitale.G1910C3 / 100).ToString)
            RichTextBox1.AppendText(Chr(10) + "Total participation assuré:  " + (CurrentFactureVitale.G1910C4 / 100).ToString)
            RichTextBox1.AppendText(Chr(10) + "Total théorique remboursable par l'AMC:  " + (CurrentFactureVitale.G1910C5 / 100).ToString)
            RichTextBox1.AppendText(Chr(10) + "Total remboursable par l’AMC:  " + (CurrentFactureVitale.G1910C6 / 100).ToString)
            RichTextBox1.AppendText(Chr(10))
            If CurrentFactureVitale.TP_AMO = False And CurrentFactureVitale.TP_AMC = False Then
                total_restant_assuré = CurrentFactureVitale.G1910C2
                RichTextBox1.AppendText(Chr(10) + "Pas de tiers-payant: reste " + (total_restant_assuré / 100).ToString)
                reste_à_payer = (Total_des_Montants_Facturés + (CurrentFactureVenteDirecte.Total * 100)) / 100
            ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = False Then
                total_restant_assuré = CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3
                RichTextBox1.AppendText(Chr(10) + "Tiers-payant sur la part obligatoire seulement: reste " + (total_restant_assuré / 100).ToString)
                'reste_à_payer = ((CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3) + (CurrentFactureVenteDirecte.Total * 100)) / 100
                reste_à_payer = ((Total_des_Montants_Facturés - CurrentFactureVitale.G1910C3) + (CurrentFactureVenteDirecte.Total * 100)) / 100
            ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = True Then
                total_restant_assuré = CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3 - CurrentFactureVitale.G1910C6
                RichTextBox1.AppendText(Chr(10) + "Tiers-payant: reste " + (total_restant_assuré / 100).ToString)
                'reste_à_payer = ((CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3 - CurrentFactureVitale.G1910C6) + (CurrentFactureVenteDirecte.Total * 100)) / 100
                reste_à_payer = ((Total_des_Montants_Facturés - CurrentFactureVitale.G1910C3 - CurrentFactureVitale.G1910C6) + (CurrentFactureVenteDirecte.Total * 100)) / 100
            ElseIf CurrentFactureVitale.TP_AMO = False And CurrentFactureVitale.TP_AMC = True Then
                total_restant_assuré = CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3 - CurrentFactureVitale.G1910C6
                RichTextBox1.AppendText(Chr(10) + "Tiers-payant sur la part complémentaire seulement: reste " + (total_restant_assuré / 100).ToString)
                'reste_à_payer = ((CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C6) + (CurrentFactureVenteDirecte.Total * 100)) / 100
                reste_à_payer = ((Total_des_Montants_Facturés - CurrentFactureVitale.G1910C6) + (CurrentFactureVenteDirecte.Total * 100)) / 100
            End If
            RichTextBox1.AppendText(Chr(10) + "_________________________________________________" + Chr(10))
        Else
            reste_à_payer = (Total_des_Montants_Facturés + (CurrentFactureVenteDirecte.Total * 100)) / 100
        End If

        If CurrentFactureVenteDirecte.NumVenteDirecte > 0 Then
            RichTextBox1.AppendText("VENTE DIRECTE:")
            RichTextBox1.AppendText(Chr(10) + "Total des montants facturés:  " + CurrentFactureVenteDirecte.Total.ToString)
            RichTextBox1.AppendText(Chr(10) + "_________________________________________________" + Chr(10))
        End If


        Dim total_crédits As Decimal = 0
        If Crédits_CheckedListBox1.Items.Count > 0 Then
            For idx As Integer = 0 To Crédits_CheckedListBox1.Items.Count - 1
                If Crédits_CheckedListBox1.GetItemChecked(idx) = True Then
                    Dim value_strg = Mid(Crédits_CheckedListBox1.Items.Item(idx).ToString, InStrRev(Crédits_CheckedListBox1.Items.Item(idx).ToString, " ") + 1)
                    value_strg = Replace(value_strg, "€", "")
                    total_crédits = total_crédits + Convert.ToDecimal(value_strg)
                End If
            Next

            RichTextBox1.AppendText("crédits en cours: " & total_crédits.ToString & "€" + Chr(10))

        End If

        Dim total_encaissements_en_attente As Decimal = 0
        If Not Ventes_enchainées_encaissement_en_attente Is Nothing Then
            For Each en_attente As Vente_enchainée_encaissement_en_attente In Ventes_enchainées_encaissement_en_attente
                total_encaissements_en_attente = total_encaissements_en_attente + en_attente.montant_à_encaisser
            Next
        End If
        If total_encaissements_en_attente <> 0 Then
            RichTextBox1.AppendText("encaissements en attente: " & total_encaissements_en_attente.ToString & "€" + Chr(10))
        End If
        reste_à_payer_plus_crédits_plus_encaissements_en_attente = reste_à_payer + total_crédits + total_encaissements_en_attente - Encaissement_partiel_montant_crédit - Encaissement_partiel_montant_remise
        RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", 30)
        Dim reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg = reste_à_payer_plus_crédits_plus_encaissements_en_attente.ToString
        If InStr(reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg, ",") = 0 Then
            reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg = reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg & ",00 €"
        ElseIf InStr(reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg, ",") = reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg.Length - 1 Then
            reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg = reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg & "0 €"
        Else
            reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg = reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg & " €"
        End If
        RichTextBox1.AppendText("A PAYER: " & reste_à_payer_plus_crédits_plus_encaissements_en_attente_strg)
        If Encaissement_partiel_montant_crédit <> 0 Then
            RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", 10)
            RichTextBox1.AppendText(Chr(10) + "(Crédit partiel: " & Encaissement_partiel_montant_crédit.ToString & " )")
        End If
        If Encaissement_partiel_montant_remise <> 0 Then
            RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", 10)
            RichTextBox1.AppendText(Chr(10) + "(Remise: " & Encaissement_partiel_montant_remise.ToString & " )")
        End If
        'reste_à_payer = reste_à_payer + total_crédits
        'RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", 30)
        'Dim reste_à_payer_strg = reste_à_payer.ToString
        'If InStr(reste_à_payer_strg, ",") = 0 Then
        '    reste_à_payer_strg = reste_à_payer_strg & ",00 €"
        'ElseIf InStr(reste_à_payer_strg, ",") = reste_à_payer_strg.Length - 1 Then
        '    reste_à_payer_strg = reste_à_payer_strg & "0 €"
        'Else
        '    reste_à_payer_strg = reste_à_payer_strg & " €"
        'End If
        'RichTextBox1.AppendText(Chr(10) + "A PAYER:" & reste_à_payer_strg)
        RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", (15.75))
        RichTextBox1.AppendText(Chr(10) + "___________________________________________________________" + Chr(10))
        RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", 12)
        If Val(CurrentFactureVitale.num).ToString <> "0" Then
            RichTextBox1.AppendText("Facture SV " + Val(CurrentFactureVitale.num).ToString + Chr(10))
        End If
        RichTextBox1.SelectionFont = New System.Drawing.Font("Century Gothic", 12)
        If Val(CurrentFactureVenteDirecte.NumVenteDirecte).ToString <> "0" Then
            RichTextBox1.AppendText("Facture Vente Directe " + Val(CurrentFactureVenteDirecte.NumVenteDirecte).ToString + Chr(10))
        End If

    End Sub
    Public Sub affiche_nombres_boites()
        Try



            nombre_produits = 0
            Dim nombre_produits_dus = 0
            For r = 0 To COMPTOIR_MAIN.Vente.Rows.Count - 1
                If InStr(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, r).Value, "Honoraire de Dispensation ") <> 1 Then
                    nombre_produits = nombre_produits + Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, r).Value)
                End If
            Next
            If Not liste_du Is Nothing Then
                For Each du_ As du In liste_du
                    nombre_produits = nombre_produits - du_.Quantité_Du
                    nombre_produits_dus = nombre_produits_dus + du_.Quantité_Du
                Next
            End If
            If nombre_produits < 0 Then nombre_produits = 0

            If nombre_produits < 2 Then
                Recap_Label.Text = nombre_produits.ToString & " produit au comptoir"
            Else
                Recap_Label.Text = nombre_produits.ToString & " produits au comptoir"
            End If
            If nombre_produits_dus < 2 Then
                Recap_Label.Text = Recap_Label.Text & vbCrLf & nombre_produits_dus.ToString & " produit dû"
            Else
                Recap_Label.Text = Recap_Label.Text & vbCrLf & nombre_produits_dus.ToString & " produits dûs"
            End If



        Catch ex As Exception

        End Try
    End Sub




    Private Sub VenteForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If


        If e.CloseReason = CloseReason.UserClosing Then
            e.Cancel = True
        End If

    End Sub


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


        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        If Config.cerfa_debile Then
            Transmettre_CERFA.Visible = True
        End If
        If COMPTOIR_MAIN.Encaissement_Note Is Nothing Then
            COMPTOIR_MAIN.Encaissement_Note = ""
        End If
        Encaissement_Note_RichTextBox.Text = COMPTOIR_MAIN.Encaissement_Note

        If Val(CurrentFactureVitale.num) = 0 Then
            TKVT_LinkLabel.Visible = False
            ScanOrdo_Button.Visible = False
            SCOR_show_scanner_interface_CheckBox.Visible = False
            'Feuille_de_soins_LinkLabel.Visible = False
            SCOR_Documents_externes_LinkLabel.Visible = False
            Fact_ventedirecte_Label.Visible = True
        Else
            SCOR_show_scanner_interface_CheckBox.Checked = SCOR_show_scanner_interface
        End If

        Me.Location = New Point(0, 0)
        Me.Width = Screen.PrimaryScreen.Bounds.Width
        Me.Height = Screen.PrimaryScreen.Bounds.Height
        'RectangleShape1.Width = Screen.PrimaryScreen.Bounds.Width - 6 '1274
        'RectangleShape1.Height = Screen.PrimaryScreen.Bounds.Height - 6 '1018
        If Not CurrentBenéficiaire.Crédits_en_Cours Is Nothing And COMPTOIR_MAIN.Reprise_Facture_Num = 0 Then
            For r = 0 To CurrentBenéficiaire.Crédits_en_Cours.Count - 1
                Crédits_CheckedListBox1.Items.Add(CurrentBenéficiaire.Crédits_en_Cours.Item(r).Num & ": " & CurrentBenéficiaire.Crédits_en_Cours.Item(r)._Date.ToShortDateString & " " & CurrentBenéficiaire.Crédits_en_Cours.Item(r)._Date.ToShortTimeString & "  " & CurrentBenéficiaire.Crédits_en_Cours.Item(r).Valeur.ToString & "€", True)
            Next
            If Not Ventes_enchainées_Crédits_en_attente Is Nothing Then
                For Each Num_Crédit As Decimal In Ventes_enchainées_Crédits_en_attente
                    Dim déja_affiché As Boolean = False
                    For r = 0 To CurrentBenéficiaire.Crédits_en_Cours.Count - 1
                        If CurrentBenéficiaire.Crédits_en_Cours.Item(r).Num = Num_Crédit Then
                            déja_affiché = True
                        End If
                    Next
                    For i = 0 To Crédits_CheckedListBox1.Items.Count - 1
                        If CDec(Mid(Crédits_CheckedListBox1.Items.Item(i).ToString, 1, InStr(Crédits_CheckedListBox1.Items.Item(i).ToString, ":") - 1)) = Num_Crédit Then
                            déja_affiché = True
                        End If
                    Next
                    If déja_affiché = False Then
                        Dim crédit_row = EncaissementsTableAdapter.GetDataBy_Num(Num_Crédit).Item(0)
                        Crédits_CheckedListBox1.Items.Add(crédit_row.Num & ": " & crédit_row._Date.ToShortDateString & " " & crédit_row._Date.ToShortTimeString & "  " & crédit_row.Valeur.ToString & "€", True)
                    End If
                Next
            End If
        End If

        afficheinfovente()
        If is_opened_for_print_only = False Then
            If Not facilEpharm.Ordo_row Is Nothing Then
                Dim fichiers = facilEpharm.Ordo_FichiersTableAdapter.GetDataBy_Id_Ordo(facilEpharm.Ordo_row.Id_Ordo)
                Dim compteur As Integer = 1
                For r = 0 To fichiers.Rows.Count - 1
                    My.Computer.FileSystem.CopyFile(Config.facilEpharm_Rep_Doc & "\" & fichiers(r).Fichier, Config.LocalNetwork_ServerName & "\scor\doc\PreScan" & Config.Idposte + CurrentFactureVitale.G1110C1 + "_" + compteur.ToString + ".pdf", True)
                    ListBox_scanordo.Items.Add(CurrentFactureVitale.G1110C1 + "_" + compteur.ToString + ".pdf")
                    compteur = compteur + 1
                Next
                Encaissement_Note_RichTextBox.Text = "Prescr:" & facilEpharm.Ordo_row.Notes_Prescripteur & vbCrLf & "Phar:" & facilEpharm.Ordo_row.Notes_Pharma
            End If

            ScanOrdo.Rename_PreScaned_Docs()
            If Not COMPTOIR_MAIN.liste_du Is Nothing Then
                If COMPTOIR_MAIN.liste_du.Count > 0 Then
                    If liste_du Is Nothing Then
                        liste_du = New List(Of du)
                    End If
                    For Each du_ As du In COMPTOIR_MAIN.liste_du
                        liste_du.Add(du_)
                        Produits_Dus_ListBox.Items.Add(du_.Quantité_Du.ToString & "  " & du_.désignation)
                    Next
                End If
            End If
        End If
        If COMPTOIR_MAIN.Reprise_Facture_Num <> 0 Or is_opened_for_print_only = True Then
            Button_Vente_enchainée.Enabled = False
            Paiement_Type_Button.Enabled = False
            Crédits_CheckedListBox1.Enabled = False
            Paiement_Type_Button.Text = "Reprise"
            If is_opened_for_print_only Then
                Paiement_Type_Button.Text = "Impressions"
                Paiement_Type_Button.Enabled = False
            End If
            'TT02.01 Préparer le fichier d'index ScanOrdo
            If CurrentFactureVitale.G1110C1 <> "" And is_opened_for_print_only = False Then
                If My.Computer.FileSystem.FileExists(Config.LocalNetwork_ServerName & "\scor\index\" & CurrentFactureVitale.G1110C1 & ".xml") = False Then
                    ScanOrdo.TT02()
                End If
            End If
            '--------------------------------------------------
            'Recherche documents SCOR except TKVT
            If is_opened_for_print_only = False Then


                Dim FileName = Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & COMPTOIR_MAIN.Reprise_Facture_Num.ToString & "_*.pdf")

                Dim compteur As Integer = 0
                While FileName <> ""
                    If InStr(FileName, "TKVT") = 0 Then
                        compteur = compteur + 1
                        Dim Type_pièce = Mid(FileName, InStrRev(FileName, "_") + 1, 4)
                        Dim new_filename = CurrentFactureVitale.num.ToString & "_" & compteur.ToString & "_" & Type_pièce & ".pdf"
                        My.Computer.FileSystem.CopyFile(Config.LocalNetwork_ServerName & "\scor\doc\" & FileName, Config.LocalNetwork_ServerName & "\scor\doc\" + new_filename)
                        'save to Bdd
                        ScanOrdo.SCOR_PJTableAdapter.Insert(new_filename, ScanOrdo.ID_PJ(compteur.ToString, Type_pièce), "A FINALISER", CurrentFactureVitale.G1110C1)
                        ListBox_scanordo.Items.Add(new_filename)
                    End If
                    FileName = Dir()
                End While
            End If
        End If
        affiche_nombres_boites()

        If COMPTOIR_MAIN.FS_Papier = False Then
            If Config.STS_Activer = False And CurrentFactureVitale.TOP_CMU = False And COMPTOIR_MAIN.CheckBox_Facturation_AMC.Checked = True And Val(CurrentFactureVitale.G1110C1) > 0 Then
                Warning_STS_Label.Visible = True
            End If
        End If

        Encaissement_partiel_montant_crédit = 0
        Encaissement_partiel_montant_remise = 0

        If CurrentBenéficiaire.Organisme <> "" Then
            Paiement_Type_Button.Text = CurrentBenéficiaire.Organisme
        End If

        If Val(CurrentFactureVitale.num) <> 0 Then
            Dim impr = New impression_Comptoir_Config
            impr.Ticket_vitale_total_restant_assuré = total_restant_assuré
            'impr.load_config("Ticket_Vitale")
            drawString = impr.Ticket_Vitale_Entête_PiedPagedrawstring("Entête") & vbCrLf & impr.Ticket_Vitale_Ligne_drawstring() & vbCrLf & impr.Ticket_Vitale_Entête_PiedPagedrawstring("Pied")
            Save_TKVT_to_pdf()
        End If
        Me.BringToFront()
        Me.Activate()
        Me.Focus()

    End Sub

#Region "IMPRESSIONS"

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        Dim drawFont As New Font(PrintFont, SizeFont)
        Dim drawBrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(drawString, drawFont, drawBrush, X, Y)


    End Sub



    Public Sub impime_quittance_AMC(ByVal num_FSE As Integer, num_VD As Integer)
        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        Dim ConfigXml As New XmlDocument
        ConfigXml.Load(Application.StartupPath + "\InfoPro.xml")
        Dim nodeliste As XmlNodeList
        nodeliste = ConfigXml.GetElementsByTagName("Quittance")
        Dim EnTete As String = nodeliste.Item(0).Item("EnTete").InnerText
        Dim PiedPage As String = nodeliste.Item(0).Item("PiedPage").InnerText
        PrintFont = nodeliste.Item(0).Item("PrintFont").InnerText
        SizeFont = 10
        Try
            SizeFont = Val(nodeliste.Item(0).Item("SizeFont").InnerText)
        Catch ex As Exception

        End Try

        Dim Lignes_blanches = CInt(nodeliste.Item(0).Item("Lignes_blanches").InnerText)
        Dim default_printer = ""
        If Not nodeliste.Item(0).Item("default_printer") Is Nothing Then
            default_printer = nodeliste.Item(0).Item("default_printer").InnerText
        End If
        drawString = drawString + EnTete + Chr(10)
        If num_FSE > 0 Then
            Dim FSE = BDD.FacturesTableAdapter.GetFactureDataByNum1(num_FSE).Item(0)
            drawString = ""
            If Val(FSE.G1110C1) > 0 Then 'FACTURE VITALE
                For i = 1 To Lignes_blanches
                    drawString = drawString + Chr(10)
                Next

                drawString = drawString & "FSE N°:" & FSE.G1110C1 & "  " & Mid(FSE.G1110C3, 7, 2) & "/" & Mid(FSE.G1110C3, 5, 2) & "/" & Mid(FSE.G1110C3, 1, 4)
                drawString = drawString + Chr(10) + Chr(10)
                drawString = drawString & "caisse: " & FSE.G1310C1 & " " & FSE.G1310C2 & " " & FSE.G1310C3 & Chr(10)
                drawString = drawString & "org dest: " & FSE.G1310C4 & "   CI: " & FSE.G1310C5 & Chr(10) & Chr(10)
                drawString = drawString & "org compl: " & FSE.G1321C2 & Chr(10) & Chr(10)
                drawString = drawString & "NIR: " & FSE.G1130C2 & " " & FSE.G1130C3 & Chr(10)
                Dim benef = Me.VitaleTableAdapter1.GetDataBénéficiaire(FSE.G1130C2, FSE.G1130C4, FSE.G1130C5, FSE.G1130C6).Item(0)
                drawString = drawString & benef.G104C1 & " " & benef.G104C3 & vbCrLf & " né(e) le " & Mid(benef.G104C12, 7, 2) & "/" & Mid(benef.G104C12, 5, 2) & "/" & Mid(benef.G104C12, 1, 4) + Chr(10) + Chr(10)
                Dim prescr = Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(FSE.IDPrescripteur).Item(0)
                drawString = drawString & "Prescr: " & prescr.NomPrénom & Chr(10)
                drawString = drawString & "Num:" & prescr.Numidentification & Chr(10)
                drawString = drawString & "Num RPPS:" & prescr.NumRPPS & Chr(10)
                drawString = drawString & "num Structure:" & prescr.numStructure & Chr(10) & Chr(10)
                '____________________________________________________________________ 
                'détail
                drawString = drawString + "----------------------------------" + Chr(10) + "Qté PrixUnit|T.Remb|Prest|TxRb|Rem" + Chr(10) + "----------------------------------"
                Dim mydatatable = Me.ActesTableAdapter1.GetDataByNumFacturesSV(FSE.G1110C1)
                Dim total_facturé As Decimal = 0
                For r = 0 To mydatatable.Rows.Count - 1
                    Dim Quantité As String = ""
                    Dim Prix_Unitaire As String = ""
                    Dim Tarif_Remboursement As String = ""
                    Dim CodeActe As String = ""
                    Dim TauxRmbrsmnt As String = ""
                    Dim remise As String = ""
                    Quantité = mydatatable(r).Quantité.ToString
                    total_facturé = total_facturé + CDec(mydatatable(r).Total)
                    Prix_Unitaire = mydatatable(r).Prix_Unitaire.ToString
                    Tarif_Remboursement = Mid(mydatatable(r).Tarif_Remboursement.ToString, 1, 24)
                    CodeActe = mydatatable(r).CodeActe.ToString
                    TauxRmbrsmnt = mydatatable(r).TauxRmbrsmnt.ToString
                    If Val(mydatatable(r).Remise) <> 0 Then
                        remise = mydatatable(r).Remise & "%"
                    End If
                    'taille des string pour presentation
                    While Quantité.Length < 3
                        Quantité = Quantité + " "
                    End While
                    While Prix_Unitaire.Length < 8
                        Prix_Unitaire = Prix_Unitaire + " "
                    End While
                    While Tarif_Remboursement.Length < 6
                        Tarif_Remboursement = Tarif_Remboursement + " "
                    End While
                    While CodeActe.Length < 5
                        CodeActe = CodeActe + " "
                    End While
                    While TauxRmbrsmnt.Length < 4
                        TauxRmbrsmnt = TauxRmbrsmnt + " "
                    End While

                    drawString = drawString + Chr(10) + Quantité + " " + Prix_Unitaire + " " + Tarif_Remboursement + " " + CodeActe + " " + TauxRmbrsmnt + " " + remise
                Next
                '____________________________________________________________________



                drawString = drawString + Chr(10) + Chr(10) + "Total facturé:" + total_facturé.ToString + Chr(10)
                drawString = drawString + "Total FSE:" + (FSE.G1910C2 / 100).ToString + Chr(10)
                drawString = drawString + "Total  AMO: " + (FSE.G1910C3 / 100).ToString + Chr(10)
                'drawString = drawString + "Total participation assuré: " + (FSE.G1910C4 / 100).ToString + Chr(10)
                'drawString = drawString + "Total théorique remboursable par l’AMC: " + (FSE.G1910C5 / 100).ToString + Chr(10)
                drawString = drawString + "Total AMC: " + (FSE.G1910C6 / 100).ToString + Chr(10)

                If FSE.TP_AMO = False And FSE.TP_AMC = False Then
                    drawString = drawString + "Pas de tiers-payant" + Chr(10)
                ElseIf FSE.TP_AMO = True And FSE.TP_AMC = False Then
                    drawString = drawString + "Tiers-payant AMO seulement" + Chr(10)
                ElseIf FSE.TP_AMO = True And FSE.TP_AMC = True Then
                    drawString = drawString + "Tiers-payant" + Chr(10)
                End If
                drawString = drawString + "Payé par l'assuré: " + ((((total_facturé * 100) - FSE.G1910C3 - FSE.G1910C6) / 100).ToString) & Chr(10)
                'drawString = drawString + "Total restant assuré: " + (total_restant_assuré / 100).ToString + Chr(10)



                drawString = drawString + Chr(10) + Chr(10) + Chr(10) + PiedPage

                X = 10
                Y = 10

                PrintPreviewDialog1.Document = PrintDocument1
                PrintDialog1.Document = PrintDocument1
                If default_printer <> "" Then
                    PrintDocument1.PrinterSettings.PrinterName = default_printer
                    PrintDocument1.Print()
                ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    PrintDocument1.Print()

                    'End If
                End If
                'If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                '    PrintPreviewDialog1.ShowDialog()
                '    If PrintPreviewDialog1.DialogResult = DialogResult.OK Then
                '        PrintDocument1.Print()
                '    End If
                'End If
            End If
        End If
        If num_VD > 0 Then
            Dim VD = COMPTOIR_MAIN.Facture_VenteDirecteTableAdapter1.GetDataBy_Num(num_VD).Item(0)

            If VD.Total <> 0 Then 'FACTURE VENTE DIRECTE
                drawString = ""
                If num_FSE > 0 Then
                    MyMsg_Box.Presentation("Officine ?", "voulez-vous imprimer une facture pour les ventes directes ?", True, "OUI", True, "NON", False, "")
                    If MyMsg_Box.ShowDialog() = MsgBoxResult.No Then
                        Exit Sub
                    End If
                End If
                For i = 1 To Lignes_blanches
                    drawString = drawString + Chr(10)
                Next
                'drawString = drawString + EnTete + Chr(10) + Chr(10) + Chr(10)
                drawString = drawString & "Vente directe N°:" & VD.Num.ToString & "  " & Mid(VD.Date_, 7, 2) & "/" & Mid(VD.Date_, 5, 2) & "/" & Mid(VD.Date_, 1, 4)
                drawString = drawString + Chr(10) + Chr(10)
                '____________________________________________________________________ 
                'détail
                drawString = drawString + "--------------------------------------------------------------" + Chr(10) + "                              |Qté|PrixUnit|Rem%|Rem    |Total" + Chr(10) + "--------------------------------------------------------------"
                ' Dim mydatatable As DataTable = Me.ActesTableAdapter1.GetDataBy_NumFactureVenteDirecte(VD.NumVenteDirecte)
                Dim mydatatable As PharmaDataSet.ActesDataTable = Me.ActesTableAdapter1.GetDataBy_NumFactureVenteDirecte(VD.Num.ToString)
                For r = 0 To mydatatable.Rows.Count - 1
                    If Not COMPTOIR_MAIN.Hono_Disp_Codes_list.Contains(mydatatable(r).CodeActe) Then
                        Dim Quantité = mydatatable(r).Quantité
                        Dim Prix_Unitaire = mydatatable(r).Prix_Unitaire
                        Dim prix_non_remisé = mydatatable(r).prix_non_remisé
                        Dim total = mydatatable(r).Total

                        Dim Désignation = Mid(mydatatable(r).Désignation.ToString, 1, 30)
                        Dim remise = ""
                        If Val(mydatatable(r).Remise) <> 0 Then
                            remise = mydatatable(r).Remise & "%"
                        End If
                        While remise.Length < 4
                            remise = remise & " "
                        End While
                        If mydatatable.Rows.Count - 1 > r Then
                            If COMPTOIR_MAIN.Hono_Disp_Codes_list.Contains(mydatatable(r + 1).CodeActe) Then
                                Prix_Unitaire = Prix_Unitaire + mydatatable(r + 1).Prix_Unitaire
                                prix_non_remisé = prix_non_remisé + mydatatable(r + 1).Prix_Unitaire
                            End If
                        End If
                        Dim montant_remise_totale As Decimal = (Val(Quantité) * (prix_non_remisé - Prix_Unitaire))
                        'taille des string pour presentation
                        While Quantité.Length < 3
                            Quantité = Quantité + " "
                        End While
                        Dim prix_non_remisé_strg = prix_non_remisé.ToString
                        While prix_non_remisé_strg.Length < 8
                            prix_non_remisé_strg = prix_non_remisé_strg + " "
                        End While
                        While Désignation.Length < 30
                            Désignation = Désignation + " "
                        End While
                        Dim montant_remise_totale_strg = montant_remise_totale.ToString
                        While montant_remise_totale_strg.Length < 7
                            montant_remise_totale_strg = montant_remise_totale_strg & " "
                        End While
                        drawString = drawString + Chr(10) + Désignation + " " + Quantité + " " + prix_non_remisé_strg + " " + remise + " " + montant_remise_totale_strg + " " + total.ToString
                    End If
                Next
                '____________________________________________________________________



                drawString = drawString + Chr(10) + Chr(10) + "Total des montants facturés:" + (VD.Total.ToString + Chr(10))

                drawString = drawString + Chr(10) + Chr(10) + Chr(10) + PiedPage

                X = 10
                Y = 10

                PrintPreviewDialog1.Document = PrintDocument1
                PrintDialog1.Document = PrintDocument1
                If default_printer <> "" Then
                    PrintDocument1.PrinterSettings.PrinterName = default_printer
                    PrintDocument1.Print()
                ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    'PrintPreviewDialog1.ShowDialog()
                    'If PrintPreviewDialog1.DialogResult = DialogResult.OK Then
                    PrintDocument1.Print()

                    'End If
                End If
                If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    PrintPreviewDialog1.ShowDialog()
                    If PrintPreviewDialog1.DialogResult = DialogResult.OK Then
                        PrintDocument1.Print()
                    End If
                End If
            End If
        End If

        If Me.Visible = True Then
            Me.BringToFront()
        End If

    End Sub

    Public Sub impime_Ticket_Caisse(ByVal num_FSE As Integer, num_VD As Integer)
        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If
        Try
            drawString = ""

            Dim ConfigXml As New XmlDocument
            ConfigXml.Load(Application.StartupPath + "\InfoPro.xml")
            Dim nodeliste As XmlNodeList
            nodeliste = ConfigXml.GetElementsByTagName("Quittance")
            Dim EnTete As String = nodeliste.Item(0).Item("EnTete").InnerText
            Dim PiedPage As String = nodeliste.Item(0).Item("PiedPage").InnerText
            PrintFont = nodeliste.Item(0).Item("PrintFont").InnerText
            SizeFont = Val(nodeliste.Item(0).Item("SizeFont").InnerText)
            Dim Lignes_blanches = CInt(nodeliste.Item(0).Item("Lignes_blanches").InnerText)
            Dim default_printer = ""
            If Not nodeliste.Item(0).Item("default_printer") Is Nothing Then
                default_printer = nodeliste.Item(0).Item("default_printer").InnerText
            End If
            For i = 1 To Lignes_blanches
                drawString = drawString + Chr(10)
            Next
            drawString = drawString + EnTete + Chr(10)
            Dim total_des_totaux As Decimal = 0
            If num_FSE > 0 Then
                Dim FSE = BDD.FacturesTableAdapter.GetFactureDataByNum1(num_FSE).Item(0)
                If Val(FSE.G1110C1) > 0 Then 'FACTURE VITALE
                    Dim benef = Me.VitaleTableAdapter1.GetDataBénéficiaire(FSE.G1130C2, FSE.G1130C4, FSE.G1130C5, FSE.G1130C6).Item(0)
                    drawString = drawString & benef.G104C1 & " " & benef.G104C3 + Chr(10)
                    drawString = drawString & FSE.G1130C2 & " " & FSE.G1130C3 & Chr(10)
                    drawString = drawString & "FSE " & FSE.G1110C1 & "  " & Mid(FSE.G1110C3, 7, 2) & "/" & Mid(FSE.G1110C3, 5, 2) & "/" & Mid(FSE.G1110C3, 1, 4) + Chr(10)

                    Dim mydatatable = Me.ActesTableAdapter1.GetDataByNumFacturesSV(FSE.G1110C1)
                    Dim total_facturé As Decimal = 0
                    For r = 0 To mydatatable.Rows.Count - 1
                        total_facturé = total_facturé + CDec(mydatatable(r).Total)
                    Next
                    drawString = drawString + "Total facturé:" + total_facturé.ToString + Chr(10)
                    drawString = drawString + "Total FSE:" + (FSE.G1910C2 / 100).ToString + Chr(10)
                    drawString = drawString + "AMO: " + (FSE.G1910C3 / 100).ToString + Chr(10)
                    'drawString = drawString + "Total participation assuré: " + (FSE.G1910C4 / 100).ToString + Chr(10)
                    'drawString = drawString + "Total théorique remboursable par l’AMC: " + (FSE.G1910C5 / 100).ToString + Chr(10)
                    drawString = drawString + "AMC: " + (FSE.G1910C6 / 100).ToString + Chr(10)

                    If FSE.TP_AMO = False And FSE.TP_AMC = False Then
                        drawString = drawString + "Pas de tiers-payant" + Chr(10)
                    ElseIf FSE.TP_AMO = True And FSE.TP_AMC = False Then
                        drawString = drawString + "Tiers-payant AMO seulement" + Chr(10)
                    ElseIf FSE.TP_AMO = True And FSE.TP_AMC = True Then
                        drawString = drawString + "Tiers-payant" + Chr(10)
                    End If
                    drawString = drawString + "Payé par l'assuré: " + ((((total_facturé * 100) - FSE.G1910C3 - FSE.G1910C6) / 100).ToString) & Chr(10)
                    total_des_totaux = (((total_facturé * 100) - FSE.G1910C3 - FSE.G1910C6) / 100)
                End If
            End If
            If num_VD > 0 Then
                Dim VD = COMPTOIR_MAIN.Facture_VenteDirecteTableAdapter1.GetDataBy_Num(num_VD).Item(0)
                If VD.Total <> 0 Then 'FACTURE VENTE DIRECTE
                    drawString = drawString & Chr(10)
                    drawString = drawString & "Vente " & VD.Num.ToString & "  " & Mid(VD.Date_, 7, 2) & "/" & Mid(VD.Date_, 5, 2) & "/" & Mid(VD.Date_, 1, 4) + Chr(10)
                    '____________________________________________________________________ 
                    'détail
                    drawString = drawString + "--------------------------------" + Chr(10) + "                    |Qté|Prix" + Chr(10) + "--------------------------------"
                    ' Dim mydatatable As DataTable = Me.ActesTableAdapter1.GetDataBy_NumFactureVenteDirecte(VD.NumVenteDirecte)
                    Dim mydatatable As PharmaDataSet.ActesDataTable = Me.ActesTableAdapter1.GetDataBy_NumFactureVenteDirecte(VD.Num.ToString)
                    For r = 0 To mydatatable.Rows.Count - 1
                        Dim Quantité = mydatatable(r).Quantité
                        Dim Prix_Unitaire = mydatatable(r).Prix_Unitaire
                        Dim prix_non_remisé = mydatatable(r).prix_non_remisé
                        Dim total = mydatatable(r).Total

                        Dim Désignation As String
                        If mydatatable(r).Désignation.ToString.Length > 20 Then
                            Désignation = Mid(mydatatable(r).Désignation.ToString, 1, 20)
                        Else
                            Désignation = mydatatable(r).Désignation.ToString
                            While Désignation.Length < 20
                                Désignation = Désignation + " "
                            End While
                        End If

                        Dim remise = ""
                        If Val(mydatatable(r).Remise) <> 0 Then
                            remise = mydatatable(r).Remise & "%"
                        End If
                        While remise.Length < 4
                            remise = remise & " "
                        End While
                        If mydatatable.Rows.Count - 1 > r Then
                            If COMPTOIR_MAIN.Hono_Disp_Codes_list.Contains(mydatatable(r + 1).CodeActe) Then
                                Prix_Unitaire = Prix_Unitaire + mydatatable(r + 1).Prix_Unitaire
                                prix_non_remisé = prix_non_remisé + mydatatable(r + 1).Prix_Unitaire
                            End If
                        End If
                        Dim montant_remise_totale As Decimal = (Val(Quantité) * (prix_non_remisé - Prix_Unitaire))
                        'taille des string pour presentation
                        While Quantité.Length < 3
                            Quantité = Quantité + " "
                        End While
                        Dim prix_non_remisé_strg = prix_non_remisé.ToString
                        While prix_non_remisé_strg.Length < 6
                            prix_non_remisé_strg = prix_non_remisé_strg + " "
                        End While

                        Dim montant_remise_totale_strg = montant_remise_totale.ToString
                        While montant_remise_totale_strg.Length < 7
                            montant_remise_totale_strg = montant_remise_totale_strg & " "
                        End While
                        'drawString = drawString + Chr(10) + Désignation + " " + Quantité + " " + prix_non_remisé_strg + " " + remise + " " + montant_remise_totale_strg + " " + total.ToString
                        drawString = drawString + Chr(10) + Désignation + " " + Quantité + " " + total.ToString

                    Next
                    '____________________________________________________________________



                    drawString = drawString + Chr(10) + Chr(10) + "Total à payer:" + (VD.Total + total_des_totaux).ToString & "€" + Chr(10)
                End If
            End If
            drawString = drawString + Chr(10) + Chr(10) + Chr(10) + PiedPage

            X = 10
            Y = 10

            PrintPreviewDialog1.Document = PrintDocument1
            PrintDialog1.Document = PrintDocument1
            If default_printer <> "" Then
                PrintDocument1.PrinterSettings.PrinterName = default_printer
                PrintDocument1.Print()
            ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                PrintDocument1.Print()
            End If
        Catch ex As Exception

        End Try
        If Me.Visible = True Then
            Me.BringToFront()
        End If

    End Sub
    Public Sub Imprime_FSE(ByVal Document As String)

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        drawString = ""

        Dim ConfigXml As New XmlDocument

        ConfigXml.Load(Mid(Application.ExecutablePath, 1, InStrRev(Application.ExecutablePath, "\")) + "InfoPro.xml")

        Dim nodeliste As XmlNodeList
        nodeliste = ConfigXml.GetElementsByTagName(Document)
        Dim EnTete As String = nodeliste.Item(0).Item("EnTete").InnerText
        Dim PiedPage As String = nodeliste.Item(0).Item("PiedPage").InnerText
        PrintFont = nodeliste.Item(0).Item("PrintFont").InnerText
        SizeFont = Val(nodeliste.Item(0).Item("SizeFont").InnerText)
        Dim Lignes_blanches = CInt(nodeliste.Item(0).Item("Lignes_blanches").InnerText)
        Dim default_printer = ""
        If Not nodeliste.Item(0).Item("default_printer") Is Nothing Then
            default_printer = nodeliste.Item(0).Item("default_printer").InnerText
        End If
        Dim reduire_largeur_Impr_Ordo As Boolean = False
        If Not nodeliste.Item(0).Item("reduire_largeur") Is Nothing Then
            If UCase(nodeliste.Item(0).Item("reduire_largeur").InnerText) = "OUI" Then
                reduire_largeur_Impr_Ordo = True
            End If
        End If
        For i = 1 To Lignes_blanches
            drawString = drawString + Chr(10)
        Next
        drawString = drawString + EnTete + Chr(10) + current_User.ID + Chr(10)
        drawString = drawString + Chr(10) + "Fact Num: " + CurrentFactureVitale.G1110C1.ToString + "   Date Fact: " + Mid(CurrentFactureVitale.G1110C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1110C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1110C3, 1, 4)
        Select Case CurrentFactureVitale.ModeSecur
            Case "1"
                drawString = drawString + " SESAM sans Vitale" + Chr(10)
            Case "3"
                drawString = drawString + " Sécurisée" + Chr(10)
            Case "4"
                drawString = drawString + " désynchronisation" + Chr(10)
            Case "5"
                drawString = drawString + " dégradée" + Chr(10)


        End Select
        If CurrentFactureVitale.Bénéficiaire = "CONTRACEPTIF URGENCE MINEURE" Then
            drawString = drawString + Chr(10) + "Prescripteur: " + Config.Data_ContaceptifUrgence_NumPrecripteur & " " & Config.Data_ContaceptifUrgence_CleNumPrecripteur
        Else
            drawString = drawString + Chr(10) + "Prescripteur: " + Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).NomPrénom
        End If

        If CurrentFactureVitale.G1211C3 <> "" Then
            drawString = drawString + Chr(10) + "Date prescr: " + Mid(CurrentFactureVitale.G1211C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1211C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1211C3, 1, 4)
        ElseIf CurrentFactureVitale.G1213C4 <> "" Then
            drawString = drawString + Chr(10) + "Date prescr: " + Mid(CurrentFactureVitale.G1213C4, 7, 2) + "/" + Mid(CurrentFactureVitale.G1213C4, 5, 2) + "/" + Mid(CurrentFactureVitale.G1213C4, 1, 4)
        ElseIf CurrentFactureVitale.G1214C4 <> "" Then
            drawString = drawString + Chr(10) + "Date prescr: " + Mid(CurrentFactureVitale.G1214C4, 7, 2) + "/" + Mid(CurrentFactureVitale.G1214C4, 5, 2) + "/" + Mid(CurrentFactureVitale.G1214C4, 1, 4)
        End If

        drawString = drawString + Chr(10) + "Assuré: " + CurrentFactureVitale.G1130C2 + CurrentFactureVitale.G1130C3 + "  " + CurrentFactureVitale.Assuré
        drawString = drawString + Chr(10) + "Bénéficiaire: " + CurrentFactureVitale.Bénéficiaire + Chr(10) + "né le " + DateVitale_To_DateString(CurrentFactureVitale.G1130C4) + ", rang " + CurrentFactureVitale.G1130C5
        drawString = drawString + Chr(10) + "AMO: " + CurrentFactureVitale.G1310C1 + " " + CurrentFactureVitale.G1310C2 + " " + CurrentFactureVitale.G1310C3 + " " + Me.AmoTableAdapter1.SelectLibellé(CurrentFactureVitale.G1310C1, CurrentFactureVitale.G1310C2, CurrentFactureVitale.G1310C3)
        If CurrentFactureVitale.G1321C2 <> "" Then
            drawString = drawString + Chr(10) + "Org Compl: " + CurrentFactureVitale.G1321C2
            If Me.AmC_OrganismesTableAdapter1.GetDataBy_Num(CurrentFactureVitale.G1321C2).Rows.Count > 0 Then
                drawString = drawString + " " + Me.AmC_OrganismesTableAdapter1.GetDataBy_Num(CurrentFactureVitale.G1321C2).Item(0).Intitulé.ToString
            End If
            If CurrentFactureVitale.G1321C3 <> "" Then
                drawString = drawString + ", Num adhérent: " + CurrentFactureVitale.G1321C3
            End If
        End If
        drawString = drawString + Chr(10) + COMPTOIR_MAIN.NatureAssurance_Button.Text
        If CurrentFactureVitale.G1511C1 <> "" Then
            drawString = drawString + Chr(10) + "Date d’accident de droit commun: " + DateVitale_To_DateString(CurrentFactureVitale.G1511C1)
        End If
        If Not CurrentFactureVitale.TabLigneFacture(1).G1850C2 Is Nothing Then
            If CurrentFactureVitale.TabLigneFacture(1).G1850C2 <> "" Then
                If CInt(CurrentFactureVitale.TabLigneFacture(1).G1850C2) > 0 Then
                    drawString = drawString + Chr(10) + "Renouvellement " & CurrentFactureVitale.TabLigneFacture(1).G1850C2
                End If
            End If
        End If

        'drawString = drawString + Chr(10) + Chr(10) + "--------------------------------------------------------------------------------------" + Chr(10) + "Qté|PrixUnit|T.Remb|Prest|TxRb|Cip Ean13    |LPP            |Désignation             |" + Chr(10) + "--------------------------------------------------------------------------------------"
        drawString = drawString + Chr(10) + Chr(10) + "Qté|PrixUnit|T.Remb|Prest|TxRb|" + Chr(10) + "Cip          |LPP            |Désignation             |"
        '____________________________________________________________________

        'détail
        Dim actes = Me.ActesTableAdapter1.GetDataByNumFacturesSV(CurrentFactureVitale.G1110C1)
        For r = 0 To actes.Rows.Count - 1
            Dim ligne_fact = COMPTOIR_MAIN.Facture_LigneFactureTableAdapter1.GetDataBy_NumFacture_NumLigne(actes(r).NumFacturesSV, actes(r).Ligne_Facture_SV.ToString).Item(0)
            Dim Quantité As String = actes(r).Quantité.ToString
            'Dim Prix_Unitaire As String = actes(r).Prix_Unitaire.ToString
            Dim Prix_Unitaire As String = ((CDec(ligne_fact.G1610C11) / CDec(actes(r).Quantité)) / 100).ToString
            If Mid(actes(r).CodeActe, 1, 2) = "HD" And IsNumeric(Mid(actes(r).CodeActe, 3, 1)) Then
                Prix_Unitaire = ((CDec(ligne_fact.G1610C11)) / 100).ToString
            End If
            Dim Tarif_Remboursement As String = actes(r).Tarif_Remboursement.ToString
            Dim CodeActe As String = actes(r).CodeActe.ToString
            Dim TauxRmbrsmnt As String = actes(r).TauxRmbrsmnt.ToString
            Dim cip_ean13 As String = actes(r).EAN13.ToString
            If cip_ean13 = "" Then
                cip_ean13 = actes(r).CIP.ToString
            End If

            Dim LPP_Ref As String = actes(r).LPP_Ref.ToString
            Dim LPP_Quantité As String = ""
            Dim LPP_Type_prestation As String = ""
            If LPP_Ref <> "" Then
                LPP_Quantité = actes(r).LPP_Quantité.ToString
                If BDD.LPPTableAdapter.GetData_CodeLPP_Date(LPP_Ref, Val(Format(COMPTOIR_MAIN.DateExecution.Value, "yyyyMMdd"))).Rows.Count > 0 Then
                    LPP_Type_prestation = BDD.LPPTableAdapter.GetData_CodeLPP_Date(LPP_Ref, Val(Format(COMPTOIR_MAIN.DateExecution.Value, "yyyyMMdd"))).Item(0).Type_prestation
                End If
            ElseIf COMPTOIR_MAIN.KitsTableAdapter.GetDataBy_Désignation_Kit(actes(r).Désignation.ToString).Rows.Count > 0 Then
                LPP_Type_prestation = BDD.LPPTableAdapter.GetDataBy_CodeLPP(COMPTOIR_MAIN.KitsTableAdapter.GetDataBy_Désignation_Kit(actes(r).Désignation.ToString).Item(0).Code_LPP).Item(0).Type_prestation
                Dim LPP_Quantité_dec = 0
                For Each ligne_du_kit As PharmaDataSet.KitsRow In COMPTOIR_MAIN.KitsTableAdapter.GetDataBy_Désignation_Kit(actes(r).Désignation.ToString)
                    LPP_Quantité_dec = LPP_Quantité_dec + ligne_du_kit.Quantité_LPP
                Next
                LPP_Quantité = LPP_Quantité_dec.ToString
            End If


            Dim Désignation As String = Mid(actes(r).Désignation.ToString, 1, 24)



            'taille des string pour presentation
            While Quantité.Length < 3
                Quantité = Quantité + " "
            End While
            While Prix_Unitaire.Length < 8
                Prix_Unitaire = Prix_Unitaire + " "
            End While
            While Tarif_Remboursement.Length < 6
                Tarif_Remboursement = Tarif_Remboursement + " "
            End While
            While CodeActe.Length < 5
                CodeActe = CodeActe + " "
            End While
            While TauxRmbrsmnt.Length < 4
                TauxRmbrsmnt = TauxRmbrsmnt + " "
            End While
            While cip_ean13.Length < 13
                cip_ean13 = cip_ean13 + " "
            End While
            While LPP_Type_prestation.Length < 1
                LPP_Type_prestation = LPP_Type_prestation + " "
            End While
            While LPP_Ref.Length < 8
                LPP_Ref = LPP_Ref + " "
            End While
            LPP_Quantité = "(" + LPP_Quantité + ")"
            While LPP_Quantité.Length < 4
                LPP_Quantité = LPP_Quantité + " "
            End While
            While Désignation.Length < 24
                Désignation = Désignation + " "
            End While
            If reduire_largeur_Impr_Ordo = True Then
                drawString = drawString + Chr(10) + Quantité + " " + Prix_Unitaire + " " + Tarif_Remboursement + " " + CodeActe + " " + TauxRmbrsmnt + Chr(10) + cip_ean13 + " " + LPP_Type_prestation + " " + LPP_Ref + " " + LPP_Quantité + " " + Désignation + " " '+ Chr(10) + "--------------------------------------------------------------------------------------"
            Else
                drawString = drawString + Chr(10) + Quantité + " " + Prix_Unitaire + " " + Tarif_Remboursement + " " + CodeActe + " " + TauxRmbrsmnt + " " + cip_ean13 + " " + LPP_Type_prestation + " " + LPP_Ref + " " + LPP_Quantité + " " + Désignation + " " '+ Chr(10) + "--------------------------------------------------------------------------------------"
            End If

        Next
        '____________________________________________________________________
        'Totaux
        drawString = drawString + Chr(10) + Chr(10) + "Total: " + (CurrentFactureVitale.G1910C2 / 100).ToString + Chr(10) + "AMO: " + (CurrentFactureVitale.G1910C3 / 100).ToString + _
        "   AMC: " + (CurrentFactureVitale.G1910C6 / 100).ToString + "   ASSURÉ: " + ((CurrentFactureVitale.G1910C4 - CurrentFactureVitale.G1910C6) / 100).ToString + Chr(10)
        '____________________________________________________________________

        'drawString = drawString + Chr(10) + Chr(10) + "Total des montants facturés:" + (CurrentFactureVitale.G1910C2 / 100).ToString + Chr(10)
        'drawString = drawString + "Total AMO: " + (CurrentFactureVitale.G1910C3 / 100).ToString + " "
        'drawString = drawString + "Total assuré: " + (CurrentFactureVitale.G1910C4 / 100).ToString + " "
        'drawString = drawString + "Total théorique remboursable par l’AMC: " + (CurrentFactureVitale.G1910C5 / 100).ToString + Chr(10)
        'drawString = drawString + "Total AMC: " + (CurrentFactureVitale.G1910C6 / 100).ToString + Chr(10)

        If CurrentFactureVitale.TP_AMO = False And CurrentFactureVitale.TP_AMC = False Then
            drawString = drawString + "Pas de tiers-payant" + Chr(10)
        ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = False Then
            drawString = drawString + "Tiers-payant AMO seulement" + Chr(10)
        ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = True Then
            drawString = drawString + "Tiers-payant" + Chr(10)
        End If

        drawString = drawString + "Total restant assuré: " + (total_restant_assuré / 100).ToString + Chr(10)
        If CurrentFactureVenteDirecte.Total <> 0 Then
            MyMsg_Box.Presentation("Officine ?", "Inscrire les ventes directes?", True, "OUI", True, "NON", False, "")
            If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
                drawString = drawString + "__________________________" + Chr(10) + "Ventes Directes: " + (CurrentFactureVenteDirecte.Total).ToString + Chr(10)
            End If
        End If
        drawString = drawString + Chr(10) + Chr(10) + Chr(10) + PiedPage

        X = 10
        Y = 10
        PrintPreviewDialog1.Document = PrintDocument1
        PrintDialog1.Document = PrintDocument1
        If default_printer <> "" Then
            PrintDocument1.PrinterSettings.PrinterName = default_printer
            PrintDocument1.Print()
        ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            'PrintPreviewDialog1.ShowDialog()
            'If PrintPreviewDialog1.DialogResult = DialogResult.OK Then
            PrintDocument1.Print()

            'End If
        End If
    End Sub
    Public Sub Save_TKVT_to_pdf()
        If CurrentFactureVitale.G1110C1 = "" Then
            Exit Sub
        End If
        If Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & CurrentFactureVitale.G1110C1 & "_*_TKVT.pdf") <> "" Then
            Dim add_to_list = True
            For r = 0 To ListBox_scanordo.Items.Count - 1

                If InStr(ListBox_scanordo.Items.Item(r).ToString, "TKVT") <> 0 Then
                    add_to_list = False
                End If
            Next
            If add_to_list = True Then
                ListBox_scanordo.Items.Add(Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & CurrentFactureVitale.G1110C1 & "_*_TKVT.pdf"))
            End If
            Exit Sub
        End If


        'numfacture
        Dim FileName As String = CurrentFactureVitale.G1110C1

        '--------------------------------------------------
        'compteur
        Dim compteur As Integer = 1
        While Dir(Config.LocalNetwork_ServerName & "\scor\doc\" + FileName + "_" + compteur.ToString + "*.pdf") <> ""
            compteur = compteur + 1
        End While
        FileName = FileName + "_" + compteur.ToString
        '--------------------------------------------------
        'A10-1 Nature de pièces justificatives
        FileName = FileName + "_TKVT.pdf"

        '--------------------------------------------------
        'pdf
        Dim document As New PdfDocument()
        Dim page = document.AddPage()
        Dim tf As XTextFormatter
        Dim gfx = XGraphics.FromPdfPage(page)
        tf = New XTextFormatter(gfx)
        Dim font = New XFont("Courier New", 10, XFontStyle.Regular)
        tf.DrawString(drawString, font, XBrushes.Black, New XRect(5, 5, page.Width, page.Height), XStringFormats.TopLeft)
        document.Save(Config.LocalNetwork_ServerName & "\scor\doc\" + FileName)
        ListBox_scanordo.Items.Add(FileName)

        ScanOrdo.SCOR_PJTableAdapter.Insert(FileName, ScanOrdo.ID_PJ(compteur.ToString, "TKVT"), "A FINALISER", CurrentFactureVitale.G1110C1)



    End Sub


    Public Sub Imprime_CERFA(ByVal numfacture As Decimal)

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        Dim ConfigXml As New XmlDocument

        ConfigXml.Load(Mid(Application.ExecutablePath, 1, InStrRev(Application.ExecutablePath, "\")) + "InfoPro.xml")
        Dim nodeliste As XmlNodeList
        nodeliste = ConfigXml.GetElementsByTagName("CERFA")
        PrintFont = "Lucida console"
        SizeFont = 12
        LigneCERFA = 1
        drawString = ""
        Dim fact As DataTable = COMPTOIR_MAIN.FacturesTableAdapter.GetFactureDataByNum1(numfacture)
        Dim lignes_fact As DataTable = COMPTOIR_MAIN.Facture_LigneFactureTableAdapter1.GetDataByNumFacture(numfacture)

        '_______________________________________________________________________________________________________
        'En tête
        Avance_Ligne_CERFA(2)
        Avance_Colonne_CERFA(60)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1110C1" Then
                Avance_Colonne_CERFA(6 - fact(0).Item(c).ToString.Length)
                drawString = drawString + fact(0).Item(c).ToString
                Exit For
            End If
        Next

        Avance_Ligne_CERFA(4)
        Avance_Colonne_CERFA(61)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1110C3" Then
                Ecrit_DAte_Vitale_Sur_CERFA(fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        '_______________________________________________________________________________________________________
        'PERSONNE RECEVANT LES SOINS ET ASSURE
        Avance_Ligne_CERFA(7)
        Avance_Colonne_CERFA(10)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "Bénéficiaire" Then
                drawString = drawString + fact(0).Item(c).ToString
                Exit For
            End If
        Next

        Avance_Ligne_CERFA(9)
        Avance_Colonne_CERFA(21)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1130C2" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        drawString = drawString + " "
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1130C3" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next

        Avance_Colonne_CERFA(8)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1310C1" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1310C2" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1310C3" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next

        Avance_Ligne_CERFA(11)
        Avance_Colonne_CERFA(21)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1310C3" Then
                Ecrit_DAte_Vitale_Sur_CERFA(fact(0).Item(c).ToString)
                Exit For
            End If
        Next

        Avance_Ligne_CERFA(13)
        Avance_Colonne_CERFA(10)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "Assuré" Then
                drawString = drawString + fact(0).Item(c).ToString
                Exit For
            End If
        Next

        Avance_Ligne_CERFA(15)
        Avance_Colonne_CERFA(21)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1130C2" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        drawString = drawString + " "
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1130C3" Then
                Ecrit_CERFA_espacé(fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        '_______________________________________________________________________________________________________
        'IDENTIFICATION DU PHARMACIEN
        Avance_Ligne_CERFA(20)
        drawString = drawString + nodeliste.Item(0).Item("Pharmacie_Structure").InnerText
        LigneCERFA = LigneCERFA + 5

        If Config.Activer_Session_Remplacement = True Then
            Avance_Ligne_CERFA(26)
            Avance_Colonne_CERFA(10)
            'à faire: nom prénom du remplaçant
            Avance_Ligne_CERFA(27)
            Avance_Colonne_CERFA(21)
            drawString = drawString + Config.Remplacant_Num_Id_Nat + " " + Config.Remplacant_Cle_Num_Id_Nat
        End If
        '_______________________________________________________________________________________________________
        'IDENTIFICATION DU PRESCRIPTEUR
        Avance_Ligne_CERFA(30)
        Avance_Colonne_CERFA(10)
        Dim IDPrescripteur As String = ""
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "IDPrescripteur" Then
                IDPrescripteur = fact(0).Item(c).ToString
                Exit For
            End If
        Next
        drawString = drawString + Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(IDPrescripteur).Item(0).NomPrénom
        Avance_Ligne_CERFA(31)
        Avance_Colonne_CERFA(21)
        Ecrit_CERFA_espacé(Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(IDPrescripteur).Item(0).Numidentification)

        Avance_Colonne_CERFA(16)
        Ecrit_CERFA_espacé(Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(IDPrescripteur).Item(0).numStructure)
        '_______________________________________________________________________________________________________
        'CONDITION DE PRISE EN CHARGE
        Avance_Ligne_CERFA(34)
        Avance_Colonne_CERFA(21)
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "G1211C3" Or fact.Columns.Item(c).ColumnName = "G1213C4" Or fact.Columns.Item(c).ColumnName = "G1214C4" Then
                If fact(0).Item(c).ToString <> "" Then
                    Ecrit_DAte_Vitale_Sur_CERFA(fact(0).Item(c).ToString)
                    Exit For
                End If
            End If
        Next
        Avance_Colonne_CERFA(26)
        Dim dateEP As String = ""
        For r = 0 To lignes_fact.Rows.Count - 1
            For c = 0 To lignes_fact.Columns.Count - 1
                If fact.Columns.Item(c).ColumnName = "G1840C3" Then
                    If fact(0).Item(c).ToString <> "" Then
                        dateEP = (fact(0).Item(c).ToString)
                        Exit For
                    End If
                End If
            Next
        Next
        Ecrit_DAte_Vitale_Sur_CERFA(dateEP)

        Dim nature_assurance As String = ""
        For c = 0 To fact.Columns.Count - 1
            If fact.Columns.Item(c).ColumnName = "Nature_Assurance" Then
                nature_assurance = (fact(0).Item(c).ToString)
                Exit For
            End If
        Next
        Avance_Ligne_CERFA(35)
        Avance_Colonne_CERFA(13)
        drawString = drawString + nature_assurance

        If nature_assurance = "SMG" Then
            For c = 0 To fact.Columns.Count - 1
                If fact.Columns.Item(c).ColumnName = "G1310C1" Then
                    If (fact(0).Item(c).ToString) = "08" Then
                        Avance_Colonne_CERFA(51 - COMPTOIR_MAIN.NatureAssurance_Button.Text.Length)
                        drawString = drawString + "XXX"
                    End If
                    Exit For
                End If
            Next
        End If

        Avance_Ligne_CERFA(37)
        Avance_Colonne_CERFA(20)
        Dim ald, prev, autre As Boolean
        For i = 0 To CurrentFactureVitale.TabLigneFacture.Length - 1
            If Val(CurrentFactureVitale.TabLigneFacture(i).G1820C2) = 4 Then
                ald = True
            ElseIf Val(CurrentFactureVitale.TabLigneFacture(i).G1820C2) = 7 Then
                prev = True
            ElseIf Val(CurrentFactureVitale.TabLigneFacture(i).G1820C2) <> 0 Then
                autre = True
            End If
        Next
        If ald = True Then
            drawString = drawString = "XX"
        Else
            drawString = drawString = "  "
        End If
        Avance_Colonne_CERFA(14)
        If prev = True Then
            drawString = drawString = "XX"
        Else
            drawString = drawString = "  "
        End If
        Avance_Colonne_CERFA(9)
        If autre = True Then
            drawString = drawString = "XX"
        Else
            drawString = drawString = "  "
        End If
        Avance_Ligne_CERFA(38)
        If CurrentFactureVitale.G1511C1 <> "" Then
            Avance_Colonne_CERFA(32)
            drawString = drawString = "XX"
            Avance_Colonne_CERFA(6)
            Ecrit_DAte_Vitale_Sur_CERFA(CurrentFactureVitale.G1511C1)
        Else
            Avance_Colonne_CERFA(21)
            drawString = drawString = "XX"
        End If
        Avance_Ligne_CERFA(41)
        Avance_Colonne_CERFA(25)
        If CurrentFactureVitale.G1513C2 <> "" Then
            Ecrit_CERFA_espacé(CurrentFactureVitale.G1513C2 + CurrentFactureVitale.G1513C3)
        Else
            Avance_Colonne_CERFA(18)
        End If
        If CurrentFactureVitale.G1513C1 <> "" Then
            Avance_Colonne_CERFA(18)
            Ecrit_DAte_Vitale_Sur_CERFA(CurrentFactureVitale.G1513C1)
        End If
        '_______________________________________________________________________________________________________
        'PRODUITS ET PRESTATIONS
        Avance_Ligne_CERFA(43)
        drawString = drawString + "Qté|PrixUnit|T.Remb|Prest|TxRb|Cip Ean13    |LPP            |Désignation             |"
        Dim mydatatable As DataTable = COMPTOIR_MAIN.Facture_LigneFactureTableAdapter1.GetDataByNumFacture(CurrentFactureVitale.G1110C1)
        Me.ActesTableAdapter1.GetDataByNumFacturesSV(CurrentFactureVitale.G1110C1)
        For r = 0 To mydatatable.Rows.Count - 1
            Avance_Ligne_CERFA(44 + r)
            Dim Quantité As String = ""
            Dim Prix_Unitaire As String = ""
            Dim Tarif_Remboursement As String = ""
            Dim CodeActe As String = ""
            Dim TauxRmbrsmnt As String = ""
            Dim cip_ean13 As String = ""
            Dim LPP_Type_prestation As String = ""
            Dim LPP_Ref As String = ""
            Dim LPP_Quantité As String = ""
            Dim Désignation As String = ""
            Dim codeExo As String = ""

            For c = 0 To mydatatable.Columns.Count - 1
                Select Case mydatatable.Columns.Item(c).ColumnName
                    Case "G1730C8", "G1740C5"
                        If Quantité = "" Then
                            Quantité = mydatatable(r).Item(c).ToString
                        End If
                    Case "G1730C9", "G1740C4"
                        If Prix_Unitaire = "" Then
                            Prix_Unitaire = mydatatable(r).Item(c).ToString
                        End If
                    Case "G1730C7", "G1740C4"
                        If Tarif_Remboursement = "" Then
                            Tarif_Remboursement = mydatatable(r).Item(c).ToString
                        End If
                    Case "G1610C4"
                        CodeActe = mydatatable(r).Item(c).ToString
                    Case "G1610"
                        TauxRmbrsmnt = mydatatable(r).Item(c).ToString
                    Case "G1740C3"
                        cip_ean13 = mydatatable(r).Item(c).ToString
                    Case "G1730C3"
                        LPP_Type_prestation = mydatatable(r).Item(c).ToString
                    Case "G1730C2"
                        LPP_Ref = mydatatable(r).Item(c).ToString
                    Case "G1730C8"
                        LPP_Quantité = mydatatable(r).Item(c).ToString

                End Select
            Next
            'taille des string pour presentation
            While Quantité.Length < 3
                Quantité = Quantité + " "
            End While
            While Prix_Unitaire.Length < 8
                Prix_Unitaire = Prix_Unitaire + " "
            End While
            While Tarif_Remboursement.Length < 6
                Tarif_Remboursement = Tarif_Remboursement + " "
            End While
            While CodeActe.Length < 5
                CodeActe = CodeActe + " "
            End While
            While TauxRmbrsmnt.Length < 4
                TauxRmbrsmnt = TauxRmbrsmnt + " "
            End While
            While cip_ean13.Length < 13
                cip_ean13 = cip_ean13 + " "
            End While
            While LPP_Type_prestation.Length < 1
                LPP_Type_prestation = LPP_Type_prestation + " "
            End While
            While LPP_Ref.Length < 8
                LPP_Ref = LPP_Ref + " "
            End While
            LPP_Quantité = "(" + LPP_Quantité + ")"
            While LPP_Quantité.Length < 4
                LPP_Quantité = LPP_Quantité + " "
            End While
            While Désignation.Length < 24
                Désignation = Désignation + " "
            End While

            drawString = drawString + Chr(10) + Quantité + " " + Prix_Unitaire + " " + Tarif_Remboursement + " " + CodeActe + " " + TauxRmbrsmnt + " " + cip_ean13 + " " + LPP_Type_prestation + " " + LPP_Ref + " " + LPP_Quantité + " " + Désignation + Chr(10) + "--------------------------------------------------------------------------------------"
        Next
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        drawString = drawString + Chr(10) + "Fact Num: " + CurrentFactureVitale.G1110C1.ToString + "   Date Fact: " + Mid(CurrentFactureVitale.G1110C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1110C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1110C3, 1, 4)
        Select Case CurrentFactureVitale.ModeSecur
            Case "1"
                drawString = drawString + " SESAM sans Vitale" + Chr(10)
            Case "3"
                drawString = drawString + " Sécurisée" + Chr(10)
            Case "4"
                drawString = drawString + " désynchronisation" + Chr(10)
            Case "5"
                drawString = drawString + " dégradée" + Chr(10)


        End Select
        drawString = drawString + Chr(10) + "Prescripteur: " + Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).NomPrénom
        If CurrentFactureVitale.G1211C3 <> "" Then
            drawString = drawString + "   Date prescr: " + Mid(CurrentFactureVitale.G1211C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1211C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1211C3, 1, 4)
        ElseIf CurrentFactureVitale.G1213C4 <> "" Then
            drawString = drawString + "   Date prescr: " + Mid(CurrentFactureVitale.G1213C4, 7, 2) + "/" + Mid(CurrentFactureVitale.G1213C4, 5, 2) + "/" + Mid(CurrentFactureVitale.G1213C4, 1, 4)
        ElseIf CurrentFactureVitale.G1214C4 <> "" Then
            drawString = drawString + "   Date prescr: " + Mid(CurrentFactureVitale.G1214C4, 7, 2) + "/" + Mid(CurrentFactureVitale.G1214C4, 5, 2) + "/" + Mid(CurrentFactureVitale.G1214C4, 1, 4)
        End If


        drawString = drawString + Chr(10) + "Assuré: " + CurrentFactureVitale.G1130C2 + CurrentFactureVitale.G1130C3 + "  " + CurrentFactureVitale.Assuré
        drawString = drawString + Chr(10) + "Bénéficiaire: " + CurrentFactureVitale.Bénéficiaire + ", né le " + DateVitale_To_DateString(CurrentFactureVitale.G1130C4) + ", rang " + CurrentFactureVitale.G1130C5
        drawString = drawString + Chr(10) + "AMO: " + CurrentFactureVitale.G1310C1 + " " + CurrentFactureVitale.G1310C2 + " " + CurrentFactureVitale.G1310C3 + " " + Me.AmoTableAdapter1.SelectLibellé(CurrentFactureVitale.G1310C1, CurrentFactureVitale.G1310C2, CurrentFactureVitale.G1310C3)
        If CurrentFactureVitale.G1321C2 <> "" Then
            drawString = drawString + Chr(10) + "Org Compl: " + CurrentFactureVitale.G1321C2
            If Me.AmC_OrganismesTableAdapter1.GetDataBy_Num(CurrentFactureVitale.G1321C2).Rows.Count > 0 Then
                drawString = drawString + " " + Me.AmC_OrganismesTableAdapter1.GetDataBy_Num(CurrentFactureVitale.G1321C2).Item(0).Intitulé.ToString
            End If
            If CurrentFactureVitale.G1321C3 <> "" Then
                drawString = drawString + ", Num adhérent: " + CurrentFactureVitale.G1321C3
            End If
        End If
        drawString = drawString + Chr(10) + COMPTOIR_MAIN.NatureAssurance_Button.Text
        If CurrentFactureVitale.G1511C1 <> "" Then
            drawString = drawString + Chr(10) + "Date d’accident de droit commun: " + DateVitale_To_DateString(CurrentFactureVitale.G1511C1)
        End If

        drawString = drawString + Chr(10) + Chr(10) + "--------------------------------------------------------------------------------------" + Chr(10) + "Qté|PrixUnit|T.Remb|Prest|TxRb|Cip Ean13    |LPP            |Désignation             |" + Chr(10) + "--------------------------------------------------------------------------------------"
        '____________________________________________________________________
        'détail
        For r = 0 To mydatatable.Rows.Count - 1
            Dim Quantité As String = ""
            Dim Prix_Unitaire As String = ""
            Dim Tarif_Remboursement As String = ""
            Dim CodeActe As String = ""
            Dim TauxRmbrsmnt As String = ""
            Dim cip_ean13 As String = ""
            Dim LPP_Type_prestation As String = ""
            Dim LPP_Ref As String = ""
            Dim LPP_Quantité As String = ""
            Dim Désignation As String = ""

            For c = 0 To mydatatable.Columns.Count - 1
                Select Case mydatatable.Columns.Item(c).ColumnName
                    Case "Quantité"
                        Quantité = mydatatable(r).Item(c).ToString
                    Case "Prix_Unitaire"
                        Prix_Unitaire = mydatatable(r).Item(c).ToString
                    Case "Tarif_Remboursement"
                        Tarif_Remboursement = mydatatable(r).Item(c).ToString
                    Case "CodeActe"
                        CodeActe = mydatatable(r).Item(c).ToString
                    Case "TauxRmbrsmnt"
                        TauxRmbrsmnt = mydatatable(r).Item(c).ToString
                    Case "CIP"
                        cip_ean13 = mydatatable(r).Item(c).ToString
                    Case "EAN13"
                        If cip_ean13 = "" Then
                            cip_ean13 = mydatatable(r).Item(c).ToString
                        End If
                    Case "LPP_Type_prestation"
                        LPP_Type_prestation = mydatatable(r).Item(c).ToString
                    Case "LPP_Ref"
                        LPP_Ref = mydatatable(r).Item(c).ToString
                    Case "LPP_Quantité"
                        LPP_Quantité = mydatatable(r).Item(c).ToString
                    Case "Désignation"
                        Désignation = Mid(mydatatable(r).Item(c).ToString, 1, 24)
                End Select
            Next
            'taille des string pour presentation
            While Quantité.Length < 3
                Quantité = Quantité + " "
            End While
            While Prix_Unitaire.Length < 8
                Prix_Unitaire = Prix_Unitaire + " "
            End While
            While Tarif_Remboursement.Length < 6
                Tarif_Remboursement = Tarif_Remboursement + " "
            End While
            While CodeActe.Length < 5
                CodeActe = CodeActe + " "
            End While
            While TauxRmbrsmnt.Length < 4
                TauxRmbrsmnt = TauxRmbrsmnt + " "
            End While
            While cip_ean13.Length < 13
                cip_ean13 = cip_ean13 + " "
            End While
            While LPP_Type_prestation.Length < 1
                LPP_Type_prestation = LPP_Type_prestation + " "
            End While
            While LPP_Ref.Length < 8
                LPP_Ref = LPP_Ref + " "
            End While
            LPP_Quantité = "(" + LPP_Quantité + ")"
            While LPP_Quantité.Length < 4
                LPP_Quantité = LPP_Quantité + " "
            End While
            While Désignation.Length < 24
                Désignation = Désignation + " "
            End While

            drawString = drawString + Chr(10) + Quantité + " " + Prix_Unitaire + " " + Tarif_Remboursement + " " + CodeActe + " " + TauxRmbrsmnt + " " + cip_ean13 + " " + LPP_Type_prestation + " " + LPP_Ref + " " + LPP_Quantité + " " + Désignation + " " + Chr(10) + "--------------------------------------------------------------------------------------"
        Next
        '____________________________________________________________________
        'Totaux
        drawString = drawString + Chr(10) + Chr(10) + "Total: " + (CurrentFactureVitale.G1910C2 / 100).ToString + "   AMO: " + (CurrentFactureVitale.G1910C3 / 100).ToString + _
        "   AMC: " + (CurrentFactureVitale.G1910C6 / 100).ToString + "   ASSURÉ: " + ((CurrentFactureVitale.G1910C4 - CurrentFactureVitale.G1910C6) / 100).ToString
        '____________________________________________________________________

        drawString = drawString + Chr(10) + Chr(10) + "Total des montants facturés:" + (CurrentFactureVitale.G1910C2 / 100).ToString + Chr(10)
        drawString = drawString + "Total remboursable par l’AMO: " + (CurrentFactureVitale.G1910C3 / 100).ToString + Chr(10)
        drawString = drawString + "Total participation assuré: " + (CurrentFactureVitale.G1910C4 / 100).ToString + Chr(10)
        drawString = drawString + "Total théorique remboursable par l’AMC: " + (CurrentFactureVitale.G1910C5 / 100).ToString + Chr(10)
        drawString = drawString + "Total remboursable par l’AMC: " + (CurrentFactureVitale.G1910C6 / 100).ToString + Chr(10)

        If CurrentFactureVitale.TP_AMO = False And CurrentFactureVitale.TP_AMC = False Then
            drawString = drawString + "Pas de tiers-payant" + Chr(10)
        ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = False Then
            drawString = drawString + "Tiers-payant AMO seulement" + Chr(10)
        ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = True Then
            drawString = drawString + "Tiers-payant" + Chr(10)
        End If

        drawString = drawString + "Total restant assuré: " + (total_restant_assuré / 100).ToString + Chr(10)
        If CurrentFactureVenteDirecte.Total <> 0 Then
            MyMsg_Box.Presentation("Officine ?", "Inscrire les ventes directes?", True, "OUI", True, "NON", False, "")
            If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
                drawString = drawString + "__________________________" + Chr(10) + "Ventes Directes: " + (CurrentFactureVenteDirecte.Total).ToString + Chr(10)
            End If
        End If

        X = 10
        Y = 10

        PrintPreviewDialog1.Document = PrintDocument1
        PrintDialog1.Document = PrintDocument1
        If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PrintPreviewDialog1.ShowDialog()
            If PrintPreviewDialog1.DialogResult = DialogResult.OK Then
                PrintDocument1.Print()
            End If
        End If
    End Sub

    Public Sub Avance_Ligne_CERFA(ByVal LigneCERFA_Cible As Integer)

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        For i = 1 To LigneCERFA_Cible - LigneCERFA
            drawString = drawString + Chr(10)
        Next
        LigneCERFA = LigneCERFA_Cible
    End Sub
    Public Sub Avance_Colonne_CERFA(ByVal Nombre_Colonne As Integer)

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        For i = 1 To Nombre_Colonne
            drawString = drawString + " "
        Next
    End Sub
    Public Sub Ecrit_CERFA_espacé(ByVal Chaine As String)

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        For i = 1 To Chaine.Length

            drawString = drawString + Mid(Chaine, i, 1) + " "
        Next
    End Sub
    Public Sub Ecrit_DAte_Vitale_Sur_CERFA(ByRef datevitale As String)

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        drawString = drawString + Mid(datevitale, 7, 1) + " " + Mid(datevitale, 8, 1) + " " + Mid(datevitale, 5, 1) + " " + Mid(datevitale, 6, 1) + " " + Mid(datevitale, 1, 1) + " " + _
       Mid(datevitale, 2, 1) + " " + Mid(datevitale, 3, 1) + " " + Mid(datevitale, 4, 1)
    End Sub

    'Ordonnance
    'Private Sub TKVT_LinkLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TKVT_LinkLabel.Click

    '    If Trace_Appel_Fonctions = True Then
    '        Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
    '            sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
    '        End Using
    '    End If

    '    Imprime_FSE("Impr_Ordo")
    '    Save_TKVT_to_pdf()
    '    Me.BringToFront()
    '    Me.Focus()
    'End Sub



    Private Sub Dus_PrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Dus_PrintDocument.PrintPage

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        Dim drawFont As New Font("Courier", 10)
        Dim drawBrush As New SolidBrush(Color.Black)

        e.Graphics.DrawString(Dus_drawString, drawFont, drawBrush, 10, 10)
    End Sub

#End Region



    Private Sub ListBox_scanordo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox_scanordo.Click

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If
        If Not ListBox_scanordo.SelectedItem Is Nothing Then
            Process.Start(Config.LocalNetwork_ServerName & "\scor\doc\" + ListBox_scanordo.SelectedItem.ToString)
        End If

    End Sub




    Private Sub Inscription_Ordonnancier()
        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If
        Try
            If COMPTOIR_MAIN.Reprise_Facture_Num <> 0 Then Exit Sub
            If Paiement_Type_Button.Text = "Devis" Then Exit Sub
        Catch ex As Exception
        End Try

        'stup
        For r = 0 To COMPTOIR_MAIN.Vente.Rows.Count - 1
            If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteListe.Index, r).Value = "Stupéfiant" And UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) <> "VENTE DIRECTE" Then
                Ordonnancier_Inscription.WindowState = FormWindowState.Normal
                Ordonnancier_Inscription.pour_vente_directe = False
                Me.TopMost = False
                Ordonnancier_Inscription.ShowDialog()
                Me.TopMost = True
                Exit Sub 'ne pas réouvrir Ordonnancier_Inscription si il a déja été ouvert
            End If
        Next
        For r = 0 To COMPTOIR_MAIN.Vente.Rows.Count - 1
            If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteListe.Index, r).Value = "Stupéfiant" And UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) = "VENTE DIRECTE" Then
                Ordonnancier_Inscription.WindowState = FormWindowState.Normal
                Ordonnancier_Inscription.pour_vente_directe = True
                Me.TopMost = False
                Ordonnancier_Inscription.ShowDialog()
                Me.TopMost = True
                Exit Sub 'ne pas réouvrir Ordonnancier_Inscription si il a déja été ouvert
            End If
        Next

        'Liste 1 Liste 2
        For r = 0 To COMPTOIR_MAIN.Vente.Rows.Count - 1
            If (COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteListe.Index, r).Value = "Liste 1" Or COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteListe.Index, r).Value = "Liste 2") _
                And UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) <> "VENTE DIRECTE" Then
                If COMPTOIR_MAIN.InscriptionAutoListeIEtListeIIToolStripMenuItem.Checked = False Then
                    Ordonnancier_Inscription.WindowState = FormWindowState.Normal
                    Ordonnancier_Inscription.pour_vente_directe = False
                    Me.TopMost = False
                    Ordonnancier_Inscription.ShowDialog()
                    Me.TopMost = True
                    Exit Sub 'ne pas réouvrir Ordonnancier_Inscription si il a déja été ouvert
                Else
                    Ordonnancier_Inscription.WindowState = FormWindowState.Minimized
                    Ordonnancier_Inscription.pour_vente_directe = False
                    Ordonnancier_Inscription.Visible = True
                    Ordonnancier_Inscription.OK_Button.PerformClick()
                    Exit Sub 'ne pas réouvrir Ordonnancier_Inscription si il a déja été ouvert
                End If
            End If
        Next
        For r = 0 To COMPTOIR_MAIN.Vente.Rows.Count - 1
            If (COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteListe.Index, r).Value = "Liste 1" Or COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteListe.Index, r).Value = "Liste 2") _
                And UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) = "VENTE DIRECTE" Then
                'If COMPTOIR_MAIN.InscriptionAutoListeIEtListeIIToolStripMenuItem.Checked = False Then
                Ordonnancier_Inscription.WindowState = FormWindowState.Normal
                Ordonnancier_Inscription.pour_vente_directe = True
                Me.TopMost = False
                Ordonnancier_Inscription.ShowDialog()
                Me.TopMost = True
                Exit Sub 'ne pas réouvrir Ordonnancier_Inscription si il a déja été ouvert
                'Else
                '    Ordonnancier_Inscription.WindowState = FormWindowState.Minimized
                '    Ordonnancier_Inscription.Visible = True
                '    Ordonnancier_Inscription.OK_Button.PerformClick()
                '    Exit Sub 'ne pas réouvrir Ordonnancier_Inscription si il a déja été ouvert
                'End If
            End If
        Next
    End Sub

    Private Sub VenteForm_RightToLeftChanged(sender As Object, e As EventArgs) Handles Me.RightToLeftChanged

    End Sub

    Private Sub VenteForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        'If is_opened_for_print_only = False Then
        '    Inscription_Ordonnancier()
        'End If

        Try
            If liste_du.Count > 0 Then

                Dus_LinkLabel_LinkClicked(Nothing, Nothing)

            End If
        Catch ex As Exception

        End Try
        If current_User.comptage_boite = True And Facture_Auto.Facturation_auto = False Then
            Recap_Label.Visible = False
            Dim nombre_compté As Integer = 0

            MyInptBox.my_showdialog("Comptez les boites au comptoir", VarType(nombre_compté), 100, "")
            nombre_compté = MyInptBox.result
            If nombre_compté <> nombre_produits Then
                MyMsg_Box.Presentation("Nombre de boites au comptoir", "Le nombre de boites indiqué: " & nombre_compté.ToString & vbCrLf & "ne correspond pas" & vbCrLf & "au nombre calculé: " & nombre_produits.ToString, False, "", False, "", True, "Ok")
                MyMsg_Box.ShowDialog()
                Recap_Label.ForeColor = Color.Red
            End If
            Recap_Label.Visible = True
        End If

        Facturation_Auto_feed()

        Jeux_D_Essai_AutoClick()
        The_debile_cerfa()
    End Sub
    Private Sub The_debile_cerfa()
        If CurrentFactureVitale.ModeSecur = "5" And CurrentFactureVitale.num > 0 And Config.cerfa_debile Then
            'For Each item In ListBox_scanordo.Items
            '    If InStr(item.ToString, "_FNSC") <> 0 Then
            '        ordo_scannée = True
            '        Exit For
            '    End If

            'Next
            Transmettre_CERFA_LinkClicked(Nothing, Nothing)
        End If


    End Sub

    Private Sub Facturation_Auto_feed()
        If Facture_Auto.Facturation_auto Then
            If Facture_Auto.Facturation_auto_TypeEncaissement <> "" Then
                Paiement_Type_Button.Text = Facture_Auto.Facturation_auto_TypeEncaissement
            End If
            If Facture_Auto.Facturation_auto_IdOrdo > 0 Then
                Dim fichier_ordo = ""
                Dim docs_ = BDD.Ordo_FichiersTableAdapter.GetDataBy_Id_Ordo(Facture_Auto.Facturation_auto_IdOrdo)
                If docs_.Rows.Count > 0 Then
                    For Each doc_ In docs_
                        If InStr(doc_.Fichier, "ORDN") = 1 Or InStr(doc_.Fichier, "ORDE") = 1 Or InStr(doc_.Fichier, "ORBZ") = 1 _
                            Or InStr(doc_.Fichier, "FSNC") = 1 Or InStr(doc_.Fichier, "FSEC") = 1 Or InStr(doc_.Fichier, "TKVT") = 1 _
                            Or InStr(doc_.Fichier, "PREV") = 1 Or InStr(doc_.Fichier, "GRIP") = 1 Or InStr(doc_.Fichier, "AUTP") = 1 Then
                            fichier_ordo = doc_.Fichier
                            Exit For
                        End If
                    Next
                    If fichier_ordo <> "" Then
                        Dim compteur As Integer = 1
                        'compteur
                        While Dir(Config.LocalNetwork_ServerName & "\scor\doc\" + CurrentFactureVitale.G1110C1 + "_" + compteur.ToString + "*.pdf") <> ""
                            compteur = compteur + 1
                        End While
                        Dim new_file_name = CurrentFactureVitale.G1110C1 + "_" + compteur.ToString + "_" + Mid(fichier_ordo, 1, 4) + ".pdf" 'A10-1 Nature de pièces justificatives
                        My.Computer.FileSystem.CopyFile(Config.LocalNetwork_ServerName & "\scor\Ordo\" & fichier_ordo, Config.LocalNetwork_ServerName & "\scor\doc\" + new_file_name, True)

                        'save to Bdd
                        While ScanOrdo.SCOR_PJTableAdapter.GetDataBy_Fichier(new_file_name).Rows.Count = 0
                            ScanOrdo.SCOR_PJTableAdapter.Insert(new_file_name, ScanOrdo.ID_PJ(compteur.ToString, Mid(fichier_ordo, 1, 4)), "A FINALISER", CurrentFactureVitale.G1110C1)
                            System.Threading.Thread.Sleep(1000)
                        End While

                        'TT02.01 Préparer le fichier d'index ScanOrdo
                        If CurrentFactureVitale.G1110C1 <> "" Then
                            If My.Computer.FileSystem.FileExists(Config.LocalNetwork_ServerName & "\scor\index\" & CurrentFactureVitale.G1110C1 & ".xml") = False Then
                                ScanOrdo.TT02()
                            End If
                        End If
                        ListBox_scanordo.Items.Add(new_file_name)
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Jeux_D_Essai_AutoClick()

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        If jeux_d_essai.Visible = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\technique\jeux d'essai\jeux d'essai tronc commun.log", True)
                sw.WriteLine(jeux_d_essai.ComboBox1.Text + " " + jeux_d_essai.Chapitre_combobox.Text + " test n° " + jeux_d_essai.num_Test_TextBox.Text + " --> fact n°: " + CurrentFactureVitale.G1110C1)
            End Using
        End If
        If Jeux_d_essai2.Visible = True Then
            Dim sw = New StreamWriter(Application.StartupPath + "\technique\jeux d'essai\jeux d'essai2.log", True)
            sw.WriteLine(Jeux_d_essai2.Serie_ComboBox.Text + "." + Jeux_d_essai2.Num_ComboBox.Text + ";" + CurrentFactureVitale.G1110C1)
            Jeux_d_essai2.RichTextBox1.AppendText(" Fact n° " + CurrentFactureVitale.G1110C1)
            sw.Close()
            Button_Facturation_Click(Nothing, Nothing)
        End If
        If jeux_d_essai_CAS_STANDARD.Visible = True Then
            Dim sw = New StreamWriter(Application.StartupPath + "\technique\jeux d'essai\III.03 - CAS STANDARD.log", True)
            sw.WriteLine(jeux_d_essai_CAS_STANDARD.série_Label1.Text + "." + jeux_d_essai_CAS_STANDARD.Test_Label1.Text + " ; " + jeux_d_essai_CAS_STANDARD.InfosParticulières_Label1.Text + " ; " + CurrentFactureVitale.G1110C1 + " ; " + Format(Now, "HH:mm:ss"))
            sw.Close()
            Button_Facturation_Click(Nothing, Nothing)
        End If
        If jeux_d_essai_TRONC_COMMUN.Visible = True Then
            Dim sw = New StreamWriter(Application.StartupPath + "\technique\jeux d'essai\III.04 - TRONC COMMUN.log", True)
            sw.WriteLine(jeux_d_essai_TRONC_COMMUN.Série_Label.Text + "  Test n°" + jeux_d_essai_TRONC_COMMUN.NumTest_Label.Text + " ; " + CurrentFactureVitale.G1110C1 + " ; " + Format(Now, "HH:mm:ss"))
            sw.Close()
        End If
    End Sub




    Private Sub SCOR_Documents_externes_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles SCOR_Documents_externes_LinkLabel.LinkClicked
        If SCOR_Documents_Externes_list Is Nothing Then
            SCOR_Documents_Externes_list = New List(Of String)
        End If
        Me.TopMost = False
        SCOR_Documents_externes.TopMost = True
        SCOR_Documents_externes.ShowDialog()
        Me.TopMost = True
        Me.BringToFront()
        Me.Focus()
    End Sub






    Private Sub Paiement_Type_Button_Click(sender As Object, e As EventArgs) Handles Paiement_Type_Button.Click
        'VenteForm_Moyen_paiement.ShowDialog()
        Me.TopMost = False
        VenteForm_Moyen_paiement2.TopMost = True
        VenteForm_Moyen_paiement2.ShowDialog()
        Me.TopMost = True
    End Sub



    Private Sub ListBox_Doc_archive_Click(sender As Object, e As EventArgs) Handles ListBox_Doc_archive.Click
        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If
        If Not ListBox_Doc_archive.SelectedItem Is Nothing Then
            Process.Start(Config.LocalNetwork_ServerName & "\scor\doc\" + ListBox_Doc_archive.SelectedItem.ToString)
        End If
    End Sub




    Private Sub Dus_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Dus_LinkLabel.LinkClicked
        Me.TopMost = False
        Vente_Du.TopMost = True
        Vente_Du.ShowDialog()
        Me.TopMost = True
    End Sub





    Private Sub Reset_PictureBox_Click(sender As Object, e As EventArgs) Handles Reset_PictureBox.Click

        If is_opened_for_print_only = True Then
            Me.Close()
        End If

        'Update Stock
        If COMPTOIR_MAIN.Reprise_Facture_Num = 0 Then
            For i = 0 To COMPTOIR_MAIN.Vente.RowCount - 1
                If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value <> "" Then
                    COMPTOIR_MAIN.ProduitsTableAdapter.UpdateStock_By_CIP_CAB(Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value), _
                                                                   COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, i).Value)
                ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value <> "" Then
                    COMPTOIR_MAIN.ProduitsTableAdapter.UpdateStock_By_CIP_CAB(Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value), _
                                                                   COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, i).Value)
                ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, i).Value <> "" And COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCodeActe.Index, i).Value = "" Then
                    COMPTOIR_MAIN.ProduitsTableAdapter.UpdateStock_by_Designation(Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value), _
                                                                                  COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, i).Value)
                End If

            Next
        End If
        If CurrentFactureVitale.G1110C1 <> "" Then
            Dim file = Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & CurrentFactureVitale.G1110C1.ToString & "_*")
            While file <> ""
                If InStr(file, "TKVT") <> 0 Then
                    Try
                        My.Computer.FileSystem.DeleteFile(Config.LocalNetwork_ServerName & "\scor\doc\" & file)
                        ScanOrdo.SCOR_PJTableAdapter.Delete_by_Fichier(file)
                    Catch ex As Exception
                    End Try
                Else
                    Try
                        My.Computer.FileSystem.RenameFile(Config.LocalNetwork_ServerName & "\scor\doc\" & file, "Prescan" & Config.Idposte & Mid(file, InStr(file, "_")))

                        ScanOrdo.SCOR_PJTableAdapter.UpdatePresScan("Prescan" & Config.Idposte, "Prescan" & Config.Idposte & Mid(file, InStr(file, "_")), _
                                                                     ScanOrdo.SCOR_PJTableAdapter.GetDataBy_Fichier(file).Item(0).ID, file)
                    Catch ex As Exception
                    End Try

                End If
                file = Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & CurrentFactureVitale.G1110C1.ToString & "_*")
            End While
            If Facture.FacturesTableAdapter.GetFactureDataByNum1(CDec(CurrentFactureVitale.G1110C1)).Rows.Count > 0 Then
                Facture.Supprimer_FSE(CurrentFactureVitale.G1110C1, False, False, False, False, False)
            End If

            If My.Computer.FileSystem.FileExists(Config.LocalNetwork_ServerName & "\scor\index\" & CurrentFactureVitale.G1110C1 & ".xml") Then
                My.Computer.FileSystem.DeleteFile(Config.LocalNetwork_ServerName & "\scor\index\" & CurrentFactureVitale.G1110C1 & ".xml")
            End If
            Dim doc = Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & CurrentFactureVitale.G1110C1 & "_*.pdf")
            'While doc <> ""
            '    System.Threading.Thread.Sleep(1000)
            '    My.Computer.FileSystem.DeleteFile(Config.LocalNetwork_ServerName & "\scor\doc\" & doc)
            '    doc = Dir(Config.LocalNetwork_ServerName & "\scor\doc\" & CurrentFactureVitale.G1110C1 & "_*.pdf")
            'End While



        End If

        If CurrentFactureVenteDirecte.NumVenteDirecte > 0 Then
            Facture.Supprimer_VenteDirecte(CurrentFactureVenteDirecte.NumVenteDirecte, False, False, False)
        End If
        CurrentFactureVenteDirecte.Clear()
        CurrentFactureVenteDirecte.Clear()
        CurrentFactureVenteDirecte.Clear()
        CurrentFactureVenteDirecte.Clear()

        COMPTOIR_MAIN.Scor_Label_refresh()

        COMPTOIR_MAIN.Button_Facturation.Visible = True
        COMPTOIR_MAIN.Vente.Visible = True
        COMPTOIR_MAIN.Show()
        Me.Dispose()


    End Sub


    Private Sub Crédits_CheckedListBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles Crédits_CheckedListBox1.MouseUp
        afficheinfovente()
    End Sub




    Private Sub Button_Facturation_Click(sender As Object, e As EventArgs) Handles Button_Facturation.Click, Button_Vente_enchainée.Click
        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If


        '____________________________________________________________________________________________________
        If Control_ordonnance_TKVT() = False Then
            Exit Sub
        End If
        '____________________________________________________________________________________________________
        Dim butt_clicked = CType(sender, Button)
        '____________________________________________________________________________________________________
        If is_opened_for_print_only = False Then
            If Paiement_Type_Button.Text = "Type Paiement" And butt_clicked.Name = "Button_Facturation" And reste_à_payer_plus_crédits_plus_encaissements_en_attente <> 0 Then
                MyMsg_Box.Presentation("Officine !", "CHOIX MODE PAIEMENT", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                Exit Sub
            End If
            '____________________________________________________________________________________________________
            'table des dus
            If Not liste_du Is Nothing Then
                If liste_du.Count > 0 Then
                    If CurrentBenéficiaire.G104C1 = "" Then
                        MyMsg_Box.Presentation("Officine !", "Données de l'assuré insufisantes pour enregistrer un dû.", False, "", False, "", True, "OK")
                        MyMsg_Box.ShowDialog()
                        Exit Sub
                    End If
                End If
                Dim date_du = Now
                For Each du_ In liste_du
                    COMPTOIR_MAIN.DusTableAdapter.Insert(du_.cip7, du_.cip13, du_.désignation, du_.Quantité_Du, COMPTOIR_MAIN.ComboBoxLECTURE_VITALE.Text, COMPTOIR_MAIN.NirTextBox.Text, _
                                                         du_.Note, date_du, date_du, "", "", _
                                                         0, CurrentFactureVitale.num, CurrentFactureVenteDirecte.NumVenteDirecte, False)
                Next
            End If
            'impression des dus
            If Not liste_du Is Nothing Then
                If liste_du.Count > 0 Then
                    impression_Comptoir_Config.liste_du = liste_du
                    MyMsg_Box.Presentation("Officine ?", "Impression Ticket de du ?", True, "OUI", True, "NON", False, "")
                    If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
                        impression_Comptoir_Config.Imprim_Ticket_Dus()
                    End If
                    MyMsg_Box.Presentation("Officine ?", "Impression deuxième Ticket de du ?", True, "OUI", True, "NON", False, "")
                    If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
                        impression_Comptoir_Config.Imprim_Ticket_Dus()
                    End If


                End If
            End If
            '____________________________________________________________________________________________________
            'Définit le numéro de l'encaissement
            Dim num_encaissement As Integer = EncaissementsTableAdapter.Select_Max_Num + 1
            'enregistre l'encaissement dans la table Encaissements
            Dim bénéficiaire As String = COMPTOIR_MAIN.ComboBoxLECTURE_VITALE.Text
            If Paiement_Type_Button.Text = "Crédit" And butt_clicked.Name = "Button_Facturation" And bénéficiaire = "" Then
                MyMsg_Box.Presentation("Officine !", "Vous devez selectionner un beneficiaire avant d'accorder un crédit.", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                Exit Sub
            End If
            '____________________________________________________________________________________________________
            If butt_clicked.Name = "Button_Facturation" Then
                If Paiement_Type_Button.Text = "Reprise" Then
                    Dim num_fact_strg = COMPTOIR_MAIN.Reprise_Facture_Num.ToString
                    While num_fact_strg.Length < 9
                        num_fact_strg = "0" & num_fact_strg
                    End While
                    Teletransmission_MAIN.RSP_LIGNE_REJETTableAdapter.Update_Acquitement(True, num_fact_strg, "AMO")
                    Teletransmission_MAIN.RSP_LIGNE_REJETTableAdapter.Update_Acquitement(True, num_fact_strg, "AMC")
                    Dim original_facture = BDD.FacturesTableAdapter.GetFactureDataByNum1(COMPTOIR_MAIN.Reprise_Facture_Num).Item(0)
                    Dim Reprise_encaiss As New Reprise_Facture_Encaissement
                    Reprise_encaiss.Dif_G1910C3 = original_facture.G1910C3 - CurrentFactureVitale.G1910C3
                    Reprise_encaiss.Dif_G1910C6 = original_facture.G1910C6 - CurrentFactureVitale.G1910C6
                    Reprise_dif_à_encaisser = 0
                    If Reprise_encaiss.Dif_G1910C3 <> 0 Or Reprise_encaiss.Dif_G1910C6 <> 0 Then
                        Me.TopMost = False
                        Reprise_encaiss.ShowDialog()
                        Me.TopMost = True
                    End If
                    If Reprise_dif_à_encaisser <> 0 Then
                        EncaissementsTableAdapter.Insert(num_encaissement, "Crédit", Reprise_dif_à_encaisser, Val(CurrentFactureVitale.num), _
                                                   Val(CurrentFactureVenteDirecte.NumVenteDirecte), Now.ToString(), Now, "", bénéficiaire, 0, False, num_encaissement, Reprise_dif_à_encaisser.ToString & "€ mis en crédit client sur reprise", False, 0)
                    Else
                        EncaissementsTableAdapter.Insert(num_encaissement, Paiement_Type_Button.Text, 0, Val(CurrentFactureVitale.num), _
                                                   Val(CurrentFactureVenteDirecte.NumVenteDirecte), Now.ToString(), Now, "", bénéficiaire, 0, False, num_encaissement, "Reprise sans encaissement", False, 0)
                    End If
                    If Teletransmission_MAIN.Visible = True Then
                        Teletransmission_MAIN.Affiche_Rejets_Paiement(Teletransmission_MAIN.DataGridView_Rejets_Paiements)
                    End If
                    BDD.FacturesTableAdapter.Set_Recyclée(True, original_facture.Num)
                Else
                    EncaissementsTableAdapter.Insert(num_encaissement, Paiement_Type_Button.Text, reste_à_payer - Encaissement_partiel_montant_crédit - Encaissement_partiel_montant_remise, Val(CurrentFactureVitale.num), _
                                                    Val(CurrentFactureVenteDirecte.NumVenteDirecte), Now.ToString(), Now, "", bénéficiaire, 0, False, num_encaissement, COMPTOIR_MAIN.Encaissement_Note, Note_rappel_CheckBox.Checked, Encaissement_partiel_montant_remise)
                    Caisse(reste_à_payer - Encaissement_partiel_montant_crédit - Encaissement_partiel_montant_remise)

                    If Not Ventes_enchainées_encaissement_en_attente Is Nothing Then
                        For Each encaiss_attente As Vente_enchainée_encaissement_en_attente In Ventes_enchainées_encaissement_en_attente
                            If Paiement_Type_Button.Text = "Crédit" Or Paiement_Type_Button.Text = "Organisme" Then
                                EncaissementsTableAdapter.Update_Encaissement_Vente_Enchainée(Paiement_Type_Button.Text, num_encaissement, encaiss_attente.num_encaissement)
                                If EncaissementsTableAdapter.GetDataBy_Num(encaiss_attente.num_encaissement).Item(0).Nom_Complet = "" Then
                                    EncaissementsTableAdapter.Update_Nom_Complet_by_Num(bénéficiaire, encaiss_attente.num_encaissement)
                                End If
                            Else
                                EncaissementsTableAdapter.Update_Encaissement_Vente_Enchainée(Paiement_Type_Button.Text, num_encaissement, encaiss_attente.num_encaissement)
                            End If
                        Next
                    End If
                    If Encaissement_partiel_montant_crédit > 0 Then
                        num_encaissement = EncaissementsTableAdapter.Select_Max_Num + 1
                        EncaissementsTableAdapter.Insert(num_encaissement, "Crédit", Encaissement_partiel_montant_crédit, Val(CurrentFactureVitale.num), _
                                                    Val(CurrentFactureVenteDirecte.NumVenteDirecte), Now.ToString(), Now, "", bénéficiaire, 0, False, num_encaissement, COMPTOIR_MAIN.Encaissement_Note, Note_rappel_CheckBox.Checked, 0)

                    End If
                    Ventes_enchainées_encaissement_en_attente = New List(Of Vente_enchainée_encaissement_en_attente)
                    Ventes_enchainées_encaissement_en_attente.Clear()
                    'Ventes_enchainées_Last_Bénéficiaire = ""
                    Ventes_enchainées_Crédits_en_attente = New List(Of Decimal)
                    Ventes_enchainées_Crédits_en_attente.Clear()
                End If
            Else
                Encaissement_partiel_montant_crédit = 0
                Encaissement_partiel_montant_remise = 0
                EncaissementsTableAdapter.Insert(num_encaissement, "Vente enchainée", reste_à_payer, Val(CurrentFactureVitale.num), _
                                            Val(CurrentFactureVenteDirecte.NumVenteDirecte), Now.ToString(), Now, "", bénéficiaire, 0, False, 0, COMPTOIR_MAIN.Encaissement_Note, Note_rappel_CheckBox.Checked, 0)
                If Ventes_enchainées_encaissement_en_attente Is Nothing Then
                    Ventes_enchainées_encaissement_en_attente = New List(Of Vente_enchainée_encaissement_en_attente)
                End If
                Dim encaiss As New Vente_enchainée_encaissement_en_attente
                encaiss.montant_à_encaisser = reste_à_payer
                encaiss.num_encaissement = num_encaissement
                Ventes_enchainées_encaissement_en_attente.Add(encaiss)
                If Ventes_enchainées_Crédits_en_attente Is Nothing Then
                    Ventes_enchainées_Crédits_en_attente = New List(Of Decimal)
                End If
                For r = 0 To CurrentBenéficiaire.Crédits_en_Cours.Count - 1
                    Ventes_enchainées_Crédits_en_attente.Add(CurrentBenéficiaire.Crédits_en_Cours.Item(r).Num)
                Next
            End If
            '____________________________________________________________________________________________________
            'sauvegarde numéro encaissement pour chaque actes dans la table Actes
            ActesTableAdapter1.Update_Encaissement_Num(num_encaissement, CurrentFactureVitale.num, CurrentFactureVenteDirecte.NumVenteDirecte)
            '____________________________________________________________________________________________________
            If Paiement_Type_Button.Text <> "Crédit" And Paiement_Type_Button.Text <> "Organisme" And Paiement_Type_Button.Text <> "Devis" And butt_clicked.Name = "Button_Facturation" Then
                If Crédits_CheckedListBox1.Items.Count > 0 Then
                    For idx As Integer = 0 To Crédits_CheckedListBox1.Items.Count - 1
                        If Crédits_CheckedListBox1.GetItemChecked(idx) = True Then
                            Dim num_crédit = Mid(Crédits_CheckedListBox1.Items.Item(idx).ToString, 1, InStr(Crédits_CheckedListBox1.Items.Item(idx).ToString, ":") - 1)
                            Dim value_strg = Mid(Crédits_CheckedListBox1.Items.Item(idx).ToString, InStrRev(Crédits_CheckedListBox1.Items.Item(idx).ToString, " ") + 1)
                            value_strg = Replace(value_strg, "€", "")
                            Me.EncaissementsTableAdapter.Update_Crédit_data_ByNum(Paiement_Type_Button.Text, Now, Convert.ToDecimal(value_strg), False, Convert.ToDecimal(num_crédit))
                        End If
                    Next
                End If
            End If
            '____________________________________________________________________________________________________
            If Imprimer_facture_CheckBox.Checked = True Then
                Dim parameters As String = ""

                parameters = parameters & "&Encaissements_num=" & num_encaissement.ToString

                If parameters = "" Then Exit Sub

                Dim edition As New Encaissements_Edition_Facture
                edition.parameters = parameters
                edition.Visible = True
                edition.BringToFront()
                edition.TopMost = True
            End If
            '____________________________________________________________________________________________________
            ' scor documents externes
            If Not SCOR_Documents_Externes_list Is Nothing Then
                For Each item In SCOR_Documents_Externes_list
                    ScanOrdo.SCOR_PJTableAdapter.Insert(item, ScanOrdo.SCOR_PJTableAdapter.GetDataBy_Fichier(item).Item(0).ID, "DOCUMENT EXTERNE", CurrentFactureVitale.G1110C1)
                Next
                'création de l'index scanordo si non existant
                If CurrentFactureVitale.G1110C1 <> "" Then
                    If My.Computer.FileSystem.FileExists(Config.LocalNetwork_ServerName & "\scor\index\" & CurrentFactureVitale.G1110C1 & ".xml") = False Then
                        ScanOrdo.TT02()
                    End If
                End If
            End If
            '____________________________________________________________________________________________________
            Inscription_Ordonnancier()
            '____________________________________________________________________________________________________
            'alimentation du DP
            Try


                If COMPTOIR_MAIN.Reprise_Facture_Num = 0 And Paiement_Type_Button.Text <> "Devis" Then
                    If Config.DP_Activer = True Then
                        If DP_Carte_Vitale_lue = True Then
                            COMPTOIR_MAIN.DP_form.Visible = False
                            COMPTOIR_MAIN.DP_form.Fill_Dispensation_DataGridView()
                            If COMPTOIR_MAIN.DP_form.Dispensation_DataGridView.Rows.Count > 0 Then
                                'My.Computer.FileSystem.WriteAllText("c:\testdp.txt", "COMPTOIR_MAIN.DP_form.Dispensation_DataGridView.Rows.Count: " & COMPTOIR_MAIN.DP_form.Dispensation_DataGridView.Rows.Count.ToString & vbCrLf, True)
                                COMPTOIR_MAIN.DP_form.Dispensation_Button.Visible = True
                                COMPTOIR_MAIN.DP_form.Back_Button.Visible = False
                                Me.TopMost = False
                                COMPTOIR_MAIN.DP_form.ShowDialog()
                                Me.TopMost = True
                            End If
                        ElseIf CurrentBenéficiaire.G104C1 <> "" And CurrentBenéficiaire.G104C3 <> "" And (CurrentBenéficiaire.G104C9 <> "" Or CurrentBenéficiaire.G101C8 <> "") Then
                            COMPTOIR_MAIN.DP_form = New DP
                            COMPTOIR_MAIN.DP_form.Visible = False
                            COMPTOIR_MAIN.DP_form.Fill_Dispensation_DataGridView()
                            If COMPTOIR_MAIN.DP_form.Dispensation_DataGridView.Rows.Count > 0 Then
                                DP.Write_Trace_Fonc("Dispensation sans carte Vitale", "FSV:" & CurrentFactureVitale.num.ToString & "  FVD:" & CurrentFactureVenteDirecte.NumVenteDirecte.ToString, "Pas d’utilisation du DP", DP.Identifiant_patient_function())
                            End If
                        End If
                        If Not COMPTOIR_MAIN.DP_form Is Nothing Then
                            COMPTOIR_MAIN.DP_form.Close()
                        End If
                    End If
                End If
                If DP_Carte_Vitale_lue = True And Not COMPTOIR_MAIN.IAM_info_form.interactions_détectées Is Nothing Then
                    For Each inter In COMPTOIR_MAIN.IAM_info_form.interactions_détectées
                        If Val(inter.IamNiv) >= Val(Config.Piam3) Then
                            Dim iam_alim_form As New IAM_alimentation_DP
                            iam_alim_form.interaction_ = inter
                            Me.TopMost = False
                            iam_alim_form.ShowDialog()
                            Me.TopMost = True
                        Else
                            Dim iam_alim_form As New IAM_alimentation_DP
                            iam_alim_form.interaction_ = inter
                            iam_alim_form.RadioButton1.Checked = False
                            iam_alim_form.WindowState = FormWindowState.Minimized
                            iam_alim_form.Visible = True
                            iam_alim_form.Button1.PerformClick()
                        End If
                    Next
                End If
            Catch ex As Exception
                trace_log(ex.ToString)
            End Try
            '____________________________________________________________________________________________________
        End If

        If COMPTOIR_MAIN.Reprise_Facture_Num = 0 And Paiement_Type_Button.Text <> "Devis" Then
            For r = 0 To COMPTOIR_MAIN.Vente.RowCount - 2
                Try
                    BDD.ProduitsTableAdapter.Update_DateDernièrevente(Format(Now, "dd/MM/yyyy HH:mm:ss"), COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, r).Value, _
                                                                      COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, r).Value, _
                                                                      COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, r).Value, _
                                                                      COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, r).Value)
                Catch ex As Exception
                End Try
            Next
        End If
        If Config.facilEpharm_Activé = True Then
            If Not facilEpharm.Ordo_row Is Nothing Then
                facilEpharm.OrdoTableAdapter.Update_Etat("Délivrée", facilEpharm.Ordo_row.Id_Ordo)
            End If
        End If
        If COMPTOIR_MAIN.Reprise_Facture_Num = 0 And Paiement_Type_Button.Text <> "Devis" Then
            Chronique_MAJ()
            Dim suivitrait As New SuiviTraitementList
            suivitrait.Fin_de_Vente = True
            Me.TopMost = False
            suivitrait.ShowDialog()
            Me.TopMost = True
        End If


        ''''''''''''''''''''''''''''
        'nettoyage fichiers apperçu scanordo affichés dans WebBrowser_SCOR)
        If Config.Scor_hide_VenteForm_WebBrowser_SCOR = False Then
            Dim WebBrowser_SCOR_files As New List(Of String)
            Dim WebBrowser_SCOR_file = Dir(Application.StartupPath + "\temp\VenteForm_WebBrowser_SCOR*.pdf")
            While WebBrowser_SCOR_file <> ""
                WebBrowser_SCOR_files.Add(WebBrowser_SCOR_file)
                WebBrowser_SCOR_file = Dir()
            End While
            For Each item As String In WebBrowser_SCOR_files
                Try
                    My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\temp\" & item)
                Catch ex As Exception
                End Try
            Next
        End If


        ''''''''''''''''''''''''''''''''
        If Paiement_Type_Button.Text = "Devis" Then
            For i = 0 To COMPTOIR_MAIN.Vente.RowCount - 1
                If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value <> "" Then
                    COMPTOIR_MAIN.ProduitsTableAdapter.UpdateStock_By_CIP_CAB(Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value), _
                                                                   COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, i).Value, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, i).Value)
                ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value <> "" Then
                    COMPTOIR_MAIN.ProduitsTableAdapter.UpdateStock_By_CIP_CAB(Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value), _
                                                                   COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, i).Value, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, i).Value)
                ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, i).Value <> "" And COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCodeActe.Index, i).Value = "" Then
                    COMPTOIR_MAIN.ProduitsTableAdapter.UpdateStock_by_Designation(Val(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, i).Value), _
                                                                                  COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, i).Value)
                End If

            Next
        End If
        '''''''''''''''''''''''''''''''''''''
        COMPTOIR_MAIN.ResetForm()
        'COMPTOIR_MAIN.Enabled = True
        COMPTOIR_MAIN.Dispose()
        If current_User.Locked = True Or butt_clicked.Name = "Button_Vente_enchainée" Then
            COMPTOIR_MAIN.Visible = True
        Else
            MENU_PRINCIPAL.WindowState = FormWindowState.Maximized
        End If
        '____________________________________________________________________________________________________
        If jeux_d_essai_TRONC_COMMUN.Visible = True Then
            COMPTOIR_MAIN.Close()
        End If
        '____________________________________________________________________________________________________

        If Facture_Auto.Facturation_auto Then
            Dim restant = BDD.OrdoTableAdapter.GetDataBy_Id_Ordo(Facture_Auto.Facturation_auto_IdOrdo).Item(0).Renouvellement_restant - 1
            BDD.OrdoTableAdapter.Update_Renouvellement_restant(restant, Facture_Auto.Facturation_auto_IdOrdo)
            Facture_Auto.WindowState = FormWindowState.Normal
            Facture_Auto.BringToFront()

        End If
        Facture_Auto.Facturation_auto = False
        Facture_Auto.Facturation_auto_TypeEncaissement = ""
        Facture_Auto.Facturation_auto_IdOrdo = 0


        Me.Dispose()
    End Sub

    Private Sub Caisse(ByVal Montant As Decimal)
        If Paiement_Type_Button.Text = "Espèces" Then
            If BDD.CaisseTableAdapter.GetData.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
            Dim FondCaisse As Decimal = BDD.CaisseTableAdapter.GetDataBy_Num(BDD.CaisseTableAdapter.SelectMaxNum).Item(0).Fond_caisse
            BDD.CaisseTableAdapter.Insert(BDD.CaisseTableAdapter.SelectMaxNum + 1, Now, current_User.ID, Montant, "encaissement", FondCaisse + Montant)
        End If
    End Sub
    Private Sub ScanOrdo_Button_Click(sender As Object, e As EventArgs) Handles ScanOrdo_Button.Click
        ScanOrdo.Validate_Button.Visible = True

        Me.TopMost = False
        ScanOrdo.Validate_Button.Visible = True
        ScanOrdo.TopMost = True
        ScanOrdo.ShowDialog()
        Me.TopMost = True
    End Sub

    Private Function Control_ordonnance_TKVT() As Boolean
        'control ordonnance


        If is_opened_for_print_only = False And CurrentFactureVitale.G1110C1 <> "" Then
            Dim ordo_scannée = False
            For Each item In ListBox_scanordo.Items
                If InStr(item.ToString, "_OR") <> 0 Then
                    ordo_scannée = True
                    Exit For
                End If

            Next
            If Not SCOR_Documents_Externes_list Is Nothing Then
                For Each item In SCOR_Documents_Externes_list
                    If InStr(item.ToString, "_OR") <> 0 Then
                        ordo_scannée = True
                        Exit For
                    End If
                Next
            End If
            If ordo_scannée = False And CurrentBenéficiaire.G101C8 <> Config.Data_ContaceptifUrgence_NIR Then
                'MyMsg_Box.Presentation("Officine !", vbCrLf & "Scannez l' Ordonance", True, "OUI", True, "NON", False, "")
                'If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
                'Return False

                'End If
                MyMsg_Box.Presentation("Officine !", vbCrLf & "Scannez l' Ordonance", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                Return False

            End If
        End If
        'control TKVT
        If is_opened_for_print_only = False And CurrentFactureVitale.G1110C1 <> "" Then
            Dim TKVT = False
            For Each item In ListBox_scanordo.Items
                If InStr(item.ToString, "_TKVT") <> 0 Then
                    TKVT = True
                    Exit For
                End If

            Next
            If TKVT = False Then
                MyMsg_Box.Presentation("Officine !", "TICKET VITALE", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                Return False
            End If
        End If
        Return True
    End Function




    Private Sub LinkLabel2_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Impression_Chèque_LinkLabel.LinkClicked
        Try
            Dim impr As New impression_Comptoir_Config
            impr.reste_à_payer_plus_crédits_plus_encaissements_en_attente = reste_à_payer_plus_crédits_plus_encaissements_en_attente
            impr.Imprim_Chèque()
        Catch ex As Exception

        End Try


    End Sub




    Private Sub SCOR_show_scanner_interface_CheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles SCOR_show_scanner_interface_CheckBox.CheckedChanged
        SCOR_show_scanner_interface = SCOR_show_scanner_interface_CheckBox.Checked
    End Sub


    Private Sub Crédits_détails_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Crédits_détails_LinkLabel.LinkClicked

        Dim parameters As String = ""
        For r = 0 To Crédits_CheckedListBox1.Items.Count - 1
            parameters = parameters & "&Num=" & Mid(Crédits_CheckedListBox1.Items.Item(r).ToString, 1, InStr(Crédits_CheckedListBox1.Items.Item(r).ToString, ":") - 1)
        Next
        If parameters <> "" Then
            Web_browser.Visible = True
            Web_browser.BringToFront()
            Web_browser.WebBrowser1.Navigate("http://" & Replace(Config.LocalNetwork_ServerName, "\", "") & "/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2fComptoir%2fComptoir_Ventes_D%c3%a9tail_Cr%c3%a9dit&rs:Command=Render" & parameters)
        End If
    End Sub



    Private Sub LinkLabel2_LinkClicked_1(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        If Paiement_Type_Button.Text = "Reprise" Then
            MyMsg_Box.Presentation("Officine !", "impossible sur reprise", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Encaissement_partiel_montant_crédit = 0
            Encaissement_partiel_montant_remise = 0
            afficheinfovente()
            Exit Sub
        End If
        If Val(CurrentFactureVitale.num) = 0 And Val(CurrentFactureVenteDirecte.NumVenteDirecte) = 0 Then
            MyMsg_Box.Presentation("Officine !", "Un encaissement partiel est impossible hors facturation." & vbCrLf & vbCrLf & "Pour encaisser une partie de crédit, utilisez le module Financier." & vbCrLf & vbCrLf & _
                                   "(Financier / Encaissements / Encaissement partiel de crédit)", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Encaissement_partiel_montant_crédit = 0
            Encaissement_partiel_montant_remise = 0
            afficheinfovente()
            Exit Sub
        End If
        Try

            Encaissement_Partiel.Montant_TextBox1.Text = reste_à_payer_plus_crédits_plus_encaissements_en_attente
            Encaissement_Partiel.crédit_TextBox2.Text = Encaissement_partiel_montant_crédit
            Encaissement_Partiel.Remise_TextBox3.Text = Encaissement_partiel_montant_remise
            Me.TopMost =
                Encaissement_Partiel.TopMost = True
            Encaissement_Partiel.ShowDialog()
            Me.TopMost = True
        Catch ex As Exception
            Me.TopMost = True
            MyMsg_Box.Presentation("Officine !", "Montant Invalide.", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Encaissement_partiel_montant_crédit = 0
            Encaissement_partiel_montant_remise = 0
            afficheinfovente()

            Exit Sub
        End Try
        If Encaissement_partiel_montant_crédit >= reste_à_payer_plus_crédits_plus_encaissements_en_attente Then
            MyMsg_Box.Presentation("Officine !", "Montant Invalide.", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Encaissement_partiel_montant_crédit = 0
            Encaissement_partiel_montant_remise = 0
            afficheinfovente()
            Exit Sub
        End If
        afficheinfovente()
    End Sub

    Private Sub Encaissement_Note_RichTextBox_TextChanged(sender As Object, e As EventArgs) Handles Encaissement_Note_RichTextBox.TextChanged
        COMPTOIR_MAIN.Encaissement_Note = Encaissement_Note_RichTextBox.Text
        If Encaissement_Note_RichTextBox.Text = "" Then
            Note_rappel_CheckBox.Checked = False
            Note_rappel_CheckBox.Enabled = False
        Else
            Note_rappel_CheckBox.Checked = True
            Note_rappel_CheckBox.Enabled = True
        End If
    End Sub

    Private Sub Feuille_de_soins_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Feuille_de_soins_LinkLabel.LinkClicked
        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        'Imprime_FSE("Impr_Duplicata_FSE")
        Choix_Papier.num_facture_SV = CurrentFactureVitale.num
        Choix_Papier.num_facture_VD = CurrentFactureVenteDirecte.NumVenteDirecte
        Me.TopMost = False
        Choix_Papier.TopMost = True
        Choix_Papier.ShowDialog()
        Me.TopMost = True
        Me.BringToFront()
        Me.Focus()


    End Sub

    Public Sub Chronique_MAJ()
        'CHRONIQUE
        If COMPTOIR_MAIN.Reprise_Facture_Num = 0 And CurrentBenéficiaire.G101C8 <> "" Then
            For r2 = 0 To COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView.Rows.Count - 1
                For r1 = 0 To COMPTOIR_MAIN.Vente.RowCount - 2
                    If (COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCIP.Index, r1).Value <> "" And _
                        COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCIP.Index, r1).Value = COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CIP.Index, r2).Value) Or _
                       (COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteEAN13.Index, r1).Value <> "" And _
                        COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteEAN13.Index, r1).Value = COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_EAN13.Index, r2).Value) Or _
                       (COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.Ventecab.Index, r1).Value <> "" And _
                        COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.Ventecab.Index, r1).Value = COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CAB.Index, r2).Value) Or _
                        (COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteDésignation.Index, r1).Value <> "" And _
                         COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteDésignation.Index, r1).Value = COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_Désignation.Index, r2).Value) Then
                        Dim data = BDD.ChroniqueTableAdapter.GetDataBy_Datas(CurrentBenéficiaire.Num, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_Désignation.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CIP.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_EAN13.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CAB.Index, r2).Value).Item(0)
                        Dim Date_Renouvellement = DateAdd(DateInterval.DayOfYear, data.Intervalle_renouvellement, COMPTOIR_MAIN.DateExecution.Value)
                        Dim Date_Commande_Produit As Date
                        If data.Période_ID = 0 Then
                            Date_Commande_Produit = DateAdd(DateInterval.DayOfYear, data.Intervalle_Commande_Produit * (-1), Date_Renouvellement)
                        Else
                            If data.Date_Commande_Produit < Now Then
                                Dim période_data = BDD.Chronique_PériodeTableAdapter.GetDataBy_Id(data.Période_ID).Item(0)
                                Dim interval As Integer = CInt(période_data.interval_command_jours * CInt(Mid(data.Période_récurence, InStr(data.Période_récurence, "/") + 1)) / CInt(Mid(data.Période_récurence, 1, InStr(data.Période_récurence, "/") - 1)))
                                Date_Commande_Produit = DateAdd(DateInterval.Day, interval, BDD.Chronique_PériodeTableAdapter.GetDataBy_Id(data.Période_ID).Item(0).Date_dernière_commande)
                                If CurrentBenéficiaire.Chronique_Periode_decalage_jour <> 0 Then
                                    Date_Commande_Produit = DateAdd(DateInterval.Day, CurrentBenéficiaire.Chronique_Periode_decalage_jour, Date_Commande_Produit)
                                End If
                            Else
                                Date_Commande_Produit = data.Date_Commande_Produit
                            End If
                        End If
                        BDD.ChroniqueTableAdapter.Update_Dates(COMPTOIR_MAIN.DateExecution.Value, Date_Renouvellement, Date_Commande_Produit, CurrentBenéficiaire.Num, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_Désignation.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CIP.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_EAN13.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CAB.Index, r2).Value)
                        BDD.ChroniqueTableAdapter.Update_Commande_Ref("", 0, CurrentBenéficiaire.Num, _
                                                                      COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_Désignation.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CIP.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_EAN13.Index, r2).Value, _
                                                                            COMPTOIR_MAIN.Dossier_Patient_Chronique_DataGridView(COMPTOIR_MAIN.Dossier_Patient_Chronique_Produit_CAB.Index, r2).Value)
                    End If
                Next
            Next
        End If
    End Sub

    
  

    Private Sub TKVT_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles TKVT_LinkLabel.LinkClicked

        If Trace_Appel_Fonctions = True Then
            Using sw As New StreamWriter(Application.StartupPath + "\traces\appels_fonctions.txt", True)
                sw.WriteLine(Me.Name + " / " + System.Reflection.MethodInfo.GetCurrentMethod.ToString + " (called by " + (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name + ")")
            End Using
        End If

        Dim impr = New impression_Comptoir_Config
        impr.Ticket_vitale_total_restant_assuré = total_restant_assuré
        'impr.load_config("Ticket_Vitale")
        impr.Imprim_Ticker_Vitale()



        Save_TKVT_to_pdf()


        Me.BringToFront()
        Me.Focus()
    End Sub


    Private Sub Facture_rapide_LinkLabel_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Facture_rapide_LinkLabel.LinkClicked
        Me.TopMost = False
        impime_quittance_AMC(CurrentFactureVitale.num, CurrentFactureVenteDirecte.NumVenteDirecte)
        Me.TopMost = True
        Me.BringToFront()
        Me.Focus()
    End Sub

    Private Sub Ticket_Caisse_LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Ticket_Caisse_LinkLabel1.LinkClicked
        impime_Ticket_Caisse(CurrentFactureVitale.num, CurrentFactureVenteDirecte.NumVenteDirecte)

    End Sub

    
    Private Sub Transmettre_CERFA_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Transmettre_CERFA.LinkClicked
        Dim impr As New CERFA
        impr.cerfa_médecin = False
        impr.num_facture_SV = CurrentFactureVitale.num
        impr.num_facture_VD = 0
        impr.Type_Papier_CERFA = True
        impr.debile = True
        impr.ShowDialog()
        'impr.Visible = True
    End Sub

    Private Sub Imprimer_facture_CheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles Imprimer_facture_CheckBox.CheckedChanged

    End Sub
End Class