// 删除Category public ActionResult Delete(int id,string CategoryName) { try { CategoryDto dto = new CategoryDto(); DataTable dt = CMSService.SelectOne("Category", "CMSCategory", "CategoryId=" + id); foreach (DataRow dr in dt.Rows) { dto = CategoryMapping.getDTO(dr); } string strwhere = "CategoryParentId="+id; DataTable categorydt = CMSService.SelectSome("Category", "CMSCategory", strwhere); Message msg = new Message(); if (categorydt.Rows.Count > 0) { msg.MessageInfo = "此角色还有" + categorydt.Rows.Count + "条相关数据,不允许删除"; return RedirectTo("/Category/Index/" + dto.CategoryParentId + "?CategoryName=" + CategoryName, msg.MessageInfo); } else { msg = CMSService.Delete("Category", "CMSCategory", "CategoryId=" + id); msg.MessageInfo = "数据删除操作成功"; return RedirectTo("/Category/Index/" + dto.CategoryParentId + "?CategoryName=" + CategoryName, msg.MessageInfo); } } catch { return View(); } }
public static string CategoryIdToName(string strWhere) { CategoryDto dto = new CategoryDto(); DataTable dt = CMSService.SelectOne("Category", "CMSCategory", strWhere); foreach (DataRow dr in dt.Rows) { dto = CategoryMapping.getDTO(dr); } return dto.CategoryName; }
public static CategoryDto getDTO(DataRow dr) { CategoryDto categoryDto = new CategoryDto(); categoryDto.CategoryId = int.Parse(dr["CategoryId"].ToString()); categoryDto.CategoryName = dr["CategoryName"].ToString(); categoryDto.CategoryDescription = dr["CategoryDescription"].ToString(); categoryDto.CategoryParentId = int.Parse(dr["CategoryParentId"].ToString()); return categoryDto; }
public ActionResult Create(CategoryModel model) { try { CategoryDto dto = new CategoryDto(); dto.CategoryName = model.CategoryName; dto.CategoryDescription = model.CategoryDescription; dto.CategoryParentId = model.CategoryParentId; string JsonString = JsonHelper.JsonSerializerBySingleData(dto); Message msg = CMSService.Insert("Category", JsonString); return RedirectTo("/Category/Index/" + model.CategoryParentId + "?CategoryParentName=" + model.CategoryParentName, msg.MessageInfo); } catch { Message msg = new Message(); msg.MessageInfo = "插入操作出错了"; ViewBag.Status = "Error"; ViewBag.msg = msg.MessageInfo; return View(); } }
public ActionResult Edit(CategoryModel model) { CategoryDto dto = new CategoryDto(); DataTable dt = CMSService.SelectOne("Category", "CMSCategory", "CategoryId=" + model.CategoryId); foreach (DataRow dr in dt.Rows) { dto = CategoryMapping.getDTO(dr); dto.CategoryId = model.CategoryId; dto.CategoryName = model.CategoryName; dto.CategoryDescription = model.CategoryDescription; dto.CategoryParentId = model.CategoryParentId; } string JsonString = JsonHelper.JsonSerializerBySingleData(dto); Message msg = CMSService.Update("Category", JsonString); // TODO: Add update logic here return RedirectTo("/Category/Index/" + model.CategoryParentId + "?CategoryParentName=" + model.CategoryParentName, msg.MessageInfo); }
// 编辑Category视图 public ActionResult Edit(int id,string CategoryParentName) { CategoryModel model = new CategoryModel(); DataTable dt = CMSService.SelectOne("Category", "CMSCategory", "CategoryId=" + id); foreach (DataRow dr in dt.Rows) { CategoryDto dto = new CategoryDto(); dto = CategoryMapping.getDTO(dr); model.CategoryId = dto.CategoryId; model.CategoryName = dto.CategoryName; model.CategoryDescription = dto.CategoryDescription; model.CategoryParentId = dto.CategoryParentId; model.CategoryParentName = CategoryParentName; } return View(model); }
public static double GetFenshuByCategory(int categoryId) { double fenshu = 0; CategoryDto dto = new CategoryDto(); DataTable dt = CMSService.SelectOne("Category", "CMSCategory", "CategoryId="+categoryId); foreach (DataRow dr in dt.Rows) { dto = CategoryMapping.getDTO(dr); } try { fenshu = double.Parse(dto.CategoryDescription); } catch { fenshu = 0; } return fenshu; }