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

📄 admingbsou.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.Data.SqlClient;
public partial class admingbsou : System.Web.UI.Page
{
	//该源码下载自www.51aspx.com(51aspx.com)

    DataSet ds3 = new DataSet();
    SqlCommand cmd, cmd1, cmd2, cmd3;
    SqlConnection cn;
    SqlDataReader dr, dr1;
    SqlDataAdapter da, da1, da2, da3,da4;
    DataSet ds = new DataSet();
    DataSet ds2 = new DataSet();
    DataSet ds1 = new DataSet();
    DataSet ds4 = new DataSet();
    string strsql, strsql1, strsql2, strsql3, strsql4;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.databindlist();
            if (Session["adminname"] == null)
            {
                Response.Redirect("index.aspx");
            }
        }
    }
    public void databindlist()
    {

        cn = sqldata.createcon();
        cn.Open();
        int countpage = Convert.ToInt32(this.Labelye.Text);
        strsql2 = "select * from guestbook  order by id desc ";
        da2 = new SqlDataAdapter(strsql2, cn);
        da2.Fill(ds2, "Result");
        System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds2.Tables["Result"].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = 6;
        ps.CurrentPageIndex = countpage - 1;
        this.lblPageCount.Text = Convert.ToString(ps.PageCount);

        this.Button1.Enabled = true;
        this.Button2.Enabled = true;

        if (countpage == 1)
        {
            this.Button1.Enabled = false;
        }
        if (countpage == ps.PageCount)
        {
            this.Button2.Enabled = false;
        }

        this.mydatalist.DataSource = ps;
        this.mydatalist.DataBind();

        SqlCommand cmd1 = new SqlCommand("select count(*) from guestbook", cn);
        this.lblRecordCount.Text = Convert.ToString(cmd1.ExecuteScalar());
        sqldata.pagecount = Convert.ToString(ps.PageCount);
        cn.Close();
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        if (this.IsValid)
        {
            if (this.DropDownList1.Text == "留言标题")
            {
               
                cn = sqldata.createcon();
                cn.Open();
                strsql1 = "select*from guestbook where title='" + this.txttitle.Text.ToString() + "'";
                da1 = new SqlDataAdapter(strsql1, cn);
                da1.Fill(ds1);
                this.mydatalist .DataSource = ds1.Tables[(0)].DefaultView;
                this.mydatalist .DataBind();
                if (this.mydatalist .Items.Count == 0)
                {
                    this.Panel1.Visible = false;
                    this.labmessage.Text = "对不起?要找的" + this.txttitle.Text.ToString() + "内容还没有找到";
                    this.HyperLink1.Visible = true;
                }
                else
                {
                    this.Panel1.Visible = true;
                    this.HyperLink1.Visible = true;
                    this.labmessage.Text = "恭喜!要找的" + this.txttitle.Text.ToString() + "内容找到了"; ;
                }
            }
            else if (this.DropDownList1.Text == "姓名")
            {
              
                cn = sqldata.createcon();
                cn.Open();
                strsql = "select*from guestbook where username='" + this.txttitle.Text.ToString() + "'";
                da = new SqlDataAdapter(strsql, cn);
                da.Fill(ds);
                this.mydatalist .DataSource = ds.Tables[(0)].DefaultView;
                this.mydatalist .DataBind();
                if (this.mydatalist.Items.Count == 0)
                {
                    this.Panel1.Visible = false;
                    this.labmessage.Text = "对不起?要找的" + this.txttitle.Text.ToString() + "内容还没有找到";
                    this.HyperLink1.Visible = true;
                }
                else
                {
                    this.Panel1.Visible = true;
                    this.HyperLink1.Visible = true;
                    this.labmessage.Text = "恭喜!要找的" + this.txttitle.Text.ToString() + "内容找到了"; ;
                }
            }
            else if (this.DropDownList1.Text == "系别名称")
            {

                cn = sqldata.createcon();
                cn.Open();
                strsql3 = "select*from guestbook where userxiname='" + this.txttitle.Text.ToString() + "'";
                da3 = new SqlDataAdapter(strsql3, cn);
                da3.Fill(ds3);
                this.mydatalist.DataSource = ds3.Tables[(0)].DefaultView;
                this.mydatalist.DataBind();
                if (this.mydatalist.Items.Count == 0)
                {
                    this.Panel1.Visible = false;
                    this.labmessage.Text = "对不起?要找的" + this.txttitle.Text.ToString() + "内容还没有找到";
                    this.HyperLink1.Visible = true;
                }
                else
                {
                    this.Panel1.Visible = true;
                    this.HyperLink1.Visible = true;
                    this.labmessage.Text = "恭喜!要找的" + this.txttitle.Text.ToString() + "内容找到了"; ;
                }
            }
            else
            {
                cn = sqldata.createcon();
                cn.Open();
                strsql4 = "select*from guestbook where rename='" + this.txttitle.Text.ToString() + "'";
                da4 = new SqlDataAdapter(strsql4, cn);
                da4.Fill(ds4);
                this.mydatalist.DataSource = ds4.Tables[(0)].DefaultView;
                this.mydatalist.DataBind();
                if (this.mydatalist.Items.Count == 0)
                {
                    this.Panel1.Visible = false;
                    this.labmessage.Text = "对不起?要找的" + this.txttitle.Text.ToString() + "内容还没有找到";
                    this.HyperLink1.Visible = true;
                }
                else
                {
                    this.Panel1.Visible = true;
                    this.HyperLink1.Visible = true;
                    this.labmessage.Text = "恭喜!要找的" + this.txttitle.Text.ToString() + "内容找到了"; ;
                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) - 1);
        this.databindlist();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) + 1);
        this.databindlist();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = "1";
        this.databindlist();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {

        this.Labelye.Text = sqldata.pagecount;
        this.databindlist();
    }
    protected void mydatalist_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        LinkButton lkb = (LinkButton)(e.Item.FindControl("LinkButton2"));
        if (lkb != null)
        {
            lkb.Attributes.Add("onclick", "return confirm('您是否删除留言?');");
        }
    }
    protected void LinkButton2_Command(object sender, CommandEventArgs e)
    {
        cn = sqldata.createcon();
        cn.Open();
        cmd = new SqlCommand("delete from guestbook where id=" + e.CommandArgument, cn);
        if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
        {
            this.labmessage.Text = "删除成功!";

        }
        else
        {
            this.labmessage.Text = "删除失败!?";
        }
        cn.Close();
    }
}

⌨️ 快捷键说明

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