-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourses.aspx.cs
More file actions
79 lines (70 loc) · 3.19 KB
/
courses.aspx.cs
File metadata and controls
79 lines (70 loc) · 3.19 KB
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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RegisterLogin
{
public partial class courses : System.Web.UI.Page
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
Session["addcourse"] = "true";
if(e.CommandName == "AddToCart")
{
//Response.Redirect("userprofile.aspx?id=" + e.CommandArgument.ToString());
if(Session["role"]==null)
{
Response.Redirect("userlogin.aspx");
}
else
{
string name= Session["fullname"].ToString();
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
string CID = e.CommandArgument.ToString();
//string Title, Description, Imageurl, price;
SqlCommand ttl = new SqlCommand("select * from courses where c_id = '" + CID.ToString() + "'", con);
ttl.ExecuteNonQuery();
SqlDataReader dr = ttl.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Session["Title"] = dr.GetValue(1).ToString();
Session["Description"] = dr.GetValue(2).ToString();
Session["Imageurl"] = dr.GetValue(3).ToString();
Session["Price"] = dr.GetValue(4).ToString();
}
dr.Close();
}
else
{
Response.Write("<script>alert('Error !');</script>");
}
SqlCommand cmd = new SqlCommand("insert into coursestaken(name,id,title,description,imageurl,price) values (@name,@id,@title,@description,@imageurl,@price)", con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@id", e.CommandArgument.ToString());
cmd.Parameters.AddWithValue("@title", Session["Title"]);
cmd.Parameters.AddWithValue("@description", Session["Description"]);
cmd.Parameters.AddWithValue("@imageurl", Session["Imageurl"]);
cmd.Parameters.AddWithValue("@price", Session["Price"]);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Course succesfully added to cart. Go to your profile.');</script>");
}
}
}
}
}