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

    Private Sub impression_Comptoir_Config_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        For Each pkInstalledPrinters In _
        PrinterSettings.InstalledPrinters()
            default_printerComboBox1.Items.Add(pkInstalledPrinters)
        Next pkInstalledPrinters
        Pharmacie_Présentation_RichTextBox.Text = InfoPro.Pharmacie.présentation
    End Sub

    Public Sub Font_ComboBox1_Enter(sender As Object, e As EventArgs) Handles Font_ComboBox1.Enter
        Dim fonts As New InstalledFontCollection
        Font_ComboBox1.Items.Clear()
        For Each one As FontFamily In fonts.Families
            Font_ComboBox1.Items.Add(one.Name)
        Next
    End Sub

#Region "CHEQUE"

    Public Function Cheques_drawstring() As String
        Dim drawString = ""
        Dim somme_en_lettre As String
        somme_en_lettre = nombre_en_lettre(Int(reste_à_payer_plus_crédits_plus_encaissements_en_attente)) & " euros et " & _
            nombre_en_lettre((reste_à_payer_plus_crédits_plus_encaissements_en_attente - Int(reste_à_payer_plus_crédits_plus_encaissements_en_attente)) * 100) & " cents"
        For r = 1 To InfoPro.Chèque.Lignes_blanches
            drawString = drawString + Chr(10)
        Next
        drawString = drawString + "   " + somme_en_lettre + Chr(10) + Chr(10)
        drawString = drawString + "   " + InfoPro.Chèque.A + Chr(10)
        For r = 1 To InfoPro.Chèque.decalage_droite
            drawString = drawString + " "
        Next
        drawString = drawString + reste_à_payer_plus_crédits_plus_encaissements_en_attente.ToString + "€" + Chr(10) + Chr(10)
        For r = 1 To InfoPro.Chèque.decalage_droite
            drawString = drawString + " "
        Next
        drawString = drawString + InfoPro.Chèque.FAIT_A + Chr(10)
        For r = 1 To InfoPro.Chèque.decalage_droite
            drawString = drawString + " "
        Next
        drawString = drawString + Now.ToShortDateString()
        Return drawString

    End Function


    Public Sub Apperçu_Button_Click(sender As Object, e As EventArgs) Handles Apperçu_Button.Click
        Try

            reste_à_payer_plus_crédits_plus_encaissements_en_attente = (99.99)
            Chèques_RichTextBox.Clear()
            InfoPro.Chèque.Lignes_blanches = Lignes_blanches_TextBox5.Text
            InfoPro.Chèque.decalage_droite = decalage_droiteTextBox.Text
            InfoPro.Chèque.default_printer = default_printerComboBox1.Text
            InfoPro.Chèque.A = A_TextBox1.Text
            InfoPro.Chèque.FAIT_A = FAIT_A_TextBox2.Text
            InfoPro.Chèque.Font = Font_ComboBox1.Text
            InfoPro.Chèque.FontSize = SizeFontTextBox4.Text
            Chèques_RichTextBox.Font = New Font(InfoPro.Chèque.Font, InfoPro.Chèque.FontSize, FontStyle.Regular)
            Chèques_RichTextBox.Text = Cheques_drawstring()


        Catch ex As Exception

        End Try
    End Sub
    Public Sub Imprimer_button_Click(sender As Object, e As EventArgs) Handles Imprimer_button.Click

        InfoPro.Chèque.default_printer = default_printerComboBox1.Text
        reste_à_payer_plus_crédits_plus_encaissements_en_attente = (99.99)
        Imprim_Chèque()

    End Sub





    Public Sub Imprim_Chèque()
        Try
            If InfoPro.Chèque.default_printer <> "" Then
                Chèques_PrintDocument.PrinterSettings.PrinterName = InfoPro.Chèque.default_printer
                Chèques_PrintDocument.Print()
            ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Chèques_PrintDocument.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
                Chèques_PrintDocument.Print()
            End If
        Catch ex As Exception

        End Try


    End Sub

    Public Sub Chèques_PrintDocument_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles Chèques_PrintDocument.PrintPage

        Dim drawFont As New Font(InfoPro.Chèque.Font, InfoPro.Chèque.FontSize, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(Cheques_drawstring(), drawFont, drawBrush, 10, 10)
    End Sub
#End Region
#Region "TICKET VITALE"


    Public Sub Imprim_Ticker_Vitale()
        Try
            If InfoPro.Impr_Ordo.default_printer <> "" Then
                Ticket_Vitale_PrintDocument.PrinterSettings.PrinterName = InfoPro.Impr_Ordo.default_printer
                Ticket_Vitale_PrintDocument.Print()
            ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Ticket_Vitale_PrintDocument.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
                Ticket_Vitale_PrintDocument.Print()
            End If
        Catch ex As Exception

        End Try


    End Sub

    Public Sub Ticket_Vitale_PrintDocument_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles Ticket_Vitale_PrintDocument.PrintPage
        Dim drawFont As New Font(InfoPro.Impr_Ordo.Font, InfoPro.Impr_Ordo.FontSize, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)
        Dim Strg = Ticket_Vitale_Entête_PiedPagedrawstring("Entête") & vbCrLf & Ticket_Vitale_Ligne_drawstring() & vbCrLf & Ticket_Vitale_Entête_PiedPagedrawstring("Pied")

        'VACCINATION_______________________________________________________________
        Try
            Dim vacc As Boolean = False
            For r = 1 To CurrentFactureVitale.TabLigneFacture.Length - 1
                If CurrentFactureVitale.TabLigneFacture(r).G1610C4 = "VGP" Then
                    Strg = Strg & vbCrLf & vbCrLf & "Attestation de Vaccination" & vbCrLf & _
                         "executant: " & current_User.ID & vbCrLf
                    vacc = True
                    Exit For
                End If
            Next
            If vacc = True Then

                For r = 0 To COMPTOIR_MAIN.Vente.RowCount - 2
                    If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value.ToString = "PREV" And COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, r).Value.ToString <> "" Then
                        Strg = Strg & "Produit: " & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, r).Value.ToString & " " & vbCrLf & "         " & _
                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, r).Value.ToString & "   " & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_lot.Index, r).Value & vbCrLf
                    End If
                Next
            End If
        Catch ex As Exception
        End Try
        'VACCINATION_FIN______________________________________________________________

        e.Graphics.DrawString(Strg, drawFont, drawBrush, 10, 10)
        VenteForm.drawString = Strg

    End Sub

    Public Function Ticket_Vitale_Entête_PiedPagedrawstring(ByVal Entête_ou_Pied As String) As String
        'Facture: @Num_Facture @Date_Facture
        '@Mode_TP
        'Prescripteur: @Prescripteur @Date_prescription
        'Assuré: @Assuré
        'Bénéficiaire: @Bénéficiaire
        'AMO: @AMO
        'Org Compl: @AMC
        'Num adhérent: @Num_adhérent
        'Renouvellement: @Renouvellement
        'Total:@Total_FSE
        'AMO:@Total_AMO  AMC:@Total_AMC  
        'Total restant assuré:@Total_restant_assuré
        Dim drawString = ""
        If Entête_ou_Pied = "Entête" Then
            drawString = InfoPro.Impr_Ordo.EnTete_Template
        ElseIf Entête_ou_Pied = "Pied" Then
            drawString = InfoPro.Impr_Ordo.PiedPage_Template
        End If
        drawString = Replace(drawString, "@Pharmacie_Présentation", InfoPro.Pharmacie.présentation)
        drawString = Replace(drawString, "@Num_Facture", CurrentFactureVitale.G1110C1.ToString)
        drawString = Replace(drawString, "@Date_Facture", Mid(CurrentFactureVitale.G1110C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1110C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1110C3, 1, 4))
        If CurrentFactureVitale.Bénéficiaire = "CONTRACEPTIF URGENCE MINEURE" Then
            drawString = Replace(drawString, "@Prescripteur", Config.Data_ContaceptifUrgence_NumPrecripteur & " " & Config.Data_ContaceptifUrgence_CleNumPrecripteur)
        Else
            Dim prescr = BDD.PrescripteursTableAdapter.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0)
            drawString = Replace(drawString, "@Prescripteur", prescr.NomPrénom & " " & prescr.Numidentification)
        End If
        If CurrentFactureVitale.G1211C3 <> "" Then
            drawString = Replace(drawString, "@Date_prescription", Mid(CurrentFactureVitale.G1211C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1211C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1211C3, 1, 4))
        ElseIf CurrentFactureVitale.G1213C4 <> "" Then
            drawString = Replace(drawString, "@Date_prescription", Mid(CurrentFactureVitale.G1213C4, 7, 2) + "/" + Mid(CurrentFactureVitale.G1213C4, 5, 2) + "/" + Mid(CurrentFactureVitale.G1213C4, 1, 4))
        ElseIf CurrentFactureVitale.G1214C4 <> "" Then
            drawString = Replace(drawString, "@Date_prescription", Mid(CurrentFactureVitale.G1214C4, 7, 2) + "/" + Mid(CurrentFactureVitale.G1214C4, 5, 2) + "/" + Mid(CurrentFactureVitale.G1214C4, 1, 4))
        End If
        drawString = Replace(drawString, "@Assuré", CurrentFactureVitale.G1130C2 + CurrentFactureVitale.G1130C3 + "  " + CurrentFactureVitale.Assuré)
        drawString = Replace(drawString, "@Bénéficiaire", CurrentFactureVitale.Bénéficiaire + Chr(10) + "né le " + DateVitale_To_DateString(CurrentFactureVitale.G1130C4) + ", rang " + CurrentFactureVitale.G1130C5)
        drawString = Replace(drawString, "@AMO", CurrentFactureVitale.G1310C1 + " " + CurrentFactureVitale.G1310C2 + " " + CurrentFactureVitale.G1310C3 + " " + BDD.AMOTableAdapter.SelectLibellé(CurrentFactureVitale.G1310C1, CurrentFactureVitale.G1310C2, CurrentFactureVitale.G1310C3))
        If BDD.AMC_OrganismesTableAdapter.GetDataBy_Num(CurrentFactureVitale.G1321C2).Rows.Count > 0 Then
            drawString = Replace(drawString, "@AMC", CurrentFactureVitale.G1321C2 & " " & BDD.AMC_OrganismesTableAdapter.GetDataBy_Num(CurrentFactureVitale.G1321C2).Item(0).Intitulé.ToString)
        Else
            drawString = Replace(drawString, "@AMC", CurrentFactureVitale.G1321C2)
        End If
        drawString = Replace(drawString, "@Num_adhérent", CurrentFactureVitale.G1321C3)
        If Not CurrentFactureVitale.TabLigneFacture(1).G1850C2 Is Nothing Then
            If CurrentFactureVitale.TabLigneFacture(1).G1850C2 <> "" Then
                drawString = Replace(drawString, "@Renouvellement", CurrentFactureVitale.TabLigneFacture(1).G1850C2)
            Else
                drawString = Replace(drawString, "@Renouvellement", "0")
            End If
        Else
            drawString = Replace(drawString, "@Renouvellement", "0")
        End If
        drawString = Replace(drawString, "@Total_FSE", (CurrentFactureVitale.G1910C2 / 100).ToString)
        drawString = Replace(drawString, "@Total_AMO", (CurrentFactureVitale.G1910C3 / 100).ToString)
        drawString = Replace(drawString, "@Total_AMC", (CurrentFactureVitale.G1910C6 / 100).ToString)
        drawString = Replace(drawString, "@Total_restant_assuré", (Ticket_vitale_total_restant_assuré / 100).ToString)

        If CurrentFactureVitale.TP_AMO = False And CurrentFactureVitale.TP_AMC = False Then
            drawString = Replace(drawString, "@Mode_TP", "Pas de tiers-payant")
        ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = False Then
            drawString = Replace(drawString, "@Mode_TP", "Tiers-payant AMO seulement")
        ElseIf CurrentFactureVitale.TP_AMO = True And CurrentFactureVitale.TP_AMC = True Then
            drawString = Replace(drawString, "@Mode_TP", "Tiers-payant")
        ElseIf CurrentFactureVitale.TP_AMO = False And CurrentFactureVitale.TP_AMC = True Then
            drawString = Replace(drawString, "@Mode_TP", "Tiers-payant AMC seulement")
        End If
        Select Case CurrentFactureVitale.ModeSecur
            Case "1"
                drawString = Replace(drawString, "@Mode_Secur", "SESAM sans Vitale")
            Case "3"
                drawString = Replace(drawString, "@Mode_Secur", "Sécurisée")
            Case "4"
                drawString = Replace(drawString, "@Mode_Secur", "désynchronisation")
            Case "5"
                drawString = Replace(drawString, "@Mode_Secur", "dégradée")
            Case Else
                drawString = Replace(drawString, "@Mode_Secur", "")
        End Select
        Return (drawString)

    End Function

    Public Function Ticket_Vitale_Ligne_drawstring() As String
        '@Quantité @Désignation @Code_Produit @Prix_Unitaire @Tarif_Remb @Taux_Remb @Code_Acte @LPP 
        Dim drawString = ""
        Dim ligne_template = InfoPro.Impr_Ordo.Lignes_Template
        Dim actes = BDD.ActesTableAdapter.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
            Dim ligne = Replace(ligne_template, "@Quantité", Quantité)
            ligne = Replace(ligne, "@Désignation", Désignation)
            ligne = Replace(ligne, "@Code_Produit", cip_ean13)
            ligne = Replace(ligne, "@Prix_Unitaire", Prix_Unitaire)
            ligne = Replace(ligne, "@Tarif_Remb", Tarif_Remboursement)
            ligne = Replace(ligne, "@Taux_Remb", TauxRmbrsmnt)
            ligne = Replace(ligne, "@Code_Acte", CodeActe)
            ligne = Replace(ligne, "@LPP", LPP_Type_prestation + " " + LPP_Ref + " " + LPP_Quantité)
            drawString = drawString & ligne & vbCrLf
        Next

        Return drawString
    End Function

