' 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.PrescripteurTextBox.Text)
        For r = 0 To mydatatable.Rows.Count - 1
            PrescripteurDataGridView.Rows.Add()
            ReDim Preserve IDinterneByRow(IDinterneByRow.Length + 1)
            For c = 0 To mydatatable.Columns.Count - 1
                Select Case mydatatable.Columns.Item(c).ColumnName
                    Case "NomPrénom"
                        PrescripteurDataGridView.Item(Prescripteur_Nom.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "CodeSpécialité"
                        PrescripteurDataGridView.Item(Prescripteur_Spécialité.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "Adresse"
                        PrescripteurDataGridView.Item(Prescripteur_Adresse.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "Numidentification"
                        PrescripteurDataGridView.Item(Prescripteur_NumFiness.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "IDinterne"
                        IDinterneByRow(r) = mydatatable(r).Item(c).ToString
                End Select
            Next
        Next
    End Sub

    Private Sub PrescripteurDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles PrescripteurDataGridView.CellContentClick

        CurrentBenéficiaire.IDPrescripteur = IDinterneByRow(PrescripteurDataGridView.CurrentRow.Index)
        Dim mydatatable = Me.PrescripteursTableAdapter1.GetPrescripteurDataByIDinterne(CurrentBenéficiaire.IDPrescripteur)
        For i = 0 To mydatatable.Columns.Count - 1
            Select Case mydatatable.Columns.Item(i).ColumnName
                Case "IDinterne"
                    CurrentBenéficiaire.IDPrescripteur = mydatatable(0).Item(i).ToString
                Case "NomPrénom"
                    COMPTOIR_MAIN.PrescripteurTextBox.Text = mydatatable(0).Item(i).ToString
                Case "Numidentification"
                    COMPTOIR_MAIN.TextBox_Prescripteur_NumID.Text = mydatatable(0).Item(i).ToString
            End Select
        Next

        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