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

            OrderObject order;
            OrderObject order1 = businessLogicLayer.CheckOrdersByID(int.Parse(orderIdInput.Text));
            OrderObject order2 = businessLogicLayer.CheckOrderIsAllocated(int.Parse(orderIdInput.Text));

            try
            {
                if (!int.Parse(orderIdInput.Text).Equals(order1.order_id))
                {
                    MessageBox.Show("The Order ID provided does not exist.");
                    orderIdInput.Focus();
                    return;
                }
                else if (order2.status.Equals("allocated"))
                {
                    MessageBox.Show("The Order provided is currently allocated and so cannot be deleted. \n\nPlease contact an administrator if the order still needs to be deleted.");
                    orderIdInput.Focus();
                    return;
                }
                else if (order2.status.Equals("picked"))
                {
                    MessageBox.Show("The Order provided has already been picked and so cannot be deleted. \n\nPlease contact an administrator if the order still needs to be deleted.");
                    orderIdInput.Focus();
                    return;
                }
                else if (order2.status.Equals("dispatched"))
                {
                    MessageBox.Show("The Order provided has already been dispatched and so cannot be deleted. \n\nPlease contact an administrator if the order still needs to be deleted.");
                    orderIdInput.Focus();
                    return;
                }
                else
                {
                    order = businessLogicLayer.DeleteCurrentOrder(int.Parse(orderIdInput.Text));
                    MessageBox.Show("The provided Order has been deleted from 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());
            }
        }