/// <summary>
        ///     Adds a new receipt line to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (receiptIdInput.Text.Equals("") || productIdInput.Text.Equals("") || quantityInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    receiptIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(receiptIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(productIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(quantityInput.Text, "^[0-9]*$")))
                {
                    MessageBox.Show("Please input only numerical characters into all text boxes.");
                    receiptIdInput.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }

            ReceiptLineObject receiptLine;
            ReceiptObject     receipt = businessLogicLayer.CheckReceiptsByID(int.Parse(receiptIdInput.Text));
            ProductObject     product = businessLogicLayer.CheckProductsByID(int.Parse(productIdInput.Text));

            try
            {
                if (!int.Parse(receiptIdInput.Text).Equals(receipt.receipt_id))
                {
                    MessageBox.Show("The Receipt ID provided does not exist.");
                    receiptIdInput.Focus();
                    return;
                }
                else if (!int.Parse(productIdInput.Text).Equals(product.product_id))
                {
                    MessageBox.Show("The Product ID provided does not exist.");
                    productIdInput.Focus();
                    return;
                }
                else
                {
                    receiptLine = businessLogicLayer.InsertNewReceiptLine(int.Parse(receiptIdInput.Text), int.Parse(productIdInput.Text), int.Parse(quantityInput.Text));
                    MessageBox.Show("The provided Receipt Line has been added to the system.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }
예제 #2
0
        /// <summary>
        ///     Add new Stock to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (accountIdInput.Text.Equals("") || productIdInput.Text.Equals("") || warehouseIdInput.Text.Equals("") || quantityInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    accountIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(accountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(productIdInput.Text, "^[0-9]*$")) ||
                         (!Regex.IsMatch(warehouseIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(quantityInput.Text, "^[0-9]*$")))
                {
                    MessageBox.Show("Please input only numerical characters into all text boxes.");
                    accountIdInput.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }

            StockObject     stock;
            AccountObject   account       = businessLogicLayer.CheckAccountsByID(int.Parse(accountIdInput.Text));
            ProductObject   product       = businessLogicLayer.CheckProductsByID(int.Parse(productIdInput.Text));
            WarehouseObject warehouse     = businessLogicLayer.CheckWarehousesByID(int.Parse(warehouseIdInput.Text));
            LocationObject  location      = businessLogicLayer.FindFreeLocation(int.Parse(warehouseIdInput.Text));
            int             stockLocation = location.location_id;

            try
            {
                if (!int.Parse(accountIdInput.Text).Equals(account.account_id))
                {
                    MessageBox.Show("The Account ID provided does not exist.");
                    accountIdInput.Focus();
                    return;
                }
                else if (!int.Parse(productIdInput.Text).Equals(product.product_id))
                {
                    MessageBox.Show("The product ID provided does not exist.");
                    productIdInput.Focus();
                    return;
                }
                else if (!int.Parse(warehouseIdInput.Text).Equals(warehouse.warehouse_id))
                {
                    MessageBox.Show("The Warehouse ID provided does not exist.");
                    warehouseIdInput.Focus();
                    return;
                }
                else if (stockLocation.Equals(0))
                {
                    MessageBox.Show("There are no more locations free in warehouse: " + warehouseIdInput.Text);
                    warehouseIdInput.Focus();
                    return;
                }
                else
                {
                    stock = businessLogicLayer.InsertNewStock(int.Parse(accountIdInput.Text), int.Parse(productIdInput.Text), int.Parse(warehouseIdInput.Text),
                                                              stockLocation, int.Parse(quantityInput.Text));
                    location = businessLogicLayer.MarkLocationAllocated(stockLocation);
                    MessageBox.Show("The Stock provided has been added to the system. \n\nA location has been found for the Stock and is now set as allocated. \n\nThe Stock (Pallet) is now ready to be put away, please see the location code as to where.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }
예제 #3
0
        /// <summary>
        ///     Edits a stock in the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (currentStockIdInput.Text.Equals("") || currentLocationIdInput.Text.Equals("") ||
                    newAccountIdInput.Text.Equals("") || newProductIdInput.Text.Equals("") || newWarehouseIdInput.Text.Equals("") || newLocationIdInput.Equals("") ||
                    newQuantityInput.Text.Equals("") || newAllocatedQuantityInput.Text.Equals("") || newAvailabilityStatusInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    currentStockIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(currentStockIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(currentLocationIdInput.Text, "^[0-9]*$")) ||
                         (!Regex.IsMatch(newAccountIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newProductIdInput.Text, "^[0-9]*$")) ||
                         (!Regex.IsMatch(newWarehouseIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newLocationIdInput.Text, "^[0-9]*$")) ||
                         (!Regex.IsMatch(newQuantityInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newAllocatedQuantityInput.Text, "^[0-9]*$")))
                {
                    MessageBox.Show("Please input only numerical characters into all text boxes apart from the current and new 'Availability Status Input'.");
                    currentStockIdInput.Focus();
                    return;
                }
                else if (!(newAvailabilityStatusInput.Text.ToLower().Equals("true") || newAvailabilityStatusInput.Text.ToLower().Equals("false")))
                {
                    MessageBox.Show("Please input only 'True' or 'False' into the current and new Availability Status Input text boxes.");
                    newAvailabilityStatusInput.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }

            StockObject stock;
            StockObject stockCurrentId = businessLogicLayer.CheckStockByID(int.Parse(currentStockIdInput.Text));
            StockObject stockCurrentIdAndWarehouseAndLocation = businessLogicLayer.CheckStockByIDAndWarehouseAndLocation(int.Parse(currentStockIdInput.Text),
                                                                                                                         int.Parse(currentWarehouseIdInput.Text),
                                                                                                                         int.Parse(currentLocationIdInput.Text));
            StockObject stockCurrentWarehouseAndLocation = businessLogicLayer.CheckStockByWarehouseAndLocation(int.Parse(currentWarehouseIdInput.Text),
                                                                                                               int.Parse(currentLocationIdInput.Text));
            StockObject stockNewWarehouseAndLocation = businessLogicLayer.CheckStockByWarehouseAndLocation(int.Parse(newWarehouseIdInput.Text),
                                                                                                           int.Parse(newLocationIdInput.Text));
            LocationObject locationNewLocationByWarehouse = businessLogicLayer.CheckLocationByIDAndWarehouse(int.Parse(newLocationIdInput.Text),
                                                                                                             int.Parse(newWarehouseIdInput.Text));
            AccountObject   accountId   = businessLogicLayer.CheckAccountsByID(int.Parse(newAccountIdInput.Text));
            ProductObject   productId   = businessLogicLayer.CheckProductsByID(int.Parse(newProductIdInput.Text));
            WarehouseObject warehouseId = businessLogicLayer.CheckWarehousesByID(int.Parse(newWarehouseIdInput.Text));
            LocationObject  locationId  = businessLogicLayer.CheckLocationsByID(int.Parse(newLocationIdInput.Text));
            LocationObject  locationUnallocated;
            LocationObject  locationAllocated;

            try
            {
                if (!int.Parse(currentStockIdInput.Text).Equals(stockCurrentId.stock_id))
                {
                    MessageBox.Show("The current Stock ID provided does not exist.");
                    currentStockIdInput.Focus();
                    return;
                }
                else if (!int.Parse(currentStockIdInput.Text).Equals(stockCurrentIdAndWarehouseAndLocation.stock_id) &&
                         !int.Parse(currentWarehouseIdInput.Text).Equals(stockCurrentIdAndWarehouseAndLocation.warehouse_id) &&
                         !int.Parse(currentLocationIdInput.Text).Equals(stockCurrentIdAndWarehouseAndLocation.location_id))
                {
                    MessageBox.Show("The current Stock provided does not exist in that Warehouse & Location.");
                    currentStockIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newAccountIdInput.Text).Equals(accountId.account_id))
                {
                    MessageBox.Show("The new Account ID provided does not exist.");
                    newAccountIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newProductIdInput.Text).Equals(productId.product_id))
                {
                    MessageBox.Show("The new product ID provided does not exist.");
                    newProductIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newWarehouseIdInput.Text).Equals(warehouseId.warehouse_id))
                {
                    MessageBox.Show("The new Warehouse ID provided does not exist.");
                    newWarehouseIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newLocationIdInput.Text).Equals(locationId.location_id))
                {
                    MessageBox.Show("The new Location ID provided does not exist.");
                    newLocationIdInput.Focus();
                    return;
                }
                else if (int.Parse(newQuantityInput.Text) < int.Parse(newAllocatedQuantityInput.Text))
                {
                    MessageBox.Show("The new Allocated Quantity cannot be greater than the new Quantity.");
                    newQuantityInput.Focus();
                    return;
                }
                else if (!int.Parse(newLocationIdInput.Text).Equals(locationNewLocationByWarehouse.location_id))
                {
                    MessageBox.Show("The new Location ID provided does not exist in that warehouse.");
                    currentStockIdInput.Focus();
                    return;
                }
                else if (int.Parse(newWarehouseIdInput.Text).Equals(stockNewWarehouseAndLocation.warehouse_id) &&
                         !int.Parse(newWarehouseIdInput.Text).Equals(stockCurrentWarehouseAndLocation.warehouse_id) ||
                         int.Parse(newLocationIdInput.Text).Equals(stockNewWarehouseAndLocation.location_id) &&
                         !int.Parse(newLocationIdInput.Text).Equals(stockCurrentWarehouseAndLocation.location_id))
                {
                    MessageBox.Show("Stock already exists in that Warehouse and Location.");
                    newWarehouseIdInput.Focus();
                    return;
                }
                else
                {
                    stock = businessLogicLayer.EditCurrentStock(int.Parse(newAccountIdInput.Text), int.Parse(newProductIdInput.Text), int.Parse(newWarehouseIdInput.Text),
                                                                int.Parse(newLocationIdInput.Text), int.Parse(newQuantityInput.Text), int.Parse(newAllocatedQuantityInput.Text),
                                                                bool.Parse(newAvailabilityStatusInput.Text.ToLower()),
                                                                int.Parse(currentStockIdInput.Text));
                    locationUnallocated = businessLogicLayer.MarkLocationUnallocated(int.Parse(currentLocationIdInput.Text));
                    locationAllocated   = businessLogicLayer.MarkLocationAllocated(int.Parse(newLocationIdInput.Text));
                    MessageBox.Show("The Stock provided has been updated. \n\nThe current Location has been marked unallocated. \n\nThe new Location has been marked allocated");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }
        /// <summary>
        ///     Edits an order line in the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (currentOrderLineIdInput.Text.Equals("") || newOrderIdInput.Text.Equals("") || newProductIdInput.Text.Equals("") || newQuantityInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    currentOrderLineIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(currentOrderLineIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newOrderIdInput.Text, "^[0-9]*$")) ||
                         (!Regex.IsMatch(newProductIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newQuantityInput.Text, "^[0-9]*$")))
                {
                    MessageBox.Show("Please input only numerical characters into all text boxes.");
                    currentOrderLineIdInput.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }

            OrderLineObject orderLine;
            OrderLineObject orderLineCurrent = businessLogicLayer.CheckOrderLinesByID(int.Parse(currentOrderLineIdInput.Text));
            OrderObject     order            = businessLogicLayer.CheckOrdersByID(int.Parse(newOrderIdInput.Text));
            ProductObject   product          = businessLogicLayer.CheckProductsByID(int.Parse(newProductIdInput.Text));

            try
            {
                if (!int.Parse(currentOrderLineIdInput.Text).Equals(orderLineCurrent.order_line_id))
                {
                    MessageBox.Show("The Current Order Line ID provided does not exist.");
                    newProductIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newOrderIdInput.Text).Equals(order.order_id))
                {
                    MessageBox.Show("The New Order ID provided does not exist.");
                    newOrderIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newProductIdInput.Text).Equals(product.product_id))
                {
                    MessageBox.Show("The New Product ID provided does not exist.");
                    newProductIdInput.Focus();
                    return;
                }
                else
                {
                    orderLine = businessLogicLayer.EditCurrentOrderLine(int.Parse(newOrderIdInput.Text), int.Parse(newProductIdInput.Text), int.Parse(newQuantityInput.Text),
                                                                        int.Parse(currentOrderLineIdInput.Text));
                    MessageBox.Show("The provided Order Line has been updated.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }