-
Notifications
You must be signed in to change notification settings - Fork 1
/
EditRestaurant.aspx.cs
202 lines (159 loc) · 7.1 KB
/
EditRestaurant.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;
using System.Data;
using System.Data.SqlClient;
namespace FoodFest
{
public partial class EditRestaurant : System.Web.UI.Page
{
DBConnect conn = new DBConnect();
public List<Restaurant> restaurants = new List<Restaurant>();
protected void Page_Load(object sender, EventArgs e)
{
if ((Session["LoggedInUserName"] != null))
{
LinkButton LinkButton1 = (LinkButton)Master.FindControl("LinkButton1");
LinkButton1.Visible = false;
LinkButton LinkButton2 = (LinkButton)Master.FindControl("LinkButton2");
LinkButton2.Visible = true;
Label Welcome_label = (Label)Master.FindControl("Welcome_label");
Welcome_label.Text = "Welcome " + Session["LoggedInUserName"];
Welcome_label.Visible = true;
}
else
{
LinkButton LinkButton1 = (LinkButton)Master.FindControl("LinkButton1");
LinkButton1.Visible = true;
LinkButton LinkButton2 = (LinkButton)Master.FindControl("LinkButton2");
LinkButton2.Visible = false;
}
populateRestaurantList();
}
private void populateRestaurantList()
{
Restaurant aRestaurant;
try
{
conn.SqlConnectionObj.Open();
string query = String.Format("SELECT RestaurantId, RestaurantName, RestaurantAddress, RestaurantPhone, RestaurantMinOrder,OpeningHour,ClosingHour,DeliveryFee FROM Restaurant_tbl");
conn.SqlCommandObj.CommandText = query;
SqlDataReader reader = conn.SqlCommandObj.ExecuteReader();
while (reader.Read())
{
aRestaurant = new Restaurant();
aRestaurant.RestaurantId = reader.GetInt32(0);
aRestaurant.RestaurantName = reader.GetString(1);
aRestaurant.RestaurantAddress = reader.GetString(2);
aRestaurant.RestaurantPhone = reader.GetString(3);
aRestaurant.RestaurantMinOrder = reader.GetString(4);
aRestaurant.OpenHour = reader.GetDateTime(5);
aRestaurant.CLoseHour = reader.GetDateTime(6);
aRestaurant.DeliveryFee = reader.GetInt32(7);
restaurants.Add(aRestaurant);
}
}
catch (Exception ex)
{
throw new Exception("Error occurred during user save operation. Try again", ex);
}
finally
{
if (conn.SqlConnectionObj != null && conn.SqlConnectionObj.State == ConnectionState.Open)
{
conn.SqlConnectionObj.Close();
}
}
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
string message;
if (FileUpload1.FileName != "")
{
SqlDataSource2.Update();
message = "Restaurant Updated successfully";
msgLabel.Text = message;
}
else
{
try
{
conn.SqlConnectionObj.Open();
string query = String.Format("Update Restaurant_tbl SET RestaurantAddress='{0}',RestaurantPhone='{1}',RestaurantMinOrder='{2}',OpeningHour='{3}',ClosingHour='{4}',DeliveryFee='{5}' where RestaurantName='{6}'", ResAddTextBox.Text, ResPhoneTextBox.Text, MinOrderTextBox.Text, OpenHrTextBox.Text, CloseHrTextBox.Text,TextBox1.Text, DropDownList1.SelectedValue);
conn.SqlCommandObj.CommandText = query;
conn.SqlCommandObj.ExecuteNonQuery();
message = "Restaurant Updated successfully";
msgLabel.Text = message;
}
catch (Exception ex)
{
throw new Exception("Error occurred during update operation. Try again", ex);
}
finally
{
if (conn.SqlConnectionObj != null && conn.SqlConnectionObj.State == ConnectionState.Open)
{
conn.SqlConnectionObj.Close();
}
}
}
ResPhoneTextBox.Text = "";
ResAddTextBox.Text = "";
MinOrderTextBox.Text = "";
CloseHrTextBox.Text = "";
TextBox1.Text = "";
OpenHrTextBox.Text = "";
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
msgLabel.Text = null;
Restaurant selectedRestaurant = Get(DropDownList1.SelectedValue);
if (selectedRestaurant != null)
{
ResAddTextBox.Text = selectedRestaurant.RestaurantAddress;
ResPhoneTextBox.Text = selectedRestaurant.RestaurantPhone;
MinOrderTextBox.Text = selectedRestaurant.RestaurantMinOrder.ToString();
OpenHrTextBox.Text = selectedRestaurant.OpenHour.ToString("t");
CloseHrTextBox.Text = selectedRestaurant.CLoseHour.ToString("t");
TextBox1.Text = selectedRestaurant.DeliveryFee.ToString();
int id = selectedRestaurant.RestaurantId;
Image1.ImageUrl = "~/HandlerImg.ashx?restId=" + id;
}
}
public Restaurant Get(string p)
{
foreach (Restaurant aRestaurant in restaurants)
{
if (aRestaurant.RestaurantName == p)
{
return aRestaurant;
}
}
return null;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
msgLabel.Text = null;
Restaurant selectedRestaurant = Get(DropDownList2.SelectedValue);
if (selectedRestaurant != null)
{
ResAddTextBox.Text = selectedRestaurant.RestaurantAddress;
ResPhoneTextBox.Text = selectedRestaurant.RestaurantPhone;
MinOrderTextBox.Text = selectedRestaurant.RestaurantMinOrder.ToString();
OpenHrTextBox.Text = selectedRestaurant.OpenHour.ToString("t");
CloseHrTextBox.Text = selectedRestaurant.CLoseHour.ToString("t");
TextBox1.Text = selectedRestaurant.DeliveryFee.ToString();
int id = selectedRestaurant.RestaurantId;
Image1.ImageUrl = "~/HandlerImg.ashx?restId=" + id;
}
}
protected void DelButton1_Click(object sender, EventArgs e)
{
SqlDataSource4.Delete();
SqlDataSource5.Delete();
}
}
}