⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 很好的一个留言本
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.OleDb;

[AjaxPro.AjaxNamespace("xkziBook")]
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
    }
    private bool isLogin()
    {
        if (Session["logined"] != null)
        {
            if (Convert.ToBoolean(Session["logined"].ToString()))
                return true;
        }
        return false;
    }
    [AjaxPro.AjaxMethod]
    public bool addMsg(string author, string title, string content)
    {
        return WebFunction.ExecuteUpdate("insert into [Topic] (author,addDate,title,content) values ('" + author + "','" + DateTime.Now.ToString() + "','" + title + "','" + content + "')");
    }
    [AjaxPro.AjaxMethod]
    public string msgList(int currentPage)
    {
        OleDbDataReader odr;
        StringBuilder sb = new StringBuilder();
        string sqlStr = string.Empty;
        int countNum = 0;
        int pageSize = 5;
        sqlStr = " from [Topic] where id>0";
        countNum = Convert.ToInt32(WebFunction.ExecuteScalar("select count(id) from [Topic]"));
        if (currentPage > 1)
        {
            sqlStr += " and id not in (select top " + pageSize * (currentPage - 1) + " id from [Topic] order by id desc)";
        }
        sqlStr = "select top " + pageSize + " id,title,author,addDate,content " + sqlStr + " order by id desc";
        odr = WebFunction.dataReader(sqlStr);
        while (odr.Read())
        {
            sb.Append("<dl><dt>" + odr[1].ToString() + "</dt>");
            sb.Append("<dd>作者:" + odr[2].ToString() + " 时间:" + odr[3].ToString() + "</dd>");
            sb.Append("<dd>" + odr[4].ToString() + "</dd></dl>");
            sb.Append("<dl id='msgFoot'><dd><a href='javascript:void(0)' onclick='showReply("+odr[0].ToString()+")'>查看回复</a>");
            if (isLogin())
                sb.Append(" <a href='javascript:void(0)' onclick='delTopic("+odr[0].ToString()+")'>删除</a> <a href='javascript:void(0)' onclick='showReplyBar("+odr[0].ToString()+")'>回复</a>");
            sb.Append("</dd><dd id='reply"+odr[0].ToString()+"' class='reply'></dd></dl>");
        }
        WebFunction.closeDataReader(ref odr);
        sb.Append(WebFunction.PageList(pageSize,"showList",countNum,currentPage));
        return sb.ToString();
    }
    [AjaxPro.AjaxMethod]
    public bool userLogin(string pass)
    {
        if (WebFunction.chkExist("select * from [Config] where pass='" + pass + "'"))
        {
            Session["logined"] = true;
            return true;
        }
        else
        {
            return false;
        }
    }
    [AjaxPro.AjaxMethod]
    public string showReply(int tid)
    {
        StringBuilder sb = new StringBuilder();
        OleDbDataReader odr = WebFunction.dataReader("select addDate,content from [Reply] where topicId=" + tid.ToString());
        if (odr.HasRows)
        {
            while (odr.Read())
            {
                sb.Append("<div class='replyBody'>");
                sb.Append(odr[0].ToString() + "回复:<br>" + odr[1].ToString());
                sb.Append("</div>");
            }
        }
        else
        {
            sb.Append("暂无回复!");
        }
        WebFunction.closeDataReader(ref odr);
        return sb.ToString();
    }
    [AjaxPro.AjaxMethod]
    public string showReplyBar(int tid)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<div id='replyMsg" + tid.ToString() + "'></div><textarea id='replyContent" + tid.ToString() + "' cols='40' rows='4'></textarea><br><input type='button' onclick='addReply(" + tid.ToString() + ")' value='发表回复'>");
        return sb.ToString();
    }
    [AjaxPro.AjaxMethod]
    public bool addReply(int tid, string content)
    {
        if (isLogin())
            return WebFunction.ExecuteUpdate("insert into [Reply] (topicId,addDate,content) values (" + tid.ToString() + ",'" + DateTime.Now.ToString() + "','" + WebFunction.safeForm(content) + "')");
        else
            return false;
    }
    [AjaxPro.AjaxMethod]
    public bool delTopic(int tid)
    {
        if (isLogin())
        {
            WebFunction.ExecuteUpdate("delete * from [Topic] where id=" + tid.ToString());
            WebFunction.ExecuteUpdate("delete * from [Reply] where topicId=" + tid.ToString());
            return true;
        }
        else
            return false;
    }
    [AjaxPro.AjaxMethod]
    public bool logOut()
    {
        if (isLogin())
        {
            Session["logined"] = false;
            return true;
        }
        else
            return false;
    }
}

⌨️ 快捷键说明

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