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

📄 index.aspx.cs

📁 三层班级留言本源码 用VS2005写的,对于其中没有太多的技术含量, 但是还是蛮有参考价值的. 后台数据库的读写采用三层架构,没有专业的后台管理程序,所有操作都是同一个页面上进行. 如果
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.IO;
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 UserInfoLib;


public partial class index : System.Web.UI.Page
{   
    private void BindToDataGrid()
    {
        DataSet table = UserInfo.Sele();

        DataView dv = table.Tables[0].DefaultView;

        dv.Sort = "TextID DESC";

        this.DataGrid1.DataSource = dv;
        int i = UserInfo.CountTextSum();
        this.Label1.Text = i.ToString();
        this.Label3.Text = this.Application["SumConunt"].ToString();
        this.Label2.Text = this.Application["CountUser"].ToString();
        this.Label4.Text = UserInfo.SeleGG();
        this.DataGrid1.DataBind();
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {           
            //B
            Image10.Attributes.Add("onclick", "LinkImage(1);");
            //U
            Image2.Attributes.Add("onclick", "LinkImage(2);");
            //EMAIL
            Image6.Attributes.Add("onclick", "LinkImage(3);");           
            //CENTER
            Image8.Attributes.Add("onclick", "LinkImage(4);");
            //LINK
            Image3.Attributes.Add("onclick", "LinkImage(5);");
            //IMAGE
            Image4.Attributes.Add("onclick", "LinkImage(6);");

            Image0.Attributes.Add("onclick", "LinkFace('[/呲牙]');");
            Image7.Attributes.Add("onclick", "LinkFace('[/微笑]');");
            Image9.Attributes.Add("onclick", "LinkFace('[/偷笑]');");
            Image11.Attributes.Add("onclick", "LinkFace('[/害羞]');");
            Image12.Attributes.Add("onclick", "LinkFace('[/色]');");
            Image13.Attributes.Add("onclick", "LinkFace('[/调皮]');");
            Image14.Attributes.Add("onclick", "LinkFace('[/大兵]');");
            Image15.Attributes.Add("onclick", "LinkFace('[/饥饿]');");
            Image16.Attributes.Add("onclick", "LinkFace('[/睡]');");
            Image17.Attributes.Add("onclick", "LinkFace('[/惊讶]');");
            Image18.Attributes.Add("onclick", "LinkFace('[/疑问]');");
            Image19.Attributes.Add("onclick", "LinkFace('[/咒骂]');");
            Image20.Attributes.Add("onclick", "LinkFace('[/大哭]');");
            Image21.Attributes.Add("onclick", "LinkFace('[/抓狂]');");
            Image22.Attributes.Add("onclick", "LinkFace('[/流汗]');");
            Image23.Attributes.Add("onclick", "LinkFace('[/衰]');");
            Image24.Attributes.Add("onclick", "LinkFace('[/难过]');");
            Image25.Attributes.Add("onclick", "LinkFace('[/敲打]');");
            Image26.Attributes.Add("onclick", "LinkFace('[/发怒]');");
            Image27.Attributes.Add("onclick", "LinkFace('[/尴尬]');");
            Image28.Attributes.Add("onclick", "LinkFace('[/困]');");
            Image29.Attributes.Add("onclick", "LinkFace('[/嘘]');");
            Image30.Attributes.Add("onclick", "LinkFace('[/晕]');");
            Image31.Attributes.Add("onclick", "LinkFace('[/折磨]');");
            Image32.Attributes.Add("onclick", "LinkFace('[/骷髅]');");
            Image33.Attributes.Add("onclick", "LinkFace('[/再见]');");
            Image34.Attributes.Add("onclick", "LinkFace('[/得意]');");
            Image35.Attributes.Add("onclick", "LinkFace('[/奋斗]');");
            Image36.Attributes.Add("onclick", "LinkFace('[/玫瑰]');");
            Image37.Attributes.Add("onclick", "LinkFace('[/猪头]');");
            Image38.Attributes.Add("onclick", "LinkFace('[/吻]');");
            Image39.Attributes.Add("onclick", "LinkFace('[/爱心]');");
            Image40.Attributes.Add("onclick", "LinkFace('[/心碎]');");
            Image41.Attributes.Add("onclick", "LinkFace('[/电话]');");
            Image42.Attributes.Add("onclick", "LinkFace('[/邮件]');");
            Image43.Attributes.Add("onclick", "LinkFace('[/强]');");
            Image44.Attributes.Add("onclick", "LinkFace('[/弱]');");
            Image45.Attributes.Add("onclick", "LinkFace('[/握手]');");
            Image46.Attributes.Add("onclick", "LinkFace('[/胜利]');");
            Image47.Attributes.Add("onclick", "LinkFace('[/礼物]');");
            Image48.Attributes.Add("onclick", "LinkFace('[/蛋糕]');");
            Image49.Attributes.Add("onclick", "LinkFace('[/钱]');");
            
            this.Image1.ImageUrl = "MAC.aspx";
            BindToDataGrid();
            if (this.Session["Root"] == null)
            {
                this.PanelTwo.Visible = false;
                this.PanelOne.Visible = true;
                this.ButtonSend.Enabled = false;
                this.FileUpload1.Visible = false;
                this.LinkButtonInsert.Visible = false;
            }
            else
            {
                this.PanelTwo.Visible = true;
                this.PanelOne.Visible = false;
                this.ButtonSend.Enabled = true;
                this.FileUpload1.Visible = true;
                this.LinkButtonInsert.Visible = true;
            }
           
            CleaALL();
        }        
    }   