#End Region
    Public Sub Enregistrer_Button_Click(sender As Object, e As EventArgs) Handles Enregistrer_Button.Click
        If TabControl1.SelectedIndex = 0 Then
            Bandeau_info_bas_show("Enregistrement Présentation Pharmacie")
            InfoPro.Pharmacie.présentation = Pharmacie_Présentation_RichTextBox.Text
            InfoPro.Save()
            System.Threading.Thread.Sleep(1000)
            Bandeau_info_bas_hide()
        ElseIf TabControl1.SelectedIndex = 1 Then
            Bandeau_info_bas_show("Enregistrement Présentation Chèques")

            InfoPro.Chèque.A = A_TextBox1.Text
            InfoPro.Chèque.FAIT_A = FAIT_A_TextBox2.Text
            InfoPro.Chèque.Font = Font_ComboBox1.Text
            InfoPro.Chèque.FontSize = Val(SizeFontTextBox4.Text)
            InfoPro.Chèque.default_printer = default_printerComboBox1.Text
            InfoPro.Chèque.decalage_droite = Val(decalage_droiteTextBox.Text)
            InfoPro.Chèque.Lignes_blanches = Val(Lignes_blanches_TextBox5.Text)
            InfoPro.Save()
            System.Threading.Thread.Sleep(1000)
            Bandeau_info_bas_hide()

        ElseIf TabControl1.SelectedIndex = 2 Then
            Bandeau_info_bas_show("Enregistrement Présentation Ticket Vitale")

            InfoPro.Impr_Ordo.EnTete_Template = Ticket_vitale_EnTete_RichTextBox.Text
            InfoPro.Impr_Ordo.PiedPage_Template = Ticket_vitale_PiedPage_RichTextBox.Text()
            InfoPro.Impr_Ordo.Lignes_Template = Ticket_vitale_Lignes_RichTextBox.Text
            InfoPro.Impr_Ordo.Font = Font_ComboBox1.Text
            InfoPro.Impr_Ordo.FontSize = Val(SizeFontTextBox4.Text)
            InfoPro.Impr_Ordo.default_printer = default_printerComboBox1.Text
            InfoPro.Save()
            System.Threading.Thread.Sleep(1000)
            Bandeau_info_bas_hide()

        ElseIf TabControl1.SelectedIndex = 3 Then
            Bandeau_info_bas_show("Enregistrement Présentation Ticket de dûs")
            InfoPro.Ticket_Dus.EnTete_Template = Ticket_dus_entête_RichTextBox.Text
            InfoPro.Ticket_Dus.Font = Font_ComboBox1.Text
            InfoPro.Ticket_Dus.FontSize = Val(SizeFontTextBox4.Text)
            InfoPro.Ticket_Dus.default_printer = default_printerComboBox1.Text
            InfoPro.Ticket_Dus.Lignes_Template = Ticket_dus_Ligne_RichTextBox.Text
            InfoPro.Save()
            System.Threading.Thread.Sleep(1000)
            Bandeau_info_bas_hide()

        ElseIf TabControl1.SelectedIndex = 4 Then
            Bandeau_info_bas_show("Enregistrement Présentation Ticket de dûs")
            InfoPro.Ticket_Promis.EnTete_Template = Ticket_Promis_entête_RichTextBox.Text
            InfoPro.Ticket_Promis.Font = Font_ComboBox1.Text
            InfoPro.Ticket_Promis.FontSize = Val(SizeFontTextBox4.Text)
            InfoPro.Ticket_Promis.default_printer = default_printerComboBox1.Text
            InfoPro.Ticket_Promis.Lignes_Template = Ticket_Promis_Ligne_RichTextBox.Text
            InfoPro.Save()
            System.Threading.Thread.Sleep(1000)
            Bandeau_info_bas_hide()
        End If
    End Sub


    Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
        Select Case TabControl1.SelectedIndex
            Case 0
                Pharmacie_Présentation_RichTextBox.Text = InfoPro.Pharmacie.présentation
            Case 1
                A_TextBox1.Text = InfoPro.Chèque.A
                FAIT_A_TextBox2.Text = InfoPro.Chèque.FAIT_A
                decalage_droiteTextBox.Text = InfoPro.Chèque.decalage_droite.ToString
                Font_ComboBox1.Text = InfoPro.Chèque.Font
                SizeFontTextBox4.Text = InfoPro.Chèque.FontSize.ToString
                Lignes_blanches_TextBox5.Text = InfoPro.Chèque.Lignes_blanches
                default_printerComboBox1.Text = InfoPro.Chèque.default_printer

            Case 2
                Ticket_vitale_EnTete_RichTextBox.Text = InfoPro.Impr_Ordo.EnTete_Template
                Ticket_vitale_PiedPage_RichTextBox.Text = InfoPro.Impr_Ordo.PiedPage_Template
                Ticket_vitale_Lignes_RichTextBox.Text = InfoPro.Impr_Ordo.Lignes_Template
                Font_ComboBox1.Text = InfoPro.Impr_Ordo.Font
                SizeFontTextBox4.Text = InfoPro.Impr_Ordo.FontSize.ToString
                default_printerComboBox1.Text = InfoPro.Impr_Ordo.default_printer

            Case 3
                Ticket_dus_entête_RichTextBox.Text = InfoPro.Ticket_Dus.EnTete_Template
                Font_ComboBox1.Text = InfoPro.Ticket_Dus.Font
                SizeFontTextBox4.Text = InfoPro.Ticket_Dus.FontSize.ToString
                default_printerComboBox1.Text = InfoPro.Ticket_Dus.default_printer
                Ticket_dus_Ligne_RichTextBox.Text = InfoPro.Ticket_Dus.Lignes_Template

            Case 4
                Ticket_Promis_entête_RichTextBox.Text = InfoPro.Ticket_Promis.EnTete_Template
                Font_ComboBox1.Text = InfoPro.Ticket_Promis.Font
                SizeFontTextBox4.Text = InfoPro.Ticket_Promis.FontSize.ToString
                default_printerComboBox1.Text = InfoPro.Ticket_Promis.default_printer
                Ticket_Promis_Ligne_RichTextBox.Text = InfoPro.Ticket_Promis.Lignes_Template
        End Select



    End Sub

