public static Models.FicheroIAP_Errores Procesar(string tipoFichero) { Models.FicheroIAP_Errores oRes = null; BLL.FicheroIAP bFichero = new BLL.FicheroIAP(); string sNombre = "FicheroIAP_" + HttpContext.Current.Session["IDFICEPI_ENTRADA"].ToString(); try { HttpPostedFile selectedFile = (HttpPostedFile)HttpContext.Current.Cache[sNombre]; if (selectedFile != null) { oRes = bFichero.Grabar(tipoFichero, selectedFile); } } catch (Exception ex) { throw (new Exception(ex.Message)); } finally { bFichero.Dispose(); HttpContext.Current.Cache.Remove(sNombre); } return(oRes); }
public static Models.FicheroIAP_Errores getErroresValidacion(string tipoFichero) { try { //var httpPostedFile = Session["FicheroIAP" + Session["IDFICEPI_ENTRADA"].ToString()]; string sNombre = "FicheroIAP_" + HttpContext.Current.Session["IDFICEPI_ENTRADA"].ToString(); HttpPostedFile httpPostedFile = (HttpPostedFile)HttpContext.Current.Cache[sNombre]; Models.FicheroIAP_Errores oRes = Validar(httpPostedFile, tipoFichero, int.Parse(HttpContext.Current.Session["IDFICEPI_ENTRADA"].ToString())); //HttpContext.Current.Cache[sNombre] = ""; return(oRes); } catch (Exception ex) { LogError.LogearError("Error al validar el fichero", ex); throw new Exception(System.Uri.EscapeDataString("Error al validar el fichero. " + ex.Message)); } finally { } }
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(); } }