/// <summary> /// Creates a new transaction. /// </summary> /// <param name="transaction"></param> public void CreateTransaction(List <Tuple <int, int> > transaction) { try { status = State.Transaction; List <Tuple <Product, int> > TrueTransaction = new List <Tuple <Product, int> >(); // error checking foreach (Tuple <int, int> T in transaction) { if (T.Item1 >= ProductDB.GetProductList().Count || T.Item1 <= 0) { throw new Exception("Invalid item ID"); } else { TrueTransaction.Add(new Tuple <Product, int>(ProductDB.GetProduct(T.Item1), T.Item2)); } } if (TrueTransaction.Count == 0) { throw new Exception(); } salesID++; Transaction newTransaction = new Transaction(salesID, TrueTransaction); TransactionDB.AddTransaction(newTransaction); MessageBox.Show(newTransaction.FormatReceipt()); returnval = "Transaction generated successfully!"; update(returnval, status); } catch (Exception) { returnval = "\nAn error has occurred. Please try again."; } }
/// <summary> /// Processes a return request given a receipt. /// </summary> /// <param name="receiptID"></param> /// <param name="itemID"></param> /// <param name="itemAmount"></param> public void ProcessReturn(int receiptID, int itemID, int itemAmount) { status = State.Return; if (receiptID > TransactionDB.GetTransactionInt() || receiptID < 0) { throw new Exception(); } Transaction receipt = TransactionDB.GetTransaction(receiptID); for (int i = 0; i < receipt.GetItems.Count; i++) { List <Tuple <Product, int> > temp = receipt.GetItems; if (temp[i].Item1.ID == itemID) { if (itemAmount > temp[i].Item2) { returnval = "Error. Cannot return more items than purchased."; update(returnval, status); return; } else { temp[i] = new Tuple <Product, int>(temp[i].Item1, temp[i].Item2 - itemAmount); returnval = "Success! Items returned."; update(returnval, status); return; } } } returnval = "Error. Item Not Found."; update(returnval, status); }
/// <summary> /// Adds a Transaction to the Rebate DataBase. /// </summary> /// <param name="Date"></param> /// <param name="ID"></param> public void AddToRebateList(DateTime Date, int ID) { status = State.Rebate; Transaction temp = TransactionDB.GetTransaction(ID); returnval = RebateDB.AddRebateToList(temp, Date); update(returnval, status); }