#Region "BOUTONS VARIABLES"


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("Facture: @Num_Facture @Date_Facture" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("Facture: @Num_Facture @Date_Facture" & vbCrLf)
        End If
    End Sub



    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("@Mode_TP" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("@Mode_TP" & vbCrLf)
        End If
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("Prescripteur: @Prescripteur @Date_prescription" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("Prescripteur: @Prescripteur @Date_prescription" & vbCrLf)
        End If
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("Assuré: @Assuré" & vbCrLf & "Bénéficiaire: @Bénéficiaire" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("Assuré: @Assuré" & vbCrLf & "Bénéficiaire: @Bénéficiaire" & vbCrLf)
        End If
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("AMO: @AMO" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("AMO: @AMO" & vbCrLf)
        End If
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("Org Compl: @AMC" & vbCrLf & "Num adhérent: @Num_adhérent" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("Org Compl: @AMC" & vbCrLf & "Num adhérent: @Num_adhérent" & vbCrLf)
        End If
    End Sub

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("Renouvellement: @Renouvellement" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("Renouvellement: @Renouvellement" & vbCrLf)
        End If
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("Total:@Total_FSE" & vbCrLf & "AMO:@Total_AMO  AMC:@Total_AMC" & vbCrLf & "Total restant assuré:@Total_restant_assuré" & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("Total:@Total_FSE" & vbCrLf & "AMO:@Total_AMO  AMC:@Total_AMC" & vbCrLf & "Total restant assuré:@Total_restant_assuré" & vbCrLf)
        End If
    End Sub

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Quantité ")
    End Sub

    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Désignation ")
    End Sub

    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Code_Produit ")
    End Sub

    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Prix_Unitaire ")
    End Sub

    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Tarif_Remb ")
    End Sub

    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Taux_Remb ")
    End Sub

    Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@Code_Acte ")
    End Sub

    Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
        Ticket_vitale_Lignes_RichTextBox.AppendText("@LPP ")
    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("@Mode_Secur " & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("@Mode_Secur " & vbCrLf)
        End If
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If Entête_RadioButton.Checked Then
            Ticket_vitale_EnTete_RichTextBox.AppendText("@Pharmacie_Présentation " & vbCrLf)
        ElseIf PiedPage_RadioButton.Checked Then
            Ticket_vitale_PiedPage_RichTextBox.AppendText("@Pharmacie_Présentation " & vbCrLf)
        End If
    End Sub
#End Region

#Region "TICKET DUS"


    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Ticket_dus_entête_RichTextBox.AppendText("@Pharmacie_Présentation " & vbCrLf)
    End Sub

    Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
        Ticket_dus_entête_RichTextBox.AppendText("Bénéficiaire: @Bénéficiaire" & vbCrLf)
    End Sub


    Private Sub Button21_Click(sender As Object, e As EventArgs) Handles Button21.Click
        Ticket_dus_entête_RichTextBox.AppendText("@Date" & vbCrLf)
    End Sub

    Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click
        Ticket_dus_Ligne_RichTextBox.AppendText("@Quantité ")
    End Sub

    Private Sub Button23_Click(sender As Object, e As EventArgs) Handles Button23.Click
        Ticket_dus_Ligne_RichTextBox.AppendText("@Produit ")
    End Sub

    Private Sub Button22_Click(sender As Object, e As EventArgs) Handles Button22.Click
        Ticket_dus_Ligne_RichTextBox.AppendText("@Code ")
    End Sub

    Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
        Ticket_dus_entête_RichTextBox.AppendText("@Opérateur" & vbCrLf)
    End Sub

    Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click
        Ticket_dus_entête_RichTextBox.AppendText("@Type_Paiement" & vbCrLf)
    End Sub
    Public Function Ticket_Dus_drawstring() As String
        'impression des dus
        Dim Dus_drawString = ""
        If Not liste_du Is Nothing Then
            If liste_du.Count > 0 Then
                Dus_drawString = Replace(InfoPro.Ticket_Dus.EnTete_Template & vbCrLf, "@Pharmacie_Présentation", InfoPro.Pharmacie.présentation)
                Dus_drawString = Replace(Dus_drawString, "@Opérateur", current_User.ID)
                If CurrentBenéficiaire.G101C8 <> "" Then
                    Dus_drawString = Replace(Dus_drawString, "@Bénéficiaire", CurrentBenéficiaire.G104C1 & " " & CurrentBenéficiaire.G104C3 & " " & CurrentBenéficiaire.G101C8)

                Else
                    Dus_drawString = Replace(Dus_drawString, "@Bénéficiaire", COMPTOIR_MAIN.ComboBoxLECTURE_VITALE.Text)
                End If
                Try
                    If COMPTOIR_MAIN.Vitale_téléphone_TextBox.Text <> "" Then
                        Dus_drawString = Dus_drawString & vbCrLf & "tel: " & COMPTOIR_MAIN.Vitale_téléphone_TextBox.Text & vbCrLf
                    End If
                    If COMPTOIR_MAIN.Vitale_adresse_TextBox.Text <> "" Then
                        Dus_drawString = Dus_drawString & vbCrLf & COMPTOIR_MAIN.Vitale_adresse_TextBox.Text & vbCrLf
                    End If
                Catch ex As Exception

                End Try
                Dus_drawString = Replace(Dus_drawString, "@Date", Now.ToShortDateString & " " & Now.ToShortTimeString)
                If VenteForm.Visible = True Then
                    Dus_drawString = Replace(Dus_drawString, "@Type_Paiement", VenteForm.Paiement_Type_Button.Text)
                Else
                    Dus_drawString = Replace(Dus_drawString, "@Type_Paiement", "")
                End If


                For Each du_ In liste_du
                    Dus_drawString = Dus_drawString & InfoPro.Ticket_Dus.Lignes_Template & vbCrLf
                    Dus_drawString = Replace(Dus_drawString, "@Quantité", du_.Quantité_Du.ToString)
                    Dus_drawString = Replace(Dus_drawString, "@Produit", du_.désignation)
                    Dim code = ""
                    If du_.cip13 <> "" Then
                        code = du_.cip13
                    ElseIf du_.cip7 <> "" Then
                        code = du_.cip7
                    End If
                    Dus_drawString = Replace(Dus_drawString, "@Code", code)

                Next
            End If
        End If
        MsgBox(Dus_drawString)
        Return Dus_drawString
    End Function
    Public Sub Imprim_Ticket_Dus()
        Try
            If InfoPro.Ticket_Dus.default_printer <> "" Then
                Ticket_Dus_PrintDocument.PrinterSettings.PrinterName = InfoPro.Ticket_Dus.default_printer
                Ticket_Dus_PrintDocument.Print()
            ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Ticket_Dus_PrintDocument.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
                Ticket_Dus_PrintDocument.Print()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Ticket_Dus_PrintDocument_PrintPage(sender As Object, e As PrintPageEventArgs) Handles Ticket_Dus_PrintDocument.PrintPage
        Dim drawFont As New Font(InfoPro.Ticket_Dus.Font, InfoPro.Ticket_Dus.FontSize, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(Ticket_Dus_drawstring(), drawFont, drawBrush, 10, 10)
    End Sub
#End Region

#Region "TICKET PROMIS"



    Private Sub Button33_Click(sender As Object, e As EventArgs) Handles Button33.Click
        Ticket_Promis_entête_RichTextBox.AppendText("@Pharmacie_Présentation " & vbCrLf)
    End Sub

    Private Sub Button28_Click(sender As Object, e As EventArgs) Handles Button28.Click
        Ticket_Promis_entête_RichTextBox.AppendText("@Opérateur" & vbCrLf)
    End Sub

    Private Sub Button34_Click(sender As Object, e As EventArgs) Handles Button34.Click
        Ticket_Promis_entête_RichTextBox.AppendText("Bénéficiaire: @Bénéficiaire" & vbCrLf)
    End Sub

    Private Sub Button32_Click(sender As Object, e As EventArgs) Handles Button32.Click
        Ticket_Promis_entête_RichTextBox.AppendText("@Date" & vbCrLf)
    End Sub

    Private Sub Button31_Click(sender As Object, e As EventArgs) Handles Button31.Click
        Ticket_Promis_Ligne_RichTextBox.AppendText("@Quantité ")
    End Sub

    Private Sub Button30_Click(sender As Object, e As EventArgs) Handles Button30.Click
        Ticket_Promis_Ligne_RichTextBox.AppendText("@Code ")
    End Sub

    Private Sub Button29_Click(sender As Object, e As EventArgs) Handles Button29.Click
        Ticket_Promis_Ligne_RichTextBox.AppendText("@Code ")
    End Sub
    Public Function Ticket_Promis_drawstring() As String
        'impression des dus
        Dim Promis_drawString = ""
        If Not liste_produits_réservés Is Nothing Then
            If liste_produits_réservés.Count > 0 Then
                Promis_drawString = current_User.ID & vbCrLf & Replace(InfoPro.Ticket_Promis.EnTete_Template, "@Pharmacie_Présentation", InfoPro.Pharmacie.présentation)
                Promis_drawString = Replace(Promis_drawString, "@Opérateur", current_User.ID)
                If CurrentBenéficiaire.G101C8 <> "" Then
                    Promis_drawString = Replace(Promis_drawString, "@Bénéficiaire", CurrentBenéficiaire.G104C1 & " " & CurrentBenéficiaire.G104C3 & " " & CurrentBenéficiaire.G101C8)
                Else
                    Promis_drawString = Replace(Promis_drawString, "@Bénéficiaire", COMPTOIR_MAIN.ComboBoxLECTURE_VITALE.Text)
                End If
                Promis_drawString = Replace(Promis_drawString, "@Date", Now.ToShortDateString & " " & Now.ToShortTimeString)


                For Each Produit_réservé In liste_produits_réservés
                    Promis_drawString = Promis_drawString & InfoPro.Ticket_Promis.Lignes_Template & vbCrLf
                    Promis_drawString = Replace(Promis_drawString, "@Quantité", Produit_réservé.Quantité_Du.ToString)
                    Promis_drawString = Replace(Promis_drawString, "@Produit", Produit_réservé.désignation)
                    Dim code = ""
                    If Produit_réservé.cip13 <> "" Then
                        code = Produit_réservé.cip13
                    ElseIf Produit_réservé.cip7 <> "" Then
                        code = Produit_réservé.cip7
                    End If
                    Promis_drawString = Replace(Promis_drawString, "@Code", code)

                Next
            End If
        End If
        Return Promis_drawString
    End Function
    Public Sub Imprim_Ticket_Promis()
        Try
            If InfoPro.Ticket_Promis.default_printer <> "" Then
                Ticket_Promis_PrintDocument.PrinterSettings.PrinterName = InfoPro.Ticket_Promis.default_printer
                Ticket_Promis_PrintDocument.Print()
            ElseIf PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Ticket_Promis_PrintDocument.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
                Ticket_Promis_PrintDocument.Print()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Ticket_Promis_PrintDocument_PrintPage(sender As Object, e As PrintPageEventArgs) Handles Ticket_Promis_PrintDocument.PrintPage
        Dim drawFont As New Font(InfoPro.Ticket_Promis.Font, InfoPro.Ticket_Promis.FontSize, FontStyle.Regular)
        Dim drawBrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(Ticket_Promis_drawstring(), drawFont, drawBrush, 10, 10)
    End Sub
#End Region
End Class