protected void InitInfo() { categoryId = CECRequest.GetQueryInt("categoryid", 0); Action = CECRequest.GetQueryString("action"); if (Action == "del") { bool isDelete = ArticleCategoryManage.DeleteCategory(categoryId); if (!isDelete) { Page.ClientScript.RegisterStartupScript(this.GetType(), "DelError", "alert('该分类可能有字分类,请先删掉子分类!');window.location.href='categorylist.aspx';", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "DeleSuccess", "alert('删除成功!');window.location.href='categorylist.aspx';", true); } return; } this.ddlcategoryList.BuildTree(ArticleCategoryManage.GetArticleCategoryTable(), "CategoryName", "CategoryId"); this.ddlcategoryList.SelectedValue = categoryId.ToString(); if (Action.ToLower() == "edit") { categoryInfo = ArticleCategoryManage.GetArticleCategoryInfo(categoryId); this.ddlcategoryList.SelectedValue = categoryInfo.ParentId.ToString(); } }
void btnSave_Click(object sender, EventArgs e) { if (Action.ToLower() == "edit") { categoryInfo = new ArticleCategoryInfo(); categoryInfo.CategoryName = txtName.Text; categoryInfo.Sort = Convert.ToInt32(txtSort.Text); categoryInfo.CategoryId = categoryId; ArticleCategoryManage.UpdateArticleCategory(categoryInfo); } else { if (this.ddlcategoryList.SelectedValue != "0") { int _id = Utils.StrToInt(this.ddlcategoryList.SelectedValue, 0); categoryInfo = ArticleCategoryManage.GetArticleCategoryInfo(_id); if (categoryInfo != null) { string parentIdList = string.Empty; if (categoryInfo.ParentIdList == "0") { parentIdList = categoryInfo.CategoryId.ToString(); } else { parentIdList = categoryInfo.ParentIdList + "," + categoryInfo.CategoryId; } int maxOrder = 0; DataTable dt = ArticleCategoryManage.GetSubCategoryListTable(_id); if (dt.Rows.Count > 0) { maxOrder = TypeConverter.ObjectToInt(dt.Compute("Max(Sort)", "")); } else { maxOrder = categoryInfo.Sort; } InsertCategory(_id, categoryInfo.Layer + 1, parentIdList, 0, maxOrder); ArticleCategoryManage.UpdateSubCategoryCount(_id); } } else { int maxdisplayorder = TypeConverter.ObjectToInt(ArticleCategoryManage.GetArticleCategoryTable().Compute("Max(Sort)", "")) + 1; InsertCategory(0, 0, "0", 0, maxdisplayorder); } } Page.ClientScript.RegisterStartupScript(this.GetType(), "SaveSuccess", "alert('添加成功!');window.location.href='categorylist.aspx';", true); }