public RoomPreference Get(String ObjType, int Id, int RoomId)
        {
            String         query = "SELECT ra.ObjId,ra.ObjVersion,ra.ObjType,ra.Id,ra.RoomId,l.RoomNo,b.BuildingName FROM room_allocation_tab ra,location_tab l, building_tab b WHERE b.ObjId=l.BuildingId and l.ObjId=ra.RoomId and ra.ObjType='" + ObjType + "'  and ra.Id=" + Id + "  and RoomId=" + RoomId;
            RoomPreference obj   = new RoomPreference();

            if (this.OpenConnection() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    obj.ObjId      = int.Parse(dataReader["ObjId"].ToString());
                    obj.ObjVersion = int.Parse(dataReader["ObjVersion"].ToString());

                    obj.ObjType  = dataReader["ObjType"].ToString();
                    obj.Id       = int.Parse(dataReader["Id"].ToString());
                    obj.RoomId   = int.Parse(dataReader["RoomId"].ToString());
                    obj.Room     = dataReader["RoomNo"].ToString();
                    obj.Building = dataReader["BuildingName"].ToString();
                }
                dataReader.Close();
                this.CloseConnection();
                return(obj);
            }
            else
            {
                return(obj);
            }
        }
Exemple #2
0
        protected void SetUp()
        {
            RoomPreference rp = new RoomPreference()
            {
                Floor = 1,
                Price = 100f,
                Beds  = new List <ABed>()
                {
                    new Standard(1,
                                 false,
                                 25f),
                    new Standard(1, false, 25f)
                }
            };

            _cust = new Customer("Tom",
                                 "Æøå",
                                 45,
                                 23,
                                 DateTime.Today,
                                 DateTime.Today.AddDays(1),
                                 rp);
            _booking = new Booking(100f,
                                   DateTime.Now.AddDays(1),
                                   DateTime.Now,
                                   _cust);
        }
 private RoomPreference Delete(RoomPreference obj)
 {
     obj.ValidationErrors.Clear();
     try
     {
         if (ExcuteStatement("DELETE FROM room_allocation_tab WHERE ObjType='" + obj.ObjType + "' and Id=" + obj.Id))
         {
             return(obj);
         }
         else
         {
             obj.ValidationErrors.Add("Error While deleting..");
             return(obj);
         };
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public List <RoomPreference> GetAll()
        {
            String query = "SELECT ra.ObjId,ra.ObjVersion,ra.ObjType,ra.Id,ra.RoomId,l.RoomNo,b.BuildingName FROM room_allocation_tab ra,location_tab l, building_tab b WHERE b.ObjId=l.BuildingId and l.ObjId=ra.RoomId  ORDER BY ra.ObjId DESC";

            List <RoomPreference> lst = new List <RoomPreference>();
            RoomPreference        obj;

            if (this.OpenConnection() == true)
            {
                //Create Command
                MySqlCommand    cmd        = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    obj            = new RoomPreference();
                    obj.ObjId      = int.Parse(dataReader["ObjId"].ToString());
                    obj.ObjVersion = int.Parse(dataReader["ObjVersion"].ToString());

                    obj.ObjType  = dataReader["ObjType"].ToString();
                    obj.Id       = int.Parse(dataReader["Id"].ToString());
                    obj.RoomId   = int.Parse(dataReader["RoomId"].ToString());
                    obj.Room     = dataReader["RoomNo"].ToString();
                    obj.Building = dataReader["BuildingName"].ToString();

                    lst.Add(obj);
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return(lst);
            }
            else
            {
                return(lst);
            }
        }
        private bool Exists(RoomPreference obj) // added condition for issues in update method
        {
            String query = "SELECT 1 FROM room_allocation_tab  where  ObjType='" + obj.ObjType + "' and Id=" + obj.Id + " and RoomId=" + obj.RoomId + " and ObjId!=" + obj.ObjId;

            if (this.OpenConnection() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    CloseConnection();
                    return(true);
                }
                CloseConnection();

                return(false);
            }
            else
            {
                return(false);
            }
        }
        private RoomPreference Add(RoomPreference obj)
        {
            obj.ValidationErrors.Clear();

            try
            {
                if (Exists(obj))
                {
                    obj.ValidationErrors.Add("Room is already Exist.");
                    return(obj);
                }
                else
                {
                    String query = "INSERT INTO room_allocation_tab (ObjType,Id,RoomId,ObjVersion)VALUES(" +
                                   "'" + obj.ObjType + "'," +
                                   "'" + obj.Id + "'," +
                                   "'" + obj.RoomId + "'," +
                                   "'0')";

                    if (ExcuteStatement(query))
                    {
                        obj.ObjId = Get(obj.ObjType, obj.Id, obj.RoomId).ObjId;
                        return(obj);
                    }
                    else
                    {
                        obj.ValidationErrors.Add("Error While adding..");
                        return(obj);
                    };
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 public void SelectRoomPreference(RoomPreference room)
 {
     SelectRoomPreference(StringEnum.GetStringValue(room));
 }