Ejemplo n.º 1
0
 protected void grvOrderProduct_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         OrderDetail orderDetail = (OrderDetail)e.Row.DataItem;
         if (orderDetail != null)
         {
             Image imgProduct = (Image)e.Row.FindControl("imgProduct");
             if (imgProduct != null)
             {
                 string image = (new ProductImageRepo()).GetImageDefaultAllByProductId(ToSQL.SQLToInt(orderDetail.Product_ID));
                 if (CheckFileShared.CheckImageExist(image))
                 {
                     imgProduct.ImageUrl = "~/Resources/ImagesProduct/" + image;
                 }
                 else
                 {
                     imgProduct.ImageUrl = "~/Resources/ImagesProduct/no-image.png";
                 }
             }
             Label lbProductName = (Label)e.Row.FindControl("lbProductName");
             if (lbProductName != null)
             {
                 lbProductName.Text = orderDetail.Product.Name;
             }
         }
     }
 }
Ejemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Product p = new Product();

            p.Name             = txtName.Text;
            p.Price            = ToSQL.SQLToDecimal(txtPriceNew.Text);
            p.ProductType_ID   = ToSQL.SQLToIntNull(ddlProductType.SelectedValue);
            p.Manufacuturer_ID = ToSQL.SQLToIntNull(ddlManufacturer.SelectedValue);
            p.Description      = CKEditorControlDescription.Text;
            p.IsActive         = true;
            p.IsBestSelling    = chkBestSelling.Checked;
            p.IsNew            = chkNew.Checked;
            p.IsSpecial        = chkSpecial.Checked;
            p.DateCreated      = DateTime.Now;
            if (fulImageDefault.HasFile)
            {
                ProductImage image = new ProductImage();
                string       url   = CheckFileShared.UploadAndRsizeImage(fulImageDefault.PostedFile);
                if (url != "")
                {
                    image.Image     = url;
                    image.IsDefault = true;
                    p.ProductImages.Add(image);
                }
            }
            HttpFileCollection uploads = Request.Files;

            //for (int fileCount = 0; fileCount < uploads.Count; fileCount++)
            foreach (HttpPostedFile uploadedFile in FileUploadJquery.PostedFiles)
            {
                ProductImage image = new ProductImage();
                string       url   = CheckFileShared.UploadAndRsizeImage(uploadedFile);
                if (url != "")
                {
                    image.Image     = url;
                    image.IsDefault = false;
                    p.ProductImages.Add(image);
                }
            }
            if (productRepo.CreateProduct(p) > 0)
            {
                ProductPriceHistory productPriceHistory = new ProductPriceHistory();
                productPriceHistory.Product_ID  = p.ID;
                productPriceHistory.Price       = p.Price;
                productPriceHistory.DateCreated = DateTime.Now;
                new ProductPriceHistoryRepo().CreateProductPriceHistory(productPriceHistory);
                Response.Redirect("~/Admincp/Management-Products.aspx");
            }
            else
            {
                lbMessage.Text = "Please check input data! Try again!";
            }
        }
Ejemplo n.º 3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Product p = productRepo.GetById(ToSQL.SQLToInt(Request.QueryString["ID"]));

            if (p != null)
            {
                p.Name = ToSQL.EmptyNull(txtName.Text);
                decimal priceOld = p.Price;
                p.Price            = ToSQL.SQLToDecimal(txtPrice.Text);
                p.ProductType_ID   = ToSQL.SQLToIntNull(ddlProductType.SelectedValue);
                p.Manufacuturer_ID = ToSQL.SQLToIntNull(ddlManufacturer.SelectedValue);
                p.Description      = CKEditorControlDescription.Text;
                p.IsActive         = ToSQL.SQLToBool(chkActive.Checked);
                p.IsBestSelling    = ToSQL.SQLToBool(chkBestSelling.Checked);
                p.IsNew            = ToSQL.SQLToBool(chkNew.Checked);
                p.IsSpecial        = ToSQL.SQLToBool(chkSpecial.Checked);
                if (fulImageDefault.HasFile)
                {
                    ProductImage image = new ProductImage();
                    string       url   = CheckFileShared.UploadAndRsizeImage(fulImageDefault.PostedFile);
                    if (url != "")
                    {
                        var pi = p.ProductImages.FirstOrDefault(u => u.IsDefault.Value == true); if (pi != null)
                        {
                            pi.IsDefault = false;
                        }
                        image.Image     = url;
                        image.IsDefault = true;
                        p.ProductImages.Add(image);
                    }
                }

                foreach (HttpPostedFile uploadedFile in FileUploadJquery.PostedFiles)
                {
                    ProductImage image = new ProductImage();
                    string       url   = CheckFileShared.UploadAndRsizeImage(uploadedFile);
                    if (url != "")
                    {
                        image.Image     = url;
                        image.IsDefault = false;
                        p.ProductImages.Add(image);
                    }
                }
                if (productRepo.UpdateProduct(p) > 0)
                {
                    if (priceOld != p.Price)
                    {
                        ProductPriceHistory productPriceHistory = new ProductPriceHistory();
                        productPriceHistory.Product_ID  = p.ID;
                        productPriceHistory.Price       = p.Price;
                        productPriceHistory.DateCreated = DateTime.Now;
                        new ProductPriceHistoryRepo().CreateProductPriceHistory(productPriceHistory);
                    }
                    Response.Redirect("~/Admincp/Management-Products.aspx");
                }
                else
                {
                    lbMessage.Text = "Please check input data! Try again!";
                }
            }
            else
            {
                Response.Redirect("Management-Products.aspx");
            }
        }