Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="InventoryUC" /> class.
 /// </summary>
 public InventoryUC(DataGridView theGrid)
 {
     DataGrid = theGrid;
     this.theController = new FurnitureController();
     this.InitializeComponent();
     UserControlType = UserControls.Inventory;
     this.loadAllData();
 }
Esempio n. 4
0
        private void submitTransactionButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(customerID) || customerID == "null")
            {
                ErrorHandler.DisplayErrorBox("Customer Not Selected","Please select a customer before submitting the transaction.");
                return;
            }

            if (this.items.Count < 1)
            {
                ErrorHandler.DisplayErrorBox("Items Not Selected", "You must add at least one item before submitting the transaction.");
                return;
            }

            try
            {
                this.theController.ReturnItems(this.items, this.theSession);

                var furnitureController = new FurnitureController();

                foreach (var item in this.items)
                {
                    item.Quantity = -item.Quantity;
                }

                furnitureController.UpdateQuantitiesByIds(this.items);
            }
            catch (MySqlException exception)
            {
                ErrorHandler.DisplayErrorMessageToUserAndLog("Error",
                    "Unable to process this return transaction. Please try again.", exception);
                return;
            }
            catch (Exception exception)
            {
                ErrorHandler.DisplayErrorMessageToUserAndLog("Unknown Error", "An unknown error has occured.", exception);
                return;
            }

            MessageBox.Show(this.items.Count + @" item(s) returned successfully! Extra Fees: " + this.extraFeesValueLabel.Text, @"Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.clearScreen();

        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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;
        }