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

📄 leaving.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 BLL;
using Model;

public partial class Leaving : System.Web.UI.Page
{
    private RoomOperatorBLL roomOp = new RoomOperatorBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {            
            ///判断如果为Access数据库则要更改数据源的配置
            if (ConfigurationManager.AppSettings["DAL"].Equals("Access"))
                this.ObjectDataSource1.SelectParameters["sql"].DefaultValue = "select RoomId,Numbers,BedNumber,Description,State,GuessNumber,TypeID from Room where State = '入住'";
            GetData();
        }
    }

    /// <summary>
    /// 得到数据
    /// </summary>
    private void GetData()
    {
        if (Session["number"] != null) //如果输入了搜索关键字
        {
            string number = Session["number"].ToString();

            if (roomOp.GetRoomByNumber(number) != null) //并且有结果
            {
                DataTable table = roomOp.GetRoomByNumber(number);

                if (this.GridView1.DataSourceID != "")
                    this.GridView1.DataSourceID = "";
                this.GridView1.DataSource = null;//去除所有的绑定重新绑定
                this.GridView1.DataSource = table.DefaultView;
                this.GridView1.DataBind();
            }
        }
        else//否则没有输入关键字采用默认绑定数据源
        {
            this.GridView1.DataSource = null;//去除所有的绑定重新绑定
            this.GridView1.DataSourceID = "ObjectDataSource1";
            this.GridView1.DataBind();
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        ///判断如果是入住的房间则显示退房,否则不显示
        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            if (i != -1 && i <= this.GridView1.Rows.Count)
            {
                Label state = this.GridView1.Rows[i].FindControl("lbl_State") as Label;
                Button housing = this.GridView1.Rows[i].FindControl("btn_Leaving") as Button;
                if (state != null && housing != null)
                {
                    if (!state.Text.Trim().Equals("入住"))
                        housing.Visible = false;
                }
            }
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {

    }

    /// <summary>
    /// 得到链接路径
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    protected string GetUrl(object temp)
    {
        string num = temp as string;
        string result = string.Empty;
        if (!string.IsNullOrEmpty(num))
        {
            result = "javascript:window.open('LeavingDetails.aspx?roomId="+num+"','','toolbars=0,scrollbars=0,location=0,statusbars=0,menubars=0,resizable=0,width=344,height=333')";
        }
        return result;
    }

    /// <summary>
    /// 截取字符串为指定长度
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    protected string GetSubStr(object temp)
    {
        return GetSubstring.GetSubStr(temp);
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        GetData();//定时重新绑定数据
    }
}

⌨️ 快捷键说明

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