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

📄 addroom.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 AddRoom : System.Web.UI.Page
{
    private RoomOperatorBLL roomOp = new RoomOperatorBLL();
    private RoomTypeOperatorBLL roomTypeOp = new RoomTypeOperatorBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        //不是回发则为首次加载
        if (!Page.IsPostBack && Request.QueryString["id"] != null)
        {
            string id = Request.QueryString["id"].ToString();
            if (!string.IsNullOrEmpty(id))
                SetData(int.Parse(id));
        }
    }

    /// <summary>
    /// 根据编号查询值
    /// </summary>
    private void SetData(int id)
    {
        Room room = roomOp.GetRoomByRoomID(id);
        if (room != null)
        {
            this.txt_Number.Text = room.Roomnumber;
            this.txt_BedNumber.Text = room.Bednumber.ToString();
            this.txt_Description.Text = room.Description;
            this.txt_GuessNumber.Text = room.Guessnumber.ToString();
            this.ddl_State.Text = room.State;
            this.ddl_TypeID.Text = room.TypeId.Typename;
            this.ddl_TypeID.SelectedValue = room.TypeId.Typeid.ToString();
            this.btn_Confirm.Text = "  更  新  ";
            this.btn_Confirm.ToolTip = "更新";
        }
    }
    protected void btn_Confirm_Click(object sender, EventArgs e)
    {
        string number = this.txt_Number.Text;
        string bedNumber = this.txt_BedNumber.Text;
        string description = this.txt_Description.Text;
        string guessNumber = this.txt_GuessNumber.Text;
        string state = ddl_State.SelectedItem.Text;
        string typeName = ddl_TypeID.SelectedItem.Text;

        Room room = new Room();
        room.Roomnumber = number;
        room.Bednumber = int.Parse(bedNumber);
        room.Guessnumber = int.Parse(guessNumber);
        room.Description = description;
        room.State = state;
        RoomType roomType = roomTypeOp.SelectDataForRoomTypeByRoomTypeName(typeName);
        room.TypeId = roomType;

        if (this.btn_Confirm.ToolTip.Equals("确定"))
        {
            if (roomOp.GetRoomIdByRoomNumber(number) != 0)
                lbl_Message.Text = "已经存在的房间号!!";
            else
            {
                if (roomOp.InsertValuesToRoom(room))
                    Response.Redirect("~\\ViewRoom.aspx");
                else
                    Response.Write("<script>alert('添加失败!')</script>");
            }
        }
        else
        {
            string id = Request.QueryString["id"].ToString();
            if (!string.IsNullOrEmpty(id))
                room.Roomid = int.Parse(id);
            if (roomOp.ModifyValuesFormRoom(room))
            {
                Response.Write("<script>alert('修改成功!')</script>");
                Server.Transfer("~\\ViewRoom.aspx");
            }
            else
                Response.Write("<script>alert('修改失败!')</script>");
        }
    }
    protected void ddl_State_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ddl_State.SelectedValue.Equals("空闲"))
        {
            this.txt_GuessNumber.Text = "0";
        }
        else
        {
            this.txt_GuessNumber.Text = "";
        }
    }
}

⌨️ 快捷键说明

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