Public Class Form4
    Dim db_informatique3 As New class3
    Dim db_informatique4 As New class4
    Dim db_informatique2 As New class2
    Dim nbr As Integer
    Dim prg As Double
    Dim nmbr As Double

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

    End Sub

    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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form5.Show()
        Me.Hide()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        ListView2.Items.Clear()

        db_informatique3.Myreq = "select*from listefacture where datf >='" & Me.d1.Text & "' and datf<='" & Me.d2.Text & "'"
        db_informatique3.Connecting_in_informatique()
        ListView1.Items.Clear()
        Dim sommlist As Double = 0
        Do While db_informatique3.rdr.Read
            ListView1.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString)}))
            sommlist = sommlist + db_informatique3.rdr(2).ToString
        Loop
        db_informatique3.Disconnecting_in_informatique()
        TextBox8.Text = sommlist

            db_informatique3.Myreq = "select*from factureachat  where datf >='" & Me.d1.Text & "' and datf<='" & Me.d2.Text & "'"
            db_informatique3.Connecting_in_informatique()
            ListView2.Items.Clear()

            Do While db_informatique3.rdr.Read
                ListView2.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString), (db_informatique3.rdr(3).ToString), (db_informatique3.rdr(5).ToString), (db_informatique3.rdr(6).ToString), (db_informatique3.rdr(8).ToString), (db_informatique3.rdr(9).ToString)}))

            Loop
        db_informatique3.Disconnecting_in_informatique()
        maksbi()


    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        ListView2.Items.Clear()

        db_informatique3.Myreq = "select*from listefacture where datf >='" & Me.d1.Text & "' and datf<='" & Me.d2.Text & "' and numf='" & Me.t9.Text & "'"
        db_informatique3.Connecting_in_informatique()
        ListView1.Items.Clear()
        Dim sommlist As Double = 0
        Do While db_informatique3.rdr.Read
            ListView1.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString)}))
            sommlist = sommlist + db_informatique3.rdr(2).ToString

        Loop
        db_informatique3.Disconnecting_in_informatique()
        db_informatique3.Myreq = "select*from factureachat where datf >='" & Me.d1.Text & "' and datf<='" & Me.d2.Text & "' and numf='" & Me.t9.Text & "'"

        db_informatique3.Connecting_in_informatique()
        ListView2.Items.Clear()

        Do While db_informatique3.rdr.Read
            ListView2.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString), (db_informatique3.rdr(3).ToString), (db_informatique3.rdr(5).ToString), (db_informatique3.rdr(6).ToString), (db_informatique3.rdr(8).ToString), (db_informatique3.rdr(9).ToString)}))

        Loop
        db_informatique3.Disconnecting_in_informatique()


        TextBox8.Text = sommlist
        maksbi()

    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedItems.Count > 0 Then
            db_informatique3.Myreq = "select*from factureachat where numf ='" & ListView1.SelectedItems(0).Text & "' and datf<='" & ListView1.SelectedItems(0).SubItems(1).Text & "'"
            db_informatique3.Connecting_in_informatique()
            ListView2.Items.Clear()

            Do While db_informatique3.rdr.Read
                ListView2.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString), (db_informatique3.rdr(3).ToString), (db_informatique3.rdr(5).ToString), (db_informatique3.rdr(6).ToString), (db_informatique3.rdr(8).ToString), (db_informatique3.rdr(9).ToString)}))

            Loop
            db_informatique3.Disconnecting_in_informatique()
            maksbi()

        End If
    End Sub

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

    End Sub

    Private Sub Form4_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()
        ComboBox2.Items.Clear()
        Do While db_informatique4.rdr.Read
            ComboBox2.Items.Add(db_informatique4.rdr(0).ToString)

        Loop
        db_informatique4.Disconnecting_in_informatique()
    End Sub
    Private Sub maksbi()
        Dim i As Integer
        Dim maksebi As Double = 0
        For i = 0 To ListView2.Items.Count - 1 Step 1
            maksebi = maksebi + ListView2.Items(i).SubItems(6).Text
        Next
        TextBox6.Text = maksebi

    End Sub

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

    End Sub

    Private Sub t9_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t9.KeyPress
        If (Not Char.IsControl(e.KeyChar) And Not Char.IsDigit(e.KeyChar)) Then
            t9.BackColor = Color.Red
            e.Handled = True
        Else
            t9.BackColor = Color.White
        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 Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        ListView2.Items.Clear()

        db_informatique3.Myreq = "select*from listefacture where ismi ='" & Me.ComboBox2.Text & "' and datf >='" & Me.d1.Text & "' and datf<='" & Me.d2.Text & "'"
        db_informatique3.Connecting_in_informatique()
        ListView1.Items.Clear()
        Dim sommlist As Double = 0
        Do While db_informatique3.rdr.Read
            ListView1.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString)}))
            sommlist = sommlist + db_informatique3.rdr(2).ToString
        Loop
        db_informatique3.Disconnecting_in_informatique()
        TextBox8.Text = sommlist

        db_informatique3.Myreq = "select*from factureachat where ismi ='" & Me.ComboBox2.Text & "' and datf >='" & Me.d1.Text & "' and datf<='" & Me.d2.Text & "'"
        db_informatique3.Connecting_in_informatique()
        ListView2.Items.Clear()

        Do While db_informatique3.rdr.Read
            ListView2.Items.Add(New ListViewItem({(db_informatique3.rdr(0).ToString), (db_informatique3.rdr(1).ToString), (db_informatique3.rdr(2).ToString), (db_informatique3.rdr(3).ToString), (db_informatique3.rdr(5).ToString), (db_informatique3.rdr(6).ToString), (db_informatique3.rdr(8).ToString), (db_informatique3.rdr(9).ToString)}))

        Loop
        db_informatique3.Disconnecting_in_informatique()
        maksbi()
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        db_informatique2.Myreq = "select*from factureachat where codep='" & ListView2.SelectedItems(0).Text & "'"
        db_informatique2.Connecting_in_informatique()


        Do While db_informatique2.rdr.Read
            nbr = db_informatique2.rdr(4).ToString
            prg = db_informatique2.rdr(12).ToString
        Loop
        db_informatique2.Disconnecting_in_informatique()

        db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbr + ListView2.SelectedItems(0).SubItems(2).Text & "',prixg='" & prg + (ListView2.SelectedItems(0).SubItems(2).Text * ListView2.SelectedItems(0).SubItems(3).Text) & "' where codep='" & ListView2.SelectedItems(0).Text & "'"
        db_informatique2.Connecting_in_informatique()
        db_informatique2.Disconnecting_in_informatique()



        db_informatique3.Myreq = "delete from factureachat  where codep='" & ListView2.SelectedItems(0).Text & "' and numf='" & ListView2.SelectedItems(0).SubItems(7).Text & "'"
        db_informatique3.Connecting_in_informatique()
        db_informatique3.Disconnecting_in_informatique()
        'db_informatique3.Myreq = "select*from factureachat where codep='" & ListView2.SelectedItems(0).Text & "' and numf='" & ListView2.SelectedItems(0).SubItems(7).Text & "'"
        'db_informatique3.Connecting_in_informatique()


        'Do While db_informatique3.rdr.Read
        '    nbr = db_informatique3.rdr(2).ToString
        'Loop
        'db_informatique3.Disconnecting_in_informatique()

        'db_informatique3.Myreq = "update factureachat set nbrep='" & nbr - ListView2.SelectedItems(0).SubItems(2).Text & "' where codep='" & ListView2.SelectedItems(0).Text & "' and numf='" & ListView2.SelectedItems(0).SubItems(7).Text & "'"
        'db_informatique3.Connecting_in_informatique()
        'db_informatique3.Disconnecting_in_informatique()

    End Sub

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

    End Sub

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

    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        If ListView2.SelectedItems.Count > 0 Then
            db_informatique2.Myreq = "select*from factureachat where codep='" & ListView2.SelectedItems(0).Text & "'"
            db_informatique2.Connecting_in_informatique()
            Do While db_informatique2.rdr.Read
                nbr = db_informatique2.rdr(4).ToString
                prg = db_informatique2.rdr(12).ToString
            Loop
            db_informatique2.Disconnecting_in_informatique()

            db_informatique2.Myreq = "update factureachat set nbregpiece='" & nbr + ListView2.SelectedItems(0).SubItems(2).Text & "',prixg='" & prg + (ListView2.SelectedItems(0).SubItems(2).Text * ListView2.SelectedItems(0).SubItems(3).Text) & "' where codep='" & ListView2.SelectedItems(0).Text & "'"
            db_informatique2.Connecting_in_informatique()
            db_informatique2.Disconnecting_in_informatique()



            db_informatique3.Myreq = "delete from factureachat  where codep='" & ListView2.SelectedItems(0).Text & "' and numf='" & ListView2.SelectedItems(0).SubItems(7).Text & "'"
            db_informatique3.Connecting_in_informatique()
            db_informatique3.Disconnecting_in_informatique()

            db_informatique3.Myreq = "select*from listefacture  where numf='" & ListView2.SelectedItems(0).SubItems(7).Text & "'"
            db_informatique3.Connecting_in_informatique()
            Do While db_informatique3.rdr.Read
                nmbr = db_informatique3.rdr(2).ToString
            Loop
            db_informatique3.Disconnecting_in_informatique()
            MsgBox(nmbr)
            MsgBox((ListView2.SelectedItems(0).SubItems(2).Text * ListView2.SelectedItems(0).SubItems(4).Text))
            db_informatique3.Myreq = "update listefacture set somm='" & nmbr - (ListView2.SelectedItems(0).SubItems(2).Text * ListView2.SelectedItems(0).SubItems(4).Text) & "' where numf='" & ListView2.SelectedItems(0).SubItems(7).Text & "'"
            db_informatique3.Connecting_in_informatique()
            db_informatique3.Disconnecting_in_informatique()

        End If

    End Sub
End Class
