Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string key = Request.Params["key"];

            if (!string.IsNullOrEmpty(key))
            {
                db = new lafien_products_dbEntities();

                product = db.Products.Where(x => x.ProductID.ToUpper() == key.ToUpper()).FirstOrDefault();

                if (product == null)
                {
                    var tmp = db.ProductOwnerReferences.Where(x => x.RefProductID.ToUpper() == key.ToUpper()).FirstOrDefault();
                    if (tmp != null)
                    {
                        product  = tmp.Product;
                        mess     = key + " reference to " + product.ProductName;
                        noResult = false;
                    }
                }
                else
                {
                    noResult = false;
                }


                if (noResult == false)
                {
                    productCat = db.ProductCategories.Where(x => x.Active == true).ToList();
                }
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string key = Request.Params["key"];
            if (!string.IsNullOrEmpty(key))
            {

                db = new lafien_products_dbEntities();

                product = db.Products.Where(x => x.ProductID.ToUpper() == key.ToUpper()).FirstOrDefault();

                if (product == null)
                {
                    var tmp = db.ProductOwnerReferences.Where(x => x.RefProductID.ToUpper() == key.ToUpper()).FirstOrDefault();
                    if (tmp != null)
                    {
                        product = tmp.Product;
                        mess = key + " reference to " + product.ProductName;
                        noResult = false;
                    }
                }
                else
                {
                    noResult = false;
                }

                if (noResult == false)
                {
                    productCat = db.ProductCategories.Where(x => x.Active == true).ToList();
                }

            }
        }
Exemple #3
0
        protected void gvListItem_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                string      id       = e.CommandArgument.ToString();
                GridViewRow row      = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
                Label       lblTitle = (Label)row.Cells[1].FindControl("lblName");

                if (e.CommandName.ToLower() == "deleteitem")
                {
                    LPS.Product obj = db.Products.FirstOrDefault(x => x.ProductID == id);
                    if (obj != null)
                    {
                        if (db.CarItems.Count(x => x.ProductID == obj.ProductID) > 0)
                        {
                            mess = "Can't not delete this product, because this is using in some cars ";
                        }
                        else
                        {
                            var lispPO = db.ProductOwnerReferences.Where(x => x.ProductID == obj.ProductID).ToList();
                            foreach (var item in lispPO)
                            {
                                db.ProductOwnerReferences.Remove(item);
                            }
                            db.SaveChanges();
                            db.Products.Remove(obj);
                            db.SaveChanges();
                        }
                    }
                    LoadData();
                }
            }
            catch (Exception ex)
            {
                mess = ex.Message;
            }
        }