' 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 facilEpharm_Control
    Public Sub refresh_()
        Button1.Text = "Reçue(s): 0"
        Button1.ForeColor = Color.Red
        Button1.BackColor = Color.Black
        Button2.Text = "Confirmée(s): 0"
        Button2.ForeColor = Color.Yellow
        Button2.BackColor = Color.Black
        Button3.Text = "Préparée(s): 0"
        Button3.ForeColor = Color.Green
        Button3.BackColor = Color.Black
        facilEpharm.Button1.Text = "Reçue(s): 0"
        facilEpharm.Button2.Text = "Confirmée(s): 0"
        facilEpharm.Button3.Text = "Préparée(s): 0"

        Dim infos = facilEpharm.OrdoTableAdapter.GetData
        Dim nbr_Reçue, nbr_Confirmée, nbr_Préparée As Integer
        For r = 0 To infos.Count - 1
            If infos(r).Etat = "Reçue" Then
                nbr_Reçue = nbr_Reçue + 1
            ElseIf infos(r).Etat = "Confirmée" Then
                nbr_Confirmée = nbr_Confirmée + 1
                
            ElseIf infos(r).Etat = "Préparée" Then
                nbr_Préparée = nbr_Préparée + 1
            End If
        Next

        If nbr_Reçue > 0 Then
            Button1.Text = "Reçue(s): " & nbr_Reçue.ToString
            Button1.ForeColor = Color.Black
            Button1.BackColor = Color.Red
            facilEpharm.Button1.Text = "Reçue(s): " & nbr_Reçue.ToString
        End If
        If nbr_Confirmée > 0 Then
            Button2.Text = "Confirmée(s): " & nbr_Confirmée.ToString
            Button2.ForeColor = Color.Black
            Button2.BackColor = Color.Yellow
            facilEpharm.Button2.Text = "Confirmée(s): " & nbr_Confirmée.ToString
        End If
        If nbr_Préparée > 0 Then
            Button3.ForeColor = Color.Black
            Button3.BackColor = Color.Green
            Button3.Text = "Préparée(s): " & nbr_Préparée.ToString
            facilEpharm.Button3.Text = "Préparée(s): " & nbr_Préparée.ToString
        End If
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        refresh_()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
         Bandeau_info_bas_show("Chargement des ordonnances")
        facilEpharm.Visible = True
        facilEpharm.BringToFront()
        Application.DoEvents()
        facilEpharm.Button1_Click(Nothing, Nothing)
        Bandeau_info_bas_hide()'Bandeau_info_bas_show_thread)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
         Bandeau_info_bas_show("Chargement des ordonnances")
        facilEpharm.Visible = True
        facilEpharm.BringToFront()
        Application.DoEvents()
        facilEpharm.Button2_Click(Nothing, Nothing)
        Bandeau_info_bas_hide()'Bandeau_info_bas_show_thread)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
         Bandeau_info_bas_show("Chargement des ordonnances")
        facilEpharm.Visible = True
        facilEpharm.BringToFront()
        Application.DoEvents()
        facilEpharm.Button3_Click(Nothing, Nothing)
        Bandeau_info_bas_hide()'Bandeau_info_bas_show_thread)
    End Sub


    Private Sub facilEpharm_Control_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        round2(Me)
      
    End Sub
End Class
