' 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 Choix_Prescripteur
    Private IDinterneByRow() As String
    Private Sub Choix_Prescripteur_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ReDim IDinterneByRow(0)
        Dim mydatatable = Me.PrescripteursTableAdapter1.recherche_prescripteur1(COMPTOIR_MAIN.PrescripteurMyCombobox.Text)
        For r = 0 To mydatatable.Rows.Count - 1
            PrescripteurDataGridView.Rows.Add()
            ReDim Preserve IDinterneByRow(IDinterneByRow.Length + 1)
            PrescripteurDataGridView.Item(Prescripteur_Nom.Index, r).Value = mydatatable(r).NomPrénom
            PrescripteurDataGridView.Item(Prescripteur_Spécialité.Index, r).Value = mydatatable(r).CodeSpécialité
            PrescripteurDataGridView.Item(Prescripteur_Adresse.Index, r).Value = mydatatable(r).Adresse
            PrescripteurDataGridView.Item(Prescripteur_NumFiness.Index, r).Value = mydatatable(r).Numidentification
            PrescripteurDataGridView.Item(Prescripteur_NumRPPS.Index, r).Value = mydatatable(r).NumRPPS
            IDinterneByRow(r) = mydatatable(r).IDinterne
        Next
    End Sub

    Private Sub PrescripteurDataGridView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles PrescripteurDataGridView.CellClick


        CurrentBenéficiaire.Prescripteur_ID = IDinterneByRow(PrescripteurDataGridView.CurrentRow.Index)
        Dim mydatatable = Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentBenéficiaire.Prescripteur_ID)
        CurrentBenéficiaire.Prescripteur_ID = mydatatable(0).IDinterne
        COMPTOIR_MAIN.PrescripteurMyCombobox.Text = mydatatable(0).NomPrénom
        COMPTOIR_MAIN.TextBox_Prescripteur_NumID.Text = mydatatable(0).Numidentification
        COMPTOIR_MAIN.TextBox_Prescripteur_NumRPPS.Text = mydatatable(0).NumRPPS
        CurrentBenéficiaire.Prescripteur_CodeSpécialité = mydatatable(0).CodeSpécialité
        COMPTOIR_MAIN.Prescripteur_Spécialité_TextBox.Text = Traduction_CodeSpécialité_Prescripteur(mydatatable(0).CodeSpécialité)

        Me.Close()
    End Sub

    Private Sub ButtonEditionPrescripteur_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEditionPrescripteur.Click
        Edition_Prescripteurs.Visible = True
        Me.Close()
    End Sub
End Class