' 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 Assurés

    Private MyDataTable As DataTable

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MyDataTable = Me.VitaleTableAdapter1.GetDataBénéficiaire(G101C8TextBox.Text, G104C12TextBox.Text, G104C13TextBox.Text, G104C14ComboBox.Text)
        Select Case MyDataTable.Rows.Count
            Case 0
                GroupBoxDetail.Visible = True
                GroupBoxAssure.Enabled = False
            Case 1
                GroupBoxDetail.Visible = True
                GroupBoxAssure.Enabled = False
                For c = 0 To MyDataTable.Columns.Count - 1
                    Select Case MyDataTable.Columns.Item(c).ColumnName
                        Case "G101C1"
                            G101C1ComboBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G101C9"
                            G101C9TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G104C1"
                            G104C1TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G104C2"
                            G104C2TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G104C3"
                            G104C3TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G101C7"
                            G101C7ComboBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G101C10"
                            G101C10TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G101C11"
                            G101C11TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G101C12"
                            G101C12TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O1"
                            G106C1O1TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O1"
                            G106C2O1TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O1"
                            G106C3O1TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O1"
                            G106C4O1TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O2"
                            G106C1O2TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O2"
                            G106C2O2TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O2"
                            G106C3O2TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O2"
                            G106C4O2TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O3"
                            G106C1O3TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O3"
                            G106C2O3TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O3"
                            G106C3O3TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O3"
                            G106C4O3TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O4"
                            G106C1O4TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O4"
                            G106C2O4TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O4"
                            G106C3O4TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O4"
                            G106C4O4TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O5"
                            G106C1O5TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O5"
                            G106C2O5TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O5"
                            G106C3O5TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O5"
                            G106C4O5TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O6"
                            G106C1O6TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O6"
                            G106C2O6TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O6"
                            G106C3O6TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O6"
                            G106C4O6TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C1O7"
                            G106C1O7TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C2O7"
                            G106C2O7TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C3O7"
                            G106C3O7TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G106C4O7"
                            G106C4O7TextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "Assuré"
                            AssuréTextBox.Text = MyDataTable(0).Item(c).ToString
                    End Select


                Next

            Case Else
                MsgBox(MyDataTable.Rows.Count.ToString & " résultats", MsgBoxStyle.Information)
        End Select
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Select Case MyDataTable.Rows.Count
            Case 0
                Me.VitaleTableAdapter1.InsertDégradé(G101C1ComboBox.Text, G101C7ComboBox.Text, G101C8TextBox.Text, G101C9TextBox.Text, G101C10TextBox.Text, G101C11TextBox.Text, G101C12TextBox.Text, G104C1TextBox.Text, G104C2TextBox.Text, G104C3TextBox.Text, G104C12TextBox.Text, G104C13TextBox.Text, G104C14ComboBox.Text, G106C1O1TextBox.Text, G106C2O1TextBox.Text, G106C3O1TextBox.Text, G106C4O1TextBox.Text, G106C1O2TextBox.Text, G106C2O2TextBox.Text, G106C3O2TextBox.Text, G106C4O2TextBox.Text, G106C1O3TextBox.Text, G106C2O3TextBox.Text, G106C3O3TextBox.Text, G106C4O3TextBox.Text, G106C1O4TextBox.Text, G106C2O4TextBox.Text, G106C3O4TextBox.Text, G106C4O4TextBox.Text, G106C1O5TextBox.Text, G106C2O5TextBox.Text, G106C3O5TextBox.Text, G106C4O5TextBox.Text, G106C1O6TextBox.Text, G106C2O6TextBox.Text, G106C3O6TextBox.Text, G106C4O6TextBox.Text, G106C1O7TextBox.Text, G106C2O7TextBox.Text, G106C3O7TextBox.Text, G106C4O7TextBox.Text, "0", AssuréTextBox.Text)
                Me.Close()
            Case 1
                Me.VitaleTableAdapter1.UpdateDegrade(G101C1ComboBox.Text, G101C7ComboBox.Text, G101C8TextBox.Text, G101C9TextBox.Text, G101C10TextBox.Text, G101C11TextBox.Text, G101C12TextBox.Text, G104C1TextBox.Text, G104C2TextBox.Text, G104C3TextBox.Text, G104C12TextBox.Text, G104C13TextBox.Text, G104C14ComboBox.Text, G106C1O1TextBox.Text, G106C2O1TextBox.Text, G106C3O1TextBox.Text, G106C4O1TextBox.Text, G106C1O2TextBox.Text, G106C2O2TextBox.Text, G106C3O2TextBox.Text, G106C4O2TextBox.Text, G106C1O3TextBox.Text, G106C2O3TextBox.Text, G106C3O3TextBox.Text, G106C4O3TextBox.Text, G106C1O4TextBox.Text, G106C2O4TextBox.Text, G106C3O4TextBox.Text, G106C4O4TextBox.Text, G106C1O5TextBox.Text, G106C2O5TextBox.Text, G106C3O5TextBox.Text, G106C4O5TextBox.Text, G106C1O6TextBox.Text, G106C2O6TextBox.Text, G106C3O6TextBox.Text, G106C4O6TextBox.Text, G106C1O7TextBox.Text, G106C2O7TextBox.Text, G106C3O7TextBox.Text, G106C4O7TextBox.Text, AssuréTextBox.Text)
                Me.Close()
        End Select
    End Sub

    Private Sub G101C8TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C8TextBox.Validated
        If G101C8TextBox.Text.Length <> 13 Or Val(Mid(G101C8TextBox.Text, 4, 2)) > 12 Then
            MsgBox("ERREUR N° IMMATRICULATION")
            G101C8TextBox.Text = ""
        End If
        G101C9TextBox.Text = (97 - (Val(G101C8TextBox.Text) Mod 97)).ToString
    End Sub

    Private Sub G101C12TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C12TextBox.Enter
        If G101C10TextBox.TextLength <> 2 Then
            MsgBox("RENSEIGNER CODE RÉGIME", MsgBoxStyle.Exclamation)
            G101C10TextBox.Focus()
        End If
    End Sub

    Private Sub G101C12TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C12TextBox.Validated
        Select Case G101C12TextBox.TextLength
            Case 3
                If G101C10TextBox.Text = "03" Then
                    G101C12TextBox.Text = G101C12TextBox.Text & "0"
                Else
                    G101C12TextBox.Text = "0" & G101C12TextBox.Text
                End If
            Case 4
            Case Else
                MsgBox("CODE CENTRE GESTIONNAIRE INVALiDE", MsgBoxStyle.Critical)
                G101C12TextBox.Text = ""
        End Select
     

    End Sub

  
End Class