Exemple #1
0
        public static Sensor FromDB(SqlDataReader reader)
        {
            int    sensorId    = (int)reader["id"];
            string description = reader["description"].ToString();

            return(new Sensor()
            {
                Id = sensorId,
                UserId = (int)reader["user_id"],
                LocationId = (int)reader["location_id"],
                Description = description.Equals("") ? null : description,
                Personal = (bool)reader["personal"],
                Valid = (bool)reader["valid"],
                Fields = SensorField.GetAllForSensor(sensorId).ToArray(),
                Date = DateTime.Parse(reader["date"].ToString())
            });
        }
Exemple #2
0
        public static SensorField GetById(int id)
        {
            using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DB))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT id, sensor_id, measure_name, measure_type, min_value, max_value FROM t_sensor_reading_types WHERE id = @id", conn))
                {
                    cmd.Parameters.AddWithValue("@id", id);

                    SqlDataReader reader = cmd.ExecuteReader();
                    if (!reader.Read())
                    {
                        return(null);
                    }

                    return(SensorField.FromDB(reader));
                }
            }
        }
Exemple #3
0
        public static List <SensorField> GetAllForSensor(int sensorId)
        {
            using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DB))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT id, sensor_id, measure_name, measure_type, min_value, max_value FROM t_sensor_reading_types WHERE sensor_id = @sensorId", conn))
                {
                    cmd.Parameters.AddWithValue("sensorId", sensorId);
                    List <SensorField> sensorFields = new List <SensorField>();

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        sensorFields.Add(SensorField.FromDB(reader));
                    }

                    return(sensorFields);
                }
            }
        }