-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.cs
693 lines (592 loc) · 29.6 KB
/
Database.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*FILE : Database.cs
* Project:JBWally
* Programmer: Jayson Ovishek Biswas
* Description: This file contains the Database class. This Database class basically does all the communications between the application
* and the JBWally database
* First Version: 06-12-2019
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using MySql.Data.MySqlClient;
namespace JBWally
{
/*
* Class Name: Database
* Description: This class handles all the scenarios that involves the database. This class can update, delete and retrieve information
* from the JBWally database.
*/
class Database
{
public static String firstName { get; set; }
public static String lastName { get; set; }
public static String phoneNo { get; set; }
public List<string> customerOrder = new List<string>();
/// <summary>
/// checks if the customer exists or not
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <returns>Returns true if customer exists, false otherwise</returns>
public static bool CheckCustomer(String firstName, String lastName)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" USE JBWally;
SELECT FirstName,LastName FROM Customers;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
MySqlDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
{
//check if the customer exists (case insensitive)
if ((reader[0].ToString().ToLower().Trim() == firstName) && (reader[1].ToString().ToLower().Trim() == lastName))
{
return true;
}
}
}
myConn.Close();
}
return false;
}
/// <summary>
/// Enrolls a new customer with first name last name and phone number
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <param name="PhoneNo"></param>
public static void EnrollCustomer(String firstName, String lastName, String PhoneNo)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" USE JBWally;
Insert Into Customers (FirstName,LastName,PhoneNumber)
values (@fName, @lName, @pNumber);";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myCommand.Parameters.AddWithValue("@fName", firstName);
myCommand.Parameters.AddWithValue("@lName", lastName);
myCommand.Parameters.AddWithValue("@pNumber", PhoneNo);
myConn.Open();
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
return;
}
/// <summary>
/// This method fills up any combo box with the name of the branches retrieved from Branch table
/// </summary>
/// <returns>A list of string containing the name of branches</returns>
public static List<string> FillBranchCombo()
{
List<string> branch = new List<string>();
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @"Select BranchName from Branch;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
MySqlDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
{
string branchName = reader.GetString(0);
branch.Add(branchName);
}
}
myConn.Close();
}
return branch;
}
/// <summary>
/// This method fills up any combo box with the name of the products retrieved from Product table
/// </summary>
/// <returns>A list of string containing the name of products</returns>
public static List<string> FillProductCombo()
{
List<string> products = new List<string>();
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @"Select ProductName from Product;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
MySqlDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
{
string productName = reader.GetString(0);
products.Add(productName);
}
}
myConn.Close();
}
return products;
}
/// <summary>
/// This method retrives the branch ID for a particular branch using the branch name from the Branch table
/// </summary>
/// <param name="branchName"></param>
/// <returns>The branch ID is returned as Int32</returns>
public static Int32 GetBranchID(string branchName)
{
string bID;
Int32 branchID = 0;
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" SELECT BranchID FROM Branch Where BranchName = @bName;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@bName", branchName);
bID = myCommand.ExecuteScalar().ToString();
branchID = Convert.ToInt32(bID);
}
myConn.Close();
}
return branchID;
}
/// <summary>
/// This method retrives the product ID for a particular product using the product name from the Product table
/// </summary>
/// <param name="productName"></param>
/// <returns>The product ID is returned as Int32</returns>
public static Int32 GetProductID(string productName)
{
Int32 bID = 0;
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" SELECT SKU FROM Product Where ProductName = @pName;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@pName", productName);
bID = (Int32)myCommand.ExecuteScalar();
}
myConn.Close();
}
return bID;
}
/// <summary>
/// This method retrieves the available quantity of a product in a particular branch from BranchProduct table
/// using the branchID and productID
/// </summary>
/// <param name="branchID"></param>
/// <param name="productID"></param>
/// <returns>Returns the available Quantity</returns>
public static int GetQuantity(int branchID, int productID)
{
Int32 BranchID = 0;
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" SELECT Quantity FROM BranchProduct Where ProductID = @pID and BranchID = @bID;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@pID", productID);
myCommand.Parameters.AddWithValue("@bID", branchID);
BranchID = (Int32)myCommand.ExecuteScalar();
}
myConn.Close();
}
return BranchID;
}
/// <summary>
/// This method retrieves the wholesale price of a product from the Product table
/// </summary>
/// <param name="productID"></param>
/// <returns>The wholesale price is returned as float</returns>
public static float RetrieveWPrice(int productID)
{
float wprice = 0;
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" SELECT wprice from Product where SKU = @prodID;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@prodID", productID);
wprice = (float)myCommand.ExecuteScalar();
}
myConn.Close();
}
return wprice;
}
/// <summary>
/// This method works as a part of an order process. It changes the 'Orders' table. This method inesrts an entry in the 'Orders' for
/// a requested order. A new entry of CustomerID,OrderDate,OrderStatus,BranchID and BranchName is inserted into the table. OrderID is
/// set automatically as it is set to auto_increment
/// </summary>
/// <param name="orderStatus"></param>
/// <param name="branchName"></param>
public static void ChangeOrderTable(int orderStatus, string branchName)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" INSERT INTO Orders(CustomerID,OrderDate,OrderStatus,BranchID,BranchName)
VALUES((select CustomerID from Customers where FirstName=@fName and LastName=@lName),
curdate(),@status,(select BranchID from Branch where BranchName = @bName),@bName);";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@fName", firstName);
myCommand.Parameters.AddWithValue("@lName", lastName);
myCommand.Parameters.AddWithValue("@status", orderStatus);
myCommand.Parameters.AddWithValue("@bName", branchName);
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
}
/// <summary>
/// This method changes the OrderLine table while processing an order. A new entry for OrderID, ProductID,ProductName,sPrice,Quantity
/// and TotalPrice is inserted into the table.
/// </summary>
/// <param name="productName"></param>
/// <param name="quantity"></param>
/// <param name="totalPrice"></param>
public static void ChangeOrderLineTable(string productName, int quantity, float totalPrice)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @"INSERT INTO OrderLine(OrderID,ProductID,ProductName,sPrice,Quantity,TotalPrice)
VALUES((select OrderID from Orders ORDER BY OrderID DESC LIMIT 1),(Select SKU from Product where ProductName = @pName),
@pName,(Select wPrice from Product where ProductName = @pName)*1.4,@qty,@tPrice);";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@pName", productName);
myCommand.Parameters.AddWithValue("@qty", quantity);
myCommand.Parameters.AddWithValue("@tPrice", totalPrice);
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
}
/// <summary>
/// This method changes the BranchProduct table while processing an order. This method is called when the quantity of a product in a
/// particular branch changes. This method updates the quantity.
/// </summary>
/// <param name="allowedQty"></param>
/// <param name="quantity"></param>
/// <param name="branchID"></param>
/// <param name="productID"></param>
public static void UpdateBranchQuantity(int allowedQty, int quantity, int branchID, int productID)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" Update BranchProduct
Set Quantity=(@qty-@quan) where BranchID = @bID and ProductID=@pID; ";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@qty", allowedQty);
myCommand.Parameters.AddWithValue("@quan", quantity);
myCommand.Parameters.AddWithValue("@bID", branchID);
myCommand.Parameters.AddWithValue("@pID", productID);
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
}
/// <summary>
/// Updates the total quantity in the products table while ordering
/// </summary>
/// <param name="productID"></param>
/// <param name="quantity"></param>
public static void UpdateBranchProductQuantity(int productID, int quantity)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" Update Product
Set Stock=Stock-@qty where SKU=@pID;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@qty", quantity);
myCommand.Parameters.AddWithValue("@pID", productID);
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
}
/// <summary>
/// ProductName,Quantity,TotalPrice,Branch.BranchName,Concat(Customers.FirstName,' ',Customers.LastName)as CustomerName,Orders.OrderDate, Orders.OrderID,Orders.OrderStatus
/// is used to create a view that is used to retrieve information for refunding
/// </summary>
public static void CreateRefundView()
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" create or replace view custOrderInfo
as
Select ProductName,Quantity,TotalPrice,Branch.BranchName,Concat(Customers.FirstName,' ',Customers.LastName)as CustomerName,Orders.OrderDate, Orders.OrderID,Orders.OrderStatus
from Orderline
Inner join Orders on Orders.OrderID = OrderLine.OrderID
Inner join Branch on Orders.BranchID = Branch.BranchID
Inner join Customers on Orders.CustomerID = Customers.CustomerID
Order by OrderID; ";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
}
/// <summary>
/// Retrieves all the order details of a customer.
/// </summary>
/// <param name="name"></param>
/// <returns>List of string containing order details</returns>
public static List<string>[] CustomerOrderHistory(string name)
{
CreateRefundView();
List<string> customerHistory = new List<string>();
List<string> custHist = new List<string>();
List<string>[] s = new List<string>[2];
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @"SELECT ProductName,BranchName,Quantity,TotalPrice,OrderID,OrderDate,OrderStatus from custOrderInfo where CustomerName=@custName;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@custName", name);
MySqlDataReader reader = myCommand.ExecuteReader();
string status = "";
while (reader.Read())
{
if (Convert.ToInt32(reader[6].ToString().Trim()) == 0)
{
status = "Refunded";
}
else if (Convert.ToInt32(reader[6].ToString().Trim()) == 1)
{
status = "Paid";
}
else
{
status = "Refund Requested";
}
string orderHistory = reader[0].ToString() + "\n" + "Purchased From " +
reader[1].ToString() + "\nQuantity: " + reader[2].ToString() +
"\t\t\t\t\tPrice: " + reader[3].ToString() + "\nOrderID: " + reader[4].ToString() +
"\nOrder Date: " + reader[5].ToString() + "\t\tOrderStatus: " + status.ToString();
customerHistory.Add(orderHistory);
orderHistory = "ProductName: " + reader[0].ToString() + " BranchName: " + reader[1].ToString() + "Quantity: " + reader[2].ToString() + " OrderID: " + reader[4].ToString() + "\n" + "OrderStatus: " + reader[6].ToString() + "Done" + " Order Date: " + reader[5].ToString() + "date";
custHist.Add(orderHistory);
}
s[0] = customerHistory;
s[1] = custHist;
}
myConn.Close();
}
return s;
}
/// <summary>
/// Updates OrderLine, Orders, BranchProduct and Product table to refund
/// </summary>
/// <param name="orderID"></param>
/// <param name="quantity"></param>
/// <param name="branchID"></param>
/// <param name="productID"></param>
public static void Refund(int orderID, int quantity, int branchID, int productID)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" Update OrderLine Set Quantity=0 where OrderID=@oID;
Update OrderLine Set TotalPrice=0 where OrderID=@oID;
Update Orders Set OrderStatus=0 where OrderID=@oID;
Update BranchProduct Set Quantity=Quantity+@qty where BranchID=@bID and ProductID=@pID;
Update Product Set Stock=Stock+@qty where SKU=@pID; ";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@oID", orderID);
myCommand.Parameters.AddWithValue("@qty", quantity);
myCommand.Parameters.AddWithValue("@bID", branchID);
myCommand.Parameters.AddWithValue("@pID", productID);
myCommand.ExecuteNonQuery();
}
myConn.Close();
}
}
/// <summary>
/// Gets the Customer ID
/// </summary>
/// <param name="fName"></param>
/// <param name="lName"></param>
/// <returns></returns>
public static Int32 GetCustomerID(string fName, string lName)
{
string cID = "";
int custID = 0;
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" SELECT CustomerID FROM Customers Where FirstName = @fName and LastName=@lName;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@fName", fName);
myCommand.Parameters.AddWithValue("@lName", lName);
cID = myCommand.ExecuteScalar().ToString();
custID = Convert.ToInt32(cID);
}
myConn.Close();
}
return custID;
}
/// <summary>
/// Shows all the information about an order according to the order status
/// </summary>
/// <param name="OrderStatus"></param>
/// <returns>Returns 2 lists of String in an array containing the information</returns>
public static List<string>[] ShowData(int OrderStatus)
{
CreateRefundView();
List<string> customerHistory = new List<string>();
List<string> custHist = new List<string>();
List<string>[] s = new List<string>[2];
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @"SELECT ProductName,BranchName,Quantity,TotalPrice,OrderID,OrderDate,OrderStatus from custOrderInfo where OrderStatus=@oStatus;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@oStatus", OrderStatus);
MySqlDataReader reader = myCommand.ExecuteReader();
string status = "";
while (reader.Read())
{
if (Convert.ToInt32(reader[6].ToString().Trim()) == 0)
{
status = "Refunded";
}
else if (Convert.ToInt32(reader[6].ToString().Trim()) == 1)
{
status = "Paid";
}
else
{
status = "Refund Requested";
}
string orderHistory = reader[0].ToString() + "\n" + "Purchased From " +
reader[1].ToString() + "\nQuantity: " + reader[2].ToString() +
"\t\t\t\t\tPrice: " + reader[3].ToString() + "\nOrderID: " + reader[4].ToString() +
"\nOrder Date: " + reader[5].ToString() + "\t\tOrderStatus: " + status.ToString();
customerHistory.Add(orderHistory);
orderHistory = "ProductName: " + reader[0].ToString() + " BranchName: " + reader[1].ToString() + "Quantity: " + reader[2].ToString() + " OrderID: " + reader[4].ToString() + "\n";
custHist.Add(orderHistory);
}
s[0] = customerHistory;
s[1] = custHist;
}
myConn.Close();
}
return s;
}
/// <summary>
/// Retrieves the inventory for a particular branch
/// </summary>
/// <param name="branchID"></param>
/// <returns></returns>
public static List<string> DisplayInventory(int branchID)
{
List<string> BranchInventory = new List<string>();
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @"select ProductID, Quantity,Product.ProductName from BranchProduct
inner join Product on BranchProduct.ProductID = Product.SKU
where BranchID = @bID;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@bID", branchID);
MySqlDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
{
string branchInv = "Product ID: " + reader[0].ToString() + "\t\tProduct Name: " +
reader[2].ToString() + "\t\tStock: " + reader[1].ToString();
BranchInventory.Add(branchInv);
}
}
myConn.Close();
}
return BranchInventory;
}
/// <summary>
/// Retrieves all information about a single product using the product ID.
/// </summary>
/// <param name="productID"></param>
/// <returns></returns>
public static string DisplayProduct(int productID)
{
string Desc = "";
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" Select ProductName, Stock, ProductDescription, ProductColour, ProductSize, ProductPattern, ProductType, wprice from Product
where SKU=@pID;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
myCommand.Parameters.AddWithValue("@pID", productID);
MySqlDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
{
Desc = "Product Name: " + reader[0].ToString() + "\nProduct ID: " + productID.ToString() + "\nProduct Description: " +
reader[2].ToString() + "\nColor: " + reader[3].ToString() + "\nSize: " + reader[4].ToString() + "\nPattern: " + reader[5].ToString() +
"\nType: " + reader[6] + "\nTotal Stock: " + reader[1].ToString() + "\nUnit Price: " + reader[7];
}
}
myConn.Close();
}
return Desc;
}
/// <summary>
/// Gets the last order ID
/// </summary>
/// <returns></returns>
public static Int32 GetOrderID()
{
string cID = "";
int orderID = 0;
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (var myConn = new MySqlConnection(connString))
{
const string sqlStatement = @" select OrderID from Orders ORDER BY OrderID DESC LIMIT 1;";
using (var myCommand = new MySqlCommand(sqlStatement, myConn))
{
myConn.Open();
cID = myCommand.ExecuteScalar().ToString();
orderID = Convert.ToInt32(cID);
}
myConn.Close();
}
return orderID;
}
}
}