📄 reservation.aspx.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;
public partial class reservation : System.Web.UI.Page
{
//private int test;
private ReservationOperater oper;
public reservation()
{
oper = new ReservationOperater();
oper.initDB();
}
protected void Page_Load(object sender, EventArgs e)
{
/*
if (ViewState["Isgroup"]!=null&&(bool)ViewState["isgroup"]==true)
{
DropDownList1.Visible = true;
// DropDownList1.SelectedIndex = (int)ViewState["groupName"];
TextBox1.Visible = false;
}
* */
DropDownList1.EnableViewState = true;
CheckBox1.EnableViewState = true;
if (CheckBox1.Checked == false)
{
DropDownList1.Visible = false;
TextBox1.Visible = true;
}
else
{
DropDownList1.Visible = true;
TextBox1.Visible = false;
}
CheckBox1.AutoPostBack = true;
Response.RedirectLocation = Table1.TemplateSourceDirectory;
FindAvailableRoom();
/*
for (int i = Table1.Rows.Count; i > 1; i--)
{
string room = Table1.Rows[i - 1].Cells[0].Text;
if (ViewState[room] != null&&(bool)ViewState[room]==true)
{
((CheckBox)(Table1.Rows[i - 1].Cells[3]).Controls[0]).Checked = true;
//Table1.Focus();
}
}
*/
}
//提交
protected void LinkButton1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
if (CheckBox1.Checked == true)
name = DropDownList1.Text;
string contact = TextBox3.Text;
string starttime = TextBox4.Text+" "+TextBox6.Text;
string endtime = TextBox5.Text+" "+TextBox7.Text;
int ischecked =((CheckBox1.Checked==true) ? 1:0);
string isgroup = ischecked.ToString();
//string engaged = "0";//不知道这个东西是什么意思..
string memo = TextBox8.Text;
if (name == ""||contact==""||starttime==""||endtime=="")
{
TextBox2.Visible = true;
TextBox2.Text = "预定信息不完整!";
return;
}
int roomCount = Table1.Rows.Count ;
if (roomCount == 1)
{
TextBox2.Visible = true;
TextBox2.Text = "客满!";
return;
}
bool ok = true;
ArrayList roomList = getRoomList();
if(roomList.Count==0)
{
TextBox2.Visible = true;
TextBox2.Text = " 您还没选房间呢!!";
return;
}
//增加一条定单记录
int id=oper.InsertAnOrder(name, contact, starttime, endtime, isgroup, memo);
if (id < 0)
{
ok = false;
return;
}
//增加定房间信息
foreach(string room in roomList)
ok &= oper.orderARomm(room,id);
if (ok == false)
{
TextBox2.Visible = true;
TextBox2.Text = oper.errorMessage;
}
else
{
TextBox2.Visible = false;
try
{
Response.Redirect("successPage.aspx", true);
}
catch (HttpException exp)
{
TextBox2.Visible = true;
TextBox2.Text = exp.Message;
return;
}
}
}
/// <summary>
/// 获取定的房间列表
/// </summary>
/// <returns></returns>
protected ArrayList getRoomList()
{
ArrayList roomlist=new ArrayList();
int count = Table1.Rows.Count-1;
if (count == 0)
return null;
for (int i = count; i > 0; i--)
{
if (((CheckBox)Table1.Rows[i].Cells[3].Controls[0]).Checked == true)
{
roomlist.Add(Table1.Rows[i].Cells[0].Text);
}
}
return roomlist;
}
/// <summary>
/// 选离开日期
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
//test = 100;
DateTime endday=Calendar2.SelectedDate;
TextBox5.Text =endday.Year+"-"+endday.Month+"-"+endday.Day;
TextBox7.Text = Calendar2.SelectedDate.TimeOfDay.ToString();
if (TextBox4.Text != "")
{
FindAvailableRoom();
}
}
/// <summary>
/// 寻找可用房间
/// </summary>
void FindAvailableRoom()
{
string startTime=TextBox4.Text+" "+TextBox6.Text;
string endTime=TextBox5.Text+" "+TextBox7.Text;
if (startTime == " " || endTime == " ")
return;
ArrayList availableroom = oper.GetAvailableRoom(startTime,endTime);
//只留第一行标签项目
for (int i = Table1.Rows.Count; i > 1; i--)
{
if (i > 1)
{
Table1.Rows.RemoveAt(i - 1);
}
}
string Groupname="";
if(CheckBox1.Checked==true)
Groupname = DropDownList1.Text;
double group_discount;
foreach (HotelRoomInfo aRoom in availableroom)
{
TableRow arow = new TableRow();
Table1.Rows.Add(arow);
TableCell roomNOCell = new TableCell();
roomNOCell.Text = aRoom.roomNO.ToString();
arow.Cells.Add(roomNOCell);
TableCell roomtypeCell = new TableCell();
roomtypeCell.Text = aRoom.roomtype;
arow.Cells.Add(roomtypeCell);
TableCell priceCell = new TableCell();
group_discount = oper.GetGroupDiscount(Groupname);
priceCell.Text = ((aRoom.roomPrice)*(group_discount)).ToString();
arow.Cells.Add(priceCell);
TableCell checkBoxCell = new TableCell();
CheckBox thecheckbox = new CheckBox();
thecheckbox.EnableViewState = true;
//thecheckbox.CheckedChanged += new EventHandler(thecheckbox_CheckedChanged);
//thecheckbox.AutoPostBack = true;
thecheckbox.ToolTip = roomNOCell.Text;
checkBoxCell.Controls.Add(thecheckbox);
arow.Cells.Add(checkBoxCell);
arow.EnableViewState = true;
//form1.Controls.Add(checkBoxCell);
//Table1.Rows.Add(arow);
}
}
/// <summary>
/// 选房间
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void thecheckbox_CheckedChanged(object sender, EventArgs e)
{
/*
CheckBox mysender = (CheckBox)sender;
if (mysender.Checked == true)
{
ViewState[mysender.ToolTip] = true;
return;
}
if (mysender.Checked == false)
{
ViewState[mysender.ToolTip] = false;
return;
}
* */
}
/// <summary>
/// 选入住日期
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime startday = Calendar1.SelectedDate;
TextBox4.Text = startday.Year + "-" + startday.Month + "-" + startday.Day;
TextBox6.Text = Calendar1.SelectedDate.TimeOfDay.ToString();
if (TextBox5.Text !="")
{
if (TextBox4.Text != null)
{
FindAvailableRoom();
}
}
}
protected void Table1_Disposed(object sender, EventArgs e)
{
}
/// <summary>
/// 是否团体按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
CheckBox mysender = (CheckBox)sender;
if (mysender.Checked == false)
{
DropDownList1.Visible = false;
TextBox1.Visible = true;
}
else
{
TextBox1.Visible = false;
DropDownList1.Visible = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -