selectroomtype.aspx.cs

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

CS
160
字号

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 SelectRoomType : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["Name"] == null)
            {
                Response.Redirect("Index.aspx");
            }

            if (Session["Status"].ToString() == "普通用户")
            {
                GridView1.Columns[5].Visible = false;
                GridView1.Columns[6].Visible = false;
                GridView2.Columns[5].Visible = false;
                GridView2.Columns[6].Visible = false;
                GridView1.Columns[7].Visible = true;
                GridView2.Columns[7].Visible = true;
            }
            else
            {
                GridView1.Columns[7].Visible = false;
                GridView2.Columns[7].Visible = false;
            }
            MultiView3.ActiveViewIndex = 0;
            Bind();
        }
    }
    /// <summary>
    /// 查询所有
    /// </summary>
    void Bind()
    {
        DataTable dt = RoomTypeBLL.GetRoomTypeByFilter();
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    /// <summary>
    /// 按条件查询
    /// </summary>
    void Bind1()
    {
        DataTable dt = RoomTypeBLL.GetRoomTypeByFilter(txtfilter.Text);
        GridView2.DataSource = dt;
        GridView2.DataBind();
        
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string TypeID = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();
        if (Session["Status"].ToString() == "普通用户")
        {
            Response.Redirect("SelectRoomTypeInfo.aspx?TypeID=" + TypeID);
        }
        else
        {
            Response.Redirect("UpdateRoomType.aspx?TypeID=" + TypeID);
        }
    }

    void Del(int TypeID)
    { 
        if (RoomTypeBLL.GetRoomTypeByRoom_TypeID(TypeID))
        {
            Session["flag"] = "已存在该房间类型的房间,不能删除...要删除请先删除该类型的房间...";
            Response.Redirect("success.aspx");
        }
        else
        {
            RoomTypeEntity RTE = new RoomTypeEntity();
            RTE.TypeID = TypeID;
            if (RoomTypeBLL.DeleteRoomType(RTE) == 1)
            {
                if (MultiView3.ActiveViewIndex == 0)
                    Bind();
                else
                    Bind1();
            }
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }
    protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
    {
        int TypeID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        Del(TypeID);
    }
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string TypeID = GridView2.DataKeys[GridView2.SelectedIndex].Value.ToString();
        if (Session["Status"].ToString() == "普通用户")
        {
            Response.Redirect("SelectRoomTypeInfo.aspx?TypeID=" + TypeID);
        }
        else
        {
            Response.Redirect("UpdateRoomType.aspx?TypeID=" + TypeID);
        }
    }
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        Bind1();
    }
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int TypeID = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value);
        Del(TypeID);
    }

    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 LinkButton12_Click(object sender, EventArgs e)
    {
        MultiView3.ActiveViewIndex = 1;
        Bind1();
    }
    protected void LinkButton13_Click(object sender, EventArgs e)
    {
        MultiView3.ActiveViewIndex = 0;
        Bind();
    }
}

⌨️ 快捷键说明

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