/// <summary> /// 增加订单 /// </summary> /// <param name="order">所有订单信息</param> /// <returns></returns> public bool AddOrder(Order order) { try { using (HotelManageDBEntities db = new HotelManageDBEntities()) { db.Order.Add(order); Room data = db.Room.Where(s => s.Id == order.RoomId).FirstOrDefault(); data.Room_StateId = 3; db.Entry(data).State = EntityState.Modified; Room_State room_State = new Room_State(); room_State.EstablishDate = DateTime.Now; room_State.IsDelete = false; room_State.RoomId = order.RoomId; room_State.StateTxt = "使用中"; db.Room_State.Add(room_State); db.SaveChanges(); return(true); } } catch (Exception) { //throw; } return(false); }
/// <summary> /// 修改状态 /// </summary> /// <param name="id">房间编号</param> /// <param name="dentityId">身份编号</param> /// <returns></returns> public bool ModifyState(int id, int dentityId) { try { using (HotelManageDBEntities db = new HotelManageDBEntities()) { Room room = db.Room.Where(s => s.Id == id).FirstOrDefault(); Room_State room_State = new Room_State(); room_State.EstablishDate = DateTime.Now; room_State.IsDelete = false; room_State.RoomId = id; bool flag = true; if (dentityId == 5) //清洁部门 状态 待清洁 { if (room.Room_StateId == 7) { room.Room_StateId = 4; room_State.StateTxt = "在清洁"; flag = false; } else if (room.Room_StateId == 4) { room.Room_StateId = 1; room_State.StateTxt = "可使用"; flag = false; } } if (dentityId == 6) //维修部门 状态 待清洁 { if (room.Room_StateId == 7 || room.Room_StateId == 1) { room.Room_StateId = 5; room_State.StateTxt = "维修中"; flag = false; } else if (room.Room_StateId == 5) { room.Room_StateId = 7; room_State.StateTxt = "待清洁"; flag = false; } } if (flag) { return(false); } db.Entry(room).State = EntityState.Modified; db.Room_State.Add(room_State); db.SaveChanges(); return(true); } } catch (Exception) { //throw; } return(false); }
/// <summary> /// 退房 /// </summary> /// <param name="Id">房间编号</param> /// <param name="Amount">退还金额</param> /// <returns></returns> public bool AddSignOut(int Id, decimal Amount) { try { using (HotelManageDBEntities db = new HotelManageDBEntities()) { //写入退房表 CheckOut checkOut = new CheckOut(); checkOut.EstablishDate = DateTime.Now; checkOut.IsDelete = false; checkOut.OrderId = Id; checkOut.CheckOutDate = DateTime.Now; checkOut.refundAmount = Amount; db.CheckOut.Add(checkOut); //订单表标记完成 Order order = db.Order.Where(s => s.Id == Id).FirstOrDefault(); order.IsDelete = true; order.DeleteDate = DateTime.Now; db.Entry(order).State = EntityState.Modified; //房间状态设置成待清洁 int? roomID = order.RoomId; Room room = db.Room.Where(s => s.Id == roomID).FirstOrDefault(); room.Room_StateId = 7; // 7 待清洁 db.Entry(room).State = EntityState.Modified; Room_State room_State = new Room_State(); room_State.EstablishDate = DateTime.Now; room_State.IsDelete = false; room_State.RoomId = roomID; room_State.StateTxt = "待清洁"; db.Room_State.Add(room_State); db.SaveChanges(); return(true); } } catch (Exception) { //throw; } return(false); }