📄 roomoperationform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HotelManagerModels;
using HotelManagerBLL;
namespace HotelManager
{
public partial class RoomOperationForm : Form
{
private int id = 0;
private int i = 0;//根据用户的身份决定控件的显示状态
public static int IsFormOpen = 0;//判断窗体是否打开是使用,0为没打开,1为已打开
RoomOperationBLL bll = new RoomOperationBLL();
RoomBLL roombll = new RoomBLL();
CustomersInfoBLL customerbll = new CustomersInfoBLL();
public RoomOperationForm()
{
IsFormOpen = 1;
InitializeComponent();
}
public RoomOperationForm(int x)
{
i = x;
IsFormOpen = 1;
InitializeComponent();
}
private void RoomOperationForm_Load(object sender, EventArgs e)
{
this.tabPage2.Parent = null;//隐藏退房的子选项卡
panel2.Visible = false;
//服务员登陆,隐藏控件
if (i == 2)
{
txRoomInfo.Visible = false;
}
try
{
//取出房间类型,在根据房间类型取出床位数
RoomTypeBLL rtbll = new RoomTypeBLL();
List<RoomType> list = rtbll.SelectRoomType();
cboRoomType.DataSource = list;
cboRoomType.DisplayMember = "TypeName";
cboRoomType.ValueMember = "TypeID";
cboRoomType.Text = "-----请选择-----";
//根据上面的信息在空房中筛选出适合的房间
List<RoomInfo> list2 = bll.SelectRoomInfoAll();
dgvRoomInfo.DataSource = list2;
//在datagrilview中选中一个房间后,把此房间的详细信息显示在下面的控件上
txtNumber.Text = dgvRoomInfo.CurrentRow.Cells["Number"].Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void BtnYes_Click(object sender, EventArgs e)
{
//判断文本框是否为空
if (txtID.Text.Trim() == "" || txtCName.Text.Trim() == "" || txtCPhone.Text.Trim() == "")
{
MessageBox.Show("请填写完整信息");
return;
}
else
{
try
{
//判断用户是否存在
List<CustomersInfo> list = customerbll.SelectCustomersInfoByID(txtID.Text.ToString());
if (list.Count <= 0)
{
//添加新用户
CustomersInfo c = new CustomersInfo();
c.ID = txtID.Text.ToString();
c.CName = txtCName.Text.ToString();
c.CPhone = txtCPhone.Text.ToString();
CustomersType ct = new CustomersType();
ct.Name = cboCTypeID.Text.ToString();
ct.ID = Convert.ToInt32(cboCTypeID.SelectedValue);
c.Ct = ct;
CustomersInfoBLL cb = new CustomersInfoBLL();
cb.InsertCustomersInfo(c);
}
//查房间编号,方便添加到业务表中
RoomBLL roombll = new RoomBLL();
int roomID = roombll.SelectRoomIDByRoomNumber(txtNumber.Text.ToString());
//用户信息表中,在把住房信息存到业务表中
RoomOperation ro = new RoomOperation();
ro.BeginTime = Convert.ToDateTime(DateTime.Now);
ro.RoomId = roomID;
ro.CIdentityId = txtID.Text.ToString();
ro.Remarks = txtRemark.Text.ToString();
bll.InsertRoomOperation(ro);
//入住时,room的信息状态和人数更改
int guestNumber = Convert.ToInt32(txtGuest.Text);
roombll.UpdateStatusId2ByNumber(txtNumber.Text.ToString(), guestNumber);
//刷新
List<RoomInfo> list2 = bll.SelectRoomInfoAll();
dgvRoomInfo.DataSource = list2;
txtNumber.Text = dgvRoomInfo.CurrentRow.Cells["Number"].Value.ToString();
//文本框清空
txtCName.Text = "";
txtCPhone.Text = "";
txtGuest.Text = "";
txtID.Text = "";
txtRemark.Text = "";
cboCTypeID.Text = "";
txtID.Enabled = true;
txtCName.Enabled = true;
txtCPhone.Enabled = true;
cboCTypeID.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void cboRoomType_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cboBedNumber.Items.Clear();//清空上次的元素
//根据房间类型查询床位数,加到combox集合中
List<int> list = bll.SelectBedNumberByTypeName(cboRoomType.Text.ToString());
foreach (int i in list)
{
cboBedNumber.Items.Add(i);
}
if (list.Count>0)
{
cboBedNumber.Text = "-----请选择-----";
}
else
{
cboBedNumber.Text = "暂时没有空房";
}
//根据选定的房间类型,取出对应的空房间信息
List<RoomInfo> list2 = bll.SelectRoomInfoByRoomType(cboRoomType.Text.ToString());
dgvRoomInfo.DataSource = list2;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void cboBedNumber_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//根据房间床位数,查询空房间信息
List<RoomInfo> list = bll.SelectRoomInfoByBedNumber(cboRoomType.Text.ToString(), Convert.ToInt32(cboBedNumber.Text));
dgvRoomInfo.DataSource = list;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dgvRoomInfo_CellClick(object sender, DataGridViewCellEventArgs e)
{
//在datagrilview中选中一个房间后,把此房间的详细信息显示在下面的控件上,
txtNumber.Text = dgvRoomInfo.CurrentRow.Cells["Number"].Value.ToString();
}
private void txtID_Leave(object sender, EventArgs e)
{
//在填写用户信息,在填身份证时对用户进行判断,存在取出用户信息,不存在,把此用户添加到
//客户信息表中
try
{
//用户存在,显示用户详细信息,并不可修改
List<CustomersInfo> list = customerbll.SelectCustomersInfoByID(txtID.Text.ToString());
if (list.Count > 0)
{
txtID.Text = list[0].ID.ToString();
txtCName.Text = list[0].CName.ToString();
txtCPhone.Text = list[0].CPhone.ToString();
cboCTypeID.Text = list[0].Ct.Name.ToString();
txtID.Enabled = false;
txtCName.Enabled = false;
txtCPhone.Enabled = false;
cboCTypeID.Enabled = false;
}
//不存在,激活控件,供用户填写信息
else
{
CustomersTypeBLL ctBLL = new CustomersTypeBLL();
List<CustomersType> ctlist = ctBLL.SelectCustomersType();
cboCTypeID.DataSource = ctlist;
cboCTypeID.DisplayMember = "Name";
cboCTypeID.ValueMember = "ID";
cboCTypeID.Text = "普通会员";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tsBntEnd_Click(object sender, EventArgs e)
{
this.tabPage1.Parent = null;
this.tabPage2.Parent = this.tabControl1;
tabControl1.SelectedIndex = 1;
panel2.Visible = false;
panInfo.Visible = true;
//退房信息
List<RoomOfExit> l = bll.SelectRoomOperationAll();
dgvRoomOperation.DataSource = l;
}
private void btnExit_Click(object sender, EventArgs e)
{
try
{
//确认是否退出
List<ExitRoomInfo> list = bll.SelectExitRoomInfo(txtExitID.Text.ToString());
if (list.Count <= 0)
{
MessageBox.Show("该房间尚未入住!");
return;
}
else
{
panel2.Visible = true;
panInfo.Visible = false;
//对的房间号
dgvRoomInfo.DataSource = list;
//显示用户入住房间的信息
foreach (ExitRoomInfo er in list)
{
int day = 0;
id = Convert.ToInt32(er.Id);
lblEnumber.Text = er.Number.ToString();
lblEbegintime.Text = er.BeginTime.ToString();
lblEendtime.Text = DateTime.Now.ToString();
string time = (DateTime.Now - er.BeginTime).ToString();
string temp = time.Substring(0, 1);//如果入住不到一天,则按一天计算
if (temp == "0")
{
day = 0;
}
else
{
int index = time.IndexOf(".");//截取整位天数
string t = time.Substring(0, index);
day = Convert.ToInt32(t);
}
lblEdayNum.Text = (day + 1).ToString();//显示入住天数
lblEprice.Text = (er.Price * (day + 1) * er.CDiscount).ToString();//计算价格
lblEname.Text = er.Name.ToString();
lblECid.Text = er.CID.ToString();
lblEctype.Text = er.CustomersType.ToString();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dgvRoomOperation_CellClick(object sender, DataGridViewCellEventArgs e)
{
//选定一行用实体对象封装
//ExitRoomInfo er = (ExitRoomInfo)dgvRoomOperation.CurrentRow.DataBoundItem;
txtExitID.Text = dgvRoomOperation.CurrentRow.Cells[0].Value.ToString();
}
//确定退房
private void button1_Click(object sender, EventArgs e)
{
try
{
//修改退房时间,修改价格
RoomOperation ro = new RoomOperation();
ro.EndTime = Convert.ToDateTime(DateTime.Now.ToString());
ro.ID = id;
ro.TotalPrice = Convert.ToSingle(lblEprice.Text);
bll.UpdateRoomOperation(ro);
//修改房间状态和房间入住人数
RoomBLL roombll = new RoomBLL();
roombll.UpdateStatusId1ByNumber(lblEnumber.Text.ToString(),0);
MessageBox.Show("退房成功!");
panel2.Visible = false;
panInfo.Visible = true;
txtExitID.Text = "";
//刷新退房信息
List<RoomOfExit> l = bll.SelectRoomOperationAll();
dgvRoomOperation.DataSource = l;
//刷新空房信息
List<RoomInfo> list2 = bll.SelectRoomInfoAll();
dgvRoomInfo.DataSource = list2;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
panel2.Visible = false;
panInfo.Visible = true;
}
private void tsBntAdd_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 0;
this.tabPage2.Parent = null;
this.tabPage1.Parent = this.tabControl1;
panel2.Visible = true;
panInfo.Visible = false;
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
//刷新退房信息
List<RoomOfExit> l = bll.SelectRoomOperationAll();
dgvRoomOperation.DataSource = l;
}
private void tsBtnCancel_Click(object sender, EventArgs e)
{
panel2.Visible = false;
panInfo.Visible = true;
}
private void toolStripButton1_Click_1(object sender, EventArgs e)
{
InfoForm f = new InfoForm();
f.Show();
}
private void tsBtnExit_Click(object sender, EventArgs e)
{
IsFormOpen = 0;
}
private void RoomOperationForm_FormClosing(object sender, FormClosingEventArgs e)
{
IsFormOpen = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -