' 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
    Public ligne As Integer
    Public CodeSituation As String


    Private Sub Assurés_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For i = 1 To 7
            DataGridView_Couverture.Rows.Add()
        Next
        For r = 0 To DataGridView_Couverture.Rows.Count - 1
            DataGridView_Couverture.Item(Date_Début.Index, r).Value = ""
            DataGridView_Couverture.Item(Date_Fin.Index, r).Value = ""
            DataGridView_Couverture.Item(Code_ALD.Index, r).Value = ""
            DataGridView_Couverture.Item(Code_Situation.Index, r).Value = ""
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '___________________________________________________________________________________________________
        'Controle cohérence DATA
        If G101C8TextBox.Text.Length <> 13 Then
            MsgBox("Erreur N° Immatriculation", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        If G101C9TextBox.Text.Length <> 2 Then
            MsgBox("Erreur Clé du N° Immatriculation", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        If G104C12TextBox.Text.Length <> 10 Or Mid(G104C12TextBox.Text, 3, 1) <> "/" Or Mid(G104C12TextBox.Text, 6, 1) <> "/" Then
            MsgBox("Erreur Date de Naissance", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        If Not IsNumeric(G104C13TextBox.Text) Or Val(G104C13TextBox.Text) = 0 Then
            MsgBox("Erreur Rang de Naissance", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        If G104C14ComboBox.Text = "" Then
            MsgBox("Erreur Qualité Assuré", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        '___________________________________________________________________________________________________
        MyDataTable = Me.VitaleTableAdapter1.GetDataBénéficiaire(G101C8TextBox.Text, Mid(G104C12TextBox.Text, 7, 4) + Mid(G104C12TextBox.Text, 4, 2) + Mid(G104C12TextBox.Text, 1, 2) + "0000", 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"
                            DataGridView_Couverture.Item(Date_Début.Index, 0).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O1"
                            DataGridView_Couverture.Item(Date_Fin.Index, 0).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O1"
                            DataGridView_Couverture.Item(Code_ALD.Index, 0).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 0).Value = True
                            End If
                        Case "G106C4O1"
                            DataGridView_Couverture.Item(Code_Situation.Index, 0).Value = MyDataTable(0).Item(c).ToString
                        Case "G106C1O2"
                            DataGridView_Couverture.Item(Date_Début.Index, 1).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O2"
                            DataGridView_Couverture.Item(Date_Fin.Index, 1).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O2"
                            DataGridView_Couverture.Item(Code_ALD.Index, 1).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 1).Value = True
                            End If
                        Case "G106C4O2"
                            DataGridView_Couverture.Item(Code_Situation.Index, 1).Value = MyDataTable(0).Item(c).ToString
                        Case "G106C1O3"
                            DataGridView_Couverture.Item(Date_Début.Index, 2).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O3"
                            DataGridView_Couverture.Item(Date_Fin.Index, 2).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O3"
                            DataGridView_Couverture.Item(Code_ALD.Index, 2).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 2).Value = True
                            End If
                        Case "G106C4O3"
                            DataGridView_Couverture.Item(Code_Situation.Index, 2).Value = MyDataTable(0).Item(c).ToString
                        Case "G106C1O4"
                            DataGridView_Couverture.Item(Date_Début.Index, 3).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O4"
                            DataGridView_Couverture.Item(Date_Fin.Index, 3).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O4"
                            DataGridView_Couverture.Item(Code_ALD.Index, 3).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 3).Value = True
                            End If
                        Case "G106C4O4"
                            DataGridView_Couverture.Item(Code_Situation.Index, 3).Value = MyDataTable(0).Item(c).ToString
                        Case "G106C1O5"
                            DataGridView_Couverture.Item(Date_Début.Index, 4).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O5"
                            DataGridView_Couverture.Item(Date_Fin.Index, 4).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O5"
                            DataGridView_Couverture.Item(Code_ALD.Index, 4).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 4).Value = True
                            End If
                        Case "G106C4O5"
                            DataGridView_Couverture.Item(Code_Situation.Index, 4).Value = MyDataTable(0).Item(c).ToString
                        Case "G106C1O6"
                            DataGridView_Couverture.Item(Date_Début.Index, 5).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O6"
                            DataGridView_Couverture.Item(Date_Fin.Index, 5).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O6"
                            DataGridView_Couverture.Item(Code_ALD.Index, 5).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 5).Value = True
                            End If
                        Case "G106C4O6"
                            DataGridView_Couverture.Item(Code_Situation.Index, 5).Value = MyDataTable(0).Item(c).ToString
                        Case "G106C1O7"
                            DataGridView_Couverture.Item(Date_Début.Index, 6).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C2O7"
                            DataGridView_Couverture.Item(Date_Fin.Index, 6).Value = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G106C3O7"
                            DataGridView_Couverture.Item(Code_ALD.Index, 6).Value = MyDataTable(0).Item(c).ToString
                            If Val(MyDataTable(0).Item(c).ToString) <> 0 Then
                                DataGridView_Couverture.Item(ALD.Index, 6).Value = True
                            End If
                        Case "G106C4O7"
                            DataGridView_Couverture.Item(Code_Situation.Index, 5).Value = MyDataTable(0).Item(c).ToString
                        Case "Assuré"
                            AssuréTextBox.Text = MyDataTable(0).Item(c).ToString
                        Case "G1420C1"
                            Dim G1420C1 As String
                            G1420C1 = MyDataTable(0).Item(c).ToString
                            For i = 0 To G1420C1_ComboBox.Items.Count - 1
                                If Mid(G1420C1, 1, 1) = Mid(G1420C1_ComboBox.Items.Item(i), 1, 1) Then
                                    G1420C1_ComboBox.SelectedIndex = i
                                End If
                            Next
                        Case "G1420C2"
                            G1420C2_TextBox.Text = Mid(MyDataTable(0).Item(c).ToString, 7, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 5, 2) + "/" + Mid(MyDataTable(0).Item(c).ToString, 1, 4)
                        Case "G1420C3"
                            G1420C3_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
    'retourne une date string au format yyyyMMdd0000 à partir d'une date string au format dd/MM/aaaa
    Private Function Format_Date_Vitale(ByVal DateIn As String) As String
        If DateIn.Length = 10 And Mid(DateIn, 3, 1) = "/" And Mid(DateIn, 6, 1) = "/" Then
            Return Mid(DateIn, 7, 4) + Mid(DateIn, 4, 2) + Mid(DateIn, 1, 2) + "0000"
        Else
            Return "000000000000"
            End If
    End Function

    'sauvegarde
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'verif data
        If AssuréTextBox.Text = "" Or G104C1TextBox.Text = "" Or G104C3TextBox.Text = "" Or G101C7ComboBox.Text = "" Or G101C10TextBox.Text = "" Or G101C11TextBox.Text = "" Or G101C12TextBox.Text = "" Then
            MsgBox("Champ obligatoire non renseigné", MsgBoxStyle.Critical)
            Exit Sub
        End If

        '___________________________________________________________________________
        'verif data G1420
        If G1420C1_ComboBox.Text = "" Then
            MsgBox("Nature de la pièce justificative pour l'AMO obligatoire", MsgBoxStyle.Critical)
            Exit Sub
        End If
        If G1420C2_TextBox.Text = "" Then
            MsgBox("Indiquez date de validité pour la pièce justificative pour l'AMO obligatoire", MsgBoxStyle.Critical)
            Exit Sub
        End If
        If G1420C3_TextBox.Text.Length > 3 Then
            MsgBox("Origine de la pièce justificative pour l'AMO: 3 caractères max", MsgBoxStyle.Critical)
            Exit Sub
        End If
        If Mid(G1420C1_ComboBox.Text, 1, 1) = "2" And G1420C3_TextBox.Text = "" Then
            MsgBox("Indiquez Origine de la pièce justificative pour l'AMO", MsgBoxStyle.Critical)
            Exit Sub
        End If
        '___________________________________________________________________________  
        'mettre les code ALD à 0 si ald pas checké
        For i = 0 To 6
            If DataGridView_Couverture.Item(ALD.Index, i).Value = False Then
                DataGridView_Couverture.Item(Code_ALD.Index, i).Value = "0"
            Else
                If Val(DataGridView_Couverture.Item(Code_ALD.Index, i).Value.ToString) <> 0 Then
                    DataGridView_Couverture.Item(Code_ALD.Index, i).Value = DataGridView_Couverture.Item(Code_ALD.Index, i).Value.ToString
                Else
                    DataGridView_Couverture.Item(Code_ALD.Index, i).Value = "1"
                End If
            End If
        Next
        '___________________________________________________________________________
        'Groupes 106
        Dim CodeSituation() As String
        ReDim CodeSituation(7)
        Dim CodeALD() As String
        ReDim CodeALD(7)
        Dim Datedebut() As String
        ReDim Datedebut(7)
        Dim Datefin() As String
        ReDim Datefin(7)
        For i = 0 To 6
            If DataGridView_Couverture.Item(Code_Situation.Index, i).Value.ToString <> "" Then
                CodeSituation(i) = DataGridView_Couverture.Item(Code_Situation.Index, i).Value.ToString
                CodeALD(i) = DataGridView_Couverture.Item(Code_ALD.Index, i).Value.ToString
                Datedebut(i) = Format_Date_Vitale(DataGridView_Couverture.Item(Date_Début.Index, i).Value.ToString)
                Datefin(i) = Format_Date_Vitale(DataGridView_Couverture.Item(Date_Fin.Index, i).Value.ToString)
            End If
        Next
        '___________________________________________________________________________
        'Alsace-Moselle
        Dim G1511C2 As String
        If G1511C2_CheckBox1.Checked = True Then
            G1511C2 = "O"
        Else
            G1511C2 = "N"
        End If
        '___________________________________________________________________________
        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, _
                                                     Format_Date_Vitale(G104C12TextBox.Text), G104C13TextBox.Text, G104C14ComboBox.Text, _
                                                     Datedebut(0), Datefin(0), CodeALD(0), CodeSituation(0), _
                                                     Datedebut(1), Datefin(1), CodeALD(1), CodeSituation(1), _
                                                     Datedebut(2), Datefin(2), CodeALD(2), CodeSituation(2), _
                                                     Datedebut(3), Datefin(3), CodeALD(3), CodeSituation(3), _
                                                     Datedebut(4), Datefin(4), CodeALD(4), CodeSituation(4), _
                                                     Datedebut(5), Datefin(5), CodeALD(5), CodeSituation(5), _
                                                     Datedebut(6), Datefin(6), CodeALD(6), CodeSituation(6), _
                                                     "0", AssuréTextBox.Text, Mid(G1420C1_ComboBox.SelectedItem.ToString, 1, 1), _
                                                     Format_Date_Vitale(G1420C2_TextBox.Text), G1420C3_TextBox.Text, G1511C2, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "")
                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, _
                                                     Format_Date_Vitale(G104C12TextBox.Text), G104C13TextBox.Text, G104C14ComboBox.Text, _
                                                     Datedebut(0), Datefin(0), CodeALD(0), CodeSituation(0), _
                                                     Datedebut(1), Datefin(1), CodeALD(1), CodeSituation(1), _
                                                     Datedebut(2), Datefin(2), CodeALD(2), CodeSituation(2), _
                                                     Datedebut(3), Datefin(3), CodeALD(3), CodeSituation(3), _
                                                     Datedebut(4), Datefin(4), CodeALD(4), CodeSituation(4), _
                                                     Datedebut(5), Datefin(5), CodeALD(5), CodeSituation(5), _
                                                     Datedebut(6), Datefin(6), CodeALD(6), CodeSituation(6), _
                                                     AssuréTextBox.Text, Mid(G1420C1_ComboBox.SelectedItem.ToString, 1, 1), _
                                                     Format_Date_Vitale(G1420C2_TextBox.Text), G1420C3_TextBox.Text, G1511C2)
                Me.Close()
        End Select
    End Sub

    'verif NIR 
    Private Sub G101C8TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C8TextBox.Validated
        If G101C8TextBox.Text.Length <> 13 Then
            MsgBox("ERREUR N° IMMATRICULATION")
            G101C8TextBox.Text = ""
        End If
        If Not IsNumeric(G101C8TextBox.Text) Then
            G101C8TextBox.Text = UCase(G101C8TextBox.Text)
            If Mid(G101C8TextBox.Text, 7, 1) <> "A" And Mid(G101C8TextBox.Text, 7, 1) <> "B" Then
                MsgBox("ERREUR N° IMMATRICULATION")
                G101C8TextBox.Text = ""
                Exit Sub
            End If
            If Not IsNumeric(Mid(G101C8TextBox.Text, 1, 6)) Or Not IsNumeric(Mid(G101C8TextBox.Text, 8, 6)) Then
                MsgBox("ERREUR N° IMMATRICULATION")
                G101C8TextBox.Text = ""
                Exit Sub
            End If
        End If
    End Sub

    'verif cle du NIR
    Private Sub G101C9TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C9TextBox.Validated
        If G101C8TextBox.Text.Length <> 13 Then
            MsgBox("ERREUR N° IMMATRICULATION")
            G101C9TextBox.Text = ""
            Exit Sub
        End If

        If IsNumeric(G101C8TextBox.Text) Then
            If Val(G101C9TextBox.Text) <> (97 - (Val(G101C8TextBox.Text) Mod 97)) Then
                MsgBox("CLE INVALIDE")
                G101C9TextBox.Text = ""
                Exit Sub
            End If
        Else
            Select Case Mid(G101C8TextBox.Text, 7, 1)
                Case "A"
                    Dim Nir As String = Mid(G101C8TextBox.Text, 1, 6) + "0" + Mid(G101C8TextBox.Text, 8, 6)
                    If G101C9TextBox.Text <> (97 - ((Val(Nir) - 1000000) Mod 97)).ToString Then
                        MsgBox("CLE INVALIDE")
                        G101C9TextBox.Text = ""
                        Exit Sub
                    End If
                Case "B"
                    Dim Nir As String = Mid(G101C8TextBox.Text, 1, 6) + "0" + Mid(G101C8TextBox.Text, 8, 6)
                    If G101C9TextBox.Text <> (97 - ((Val(Nir) - 2000000) Mod 97)).ToString Then
                        MsgBox("CLE INVALIDE")
                        G101C9TextBox.Text = ""
                        Exit Sub
                    End If
                Case Else
                    MsgBox("ERREUR N° IMMATRICULATION")
                    G101C8TextBox.Text = ""
                    G101C9TextBox.Text = ""

            End Select

        End If


    End Sub

    'verif code régime renseigné pour verif centre gestionnaire
    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

    'code centre gestionnaire
    Private Sub G101C12TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C12TextBox.Validated
        If Not IsNumeric(G101C12TextBox.Text) And G101C12TextBox.Text <> "" Then
            G101C12TextBox.Text = ""
            MsgBox("VALEUR NUMERIQUE OBLIGATOIRE", MsgBoxStyle.Information)
        End If
        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


    'affiche libellé régime
    Private Sub G101C10TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles G101C10TextBox.TextChanged
        If G101C10TextBox.Text = "09" Then
            MsgBox("Les spécificités du régime 09 (Banque de France) ont disparu (bénéficiaires rattachés au régime des fonctionnaires).", MsgBoxStyle.Exclamation)
            G101C10TextBox.Text = ""
        End If
        Label_Régime.Text = TraductionCodeRégime(G101C10TextBox.Text)
    End Sub

    'tabulation automatique quand maxlength atteint
    Private Sub TextBox_TextChanged(ByVal sender As TextBox, ByVal e As System.EventArgs) Handles G104C12TextBox.TextChanged, G101C8TextBox.TextChanged, G104C13TextBox.TextChanged, G1420C2_TextBox.TextChanged, G1420C3_TextBox.TextChanged, G101C9TextBox.TextChanged
        If sender.Text.Length = sender.MaxLength Then
            Me.SelectNextControl(sender, True, True, True, True)
        End If
    End Sub

    'mise en forme date dans textbox
    Private Sub DateTextBox_TextChanged(ByVal sender As TextBox, ByVal e As System.EventArgs) Handles G104C12TextBox.TextChanged, G1420C2_TextBox.TextChanged
        If sender.Text.Length = 2 Or sender.Text.Length = 5 Then
            sender.AppendText("/")
        End If
    End Sub

    'mise en forme date dans datagrid
    Private Sub DataGridView_Couverture_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView_Couverture.CellValidated

        Select Case DataGridView_Couverture.Columns(e.ColumnIndex).Name

            Case "Date_Début", "Date_Fin"
                Select Case DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value.ToString.Length
                    Case 8
                        Dim mydate As String
                        mydate = Mid(DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value.ToString, 1, 2) + "/" + Mid(DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value.ToString, 3, 2) + "/" + Mid(DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value.ToString, 5, 4)
                        DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value = mydate
                    Case 10
                        Dim valeur As String
                        valeur = DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value.ToString
                        If Not IsNumeric(Mid(valeur, 1, 2)) Or Not IsNumeric(Mid(valeur, 4, 2)) Or Not IsNumeric(Mid(valeur, 7, 4)) Or Mid(valeur, 3, 1) <> "/" Or Mid(valeur, 6, 1) <> "/" Then
                            MsgBox("date incorrecte, entrez JJMMAAAA", MsgBoxStyle.Critical)
                        End If
                    Case Else
                        MsgBox("date incorrecte, entrez JJMMAAAA", MsgBoxStyle.Critical)
                End Select

         
        End Select
    End Sub

    'choix remboursement
    Private Sub DataGridView_Couverture_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView_Couverture.CellContentClick
        Select Case DataGridView_Couverture.CurrentCellAddress.X
            Case Editer.Index
                Choix_remboursement_amo.ShowDialog()
                DataGridView_Couverture.Item(Code_Situation.Index, DataGridView_Couverture.CurrentCellAddress.Y).Value = CodeSituation
        End Select
    End Sub

    'affiche couverture
    Private Sub DataGridView_Couverture_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView_Couverture.CellValueChanged
         Select DataGridView_Couverture.Columns(e.ColumnIndex).Name

            Case "Code_Situation"

                If DataGridView_Couverture.Item(e.ColumnIndex, e.RowIndex).Value.ToString.Length = 4 Then
                    DataGridView_Couverture.Item(Couverture.Index, e.RowIndex).Value = "COUVERTURE"

                Else
                    DataGridView_Couverture.Item(Couverture.Index, e.RowIndex).Value = "PAS DE DROITS"

                End If
        End Select
    End Sub

    'remplissage automatique G104C2
    Private Sub G104C1TextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles G104C1TextBox.TextChanged
        If G104C1TextBox.Text.Length <> 0 Then
            If AssuréTextBox.Text = Mid(G104C1TextBox.Text, 1, G104C1TextBox.Text.Length - 1) Then
                AssuréTextBox.Text = G104C1TextBox.Text
            End If
            If G104C2TextBox.Text = Mid(G104C1TextBox.Text, 1, G104C1TextBox.Text.Length - 1) Then
                G104C2TextBox.Text = G104C1TextBox.Text
            End If
        End If
    End Sub

    'remplissage automatique G104C3
    Private Sub G104C3TextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles G104C3TextBox.TextChanged
        If G104C3TextBox.Text.Length = 1 Then
            AssuréTextBox.Text = AssuréTextBox.Text + " "
        End If
        If G104C3TextBox.Text.Length <> 0 Then
            If AssuréTextBox.Text = G104C1TextBox.Text + " " + Mid(G104C3TextBox.Text, 1, G104C3TextBox.Text.Length - 1) Then
                AssuréTextBox.Text = G104C1TextBox.Text + " " + G104C3TextBox.Text
            End If
        End If
    End Sub

 
 

    Private Sub G101C11TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C11TextBox.Validated
        If Not IsNumeric(G101C11TextBox.Text) And G101C11TextBox.Text <> "" Then
            G101C11TextBox.Text = ""
            MsgBox("VALEUR NUMERIQUE OBLIGATOIRE", MsgBoxStyle.Information)
        End If
    End Sub

    Private Sub G101C10TextBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles G101C10TextBox.Validated
        If Not IsNumeric(G101C10TextBox.Text) And G101C10TextBox.Text <> "" Then
            G101C10TextBox.Text = ""
            MsgBox("VALEUR NUMERIQUE OBLIGATOIRE", MsgBoxStyle.Information)
        End If
    End Sub


End Class
