/
SetRate.aspx.cs
102 lines (80 loc) · 3.64 KB
/
SetRate.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SetRate : System.Web.UI.Page
{
Customers actualCustomer;
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
MySql.Data.MySqlClient.MySqlDataReader reader;
string queryStr;
string title;
string id;
string em;
Movies movie;
List<Movies> allTitles;
protected void Page_Load(object sender, EventArgs e)
{
title = "";
allTitles = new List<Movies>();
actualCustomer = new Customers();
actualCustomer = (Customers)Session["myCustomer"];
System.Diagnostics.Debug.WriteLine("Rateeeeeeeeeeee=" + actualCustomer.Email);
if (!IsPostBack)
{
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebbAppConnString"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
conn.Open();
em = actualCustomer.Email;
queryStr = "";
queryStr = "SELECT distinct id, title from movies,bookings,bookings_has_movies,comments where movies.id = bookings_has_movies.movies_id and bookings_has_movies.Bookings_id = bookings.idBookings and bookings.user_email = '" + em + "' and bookings_has_movies.movies_id=comments.movies_id and bookings.user_email=comments.user_email and comments.isSetBetyg=false";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
id = reader.GetString(reader.GetOrdinal("id"));
title = reader.GetString(reader.GetOrdinal("title"));
allTitles.Add(new Movies(id, title));
System.Diagnostics.Debug.Write("Sizeeeeeeeeeeeee:" + allTitles.Count+"id: "+id+" title: "+title);
}
conn.Close();
ddlMovies.DataValueField = "id";
ddlMovies.DataTextField = "title";
ddlMovies.DataSource = allTitles;
ddlMovies.DataBind();
}
}
protected void buttonComments_Click(object sender, EventArgs e)
{
em = actualCustomer.Email;
var dateAsString = DateTime.Now.ToString("yyyy-MM-dd");
string comments = actualCustomer.FirstName+" said at: " + dateAsString+": "+TextBox1.Text;
int idTemp = Convert.ToInt32(ddlMovies.SelectedValue);
int betyg = Convert.ToInt32(DropDownListRate.SelectedValue);
updateComments(comments,betyg,em,idTemp);
}
protected void updateComments(string s,int betyg, string email,int id)
{
try
{
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebbAppConnString"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
conn.Open();
queryStr = "";
queryStr = "update comments set comment = '" + s + "', betyg= "+betyg+", isSetBetyg="+true+" where movies_id =" + id + " and user_email='"+email+"' and isSetBetyg=false";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
cmd.ExecuteReader();
conn.Close();
TextBox1.Text = "";
DropDownListRate.SelectedValue = "None";
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
System.Diagnostics.Debug.Write("error: "+ex);
errorLabel.Text = " It is not possible to set a new rate for this movie!!";
}
}
}