/// <summary> /// Initializes a new instance of the <see cref="PurchaseTransactionUC"/> class. /// </summary> /// <param name="theGrid">The grid.</param> public PurchaseTransactionUC(DataGridView theGrid) { DataGrid = theGrid; this.theController = new TransactionController(); InitializeComponent(); UserControlType = UserControls.PurchaseTransaction; }
private void DataGridOnRowsChanged(object sender, object dataGridViewRowsAddedEventArgs) { var dataGridViewColumn = DataGrid.Columns["FurnitureId"]; if (dataGridViewColumn != null) { dataGridViewColumn.Visible = false; } try { FurnitureController tempFurnitureController = new FurnitureController(); TransactionController tempTransactionController = new TransactionController(); decimal total = 0; var purchaseTransactionItems = DataGrid.DataSource as BindingList<PurchaseTransaction_Item>; if (purchaseTransactionItems != null) { foreach (var purchaseTransactionItem in purchaseTransactionItems) { int daysOut = (DateTime.Now - tempTransactionController.GetByID(purchaseTransactionItem.PurchaseTransactionId) .TransactionTime).Days; daysOut++; daysOut -= purchaseTransactionItem.LeaseTime; if (daysOut < 0) daysOut = 0; Furniture tempFurniture = tempFurnitureController.GetItemById(int.Parse(purchaseTransactionItem.FurnitureId)); total += daysOut * (tempFurniture.LateFee + tempFurniture.Price); } } this.extraFeesValueLabel.Text = string.Format("{0:C}", total); } catch (MySqlException exception) { ErrorHandler.DisplayErrorMessageToUserAndLog("Network Error", "There was an error connecting to the database. Please try again.", exception); } catch (Exception exception) { ErrorHandler.DisplayErrorMessageToUserAndLog("Unknown Error", "An unknown error occured.", exception); } }
private void submitTransactionButton_Click(object sender, EventArgs e) { if (this.itemsToPurchase.Count == 0) { ErrorHandler.DisplayErrorBox("Error", "Cannot submit an empty transaction."); return; } if (this.customerID == "null") { ErrorHandler.DisplayErrorBox("Error", "Must select a customer."); return; } try { var theController = new TransactionController(); var furnitureController = new FurnitureController(); var transaction = new PurchaseTransaction { TransactionTime = DateTime.Now, CustomerId = this.customerID, EmployeeId = this.session.Id.ToString(), Items = new List<PurchaseTransaction_Item>(this.itemsToPurchase) }; theController.AddPurchaseTransaction(transaction); furnitureController.UpdateQuantitiesByIds(transaction.Items); MessageBox.Show(this.itemsToPurchase.Count + @" item(s) were purchased for a total of " + this.totalPriceLabel.Text + ".", @"Transaction Successful", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); this.clearTransaction(); } catch (NullReferenceException nullReference) { ErrorHandler.DisplayErrorMessageToUserAndLog("Session Error", "The login session is null.", nullReference); } catch (InvalidCastException invalidCast) { ErrorHandler.DisplayErrorMessageToUserAndLog("Session Error", "The tag cannot be cast as a login session.", invalidCast); } catch (MySqlException sqlException) { ErrorHandler.DisplayErrorMessageToUserAndLog("SQL Error", "The transaction could not be added to the database.", sqlException); } catch (ArgumentOutOfRangeException rangeException) { ErrorHandler.DisplayErrorMessageToUserAndLog("Quantity Error", rangeException.Message, rangeException); } }