forked from Mohammed4mach/Recipehub-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Recipe.aspx.cs
130 lines (104 loc) · 4.1 KB
/
Recipe.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.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Recipehub
{
public partial class Recipe : System.Web.UI.Page
{
// Product Variables
public int prod_id;
public string prod_name;
// Recipe Variables
public int rec_id;
public string rec_pic;
public int time;
public double cost;
public string ingredients;
public string method;
public string video;
public string rec_date;
// User data Variables
public int user_id;
public string username;
public string user_pic;
// Debugging Variables
public string err;
MySqlConnection conn;
// Some page functions
int getProductId()
{
int result;
string sql = $"SELECT prod_id FROM recipe WHERE rec_id = {rec_id};";
MySqlDataReader readId = Func.executeSQLReader(conn, sql);
readId.Read();
result = int.Parse(readId["prod_id"].ToString());
readId.Close();
return result;
}
string getProductName()
{
string result;
string sql = $"SELECT name FROM product WHERE prod_id = {prod_id}";
MySqlDataReader readName = Func.executeSQLReader(conn, sql);
readName.Read();
result = readName["name"].ToString();
readName.Close();
return result;
}
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["recid"] == null)
{
Response.Redirect("~/Default.aspx");
}
conn = new MySqlConnection("server=127.0.0.1;user=root;password=root;database=recipehub;");
try
{
conn.Open();
// Assigning variables
rec_id = int.Parse(Request.QueryString["recid"]);
prod_id = getProductId();
prod_name = getProductName();
// Retrieve recipe information
string sql = $"SELECT user_id, picture, time, cost, ingredients, method, video, create_date FROM recipe WHERE rec_id = {rec_id}";
MySqlDataReader readRecInfo = Func.executeSQLReader(conn, sql);
readRecInfo.Read();
// Assigning recipe variables
rec_pic = readRecInfo["picture"].ToString() != "" ?
readRecInfo["picture"].ToString() :
"./assets/img/background.jpg";
if(readRecInfo["time"].ToString() != "")
time = int.Parse(readRecInfo["time"].ToString());
if(readRecInfo["cost"].ToString() != "")
cost = Convert.ToDouble(readRecInfo["cost"].ToString());
ingredients = readRecInfo["ingredients"].ToString();
method = readRecInfo["method"].ToString();
video = readRecInfo["video"].ToString();
rec_date = readRecInfo["create_date"].ToString();
// Assigning user variables
user_id = int.Parse(readRecInfo["user_id"].ToString());
readRecInfo.Close();
// Fetch user info
sql = $"SELECT username, picture FROM user WHERE user_id = {user_id}";
MySqlDataReader readUserInfo = Func.executeSQLReader(conn, sql);
readUserInfo.Read();
username = readUserInfo["username"].ToString();
user_pic = readUserInfo["picture"].ToString() != "" ?
readUserInfo["picture"].ToString() :
"./uploads/pictures/users/user.png";
Page.Title = prod_name + " Recipe";
readUserInfo.Close();
conn.Close();
}
catch(Exception ex)
{
err = ex.ToString();
}
}
}
}