Ejemplo n.º 1
0
 public IList<ValoresFuente> Valores(Ciudad city, int limite, dynamic options = null)
 {
     var sql = string.Format("select {0} * ", limite == 0 ? "" : "top " + limite);
     sql += " from v_predio where id_ciudad = @id order by clave, num_construccion";
     var str = ConfigurationManager.ConnectionStrings["riesgos"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var mapa = new Dictionary<string, ValoresFuente>();
     var reader = new SqlHelper(conn).ExecuteReader(sql, new { id = city.Id });
     while (reader.Read()) {
         var temp = new ValoresFuente();
         temp.Tipo = "construccion";
         Utils.FillDict(reader, temp);
         var cod = temp.GetString("clave");
         var num = temp.GetString("num_construccion") ?? "0";
         var key = Utils.MakeKey(cod, num);
         if (!mapa.ContainsKey(key)) {
             temp.Codigo1 = cod;
             temp.Codigo2 = num;
             temp.IdItem = temp["id"];
             mapa[key] = temp;
         }
         var cat = temp.GetString("clave_dato");
         if (!string.IsNullOrEmpty(cat))
             mapa[key][cat] = temp.GetString("valor_texto");
         temp.Remove("clave_dato");
         temp.Remove("valor_texto");
     }
     reader.Close();
     conn.Close();
     return mapa.Values.ToList();
 }
Ejemplo n.º 2
0
 public FuenteRedes(IList<FichaIndicadores> fichas, Ciudad city)
 {
     Fichas = fichas;
     City = city;
     MapaFichas = Fichas.Where(x => x.Nombre != "EDIFICACIONES")
         .ToDictionary(x => x.Nombre);
 }
Ejemplo n.º 3
0
 public IList<ValoresFuente> Valores(Ciudad city, int limite, dynamic options = null)
 {
     var top = limite > 0 ? "top " + limite : "";
     var sql = "select " + top + " * from sta_elena order by codigo_catastral";
     var str = ConfigurationManager.ConnectionStrings["riesgos"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var reader = new SqlHelper(conn).ExecuteReader(sql);
     var mapa = new Dictionary<string, ValoresFuente>();
     var i = 0;
     while (reader.Read()) {
         i++;
         var temp = new ValoresFuente();
         Utils.FillDict(reader, temp);
         var clave = temp.GetString("codigo_catastral");
         if (mapa.ContainsKey(clave))
             continue;
         var manzana = GetManzana(clave);
         temp.Tipo = "construccion";
         temp.Codigo1 = clave;
         temp.Codigo2 = manzana;
         temp.IdItem = i;
         temp["clave"] = clave;
         temp["manzana"] = manzana;
         mapa[clave] = temp;
     }
     reader.Close();
     conn.Close();
     return mapa.Values.ToList();
 }
Ejemplo n.º 4
0
 public int Total(Ciudad city, dynamic options = null)
 {
     const string sql = "select count(*) from v_reporte where manzana is not null ";
     var str = ConfigurationManager.ConnectionStrings["intelligov"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var total = new SqlHelper(conn).UniqueResult<int>(sql, new { id = city.Id });
     conn.Close();
     return total;
 }
Ejemplo n.º 5
0
 public int Total(Ciudad city, dynamic options = null)
 {
     const string sql = "select count(*) from v_predio where id_ciudad = @id ";
     var str = ConfigurationManager.ConnectionStrings["riesgos"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var total = new SqlHelper(conn).UniqueResult<int>(sql, new { id = city.Id });
     conn.Close();
     return total;
 }
Ejemplo n.º 6
0
 public int Total(Ciudad city, dynamic options = null)
 {
     const string sql = "select count(*) from sta_elena";
     var str = ConfigurationManager.ConnectionStrings["riesgos"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var total = new SqlHelper(conn).UniqueResult<int>(sql);
     conn.Close();
     return total;
 }
Ejemplo n.º 7
0
        public static int BorrarResultados(string proceso, string tipo, Ciudad ciudad)
        {
            var hql = @"delete from Resultado where Proceso = :proceso and Tipo_item=:tipo
            and Canton=:ciudad and Id_ciudad=:id_ciudad";
            var q = NHibernateHelper.GetCurrentSession().CreateQuery(hql);

            q.SetString("proceso", proceso)
                .SetString("tipo", tipo)
                .SetString("ciudad", ciudad.Nombre)
                .SetParameter("id_ciudad", ciudad.Id);
            return q.ExecuteUpdate();
        }
Ejemplo n.º 8
0
        public static string CrearCiudad(Ciudad ciudad)
        {
            try {
                using (var db = new Database("riesgos")) {
                    var cuenta = db.SingleOrDefault<int>("select count(id) from ciudad where nombre = @0", ciudad.Nombre);
                    if (cuenta > 0) return "Ya existe una ciudad con el mismo nombre";
                    db.Save("ciudad", "id", ciudad);
                    return "";
                }

            } catch (Exception ex) {
                return "Error de ejecución: " + ex.Message;
            }
        }
Ejemplo n.º 9
0
 public void Procesar(Ciudad ciudad)
 {
     // TODO: poner un unit of work en marcha
     Print("Proceso Manzanas, ciudad: " + ciudad.Nombre);
     try {
         var lista = CalcularManzanas(ciudad);
         Print("Resultados: " + lista.Count);
         if (lista.Count > 0) {
             var first = lista[0];
             Print("Borrando...");
             var borrados = RepoGeneral.BorrarResultados(first.Proceso, first.Tipo_item, ciudad);
             Print("Borrados: " + borrados);
             Print("Guardando...");
             Grabador.Guardar(lista, (num, msg) => Print("Guardados " + num));
             Print("Terminado");
         }
     } catch (Exception ex) {
         Print("Error: " + ex.Message, ex);
     }
 }
Ejemplo n.º 10
0
 public IList<Resultado> CalcularManzanas(Ciudad ciudad)
 {
     var lista = RepoGeneral.Resultados(new ResultadoForm {
         Ciudad = ciudad.Nombre, Orden = "Id_item", Tipo = "construccion"
     });
     var nuevos = new List<Resultado>();
     var grupos = lista.ToLookup(x => x.Codigo3);
     foreach (var grupo in grupos) {
         var res = ProcesosUtils.CrearRes(grupo.First());
         res.Nombre = grupo.Key;
         res.Tipo_item = "manzana";
         res.Codigo = grupo.Key;
         res.Numcomponentes = grupo.Count();
         res.Completo = grupo.Average(x => x.Completo);
         //var filtrados = grupo.Where(x => x.Completo.HasValue && x.Completo == 1);
         float area = 0;
         var map = new Dictionary<int, float>();
         //foreach (var dato in filtrados) {
         foreach (var dato in grupo) {
             if (dato.Area == null || dato.Completo == null || dato.Completo.Value < Tolerancia)
                 continue;
             res.Numevaluados += 1;
             area += dato.Area.Value;
             // OJO que aquí se debe generalizar más para que coja todos los indicadores
             ProcesosUtils.Adicionar(map, 1, dato.Indicador1, dato.Area);
             ProcesosUtils.Adicionar(map, 2, dato.Indicador2, dato.Area);
             ProcesosUtils.Adicionar(map, 3, dato.Indicador3, dato.Area);
             ProcesosUtils.Adicionar(map, 4, dato.Indicador4, dato.Area);
         }
         if (area > 0) {
             var keys = map.Keys.ToList();
             foreach (var key in keys) {
                 map[key] = map[key] / area;
             }
             ProcesosUtils.LlenarResultado(map, res);
             res.Area = area;
         }
         nuevos.Add(res);
     }
     return nuevos;
 }
Ejemplo n.º 11
0
 public IList<Resultado> AgruparPredios(Ciudad ciudad)
 {
     var lista = RepoGeneral.Resultados(new ResultadoForm {
         Ciudad = ciudad.Nombre, Orden = "Id_item", Tipo = "construccion"
     });
     var nuevos = new List<Resultado>();
     var grupos = lista.ToLookup(x => x.Id_item); // ojo, x.Codigo tal vez sea mas seguro, no se puede saber
     foreach (var grupo in grupos) {
         var first = grupo.First();
         var res = ProcesosUtils.CrearRes(first);
         res.Id_item = first.Id_item;
         res.Nombre = first.Nombre;
         res.Codigo = first.Codigo;
         res.Codigo2 = first.Codigo3;
         res.Tipo_item = "predio";
         res.Numcomponentes = grupo.Count();
         res.Completo = grupo.Average(x => x.Completo);
         float area = 0;
         var map = new Dictionary<int, float>();
         foreach (var dato in grupo) {
             if (dato.Area == null || dato.Completo == null || dato.Completo.Value < Tolerancia)
                 continue;
             res.Numevaluados += 1;
             area += dato.Area.Value;
             ProcesosUtils.Adicionar(map, 1, dato.Indicador1, dato.Area);
             ProcesosUtils.Adicionar(map, 2, dato.Indicador2, dato.Area);
             ProcesosUtils.Adicionar(map, 3, dato.Indicador3, dato.Area);
             ProcesosUtils.Adicionar(map, 4, dato.Indicador4, dato.Area);
         }
         if (area > 0) {
             var keys = map.Keys.ToList();
             foreach (var key in keys) {
                 map[key] = map[key] / area;
             }
             ProcesosUtils.LlenarResultado(map, res);
             res.Area = area;
         }
         nuevos.Add(res);
     }
     return nuevos;
 }
Ejemplo n.º 12
0
        private void btnCrear_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtNombre.Text) || string.IsNullOrEmpty(txtCodigo.Text)) {
                MessageBox.Show("Debe escribir el nombre y código de la ciudad");
                return;
            }
            var ciudad = new Ciudad {
                Codigo = txtCodigo.Text,
                Nombre = txtNombre.Text,
                Observaciones = txtObservaciones.Text
            };

            var res = RepoGeneral.CrearCiudad(ciudad);
            if (string.IsNullOrEmpty(res)) {
                DialogResult = DialogResult.OK;
                MessageBox.Show("Ciudad '" + ciudad.Nombre + "' Creada");
                Close();
            } else {
                MessageBox.Show(res);
            }
        }
Ejemplo n.º 13
0
 public IList<ValoresFuente> Valores(Ciudad city, int limite, dynamic options = null)
 {
     var top = limite > 0 ? "top " + limite : "";
     var sql = "select " + top + @" * from v_reporte v
     where manzana is not null
     order by predio_ID, num_edif, pisos, catalogo, categoria, valor_item";
     var str = ConfigurationManager.ConnectionStrings["intelligov"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var reader = new SqlHelper(conn).ExecuteReader(sql);
     var mapa = new Dictionary<string, ValoresFuente>();
     while (reader.Read()) {
         var temp = new ValoresFuente();
         Utils.FillDict(reader, temp);
         var clave = temp.GetString("predio_codigo");
         var numero = temp.GetString("num_edif");
         var key = string.Format("{0}.{1}", clave, numero);
         if (!mapa.ContainsKey(key)) {
             temp.Tipo = "construccion";
             temp.Codigo1 = clave;
             temp.Codigo2 = numero;
             temp.IdItem = temp["predio_ID"];
             temp["clave"] = clave;
             ResolverBloque(temp, numero);
             temp.Remove("valor_item");
             mapa[key] = temp;
         }
         var cat = temp.GetString("categoria");
         var valor = temp.GetString("item_id", "").Trim();
         if (string.IsNullOrEmpty(valor))
             continue;
         if (mapa[key].ContainsKey(cat))
             mapa[key][cat] += "," + valor;
         else
             mapa[key][cat] = valor;
     }
     reader.Close();
     conn.Close();
     return mapa.Values.ToList();
 }
Ejemplo n.º 14
0
        public IList<ValoresFuente> Valores(Ciudad city, int limite, dynamic options = null)
        {
            var top = limite > 0 ? "top " + limite : "";
            var sql = "select " + top + @" * from v_reporte
            where catalogo is not null
            order by zona,sector,manzana,solar, numero_edificacion, anio, area_construccion desc";

            var str = ConfigurationManager.ConnectionStrings["babahoyo"].ConnectionString;
            var conn = new SqlConnection(str);
            conn.Open();
            var mapa = new Dictionary<string, ValoresFuente>();
            var reader = new SqlHelper(conn).ExecuteReader(sql);
            while (reader.Read()) {
                var temp = new ValoresFuente();
                temp.Tipo = "construccion";
                Utils.FillDict(reader, temp);
                var cod = temp.GetString("codigo_predio");
                var num = temp.GetString("numero_edificacion");
                var key = Utils.MakeKey(cod, num);
                if (!mapa.ContainsKey(key)) {
                    var clave = ClaveCatastral(
                        temp["zona"], temp["sector"], temp["manzana"], temp["solar"]
                    );
                    temp["clave"] = clave;
                    temp.Codigo1 = clave;
                    temp.Codigo2 = temp.GetString("numero_edificacion");
                    temp.IdItem = temp["codigo_predio"];
                    mapa[key] = temp;
                }
                var cat = temp.GetString("catalogo");
                if (!string.IsNullOrEmpty(cat))
                    mapa[key][cat] = temp.GetString("valor_catalogo");
                temp.Remove("catalogo");
                temp.Remove("valor_catalogo");
            }
            reader.Close();
            conn.Close();
            return mapa.Values.ToList();
        }
Ejemplo n.º 15
0
 public IList<ValoresFuente> Valores(Ciudad city, int limite, dynamic options = null)
 {
     var top = limite > 0 ? "top " + limite : "";
     var sql = "select " + top + " * from v_reporte order by clave, bloque, piso, numero_pisos";
     var str = ConfigurationManager.ConnectionStrings["latacunga"].ConnectionString;
     var conn = new SqlConnection(str);
     conn.Open();
     var lista = new List<ValoresFuente>();
     var reader = new SqlHelper(conn).ExecuteReader(sql);
     while (reader.Read()) {
         var temp = new ValoresFuente();
         Utils.FillDict(reader, temp);
         temp.Tipo = "construccion";
         temp.Codigo1 = temp.GetString("clave");
         var key = string.Format("{0}.{1}", temp["bloque"], temp["piso"]);
         temp.Codigo2 = key;
         temp.IdItem = temp["id"];
         lista.Add(temp);
     }
     reader.Close();
     conn.Close();
     return lista;
 }