Ejemplo n.º 1
0
        private void OrderButton_Click(object sender, RoutedEventArgs e)
        {
            if (newOrder.OrderItems.Count < 1)
            {
                MyDialog.Show("Order Item is empty!",
                              "Please add at least one game item.");
            }
            else if (string.IsNullOrWhiteSpace(CashTextBox.Text))
            {
                MyDialog.Show("Cash is empty!",
                              "Please input the cash.");
            }
            else
            {
                newOrder.Cash    = Convert.ToInt32(CashTextBox.Text);
                newOrder.OrderAt = DateTime.Now;

                if (newOrder.Cash < newOrder.TotalPrice)
                {
                    MyDialog.Show("Insufficient cash");
                    return;
                }

                newOrder.CountChange();

                Order.Insert(newOrder);

                int nextOrderItemId = this.initialOrderItemId;

                foreach (var orderItem in newOrder.OrderItems)
                {
                    OrderItem.Insert(nextOrderItemId, newOrder.OrderId, orderItem.GameId);
                    nextOrderItemId++;
                }

                MyDialog.ShowTo("Order is sucessfully added",
                                "Cash : Rp " + newOrder.Cash +
                                "\nTotal : Rp " + newOrder.TotalPrice +
                                "\nChange : Rp " + newOrder.Change);
            }
        }