Public Class Form1
    Dim sd, df, s, s2, s3, trouve, test5 As Integer
    Dim db_informatique As New class1
    Dim db_informatique2 As New class2
    Dim dh1, dh As Double
    Dim test4 As Integer = 1
    Dim deltp, deltc As Double
    Dim somme As Double = 0
    Dim nbreca, nbregp As Integer

    Dim prixca, priv, prig, prig1 As Double



 

    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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form5.Show()
        Me.Hide()
    End Sub
    Private Sub calculer()
        db_informatique.Myreq = "select*from factureachat where numfac = '" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
        db_informatique.Connecting_in_informatique()
        somme = Nothing
        Do While db_informatique.rdr.Read
            somme = somme + (db_informatique.rdr(5).ToString * db_informatique.rdr(2).ToString)
        Loop
        db_informatique.Disconnecting_in_informatique()
        TextBox1.Text = somme
    End Sub
    Private Sub inserer()
        db_informatique.Myreq = "Insert Into listefacture (numf,datf,somm) values('" & Me.t9.Text & "','" & Me.d2.Text & "','" & Me.TextBox1.Text & "')"
        db_informatique.Connecting_in_informatique()
        db_informatique.Disconnecting_in_informatique()

    End Sub
    Private Sub chercher()
        test4 = 1
        db_informatique.Myreq = "select*from listefacture"
        db_informatique.Connecting_in_informatique()
        Do While db_informatique.rdr.Read
            If db_informatique.rdr(0).ToString = Me.t9.Text And db_informatique.rdr(1).ToString = Me.d2.Text Then
                test4 = 0
            End If

        Loop
        db_informatique.Disconnecting_in_informatique()
    End Sub
    Private Sub updater()
        db_informatique.Myreq = "update listefacture set somm='" & Me.TextBox1.Text & "' where numf='" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
        db_informatique.Connecting_in_informatique()
        db_informatique.Disconnecting_in_informatique()
    End Sub
    Private Sub chercher2()
        test4 = 1
        db_informatique2.Myreq = "select*from factureachat  "
        db_informatique2.Connecting_in_informatique()
        Do While db_informatique.rdr.Read
            If db_informatique.rdr(0).ToString = Me.t1.Text And db_informatique.rdr(9).ToString = Me.d2.Text And db_informatique.rdr(10).ToString = Me.t9.Text Then
                test4 = 0
            End If
        Loop
        db_informatique.Disconnecting_in_informatique()
    End Sub
    Private Sub calculer2()
        nbreca = 0
        nbregp = 0
        prig = 0
        db_informatique2.Myreq = "select*from factureachat where codep='" & Me.t1.Text & "'"
        db_informatique2.Connecting_in_informatique()
        Do While db_informatique2.rdr.Read
            nbreca = nbreca + db_informatique2.rdr(2).ToString
            nbregp = nbregp + db_informatique2.rdr(4).ToString
            prig = prig + db_informatique2.rdr(12).ToString

        Loop
        db_informatique2.Disconnecting_in_informatique()
    End Sub
    Private Sub calculer3()
        nbreca = 0
        nbregp = 0
        prig = 0
        db_informatique.Myreq = "select*from factureachat where codep='" & Me.t1.Text & "' and numfac = '" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
        db_informatique.Connecting_in_informatique()
        Do While db_informatique.rdr.Read
            nbreca = nbreca + db_informatique.rdr(2).ToString
            nbregp = nbregp + db_informatique.rdr(4).ToString
            prig = prig + db_informatique.rdr(12).ToString
         
        Loop
        db_informatique.Disconnecting_in_informatique()
    End Sub

    Private Sub affichelistview()
        db_informatique.Myreq = "select*from factureachat where numfac = '" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
        db_informatique.Connecting_in_informatique()
        ListView1.Items.Clear()
        Do While db_informatique.rdr.Read

            ListView1.Items.Add(New ListViewItem({(db_informatique.rdr(0).ToString), (db_informatique.rdr(1).ToString), (db_informatique.rdr(2).ToString), (db_informatique.rdr(3).ToString), (db_informatique.rdr(4).ToString), (db_informatique.rdr(6).ToString), (db_informatique.rdr(7).ToString), (db_informatique.rdr(11).ToString), (db_informatique.rdr(8).ToString), (db_informatique.rdr(9).ToString), (db_informatique.rdr(10).ToString)}))

        Loop
        db_informatique.Disconnecting_in_informatique()
    End Sub




    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        s = d1.Text.Replace("/", "")
        s2 = d2.Text.Replace("/", "")
        s3 = s - s2
        If t1.Text = "" Or t2.Text = "" Or t3.Text = "" Or t4.Text = "" Or t5.Text = "" Or t6.Text = "" Or t7.Text = "" Or t8.Text = "" Or t9.Text = "" Then
            MsgBox("الرجاء عدم ترك الخانات فارغة", MsgBoxStyle.Information, "تنبيه المستخدم")
        ElseIf trouve = 0 Then
            If s3 < 15 Then
                If MessageBox.Show(" تاريخ الصلاحية اقل من 15 يوم هل تريد المواصلة؟ ", "صلاحية", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then

                    db_informatique.Myreq = "select*from factureachat"
                    db_informatique.Connecting_in_informatique()
                    test5 = 1
                    Do While db_informatique.rdr.Read
                        If (db_informatique.rdr(9).ToString) = d2.Text And (db_informatique.rdr(10).ToString) = t9.Text And (db_informatique.rdr(0).ToString) = t1.Text Then
                            test5 = 0
                        End If

                    Loop
                    db_informatique.Disconnecting_in_informatique()
                    calculer3()
                    If test5 = 0 Then
                        db_informatique.Myreq = "update factureachat set nomp='" & Me.t2.Text & "', nbrepiece='" & Me.t4.Text & "',prixc='" & Me.t6.Text & "',prixp='" & Me.t7.Text & "',prixvente='" & Me.t8.Text & "',nbregpiece='" & nbregp + t5.Text & "',nbrecarton='" & nbreca + t3.Text & "', val='" & d1.Text & "',prixg='" & prig + (t3.Text * t6.Text) & "'   where codep='" & Me.t1.Text & "' and numfac = '" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
                        db_informatique.Connecting_in_informatique()
                        db_informatique.Disconnecting_in_informatique()
                    Else
                        db_informatique.Myreq = "Insert Into factureachat (codep,nomp,nbrecarton,nbrepiece,nbregpiece,prixc,prixp,prixvente,val,datf,numfac,gangne,prixg) values('" & Me.t1.Text & "','" & Me.t2.Text & "','" & Me.t3.Text & "','" & Me.t4.Text & "','" & Me.t5.Text & "','" & Me.t6.Text & "','" & Me.t7.Text & "','" & Me.t8.Text & "','" & Me.d1.Text & "','" & Me.d2.Text & "','" & Me.t9.Text & "','" & Me.t8.Text - Me.t7.Text & "','" & Me.t3.Text * Me.t6.Text & "')"
                        db_informatique.Connecting_in_informatique()
                        db_informatique.Disconnecting_in_informatique()

                    End If

                    calculer2()
                    db_informatique2.Myreq = "update factureachat set nomp='" & Me.t2.Text & "', nbrepiece='" & Me.t4.Text & "',prixc='" & Me.t6.Text & "',prixp='" & Me.t7.Text & "',prixvente='" & Me.t8.Text & "',nbregpiece='" & nbregp + t5.Text & "',nbrecarton='" & nbreca + t3.Text & "', val='" & d1.Text & "',prixg='" & prig + (t3.Text * t6.Text) & "'  where codep='" & Me.t1.Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()


                    calculer()
                    chercher()

                    If test4 = 0 Then
                        updater()
                    Else
                        inserer()
                    End If
                    affichelistview()

                    vider()
                End If
            Else
                db_informatique.Myreq = "select*from factureachat"
                db_informatique.Connecting_in_informatique()
                test5 = 1
                Do While db_informatique.rdr.Read
                    If (db_informatique.rdr(9).ToString) = d2.Text And (db_informatique.rdr(10).ToString) = t9.Text And (db_informatique.rdr(0).ToString) = t1.Text Then
                        test5 = 0
                    End If

                Loop
                db_informatique.Disconnecting_in_informatique()
                calculer3()
                If test5 = 0 Then
                    db_informatique.Myreq = "update factureachat set nomp='" & Me.t2.Text & "', nbrepiece='" & Me.t4.Text & "',prixc='" & Me.t6.Text & "',prixp='" & Me.t7.Text & "',prixvente='" & Me.t8.Text & "',nbregpiece='" & nbregp + t5.Text & "',nbrecarton='" & nbreca + t3.Text & "', val='" & d1.Text & "',prixg='" & prig + (t3.Text * t6.Text) & "'   where codep='" & Me.t1.Text & "' and numfac = '" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    db_informatique.Disconnecting_in_informatique()
                Else
                    db_informatique.Myreq = "Insert Into factureachat (codep,nomp,nbrecarton,nbrepiece,nbregpiece,prixc,prixp,prixvente,val,datf,numfac,gangne,prixg) values('" & Me.t1.Text & "','" & Me.t2.Text & "','" & Me.t3.Text & "','" & Me.t4.Text & "','" & Me.t5.Text & "','" & Me.t6.Text & "','" & Me.t7.Text & "','" & Me.t8.Text & "','" & Me.d1.Text & "','" & Me.d2.Text & "','" & Me.t9.Text & "','" & Me.t8.Text - Me.t7.Text & "','" & Me.t3.Text * Me.t6.Text & "')"
                    db_informatique.Connecting_in_informatique()
                    db_informatique.Disconnecting_in_informatique()

                End If

                calculer2()
                db_informatique2.Myreq = "update factureachat set nomp='" & Me.t2.Text & "', nbrepiece='" & Me.t4.Text & "',prixc='" & Me.t6.Text & "',prixp='" & Me.t7.Text & "',prixvente='" & Me.t8.Text & "',nbregpiece='" & nbregp + t5.Text & "',nbrecarton='" & nbreca + t3.Text & "', val='" & d1.Text & "',prixg='" & prig + (t3.Text * t6.Text) & "'  where codep='" & Me.t1.Text & "'"
                db_informatique2.Connecting_in_informatique()
                db_informatique2.Disconnecting_in_informatique()


                calculer()
                chercher()

                If test4 = 0 Then
                    updater()
                Else
                    inserer()
                End If
                affichelistview()

                vider()
            End If

        ElseIf s3 < 15 Then
            If MessageBox.Show(" تاريخ الصلاحية اقل من 15 يوم هل تريد المواصلة؟ ", "صلاحية", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
                db_informatique.Myreq = "Insert Into factureachat (codep,nomp,nbrecarton,nbrepiece,nbregpiece,prixc,prixp,prixvente,val,datf,numfac,gangne,prixg) values('" & Me.t1.Text & "','" & Me.t2.Text & "','" & Me.t3.Text & "','" & Me.t4.Text & "','" & Me.t5.Text & "','" & Me.t6.Text & "','" & Me.t7.Text & "','" & Me.t8.Text & "','" & Me.d1.Text & "','" & Me.d2.Text & "','" & Me.t9.Text & "','" & Me.t8.Text - Me.t7.Text & "','" & Me.t3.Text * Me.t6.Text & "')"
                db_informatique.Connecting_in_informatique()
                db_informatique.Disconnecting_in_informatique()
                db_informatique2.Myreq = "Insert Into factureachat (codep,nomp,nbrecarton,nbrepiece,nbregpiece,prixc,prixp,prixvente,val,datf,numfac,gangne,prixg) values('" & Me.t1.Text & "','" & Me.t2.Text & "','" & Me.t3.Text & "','" & Me.t4.Text & "','" & Me.t5.Text & "','" & Me.t6.Text & "','" & Me.t7.Text & "','" & Me.t8.Text & "','" & Me.d1.Text & "','" & Me.d2.Text & "','" & Me.t9.Text & "','" & Me.t8.Text - Me.t7.Text & "','" & Me.t3.Text * Me.t6.Text & "')"
                db_informatique2.Connecting_in_informatique()
                db_informatique2.Disconnecting_in_informatique()
                calculer()
                chercher()
                If test4 = 0 Then

                    updater()
                Else
                    inserer()
                End If
                affichelistview()
                vider()
            End If

        Else
            db_informatique.Myreq = "Insert Into factureachat (codep,nomp,nbrecarton,nbrepiece,nbregpiece,prixc,prixp,prixvente,val,datf,numfac,gangne,prixg) values('" & Me.t1.Text & "','" & Me.t2.Text & "','" & Me.t3.Text & "','" & Me.t4.Text & "','" & Me.t5.Text & "','" & Me.t6.Text & "','" & Me.t7.Text & "','" & Me.t8.Text & "','" & Me.d1.Text & "','" & Me.d2.Text & "','" & Me.t9.Text & "','" & Me.t8.Text - Me.t7.Text & "','" & Me.t3.Text * Me.t6.Text & "')"
            db_informatique.Connecting_in_informatique()
            db_informatique.Disconnecting_in_informatique()
            db_informatique2.Myreq = "Insert Into factureachat (codep,nomp,nbrecarton,nbrepiece,nbregpiece,prixc,prixp,prixvente,val,datf,numfac,gangne,prixg) values('" & Me.t1.Text & "','" & Me.t2.Text & "','" & Me.t3.Text & "','" & Me.t4.Text & "','" & Me.t5.Text & "','" & Me.t6.Text & "','" & Me.t7.Text & "','" & Me.t8.Text & "','" & Me.d1.Text & "','" & Me.d2.Text & "','" & Me.t9.Text & "','" & Me.t8.Text - Me.t7.Text & "','" & Me.t3.Text * Me.t6.Text & "')"
            db_informatique2.Connecting_in_informatique()
            db_informatique2.Disconnecting_in_informatique()
            calculer()
            chercher()
            If test4 = 0 Then
                updater()
            Else
                inserer()
            End If


            affichelistview()
            vider()
        End If

        t1.Focus()

    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)) Then
            t4.BackColor = Color.Red
            e.Handled = True

        Else
            t4.BackColor = Color.White
        End If


    End Sub

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

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

            e.Handled = True
        End If
    End Sub

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

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

            e.Handled = True
        End If
    End Sub

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

    Private Sub t9_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t9.KeyPress
       
    End Sub

    Private Sub t4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t4.TextChanged
        Try
            Dim test As Double = t6.Text / t4.Text
            t7.Text = test
        Catch ex As Exception

        End Try
        Try
            t5.Text = t4.Text * t3.Text
        Catch ex As Exception

        End Try

    End Sub

    Private Sub t3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            t5.Text = t4.Text * t3.Text
        Catch ex As Exception

        End Try
    End Sub

    Private Sub t6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t6.TextChanged
        Try
            Dim test As Double = t6.Text / t4.Text
            t7.Text = test
        Catch ex As Exception

        End Try
    End Sub

    Private Sub t8_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t8.Leave
        Try
            Dim tes1, tes2 As Double
            tes1 = t8.Text
            tes2 = t7.Text
            If tes1 <= tes2 Then
                MsgBox("سعر البيع اقل من سعر الشراء")
                t8.Focus()

            End If
        Catch ex As Exception

        End Try

    End Sub
    Private Sub vider()
        t1.Text = ""
        t2.Text = ""
        t3.Text = ""
        t4.Text = ""
        t5.Text = ""
        t6.Text = ""
        t7.Text = ""
        t8.Text = ""

    End Sub



    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        vider()
        t9.Text = ""
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If ListView1.SelectedItems.Count > 0 Then
            If MessageBox.Show(" هل تريد حذف الصنف   ", "حذف الصنف المحدد", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then

                Do While ListView1.SelectedItems.Count > 0
                    db_informatique.Myreq = "select*from factureachat  where codep='" & ListView1.SelectedItems(0).Text & "' and numfac = '" & Me.ListView1.SelectedItems(0).SubItems(10).Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    Do While db_informatique.rdr.Read
                        prig1 = (db_informatique.rdr(12).ToString)
                    Loop
                    db_informatique.Disconnecting_in_informatique()
                    db_informatique.Myreq = "Delete From factureachat where codep='" & ListView1.SelectedItems(0).Text & "' and numfac = '" & Me.ListView1.SelectedItems(0).SubItems(10).Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    db_informatique.Disconnecting_in_informatique()
                    'من هنا
                    db_informatique2.Myreq = "select*from factureachat  where codep='" & ListView1.SelectedItems(0).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    Do While db_informatique2.rdr.Read
                        deltp = (db_informatique2.rdr(4).ToString)
                        deltc = (db_informatique2.rdr(2).ToString)
                        prig = (db_informatique2.rdr(12).ToString)
                    Loop
                    db_informatique2.Disconnecting_in_informatique()



                    db_informatique2.Myreq = "update factureachat set nbregpiece='" & deltp - ListView1.SelectedItems(0).SubItems(4).Text & "',nbrecarton='" & deltc - ListView1.SelectedItems(0).SubItems(2).Text & "',prixg='" & prig - prig1 & "' where codep='" & ListView1.SelectedItems(0).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()


                    calculer()
                    db_informatique.Myreq = "update listefacture set somm='" & Me.TextBox1.Text & "' where numf='" & ListView1.SelectedItems(0).SubItems(10).Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    db_informatique.Disconnecting_in_informatique()
                    Dim element As New ListViewItem
                    element = ListView1.SelectedItems(0)
                    ListView1.Items.Remove(element)
                    affichelistview()
                Loop
            End If
        End If

    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        If ListView1.Items.Count > 0 Then
            If MessageBox.Show(" هل تريد حذف جميع الاصناف بالفاتورة  ؟  ", "حذف الكل", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then

                Do While ListView1.Items.Count > 0

                    db_informatique.Myreq = "select*from factureachat  where codep='" & ListView1.Items(0).Text & "' and numfac = '" & Me.ListView1.Items(0).SubItems(10).Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    Do While db_informatique.rdr.Read
                        prig1 = (db_informatique.rdr(12).ToString)
                    Loop
                    db_informatique.Disconnecting_in_informatique()
                    db_informatique.Myreq = "Delete From factureachat where codep='" & ListView1.Items(0).Text & "' and numfac = '" & Me.ListView1.Items(0).SubItems(10).Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    db_informatique.Disconnecting_in_informatique()
                    'من هنا
                    db_informatique2.Myreq = "select*from factureachat  where codep='" & ListView1.Items(0).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    Do While db_informatique2.rdr.Read
                        deltp = (db_informatique2.rdr(4).ToString)
                        deltc = (db_informatique2.rdr(2).ToString)
                        prig = (db_informatique2.rdr(12).ToString)
                    Loop
                    db_informatique2.Disconnecting_in_informatique()



                    db_informatique2.Myreq = "update factureachat set nbregpiece='" & deltp - ListView1.Items(0).SubItems(4).Text & "',nbrecarton='" & deltc - ListView1.Items(0).SubItems(2).Text & "',prixg='" & prig - prig1 & "' where codep='" & ListView1.Items(0).Text & "'"
                    db_informatique2.Connecting_in_informatique()
                    db_informatique2.Disconnecting_in_informatique()
                    calculer()

                    Dim element As New ListViewItem
                    element = ListView1.Items(0)
                    ListView1.Items.Remove(element)
                    affichelistview()
                    db_informatique.Myreq = "Delete From listefacture where numf='" & Me.t9.Text & "' and datf='" & Me.d2.Text & "'"
                    db_informatique.Connecting_in_informatique()
                    db_informatique.Disconnecting_in_informatique()
                Loop
            End If
        End If

    End Sub

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

        affichelistview()
        calculer()

    End Sub

    Private Sub t1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.Leave

        trouve = 1
        db_informatique2.Myreq = "select*from factureachat "
        db_informatique2.Connecting_in_informatique()
        Do While db_informatique2.rdr.Read
            If (db_informatique2.rdr(0).ToString) = t1.Text Then
                t2.Text = db_informatique2.rdr(1).ToString
                t3.Text = 1
                t4.Text = db_informatique2.rdr(3).ToString
                t5.Text = t3.Text * t4.Text
                t6.Text = db_informatique2.rdr(5).ToString
                t7.Text = t6.Text / t4.Text
                t8.Text = db_informatique2.rdr(7).ToString
                d1.Text = db_informatique2.rdr(8).ToString
                trouve = 0
            End If

        Loop
        db_informatique2.Disconnecting_in_informatique()
    End Sub

   

    Private Sub t1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t1.KeyDown
        If e.KeyCode = Keys.Enter And t1.Text <> "" Then
            trouve = 1
            db_informatique2.Myreq = "select*from factureachat "
            db_informatique2.Connecting_in_informatique()
            Do While db_informatique2.rdr.Read
                If (db_informatique2.rdr(0).ToString) = t1.Text Then
                    t2.Text = db_informatique2.rdr(1).ToString
                    t3.Text = 1
                    t4.Text = db_informatique2.rdr(3).ToString

                    t6.Text = db_informatique2.rdr(5).ToString
                    t7.Text = t6.Text / t4.Text
                    t8.Text = db_informatique2.rdr(7).ToString
                    d1.Text = db_informatique2.rdr(8).ToString
                    trouve = 0
                End If

            Loop
            db_informatique2.Disconnecting_in_informatique()
            t2.Focus()
        End If


    End Sub

    Private Sub t2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles t2.GotFocus
        InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("ar-ly"))
    End Sub

    Private Sub t2_Invalidated(ByVal sender As Object, ByVal e As System.Windows.Forms.InvalidateEventArgs) Handles t2.Invalidated

    End Sub



    Private Sub t2_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t2.KeyDown
        If e.KeyCode = Keys.Enter And t2.Text <> "" Then
            t3.Focus()

        End If

    End Sub

    Private Sub t3_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t3.KeyDown
        If e.KeyCode = Keys.Enter And t3.Text <> "" Then
            t4.Focus()

        End If
        Try
            t5.Text = t4.Text * t3.Text
        Catch ex As Exception

        End Try
    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 And t4.Text <> "" Then
            t5.Focus()

        End If
    End Sub

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

        End If
    End Sub

    Private Sub t6_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t6.KeyDown
        If e.KeyCode = Keys.Enter And t6.Text <> "" Then
            t7.Focus()

        End If
    End Sub

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

        End If
    End Sub

    Private Sub t8_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t8.KeyDown
        If e.KeyCode = Keys.Enter And t8.Text <> "" Then
            Try
                Dim tes1, tes2 As Double
                tes1 = t8.Text
                tes2 = t7.Text
                If tes1 <= tes2 Then
                    MsgBox("سعر البيع اقل من سعر الشراء", MsgBoxStyle.Information, "تنبيه المستخدم")
                    t8.Focus()
                Else
                    d1.Focus()

                End If
            Catch ex As Exception
                d1.Focus()
            End Try


        End If
    End Sub

    Private Sub d1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles d1.KeyDown
        s = d1.Text.Replace("/", "")
        s2 = d2.Text.Replace("/", "")
        s3 = s - s2
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
            If s3 <= 0 Then
                MsgBox("تأكد من تاريخ الصلاحية", MsgBoxStyle.Information, "تنبيه المستخدم")
                d1.Focus()
            Else
                d2.Focus()
            End If


        End If
    End Sub

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

        End If
    End Sub

    Private Sub t9_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t9.KeyDown
        If e.KeyCode = Keys.Enter And t9.Text <> "" Then
            Button6.Focus()

        End If
    End Sub

    Private Sub d1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles d1.Leave
        s = d1.Text.Replace("/", "")
        s2 = d2.Text.Replace("/", "")
        s3 = s - s2
        If s3 <= 0 Then
            MsgBox("تأكد من تاريخ الصلاحية", MsgBoxStyle.Information, "تنبيه المستخدم")
            d1.Focus()
        End If
    End Sub

    Private Sub t3_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t3.TextChanged
        Try
            t7.Text = t6.Text / t4.Text
        Catch ex As Exception

        End Try
        Try
            t5.Text = t4.Text * t3.Text
        Catch ex As Exception

        End Try
    End Sub

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

    End Sub

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

    End Sub

    Private Sub t2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t2.KeyPress
        Select Case e.KeyChar
            Case "ء" To "ي", ControlChars.Back, Chr(Keys.Space), "0" To "9", "a" To "z", "A" To "Z"
                e.Handled = False
            Case Else
                e.Handled = True
        End Select
    End Sub

    Private Sub t7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t7.TextChanged

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        db_informatique2.Myreq = "update factureachat set prixvente='" & Me.t8.Text & "' "
        db_informatique2.Connecting_in_informatique()
        db_informatique2.Disconnecting_in_informatique()
        db_informatique.Myreq = "update factureachat set prixvente='" & Me.t8.Text & "' "
        db_informatique.Connecting_in_informatique()
        db_informatique.Disconnecting_in_informatique()
        MsgBox("تم تعديل سعر البيع", MsgBoxStyle.Information, "تعديل سعر البيع")
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        Form10.Show()

    End Sub

    Private Sub t2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t2.TextChanged

    End Sub
End Class
