Exemplo n.º 1
0
        private void BtnProductList_Click(object sender, RoutedEventArgs e)
        {
            Window WindowProductList = new ProductsList();

            WindowProductList.Show();
            Close();
        }
Exemplo n.º 2
0
        private void BtnCancelProduct_Click(object sender, RoutedEventArgs e)
        {
            Window WindowCancelProductAdd = new ProductsList();

            WindowCancelProductAdd.Show();
            Close();
        }
        private void BtnDeleteProduct_Click(object sender, RoutedEventArgs e)
        {
            selectedIndex = DataGridProducts.SelectedIndex;

            if (selectedIndex != -1)
            {
                try
                {
                    selectedProduct = productList[selectedIndex];
                }
                catch (ArgumentOutOfRangeException aex)
                {
                    MessageBox.Show("No Product Selected", "Delete Error");
                    return;
                }
                catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }

                string           msg       = "Are you sure you want to delete: " + selectedProduct.ProductName + "?";
                MessageBoxResult boxResult = MessageBox.Show(msg, "Delete Confirmation", MessageBoxButton.YesNo,
                                                             MessageBoxImage.Warning);
                if (boxResult == MessageBoxResult.Yes)
                {
                    try
                    {
                        //MessageBox.Show(selectedProduct.ToString());
                        if (!ProductDB.DeleteProduct(selectedProduct.ProductId))
                        {
                            GetCurrentProduct(selectedProduct.ProductId);
                        }
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
                }
            }
            else
            {
                MessageBox.Show("No Product Selected", "Delete Error");
            }

            //RefreshProductList();
            Window WindowPList = new ProductsList();

            WindowPList.Show();
            Close();
        }
Exemplo n.º 4
0
        private void BtnCreateProduct_Click(object sender, RoutedEventArgs e)
        {
            bool isValid = false;

            //Creating a new product MUST HAVE ProductName.
            if (!string.IsNullOrEmpty(TxtProductName.Text))
            {
                if (!string.IsNullOrEmpty(TxtProductPrice.Text))
                {
                    try
                    {
                        decimal pprice = Convert.ToDecimal(TxtProductPrice.Text);
                        isValid = true;
                    }
                    catch
                    {
                        isValid = false;
                        MessageBox.Show("Product Price must be a valid price", "Numbers only");
                    }
                }
                if (!string.IsNullOrEmpty(TxtProductTax.Text))
                {
                    try
                    {
                        decimal ptax = Convert.ToDecimal(TxtProductTax.Text);
                        isValid = true;
                    }
                    catch (Exception ex)
                    {
                        isValid = false;
                        MessageBox.Show("Product Tax must be a valid tax price", "Decimal only");
                    }
                }
                if (!string.IsNullOrEmpty(TxtProductQuantity.Text))
                {
                    try
                    {
                        int pquantity = Convert.ToInt32(TxtProductQuantity.Text);
                        isValid = true;
                    }
                    catch (Exception ex)
                    {
                        isValid = false;
                        MessageBox.Show("Product Quantity must be an Integer", "Whole Number Only");
                    }
                }
            }
            else
            {
                MessageBox.Show("You MUST enter a Product name", "Attention", MessageBoxButton.OK);
            }

            if (isValid)
            {
                if (BtnCreateProduct.Content.Equals("Save Product"))
                {
                    try
                    {
                        string  productName = TxtProductName.Text;
                        decimal prodPrice   = Convert.ToDecimal(TxtProductPrice.Text);
                        decimal prodTax     = Convert.ToDecimal(TxtProductTax.Text);
                        int     prodQuan    = Convert.ToInt32(TxtProductQuantity.Text);
                        date = loadedProduct.ProductListedDate;
                        int currentId = loadedProduct.ProductId;
                        loadedProduct = new Product(currentId, productName, prodPrice, prodTax, prodQuan, date);
                        ProductDB.UpdateProduct(loadedProduct);
                        Window WindowPList = new ProductsList();
                        WindowPList.Show();
                        Close();
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
                }
                else
                {
                    try
                    {
                        string  productName = TxtProductName.Text;
                        decimal prodPrice   = Convert.ToDecimal(TxtProductPrice.Text);
                        decimal prodTax     = Convert.ToDecimal(TxtProductTax.Text);
                        int     prodQuan    = Convert.ToInt32(TxtProductQuantity.Text);
                        date          = DateTime.Now;
                        loadedProduct = new Product(productName, prodPrice, prodTax, prodQuan, date);
                        //ProductDB.CreateProduct(loadedProduct);
                        ProductDB.CreateProductAdd(loadedProduct);
                        Window WindowProductList = new ProductsList();
                        WindowProductList.Show();
                        Close();
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
                }
            }
        }