Beispiel #1
0
        public static List <Modelo.Equipo> Buscar(int pIdEstado, int pExcluirVPN)
        {
            List <Modelo.Equipo> _lista = new List <Modelo.Equipo>();
            string strSQL = "";

            strSQL = strSQL + "SELECT *";
            strSQL = strSQL + " FROM Equipos AS E ";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Equipo pEquipo = new Modelo.Equipo();
                pEquipo.Id_Equipo = _reader.GetString(0);

                _lista.Add(pEquipo);
            }

            MyConn.Close();

            return(_lista);
        }
        public static List <Modelo.Notificacion> ValoresMinimos_y_Maximos(string pIdVariable, DateTime pFDesde, DateTime pFHasta)
        {
            List <Modelo.Notificacion> _lista = new List <Modelo.Notificacion>();
            string strSQL = "";

            strSQL = strSQL + "SELECT ";
            strSQL = strSQL + "        DATE_FORMAT(N.fecha_notificacion, '%d/%m/%Y') AS fecha_notificacion ";
            strSQL = strSQL + "      , COUNT(CASE alerta_notificada WHEN 'True' THEN 1 END) AS count_true,  ";
            strSQL = strSQL + "      , COUNT(CASE alerta_notificada WHEN 'False' THEN 1 END) AS count_false,  ";
            strSQL = strSQL + "FROM ";
            strSQL = strSQL + "               Notificaciones AS N ";
            strSQL = strSQL + "WHERE ";
            strSQL = strSQL + "         N.id_variable = '" + pIdVariable + "'";
            strSQL = strSQL + "     AND DATE_FORMAT(N.fecha_notificacion, '%d/%m/%Y') BETWEEN '" + pFDesde + "' AND '" + pFHasta + "'";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Notificacion pNotificacion = new Modelo.Notificacion();
                pNotificacion.Fecha_Notificacion = _reader.GetString(0);
                pNotificacion.Count_True         = _reader.GetInt32(1);
                pNotificacion.Count_False        = _reader.GetInt32(2);

                _lista.Add(pNotificacion);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #3
0
        public static List <Modelo.Lectura> BuscarParaCompletarGrilla(string pIdVariable, DateTime pFDesde, DateTime pFHasta)
        {
            List <Modelo.Lectura> _lista = new List <Modelo.Lectura>();
            string strSQL = "";

            strSQL = strSQL + "SELECT ";
            strSQL = strSQL + "        L.fecha_lectura ";
            strSQL = strSQL + "      , L.valor_lectura ";
            strSQL = strSQL + "FROM ";
            strSQL = strSQL + "               sensor.lecturas AS L ";
            strSQL = strSQL + "WHERE ";
            strSQL = strSQL + "         L.id_variable = '" + pIdVariable + "'";
            strSQL = strSQL + "     AND DATE_FORMAT(L.fecha_lectura, '%d/%m/%Y %H:%i:%S') BETWEEN '" + pFDesde + "' AND '" + pFHasta + "'";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Lectura pLectura = new Modelo.Lectura();
                pLectura.Fecha_Lectura = _reader.GetDateTime(0);
                pLectura.Valor_Lectura = _reader.GetString(1);

                _lista.Add(pLectura);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #4
0
        public static List <Modelo.Ip> RecuperarTodasLasIps()
        {
            List <Modelo.Ip> _lista = new List <Modelo.Ip>();
            string           strSQL = @"
                SELECT 
                      L.ip_user
                    , IFNULL(ip.ip, '') AS ip
	            FROM
	                (SELECT ip_user FROM sensor.sc_log GROUP BY ip_user) AS L
	            LEFT JOIN
	                (SELECT ip FROM ips GROUP BY ip) AS ip ON ip.ip = L.ip_user
            ";

            MySqlConnection MyConn   = DbConexion.ObtenerConexion();
            MySqlCommand    _comando = new MySqlCommand(strSQL, MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Ip pIp = new Modelo.Ip();
                pIp.Ip_User = _reader.GetString(0);
                pIp.IP      = _reader.GetString(1);

                _lista.Add(pIp);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #5
0
        public static List <Modelo.Lectura> RecuperarUltimaNotificacionEnviada()
        {
            List <Modelo.Lectura> _lista = new List <Modelo.Lectura>();
            string strSQL = @"
            SELECT 
                    L.id_lectura
                  , L.fecha_lectura
                  , E.id_equipo
                  , E.id_conexion
                  , E.Sin_Conexion_Equipo
                  , subV.alerta_variable
                  , subV.operador_alerta_variable
                  , subV.id_variable
                  , E.nombre_equipo 
                  , U.nombre_ubicacion
                  , C.nombre_conexion
                  , subV.nombre_variable
            FROM         sensor.lecturas AS L 
                INNER JOIN 
                        (SELECT  MAX(L.id_lectura) AS id_lectura, V.id_equipo FROM lecturas AS L INNER JOIN sensor.variables AS V ON L.id_variable = V.id_variable GROUP BY V.id_equipo) AS subSQL ON L.id_lectura = subSQL.id_lectura
            INNER JOIN equipos AS E ON subSQL.id_equipo = E.id_equipo
            INNER JOIN ubicaciones AS U ON E.id_ubicacion = U.id_ubicacion
            INNER JOIN conexiones AS C ON E.id_conexion = C.id_conexion
            INNER JOIN (SELECT id_variable, alerta_variable, operador_alerta_variable, id_equipo, nombre_variable FROM sensor.variables AS V WHERE es_fecha = 1 AND estado_variable = 0) AS subV ON subSQL.id_equipo = subV.id_equipo
            ";

            MySqlConnection MyConn   = DbConexion.ObtenerConexion();
            MySqlCommand    _comando = new MySqlCommand(strSQL, MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Lectura pLectura = new Modelo.Lectura();
                pLectura.Id_Lectura               = _reader.GetInt32(0);
                pLectura.Fecha_Lectura            = _reader.GetDateTime(1);
                pLectura.Id_Equipo                = _reader.GetString(2);
                pLectura.Id_Conexion              = _reader.GetInt32(3);
                pLectura.Sin_Conexion_Equipo      = _reader.GetBoolean(4);
                pLectura.Alerta_Variable          = _reader.GetString(5);
                pLectura.Operador_Alerta_Variable = _reader.GetString(6);
                pLectura.Id_Variable              = _reader.GetString(7);
                pLectura.Nombre_Equipo            = _reader.GetString(8);
                pLectura.Nombre_Ubicacion         = _reader.GetString(9);
                pLectura.Nombre_Conexion          = _reader.GetString(10);
                pLectura.Nombre_Variable          = _reader.GetString(11);

                _lista.Add(pLectura);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #6
0
        public static List <Modelo.Usuario> BuscarPorConexion(int pIdConexion)
        {
            List <Modelo.Usuario> _lista = new List <Modelo.Usuario>();
            string strSQL = "";

            strSQL = strSQL + "SELECT ";
            strSQL = strSQL + "        U.Login ";
            strSQL = strSQL + "      , U.Pswd ";
            strSQL = strSQL + "      , U.Name ";
            strSQL = strSQL + "      , U.Email ";
            strSQL = strSQL + "      , U.Active ";
            strSQL = strSQL + "      , U.Activation_Code ";
            strSQL = strSQL + "      , U.Priv_Admin ";
            strSQL = strSQL + "FROM ";
            strSQL = strSQL + "               sensor.usuarios_conexiones AS UC ";
            strSQL = strSQL + "    INNER JOIN sensor.sec_users AS U ";
            strSQL = strSQL + "                                    ON(UC.id_usuario = U.login) ";
            strSQL = strSQL + "WHERE   ( U.Active = 'Y' ";
            strSQL = strSQL + "     AND UC.id_conexion = '" + pIdConexion + "' AND UC.notifico_por_email = 1) ";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Usuario pUsuario = new Modelo.Usuario();
                pUsuario.Login           = _reader.GetString(0);
                pUsuario.Pswd            = _reader.GetString(1);
                pUsuario.Name            = _reader.GetString(2);
                pUsuario.Email           = _reader.GetString(3);
                pUsuario.Active          = _reader.GetString(4);
                pUsuario.Activation_Code = _reader.GetString(5);
                pUsuario.Priv_Admin      = _reader.GetString(6);

                _lista.Add(pUsuario);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #7
0
        public static int ModificarSinConexion(Modelo.Equipo pE)
        {
            int    retorno = 0;
            string strSQL  = "";

            strSQL = strSQL + " UPDATE Equipos SET ";
            strSQL = strSQL + "                Sin_Conexion_Equipo = " + pE.Sin_Conexion_Equipo;
            strSQL = strSQL + " WHERE Id_Equipo = '" + pE.Id_Equipo + "'";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            retorno = _comando.ExecuteNonQuery();

            MyConn.Close();

            return(retorno);
        }
Beispiel #8
0
        public static int AnalizadadLecturaTrue(Modelo.Lectura pL)
        {
            int    retorno = 0;
            string strSQL  = "";

            strSQL = strSQL + " UPDATE Lecturas SET ";
            strSQL = strSQL + "                Analizada_Lectura = 1";
            strSQL = strSQL + " WHERE Id_Variable = '" + pL.Id_Variable + "' AND Id_Lectura <= " + pL.Id_Lectura;
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            retorno = _comando.ExecuteNonQuery();

            MyConn.Close();

            return(retorno);
        }
Beispiel #9
0
        public static int ModificarAlertaNotificada(Modelo.Variable pV)
        {
            int    retorno = 0;
            string strSQL  = "";

            strSQL = strSQL + " UPDATE Variables SET ";
            strSQL = strSQL + "                Alerta_Notificada = " + pV.Alerta_Notificada;
            strSQL = strSQL + " WHERE Id_Variable = '" + pV.Id_Variable + "'";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            retorno = _comando.ExecuteNonQuery();

            MyConn.Close();

            return(retorno);
        }
Beispiel #10
0
        public static List <Modelo.Variable> RecuperarAlertaFecha(string id_equipo)
        {
            List <Modelo.Variable> _lista = new List <Modelo.Variable>();
            string strSQL = @"
            SELECT
                alerta_notificada
                , operador_alerta_variable
                , alerta_variable
                , id_variable
                , Nombre_variable
                , unidad_variable
            FROM
                sensor.variables
            WHERE (es_fecha = 1
                AND id_equipo = @idEquipo
                AND estado_variable = 0);
            ";

            MySqlConnection MyConn   = DbConexion.ObtenerConexion();
            MySqlCommand    _comando = new MySqlCommand(strSQL, MyConn);

            _comando.Parameters.AddWithValue("@idEquipo", id_equipo);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Variable pVariable = new Modelo.Variable();
                pVariable.Alerta_Notificada        = _reader.GetBoolean(0);
                pVariable.Operador_Alerta_Variable = _reader.GetString(1);
                pVariable.Alerta_Variable          = _reader.GetString(2);
                pVariable.Id_Variable     = _reader.GetString(3);
                pVariable.Nombre_Variable = _reader.GetString(4);
                pVariable.Unidad_Variable = _reader.GetString(5);

                _lista.Add(pVariable);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #11
0
        public static List <Modelo.Usuario> BuscarPrivAdmin()
        {
            List <Modelo.Usuario> _lista = new List <Modelo.Usuario>();
            string strSQL = "";

            strSQL = strSQL + "SELECT ";
            strSQL = strSQL + "        U.Login ";
            strSQL = strSQL + "      , U.Pswd ";
            strSQL = strSQL + "      , U.Name ";
            strSQL = strSQL + "      , U.Email ";
            strSQL = strSQL + "      , U.Active ";
            strSQL = strSQL + "      , U.Activation_Code ";
            strSQL = strSQL + "      , U.Priv_Admin ";
            strSQL = strSQL + "FROM ";
            strSQL = strSQL + "               sensor.sec_users AS U ";
            strSQL = strSQL + "WHERE   ( U.Active = 'Y' AND priv_admin = 'Y')";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Usuario pUsuario = new Modelo.Usuario();
                pUsuario.Login           = _reader.GetString(0);
                pUsuario.Pswd            = _reader.GetString(1);
                pUsuario.Name            = _reader.GetString(2);
                pUsuario.Email           = _reader.GetString(3);
                pUsuario.Active          = _reader.GetString(4);
                pUsuario.Activation_Code = _reader.GetString(5);
                pUsuario.Priv_Admin      = _reader.GetString(6);

                _lista.Add(pUsuario);
            }

            MyConn.Close();

            return(_lista);
        }
        public static int Agregar(Modelo.Notificacion pN)
        {
            int    retorno = 0;
            string strSQL  = "";

            strSQL = strSQL + " INSERT INTO Notificaciones ";
            strSQL = strSQL + " (Id_Variable, Nombre_Variable, Email_Notificado, Id_Conexion, Nombre_Conexion, Id_Usuario, Nombre_Usuario, Id_Equipo, Nombre_Equipo, Alerta_Notificada, Valor_Variable, Operador_Variable, Valor_Leido, version_sistema ";
            strSQL = strSQL + " ) VALUES ";
            strSQL = strSQL + "('" + pN.Id_Variable + "', '" + pN.Nombre_Variable + "', '" + pN.Email_Notificacion + "', '" + pN.Id_Conexion + "', '" + pN.Nombre_Conexion + "', '" + pN.Id_Usuario + "', '" + pN.Nombre_Usuario + "', '" + pN.Id_Equipo + "', '" + pN.Nombre_Equipo + "', '" + pN.Alerta_Notificada + "', '" + pN.Valor_Variable + "', '" + pN.Operador_Variable + "', '" + pN.Valor_Leido + "', '" + Application.ProductVersion + "' ";
            strSQL = strSQL + " )";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            retorno = _comando.ExecuteNonQuery();

            MyConn.Close();

            return(retorno);
        }
Beispiel #13
0
        public static int Agregar(Modelo.Ip pI)
        {
            int    retorno = 0;
            string strSQL  = "";

            strSQL = strSQL + " INSERT INTO sensor.ips ";
            strSQL = strSQL + " (ip, isp, country, latitud, longitud, zona, ciudad, continente ";
            strSQL = strSQL + " ) VALUES ";
            strSQL = strSQL + "('" + pI.IP + "', '" + pI.Isp + "', '" + pI.Country + "', '" + pI.Latitud + "', '" + pI.Longitud + "', '" + pI.Zona + "', '" + pI.Ciudad + "', '" + pI.Continente + "'";
            strSQL = strSQL + " )";
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            retorno = _comando.ExecuteNonQuery();

            MyConn.Close();

            return(retorno);
        }
Beispiel #14
0
        public static List <Modelo.Lectura> Buscar(int pIdEstado)
        {
            List <Modelo.Lectura> _lista = new List <Modelo.Lectura>();
            string strSQL = "";

            strSQL = strSQL + "SELECT ";
            strSQL = strSQL + "      L.id_lectura ";
            strSQL = strSQL + "      , L.fecha_lectura";
            strSQL = strSQL + "      , L.valor_lectura ";
            strSQL = strSQL + "      , L.id_variable ";
            strSQL = strSQL + "      , L.analizada_lectura ";
            strSQL = strSQL + "      , V.nombre_variable ";
            strSQL = strSQL + "      , V.unidad_variable ";
            strSQL = strSQL + "      , IFNULL(V.alerta_variable, '') AS alerta_variable ";
            strSQL = strSQL + "      , IFNULL((V.operador_alerta_variable, '') AS operador_alerta_variable ";
            strSQL = strSQL + "      , V.id_equipo ";
            strSQL = strSQL + "      , E.nombre_equipo ";
            strSQL = strSQL + "      , E.id_ubicacion ";
            strSQL = strSQL + "      , U.nombre_ubicacion ";
            strSQL = strSQL + "      , E.id_conexion ";
            strSQL = strSQL + "      , C.nombre_conexion ";
            strSQL = strSQL + "FROM ";
            strSQL = strSQL + "               sensor.lecturas AS L ";
            strSQL = strSQL + "    INNER JOIN sensor.variables AS V ";
            strSQL = strSQL + "                                    ON(L.id_variable = V.id_variable) ";
            strSQL = strSQL + "    INNER JOIN sensor.equipos AS E ";
            strSQL = strSQL + "                                    ON(V.id_equipo = E.id_equipo) ";
            strSQL = strSQL + "    INNER JOIN sensor.ubicaciones AS U ";
            strSQL = strSQL + "                                    ON(E.id_ubicacion = U.id_ubicacion) ";
            strSQL = strSQL + "    INNER JOIN sensor.conexiones AS C ";
            strSQL = strSQL + "                                    ON(E.id_conexion = C.id_conexion) ";
            strSQL = strSQL + "WHERE ";
            strSQL = strSQL + "     L.analizada_lectura = " + pIdEstado;
            MySqlConnection MyConn = new MySqlConnection();

            MyConn = DbConexion.ObtenerConexion();
            MySqlCommand _comando = new MySqlCommand(String.Format(strSQL), MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Lectura pLectura = new Modelo.Lectura();
                pLectura.Id_Lectura               = _reader.GetInt32(0);
                pLectura.Fecha_Lectura            = _reader.GetDateTime(1);
                pLectura.Valor_Lectura            = _reader.GetString(2);
                pLectura.Id_Variable              = _reader.GetString(3);
                pLectura.Analizada_Lectura        = _reader.GetBoolean(4);
                pLectura.Nombre_Variable          = _reader.GetString(5);
                pLectura.Unidad_Variable          = _reader.GetString(6);
                pLectura.Alerta_Variable          = _reader.GetString(7);
                pLectura.Operador_Alerta_Variable = _reader.GetString(8);
                pLectura.Id_Equipo        = _reader.GetString(9);
                pLectura.Nombre_Equipo    = _reader.GetString(10);
                pLectura.Id_Ubicacion     = _reader.GetInt32(11);
                pLectura.Nombre_Ubicacion = _reader.GetString(12);
                pLectura.Id_Conexion      = _reader.GetInt32(13);
                pLectura.Nombre_Conexion  = _reader.GetString(14);

                _lista.Add(pLectura);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #15
0
        public static List <Modelo.Lectura> RecuperarUltimasLecturas()
        {
            List <Modelo.Lectura> _lista = new List <Modelo.Lectura>();
            string strSQL = @"
            SELECT 
                    L.id_lectura 
                  , L.fecha_lectura
                  , L.valor_lectura 
                  , L.id_variable 
                  , L.analizada_lectura 
                  , V.nombre_variable 
                  , V.unidad_variable 
                  , IFNULL(V.alerta_variable, '') AS alerta_variable 
                  ,  IFNULL(V.operador_alerta_variable, '') AS operador_alerta_variable 
                  , V.id_equipo 
                  , E.nombre_equipo 
                  , E.id_ubicacion 
                  , U.nombre_ubicacion 
                  , E.id_conexion 
                  , C.nombre_conexion 
                  , V.Alerta_Notificada 
                  , E.Sin_Conexion_Equipo 
            FROM sensor.lecturas AS L 
            INNER JOIN sensor.variables AS V 
                ON(L.id_variable = V.id_variable) 
            INNER JOIN sensor.equipos AS E 
                ON(V.id_equipo = E.id_equipo) 
            INNER JOIN sensor.ubicaciones AS U 
                ON(E.id_ubicacion = U.id_ubicacion) 
            INNER JOIN sensor.conexiones AS C 
                ON(E.id_conexion = C.id_conexion)
            INNER JOIN (SELECT  MAX(L.id_lectura) AS id_lectura, L.id_variable FROM lecturas AS L GROUP BY L.id_variable) AS sql_ 
                ON sql_.id_lectura = L.id_lectura 
            WHERE V.estado_variable = 0
            ORDER BY V.Id_Equipo
            ";

            MySqlConnection MyConn   = DbConexion.ObtenerConexion();
            MySqlCommand    _comando = new MySqlCommand(strSQL, MyConn);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Lectura pLectura = new Modelo.Lectura();
                pLectura.Id_Lectura               = _reader.GetInt32(0);
                pLectura.Fecha_Lectura            = _reader.GetDateTime(1);
                pLectura.Valor_Lectura            = _reader.GetString(2);
                pLectura.Id_Variable              = _reader.GetString(3);
                pLectura.Analizada_Lectura        = _reader.GetBoolean(4);
                pLectura.Nombre_Variable          = _reader.GetString(5);
                pLectura.Unidad_Variable          = _reader.GetString(6);
                pLectura.Alerta_Variable          = _reader.GetString(7);
                pLectura.Operador_Alerta_Variable = _reader.GetString(8);
                pLectura.Id_Equipo           = _reader.GetString(9);
                pLectura.Nombre_Equipo       = _reader.GetString(10);
                pLectura.Id_Ubicacion        = _reader.GetInt32(11);
                pLectura.Nombre_Ubicacion    = _reader.GetString(12);
                pLectura.Id_Conexion         = _reader.GetInt32(13);
                pLectura.Nombre_Conexion     = _reader.GetString(14);
                pLectura.Alerta_Notificada   = _reader.GetBoolean(15);
                pLectura.Sin_Conexion_Equipo = _reader.GetBoolean(16);

                _lista.Add(pLectura);
            }

            MyConn.Close();

            return(_lista);
        }
Beispiel #16
0
        public static List <Modelo.Lectura> ValoresMinimos_y_Maximos(string pIdVariable, DateTime pFDesde, DateTime pFHasta)
        {
            List <Modelo.Lectura> _lista = new List <Modelo.Lectura>();
            string          strSQL       = @"
            SELECT 
                    L.fecha_lectura
                  , MAX(L.valor_lectura) AS valor_maximo       
                  , MIN(L.valor_lectura) AS valor_minimo
                  , L.id_variable 
                  , V.nombre_variable 
                  , V.unidad_variable 
                  , V.id_equipo 
                  , E.nombre_equipo 
                  , E.id_ubicacion 
                  , U.nombre_ubicacion 
                  , E.id_conexion 
                  , C.nombre_conexion 
            FROM sensor.lecturas AS L 
            INNER JOIN sensor.variables AS V 
                ON(L.id_variable = V.id_variable) 
            INNER JOIN sensor.equipos AS E 
                ON(V.id_equipo = E.id_equipo) 
            INNER JOIN sensor.ubicaciones AS U 
                ON(E.id_ubicacion = U.id_ubicacion) 
            INNER JOIN sensor.conexiones AS C 
                ON(E.id_conexion = C.id_conexion)
            WHERE V.id_variable = @id_variable
                AND L.fecha_lectura BETWEEN @fecha_desde AND @fecha_hasta
            GROUP BY DATE_FORMAT(L.fecha_lectura, '%d/%m/%Y')
            ORDER BY L.fecha_lectura DESC
            ";
            MySqlConnection MyConn       = DbConexion.ObtenerConexion();
            MySqlCommand    _comando     = new MySqlCommand(strSQL, MyConn);

            _comando.Parameters.AddWithValue("@id_variable", pIdVariable);
            _comando.Parameters.AddWithValue("@fecha_desde", pFDesde);
            _comando.Parameters.AddWithValue("@fecha_hasta", pFHasta);

            MySqlDataReader _reader = _comando.ExecuteReader();

            while (_reader.Read())
            {
                Modelo.Lectura pLectura = new Modelo.Lectura();
                pLectura.Fecha_Lectura    = _reader.GetDateTime(0);
                pLectura.Valor_Maximo     = _reader.GetString(1);
                pLectura.Valor_Minimo     = _reader.GetString(2);
                pLectura.Id_Variable      = _reader.GetString(3);
                pLectura.Nombre_Variable  = _reader.GetString(4);
                pLectura.Unidad_Variable  = _reader.GetString(5);
                pLectura.Id_Equipo        = _reader.GetString(6);
                pLectura.Nombre_Equipo    = _reader.GetString(7);
                pLectura.Id_Ubicacion     = _reader.GetInt32(8);
                pLectura.Nombre_Ubicacion = _reader.GetString(9);
                pLectura.Id_Conexion      = _reader.GetInt32(10);
                pLectura.Nombre_Conexion  = _reader.GetString(11);

                _lista.Add(pLectura);
            }

            MyConn.Close();

            return(_lista);
        }