    private void CleaALL()
    {
        this.TextBoxTitle.Text = null;
        this.TextBoxBody.Text = null;
        this.TextBoxMAC.Text = null;
        this.TextBoxUsername.Text = null;
        this.TextBoxPassword.Text = null;
        
    }
    //添加记录
    protected void ButtonSend_Click(object sender, EventArgs e)
    {
        if (this.TextBoxMAC.Text == Session["ValidateCode"].ToString()
            && this.TextBoxTitle.Text != "" && this.TextBoxBody.Text != "")
        {
            UserInfo user = new UserInfo();

            user.UserTitle = this.TextBoxTitle.Text;
            user.UserText = this.TextBoxBody.Text;
            user.UserName = this.Session["User"].ToString();
            user.Time = DateTime.Now;
            int rows = user.InsertText();

            if (rows == 1)
            {
                this.Response.Write("<script>alert('添加留言成功!');</script>");
                CleaALL();
            }
            BindToDataGrid();
        }
        else
        {
            this.Response.Write("<script>alert('输入出错!');</script>");
        }        
        
    }
    protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
        BindToDataGrid();
    }
    //重置
    protected void ButtonExit_Click(object sender, EventArgs e)
    {
        this.TextBoxUsername.Text = "";
        this.TextBoxPassword.Text = "";
    }
    //登陆
    protected void ButtonLogin_Click(object sender, EventArgs e)
    {

        UserInfo user = new UserInfo();
        user.UserName = this.TextBoxUsername.Text;
        user.UserPassword = this.TextBoxPassword.Text;
        string Root = user.UserRoot();
        if (Root != "0")
        {
            this.PanelOne.Visible = false;
            this.PanelTwo.Visible = true;
            if (Root == "1")
            {
                this.TextBox1.Visible = true;
                this.Button2.Visible = true;
            }
            else
            {
                this.TextBox1.Visible = false;
                this.Button2.Visible = false;
            }
            this.LabelUserInfo.Text = this.TextBoxUsername.Text;
            this.ButtonSend.Enabled = true;
            this.Session["Root"] = Root;
            this.Session["User"] = this.TextBoxUsername.Text;
            this.FileUpload1.Visible = true;
            this.LinkButtonInsert.Visible = true;
        }
        else
        {
            this.Response.Write("<script>alert('用户名密码错误!');</script>");
        }
        BindToDataGrid();
        this.CleaALL();

    }
    //修改密码
    protected void ButtonModifyPass_Click(object sender, EventArgs e)
    {               
        this.Response.Write("<script>window.open('ModifyPass.aspx','_blank','toolbar=no,width=390,height=200,status=no,scrollbars=no,resizable=no,menubar=no');</script>");

    }
    //注册
    protected void ButtonLoginone_Click(object sender, EventArgs e)
    {
        this.Server.Transfer("AddUser.aspx");
    }
    //
    protected void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        if (e.CommandName == "Jump")
        {
            this.Session["TitleID"] = ((Label)e.Item.Cells[0].FindControl("LabelTitle")).Text;
            this.Response.Redirect("body.aspx");
        }
        else if (e.CommandName == "TextIDdele")
        {
            if ((Session["User"] != null) && (Session["Root"] != null) && (Session["Root"].ToString()) != "0")
            {
                UserInfo user = new UserInfo();
                user.TextID = int.Parse(((Label)e.Item.Cells[0].FindControl("LabelTitle")).Text);
                user.DeleText();
            }
        }
        else if (e.CommandName == "点击回复")
        {
            if ((Session["User"] != null) && (Session["Root"] != null) && (Session["Root"].ToString()) != "0")
            {
                Session["TextID"] = int.Parse(((Label)e.Item.Cells[0].FindControl("LabelTitle")).Text);
                this.Response.Write("<script>window.open('AddBack.aspx ','_blank','toolbar=no,width=490,height=260,status=no,scrollbars=no,resizable=no,menubar=no');</script>");
            }
            else
            {
                this.Response.Write("<script>alert('请登陆后再回复!查看留言点击标题!');</script>");
            }
        }
        BindToDataGrid();
    }
    protected void DataGrid1_PageIndexChanged1(object source, DataGridPageChangedEventArgs e)
    {
        this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
        BindToDataGrid();
    }
    protected void DataGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Session.Remove("Root");
        this.Session.Remove("User");
        this.Session.Remove("TitleID");
        this.PanelTwo.Visible = false;
        this.PanelOne.Visible = true;
        this.ButtonSend.Enabled = false;
        this.FileUpload1.Visible = false;
        this.LinkButtonInsert.Visible = false;
        CleaALL();
        BindToDataGrid();
    }
    //排序
    protected void DataGrid1_SortCommand(object source, DataGridSortCommandEventArgs e)
    {

    }
    public string BackSum(int i)
    {
        string str = null;
        if (i != 0)
        {
            str = "已有" + i.ToString() + "条回复!";
        }
        return str;
    }
    //上载图片
    protected void ImageButton9_Click(object sender, ImageClickEventArgs e)
    {
        this.Server.Transfer("AddImage.aspx");
        this.Session["body"] = this.TextBoxBody.Text;
    }
    protected void LinkButtonInsert_Click(object sender, EventArgs e)
    {
        string[] FileName = this.FileUpload1.FileName.Split('.');

        if (FileName[FileName.Length - 1].ToLower() == "jpg" || FileName[FileName.Length - 1].ToLower() == "jpeg"
                || FileName[FileName.Length - 1].ToLower() == "gif" || FileName[FileName.Length - 1].ToLower() == "bmp")
        {
            try
            {
                this.FileUpload1.SaveAs(this.Server.MapPath("bodyImages") + "\\" + Path.GetFileName(this.FileUpload1.PostedFile.FileName));
                this.TextBoxBody.Text = this.TextBoxBody.Text + "<br><img-src=bodyImages/" + Path.GetFileName(this.FileUpload1.PostedFile.FileName) + "><br>";
            }
            catch
            {
                this.Response.Write("<script>alert('图片路径不对!');</script>");
            }
        }
        else
        {
            this.Response.Write("<script>alert('您的图片格式不对');</script>");
            return;
        }


    }
    protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
    {
        
    }
    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if ((Session["User"] != null) && (Session["Root"] != null) && (Session["Root"].ToString()) == "1")
            {
                Button ButtonDele = (Button)e.Item.Cells[0].FindControl("ButtonDele");
                ButtonDele.Visible = true;
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        UserInfo user = new UserInfo();
        user.UserText = this.TextBox1.Text;
        user.UpdateGG();
    }
}

⌨️ 快捷键说明

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