/
Search.aspx.cs
171 lines (164 loc) · 7.16 KB
/
Search.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RecipeDatabaseModel;
public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from p in rdbEnty.recipes
select p);
IEnumerable<recipe> recipeList = query.ToList();
foreach (var recipe1 in recipeList)
{
ddRecipeName.Items.Add(new ListItem(recipe1.name, recipe1.id.ToString()));
ddRecipeCreator.Items.Add(new ListItem(recipe1.submitted_by, recipe1.id.ToString()));
}
var query1 = (from i1 in rdbEnty.ingredients
select i1);
IEnumerable<ingredient> incList = query1.ToList();
foreach (var inc1 in incList)
{
ddInc.Items.Add(new ListItem(inc1.name, inc1.id.ToString()));
}
}
}
protected void Page_PreInit(object sender, EventArgs e)
{
}
protected void BtnSearch_Click(object sender, EventArgs e)
{
int IncVal = Convert.ToInt32(ddInc.SelectedValue);
int RecVal = Convert.ToInt32(ddRecipeName.SelectedValue);
if (IncVal > 0 && RecVal > 0 && ddRecipeCreator.SelectedItem.Text != "All")
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from p in rdbEnty.recipes
from ri in rdbEnty.recipe_ingredients
join i in rdbEnty.ingredients on ri.ingredient_id equals i.id
where p.id == RecVal && i.id == IncVal && p.submitted_by == ddRecipeCreator.SelectedItem.Text
select p);
IEnumerable<recipe> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int ii;
ii = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
ii++;
}
searchedItemsCount.InnerHtml = (ii).ToString();
searchedItems.InnerHtml = htmlElts;
}
else if (IncVal > 0 && RecVal > 0 && ddRecipeCreator.SelectedItem.Text == "All")
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from p in rdbEnty.recipes from ri in rdbEnty.recipe_ingredients join i in rdbEnty.ingredients on ri.ingredient_id equals i.id where p.id == RecVal && i.id == IncVal select p);
IEnumerable<recipe> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int ii;
ii = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
ii++;
}
searchedItemsCount.InnerHtml = (ii).ToString();
searchedItems.InnerHtml = htmlElts;
}
else if (IncVal == 0 && RecVal > 0 && ddRecipeCreator.SelectedItem.Text != "All")
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from p in rdbEnty.recipes where p.id == RecVal && p.submitted_by == ddRecipeCreator.SelectedItem.Text select p);
IEnumerable<recipe> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int ii;
ii = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
ii++;
}
searchedItemsCount.InnerHtml = (ii).ToString();
searchedItems.InnerHtml = htmlElts;
}
else if (IncVal == 0 && RecVal > 0 && ddRecipeCreator.SelectedItem.Text == "All")
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from p in rdbEnty.recipes where p.id == RecVal select p);
IEnumerable<recipe> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int ii;
ii = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
ii++;
}
searchedItemsCount.InnerHtml = (ii).ToString();
searchedItems.InnerHtml = htmlElts;
}
else if (IncVal > 0 && RecVal == 0 && ddRecipeCreator.SelectedItem.Text == "All")
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from i in rdbEnty.ingredients where i.name == ddInc.SelectedItem.Text select i);
IEnumerable<ingredient> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int ii;
ii = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
ii++;
}
searchedItemsCount.InnerHtml = (ii).ToString();
searchedItems.InnerHtml = htmlElts;
}
else if (IncVal == 0 && RecVal == 0 && ddRecipeCreator.SelectedItem.Text != "All")
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from r in rdbEnty.recipes where r.submitted_by == ddRecipeCreator.SelectedItem.Text select r);
IEnumerable<recipe> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int ii;
ii = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
ii++;
}
searchedItemsCount.InnerHtml = (ii).ToString();
searchedItems.InnerHtml = htmlElts;
}
else
{
RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
var query = (from p in rdbEnty.recipes
select p);
IEnumerable<recipe> recipeList = query.ToList();
string htmlElts;
htmlElts = "";
int i;
i = 0;
foreach (var recipe1 in recipeList)
{
htmlElts = htmlElts + "<p class='item'><a href='RecipeDetails.aspx?recipe=" + recipe1.id.ToString() + "'>" + recipe1.name + "</a></p>";
i++;
}
searchedItemsCount.InnerHtml = (i - 1).ToString();
searchedItems.InnerHtml = htmlElts;
}
}
}