Public Class Form5
    Dim db_informatique4 As New class4
    Dim masroufi As Double
    Dim thf, tmf, tsf As Integer


    

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Form1.Show()
        Me.Hide()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form3.Show()
        Me.Hide()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form4.Show()
        Me.Hide()
    End Sub

    Private Sub Form5_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Form1.Close()
    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        db_informatique4.Myreq = "select*from entrer "
        db_informatique4.Connecting_in_informatique()
        t1.Items.Clear()
        Do While db_informatique4.rdr.Read
            t1.Items.Add(db_informatique4.rdr(0).ToString)

        Loop
        db_informatique4.Disconnecting_in_informatique()
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If t1.Text = "" Or t2.Text = "" Or t4.Text = "" Or t5.Text = "" Then
            MsgBox("لايمكن ترك خانة فارغة", MsgBoxStyle.Information, "تنبيه المستخدم")

        Else
            Try
                db_informatique4.Myreq = "Insert Into entrer (username,pass,datebegin,salaire,type) values('" & t1.Text & "','" & t2.Text & "','" & t3.Text & "','" & t4.Text & "','" & t5.Text & "')"
                db_informatique4.Connecting_in_informatique()
                db_informatique4.Disconnecting_in_informatique()
                t1.Text = ""
                t2.Text = ""
                t3.Text = ""
                t4.Text = ""
                t5.Text = ""
                MsgBox("تم الاضافة", MsgBoxStyle.Information, "اضافة")


                db_informatique4.Myreq = "select*from entrer "
                db_informatique4.Connecting_in_informatique()
                t1.Items.Clear()
                Do While db_informatique4.rdr.Read
                    t1.Items.Add(db_informatique4.rdr(0).ToString)

                Loop
                db_informatique4.Disconnecting_in_informatique()
            Catch ex As Exception
                MsgBox("هذا المستخدم موجود سابقا", MsgBoxStyle.Information, "تنبيه المستخدم")
                t1.Text = ""
                t1.Focus()
            End Try

        End If

    End Sub

    Private Sub t4_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t4.KeyPress
        If (Not Char.IsControl(e.KeyChar) And Not Char.IsDigit(e.KeyChar) And (e.KeyChar <> ".")) Then
            t4.BackColor = Color.Red
            e.Handled = True
        Else
            t4.BackColor = Color.White
        End If

        If ((e.KeyChar = ".") And ((sender).Text.IndexOf(".") > -1)) Then

            e.Handled = True
        End If
    End Sub

    Private Sub t1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.SelectedIndexChanged
        db_informatique4.Myreq = "select*from entrer where username='" & t1.Text & "'"
        db_informatique4.Connecting_in_informatique()
      

        Do While db_informatique4.rdr.Read
            t2.Text = (db_informatique4.rdr(1).ToString)
            t3.Text = (db_informatique4.rdr(2).ToString)
            t4.Text = (db_informatique4.rdr(3).ToString)
            t5.Text = (db_informatique4.rdr(4).ToString)

        Loop
        db_informatique4.Disconnecting_in_informatique()
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If t1.Text = "" Or t2.Text = "" Or t4.Text = "" Or t5.Text = "" Then

            MsgBox("لا يمكن التعديل ", MsgBoxStyle.Information, "تعديل")
        Else

            db_informatique4.Myreq = " update entrer set pass='" & Me.t2.Text & "', datebegin='" & Me.t3.Text & "',salaire='" & Me.t4.Text & "',type='" & Me.t5.Text & "' where username='" & t1.Text & "'"
            db_informatique4.Connecting_in_informatique()
            db_informatique4.Disconnecting_in_informatique()
            MsgBox("تم التعديل", MsgBoxStyle.Information, "تعديل")


        End If



    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

        db_informatique4.Myreq = "select*from temp where username='" & t1.Text & "' and datee >='" & DateTimePicker1.Text & "' and datee<='" & DateTimePicker2.Text & "'"
        db_informatique4.Connecting_in_informatique()
        ListView1.Items.Clear()
        Do While db_informatique4.rdr.Read
            ListView1.Items.Add(New ListViewItem({(db_informatique4.rdr(1).ToString), (db_informatique4.rdr(2).ToString)}))

        Loop
        db_informatique4.Disconnecting_in_informatique()
        db_informatique4.Myreq = "select*from masrouf where username='" & t1.Text & "' and dated >='" & DateTimePicker1.Text & "' and dated<='" & DateTimePicker2.Text & "'"
        db_informatique4.Connecting_in_informatique()
        ListView2.Items.Clear()
        masroufi = 0
        Do While db_informatique4.rdr.Read
            ListView2.Items.Add(New ListViewItem({(db_informatique4.rdr(2).ToString), (db_informatique4.rdr(3).ToString)}))
            masroufi = masroufi + (db_informatique4.rdr(2).ToString)
        Loop
        db_informatique4.Disconnecting_in_informatique()
        TextBox2.Text = masroufi
        thf = 0
        tmf = 0
        tsf = 0
        For i = 0 To ListView1.Items.Count - 1 Step 1
            Dim diff = ListView1.Items(i).SubItems(1).Text
            diff = diff.Remove(diff.Length - 1)
            diff = diff.Replace(":", "")
            Dim diffh = diff(0) & diff(1)
            Dim diffm = diff(2) & diff(3)
            Dim diffs = diff(4) & diff(5)


            Dim diff1 = ListView1.Items(i).Text
            diff1 = diff1.Remove(diff1.Length - 1)
            diff1 = diff1.Replace(":", "")
            Dim diffh1 = diff1(0) & diff1(1)
            Dim diffm1 = diff1(2) & diff1(3)
            Dim diffs1 = diff1(4) & diff1(5)
            

            If diffs < diffs1 Then
                diffs = diffs + 60
                diffm = diffm - 1
                If diffm < diffm1 Then
                    diffm = diffm + 60
                    diffh = diffh - 1
                End If
            Else
                If diffm < diffm1 Then
                    diffm = diffm + 60
                    diffh = diffh - 1
                End If

            End If
            Dim dh = diffh - diffh1
            Dim dm = diffm - diffm1
            Dim ds = diffs - diffs1

            Do While ds >= 60 Or dm >= 60
                If ds >= 60 Then
                    ds = ds - 60
                    dm = dm + 1
                End If

                If dm >= 60 Then
                    dm = dm - 60
                    dh = dh + 1
                End If
            Loop

            thf = thf + dh
            tmf = tmf + dm
            tsf = tsf + ds

        Next
        Do While tsf >= 60 Or tmf >= 60
            If tsf >= 60 Then
                tsf = tsf - 60
                tmf = tmf + 1
            End If

            If tmf >= 60 Then
                tmf = tmf - 60
                thf = thf + 1
            End If
        Loop
        TextBox1.Text = thf & ":" & tmf & ":" & tsf
    End Sub

    Private Sub Label11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label11.Click
   

    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        If t1.Text = "" Then

            MsgBox("لا يمكن الحذف ", MsgBoxStyle.Information, "تنبيه")
        Else

            db_informatique4.Myreq = " delete from entrer where username ='" & Me.t1.Text & "'"
            db_informatique4.Connecting_in_informatique()
            db_informatique4.Disconnecting_in_informatique()
            db_informatique4.Myreq = " delete from temp where username ='" & Me.t1.Text & "'"
            db_informatique4.Connecting_in_informatique()
            db_informatique4.Disconnecting_in_informatique()
            db_informatique4.Myreq = " delete from masrouf where username ='" & Me.t1.Text & "'"
            db_informatique4.Connecting_in_informatique()
            db_informatique4.Disconnecting_in_informatique()
            ListView1.Items.Clear()
            ListView2.Items.Clear()
            TextBox1.Text = "00:00:00"
            TextBox2.Text = 0


            MsgBox("تم الحذف", MsgBoxStyle.Information, "حذف")
            t1.Items.Remove(t1.Text)
            t1.Text = ""
            t2.Text = ""
            t3.Text = t3.Value
            t4.Text = ""
            t5.Text = ""
          
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.Hide()
        Form8.Show()

    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Me.Hide()
        Form9.Show()

    End Sub
End Class
