Beispiel #1
0
        public Sensor GetSensor(string MacAddress)
        {
            SensorDataController sdc = new SensorDataController();
            SensorData           sd  = sdc.GetSensorData(MacAddress);
            Sensor sensor            = null;

            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();

                string     sqlString = "SELECT * FROM Sensors WHERE MacAddress = '" + MacAddress + "'";
                SqlCommand cmd       = new SqlCommand(sqlString, conn);

                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        sensor = new Sensor {
                            MacAddress = reader[0].ToString(), Name = reader[1].ToString(), LimitUp = Convert.ToDouble(reader[2]), LimitLow = Convert.ToDouble(reader[3]), FK_UserId = Convert.ToInt32(reader[4]), Data = sd
                        };
                    }
                }

                reader.Close();
            }
            return(sensor);
        }