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
|
Sub dlVoiture_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlVoiture.UpdateCommand
Dim sqlArgent, sqlPrix As String
Dim Argent As Integer
lbIndex = e.Item.FindControl("lbIndex")
lbMarque = e.Item.FindControl("lbMarque")
lbModele = e.Item.FindControl("lbModele")
lbPuissance = e.Item.FindControl("lbPuissance")
lbCouple = e.Item.FindControl("lbCouple")
lbMasse = e.Item.FindControl("lbMasse")
lbVitMax = e.Item.FindControl("lbVitMax")
lbPrix = e.Item.FindControl("lbPrix")
Dim ma As String = lbMarque.Text
Dim mo As String = lbModele.Text
Dim pu As String = lbPuissance.Text
Dim co As String = lbCouple.Text
Dim vi As String = lbVitMax.Text
Dim ms As String = lbMasse.Text
Dim pr As Integer = lbPrix.Text
Dim ph As Integer = lbIndex.Text
sqlArgent = "select Argent from Speed_Joueur where IDJoueur = " & userid
sqlPrix = "select Prix from Speed_Voiture where IDVoiture = " & lbIndex.Text
Argent = RetourneUneValeur(sqlArgent)
pr = RetourneUneValeur(sqlPrix)
If Argent < pr Then
Label1.Text = "Vous n'avez pas assez d'argent pour acheter cette voiture."
Else
Dim sqlverif As String = "select Marque, Modele from Speed_VoitureJoueur where IDJoueur =" & userid
Dim cmdVerif As New SqlCommand(sqlverif, scConnexion)
Dim chaineverif As String
Dim drVerif = cmdVerif.ExecuteReader
chaineverif = "Vous possédez déjà les voitures suivantes : "
Do While drVerif.read()
chaineverif &= drVerif.getvalue(0) & ", " & drVerif.getvalue(1)
Loop
chaineverif &= "Etes vous sur de vouloir acheter celle ci : " & ma & ", " & mo
drVerif.close()
phVerif.Visible = True
'Déclenchement de la popup de confirmation
If MsgBox(chaineverif, MsgBoxStyle.YesNo, "SpeedMachin") = MsgBoxResult.Yes Then
Label1.Text = "Félicitation pour votre achat"
Dim cmdNewCar As New SqlCommand()
With cmdNewCar
.Connection = scConnexion
.CommandType = CommandType.StoredProcedure
.CommandText = "Speed_NewVoiture"
Dim p0 As SqlParameter = .Parameters.Add("IDJ", SqlDbType.Int)
Dim p1 As SqlParameter = .Parameters.Add("IDV", SqlDbType.Int)
Dim p2 As SqlParameter = .Parameters.Add("PR", SqlDbType.Int)
p0.Value = userid
p1.Value = ph
p2.Value = pr
'.CommandText = "Speed_NewVoiture(" & userid & "," & ph & "," & pr & ")"
.ExecuteNonQuery()
End With
End If
End If
End Sub |
Partager