' 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

Public Class VenteForm

    Private drawString As String
    Private X As Integer
    Private Y As Integer
    Private PrintFont As String
    Private SizeFont As Integer
    Private PrintColor As Color
    Public total_restant_assuré As Single



    Private Sub afficheinfovente()
        RichTextBox1.AppendText("FACTURE VITALE:")
        RichTextBox1.AppendText(Chr(10) + "Total des montants facturés:" + (CurrentFactureVitale.G1910C2 / 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) + "______________________________________")
        RichTextBox1.AppendText(Chr(10) + "VENTE DIRECTE:")
        RichTextBox1.AppendText(Chr(10) + "Total des montants facturés:" + CurrentFactureVenteDirecte.Total.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)
            RichTextBox1.AppendText(Chr(10) + "A PAYER:" + ((CurrentFactureVitale.G1910C2 + (CurrentFactureVenteDirecte.Total * 100)) / 100).ToString)
        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)
            RichTextBox1.AppendText(Chr(10) + "A PAYER:" + (((CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3) + (CurrentFactureVenteDirecte.Total * 100)) / 100).ToString)
        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)
            RichTextBox1.AppendText(Chr(10) + "A PAYER:" + (((CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C3 - CurrentFactureVitale.G1910C6) + (CurrentFactureVenteDirecte.Total * 100)) / 100).ToString)
        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-payan sur la part complémentaire seulement: reste " + (total_restant_assuré / 100).ToString)
            RichTextBox1.AppendText(Chr(10) + "A PAYER:" + (((CurrentFactureVitale.G1910C2 - CurrentFactureVitale.G1910C6) + (CurrentFactureVenteDirecte.Total * 100)) / 100).ToString)
        End If


    End Sub


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

