Exemplo n.º 1
0
        private void button_addProductDetails_Click(object sender, EventArgs e)
        {
            String errorMessage = "";
            if(textBox_quantity.Text.Trim().Length == 0)
            {
                errorMessage += "Please Enter Product Quantity \n";
                MessageBox.Show(errorMessage, "Error");
                return;
            }
            int result;

            if (! Int32.TryParse(textBox_quantity.Text.Trim(), out result))
            {
                errorMessage += "\n Please Enter Valid Product Quantity \n";
                MessageBox.Show(errorMessage, "Error");
                return;
            }

            Product productDetails = new Product();

            long lastProductId = 0;
            if (db.Products.Where(x => x.CategoryId == ProductDetails.categoryId).Count() > 0)
                lastProductId = db.Products.Where(x => x.CategoryId == ProductDetails.categoryId).Max(x => x.ProductId);

            productDetails.ProductId = lastProductId + 1;
            productDetails.ProductName = ProductDetails.productName;
            productDetails.CategoryId = ProductDetails.categoryId;
            productDetails.Product_Details = richTextBox_productDescription.Text.Trim();
            productDetails.Quantity = Int32.Parse(textBox_quantity.Text.Trim());

            db.Products.Add(productDetails);
            db.SaveChanges();

            MessageBox.Show("Added " + ProductDetails.productName + " Details Successfully","Success");
            this.Hide();
        }
Exemplo n.º 2
0
        private void button_addProduct_Click(object sender, EventArgs e)
        {
            if (textBox_newProduct.Text.Trim().Length == 0)
            {
                CommonUtilities.showErrorPopUp("Please Enter a Product Name");
                return;
            }

            Category selectedCategory = comboBox_existingProductCategories.SelectedItem as Category;
            if (db.Products.Where(x => x.CategoryId == selectedCategory.CategoryId && x.ProductName.ToLower().Equals(textBox_newProduct.Text.Trim().ToLower())).Count() > 0)
            {
                CommonUtilities.showErrorPopUp(textBox_newProduct.Text.Trim().ToLower() + " Already Available Under " + selectedCategory.CategoryName);
                return;
            }

            long lastProductId = 0;

            if (db.Products.Where(x => x.CategoryId == selectedCategory.CategoryId).Count() > 0)
                lastProductId = db.Products.Where(x => x.CategoryId == selectedCategory.CategoryId).Max(x => x.ProductId);

            long newProductId = lastProductId + 1;

            Product newProduct = new Product();
            newProduct.ProductId = newProductId;
            newProduct.ProductName = textBox_newProduct.Text.Trim().ToLower();
            newProduct.CategoryId = selectedCategory.CategoryId;

            db.Products.Add(newProduct);
            db.SaveChanges();

            setDropDownValues(comboBox_existingProductCategories);
            setDropDownValues(comboBox_editCategories);

            CommonUtilities.showSuccessPopup(textBox_newProduct.Text.Trim().ToLower() + " Added Successfully Under " + selectedCategory.CategoryName);
        }