public void GenerarReporte()
        {
            try
            {
                var encabezado                = new System.Collections.Generic.List <cEncabezado>();
                var listaIngresosActivos      = new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>();
                var listaIngresosDefinitivos  = new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>(); //COMUNES
                var listaIngresosDefinitivos2 = new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>(); //FEDERALES
                var listaIngresosDefinitivos3 = new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>(); //OTROS
                var centro = new SSP.Controlador.Catalogo.Justicia.cCentro().Obtener(GlobalVar.gCentro).FirstOrDefault();
                encabezado.Add(new cEncabezado()
                {
                    ImagenDerecha = Parametro.LOGO_ESTADO_BC,
                    TituloUno     = Parametro.ENCABEZADO1,
                    TituloDos     = Parametro.ENCABEZADO2,
                    NombreReporte = centro != null ? !string.IsNullOrEmpty(centro.DESCR) ? centro.DESCR.Trim() : string.Empty : string.Empty,
                    PieUno        = string.Format("Reporte de Sentenciados por Sexo, Fuero y Delito \n Del {0} Al {1}",
                                                  SelectedFechaInicial.HasValue ? SelectedFechaInicial.Value.ToString("dd/MM/yyyy") : string.Empty,
                                                  SelectedFechaFinal.HasValue ? SelectedFechaFinal.Value.ToString("dd/MM/yyyy") : string.Empty)
                });

                var _IngresosActivos = new SSP.Controlador.Catalogo.Justicia.cIngreso().ObtenerIngresosActivosPorFecha(GlobalVar.gCentro, SelectedFechaInicial, SelectedFechaFinal);
                var PrimerIngreso    = _IngresosActivos.Where(x => x.ID_CLASIFICACION_JURIDICA == "3" && x.CAUSA_PENAL.Any(y => y.CAUSA_PENAL_DELITO.Any() && y.ID_ESTATUS_CP == (short)eEstatusCausaPenal.ACTIVO));
                foreach (var item in PrimerIngreso)
                {//CAUSAS PENALES CON DELITOS, ACTIVAS, PRODUCTO DE UN INGRESO SENTENCIADO ACTIVO
                    foreach (var item2 in item.CAUSA_PENAL)
                    {
                        foreach (var item3 in item2.CAUSA_PENAL_DELITO)
                        {
                            listaIngresosActivos.Add(new cReportePrimeraVezFueroDelito
                            {
                                Delito  = item3.MODALIDAD_DELITO != null ? !string.IsNullOrEmpty(item3.MODALIDAD_DELITO.DESCR) ? item3.MODALIDAD_DELITO.DESCR.Trim() : string.Empty : string.Empty,
                                Fuero   = item2.CP_FUERO,
                                Hombres = item2.INGRESO != null ? item2.INGRESO.IMPUTADO != null ? item2.INGRESO.IMPUTADO.SEXO == "M" ? +1 : +0 : +0 : +0,
                                Mujeres = item2.INGRESO != null ? item2.INGRESO.IMPUTADO != null ? item2.INGRESO.IMPUTADO.SEXO == "F" ? +1 : +0 : +0 : +0,
                                Total   = (item2.INGRESO != null ? item2.INGRESO.IMPUTADO != null ? item2.INGRESO.IMPUTADO.SEXO == "M" ? +1 : +0 : +0 : +0) +
                                          (item2.INGRESO != null ? item2.INGRESO.IMPUTADO != null ? item2.INGRESO.IMPUTADO.SEXO == "F" ? +1 : +0 : +0 : +0)
                            });
                        }
                        ;
                    }
                    ;
                }
                ;

                if (listaIngresosActivos != null && listaIngresosActivos.Any())
                {
                    var GruposDelitos = listaIngresosActivos.GroupBy(x => x.Delito);
                    foreach (var item in GruposDelitos)
                    {
                        var _Comunes     = item.Any() ? item.Where(x => x.Fuero == "C") : null;
                        var _Federales   = item.Any() ? item.Where(x => x.Fuero == "F") : null;
                        var _OtrosFueros = item.Any() ? item.Where(x => x.Fuero != "C" && x.Fuero != "F") : null;

                        if (_Comunes != null && _Comunes.Any())
                        {
                            if (_Comunes.Any())
                            {
                                listaIngresosDefinitivos.Add(new cReportePrimeraVezFueroDelito
                                {
                                    Delito  = item.Key,
                                    Fuero   = "COMÚN",
                                    Hombres = _Comunes.Sum(x => x.Hombres),
                                    Mujeres = _Comunes.Sum(x => x.Mujeres),
                                    Total   = (_Comunes.Sum(x => x.Hombres)) + (_Comunes.Sum(x => x.Mujeres))
                                });
                            }
                        }

                        if (_Federales != null && _Federales.Any())
                        {
                            if (_Federales.Any())
                            {
                                listaIngresosDefinitivos2.Add(new cReportePrimeraVezFueroDelito
                                {
                                    Delito  = item.Key,
                                    Fuero   = "FEDERAL",
                                    Hombres = _Federales.Sum(x => x.Hombres),
                                    Mujeres = _Federales.Sum(x => x.Mujeres),
                                    Total   = (_Federales.Sum(x => x.Hombres)) + (_Federales.Sum(x => x.Mujeres))
                                });
                            }
                        }


                        if (_OtrosFueros != null && _OtrosFueros.Any())
                        {
                            if (_OtrosFueros.Any())
                            {
                                listaIngresosDefinitivos3.Add(new cReportePrimeraVezFueroDelito
                                {
                                    Delito  = item.Key,
                                    Fuero   = "SIN FUERO",
                                    Hombres = _OtrosFueros.Sum(x => x.Hombres),
                                    Mujeres = _OtrosFueros.Sum(x => x.Mujeres),
                                    Total   = (_OtrosFueros.Sum(x => x.Hombres)) + (_OtrosFueros.Sum(x => x.Mujeres))
                                });
                            }
                        }
                    }
                    ;
                }

                Reporte.LocalReport.ReportPath = "Reportes/rReporteSentenciados.rdlc";
                Reporte.LocalReport.DataSources.Clear();

                Microsoft.Reporting.WinForms.ReportDataSource ReportDataSource_Encabezado = new Microsoft.Reporting.WinForms.ReportDataSource();
                ReportDataSource_Encabezado.Name  = "DataSet1";
                ReportDataSource_Encabezado.Value = encabezado;

                Microsoft.Reporting.WinForms.ReportDataSource ReportDataSource_Motivos = new Microsoft.Reporting.WinForms.ReportDataSource();
                ReportDataSource_Motivos.Name  = "DataSet2";
                ReportDataSource_Motivos.Value = listaIngresosDefinitivos != null?listaIngresosDefinitivos.Any() ? listaIngresosDefinitivos.OrderBy(x => x.Delito).ToList() : new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>() : new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>();

                Microsoft.Reporting.WinForms.ReportDataSource ReportDataSource_Motivos2 = new Microsoft.Reporting.WinForms.ReportDataSource();
                ReportDataSource_Motivos2.Name  = "DataSet3";
                ReportDataSource_Motivos2.Value = listaIngresosDefinitivos2 != null?listaIngresosDefinitivos2.Any() ? listaIngresosDefinitivos2.OrderBy(x => x.Delito).ToList() : new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>() : new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>();

                Microsoft.Reporting.WinForms.ReportDataSource ReportDataSource_Motivos3 = new Microsoft.Reporting.WinForms.ReportDataSource();
                ReportDataSource_Motivos3.Name  = "DataSet4";
                ReportDataSource_Motivos3.Value = listaIngresosDefinitivos3 != null?listaIngresosDefinitivos3.Any() ? listaIngresosDefinitivos3.OrderBy(x => x.Delito).ToList() : new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>() : new System.Collections.Generic.List <cReportePrimeraVezFueroDelito>();

                Reporte.LocalReport.DataSources.Add(ReportDataSource_Encabezado);
                Reporte.LocalReport.DataSources.Add(ReportDataSource_Motivos);
                Reporte.LocalReport.DataSources.Add(ReportDataSource_Motivos2);
                Reporte.LocalReport.DataSources.Add(ReportDataSource_Motivos3);

                System.Windows.Application.Current.Dispatcher.Invoke((System.Action)(delegate
                {
                    Reporte.Refresh();
                    Reporte.RefreshReport();
                }));
            }

            catch (System.Exception exc)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al generar el reporte", exc);
            }
        }