#Region "IMPRESSIONS"

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim drawFont As New Font(PrintFont, SizeFont)
        Dim drawBrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(drawString, drawFont, drawBrush, X, Y)

    End Sub

    'Quittance
    Private Sub ButtonQuittance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonQuittance.Click
        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)

        drawString = EnTete + Chr(10) + Chr(10) + Chr(10)

        drawString = drawString & "FSE N°:" & CurrentFactureVitale.G1110C1 & "         Date:" & Mid(CurrentFactureVitale.G1110C3, 7, 2) & "/" & Mid(CurrentFactureVitale.G1110C3, 5, 2) & "/" & Mid(CurrentFactureVitale.G1110C3, 1, 4)
        drawString = drawString + Chr(10) + Chr(10)
        drawString = drawString & "Régime:" & CurrentFactureVitale.G1310C1 & "   Caisse gestionnaire:" & CurrentFactureVitale.G1310C2 & "   Centre gestionnaire:" & CurrentFactureVitale.G1310C3 & Chr(10)
        drawString = drawString & "Organisme destinataire:" & CurrentFactureVitale.G1310C4 & "   Centre informatique:" & CurrentFactureVitale.G1310C5 & Chr(10) & Chr(10)
        drawString = drawString & "N° organisme complémentaire:" & CurrentFactureVitale.G1321C2 & Chr(10) & Chr(10)
        drawString = drawString & "NIR + clé:" & CurrentFactureVitale.G1130C2 & " " & CurrentFactureVitale.G1130C3 & Chr(10)
        drawString = drawString & "Bénéficiaire:" & Me.VitaleTableAdapter1.GetDataBénéficiaire(CurrentFactureVitale.G1130C2, CurrentFactureVitale.G1130C4, CurrentFactureVitale.G1130C5, CurrentFactureVitale.G1130C6).Item(0).G104C1 & " " & Me.VitaleTableAdapter1.GetDataBénéficiaire(CurrentFactureVitale.G1130C2, CurrentFactureVitale.G1130C4, CurrentFactureVitale.G1130C5, CurrentFactureVitale.G1130C6).Item(0).G104C2 & " " & Me.VitaleTableAdapter1.GetDataBénéficiaire(CurrentFactureVitale.G1130C2, CurrentFactureVitale.G1130C4, CurrentFactureVitale.G1130C5, CurrentFactureVitale.G1130C6).Item(0).G104C3 & " né(e) le " & Mid(Me.VitaleTableAdapter1.GetDataBénéficiaire(CurrentFactureVitale.G1130C2, CurrentFactureVitale.G1130C4, CurrentFactureVitale.G1130C5, CurrentFactureVitale.G1130C6).Item(0).G104C12, 7, 2) & "/" & Mid(Me.VitaleTableAdapter1.GetDataBénéficiaire(CurrentFactureVitale.G1130C2, CurrentFactureVitale.G1130C4, CurrentFactureVitale.G1130C5, CurrentFactureVitale.G1130C6).Item(0).G104C12, 5, 2) & "/" & Mid(Me.VitaleTableAdapter1.GetDataBénéficiaire(CurrentFactureVitale.G1130C2, CurrentFactureVitale.G1130C4, CurrentFactureVitale.G1130C5, CurrentFactureVitale.G1130C6).Item(0).G104C12, 1, 4) + Chr(10) + Chr(10)
        drawString = drawString & "Prescripteur:" & Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).NomPrénom & Chr(10)
        drawString = drawString & "Num:" & Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).Numidentification & Chr(10)
        drawString = drawString & "Num RPPS:" & Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).NumRPPS & Chr(10)
        drawString = drawString & "num Structure:" & Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).numStructure & Chr(10) & Chr(10)
        '____________________________________________________________________ 
        'détail
        drawString = drawString + "-------------------------------" + Chr(10) + "Qté|PrixUnit|T.Remb|Prest|TxRb|" + Chr(10) + "-------------------------------"
        Dim mydatatable As DataTable = Me.ActesTableAdapter1.GetDataByNumFacturesSV(CurrentFactureVitale.G1110C1)
        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 = ""
            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 = Mid(mydatatable(r).Item(c).ToString, 1, 24)
                    Case "CodeActe"
                        CodeActe = mydatatable(r).Item(c).ToString
                    Case "TauxRmbrsmnt"
                        TauxRmbrsmnt = 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

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



        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
            If MsgBox("Inscrire les ventes directes?", 36) = MsgBoxResult.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 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 Imprime_FSE(ByVal Document As String)
        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)

        drawString = EnTete + 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)
        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
        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) + "Num Org Compl: " + CurrentFactureVitale.G1321C2 + "   Num adhérent: " + CurrentFactureVitale.G1321C3
        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
        Dim mydatatable As DataTable = Me.ActesTableAdapter1.GetDataByNumFacturesSV(CurrentFactureVitale.G1110C1)
        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
            If MsgBox("Inscrire les ventes directes?", 36) = MsgBoxResult.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 PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            PrintPreviewDialog1.ShowDialog()
            If PrintPreviewDialog1.DialogResult = DialogResult.OK Then
                PrintDocument1.Print()
            End If
        End If
    End Sub
 

    'Ordonnance
    Private Sub Button_Ordonance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Ordonance.Click
        Imprime_FSE("Impr_Ordo")

        'Dim ConfigXml As New XmlDocument
        'ConfigXml.Load("InfoPro.xml")
        'Dim nodeliste As XmlNodeList
        'nodeliste = ConfigXml.GetElementsByTagName("Impr_Ordo")
        '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)

        'drawString = EnTete + 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)
        'drawString = drawString + Chr(10) + "Prescripteur: " + Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).NomPrénom
        'drawString = drawString + Chr(10) + "NIR: " + CurrentFactureVitale.G1130C2 + CurrentFactureVitale.G1130C3 + "  " + CurrentFactureVitale.Bénéficiaire
        'drawString = drawString + Chr(10) + CurrentFactureVitale.G1310C1 + " " + CurrentFactureVitale.G1310C2 + " " + CurrentFactureVitale.G1310C3 + " " + Me.AmoTableAdapter1.SelectLibellé(CurrentFactureVitale.G1310C1, CurrentFactureVitale.G1310C2, CurrentFactureVitale.G1310C3)
        'drawString = drawString + Chr(10) + Chr(10) + "----------------------------------------------------" + Chr(10) + "Qté|PrixUnit|Désignation             |Cip Ean13    |" + Chr(10) + "----------------------------------------------------"
        ''____________________________________________________________________
        ''détail
        'Dim mydatatable As DataTable = Me.ActesTableAdapter1.GetDataByNumFacturesSV(CurrentFactureVitale.G1110C1)
        'For r = 0 To mydatatable.Rows.Count - 1
        '    Dim Quantité As String = ""
        '    Dim Prix_Unitaire As String = ""
        '    Dim Désignation As String = ""
        '    Dim cip_ean13 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 "Désignation"
        '                Désignation = Mid(mydatatable(r).Item(c).ToString, 1, 24)
        '            Case "CIP"
        '                cip_ean13 = mydatatable(r).Item(c).ToString
        '            Case "EAN13"
        '                If cip_ean13 = "" Then
        '                    cip_ean13 = mydatatable(r).Item(c).ToString
        '                End If
        '        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 cip_ean13.Length < 13
        '        cip_ean13 = cip_ean13 + " "
        '    End While
        '    While Désignation.Length < 24
        '        Désignation = Désignation + " "
        '    End While
        '    drawString = drawString + Chr(10) + Quantité + "|" + Prix_Unitaire + "|" + Désignation + "|" + cip_ean13 + "|" + 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 / 100).ToString
        ''____________________________________________________________________
        'drawString = drawString + Chr(10) + Chr(10) + Chr(10) + PiedPage

        '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

    Private Sub Button_Duplicata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Duplicata.Click
        Imprime_FSE("Impr_Duplicata")
        'Dim ConfigXml As New XmlDocument
        'ConfigXml.Load("InfoPro.xml")
        'Dim nodeliste As XmlNodeList
        'nodeliste = ConfigXml.GetElementsByTagName("Impr_Duplicata")
        'Dim EnTete As String = nodeliste.Item(0).Item("EnTete").InnerText
        'Dim PiedPage As String = nodeliste.Item(0).Item("PiedPage").InnerText
        'SizeFont = Val(nodeliste.Item(0).Item("SizeFont").InnerText)

        'drawString = EnTete + 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)
        'drawString = drawString + Chr(10) + "Prescripteur: " + Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentFactureVitale.IDPrescripteur).Item(0).NomPrénom
        'drawString = drawString + Chr(10) + "NIR: " + CurrentFactureVitale.G1130C2 + CurrentFactureVitale.G1130C3 + "  " + CurrentFactureVitale.Bénéficiaire
        'drawString = drawString + Chr(10) + CurrentFactureVitale.G1310C1 + " " + CurrentFactureVitale.G1310C2 + " " + CurrentFactureVitale.G1310C3 + " " + Me.AmoTableAdapter1.SelectLibellé(CurrentFactureVitale.G1310C1, CurrentFactureVitale.G1310C2, CurrentFactureVitale.G1310C3)
        'drawString = drawString + Chr(10) + Chr(10) + "--------------------------------------------------------------------------------------" + Chr(10) + "Qté|PrixUnit|T.Remb|Prest|TxRb|Cip Ean13    |LPP            |Désignation             |" + Chr(10) + "--------------------------------------------------------------------------------------"
        ''____________________________________________________________________
        ''détail
        'Dim mydatatable As DataTable = Me.ActesTableAdapter1.GetDataByNumFacturesSV(CurrentFactureVitale.G1110C1)
        '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) / 100).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 / 100).ToString
        ''____________________________________________________________________
        'drawString = drawString + Chr(10) + Chr(10) + Chr(10) + PiedPage

        '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
