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






}