コード例 #1
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();

        }
コード例 #2
0
ファイル: TransactionUC.cs プロジェクト: jwalke24/Rent-Me
        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);
            }
        }