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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
tran.Transaction = odbctran
odbctran = Connexion.BeginTransaction
Try
'insertion dans la table parent
tran.CommandText = "Insert into VenteCptoire(CodVent,DateVent,dateenreg,CodDep,Depot,Vendeur,CodCli,Client,MttTTC,OptValider,OptEncaisser,OptFacturer,Caisse,optcomptabiliser,OptAnnuler)values ('" & Me.TextBox1.Text & "','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "','" & PCodDepo & "','" & PDepot & "','" & PVendeur & "','" & Me.txtcodcli.Text & "','" & Trim(Me.ComboBox3.Text) & "','" & CDec(Me.txtttc.Text) & "','" & True & "','" & False & "','" & False & "','" & PCaisse & "','" & False & "','" & False & "')"
tran.ExecuteNonQuery()
'insertion dans la table enfant
For i = 0 To Me.DataGridView1.Rows.Count - 1
'Try
Dim row As DataGridViewRow = Me.DataGridView1.Rows(i)
tran.CommandText = "Insert into dtlVenteCpt(CodVent0,CodArt,Article,QteVendu,PVU,Mtt)values ('" & Me.TextBox1.Text & "','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "')"
tran.ExecuteNonQuery()
Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand()
Mycommand2.CommandText = "SELECT * FROM Mvt_VenteCaisse where dateop = '" & Now.ToShortDateString & "' and CodArt = '" & Me.DataGridView1.Rows(i).Cells(0).Value & "' and CodeDep = '" & PCodDepo & "' and caisse = '" & PCaisse & "'"
Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()
If myReader2.HasRows = False Then
OptTV = False
tran.CommandText = "Insert into Mvt_VenteCaisse(dateop,CodeDep,Depot,codcaiss,caisse,marque,codfam,famille,CodArt,Article,Qtevendu,PVU,Mtt)values ('" & CDate(Me.MaskedTextBox1.Text) & "','" & PCodDepo & "','" & PDepot & "','" & PCodcaiss & "','" & PCaisse & "','" & Me.DataGridView1.Rows(i).Cells(10).Value & "','" & Me.DataGridView1.Rows(i).Cells(11).Value & "','" & Me.DataGridView1.Rows(i).Cells(12).Value & "','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "')"
tran.ExecuteNonQuery()
Else
OptTV = True
tran.CommandText = "Update Mvt_VenteCaisse set Qtevendu = '" & Val(Me.DataGridView1.Rows(i).Cells(13).Value) & "' where CodArt = '" & Me.DataGridView1.Rows(i).Cells(0).Value & "' and famille = '" & Me.DataGridView1.Rows(i).Cells(12).Value & "' and caisse = '" & PCaisse & "' and Depot = '" & PDepot & "' and dateop = '" & Now.ToShortDateString & "'"
tran.ExecuteNonQuery()
tran.CommandText = "Update Mvt_VenteCaisse set Mtt = '" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "' where CodArt = '" & Me.DataGridView1.Rows(i).Cells(0).Value & "' and famille = '" & Me.DataGridView1.Rows(i).Cells(12).Value & "' and caisse = '" & PCaisse & "' and Depot = '" & PDepot & "' and dateop = '" & Now.ToShortDateString & "'"
tran.ExecuteNonQuery()
End If
myReader2.Close()
tran.CommandText = "Insert into MVDepot(CodeMvt,CodeDep,CodArt,Article,Depot,PA,PVU,QteInitial,QteEntre,QteSortie,QteFinale,SensMvt,Observat,TypDepot,DateMv,DateEnreg)values ('" & Me.TextBox1.Text & "','Cood','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & PDepot & "','" & Val(Me.DataGridView1.Rows(i).Cells(6).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(8).Value) & "',0,'" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(9).Value) & "','Sortie','Vente Comptoire','Depot de Vente','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "')"
tran.ExecuteNonQuery()
'odbctran.Commit()
'Catch g As Exception
' MsgBox(Err.Description)
' odbctran.Rollback()
'End Try
Next i
'Catch g As Exception
' MsgBox(Err.Description)
' odbctran.Rollback()
'End Try
tran.CommandText = "Insert into BrouillardCaisse(dateenreg,dateop,codCaiss,Caisse,Libelle,Entree,Sortie,solde) values ('" & Now.ToShortDateString & "','" & Pdate & "','" & PCodcaiss & "','" & PCaisse & "','vente au Comptoire Ticket N° " & Me.TextBox1.Text & "','" & Val(Me.txtttc.Text) & "',0, '" & Val(Me.txtttc.Text) & "')"
tran.ExecuteNonQuery()
tran.CommandText = "Update VenteCptoire set MttTTC = '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'"
tran.ExecuteNonQuery()
tran.CommandText = "Update VenteCptoire set MttPayer = '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'"
tran.ExecuteNonQuery()
odbctran.Commit()
optvalider = False
MsgBox("Vente effectuée avec succès...")
Catch ex As Exception
MsgBox("La Transaction a échouée.Aucun Mouvement n'a été effectué")
MsgBox(Err.Description)
Try
odbctran.Rollback()
Catch g As Exception
MsgBox("Délai Dépassé, La Transaction sur les différents comptes a échouée...")
Me.Close()
End Try
End Try
End If |
Partager