Beispiel #1
0
        public static Room[] getRoomsAndSensorsFromFloor(int homeID)
        {
            Room[] rooms = getRoomsFromFloor(homeID);

            if (rooms != null)
            {
                foreach (Room room in rooms)

                {
                    Sensor[] sensors = null;

                    //room.Sensors = getSensorsFromRoom(room.RoomID);
                    MySqlConnection connn = DBConection();
                    MySqlCommand    cmd   = new MySqlCommand("SELECT * FROM sensor WHERE idrooms = @roomID", con);
                    cmd.Parameters.Add(new MySqlParameter("@roomID", room.RoomID));

                    //Sensor[] sensors = null;

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();

                        MySqlDataReader reader     = cmd.ExecuteReader();
                        List <Sensor>   sensorList = new List <Sensor>();

                        while (reader.Read())
                        {
                            Sensor sensor = new Sensor();

                            sensor.SensorID = reader.GetInt32("idsensor");
                            sensor.Value    = reader.GetString("v");

                            string t = reader.GetString("sensorTypes");
                            sensor.Type = CStuff.convertMySQLEnumToCSharpEnum <SensorTypeEnum>(t);

                            //string s = reader.GetString("state");
                            //sensor.State = Common.convertMySQLEnumToCSharpEnum<AlarmState>(s);

                            sensorList.Add(sensor);
                        }

                        reader.Close();
                        sensors = sensorList.ToArray();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        con.Close();
                    }

                    room.Sensors = sensors;
                }
            }

            return(rooms);
        }
Beispiel #2
0
        public static Room[] getRoomsFromFloor(int homeID)
        {
            MySqlConnection con = DBConection();
            MySqlCommand    cmd = new MySqlCommand("SELECT * FROM rooms WHERE idhome = @homeID", con);

            cmd.Parameters.Add(new MySqlParameter("@homeID", homeID));

            Room[] rooms = null;

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();

                MySqlDataReader reader   = cmd.ExecuteReader();
                List <Room>     roomList = new List <Room>();

                while (reader.Read())
                {
                    Room room = new Room();

                    room.RoomID     = reader.GetInt32("idrooms");
                    room.X          = reader.GetInt32("x");
                    room.Y          = reader.GetInt32("y");
                    room.DLocations = reader.GetString("DLocation");

                    string t = reader.GetString("roomsType");
                    room.Type = CStuff.convertMySQLEnumToCSharpEnum <RoomType>(t);

                    //string c = reader.GetString("RLocation");
                    //if (c != null)
                    //{
                    //    room.Category = CStuff.convertMySQLEnumToCSharpEnum<RLocation>(c);

                    //}
                    ///  room.Category = CStuff.convertMySQLEnumToCSharpEnum<RLocation>(c);

                    roomList.Add(room);
                }

                reader.Close();
                rooms = roomList.ToArray();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }

            return(rooms);
        }
Beispiel #3
0
        //public static Sensor[] getSensorsFromRoom(int roomID)
        //{
        //    MySqlConnection con = DBConection();
        //    MySqlCommand cmd = new MySqlCommand("SELECT * FROM sensor WHERE idrooms = @roomID", con);
        //    cmd.Parameters.Add(new MySqlParameter("@roomID", roomID));

        //    Sensor[] sensors = null;

        //    try
        //    {
        //        con.Open();
        //        cmd.ExecuteNonQuery();

        //        MySqlDataReader reader = cmd.ExecuteReader();
        //        List<Sensor> sensorList = new List<Sensor>();

        //        while (reader.Read())
        //        {
        //            Sensor sensor = new Sensor();

        //            sensor.SensorID = reader.GetInt32("idsensor");
        //            sensor.Value = reader.GetString("v");

        //            string t = reader.GetString("sensorTypes");
        //            sensor.Type = CStuff.convertMySQLEnumToCSharpEnum<SensorTypeEnum>(t);

        //            //string s = reader.GetString("state");
        //            //sensor.State = Common.convertMySQLEnumToCSharpEnum<AlarmState>(s);

        //            sensorList.Add(sensor);
        //        }

        //        reader.Close();
        //        sensors = sensorList.ToArray();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //    finally
        //    {
        //        con.Close();
        //    }

        //    return sensors;
        //}

        public static House getHouse(int houseid)
        {
            MySqlConnection con1 = DBConection();
            MySqlCommand    cmd  = new MySqlCommand("SELECT * FROM home WHERE idhome = @houseID", con1);

            cmd.Parameters.Add(new MySqlParameter("@houseID", houseid));

            House home = null;

            try
            {
                con1.Open();
                cmd.ExecuteNonQuery();

                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    home          = new House();
                    home.Idhome   = reader.GetInt32("idhome");
                    House.HomeIDs = reader.GetInt32("idhome");
                    home.size     = reader.GetInt32("x");
                    string s = reader.GetString("alarmS");
                    home.State = CStuff.convertMySQLEnumToCSharpEnum <AlarmS>(s);
                    home.HName = reader.GetString("hName");
                    int x = reader.GetInt32("x");
                    int y = reader.GetInt32("y");

                    home.Rooms = new Room[x, y];
                }
                else
                {
                    Console.WriteLine($"No home with user ID of '{houseid}' found.");
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con1.Close();
            }

            return(home);
        }