Exemplo n.º 1
0
        private void btnRemoveBrand_Click(object sender, EventArgs e)
        {
            int             currentRow = dgvBrand.CurrentRow.Index;
            DataGridViewRow row        = dgvBrand.CurrentRow;

            if (row != null)
            {
                if (row.Cells["brandName"].Value != null)
                {
                    String brandName = row.Cells["brandName"].Value.ToString();
                    var    db        = new ThriftShopContext.ThriftShopDataContext();
                    db.Products.DeleteAllOnSubmit(db.Products.Where(p => p.Brand.BrandName == brandName));
                    db.SubmitChanges();
                    db.Brands.DeleteOnSubmit(db.Brands.Where(p => p.BrandName == brandName).First());
                    db.SubmitChanges();
                    dgvBrand.Rows.RemoveAt(currentRow);
                    ShowProducts(db.Products);
                }
            }
        }
Exemplo n.º 2
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            String name      = tbProductName.Text;
            String category  = tbProductCategory.Text;
            String brandName = tbProductBrandName.Text;
            String price     = tbProductPrice.Text;

            if (!(name == "" || category == "" || brandName == "" || price == ""))
            {
                var db = new ThriftShopContext.ThriftShopDataContext();
                if (!CheckProductId(name))
                {
                    if (CheckBrandId(brandName))
                    {
                        if (statusOfFilterOrSort)
                        {
                            ShowProducts(db.Products);
                            statusOfFilterOrSort = false;
                        }
                        var     brand      = db.Brands.First(p => p.BrandName == brandName);
                        double  parsePrice = double.Parse(price);
                        Product product    = new ThriftShopContext.Product();
                        product.ProductName     = name;
                        product.ProductCategory = category;
                        product.ProductPrice    = parsePrice;
                        product.Brand           = brand;
                        db.Products.InsertOnSubmit(product);
                        db.SubmitChanges();
                        dgvProduct.Rows.Add(name, category, price, brandName);
                        IQueryable <Brand> result = from brandI in db.Brands
                                                    orderby brandI.Products.Count()
                                                    select brandI;

                        ShowBrands(result);
                        tbProductBrandName.Clear();
                        tbProductCategory.Clear();
                        tbProductName.Clear();
                        tbProductPrice.Clear();
                    }
                    else
                    {
                        tbProductBrandName.Text      = "Brand Not Exist";
                        tbProductBrandName.ForeColor = Color.Red;
                    }
                }
                else
                {
                    tbProductName.Text      = "Product is already exist";
                    tbProductName.ForeColor = Color.Red;
                }
            }
        }
Exemplo n.º 3
0
        private void btnAddBrand_Click(object sender, EventArgs e)
        {
            String Name = tbBrandName.Text;

            if (Name != "")
            {
                if (!CheckBrandId(Name))
                {
                    var   db    = new ThriftShopContext.ThriftShopDataContext();
                    Brand brand = new ThriftShopContext.Brand();
                    brand.BrandName = Name;
                    db.Brands.InsertOnSubmit(brand);
                    db.SubmitChanges();
                    dgvBrand.Rows.Add(Name, "0");
                }
                else
                {
                    tbBrandName.Text      = "Brand is already exist";
                    tbBrandName.ForeColor = Color.Red;
                }
            }
        }
Exemplo n.º 4
0
        private void btnRemoveProduct_Click(object sender, EventArgs e)
        {
            int             currentRow = dgvProduct.CurrentRow.Index;
            DataGridViewRow row        = dgvProduct.CurrentRow;

            if (row != null)
            {
                if (row.Cells["productName"].Value != null)
                {
                    String productName = row.Cells["productName"].Value.ToString();
                    var    db          = new ThriftShopContext.ThriftShopDataContext();
                    db.Products.DeleteOnSubmit(db.Products.Where(p => p.ProductName == productName).First());
                    db.SubmitChanges();
                    dgvProduct.Rows.RemoveAt(currentRow);
                    IQueryable <Brand> result = from brand in db.Brands
                                                orderby brand.Products.Count()
                                                select brand;

                    ShowBrands(result);
                }
            }
        }