Пример #1
0
        /*
         * Event Handler for Modifying Product Details
         */
        private void ModifyButton_Click(object sender, EventArgs e)
        {
            if (ProductComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please select one product from the drop down list.", "Manual Entry Restricted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ProductComboBox.Focus();
            }
            else
            {
                String ProdName = ProductComboBox.SelectedItem.ToString();

                try
                {
                    var result = from Prod in ProductList
                                 where Prod.ProductName == ProdName
                                 select Prod;

                    foreach (var prod in result)
                    {
                        prod.ProductPrice    = decimal.Parse(ProductPriceTextBox.Text);
                        prod.ProductQuantity = int.Parse(ProductQuantityTextBox.Text);
                    }
                    EndOfTheDayStock();
                    MessageBox.Show("Product Updated Successfully", "Updation Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ProductNameTextBox.Text             = "";
                    ProductCategoryListBox.SelectedItem = -1;
                    ProductPriceTextBox.Text            = "";
                    ProductQuantityTextBox.Text         = "";
                    ProductComboBox.SelectedIndex       = -1;
                }
                catch
                {
                    MessageBox.Show("Error Occured while updating the product. Please try again later");
                }
            }
        }
Пример #2
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();
            }
        }