-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reviewer.aspx.cs
130 lines (121 loc) · 4.74 KB
/
Reviewer.aspx.cs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Food_Rating_System
{
public partial class Reviewer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlTheme.Items.Add("Choose Theme");
ddlTheme.Items.Add("Normal");
ddlTheme.Items.Add("Dark");
List<string> category = new List<string>();
category.Add("Name");
category.Add("Location");
category.Add("Rating");
category.Add("Cuisine");
ddlSearch.DataSource = category;
List<int> rating = new List<int>();
rating.Add(1);
rating.Add(2);
rating.Add(3);
rating.Add(4);
rating.Add(5);
ddlReview.DataSource = rating;
this.DataBind();
//this.Master.FindControl("ddlTheme").Visible = false;
//Changing theme creates a new session
}
HttpCookie cookie = Request.Cookies["prevSearch"];
if (cookie != null)
lbPrev.Text =cookie["category"].ToString() + " and " +cookie["value"].ToString();
}
protected void btnReview_Click(object sender, EventArgs e)
{
int row = 0;
if (Page.IsValid)
{
string conStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string cmdStr = "INSERT INTO Comments values(@Email,@RestName,@Comment,@Rating,@Approved)";
using (SqlConnection cnn = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand(cmdStr, cnn))
{
cmd.Parameters.AddWithValue("@Email", Session["Email"].ToString());
cmd.Parameters.AddWithValue("@RestName", ddlNames.SelectedValue);
cmd.Parameters.AddWithValue("@Comment", tbReview.Text);
cmd.Parameters.AddWithValue("@Rating", ddlReview.SelectedValue);
cmd.Parameters.AddWithValue("@Approved", 0);
try
{
cnn.Open();
row = cmd.ExecuteNonQuery();
}
catch (Exception)
{
lbStatus.Text = "One Review Per Restaurant";
//other inputs can't cause an error
}
finally
{
cnn.Close();
}
}
}
tbReview.Text = "";
if (row == 1)
lbStatus.Text = "Success";
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
HttpCookie prevSearch;
prevSearch = Request.Cookies["prevSearch"];
if(prevSearch == null)
{
prevSearch = new HttpCookie("prevSearch");
}
prevSearch["category"] = ddlSearch.SelectedValue;
prevSearch["value"] = tbSearch.Text;
prevSearch.Expires.AddMonths(1);
Response.Cookies.Add(prevSearch);
Response.Redirect("searchResults.aspx?category=" + ddlSearch.SelectedValue + "&value=" + tbSearch.Text.ToString());
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("Login.aspx");
}
protected void ddlTheme_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Theme"] = ddlTheme.SelectedItem.Text.ToString();
Response.Redirect(Request.RawUrl);
}
protected void Page_PreInit(object sender, EventArgs e)
{
if (Session["Theme"] != null)
{
this.Theme = Session["Theme"].ToString();
}
else if (Request.QueryString["theme"] != null && Request.QueryString["theme"].ToString() != "Choose Theme")
{
this.Theme = Request.QueryString["theme"].ToString();
}
}
protected void btnComments_Click(object sender, EventArgs e)
{
Response.Redirect("Comments.aspx?name=" + ddlComments.SelectedValue);
}
}
}