温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:
SpaceBuider11/BasicWebControls/Manage/Club/EditClubCategory.cs[5K,2009-6-12 11:54:33],打开代码结构图
SpaceBuider11/BasicWebControls/Manage/Club/EditClubCategory.cs[5K,2009-6-12 11:54:33],打开代码结构图1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Inc. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.Collections.Generic; 9
using System.Text; 10
using SpaceBuilder.Components; 11
using SpaceBuilder.Posts.Permissions; 12
using System.Web.UI.WebControls; 13
using SpaceBuilder.Controls.Utils; 14
using SpaceBuilder.Clubs.Components; 15
using TunyNet.Data.Utils; 16
using TunyNet.Utils; 17
using SpaceBuilder.Utils; 18
using System.Collections; 19
using TunyNet.Web.UI; 20
using System.Web.UI.HtmlControls; 21
22
namespace SpaceBuilder.Web.Manage.Controls 23
{ 24
/// <summary> 25
/// 编辑圈子类别 26
/// </summary> 27
public class EditClubCategory : ManageBaseControl 28
{ 29
SBContext wlContext; 30
int parentID = -1; 31
int categoryID = -1; 32
33
/// <summary> 34
/// 验证权限 35
/// </summary> 36
protected override void Authorize() 37
{ 38
base.Authorize(); 39
if (!(SBContext.Current.User.IsClubAdministrator)) 40
PermissionBase.RedirectOrExcpetion(SBExceptionType.AccessDenied); 41
} 42
43
protected override void OnInit(EventArgs e) 44
{ 45
if (SkinName == null) 46
SkinName = "Clubs/Skin-EditClubCategory.ascx"; 47
48
wlContext = SBContext.Current; 49
base.OnInit(e); 50
} 51
52
protected override void OnLoad(EventArgs e) 53
{ 54
base.OnLoad(e); 55
EnsureChildControls(); 56
parentID = wlContext.GetIntFromQueryString("ParentID", -1); 57
categoryID = wlContext.GetIntFromQueryString("CategoryID", -1); 58
if (!Page.IsPostBack) 59
BindData(); 60
} 61
62
63
Child Controls 87
88
protected override void AttachChildControls() 89
{ 90
parentName = FindControl("ParentName") as Literal; 91
categoryName = FindControl("CategoryName") as TextBox; 92
saveButton = FindControl("SaveButton") as LinkButton; 93
parentCategoryTr = FindControl("ParentCategoryTr") as HtmlTableRow; 94
saveButton.Click += new EventHandler(saveButton_Click); 95
cancelButton = FindControl("CancelButton") as LinkButton; 96
cancelButton.Click += new EventHandler(cancelButton_Click); 97
} 98
99
100
101
void BindData() 102
{ 103
string stringPageTitle = string.Empty; 104
if (parentID > 0) 105
{ 106
stringPageTitle = "创建子类别"; 107
ClubCategory parentCategory = ClubCategories.GetCategory(parentID); 108
if (parentCategory != null) 109
{ 110
if (parentName != null) 111
{ 112
parentName.Text = parentCategory.CategoryName; 113
} 114
} 115
} 116
else if (categoryID > 0) 117
{ 118
stringPageTitle = "更新类别"; 119
ClubCategory category = ClubCategories.GetCategory(categoryID); 120
if (category != null) 121
{ 122
if (category.ParentID > 0) 123
{ 124
ClubCategory parent = ClubCategories.GetCategory(category.ParentID); 125
if (parent != null) 126
{ 127
parentName.Text = parent.CategoryName; 128
} 129
} 130
else 131
{ 132
parentCategoryTr.Visible = false; 133
} 134
if (categoryName != null) 135
{ 136
categoryName.Text = category.CategoryName; 137
} 138
} 139
140
} 141
else 142
{ 143
stringPageTitle = "创建根类别"; 144
if (parentCategoryTr != null) 145
{ 146
parentCategoryTr.Visible = false; 147
} 148
} 149
SpaceBuilder.Controls.Header.AddTitle(stringPageTitle, this.Context); 150
} 151
152
void cancelButton_Click(object sender, EventArgs e) 153
{ 154
ModalHelper.ClosePage(this.Page); 155
} 156
157
void saveButton_Click(object sender, EventArgs e) 158
{ 159
if (parentID > 0) 160
{ 161
ClubCategory newCategory = new ClubCategory(); 162
newCategory.ParentID = parentID; 163
newCategory.CategoryName = categoryName.Text; 164
ClubCategories.Create(newCategory); 165
} 166
else if (categoryID > 0) 167
{ 168
ClubCategory categoryToChange = ClubCategories.GetCategory(categoryID); 169
if (categoryToChange != null) 170
{ 171
categoryToChange.CategoryName = categoryName.Text; 172
ClubCategories.Update(categoryToChange); 173
} 174
} 175
else 176
{ 177
ClubCategory rootCategory = new ClubCategory(); 178
rootCategory.ParentID = 0; 179
rootCategory.CategoryName = categoryName.Text; 180
ClubCategories.Create(rootCategory); 181
} 182
ModalHelper.ClosePage(this.Page, "true"); 183
} 184
} 185
} 186






}