Beispiel #1
0
        public bool DeleteBrand(int BrandId)
        {
            ProductsDS.BrandsRow brand = this.GetBrand(BrandId);

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

            BrandsAdp adp = new BrandsAdp();

            adp.DeleteBrand(BrandId);

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

            return(true);
        }
Beispiel #2
0
        public int AddBrand(string Title, System.Web.HttpPostedFile Image)
        {
            BrandsAdp adp = new BrandsAdp();

            adp.Insert(Title, "", DateTime.Now, DateTime.Now);

            int BrandId = GetBrand(Title).BrandId;

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

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

            if (Image != null && Image.ContentLength > 0)
            {
                string pathTo = WebContext.Root + lw.CTE.Folders.BrandsImages;
                pathTo = WebContext.Server.MapPath(pathTo);

                string extension = lw.Utils.StringUtils.GetFileExtension(Image.FileName);
                string ImageName = PartName + "_" + BrandId + "." + extension;
                string Large     = pathTo + "/" + 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);
                }
                adp.UpdateImage(ImageName, BrandId);
            }

            return(BrandId);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public ProductsDS.BrandsDataTable GetBrands(string cond)
        {
            BrandsAdp adp = new BrandsAdp();

            return(adp.GetBrands(cond));
        }