1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Verification De Mode de Paiement (Pour Calculer Le Montant De Timbre)
If Me.RadioButton1.Checked = True Then Z = 1
If Me.RadioButton2.Checked = True Then Z = 2
If Me.RadioButton3.Checked = True Then Z = 3
If Me.RadioButton4.Checked = True Then Z = 4
'Inserer les informations de la facture
Try
Dim ConStr As String = "Data Source=Riadh;Initial Catalog=StockGuard;Integrated Security=SSPI"
Dim Conn As New SqlConnection(ConStr)
Dim SavInto As New SqlCommand
SavInto.Connection = Conn
SavInto.CommandType = CommandType.Text
SavInto.CommandText = "Insert Into Ventes(Code_cli,date_fact,remarque,Paiement)" & _
"values('" & Me.TextBox4.Text & "','" & Me.DateTimePicker1.Text & "','" & Me.TextBox2.Text & "','" & Z & "')"
'inserer les details facture
Dim DGVinto As New SqlCommand
Dim i, Qte As Integer
Dim Prix_Unit As Decimal
Dim ref, designation As String
Dim qtedispon As Integer
Conn.Open()
SavInto.ExecuteNonQuery()
For i = 0 To DataGridView1.RowCount - 2
ref = DataGridView1.Item(0, i).Value
designation = DataGridView1.Item(1, i).Value
Qte = DataGridView1.Item(2, i).Value
Prix_Unit = DataGridView1.Item(3, i).Value
'recuperer la quantité disponible
Try
Dim QteDispo As New SqlCommand
Dim connex As New SqlConnection(ConStr)
QteDispo.Connection = Conn
QteDispo.CommandType = CommandType.Text
QteDispo.CommandText = "Select qtedisp From produits"
connex.Open()
qtedispon = QteDispo.ExecuteScalar()
Me.TextBox1.Text = X + 1
connex.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
'l'insertion des details facture
DGVinto.Connection = Conn
DGVinto.CommandType = CommandType.Text
DGVinto.CommandText = "Insert Into Detailes_Factures(ref,designation,qte,prix_unit,Num_fact) values('" & ref & "','" & designation & "','" & Qte & "','" & Prix_Unit & "','" & TextBox1.Text & "')"
DGVinto.CommandText = "Update Produits Set Qtedisp=" & (qtedispon - Qte).ToString & " where designation='" & designation & "''"
Next
Conn.Close()
X = Me.TextBox1.Text
MsgBox("Nouvelle Facture Inserer Avec Succés", MsgBoxStyle.Information)
Me.Button1.Enabled = True
Me.Button4.Enabled = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub |
Partager