' 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/>.
Public Class DP_Attestations

    Dim string_to_print As String = "" '"INTERVENTIONS REALISEES SUR LE DOSSIER PHARMACEUTIQUE" & Chr(10) & Now.ToLongDateString & "  " & Now.ToLongTimeString & Chr(10) _
    '& CurrentBenéficiaire.G104C1 & " " & CurrentBenéficiaire.G104C3 & " " & CurrentBenéficiaire.G104C12 & Chr(10) _
    '& CurrentBenéficiaire.G104C4 & " " & CurrentBenéficiaire.G104C5 & " " & CurrentBenéficiaire.G104C6 & " " & CurrentBenéficiaire.G104C7 & " " & CurrentBenéficiaire.G104C8 & Chr(10) & Chr(10) & _
    'Config.Titulaire_raison_sociale & Chr(10)

    Private Sub DP_Attestations_Load(sender As Object, e As EventArgs) Handles Me.Load
        ListBox1.Items.Clear()
        Dim file As String
        file = Dir(Config.LocalNetwork_ServerName & "\DP\attestations\*" & DP.Identifiant_patient_function() & "*.*")
        While file <> ""
            ListBox1.Items.Add(file)
            If InStr(file, "Création_") <> 0 Then
                ListBox2.Items.Add("Création de DP")
            ElseIf InStr(file, "refus_consult_") <> 0 Then
                ListBox2.Items.Add("Refus de consultation")
            ElseIf InStr(file, "Refus_Alimentation_") <> 0 Then
                ListBox2.Items.Add("Refus d’alimentation ")
            ElseIf InStr(file, "refus_consult_") <> 0 Then
                ListBox2.Items.Add("Refus de consultation")
            ElseIf InStr(file, "Edition_") <> 0 Then
                ListBox2.Items.Add("Remise d’une copie papier du DP ")
            Else
                ListBox2.Items.Add("")
            End If
            file = Dir()
        End While

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        If Not ListBox1.SelectedItem Is Nothing Then
            RichTextBox1.Clear()
            RichTextBox1.AppendText(My.Computer.FileSystem.ReadAllText(Config.LocalNetwork_ServerName & "\DP\attestations\" & ListBox1.SelectedItem))
            'string_to_print = RichTextBox1.Text
        End If
    End Sub

    Private Sub Impression_Button_Click(sender As Object, e As EventArgs) Handles Impression_Button.Click

        PrintDialog1.Document = PrintDocument1
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            DP.Write_Trace_Fonc("Réimpression d’une attestation", "", ListBox1.SelectedItem.ToString, DP.Identifiant_patient_function)
            string_to_print = RichTextBox1.Text
            PrintDocument1.Print()
        End If
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim drawFont As New Font("Century Gothic", 10)
        Dim drawBrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(string_to_print, drawFont, drawBrush, 10, 10)
    End Sub

    Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged

    End Sub
End Class