Example #1
0
        private void GenerarReporteAeronave()
        {
            var documento = new Document();

            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "PDF (*.pdf)|*.pdf";
            if (save.ShowDialog() == false)
            {
                return;
            }

            string path = save.FileName;

            try
            {
                PdfWriter.GetInstance(documento, new FileStream(path, FileMode.Create));
            }
            catch (IOException)
            {
                MessageBox.Show("Hubo un error al tratar de guardar el archivo.");
                return;
            }

            PdfPTable pdf = new PdfPTable(6);

            Aeronave aero = null;

            try
            {
                aero = Aeronave.GetAeronave(Matricula.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Error al conseguir la aeronave. ¿La matrícula ingresada existe?");
                return;
            }



            pdf.AddCell("Numero de vuelo");
            pdf.AddCell("Condicion de vuelo");
            pdf.AddCell("Tiempo de vuelo");
            pdf.AddCell("Origen de vuelo");
            pdf.AddCell("Destino de vuelo");
            pdf.AddCell("Matricula de aeronave");

            List <Vuelo> lista = Vuelo.getAllVuelosFromAeronave(aero.Matricula);

            foreach (var item in lista)
            {
                pdf.AddCell(item.NumeroVuelo.ToString());
                pdf.AddCell(item.CondicionVuelo.ToString());
                pdf.AddCell(item.TotalTiempoVuelo.ToString());
                pdf.AddCell(item.OrigenVuelo.ToString());
                pdf.AddCell(item.DestinoVuelo.ToString());
                pdf.AddCell(item.Aeronave.Matricula.ToString());
            }

            iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph();

            par.Add("Lista de vuelos para la aeronave cuya matrícula es " + aero.Matricula);

            documento.Open();
            documento.Add(par);
            documento.Add(Chunk.NEWLINE);
            documento.Add(Chunk.NEWLINE);
            documento.Add(pdf);
            documento.Close();
            MessageBox.Show("Reporte correctamente guardado.");
        }
Example #2
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            List <string> errores = ValidarVuelo();

            string erroresAMostrar = "Se encontraron los siguientes errores en el vuelo a ingresar:" + System.Environment.NewLine;

            foreach (var item in errores)
            {
                erroresAMostrar = string.Concat(erroresAMostrar + System.Environment.NewLine, item);
            }

            if (errores.Count > 0)
            {
                MessageBox.Show(erroresAMostrar, "Error");
                return;
            }

            int    noVuelo     = int.Parse(NoVuelo.Text);
            string condicion   = CondicionVuelo.Text;
            int    tiempoTotal = int.Parse(TiempoVuelo.Text);
            string destino     = DestinoVuelo.Text;

            string         matricula = Matricula.Text;
            string         origen    = OrigenVuelo.Text;
            List <Usuario> lista     = new List <Usuario>();

            Usuario piloto   = null;
            Usuario copiloto = null;

            try
            {
                piloto = Usuario.getUsuarioDeBD(Usuario.getRutFromString(RUT.Text));
            }
            catch (Exception)
            {
                MessageBox.Show("El piloto no existe.");
                return;
            }

            if (RutCopiloto.Text != string.Empty)
            {
                try
                {
                    copiloto = Usuario.getUsuarioDeBD(Usuario.getRutFromString(RutCopiloto.Text));
                }
                catch (Exception)
                {
                    MessageBox.Show("El copiloto no existe.");
                    return;
                }
                lista.Add(copiloto);
            }

            lista.Add(piloto);

            Aeronave ae = null;

            try
            {
                ae = Aeronave.GetAeronave(matricula);
            }
            catch (Exception)
            {
                MessageBox.Show("El aeronave no existe.");
                return;
            }



            Vuelo vue = new Vuelo(noVuelo, condicion, tiempoTotal, origen, destino, ae, lista);

            vue.Coordenadas = File.ReadAllText(Json);


            if (vue.GuardarVuelo() > 0)
            {
                MessageBox.Show("Vuelo guardado correctamente.");
            }
        }