1
//------------------------------------------------------------------------------
2
// <copyright company="Tunynet">
3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved.
4
// </copyright>
5
//------------------------------------------------------------------------------
6
7
8
using System;
9
using System.Collections.Generic;
10
using System.Text;
11
using System.Web.UI.WebControls;
12
using SpaceBuilder.Utils;
13
using SpaceBuilder.Blogs.Components;
14
using SpaceBuilder.Components;
15
using System.Web.UI;
16
using TunyNet.Data.Utils;
17
using TunyNet.Utils;
18
19
namespace SpaceBuilder.Blogs.Controls
20
...{
21
public class CommentRepeater : Repeater
22
...{
23
private PagingDataSet<BlogPost> pds;
24
25
protected override void OnInit(EventArgs e)
26
...{
27
base.OnInit(e);
28
this.EnableViewState = false;
29
}
30
31
public void Bind()
32
...{
33
this.ItemDataBound += new RepeaterItemEventHandler(CommentsRepeater_ItemDataBound);
34
35
BlogCommentQuery query = new BlogCommentQuery();
36
query.SectionID = this.SectionID;
37
query.ApproveStatus = this.Status;
38
query.SortBy = this.SortBy;
39
query.SortOrder = this.SortOrder;
40
query.PageSize = this.DisplayItemCount;
41
query.IgnorePaging = true;
42
43
pds = BlogPosts.GetComments(query);
44
45
if (pds.Records.Count > 0)
46
...{
47
this.DataSource = this.pds.Records;
48
this.DataBind();
49
}
50
else
51
...{
52
this.DataSource = null;
53
this.DataBind();
54
}
55
}
56
57
protected override void Render(HtmlTextWriter writer)
58
...{
59
this.Bind();
60
if (this.pds.Records.Count > 0)
61
base.Render(writer);
62
}
63
64
事件#region 事件
65
66
protected void CommentsRepeater_ItemDataBound(object Sender, RepeaterItemEventArgs e)
67
...{
68
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
69
...{
70
BlogPost post = e.Item.DataItem as BlogPost;
71
if (post != null)
72
...{
73
BlogThread thread = BlogPosts.GetThread(post.ParentID, false);
74
Weblog blog = Weblogs.GetWeblog(thread.SectionID);
75
76
HyperLink subject = e.Item.FindControl("Subject") as HyperLink;
77
if (subject != null)
78
...{
79
subject.Text = StringUtils.Trim(post.Subject, 14);
80
subject.ToolTip = post.Subject;
81
subject.NavigateUrl = BlogUrls.Instance().ShowPost(thread, blog, post);
82
//subject.Attributes["target"] = "_blank";
83
}
84
85
Label body = e.Item.FindControl("Body") as Label;
86
if (body != null)
87
...{
88
body.Text = HtmlUtils.TrimHtml(post.Body, 50);
89
body.ToolTip = HtmlUtils.TrimHtml(post.Body, 1000);
90
}
91
92
HyperLink author = (HyperLink)e.Item.FindControl("Author");
93
if (author != null)
94
...{
95
//暂时去掉允许用户填写自己的url
96
//if (post.HasTitleUrl)
97
//{
98
// author.NavigateUrl = GlobalUrls.Instance().Redirect(post.TitleUrl);
99
//}
100
//else
101
//{
102
//if (post.UserID != Users.GetAnonymousUser().UserID)
103
// author.NavigateUrl = UserUrls.Instance().UserChannelHome(post.UserID, UserDomainMenuType.Profile);
104
//}
105
106
if (post.UserID != Users.GetAnonymousUser().UserID)
107
author.NavigateUrl = UserUrls.Instance().UserChannelHome(post.UserID, UserDomainMenuType.Profile);
108
109
if (post.BlogPostType == BlogPostType.Comment)
110
...{
111
author.Text = post.Author;
112
author.ToolTip = author.Text;
113
}
114
else if (post.BlogPostType == BlogPostType.Trackback)
115
...{
116
author.Text = post.TrackBackName != null ? post.TrackBackName : "TrackBack";
117
author.Attributes.Add("title", "TrackBack");
118
}
119
}
120
121
Literal postDate = e.Item.FindControl("PostDate") as Literal;
122
if (postDate != null)
123
postDate.Text = Formatter.FormatDate(post.PostDate);
124
}
125
126
}
127
}
128
129
#endregion
130
131
132
属性#region 属性
133
134
//public int SectionID
135
//{
136
// get
137
// {
138
// object state = ViewState["SectionID"];
139
// if (state != null)
140
// return (int)state;
141
// else
142
// return -1;
143
// }
144
// set { ViewState["SectionID"] = value; }
145
//}
146
147
private int sectionID = -1;
148
public int SectionID
149
...{
150
get
151
...{
152
if (sectionID <= 0)
153
sectionID = Weblogs.GetWeblog(SBContext.Current.ApplicationKey).SectionID;
154
155
return sectionID;
156
}
157
set ...{ ViewState["SectionID"] = value; }
158
}
159
160
public ApproveStatus Status
161
...{
162
get
163
...{
164
object state = ViewState["Status"];
165
if (state != null)
166
return (ApproveStatus)state;
167
else
168
return ApproveStatus.IsApproved;
169
}
170
set ...{ ViewState["Status"] = value; }
171
}
172
173
public int DisplayItemCount
174
...{
175
get
176
...{
177
object state = ViewState["DisplayItemCount"];
178
if (state != null)
179
return (int)state;
180
else
181
return 10;
182
}
183
set ...{ ViewState["DisplayItemCount"] = value; }
184
}
185
186
public BlogCommentSortBy SortBy
187
...{
188
get
189
...{
190
object state = ViewState["SortBy"];
191
if (state != null)
192
return (BlogCommentSortBy)state;
193
else
194
return BlogCommentSortBy.PostDate;
195
}
196
set ...{ ViewState["SortBy"] = value; }
197
}
198
199
public SortOrder SortOrder
200
...{
201
get
202
...{
203
object state = ViewState["SortOrder"];
204
if (state != null)
205
return (SortOrder)state;
206
else
207
return SortOrder.Descending;
208
}
209
set ...{ ViewState["SortOrder"] = value; }
210
}
211
#endregion
212
213
}
214
}
215
216
217