温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:破竹CMS4.0免安装版源码
当前文件:
PozhuCMS/admin/Categories/EditCategory.aspx.cs,打开代码结构图
PozhuCMS/admin/Categories/EditCategory.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using Pozhu.Common; 12
using Pozhu.CMS; 13
using Pozhu.CMS.Categories; 14
using Pozhu.Sites; 15
using Pozhu.UI.WebControls; 16
using Pozhu.CMS.PropertyDefinitions.PropertyControls; 17
using Pozhu.CMS.PropertyDefinitions; 18
using Pozhu.CMS.Web; 19
20
public partial class admin_Categories_EditCategory : AdminPageBase 21
{ 22
23
protected override bool IsAuthenticated() 24
{ 25
if (base.IsAuthenticated()) 26
return true; 27
28
if (base.IsEditor()) 29
return true; 30
31
return false; 32
} 33
34
protected void Page_Load(object sender, EventArgs e) 35
{ 36
if (!Page.IsPostBack) 37
{ 38
string path = CategoryPath.CheckRepairPath(Request.QueryString["path"]); 39
int siteID = SiteController.GetCurrentSite().SiteID; 40
Category category = CategoryController.GetCategory(siteID,path); 41
42
string action = Request.QueryString["action"]; 43
if (action == "add") 44
{ 45
lblParentPath.Text = path; 46
this.lbtnUpdate.Visible = false; 47
} 48
else if(action == "edit") 49
{ 50
lblParentPath.Text = CategoryPath.GetParentPath(category.Path); 51
tbName.Text = CategoryPath.GetPathName(category.Path); 52
tbTitle.Text = category.Title; 53
54
lbtnAdd.Visible = false; 55
} 56
57
//验证权限 58
if (!category.IsAuthorization(CategoryController.PermissionCreateCategory)) 59
{ 60
lbtnAdd.Visible = false; 61
} 62
if (!category.IsAuthorization(CategoryController.PermissionUpdateCategory)) 63
{ 64
lbtnUpdate.Visible = false; 65
} 66
} 67
} 68
protected void lbtnCancel_Click(object sender, EventArgs e) 69
{ 70
string path = CategoryPath.CheckRepairPath(Request.QueryString["path"]); 71
string action = Request.QueryString["action"]; 72
if (action == "add") 73
{ 74
Response.Redirect(Globals.ApplicationPath + "/admin/path" + path + "categoryList.aspx"); 75
} 76
else if (action == "edit") 77
{ 78
Response.Redirect(Globals.ApplicationPath + "/admin/path" + CategoryPath.GetParentPath(path) + "categoryList.aspx"); 79
} 80
} 81
protected void lbtnAdd_Click(object sender, EventArgs e) 82
{ 83
string path = CategoryPath.CheckRepairPath(lblParentPath.Text + tbName.Text); 84
int siteID = SiteController.GetCurrentSite().SiteID; 85
if (!CategoryController.Exists(siteID, path)) 86
{ 87
Category category = new Category(); 88
category.Title = tbTitle.Text; 89
category.Path = path; 90
category.SiteID = siteID; 91
CategoryController.CreateCategory(category); 92
UpdatePropertyValues(category); 93
94
Response.Redirect(Globals.ApplicationPath + "/admin/path" + CategoryPath.CheckRepairPath(lblParentPath.Text) + "categoryList.aspx"); 95
} 96
else 97
{ 98
plState.CssClass = "warning"; 99
plState.Controls.Add(new LiteralControl("栏目未能成功添加:该栏目已存在!")); 100
} 101
} 102
protected void lbtnUpdate_Click(object sender, EventArgs e) 103
{ 104
string newPath = CategoryPath.CheckRepairPath(lblParentPath.Text + tbName.Text); 105
int siteID = SiteController.GetCurrentSite().SiteID; 106
string oldPath = CategoryPath.CheckRepairPath(Request.QueryString["path"]); 107
108
if (newPath.ToLower() != oldPath.ToLower()) 109
{ 110
if (CategoryController.Exists(siteID, newPath)) 111
{ 112
plState.CssClass = "warning"; 113
plState.Controls.Add(new LiteralControl("栏目未能更新:修改后的栏目路径已存在!")); 114
115
return; 116
} 117
} 118
119
Category category = CategoryController.GetCategory(siteID,oldPath); 120
category.Path = newPath; 121
category.Title = tbTitle.Text; 122
UpdatePropertyValues(category); 123
CategoryController.UpdateCategory(category); 124
125
Response.Redirect(Globals.ApplicationPath + "/admin/path" + CategoryPath.CheckRepairPath(lblParentPath.Text) + "categoryList.aspx"); 126
127
} 128
void UpdatePropertyValues(Category category) 129
{ 130
WrappedRepeater rptPropertyCategories = (WrappedRepeater)PropertyDefinitions2.FindControl("rptPropertyCategories"); 131
foreach (RepeaterItem ri in rptPropertyCategories.Items) 132
{ 133
if ((ri.ItemType == ListItemType.Item) || (ri.ItemType == ListItemType.AlternatingItem)) 134
{ 135
WrappedRepeater rptProperties = (WrappedRepeater)ri.FindControl("rptProperties"); 136
foreach (RepeaterItem riProperty in rptProperties.Items) 137
{ 138
if ((riProperty.ItemType == ListItemType.Item) || (riProperty.ItemType == ListItemType.AlternatingItem)) 139
{ 140
PlaceHolder phControl = (PlaceHolder)riProperty.FindControl("phControl"); 141
if (phControl.HasControls()) 142
{ 143
if (!(phControl.Controls[0] is LiteralControl)) 144
{ 145
PropertyControlBase tb = (PropertyControlBase)phControl.Controls[0]; 146
category.Profile.SetProperty(((PropertyDefinition)riProperty.DataItem).Name, tb.GetValue()); 147
} 148
} 149
} 150
} 151
} 152
} 153
CategoryPropertyController.UpdatePropertyValues(category); 154
} 155
} 156





}
}