selectroominfo.aspx.cs

来自「酒店管理系统(三层开发)源码 管理员的功能: 客房类型管理(编辑房间类型、删除房」· CS 代码 · 共 211 行

CS
211
字号
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using Entity;

public partial class SelectRoom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["Name"] == null)
            {
                Response.Redirect("Index.aspx");
            }
            if (!string.IsNullOrEmpty(Request.QueryString["TypeName"]))
            {
                MultiView4.ActiveViewIndex = 1;
                Bind2();
            }
            else
            {
                MultiView4.ActiveViewIndex = 0;
                Bind();
            }
            if (Session["Status"].ToString() == "普通用户")
            {
                GridView1.Columns[7].Visible = false;
                GridView1.Columns[8].Visible = false;
                GridView2.Columns[7].Visible = false;
                GridView2.Columns[8].Visible = false;
                GridView1.Columns[9].Visible = true;
                GridView2.Columns[9].Visible = true;
            }
            else
            {
                GridView1.Columns[9].Visible = false;
                GridView2.Columns[9].Visible = false;
            }
        }
    }



    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
    /// <summary>
    /// 查询所有
    /// </summary>
    void Bind()
    {
        DataTable dt = RoomBLL.GetRoomByFilter();
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    /// <summary>
    /// 按条件查询
    /// </summary>
    void Bind1()
    {
        DataTable dt = RoomBLL.GetRoomByFilter(ddl.Text, txtnumber.Text);
        GridView2.DataSource = dt;
        GridView2.DataBind();
    }

    void Bind2()
    {
        string filter = ddl.Text;
        if (!string.IsNullOrEmpty(Request.QueryString["TypeName"]))
        {
            filter = Request.QueryString["TypeName"].ToString();
        }
        DataTable dt = RoomBLL.GetRoomByFilter(filter, txtnumber.Text);
        GridView2.DataSource = dt;
        GridView2.DataBind();
    }

    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        string RoomID = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();
        if (Session["Status"].ToString() == "普通用户")
        {
            Response.Redirect("BookOnLine.aspx?RoomID=" + RoomID);
        }
        else
        {
            string State = RoomBLL.GetStateByRoomID(Convert.ToInt32(RoomID));
            if (State == "入住" || State == "已预订")
            {
                Session["flag"] = "该房间以有人住或已预订,不能编辑...";
                Response.Redirect("success.aspx");
            }
            else
            {
                Response.Redirect("UpdateRoomInfo.aspx?RoomID=" + RoomID);
            } // get
            //Server.Transfer("") // post
        }
    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string RoomID = GridView2.DataKeys[GridView2.SelectedIndex].Value.ToString();
        if (Session["Status"].ToString() == "普通用户")
        {
            Response.Redirect("BookOnLine.aspx?RoomID=" + RoomID);
        }
        else
        {
            string State = RoomBLL.GetStateByRoomID(Convert.ToInt32(RoomID));
            if (State == "入住" || State == "已预订")
            {
                Session["flag"] = "该房间以有人住或已预订,不能编辑...";
                Response.Redirect("success.aspx");
            }
            else
            {
                Response.Redirect("UpdateRoomInfo.aspx?RoomID=" + RoomID);
            }
        }
    }
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        Bind1();
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        
        int RoomID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        Del(RoomID);
    }
    protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }

    void Del(int RoomID)
    { 
        string State = RoomBLL.GetStateByRoomID(RoomID);
        if (State == "入住" || State == "已预订")
        {
            Session["flag"] = "该房间已有人住或已预订,不能删除...";
            Response.Redirect("success.aspx");
        }
        else
        {
            RoomEntity RE = new RoomEntity();
            RE.RoomID = RoomID;
            if (RoomBLL.DeleteRoom(RE) != 1)
            {
                
            }
            else
            {
                if (MultiView4.ActiveViewIndex == 0)
                    Bind();
                else
                    Bind1();
            }
        }
    }

    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int RoomID = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value);
        Del(RoomID);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "current=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=current");
        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "current=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=current");
        }
    }
    protected void LinkButton13_Click(object sender, EventArgs e)
    {
        MultiView4.ActiveViewIndex = 1;
        Bind1();
    }
    protected void LinkButton14_Click(object sender, EventArgs e)
    {
        MultiView4.ActiveViewIndex = 0;
        Bind();
    }
}

⌨️ 快捷键说明

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