예제 #1
0
        /// <summary>
        ///     Deletes a pick from the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (pickIdInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input the text box.");
                    pickIdInput.Focus();
                    return;
                }
                else if (!Regex.IsMatch(pickIdInput.Text, "^[0-9]*$"))
                {
                    MessageBox.Show("Please input only numerical characters into the text box.");
                    pickIdInput.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());
            }

            // Check Picks by Pick ID
            PickObject pick1 = businessLogicLayer.CheckPicksByPickID(int.Parse(pickIdInput.Text));

            // Select Picks Order Line ID and Location ID And Quantity by Pick ID
            PickObject pick2           = businessLogicLayer.SelectPicksOrderLineLocationIDAndQuantityByPickID(int.Parse(pickIdInput.Text));
            int        pickOrderLineID = pick2.order_line_id;
            int        pickLocationID  = pick2.location_id;
            int        pickQuantity    = pick2.quantity;

            // Get Order Line Order ID
            OrderLineObject orderLine1       = businessLogicLayer.GetOrderLineOrderID(pickOrderLineID);
            int             orderLineOrderID = orderLine1.order_id;

            // Select Stock ID by Picks Location ID
            StockObject stock1  = businessLogicLayer.SelectStockIDByPicksLocationID(pickLocationID);
            int         stockID = stock1.stock_id;

            // Select Stock Location by Stock ID
            StockObject stock6        = businessLogicLayer.SelectStockLocationIDByID(stockID);
            int         stockLocation = stock6.location_id;

            try
            {
                if (!int.Parse(pickIdInput.Text).Equals(pick1.pick_id))
                {
                    MessageBox.Show("The Pick ID provided does not exist.");
                    pickIdInput.Focus();
                    return;
                }
                else
                {
                    // Undo Stock Quantity
                    StockObject stock2 = businessLogicLayer.UndoStockQuantity(pickQuantity, stockLocation);


                    // Undo Stock Availability Status
                    StockObject stock4        = businessLogicLayer.SelectStockQuantityByLocationID(stockLocation);
                    int         stockQuantity = stock4.quantity;

                    if (stockQuantity > 0)
                    {
                        StockObject stockObject3 = businessLogicLayer.UndoStockAvailabilityStatus(stockLocation);
                    }


                    // Undo Location Allocation
                    StockObject stock5 = businessLogicLayer.SelectStockAvailabilityStatusByStockLocation(stockLocation);
                    bool        stockAvailabilityStatus = stock5.availability_status;
                    if (stockAvailabilityStatus.Equals(true))
                    {
                        LocationObject location1 = businessLogicLayer.SetLocationAllocatedTrue(stockLocation);
                    }


                    // Undo Stock Allocated Quantity
                    StockObject stock3 = businessLogicLayer.UndoStockAllocatedQuantity(pickQuantity, stockLocation);


                    // Delete Current Pick
                    PickObject pick = businessLogicLayer.DeleteCurrentPick(int.Parse(pickIdInput.Text));


                    // Undo Order Status
                    OrderLineObject orderLine2        = businessLogicLayer.GetOrderLineQuantityByOLIDAndOID(orderLineOrderID, orderLineOrderID);
                    int             orderLineQuantity = orderLine2.quantity;

                    PickObject pick3         = businessLogicLayer.GetPickQuantityByOrderID(orderLineOrderID);
                    int        pickQuantity2 = pick3.quantity;

                    if (!pickQuantity2.Equals(orderLineQuantity))
                    {
                        OrderObject order = businessLogicLayer.SetOrderStatusCreated(orderLineOrderID);
                    }


                    // Message Box
                    MessageBox.Show("Pick: " + pickIdInput.Text + " has been deleted from the system. \n\nThe Pick Quantity has been unallocated in Stock. \n\nThe Stock Availability Status has been set back to True where relevant. \n\nThe Order Status has been set back to Created where relevant. \n\nThe Location Allocation has been set back to Allocated where relevant.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }