public List <AcumuladoBE> detalleAcumulado(List <IndicadorDataBE> listaE) { List <AcumuladoBE> listaA = new List <AcumuladoBE>(); try { List <IndicadorDataBE> lista = new List <IndicadorDataBE>(); lista = listaE; int anioP = 0; string reducido = ""; foreach (var item in lista) { if (item.ID_PARAMETRO == 17) { item.VALOR = "0"; } else if (item.ID_PARAMETRO == 32) { string fecha = item.VALOR; fecha = fecha.Substring(0, 4); item.VALOR = fecha + "-01-01"; } else if (item.ID_PARAMETRO == 6) { anioP = Convert.ToInt32(item.VALOR); item.VALOR = Convert.ToString(anioP); } else if (item.ID_PARAMETRO == 11) { reducido = item.VALOR; } } //listaA.Add(new AcumuladoBE { anio = anioP, reducido = reducido }); if (lista[0].ID_MEDMIT != 12 && lista[0].ID_MEDMIT != 4 && lista[0].ID_ENFOQUE != 6 && lista[0].ID_ENFOQUE != 9) //add 08-09-20 { List <IndicadorDataBE> listaPr = new List <IndicadorDataBE>(); //anioP += 1; while (DateTime.Now.Year > anioP) { listaPr = IndicadorLN.CalculoIndicador(lista); foreach (var item in listaPr) { if (item.ID_PARAMETRO == 6) { item.VALOR = Convert.ToString(anioP + 1); } else if (item.ID_PARAMETRO == 11) { reducido = item.VALOR; } } listaA.Add(new AcumuladoBE { anio = anioP, reducido = reducido }); anioP += 1; } } else { List <IndicadorDataBE> listaPr = IndicadorLN.CalculoIndicador(lista); foreach (var item in listaPr) { if (item.ID_PARAMETRO == 6) { item.VALOR = Convert.ToString(anioP); } else if (item.ID_PARAMETRO == 11) { reducido = item.VALOR; } } listaA.Add(new AcumuladoBE { anio = anioP, reducido = reducido }); } } catch (Exception ex) { Log.Error(ex); } return(listaA); }
//public JsonResult ProcesarExcel(HttpPostedFileBase fledeclaracion, IndicadorBE entidad) public JsonResult ProcesarExcel(HttpPostedFileBase fledeclaracion, ParametroBE entidad) { //List<IndicadorBE> listaIndicadores = new List<IndicadorBE>(); //ResponseEntity itemRespuesta = new ResponseEntity(); //List<string> excelData = new List<string>(); //int pagina = 0; //if (fledeclaracion != null) //{ // //load the uploaded file into the memorystream // byte[] archivo = new byte[fledeclaracion.ContentLength]; // fledeclaracion.InputStream.Read(archivo, 0, fledeclaracion.ContentLength - 1); // using (MemoryStream stream = new MemoryStream(archivo)) // using (ExcelPackage excelPackage = new ExcelPackage(stream)) // { // //loop all worksheets // foreach (ExcelWorksheet worksheet in excelPackage.Workbook.Worksheets) // { // pagina++; // //loop all rows // if (pagina < 2) // { // for (int i = worksheet.Dimension.Start.Row; i <= worksheet.Dimension.End.Row; i++) // { // IndicadorBE item = new IndicadorBE(); // if (i > 1) // { // //loop all columns in a row // if (worksheet.Cells[i, 1].Value != null && worksheet.Cells[i, 2].Value != null && worksheet.Cells[i, 3].Value != null && worksheet.Cells[i, 4].Value != null && worksheet.Cells[i, 5].Value != null && worksheet.Cells[i, 6].Value != null && worksheet.Cells[i, 7].Value != null && worksheet.Cells[i, 8].Value != null) // { // for (int j = worksheet.Dimension.Start.Column; j <= worksheet.Dimension.End.Column; j++) // { // //add the cell data to the List // if (worksheet.Cells[i, j].Value != null) // { // excelData.Add(worksheet.Cells[i, j].Value.ToString()); // switch (j) // { // case 1: // item.ANNOB = int.Parse(worksheet.Cells[i, j].Value.ToString()); // item.ANNO_BASE = item.ANNOB; // break; // case 2: // item.INICIO_OPERACIONES = DateTime.FromOADate(long.Parse(worksheet.Cells[i, j].Value.ToString())); // break; // case 3: // item.ID_TIPO_VEHICULOB = int.Parse(worksheet.Cells[i, j].Value.ToString()); // item.ID_TIPO_VEHICULO_BASE = item.ID_TIPO_VEHICULOB; // break; // case 4: // break; // case 5: // item.ID_TIPO_COMBUSTIBLEB = int.Parse(worksheet.Cells[i, j].Value.ToString()); // item.ID_TIPO_COMBUSTIBLE_BASE = item.ID_TIPO_COMBUSTIBLEB; // break; // case 6: // break; // case 7: // item.KRVB = int.Parse(worksheet.Cells[i, j].Value.ToString()); // item.KRV_BASE = item.KRVB; // break; // case 8: // item.CANTIDADB = int.Parse(worksheet.Cells[i, j].Value.ToString()); // item.CANT_BASE = item.CANTIDADB; // break; // case 9: // item.FACTOR_RENDIMIENTO = double.Parse(worksheet.Cells[i, j].Value.ToString()); // item.F_RENDIMIENTO = item.FACTOR_RENDIMIENTO; // break; // } // } // } // item.ID_TIPO_FUENTEI = entidad.ID_TIPO_FUENTEI; // IndicadorBE Calculado = IndicadorLN.CalcularIndicador(item)[0]; // item.TOTAL_GEI_INIMIT = Calculado.TOTAL_GEI_INIMIT; // item.TOTAL_GEI_REDUCIDO = Calculado.TOTAL_GEI_REDUCIDO; // item.TOTAL_GEI_BASE = Calculado.TOTAL_GEI_BASE; // item.F_RENDIMIENTO = Calculado.FACTOR_RENDIMIENTO; // listaIndicadores.Add(item); // } // } // } // } // } // } //} //var jsonResult = Json(listaIndicadores, JsonRequestBehavior.AllowGet); //jsonResult.MaxJsonLength = int.MaxValue; //return jsonResult; List <IndicadorDataBE> listaData = new List <IndicadorDataBE>(); List <ParametroBE> listaParametro = new List <ParametroBE>(); //add List <ParametroBE> listaTemp = new List <ParametroBE>(); //add ParametroBE entTemp = new ParametroBE(); ResponseEntity itemRespuesta = new ResponseEntity(); List <string> excelData = new List <string>(); listaTemp = ParametroLN.ListarParametroCabeceraExcel(entidad); foreach (var item in listaTemp) { item.AGREGAR = 1; listaParametro.Add(item); if (item.ID_TIPO_CONTROL == 1) { if (item.ID_PARAMETRO != 6) { entTemp.AGREGAR = 0; listaParametro.Add(entTemp); } } } int pagina = 0; if (fledeclaracion != null) { //load the uploaded file into the memorystream byte[] archivo = new byte[fledeclaracion.ContentLength]; fledeclaracion.InputStream.Read(archivo, 0, fledeclaracion.ContentLength - 1); using (MemoryStream stream = new MemoryStream(archivo)) using (ExcelPackage excelPackage = new ExcelPackage(stream)) { //loop all worksheets foreach (ExcelWorksheet worksheet in excelPackage.Workbook.Worksheets) { pagina++; pagina++; var cant_column = worksheet.Dimension.End.Column; var ultimos = listaParametro.Count - cant_column; //loop all rows if (pagina < 3) { for (int i = worksheet.Dimension.Start.Row; i <= worksheet.Dimension.End.Row; i++) { IndicadorDataBE itemData = new IndicadorDataBE(); List <IndicadorDataBE> listaIndicadores = new List <IndicadorDataBE>(); if (i > 2) { //loop all columns in a row var validar = 0; for (int n = 0; n < cant_column; n++) { if (worksheet.Cells[i, (n + 1)].Value == null) { validar = 1; break; } } if (validar == 0) { for (int j = worksheet.Dimension.Start.Column; j <= worksheet.Dimension.End.Column; j++) { //add the cell data to the List if (worksheet.Cells[i, j].Value != null) { IndicadorDataBE item = new IndicadorDataBE(); excelData.Add(worksheet.Cells[i, j].Value.ToString()); item.ID_ENFOQUE = entidad.ID_ENFOQUE; item.ID_MEDMIT = entidad.ID_MEDMIT; item.ID_PARAMETRO = listaParametro[(j - 1)].ID_PARAMETRO; if (listaParametro[(j - 1)].ID_TIPO_DATO == 1) { var fec = Convert.ToString(DateTime.FromOADate(long.Parse(worksheet.Cells[i, j].Value.ToString()))); item.VALOR = Convert.ToDateTime(fec).ToString("yyyy-MM-dd"); //item.VALOR = Convert.ToString(DateTime.FromOADate(long.Parse(worksheet.Cells[i, j].Value.ToString()))); //item.VALOR = item.VALOR.Substring(0, 10); //item.VALOR = "2018-11-12"; //ALTERNO //string p = worksheet.Cells[i, j].Value.ToString(); //item.VALOR = Convert.ToDateTime(p).ToString("yyyy-MM-dd"); } else { item.VALOR = worksheet.Cells[i, j].Value.ToString(); } if (listaParametro[(j - 1)].AGREGAR == 1) { listaIndicadores.Add(item); } } else { IndicadorDataBE item = new IndicadorDataBE(); excelData.Add(worksheet.Cells[i, j].Value.ToString()); item.ID_ENFOQUE = entidad.ID_ENFOQUE; item.ID_MEDMIT = entidad.ID_MEDMIT; item.ID_PARAMETRO = listaParametro[(j - 1)].ID_PARAMETRO; item.VALOR = ""; } } for (int m = cant_column; m < listaParametro.Count; m++) { IndicadorDataBE item = new IndicadorDataBE(); item.ID_ENFOQUE = entidad.ID_ENFOQUE; item.ID_MEDMIT = entidad.ID_MEDMIT; item.ID_PARAMETRO = listaParametro[m].ID_PARAMETRO; item.VALOR = ""; listaIndicadores.Add(item); } itemData.listaInd = IndicadorLN.CalculoIndicador(listaIndicadores); listaData.Add(itemData); } } } } } } } var jsonResult = Json(listaData, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); //return Respuesta(itemRespuesta); }
//public JsonResult ProcesarExcel(HttpPostedFileBase fledeclaracion, IndicadorBE entidad) public JsonResult ProcesarExcel(HttpPostedFileBase fledeclaracion, ParametroBE entidad) { List <IndicadorDataBE> listaData = new List <IndicadorDataBE>(); try { List <ParametroBE> listaParametro = new List <ParametroBE>(); //add List <ParametroBE> listaTemp = new List <ParametroBE>(); //add ParametroBE entTemp = new ParametroBE(); ResponseEntity itemRespuesta = new ResponseEntity(); List <string> excelData = new List <string>(); listaTemp = ParametroLN.ListarParametroCabeceraExcel(entidad); foreach (var item in listaTemp) { item.AGREGAR = 1; listaParametro.Add(item); if (item.ID_TIPO_CONTROL == 1) { if (item.ID_PARAMETRO != 6) { entTemp.AGREGAR = 0; listaParametro.Add(entTemp); } } } int pagina = 0; if (fledeclaracion != null) { //load the uploaded file into the memorystream byte[] archivo = new byte[fledeclaracion.ContentLength]; fledeclaracion.InputStream.Read(archivo, 0, fledeclaracion.ContentLength - 1); using (MemoryStream stream = new MemoryStream(archivo)) using (ExcelPackage excelPackage = new ExcelPackage(stream)) { //loop all worksheets foreach (ExcelWorksheet worksheet in excelPackage.Workbook.Worksheets) { pagina++; pagina++; var cant_column = worksheet.Dimension.End.Column; var ultimos = listaParametro.Count - cant_column; //loop all rows if (pagina < 4) { List <IndicadorDataBE> listaDataTemp = new List <IndicadorDataBE>(); listaDataTemp = validar_campo(worksheet, entidad, listaParametro, cant_column); if (bandera == 1) { listaData = listaDataTemp; break; } for (int i = worksheet.Dimension.Start.Row; i <= worksheet.Dimension.End.Row; i++) { IndicadorDataBE itemData = new IndicadorDataBE(); List <IndicadorDataBE> listaIndicadores = new List <IndicadorDataBE>(); if (i > 3) { //loop all columns in a row var validar = 0; for (int n = 0; n < cant_column; n++) { if (worksheet.Cells[i, (n + 1)].Value == null) { validar = 1; break; } } if (validar == 0) { string anno = ""; for (int j = worksheet.Dimension.Start.Column; j <= worksheet.Dimension.End.Column; j++) { //add the cell data to the List if (worksheet.Cells[i, j].Value != null) { IndicadorDataBE item = new IndicadorDataBE(); excelData.Add(worksheet.Cells[i, j].Value.ToString()); item.ID_ENFOQUE = entidad.ID_ENFOQUE; item.ID_MEDMIT = entidad.ID_MEDMIT; item.ID_PARAMETRO = listaParametro[(j - 1)].ID_PARAMETRO; if (listaParametro[(j - 1)].ID_TIPO_DATO == 1) { var fec = Convert.ToString(DateTime.FromOADate(long.Parse(worksheet.Cells[i, j].Value.ToString()))); item.VALOR = Convert.ToDateTime(fec).ToString("yyyy-MM-dd"); if (item.VALOR == "1920-01-01") { item.VALOR = ""; } //item.VALOR = Convert.ToString(DateTime.FromOADate(long.Parse(worksheet.Cells[i, j].Value.ToString()))); //item.VALOR = item.VALOR.Substring(0, 10); //item.VALOR = "2018-11-12"; //ALTERNO //string p = worksheet.Cells[i, j].Value.ToString(); //item.VALOR = Convert.ToDateTime(p).ToString("yyyy-MM-dd"); } else { item.VALOR = worksheet.Cells[i, j].Value.ToString(); if (item.ID_PARAMETRO == 6) { anno = item.VALOR; } } if (listaParametro[(j - 1)].AGREGAR == 1) { listaIndicadores.Add(item); } } else { IndicadorDataBE item = new IndicadorDataBE(); excelData.Add(worksheet.Cells[i, j].Value.ToString()); item.ID_ENFOQUE = entidad.ID_ENFOQUE; item.ID_MEDMIT = entidad.ID_MEDMIT; item.ID_PARAMETRO = listaParametro[(j - 1)].ID_PARAMETRO; item.VALOR = ""; } } for (int m = cant_column; m < listaParametro.Count; m++) { IndicadorDataBE item = new IndicadorDataBE(); item.ID_ENFOQUE = entidad.ID_ENFOQUE; item.ID_MEDMIT = entidad.ID_MEDMIT; item.ID_PARAMETRO = listaParametro[m].ID_PARAMETRO; item.VALOR = ""; listaIndicadores.Add(item); } //itemData.listaInd = IndicadorLN.CalculoIndicador(listaIndicadores); itemData.listaAcumulado = detalleAcumulado(listaIndicadores); listaIndicadores[0].VALOR = anno; itemData.listaInd = IndicadorLN.CalculoIndicador(listaIndicadores); listaData.Add(itemData); } } } } } } } } catch (Exception ex) { Log.Error(ex); } var jsonResult = Json(listaData, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); //return Respuesta(itemRespuesta); }