コード例 #1
0
        public int UpdateBrand(int BrandId, string Title, bool DeleteImage,
                               System.Web.HttpPostedFile Image)
        {
            ProductsDS _ds = new ProductsDS();

            if (GetBrands(string.Format("Title='{0}' and BrandId <> {1}", Title, BrandId)).Count > 0)
            {
                return(-1);
            }

            ProductsDS.BrandsRow row = GetBrand(BrandId);


            row.Title        = Title;
            row.LastModified = DateTime.Now;

            string path = WebContext.Server.MapPath(WebContext.Root + lw.CTE.Folders.BrandsImages);

            if (DeleteImage && row.Image != "")
            {
                if (GetBrands("Image='" + row.Image + "' and BrandId<>" + BrandId.ToString()).Count == 0)
                {
                    if (System.IO.File.Exists(path + "/" + row.Image))
                    {
                        System.IO.File.Delete(path + "/" + row.Image);
                    }
                }
                row.Image = "";
            }

            string PartName = lw.Utils.StringUtils.ToURL(Title);

            if (PartName.Length >= 35)
            {
                PartName = PartName.Substring(0, 35);
            }

            if (Image != null && Image.ContentLength > 0)
            {
                if (!DeleteImage)
                {
                    if (GetBrands("Image='" + row.Image + "' and BrandId<>" + BrandId.ToString()).Count == 0)
                    {
                        if (System.IO.File.Exists(path + "/" + row.Image))
                        {
                            System.IO.File.Delete(path + "/" + row.Image);
                        }
                    }
                }

                string extension = lw.Utils.StringUtils.GetFileExtension(Image.FileName);
                string ImageName = PartName + "_" + row.BrandId + "." + extension;
                string Large     = path + "/" + ImageName;

                Image.SaveAs(Large);

                Config cfg = new Config();

                Dimension dim = new Dimension(cfg.GetKey(Settings.BrandsImagesSize));
                if (dim.Valid)
                {
                    lw.GraphicUtils.ImageUtils.Resize(Large, Large, dim.IntWidth, dim.IntHeight);
                }

                row.Image = ImageName;
            }

            BrandsAdp adp = new BrandsAdp();

            adp.Update(row);

            return(BrandId);
        }