Beispiel #1
0
        private void GenerarReporteConQuery()
        {
            try
            {
                var centro       = new cCentro().Obtener(GlobalVar.gCentro).FirstOrDefault();
                var grafica      = new List <cReporteIncidenteGrafica>();
                var datosReporte = new List <cReporteDatos>();
                datosReporte.Add(new cReporteDatos()
                {
                    Encabezado1 = Parametro.ENCABEZADO1,
                    Encabezado2 = Parametro.ENCABEZADO2,
                    Encabezado3 = centro.DESCR.ToUpper().Trim(),
                    Logo1       = Parametro.REPORTE_LOGO1,
                    Logo2       = Parametro.REPORTE_LOGO2,
                    Titulo      = "INCIDENCIAS",
                    Centro      = centro.DESCR.ToUpper().Trim()
                });

                Application.Current.Dispatcher.Invoke((Action)(delegate
                {
                    Reporte.Reset();
                }));
                var reporte = new cIncidente().ObtenerReporteIncidente(GlobalVar.gCentro).Select(w => new cReporteIncidentes()
                {
                    INCIDENTE           = w.INCIDENTE,
                    COMUN_PROCESADO     = w.PROCESADO_COMUN,
                    COMUN_SENTENCIADO   = w.SENTENCIADO_COMUN,
                    SIN_FUERO_IMPUTADO  = w.SIN_FUERO_IMPUTADO,
                    SIN_FUERO_PROCESADO = w.SIN_FUERO_PROCESADO,
                });

                if (reporte != null)
                {
                    //imputados sin fuero
                    grafica.Add(new cReporteIncidenteGrafica()
                    {
                        TIPO  = "IMPUTADO\nSIN FUERO",
                        VALOR = reporte.Sum(w => w.SIN_FUERO_IMPUTADO)
                    });
                    //procesado fuero comun
                    grafica.Add(new cReporteIncidenteGrafica()
                    {
                        TIPO  = "PROCESADO\nFUERO COMUN",
                        VALOR = reporte.Sum(w => w.COMUN_PROCESADO)
                    });
                    //procesado sin fuero
                    grafica.Add(new cReporteIncidenteGrafica()
                    {
                        TIPO  = "PROCESADO\nSIN FUERO",
                        VALOR = reporte.Sum(w => w.SIN_FUERO_PROCESADO)
                    });
                    //sentenciado fuero comun
                    grafica.Add(new cReporteIncidenteGrafica()
                    {
                        TIPO  = "SENTENCIADO\nFUERO COMUN",
                        VALOR = reporte.Sum(w => w.COMUN_SENTENCIADO)
                    });
                }
                Application.Current.Dispatcher.Invoke((Action)(delegate
                {
                    Reporte.Reset();
                }));
                Reporte.LocalReport.ReportPath = "../../Reportes/rIncidente.rdlc";
                Reporte.LocalReport.DataSources.Clear();

                ReportDataSource rds1 = new ReportDataSource();
                rds1.Name  = "DataSet1";
                rds1.Value = datosReporte;
                Reporte.LocalReport.DataSources.Add(rds1);

                ReportDataSource rds2 = new ReportDataSource();
                rds2.Name  = "DataSet2";
                rds2.Value = reporte;
                Reporte.LocalReport.DataSources.Add(rds2);

                ReportDataSource rds3 = new ReportDataSource();
                rds3.Name  = "DataSet3";
                rds3.Value = grafica;
                Reporte.LocalReport.DataSources.Add(rds3);

                Application.Current.Dispatcher.Invoke((Action)(delegate
                {
                    Reporte.Refresh();
                    Reporte.RefreshReport();
                }));
            }
            catch (Exception ex)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al generar reporte.", ex);
            }
        }
        private void ImprimirActa()
        {
            try
            {
                if (SelectIncidentesCumplimentar == null)
                {
                    new Dialogos().ConfirmacionDialogo("Validación", "Favor de seleccionar una sanción");
                    return;
                }

                var documento = new cImputadoTipoDocumento().Obtener((short)enumTipoDocumentoImputado.ACTA_CONSEJO_TECNICO_INTERDICIPLINARIO);
                if (documento == null)
                {
                    new Dialogos().ConfirmacionDialogo("Validación", "No se encontro la plantilla del documento");
                    return;
                }

                using (var ms = new MemoryStream())
                {
                    ms.Write(documento.DOCUMENTO, 0, documento.DOCUMENTO.Length);
                    using (DocX doc = DocX.Load(ms))
                    {
                        var fecha = SelectIncidentesCumplimentar.Autorizacion_Fecha;
                        doc.ReplaceText("{hora}", fecha.Value.Hour + ":" + fecha.Value.Minute);
                        doc.ReplaceText("{dia}", fecha.Value.Day.ToString());
                        CultureInfo cultura = new CultureInfo("es-MX");
                        doc.ReplaceText("{mes}", cultura.DateTimeFormat.GetMonthName(fecha.Value.Month));
                        doc.ReplaceText("{anio}", fecha.Value.Year.ToString());

                        var incidente = new cIncidente().ObtenerTodas(
                            SelectIncidentesCumplimentar.Id_Centro,
                            SelectIncidentesCumplimentar.Id_Anio,
                            SelectIncidentesCumplimentar.Id_Imputado,
                            SelectIncidentesCumplimentar.Id_Ingreso,
                            SelectIncidentesCumplimentar.Id_Incidente
                            ).FirstOrDefault();
                        if (incidente != null)
                        {
                            var interno = incidente.INGRESO.IMPUTADO;
                            doc.ReplaceText("{interno}", string.Format("{0} {1} {2}", interno.NOMBRE.Trim(),
                                                                       !string.IsNullOrEmpty(interno.PATERNO) ? interno.PATERNO.Trim() : string.Empty,
                                                                       !string.IsNullOrEmpty(interno.MATERNO) ? interno.MATERNO.Trim() : string.Empty));
                            if (incidente.SANCION != null)
                            {
                                var fmenor = incidente.SANCION.OrderBy(w => w.INICIA_FEC).FirstOrDefault();
                                var fmayor = incidente.SANCION.OrderByDescending(w => w.TERMINA_FEC).FirstOrDefault();
                                if (fmenor != null && fmayor != null)
                                {
                                    doc.ReplaceText("{fecha_inicio}", string.Format("{0:dd/MM/yyyy}", fmenor.INICIA_FEC));
                                    doc.ReplaceText("{fecha_fin}", string.Format("{0:dd/MM/yyyy}", fmayor.TERMINA_FEC));
                                    var t = (fmayor.TERMINA_FEC.Value.Date - fmenor.INICIA_FEC.Value.Date).TotalDays;
                                    doc.ReplaceText("{días_sancion}", t.ToString());
                                }
                                foreach (var s in incidente.SANCION)
                                {
                                    switch (s.ID_SANCION)
                                    {
                                    case 2:
                                        doc.ReplaceText("{1}", "X");
                                        doc.ReplaceText("{2}", "X");
                                        break;

                                    case 3:
                                        doc.ReplaceText("{3}", "X");
                                        break;

                                    case 4:
                                        doc.ReplaceText("{4}", "X");
                                        break;

                                    case 5:
                                        doc.ReplaceText("{5}", "X");
                                        break;

                                    case 9:
                                        doc.ReplaceText("{7}", "X");
                                        break;

                                    case 10:
                                        doc.ReplaceText("{8}", "X");
                                        break;

                                    case 11:
                                        doc.ReplaceText("{9}", "X");
                                        break;

                                    case 12:
                                        doc.ReplaceText("{10}", "X");
                                        doc.ReplaceText("{11}", "X");
                                        break;
                                    }
                                }
                            }
                        }
                        doc.ReplaceText("{1}", " ");
                        doc.ReplaceText("{2}", " ");
                        doc.ReplaceText("{3}", " ");
                        doc.ReplaceText("{4}", " ");
                        doc.ReplaceText("{5}", " ");
                        doc.ReplaceText("{6}", " ");
                        doc.ReplaceText("{7}", " ");
                        doc.ReplaceText("{8}", " ");
                        doc.ReplaceText("{9}", " ");
                        doc.ReplaceText("{10}", " ");
                        doc.ReplaceText("{11}", " ");
                        doc.ReplaceText("{12}", " ");



                        doc.ReplaceText("{días_sancion}", " ");
                        doc.ReplaceText("{fecha_inicio}", " ");
                        doc.ReplaceText("{fecha_fin}", " ");

                        doc.Save();
                    }

                    var tc = new TextControlView();
                    PopUpsViewModels.ClosePopUp(PopUpsViewModels.TipoPopUp.OSCURECER_FONDO);
                    tc.editor.Loaded += (s, e) =>
                    {
                        try
                        {
                            tc.editor.Load(ms.ToArray(), TXTextControl.BinaryStreamType.WordprocessingML);
                        }
                        catch (Exception ex)
                        {
                            StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al mostrar el documento", ex);
                        }
                    };
                    tc.Owner   = PopUpsViewModels.MainWindow;
                    tc.Closed += (s, e) => { PopUpsViewModels.ClosePopUp(PopUpsViewModels.TipoPopUp.OSCURECER_FONDO); };
                    PopUpsViewModels.ShowPopUp(this, PopUpsViewModels.TipoPopUp.OSCURECER_FONDO);
                    tc.Show();
                }
            }
            catch (Exception ex)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al cargar datos", ex);
            }
        }