Пример #1
0
        private void AddOrderContent_Click(object sender, RoutedEventArgs e)    // Adds a new order
        {
            var           parent          = (sender as Button).Parent;
            CustomerClass customerOrderer = null;
            StockClass    stockOrder      = null;
            DateTime      orderDate       = DateTime.UtcNow;

            string orderQuantity = OrderQuantity.Text;

            int.TryParse(orderQuantity, out int amount);
            customerOrderer = (CustomerClass)CreateOrderTabCustomersComboBox.SelectedValue;
            stockOrder      = (StockClass)CreateOrderTabItemComboBox.SelectedValue;

            if (customerOrderer == null || stockOrder == null)
            {
                MessageToUser("You must choose a customer and an item");
            }
            else if (orderQuantity == "" || orderQuantity == "" || amount == 0)
            {
                MessageToUser("You must enter an integer");
            }
            else
            {
                if (orderQuantity != "" && stockOrder.Qty - amount >= 0)
                {
                    // if no orders are present, simply add an order to the collection.
                    if (_app.GetDefaultCustomerOrdersList().Count == 0)
                    {
                        store.RemoveFromStock(stockOrder, amount);

                        StockClass order = new StockClass(stockOrder.ItemName, stockOrder.Supplier, amount);

                        store.CreateOrder(customerOrderer, order);

                        MessageToUser($"You have successfully created a new Customer order \n\nCustomer: {customerOrderer.CustomerName} \nItem: {order.ItemName} " +
                                      $"\nAmount: {order.Qty} \nOrderdate: {orderDate.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}");

                        CreateOrderTabCustomersComboBox.SelectedIndex = -1;
                        CreateOrderTabItemComboBox.SelectedIndex      = -1;
                        OrderQuantity.Text = "";
                    }

                    // Otherwise create a new order object, prepared for future functionality
                    else
                    {
                        store.RemoveFromStock(stockOrder, amount);

                        StockClass order = new StockClass(stockOrder.ItemName, stockOrder.Supplier, amount);

                        store.CreateOrder(customerOrderer, order);

                        MessageToUser($"You have successfully created a new Customer order \n\nCustomer: {customerOrderer.CustomerName} \nItem: {order.ItemName} " +
                                      $"\nAmount: {order.Qty} \nOrderdate: {orderDate.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}");

                        CreateOrderTabCustomersComboBox.SelectedIndex = -1;
                        CreateOrderTabItemComboBox.SelectedIndex      = -1;
                        OrderQuantity.Text = "";
                    }
                }
                else   // If stock is missing item or low on stock order gets Queued
                {
                    int currQ = _app.QueuedOrders.Count + 1;
                    store.CreateOrder(customerOrderer, stockOrder, amount, currQ);
                    MessageToUser($"You have successfully created a new Customer order \n\nCustomer: {customerOrderer.CustomerName} \nItem: {stockOrder.ItemName} " +
                                  $"\nAmount: {amount} \nOrderdate: {orderDate.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} \nYour order is placed at number {currQ} in the queue.");
                    CreateOrderTabCustomersComboBox.SelectedIndex = -1;
                    CreateOrderTabItemComboBox.SelectedIndex      = -1;
                    OrderQuantity.Text = "";
                }
            }
        }