Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
Imports System.Linq
Imports System.Text
'Imports System.Text.UTF7Encoding
Public Class Form1


    ' Détecte le BOM (UTF8/UTF16/UTF32). Si rien -> fallback Windows-1252 (ANSI FR)
    Private Function OpenReaderSmart(path As String) As StreamReader
        Dim fs = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
        Dim bom(3) As Byte
        Dim read = fs.Read(bom, 0, 4)
        fs.Position = 0

        Dim enc As Encoding = Nothing
        If read >= 3 AndAlso bom(0) = &HEF AndAlso bom(1) = &HBB AndAlso bom(2) = &HBF Then
            enc = New UTF8Encoding(encoderShouldEmitUTF8Identifier:=True) ' UTF-8 BOM
        ElseIf read >= 2 AndAlso bom(0) = &HFF AndAlso bom(1) = &HFE Then
            enc = Encoding.Unicode ' UTF-16 LE
        ElseIf read >= 2 AndAlso bom(0) = &HFE AndAlso bom(1) = &HFF Then
            enc = Encoding.BigEndianUnicode ' UTF-16 BE
        ElseIf read = 4 AndAlso bom(0) = 0 AndAlso bom(1) = 0 AndAlso bom(2) = &HFE AndAlso bom(3) = &HFF Then
            enc = Encoding.GetEncoding("utf-32BE")
        ElseIf read = 4 AndAlso bom(0) = &HFF AndAlso bom(1) = &HFE AndAlso bom(2) = 0 AndAlso bom(3) = 0 Then
            enc = Encoding.UTF32
        Else
            ' Fallback très courant sur Windows FR : ANSI (Windows-1252)
            enc = Encoding.GetEncoding(1252)
        End If

        Return New StreamReader(fs, enc, detectEncodingFromByteOrderMarks:=True)
    End Function

    Private Function OpenWriterUtf8Bom(path As String, append As Boolean) As StreamWriter
        Dim enc = New UTF8Encoding(encoderShouldEmitUTF8Identifier:=True) ' UTF-8 + BOM
        Return New StreamWriter(path, append, enc)
    End Function


    'fichier INI sections htot=label3, htot2=textbox5, heured1=textbox1, heured2=textbox2, heured3=textbox6, heured4=textbox7, dated1=textbox3, dated2=textbox4

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        ecrireINI("DernierePersonSelect", "General", ComboBox2.SelectedIndex.ToString())
        Me.Close()
    End Sub


    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If ComboBox1.Items.Count = 0 Or ComboBox2.Items.Count = 0 Then
            MsgBox("Vous devez au moins rentrer une personne et un travail...")
            Exit Sub
        End If

        heures.Show()

    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If ComboBox1.Items.Count = 0 Or ComboBox2.Items.Count = 0 Then
            MsgBox("Vous devez au moins rentrer une personne et un travail...")
            Exit Sub
        End If
        jtravaille.Show()
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If ComboBox1.Items.Count = 0 Or ComboBox2.Items.Count = 0 Then
            MsgBox("Vous devez au moins rentrer une personne et un travail...")
            Exit Sub
        End If
        jfv.Show()
    End Sub


    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click


        visuelheures.Show()
        visuelheures.ListView1.View = View.Details
        visuelheures.ListView1.Columns.Add("Etat", 50, HorizontalAlignment.Left)
        visuelheures.ListView1.Columns.Add("Temps", 150, HorizontalAlignment.Left)
        visuelheures.ListView1.Columns.Add("Notes", 100, HorizontalAlignment.Left)
        visuelheures.ListView1.Columns.Add("Personne(s)", 300, HorizontalAlignment.Left)
        If ComboBox2.text <> "" Then
            For i = 0 To ComboBox2.Items.Count - 1
                If lireINI("boutonstop", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.Text) = "vrai" Then
                    Dim MyLine As ListViewItem = New ListViewItem(New String() {"EC", lireINI("htot1", ComboBox2.Items(i) & ComboBox1.Text), lireINI("notes", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.Text), ComboBox2.Items(i)})
                    visuelheures.ListView1.Items.Add(MyLine)
                ElseIf lireINI("boutonstop", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.Text) = "faux" And lireINI("heured1", ComboBox2.Items(i) & ComboBox1.Text) <> "" Then
                    Dim MyLine As ListViewItem = New ListViewItem(New String() {"TE", lireINI("htot1", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.Text), lireINI("notes", ComboBox2.Items(i) & ComboBox1.Text), ComboBox2.Items(i)})
                    visuelheures.ListView1.Items.Add(MyLine)
                    'ElseIf lireINI("htot1", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.text) = "" Or lireINI("boutonstop", ComboBox2.Items(i) & ComboBox1.text) = "" Then
                Else
                    Dim MyLine As ListViewItem = New ListViewItem(New String() {"PC", "00:00:00", "_", ComboBox2.Items(i)})
                    visuelheures.ListView1.Items.Add(MyLine)
                End If
            Next
            For y = 0 To ComboBox2.Items.Count - 1
                If lireINI("boutonstop", ComboBox8.Text & ComboBox2.Items(y) & ComboBox1.Text) = "vrai" Then
                    noteencours.Show()
                End If
            Next
        End If


    End Sub



    ' 1) Ici : ta méthode privée qui charge la ComboBox8
    Private Sub ChargerGroupes()
        ComboBox8.Items.Clear()
        Using SR As New StreamReader("groupes.txt")
            Do Until SR.EndOfStream
                Dim ligne = SR.ReadLine()
                If Not String.IsNullOrWhiteSpace(ligne) Then
                    ComboBox8.Items.Add(ligne)
                End If
            Loop
        End Using

        ComboBox8.Sorted = True
        If ComboBox8.Items.Count > 0 Then
            Me.ComboBox8.SelectedIndex = 0
        End If

    End Sub




    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'TextBox8.Text = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)
        notemax = lireINI("notemaximum", ComboBox8.Text & "notemaximum")
            notemaxi.Text = notemax
        Me.Width = 965
        Me.Height = 513


        ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
        ComboBox1.BackColor = Color.White

        ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList
        ComboBox2.BackColor = Color.White



        'Timer2.Start()
        'remplis la combo personnes
        ComboBox8.Items.Clear()
        Using SR As New StreamReader("groupes.txt")
            Do Until SR.EndOfStream
                Dim ligne = SR.ReadLine()
                If ligne <> "" Then ComboBox8.Items.Add(ligne)
            Loop
            ComboBox8.Sorted = True
            ' Sélectionne le premier élément s’il existe
            'If ComboBox8.Items.Count > 0 Then
            'ComboBox8.SelectedIndex = 0
            'End If

        End Using
        ChargerGroupes()
        If ComboBox8.Items.Count > 0 Then
            ComboBox8.SelectedIndex = lireINI("DernierGroupesSelect", "General2")
        End If

        Dim prefixe As String = ComboBox8.Text.Trim()               ' "Auma 1"
        Dim basePath As String = Application.StartupPath             ' dossier de l'exe
        Dim nomFichier As String = prefixe & "employes.txt"           ' "Auma 1employes.txt"
        Dim fullPath As String = Path.Combine(basePath, nomFichier)  ' "C:\MonApp\Auma 1employes.txt"

        ' Débogage
        'MessageBox.Show("Je vais ouvrir : " & fullPath, "DEBUG")
        ComboBox2.Items.Clear()
        Using SR7 As New StreamReader(nomFichier)
            Do Until SR7.EndOfStream
                Dim ligne = SR7.ReadLine()
                If ligne <> "" Then ComboBox2.Items.Add(ligne)
            Loop
            ComboBox2.Sorted = True

        End Using

        ' 2) Restauration de l'index
        If ComboBox2.Items.Count > 0 Then
            ComboBox2.SelectedIndex = lireINI("DernierePersonSelect", "General")
        End If

        ' 2) Restauration de l'index
        Dim saved2 As String = lireINI("DernierGroupesSelect", "General2")
        Dim idx2 As Integer
        If Integer.TryParse(saved2, idx2) AndAlso idx2 >= 0 AndAlso idx2 < ComboBox8.Items.Count Then
            ComboBox8.SelectedIndex = idx2
        ElseIf ComboBox8.Items.Count > 0 Then
            ComboBox8.SelectedIndex = 0   ' fallback
        End If

        Timer1.Start()

        'test si les combo personnes ou travaux sont vide
        If ComboBox1.Items.Count = 0 Or ComboBox2.Items.Count = 0 Then
            MsgBox("Vous devez au moins rentrer une personne et un travail...")
            Exit Sub
        End If

        ComboBox1.Items.Clear()
        Dim prefixe2 As String = ComboBox8.Text.Trim()               ' "Auma 1"
        Dim basePath2 As String = Application.StartupPath             ' dossier de l'exe
        Dim nomFichier2 As String = prefixe2 & "travaux.txt"           ' "Auma 1employes.txt"
        Dim fullPath2 As String = Path.Combine(basePath2, nomFichier2)  ' "C:\MonApp\Auma 1employes.txt"
        'remplis la combo travaux
        Dim SR2 As New StreamReader(nomFichier2)
        Do Until SR2.Peek = -1
                Dim Ligne2 As String
                Ligne2 = SR2.ReadLine()
                If Ligne2 <> "" Then
                    Me.ComboBox1.Items.Add(Ligne2)
                End If
            Loop
            'ComboBox1.Sorted = True
            If ComboBox1.Items.Count > 0 Then
                Me.ComboBox1.SelectedIndex = 0
            End If
            SR2.Close()

        'remplis la combox travaus en cours
        Dim SR3 As New StreamReader(nomFichier2)
        Do Until SR3.Peek = -1
                Dim Ligne3 As String
                Ligne3 = SR3.ReadLine()
                If Ligne3 <> "" Then
                    Me.ComboBox3.Items.Add(Ligne3)
                End If
            Loop
            ComboBox3.Sorted = True
            If ComboBox3.Items.Count > 0 Then
                Me.ComboBox3.SelectedIndex = 0
            End If
            SR3.Close()


        Dim nomPersonne As String = ComboBox2.SelectedItem.ToString()
        'ajoute les dates de vacances et jours fériés
        ComboBox4.Items.Clear()
        If (lireINI("jfv", ComboBox8.Text & nomPersonne & "_1")) <> "" And (lireINI("jfv", nomPersonne & "_2")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_1"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_2"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_1")) <> "" And (lireINI("jfv", nomPersonne & "_2")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_1"))
            ComboBox4.Items.Add(dt1)
            End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If




        'fichier INI sections htot1=label3, htot2=textbox5, heured1=textbox1, heured2=textbox2, heured3=textbox6, heured4=textbox7, dated1=textbox3, dated2=textbox4, heurestr=textbox13
        Dim htot1, htot2, heured1, heured2, heured3, heured4, dated1, dated2, heurestr, boutonstop As String
            htot1 = lireINI("htot1", ComboBox2.Text & ComboBox1.Text)
            Label3.Text = htot1
            htot2 = lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            TextBox5.Text = htot2
            heured1 = lireINI("heured1", ComboBox2.Text & ComboBox1.Text)
            TextBox1.Text = heured1
            heured2 = lireINI("heured2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            TextBox2.Text = heured2
            heured3 = lireINI("heured3", ComboBox2.Text & ComboBox1.Text)
            TextBox6.Text = heured3
            heured4 = lireINI("heured4", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            TextBox7.Text = heured4
            dated1 = lireINI("dated1", ComboBox2.Text & ComboBox1.Text)
            TextBox3.Text = dated1
            dated2 = lireINI("dated2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            TextBox4.Text = dated2
            heurestr = lireINI("heurestr", ComboBox1.Text)
            TextBox13.Text = heurestr
            For i = 0 To ComboBox1.Items.Count - 1
                boutonstop = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Items(i))
                If boutonstop = "vrai" Then
                    Button1.Text = "Stop"
                    Button1.BackColor = Color.Lime
                    ComboBox1.Text = ComboBox1.Items(i)
                    Exit For
                Else
                    Button1.Text = "Start"
                    Button1.BackColor = Color.DodgerBlue
                End If
            Next
        If (lireINI("jfv", nomPersonne & "_3")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_4")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_3"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_4"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_3")) <> "" And (lireINI("jfv", nomPersonne & "_4")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_3"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_5")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_6")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_5"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_6"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_5")) <> "" And (lireINI("jfv", nomPersonne & "_6")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_5"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_7")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_8")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_7"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_8"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_7")) <> "" And (lireINI("jfv", nomPersonne & "_8")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_7"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_9")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_10")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_9"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_10"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_9")) <> "" And (lireINI("jfv", nomPersonne & "_10")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_9"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_11")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_12")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_11"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_12"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_11")) <> "" And (lireINI("jfv", nomPersonne & "_12")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_11"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_13")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_14")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_13"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_14"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_13")) <> "" And (lireINI("jfv", nomPersonne & "_14")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_13"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_15")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_16")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_15"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_16"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_15")) <> "" And (lireINI("jfv", nomPersonne & "_16")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_15"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_17")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_18")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_17"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_18"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_17")) <> "" And (lireINI("jfv", nomPersonne & "_18")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_17"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_19")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_20")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_19"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_20"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_19")) <> "" And (lireINI("jfv", nomPersonne & "_20")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_19"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_21")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_22")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_21"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_22"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_21")) <> "" And (lireINI("jfv", nomPersonne & "_22")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_21"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
        If (lireINI("jfv", nomPersonne & "_23")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_24")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_23"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_24"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_23")) <> "" And (lireINI("jfv", nomPersonne & "_24")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_23"))
            ComboBox4.Items.Add(dt1)
            End If
            If ComboBox4.Items.Count > 0 Then
                ComboBox4.SelectedIndex = 0
            End If
            Dim dates As New List(Of Date)
            For i = 0 To ComboBox4.Items.Count - 1
                dates.Add(Date.Parse(ComboBox4.Items(i)))
            Next
            ComboBox4.Items.Clear()
            dates.Sort()
            For i = 0 To dates.Count - 1
                ComboBox4.Items.Add(dates(i).ToShortDateString)
            Next

            If lireINI("heured4", ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox7.Text = DateTime.Now.ToString("HH/mm/ss")
            End If
            If lireINI("dated2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
            End If

            If lireINI("htot1", ComboBox2.Text & ComboBox1.Text) = "" Then
                Label3.Text = "00:00:00"
            End If
            If lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox5.Text = "00:00:00"
            End If
            If lireINI("heured3", ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox6.Text = DateTime.Now.ToString("HH:mm:ss")
            End If
            If lireINI("heured4", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox7.Text = DateTime.Now.ToString("HH:mm:ss")
            End If
            If lireINI("dated1", ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox3.Text = DateTime.Now.ToString("dd/MM/yyyy")
            End If
            If lireINI("dated2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text) = "" Then
                TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
            End If


        'met en marche le compteur 3 et compte le temps qui s'écoule

        ' TextBox11.Text = String.Format("{0}:{1}:{2}", hr2, min2, sec2)
        'If TextBox13.Text <> "" And Len(TextBox13.Text) = 11 Then
        'note
        'If Label3.Text <> "" And TextBox13.Text <> "" Then
        'Dim formule, heur3, heur4, formule1 As Single
        'Dim coefficient As Integer
        'Dim heur1, heur2 As TimeSpan
        'If RadioButton1.Checked = True Then
        ' coefficient = 155
        'Else
        'coefficient = 120
        'End If
        'heur1 = result1jour2
        'heur2 = TimeSpan.Parse(TextBox13.Text)
        'heur3 = heur1.TotalSeconds
        'heur4 = heur2.TotalSeconds
        'formule1 = heur3 - heur4
        'formule = ((formule1 / heur4) * 100)
        'If formule1 < 0 Then
        'TextBox14.Text = 6
        'ElseIf (formule1 > 0) Then
        'TextBox14.Text = Math.Round((6 - ((6 * formule) / coefficient)) / 5, 1) * 5
        'ElseIf (formule1) = 0 Then
        'TextBox14.Text = Math.Round((6 - ((6 * formule) / coefficient)) / 5, 1) * 5
        'End If
        'If TextBox14.Text < 1 Then
        'TextBox14.Text = 1
        'End If
        '  TextBox11.Text = heur3
        'TextBox12.Text = heur4
        'End If
        'End If

        '(ARRONDI(I51/5;1)*5))
        ' Lire la valeur stockée (ou "False" si la clé n'existe pas)
        Dim val1 = lireINI("coefficient155", ComboBox8.Text & "coeff")
        Dim val2 = lireINI("coefficient120", "coeff")

        If (val1 = True) Then
            RadioButton1.Checked = True
        End If
        If (val2 = True) Then
            RadioButton2.Checked = True
        End If

    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        If (ComboBox8.Text = "") Then
            MsgBox("Vous devez commencer à remplir au moins un groupe...")
            Exit Sub
        End If
        ' Récupération du dossier à partir de ComboBox8
        Dim folderPath As String = ComboBox8.Text

        ' S’assure que le dossier existe
        If Not Directory.Exists(folderPath) Then
            Directory.CreateDirectory(folderPath)
        End If

        ' Construit le chemin complet du fichier
        Dim filePath As String = Path.Combine(ComboBox8.Text & "employes.txt")

        ' Crée le fichier s’il n’existe pas
        If Not File.Exists(filePath) Then
            File.Create(filePath).Dispose()  ' Dispose pour fermer immédiatement le flux
        End If

        ' Ouvre le fichier (avec l’éditeur par défaut)  
        Dim personnes = Process.Start(filePath)

        ' Vide et recharge la liste
        ComboBox6.Items.Clear()
        Using sr As New StreamReader(filePath)
            While Not sr.EndOfStream
                Dim line As String = sr.ReadLine()
                If Not String.IsNullOrWhiteSpace(line) Then
                    ComboBox6.Items.Add(line)
                End If
            End While
        End Using

        ' Trie et sélectionne le premier élément si la liste n’est pas vide
        ComboBox6.Sorted = True
        If ComboBox6.Items.Count > 0 Then
            ComboBox6.SelectedIndex = 0
        End If
        personnes.WaitForExit()
        chargerpersonnes()
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        If (ComboBox8.Text = "") Then
            MsgBox("Vous devez commencer à remplir au moins un groupe...")
            Exit Sub
        End If
        ' Récupération du dossier à partir de ComboBox8
        Dim folderPath As String = ComboBox8.Text

        ' S’assure que le dossier existe
        If Not Directory.Exists(folderPath) Then
            Directory.CreateDirectory(folderPath)
        End If

        ' Construit le chemin complet du fichier
        Dim filePath As String = Path.Combine(ComboBox8.Text & "travaux.txt")

        ' Crée le fichier s’il n’existe pas
        If Not File.Exists(filePath) Then
            File.Create(filePath).Dispose()  ' Dispose pour fermer immédiatement le flux
        End If
        Dim filepath1 = Process.Start(filePath)
        ComboBox7.Items.Clear()
        Dim SR2 As New StreamReader(ComboBox8.Text & "travaux.txt")
        Do Until SR2.Peek = -1
            Dim Ligne2 As String
            Ligne2 = SR2.ReadLine()
            If Ligne2 <> "" Then
                Me.ComboBox7.Items.Add(Ligne2)
            End If
        Loop
        'ComboBox7.Sorted = True
        If ComboBox7.Items.Count > 0 Then
            Me.ComboBox7.SelectedIndex = 0
        End If
        SR2.Close()
        filepath1.WaitForExit()
        chargertravaux()
    End Sub

    Private Sub Button8_DragOver(sender As Object, e As DragEventArgs) Handles Button8.DragOver

        End Sub

        Private Sub Button8_GotFocus(sender As Object, e As EventArgs) Handles Button8.GotFocus
            TextBox15.Text = ""
        'End If
        Dim prefixe As String = ComboBox8.Text       ' ex: "Auma 2"
        Dim nomFichier As String = prefixe & "employes.txt" ' ou " " & "employes.txt" si votre fichier s'appelle "Auma 2 employes.txt"
        Dim fullPath As String = Path.Combine(Application.StartupPath, nomFichier)

        '--- création si nécessaire, avec "vide" à l'intérieur ---
        If Not File.Exists(fullPath) OrElse New FileInfo(fullPath).Length = 0 Then
        Else


            ComboBox2.Items.Clear()
            Dim SR As New StreamReader(ComboBox8.Text & "employes.txt")
            Do Until SR.Peek = -1
                Dim Ligne As String
                Ligne = SR.ReadLine()
                If Ligne <> "" Then
                    Me.ComboBox2.Items.Add(Ligne)
                End If
            Loop
            ComboBox2.Sorted = True
            If ComboBox2.Items.Count > 0 Then
                Me.ComboBox2.SelectedIndex = 0
            End If
            SR.Close()
        End If

        ' 2) Si le fichier est présent mais vide (taille = 0), on écrit "vide" dedans.

        'ComboBox2.SelectedIndex = (0)

        'efface les lignes vides
        'Dim nomFichier As String
        'Dim nvoFichier As String
        'Dim lng As Integer
        'Dim count As Integer
        'count = 0
        'nomFichier = "employes.txt"
        'lng = nomFichier.Length
        'nvoFichier = nomFichier.Substring(0, lng - 4)
        'nvoFichier = "employes" & "_2.txt"
        'Using sw As StreamWriter = File.CreateText(nvoFichier)
        'Try
        'Using sr2 As StreamReader = New StreamReader("employes.txt", System.Text.Encoding.UTF7)
        'Dim line As String
        '' Read and display the lines from the file until the end 
        '' of the file is reached.
        'Do
        'line = sr2.ReadLine()
        'If line <> "" Then
        'sw.WriteLine(line)
        'count += 1
        'End If
        'Loop Until line Is Nothing
        'sr2.Close()
        'End Using
        'Catch ex1 As Exception
        'End Try
        'sw.Close()
        'End Using
        If ComboBox2.Items.Count < ComboBox6.Items.Count Then
            Dim oui As Integer
            oui = 0
            For i = 0 To ComboBox6.Items.Count - 1
                oui = 0
                For y = 0 To ComboBox2.Items.Count - 1
                    If ComboBox6.Items(i) = ComboBox2.Items(y) Then
                        oui = 1

                    End If
                    If y = ComboBox2.Items.Count - 1 And oui <> 1 Then
                        DeleteKey(".\badgeuse.ini", "boutonstop", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "htot1", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "htot2", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured1", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured2", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured3", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured4", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "dated1", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "dated2", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "notes", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured1d", ComboBox6.Items(i) & ComboBox1.Text)
                    End If
                Next
            Next
        End If





        'My.Computer.FileSystem.DeleteFile("employes.txt")
        'My.Computer.FileSystem.RenameFile("employes_2.txt", "employes.txt")
        If ComboBox2.Items.Count > 0 Then
                ComboBox2.SelectedIndex = (0)
            End If

            ComboBox2.Items.Clear()
        Dim SR3 As New StreamReader(ComboBox8.Text & "employes.txt")
        Do Until SR3.Peek = -1
                Dim Ligne As String
                Ligne = SR3.ReadLine()
                If Ligne <> "" Then
                    Me.ComboBox2.Items.Add(Ligne)
                End If
            Loop
            ComboBox2.Sorted = True
            If ComboBox2.Items.Count > 0 Then
                Me.ComboBox2.SelectedIndex = 0
            End If
            SR3.Close()

        End Sub

        Private Sub Button7_DragOver(sender As Object, e As DragEventArgs) Handles Button7.DragOver

        End Sub


        Private Sub Button7_GotFocus(sender As Object, e As EventArgs) Handles Button7.GotFocus
        'remplis la combo travaux
        Dim prefixe As String = ComboBox8.Text       ' ex: "Auma 2"
        Dim nomFichier As String = prefixe & "travaux.txt" ' ou " " & "employes.txt" si votre fichier s'appelle "Auma 2 employes.txt"
        Dim fullPath As String = Path.Combine(Application.StartupPath, nomFichier)

        '--- création si nécessaire, avec "vide" à l'intérieur ---
        If Not File.Exists(fullPath) OrElse New FileInfo(fullPath).Length = 0 Then
        Else
            ComboBox1.Items.Clear()
            Dim SR2 As New StreamReader(ComboBox8.Text & "travaux.txt")
            Do Until SR2.Peek = -1
                Dim Ligne2 As String
                Ligne2 = SR2.ReadLine()
                If Ligne2 <> "" Then
                    Me.ComboBox1.Items.Add(Ligne2)
                End If
            Loop
            'ComboBox1.Sorted = True
            If ComboBox1.Items.Count > 0 Then
                Me.ComboBox1.SelectedIndex = 0
            End If
            SR2.Close()
        End If
        'efface les lignes vides
        'Dim nomFichier As String
        'Dim nvoFichier As String
        'Dim lng As Integer
        'Dim count As Integer
        'count = 0
        'nomFichier = "travaux.txt"
        'lng = nomFichier.Length
        'nvoFichier = nomFichier.Substring(0, lng - 4)
        'nvoFichier = "travaux" & "_2.txt"
        'Using sw As StreamWriter = File.CreateText(nvoFichier)
        'Try
        'Using sr4 As StreamReader = New StreamReader("travaux.txt", System.Text.Encoding.UTF7)
        'Dim line As String
        '' Read and display the lines from the file until the end 
        '' of the file is reached.
        'Do
        'line = sr4.ReadLine()
        'If line <> "" Then
        'sw.WriteLine(line)
        'count += 1
        'End If
        'Loop Until line Is Nothing
        'sr4.Close()
        'End Using
        'Catch ex1 As Exception
        'End Try
        'sw.Close()
        'End Using
        If ComboBox1.Items.Count < ComboBox7.Items.Count Then
                Dim oui As Integer
                oui = 0
                For i = 0 To ComboBox7.Items.Count - 1
                    oui = 0
                    For y = 0 To ComboBox1.Items.Count - 1
                        If ComboBox7.Items(i) = ComboBox1.Items(y) Then
                            oui = 1

                        End If
                        If y = ComboBox1.Items.Count - 1 And oui <> 1 Then
                            DeleteKey(".\badgeuse.ini", "heurestr", ComboBox7.Items(i))
                            DeleteKey(".\badgeuse.ini", "notes", ComboBox2.Text & ComboBox7.Items(i))
                        End If
                    Next
                Next
            End If
            'My.Computer.FileSystem.DeleteFile("travaux.txt")
            'My.Computer.FileSystem.RenameFile("travaux_2.txt", "travaux.txt")
            If ComboBox2.Items.Count > 0 Then
                ComboBox2.SelectedIndex = (0)
            End If

            ComboBox1.Items.Clear()
        Dim SR3 As New StreamReader(ComboBox8.Text & "travaux.txt")
        Do Until SR3.Peek = -1
                Dim Ligne2 As String
                Ligne2 = SR3.ReadLine()
                If Ligne2 <> "" Then
                    Me.ComboBox1.Items.Add(Ligne2)
                End If
            Loop
            'ComboBox1.Sorted = True
            If ComboBox1.Items.Count > 0 Then
                Me.ComboBox1.SelectedIndex = 0
            End If
            SR3.Close()

        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            'test si les combo personnes ou travaux sont vide
            If ComboBox1.Items.Count = 0 Or ComboBox2.Items.Count = 0 Then
                MsgBox("Vous devez au moins rentrer une personne et un travail...")
                Exit Sub
            End If
            If TextBox13.Text = "" Then
                MsgBox("Vous n'avez pas entré d'heure prescrite, corrigez...")
                TextBox13.Focus()
                Exit Sub
            End If

            'Button1.BackColor = Color.Lime
            If Button1.Text = "Start" Then
                heuredecale = 0
                Dim depart As String = lireINI("heured1d", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
                If depart = "" Then
                    TextBox15.Text = DateTime.Now.ToString("dd/MM/yyyy" & "-------" & "HH:mm:ss")
                Else
                    TextBox15.Text = depart
                End If
                If Label3.Text = "" Then
                    Label3.Text = "00:00:00"
                End If
                If TextBox5.Text = "" Then
                    TextBox5.Text = "00:00:00"
                End If
                Dim boutonstop As String
                For i = 0 To ComboBox1.Items.Count - 1
                    boutonstop = lireINI("boutonstop", ComboBox2.Text & ComboBox1.Items(i))
                    If boutonstop = "vrai" Then
                        MsgBox("cette personne a déjà un travail en route...")
                        ComboBox1.Text = ComboBox1.Items(i)
                        Exit Sub
                    End If
                Next
                Button1.Text = "Stop"
                Button1.BackColor = Color.Lime
                TextBox1.Text = DateTime.Now.ToString("dd/MM/yyyy" & "-------" & "HH:mm:ss")
                TextBox3.Text = DateTime.Now.ToString("dd/MM/yyyy")
                TextBox6.Text = DateTime.Now.ToString("HH:mm:ss")
                ecrireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, "vrai")


                'ecris dans les travaux en cours
                Me.ComboBox3.Items.Add(ComboBox2.Text & "  " & ComboBox1.Text)
                ComboBox3.Sorted = True
                File.Delete("tencours.txt")
                Dim sw As New StreamWriter("tencours.txt")
                sw.Close()
                Dim sw2 As New System.IO.StreamWriter("tencours.txt")
                For i = 0 To ComboBox3.Items.Count - 1
                    sw2.WriteLine(ComboBox3.Items(i))
                Next
                sw2.Close()
                If ComboBox3.Items.Count > 0 Then
                    Me.ComboBox3.SelectedIndex = 0
                End If
                sw.Close()
                If ComboBox3.Items.Count > 0 Then
                    ComboBox3.Text = ComboBox3.Items(0)
                End If
                'Label3.Text = "En cours..."

            Else

                heuredecale = 1
                'efface dans les travaux en cours
                If ComboBox3.Items.Count > 0 Then
                    ComboBox3.Items.Remove(ComboBox2.Text & "  " & ComboBox1.Text)
                    File.Delete("tencours.txt")
                    Dim sw As New StreamWriter("tencours.txt")
                    sw.Close()
                    Dim sw2 As New System.IO.StreamWriter("tencours.txt")
                    For i = 0 To ComboBox3.Items.Count - 1
                        sw2.WriteLine(ComboBox3.Items(i))
                    Next
                    sw2.Close()
                End If
                'If ComboBox3.Items.Count < 1 Then
                'ComboBox3.Text = ""
                'End If
                If ComboBox3.Items.Count > 0 Then
                    ComboBox3.Text = ComboBox3.Items(0)
                End If
                Button1.Text = "Start"
                Button1.BackColor = Color.DodgerBlue
                TextBox2.Text = DateTime.Now.ToString("dd/MM/yyyy" & "-------" & "HH:mm:ss")
                TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
                TextBox7.Text = DateTime.Now.ToString("HH:mm:ss")
                TextBox5.Text = DateTime.Now.ToUniversalTime()
                ecrireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, "faux")



            'met les heures dans des timespan


            Dim nomPersonne As String = ComboBox2.SelectedItem.ToString()
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure1") <> "") Then
                h1 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure1"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure2") <> "") Then
                h2 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure2"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure3") <> "") Then
                h3 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure3"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure4") <> "") Then
                h4 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure4"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure5") <> "") Then
                h5 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure5"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure6") <> "") Then
                h6 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure6"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure7") <> "") Then
                h7 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure7"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure8") <> "") Then
                h8 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure8"))
            End If
            heure1 = TimeSpan.Parse(TextBox6.Text)
                heure2 = TimeSpan.Parse(TextBox7.Text)
                If (lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)) = "" Then
                    ecrireINI("htot2", ComboBox2.Text & ComboBox1.Text, "00:00:00")
                End If
                heure3 = TimeSpan.Parse(lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                heurem = (h2 - h1) + (h4 - h3)
                heureapm = (h6 - h5) + (h8 - h7)
                htotmapm = heurem + heureapm

                'nombre de jours entre la date de départ et d'arrivée
                If TextBox4.Text <> "" Then
                    Dim datTim1 As Date = CDate(TextBox3.Text)
                    Dim datTim2 As Date = CDate(TextBox4.Text)
                    Dim diff As Long = DateDiff("d", datTim1, datTim2)
                    ' TextBox11.Text = diff



                    'jour de la semaine en clair du jour du départ
                    Dim jourdebut As String
                    jourdebut = Format(CDate(TextBox3.Text), "dddd")
                    'TextBox9.Text = jourdebut

                    'jour de la semaine en clair du jour de fin
                    Dim jourfin As String
                    jourfin = Format(CDate(TextBox4.Text), "dddd")
                    TextBox9.Text = jourfin

                    'compte les heures si jour départ = jour arrivée

                    If diff = 0 Then
                        'matin
                        If heure1 <= h1 And heure2 <= h1 Then
                            htotm = TimeSpan.Parse("00:00:00")
                        ElseIf heure1 <= h1 And (heure2 >= h1 And heure2 <= h2) Then
                            htotm = heure2 - h1
                        ElseIf heure1 <= h1 And (heure2 >= h2 And heure2 <= h3) Then
                            htotm = h2 - h1
                        ElseIf heure1 <= h1 And (heure2 >= h3 And heure2 <= h4) Then
                            htotm = (heure2 - h3) + (h2 - h1)
                        ElseIf heure1 <= h1 And (heure2 >= h4) Then
                            htotm = (h4 - h3) + (h2 - h1)
                        ElseIf (heure1 >= h1 And heure1 <= h2) And (heure2 <= h2) Then
                            htotm = heure2 - heure1
                        ElseIf (heure1 >= h1 And heure1 <= h2) And (heure2 >= h2 And heure2 <= h3) Then
                            htotm = h2 - heure1
                        ElseIf (heure1 >= h1 And heure1 <= h2) And (heure2 >= h3 And heure2 <= h4) Then
                            htotm = (heure2 - h3) + (h2 - heure1)
                        ElseIf (heure1 >= h1 And heure1 <= h2) And (heure2 >= h4) Then
                            htotm = (h4 - h3) + (h2 - heure1)
                        ElseIf (heure1 >= h2 And heure1 <= h3) And (heure2 <= h3) Then
                            htotm = TimeSpan.Parse("00:00:00")
                        ElseIf (heure1 >= h2 And heure1 <= h3) And (heure2 >= h3 And heure2 <= h4) Then
                            htotm = (heure2 - h3)
                        ElseIf (heure1 >= h2 And heure1 <= h3) And (heure2 >= h4) Then
                            htotm = h4 - h3
                        ElseIf (heure1 >= h3 And heure1 <= h4) And (heure2 >= h3 And heure2 <= h4) Then
                            htotm = heure2 - heure1
                        ElseIf (heure1 >= h3 And heure1 <= h4) And (heure2 >= h4) Then
                            htotm = h4 - heure1
                        ElseIf heure1 >= h4 Then
                            htotm = TimeSpan.Parse("00:00:00")
                        End If
                        'après-midi
                        If heure1 <= h5 And heure2 <= h5 Then
                            htotapm = TimeSpan.Parse("00:00:00")
                        ElseIf heure1 <= h5 And (heure2 >= h5 And heure2 <= h6) Then
                            htotapm = heure2 - h5
                        ElseIf heure1 <= h5 And (heure2 >= h6 And heure2 <= h7) Then
                            htotapm = h6 - h5
                        ElseIf heure1 <= h5 And (heure2 >= h7 And heure2 <= h8) Then
                            htotapm = (heure2 - h7) + (h6 - h5)
                        ElseIf heure1 <= h5 And (heure2 >= h8) Then
                            htotapm = (h8 - h7) + (h6 - h5)
                        ElseIf (heure1 >= h5 And heure1 <= h6) And (heure2 <= h6) Then
                            htotapm = heure2 - heure1
                        ElseIf (heure1 >= h5 And heure1 <= h6) And (heure2 >= h6 And heure2 <= h7) Then
                            htotapm = h6 - heure1
                        ElseIf (heure1 >= h5 And heure1 <= h6) And (heure2 >= h7 And heure2 <= h8) Then
                            htotapm = (heure2 - h7) + (h6 - heure1)
                        ElseIf (heure1 >= h5 And heure1 <= h6) And (heure2 >= h8) Then
                            htotapm = (h8 - h7) + (h6 - heure1)
                        ElseIf (heure1 >= h6 And heure1 <= h7) And (heure2 <= h7) Then
                            htotapm = TimeSpan.Parse("00:00:00")
                        ElseIf (heure1 >= h6 And heure1 <= h7) And (heure2 >= h7 And heure2 <= h8) Then
                            htotapm = (heure2 - h7)
                        ElseIf (heure1 >= h6 And heure1 <= h7) And (heure2 >= h8) Then
                            htotapm = h8 - h7
                        ElseIf (heure1 >= h7 And heure1 <= h8) And (heure2 >= h7 And heure2 <= h8) Then
                            htotapm = heure2 - heure1
                        ElseIf (heure1 >= h7 And heure1 <= h8) And (heure2 >= h8) Then
                            htotapm = h8 - heure1
                        ElseIf heure1 >= h8 Then
                            htotapm = TimeSpan.Parse("00:00:00")
                        End If

                        'control si les jours sont travaillés

                        lm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lm")
                        If lm = "true" Then
                            lmt = 1
                        Else
                            lmt = 0
                        End If
                        lam = lireINI("jtravaille", nomPersonne & "_lam")
                        If lam = "true" Then
                            lamt = 1
                        Else
                            lamt = 0
                        End If
                        mm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mm")
                        If mm = "true" Then
                            mmt = 1
                        Else
                            mmt = 0
                        End If
                        mam = lireINI("jtravaille", nomPersonne & "_mam")
                        If mam = "true" Then
                            mamt = 1
                        Else
                            mamt = 0
                        End If
                        mem = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mem")
                        If mem = "true" Then
                            memt = 1
                        Else
                            memt = 0
                        End If
                        meam = lireINI("jtravaille", nomPersonne & "_meam")
                        If meam = "true" Then
                            meamt = 1
                        Else
                            meamt = 0
                        End If
                        jm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jm")
                        If jm = "true" Then
                            jmt = 1
                        Else
                            jmt = 0
                        End If
                        jam = lireINI("jtravaille", nomPersonne & "_jam")
                        If jam = "true" Then
                            jamt = 1
                        Else
                            jamt = 0
                        End If
                        vm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vm")
                        If vm = "true" Then
                            vmt = 1
                        Else
                            vmt = 0
                        End If
                        vam = lireINI("jtravaille", nomPersonne & "_vam")
                        If vam = "true" Then
                            vamt = 1
                        Else
                            vamt = 0
                        End If
                        sm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sm")
                        If sm = "true" Then
                            smt = 1
                        Else
                            smt = 0
                        End If
                        sam = lireINI("jtravaille", nomPersonne & "_sam")
                        If sam = "true" Then
                            samt = 1
                        Else
                            samt = 0
                        End If
                        dm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dm")
                        If dm = "true" Then
                            dmt = 1
                        Else
                            dmt = 0
                        End If
                        dam = lireINI("jtravaille", nomPersonne & "_dam")
                        If dam = "true" Then
                            damt = 1
                        Else
                            damt = 0
                        End If
                        If jourdebut = "lundi" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * lmt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * lamt)
                            heuretotal = htotm + htotapm
                        ElseIf jourdebut = "mardi" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * mmt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * mamt)
                            heuretotal = htotm + htotapm
                        ElseIf jourdebut = "mercredi" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * memt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * meamt)
                            heuretotal = htotm + htotapm
                        ElseIf jourdebut = "jeudi" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * jmt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * jamt)
                            heuretotal = htotm + htotapm
                        ElseIf jourdebut = "vendredi" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * vmt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * vamt)
                            heuretotal = htotm + htotapm
                        ElseIf jourdebut = "samedi" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * smt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * samt)
                            heuretotal = htotm + htotapm
                        ElseIf jourdebut = "dimanche" Then
                            htotm = TimeSpan.FromTicks(htotm.Ticks * dmt)
                            htotapm = TimeSpan.FromTicks(htotapm.Ticks * damt)
                            heuretotal = htotm + htotapm
                        End If
                        For i = 0 To ComboBox4.Items.Count - 1
                            If TextBox3.Text = ComboBox4.Items(i) Then
                                heuretotal = TimeSpan.Parse("00:00:00")
                                Exit For
                            End If
                        Next

                        'heures totales pour 1 seul jour
                        text5 = TimeSpan.Parse(lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                        result1jour = heuretotal + heure3
                        Label3.Text = result1jour.ToString
                        'TextBox5.Text = heuretotal.ToString
                        TextBox5.Text = Label3.Text

                        'si il y a plusieurs jours
                    ElseIf diff > 0 Then

                        If heure1 <= h1 Then
                            htotm1 = (h4 - h3) + (h2 - h1)
                        ElseIf heure1 >= h1 And heure1 <= h2 Then
                            htotm1 = (h2 - heure1) + (h4 - h3)
                        ElseIf heure1 >= h2 And heure1 <= h3 Then
                            htotm1 = h4 - h3
                        ElseIf heure1 >= h3 And heure1 <= h4 Then
                            htotm1 = h4 - heure1
                        ElseIf heure1 >= h4 Then
                            htotm1 = TimeSpan.Parse("00:00:00")
                        End If
                        If heure1 <= h5 Then
                            htotapm1 = (h8 - h7) + (h6 - h5)
                        ElseIf heure1 >= h5 And heure1 <= h6 Then
                            htotapm1 = (h8 - h7) + (h6 - heure1)
                        ElseIf heure1 >= h6 And heure1 <= h7 Then
                            htotapm1 = h8 - h7
                        ElseIf heure1 >= h7 And heure1 <= h8 Then
                            htotapm1 = h8 - heure1
                        ElseIf heure1 >= h8 Then
                            htotapm1 = TimeSpan.Parse("00:00:00")
                        End If
                        If heure2 <= h1 Then
                            htotm2 = TimeSpan.Parse("00:00:00")
                        ElseIf heure2 >= h1 And heure2 <= h2 Then
                            htotm2 = heure2 - h1
                        ElseIf heure1 >= h2 And heure2 <= h3 Then
                            htotm2 = h2 - h1
                        ElseIf heure2 >= h3 And heure2 <= h4 Then
                            htotm2 = (heure2 - h3) + (h2 - h1)
                        ElseIf heure2 >= h4 Then
                            htotm2 = (h4 - h3) + (h2 - h1)
                        End If
                        If heure2 <= h5 Then
                            htotapm2 = TimeSpan.Parse("00:00:00")
                        ElseIf heure2 >= h5 And heure2 <= h6 Then
                            htotapm2 = heure2 - h5
                        ElseIf heure2 >= h6 And heure2 <= h7 Then
                            htotapm2 = h6 - h5
                        ElseIf heure2 >= h7 And heure2 <= h8 Then
                            htotapm2 = (heure2 - h7) + (h6 - h5)
                        ElseIf heure2 >= h8 Then
                            htotapm2 = (h8 - h7) + (h6 - h5)
                        End If

                        'control si les jours sont travaillés

                        lm = lireINI("jtravaille", nomPersonne & "_lm")
                        If lm = "true" Then
                            lmt = 1
                        Else
                            lmt = 0
                        End If
                        lam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lam")
                        If lam = "true" Then
                            lamt = 1
                        Else
                            lamt = 0
                        End If
                        mm = lireINI("jtravaille", nomPersonne & "_mm")
                        If mm = "true" Then
                            mmt = 1
                        Else
                            mmt = 0
                        End If
                        mam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mam")
                        If mam = "true" Then
                            mamt = 1
                        Else
                            mamt = 0
                        End If
                        mem = lireINI("jtravaille", nomPersonne & "_mem")
                        If mem = "true" Then
                            memt = 1
                        Else
                            memt = 0
                        End If
                        meam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_meam")
                        If meam = "true" Then
                            meamt = 1
                        Else
                            meamt = 0
                        End If
                        jm = lireINI("jtravaille", nomPersonne & "_jm")
                        If jm = "true" Then
                            jmt = 1
                        Else
                            jmt = 0
                        End If
                        jam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jam")
                        If jam = "true" Then
                            jamt = 1
                        Else
                            jamt = 0
                        End If
                        vm = lireINI("jtravaille", nomPersonne & "_vm")
                        If vm = "true" Then
                            vmt = 1
                        Else
                            vmt = 0
                        End If
                        vam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vam")
                        If vam = "true" Then
                            vamt = 1
                        Else
                            vamt = 0
                        End If
                        sm = lireINI("jtravaille", nomPersonne & "_sm")
                        If sm = "true" Then
                            smt = 1
                        Else
                            smt = 0
                        End If
                        sam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sam")
                        If sam = "true" Then
                            samt = 1
                        Else
                            samt = 0
                        End If
                        dm = lireINI("jtravaille", nomPersonne & "_dm")
                        If dm = "true" Then
                            dmt = 1
                        Else
                            dmt = 0
                        End If
                        dam = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dam")
                        If dam = "true" Then
                            damt = 1
                        Else
                            damt = 0
                        End If
                        If jourdebut = "lundi" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * lmt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * lamt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "lundi" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * lmt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * lamt)
                            heuretotal2 = htotm2 + htotapm2
                        End If
                        If jourdebut = "mardi" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * mmt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * mamt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "mardi" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * mmt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * mamt)
                            heuretotal2 = htotm2 + htotapm2
                        End If
                        If jourdebut = "mercredi" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * memt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * meamt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "mercredi" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * memt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * meamt)
                            heuretotal2 = htotm2 + htotapm2
                        End If
                        If jourdebut = "jeudi" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * jmt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * jamt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "jeudi" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * jmt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * jamt)
                            heuretotal2 = htotm2 + htotapm2
                        End If
                        If jourdebut = "vendredi" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * vmt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * vamt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "vendredi" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * vmt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * vamt)
                            heuretotal2 = htotm2 + htotapm2
                        End If
                        If jourdebut = "samedi" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * smt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * samt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "samedi" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * smt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * samt)
                            heuretotal2 = htotm2 + htotapm2
                        End If
                        If jourdebut = "dimanche" Then
                            htotm1 = TimeSpan.FromTicks(htotm1.Ticks * dmt)
                            htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * damt)
                            heuretotal1 = htotm1 + htotapm1
                        End If
                        If jourfin = "dimanche" Then
                            htotm2 = TimeSpan.FromTicks(htotm2.Ticks * dmt)
                            htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * damt)
                            heuretotal2 = htotm2 + htotapm2
                        End If

                        'nombre de lundi, mardi, etc. entre le jour de départ et d'arrivée

                        nlundi = lundi(CDate(TextBox3.Text), CDate(TextBox4.Text))
                        nmardi = mardi(CDate(TextBox3.Text), CDate(TextBox4.Text))
                        nmercredi = mercredi(CDate(TextBox3.Text), CDate(TextBox4.Text))
                        njeudi = jeudi(CDate(TextBox3.Text), CDate(TextBox4.Text))
                        nvendredi = vendredi(CDate(TextBox3.Text), CDate(TextBox4.Text))
                        nsamedi = samedi(CDate(TextBox3.Text), CDate(TextBox4.Text))
                        ndimanche = dimanche(CDate(TextBox3.Text), CDate(TextBox4.Text))

                        'total des heures des lundis, mardis, etc entre la date de départ et d'arrivée
                        tlundim = TimeSpan.FromTicks(heurem.Ticks * nlundi * lmt)
                        tlundiapm = TimeSpan.FromTicks(heureapm.Ticks * nlundi * lamt)

                        tmardim = TimeSpan.FromTicks(heurem.Ticks * nmardi * mmt)
                        tmardiapm = TimeSpan.FromTicks(heureapm.Ticks * nmardi * mamt)

                        tmercredim = TimeSpan.FromTicks(heurem.Ticks * nmercredi * memt)
                        tmercrediapm = TimeSpan.FromTicks(heureapm.Ticks * nmercredi * meamt)

                        tjeudim = TimeSpan.FromTicks(heurem.Ticks * njeudi * jmt)
                        tjeudiapm = TimeSpan.FromTicks(heureapm.Ticks * njeudi * jamt)

                        tvendredim = TimeSpan.FromTicks(heurem.Ticks * nvendredi * vmt)
                        tvendrediapm = TimeSpan.FromTicks(heureapm.Ticks * nvendredi * vamt)

                        tsamedim = TimeSpan.FromTicks(heurem.Ticks * nsamedi * smt)
                        tsamediapm = TimeSpan.FromTicks(heureapm.Ticks * nsamedi * samt)

                        tdimanchem = TimeSpan.FromTicks(heurem.Ticks * ndimanche * dmt)
                        tdimancheapm = TimeSpan.FromTicks(heureapm.Ticks * ndimanche * damt)


                        'heures totales sans jours congés
                        Dim heuretotalsansjc, heuretotaleavecjc
                        'heuretotalsansjc = heuretotal + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm

                        'détermine le nombre de jours congés entre la date de début et de fin
                        ComboBox5.Items.Clear()
                        Dim dt1 As Date = CDate(TextBox3.Text)
                        Dim dt2 As Date = CDate(TextBox4.Text)
                        ComboBox5.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
                        For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                            ComboBox5.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
                        Next

                        Dim jcentredeux As Integer
                        jcentredeux = 0
                        Dim jourcongeentredeux
                        For i = 0 To ComboBox4.Items.Count - 1
                            For y = 1 To ComboBox5.Items.Count - 2
                                If ComboBox5.Items(y) = ComboBox4.Items(i) Then
                                    jcentredeux = jcentredeux + 1
                                End If
                            Next
                        Next
                        jourcongeentredeux = TimeSpan.FromTicks(htotmapm.Ticks * jcentredeux)

                        'determine si le jour de départ ou d'arrivée est congé
                        Dim jour1, jour2 As Integer
                        For i = 0 To ComboBox4.Items.Count - 1
                            If TextBox3.Text = ComboBox4.Items(i) Then
                                jour1 = 1
                                Exit For
                            Else
                                jour1 = 0
                            End If
                        Next
                        For i = 0 To ComboBox4.Items.Count - 1
                            If TextBox4.Text = ComboBox4.Items(i) Then
                                jour2 = 1
                                Exit For
                            Else
                                jour2 = 0
                            End If
                        Next
                        If jour1 = 1 And jour2 = 0 Then
                            result1jour = (htotm2 + htotapm2 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                        ElseIf jour1 = 0 And jour2 = 1 Then
                            result1jour = (htotm1 + htotapm1 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                        ElseIf jour1 = 1 And jour2 = 1 Then
                            result1jour = (tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                        Else
                            result1jour = (heuretotal1 + heuretotal2 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                        End If

                        'total des heures entre les jours travaillés
                        Label3.Text = result1jour.ToString
                        TextBox5.Text = Label3.Text


                    End If
                End If
                temps1jour()

                'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                'temps = (ts).TotalSeconds
                'Dim totalSeconds As Integer = Math.Floor(temps / 1000)


                'Dim sec2 As Integer = totalSeconds Mod 60
                Dim result1jour3, right As String
                Dim m11, j11, h11, min11, s11 As Single
                result1jour3 = result1jour.ToString
                If Len(result1jour3) = 10 Then
                    right = result1jour3.Substring(result1jour3.Length - 10, 1)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 11 Then
                    right = result1jour3.Substring(result1jour3.Length - 11, 2)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 12 Then
                    right = result1jour3.Substring(result1jour3.Length - 12, 3)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 13 Then
                    right = result1jour3.Substring(result1jour3.Length - 13, 4)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                Else
                    temps = (result1jour).TotalSeconds
                End If
                'mois2 =Int(temps / (12960000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                'j2 = Int(((temps / 12960000) - Int(temps / 12960000)) * 60)
                'hr2 = Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)
                'min2 = Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)
                'sec2 = Int(((((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60) - Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)) * 60)
                'TextBox8.Text = temps.ToString
                'TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

                ' --- Début du nouveau calcul jour/h/m/s — plus simple et sans erreurs 59→00 ---
                ' 1) Total de secondes entières
                ' 1) Secondes totales depuis le début (division entière)
                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
                ' --- Fin du nouveau calcul jour/h/m/s ---

                'AA14-$AD$4)/$AD$4*100)
                'SI((AA14-$AD$4<0);6;SI((AA14-$AD$4>0);6-6*AB14/$AC$6;SI((AA14-$AD$4=0);6-6*AB14/$AC$6))))
            End If
            'fichier INI sections htot=label3, htot2=textbox5, heured1=textbox1, heured2=textbox2, heured3=textbox6, heured4=textbox7, dated1=textbox3, dated2=textbox4
            ecrireINI("htot1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, Label3.Text)
        ecrireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox5.Text)
        ecrireINI("heured1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox1.Text)
        ecrireINI("heured2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox2.Text)
        ecrireINI("heured3", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox6.Text)
        ecrireINI("heured4", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox7.Text)
        ecrireINI("dated1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox3.Text)
        ecrireINI("dated2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox4.Text)
        ecrireINI("notes", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox14.Text)
        ecrireINI("heured1d", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox15.Text)

        'ecrireINI("tempsmois", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, mois) 'mois, j, hr, min, sec
        'ecrireINI("tempsj", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, j)
        'ecrireINI("tempshr", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, hr)
        'ecrireINI("tempsmin", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, min)
        'ecrireINI("tempssec", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, sec)

        'Timer2.Enabled = False
        'Timer3.Enabled = False
        Dim Selec As String
        Selec = ComboBox2.Text
        ComboBox2.SelectedItem = Selec


    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        debutCompteur = DateTime.Now
        'TextBox11.Text = result1jour.ToString
        If TextBox13.Text = "" Then TextBox14.Text = ""
        'affiche l'heure en permanence
        'affiche l'heure en permanence
        Label9.Text = DateTime.Now.ToString

        'stop ou met en route le temps effectif suivant les jours conges et les jours travailles ou non et les creneaux horaire
        'jours conges
        Dim jourconge As Integer
        jourconge = 0
        For i = 0 To ComboBox4.Items.Count - 1
            If DateTime.Now.ToString("dd/MM/yyyy") = ComboBox4.Items(i) Then
                jourconge = 1
            End If
        Next

        'jours travailles
        Dim aujourdhui As String
        aujourdhui = Format((DateTime.Now.Date), "dddd")

        Dim travaille As Integer
        travaille = 1
        If (ComboBox2.Text <> "") Then
            Dim nomPersonne As String = ComboBox2.SelectedItem.ToString()
            If aujourdhui = "lundi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lm") = "false") Then travaille = 0
            If aujourdhui = "lundi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_lam") = "false") Then travaille = 0
            If aujourdhui = "mardi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mm") = "false") Then travaille = 0
            If aujourdhui = "mardi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_mam") = "false") Then travaille = 0
            If aujourdhui = "mercredi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mem") = "false") Then travaille = 0
            If aujourdhui = "mercredi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_meam") = "false") Then travaille = 0
            If aujourdhui = "jeudi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jm") = "false") Then travaille = 0
            If aujourdhui = "jeudi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_jam") = "false") Then travaille = 0
            If aujourdhui = "vendredi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vm") = "false") Then travaille = 0
            If aujourdhui = "vendredi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_vam") = "false") Then travaille = 0
            If aujourdhui = "samedi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sm") = "false") Then travaille = 0
            If aujourdhui = "samedi" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_sam") = "false") Then travaille = 0
            If aujourdhui = "dimanche" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) And (lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dm") = "false") Then travaille = 0
            If aujourdhui = "dimanche" And (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5) And (lireINI("jtravaille", nomPersonne & "_dam") = "false") Then travaille = 0





            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure1") <> "") Then
                h1 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure1"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure2") <> "") Then
                h2 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure2"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure3") <> "") Then
                h3 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure3"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure4") <> "") Then
                h4 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure4"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure5") <> "") Then
                h5 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure5"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure6") <> "") Then
                h6 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure6"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure7") <> "") Then
                h7 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure7"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure8") <> "") Then
                h8 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure8"))
            End If
        End If

        'h1 = TimeSpan.Parse(lireINI("heuresjournaliere", ComboBox8.Text & "heure1"))
        'h2 = TimeSpan.Parse(lireINI("heuresjournaliere", "heure2"))
        'h3 = TimeSpan.Parse(lireINI("heuresjournaliere", ComboBox8.Text & "heure3"))
        'h4 = TimeSpan.Parse(lireINI("heuresjournaliere", "heure4"))
        'h5 = TimeSpan.Parse(lireINI("heuresjournaliere", ComboBox8.Text & "heure5"))
        'h6 = TimeSpan.Parse(lireINI("heuresjournaliere", "heure6"))
        'h7 = TimeSpan.Parse(lireINI("heuresjournaliere", ComboBox8.Text & "heure7"))
        'h8 = TimeSpan.Parse(lireINI("heuresjournaliere", "heure8"))
        Dim boutonstop2 As String
        boutonstop2 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        If ((TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h1 And TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h2) Or (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h3 And TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h4) Or (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h5 And TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h6) Or (TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) >= h7 And TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) <= h8)) And (jourconge = 0) And (travaille = 1) And (boutonstop2 = "vrai") Then
            sec2 = sec2 + 1
            If (sec2 = 60) Then
                sec2 = 0
                If (sec2 <> 0) Then sec2 = 0
                min2 = min2 + 1
            End If
            If (min2 = 60) Then
                min2 = 0
                If (min2 <> 0) Then min2 = 0
                hr2 = hr2 + 1
            End If
            If (hr2 = 24) Then
                hr2 = 0
                If (hr2 <> 0) Then hr2 = 0
                min2 = 0
                If (min2 <> 0) Then min2 = 0
                sec2 = 0
                If (sec2 <> 0) Then sec2 = 0
                j2 = j2 + 1
            End If
            If (j2 = 10000) Then
                j2 = 0
                If (j2 <> 0) Then j2 = 0
                hr2 = 0
                If (hr2 <> 0) Then hr2 = 0
                min2 = 0
                If (min2 <> 0) Then min2 = 0
                sec2 = 0
                If (sec2 <> 0) Then sec2 = 0
                mois2 = mois2 + 1
            End If
            'TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
            Timer1.Interval = 1000








            boutonstop2 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            If boutonstop2 = "vrai" Then
                temps1jour()

                'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox2.Text & ComboBox1.Text))
                'temps = (ts).TotalSeconds

                Dim result1jour3, right As String
                Dim m11, j11, h11, min11, s11 As Single
                result1jour3 = result1jour.ToString
                If Len(result1jour3) = 10 Then
                    right = result1jour3.Substring(result1jour3.Length - 10, 1)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 11 Then
                    right = result1jour3.Substring(result1jour3.Length - 11, 2)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 12 Then
                    right = result1jour3.Substring(result1jour3.Length - 12, 3)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 13 Then
                    right = result1jour3.Substring(result1jour3.Length - 13, 4)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                Else
                    temps = (result1jour).TotalSeconds
                End If
                'mois2 = Int(temps / (12960000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                'j2 = Int(((temps / 12960000) - Int(temps / 12960000)) * 60)
                'hr2 = Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)
                'min2 = Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)
                'sec2 = Int(((((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60) - Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)) * 60)
                'TextBox8.Text = temps.ToString
                'TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
                'Timer3.Enabled = True

                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
            ElseIf boutonstop2 = "faux" And TextBox3.Text <> "" Then
                temps1jour()

                'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                'temps = (ts).TotalSeconds
                Dim result1jour3, right As String
                Dim m11, j11, h11, min11, s11 As Single
                result1jour3 = Label3.Text.ToString
                If Len(result1jour3) = 10 Then
                    right = result1jour3.Substring(result1jour3.Length - 10, 1)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 11 Then
                    right = result1jour3.Substring(result1jour3.Length - 11, 2)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 12 Then
                    right = result1jour3.Substring(result1jour3.Length - 13, 3)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 13 Then
                    right = result1jour3.Substring(result1jour3.Length - 14, 4)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                Else
                    temps = TimeSpan.Parse(Label3.Text).TotalSeconds
                End If

                '(result1jour).TotalSeconds
                'mois2 = Int(temps / (12960000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                'j2 = Int(((temps / 12960000) - Int(temps / 12960000)) * 60)
                'hr2 = Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)
                'min2 = Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)
                'sec2 = Int(((((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60) - Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)) * 60)
                'TextBox8.Text = temps.ToString
                'TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
            ElseIf Label3.Text = "" Then
                temps = TimeSpan.Parse("00:00:00").TotalSeconds
                'mois2 = Int(temps / (12960000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                'j2 = Int(((temps / 12960000) - Int(temps / 12960000)) * 60)
                'hr2 = Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)
                'min2 = Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)
                'sec2 = Int(((((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60) - Int(((((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60) - Int(((((temps / 12960000) - Int(temps / 12960000)) * 60) - Int((((temps / 12960000) - Int(temps / 12960000)) * 60))) * 60)) * 60)) * 60)
                'TextBox8.Text = temps.ToString
                'TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

                'th.Abs(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                ' 1) Secondes totales depuis le début (division entière)
                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
            End If

        Else
            boutonstop2 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            If boutonstop2 = "vrai" Then
                temps1jour()

                'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox2.Text & ComboBox1.Text))
                'temps = (ts).TotalSeconds
                Dim result1jour3, right As String
                Dim m11, j11, h11, min11, s11 As Single
                result1jour3 = result1jour.ToString
                If Len(result1jour3) = 10 Then
                    right = result1jour3.Substring(result1jour3.Length - 10, 1)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 11 Then
                    right = result1jour3.Substring(result1jour3.Length - 11, 2)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 12 Then
                    right = result1jour3.Substring(result1jour3.Length - 13, 3)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 13 Then
                    right = result1jour3.Substring(result1jour3.Length - 14, 4)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                Else
                    temps = (result1jour).TotalSeconds
                End If
                'Abs(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)
                'Timer3.Enabled = True

            ElseIf boutonstop2 = "faux" And TextBox3.Text <> "" Then
                temps1jour()

                'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                'temps = (ts).TotalSeconds
                Dim result1jour3, right As String
                Dim m11, j11, h11, min11, s11 As Single
                result1jour3 = Label3.Text.ToString
                If Len(result1jour3) = 10 Then
                    right = result1jour3.Substring(result1jour3.Length - 10, 1)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 11 Then
                    right = result1jour3.Substring(result1jour3.Length - 11, 2)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 12 Then
                    right = result1jour3.Substring(result1jour3.Length - 13, 3)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                ElseIf Len(result1jour3) = 13 Then
                    right = result1jour3.Substring(result1jour3.Length - 14, 4)
                    j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                    right = result1jour3.Substring(result1jour3.Length - 8, 2)
                    h11 = right * 60 * 60
                    right = result1jour3.Substring(result1jour3.Length - 5, 2)
                    min11 = right * 60
                    right = result1jour3.Substring(result1jour3.Length - 2, 2)
                    s11 = right
                    temps = m11 + j11 + h11 + min11 + s11
                Else
                    temps = TimeSpan.Parse(Label3.Text).TotalSeconds
                End If
                '(result1jour).TotalSeconds
                'bs(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

            ElseIf Label3.Text = "" Then
                temps = TimeSpan.Parse("00:00:00").TotalSeconds
                'Abs(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
                j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
                If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
                If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
                If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
                If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
                If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
                If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

                hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
                min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
                sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
                If (sec2 = -1) Then sec2 = 0
                TextBox8.Text = temps.ToString()
                TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

            End If

            'Dim note As String
            'note = lireINI("notes", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            'TextBox14.Text = note


            'temps1jour()
            If TextBox13.Text = "" Then TextBox14.Text = ""
        End If
        'note


        heure()

        If Label3.Text <> "" And TextBox13.Text <> "" And Len(TextBox13.Text) = 12 And TextBox13.Text <> "000.00:00:00" Then
            Dim formule, heur3, heur4, formule1 As Integer
            Dim coefficient As Integer

            If RadioButton1.Checked = True Then
                coefficient = 155
            Else
                coefficient = 120
            End If
            If heuredecale = 0 And Button1.Text = "Stop" Then
                heur1 = result1jour2
            Else
                heur1 = TimeSpan.Parse(Label3.Text)
            End If

            heur2 = TimeSpan.Parse(TextBox13.Text)
            heur3 = heur1.TotalSeconds
            heur4 = heur2.TotalSeconds
            formule1 = heur3 - heur4
            formule = ((formule1 / heur4) * 100)
            If formule1 < 0 Or formule1 = 0 Then
                TextBox14.Text = notemaxi.Text '6
            Else
                TextBox14.Text = Math.Round((notemaxi.Text - ((notemaxi.Text * formule) / coefficient)) / 5, 1) * 5
                'ElseIf (formule1) = 0 Then
                '   TextBox14.Text = Math.Round((6 - ((6 * formule) / coefficient)) / 5, 1) * 5
            End If
            If (Math.Round((notemaxi.Text - ((notemaxi.Text * formule) / coefficient)) / 5, 1) * 5) <= 1 Then
                TextBox14.Text = 1
            End If

            'TextBox12.Text = heur4
            'ecrireINI("notes", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, TextBox14.Text)
            If TextBox13.Text = "" Then TextBox14.Text = ""
            If Label3.Text = "" Then TextBox14.Text = 6
            'TextBox11.Text = temps.ToString
            TextBox16.Text = heur1.ToString
            TextBox11.Text = heuredecale

        End If



    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

        Timer1.Stop()





        Dim depart As String = lireINI("heured1d", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        If depart = "" Then
            TextBox15.Text = ""
        Else
            TextBox15.Text = depart
        End If
        Dim htot1, htot2, heured1, heured2, heured3, heured4, dated1, dated2, heurestr, boutonstop As String
        htot1 = lireINI("htot1", ComboBox2.Text & ComboBox1.Text)
        Label3.Text = htot1
        htot2 = lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox5.Text = htot2
        heured1 = lireINI("heured1", ComboBox2.Text & ComboBox1.Text)
        TextBox1.Text = heured1
        heured2 = lireINI("heured2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox2.Text = heured2
        heured3 = lireINI("heured3", ComboBox2.Text & ComboBox1.Text)
        TextBox6.Text = heured3
        If heured3 = "" Then
            TextBox6.Text = (DateTime.Now.ToString("HH:mm:ss"))
        End If
        heured4 = lireINI("heured4", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox7.Text = heured4
        If heured4 = "" Then
            TextBox7.Text = (DateTime.Now.ToString("HH:mm:ss"))
        End If
        dated1 = lireINI("dated1", ComboBox2.Text & ComboBox1.Text)
        TextBox3.Text = dated1
        If dated1 = "" Then
            TextBox3.Text = DateTime.Now.ToString("dd/MM/yyyy")
        End If
        dated2 = lireINI("dated2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox4.Text = dated2
        If lireINI("dated2", ComboBox2.Text & ComboBox1.Text) = "" Then
            TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
        End If
        heurestr = lireINI("heurestr", ComboBox8.Text & ComboBox1.Text)
        TextBox13.Text = heurestr
        For i = 0 To ComboBox1.Items.Count - 1
            boutonstop = lireINI("boutonstop", ComboBox2.Text & ComboBox1.Items(i))
            If boutonstop = "vrai" Then
                Button1.Text = "Stop"
                Button1.BackColor = Color.Lime
                ComboBox1.Text = ComboBox1.Items(i)
                Exit For
            Else
                Button1.Text = "Start"
                Button1.BackColor = Color.DodgerBlue
            End If
        Next
        Timer1.Start()

        'fonction pour déterminer le temps total pour 1 jour
        'temps1jour()
        'TextBox10.Text = String.Format("{0}M : {1}j : {2}H : {3}m : {4}s", mois, j, hr, min, sec)
        'heure()
        'ComboBox1.Items.Clear()
        'Dim SR2 As New StreamReader("travaux.txt", System.Text.Encoding.UTF7)
        'Do Until SR2.Peek = -1
        ' Dim Ligne2 As String
        'Ligne2 = SR2.ReadLine()
        'If Ligne2 <> "" Then
        'Me.ComboBox1.Items.Add(Ligne2)
        'End If
        'Loop
        'ComboBox1.Sorted = True
        'If ComboBox1.Items.Count > 0 Then
        'Me.ComboBox1.SelectedIndex = 0
        'End If
        'SR2.Close()

    End Sub

    Private Sub TextBox13_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox13.KeyPress
        ' Vérifie si la touche pressée est un chiffre, un point ou un deux-points
        If Not Char.IsDigit(e.KeyChar) AndAlso Not e.KeyChar = "."c AndAlso Not e.KeyChar = ":"c Then
            ' Si ce n'est pas le cas, ignore la touche pressée
            e.Handled = True
        End If
        If Len(TextBox13.Text) = 0 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 1 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 2 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 3 Then
            If Asc(e.KeyChar) <> 46 Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 4 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 5 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 6 Then
            If Asc(e.KeyChar) <> 58 Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 7 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 8 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 9 Then
            If Asc(e.KeyChar) <> 58 Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 10 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If
        If Len(TextBox13.Text) = 11 Then
            If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
                e.Handled = True
            End If
        End If

    End Sub


    Private Sub TextBox13_LostFocus(sender As Object, e As EventArgs) Handles TextBox13.LostFocus
        If Len(TextBox13.Text) <> 12 Then
            MsgBox("Vous devez entrer l'heure sous ce format  001.07:25:45")
            TextBox13.Text = "000.03:00:00"
            TextBox13.Focus()
            Exit Sub
        End If
        Dim regex As New Regex("\d{3}\.\d{2}:\d{2}:\d{2}")

        If Not regex.IsMatch(TextBox13.Text) Then
            MessageBox.Show("Le format doit être 000.00:00:00", "Format incorrect", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox13.Focus()
            TextBox13.SelectAll()
        End If
        If TextBox13.Text = "000.00:00:00" Then
            TextBox13.Text = "000.03:00:00"
            TextBox13.Focus()
            Exit Sub
        End If

        ecrireINI("heurestr", ComboBox8.Text & ComboBox1.Text, TextBox13.Text)
    End Sub



    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        Timer1.Stop()
        ComboBox4.Items.Clear()
        ComboBox4.SelectedIndex = -1    ' plus aucune ligne sélectionnée
        ComboBox4.Text = String.Empty   ' on vide la zone de texte
        Dim nomPersonne As String = ComboBox2.SelectedItem.ToString()
        'ajoute les dates de vacances et jours fériés
        If (lireINI("jfv", ComboBox8.Text & nomPersonne & "_1")) <> "" And (lireINI("jfv", nomPersonne & "_2")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_1"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_2"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_1")) <> "" And (lireINI("jfv", nomPersonne & "_2")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_1"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_3")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_4")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_3"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_4"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_3")) <> "" And (lireINI("jfv", nomPersonne & "_4")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_3"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_5")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_6")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_5"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_6"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_5")) <> "" And (lireINI("jfv", nomPersonne & "_6")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_5"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_7")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_8")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_7"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_8"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_7")) <> "" And (lireINI("jfv", nomPersonne & "_8")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_7"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_9")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_10")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_9"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_10"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_9")) <> "" And (lireINI("jfv", nomPersonne & "_10")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_9"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_11")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_12")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_11"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_12"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_11")) <> "" And (lireINI("jfv", nomPersonne & "_12")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_11"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_13")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_14")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_13"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_14"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_13")) <> "" And (lireINI("jfv", nomPersonne & "_14")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_13"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_15")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_16")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_15"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_16"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_15")) <> "" And (lireINI("jfv", nomPersonne & "_16")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_15"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_17")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_18")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_17"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_18"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_17")) <> "" And (lireINI("jfv", nomPersonne & "_18")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_17"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_19")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_20")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_19"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_20"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_19")) <> "" And (lireINI("jfv", nomPersonne & "_20")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_19"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_21")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_22")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_21"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_22"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_21")) <> "" And (lireINI("jfv", nomPersonne & "_22")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_21"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If
        If (lireINI("jfv", nomPersonne & "_23")) <> "" And (lireINI("jfv", ComboBox8.Text & nomPersonne & "_24")) <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_23"))
            Dim dt2 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_24"))
            ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf (lireINI("jfv", ComboBox8.Text & nomPersonne & "_23")) <> "" And (lireINI("jfv", nomPersonne & "_24")) = "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", ComboBox8.Text & nomPersonne & "_23"))
            ComboBox4.Items.Add(dt1)
        End If
        If ComboBox4.Items.Count > 0 Then
            ComboBox4.SelectedIndex = 0
        End If

        Dim depart As String = lireINI("heured1d", ComboBox2.Text & ComboBox1.Text)
        If depart = "" Then
            TextBox15.Text = ""
        Else
            TextBox15.Text = depart
        End If
        Dim htot1, htot2, heured1, heured2, heured3, heured4, dated1, dated2, heurestr, boutonstop As String
        htot1 = lireINI("htot1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        Label3.Text = htot1
        htot2 = lireINI("htot2", ComboBox2.Text & ComboBox1.Text)
        TextBox5.Text = htot2
        heured1 = lireINI("heured1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox1.Text = heured1
        heured2 = lireINI("heured2", ComboBox2.Text & ComboBox1.Text)
        TextBox2.Text = heured2
        heured3 = lireINI("heured3", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox6.Text = heured3
        If heured3 = "" Then
            TextBox6.Text = (DateTime.Now.ToString("HH:mm:ss"))
        End If
        heured4 = lireINI("heured4", ComboBox2.Text & ComboBox1.Text)
        TextBox7.Text = heured4
        If heured4 = "" Then
            TextBox7.Text = (DateTime.Now.ToString("HH:mm:ss"))
        End If
        dated1 = lireINI("dated1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        TextBox3.Text = dated1
        If dated1 = "" Then
            TextBox3.Text = DateTime.Now.ToString("dd/MM/yyyy")
        End If
        dated2 = lireINI("dated2", ComboBox2.Text & ComboBox1.Text)
        TextBox4.Text = dated2
        If lireINI("dated2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text) = "" Then
            TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
        End If
        heurestr = lireINI("heurestr", ComboBox1.Text)
        TextBox13.Text = heurestr
        For i = 0 To ComboBox1.Items.Count - 1
            boutonstop = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Items(i))
            If boutonstop = "vrai" Then
                Button1.Text = "Stop"
                Button1.BackColor = Color.Lime
                ComboBox1.Text = ComboBox1.Items(i)
                Exit For
            Else
                Button1.Text = "Start"
                Button1.BackColor = Color.DodgerBlue
            End If
        Next
        Timer1.Start()

        'fonction pour déterminer le temps total pour 1 jour

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim boutonstop As String
        For i = 0 To ComboBox1.Items.Count - 1
            boutonstop = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Items(i))
            If boutonstop = "vrai" And Button1.Text <> "Stop" Then
                MsgBox("cette personne a déjà un travail en route...")
                ComboBox1.Text = ComboBox1.Items(i)
                Exit Sub
            End If
        Next
        If Button1.Text = "Stop" Then
            MsgBox(" Vous devez d'abord Stopper le temps en cours de la personne...")
            Exit Sub
        End If
        login2.Show()


    End Sub




    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        Dim d As Integer
        For i = 0 To ComboBox2.Items.Count - 1
            Dim boutonstop3 As String

            boutonstop3 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.Text)
            If boutonstop3 = "faux" Then


                d = 0

            Else
                d = 1
                Exit For
            End If
        Next
        If (d = 1) Then
            MsgBox("Il faut d'abord Stopper toutes les personnes...")
            Exit Sub
        Else
            login1.Show()

        End If

        ' Ici, TOUTES les personnes sont sur "vrai" dans boutonstop → on continue
        login1.Show()

        'If Button1.Text = "Stop" Then
        'MsgBox("Vous devez d'abord Stopper le temps en cours de **toutes** les personnes...")
        'Exit Sub
        'End If

        ' Ici, tous les statuts sont "Stop" => on peut continuer
        ' ...
    End Sub



    Private h1 As TimeSpan

    Function temps1jour()
        'met les heures dans des timespan

        Dim heure22
        Dim nomPersonne As String = ComboBox2.SelectedItem.ToString()

        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure1") <> "") Then
            h1 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure1"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure2") <> "") Then
            h2 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure2"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure3") <> "") Then
            h3 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure3"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure4") <> "") Then
            h4 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure4"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure5") <> "") Then
            h5 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure5"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure6") <> "") Then
            h6 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure6"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure7") <> "") Then
            h7 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure7"))
        End If
        If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure8") <> "") Then
            h8 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure8"))
        End If
        heure1 = TimeSpan.Parse(TextBox6.Text)
        TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
        Dim boutonstop2 As String
        boutonstop2 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        If boutonstop2 = "vrai" Then
            heure22 = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss"))
        Else
            heure22 = TimeSpan.Parse(TextBox7.Text)
        End If
        If (lireINI("htot2", ComboBox2.Text & ComboBox1.Text)) = "" Then
            ecrireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, "00:00:00")
        End If
        heure3 = TimeSpan.Parse(lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
        heurem = (h2 - h1) + (h4 - h3)
        heureapm = (h6 - h5) + (h8 - h7)
        htotmapm = heurem + heureapm

        'nombre de jours entre la date de départ et d'arrivée
        If TextBox4.Text <> "" Then
            Dim datTim1 As Date = CDate(TextBox3.Text)
            Dim datTim2 As Date = DateTime.Now.Date
            Dim diff As Long = DateDiff("d", datTim1, datTim2)
            'TextBox11.Text = diff



            'jour de la semaine en clair du jour du départ
            Dim jourdebut As String
            jourdebut = Format(CDate(TextBox3.Text), "dddd")
            'TextBox9.Text = jourdebut

            'jour de la semaine en clair du jour de fin
            Dim jourfin As String
            If boutonstop2 = "vrai" Then
                jourfin = Format((DateTime.Now.Date), "dddd")
            Else
                jourfin = Format(CDate(TextBox4.Text), "dddd")
            End If
            TextBox9.Text = jourfin

            'compte les heures si jour départ = jour arrivée
            If diff = 0 Then
                'matin
                If heure1 <= h1 And heure22 <= h1 Then
                    htotm = TimeSpan.Parse("00:00:00")
                ElseIf heure1 <= h1 And (heure22 >= h1 And heure22 <= h2) Then
                    htotm = heure22 - h1
                ElseIf heure1 <= h1 And (heure22 >= h2 And heure22 <= h3) Then
                    htotm = h2 - h1
                ElseIf heure1 <= h1 And (heure22 >= h3 And heure22 <= h4) Then
                    htotm = (heure22 - h3) + (h2 - h1)
                ElseIf heure1 <= h1 And (heure22 >= h4) Then
                    htotm = (h4 - h3) + (h2 - h1)
                ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 <= h2) Then
                    htotm = heure22 - heure1
                ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 >= h2 And heure22 <= h3) Then
                    htotm = h2 - heure1
                ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 >= h3 And heure22 <= h4) Then
                    htotm = (heure22 - h3) + (h2 - heure1)
                ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 >= h4) Then
                    htotm = (h4 - h3) + (h2 - heure1)
                ElseIf (heure1 >= h2 And heure1 <= h3) And (heure22 <= h3) Then
                    htotm = TimeSpan.Parse("00:00:00")
                ElseIf (heure1 >= h2 And heure1 <= h3) And (heure22 >= h3 And heure22 <= h4) Then
                    htotm = (heure22 - h3)
                ElseIf (heure1 >= h2 And heure1 <= h3) And (heure22 >= h4) Then
                    htotm = h4 - h3
                ElseIf (heure1 >= h3 And heure1 <= h4) And (heure22 >= h3 And heure22 <= h4) Then
                    htotm = heure22 - heure1
                ElseIf (heure1 >= h3 And heure1 <= h4) And (heure22 >= h4) Then
                    htotm = h4 - heure1
                ElseIf heure1 >= h4 Then
                    htotm = TimeSpan.Parse("00:00:00")
                End If
                'après-midi
                If heure1 <= h5 And heure22 <= h5 Then
                    htotapm = TimeSpan.Parse("00:00:00")
                ElseIf heure1 <= h5 And (heure22 >= h5 And heure22 <= h6) Then
                    htotapm = heure22 - h5
                ElseIf heure1 <= h5 And (heure22 >= h6 And heure22 <= h7) Then
                    htotapm = h6 - h5
                ElseIf heure1 <= h5 And (heure22 >= h7 And heure22 <= h8) Then
                    htotapm = (heure22 - h7) + (h6 - h5)
                ElseIf heure1 <= h5 And (heure22 >= h8) Then
                    htotapm = (h8 - h7) + (h6 - h5)
                ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 <= h6) Then
                    htotapm = heure22 - heure1
                ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 >= h6 And heure22 <= h7) Then
                    htotapm = h6 - heure1
                ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 >= h7 And heure22 <= h8) Then
                    htotapm = (heure22 - h7) + (h6 - heure1)
                ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 >= h8) Then
                    htotapm = (h8 - h7) + (h6 - heure1)
                ElseIf (heure1 >= h6 And heure1 <= h7) And (heure22 <= h7) Then
                    htotapm = TimeSpan.Parse("00:00:00")
                ElseIf (heure1 >= h6 And heure1 <= h7) And (heure22 >= h7 And heure22 <= h8) Then
                    htotapm = (heure22 - h7)
                ElseIf (heure1 >= h6 And heure1 <= h7) And (heure22 >= h8) Then
                    htotapm = h8 - h7
                ElseIf (heure1 >= h7 And heure1 <= h8) And (heure22 >= h7 And heure22 <= h8) Then
                    htotapm = heure22 - heure1
                ElseIf (heure1 >= h7 And heure1 <= h8) And (heure22 >= h8) Then
                    htotapm = h8 - heure1
                ElseIf heure1 >= h8 Then
                    htotapm = TimeSpan.Parse("00:00:00")
                End If

                'control si les jours sont travaillés

                lm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lm")
                If lm = "true" Then
                    lmt = 1
                Else
                    lmt = 0
                End If
                lam = lireINI("jtravaille", nomPersonne & "_lam")
                If lam = "true" Then
                    lamt = 1
                Else
                    lamt = 0
                End If
                mm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mm")
                If mm = "true" Then
                    mmt = 1
                Else
                    mmt = 0
                End If
                mam = lireINI("jtravaille", nomPersonne & "_mam")
                If mam = "true" Then
                    mamt = 1
                Else
                    mamt = 0
                End If
                mem = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mem")
                If mem = "true" Then
                    memt = 1
                Else
                    memt = 0
                End If
                meam = lireINI("jtravaille", nomPersonne & "_meam")
                If meam = "true" Then
                    meamt = 1
                Else
                    meamt = 0
                End If
                jm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jm")
                If jm = "true" Then
                    jmt = 1
                Else
                    jmt = 0
                End If
                jam = lireINI("jtravaille", nomPersonne & "_jam")
                If jam = "true" Then
                    jamt = 1
                Else
                    jamt = 0
                End If
                vm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vm")
                If vm = "true" Then
                    vmt = 1
                Else
                    vmt = 0
                End If
                vam = lireINI("jtravaille", nomPersonne & "_vam")
                If vam = "true" Then
                    vamt = 1
                Else
                    vamt = 0
                End If
                sm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sm")
                If sm = "true" Then
                    smt = 1
                Else
                    smt = 0
                End If
                sam = lireINI("jtravaille", nomPersonne & "_sam")
                If sam = "true" Then
                    samt = 1
                Else
                    samt = 0
                End If
                dm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dm")
                If dm = "true" Then
                    dmt = 1
                Else
                    dmt = 0
                End If
                dam = lireINI("jtravaille", nomPersonne & "_dam")
                If dam = "true" Then
                    damt = 1
                Else
                    damt = 0
                End If
                If jourdebut = "lundi" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * lmt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * lamt)
                    heuretotal = htotm + htotapm
                ElseIf jourdebut = "mardi" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * mmt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * mamt)
                    heuretotal = htotm + htotapm
                ElseIf jourdebut = "mercredi" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * memt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * meamt)
                    heuretotal = htotm + htotapm
                ElseIf jourdebut = "jeudi" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * jmt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * jamt)
                    heuretotal = htotm + htotapm
                ElseIf jourdebut = "vendredi" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * vmt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * vamt)
                    heuretotal = htotm + htotapm
                ElseIf jourdebut = "samedi" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * smt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * samt)
                    heuretotal = htotm + htotapm
                ElseIf jourdebut = "dimanche" Then
                    htotm = TimeSpan.FromTicks(htotm.Ticks * dmt)
                    htotapm = TimeSpan.FromTicks(htotapm.Ticks * damt)
                    heuretotal = htotm + htotapm
                End If
                For i = 0 To ComboBox4.Items.Count - 1
                    If TextBox3.Text = ComboBox4.Items(i) Then
                        heuretotal = TimeSpan.Parse("00:00:00")
                        Exit For
                    End If
                Next
                'heures totales pour 1 seul jour
                'text5 = TimeSpan.Parse(lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                result1jour = heuretotal + heure3
                'TextBox12.Text = datTim1.ToString
            ElseIf diff > 0 Then
                Dim date2
                boutonstop2 = lireINI("boutonstop", ComboBox2.Text & ComboBox1.Text)
                If boutonstop2 = "vrai" Then
                    date2 = DateTime.Now.ToString("dd/MM/yyyy")
                Else
                    date2 = CDate(TextBox4.Text)
                End If

                If heure1 <= h1 Then
                    htotm1 = (h4 - h3) + (h2 - h1)
                ElseIf heure1 >= h1 And heure1 <= h2 Then
                    htotm1 = (h2 - heure1) + (h4 - h3)
                ElseIf heure1 >= h2 And heure1 <= h3 Then
                    htotm1 = h4 - h3
                ElseIf heure1 >= h3 And heure1 <= h4 Then
                    htotm1 = h4 - heure1
                ElseIf heure1 >= h4 Then
                    htotm1 = TimeSpan.Parse("00:00:00")
                End If
                If heure1 <= h5 Then
                    htotapm1 = (h8 - h7) + (h6 - h5)
                ElseIf heure1 >= h5 And heure1 <= h6 Then
                    htotapm1 = (h8 - h7) + (h6 - heure1)
                ElseIf heure1 >= h6 And heure1 <= h7 Then
                    htotapm1 = h8 - h7
                ElseIf heure1 >= h7 And heure1 <= h8 Then
                    htotapm1 = h8 - heure1
                ElseIf heure1 >= h8 Then
                    htotapm1 = TimeSpan.Parse("00:00:00")
                End If
                If heure22 <= h1 Then
                    htotm2 = TimeSpan.Parse("00:00:00")
                ElseIf heure22 >= h1 And heure22 <= h2 Then
                    htotm2 = heure22 - h1
                ElseIf heure22 >= h2 And heure22 <= h3 Then
                    htotm2 = h2 - h1
                ElseIf heure22 >= h3 And heure22 <= h4 Then
                    htotm2 = (heure22 - h3) + (h2 - h1)
                ElseIf heure22 >= h4 Then
                    htotm2 = (h4 - h3) + (h2 - h1)
                End If
                If heure22 <= h5 Then
                    htotapm2 = TimeSpan.Parse("00:00:00")
                ElseIf heure22 >= h5 And heure22 <= h6 Then
                    htotapm2 = heure22 - h5
                ElseIf heure22 >= h6 And heure22 <= h7 Then
                    htotapm2 = h6 - h5
                ElseIf heure22 >= h7 And heure22 <= h8 Then
                    htotapm2 = (heure22 - h7) + (h6 - h5)
                ElseIf heure22 >= h8 Then
                    htotapm2 = (h8 - h7) + (h6 - h5)
                End If


                'control si les jours sont travaillés

                lm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lm")
                If lm = "true" Then
                    lmt = 1
                Else
                    lmt = 0
                End If
                lam = lireINI("jtravaille", nomPersonne & "_lam")
                If lam = "true" Then
                    lamt = 1
                Else
                    lamt = 0
                End If
                mm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mm")
                If mm = "true" Then
                    mmt = 1
                Else
                    mmt = 0
                End If
                mam = lireINI("jtravaille", nomPersonne & "_mam")
                If mam = "true" Then
                    mamt = 1
                Else
                    mamt = 0
                End If
                mem = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mem")
                If mem = "true" Then
                    memt = 1
                Else
                    memt = 0
                End If
                meam = lireINI("jtravaille", nomPersonne & "_meam")
                If meam = "true" Then
                    meamt = 1
                Else
                    meamt = 0
                End If
                jm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jm")
                If jm = "true" Then
                    jmt = 1
                Else
                    jmt = 0
                End If
                jam = lireINI("jtravaille", nomPersonne & "_jam")
                If jam = "true" Then
                    jamt = 1
                Else
                    jamt = 0
                End If
                vm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vm")
                If vm = "true" Then
                    vmt = 1
                Else
                    vmt = 0
                End If
                vam = lireINI("jtravaille", nomPersonne & "_vam")
                If vam = "true" Then
                    vamt = 1
                Else
                    vamt = 0
                End If
                sm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sm")
                If sm = "true" Then
                    smt = 1
                Else
                    smt = 0
                End If
                sam = lireINI("jtravaille", nomPersonne & "_sam")
                If sam = "true" Then
                    samt = 1
                Else
                    samt = 0
                End If
                dm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dm")
                If dm = "true" Then
                    dmt = 1
                Else
                    dmt = 0
                End If
                dam = lireINI("jtravaille", nomPersonne & "_dam")
                If dam = "true" Then
                    damt = 1
                Else
                    damt = 0
                End If
                If jourdebut = "lundi" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * lmt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * lamt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "lundi" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * lmt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * lamt)
                    heuretotal2 = htotm2 + htotapm2
                End If
                If jourdebut = "mardi" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * mmt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * mamt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "mardi" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * mmt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * mamt)
                    heuretotal2 = htotm2 + htotapm2
                End If
                If jourdebut = "mercredi" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * memt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * meamt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "mercredi" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * memt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * meamt)
                    heuretotal2 = htotm2 + htotapm2
                End If
                If jourdebut = "jeudi" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * jmt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * jamt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "jeudi" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * jmt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * jamt)
                    heuretotal2 = htotm2 + htotapm2
                End If
                If jourdebut = "vendredi" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * vmt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * vamt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "vendredi" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * vmt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * vamt)
                    heuretotal2 = htotm2 + htotapm2
                End If
                If jourdebut = "samedi" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * smt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * samt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "samedi" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * smt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * samt)
                    heuretotal2 = htotm2 + htotapm2
                End If
                If jourdebut = "dimanche" Then
                    htotm1 = TimeSpan.FromTicks(htotm1.Ticks * dmt)
                    htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * damt)
                    heuretotal1 = htotm1 + htotapm1
                End If
                If jourfin = "dimanche" Then
                    htotm2 = TimeSpan.FromTicks(htotm2.Ticks * dmt)
                    htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * damt)
                    heuretotal2 = htotm2 + htotapm2
                End If

                'nombre de lundi, mardi, etc. entre le jour de départ et d'arrivée

                nlundi = lundi(CDate(TextBox3.Text), date2)
                nmardi = mardi(CDate(TextBox3.Text), date2)
                nmercredi = mercredi(CDate(TextBox3.Text), date2)
                njeudi = jeudi(CDate(TextBox3.Text), date2)
                nvendredi = vendredi(CDate(TextBox3.Text), date2)
                nsamedi = samedi(CDate(TextBox3.Text), date2)
                ndimanche = dimanche(CDate(TextBox3.Text), date2)

                'total des heures des lundis, mardis, etc entre la date de départ et d'arrivée
                tlundim = TimeSpan.FromTicks(heurem.Ticks * nlundi * lmt)
                tlundiapm = TimeSpan.FromTicks(heureapm.Ticks * nlundi * lamt)

                tmardim = TimeSpan.FromTicks(heurem.Ticks * nmardi * mmt)
                tmardiapm = TimeSpan.FromTicks(heureapm.Ticks * nmardi * mamt)

                tmercredim = TimeSpan.FromTicks(heurem.Ticks * nmercredi * memt)
                tmercrediapm = TimeSpan.FromTicks(heureapm.Ticks * nmercredi * meamt)

                tjeudim = TimeSpan.FromTicks(heurem.Ticks * njeudi * jmt)
                tjeudiapm = TimeSpan.FromTicks(heureapm.Ticks * njeudi * jamt)

                tvendredim = TimeSpan.FromTicks(heurem.Ticks * nvendredi * vmt)
                tvendrediapm = TimeSpan.FromTicks(heureapm.Ticks * nvendredi * vamt)

                tsamedim = TimeSpan.FromTicks(heurem.Ticks * nsamedi * smt)
                tsamediapm = TimeSpan.FromTicks(heureapm.Ticks * nsamedi * samt)

                tdimanchem = TimeSpan.FromTicks(heurem.Ticks * ndimanche * dmt)
                tdimancheapm = TimeSpan.FromTicks(heureapm.Ticks * ndimanche * damt)


                'heures totales sans jours congés
                Dim heuretotalsansjc, heuretotaleavecjc
                'heuretotalsansjc = heuretotal + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm

                'détermine le nombre de jours congés entre la date de début et de fin
                ComboBox5.Items.Clear()
                Dim dt1 As Date = CDate(TextBox3.Text)
                Dim dt2 As Date = date2
                ComboBox5.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
                For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                    ComboBox5.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
                Next

                Dim jcentredeux As Integer
                jcentredeux = 0
                Dim jourcongeentredeux
                For i = 0 To ComboBox4.Items.Count - 1
                    For y = 1 To ComboBox5.Items.Count - 2
                        If ComboBox5.Items(y) = ComboBox4.Items(i) Then
                            jcentredeux = jcentredeux + 1
                        End If
                    Next
                Next
                jourcongeentredeux = TimeSpan.FromTicks(htotmapm.Ticks * jcentredeux)

                'determine si le jour de départ ou d'arrivée est congé
                Dim jour1, jour2 As Integer
                For i = 0 To ComboBox4.Items.Count - 1
                    If TextBox3.Text = ComboBox4.Items(i) Then
                        jour1 = 1
                        Exit For
                    Else
                        jour1 = 0
                    End If
                Next
                For i = 0 To ComboBox4.Items.Count - 1
                    If TextBox4.Text = ComboBox4.Items(i) Then
                        jour2 = 1
                        Exit For
                    Else
                        jour2 = 0
                    End If
                Next
                If jour1 = 1 And jour2 = 0 Then
                    result1jour = (htotm2 + htotapm2 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                ElseIf jour1 = 0 And jour2 = 1 Then
                    result1jour = (htotm1 + htotapm1 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                ElseIf jour1 = 1 And jour2 = 1 Then
                    result1jour = (tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                Else
                    result1jour = (heuretotal1 + heuretotal2 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                End If

                'total des heures entre les jours travaillés

                'TextBox12.Text = jourcongef.ToString
            End If
        End If


    End Function



    Function heure()
        Dim heure22
        If (ComboBox2.Text <> "") Then
            Dim nomPersonne As String = ComboBox2.SelectedItem.ToString()

            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure1") <> "") Then
                h1 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure1"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure2") <> "") Then
                h2 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure2"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure3") <> "") Then
                h3 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure3"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure4") <> "") Then
                h4 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure4"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure5") <> "") Then
                h5 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure5"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure6") <> "") Then
                h6 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure6"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure7") <> "") Then
                h7 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure7"))
            End If
            If (lireINI("heuresjournaliere", ComboBox8.Text & nomPersonne & "_heure8") <> "") Then
                h8 = TimeSpan.Parse(lireINI("heuresjournaliere", nomPersonne & "_heure8"))
            End If


            heure1 = TimeSpan.Parse(TextBox6.Text)
            TextBox4.Text = DateTime.Now.ToString("dd/MM/yyyy")
            Dim boutonstop2 As String
            boutonstop2 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            If boutonstop2 = "vrai" Then
                heure22 = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss"))
            Else
                heure22 = TimeSpan.Parse(TextBox7.Text)
            End If
            If (lireINI("htot2", ComboBox2.Text & ComboBox1.Text)) = "" Then
                ecrireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text, "00:00:00")
            End If
            heure3 = TimeSpan.Parse(lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
            heurem = (h2 - h1) + (h4 - h3)
            heureapm = (h6 - h5) + (h8 - h7)
            htotmapm = heurem + heureapm

            'nombre de jours entre la date de départ et d'arrivée
            If TextBox4.Text <> "" Then
                Dim datTim1 As Date = CDate(TextBox3.Text)
                Dim datTim2 As Date = DateTime.Now.Date
                Dim diff As Long = DateDiff("d", datTim1, datTim2)
                'TextBox11.Text = diff



                'jour de la semaine en clair du jour du départ
                Dim jourdebut As String
                jourdebut = Format(CDate(TextBox3.Text), "dddd")
                'TextBox9.Text = jourdebut

                'jour de la semaine en clair du jour de fin
                Dim jourfin As String
                If boutonstop2 = "vrai" Then
                    jourfin = Format((DateTime.Now.Date), "dddd")
                Else
                    jourfin = Format(CDate(TextBox4.Text), "dddd")
                End If
                TextBox9.Text = jourfin

                'compte les heures si jour départ = jour arrivée
                If diff = 0 Then
                    'matin
                    If heure1 <= h1 And heure22 <= h1 Then
                        htotm = TimeSpan.Parse("00:00:00")
                    ElseIf heure1 <= h1 And (heure22 >= h1 And heure22 <= h2) Then
                        htotm = heure22 - h1
                    ElseIf heure1 <= h1 And (heure22 >= h2 And heure22 <= h3) Then
                        htotm = h2 - h1
                    ElseIf heure1 <= h1 And (heure22 >= h3 And heure22 <= h4) Then
                        htotm = (heure22 - h3) + (h2 - h1)
                    ElseIf heure1 <= h1 And (heure22 >= h4) Then
                        htotm = (h4 - h3) + (h2 - h1)
                    ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 <= h2) Then
                        htotm = heure22 - heure1
                    ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 >= h2 And heure22 <= h3) Then
                        htotm = h2 - heure1
                    ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 >= h3 And heure22 <= h4) Then
                        htotm = (heure22 - h3) + (h2 - heure1)
                    ElseIf (heure1 >= h1 And heure1 <= h2) And (heure22 >= h4) Then
                        htotm = (h4 - h3) + (h2 - heure1)
                    ElseIf (heure1 >= h2 And heure1 <= h3) And (heure22 <= h3) Then
                        htotm = TimeSpan.Parse("00:00:00")
                    ElseIf (heure1 >= h2 And heure1 <= h3) And (heure22 >= h3 And heure22 <= h4) Then
                        htotm = (heure22 - h3)
                    ElseIf (heure1 >= h2 And heure1 <= h3) And (heure22 >= h4) Then
                        htotm = h4 - h3
                    ElseIf (heure1 >= h3 And heure1 <= h4) And (heure22 >= h3 And heure22 <= h4) Then
                        htotm = heure22 - heure1
                    ElseIf (heure1 >= h3 And heure1 <= h4) And (heure22 >= h4) Then
                        htotm = h4 - heure1
                    ElseIf heure1 >= h4 Then
                        htotm = TimeSpan.Parse("00:00:00")
                    End If
                    'après-midi
                    If heure1 <= h5 And heure22 <= h5 Then
                        htotapm = TimeSpan.Parse("00:00:00")
                    ElseIf heure1 <= h5 And (heure22 >= h5 And heure22 <= h6) Then
                        htotapm = heure22 - h5
                    ElseIf heure1 <= h5 And (heure22 >= h6 And heure22 <= h7) Then
                        htotapm = h6 - h5
                    ElseIf heure1 <= h5 And (heure22 >= h7 And heure22 <= h8) Then
                        htotapm = (heure22 - h7) + (h6 - h5)
                    ElseIf heure1 <= h5 And (heure22 >= h8) Then
                        htotapm = (h8 - h7) + (h6 - h5)
                    ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 <= h6) Then
                        htotapm = heure22 - heure1
                    ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 >= h6 And heure22 <= h7) Then
                        htotapm = h6 - heure1
                    ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 >= h7 And heure22 <= h8) Then
                        htotapm = (heure22 - h7) + (h6 - heure1)
                    ElseIf (heure1 >= h5 And heure1 <= h6) And (heure22 >= h8) Then
                        htotapm = (h8 - h7) + (h6 - heure1)
                    ElseIf (heure1 >= h6 And heure1 <= h7) And (heure22 <= h7) Then
                        htotapm = TimeSpan.Parse("00:00:00")
                    ElseIf (heure1 >= h6 And heure1 <= h7) And (heure22 >= h7 And heure22 <= h8) Then
                        htotapm = (heure22 - h7)
                    ElseIf (heure1 >= h6 And heure1 <= h7) And (heure22 >= h8) Then
                        htotapm = h8 - h7
                    ElseIf (heure1 >= h7 And heure1 <= h8) And (heure22 >= h7 And heure22 <= h8) Then
                        htotapm = heure22 - heure1
                    ElseIf (heure1 >= h7 And heure1 <= h8) And (heure22 >= h8) Then
                        htotapm = h8 - heure1
                    ElseIf heure1 >= h8 Then
                        htotapm = TimeSpan.Parse("00:00:00")
                    End If

                    'control si les jours sont travaillés

                    lm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lm")
                    If lm = "true" Then
                        lmt = 1
                    Else
                        lmt = 0
                    End If
                    lam = lireINI("jtravaille", nomPersonne & "_lam")
                    If lam = "true" Then
                        lamt = 1
                    Else
                        lamt = 0
                    End If
                    mm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mm")
                    If mm = "true" Then
                        mmt = 1
                    Else
                        mmt = 0
                    End If
                    mam = lireINI("jtravaille", nomPersonne & "_mam")
                    If mam = "true" Then
                        mamt = 1
                    Else
                        mamt = 0
                    End If
                    mem = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mem")
                    If mem = "true" Then
                        memt = 1
                    Else
                        memt = 0
                    End If
                    meam = lireINI("jtravaille", nomPersonne & "_meam")
                    If meam = "true" Then
                        meamt = 1
                    Else
                        meamt = 0
                    End If
                    jm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jm")
                    If jm = "true" Then
                        jmt = 1
                    Else
                        jmt = 0
                    End If
                    jam = lireINI("jtravaille", nomPersonne & "_jam")
                    If jam = "true" Then
                        jamt = 1
                    Else
                        jamt = 0
                    End If
                    vm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vm")
                    If vm = "true" Then
                        vmt = 1
                    Else
                        vmt = 0
                    End If
                    vam = lireINI("jtravaille", nomPersonne & "_vam")
                    If vam = "true" Then
                        vamt = 1
                    Else
                        vamt = 0
                    End If
                    sm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sm")
                    If sm = "true" Then
                        smt = 1
                    Else
                        smt = 0
                    End If
                    sam = lireINI("jtravaille", nomPersonne & "_sam")
                    If sam = "true" Then
                        samt = 1
                    Else
                        samt = 0
                    End If
                    dm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dm")
                    If dm = "true" Then
                        dmt = 1
                    Else
                        dmt = 0
                    End If
                    dam = lireINI("jtravaille", nomPersonne & "_dam")
                    If dam = "true" Then
                        damt = 1
                    Else
                        damt = 0
                    End If
                    If jourdebut = "lundi" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * lmt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * lamt)
                        heuretotal = htotm + htotapm
                    ElseIf jourdebut = "mardi" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * mmt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * mamt)
                        heuretotal = htotm + htotapm
                    ElseIf jourdebut = "mercredi" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * memt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * meamt)
                        heuretotal = htotm + htotapm
                    ElseIf jourdebut = "jeudi" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * jmt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * jamt)
                        heuretotal = htotm + htotapm
                    ElseIf jourdebut = "vendredi" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * vmt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * vamt)
                        heuretotal = htotm + htotapm
                    ElseIf jourdebut = "samedi" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * smt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * samt)
                        heuretotal = htotm + htotapm
                    ElseIf jourdebut = "dimanche" Then
                        htotm = TimeSpan.FromTicks(htotm.Ticks * dmt)
                        htotapm = TimeSpan.FromTicks(htotapm.Ticks * damt)
                        heuretotal = htotm + htotapm
                    End If
                    For i = 0 To ComboBox4.Items.Count - 1
                        If TextBox3.Text = ComboBox4.Items(i) Then
                            heuretotal = TimeSpan.Parse("00:00:00")
                            Exit For
                        End If
                    Next
                    'heures totales pour 1 seul jour
                    'text5 = TimeSpan.Parse(lireINI("htot2", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
                    result1jour2 = heuretotal + heure3
                    'TextBox12.Text = datTim1.ToString
                ElseIf diff > 0 Then
                    Dim date2
                    boutonstop2 = lireINI("boutonstop", ComboBox2.Text & ComboBox1.Text)
                    If boutonstop2 = "vrai" Then
                        date2 = DateTime.Now.ToString("dd/MM/yyyy")
                    Else
                        date2 = CDate(TextBox4.Text)
                    End If

                    If heure1 <= h1 Then
                        htotm1 = (h4 - h3) + (h2 - h1)
                    ElseIf heure1 >= h1 And heure1 <= h2 Then
                        htotm1 = (h2 - heure1) + (h4 - h3)
                    ElseIf heure1 >= h2 And heure1 <= h3 Then
                        htotm1 = h4 - h3
                    ElseIf heure1 >= h3 And heure1 <= h4 Then
                        htotm1 = h4 - heure1
                    ElseIf heure1 >= h4 Then
                        htotm1 = TimeSpan.Parse("00:00:00")
                    End If
                    If heure1 <= h5 Then
                        htotapm1 = (h8 - h7) + (h6 - h5)
                    ElseIf heure1 >= h5 And heure1 <= h6 Then
                        htotapm1 = (h8 - h7) + (h6 - heure1)
                    ElseIf heure1 >= h6 And heure1 <= h7 Then
                        htotapm1 = h8 - h7
                    ElseIf heure1 >= h7 And heure1 <= h8 Then
                        htotapm1 = h8 - heure1
                    ElseIf heure1 >= h8 Then
                        htotapm1 = TimeSpan.Parse("00:00:00")
                    End If
                    If heure22 <= h1 Then
                        htotm2 = TimeSpan.Parse("00:00:00")
                    ElseIf heure22 >= h1 And heure22 <= h2 Then
                        htotm2 = heure22 - h1
                    ElseIf heure22 >= h2 And heure22 <= h3 Then
                        htotm2 = h2 - h1
                    ElseIf heure22 >= h3 And heure22 <= h4 Then
                        htotm2 = (heure22 - h3) + (h2 - h1)
                    ElseIf heure22 >= h4 Then
                        htotm2 = (h4 - h3) + (h2 - h1)
                    End If
                    If heure22 <= h5 Then
                        htotapm2 = TimeSpan.Parse("00:00:00")
                    ElseIf heure22 >= h5 And heure22 <= h6 Then
                        htotapm2 = heure22 - h5
                    ElseIf heure22 >= h6 And heure22 <= h7 Then
                        htotapm2 = h6 - h5
                    ElseIf heure22 >= h7 And heure22 <= h8 Then
                        htotapm2 = (heure22 - h7) + (h6 - h5)
                    ElseIf heure22 >= h8 Then
                        htotapm2 = (h8 - h7) + (h6 - h5)
                    End If


                    'control si les jours sont travaillés

                    lm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_lm")
                    If lm = "true" Then
                        lmt = 1
                    Else
                        lmt = 0
                    End If
                    lam = lireINI("jtravaille", nomPersonne & "_lam")
                    If lam = "true" Then
                        lamt = 1
                    Else
                        lamt = 0
                    End If
                    mm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mm")
                    If mm = "true" Then
                        mmt = 1
                    Else
                        mmt = 0
                    End If
                    mam = lireINI("jtravaille", nomPersonne & "_mam")
                    If mam = "true" Then
                        mamt = 1
                    Else
                        mamt = 0
                    End If
                    mem = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_mem")
                    If mem = "true" Then
                        memt = 1
                    Else
                        memt = 0
                    End If
                    meam = lireINI("jtravaille", nomPersonne & "_meam")
                    If meam = "true" Then
                        meamt = 1
                    Else
                        meamt = 0
                    End If
                    jm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_jm")
                    If jm = "true" Then
                        jmt = 1
                    Else
                        jmt = 0
                    End If
                    jam = lireINI("jtravaille", nomPersonne & "_jam")
                    If jam = "true" Then
                        jamt = 1
                    Else
                        jamt = 0
                    End If
                    vm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_vm")
                    If vm = "true" Then
                        vmt = 1
                    Else
                        vmt = 0
                    End If
                    vam = lireINI("jtravaille", nomPersonne & "_vam")
                    If vam = "true" Then
                        vamt = 1
                    Else
                        vamt = 0
                    End If
                    sm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_sm")
                    If sm = "true" Then
                        smt = 1
                    Else
                        smt = 0
                    End If
                    sam = lireINI("jtravaille", nomPersonne & "_sam")
                    If sam = "true" Then
                        samt = 1
                    Else
                        samt = 0
                    End If
                    dm = lireINI("jtravaille", ComboBox8.Text & nomPersonne & "_dm")
                    If dm = "true" Then
                        dmt = 1
                    Else
                        dmt = 0
                    End If
                    dam = lireINI("jtravaille", nomPersonne & "_dam")
                    If dam = "true" Then
                        damt = 1
                    Else
                        damt = 0
                    End If


                    If jourdebut = "lundi" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * lmt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * lamt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "lundi" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * lmt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * lamt)
                        heuretotal2 = htotm2 + htotapm2
                    End If
                    If jourdebut = "mardi" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * mmt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * mamt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "mardi" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * mmt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * mamt)
                        heuretotal2 = htotm2 + htotapm2
                    End If
                    If jourdebut = "mercredi" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * memt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * meamt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "mercredi" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * memt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * meamt)
                        heuretotal2 = htotm2 + htotapm2
                    End If
                    If jourdebut = "jeudi" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * jmt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * jamt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "jeudi" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * jmt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * jamt)
                        heuretotal2 = htotm2 + htotapm2
                    End If
                    If jourdebut = "vendredi" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * vmt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * vamt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "vendredi" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * vmt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * vamt)
                        heuretotal2 = htotm2 + htotapm2
                    End If
                    If jourdebut = "samedi" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * smt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * samt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "samedi" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * smt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * samt)
                        heuretotal2 = htotm2 + htotapm2
                    End If
                    If jourdebut = "dimanche" Then
                        htotm1 = TimeSpan.FromTicks(htotm1.Ticks * dmt)
                        htotapm1 = TimeSpan.FromTicks(htotapm1.Ticks * damt)
                        heuretotal1 = htotm1 + htotapm1
                    End If
                    If jourfin = "dimanche" Then
                        htotm2 = TimeSpan.FromTicks(htotm2.Ticks * dmt)
                        htotapm2 = TimeSpan.FromTicks(htotapm2.Ticks * damt)
                        heuretotal2 = htotm2 + htotapm2
                    End If

                    'nombre de lundi, mardi, etc. entre le jour de départ et d'arrivée

                    nlundi = lundi(CDate(TextBox3.Text), date2)
                    nmardi = mardi(CDate(TextBox3.Text), date2)
                    nmercredi = mercredi(CDate(TextBox3.Text), date2)
                    njeudi = jeudi(CDate(TextBox3.Text), date2)
                    nvendredi = vendredi(CDate(TextBox3.Text), date2)
                    nsamedi = samedi(CDate(TextBox3.Text), date2)
                    ndimanche = dimanche(CDate(TextBox3.Text), date2)

                    'total des heures des lundis, mardis, etc entre la date de départ et d'arrivée
                    tlundim = TimeSpan.FromTicks(heurem.Ticks * nlundi * lmt)
                    tlundiapm = TimeSpan.FromTicks(heureapm.Ticks * nlundi * lamt)

                    tmardim = TimeSpan.FromTicks(heurem.Ticks * nmardi * mmt)
                    tmardiapm = TimeSpan.FromTicks(heureapm.Ticks * nmardi * mamt)

                    tmercredim = TimeSpan.FromTicks(heurem.Ticks * nmercredi * memt)
                    tmercrediapm = TimeSpan.FromTicks(heureapm.Ticks * nmercredi * meamt)

                    tjeudim = TimeSpan.FromTicks(heurem.Ticks * njeudi * jmt)
                    tjeudiapm = TimeSpan.FromTicks(heureapm.Ticks * njeudi * jamt)

                    tvendredim = TimeSpan.FromTicks(heurem.Ticks * nvendredi * vmt)
                    tvendrediapm = TimeSpan.FromTicks(heureapm.Ticks * nvendredi * vamt)

                    tsamedim = TimeSpan.FromTicks(heurem.Ticks * nsamedi * smt)
                    tsamediapm = TimeSpan.FromTicks(heureapm.Ticks * nsamedi * samt)

                    tdimanchem = TimeSpan.FromTicks(heurem.Ticks * ndimanche * dmt)
                    tdimancheapm = TimeSpan.FromTicks(heureapm.Ticks * ndimanche * damt)


                    'heures totales sans jours congés
                    Dim heuretotalsansjc, heuretotaleavecjc
                    'heuretotalsansjc = heuretotal + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm

                    'détermine le nombre de jours congés entre la date de début et de fin
                    ComboBox5.Items.Clear()
                    Dim dt1 As Date = CDate(TextBox3.Text)
                    Dim dt2 As Date = date2
                    ComboBox5.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
                    For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                        ComboBox5.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
                    Next

                    Dim jcentredeux As Integer
                    jcentredeux = 0
                    Dim jourcongeentredeux
                    For i = 0 To ComboBox4.Items.Count - 1
                        For y = 1 To ComboBox5.Items.Count - 2
                            If ComboBox5.Items(y) = ComboBox4.Items(i) Then
                                jcentredeux = jcentredeux + 1
                            End If
                        Next
                    Next
                    jourcongeentredeux = TimeSpan.FromTicks(htotmapm.Ticks * jcentredeux)

                    'determine si le jour de départ ou d'arrivée est congé
                    Dim jour1, jour2 As Integer
                    For i = 0 To ComboBox4.Items.Count - 1
                        If TextBox3.Text = ComboBox4.Items(i) Then
                            jour1 = 1
                            Exit For
                        Else
                            jour1 = 0
                        End If
                    Next
                    For i = 0 To ComboBox4.Items.Count - 1
                        If TextBox4.Text = ComboBox4.Items(i) Then
                            jour2 = 1
                            Exit For
                        Else
                            jour2 = 0
                        End If
                    Next
                    If jour1 = 1 And jour2 = 0 Then
                        result1jour2 = (htotm2 + htotapm2 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                    ElseIf jour1 = 0 And jour2 = 1 Then
                        result1jour2 = (htotm1 + htotapm1 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                    ElseIf jour1 = 1 And jour2 = 1 Then
                        result1jour2 = (tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                    Else
                        result1jour2 = (heuretotal1 + heuretotal2 + tlundim + tlundiapm + tmardim + tmardiapm + tmercredim + tmercrediapm + tjeudim + tjeudiapm + tvendredim + tvendrediapm + tsamedim + tsamediapm + tdimanchem + tdimancheapm + heure3) - jourcongeentredeux
                    End If

                    'total des heures entre les jours travaillés

                    'TextBox12.Text = jourcongef.ToString
                End If
            End If

        End If
    End Function

    Private Sub Timer3_Tick(sender As Object, e As EventArgs)


    End Sub




    Private Sub chargerpersonnes()
        If ComboBox2.Items.Count < ComboBox6.Items.Count Then
            Dim oui As Integer
            oui = 0
            For i = 0 To ComboBox6.Items.Count - 1
                oui = 0
                For y = 0 To ComboBox2.Items.Count - 1
                    If ComboBox6.Items(i) = ComboBox2.Items(y) Then
                        oui = 1

                    End If
                    If y = ComboBox2.Items.Count - 1 And oui <> 1 Then
                        DeleteKey(".\badgeuse.ini", "boutonstop", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "htot1", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "htot2", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured1", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured2", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured3", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured4", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "dated1", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "dated2", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "notes", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heured1d", ComboBox6.Items(i) & ComboBox1.Text)
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure1")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure2")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure3")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure4")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure5")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure6")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure7")
                        DeleteKey(".\badgeuse.ini", "heuresjournaliere", ComboBox6.Items(i) & "_heure8")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_lm")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_lam")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_mm")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_mam")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_mem")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_meam")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_jm")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_jam")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_vm")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_vam")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_sm")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_sam")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_dm")
                        DeleteKey(".\badgeuse.ini", "jtravaille", ComboBox6.Items(i) & "_dam")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_1")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_2")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_3")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_4")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_5")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_6")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_7")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_8")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_9")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_10")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_11")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_12")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_13")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_14")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_15")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_16")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_17")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_18")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_19")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_20")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_21")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_22")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_23")
                        DeleteKey(".\badgeuse.ini", "jfv", ComboBox6.Items(i) & "_24")
                    End If
                Next
            Next


        End If
        Dim iniSection As String = "heuresjournaliere"
        ' Tableau des valeurs à écrire pour heure1 à heure8
        Dim valeurs() As String = {
        "07:30:00",
        "09:20:00",
        "09:40:00",
        "11:35:00",
        "12:50:00",
        "14:35:00",
        "14:50:00",
        "16:50:00"
    }

        For Each personneObj In ComboBox2.Items
            Dim personne As String = personneObj.ToString()

            For i As Integer = 1 To valeurs.Length
                Dim nomHeure As String = "heure" & i
                Dim cleComplete As String = $"{personne}_{nomHeure}"

                ' On lit la valeur actuelle (renvoie "" si rien)
                Dim existingValue As String = lireINI(iniSection, ComboBox8.Text & cleComplete)

                ' Si vide ou uniquement des espaces, on écrit la valeur du tableau
                If String.IsNullOrWhiteSpace(existingValue) Then
                    ecrireINI(iniSection, ComboBox8.Text & cleComplete, valeurs(i - 1))
                    'Debug.WriteLine($"Écriture de '{valeurs(i - 1)}' pour {cleComplete}")
                End If
            Next
        Next

    End Sub


    Private Sub chargertravaux()
        If ComboBox1.Items.Count < ComboBox7.Items.Count Then
            Dim oui As Integer
            oui = 0
            For i = 0 To ComboBox7.Items.Count - 1
                oui = 0
                For y = 0 To ComboBox1.Items.Count - 1
                    If ComboBox7.Items(i) = ComboBox1.Items(y) Then
                        oui = 1

                    End If
                    If y = ComboBox1.Items.Count - 1 And oui <> 1 Then
                        DeleteKey(".\badgeuse.ini", "heurestr", ComboBox7.Items(i))
                        DeleteKey(".\badgeuse.ini", "notes", ComboBox2.Text & ComboBox7.Items(i))
                    End If
                Next
            Next
        End If
    End Sub

    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        If TextBox13.Text <> "" And Len(TextBox13.Text) = 11 Then
            'note
            If Label3.Text <> "" And TextBox13.Text <> "" Then
                Dim formule, heur3, heur4, formule1 As Single
                Dim coefficient As Integer
                Dim heur1, heur2 As TimeSpan
                If RadioButton1.Checked = True Then
                    coefficient = 155
                Else
                    coefficient = 120
                End If
                heur1 = result1jour2
                heur2 = TimeSpan.Parse(TextBox13.Text)
                heur3 = heur1.TotalSeconds
                heur4 = heur2.TotalSeconds
                formule1 = heur3 - heur4
                formule = ((formule1 / heur4) * 100)
                If formule1 < 0 Or formule1 = 0 Then
                    TextBox14.Text = notemaxi.Text '6
                Else
                    TextBox14.Text = Math.Round((notemaxi.Text - ((notemaxi.Text * formule) / coefficient)) / 5, 1) * 5
                    'ElseIf (formule1) = 0 Then
                    '   TextBox14.Text = Math.Round((6 - ((6 * formule) / coefficient)) / 5, 1) * 5
                End If
                'If TextBox14.Text < 1 Then
                'TextBox14.Text = 1
                'End If
                'TextBox11.Text = heur3
                'TextBox12.Text = heur4
            End If


        End If

        ecrireINI("coefficient155", ComboBox8.Text & "coeff", False)
        ecrireINI("coefficient120", ComboBox8.Text & "coeff", True)
    End Sub




    Private Sub TextBox13_TextChanged(sender As Object, e As EventArgs) Handles TextBox13.TextChanged

    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        attention.Show()
    End Sub

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        travauxencours.Show()
        travauxencours.Show()
        travauxencours.ListView1.View = View.Details
        travauxencours.ListView1.Columns.Add("Personne(s)", 300, HorizontalAlignment.Left)
        travauxencours.ListView1.Columns.Add("Travail(aux) en cours...", 300, HorizontalAlignment.Left)
        Dim anyFound As Boolean = False
        travauxencours.ListView1.Items.Clear()

        For i As Integer = 0 To ComboBox2.Items.Count - 1
            For y As Integer = 0 To ComboBox1.Items.Count - 1
                If lireINI("boutonstop", ComboBox8.Text & ComboBox2.Items(i) & ComboBox1.Items(y)) = "vrai" Then
                    ' On a trouvé un travail en cours : on ajoute et on marque le flag
                    Dim MyLine As New ListViewItem(New String() {ComboBox2.Items(i).ToString(), ComboBox1.Items(y).ToString()})
                    travauxencours.ListView1.Items.Add(MyLine)
                    anyFound = True
                End If
                ' Sinon on ne fait rien (pas besoin d'un Else vide)
            Next
        Next

        ' Après les boucles, si on n’a jamais ajouté, on affiche le message :
        If Not anyFound Then
            travauxencours.ListView1.Items.Add(New ListViewItem("Personne n'a un travail en cours"))
        End If
    End Sub


    Function rafraichir()
        Dim boutonstop2 As String
        boutonstop2 = lireINI("boutonstop", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
        If boutonstop2 = "vrai" Then
            temps1jour()

            'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox2.Text & ComboBox1.Text))
            'temps = (ts).TotalSeconds
            Dim result1jour3, right As String
            Dim m11, j11, h11, min11, s11 As Single
            result1jour3 = result1jour.ToString
            If Len(result1jour3) = 10 Then
                right = result1jour3.Substring(result1jour3.Length - 10, 1)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = j11 + h11 + min11 + s11
            ElseIf Len(result1jour3) = 11 Then
                right = result1jour3.Substring(result1jour3.Length - 11, 2)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = j11 + h11 + min11 + s11
            ElseIf Len(result1jour3) = 12 Then
                right = result1jour3.Substring(result1jour3.Length - 12, 3)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = m11 + j11 + h11 + min11 + s11
            ElseIf Len(result1jour3) = 13 Then
                right = result1jour3.Substring(result1jour3.Length - 13, 4)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = m11 + j11 + h11 + min11 + s11
            Else
                temps = (result1jour).TotalSeconds
            End If
            's(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
            mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
            j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
            j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
            If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
            If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
            If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
            If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
            If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
            If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

            hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
            min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
            sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
            If (sec2 = -1) Then sec2 = 0
            TextBox8.Text = temps.ToString()
            TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

            'Timer3.Enabled = True
        ElseIf boutonstop2 = "faux" And TextBox3.Text <> "" Then
            temps1jour()

            'Dim ts As TimeSpan = TimeSpan.Parse(lireINI("htot1", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text))
            'temps = (ts).TotalSeconds
            Dim result1jour3, right As String
            Dim m11, j11, h11, min11, s11 As Single
            result1jour3 = Label3.Text.ToString
            If Len(result1jour3) = 10 Then
                right = result1jour3.Substring(result1jour3.Length - 10, 1)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = j11 + h11 + min11 + s11
            ElseIf Len(result1jour3) = 11 Then
                right = result1jour3.Substring(result1jour3.Length - 11, 2)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = j11 + h11 + min11 + s11
            ElseIf Len(result1jour3) = 12 Then
                right = result1jour3.Substring(result1jour3.Length - 12, 3)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = m11 + j11 + h11 + min11 + s11
            ElseIf Len(result1jour3) = 13 Then
                right = result1jour3.Substring(result1jour3.Length - 13, 4)
                j11 = right * 60 * 60 * 60 'result1jour2.Substring(-3)
                right = result1jour3.Substring(result1jour3.Length - 8, 2)
                h11 = right * 60 * 60
                right = result1jour3.Substring(result1jour3.Length - 5, 2)
                min11 = right * 60
                right = result1jour3.Substring(result1jour3.Length - 2, 2)
                s11 = right
                temps = m11 + j11 + h11 + min11 + s11
            Else
                temps = TimeSpan.Parse(Label3.Text).TotalSeconds
            End If
            '(result1jour).TotalSeconds
            't(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
            mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
            j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
            j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
            If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
            If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
            If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
            If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
            If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
            If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

            hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
            min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
            sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
            If (sec2 = -1) Then sec2 = 0
            TextBox8.Text = temps.ToString()
            TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

        ElseIf Label3.Text = "" Then
            temps = TimeSpan.Parse("00:00:00").TotalSeconds
            'nt(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
            mois2 = Int(temps / (777600000)) ' * DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)))
            j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
            j22 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)
            If (Int(((temps / (777600000) * 60) * 60))) >= 60 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 60
            If (Int(((temps / (777600000) * 60) * 60))) >= 120 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 120
            If (Int(((temps / (777600000) * 60) * 60))) >= 180 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 180
            If (Int(((temps / (777600000) * 60) * 60))) >= 240 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 240
            If (Int(((temps / (777600000) * 60) * 60))) >= 300 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 300
            If (Int(((temps / (777600000) * 60) * 60))) >= 360 Then j2 = Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) + 360

            hr2 = Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - j22) * 60)
            min2 = Int(((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - hr2) * 60)
            sec2 = Int(Int(((((((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60) - Int(((((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60) - Int(((((temps / 777600000) - mois2) * 60) - Int((((temps / 777600000) - mois2) * 60))) * 60)) * 60)) * 60) - min2) * 60))
            If (sec2 = -1) Then sec2 = 0
            TextBox8.Text = temps.ToString()
            TextBox10.Text = String.Format("{0:000}j {1:00}h {2:00}m {3:00}s", j2, hr2, min2, sec2)

        End If
        Dim note As String
            note = lireINI("notes", ComboBox8.Text & ComboBox2.Text & ComboBox1.Text)
            'TextBox14.Text = note
            If TextBox13.Text = "" Then TextBox14.Text = ""
            'TextBox12.Text = temps
        End Function

        Private Sub TextBox15_TextChanged(sender As Object, e As EventArgs) Handles TextBox15.TextChanged

        End Sub

        Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
        If TextBox13.Text <> "" And Len(TextBox13.Text) = 11 Then
            'note
            If Label3.Text <> "" And TextBox13.Text <> "" Then
                Dim formule, heur3, heur4, formule1 As Single
                Dim coefficient As Integer
                Dim heur1, heur2 As TimeSpan
                If RadioButton1.Checked = True Then
                    coefficient = 155
                Else
                    coefficient = 120
                End If
                heur1 = result1jour2
                heur2 = TimeSpan.Parse(TextBox13.Text)
                heur3 = heur1.TotalSeconds
                heur4 = heur2.TotalSeconds
                formule1 = heur3 - heur4
                formule = ((formule1 / heur4) * 100)
                If formule1 < 0 Or formule1 = 0 Then
                    TextBox14.Text = notemaxi.Text '6
                Else
                    TextBox14.Text = Math.Round((notemaxi.Text - ((notemaxi.Text * formule) / coefficient)) / 5, 1) * 5
                    'ElseIf (formule1) = 0 Then
                    '   TextBox14.Text = Math.Round((6 - ((6 * formule) / coefficient)) / 5, 1) * 5
                End If
                'If TextBox14.Text < 1 Then
                'TextBox14.Text = 1
                'End If
                'TextBox11.Text = heur3
                'TextBox12.Text = heur4
            End If

        End If

        ecrireINI("coefficient155", ComboBox8.Text & "coeff", True)
        ecrireINI("coefficient120", ComboBox8.Text & "coeff", False)
    End Sub

        Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged

        End Sub

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

        End Sub

        Private Sub TextBox14_TextChanged(sender As Object, e As EventArgs) Handles TextBox14.TextChanged

        End Sub

        Private Sub notemaxi_TextChanged(sender As Object, e As EventArgs) Handles notemaxi.TextChanged
            ecrireINI("notemaximum", ComboBox8.Text & "notemaximum", notemaxi.Text)
        End Sub

        Private Sub ComboBox7_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox7.SelectedIndexChanged

        End Sub

        Private Sub ComboBox6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox6.SelectedIndexChanged

        End Sub

        Private Sub ComboBox7_MouseHover(sender As Object, e As EventArgs) Handles ComboBox7.MouseHover

        End Sub

        Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged

        End Sub

        Private Sub Button8_MouseEnter(sender As Object, e As EventArgs) Handles Button8.MouseEnter

        End Sub

        Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click

        End Sub

        Private Sub Button8_FontChanged(sender As Object, e As EventArgs) Handles Button8.FontChanged
        End Sub

        Private Sub Button13_Click(sender As Object, e As EventArgs)

            MsgBox(Int(((temps / (777600000) * 60) * 60)))
        End Sub

    Private Sub Label17_Click(sender As Object, e As EventArgs) Handles Label17.Click

    End Sub

    Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs) Handles TextBox10.TextChanged

    End Sub

    Private Sub Button13_Click_1(sender As Object, e As EventArgs) Handles Button13.Click
        Dim filePath As String = Path.Combine("groupes.txt")
        Dim groupes As Process = Process.Start(filePath)
        groupes.WaitForExit()
        ChargerGroupes()

    End Sub

    'Private Sub Button13_LostFocus(sender As Object, e As EventArgs) Handles Button13.LostFocus
    '    ComboBox8.Items.Clear()
    '    Dim SR2 As New StreamReader(ComboBox8.Text & "groupes.txt")
    '    Do Until SR2.Peek = -1
    '        Dim Ligne2 As String
    '        Ligne2 = SR2.ReadLine()
    '        If Ligne2 <> "" Then
    '            Me.ComboBox8.Items.Add(Ligne2)
    '        End If
    '    Loop
    '    If ComboBox8.Items.Count > 0 Then
    '        Me.ComboBox8.SelectedIndex = 0
    '    End If
    'End Sub

    Private Sub ComboBox8_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.SelectedIndexChanged

        ecrireINI("DernierGroupesSelect", "General2", ComboBox8.SelectedIndex.ToString())
        Dim prefixe As String = ComboBox8.Text       ' ex: "Auma 2"
        Dim nomFichier As String = prefixe & "employes.txt" ' ou " " & "employes.txt" si votre fichier s'appelle "Auma 2 employes.txt"
        Dim fullPath As String = Path.Combine(Application.StartupPath, nomFichier)

        '--- création si nécessaire, avec "vide" à l'intérieur ---
        If Not File.Exists(fullPath) Then
            ' on écrit "vide" + un retour à la ligne pour qu'un StreamReader lise bien une ligne
            File.WriteAllText(fullPath, "vide" & Environment.NewLine)
        End If

        ComboBox2.Items.Clear()
        '--- lecture avec le même fullPath ---
        Using SR5 As New StreamReader(nomFichier)
            Do Until SR5.EndOfStream

                Dim ligne = SR5.ReadLine()
                If ligne <> "" Then ComboBox2.Items.Add(ligne)
            Loop
            ComboBox2.Sorted = True

        End Using


        '--- tri (on peut aussi le faire avant ou cocher la propriété Sorted à vrai) ---
        ComboBox2.Sorted = True
        If ComboBox2.Items.Count > 0 Then
            ComboBox2.SelectedIndex = 0

        End If


        Dim prefixe2 As String = ComboBox8.Text       ' ex: "Auma 2"
        Dim nomFichier2 As String = prefixe2 & "travaux.txt" ' ou " " & "employes.txt" si votre fichier s'appelle "Auma 2 employes.txt"
        Dim fullPath2 As String = Path.Combine(Application.StartupPath, nomFichier2)

        '--- création si nécessaire, avec "vide" à l'intérieur ---
        If Not File.Exists(fullPath2) Then
            ' on écrit "vide" + un retour à la ligne pour qu'un StreamReader lise bien une ligne
            File.WriteAllText(fullPath2, "vide" & Environment.NewLine)
        End If

        ComboBox1.Items.Clear()
        '--- lecture avec le même fullPath ---
        Using SR6 As New StreamReader(nomFichier2)
            Do Until SR6.EndOfStream

                Dim ligne2 = SR6.ReadLine()
                If ligne2 <> "" Then ComboBox1.Items.Add(ligne2)
            Loop
            ComboBox1.Sorted = True

        End Using


        '--- tri (on peut aussi le faire avant ou cocher la propriété Sorted à vrai) ---
        ComboBox1.Sorted = True
        If ComboBox1.Items.Count > 0 Then
            ComboBox1.SelectedIndex = 0

        End If

    End Sub
End Class