#End Region


 

    Private Sub PictureBoxScanOrdo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxScanOrdo.Click

        ScanOrdo.Visible = True

    End Sub

    Private Sub ListBox_scanordo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox_scanordo.Click
        Process.Start(Application.StartupPath + "\scanordo\doc\" + ListBox_scanordo.Items.Item(ListBox_scanordo.SelectedIndex).ToString)
        'Process.Start(Application.StartupPath + "\scanordo\45_1_ORDN.pdf")
    End Sub

   
    Private Sub Create_File_Index_Scanordo(ByVal num_facture As String)

        If ListBox_scanordo.Items.Count = 0 Then
            Exit Sub
        End If

        Dim Scanordo_Xml As New XmlDocument
        Scanordo_Xml.Load(Application.StartupPath + "\scanordo\dos\D-Model.xml")
        Dim XMLelementliste As XmlNodeList
        '--------------------------------------
        'SCANORDO
        XMLelementliste = Scanordo_Xml.GetElementsByTagName("Temps")
        XMLelementliste.Item(0).InnerText = Format(Now, "yyyy-MM-dd") + "T" + Format(Now, "HH:mm:ss")
        '--------------------------------------
        'FACTURE
        XMLelementliste = Scanordo_Xml.GetElementsByTagName("Facture")
        XMLelementliste.Item(0).Item("Identifiant").InnerText = CurrentFactureVitale.G1110C1
        XMLelementliste.Item(0).Item("Renouvellement").InnerText = "0"
        For l = 0 To CurrentFactureVitale.TabLigneFacture.Length - 1

            If Val(CurrentFactureVitale.TabLigneFacture(l).G1850C2) <> 0 Then
                XMLelementliste.Item(0).Item("Renouvellement").InnerText = "1"
            End If
        Next
        XMLelementliste.Item(0).Item("MtTotal").InnerText = Mid(CurrentFactureVitale.G1910C2.ToString, 1, CurrentFactureVitale.G1910C2.ToString.Length - 2) + "." + Mid(CurrentFactureVitale.G1910C2.ToString, CurrentFactureVitale.G1910C2.ToString.Length - 1)
        XMLelementliste.Item(0).Item("MtCaisse").InnerText = Mid(CurrentFactureVitale.G1910C3.ToString, 1, CurrentFactureVitale.G1910C3.ToString.Length - 2) + "." + Mid(CurrentFactureVitale.G1910C3.ToString, CurrentFactureVitale.G1910C3.ToString.Length - 1)
        XMLelementliste.Item(0).Item("MtComplementaire").InnerText = "0000000"
        '--------------------------------------
        'BENEFICIAIRE
        XMLelementliste = Scanordo_Xml.GetElementsByTagName("Beneficiaire")
        XMLelementliste.Item(0).Item("NIRAssure").InnerText = CurrentFactureVitale.G1130C2 & CurrentFactureVitale.G1130C3
        XMLelementliste.Item(0).Item("DateNai").InnerText = CurrentFactureVitale.G1130C4
        XMLelementliste.Item(0).Item("RangNai").InnerText = CurrentFactureVitale.G1130C5
        '--------------------------------------
        'ORGANISME GESTIONNAIRE
        XMLelementliste = Scanordo_Xml.GetElementsByTagName("Organisme")
        XMLelementliste.Item(0).Item("Identite").InnerText = CurrentFactureVitale.G1310C1 & CurrentFactureVitale.G1310C2 & CurrentFactureVitale.G1310C3
        '--------------------------------------
        'SAVE
        Scanordo_Xml.Save(Application.StartupPath + "\scanordo\dos\D-" + CurrentFactureVitale.G1110C1 + ".xml")
    End Sub


    Private Sub PictureBox_Facturation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox_Facturation.Click
        Create_File_Index_Scanordo(CurrentFactureVitale.G1110C1)
        COMPTOIR_MAIN.ResetForm()
        COMPTOIR_MAIN.Enabled = True
        COMPTOIR_MAIN.Dispose()
        COMPTOIR_MAIN.Visible = True
        Me.Dispose()
    End Sub
End Class