/// <summary> /// 新增分类 /// </summary> private void AddCategory() { oyxf.Model.Category newCategory = GetControlData();//当前新增的分类 newCategory.Content = ""; newCategory.HasChildren = 0; int categoryId = bll.Add(newCategory); newCategory.CategoryId = categoryId; //将自增长的id赋值到当前新增分类的实体对象 if (newCategory.ParentId == 0) //新增顶级分类 { newCategory.IdPath = ',' + categoryId.ToString() + ','; newCategory.Depth = 1; } else //新增非顶级分类 { oyxf.Model.Category parentCategory = bll.GetModel(newCategory.ParentId); newCategory.IdPath = parentCategory.IdPath + categoryId + ','; newCategory.Depth = parentCategory.Depth + 1; //修改父级分类的HasChildren parentCategory.HasChildren = 1; bll.Update(parentCategory); } bll.Update(newCategory); ScriptHelper.AlertRedirect("新增成功", "/Category/List.aspx"); }
/// <summary> /// 验证Cookie /// </summary> private void CheckCookie() { HttpCookie cookie = HttpContext.Current.Request.Cookies[Key.COOKIE_CURRENTUSER]; if (cookie == null) { ScriptHelper.AlertRedirect("您还未登录", "/login.aspx"); return; } if (string.IsNullOrWhiteSpace(cookie.Value)) { ScriptHelper.AlertRedirect("您还未登录", "/login.aspx"); return; } string UserIdStr = CryptoHelper.TripleDES_Decrypt(cookie.Value, Key.TRIPLEDES_KEY); if (!UserIdStr.IsNumber()) { ScriptHelper.AlertRedirect("您还未登录", "/login.aspx"); return; } int userid = Convert.ToInt32(UserIdStr); UserInfoBll bll = new UserInfoBll(); oyxf.Model.UserInfo ui = bll.GetModel(userid); if (ui == null) { ScriptHelper.AlertRedirect("您还未登录", "/login.aspx"); return; } HttpContext.Current.Session[Key.SESSION_CURRENTUSER] = ui; }
protected void btnSave_Click(object sender, EventArgs e) { string id = ViewState["id"].ToString(); if (string.IsNullOrWhiteSpace(id)) { return; } oyxf.Model.Category model = new Model.Category(); model.CategoryId = Convert.ToInt32(id); model.Content = Request.Form["ueditor"].ToString(); if (bll.UpdateContent(model)) { ScriptHelper.AlertRedirect("修改成功", "/Category/List.aspx"); } else { ScriptHelper.Alert("修改失败"); } }
/// <summary> /// 修改分类 /// </summary> private void modifyCategory() { string categoryId = ViewState["id"].ToString(); oyxf.Model.Category oldCategory = bll.GetModel(Convert.ToInt32(categoryId)); oyxf.Model.Category newCategory = GetControlData(); //数据没有被修改 if (oldCategory.Name == newCategory.Name && oldCategory.ParentId == newCategory.ParentId && oldCategory.Type == newCategory.Type && oldCategory.Status == newCategory.Status && oldCategory.SortIndex == newCategory.SortIndex && oldCategory.Url == newCategory.Url) { ScriptHelper.Alert("数据没有被修改"); return; } //数据被修改了 newCategory.CategoryId = oldCategory.CategoryId; newCategory.Content = oldCategory.Content; oyxf.Model.Category oldParentCategory = bll.GetModel(oldCategory.ParentId); oyxf.Model.Category newParentCategory = bll.GetModel(newCategory.ParentId); bll.UpdateFatherCategory(oldParentCategory, newParentCategory, oldCategory, newCategory); ScriptHelper.AlertRedirect("修改成功", "/Category/List.aspx"); }