首页->博客空间->SpaceBuilderV1.0RC免安装版源码(51aspx调测)>>BasicWebControls/Channel/Search/BlogSearchResults.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilderV1.0RC免安装版源码(51aspx调测)
当前文件:
SpaceBuilderV10RC/BasicWebControls/Channel/Search/BlogSearchResults.cs[6K,2009-6-12 11:55:43],打开代码结构图
SpaceBuilderV10RC/BasicWebControls/Channel/Search/BlogSearchResults.cs[6K,2009-6-12 11:55:43],打开代码结构图1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.Collections.Generic; 9
using System.Text; 10
using SpaceBuilder.Controls.BaseClasses; 11
using SpaceBuilder.Components; 12
using SpaceBuilder.Controls.Utils; 13
using System.Web.UI.HtmlControls; 14
using System.Web.UI.WebControls; 15
using SpaceBuilder.Utils; 16
using TunyNet.Data.Utils; 17
using TunyNet.Utils; 18
using SpaceBuilder.Posts.Components; 19
using SpaceBuilder.Posts.Providers; 20
using SpaceBuilder.Blogs.Components; 21
22
namespace SpaceBuilder.Search.Controls 23
{ 24
public class BlogSearchResults : TemplatedWebControl 25
{ 26
SBContext wlContext; 27
28
protected override void OnInit(EventArgs e) 29
{ 30
if (SkinName == null) 31
ExternalSkinFileName = "Searchs/Skin-BlogSearchResults.ascx"; 32
else 33
ExternalSkinFileName = SkinName; 34
35
wlContext = SBContext.Current; 36
base.OnInit(e); 37
} 38
39
protected override void OnLoad(EventArgs e) 40
{ 41
base.OnLoad(e); 42
EnsureChildControls(); 43
if (!Page.IsPostBack) 44
Bind(); 45
} 46
47
Child Controls 59
60
protected override void AttachChildControls() 61
{ 62
statusMessage = FindControl("StatusMessage") as StatusMessage; 63
64
noResultsDiv = FindControl("NoResultsDiv") as HtmlControl; 65
listPostsDiv = FindControl("ListPostsDiv") as HtmlControl; 66
searchHint = FindControl("SearchHint") as Literal; 67
postsRepeater = FindControl("PostsRepeater") as Repeater; 68
pager = FindControl("Pager") as Pager; 69
70
if (postsRepeater != null) 71
postsRepeater.ItemDataBound += new RepeaterItemEventHandler(PostsRepeater_ItemDataBound); 72
} 73
74
void Bind() 75
{ 76
PostFullTextQuery query = new PostFullTextQuery(); 77
query.ConvertFromQueryString(); 78
if (query.IsValid()) 79
{ 80
query.PageSize = 10; 81
query.PageIndex = pager.PageIndex; 82
83
SearchResultDataSet<PostSearchItem> pds = PostSearchProvider.Instance().Search(query); 84
postsRepeater.DataSource = pds.Records; 85
postsRepeater.DataBind(); 86
87
if (pds.TotalRecords > 0) 88
{ 89
searchHint.Text = "约有 <span class='stress'>" + pds.TotalRecords + " </span>个文章满足搜索条件,搜索用时 " + pds.SearchDuration + " 秒"; 90
91
pager.TotalRecords = pds.TotalRecords; 92
pager.PageSize = query.PageSize; 93
} 94
else 95
{ 96
noResultsDiv.Visible = true; 97
listPostsDiv.Visible = false; 98
} 99
} 100
else 101
{ 102
listPostsDiv.Visible = false; 103
statusMessage.Visible = true; 104
statusMessage.MessageType = StatusMessageType.Error; 105
statusMessage.Text = "请填写您的搜索条件,再进行搜索"; 106
} 107
} 108
109
private void PostsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 110
{ 111
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 112
{ 113
PostSearchItem item = e.Item.DataItem as PostSearchItem; 114
if (item != null) 115
{ 116
HyperLink subject = e.Item.FindControl("Subject") as HyperLink; 117
if (subject != null) 118
{ 119
subject.Text = item.Subject; 120
if (!ValueHelper.IsNullOrEmpty(item.PostUrl)) 121
{ 122
subject.NavigateUrl = Globals.FullPathForMainSite(item.PostUrl); 123
subject.Attributes["target"] = "_blank"; 124
} 125
} 126
127
Literal body = e.Item.FindControl("Body") as Literal; 128
if (body != null) 129
body.Text = item.Body; 130
131
HyperLink author = e.Item.FindControl("Author") as HyperLink; 132
if (author != null) 133
{ 134
author.Text = item.Author; 135
if (!ValueHelper.IsNullOrEmpty(item.UserProfileUrl)) 136
{ 137
author.NavigateUrl = Globals.FullPathForMainSite(item.UserProfileUrl); 138
author.Attributes["target"] = "_blank"; 139
} 140
} 141
142
Literal lastUpdatedDate = e.Item.FindControl("LastUpdatedDate") as Literal; 143
if (lastUpdatedDate != null) 144
lastUpdatedDate.Text = Formatter.FormatDate(item.LastUpdatedDate); 145
146
HyperLink sectionName = e.Item.FindControl("SectionName") as HyperLink; 147
if (sectionName != null && !ValueHelper.IsNullOrEmpty(item.SectionName)) 148
{ 149
sectionName.Text = item.SectionName; 150
if (!ValueHelper.IsNullOrEmpty(item.SectionUrl)) 151
{ 152
sectionName.NavigateUrl = Globals.FullPathForMainSite(item.SectionUrl); 153
sectionName.Attributes["target"] = "_blank"; 154
} 155
} 156
157
Literal tags = e.Item.FindControl("Tags") as Literal; 158
if (tags != null && item.Tags != null) 159
{ 160
for (int i = 0; i < item.Tags.Length; i++) 161
{ 162
tags.Text += string.Format("<a href='{0}' target='_blank'>{1}</a> ", Globals.FullPathForMainSite(ChannelUrls.Instance().ListWebLogPostsByTag(item.Tags[i])), item.Tags[i]); 163
} 164
} 165
} 166
} 167
} 168
169
} 170
} 171






}
}