Exemple #1
0
        private List <Usuario> ReadAllAsync(MySqlDataReader reader)
        {
            posts = new List <Usuario>();


            while (reader.HasRows)
            {
                while (reader.Read())
                {
                    Usuario temp = new Usuario();
                    int     id   = Int32.Parse(reader[0].ToString());
                    temp.id = id;
                    int tipo = Int32.Parse(reader[4].ToString());
                    temp.tipo = tipo;

                    posts.Add(temp);
                }
                reader.NextResult();
            }
            try
            {
                Autenticacion.set_idUsuario(posts[0].id);
                Autenticacion.set_tipo(posts[0].tipo);
            }
            catch (Exception e) {
                return(new List <Usuario>());
            }
            return(posts);
        }
Exemple #2
0
        public List <Historial> llenarTablaHistorial()
        {
            var             connection = GetConnection().GetSection("ConnectionStrings").GetSection("Sersa").Value;
            MySqlConnection conn       = new MySqlConnection(connection);

            conn.Open();
            string sql = "";
            int    id  = Autenticacion.get_idUsuario();

            if (id == 5)
            {
                sql = "select h.id, h.nombre,h.fecha,h.identificadores from sersa.Historial h inner join sersa.InformexUsuario i on h.id = i.idInforme";
            }
            else
            {
                sql = "select h.id, h.nombre,h.fecha,h.identificadores from sersa.Historial h inner join sersa.InformexUsuario i on h.id = i.idInforme where i.idUsuario = " + id;
            }
            MySqlCommand    cmd = new MySqlCommand(sql, conn);
            MySqlDataReader rdr = cmd.ExecuteReader();

            List <Historial> lista = new List <Historial>();

            while (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    Historial temp      = new Historial();
                    string    col1Value = rdr[0].ToString();
                    temp.id = col1Value;
                    string col2Value = rdr[1].ToString();
                    temp.nombre = col2Value;
                    if (temp.nombre == "")
                    {
                        temp.nombre = "Administrador";
                    }
                    string          col3Value   = rdr[2].ToString();
                    double          col3Double  = Double.Parse(col3Value);
                    System.DateTime colDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                    colDateTime = colDateTime.AddSeconds(col3Double).ToLocalTime();
                    temp.Fecha  = colDateTime.ToString("dd/MM/yyyy");
                    string col4Value = rdr[3].ToString();
                    temp.identificadores = col4Value;
                    lista.Add(temp);
                }
                rdr.NextResult();
            }
            return(lista);
        }
Exemple #3
0
        private string[] ReadAllAsyncAsada(MySqlDataReader reader)
        {
            string[] asadas = new string[10];

            int cont = 0;

            while (reader.HasRows)
            {
                while (reader.Read())
                {
                    asadas[cont + 1] = reader[1].ToString();
                    Autenticacion.set_idAsada(asadas[cont + 1]);
                }
                reader.NextResult();
            }



            return(asadas);
        }
Exemple #4
0
        public List <Mapa> obtenerPuntos(long fechaInicio, long fechaFin, List <int> tipos)
        {
            string asada = Autenticacion.get_idAsada();

            string res = "";

            //Conexion escondida
            var             connection = GetConnection().GetSection("ConnectionStrings").GetSection("Sersa").Value;
            MySqlConnection conn       = new MySqlConnection(connection);

            conn.Open();

            res += "(";

            foreach (int tipo in tipos)
            {
                //res += "'";
                res += tipo.ToString();
                res += ",";
            }
            res.TrimEnd(',');
            res += ")";

            string sql1 = "SELECT f.tipo_formulario, f.latitud, f.longitud, f.acueducto, f.infraestructura FROM sersa.Formulario AS f WHERE (f.fecha BETWEEN @fechaI AND @fechaF) AND (f.tipo_formulario IN";

            sql1 += "(";
            foreach (int tipo in tipos)
            {
                sql1 += "'" + tipo.ToString() + "',";
            }
            string sql = sql1.Remove(sql1.Length - 1, 1);

            if (asada != null)
            {
                sql += ")) AND (f.asada = @asada) AND (f.latitud BETWEEN -90 AND 90) AND (f.longitud BETWEEN -180 AND 180)";
            }
            else
            {
                sql += ")) AND (f.latitud BETWEEN -90 AND 90) AND (f.longitud BETWEEN -180 AND 180)";
            }

            MySqlCommand cmd = new MySqlCommand(sql, conn);

            cmd.Parameters.AddWithValue("@fechaI", fechaInicio);
            cmd.Parameters.AddWithValue("@fechaF", fechaFin);
            cmd.Parameters.AddWithValue("@asada", asada);
            cmd.Parameters.AddWithValue("@res", res);
            MySqlDataReader rdr = cmd.ExecuteReader();

            List <Mapa> lista = new List <Mapa>();

            while (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    Mapa temp      = new Mapa();
                    int  col1Value = (int)rdr[0];
                    temp.tipo = col1Value;
                    string col2Value = rdr[1].ToString();
                    temp.latitud = col2Value;
                    string col3Value = rdr[2].ToString();
                    temp.longitud = col3Value;
                    string col4Value = rdr[3].ToString();
                    temp.acueducto = col4Value;
                    string col5Value   = rdr[4].ToString();
                    int    riesgoTotal = 0;

                    var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(col5Value);
                    foreach (var kv in dict)
                    {
                        if (kv.Value == "Si")
                        {
                            riesgoTotal++;
                        }
                    }

                    temp.riesgo = riesgoTotal;

                    lista.Add(temp);
                }
                rdr.NextResult();
            }
            return(lista);
        }