private void DataGridOnRowsChanged(object sender, object dataGridViewRowsAddedEventArgs) { try { FurnitureController tempFurnitureController = new FurnitureController(); decimal total = 0; foreach (var purchaseTransactionItem in DataGrid.DataSource as BindingList<PurchaseTransaction_Item>) { total += purchaseTransactionItem.LeaseTime * tempFurnitureController.GetItemById(int.Parse(purchaseTransactionItem.FurnitureId)).Price * purchaseTransactionItem.Quantity; } this.totalPriceLabel.Text = string.Format("{0:C}", total); } catch (MySqlException exception) { ErrorHandler.DisplayErrorMessageToUserAndLog("Network Exception", "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 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 addItemConfirmButton_Click(object sender, EventArgs e) { FurnitureController theController = new FurnitureController(); try { var id = int.Parse(this.itemToAddTextBox.Text); var result = theController.GetItemById(id); var quantity = int.Parse(this.qtyTextBox.Text); var days = (this.dateTimePicker1.Value - DateTime.Now).Days + 1; if (quantity <= 0) { ErrorHandler.DisplayErrorBox("Error", "Please enter a valid quantity. "); return; } if (result == null) { ErrorHandler.DisplayErrorBox("Error", "Item not found. Please try again."); return; } if (result.Quantity < quantity) { ErrorHandler.DisplayErrorBox("Quantity Error", "There are not enough items in stock. You can only rent " + result.Quantity + " items or less."); return; } if (days <= 0) { ErrorHandler.DisplayErrorBox("Lease Time Error", "You must rent for at least one day."); return; } PurchaseTransaction_Item theItem = new PurchaseTransaction_Item(); theItem.FurnitureId = result.Id; theItem.Quantity = quantity; theItem.LeaseTime = days; theItem.FurnitureName = result.Name; foreach (var purchaseTransactionItem in this.itemsToPurchase) { if (purchaseTransactionItem.FurnitureId == theItem.FurnitureId) { ErrorHandler.DisplayErrorBox("Duplicate Error", "Cannot add duplicate item to transaction"); return; } } this.itemsToPurchase.Add(theItem); if (this.DataGrid.DataSource == null) { this.DataGrid.DataSource = this.itemsToPurchase; this.DataGrid.Columns["ReturnableQuantity"].Visible = false; } } catch (MySqlException error) { ErrorHandler.DisplayErrorMessageToUserAndLog("Network Error", "There was a problem adding this item to the transaciton. Please try again.", error); return; } catch (Exception) { ErrorHandler.DisplayErrorBox("Error", "Please enter a numerical value."); return; } this.InternalState = TransactionStates.Main; }