-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddFoodItem.aspx.cs
106 lines (88 loc) · 3.97 KB
/
AddFoodItem.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace FoodFest
{
public partial class AddFoodItem : System.Web.UI.Page
{
DBConnect resConn = new DBConnect();
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;
}
//DropDownList1.Items.Insert(0, new ListItem("-- choose one--", "0"));
}
protected void AddFoodButton_Click(object sender, EventArgs e)
{
string message = "";
bool exist = false;
try
{
resConn.SqlConnectionObj.Open();
string query = String.Format("Select FoodName,RestaurantId from Food_tbl");
resConn.SqlCommandObj.CommandText = query;
SqlDataReader reader = resConn.SqlCommandObj.ExecuteReader();
while (reader.Read())
{
if (reader.GetString(0) == FoodNameTextBox.Text.ToString() && reader.GetInt32(1)==Convert.ToInt32(DropDownList1.SelectedValue))
{
exist = true;
break;
}
else
exist = false;
}
resConn.SqlConnectionObj.Close();
if (exist == false)
{
//file upload
//string logoStr = LogoFileUpload.FileName;
//LogoFileUpload.PostedFile.SaveAs(@"D:\Project\1Mourin\With_Admin_Page_290414\FoodFest\FoodFest\UploadedLogos\" + logoStr);
//logoPathStr = @"D:\Project\1Mourin\With_Admin_Page_290414\FoodFest\FoodFest\UploadedLogos\" + logoStr.ToString();
//resConn.SqlConnectionObj.Open();
//string query2 = String.Format("INSERT INTO Food_tbl(FoodName,FoodPrice,FoodType,RestaurantId) VALUES('{0}','{1}','{2}','{3}')", FoodNameTextBox.Text, FoodPriceTextBox.Text, FoodTypeTextBox.Text,DropDownList1.SelectedValue);
//resConn.SqlCommandObj.CommandText = query2;
//resConn.SqlCommandObj.ExecuteNonQuery();
SqlDataSource2.Insert();
message = "New Food Item added successfully";
foodMsgLabel.Text = message;
}
else
foodMsgLabel.Text = "Food item already exists in this restaurant.";
}
catch (Exception ex)
{
throw new Exception("Error occurred during user save operation. Try again", ex);
}
finally
{
if (resConn.SqlConnectionObj != null && resConn.SqlConnectionObj.State == ConnectionState.Open)
{
resConn.SqlConnectionObj.Close();
}
FoodNameTextBox.Text = "";
FoodPriceTextBox.Text = "";
}
}
}
}