// GET: NominaExcel public ActionResult Start() { EsquemasExcelModel model = new EsquemasExcelModel(); if (sesion == null) { sesion = SessionDB.start(Request, Response, false, db); } model.sesion = sesion; model.clean(); Main view = new Main(); ViewBag.MainUser = view.CreateMenuInfoUser(sesion); ViewBag.Main = view.createMenu("Esquemas de pago", "Importar Esquemas", sesion); ViewBag.sedes = view.createSelectSedes("Sedes", sesion); ViewBag.DataTable = CreateDataTable(10, 1, null, "ID_ESQUEMA", "ASC", sesion); //Intercom ViewBag.User = sesion.nickName.ToString(); ViewBag.Email = sesion.nickName.ToString(); ViewBag.FechaReg = DateTime.Today; ViewBag.Scripts = Scripts.addScript() + Scripts.setPrivileges(Privileges, sesion); ViewBag.TIPO_BLOQUEO = getTiposDeBloqueo(new EsquemasModel()); if (!sesion.permisos.havePermission(Privileges[0].Permiso)) { return(View(Factory.View.NotAccess)); } ViewBag.sede = view.createLevels(sesion, "sedes"); return(View(Factory.View.Access + "EsquemasdePago/EsquemasExcel/Start.cshtml")); }
public ActionResult FindFirstError() { if ((sesion = SessionDB.start(Request, Response, false, db, SESSION_BEHAVIOR.AJAX)) == null) { return(Content("")); } EsquemasExcelModel model = new EsquemasExcelModel(); model.sesion = sesion; if (sesion.vdata.ContainsKey("EsquemasExcelError")) { return(Json(new { msg = Notification.Error(sesion.vdata["EsquemasExcelError"]) })); } int total; int maxErrors; string idsError; model.FindFirstError(out total, out maxErrors, out idsError); if (total == 0) { return(Json(new { msg = Notification.Warning("No se han encontrado registros auditados") })); } else if (maxErrors == 0) { return(Json(new { msg = Notification.Succes("Archivo auditado correctamente") })); } else { return(Json(new { msg = Notification.Error("" + maxErrors + " error(es). Esquemas: " + idsError) })); } }
public ActionResult Generar() { if ((sesion = SessionDB.start(Request, Response, false, db, SESSION_BEHAVIOR.AJAX)) == null) { return(Content("")); } EsquemasExcelModel model = new EsquemasExcelModel(); model.sesion = sesion; string str_bloqueos = Request.Params["bloqueos"]; int total, errores; model.generar(str_bloqueos, out total, out errores); if (errores == 0) { return(Json(new { msg = Notification.Succes("Esquemas importados correctamente") })); } else { return(Json(new { msg = Notification.Error("Error al momento de importar, " + errores + " / " + total + " registros no importados.") })); } }
public bool ValidarExcel(string fileName, SessionDB sesion, out List <EsquemasExcelModel> listModels, string sede) { listModels = new List <EsquemasExcelModel>(); EsquemasExcelModel auxModel = new EsquemasExcelModel(); auxModel.sesion = sesion; auxModel.clean(); auxModel.SedeX = sede; auxModel.cargaListas(); int paso = 1; ESQUEMA current = ESQUEMA.ESQUEMADEPAGO; // Cargar el excel en los modelos. try { using (ExcelPackage xlPackage = new ExcelPackage(new FileInfo(fileName))) { paso = 1; // 1.- Get the first worksheet in the workbook ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1]; Dictionary <string, int> col = new Dictionary <string, int>(); Dictionary <ESQUEMA, object> dataValid = new Dictionary <ESQUEMA, object>(); int start = worksheet.Dimension.Start.Column; int end = worksheet.Dimension.End.Column; int y = worksheet.Dimension.Start.Row; for (int x = start; x <= end; x++) { string head = worksheet.Cells[y, x].Text.ToUpper(); col.Add(head, x); } start = 1 + worksheet.Dimension.Start.Row; // se le suma 1 por las cabeceras end = worksheet.Dimension.End.Row; DateTime dt_1 = DateTime.Now; for (int row = start; row <= end; row++) { // ------------------- Parche para excluir las lineas vacias ------------------- bool emptyLine = true; for (int i = 1; i <= 14; i++) { if (string.IsNullOrWhiteSpace(worksheet.Cells[row, i].Text) == false) { emptyLine = false; break; } } if (emptyLine) { continue; } // ----------------------------------------------------------------------------- EsquemasExcelModel model = new EsquemasExcelModel(); model.sesion = sesion; paso = 2; // 2.- Se asignan los valores al modelo current = ESQUEMA.ESQUEMADEPAGO; model.EsquemaDePago = worksheet.Cells[row, col["ESQUEMADEPAGO"]].Text; current = ESQUEMA.CVE_SEDE; model.Sede = worksheet.Cells[row, col["CVE_SEDE"]].Text; current = ESQUEMA.PERIODO; model.Periodo = worksheet.Cells[row, col["PERIODO"]].Text; current = ESQUEMA.ESQUEMADEPAGODES; model.EsquemaDePagoDes = worksheet.Cells[row, col["ESQUEMADEPAGODES"]].Text; current = ESQUEMA.CVE_CONTRATO; model.ClaveContrato = worksheet.Cells[row, col["CVE_CONTRATO"]].Text; current = ESQUEMA.FECHAINICIO; model.FechaInicio = worksheet.Cells[row, col["FECHAINICIO"]].Text; current = ESQUEMA.FECHAFIN; model.FechaFin = worksheet.Cells[row, col["FECHAFIN"]].Text; current = ESQUEMA.NOSEMANAS; model.NumSemanas = worksheet.Cells[row, col["NOSEMANAS"]].Text; current = ESQUEMA.NOPAGOS; model.NumPagos = worksheet.Cells[row, col["NOPAGOS"]].Text; current = ESQUEMA.BLOQUEOCONTRATO; model.BloqueoContrato = worksheet.Cells[row, col["BLOQUEO"]].Text; current = ESQUEMA.CONCEPTO; model.Concepto = worksheet.Cells[row, col["CONCEPTO"]].Text; current = ESQUEMA.FECHAPAGO; model.FechaPago = worksheet.Cells[row, col["FECHAPAGO"]].Text; current = ESQUEMA.FECHARECIBO; model.FechaRecibo = worksheet.Cells[row, col["FECHARECIBO"]].Text; paso = 3; // 3.- Se validan model.copiaListasDesde(auxModel); model.Validate(); // 4.- Se guarda en la tabla temporal. model.Add_TMP(); listModels.Add(model); // 5.- Se agregan los datos al datatable. } DateTime dt_2 = DateTime.Now; Debug.WriteLine("span:" + (dt_2 - dt_1)); } // the using statement calls Dispose() which closes the package. sesion.vdata.Remove("EsquemasExcelError"); sesion.saveSession(); return(true); } catch (Exception) { if (paso == 1) { sesion.vdata["EsquemasExcelError"] = "Error en archivo de Excel"; } else if (paso == 2) { sesion.vdata["EsquemasExcelError"] = "No se encuentra la columna '" + current + "'"; } else if (paso == 3) { sesion.vdata["EsquemasExcelError"] = "Error validando Excel"; } sesion.saveSession(); return(false); } }