Exemplo n.º 1
0
        private void CheckoutButton_Click(object sender, RoutedEventArgs e)
        {
            if (Order.OrderItems.Count == 0)
            {
                MessageBox.Show("Add products to proceed!", "Empty order");
                return;
            }
            try
            {
                var window = new OrderCheckoutDialog(Order);
                window.ShowDialog();
                if (window.DialogResult != true)
                {
                    return;
                }

                Order = new Order();
                RefreshOrderItemsDataGrid();
                UpdateGrandTotalLabel();
                ProductSource = _productHandler.GetItems();
                ProductComboBox.GetBindingExpression(ProductComboBox.ItemsSourceProperty)?.UpdateTarget();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "   :  An error has occured!");
            }
        }
Exemplo n.º 2
0
        private void RefreshSearchComboBox()
        {
            // Update Data Grid with new set of products
            ProductSource = ProductTypeComboBox.SelectedItem != null && ProductComboBox != null
                ? _productHandler.GetProducts(productType : (ProductType)ProductTypeComboBox.SelectedIndex)
                : _productHandler.GetItems();

            ProductComboBox?.GetBindingExpression(ProductComboBox.ItemsSourceProperty)?.UpdateTarget();
        }
Exemplo n.º 3
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Exception Handling

                if (QuantityTextBox.Text == "" || DiscountTextBox.Text == "" || UnitPriceTextBox.Text == "")
                {
                    MessageBox.Show("Some inputs are empty");
                    // Log.Debug("Quantity TextBox or Discount TextBox is Empty");
                    return;
                }
                else if (int.Parse(QuantityTextBox.Text) <= 0)
                {
                    //   Log.Debug("Qauntity is less than or equal to zero");
                    MessageBox.Show("Quantity is not valid");
                    return;
                }
                /* ALLOWED DISCOUNT TO BE NEGATIVE  */
                //else if (decimal.Parse(DiscountTextBox.Text) < 0)
                //{
                //    //   Log.Debug("Discount is negative ");
                //    MessageBox.Show("Discount is negative");
                //    return;
                //}
                else if (decimal.Parse(DiscountTextBox.Text) >= 100)
                {
                    //   Log.Debug("Discount greater than 100");
                    MessageBox.Show("Discount is more than 100%");
                    return;
                }
                else if (decimal.Parse(UnitPriceTextBox.Text) < 0)
                {
                    //   Log.Debug("Discount greater than 100");
                    MessageBox.Show("Unit Price is negative");
                    return;
                }

                #endregion

                var quantity = QuantityTextBox.Text == "" ? 0 : uint.Parse(QuantityTextBox.Text);
                var product  = ProductComboBox.SelectedItem as Product;
                var item     = product as Item;
                _discount  = DiscountTextBox.Text == "" ? 0 : decimal.Parse(DiscountTextBox.Text);
                _unitPrice = UnitPriceTextBox.Text == "" ? 0 : decimal.Parse(UnitPriceTextBox.Text);

                if (product != null)
                {
                    #region validation

                    if (quantity > item?.StockQty)
                    {
                        MessageBox.Show("Not enough items in stock to fullfil your requirement", "Not Enough Stock");
                        //    Log.Debug("Entered quantity is greater than available items");
                        return;
                    }
                    if (IsAlreadyEntered(product.Id))
                    {
                        // Log.Debug("Attempted to enter same item twice");
                        MessageBox.Show("This entry is already entered once. Try updating its quantity instead");
                    }

                    #endregion

                    else
                    {
                        var salePrice = _unitPrice != 0 ? _unitPrice : item?.UnitPrice * (100 - _discount) / 100 ?? 0;
                        var orderItem = new OrderItem(product.Id.GetValueOrDefault(), product.Name, quantity,
                                                      salePrice);

                        // add items to the order entries list
                        Order.AddOrderItem(orderItem);
                        UpdateGrandTotalLabel();
                        RefreshSearchComboBox();
                        RefreshOrderItemsDataGrid();

                        ProductTypeComboBox.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Please select a Product!", "Product not selected");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Invalid Input");
            }
            finally
            {
                QuantityTextBox.Text  = "";
                UnitPriceTextBox.Text = "";
                DiscountTextBox.Text  = "";
                ProductComboBox.GetBindingExpression(ItemsControl.ItemsSourceProperty)?.UpdateTarget();
            }
        }