public BSP_Ticket_Detalle GetTicketDetalle(string Linea) { BSP_Ticket_Detalle oBSP_Ticket_Detalle = new BSP_Ticket_Detalle(); try { oBSP_Ticket_Detalle.ISO = Linea.Substring(49, 2).Trim(); oBSP_Ticket_Detalle.ImpContado = GetTicket_ObtenerDecimal(GetStringByIndex(Linea, 52, 9)); oBSP_Ticket_Detalle.ImpCredito = GetTicket_ObtenerDecimal(GetStringByIndex(Linea, 61, 11)); oBSP_Ticket_Detalle.IVA21 = GetTicket_ObtenerDecimal(GetStringByIndex(Linea, 83, 12)); oBSP_Ticket_Detalle.Observaciones = GetStringByIndex(Linea, 144, 20).Trim(); } catch (Exception ex) { TextToFile.Errores(TextToFile.Error(ex)); } return(oBSP_Ticket_Detalle); }
public void BSP_ReadPdfFile(string fileName) { int page = 0, index = 0; string currentText = ""; BSP_Ticket oBSP_Ticket = null; BSP_Ticket_Detalle oBSP_Ticket_Detalle = null; Companias companias = new Companias(); List <Compania> lstCompanias = companias.GetAll(); Compania oCompaniaActual = null; string strFinCompania = ""; List <Compania> lstNuevasCompanias = new List <Compania>(); Conceptos conceptos = new Conceptos(); List <Concepto> lstConceptos = conceptos.GetAll(); Concepto oConceptoActual = null; string strFinConcepto = ""; BSP_Rg Tipo = BSP_Rg.Ambas; int CompaniaID = 0; string Linea = ""; try { if (File.Exists(fileName)) { semanaToImport.TicketsBSP = new List <BSP_Ticket>(); PdfReader pdfReader = new PdfReader(fileName); for (page = pageStart; page <= pdfReader.NumberOfPages; page++) { currentText = ""; currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, new SimpleTextExtractionStrategy()); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); string[] arrLineas = currentText.Split(new char[] { '\n' }); if (BSPActions.EsAnalisisDeVenta(ref arrLineas)) { string strTipo = arrLineas[3].Substring(21, 30).Trim(); Tipo = BSP_Rg.Ambas; if (strTipo == "DOMESTICO") { Tipo = BSP_Rg.Doméstico; } else if (strTipo == "INTERNACIONAL") { Tipo = BSP_Rg.Internacional; } if (Tipo != BSP_Rg.Ambas) //Si no estoy en el resumen final { for (index = 10; index < arrLineas.Length; index++) //10: Salteo cabecera { Linea = arrLineas[index]; if (Linea.Trim() != "") { if (oCompaniaActual == null && index == 10 && Linea.Length >= 3 && int.TryParse(Linea.Substring(0, 3), out CompaniaID)) //Si no estoy dentro de una compañía aerea... { oCompaniaActual = lstCompanias.Find(x => x.ID == CompaniaID); if (oCompaniaActual == null) { oCompaniaActual = new Compania() { ID = CompaniaID, Nombre = Linea.Substring(4).Trim() }; companias.Insertar(oCompaniaActual); lstCompanias.Add(oCompaniaActual); lstNuevasCompanias.Add(oCompaniaActual); } strFinCompania = "TOT " + Linea.Substring(4).Trim(); } else if (Linea.Length >= strFinCompania.Length && Linea.Substring(0, strFinCompania.Length) == strFinCompania) //Si estoy en el cierre de la compañía aerea... { oCompaniaActual = null; } else if (oConceptoActual == null) //Si estoy en la compañía aerea y no estoy dentro de un concepto... { oConceptoActual = lstConceptos.Find(x => x.Nombre.Length <= Linea.Length && x.Nombre.ToUpper() == Linea.Substring(0, x.Nombre.Length)); if (oConceptoActual != null) { strFinConcepto = "TOT " + (oConceptoActual.Nombre.Length >= 21 ? oConceptoActual.Nombre.Substring(0, 21) : oConceptoActual.Nombre).Trim().ToUpper(); } } else if (Linea.Length >= strFinConcepto.Length && Linea.Substring(0, strFinConcepto.Length) == strFinConcepto) //Si estoy en la compañía aerea y estoy en el cierre de un concepto { oConceptoActual = null; } else if (BSPActions.EsNuevoTicket(Linea)) //Si estoy en la compañía aerea y estoy en el concepto, y si los primeros 10 caracteres son long... { if (oBSP_Ticket != null) { semanaToImport.TicketsBSP.Add(oBSP_Ticket); oBSP_Ticket = null; } oBSP_Ticket = BSPActions.GetTicket(Linea, semanaToImport.Periodo.Year); oBSP_Ticket.Concepto = oConceptoActual; oBSP_Ticket.Compania = oCompaniaActual; oBSP_Ticket.Rg = Tipo; oBSP_Ticket_Detalle = BSPActions.GetTicketDetalle(Linea); //ACM y ADM if (listACM != null && oConceptoActual.Tipo == 'C') { ACM oACM = listACM.Find(x => x.Billete == oBSP_Ticket.Billete); if (oACM != null) { oBSP_Ticket_Detalle.Observaciones += (string.IsNullOrEmpty(oBSP_Ticket_Detalle.Observaciones) ? "" : "|") + oACM.Observaciones; } } if (listADM != null && oConceptoActual.Tipo == 'D') { ADM oADM = listADM.Find(x => x.Billete == oBSP_Ticket.Billete); if (oADM != null) { oBSP_Ticket_Detalle.Observaciones += (string.IsNullOrEmpty(oBSP_Ticket_Detalle.Observaciones) ? "" : "|") + oADM.Observaciones; } } oBSP_Ticket.Detalle.Add(oBSP_Ticket_Detalle); oBSP_Ticket_Detalle = null; } else if (oBSP_Ticket != null) { oBSP_Ticket_Detalle = BSPActions.GetTicketDetalle(Linea); oBSP_Ticket.Detalle.Add(oBSP_Ticket_Detalle); oBSP_Ticket_Detalle = null; } } } } else { Linea = arrLineas[10]; string strMoneda = Linea.Substring(("MONEDA: ").Length, 3); Moneda Moneda = strMoneda == "ARS" ? Moneda.Peso : Moneda.Dolar; foreach (BSP_Ticket bsp_ticket in semanaToImport.TicketsBSP.Where(x => x.Moneda == null)) { bsp_ticket.Moneda = Moneda; } if (oBSP_Ticket != null) { oBSP_Ticket.Moneda = Moneda; } } } } if (oBSP_Ticket != null) { semanaToImport.TicketsBSP.Add(oBSP_Ticket); oBSP_Ticket = null; } semanaToImport.TicketsBSP = semanaToImport.TicketsBSP.OrderBy(x => x.Compania.Codigo).ThenBy(x => x.Billete).ToList(); semanaToImport.BSPCargado = true; pdfReader.Close(); if (lstNuevasCompanias.Count > 0) { string mensaje = "Se han encontrado Compañías Aéreas que no estaban registradas en el sistema:\n\n"; lstNuevasCompanias.ForEach(x => mensaje += "ID: " + x.ID + " | Nombre: " + x.Nombre + "\n"); mensaje += "\nÉstas han sido guardadas automáticamente, pero el código alfanumérico deberá ser ingresado manualmente.\n"; mensaje += "Por favor, ingrese al \"ABM de Compañías\" y complete la información solicitada.\n"; mensaje += "Muchas gracias."; MessageBox.Show(mensaje, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception Exception1) { TextToFile.Errores(TextToFile.Error(Exception1)); MessageBox.Show("Error: " + Exception1.Message + "\nfileName: " + fileName + "\npage: " + page + "\nline: " + index, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { companias.CloseConnection(); conceptos.CloseConnection(); } }