Beispiel #1
0
        private void clic_reporte(object sender, SelectionChangedEventArgs e)
        {
            reporteSeleccionado = (Reporte)dg_reportes.SelectedItem;


            if (reporteSeleccionado != null)
            {
                wp_imagenes.Children.Clear();
                dp_fecha.SelectedDate = reporteSeleccionado.Fecha;
                tb_Descripcion.Text   = reporteSeleccionado.Descripcion;
                tb_direccion.Text     = reporteSeleccionado.Direccion;

                conductoresSeleccionados = new List <Conductor>();
                List <ConductoresReporte> conductoresDelReporte = ConductoresReporteDAO.getAllConductoresReportesByIdReporte(reporteSeleccionado.IdReporte);
                Conductor conductor;
                foreach (ConductoresReporte conductoresReporte in conductoresDelReporte)
                {
                    conductor = ConductorDAO.getConductoraById(conductoresReporte.IdConductor);
                    conductoresSeleccionados.Add(conductor);
                }

                vehiculosSeleccionados = new List <Vehiculo>();
                List <VehiculosReporte> vehiculosDelReporte = VehiculosReporteDAO.getAllVehiculosReporteByIdReporte(reporteSeleccionado.IdReporte);
                Vehiculo vehiculo;
                foreach (VehiculosReporte vehiculosReporte in vehiculosDelReporte)
                {
                    vehiculo = VehiculoDAO.getVehiculoById(vehiculosReporte.IdVehiculo);
                    vehiculosSeleccionados.Add(vehiculo);
                }

                String        actualPath = actualPath = System.IO.Path.GetTempPath();
                String        folderName = String.Format("/Reporte{0}", reporteSeleccionado.IdReporte);
                String        newPath    = actualPath + folderName;
                DirectoryInfo directory  = Directory.CreateDirectory(newPath);


                ConexionSFTP.bajarArchivo(newPath, folderName);

                FileInfo[] fileInfos = directory.GetFiles();

                Image fotografia = new Image();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    if (fileInfo.FullName != null)
                    {
                        Uri uri = new Uri(fileInfo.FullName);
                        fotografia        = new Image();
                        fotografia.Source = new BitmapImage(uri);
                        fotografia.Width  = 100;
                        fotografia.Height = 100;
                        wp_imagenes.Children.Add(fotografia);
                        fotografias.Add(fotografia);
                    }
                }
                actualizarTablaConductoresSeleccionados();
                actualizarTablaVehiculosSeleccionados();
            }
        }
        private void button_RegistrarReporte_Click(object sender, RoutedEventArgs e)
        {
            if (validarCampos())
            {
                if (conductoresSeleccionados.Count > 0)
                {
                    if (vehiculosSeleccionados.Count > 0)
                    {
                        if (images.Count >= 3)
                        {
                            Reporte reporte = new Reporte();
                            reporte.Direccion   = tb_direccion.Text;
                            reporte.Descripcion = tb_descripcion.Text;
                            reporte.Fecha       = (DateTime)dp_fecha.SelectedDate;
                            reporte.Estado      = "Activo";
                            ReporteDAO.addReporte(reporte);

                            int ultimoReporte = ReporteDAO.getLastIndex();

                            Dictamen dictamen = new Dictamen();
                            dictamen.Descripcion = "";
                            dictamen.Estado      = "Activo";
                            dictamen.Fecha       = (DateTime)dp_fecha.SelectedDate;
                            string hora = DateTime.Now.ToString("t");
                            dictamen.Hora      = hora;
                            dictamen.IdPerito  = 0;
                            dictamen.IdReporte = ultimoReporte;
                            dictamen.Folio     = ultimoReporte;
                            DictamenDAO.addDictamen(dictamen);



                            VehiculosReporte vehiculosReporte;
                            foreach (Vehiculo vehiculo in vehiculosSeleccionados)
                            {
                                vehiculosReporte            = new VehiculosReporte();
                                vehiculosReporte.IdReporte  = ultimoReporte;
                                vehiculosReporte.IdVehiculo = vehiculo.IdVehiculo;
                                VehiculosReporteDAO.addVehiculosReporte(vehiculosReporte);
                            }

                            ConductoresReporte conductoresReporte;
                            foreach (Conductor conductor in conductoresSeleccionados)
                            {
                                conductoresReporte             = new ConductoresReporte();
                                conductoresReporte.IdReporte   = ultimoReporte;
                                conductoresReporte.IdConductor = conductor.IdConductor;
                                ConductoresReporteDAO.addConductoresReporte(conductoresReporte);
                            }

                            try
                            {
                                foreach (Image imagen in images)
                                {
                                    String filepath = imagen.Source.ToString().Substring(8);
                                    String filename = String.Format("Reporte{0}", ultimoReporte);
                                    ConexionSFTP.subirArchivo(filepath, filename);
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                throw;
                            }
                            MessageBox.Show("Registro exitoso.");
                            limpiarCampos();
                        }
                        else
                        {
                            MessageBox.Show("Debe seleccionar al menos 3 fotografías.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Debe elegir al menos un vehículo.");
                    }
                }
                else
                {
                    MessageBox.Show("Debe elegir al menos un Conductor");
                }
            }
            else
            {
                MessageBox.Show("Asegúrese de llenar todos los campos.");
            }
        }