Imports System.Data Imports System.IO Imports System.Data.SqlClient Imports System.Text Partial Class cart Inherits System.Web.UI.Page Dim user As String Dim value As String Dim msg As String Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Data Source=D3SQ9Z2J;Initial Catalog=e-comm-proj;Integrated Security=True") Dim cmd As New System.Data.SqlClient.SqlCommand Dim check As Integer = 0 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load user = Request.QueryString("user") user_lbl.Text = user & "'s Shopping Cart" Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Data Source=D3SQ9Z2J;Initial Catalog=e-comm-proj;Integrated Security=True") Dim cmd As New System.Data.SqlClient.SqlCommand cmd.CommandType = System.Data.CommandType.Text cmd.Connection = sqlConnection1 sqlConnection1.Open() cmd.CommandText = "select CONVERT(char(10), DATEADD(day, 7, added_on), 101) " & _ "from cart where check_out=0 and user_name='" & user & "'" Dim res As Object = cmd.ExecuteScalar 'Response.Write("Resource " & res) 'If res = Date.Today Then If Date.Today >= res And res <> String.Empty Then MsgBox("Sorry " & " " & user & " Your Shopping Cart is Deleted Because You Exceeded The Allowed Time to Check Out", MsgBoxStyle.Information, "Shopping Cart Deleted") cmd.CommandText = "delete from cart where check_out=0 and user_name='" & user & "'" cmd.ExecuteNonQuery() 'Response.Write(res & " " & Date.Today) 'Response.Write("They are equal") Else cmd.Parameters.Add("@user", Data.SqlDbType.NVarChar, 15).Value = user cmd.CommandText = "select p_type,message from personalization where user_name = @user" 'Dim result As Object = cmd.ExecuteScalar() Dim result As SqlDataReader = cmd.ExecuteReader Do While result.Read 'if the data type for p_type field is nvarchar(50) for example the below condition 'will never come true because the value from the database may contain spaces ' for example the value will be like this "mo " so it never match with "mo" If result("p_type") = "mo" Then msg = " " & result("message") & "" ElseIf result("p_type") = "nb" Or result("p_type") = "pc" Then msg = msg & " " & "" & _ result("message") & "" End If Loop Label1.Text = "" & msg & "" End If End Sub 'Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound ' img = CType(GridView1.FindControl("Image1"), Image) ' img.ImageUrl = "~/Notebooks_PCs/99.jpg" 'End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click cmd.Connection = sqlConnection1 sqlConnection1.Open() ' Iterate through the Products.Rows property For Each row As GridViewRow In GridView1.Rows ' Access the CheckBox Dim cb As CheckBox = row.FindControl("selector") If cb IsNot Nothing AndAlso cb.Checked Then check = 1 ' First, get the ProductID for the selected row Dim productID As Integer = _ Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value) cmd.CommandText = "update cart set check_out = 1 where user_name = " & "'" & user & "'" & _ " and id=" & productID cmd.ExecuteNonQuery() ' "Delete" the row '... To actually delete the product, use ... 'Dim productAPI As New GridView1BLL 'productAPI.DeleteProduct(productID) '............................................ End If Next If check = 1 Then Response.Redirect("step_2_cart.aspx?user=" & user) ElseIf check = 0 Then MsgBox("No Check Box is Selected", MsgBoxStyle.Information, "Select at Least One Product") End If End Sub Protected Function GetPicture(ByVal dataItem As Object) As String Dim type As String = DataBinder.Eval(dataItem, "type") If type = "mo" Then Dim id As Integer = DataBinder.Eval(dataItem, "m_id") Return "~/Monitors/" & id & ".jpg" ElseIf type = "nb" Or type = "pc" Then Dim id As Integer = DataBinder.Eval(dataItem, "nb_pc_id") Return "~/Notebooks_PCs/" & id & ".jpg" Else Return "" End If End Function Protected Sub cart_ds_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles cart_ds.Selected If e.AffectedRows < 1 Then Button1.Visible = False End If End Sub End Class