Public Class Form6
    Dim db_informatique As New class1
    Dim db_informatique2 As New class2
    Dim db_informatique3 As New class3
    Dim db_informatique4 As New class4
    Dim nbre, sdf, cdc As Integer
    Dim somme As Double = 0
    Dim sdf1 As Double
    Dim x As String
    Dim test2 As Integer
    Dim ik, sadf As Integer


    Dim nbrep, priachat, privente, makseb, prixvg, nbreg As Double
    
    Dim test As Integer
    Dim scrolledString As String = "مرحبا بكم في عطرية أبناء حسين               الهاتف: 0911100744 "
    Dim modifiedstring As String

    Dim position As Integer = -1
    Dim stringlengthcalculater As Integer = (540 / 5.2) - 13
    Dim myStrings(stringlengthcalculater - 1) As String
    Private Sub ScrollType(ByVal someString As String)
        For index As Integer = 0 To UBound(myStrings)
            Dim workedString As String = ""
            workedString = someString.Substring(index) & someString.Substring(0, index)
            myStrings(index) = workedString
        Next
    End Sub


   
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TableLayoutPanel3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        t1.Focus()

        t1.Text = t1.Text & "1"
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        t1.Focus()
        t1.Text = t1.Text & "2"
    End Sub

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

        t1.Focus()
        t1.Text = t1.Text & "3"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        t1.Focus()
        t1.Text = t1.Text & "4"
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        t1.Focus()
        t1.Text = t1.Text & "5"
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        t1.Focus()
        t1.Text = t1.Text & "6"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        t1.Focus()
        t1.Text = t1.Text & "7"
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        t1.Focus()
        t1.Text = t1.Text & "8"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        t1.Focus()
        t1.Text = t1.Text & "9"

    End Sub

    

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If t1.Text <> "0" Then
            Try
                If ListView2.SelectedItems.Count > 0 Then
                    Dim element As New ListViewItem
                    element = ListView2.SelectedItems(0)
                    Dim x As Double = t1.Text

                    element.SubItems(2).Text = x
                    element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text

                    t1.Text = ""
                ElseIf ListView2.Items.Count > 0 Then
                    Dim element As New ListViewItem
                    element = ListView2.Items(ListView2.Items.Count - 1)
                    Dim x As Double = t1.Text
                    element.SubItems(2).Text = x
                    element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text

                    t1.Text = ""

                End If
            Catch ex As Exception
                t1.Text = ""
            End Try

            calculesomme()

            t1.Focus()

        End If


    End Sub


   
    Private Sub t1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles t1.DragEnter
      
    End Sub

    Private Sub t1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.Validated
       
    End Sub

    Private Sub Form6_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles MyBase.PreviewKeyDown
       
    End Sub
    Private Sub calculesomme()
        somme = 0
        nbrep = 0
        For Me.sadf = 0 To ListView2.Items.Count - 1 Step 1

            Dim element2 As New ListViewItem
            element2 = ListView2.Items(Me.sadf)
            somme = element2.SubItems(4).Text + somme
            nbrep = nbrep + element2.SubItems(2).Text
        Next
        TextBox6.Text = somme
        TextBox5.Text = nbrep
    End Sub

    Private Sub t1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles t1.PreviewKeyDown
       

    End Sub

    Private Sub t1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.TextChanged

    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        t1.Focus()
        t1.Text = t1.Text & "0"
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        t1.Focus()
        t1.Text = t1.Text & "."
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        t1.Focus()
        t1.Text = ""
    End Sub

    Private Sub t1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t1.KeyPress
        If ((e.KeyChar = ".") And ((sender).Text.IndexOf(".") > -1)) Then

            e.Handled = True
        End If
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click


    End Sub

    Private Sub Form6_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

    End Sub

    Private Sub Form6_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Select Case e.KeyCode
            Case Keys.F10 And ListView2.Items.Count > 0
                If MessageBox.Show("سيتم الغاء الفاتورة هل تريد المواصلة؟  ", "الغاء الفاتورة", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
                    ListView2.Items.Clear()
                    TextBox6.Text = 0
                    TextBox5.Text = 0
                End If
            Case Keys.F3
                Form13.ShowDialog()
            Case Keys.F12 And ListView2.Items.Count > 0
                Form7.ShowDialog()
                Do While ListView2.Items.Count > 0
                    Dim i = 0
                    db_informatique2.Myreq = "select*from factureachat where codep ='" & ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    Do While db_informatique2.rdr.Read
                        priachat = db_informatique2.rdr(6).ToString
                        privente = db_informatique2.rdr(7).ToString
                        makseb = db_informatique2.rdr(7).ToString - db_informatique2.rdr(6).ToString
                        nbreg = db_informatique2.rdr(4).ToString
                        prixvg = db_informatique2.rdr(12).ToString
                    Loop
                    db_informatique2.Disconnecting_in_informatique()
                    db_informatique3.Myreq = "Insert Into factureachat (codep,nomp,nbrep,prixap,prixgp,prixvp,prixvgp,maksebp,maksebg,numf,datf,ismi,timev) values('" & Me.ListView2.Items(i).Text & "','" & Me.ListView2.Items(i).SubItems(1).Text & "','" & Me.ListView2.Items(i).SubItems(2).Text & "','" & priachat & "','" & (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "','" & privente & "','" & (privente * Me.ListView2.Items(i).SubItems(2).Text) & "','" & makseb & "','" & (makseb * Me.ListView2.Items(i).SubItems(2).Text) & "','" & TextBox3.Text & "','" & Me.d2.Text & "','" & Me.Label11.Text & "','" & Me.Label12.Text & "')"
                    db_informatique3.Connecting_in_informatique()
                    db_informatique3.Disconnecting_in_informatique()
                    db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbreg - Me.ListView2.Items(i).SubItems(2).Text & "', prixg='" & prixvg - (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "'   where codep='" & Me.ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()
                    ListView2.Items.Remove(ListView2.Items(0))
                Loop
                MsgBox("تم حفظ الفاتورة بنجاح", MsgBoxStyle.Information, "حفظ الفاتورة")
                db_informatique3.Myreq = "Insert Into listefacture (numf,datf,somm,ismi) values('" & TextBox3.Text & "','" & Me.d2.Text & "','" & TextBox6.Text & "','" & Label11.Text & "')"
                db_informatique3.Connecting_in_informatique()
                db_informatique3.Disconnecting_in_informatique()
                TextBox3.Text = TextBox3.Text + 1
                TextBox5.Text = 0
                TextBox6.Text = 0
        End Select
    End Sub

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        db_informatique2.Myreq = "select*from factureachat"
        db_informatique2.Connecting_in_informatique()
        ComboBox2.Items.Clear()

        Do While db_informatique2.rdr.Read
            ComboBox2.Items.Add(db_informatique2.rdr(1).ToString)

        Loop
        db_informatique2.Disconnecting_in_informatique()


        Label11.Text = LoginForm1.t1.Text

        Label12.Text = Now.ToLongTimeString
        x = Label12.Text


        db_informatique3.Myreq = "select*from listefacture"
        db_informatique3.Connecting_in_informatique()
        Do While db_informatique3.rdr.Read
            TextBox3.Text = db_informatique3.rdr(0).ToString + 1

        Loop
        db_informatique3.Disconnecting_in_informatique()

        ComboBox1.Text = ComboBox1.Items(0)
        If stringlengthcalculater > scrolledString.Length Then
            modifiedstring = scrolledString
            For index = scrolledString.Length To stringlengthcalculater
                modifiedstring = modifiedstring & " "
            Next
        End If
        Call ScrollType(modifiedstring)


        Timer1.Interval = 200
        Timer1.Start()
        t1.Focus()
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        If ListView2.Items.Count > 0 Then
            If MessageBox.Show("سيتم الغاء الفاتورة هل تريد المواصلة؟  ", "الغاء الفاتورة", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then

                ListView2.Items.Clear()
                TextBox5.Text = "0"
                TextBox6.Text = "0"
            End If


        End If
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label12.Text = Now.ToLongTimeString

        position += 1
        Dim testString As String
        testString = myStrings(position)
        Label13.Text = testString
        If position = UBound(myStrings) Then position = -1
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click

        If MessageBox.Show("سيتم تسجيل الخروج هل تريد المواصلة  ", "تسجيل خروج", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then



            db_informatique4.Myreq = "Insert Into temp (username,datd,dats,datee) values('" & Label11.Text & "','" & x & "','" & Label12.Text & "','" & d2.Text & "')"
            db_informatique4.Connecting_in_informatique()
            db_informatique4.Disconnecting_in_informatique()
            End

        End If

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If ListView2.SelectedItems.Count > 0 Then
            ListView2.Items.Remove(ListView2.SelectedItems(0))
        ElseIf ListView2.Items.Count > 0 Then
            ListView2.Items.Remove(ListView2.Items(ListView2.Items.Count - 1))
        End If
        calculesomme()
        t1.Focus()
    End Sub

 


    Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = ComboBox1.Items(0) Then
            ComboBox2.Visible = False
        Else
            ComboBox2.Visible = True

        End If
    End Sub

    Private Sub ComboBox2_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox2.KeyDown
        test = 1
        test2 = 1
        ik = 0
        Do While ListView2.Items.Count > ik And test = 1
            If ComboBox2.Text = ListView2.Items(ik).SubItems(1).Text Then
                test = 0
            End If
            ik = ik + 1
        Loop
        Select Case e.KeyCode
            Case Keys.Enter

                db_informatique2.Myreq = "select*from factureachat where nomp='" & Me.ComboBox2.Text & "'"
                db_informatique2.Connecting_in_informatique()
                Do While db_informatique2.rdr.Read
                    If ComboBox2.Text = db_informatique2.rdr(1).ToString Then
                        test2 = 0
                    End If
                Loop
                db_informatique2.Disconnecting_in_informatique()
                If test2 = 0 Then
                    If test = 0 Then
                        Dim element As New ListViewItem
                        element = ListView2.Items(ik - 1)
                        element.SubItems(2).Text = element.SubItems(2).Text + 1
                        element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                    Else

                        nbre = 1
                        db_informatique2.Myreq = "select*from factureachat where nomp = '" & Me.ComboBox2.Text & "'"
                        db_informatique2.Connecting_in_informatique()
                        Do While db_informatique2.rdr.Read
                            ListView2.Items.Add(New ListViewItem({db_informatique2.rdr(0).ToString, (db_informatique2.rdr(1).ToString), nbre, (db_informatique2.rdr(7).ToString), nbre * (db_informatique2.rdr(7).ToString)}))
                        Loop
                        db_informatique2.Disconnecting_in_informatique()
                    End If
                Else
                    MsgBox("هذا الصنف غير موجود", MsgBoxStyle.Information, "تنبيه")
                End If
                ComboBox2.Text = Nothing
                calculesomme()
                ComboBox2.Focus()
            Case Keys.F2 And ComboBox2.Text <> "0"
                Try
                    If ListView2.SelectedItems.Count > 0 Then
                        Dim element As New ListViewItem
                        element = ListView2.SelectedItems(0)
                        Dim x As Double = ComboBox2.Text
                        element.SubItems(2).Text = x
                        element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                    ElseIf ListView2.Items.Count > 0 Then
                        Dim element As New ListViewItem
                        element = ListView2.Items(ListView2.Items.Count - 1)
                        Dim x As Double = ComboBox2.Text
                        element.SubItems(2).Text = x
                        element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                    End If
                Catch ex As Exception
                End Try
                ComboBox2.Text = ""
                calculesomme()
            Case Keys.F10 And ListView2.Items.Count > 0
                If MessageBox.Show("سيتم الغاء الفاتورة هل تريد المواصلة؟  ", "الغاء الفاتورة", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
                    ListView2.Items.Clear()
                    TextBox5.Text = 0
                    TextBox6.Text = 0
                End If
            Case Keys.F12
                If ListView2.Items.Count > 0 Then
                    Form7.ShowDialog()
                    If Form7.tam = 0 Then
                        For i = 0 To ListView2.Items.Count - 1 Step 1
                            db_informatique2.Myreq = "select*from factureachat where codep ='" & ListView2.Items(i).Text & "'"
                            db_informatique2.Connecting_in_informatique()
                            Do While db_informatique2.rdr.Read
                                priachat = db_informatique2.rdr(6).ToString
                                privente = db_informatique2.rdr(7).ToString
                                makseb = db_informatique2.rdr(7).ToString - db_informatique2.rdr(6).ToString
                                nbreg = db_informatique2.rdr(4).ToString
                                prixvg = db_informatique2.rdr(12).ToString
                            Loop
                            db_informatique2.Disconnecting_in_informatique()
                            db_informatique3.Myreq = "Insert Into factureachat (codep,nomp,nbrep,prixap,prixgp,prixvp,prixvgp,maksebp,maksebg,numf,datf,ismi,timev) values('" & Me.ListView2.Items(i).Text & "','" & Me.ListView2.Items(i).SubItems(1).Text & "','" & Me.ListView2.Items(i).SubItems(2).Text & "','" & priachat & "','" & (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "','" & privente & "','" & (privente * Me.ListView2.Items(i).SubItems(2).Text) & "','" & makseb & "','" & (makseb * Me.ListView2.Items(i).SubItems(2).Text) & "','" & TextBox3.Text & "','" & Me.d2.Text & "','" & Me.Label11.Text & "','" & Me.Label12.Text & "')"
                            db_informatique3.Connecting_in_informatique()
                            db_informatique3.Disconnecting_in_informatique()
                            db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbreg - Me.ListView2.Items(i).SubItems(2).Text & "', prixg='" & prixvg - (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "'   where codep='" & Me.ListView2.Items(i).Text & "'"
                            db_informatique2.Connecting_in_informatique()
                            db_informatique2.Disconnecting_in_informatique()
                        Next
                        MsgBox("تم حفظ الفاتورة بنجاح", MsgBoxStyle.Information, "حفظ الفاتورة")
                        ListView2.Items.Clear()


                        db_informatique3.Myreq = "Insert Into listefacture (numf,datf,somm,ismi) values('" & TextBox3.Text & "','" & Me.d2.Text & "','" & TextBox6.Text & "','" & Label11.Text & "')"
                        db_informatique3.Connecting_in_informatique()
                        db_informatique3.Disconnecting_in_informatique()
                        TextBox3.Text = TextBox3.Text + 1
                        TextBox5.Text = 0
                        TextBox6.Text = 0
                    End If
                End If
            Case Keys.Delete
                If ListView2.SelectedItems.Count > 0 Then
                    ListView2.Items.Remove(ListView2.SelectedItems(0))
                ElseIf ListView2.Items.Count > 0 Then
                    ListView2.Items.Remove(ListView2.Items(ListView2.Items.Count - 1))
                End If
                calculesomme()
                t1.Focus()
        End Select




    End Sub

    Private Sub t1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t1.KeyDown
        test = 1
        test2 = 1
        ik = 0
        Do While ListView2.Items.Count > ik And test = 1
            If t1.Text = ListView2.Items(ik).Text Then
                test = 0
            End If
            ik = ik + 1
        Loop
        Select Case e.KeyCode
            Case Keys.Enter
                db_informatique2.Myreq = "select*from factureachat where codep='" & Me.t1.Text & "'"
                db_informatique2.Connecting_in_informatique()
                Do While db_informatique2.rdr.Read
                    If t1.Text = db_informatique2.rdr(0).ToString Then
                        test2 = 0
                    End If
                Loop
                db_informatique2.Disconnecting_in_informatique()
                If test2 = 0 Then
                    If test = 0 Then
                        Dim element As New ListViewItem
                        element = ListView2.Items(ik - 1)
                        element.SubItems(2).Text = element.SubItems(2).Text + 1
                        element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                    Else
                        nbre = 1
                        db_informatique2.Myreq = "select*from factureachat where codep = '" & Me.t1.Text & "'"
                        db_informatique2.Connecting_in_informatique()
                        Do While db_informatique2.rdr.Read
                            ListView2.Items.Add(New ListViewItem({db_informatique2.rdr(0).ToString, (db_informatique2.rdr(1).ToString), nbre, (db_informatique2.rdr(7).ToString), nbre * (db_informatique2.rdr(7).ToString)}))
                        Loop
                        db_informatique2.Disconnecting_in_informatique()
                    End If
                Else
                    MsgBox("هذا الصنف غير موجود", MsgBoxStyle.Information, "تنبيه")
                End If
                t1.Text = Nothing
                calculesomme()
                t1.Focus()
            Case Keys.F2
                If t1.Text <> "0" Then
                    Try
                        If ListView2.SelectedItems.Count > 0 Then
                            Dim element As New ListViewItem
                            element = ListView2.SelectedItems(0)
                            Dim x As Double = t1.Text
                            element.SubItems(2).Text = x
                            element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                        ElseIf ListView2.Items.Count > 0 Then
                            Dim element As New ListViewItem
                            element = ListView2.Items(ListView2.Items.Count - 1)
                            Dim x As Double = t1.Text
                            element.SubItems(2).Text = x
                            element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                        End If
                    Catch ex As Exception
                    End Try
                End If
                t1.Text = ""
                calculesomme()
                t1.Focus()
            Case Keys.F10 And ListView2.Items.Count > 0
                If MessageBox.Show("سيتم الغاء الفاتورة هل تريد المواصلة؟  ", "الغاء الفاتورة", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
                    ListView2.Items.Clear()
                    TextBox6.Text = 0
                    TextBox5.Text = 0
                End If
            Case Keys.F3
                Form13.ShowDialog()
            Case Keys.F12 And ListView2.Items.Count > 0
                Form7.ShowDialog()
                Do While ListView2.Items.Count > 0
                    Dim i = 0
                    db_informatique2.Myreq = "select*from factureachat where codep ='" & ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    Do While db_informatique2.rdr.Read
                        priachat = db_informatique2.rdr(6).ToString
                        privente = db_informatique2.rdr(7).ToString
                        makseb = db_informatique2.rdr(7).ToString - db_informatique2.rdr(6).ToString
                        nbreg = db_informatique2.rdr(4).ToString
                        prixvg = db_informatique2.rdr(12).ToString
                    Loop
                    db_informatique2.Disconnecting_in_informatique()
                    db_informatique3.Myreq = "Insert Into factureachat (codep,nomp,nbrep,prixap,prixgp,prixvp,prixvgp,maksebp,maksebg,numf,datf,ismi,timev) values('" & Me.ListView2.Items(i).Text & "','" & Me.ListView2.Items(i).SubItems(1).Text & "','" & Me.ListView2.Items(i).SubItems(2).Text & "','" & priachat & "','" & (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "','" & privente & "','" & (privente * Me.ListView2.Items(i).SubItems(2).Text) & "','" & makseb & "','" & (makseb * Me.ListView2.Items(i).SubItems(2).Text) & "','" & TextBox3.Text & "','" & Me.d2.Text & "','" & Me.Label11.Text & "','" & Me.Label12.Text & "')"
                    db_informatique3.Connecting_in_informatique()
                    db_informatique3.Disconnecting_in_informatique()
                    db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbreg - Me.ListView2.Items(i).SubItems(2).Text & "', prixg='" & prixvg - (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "'   where codep='" & Me.ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()
                    ListView2.Items.Remove(ListView2.Items(0))
                Loop
                MsgBox("تم حفظ الفاتورة بنجاح", MsgBoxStyle.Information, "حفظ الفاتورة")
                db_informatique3.Myreq = "Insert Into listefacture (numf,datf,somm,ismi) values('" & TextBox3.Text & "','" & Me.d2.Text & "','" & TextBox6.Text & "','" & Label11.Text & "')"
                db_informatique3.Connecting_in_informatique()
                db_informatique3.Disconnecting_in_informatique()
                TextBox3.Text = TextBox3.Text + 1
                TextBox5.Text = 0
                TextBox6.Text = 0
            Case Keys.Delete
                If ListView2.SelectedItems.Count > 0 Then
                    ListView2.Items.Remove(ListView2.SelectedItems(0))
                ElseIf ListView2.Items.Count > 0 Then
                    ListView2.Items.Remove(ListView2.Items(ListView2.Items.Count - 1))
                Else

                End If
                calculesomme()
        End Select

    End Sub

    Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If ListView2.Items.Count > 0 Then
            Form7.ShowDialog()
            If Form7.tam = 0 Then
                Do While ListView2.Items.Count > 0
                    Dim i = 0
                    db_informatique2.Myreq = "select*from factureachat where codep ='" & ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    Do While db_informatique2.rdr.Read
                        priachat = db_informatique2.rdr(6).ToString
                        privente = db_informatique2.rdr(7).ToString
                        makseb = db_informatique2.rdr(7).ToString - db_informatique2.rdr(6).ToString
                        nbreg = db_informatique2.rdr(4).ToString
                        prixvg = db_informatique2.rdr(12).ToString
                    Loop
                    db_informatique2.Disconnecting_in_informatique()
                    db_informatique3.Myreq = "Insert Into factureachat (codep,nomp,nbrep,prixap,prixgp,prixvp,prixvgp,maksebp,maksebg,numf,datf,ismi,timev) values('" & Me.ListView2.Items(i).Text & "','" & Me.ListView2.Items(i).SubItems(1).Text & "','" & Me.ListView2.Items(i).SubItems(2).Text & "','" & priachat & "','" & (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "','" & privente & "','" & (privente * Me.ListView2.Items(i).SubItems(2).Text) & "','" & makseb & "','" & (makseb * Me.ListView2.Items(i).SubItems(2).Text) & "','" & TextBox3.Text & "','" & Me.d2.Text & "','" & Me.Label11.Text & "','" & Me.Label12.Text & "')"
                    db_informatique3.Connecting_in_informatique()
                    db_informatique3.Disconnecting_in_informatique()
                    db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbreg - Me.ListView2.Items(i).SubItems(2).Text & "', prixg='" & prixvg - (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "'   where codep='" & Me.ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()
                    ListView2.Items.Remove(ListView2.Items(0))
                Loop
                MsgBox("تم حفظ الفاتورة بنجاح", MsgBoxStyle.Information, "حفظ الفاتورة")
                db_informatique3.Myreq = "Insert Into listefacture (numf,datf,somm,ismi) values('" & TextBox3.Text & "','" & Me.d2.Text & "','" & TextBox6.Text & "','" & Label11.Text & "')"
                db_informatique3.Connecting_in_informatique()
                db_informatique3.Disconnecting_in_informatique()
                TextBox3.Text = TextBox3.Text + 1
                TextBox5.Text = 0
                TextBox6.Text = 0
            End If
        End If

    End Sub

    Private Sub Form6_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

        db_informatique4.Myreq = "Insert Into temp (username,datd,dats,datee) values('" & Label11.Text & "','" & x & "','" & Label12.Text & "','" & d2.Text & "')"
        db_informatique4.Connecting_in_informatique()
        db_informatique4.Disconnecting_in_informatique()
        End


    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 TextBox4_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown
        If e.KeyCode = Keys.Enter Then
            If TextBox4.Text = "" Or t4.Text = "" Then
                MsgBox("خانة المبلغ أو السبب فارغة", MsgBoxStyle.Exclamation, "تنبيه")
            Else
                db_informatique4.Myreq = "Insert Into masrouf (username,dated,argents,sabab,timem) values('" & Label11.Text & "','" & d2.Text & "','" & t4.Text & "','" & TextBox4.Text & "','" & Label12.Text & "')"
                db_informatique4.Connecting_in_informatique()
                db_informatique4.Disconnecting_in_informatique()
                t4.Text = ""
                TextBox4.Text = ""
                t4.Focus()
            End If


        End If
    End Sub

    Private Sub Form6_ControlRemoved(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles MyBase.ControlRemoved

    End Sub

    Private Sub t4_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t4.KeyDown
        If e.KeyCode = Keys.Enter Then
            TextBox4.Focus()

        End If
    End Sub

    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        Form13.ShowDialog()

    End Sub

    Private Sub Label12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label12.Click
        Form12.Show()

    End Sub

    Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged

    End Sub

    Private Sub StatusStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs)

    End Sub

    Private Sub TableLayoutPanel7_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles TableLayoutPanel7.Paint

    End Sub

    Private Sub ListView2_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListView2.KeyDown
        Select Case e.KeyCode
            Case Keys.Delete
                If ListView2.SelectedItems.Count > 0 Then
                    ListView2.Items.Remove(ListView2.SelectedItems(0))
                ElseIf ListView2.Items.Count > 0 Then
                    ListView2.Items.Remove(ListView2.Items(ListView2.Items.Count - 1))
                End If
                calculesomme()
                t1.Focus()
            Case Keys.F10 And ListView2.Items.Count > 0
                If MessageBox.Show("سيتم الغاء الفاتورة هل تريد المواصلة؟  ", "الغاء الفاتورة", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
                    ListView2.Items.Clear()
                    TextBox6.Text = 0
                    TextBox5.Text = 0
                End If
            Case Keys.F3
                Form13.ShowDialog()
            Case Keys.F12 And ListView2.Items.Count > 0
                Form7.ShowDialog()
                Do While ListView2.Items.Count > 0
                    Dim i = 0
                    db_informatique2.Myreq = "select*from factureachat where codep ='" & ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    Do While db_informatique2.rdr.Read
                        priachat = db_informatique2.rdr(6).ToString
                        privente = db_informatique2.rdr(7).ToString
                        makseb = db_informatique2.rdr(7).ToString - db_informatique2.rdr(6).ToString
                        nbreg = db_informatique2.rdr(4).ToString
                        prixvg = db_informatique2.rdr(12).ToString
                    Loop
                    db_informatique2.Disconnecting_in_informatique()
                    db_informatique3.Myreq = "Insert Into factureachat (codep,nomp,nbrep,prixap,prixgp,prixvp,prixvgp,maksebp,maksebg,numf,datf,ismi,timev) values('" & Me.ListView2.Items(i).Text & "','" & Me.ListView2.Items(i).SubItems(1).Text & "','" & Me.ListView2.Items(i).SubItems(2).Text & "','" & priachat & "','" & (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "','" & privente & "','" & (privente * Me.ListView2.Items(i).SubItems(2).Text) & "','" & makseb & "','" & (makseb * Me.ListView2.Items(i).SubItems(2).Text) & "','" & TextBox3.Text & "','" & Me.d2.Text & "','" & Me.Label11.Text & "','" & Me.Label12.Text & "')"
                    db_informatique3.Connecting_in_informatique()
                    db_informatique3.Disconnecting_in_informatique()
                    db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbreg - Me.ListView2.Items(i).SubItems(2).Text & "', prixg='" & prixvg - (priachat * Me.ListView2.Items(i).SubItems(2).Text) & "'   where codep='" & Me.ListView2.Items(i).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()
                    ListView2.Items.Remove(ListView2.Items(0))
                Loop
                MsgBox("تم حفظ الفاتورة بنجاح", MsgBoxStyle.Information, "حفظ الفاتورة")
                db_informatique3.Myreq = "Insert Into listefacture (numf,datf,somm,ismi) values('" & TextBox3.Text & "','" & Me.d2.Text & "','" & TextBox6.Text & "','" & Label11.Text & "')"
                db_informatique3.Connecting_in_informatique()
                db_informatique3.Disconnecting_in_informatique()
                TextBox3.Text = TextBox3.Text + 1
                TextBox5.Text = 0
                TextBox6.Text = 0
            Case Keys.F2
                If ComboBox2.Visible = True Then

                    If ComboBox2.Text <> "0" Then
                        Try
                            If ListView2.SelectedItems.Count > 0 Then
                                Dim element As New ListViewItem
                                element = ListView2.SelectedItems(0)
                                Dim x As Double = ComboBox2.Text
                                element.SubItems(2).Text = x
                                element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                            ElseIf ListView2.Items.Count > 0 Then
                                Dim element As New ListViewItem
                                element = ListView2.Items(ListView2.Items.Count - 1)
                                Dim x As Double = ComboBox2.Text
                                element.SubItems(2).Text = x
                                element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                            End If
                        Catch ex As Exception
                        End Try

                    End If
                    ComboBox2.Focus()

                Else
                    If t1.Text <> "0" Then
                        Try
                            If ListView2.SelectedItems.Count > 0 Then
                                Dim element As New ListViewItem
                                element = ListView2.SelectedItems(0)
                                Dim x As Double = t1.Text
                                element.SubItems(2).Text = x
                                element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                            ElseIf ListView2.Items.Count > 0 Then
                                Dim element As New ListViewItem
                                element = ListView2.Items(ListView2.Items.Count - 1)
                                Dim x As Double = t1.Text
                                element.SubItems(2).Text = x
                                element.SubItems(4).Text = element.SubItems(3).Text * element.SubItems(2).Text
                            End If
                        Catch ex As Exception
                        End Try
                        t1.Focus()
                    End If
                End If
                calculesomme()
                t1.Text = ""
                ComboBox2.Text = ""

        End Select

    End Sub

    Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click


    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        Process.Start("C:\Windows\system32\calc.exe")
    End Sub

    Private Sub t1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles t1.GotFocus

        InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("en-us"))
    End Sub

End Class
