Beispiel #1
0
        public static RoomsViewModel GetRoomsViewModel(List <string> Styles, List <string> Sizes)
        {
            RoomsViewModel model = new RoomsViewModel();

            model.RoomStyles = RoomStyleDAO.GetAllRoomStyleViewModel();
            model.RoomSizes  = RoomSizeDAO.GetAllRoomSizeViewModel();

            using (SqlConnection conn = Connection.GetConnection())
            {
                if (conn != null)
                {
                    string     styles_formated = string.IsNullOrEmpty(string.Join(",", Styles)) ? ("0") : (string.Join(",", Styles));
                    string     sizes_formated  = string.IsNullOrEmpty(string.Join(",", Sizes)) ? ("0") : (string.Join(",", Sizes));
                    string     sql             = "select RoomID from Room, RoomType where Room.RoomTypeID = RoomType.RoomTypeID and RoomStyleID IN (" + styles_formated + ") and RoomSizeID IN (" + sizes_formated + ")";
                    SqlCommand cm = new SqlCommand(sql, conn);
                    var        rs = cm.ExecuteReader();
                    if (rs.HasRows)
                    {
                        while (rs.Read())
                        {
                            RoomViewModel room = GetRoomViewModel(rs.GetInt32(0));
                            if (room.Status == "Empty")
                            {
                                model.EmptyCount++;
                            }
                            if (room.Status == "Reserved")
                            {
                                model.ReservedCount++;
                            }
                            if (room.Status == "Occupied")
                            {
                                model.OccupiedCount++;
                            }
                            if (room.Status == "Stayover")
                            {
                                model.StayoverCount++;
                            }
                            model.Rooms.Add(room);
                        }
                    }
                    conn.Close();
                }
            }
            return(model);
        }
Beispiel #2
0
        public static RoomsViewModel GetRoomsViewModel()
        {
            RoomsViewModel model = new RoomsViewModel();

            model.RoomStyles = RoomStyleDAO.GetAllRoomStyleViewModel();
            model.RoomSizes  = RoomSizeDAO.GetAllRoomSizeViewModel();

            using (SqlConnection conn = Connection.GetConnection())
            {
                if (conn != null)
                {
                    string     sql = "select RoomID from Room";
                    SqlCommand cm  = new SqlCommand(sql, conn);
                    var        rs  = cm.ExecuteReader();
                    if (rs.HasRows)
                    {
                        while (rs.Read())
                        {
                            RoomViewModel room = GetRoomViewModel(rs.GetInt32(0));
                            if (room.Status == "Empty")
                            {
                                model.EmptyCount++;
                            }
                            if (room.Status == "Reserved")
                            {
                                model.ReservedCount++;
                            }
                            if (room.Status == "Occupied" || room.Status == "Stayover")
                            {
                                model.OccupiedCount++;
                            }
                            if (room.Status == "Stayover")
                            {
                                model.StayoverCount++;
                            }
                            model.Rooms.Add(room);
                        }
                    }
                    conn.Close();
                }
            }
            return(model);
        }