Ejemplo n.º 1
0
        public List <Home> GetHome(double pollutionInt, double bruitIntensité, double vitesseInterent)
        {
            List <Home> listHome = new List <Home>();

            OpenConnection(); //Open the connection with the database
            SqlRequete newRequest = new SqlRequete();

            newRequest.SelectAllHome();
            if (OpenConnection() == true)//try to connect on the database
            {
                SqlCommand    cmd        = new SqlCommand(newRequest.RequesteGet, connection);
                SqlDataReader dataReader = cmd.ExecuteReader(); //execute the request and take the max of the pollution
                List <Adress> listAdress = new List <Adress>();
                bool          check      = true;
                double        data       = 0;
                while (dataReader.Read())//while reading data => add on the list the data
                {
                    listAdress.Add(new Adress(Convert.ToString(dataReader["adress_number"]), Convert.ToString(dataReader["adress_street"]), Convert.ToInt32(dataReader["adress_cp"]), Convert.ToString(dataReader["adress_city"]), Convert.ToString(dataReader["adress_country"])));
                }
                foreach (Adress adress in listAdress)
                {
                    List <Device> deviceList = GetDevicesFromAdress(adress);
                    foreach (Device device in deviceList)
                    {
                        switch (device.DescriptionGet)
                        {
                        case "bruit":
                            data = GetAvgDataDevice(device.GuidGet);
                            if (data > bruitIntensité)
                            {
                                check = false;
                            }
                            break;

                        case "pollution":
                            data = GetAvgDataDevice(device.GuidGet);
                            if (data > pollutionInt)
                            {
                                check = false;
                            }
                            break;

                        case "internet":
                            data = GetAvgDataDevice(device.GuidGet);
                            if (data < vitesseInterent)
                            {
                                check = false;
                            }
                            break;
                        }
                    }
                    if (check)
                    {
                        listHome.Add(new Home(adress, deviceList));
                    }
                }
            }
            return(listHome);
        }
Ejemplo n.º 2
0
        public double GetMaxSonor()
        {
            double maxSensor = 0;

            OpenConnection(); //Open the connection with the database
            SqlRequete newRequest = new SqlRequete();

            newRequest.MaxSonor();
            if (OpenConnection() == true)//try to connect on the database
            {
                SqlCommand    cmd        = new SqlCommand(newRequest.RequesteGet, connection);
                SqlDataReader dataReader = cmd.ExecuteReader(); //execute the request and take the max of the pollution
                maxSensor = Convert.ToDouble(dataReader["value_data"]);
                return(maxSensor);
            }
            else
            {
                return(maxSensor);
            }
        }
Ejemplo n.º 3
0
        public double GetAvgDataDevice(int guid)
        {
            double dataAvg = 0;

            OpenConnection(); //Open the connection with the database
            SqlRequete newRequest = new SqlRequete();

            newRequest.AvgDataFromDevice(guid);
            if (OpenConnection() == true)//try to connect on the database
            {
                SqlCommand    cmd        = new SqlCommand(newRequest.RequesteGet, connection);
                SqlDataReader dataReader = cmd.ExecuteReader(); //execute the request and take the max of the pollution
                dataAvg = Convert.ToDouble(dataReader["value_data"]);
                return(dataAvg);
            }
            else
            {
                return(dataAvg);
            }
        }
Ejemplo n.º 4
0
        public List <Device> GetDevicesFromAdress(Adress adress)
        {
            List <Device> listDevices = new List <Device>();

            OpenConnection(); //Open the connection with the database
            SqlRequete newRequest = new SqlRequete();

            newRequest.DeviceFromAdress(adress);
            if (OpenConnection() == true)//try to connect on the database
            {
                SqlCommand    cmd        = new SqlCommand(newRequest.RequesteGet, connection);
                SqlDataReader dataReader = cmd.ExecuteReader(); //execute the request and take the max of the pollution
                while (dataReader.Read())                       //while reading data => add on the list the data
                {
                    listDevices.Add(new Device(Convert.ToInt32(dataReader["iddevice"]), Convert.ToString(dataReader["device_description"])));
                }
                return(listDevices);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        public List <Data> GetDataDevice(int guid)
        {
            List <Data> data = new List <Data>();

            OpenConnection(); //Open the connection with the database
            SqlRequete newRequest = new SqlRequete();

            newRequest.DataFromDevice(guid);
            if (OpenConnection() == true)//try to connect on the database
            {
                SqlCommand    cmd        = new SqlCommand(newRequest.RequesteGet, connection);
                SqlDataReader dataReader = cmd.ExecuteReader(); //execute the request and take the max of the pollution
                while (dataReader.Read())                       //while reading data => add on the list the data
                {
                    data.Add(new Data(Convert.ToDouble(dataReader["value_data"]), Convert.ToString(dataReader["type_data_description"]), Convert.ToDateTime(dataReader["data_time"])));
                }
                return(data);
            }
            else
            {
                return(null);
            }
        }