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

📄 index.aspx.cs

📁 此留言本对初学者很有参考价值安全性也比较高
💻 CS
字号:
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text.RegularExpressions;

public partial class _index : System.Web.UI.Page
{


    public class lyb {

        string _rq;//日期
        string _xm; //姓名
        string _yx; //邮箱
        string _zy; //主页
        string _qq; //QQ
        string _ly; //留言
        string _lj; //连接字符串
        bool _ubb; //是否使用UBB

        int _xy,_dx,_zs; //当前页,页大小,记录总数


       public lyb() {
            _ubb=true;
            _xy=1;
            _dx=5;
            _zs=0;
            _xm=_yx=_zy=_qq=_ly="";
            _lj = ConfigurationSettings.AppSettings["sjk"];
       }

       //UBB属性
       public bool ubb {
            get {
                 return _ubb;
            }
            set {
                 _ubb=value;
            }
       }


       //日期属性
       public string rq
       {
           get
           {
               return _rq;
           }
           set
           {
               _rq = html(value);
           }
       }

       //姓名属性
       public string xm {
            get {
                return _xm;
            }
            set {
                _xm=html(value);
            }
        }

        //邮箱属性
        public string yx {
            get {
                return _yx;
            }
            set {
                _yx=html(value);
            }
        }

        //主页属性
        public string zy {
            get {
                return _zy;
            }
            set {
                _zy=html(value);
            }
        }

        //QQ属性
        public string qq {
            get {
                return _qq;
            }
            set {
                _qq=html(value);
            }
        }

        //留言属性
        public string ly {
            get {
                return _ly;
            }
            set {
                if(_ubb)
                    _ly=ubbzh(html(value));
                else
                    _ly=html(value);
            }
        }

        //当前页属性
        public int xy {
            get { return _xy; }
            set { _xy=value-1; }
        }

        //页大小属性
        public int dx {
            get { return _dx; }
            set { _dx=value; }
        }

        //记录总数属性,只读
        public int zs {
            get { return _zs; }
        }

        //UBB代码
        string ubbzh(string bl) {
            Random sj = new Random();
            bl=Regex.Replace(bl,"\\[URL\\](.*?)\\[/URL\\]","<a href=\"$1\" target=\"_blank\" title=\"$1\">$1</a>");
            bl=Regex.Replace(bl,"\\[URL=(.*?)\\](.*?)\\[/URL\\]","<a href=\"$1\" target=\"_blank\" title=\"$1\">$2</a>");
            bl=Regex.Replace(bl,"\\[MAIL\\](.*?)\\[/MAIL\\]","<a href=\"mailto:$1\">$1</a>");
            bl=Regex.Replace(bl,"\\[MAIL=(.*?)\\](.*?)\\[/MAIL\\]","<a href=\"mailto:$1\">$2</a>");
            bl=Regex.Replace(bl,"\\[COLOR\\](.*?)\\[/COLOR\\]","<span style=\"color:#"+sj.Next(000000,999999)+";\">$1</span>");
            bl=Regex.Replace(bl,"\\[COLOR=(.*?)\\](.*?)\\[/COLOR\\]","<span style=\"color:$1\">$2</span>");
            bl=Regex.Replace(bl,"\\[MOVE\\](.*?)\\[/MOVE\\]","<marquee>$1</marquee>");
            bl=Regex.Replace(bl,"\\[STRONG\\](.*?)\\[/STRONG\\]","<strong>$1</strong>");
            bl=Regex.Replace(bl,"\\[EM\\](.*?)\\[/EM\\]","<em>$1</em>");
            return bl;
        }

        //还原
        public string hy(string bl) {
            return bl.Replace("<br>","\n").Replace("&lt;","<").Replace("&gt;",">").Replace("&quot;","\"").Replace("&nbsp;"," ").Replace("&","&amp;");
        }
        //还原
        public string hy(object bl) {
            return bl.ToString().Replace("<br>", "\n").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&quot;", "\"").Replace("&nbsp;", " ").Replace("&", "&amp;");
        }

        //编码
        string html(string bl) {
            return HttpContext.Current.Server.HtmlEncode(bl.Replace("'","''")).Replace("\n","<br />");
        }

        //读取留言
        public DataTable dq(int bl) {
            string mlwb="select * from ly order by bh desc";
            if(bl!=0)
                mlwb="select * from ly where bh="+bl;

            SqlConnection lj = new SqlConnection(_lj);
            SqlDataAdapter ml = new SqlDataAdapter(mlwb,lj);
            DataSet sj = new DataSet();
            if(bl!=0)
                ml.Fill(sj);
            else
                ml.Fill(sj,_xy*_dx,_dx,"数据");

            if(sj.Tables[0].Rows.Count>0 && bl!=0) {
                _xm=sj.Tables[0].Rows[0]["xm"].ToString();
                _zy=sj.Tables[0].Rows[0]["zy"].ToString();
                _yx=sj.Tables[0].Rows[0]["yx"].ToString();
                _qq=sj.Tables[0].Rows[0]["qq"].ToString();
                _ly=sj.Tables[0].Rows[0]["ly"].ToString();
            }

            //统计数量
            _zs=tjsl();

            return sj.Tables[0];
        }

        //记录总数
        int tjsl() {
            int fh=0;
            SqlConnection lj = new SqlConnection(_lj);
            SqlCommand ml = new SqlCommand("select count(*) as sl from ly",lj);
            lj.Open();
            fh=(int)ml.ExecuteScalar();
            lj.Close();
            return fh;
        }

        //提交留言
        public int tj() {
            return zx("insert into ly(xm,yx,zy,qq,ly,rq) values('"+_xm+"','"+_yx+"','"+_zy+"','"+_qq+"','"+_ly+"','"+System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")+"')");
        }

        //修改留言
        public int xg(int bh) {
            return zx("update ly set xm='"+_xm+"',yx='"+_yx+"',zy='"+_zy+"',qq='"+_qq+"',ly='"+_ly+"' where bh="+bh);
        }

        //回复留言
        public int hf(int bh) {
            return zx("update ly set hf='"+_ly+"' where bh="+bh);
        }

        //删除留言
        public int sc(int bh) {
            return zx("delete from ly where bh="+bh);
        }

        //执行操作
        int zx(string bl) {
            int fh;
            SqlConnection lj = new SqlConnection(_lj);
            SqlCommand ml = new SqlCommand(bl,lj);
            lj.Open();
            fh=ml.ExecuteNonQuery();
            lj.Close();
            return fh;
        }


        //权限判断
        public bool qx(string yh, string mm)
        {
            bool fh = false;
            string[] yhz = ConfigurationSettings.AppSettings["用户组"].Split('|');
            foreach (string i in yhz)
            {
                string[] xx = i.Split(',');
                if (yh == xx[0] && mm == xx[1])
                {
                    fh = true;
                    break;
                }
                else
                    fh = false;
            }
            return fh;
        }
    }
}

⌨️ 快捷键说明

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