温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:破竹CMS4.0免安装版源码
当前文件:
PozhuCMS/admin/Categories/DocumentTypesControl.ascx.cs,打开代码结构图
PozhuCMS/admin/Categories/DocumentTypesControl.ascx.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.CMS.DocumentTypes; 12
using Pozhu.CMS; 13
using Pozhu.Sites; 14
using Pozhu.CMS.Categories; 15
using Pozhu.Common.Utilities; 16
17
public partial class admin_Categories_DocumentTypesControl : System.Web.UI.UserControl 18
{ 19
int _CategoryID = Null.NullInteger; 20
21
public int CategoryID 22
{ 23
get 24
{ 25
if (_CategoryID == Null.NullInteger) 26
throw new Exception("请设置CategoryID属性的值"); 27
28
return _CategoryID; 29
} 30
set { _CategoryID = value; } 31
} 32
int _DocumentID = Null.NullInteger; 33
34
public int DocumentID 35
{ 36
get { return _DocumentID; } 37
set { _DocumentID = value; } 38
} 39
protected void Page_Load(object sender, EventArgs e) 40
{ 41
if (!Page.IsPostBack) 42
{ 43
44
DocumentTypeController objTypes = new DocumentTypeController(); 45
//邦定 46
this.rptDocumentTypes.DataSource = objTypes.GetDocumentTypeGroups(CategoryID); 47
this.rptDocumentTypes.DataBind(); 48
49
ArrayList noGroupTypes = objTypes.GetNoGroupTypes(CategoryID, true); 50
51
if (noGroupTypes.Count > 0) 52
{ 53
//bind 54
foreach (DocumentType type in noGroupTypes) 55
{ 56
lbNoGroupTypes.Items.Add(new ListItem(new string('-', type.Level * 2) + type.TypeName, type.TypeID.ToString())); 57
} 58
59
// 60
lbNoGroupTypes.Items.Insert(0, new ListItem("<-未分组的文档类型->", Null.NullInteger.ToString())); 61
62
//设置选中的项目 63
ItemSelected(lbNoGroupTypes); 64
} 65
else 66
{ 67
lbNoGroupTypes.Visible = false; 68
} 69
} 70
} 71
protected void rptDocumentTypes_ItemDataBound(object sender, RepeaterItemEventArgs e) 72
{ 73
DocumentTypeController objTypes = new DocumentTypeController(); 74
int categoryID; 75
string path = CategoryPath.CheckRepairPath(Request.QueryString["path"]); 76
int siteID = SiteController.GetCurrentSite().SiteID; 77
categoryID = CategoryController.GetCategory(siteID, path).CategoryID; 78
79
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) 80
{ 81
ListBox lbTypes = (ListBox)e.Item.FindControl("lbTypes"); 82
83
DocumentTypeGroup group = (DocumentTypeGroup)(e.Item.DataItem); 84
ArrayList types = objTypes.GetDocumentTypesByGroupID(categoryID, group.TypeGroupID, true); 85
foreach (DocumentType type in types) 86
{ 87
lbTypes.Items.Add(new ListItem(new string('-', type.Level * 2) + type.TypeName, type.TypeID.ToString())); 88
} 89
90
// 91
lbTypes.Items.Insert(0, new ListItem("<-" + group.TypeGroupName + "->", Null.NullInteger.ToString())); 92
93
//设置选中的项目 94
ItemSelected(lbTypes); 95
} 96
97
} 98
99
public int[] GetSelectTypes() 100
{ 101
//用于存储文档类型的ID数组 102
ArrayList alSelectItems = new ArrayList(); 103
foreach (RepeaterItem ri in rptDocumentTypes.Items) 104
{ 105
ListBox lbTypes = (ListBox)ri.FindControl("lbTypes"); 106
foreach (ListItem li in lbTypes.Items) 107
{ 108
if ((li.Selected) && (li.Value != Null.NullInteger.ToString())) 109
{ 110
alSelectItems.Add(li); 111
} 112
} 113
} 114
115
//未分组的文档类型 116
foreach (ListItem li in lbNoGroupTypes.Items) 117
{ 118
if ((li.Selected) && (li.Value != Null.NullInteger.ToString())) 119
{ 120
alSelectItems.Add(li); 121
} 122
} 123
124
//将 125
int[] arrDocumentTypes = new int[alSelectItems.Count]; 126
for (int i = 0; i < alSelectItems.Count; i++) 127
{ 128
arrDocumentTypes[i] = int.Parse(((ListItem)alSelectItems[i]).Value); 129
} 130
131
return arrDocumentTypes; 132
} 133
134
void ItemSelected(ListBox lbTypes) 135
{ 136
if (DocumentID != Null.NullInteger) 137
{ 138
DocumentTypeController objTypeController = new DocumentTypeController(); 139
ArrayList documentTypes = objTypeController.GetDocumentTypesByDocumentID(DocumentID); 140
foreach (ListItem item in lbTypes.Items) 141
{ 142
foreach (DocumentType type in documentTypes) 143
{ 144
if (type.TypeID == int.Parse(item.Value)) 145
item.Selected = true; 146
} 147
} 148
} 149
} 150
} 151





}
}