相信做了这么多小项目了,我们分析题的能力有了吧,接下来我们先来看看这个项目的需求
(1)该软件系统能涵盖酒店现有的房间入住服务业务
(2)让顾客可以查询酒店提供的房间类型,价位和空闲房间的信息,从而减少顾客和前台的沟通时间成本
案例覆盖技能点:
(1)分层开发思想(2)搭建三层架构(3)ADO.NET中存储过程的使用(4)实体类的使用(5)异常处理
问题分析:
(1)房间入住登记的功能(2)基础信息的维护功能(3)入住查看功能(4)退房功能(5)房间状态查看功能
先看看效果:
房间管理效果图:
顾客入住登记效果图:
查看入住和退房效果图:
分析完这个,你的脑袋里有没有一个简单的图,接下来要开始写代码了。
首先创建实体类
/// <summary> /// 房间信息 Model /// </summary> public class GuestRecord { private int guestID; //顾客的ID public int GuestID { get { return guestID; } set { guestID = value; } } private string identityID;//身份证号 public string IdentityID { get { return identityID; } set { identityID = value; } } private string guestName;//顾客姓名 public string GuestName { get { return guestName; } set { guestName = value; } } private int roomID; //房间ID public int RoomID { get { return roomID; } set { roomID = value; } } private int resideID; //入住状态ID public int ResideID { get { return resideID; } set { resideID = value; } } private DateTime resideDate; //入住日期 public DateTime ResideDate { get { return resideDate; } set { resideDate = value; } } private DateTime leaveDate; //退房日期 public DateTime LeaveDate { get { return leaveDate; } set { leaveDate = value; } } private decimal deposit; //押金 public decimal Deposit { get { return deposit; } set { deposit = value; } } private decimal totalMoney; //房款 public decimal TotalMoney { get { return totalMoney; } set { totalMoney = value; } } }
/// <summary> /// 入住状态Model /// </summary> public class ResideState { private int resideId; //房间状态ID public int ResideId { get { return resideId; } set { resideId = value; } } private string resideName; //入住状态 public string ResideName { get { return resideName; } set { resideName = value; } } }
/// <summary> /// 房间信息描述Model /// </summary> public class Room { private int roomID; public int RoomID { get { return roomID; } set { roomID = value; } } private int bedNum; public int BedNum { get { return bedNum; } set { bedNum = value; } } private string description; public string Description { get { return description; } set { description = value; } } private int roomStateID; public int RoomStateID { get { return roomStateID; } set { roomStateID = value; } } private int guestNum; public int GuestNum { get { return guestNum; } set { guestNum = value; } } private int roomTypeID; public int RoomTypeID { get { return roomTypeID; } set { roomTypeID = value; } } }
/// <summary> /// 房间状态 Model /// </summary> public class RoomState { private int roomStateID; public int RoomStateID { get { return roomStateID; } set { roomStateID = value; } } private string roomStateName; public string RoomStateName { get { return roomStateName; } set { roomStateName = value; } } }
/// <summary> /// 房间类型 Model /// </summary> public class RoomType { private int typeID; public int TypeID { get { return typeID; } set { typeID = value; } } private string typeName; public string TypeName { get { return typeName; } set { typeName = value; } } private decimal typePrice; public decimal TypePrice { get { return typePrice; } set { typePrice = value; } } }
数据访问层DAL:
/// <summary> /// 房间信息访问层 /// </summary> public class GuestRecordDAL { //添加客户信息 public bool IGuest(GuestRecord guest) { bool flag = false; string sql = "usp_insertGuestRecord"; CommandType type = CommandType.StoredProcedure; SqlParameter[] paras = { new SqlParameter("@identityID",guest.IdentityID), new SqlParameter("@guestName",guest.GuestName), new SqlParameter("@roomID",guest.RoomID), new SqlParameter("@ResideDate",guest.ResideDate), new SqlParameter("@deposit",guest.Deposit) }; int count = SQLHelper.ExecuteNonQuery(sql, type, paras); if (count > 0) { flag = true; } return flag; } //查询信息 public DataTable SRoom() { string sql = @"select GuestId,GuestName,IdentityId,ResideDate,Deposit,ResideName,LeaveDate,TotalMoney,RoomStateName,GuestNum,TypePrice from GuestRecord,Room,RoomState,ResideState,RoomType where GuestRecord.ResideID=ResideState.ResideID and GuestRecord.Roomid=Room.roomid and Room.RoomTypeId=RoomType.TypeId and room.RoomStateID=RoomState.RoomStateId"; DataTable table = SQLHelper.ExecuteDataTable(sql); return table; } //根据条件查询 public DataTable SRoom(string time1, string time2,int resideid) { string sql = @"select GuestId,GuestName,IdentityId,ResideDate,Deposit,ResideName,LeaveDate,TotalMoney,RoomStateName,GuestNum,TypePrice from GuestRecord,Room,RoomState,ResideState,roomType where GuestRecord.ResideID=ResideState.ResideID and GuestRecord.Roomid=Room.roomid and Room.RoomTypeId=RoomType.TypeId and room.RoomStateID=RoomState.RoomStateId and ResideDate between '" + time1+ "' and '" + time2 + "' and GuestRecord.Resideid="+resideid+" "; DataTable table = SQLHelper.ExecuteDataTable(sql); return table; } //修改客户的房间信息 public bool URoom(GuestRecord guest) { bool flag = false; string sql = "refund_Room"; CommandType type = CommandType.StoredProcedure; SqlParameter[] paras = { new SqlParameter("@GuestID",guest.GuestID), new SqlParameter("@requirePay",guest.TotalMoney), new SqlParameter("@LeaveDate",guest.LeaveDate) }; int count= SQLHelper.ExecuteNonQuery(sql,type,paras); if(count>0) { flag = true; } return flag; } }
一个工具类:
public class MyTool { /// <summary> /// DataSetToList /// </summary> /// <typeparam name="T">转换类型</typeparam> /// <param name="dataSet">数据源</param> /// <param name="tableIndex">需要转换表的索引</param> /// <returns></returns> public List<T> DataTableToList<T>(DataTable dt) { //确认参数有效 if (dt == null ) return null; List<T> list = new List<T>(); for (int i = 0; i < dt.Rows.Count; i++) { //创建泛型对象 T _t = Activator.CreateInstance<T>(); //获取对象所有属性 PropertyInfo[] propertyInfo = _t.GetType().GetProperties(); for (int j = 0; j < dt.Columns.Count; j++) { foreach (PropertyInfo info in propertyInfo) { //属性名称和列名相同时赋值 if (dt.Columns[j].ColumnName.ToUpper().Equals(info.Name.ToUpper())) { if (dt.Rows[i][j] != DBNull.Value) { info.SetValue(_t, dt.Rows[i][j], null); } else { info.SetValue(_t, null, null); } break; } } } list.Add(_t); } return list; } }
/// <summary> /// 入住状态访问层 /// </summary> public class ResideStateDAL { //查询房间入住状态 public DataTable SRoom() { string sql = "select * from ResideState"; DataTable table = SQLHelper.ExecuteDataTable(sql); return table; } }
/// <summary> /// 房间信息访问层 /// </summary> /// 描述 房间状态 房间类型 public class RoomDAL { //查询房间信息 public DataTable Room() { string sql = @"select RoomID, BedNum, RoomStateName, TypeName, Description, GuestNum from Room,RoomType,RoomState where Room.RoomTypeID=RoomType.TypeId and Room.RoomStateID=RoomState.RoomStateID"; DataTable table=SQLHelper.ExecuteDataTable(sql); return table; } //根据房间号查询 public DataTable Room(Room room) { string sql = @"select RoomID, BedNum, RoomStateName, TypeName, Description, GuestNum from Room,RoomType,RoomState where Room.RoomTypeID=RoomType.TypeId and Room.RoomStateID=RoomState.RoomStateID and RoomID =@roomid"; SqlParameter para = new SqlParameter("@roomid",room.RoomID); DataTable table = SQLHelper.ExecuteDataTable(sql,para); return table; } //修改房间信息 public bool URoom(Room room) { bool flag = false; string sql = "usp_updateRoom"; CommandType type = CommandType.StoredProcedure; SqlParameter[] paras = { new SqlParameter("@roomID",room.RoomID), new SqlParameter("@bedNum",room.BedNum), new SqlParameter("@description",room.Description), new SqlParameter("@roomTypeID",room.RoomTypeID) }; int count= SQLHelper.ExecuteNonQuery(sql,type,paras); if(count>0) { flag = true; } return flag; } //删除房间信息 public bool DRoom(int roomid) { bool flag = false; string sql = "usp_deleteRoomById"; CommandType type = CommandType.StoredProcedure; SqlParameter para = new SqlParameter("@roomID",roomid); int count=SQLHelper.ExecuteNonQuery(sql,type,para); if(count>0) { flag = true; } return flag; } //添加房间信息 public bool IRoom(Room room) { bool flag = false; string sql = "usp_insertRoom"; CommandType type = CommandType.StoredProcedure; SqlParameter[] paras = { new SqlParameter("@bedNum",room.BedNum), new SqlParameter("@description",room.Description), new SqlParameter("@roomTypeID",room.RoomTypeID) }; int count= SQLHelper.ExecuteNonQuery(sql,type,paras); if(count>0) { flag = true; } return flag; } }
/// <summary> /// 房间状态访问层 /// </summary> ///入住 空闲 维修 public class RoomStateDAL { //查询空闲房间 public List<Room> SRoom() { string sql = "select roomid,BedNum from Room where roomstateid=2"; DataTable table =SQLHelper.ExecuteDataTable(sql); MyTool tool = new MyTool(); return tool.DataTableToList<Room>(table); } }
/// <summary> /// 房间类型访问层 /// </summary> /// 价格 类型 public class RoomTypeDAL { //查询全部房间价格 public DataTable Room() { string sql = "select * from RoomType"; DataTable table= SQLHelper.ExecuteDataTable(sql); return table; } //根据房间类型查询 public DataTable Room(RoomType type) { string sql = "select * from RoomType where TypeName like '%'+@name+'%'"; SqlParameter para = new SqlParameter("@name",type.TypeName); DataTable table= SQLHelper.ExecuteDataTable(sql,para); return table; } //插入房间类型 public bool IRoom(RoomType types) { bool flag = false; string sql = "usp_insertRoomType"; CommandType type = CommandType.StoredProcedure; SqlParameter[] paras = { new SqlParameter("@TypeName",types.TypeName), new SqlParameter("@TypePrice",types.TypePrice) }; int count= SQLHelper.ExecuteNonQuery(sql,type,paras); if(count>0) { flag = true; } return flag; } //修改房间类型 public bool URoom(RoomType types) { bool flag = false; string sql = "usp_updateRoomType"; CommandType type = CommandType.StoredProcedure; SqlParameter[] paras = { new SqlParameter("@typeID",types.TypeID), new SqlParameter("@typeName",types.TypeName), new SqlParameter("@typePrice",types.TypePrice) }; int count =SQLHelper.ExecuteNonQuery(sql,type,paras); if(count>0) { flag = true; } return flag; } //删除房间类型 public bool DRoom(int typeid) { bool flag = false; string sql = "usp_deleteRoomTypeById"; CommandType type = CommandType.StoredProcedure; SqlParameter para = new SqlParameter("@typeID",typeid); int count=SQLHelper.ExecuteNonQuery(sql,type,para); if(flag) { flag = true; } return flag; } //查询房间号和入住状态 public List<Room> Romm(int typeid) { string sql = "select roomid,roomstateid from room where roomtypeid="+typeid+""; DataTable table=SQLHelper.ExecuteDataTable(sql); MyTool tool = new MyTool(); return tool.DataTableToList<Room>(table); } }
public static class SQLHelper { //用静态的方法调用的时候不用创建SQLHelper的实例 //Execetenonquery // public static string Constr = "server=HAPPYPIG\SQLMODEL;database=shooltest;uid=sa;pwd=6375196;"; public static string Constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; public static int id; /// <summary> /// 执行NonQuery命令 /// </summary> /// <param name="cmdTxt"></param> /// <param name="parames"></param> /// <returns></returns> public static int ExecuteNonQuery(string cmdTxt, params SqlParameter[] parames) { return ExecuteNonQuery(cmdTxt, CommandType.Text, parames); } //可以使用存储过程的ExecuteNonquery public static int ExecuteNonQuery(string cmdTxt, CommandType cmdtype, params SqlParameter[] parames) { //判断脚本是否为空 ,直接返回0 if (string.IsNullOrEmpty(cmdTxt)) { return 0; } using (SqlConnection con = new SqlConnection(Constr)) { using (SqlCommand cmd = new SqlCommand(cmdTxt, con)) { if (parames != null) { cmd.CommandType = cmdtype; cmd.Parameters.AddRange(parames); } con.Open(); return cmd.ExecuteNonQuery(); } } } public static SqlDataReader ExecuteDataReader(string cmdTxt, params SqlParameter[] parames) { return ExecuteDataReader(cmdTxt, CommandType.Text, parames); } //SQLDataReader存储过程方法 public static SqlDataReader ExecuteDataReader(string cmdTxt, CommandType cmdtype, params SqlParameter[] parames) { if (string.IsNullOrEmpty(cmdTxt)) { return null; } SqlConnection con = new SqlConnection(Constr); using (SqlCommand cmd = new SqlCommand(cmdTxt, con)) { cmd.CommandType = cmdtype; if (parames != null) { cmd.Parameters.AddRange(parames); } con.Open(); //把reader的行为加进来。当reader释放资源的时候,con也被一块关闭 return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); } } public static DataTable ExecuteDataTable(string sql, params SqlParameter[] parames) { return ExecuteDataTable(sql, CommandType.Text, parames); } //调用存储过程的类,关于(ExecuteDataTable) public static DataTable ExecuteDataTable(string sql, CommandType cmdType, params SqlParameter[] parames) { if (string.IsNullOrEmpty(sql)) { return null; } DataTable dt = new DataTable(); using (SqlDataAdapter da = new SqlDataAdapter(sql, Constr)) { da.SelectCommand.CommandType = cmdType; if (parames != null) { da.SelectCommand.Parameters.AddRange(parames); } da.Fill(dt); return dt; } } /// <summary> /// ExecuteScalar /// </summary> /// <param name="cmdTxt">第一个参数,SQLServer语句</param> /// <param name="parames">第二个参数,传递0个或者多个参数</param> /// <returns></returns> public static object ExecuteScalar(string cmdTxt, params SqlParameter[] parames) { return ExecuteScalar(cmdTxt, CommandType.Text, parames); } //可使用存储过程的ExecuteScalar public static object ExecuteScalar(string cmdTxt, CommandType cmdtype, params SqlParameter[] parames) { if (string.IsNullOrEmpty(cmdTxt)) { return null; } using (SqlConnection con = new SqlConnection(Constr)) { using (SqlCommand cmd = new SqlCommand(cmdTxt, con)) { cmd.CommandType = cmdtype; if (parames != null) { cmd.Parameters.AddRange(parames); } con.Open(); return cmd.ExecuteScalar(); } } } //调用存储过程的DBHelper类(关于ExeceutScalar,包含事务,只能处理Int类型,返回错误号) public static object ExecuteScalar(string cmdTxt, CommandType cmdtype,SqlTransaction sqltran, params SqlParameter[] parames) { if (string.IsNullOrEmpty(cmdTxt)) { return 0; } using (SqlConnection con = new SqlConnection(Constr)) { int sum = 0; using (SqlCommand cmd = new SqlCommand(cmdTxt, con)) { cmd.CommandType=cmdtype; if (parames != null) { cmd.Parameters.AddRange(parames); } con.Open(); sqltran = con.BeginTransaction(); try { cmd.Transaction = sqltran; sum=Convert.ToInt32( cmd.ExecuteScalar()); sqltran.Commit(); } catch (SqlException ex) { sqltran.Rollback(); } return sum; } } } }
业务逻辑层BLL:
///业务逻辑判断 public class GuestRecordBLL { GuestRecordDAL dal = new GuestRecordDAL(); //增加 public bool IGuest(GuestRecord guest) { return dal.IGuest(guest); } //查询 public DataTable SRoom() { return dal.SRoom(); } //根据条件查询 public DataTable SRoom(string time1, string time2, int resideid) { return dal.SRoom(time1, time2, resideid); } //删除 public bool URoom(GuestRecord guest) { return dal.URoom(guest); } }
public class ResideStateBLL { ResideStateDAL dal = new ResideStateDAL(); public DataTable SRoom() { return dal.SRoom(); } }
public class RoomBLL { RoomDAL dal = new RoomDAL(); public DataTable Room() { return dal.Room(); } public DataTable Room(Room room) { return dal.Room(room); } public bool URoom(Room room) { return dal.URoom(room); } public bool DRoom(int roomid) { return dal.DRoom(roomid); } public bool IRoom(Room room) { return dal.IRoom(room); } }
public class RoomStateBLL { RoomStateDAL dal = new RoomStateDAL(); public List<Room> SRoom() { return dal.SRoom(); } }
public class RoomTypeBLL { RoomTypeDAL dal = new RoomTypeDAL(); public DataTable Room() { return dal.Room(); } public DataTable Room(RoomType type) { return dal.Room(type); } public bool IRoom(RoomType type) { return dal.IRoom(type); } public bool URoom(RoomType types) { return dal.URoom(types); } public bool DRoom(int typeid) { return dal.DRoom(typeid); } public List<Room> Romm(int typeid) { return dal.Romm(typeid); } }
表示层UI:
房间管理窗体:
public partial class FrmInfo : Form { public FrmInfo() { InitializeComponent(); } RoomBLL bll = new RoomBLL(); Room room = new Room(); RoomTypeBLL tbl = new RoomTypeBLL(); private void FrmInfo_Load(object sender, EventArgs e) { cbo01.ValueMember = "TypeId"; cbo01.DisplayMember = "TypeName"; cbo01.DataSource=tbl.Room(); dgvList.DataSource = bll.Room(); } private void btncx_Click(object sender, EventArgs e) { if(txt01.Text=="") { dgvList.DataSource = bll.Room(); } else { room.RoomID = Convert.ToInt32(txt01.Text); dgvList.DataSource = bll.Room(room); } } private void 修改ToolStripMenuItem_Click(object sender, EventArgs e) { txt02.Text = dgvList.SelectedRows[0].Cells[1].Value.ToString(); cbo01.Text = dgvList.SelectedRows[0].Cells[3].Value.ToString(); txt03.Text = dgvList.SelectedRows[0].Cells[4].Value.ToString(); } private void btn02_Click(object sender, EventArgs e) { if (txt02.Text == "" || txt03.Text =="") { MessageBox.Show("请填写完整的信息"); } else { room.RoomID = Convert.ToInt32(dgvList.SelectedRows[0].Cells[0].Value); room.BedNum = Convert.ToInt32(txt02.Text); room.Description = txt03.Text; room.RoomTypeID = Convert.ToInt32(cbo01.SelectedValue); bool flag = bll.URoom(room); if (flag) { MessageBox.Show("修改成功"); dgvList.DataSource = bll.Room(); foreach (Control item in gb02.Controls) { if (item is TextBox) { item.Text = ""; } cbo01.Text = "标准间"; } } } } int roomid; private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) { roomid = Convert.ToInt32(dgvList.SelectedRows[0].Cells[0].Value); bool flag=bll.DRoom(roomid); if(flag) { MessageBox.Show("删除成功"); dgvList.DataSource = bll.Room(); foreach (Control item in gb02.Controls) { if (item is TextBox) { item.Text = ""; } cbo01.Text = "标准间"; } } } private void 新增ToolStripMenuItem_Click(object sender, EventArgs e) { if (txt02.Text == "" || txt03.Text == "") { MessageBox.Show("请填写完整的信息"); } else { room.BedNum = Convert.ToInt32(txt02.Text); room.Description = txt03.Text; room.RoomTypeID = Convert.ToInt32(cbo01.SelectedValue); bool flag = bll.IRoom(room); if (flag) { MessageBox.Show("添加成功"); dgvList.DataSource = bll.Room(); foreach (Control item in gb02.Controls) { if (item is TextBox) { item.Text = ""; } cbo01.Text = "标准间"; } } } } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } }
入住信息和退房窗体:
public partial class FrmRoom : Form { public FrmRoom() { InitializeComponent(); } ResideStateBLL bll = new ResideStateBLL(); GuestRecordBLL rbl = new GuestRecordBLL(); GuestRecord guest = new GuestRecord(); private void FrmRoom_Load(object sender, EventArgs e) { cbo01.Items.Add("全部"); cbo01.SelectedIndex = 0; cbo01.ValueMember = "ResideId"; cbo01.DisplayMember = "ResideName"; cbo01.DataSource=bll.SRoom(); dgvList.DataSource = rbl.SRoom(); } private void btn01_Click(object sender, EventArgs e) { if (cbo01.Text == "全部") { dgvList.DataSource = rbl.SRoom(); } else { string time1 = (dt01.Value).ToString(); string time2 = (dt02.Value).ToString(); int id = Convert.ToInt32(cbo01.SelectedValue); dgvList.DataSource = rbl.SRoom(time1, time2, id); } } private void btn02_Click(object sender, EventArgs e) { guest.GuestID= Convert.ToInt32(dgvList.SelectedRows[0].Cells[0].Value); guest.LeaveDate = ldate; guest.TotalMoney = Convert.ToDecimal(txt01.Text); bool flag =rbl.URoom(guest); txt01.Text = ""; if (flag) { dgvList.DataSource = rbl.SRoom(); } } DateTime ldate; private void dgvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if(dgvList.SelectedRows[0].Cells[5].Value.ToString().Trim()=="未结账") { DateTime rdate = Convert.ToDateTime(dgvList.SelectedRows[0].Cells[3].Value); ldate = DateTime.Today; int day = ldate.Subtract(rdate).Days; int price = Convert.ToInt32(dgvList.SelectedRows[0].Cells[10].Value); txt01.Text = (day * price).ToString(); } else { MessageBox.Show("已经结账"); } } }
树状结构查看房间状态:
public partial class FrmRType : Form { public FrmRType() { InitializeComponent(); } RoomTypeBLL bll = new RoomTypeBLL(); private void FrmRType_Load(object sender, EventArgs e) { TreeNode tn = new TreeNode("房间类型"); DataTable table= bll.Room(); foreach (DataRow item in table.Rows) { TreeNode node = new TreeNode(); node.Text = item["TypeName"].ToString(); node.Tag = item["TypeId"]; tn.Nodes.Add(node); } tvList.Nodes.Add(tn); } private void tvList_AfterSelect(object sender, TreeViewEventArgs e) { if(tvList.SelectedNode.Level==0) { return; } if(tvList.SelectedNode.Level==1) { int id= Convert.ToInt32(tvList.SelectedNode.Tag); List<Room> list=bll.Romm(id); lvList.Items.Clear(); foreach (Room item in list) { ListViewItem iten = new ListViewItem(); iten.Text = item.RoomID.ToString(); iten.Tag = item; lvList.Items.Add(iten); } } } }
房间类型管理:
public partial class FrmType : Form { public FrmType() { InitializeComponent(); } RoomTypeBLL bll = new RoomTypeBLL(); RoomType type = new RoomType(); private void FrmType_Load(object sender, EventArgs e) { dgvList.DataSource = bll.Room(); } private void btncx_Click(object sender, EventArgs e) { if(txt01.Text=="") { dgvList.DataSource = bll.Room(); } else { type.TypeName = txt01.Text; dgvList.DataSource = bll.Room(type); } } private void btn02_Click(object sender, EventArgs e) { if (txt02.Text == ""||txt03.Text=="") { MessageBox.Show("请选择要修改的文本"); } else { type.TypeID = Convert.ToInt32(dgvList.SelectedRows[0].Cells[0].Value); type.TypeName = txt02.Text; type.TypePrice = Convert.ToDecimal(txt03.Text); bool flag = bll.URoom(type); if (flag) { MessageBox.Show("修改成功"); dgvList.DataSource = bll.Room(); foreach (Control item in gb02.Controls) { if (item is TextBox) { item.Text = ""; } } } } } private void 新增ToolStripMenuItem_Click(object sender, EventArgs e) { if (txt02.Text == "" || txt03.Text == "") { MessageBox.Show("请填写完整的信息"); } else { type.TypeName = txt02.Text; type.TypePrice = Convert.ToInt32(txt03.Text); bool flag = bll.IRoom(type); if (flag) { MessageBox.Show("添加成功"); dgvList.DataSource = bll.Room(); foreach (Control item in gb02.Controls) { if (item is TextBox) { item.Text = ""; } } } } } private void 修改ToolStripMenuItem_Click(object sender, EventArgs e) { txt02.Text = dgvList.SelectedRows[0].Cells[1].Value.ToString(); txt03.Text= dgvList.SelectedRows[0].Cells[2].Value.ToString(); } private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) { int typeid = Convert.ToInt32(dgvList.SelectedRows[0].Cells[0].Value); bool flag=bll.DRoom(typeid); if(flag) { MessageBox.Show("删除成功"); dgvList.DataSource = bll.Room(); foreach (Control item in gb02.Controls) { if (item is TextBox) { item.Text = ""; } } } } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } }
顾客入店登记窗体:
public partial class FrmUser : Form { public FrmUser() { InitializeComponent(); } RoomStateBLL bll = new RoomStateBLL(); GuestRecordBLL gbl = new GuestRecordBLL(); private void FrmUser_Load(object sender, EventArgs e) { cbo01.DisplayMember = "Roomid"; List<Room> list=bll.SRoom(); foreach (Room item in list) { cbo01.Items.Add(item.RoomID+"号房(床位:"+item.BedNum+")"); } } private void btn01_Click(object sender, EventArgs e) { if(txt01.Text==""||txt02.Text==""||txt03.Text=="") { MessageBox.Show("请填写完整的信息"); } else { GuestRecord guest = new GuestRecord(); guest.IdentityID = txt01.Text; guest.GuestName = txt02.Text; guest.Deposit = Convert.ToDecimal(txt03.Text); int length=cbo01.Text.IndexOf("号"); guest.RoomID = Convert.ToInt32(cbo01.Text.Substring(0,length)); guest.ResideDate = Convert.ToDateTime(dt01.Text); bool flag = gbl.IGuest(guest); if (flag) { MessageBox.Show("登记成功"); foreach (Control item in gb01.Controls) { if (item is TextBox) { item.Text = ""; } cbo01.Text = ""; dt01.Text = ""; } cbo01.Items.Clear(); cbo01.DisplayMember = "Roomid"; List<Room> list = bll.SRoom(); foreach (Room item in list) { cbo01.Items.Add(item.RoomID + "号房(床位:" + item.BedNum + ")"); } } } } }