-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckinScan.aspx.cs
223 lines (179 loc) · 7.22 KB
/
CheckinScan.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
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Collections;
using System.Collections.Generic;
namespace FoodPantry
{
public partial class CheckinScan : System.Web.UI.Page
{
static string connectionStr = ConfigurationManager.ConnectionStrings["appString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Authenticated"].ToString() == "False")
{
Response.Redirect("Default.aspx");
}
}
catch(Exception ex)
{
Response.Redirect("Default.aspx");
}
Session["cart"] = null;
}
[WebMethod]
public static string Checkin(string ItemCount, List<CheckoutItem> itemList)
{
Cart cart;
int cartID;
DBConnect objDB = new DBConnect(connectionStr);
try
{
JavaScriptSerializer js = new JavaScriptSerializer();
var items = itemList;
cart = (Cart)HttpContext.Current.Session["cart"];
if (items.Count == 0 || cart == null)
{
return "No Items";
}
foreach (CheckoutItem item in items)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UpdateItemCheckin";
cmd.Parameters.AddWithValue("@CategoryID", item.CategoryID);
cmd.Parameters.AddWithValue("@Quantity", Convert.ToInt32(item.Quantity));
cmd.Parameters.AddWithValue("@lastUpdateUser", HttpContext.Current.Session["Access_Net"].ToString());
cmd.Parameters.AddWithValue("@lastUpdateDate", DateTime.Now);
objDB.DoUpdateUsingCmdObj(cmd);
}
cart = new Cart();
HttpContext.Current.Session["cart"] = cart;
return "added";
}
catch (Exception ex)
{
cart = new Cart();
HttpContext.Current.Session["cart"] = cart;
return "error";
}
}
[WebMethod]
public static string getCategoryId(string type, string packaging)
{
try
{
ArrayList ids = new ArrayList();
DBConnect objDB = new DBConnect(connectionStr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetCategoryId";
cmd.Parameters.AddWithValue("@type", type);
cmd.Parameters.AddWithValue("@packaging", packaging);
DataSet ds = objDB.GetDataSetUsingCmdObj(cmd);
if(ds.Tables[0].Rows.Count == 0)
{
try
{
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "AddCategory";
cmd.Parameters.AddWithValue("@Type", type);
cmd.Parameters.AddWithValue("@Packaging", packaging);
cmd.Parameters.AddWithValue("@LastUpdateUser", HttpContext.Current.Session["Access_Net"].ToString());
cmd.Parameters.AddWithValue("@LastUpdateDate", DateTime.Now);
cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;
int status = objDB.DoUpdateUsingCmdObj(cmd);
string ID = cmd.Parameters["@ID"].Value.ToString();
if (status != -1)
ids.Add(ID);
else
return status.ToString();
}
catch (Exception ex)
{
return "Error" + ex.Message;
}
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
ids.Add(dr["Id"].ToString());
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(ids[0]);
}
catch (Exception ex)
{
return "error: " + ex.Message;
}
}
[WebMethod]
public static string getPackagesList()
{
try
{
ArrayList packages = new ArrayList();
DBConnect objDB = new DBConnect(connectionStr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "getPackages";
DataSet ds = objDB.GetDataSetUsingCmdObj(cmd);
foreach (DataRow dr in ds.Tables[0].Rows)
{
packages.Add(dr[0].ToString());
}
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
return javaScriptSerializer.Serialize(packages);
}
catch (Exception ex)
{
ArrayList categories = new ArrayList();
categories.Add(new Category("1", "Fruit", "Single"));
categories.Add(new Category("2", "Meat", "Multiple"));
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
return javaScriptSerializer.Serialize(categories);
}
}
[WebMethod]
public static string getCategoryList()
{
try
{
ArrayList packages = new ArrayList();
DBConnect objDB = new DBConnect(connectionStr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetCategories";
DataSet ds = objDB.GetDataSetUsingCmdObj(cmd);
foreach (DataRow dr in ds.Tables[0].Rows)
{
packages.Add(dr["Type"].ToString());
}
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
return javaScriptSerializer.Serialize(packages);
}
catch (Exception ex)
{
ArrayList categories = new ArrayList();
categories.Add(new Category("1", "Fruit", "Single"));
categories.Add(new Category("2", "Meat", "Multiple"));
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
return javaScriptSerializer.Serialize(categories);
}
}
private static string CheckInventory(string upc)
{
throw new NotImplementedException();
}
}
}