threadadd.cs

来自「ASP.NET简洁论坛源代码 这是一个简单的论坛」· CS 代码 · 共 71 行

CS
71
字号
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 ThreadAdd : UserControl
    {
        protected ValuedTextBox subjectTextBox;
        protected ValuedTextBox tagsTextBox;
        protected ValuedEditor bodyEditor;
        protected ResourceButton saveButton;

        protected override void OnLoad(EventArgs e)
        {
            if (WebContext.Current.User.IsAnonymous)
            {
                Page.Response.Write("<script>window.parent.location='" + SiteUrls.Instance().Login + "'</script>");
                return;
            }
            if (WebContext.Current.SectionId <= 0)
            {
                Globals.ShowMessage(Page, "SectionIdNotExist", "发帖请到小类版块!");
                return;
            }
            saveButton.Click += new EventHandler(SaveThread);
        }

        private void SaveThread(object sender, EventArgs e)
        {
            //检查版块是否存在
            Section section = BusinessManager.GetSection(WebContext.Current.SectionId);
            if (section == null)
            {
                throw new Exception("请确认您所在的版块是存在的。");
            }

            //获取当前帖子
            Thread thread = new Thread();

            //设置帖子属性
            thread.SectionId = WebContext.Current.SectionId;
            thread.Subject = subjectTextBox.Value;
            thread.Body = bodyEditor.Value;
            thread.Tags = tagsTextBox.Value;
            thread.ThreadType = (int)ThreadType.Normal;
            thread.AuthorId = WebContext.Current.User.UserId;
            thread.Author = WebContext.Current.User.UserName;
            thread.CreateDate = DateTime.Now;
            thread.UpdateDate = DateTime.Now;
            thread.TotalViews = 0;

            //添加帖子
            BusinessManager.CreateThread(thread);

            //更新版块回复总数
            section.TotalThreads++;
            BusinessManager.UpdateSection(section);

            //返回列表页面
            Page.Response.Redirect(SiteUrls.Instance().GetThreadsUrl(WebContext.Current.SectionId));

        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?