public bool DeleteCategory(int CategoryId) { ProductsDS.CategoriesViewDataTable cats = this.GetChildrenCategories(CategoryId); foreach (DataRow cat in cats) { DeleteCategory((Int32)cat["CategoryId"]); } ProductsDS.CategoriesRow category = GetCategory(CategoryId); string path = WebContext.Server.MapPath(WebContext.Root + lw.CTE.Folders.CategoriesImages); if (category["Image"] != System.DBNull.Value) { if (category.Image != "") { if (this.GetCategories("Image='" + category.Image + "' and CategoryId<>" + CategoryId.ToString()).Count == 0) { if (System.IO.File.Exists(path + "/Large/" + category.Image)) { System.IO.File.Delete(path + "/Large/" + category.Image); } } } } CategoriesAdp adp = new CategoriesAdp(); adp.DeleteCategory(CategoryId); return(true); }
public ProductsDS.CategoriesDataTable _GetCategories(string cond) { CategoriesAdp adp = new CategoriesAdp(); return(adp.GetCategories(cond)); }
public int UpdateCategory(int CategoryId, string UniqueName, string Title, int SortingOrder, bool status, HttpPostedFile Image, bool DeleteImage, string Description, int ParentId, int ClassId) { ProductsDS _ds = new ProductsDS(); //if (this.GetCategories(string.Format("(Title='{0}' and ParentId={1} and CategoryId <> {3}) or (Name='{2}' and CategoryId <> {3})", Title, ParentId, UniqueName, CategoryId)).Count > 0) // return -1; ProductsDS.CategoriesRow row = GetCategory(CategoryId); CategoriesAdp adp = new CategoriesAdp(); UniqueName = StringUtils.ToURL(UniqueName); row.Name = UniqueName; row.Title = Title; row.SortingOrder = SortingOrder; row.Status = status; row.Description = Description; row.ParentId = ParentId; row.ClassId = ClassId; row.LastModified = DateTime.Now; string path = WebContext.Server.MapPath(WebContext.Root + lw.CTE.Folders.CategoriesImages); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!Directory.Exists(Path.Combine(path, "Thumb"))) { Directory.CreateDirectory(Path.Combine(path, "Thumb")); } if (!Directory.Exists(Path.Combine(path, "Large"))) { Directory.CreateDirectory(Path.Combine(path, "Large")); } if (DeleteImage && row.Image != "") { if (this.GetCategories("Image='" + row.Image + "' and CategoryId<>" + row.CategoryId.ToString()).Count == 0) { if (System.IO.File.Exists(path + "/Thumb/" + row.Image)) { System.IO.File.Delete(path + "/Thumb/" + row.Image); } if (System.IO.File.Exists(path + "/Large/" + row.Image)) { System.IO.File.Delete(path + "/Large/" + 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 (System.IO.File.Exists(path + "/Thumb/" + row.Image)) { System.IO.File.Delete(path + "/Thumb/" + row.Image); } if (System.IO.File.Exists(path + "/Large/" + row.Image)) { System.IO.File.Delete(path + "/Large/" + row.Image); } } string extension = lw.Utils.StringUtils.GetFileExtension(Image.FileName); string ImageName = PartName + "_" + row.CategoryId + "." + extension; string Large = path + "/Large/" + ImageName; string Thumb = path + "/Thumb/" + ImageName; Image.SaveAs(Large); Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(Settings.CategoryImagesSize)); if (dim.Valid) { lw.GraphicUtils.ImageUtils.CreateThumb(Large, Thumb, dim.IntWidth, dim.IntHeight, true); } row.Image = ImageName; } adp.Update(row); return(row.CategoryId); }
public int AddCategory(string UniqueName, string Title, int SortingOrder, bool status, HttpPostedFile Image, string Description, int ParentId, int ClassId) { ProductsDS _ds = new ProductsDS(); DataTable cats = this.GetCategories(string.Format("(Title='{0}' and ParentId={1}) or Name='{2}'", Title, ParentId, UniqueName)); if (cats.Rows.Count > 0) { return((int)cats.Rows[0]["CategoryId"]); } UniqueName = StringUtils.ToURL(UniqueName); CategoriesAdp adp = new CategoriesAdp(); adp.Insert(UniqueName, StringUtils.SQLEncode(Title), status, "", Description, ParentId, null, DateTime.Now, DateTime.Now, null, null, SortingOrder); ProductsDS.CategoriesRow cat = GetCategory(UniqueName); int CategoryId = cat.CategoryId; 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.CategoriesImages; pathTo = WebContext.Server.MapPath(pathTo); if (!Directory.Exists(pathTo)) { Directory.CreateDirectory(pathTo); } if (!Directory.Exists(Path.Combine(pathTo, "thumb"))) { Directory.CreateDirectory(Path.Combine(pathTo, "thumb")); } if (!Directory.Exists(Path.Combine(pathTo, "large"))) { Directory.CreateDirectory(Path.Combine(pathTo, "large")); } string extension = lw.Utils.StringUtils.GetFileExtension(Image.FileName); string ImageName = PartName + "_" + CategoryId.ToString() + "." + extension; string Large = pathTo + "/large/" + ImageName; string Thumb = pathTo + "/thumb/" + ImageName; Image.SaveAs(Large); Config cfg = new Config(); Dimension dim = new Dimension(cfg.GetKey(Settings.CategoryImagesSize)); if (dim.Valid) { lw.GraphicUtils.ImageUtils.Resize(Large, Large, dim.IntWidth, dim.IntHeight); } adp.UpdateImage(ImageName, CategoryId); } return(CategoryId); }