private static Models.FicheroIAP_Errores_Linea ponerFilaError(DesdeFicheroIAP oDesdeFicheroIAP, string sMens, string sEstructu, int iCont) { Models.FicheroIAP_Errores_Linea oLin = new Models.FicheroIAP_Errores_Linea(); DateTime fechaSalida; oLin.Fila = iCont; oLin.Usuario = oDesdeFicheroIAP.idusuario + "-" + oDesdeFicheroIAP.Profesional; if (DateTime.TryParse(oDesdeFicheroIAP.fechaDesde, out fechaSalida)) { oLin.Fecha = fechaSalida; } oLin.Tarea = oDesdeFicheroIAP.idtarea + "-" + oDesdeFicheroIAP.t332_destarea; oLin.Esfuerzo = Double.Parse(oDesdeFicheroIAP.esfuerzo.Replace(",", "."), CultureInfo.InvariantCulture); oLin.Error = sMens; if (sEstructu != "D") { if (DateTime.TryParse(oDesdeFicheroIAP.fechaHasta, out fechaSalida)) { oLin.FechaH = fechaSalida; } oLin.Festivos = oDesdeFicheroIAP.festivos; } return(oLin); }
private static Models.FicheroIAP_Errores_Linea validarCampos(DesdeFicheroIAP oDesdeFicheroIAP, bool bEscribir, string sEstructu, int iCont, Hashtable htTarea, Hashtable htProfesional) { TAREA oTarea; Models.FicheroIAP_Errores_Linea oRes = new Models.FicheroIAP_Errores_Linea(); if (oDesdeFicheroIAP.t332_idtarea == -99999) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "Formato incorrecto. El número de tarea no acepta puntos, signos(+,-) ni comas decimales, (" + oDesdeFicheroIAP.idtarea + ")", sEstructu, iCont); } } oTarea = (TAREA)htTarea[oDesdeFicheroIAP.idtarea]; if (oTarea == null) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "La tarea (" + oDesdeFicheroIAP.idtarea + ") no existe.", sEstructu, iCont); } } else { if ((oTarea.t332_estado == 3 || oTarea.t332_estado == 4) && oTarea.t332_impiap == false) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "La tarea (" + oDesdeFicheroIAP.idtarea + ") tiene el estado (cerrado o finalizado) y no permite imputar IAP.", sEstructu, iCont); } } else if (!(oTarea.t332_estado == 1 || ((oTarea.t332_estado == 3 || oTarea.t332_estado == 4) && oTarea.t332_impiap == true))) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "La tarea (" + oDesdeFicheroIAP.idtarea + ") tiene un estado no permitido para imputaciones (" + oTarea.t332_estado.ToString() + ")", sEstructu, iCont); } } else if (oTarea.t331_estado != 1) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "La tarea (" + oDesdeFicheroIAP.idtarea + ") tiene el estado de su proyecto técnico no activo.", sEstructu, iCont); } } } if (oDesdeFicheroIAP.t314_idusuario == -99999) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "Formato incorrecto. El número de usuario no acepta puntos, signos(+,-) ni comas decimales, (" + oDesdeFicheroIAP.idusuario + ")", sEstructu, iCont); } } if ((PROFESIONAL)htProfesional[oDesdeFicheroIAP.idusuario] == null) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "El usuario (" + oDesdeFicheroIAP.idusuario + ") no existe.", sEstructu, iCont); } } if (oDesdeFicheroIAP.t332_idtarea == -1) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "Número de tarea no numérico (" + oDesdeFicheroIAP.idtarea + ")", sEstructu, iCont); } } if (oDesdeFicheroIAP.t314_idusuario == -1) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "Número de usuario no numérico (" + oDesdeFicheroIAP.idusuario + ")", sEstructu, iCont); } } if (oDesdeFicheroIAP.t337_esfuerzo == -1) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "El valor del campo esfuerzo es no numérico (" + oDesdeFicheroIAP.esfuerzo + ")", sEstructu, iCont); } } if (oDesdeFicheroIAP.t337_esfuerzo == -99999) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "El valor del campo esfuerzo no acepta puntos ni signos (+,-), (" + oDesdeFicheroIAP.esfuerzo + ")", sEstructu, iCont); } } if (oDesdeFicheroIAP.t337_fechaDesde == null) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "El valor del campo fecha desde tiene el formato incorrecto o su valor no es válido (" + oDesdeFicheroIAP.fechaDesde + ")", sEstructu, iCont); } } //if (Request.Form[Constantes.sPrefijo + "rdbImputacion"].ToString() != "D") if (sEstructu != "D") { if (oDesdeFicheroIAP.t337_fechaHasta == null) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "El valor del campo fecha hasta tiene el formato incorrecto o su valor no es válido (" + oDesdeFicheroIAP.fechaHasta + ")", sEstructu, iCont); } } if (oDesdeFicheroIAP.bfestivos == null) { if (bEscribir) { oRes = ponerFilaError(oDesdeFicheroIAP, "El valor del campo permitir imputar a festivos o no laborables, o no es numérico o su valor no es válido (" + oDesdeFicheroIAP.festivos + ")", sEstructu, iCont); } } } return(oRes); }
private static Models.FicheroIAP_Errores Validar(HttpPostedFile selectedFile, string sEstructu, int idFicepi) { //StringBuilder sbE = new StringBuilder(); Models.FicheroIAP_Errores oRes = new Models.FicheroIAP_Errores(); List <Models.FicheroIAP_Errores_Linea> oListaE = new List <Models.FicheroIAP_Errores_Linea>(); bool bErrorControlado = false; BLL.FicheroIAP bFicheroIAP = new BLL.FicheroIAP(); //int idFicepi = int.Parse(Session["IDFICEPI_ENTRADA"].ToString()); int iCont = 0; int iNumOk = 0; string sErrores; Hashtable htT; Hashtable htP; try { //Vacío las caches //HttpContext.Current.Cache.Remove("TareasFicheroIAP_" + HttpContext.Current.Session["IDFICEPI_ENTRADA"].ToString()); //HttpContext.Current.Cache.Remove("ProfesionalesFicheroIAP_" + HttpContext.Current.Session["IDFICEPI_ENTRADA"].ToString()); try { htT = CargarArrayTareas(); htP = CargarArrayProfesionales(); } catch (Exception ex) { bErrorControlado = true; throw (new Exception(ex.Message)); } if (selectedFile.ContentLength != 0) { string sFichero = selectedFile.FileName; //Grabo el archivo en base de datos byte[] ArchivoEnBinario = new Byte[0]; ArchivoEnBinario = new Byte[selectedFile.ContentLength]; //Crear el array de bytes con la longitud del archivo selectedFile.InputStream.Read(ArchivoEnBinario, 0, selectedFile.ContentLength); //Forzar al control del archivo a cargar los datos en el array int iRows = bFicheroIAP.Update(Constantes.FicheroIAP, idFicepi, ArchivoEnBinario); if (iRows == 0) { bErrorControlado = true; throw (new Exception("No existe entrada asociada a este proceso en el fichero de Maniobra")); } selectedFile.InputStream.Position = 0; StreamReader r = new StreamReader(selectedFile.InputStream, System.Text.Encoding.UTF7); DesdeFicheroIAP oDesdeFicheroIAP = null; String strLinea = null; while ((strLinea = r.ReadLine()) != "") { if (strLinea == null) { break; } iCont++; try { oDesdeFicheroIAP = getLinea(DesdeFicheroIAP.getFila(strLinea, sEstructu), sEstructu, htT, htP); } catch (Exception ex) { bErrorControlado = true; //oDesdeFicheroIAP = new DesdeFicheroIAP(); //sbE.Append(ponerFilaError(oDesdeFicheroIAP, "Error al procesar el fichero de entrada en la línea (" + iCont + ") " + ex.Message, sEstructu, iCont)); Models.FicheroIAP_Errores_Linea oLinE = new Models.FicheroIAP_Errores_Linea(); oLinE.Error = "Error al procesar el fichero de entrada en la línea (" + iCont + ") " + ex.Message; oListaE.Add(oLinE); continue; } Models.FicheroIAP_Errores_Linea oLin = validarCampos(oDesdeFicheroIAP, true, sEstructu, iCont, htT, htP); if (oLin.Error == null) { iNumOk++; } else { oListaE.Add(oLin); } } } //if (sEstructu == "D") sFLS.Value = sCab1.Value + sbE.ToString() + sPie1.Value; //else sFLS.Value = sCab2.Value + sbE.ToString() + sPie2.Value; //nFilas.InnerText = iCont.ToString("#,##0"); //nFilasC.InnerText = iNumOk.ToString("#,##0"); //nFilasE.InnerText = (iCont - iNumOk).ToString("#,##0"); //this.hdnIniciado.Value = "T"; oRes.nFilas = iCont; oRes.nFilasC = iNumOk; oRes.nFilasE = iCont - iNumOk; if (oListaE.Count > 0) { oRes.Errores = oListaE; } //return iCont.ToString("#,##0") + "@#@" + iNumOk.ToString("#,##0") + "@#@" + (iCont - iNumOk).ToString("#,##0") + // "@#@" + sbE.ToString(); return(oRes); } catch (Exception ex) { if (bErrorControlado) { if (iCont != 0) { sErrores = "Error al procesar el fichero de entrada en la línea (" + iCont + ") " + ex.Message; } else { sErrores = ex.Message; } } else { sErrores = "El fichero no tiene el formato requerido para el proceso"; } throw (new Exception(sErrores)); } finally { bFicheroIAP.Dispose(); } }