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

📄 manageroom.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 manageroom : System.Web.UI.Page
{
    SqlConnection cn;
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Convert.ToString(Session["role"]) == "普通用户")
            {
                Response.Write("<script language='javascript'>alert('非常抱歉!您不是"管理员",不能进入该页面!^_^');window.location.href='Default.aspx'</script>");
            }
            this.databinduserinfo();
        }
    }
    public static string pagecount;
    private void databinduserinfo()
    {
        int countpage = Convert.ToInt32(this.Labelye.Text);
        cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
        cn.Open();
        SqlDataAdapter da = new SqlDataAdapter("select * from room order by id desc", cn);
        da.Fill(ds, "Result");
        System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables["Result"].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = 12;
        ps.CurrentPageIndex = countpage - 1;
        this.lblPageCount.Text = Convert.ToString(ps.PageCount);

        this.Button2.Enabled = true;
        this.Button3.Enabled = true;

        if (countpage == 1)
        {
            this.Button2.Enabled = false;
        }
        if (countpage == ps.PageCount)
        {
            this.Button3.Enabled = false;
        }
        this.gvroominfo.DataSource = ps;
        this.gvroominfo.DataBind();
        //if (this.gvroominfo.Rows.Count == 0)
        //{
        //    this.Panel1.Visible = false;
        //    this.Labmessage.Text = "温馨的提示:还没有会议室,不能进行管理";
        //}
        //else
        //{
        //    this.Panel1.Visible = true;
        //}

        SqlCommand cmd = new SqlCommand("select count(*) from room", cn);
        this.lblRecordCount.Text = Convert.ToString(cmd.ExecuteScalar());
        pagecount = Convert.ToString(ps.PageCount);
        cn.Close();
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow gr in gvroominfo.Rows)
        {
            CheckBox chk = (CheckBox)gr.Cells[4].FindControl("itemchk");
            if (!chk.Checked)
            {
                chk.Checked = true;
            }
            else
            {
                chk.Checked = false;
            }
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = "1";
        this.databinduserinfo();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) - 1);
        this.databinduserinfo();


    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) + 1);
        this.databinduserinfo();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.Labelye.Text = pagecount;
        this.databinduserinfo();

    }
    protected void Btndel_Click(object sender, EventArgs e)
    {
        try
        {
            int intCount = this.gvroominfo.Rows.Count;
            for (int i = 0; i < intCount; i++)
            {
                CheckBox CheckSingle = this.gvroominfo.Rows[i].Cells[4].FindControl("itemchk") as CheckBox;
                if (CheckSingle.Checked)
                {
                    int id = Convert.ToInt32(this.gvroominfo.Rows[i].Cells[0].Text);
                    cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
                    cn.Open();
                    SqlCommand cmd = new SqlCommand("delete from room where id='" + id + "'", cn);
                    cmd.ExecuteNonQuery();
                    this.Labmessage.Text = "删除所选的会议室成功";
                }

            }

            this.databinduserinfo();
        }
        catch
        {
            this.Labmessage.Text = "服务器忙,请一会在试!";

        }
        finally
        {
            cn.Close();
        }
    }
    protected void gvuserinfo_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ffffff';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            this.Btndel.Attributes.Add("onclick", "return confirm('您确认要删除所选的会议室吗?');");
        }

    }
}

⌨️ 快捷键说明

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