' 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_Bénéficiaire

    Private Sub Choix_Bénéficiaire_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim mydatatable = Me.VitaleTableAdapter1.GetDataByNom(COMPTOIR_MAIN.ComboBoxLECTURE_VITALE.Text)
        For r = 0 To mydatatable.Rows.Count - 1
            Choix_BénéficiaireDataGridView.Rows.Add()
            For c = 0 To mydatatable.Columns.Count - 1
                Select Case mydatatable.Columns.Item(c).ColumnName
                    Case "G104C1"
                        Choix_BénéficiaireDataGridView.Item(Nom.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C3"
                        Choix_BénéficiaireDataGridView.Item(Prénom.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C4"
                        Choix_BénéficiaireDataGridView.Item(Adresse1.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C5"
                        Choix_BénéficiaireDataGridView.Item(Adresse2.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C6"
                        Choix_BénéficiaireDataGridView.Item(Adresse3.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C7"
                        Choix_BénéficiaireDataGridView.Item(Adresse4.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C8"
                        Choix_BénéficiaireDataGridView.Item(Adresse5.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C12"
                        Choix_BénéficiaireDataGridView.Item(DateNaissance.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C13"
                        Choix_BénéficiaireDataGridView.Item(Rang.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G101C8"
                        Choix_BénéficiaireDataGridView.Item(NIR.Index, r).Value = mydatatable(r).Item(c).ToString
                    Case "G104C14"
                        Choix_BénéficiaireDataGridView.Item(Qualité.Index, r).Value = mydatatable(r).Item(c).ToString
                End Select
            Next
        Next
    End Sub

    Private Sub Choix_BénéficiaireDataGridView_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Choix_BénéficiaireDataGridView.CellClick
        CurrentBenéficiaire.G101C8 = Choix_BénéficiaireDataGridView.Item(NIR.Index, Choix_BénéficiaireDataGridView.CurrentRow.Index).Value
        CurrentBenéficiaire.G104C12 = Choix_BénéficiaireDataGridView.Item(DateNaissance.Index, Choix_BénéficiaireDataGridView.CurrentRow.Index).Value
        CurrentBenéficiaire.G104C13 = Choix_BénéficiaireDataGridView.Item(Rang.Index, Choix_BénéficiaireDataGridView.CurrentRow.Index).Value
        CurrentBenéficiaire.G104C14 = Choix_BénéficiaireDataGridView.Item(Qualité.Index, Choix_BénéficiaireDataGridView.CurrentRow.Index).Value
        COMPTOIR_MAIN.GetDataBénéficiaire()
        COMPTOIR_MAIN.ModeSecur = "5"
        'COMPTOIR_MAIN.CheckBoxDRE.Enabled = True
        'COMPTOIR_MAIN.CheckBoxFSE.Enabled = True
        COMPTOIR_MAIN.CheckBoxModeDegradé.Enabled = True
        COMPTOIR_MAIN.CheckBoxModeDegradé.Checked = True
        COMPTOIR_MAIN.ventetype_defaut = "assurance"
        'COMPTOIR_MAIN.Détail_Bénéficiaire_Button.Text = Choix_BénéficiaireDataGridView.Item(Nom.Index, Choix_BénéficiaireDataGridView.CurrentRow.Index).Value + " " + Choix_BénéficiaireDataGridView.Item(Prénom.Index, Choix_BénéficiaireDataGridView.CurrentRow.Index).Value
        COMPTOIR_MAIN.afficheDonnéesAssuré()
        If CurrentBenéficiaire.AMC_Piecejustificative <> "4" Then
            COMPTOIR_MAIN.AMC_Piècejustificative_ComboBox.SelectedIndex = Val(CurrentBenéficiaire.AMC_Piecejustificative)
        Else
            COMPTOIR_MAIN.AMC_Piècejustificative_ComboBox.SelectedIndex = 0
        End If

        Me.Close()


    End Sub

    Private Sub Choix_BénéficiaireDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Choix_BénéficiaireDataGridView.CellContentClick

    End Sub
End Class