' 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 Comptoir_AMC_famille


    Private Sub TextBox1_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter
        If TextBox1.Text = "Recherche" Then
            TextBox1.Text = ""
        End If
    End Sub


    Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
        If TextBox1.Text = "" Then
            TextBox1.Text = "Recherche"
        End If
    End Sub


    Private Sub Comptoir_AMC_famille_Load(sender As Object, e As EventArgs) Handles Me.Load
        DataGridView1.DataSource = Nothing
        If CurrentBenéficiaire.G101C8 <> "" Then
            DataGridView1.DataSource = BDD.VitaleTableAdapter.GetDataBy_G101C8(CurrentBenéficiaire.G101C8)
        End If
    End Sub

    Private Sub recherche_assurés()
        If TextBox1.Text <> "Recherche" Then
            DataGridView1.DataSource = BDD.VitaleTableAdapter.GetDataByNom(Replace(TextBox1.Text, " ", "%"))
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        recherche_assurés()
    End Sub

    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            recherche_assurés()
        End If
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Try


            If DataGridView1.RowCount = 0 Then Exit Sub
            If DataGridView1.SelectedRows.Count <> 1 Then Exit Sub
            If DataGridView1.CurrentRow Is Nothing Then Exit Sub

            Dim datas = BDD.VitaleTableAdapter.GetDataBy_Num(DataGridView1.Item(NumDataGridViewTextBoxColumn.Index, DataGridView1.CurrentRow.Index).Value).Item(0)

            If CheckBox1.Checked = True Then
                CurrentBenéficiaire.G107C1 = datas.G107C1
                CurrentBenéficiaire.G107C2 = datas.G107C2
                CurrentBenéficiaire.G107C3 = datas.G107C3
                CurrentBenéficiaire.G107C4 = datas.G107C4
                CurrentBenéficiaire.G107C5 = datas.G107C5
                CurrentBenéficiaire.G107C6 = datas.G107C6

                ReDim CurrentBenéficiaire.G108C1(2)
                ReDim CurrentBenéficiaire.G108C2(2)
                If Not datas.IsG108C1O1Null Then CurrentBenéficiaire.G108C1(0) = datas.G108C1O1
                If Not datas.IsG108C2O1Null Then CurrentBenéficiaire.G108C2(0) = datas.G108C2O1
                If Not datas.IsG108C1O2Null Then CurrentBenéficiaire.G108C1(1) = datas.G108C1O2
                If Not datas.IsG108C2O2Null Then CurrentBenéficiaire.G108C2(1) = datas.G108C2O2
                If Not datas.IsG108C1O3Null Then CurrentBenéficiaire.G108C1(2) = datas.G108C1O3
                If Not datas.IsG108C2O3Null Then CurrentBenéficiaire.G108C2(2) = datas.G108C2O3

                CurrentBenéficiaire.G109C1 = datas.G109C1
                CurrentBenéficiaire.G109C2 = datas.G109C2
                CurrentBenéficiaire.G109C3 = datas.G109C3
                CurrentBenéficiaire.G109C4 = datas.G109C4
                CurrentBenéficiaire.G109C5 = datas.G109C5
                CurrentBenéficiaire.G109C6 = datas.G109C6
                CurrentBenéficiaire.G109C7 = datas.G109C7
                CurrentBenéficiaire.G109C8 = datas.G109C8
                CurrentBenéficiaire.G109C9 = datas.G109C9
                CurrentBenéficiaire.G109C10 = datas.G109C10
                CurrentBenéficiaire.G109C11 = datas.G109C11
                CurrentBenéficiaire.G109C12 = datas.G109C12

                CurrentBenéficiaire.AMC_NumOrganisme = datas.AMC_NumOrganisme
                COMPTOIR_MAIN.AMC_NumAMC_TextBox.Text = datas.AMC_NumOrganisme

                CurrentBenéficiaire.AMC_NumMutuelle = datas.AMC_NumMutuelle
                COMPTOIR_MAIN.MUT_NumMutuelle_TextBox.Text = CurrentBenéficiaire.AMC_NumMutuelle

                CurrentBenéficiaire.AMC_NumAdherent = datas.AMC_NumAdherent
                COMPTOIR_MAIN.AMC_Numadhérent_TextBox.Text = datas.AMC_NumAdherent

                CurrentBenéficiaire.AMC_TypeContrat = datas.AMC_TypeContrat

                CurrentBenéficiaire.AMC_DateDébut = datas.AMC_DateDébut
                If CurrentBenéficiaire.AMC_DateDébut <> "" Then
                    COMPTOIR_MAIN.AMC_DateDebut_MaskedTextBox.Text = Mid(CurrentBenéficiaire.AMC_DateDébut, 7, 2) + "/" + Mid(CurrentBenéficiaire.AMC_DateDébut, 5, 2) + "/" + Mid(CurrentBenéficiaire.AMC_DateDébut, 1, 4)
                Else
                    COMPTOIR_MAIN.AMC_DateDebut_MaskedTextBox.Text = ""
                End If

                CurrentBenéficiaire.AMC_DateFin = datas.AMC_DateFin
                If CurrentBenéficiaire.AMC_DateFin <> "" Then
                    COMPTOIR_MAIN.AMC_DateFin_MaskedTextBox.Text = Mid(CurrentBenéficiaire.AMC_DateFin, 7, 2) + "/" + Mid(CurrentBenéficiaire.AMC_DateFin, 5, 2) + "/" + Mid(CurrentBenéficiaire.AMC_DateFin, 1, 4)
                Else
                    COMPTOIR_MAIN.AMC_DateFin_MaskedTextBox.Text = ""
                End If

                CurrentBenéficiaire.AMC_Piecejustificative = datas.AMC_Piecejustificative
                COMPTOIR_MAIN.AMC_Piècejustificative_ComboBox.SelectedIndex = CInt(CurrentBenéficiaire.AMC_Piecejustificative)


                CurrentBenéficiaire.AMC_Code_Aiguillage_STS = datas.AMC_Code_Aiguillage_STS
                COMPTOIR_MAIN.AMC_Code_Aiguillage_STS_TextBox.Text = datas.AMC_Code_Aiguillage_STS

                CurrentBenéficiaire.AMC_Indicateurdetrairement = datas.AMC_Indicateurdetrairement
                COMPTOIR_MAIN.AMC_Indicateurdetrairement_TextBox.Text = CurrentBenéficiaire.AMC_Indicateurdetrairement

                CurrentBenéficiaire.AMC_CodeRoutage = datas.AMC_CodeRoutage
                COMPTOIR_MAIN.AMC_CodeRoutage_TextBox.Text = CurrentBenéficiaire.AMC_CodeRoutage

                CurrentBenéficiaire.AMC_IdHote = datas.AMC_IdHote
                COMPTOIR_MAIN.AMC_IdHote_TextBox.Text = CurrentBenéficiaire.AMC_IdHote

                CurrentBenéficiaire.AMC_NomDomaine = datas.AMC_NomDomaine
                COMPTOIR_MAIN.AMC_NomDomaine_TextBox.Text = CurrentBenéficiaire.AMC_NomDomaine

                CurrentBenéficiaire.AMC_Type_Convention = datas.AMC_Type_Convention
                COMPTOIR_MAIN.AMC_Type_Convention_TextBox.Text = CurrentBenéficiaire.AMC_Type_Convention

                CurrentBenéficiaire.AMC_Critère_secondaire = datas.AMC_Critère_secondaire
                COMPTOIR_MAIN.AMC_Critère_secondaire_TextBox.Text = CurrentBenéficiaire.AMC_Critère_secondaire

                CurrentBenéficiaire.AMC_IdentifiantAMC = datas.AMC_IdentifiantAMC

            End If

            If CheckBox2.Checked = True Then
                COMPTOIR_MAIN.Vitale_adresse_TextBox.Text = datas.Adresse
            End If

            If CheckBox3.Checked = True Then
                COMPTOIR_MAIN.Vitale_téléphone_TextBox.Text = datas.Téléphone
            End If

            If CheckBox4.Checked = True Then
                COMPTOIR_MAIN.Vitale_e_mail_TextBox.Text = datas.e_mail
            End If

            COMPTOIR_MAIN.EnregistreDonnéesClientversBDD()
            Me.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
End Class