Imports System.Runtime.InteropServices
Imports System.Text
Public Class heures

    Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox1.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox1.Text <> "" Or Len(TextBox1.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox1.Text = ""
            TextBox1.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox1.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox1.Text <> "" Or Len(TextBox1.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox2.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox1.Text <> "" Or Len(TextBox2.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox2.Text = ""
            TextBox2.Focus()
            Exit Sub
        End If
        If (((TextBox1.Text) >= ("12:00:00")) And ((TextBox1.Text) <= ("24:00:00"))) And (((TextBox2.Text) >= ("00:00:00")) And ((TextBox2.Text) <= ("12:00:00"))) Then
            ts1 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox1.Text)) + (TimeSpan.Parse(TextBox2.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts1 = (TimeSpan.Parse(TextBox2.Text) - TimeSpan.Parse(TextBox1.Text))
        End If
        If ts1 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox2.Text = ""
            TextBox2.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox3_LostFocus(sender As Object, e As EventArgs) Handles TextBox3.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox2.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox2.Text <> "" Or Len(TextBox2.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox3.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox2.Text <> "" Or Len(TextBox3.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox3.Text = ""
            TextBox3.Focus()
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox2.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox2.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox3.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox3.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts5 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox2.Text)) + (TimeSpan.Parse(TextBox3.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts5 = (TimeSpan.Parse(TextBox3.Text) - TimeSpan.Parse(TextBox2.Text))
        End If
        If ts5 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox3.Text = ""
            TextBox3.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox4_LostFocus(sender As Object, e As EventArgs) Handles TextBox4.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox3.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox3.Text <> "" Or Len(TextBox3.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox4.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox3.Text <> "" Or Len(TextBox4.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox4.Text = ""
            TextBox4.Focus()
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox3.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox3.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox4.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox4.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts2 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox3.Text)) + (TimeSpan.Parse(TextBox4.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts2 = (TimeSpan.Parse(TextBox4.Text) - TimeSpan.Parse(TextBox3.Text))
        End If
        If ts2 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox4.Text = ""
            TextBox4.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox5_LostFocus(sender As Object, e As EventArgs) Handles TextBox5.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox4.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox4.Text <> "" Or Len(TextBox4.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox5.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox4.Text <> "" Or Len(TextBox5.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox5.Text = ""
            TextBox5.Focus()
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox4.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox4.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox5.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox5.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts6 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox4.Text)) + (TimeSpan.Parse(TextBox5.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts6 = (TimeSpan.Parse(TextBox5.Text) - TimeSpan.Parse(TextBox4.Text))
        End If
        If ts6 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox5.Text = ""
            TextBox5.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox6_LostFocus(sender As Object, e As EventArgs) Handles TextBox6.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox5.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox5.Text <> "" Or Len(TextBox5.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox6.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox5.Text <> "" Or Len(TextBox6.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox6.Text = ""
            TextBox6.Focus()
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox5.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox5.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox6.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox6.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts3 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox5.Text)) + (TimeSpan.Parse(TextBox6.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts3 = (TimeSpan.Parse(TextBox6.Text) - TimeSpan.Parse(TextBox5.Text))
        End If
        If ts3 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox6.Text = ""
            TextBox6.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox7_LostFocus(sender As Object, e As EventArgs) Handles TextBox7.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox6.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox6.Text <> "" Or Len(TextBox6.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox7.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox6.Text <> "" Or Len(TextBox7.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox7.Text = ""
            TextBox7.Focus()
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox6.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox6.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox7.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox7.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts7 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox6.Text)) + (TimeSpan.Parse(TextBox7.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts7 = (TimeSpan.Parse(TextBox7.Text) - TimeSpan.Parse(TextBox6.Text))
        End If
        If ts7 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox7.Text = ""
            TextBox7.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub TextBox8_LostFocus(sender As Object, e As EventArgs) Handles TextBox8.LostFocus
        Dim timeOnly2 As String
        Dim dateCheck2 As Boolean
        timeOnly2 = TextBox7.Text
        dateCheck2 = IsDate(timeOnly2)
        If dateCheck2 = False And TextBox7.Text <> "" Or Len(TextBox7.Text) <> 8 Then
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox8.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox7.Text <> "" Or Len(TextBox8.Text) <> 8 Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox8.Text = ""
            TextBox8.Focus()
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox7.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox7.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox8.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox8.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts4 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox7.Text)) + (TimeSpan.Parse(TextBox8.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts4 = (TimeSpan.Parse(TextBox8.Text) - TimeSpan.Parse(TextBox7.Text))
        End If
        If ts4 < TimeSpan.Parse("00:00:00") Then
            MsgBox("Vous avez une heure de fin inférieur à l'heure de départ, corrigez...")
            TextBox8.Text = ""
            TextBox8.Focus()
            Exit Sub
        End If
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If (((TextBox1.Text) >= ("12:00:00")) And ((TextBox1.Text) <= ("24:00:00"))) And (((TextBox2.Text) >= ("00:00:00")) And ((TextBox2.Text) <= ("12:00:00"))) Then
            ts1 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox1.Text)) + (TimeSpan.Parse(TextBox2.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts1 = (TimeSpan.Parse(TextBox2.Text) - TimeSpan.Parse(TextBox1.Text))
        End If
        If ((TimeSpan.Parse(TextBox3.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox3.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox4.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox4.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts2 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox3.Text)) + (TimeSpan.Parse(TextBox4.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts2 = (TimeSpan.Parse(TextBox4.Text) - TimeSpan.Parse(TextBox3.Text))
        End If
        If ((TimeSpan.Parse(TextBox5.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox5.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox6.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox6.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts3 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox5.Text)) + (TimeSpan.Parse(TextBox6.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts3 = (TimeSpan.Parse(TextBox6.Text) - TimeSpan.Parse(TextBox5.Text))
        End If

        If ts1 + ts2 + ts3 + ts4 > TimeSpan.Parse("24:00:00") Then
            MsgBox("Impossible, les heures d'une journée ne peuvent pas dépasser 24 heures, corrigez...")
            Exit Sub
        End If
        If TextBox1.Text = "00:00:00" Or TextBox2.Text = "00:00:00" Or TextBox3.Text = "00:00:00" Or TextBox4.Text = "00:00:00" Or TextBox5.Text = "00:00:00" Or TextBox6.Text = "00:00:00" Or TextBox7.Text = "00:00:00" Or TextBox8.Text = "00:00:00" Then
            MsgBox("Il ne faut pas saisir d'heure à 00:00:00")
            Exit Sub
        End If
        If ((TimeSpan.Parse(TextBox7.Text) >= TimeSpan.Parse("12:00:00")) And (TimeSpan.Parse(TextBox7.Text) <= TimeSpan.Parse("24:00:00"))) And ((TimeSpan.Parse(TextBox8.Text) >= TimeSpan.Parse("00:00:00")) And (TimeSpan.Parse(TextBox8.Text) <= TimeSpan.Parse("12:00:00"))) Then
            ts4 = (TimeSpan.Parse("24:00:00") - TimeSpan.Parse(TextBox7.Text)) + (TimeSpan.Parse(TextBox8.Text) - TimeSpan.Parse("00:00:00"))
        Else
            ts4 = (TimeSpan.Parse(TextBox8.Text) - TimeSpan.Parse(TextBox7.Text))
        End If
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Then
            MsgBox("Vous devez remplir toutes les cellules...")
            Exit Sub
        End If
        Dim timeOnly As String
        Dim dateCheck As Boolean
        timeOnly = TextBox1.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox1.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox1.Text = ""
            TextBox1.Focus()
        End If
        timeOnly = TextBox2.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox2.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox2.Text = ""
            TextBox2.Focus()
        End If
        timeOnly = TextBox3.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox3.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox3.Text = ""
            TextBox3.Focus()
        End If
        timeOnly = TextBox4.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox4.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox4.Text = ""
            TextBox4.Focus()
        End If
        timeOnly = TextBox5.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox5.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox5.Text = ""
            TextBox5.Focus()
        End If
        timeOnly = TextBox6.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox6.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox6.Text = ""
            TextBox6.Focus()
        End If
        timeOnly = TextBox7.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox7.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox7.Text = ""
            TextBox7.Focus()
        End If
        timeOnly = TextBox8.Text
        dateCheck = IsDate(timeOnly)
        If dateCheck = False And TextBox8.Text <> "" Then
            MsgBox("Vous devez entrer l'heure sous ce format  07:25:45")
            TextBox8.Text = ""
            TextBox8.Focus()
        End If
        'ecrireINI("heuresjournaliere", "heure1", TextBox1.Text)
        'ecrireINI("heuresjournaliere", "heure2", TextBox2.Text)
        'ecrireINI("heuresjournaliere", "heure3", TextBox3.Text)
        'ecrireINI("heuresjournaliere", "heure4", TextBox4.Text)
        'ecrireINI("heuresjournaliere", "heure5", TextBox5.Text)
        'ecrireINI("heuresjournaliere", "heure6", TextBox6.Text)
        'ecrireINI("heuresjournaliere", "heure7", TextBox7.Text)
        'ecrireINI("heuresjournaliere", "heure8", TextBox8.Text)

        Me.Close()
    End Sub

    Public Class INIHelper
        <DllImport("kernel32.dll", CharSet:=CharSet.Auto)>
        Private Shared Function GetPrivateProfileString(ByVal section As String,
                                                    ByVal key As String,
                                                    ByVal defaultValue As String,
                                                    ByVal returnedString As StringBuilder,
                                                    ByVal size As Integer,
                                                    ByVal filePath As String) As Integer
        End Function

        Public Shared Function lireINI(ByVal section As String, ByVal key As String) As String
            Dim buffer As New StringBuilder(255)
            Dim path As String = "./badgeuse.ini"
            GetPrivateProfileString(section, key, "", buffer, 255, path)
            Return buffer.ToString()
        End Function
    End Class


    Private Sub heures_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' 1) On vide la combo au cas où
        ComboBox1.Items.Clear()

        ' 2) On copie tous les items depuis Form1.ComboBox2
        For Each perso As Object In Form1.ComboBox2.Items
            ComboBox1.Items.Add(perso)
        Next

        ' 3) On recherche l’index sélectionné dans Form1 et on l’applique
        If Form1.ComboBox2.SelectedIndex >= 0 Then
            ComboBox1.SelectedIndex = Form1.ComboBox2.SelectedIndex
        End If

        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()

        TextBox1.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure1")
        TextBox2.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure2")
        TextBox3.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure3")
        TextBox4.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure4")
        TextBox5.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure5")
        TextBox6.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure6")
        TextBox7.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure7")
        TextBox8.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure8")
    End Sub


    Private Sub Button1_LostFocus(sender As Object, e As EventArgs) Handles Button1.LostFocus
        Form1.rafraichir()
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure1" ' ou heure2, etc.
        Dim valeur As String = TextBox1.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()

        TextBox1.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure1")
        If TextBox1.Text = "" Then TextBox1.Text = "07:30:00"
        TextBox2.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure2")
        If TextBox2.Text = "" Then TextBox2.Text = "09:20:00"
        TextBox3.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure3")
        If TextBox3.Text = "" Then TextBox3.Text = "09:40:00"
        TextBox4.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure4")
        If TextBox4.Text = "" Then TextBox4.Text = "11:35:00"
        TextBox5.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure5")
        If TextBox5.Text = "" Then TextBox5.Text = "12:50:00"
        TextBox6.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure6")
        If TextBox6.Text = "" Then TextBox6.Text = "14:35:00"
        TextBox7.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure7")
        If TextBox7.Text = "" Then TextBox7.Text = "14:50:00"
        TextBox8.Text = INIHelper.lireINI("heuresjournaliere", nomPersonne & "_heure8")
        If TextBox8.Text = "" Then TextBox8.Text = "16:50:00"
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure2" ' ou heure2, etc.
        Dim valeur As String = TextBox2.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure3" ' ou heure2, etc.
        Dim valeur As String = TextBox3.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure4" ' ou heure2, etc.
        Dim valeur As String = TextBox4.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure5" ' ou heure2, etc.
        Dim valeur As String = TextBox5.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure6" ' ou heure2, etc.
        Dim valeur As String = TextBox6.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure7" ' ou heure2, etc.
        Dim valeur As String = TextBox7.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "heure8" ' ou heure2, etc.
        Dim valeur As String = TextBox8.Text

        ecrireINI("heuresjournaliere", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim result As DialogResult = MessageBox.Show(
        "Voulez-vous vraiment poursuivre ?",       ' Le message
        "Confirmation",                            ' Le titre de la fenêtre
        MessageBoxButtons.OKCancel,               ' Les boutons OK et Annuler
        MessageBoxIcon.Question                   ' L’icône (optionnel)
    )

        ' Si l’utilisateur choisit OK...
        If result = DialogResult.OK Then
            If ComboBox1.Items.Count < 2 Then
                MessageBox.Show("Il faut au moins deux personnes dans ComboBox1.", "Attention",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Return
            End If

            ' 1) Récupère le nom de la première personne
            Dim firstPerson As String = ComboBox1.Items(0).ToString()

            ' 2) Lit les 8 horaires de cette personne
            Dim heures(7) As String
            For i As Integer = 1 To 8
                Dim keySrc As String = $"{firstPerson}_heure{i}"
                heures(i - 1) = lireINI("heuresjournaliere", keySrc)
            Next

            ' 3) Écrit ces mêmes horaires pour chaque autre personne
            For idx As Integer = 1 To ComboBox1.Items.Count - 1
                Dim pers As String = ComboBox1.Items(idx).ToString()
                For i As Integer = 1 To 8
                    Dim keyDst As String = $"{pers}_heure{i}"
                    ecrireINI("heuresjournaliere", keyDst, heures(i - 1))
                    'Debug.WriteLine($"[{pers}] {keyDst} ← {heures(i - 1)}")
                Next
            Next
            MessageBox.Show("Tous les horaires sont changés selon celui de la première personne", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ' TODO : remplacez cette ligne par votre code métier

        End If
    End Sub
End Class