-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdvancedSearch.aspx.cs
330 lines (296 loc) · 13 KB
/
AdvancedSearch.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Text;
using GourmetGuide;
public partial class AdvancedSearch : System.Web.UI.Page
{
public string str = "";
public string rID = "";
public string rName = "";
DataSet tbl = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["sortOrder"] = "";
bindGridView("", "");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string namesearchString;
string cuisinesearchString;
string openTimesearchString;
string closeTimesearchString;
string citysearchString;
string zipsearchString;
string statesearchString;
string foodsearchString;
Page_Load(sender, e);
if (!IsPostBack)
{
ViewState["sortOrder"] = "";
bindGridView("", "");
}
if (NameSearch.Text.Trim().Length == 0)
{
namesearchString = "UPPER(NAME)";
}
else {
namesearchString = "\'%"+NameSearch.Text.ToString().ToUpper()+"%\'";
}
if (CuisineSearch.Text.Trim().Length == 0)
{
cuisinesearchString = "UPPER(DESCRIPTION)";
}
else
{
cuisinesearchString = "\'%" + CuisineSearch.Text.ToString().ToUpper() + "%\'";
}
if (OpenTimeSearch.Text.Trim().Length == 0)
{
openTimesearchString = "UPPER(OPENTIME)";
}
else
{
openTimesearchString = "\'%" + OpenTimeSearch.Text.ToString().ToUpper() + "%\'";
}
if (CloseTimeSearch.Text.Trim().Length == 0)
{
closeTimesearchString = "UPPER(CLOSETIME)";
}
else
{
closeTimesearchString = "\'%" + CloseTimeSearch.Text.ToString().ToUpper() + "%\'";
}
if (CitrySearch.Text.Trim().Length == 0)
{
citysearchString = "UPPER(CITY)";
}
else
{
citysearchString = "\'%" + CitrySearch.Text.ToString().ToUpper() + "%\'";
}
if (ZipSearch.Text.Trim().Length == 0)
{
zipsearchString = "ZIP";
}
else
{
zipsearchString = "\'%" + ZipSearch.Text.ToString().ToUpper() + "%\'";
}
if (StateSearch.Text.Trim().Length == 0)
{
statesearchString = "UPPER(STATE)";
}
else
{
statesearchString = "\'%" + StateSearch.Text.ToString().ToUpper() + "%\'";
}
if (FoodSearch.Text.Trim().Length == 0)
{
foodsearchString = "UPPER(FOOD.NAME)";
}
else
{
foodsearchString = "\'%" + FoodSearch.Text.ToString().ToUpper() + "%\'";
}
System.Diagnostics.Debug.Write("Here Restaurant " + namesearchString+" " +OpenTimeSearch.ToString().Length);
System.Diagnostics.Debug.Write("Here Cuisine " + CuisineSearch.ToString().Length);
System.Diagnostics.Debug.Write("Here Open time " + openTimesearchString);
System.Diagnostics.Debug.Write("Here Close time " + closeTimesearchString);
System.Diagnostics.Debug.Write("Here City " + citysearchString);
System.Diagnostics.Debug.Write("Here Zip " + zipsearchString);
System.Diagnostics.Debug.Write("Here State " + statesearchString);
System.Diagnostics.Debug.Write("Here Food " + foodsearchString);
StringBuilder ConnectionString = new StringBuilder();
ConnectionString.Append("Provider=").Append(ProjectSettings.dbProvider).Append(";")
.Append(" DATA SOURCE=").Append(ProjectSettings.dbHost).Append(":")
.Append(ProjectSettings.dbPort).Append("/").Append(ProjectSettings.dbSid).Append(";")
.Append("PASSWORD=").Append(ProjectSettings.dbKey).Append(";")
.Append("USER ID=").Append(ProjectSettings.dbUser);
string searchString = "GA";
string cmd = "SELECT NAME, DESCRIPTION, OPENTIME, CLOSETIME,ADDRESS1, ADDRESS2, CITY, STATE, ZIP, RESTAURANTID FROM (SELECT NAME, DESCRIPTION, OPENTIME, CLOSETIME,ADDRESS1, ADDRESS2, CITY, STATE, ZIP, RESTAURANTID FROM " + ProjectSettings.schema + ".RESTAURANT WHERE UPPER(NAME) LIKE " + namesearchString + " AND UPPER(DESCRIPTION) LIKE " + cuisinesearchString + " AND OPENTIME LIKE " + openTimesearchString + " AND CLOSETIME LIKE " + closeTimesearchString + " AND ZIP = " +zipsearchString+ " AND UPPER(CITY) LIKE " + citysearchString + " AND UPPER(STATE) LIKE " + statesearchString + " INTERSECT SELECT DISTINCT " + ProjectSettings.schema + ".RESTAURANT.NAME, DESCRIPTION, OPENTIME, CLOSETIME, ADDRESS1, ADDRESS2, CITY, STATE, ZIP, " + ProjectSettings.schema + ".RESTAURANT.RESTAURANTID FROM " + ProjectSettings.schema + ".RESTAURANT INNER JOIN " + ProjectSettings.schema + ".FDPRICECATALOG ON " + ProjectSettings.schema + ".RESTAURANT.RESTAURANTID = " + ProjectSettings.schema + ".FDPRICECATALOG.RESTAURANTID INNER JOIN " + ProjectSettings.schema + ".FOOD ON " + ProjectSettings.schema + ".FOOD.FOODID = " + ProjectSettings.schema + ".FDPRICECATALOG.FOODID AND UPPER(" + ProjectSettings.schema + ".FOOD.NAME) LIKE " + foodsearchString + ")";
System.Diagnostics.Debug.Write("Here Qery " + cmd);
OleDbConnection conn = new OleDbConnection(ConnectionString.ToString());
conn.Open();
OleDbCommand select_search = new OleDbCommand(cmd, conn);
OleDbDataAdapter oAdapter = new OleDbDataAdapter(select_search);
oAdapter.Fill(tbl);
//RestaurantRepeater.DataSource = oReader;
//RestaurantRepeater.DataBind();
GridView2.DataSource = tbl.Tables[0];
GridView2.DataBind();
GridView2.PagerSettings.Mode = PagerButtons.Numeric;
foreach (GridViewRow gr in GridView2.Rows)
{
HyperLink hp = new HyperLink();
hp.Text = gr.Cells[0].Text;
rName = hp.Text;
rID = gr.Cells[9].Text;
rID = "~/Restaurants.aspx?restaurant=" + rID;
gr.Cells[0].Controls.Add(hp);
}
//System.Diagnostics.Debug.WriteLine("Query is " + cmd);
////GridView1.DataSource = oReader;
////GridView1.DataBind();
//str += @"<table>";
//while (oReader.Read())
//{
// str += @"<tr><td><a href='Restaurants.aspx?restaurant=" + oReader[9].ToString() + "'>" + oReader[0].ToString() + @"</a></td><td>" + oReader[1].ToString() + @"</td> <td>" + oReader[2].ToString() + @"</td> <td>" + oReader[3].ToString() + @"</td> <td>" + oReader[4].ToString() + @"</td> <td>" + oReader[5].ToString() + @"</td> <td>" + oReader[6].ToString() + @"</td> <td>" + oReader[7].ToString() + @"</td> <td>" + oReader[8].ToString() + @"</tr>";
//}
//System.Diagnostics.Debug.WriteLine(str);
//str += "</table>";
conn.Close();
}
//protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
//{
// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// HyperLink hl = (HyperLink)e.Row.FindControl("link");
// if (hl != null)
// {
// hl.NavigateUrl = "~/Restaurants.aspx?"
// }
// }
//}
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
bindGridView("", "");
GridView2.PageIndex = e.NewPageIndex;
}
protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
{
bindGridView(e.SortExpression, sortOrder);
}
public string sortOrder
{
get
{
if (ViewState["sortOrder"].ToString() == "desc")
{
ViewState["sortOrder"] = "asc";
}
else
{
ViewState["sortOrder"] = "desc";
}
return ViewState["sortOrder"].ToString();
}
set
{
ViewState["sortOrder"] = value;
}
}
public void bindGridView(string sortExp, string sortDir)
{
// string searchString = Request.QueryString["SearchString"].ToUpper();
string namesearchString;
string cuisinesearchString;
string openTimesearchString;
string closeTimesearchString;
string citysearchString;
string zipsearchString;
string statesearchString;
string foodsearchString;
//TODO: Check correctness
/*if (!IsPostBack)
{
ViewState["sortOrder"] = "";
bindGridView("", "");
}*/
if (NameSearch.Text.Trim().Length == 0)
{
namesearchString = "UPPER(NAME)";
}
else
{
namesearchString = "\'%" + NameSearch.Text.ToString().ToUpper() + "%\'";
}
if (CuisineSearch.Text.Trim().Length == 0)
{
cuisinesearchString = "UPPER(DESCRIPTION)";
}
else
{
cuisinesearchString = "\'%" + CuisineSearch.Text.ToString().ToUpper() + "%\'";
}
if (OpenTimeSearch.Text.Trim().Length == 0)
{
openTimesearchString = "UPPER(OPENTIME)";
}
else
{
openTimesearchString = "\'%" + OpenTimeSearch.Text.ToString().ToUpper() + "%\'";
}
if (CloseTimeSearch.Text.Trim().Length == 0)
{
closeTimesearchString = "UPPER(CLOSETIME)";
}
else
{
closeTimesearchString = "\'%" + CloseTimeSearch.Text.ToString().ToUpper() + "%\'";
}
if (CitrySearch.Text.Trim().Length == 0)
{
citysearchString = "UPPER(CITY)";
}
else
{
citysearchString = "\'%" + CitrySearch.Text.ToString().ToUpper() + "%\'";
}
if (ZipSearch.Text.Trim().Length == 0)
{
zipsearchString = "ZIP";
}
else
{
zipsearchString = "\'%" + ZipSearch.Text.ToString().ToUpper() + "%\'";
}
if (StateSearch.Text.Trim().Length == 0)
{
statesearchString = "UPPER(STATE)";
}
else
{
statesearchString = "\'%" + StateSearch.Text.ToString().ToUpper() + "%\'";
}
if (FoodSearch.Text.Trim().Length == 0)
{
foodsearchString = "UPPER(FOOD.NAME)";
}
else
{
foodsearchString = "\'%" + FoodSearch.Text.ToString().ToUpper() + "%\'";
}
System.Diagnostics.Debug.Write("Here we " + namesearchString);
StringBuilder ConnectionString = new StringBuilder();
ConnectionString.Append("Provider=").Append(ProjectSettings.dbProvider).Append(";")
.Append(" DATA SOURCE=").Append(ProjectSettings.dbHost).Append(":")
.Append(ProjectSettings.dbPort).Append("/").Append(ProjectSettings.dbSid).Append(";")
.Append("PASSWORD=").Append(ProjectSettings.dbKey).Append(";")
.Append("USER ID=").Append(ProjectSettings.dbUser);
string searchString = "GA";
string cmd = "SELECT NAME, DESCRIPTION, OPENTIME, CLOSETIME,ADDRESS1, ADDRESS2, CITY, STATE, ZIP, RESTAURANTID FROM (SELECT NAME, DESCRIPTION, OPENTIME, CLOSETIME,ADDRESS1, ADDRESS2, CITY, STATE, ZIP, RESTAURANTID FROM " + ProjectSettings.schema + ".RESTAURANT WHERE UPPER(NAME) LIKE " + namesearchString + " AND UPPER(DESCRIPTION) LIKE " + cuisinesearchString + " AND OPENTIME LIKE " + openTimesearchString + " AND CLOSETIME LIKE " + closeTimesearchString + " AND ZIP = " + zipsearchString + " AND UPPER(CITY) LIKE " + citysearchString + " AND UPPER(STATE) LIKE " + statesearchString + " INTERSECT SELECT DISTINCT " + ProjectSettings.schema + ".RESTAURANT.NAME, DESCRIPTION, OPENTIME, CLOSETIME, ADDRESS1, ADDRESS2, CITY, STATE, ZIP, " + ProjectSettings.schema + ".RESTAURANT.RESTAURANTID FROM " + ProjectSettings.schema + ".RESTAURANT INNER JOIN " + ProjectSettings.schema + ".FDPRICECATALOG ON " + ProjectSettings.schema + ".RESTAURANT.RESTAURANTID = " + ProjectSettings.schema + ".FDPRICECATALOG.RESTAURANTID INNER JOIN " + ProjectSettings.schema + ".FOOD ON " + ProjectSettings.schema + ".FOOD.FOODID = " + ProjectSettings.schema + ".FDPRICECATALOG.FOODID AND UPPER(" + ProjectSettings.schema + ".FOOD.NAME) LIKE " + foodsearchString + ")";
OleDbConnection conn = new OleDbConnection(ConnectionString.ToString());
conn.Open();
OleDbCommand select_search = new OleDbCommand(cmd, conn);
OleDbDataAdapter oAdapter = new OleDbDataAdapter(select_search);
oAdapter.Fill(tbl);
DataView myDataView = new DataView();
myDataView = tbl.Tables[0].DefaultView;
if (sortExp != string.Empty)
{
myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
}
GridView2.DataSource = myDataView;
GridView2.DataBind();
conn.Close();
}
}