📄 threaddetail.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetFocus.Web.Core;
namespace NetFocus.Web.Applications.Forum
{
public class ThreadDetail : UserControl, IUpdateData
{
protected Repeater list;
protected ExpanderPanel titlePanel;
protected Repeater postList;
protected HiddenField controlIDHidden;
private bool canManagePost = true;
public int ThreadId
{
get
{
object o = ViewState["ThreadId"];
if (o != null)
{
return int.Parse(o.ToString());
}
return 0;
}
set
{
ViewState["ThreadId"] = value;
}
}
public bool CanManagePost
{
get
{
return Convert.ToBoolean(canManagePost);
}
set
{
canManagePost = value;
}
}
protected override void OnLoad(EventArgs e)
{
this.ID = controlIDHidden.Value;
if (!Page.IsPostBack && !AjaxManager.IsCallBack)
{
ThreadId = WebContext.Current.EntityId;
BindData();
}
AjaxManager.Register(this, "AjaxMethod");
}
public void UpdateData()
{
Thread thread = BusinessManager.GetThread(RequestBuilder.BuildThreadRequest(ThreadId)) as Thread;
if (thread != null)
{
titlePanel.Text = thread.Subject;
List<Thread> threads = new List<Thread>();
threads.Add(thread);
list.DataSource = threads;
list.DataBind();
if (postList != null)
{
postList.DataSource = thread.ChildEntities;
postList.DataBind();
}
}
}
public void BindData()
{
Thread thread = BusinessManager.GetThread(RequestBuilder.BuildThreadRequest(ThreadId)) as Thread;
if (thread != null)
{
titlePanel.Text = thread.Subject;
List<Thread> threads = new List<Thread>();
threads.Add(thread);
list.DataSource = threads;
list.DataBind();
if (postList != null)
{
postList.DataSource = thread.ChildEntities;
postList.DataBind();
}
thread.TotalViews++;
Entities.UpdateEntity(thread);
}
}
#region Ajax Method
[AjaxMethod(IncludeControlValuesWithCallBack = false)]
public string SetAsEssence(int threadId)
{
Thread thread = BusinessManager.GetThread(RequestBuilder.BuildThreadRequest(threadId)) as Thread;
if (thread == null)
{
return "您当前要操作的帖子不存在!";
}
if (thread.ThreadType == (int)ThreadType.Wonderful)
{
return "您当前要操作的帖子已经是精华帖子!";
}
thread.ThreadType = (int)ThreadType.Wonderful;
Entities.UpdateEntity(thread);
return "成功将帖子设置为精华帖子!";
}
[AjaxMethod(IncludeControlValuesWithCallBack = false)]
public string SetAsRecommended(int threadId)
{
Thread thread = BusinessManager.GetThread(RequestBuilder.BuildThreadRequest(threadId)) as Thread;
if (thread == null)
{
return "您当前要操作的帖子不存在!";
}
if (thread.ThreadType == (int)ThreadType.Recommended)
{
return "您当前要操作的帖子已经是推荐帖子!";
}
thread.ThreadType = (int)ThreadType.Recommended;
Entities.UpdateEntity(thread);
return "成功将帖子设置为推荐帖子!";
}
[AjaxMethod(IncludeControlValuesWithCallBack = false)]
public void DeletePost(int postId)
{
//BusinessManager.DeletePost(postId);
//Thread thread = BusinessManager.GetThread(RequestBuilder.BuildThreadOnlyRequest(ThreadId)) as Thread;
//if (thread != null)
//{
// thread.TotalPosts--;
// BusinessManager.UpdateThread(thread);
//}
Post post = BusinessManager.GetPost(RequestBuilder.BuildPostRequest(postId));
post.Body = "该回复已被管理员删除";
BusinessManager.UpdatePost(post);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -