-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSales.aspx.cs
180 lines (158 loc) · 7.07 KB
/
Sales.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FoodPantry
{
public partial class Sales : System.Web.UI.Page
{
static string connectionString = 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");
}
}
[WebMethod]
public static string GetAllReceipts()
{
try
{
DBConnect objDB = new DBConnect(connectionString);
SqlCommand objCommand = new SqlCommand();
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.CommandText = "GetAllReceipts";
DataSet ds = objDB.GetDataSetUsingCmdObj(objCommand);
ArrayList receiptList = new ArrayList();
int count = 0;
foreach (DataRow row in ds.Tables[0].Rows)
{
count++;
}
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < count; i++)
{
string order_Number = objDB.GetField("ReceiptID", i).ToString();
int personID = Convert.ToInt32(objDB.GetField("PersonID", i));
string FirstName = objDB.GetField("FirstName", i).ToString();
string LastName = objDB.GetField("LastName", i).ToString();
string checkoutDate = objDB.GetField("CheckoutDate", i).ToString();
string lastUpdateDate = objDB.GetField("LastUpdateDate", i).ToString();
int point = Convert.ToInt32(objDB.GetField("TotalPoints", i).ToString());
int totQty = Convert.ToInt32(objDB.GetField("TotalQuantity", i).ToString());
string lastUpdateUser = objDB.GetField("LastUpdateUser", i).ToString();
DateTime date = DateTime.Parse(checkoutDate);
Receipt1 receipt = new Receipt1();
receipt.CheckoutDate = date.ToLongDateString();
receipt.ReceiptID = order_Number;
receipt.PersonID = personID;
receipt.TotalPoints = point;
receipt.TotalQuantity = totQty;
receipt.LastUpdateDate = lastUpdateDate;
receipt.LastUpdateUser = lastUpdateUser;
receipt.FirstName = FirstName;
receipt.LastName = LastName;
receiptList.Add(receipt);
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
for (int i = 0; i < receiptList.Count; i++)
{
}
string jsonObj = js.Serialize(receiptList);
return jsonObj;
}
catch (Exception ex)
{
ArrayList receiptList = new ArrayList();
Receipt1 receipt = new Receipt1();
receipt.CheckoutDate = DateTime.Now.ToString();
receipt.ReceiptID = "0";
receipt.PersonID = 0;
receipt.TotalPoints = 0;
receipt.TotalQuantity = 0;
receipt.LastUpdateDate = "test";
receipt.LastUpdateUser = HttpContext.Current.Session["Access_Net"].ToString();
receipt.FirstName = "Exception";
receipt.LastName = "Exception";
receiptList.Add(receipt);
JavaScriptSerializer js = new JavaScriptSerializer();
string jsonObj = js.Serialize(receiptList);
return jsonObj;
}
}
public static string GetCategory(string upc)
{
DBConnect objDB = new DBConnect(connectionString);
SqlCommand objCommand = new SqlCommand();
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.CommandText = "GetUpcCategory";
objCommand.Parameters.AddWithValue("@upc", upc);
SqlParameter returnParameter = new SqlParameter("@category", SqlDbType.VarChar);
returnParameter.Direction = ParameterDirection.ReturnValue;
objCommand.Parameters.Add(returnParameter);
DataSet ds = objDB.GetDataSetUsingCmdObj(objCommand);
string category = objCommand.Parameters["@category"].Value.ToString();
return category;
}
[WebMethod]
public static string GetReceipt(string orderNumber)
{
try
{
DBConnect objDB = new DBConnect(connectionString);
SqlCommand objCommand = new SqlCommand();
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.CommandText = "GetUpcForOrder";
objCommand.Parameters.AddWithValue("@ReceiptID", orderNumber);
DataSet ds = objDB.GetDataSetUsingCmdObj(objCommand);
Item s = new Item();
int count = 0;
ArrayList myItemList = new ArrayList();
string SwalText = " <style> table,th,td {border:1px solid black;} </style> <table> <caption align='top'> Order Details </caption> <tr> <th> Category </th> <th> UPC </th> </tr>";
foreach (DataRow row in ds.Tables[0].Rows)
{
count++;
}
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < count; i++)
{
Item myItem = new Item();
myItem.Category = objDB.GetField("Type", i).ToString();
myItem.Packaging = objDB.GetField("Packaging", i).ToString();
myItem.Quantity = Convert.ToInt32(objDB.GetField("Quantity", i));
myItem.Point = Convert.ToInt32(objDB.GetField("Point", i));
myItem.CategoryID = Convert.ToInt32(objDB.GetField("CategoryID", i));
myItemList.Add(myItem);
}
}
SwalText += "</table";
JavaScriptSerializer jss = new JavaScriptSerializer();
string output = jss.Serialize(myItemList);
return output;
}
catch (Exception ex)
{
return "ex: " + ex.ToString();
}
}
}
}