forked from lethienantran/MenuManagementService
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrderMenuMaster.Master.cs
136 lines (118 loc) · 5.13 KB
/
OrderMenuMaster.Master.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
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace SelfOrderManagementSystem
{
public partial class OrderMenuMaster : System.Web.UI.MasterPage
{
string CS = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
int userID,id;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(CS);
SqlDataAdapter da = new SqlDataAdapter("select distinct CategoryName from Category where UserID = " + Session["UserID"].ToString(), con);
SqlDataAdapter db = new SqlDataAdapter("select * from Category where UserID = " + Session["UserID"].ToString(), con);
DataSet ds = new DataSet();
DataSet dt = new DataSet();
db.Fill(dt);
da.Fill(ds);
repeater.DataSource = ds;
repeater.DataBind();
itemRepeater.DataSource = dt;
itemRepeater.DataBind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "CategoryClick":
var button = e.Item.FindControl("CategoryButton") as Button;
SqlConnection con = new SqlConnection(CS);
SqlDataAdapter da = new SqlDataAdapter("select * from Category where CategoryName = " + "\'" + button.Text.ToString() + "\'" + " and UserID = " + Session["UserID"].ToString() , con);
DataSet ds = new DataSet();
da.Fill(ds);
itemRepeater.DataSource = ds;
itemRepeater.DataBind();
break;
// Other commands here.
default:
break;
}
}
private DataTable getData(string query)
{
SqlConnection con = new SqlConnection(CS);
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
protected void itemRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "OrderClick":
id = Convert.ToInt32(Request.QueryString["id"].ToString());
userID = Convert.ToInt32(Session["UserID"]);
DataTable dtOrder = getData("select * from MealOrder where UserID = " + userID + " and OrderID = 1");
if(dtOrder.Rows.Count > 0)
{
DataRow dr = dtOrder.Rows[0];
DataTable dtOrderItem = getData("select * from OrderItem where ItemMealOrderID = " + Convert.ToInt32(dr["MealOrderID"].ToString()) + " and " + "ItemMealID" + "");
if(dtOrderItem.Rows.Count > 0)
{
insertData("Update OrderItem set quantity = quantity + 1 where ItemMealID = " + id + " and ItemMealOrderID = " + Convert.ToInt32(dr["MealOrderID"].ToString()));
}
else
{
addOrderItem(dr["MealOrderID"].ToString(), dr["userID"].ToString());
}
}
else if (dtOrder.Rows.Count == 0)
{
insertData("insert into MealOrder (userID, OrderID) values (" + userID + ", 1)");
DataTable newOrder = getData("select * from MealOrder where UserID = " + userID + " and OrderID = 1");
DataRow newOrderRow = newOrder.Rows[0];
addOrderItem(newOrderRow["MealOrderID"].ToString(), newOrderRow["userID"].ToString());
}
break;
default:
break;
}
}
private void addOrderItem(string orderID, string userID)
{
string query = "insert into OrderItem (ItemMealID, ItemMealOrderID, quantity) values (" + id + "," + orderID + "," + 1 + ")";
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
cmd.ExecuteNonQuery();
}
}
private void insertData(string query)
{
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand(query,con);
con.Open();
cmd.ExecuteNonQuery();
}
}
protected void checkoutButton_Click(object sender, EventArgs e)
{
Response.Redirect("CheckoutPage.aspx");
}
protected void cancelOrderButton_Click(object sender, EventArgs e)
{
Response.Redirect("StartOrderDisplay.aspx");
}
}
}