Exemplo n.º 1
0
        private void dgvCompanias_Load()
        {
            dgvCompanias.DataSource = null;
            Companias Companias = new Companias();

            dgvCompanias.AutoGenerateColumns = false;
            dgvCompanias.DataSource          = Companias.GetAll();
            Companias.CloseConnection();
        }
Exemplo n.º 2
0
        private void BO_ReadFile(string fileName)
        {
            int              iLinea = 0;
            string           Linea;
            List <BO_Ticket> lstDetalles = new List <BO_Ticket>();
            BO_Ticket        oBO_Detalle = null;

            try
            {
                if (!File.Exists(fileName))
                {
                    return;
                }

                Companias       companias    = new Companias();
                List <Compania> lstCompanias = companias.GetAll();
                companias.CloseConnection();
                List <Compania> lstNuevasCompanias = new List <Compania>();

                semanaToImport.TicketsBO = new List <BO_Ticket>();

                StreamReader fileReader = new StreamReader(fileName);
                fileReader.ReadLine();
                while ((Linea = fileReader.ReadLine()) != null)
                {
                    iLinea++;
                    oBO_Detalle = BOActions.GetDetalles(ref Linea, iLinea, lstCompanias);
                    if (oBO_Detalle != null)
                    {
                        if (!lstCompanias.Any(x => x.Codigo == oBO_Detalle.Compania.Codigo) && !lstNuevasCompanias.Any(x => x.Codigo == oBO_Detalle.Compania.Codigo))
                        {
                            lstNuevasCompanias.Add(oBO_Detalle.Compania);
                        }
                        lstDetalles.Add(oBO_Detalle);
                    }
                }

                fileReader.Close();

                semanaToImport.TicketsBO = lstDetalles;
                semanaToImport.BOCargado = true;

                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 += "Código: " + x.Codigo + "\n");
                    mensaje += "\nPor favor, ingrese al \"ABM de Compañías\" y agregue estas compañías.\n";
                    mensaje += "Muchas gracias.";
                    MessageBox.Show(mensaje, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception Exception1)
            {
                MessageBox.Show("Error: " + Exception1.Message + "\nfileName: " + fileName + "\nline: " + iLinea, "Error");
            }
        }
Exemplo n.º 3
0
        public List <Over> Generar(Semana oSemana)
        {
            List <Over> lstOver         = new List <Over>();
            List <Over> lstOverCompania = new List <Over>();
            Over        oOverTotal      = null;

            Companias       Companias = new Companias();
            List <Compania> companias = Companias.GetAll();

            Companias.CloseConnection();

            List <BSP_Ticket> lstTicketsBSP = oSemana.TicketsBSP.Where(x => x.Concepto.Tipo == 'B').OrderBy(x => x.Compania.Codigo).ThenBy(x => x.Billete).ToList();

            foreach (Compania compania in companias.OrderBy(x => x.Codigo))
            {
                lstOverCompania = new List <Over>();

                foreach (BSP_Ticket oBSP_Ticket in lstTicketsBSP.Where(x => x.Compania.ID == compania.ID))
                {
                    BO_Ticket oBO_Ticket = oSemana.TicketsBO.Find(x => x.Billete == oBSP_Ticket.Billete && x.Compania.Codigo == oBSP_Ticket.Compania.Codigo);

                    if (oBSP_Ticket.ComOver != 0 || (oBO_Ticket != null && oBO_Ticket.ComOver != 0))
                    {
                        lstOverCompania.Add(GetOver(oBSP_Ticket, oBO_Ticket));
                    }
                }

                foreach (BO_Ticket bo_ticketFaltante in oSemana.TicketsBO.Where(x => x.Compania.ID == compania.ID && !lstTicketsBSP.Any(y => y.Billete == x.Billete && y.Compania.Codigo == compania.Codigo) && x.ComOver != 0).OrderBy(x => x.Billete))
                {
                    lstOverCompania.Add(GetOver(null, bo_ticketFaltante));
                }

                if (lstOverCompania.Count > 0)
                {
                    lstOver.AddRange(lstOverCompania);

                    oOverTotal                    = new Over();
                    oOverTotal.Boleto             = "TOTAL";
                    oOverTotal.Tr                 = compania.Codigo;
                    oOverTotal.OverRecPesos       = lstOverCompania.Select(x => x.OverRecPesos).Sum();
                    oOverTotal.OverPedPesos       = lstOverCompania.Select(x => x.OverPedPesos).Sum();
                    oOverTotal.OverRecDolares     = lstOverCompania.Select(x => x.OverRecDolares).Sum();
                    oOverTotal.OverPedDolares     = lstOverCompania.Select(x => x.OverPedDolares).Sum();
                    oOverTotal.DiferenciasPesos   = lstOverCompania.Select(x => x.DiferenciasPesos).Sum();
                    oOverTotal.DiferenciasDolares = lstOverCompania.Select(x => x.DiferenciasDolares).Sum();

                    lstOver.Add(oOverTotal);
                }
            }

            return(lstOver);
        }
Exemplo n.º 4
0
        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();
            }
        }