温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:
SpaceBuider11/BasicWebControls/Channel/Search/BlogSearchResults.cs[6K,2009-6-12 11:54:32],打开代码结构图
SpaceBuider11/BasicWebControls/Channel/Search/BlogSearchResults.cs[6K,2009-6-12 11:54:32],打开代码结构图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.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
/// <summary> 25
/// 显示博客搜索结果 26
/// </summary> 27
public class BlogSearchResults : TemplatedWebControl 28
{ 29
SBContext wlContext; 30
31
protected override void OnInit(EventArgs e) 32
{ 33
if (SkinName == null) 34
ExternalSkinFileName = "Searchs/Skin-BlogSearchResults.ascx"; 35
else 36
ExternalSkinFileName = SkinName; 37
38
wlContext = SBContext.Current; 39
base.OnInit(e); 40
} 41
42
protected override void OnLoad(EventArgs e) 43
{ 44
base.OnLoad(e); 45
EnsureChildControls(); 46
if (!Page.IsPostBack) 47
Bind(); 48
} 49
50
Child Controls 71
72
/// <summary> 73
/// 附加子控件 74
/// </summary> 75
protected override void AttachChildControls() 76
{ 77
statusMessage = FindControl("StatusMessage") as StatusMessage; 78
79
noResultsDiv = FindControl("NoResultsDiv") as HtmlControl; 80
listPostsDiv = FindControl("ListPostsDiv") as HtmlControl; 81
searchHint = FindControl("SearchHint") as Literal; 82
postsRepeater = FindControl("PostsRepeater") as Repeater; 83
pager = FindControl("Pager") as Pager; 84
85
if (postsRepeater != null) 86
postsRepeater.ItemDataBound += new RepeaterItemEventHandler(PostsRepeater_ItemDataBound); 87
} 88
89
void Bind() 90
{ 91
PostFullTextQuery query = new PostFullTextQuery(); 92
query.ConvertFromQueryString(); 93
if (query.IsValid()) 94
{ 95
query.PageSize = 10; 96
query.PageIndex = pager.PageIndex; 97
98
SearchResultDataSet<PostSearchItem> pds = PostSearchProvider.Instance().Search(query); 99
postsRepeater.DataSource = pds.Records; 100
postsRepeater.DataBind(); 101
102
if (pds.TotalRecords > 0) 103
{ 104
searchHint.Text = "约有 <span class='stress'>" + pds.TotalRecords + " </span>个文章满足搜索条件,搜索用时 " + pds.SearchDuration + " 秒"; 105
106
pager.TotalRecords = pds.TotalRecords; 107
pager.PageSize = query.PageSize; 108
} 109
else 110
{ 111
noResultsDiv.Visible = true; 112
listPostsDiv.Visible = false; 113
} 114
} 115
else 116
{ 117
listPostsDiv.Visible = false; 118
statusMessage.Visible = true; 119
statusMessage.MessageType = StatusMessageType.Error; 120
statusMessage.Text = "请填写您的搜索条件,再进行搜索"; 121
} 122
} 123
124
private void PostsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 125
{ 126
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 127
{ 128
PostSearchItem item = e.Item.DataItem as PostSearchItem; 129
if (item != null) 130
{ 131
HyperLink subject = e.Item.FindControl("Subject") as HyperLink; 132
if (subject != null) 133
{ 134
subject.Text = item.Subject; 135
if (!ValueHelper.IsNullOrEmpty(item.PostUrl)) 136
{ 137
subject.NavigateUrl = Globals.FullPathForMainSite(item.PostUrl); 138
subject.Attributes["target"] = "_blank"; 139
} 140
} 141
142
Literal body = e.Item.FindControl("Body") as Literal; 143
if (body != null) 144
body.Text = item.Body; 145
146
HyperLink author = e.Item.FindControl("Author") as HyperLink; 147
if (author != null) 148
{ 149
author.Text = item.Author; 150
if (!ValueHelper.IsNullOrEmpty(item.UserProfileUrl)) 151
{ 152
author.NavigateUrl = Globals.FullPathForMainSite(item.UserProfileUrl); 153
author.Attributes["target"] = "_blank"; 154
} 155
} 156
157
Literal lastUpdatedDate = e.Item.FindControl("LastUpdatedDate") as Literal; 158
if (lastUpdatedDate != null) 159
lastUpdatedDate.Text = Formatter.FormatDate(item.LastUpdatedDate); 160
161
HyperLink sectionName = e.Item.FindControl("SectionName") as HyperLink; 162
if (sectionName != null && !ValueHelper.IsNullOrEmpty(item.SectionName)) 163
{ 164
sectionName.Text = item.SectionName; 165
if (!ValueHelper.IsNullOrEmpty(item.SectionUrl)) 166
{ 167
sectionName.NavigateUrl = Globals.FullPathForMainSite(item.SectionUrl); 168
sectionName.Attributes["target"] = "_blank"; 169
} 170
} 171
172
Literal tags = e.Item.FindControl("Tags") as Literal; 173
if (tags != null && item.Tags != null) 174
{ 175
for (int i = 0; i < item.Tags.Length; i++) 176
{ 177
tags.Text += string.Format("<a href='{0}' target='_blank'>{1}</a> ", Globals.FullPathForMainSite(ChannelUrls.Instance().ListWebLogPostsByTag(item.Tags[i])), item.Tags[i]); 178
} 179
} 180
} 181
} 182
} 183
184
} 185
} 186






}