// GET: Metodologias/Create public ActionResult Create() { TodasLasClases todas = new TodasLasClases(); todas.Indicadores = db.Indicadores.ToList(); return(View(todas)); }
// GET: Cuentas1 public ActionResult Index() { if (Session["UserID"] != null) { TodasLasClases todas = new TodasLasClases(); todas.Cuentas = db.Cuentas.ToList(); todas.Empresas = db.Empresas.ToList(); return(View(todas)); } else { return(View("../Login/Index")); } }
// GET: Metodologias/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Metodologia metodologia = db.Metodologias.Find(id); if (metodologia == null) { return(HttpNotFound()); } List <Metodologia> Metodologias = new List <Metodologia>(); TodasLasClases todas = new TodasLasClases(); todas.Indicadores = db.Indicadores.ToList(); Metodologias.Add(metodologia); todas.Metodologias = Metodologias; return(View(todas)); }
public ActionResult Index(string EmpresaSeleccionada, string IndicadorSeleccionado, Nullable <DateTime> FechaInicial, Nullable <DateTime> FechaFinal) { TodasLasClases todas = new TodasLasClases(); todas.Indicadores = db.Indicadores.ToList(); todas.Empresas = db.Empresas.ToList(); List <Cuenta> cuentasParaIndicador = new List <Cuenta>(); List <Cuenta> cuentasDelaEmpresa = new List <Cuenta>(); //if (EmpresaSeleccionada != null) if (EmpresaSeleccionada != "") { int IDEmpresaSeleccionada = Convert.ToInt32(EmpresaSeleccionada); cuentasDelaEmpresa = db.Cuentas .Where(c => c.Empresa.ID == IDEmpresaSeleccionada) .ToList(); } else { cuentasDelaEmpresa = db.Cuentas.ToList(); } //Aca filtro por fechas if (FechaInicial != null && FechaFinal != null && FechaInicial <= FechaFinal) { List <Cuenta> cuentasEnFecha = new List <Cuenta>(); foreach (Cuenta cuentaActual in cuentasDelaEmpresa) { if ((cuentaActual.Fecha >= FechaInicial) && (cuentaActual.Fecha <= FechaFinal)) { cuentasEnFecha.Add(cuentaActual); } } todas.Cuentas = cuentasEnFecha; } else { todas.Cuentas = cuentasDelaEmpresa; } //Aca Evaluo los Indicadores if (IndicadorSeleccionado != "") { int IDIndicadorSeleccionado = Convert.ToInt32(IndicadorSeleccionado); List <Indicador> indicadorActual = new List <Indicador>(); indicadorActual = db.Indicadores .Where(c => c.ID == IDIndicadorSeleccionado) .ToList(); for (int i = 0; i <= todas.Cuentas.Count - 1; i++) { decimal ValorCuentaSeleccionada = todas.Cuentas[i].Valor; string FormulaIndicadorSeleccionado = indicadorActual[0].Formula; if (EmpresaSeleccionada == "") { cuentasParaIndicador = todas.Cuentas; } else { int idEmpresaParaIndicador = Convert.ToInt32(todas.Cuentas[i].Empresa.ID); cuentasParaIndicador = db.Cuentas .Where(c => c.Empresa.ID == idEmpresaParaIndicador) .ToList(); } Cuenta cuentaAux = new Cuenta(); cuentaAux = cuentasParaIndicador[i]; Indicador indicadorAux = new Indicador(); indicadorAux = indicadorActual[0]; List <IndicadorCuentaValor> indicadorCuentaValorActual = new List <IndicadorCuentaValor>(); indicadorCuentaValorActual = db.IndicadorCuentaValores .Where(icv => icv.Cuenta.ID == cuentaAux.ID && icv.Indicador.ID == indicadorAux.ID).ToList(); if (indicadorCuentaValorActual.Count > 0) { todas.Cuentas[i].ValorConIndicador = indicadorCuentaValorActual[0].Valor; indicadorCuentaValorActual = null; } else { IndicadorCuentaValor indicadorCuentaValor = new IndicadorCuentaValor(); todas.Cuentas[i].ValorConIndicador = evaluarIndicador(FormulaIndicadorSeleccionado, ValorCuentaSeleccionada, cuentasParaIndicador); indicadorCuentaValor.Cuenta = cuentasParaIndicador[i]; indicadorCuentaValor.Indicador = indicadorActual[0]; indicadorCuentaValor.Valor = todas.Cuentas[i].ValorConIndicador; db.IndicadorCuentaValores.Add(indicadorCuentaValor); db.SaveChanges(); } } } return(View(todas)); //return RedirectToAction("Index"); }
public ActionResult Index(HttpPostedFileBase postedFile, string EmpresaSeleccionada) { TodasLasClases todas = new TodasLasClases(); todas.Empresas = db.Empresas.ToList(); string filePath = string.Empty; if (postedFile != null) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(postedFile.FileName); string extension = Path.GetExtension(postedFile.FileName); postedFile.SaveAs(filePath); string csvData = System.IO.File.ReadAllText(filePath); foreach (string row in csvData.Split('\n')) { if (!string.IsNullOrEmpty(row)) { if (ModelState.IsValid) { Cuenta OtraCuenta = new Cuenta(); //db.Entry(OtraCuenta).State = EntityState.Modified; string NombreEmpresa = row.Split(',')[0]; string NombreCuenta = row.Split(',')[1]; OtraCuenta = db.Cuentas.Where(e => e.Nombre == NombreCuenta).FirstOrDefault(); if (OtraCuenta == null) { //La cuenta no existe y se crea una nueva Cuenta cuenta = new Cuenta(); //db.Entry(cuenta).State = EntityState.Modified; cuenta.Empresa = db.Empresas.Where(e => e.Nombre == NombreEmpresa).FirstOrDefault(); if (cuenta.Empresa != null) { cuenta.Nombre = row.Split(',')[1]; cuenta.Fecha = Convert.ToDateTime(row.Split(',')[2]); cuenta.Valor = Convert.ToDecimal(row.Split(',')[3]); cuenta.PasivoCirculante = Convert.ToDecimal(row.Split(',')[4]); db.Cuentas.Add(cuenta); db.SaveChanges(); } TempData["msgExpresionNoValida"] = "<script>alert('Empresa inexistente');</script>"; } else { //La cuenta existe y se actualiza Cuenta NewCuenta = db.Cuentas.Find(OtraCuenta.ID); //db.Entry(NewCuenta).State = EntityState.Modified; NewCuenta.Empresa = db.Empresas.Where(e => e.Nombre == NombreEmpresa).FirstOrDefault(); if (NewCuenta.Empresa != null) { NewCuenta.Fecha = Convert.ToDateTime(row.Split(',')[2]); NewCuenta.Valor = Convert.ToDecimal(row.Split(',')[3]); db.SaveChanges(); } TempData["msgExpresionNoValida"] = "<script>alert('Empresa inexistente');</script>"; } } } } return(RedirectToAction("Index")); } if (EmpresaSeleccionada != "") { int IDEmpresaSeleccionada = Convert.ToInt32(EmpresaSeleccionada); todas.Cuentas = db.Cuentas .Where(c => c.Empresa.ID == IDEmpresaSeleccionada) .ToList(); } else { todas.Cuentas = db.Cuentas.ToList(); } return(View(todas)); //return RedirectToAction("Index"); }
public ActionResult Index(string MetodologiaSeleccionada) { TodasLasClases todas = new TodasLasClases(); todas.Metodologias = db.Metodologias.ToList(); if (MetodologiaSeleccionada != "") { int IDMetodologia = Convert.ToInt32(MetodologiaSeleccionada); Metodologia metodologia = db.Metodologias .Where(c => c.ID == IDMetodologia) .First(); FechaInicialGlobal = metodologia.FechaInicial; FechaFinalGlobal = metodologia.FechaFinal; List <Empresa> empresas = new List <Empresa>(); string[] formulaSeparada = metodologia.Formula.Split('/'); string operacion = formulaSeparada[1]; decimal valor = Convert.ToDecimal(formulaSeparada[2].Replace(".", ",")); string formulaIndicador = ""; if (operacion != "Longevidad") { int idIndicador = Convert.ToInt32(formulaSeparada[0]); formulaIndicador = db.Indicadores .Where(c => c.ID == idIndicador) .First().Formula; } opcion = ""; if (formulaSeparada.Length == 4) { opcion = formulaSeparada[3]; } switch (operacion) { case ("Menor"): empresas = MayoroMenor(operacion, valor, formulaIndicador); break; case ("Mayor"): empresas = MayoroMenor(operacion, valor, formulaIndicador); break; case ("Maximo"): empresas = Maximo(formulaIndicador); break; case ("Minimo"): empresas = Minimo(formulaIndicador); break; case ("Longevidad"): empresas = Longevidad(valor); break; case ("Ascendiente"): empresas = CrecienteODecreciente(formulaIndicador, "Creciente"); break; case ("Descendiente"): empresas = CrecienteODecreciente(formulaIndicador, "Decreciente"); break; } todas.Empresas = empresas; } else { todas.Empresas = db.Empresas.ToList(); } return(View(todas)); }