/
pgOrder.aspx.cs
202 lines (161 loc) · 5.51 KB
/
pgOrder.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pgOrder : System.Web.UI.Page
{
clsBusinessLayer myBusinessLayer;
protected void Page_Load(object sender, EventArgs e)
{
Master.AboutUs.Visible = false;
Master.AccountDetails.Visible = false;
Master.Checkout.Visible = false;
Master.FAQ.Visible = false;
Master.HomePage.Visible = false;
Master.Login.Visible = false;
Master.OrderReview.Visible = false;
Master.AboutUs.Enabled = false;
Master.AccountDetails.Enabled = false;
Master.Checkout.Enabled = false;
Master.FAQ.Enabled = false;
Master.HomePage.Enabled = false;
Master.Login.Enabled = false;
Master.OrderReview.Enabled = false;
lblOrderNum.Visible = false;
lblOrderNum.Text = "0";
lblCurrentUser.Visible = true;
foreach (ListItem li in chkJobType.Items)
{
//add margin as css style
li.Attributes.CssStyle.Add("margin-left", "75px");
}
foreach (ListItem li in chkMedia.Items)
{
//add margin as css style
li.Attributes.CssStyle.Add("margin-left", "75px");
}
// Add data to myBusinessLayer
myBusinessLayer = new clsBusinessLayer(Server.MapPath("~/App_Data/"));
try
{
if (PreviousPage.IsCrossPagePostBack)
{
lblCurrentUser.Text = PreviousPage.CurrentUser.Text;
}
}
catch (Exception error)
{
Master.UserFeedBack.Text = error.Message;
}
}
public Label CurrentCustomer
{
get { return lblCurrentCustomer; }
}
public Label OrderNum
{
get { return lblOrderNum; }
}
public TextBox Message
{
get { return txtMessage; }
}
public GridView Cart
{
get { return gvCart; }
}
public Label JobType
{
get { return lblJobTypeOutput; }
}
public Label Media
{
get { return lblMediaOutput; }
}
private void ClearInputs(ControlCollection ctrls)
{
lblOrderNum.Text = string.Empty;
lblJobTypeOutput.Text = string.Empty;
lblMediaOutput.Text = string.Empty;
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
((TextBox)ctrl).Text = string.Empty;
else if (ctrl is DropDownList)
((DropDownList)ctrl).ClearSelection();
else if (ctrl is RadioButton)
((RadioButton)ctrl).Checked = false;
else if (ctrl is RadioButtonList)
((RadioButtonList)ctrl).ClearSelection();
else
ClearInputs(ctrl.Controls);
}
}
private dsAccounts BindCartGridView()
{
// Pulls data from the database for use
string tempPath = Server.MapPath("~/App_Data/Accounts.mdb");
clsDataLayer myDataLayer = new clsDataLayer(tempPath);
// Adds data from the first to the second
dsAccounts cartListing = myDataLayer.FillCart(lblCurrentCustomer.Text);
// Adds data from the first to the second
gvCart.DataSource = cartListing.tblCart;
// Caches data collected
gvCart.DataBind();
Cache.Insert("CustomerDataSet", cartListing);
return cartListing;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
// Create the list to store.
List<String> chkJobTypeList = new List<string>();
List<String> chkMediaList = new List<string>();
// Loop through each item.
foreach (ListItem item in chkJobType.Items)
{
if (item.Selected)
{
// If the item is selected, add the value to the list.
chkJobTypeList.Add(item.Value);
}
}
// Loop through each item.
foreach (ListItem item in chkMedia.Items)
{
if (item.Selected)
{
// If the item is selected, add the value to the list.
chkMediaList.Add(item.Value);
}
}
// Join the string together using the , delimiter.
lblJobTypeOutput.Text = String.Join(", ", chkJobTypeList.ToArray());
// Join the string together using the , delimiter.
lblMediaOutput.Text = String.Join(", ", chkMediaList.ToArray());
panelOrder.Enabled = false;
}
protected void btnEmpty_Click(object sender, EventArgs e)
{
myBusinessLayer.DeleteCart(Convert.ToInt32(lblOrderNum.Text));
}
protected void btnClear_Click(object sender, EventArgs e)
{
ClearInputs(Page.Controls);
panelOrder.Enabled = true;
}
protected void btnConfirm_Click(object sender, EventArgs e)
{
myBusinessLayer.AddToCart(lblCurrentCustomer.Text, lblJobTypeOutput.Text, lblMediaOutput.Text, txtMessage.Text, Convert.ToInt32(lblOrderNum.Text));
panelOrder.Enabled = true;
lblMediaOutput.Text = "";
lblJobTypeOutput.Text = "";
txtMessage.Text = "";
BindCartGridView();
}
protected void btnCheckout_Click(object sender, EventArgs e)
{
lblCurrentUser.Text = lblCurrentUser.Text;
}
}