You are on page 1of 2

Imports System.

Data
Imports System.Data.SqlClient
Partial Class viewcart
Inherits System.Web.UI.Page
Dim con As New SqlConnection("Data Source=NAAZNEEN-PC;Initial
Catalog=testmob;Integrated Security=false;user id=sa;password=q1w2e3r4/;")
Public qry As String
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim da As SqlDataAdapter
Dim ds As DataSet

Public conn As New ADODB.Connection


Public rs As New ADODB.Recordset
Public sql As String
Public category, model As String
Public Function opendb() As Object

If conn.State = 1 Then conn.Close()


conn.Open("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;password=q1w2e3r4/;Initial Catalog=testmob;Data Source=NAAZNEEN-PC")
Return 0
End Function
Sub loadgrid()

qry = "select user_id as ID,category as CATEGORY,model as MODEL,amount as


AMOUNT,quantity as QUANTITY from tbl_cart where user_id='" & Session("userid") &
"'"
da = New SqlDataAdapter(qry, con)
ds = New DataSet
da.Fill(ds, "tbl_product")
GridView1.DataSource = ds
GridView1.DataMember = ds.Tables(0).ToString
GridView1.DataBind()

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Me.Load
con.Open()
opendb()
If Session("userid") = "" Then
Response.Write("<script> alert('pls login to view the cart')
</script>")
Else
Response.Redirect("viewcart.aspx")
loadgrid()
End If

End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Try
category = GridView1.SelectedRow.Cells(4).Text
model = GridView1.SelectedRow.Cells(5).Text
sql = "delete from tbl_cart where category='" & category & "' and
model='" & model & "' and user_id='" & Session("userid") & "' "
conn.Execute(sql)
loadgrid()

Catch ex As Exception
Response.Write("<script> alert('Select the record first and then click
on delete') </script>")
End Try
End Sub

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Try
category = GridView1.SelectedRow.Cells(4).Text
model = GridView1.SelectedRow.Cells(5).Text
sql = "select * from tbl_cart where category='" & category & "' and
model='" & model & "' and user_id='" & Session("userid") & "' "
If rs.State = 1 Then rs.Close()
rs.Open(sql, conn)
If rs.EOF = False Then
txtquantity.Text = rs(4).Value

End If
Catch ex As Exception
Response.Write("<script> alert('Select the record first and then click
on edit') </script>")
End Try
End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As


System.EventArgs) Handles GridView1.SelectedIndexChanged
category = GridView1.SelectedRow.Cells(4).Text
model = GridView1.SelectedRow.Cells(5).Text
End Sub

Protected Sub btnbuynow_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles btnbuynow.Click
Response.Redirect("frmbill.aspx")
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
category = GridView1.SelectedRow.Cells(4).Text
model = GridView1.SelectedRow.Cells(5).Text
sql = "update tbl_cart set quantity='" & txtquantity.Text & "' where
category='" & category & "' and model='" & model & "' and user_id='" &
Session("userid") & "' "
conn.Execute(sql)
Response.Write("<script> alert('quantity changed') </script>")
loadgrid()
End Sub
End Class