-
Notifications
You must be signed in to change notification settings - Fork 0
/
Employee.xaml.cs
309 lines (281 loc) · 11.5 KB
/
Employee.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace JBWally
{
/// <summary>
/// Interaction logic for Employee.xaml
/// </summary>
public partial class Employee : Page
{
public Employee()
{
InitializeComponent();
//ShowOrderInfo();
FillBranchCombo();
orderDetails.IsEnabled = false;
}
List<string> customerHistory = new List<string>();
List<string> custHist = new List<string>();
//private void RefundShow_Click(object sender, RoutedEventArgs e)
//{
// refundButton.IsEnabled = true;
// const int refundRequest = -1;
// if (employeeBox.Items.Count != 0)
// {
// employeeBox.Items.Clear();
// }
// ShowOrderInfo(refundRequest);
//}
//private void ShowOrderInfo(int status = -1)
//{
// if (employeeBox.Items.Count != 0)
// {
// employeeBox.Items.Clear();
// }
// customerHistory = Database.ShowData(status)[0];
// custHist = Database.ShowData(status)[1];
// foreach (string s in customerHistory)
// {
// employeeBox.Items.Add(s);
// }
//}
/// <summary>
/// Refunds the order
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RefundButton_Click(object sender, RoutedEventArgs e)
{
AllInfo.Text = "";
int i = 0;
int index = employeeBox.SelectedIndex;
string productName = "";
string branchName = "";
int qty = 0;
int OrderID = 0;
if (employeeBox.SelectedIndex >= 0)
{
//Extract all the values and refund the selected order
foreach (string s in custHist)
{
int pFrom = s.IndexOf("ProductName:") + "ProductName:".Length;
int pTo = s.IndexOf(" BranchName:");
productName = s.Substring(pFrom, pTo - pFrom).Trim();
pFrom = s.IndexOf(" BranchName:") + " BranchName:".Length;
pTo = s.IndexOf("Quantity:");
branchName = s.Substring(pFrom, pTo - pFrom).Trim();
pFrom = s.IndexOf("Quantity:") + "Quantity:".Length;
pTo = s.IndexOf("OrderID:");
qty = Convert.ToInt32(s.Substring(pFrom, pTo - pFrom).Trim());
pFrom = s.IndexOf("OrderID:") + "OrderID:".Length;
pTo = s.IndexOf("\n");
OrderID = Convert.ToInt32(s.Substring(pFrom, pTo - pFrom).Trim());
if (i == index)
{
break;
}
i++;
}
Orders.RefundOrder(OrderID, qty, branchName, productName);
employeeBox.Items.Clear();
ShowInfo();
}
}
//private void RefundedOrders_Click(object sender, RoutedEventArgs e)
//{
// refundButton.IsEnabled = false;
// const int refundedOrderStatus = 0;
// if (employeeBox.Items.Count != 0)
// {
// employeeBox.Items.Clear();
// }
// ShowOrderInfo(refundedOrderStatus);
//}
/// <summary>
/// Go to order page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LogOut_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("Order.xaml", UriKind.RelativeOrAbsolute));
}
private void FillBranchCombo()
{
//fill up the branch
List<string> branch = Database.FillBranchCombo();
foreach (string s in branch)
{
Branches.Items.Add(s);
}
}
/// <summary>
/// Shows the inventory for the selected branch in the listbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Inventory_Click(object sender, RoutedEventArgs e)
{
AllInfo.Text = "";
//clear list box
employeeBox.Items.Clear();
List<string> BranchInventory = new List<string>();
//disable button
refundButton.IsEnabled = false;
//chekc which item is selected and show the details for that item
if (Branches.SelectedItem != null)
{
string branchName = Branches.SelectedItem.ToString();
int bID = Database.GetBranchID(branchName);
BranchInventory = Database.DisplayInventory(bID);
AllInfo.Text = "Branch Name: " + branchName + "\nBranch ID: " + bID.ToString();
foreach (string s in BranchInventory)
{
employeeBox.Items.Add(s);
}
}
else
{
MessageBox.Show("Please Select a Branch First");
}
}
/// <summary>
/// Gets the order details
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click(object sender, RoutedEventArgs e)
{
AllInfo.Text = "";
Orders.previousOrder = true;
int index = employeeBox.SelectedIndex;
string details = "";
int i = 0;
//Extract all the values from the selected order and show the details of the selected order in sales record page
if (employeeBox.SelectedIndex >= 0)
{
foreach (string s in custHist)
{
string status = "";
int pFrom = s.IndexOf("OrderID:") + "OrderID:".Length;
int pTo = s.IndexOf("\n");
details = "OrderID: " + s.Substring(pFrom, pTo - pFrom).Trim() + "\n";
pFrom = s.IndexOf("ProductName: ") + "ProductName: ".Length;
pTo = s.IndexOf("BranchName:");
details = details + " Product Name:" + s.Substring(pFrom, pTo - pFrom).Trim() + "\n";
pFrom = s.IndexOf("BranchName:") + "BranchName:".Length;
pTo = s.IndexOf("Quantity:");
details = details + " Purchased From: " + s.Substring(pFrom, pTo - pFrom).Trim() + "\n";
pFrom = s.IndexOf("Quantity:") + "Quantity:".Length;
pTo = s.IndexOf("OrderID:");
details = details + " Quantity: " + s.Substring(pFrom, pTo - pFrom).Trim() + "\n";
pFrom = s.IndexOf("OrderStatus:") + "OrderStatus:".Length;
pTo = s.IndexOf("Done");
int OrderStatus = Convert.ToInt32(s.Substring(pFrom, pTo - pFrom).Trim());
if (OrderStatus == 0)
status = "refunded";
else if (OrderStatus == 1)
status = "Paid";
else
status = "Refund Requested";
details = details + " Order Status: " + status + "\nPurchased By: " + Database.firstName + " " + Database.lastName + "\n";
pFrom = s.IndexOf(" Order Date: ") + " Order Date: ".Length;
pTo = s.IndexOf("date");
details = details + " Date: " + s.Substring(pFrom, pTo - pFrom).Trim() + "\n";
if (i == index)
{
break;
}
i++;
}
Orders.OrderDesc = details;
Orders.orderPage = false;
NavigationService.Navigate(new Uri("SalesRecord.xaml", UriKind.RelativeOrAbsolute));
}
else
{
MessageBox.Show("Please select an order first!");
}
}
/// <summary>
/// Searches the customer and shows the orders of the customer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SearchButton_Click_1(object sender, RoutedEventArgs e)
{
employeeBox.Items.Clear();
string str = "";
str = search.Text.Trim();
string[] sr = { };
bool valid = false;
try
{
sr = str.Split(' ');
string firstName = sr[0].Trim();
string lastName = sr[1].Trim();
//check if customer exists
valid = Database.CheckCustomer(firstName.ToLower(), lastName.ToLower());
//if exists then show all the orders of the customer in the listbox else show error message
if (valid == true)
{
customerHistory = Database.CustomerOrderHistory(firstName + " " + lastName)[0];
custHist = Database.CustomerOrderHistory(firstName + " " + lastName)[1];
foreach (string s in customerHistory)
{
employeeBox.Items.Add(s);
}
int cID = Database.GetCustomerID(firstName, lastName);
AllInfo.Text = "Customer Name: " + firstName + " " + lastName + "\nCustomer ID: " + cID.ToString();
Database.firstName = firstName;
Database.lastName = lastName;
refundButton.IsEnabled = true;
orderDetails.IsEnabled = true;
}
else
{
MessageBox.Show(firstName + " " + lastName + " is not enrolled.");
}
}
catch (Exception)
{
MessageBox.Show("Full Name is Required");
}
}
/// <summary>
/// This method changes the text over the list box to show the searched customer's name and id
/// </summary>
public void ShowInfo()
{
string name = Database.firstName + " " + Database.lastName;
customerHistory = Database.CustomerOrderHistory(name)[0];
custHist = Database.CustomerOrderHistory(name)[1];
foreach (string s in customerHistory)
{
employeeBox.Items.Add(s);
}
int cID = Database.GetCustomerID(Database.firstName, Database.lastName);
AllInfo.Text = "Customer Name: " + name + "\nCustomer ID: " + cID.ToString();
}
private void Branches_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
orderDetails.IsEnabled = false; //disable orderdetails button when branch selection is changed
}
private void Enroll_Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("Enroll.xaml", UriKind.RelativeOrAbsolute));
}
}
}