Esempio n. 2
0
        private void ImprimirRecetaMedica()
        {
            try
            {
                if (SelectedNotaMedica == null)
                {
                    return;
                }

                ReportesView View = new ReportesView();
                PopUpsViewModels.ShowPopUp(this, PopUpsViewModels.TipoPopUp.OSCURECER_FONDO);
                View.Owner   = PopUpsViewModels.MainWindow;
                View.Closed += (s, e) => { PopUpsViewModels.ClosePopUp(PopUpsViewModels.TipoPopUp.OSCURECER_FONDO); };

                View.Show();

                var _UsuarioActual = new SSP.Controlador.Catalogo.Justicia.cUsuario().GetData(x => x.ID_USUARIO.Trim() == GlobalVar.gUsr).FirstOrDefault();
                cRecetaMedicaReporte DatosReporte = new cRecetaMedicaReporte()
                {
                    Edad           = SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO != null ? new Fechas().CalculaEdad(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.NACIMIENTO_FECHA).ToString() : string.Empty : string.Empty : string.Empty,
                    Fecha          = Fechas.GetFechaDateServer.ToString("dd/MM/yyyy"),
                    NoExpediente   = string.Format("{0} / {1}", SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.ID_ANIO.HasValue ? SelectedNotaMedica.ATENCION_MEDICA.ID_ANIO.Value.ToString() : string.Empty : string.Empty, SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.ID_IMPUTADO.HasValue ? SelectedNotaMedica.ATENCION_MEDICA.ID_IMPUTADO.Value.ToString() : string.Empty : string.Empty),
                    NombrePaciente = string.Format("{0} {1} {2}",
                                                   SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.NOMBRE) ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.NOMBRE.Trim() : string.Empty : string.Empty : string.Empty : string.Empty,
                                                   SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.PATERNO) ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.PATERNO.Trim() : string.Empty : string.Empty : string.Empty : string.Empty,
                                                   SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.MATERNO) ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.IMPUTADO.MATERNO.Trim() : string.Empty : string.Empty : string.Empty : string.Empty),
                    Estancia = string.Format("{0}-{1}{2}-{3}",
                                             SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR.EDIFICIO != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR.EDIFICIO.DESCR) ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR.EDIFICIO.DESCR.Trim() : string.Empty : string.Empty : string.Empty : string.Empty : string.Empty : string.Empty,
                                             SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR.DESCR) ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.SECTOR.DESCR.Trim() : string.Empty : string.Empty : string.Empty : string.Empty : string.Empty,
                                             SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.ID_CELDA) ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.CAMA.CELDA.ID_CELDA.Trim() : string.Empty : string.Empty : string.Empty : string.Empty,
                                             SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO != null ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.ID_UB_CAMA.HasValue ? SelectedNotaMedica.ATENCION_MEDICA.INGRESO.ID_UB_CAMA.Value.ToString() : string.Empty : string.Empty : string.Empty),
                    FC       = SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.FRECUENCIA_CARDIAC) ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.FRECUENCIA_CARDIAC.Trim() : string.Empty : string.Empty : string.Empty,
                    FR       = SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.FRECUENCIA_RESPIRA) ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.FRECUENCIA_RESPIRA.Trim() : string.Empty : string.Empty : string.Empty,
                    TA       = SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.TENSION_ARTERIAL) ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.TENSION_ARTERIAL.Trim() : string.Empty : string.Empty : string.Empty,
                    T        = SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.TEMPERATURA) ? SelectedNotaMedica.ATENCION_MEDICA.NOTA_SIGNOS_VITALES.TEMPERATURA.Trim() : string.Empty : string.Empty : string.Empty,
                    Servicio = SelectedNotaMedica.ATENCION_MEDICA != null ? SelectedNotaMedica.ATENCION_MEDICA.ATENCION_SERVICIO != null ? !string.IsNullOrEmpty(SelectedNotaMedica.ATENCION_MEDICA.ATENCION_SERVICIO.DESCR) ? SelectedNotaMedica.ATENCION_MEDICA.ATENCION_SERVICIO.DESCR.Trim() : string.Empty : string.Empty : string.Empty,
                    Generico = _UsuarioActual != null?string.Format("{0} {1} {2}",
                                                                    _UsuarioActual.EMPLEADO != null?_UsuarioActual.EMPLEADO.PERSONA != null? !string.IsNullOrEmpty(_UsuarioActual.EMPLEADO.PERSONA.NOMBRE)?_UsuarioActual.EMPLEADO.PERSONA.NOMBRE.Trim() : string.Empty : string.Empty : string.Empty,
                                                                        _UsuarioActual.EMPLEADO != null?_UsuarioActual.EMPLEADO.PERSONA != null? !string.IsNullOrEmpty(_UsuarioActual.EMPLEADO.PERSONA.PATERNO)?_UsuarioActual.EMPLEADO.PERSONA.PATERNO.Trim() : string.Empty : string.Empty : string.Empty,
                                                                            _UsuarioActual.EMPLEADO != null?_UsuarioActual.EMPLEADO.PERSONA != null? !string.IsNullOrEmpty(_UsuarioActual.EMPLEADO.PERSONA.MATERNO)?_UsuarioActual.EMPLEADO.PERSONA.MATERNO.Trim() : string.Empty : string.Empty : string.Empty) : string.Empty,
                                   Generico2 = _UsuarioActual != null ? _UsuarioActual.EMPLEADO != null ? !string.IsNullOrEmpty(_UsuarioActual.EMPLEADO.CEDULA) ? _UsuarioActual.EMPLEADO.CEDULA.Trim() : string.Empty : string.Empty : string.Empty
                };

                System.Collections.Generic.List <cMedicamentosRecetaMedica> ListaMedicamentos = new System.Collections.Generic.List <cMedicamentosRecetaMedica>();
                if (LstMedicamentosConAnotaciones != null && LstMedicamentosConAnotaciones.Any())
                {
                    foreach (var item in LstMedicamentosConAnotaciones)
                    {
                        ListaMedicamentos.Add(new cMedicamentosRecetaMedica
                        {
                            Cantidad      = item.Cantidad,
                            Duracion      = item.Duracion,
                            Noche         = item.Noche,
                            Maniana       = item.Maniana,
                            Observaciones = item.Anotaciones,
                            Presentacion  = string.Format("{0} {1}", item.NombreMedicamento, !string.IsNullOrEmpty(item.OBSERVACIONES) ? string.Format("({0})", item.OBSERVACIONES.Trim()) : string.Empty),
                            UnidadMedida  = item.UnidadMedida,
                            Tarde         = item.Tarde,
                        });
                    }
                }
                ;

                var _CeresoActual = new SSP.Controlador.Catalogo.Justicia.cCentro().GetData(x => x.ID_CENTRO == GlobalVar.gCentro).FirstOrDefault();
                var Encabezado    = new cEncabezado()
                {
                    TituloUno       = _CeresoActual != null ? !string.IsNullOrEmpty(_CeresoActual.DESCR) ? _CeresoActual.DESCR.Trim() : string.Empty : string.Empty,
                    TituloDos       = Parametro.ENCABEZADO2,
                    ImagenIzquierda = Parametro.REPORTE_LOGO2,
                    ImagenFondo     = Parametro.REPORTE_LOGO_MEDICINA
                };

                View.Report.LocalReport.ReportPath = "Reportes/rRecetaMedica.rdlc";
                View.Report.LocalReport.DataSources.Clear();


                var ds1 = new System.Collections.Generic.List <cEncabezado>();
                ds1.Add(Encabezado);
                Microsoft.Reporting.WinForms.ReportDataSource rds1 = new Microsoft.Reporting.WinForms.ReportDataSource();
                rds1.Name  = "DataSet1";
                rds1.Value = ds1;
                View.Report.LocalReport.DataSources.Add(rds1);

                var ds2 = new System.Collections.Generic.List <cRecetaMedicaReporte>();
                ds2.Add(DatosReporte);
                Microsoft.Reporting.WinForms.ReportDataSource rds2 = new Microsoft.Reporting.WinForms.ReportDataSource();
                rds2.Name  = "DataSet2";
                rds2.Value = ds2;
                View.Report.LocalReport.DataSources.Add(rds2);

                Microsoft.Reporting.WinForms.ReportDataSource rds3 = new Microsoft.Reporting.WinForms.ReportDataSource();
                rds3.Name  = "DataSet3";
                rds3.Value = ListaMedicamentos;
                View.Report.LocalReport.DataSources.Add(rds3);
                View.Report.RefreshReport();
            }
            catch (System.Exception exc)
            {
                throw exc;
            }
        }