/// <summary>
        /// Genera el reporte de crystal
        /// </summary>
        private void ObtenerReporte_CR()
        {
            try
            {
                var organizacion = (OrganizacionInfo)cmbOrganizacion.SelectedItem;

                if (organizacion == null || organizacion.OrganizacionID == 0)
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.ReporteProyector_MsgSelecioneOrganizacion,
                                      MessageBoxButton.OK, MessageImage.Warning);
                    cmbOrganizacion.Focus();
                    return;
                }

                string division = AuxDivision.ObtenerDivision(organizacion.OrganizacionID);

                List <ReporteProyectorInfo> resultadoInfo = ObtenerReporteProyector(organizacion.OrganizacionID);

                if (resultadoInfo != null && resultadoInfo.Count > 0)
                {
                    foreach (var dato in resultadoInfo)
                    {
                        dato.Titulo       = Properties.Resources.ReporteProyector_TituloReporte;
                        dato.Organizacion = String.Format(Properties.Resources.Reporte_NombreEmpresa, division);
                        dato.FechaReporte = DateTime.Now;
                    }

                    var documento = new ReportDocument();
                    var reporte   = String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "\\Reporte\\RptProyector.rpt");
                    documento.Load(reporte);


                    documento.DataSourceConnections.Clear();
                    documento.SetDataSource(resultadoInfo);
                    documento.Refresh();


                    var forma = new ReportViewer(documento, Properties.Resources.ReporteProyector_TituloReporte);
                    forma.rptReportViewerControl.ToggleSidePanel = Constants.SidePanelKind.None;
                    forma.MostrarReporte();
                    forma.Show();
                }
                else
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.RecepcionReporteEjecutivo_MsgSinInformacion,
                                      MessageBoxButton.OK, MessageImage.Warning);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  Properties.Resources.ReporteProyector_ErrorExcel, MessageBoxButton.OK,
                                  MessageImage.Error);
            }
        }
Example #2
0
 /// <summary>
 /// Inicializa el Contexto
 /// </summary>
 private void InicializaContexto()
 {
     Contexto = new SIE.Services.Info.Modelos.AlimentacionEstadoComederoModel();
     Contexto.OrganizacionID = AuxConfiguracion.ObtenerOrganizacionUsuario();
     Contexto.Division       = AuxDivision.ObtenerDivision(Contexto.OrganizacionID);
 }
        /// <summary>
        /// Método para exportar a excel
        /// </summary>
        /// <returns></returns>
        private void GenerarReporte()
        {
            try
            {
                List <ReporteRecuperacionMermaInfo> resultadoInfo = ObtenerReporte();

                if (resultadoInfo == null || resultadoInfo.Count == 0)
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.ReporteRecuperacionMerma_MsgSinInformacion,
                                      MessageBoxButton.OK, MessageImage.Warning);

                    return;
                }
                var organizacion = (OrganizacionInfo)cmbOrganizacion.SelectedItem;

                int organizacionId = organizacion.OrganizacionID;


                string division = AuxDivision.ObtenerDivision(organizacionId);

                string titulo = string.Format(Properties.Resources.ReporteVentaMuerte_RangoFecha,
                                              DtpFechaInicial.SelectedDate.Value.ToShortDateString(),
                                              DtpFechaFinal.SelectedDate.Value.ToShortDateString());

                foreach (var dato in resultadoInfo)
                {
                    dato.Titulo      = Properties.Resources.ReporteRecuperacionMerma_NombreReporte;
                    dato.RangoFechas = titulo;
                    dato.Organizacon = string.Format(Properties.Resources.Reporte_NombreEmpresa, division);
                }


                var documento = new ReportDocument();
                var reporte   = String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "\\Reporte\\RptReporteRecuperacionMerma.rpt");
                documento.Load(reporte);


                documento.DataSourceConnections.Clear();
                documento.SetDataSource(resultadoInfo);
                documento.Refresh();


                var forma = new ReportViewer(documento, Properties.Resources.ReporteRecuperacionMerma_NombreReporte);
                forma.MostrarReporte();
                forma.Show();
            }
            catch (ExcepcionServicio ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  ex.Message,
                                  MessageBoxButton.OK, MessageImage.Warning);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  Properties.Resources.RecepcionReporteRecuperacionMerma_MsgErrorExportarExcel, MessageBoxButton.OK, MessageImage.Error);
            }
        }
        internal void ExportarReporte()
        {
            if (fechaInicioReporte == null && fechaFinaReporte == null)
            {
                PuedeGenerarExcel = false;
                MostrarBotones    = Visibility.Hidden;
                MostrarMensaje(Properties.Resources.Reporte_MsgGeneradoConExito, MessageBoxButton.OK,
                               MessageImage.Correct);
            }
            else
            {
                int    organizacionID = AuxConfiguracion.ObtenerOrganizacionUsuario();
                string division       =
                    AuxDivision.ObtenerDivision(organizacionID);
                var exportarPrincipal =
                    new ExportarExcel <AlimentacionConsumoCorralReporte>
                {
                    Encabezados = ObtenerEncabezado(),
                    Datos       = new List <AlimentacionConsumoCorralReporte> {
                        Reporte
                    },
                    TituloReporte = string.Format(Properties.Resources.Reporte_NombreEmpresa, division),
                    NombreReporte = Properties.Resources.ReporteConsumoCorral_Titulo,
                    SubTitulo     =
                        string.Format(Properties.Resources.ReporteVentaMuerte_RangoFecha,
                                      fechaInicioReporte.Value.ToShortDateString(),
                                      fechaFinaReporte.Value.ToShortDateString()),
                    MostrarLogo   = true,
                    NombreArchivo =
                        string.Format(Properties.Resources.ReporteConsumoCorral_NombreArchivo,
                                      DateTime.Now.ToShortDateString().Replace("/", "-"))
                };

                var totalesDetalle = new List <AlimentacionConsumoCorralDetalle>();
                var totalDetalle   = new AlimentacionConsumoCorralDetalle
                {
                    DiasAnimal =
                        (Reporte.Totales[0].SumatoriaDiasAcumulados.HasValue
                                                    ? Reporte.Totales[0].SumatoriaDiasAcumulados.Value
                                                    : 0),
                    Importe =
                        (Reporte.Totales[0].SumatoriaCosto.HasValue
                                                    ? Reporte.Totales[0].SumatoriaCosto.Value
                                                    : 0),
                    KilosDia =
                        (Reporte.Totales[0].SumatoriaKilos.HasValue
                                                    ? Reporte.Totales[0].SumatoriaKilos.Value
                                                    : 0),
                    Fecha = Properties.Resources.Excel_LblTotal
                };
                totalesDetalle.Add(totalDetalle);
                var subtitulo = new StringBuilder();
                subtitulo.AppendFormat(Properties.Resources.ReporteVentaMuerte_RangoFecha,
                                       fechaInicioReporte.Value.ToShortDateString(),
                                       fechaFinaReporte.Value.ToShortDateString());
                subtitulo.AppendFormat("\r\n{0} {1}", Properties.Resources.ReporteConsumoCorral_Proveedor,
                                       Reporte.Proveedor);
                subtitulo.AppendFormat("\r\n{0} {1}", Properties.Resources.ReporteConsumoCorral_Corral,
                                       Reporte.Corral);
                subtitulo.AppendFormat("\r\n{0} {1}", Properties.Resources.ReporteConsumoCorral_TipoGanado,
                                       Reporte.TipoGanado);
                subtitulo.AppendFormat("\r\n{0} {1}", Properties.Resources.ReporteConsumoCorral_Proceso,
                                       Reporte.Proceso);
                var exportarDetalle =
                    new ExportarExcel <AlimentacionConsumoCorralDetalle>
                {
                    Encabezados   = ObtenerEncabezadoDetalle(),
                    Datos         = Reporte.Detalle,
                    Totales       = totalesDetalle,
                    TituloReporte = string.Format(Properties.Resources.Reporte_NombreEmpresa, division),
                    NombreReporte = Properties.Resources.ReporteConsumoCorral_Titulo,
                    SubTitulo     = subtitulo.ToString(),
                    MostrarLogo   = true,
                };

                var totales = new List <AlimentacionConsumoCorralTotal>();
                var total   = new AlimentacionConsumoCorralTotal
                {
                    TotalCosto                     = Reporte.Totales[0].SumatoriaCosto,
                    TotalDiasAcumulado             = Reporte.Totales[0].SumatoriaDiasAcumulados,
                    TotalDiasAcumuladoTransferidos =
                        reporte.Totales[0].SumatoriaDiasAcumuladosTransferidos,
                    TotalKilos  = Reporte.Totales[0].SumatoriaKilos,
                    KilosTrans  = Reporte.Totales[0].SumatoriaKilosTransferencia,
                    CostoTrans  = Reporte.Totales[0].SumatoriaCostoTransferencia,
                    CostoCorral = Reporte.Totales[0].SumatoriaCostoCorral,
                    KilosCorral = reporte.Totales[0].SumatoriaKilosCorral,
                    TotalDiasAcomuladoCorral = reporte.Totales[0].SumatoriaDiasAcumuladoCorral,
                    Formula = Properties.Resources.Excel_LblTotal,
                };

                totales.Add(total);
                var exportarTotales =
                    new ExportarExcel <AlimentacionConsumoCorralTotal>
                {
                    Encabezados   = ObtenerEncabezadoTotales(),
                    Datos         = Reporte.Totales,
                    Totales       = totales,
                    TituloReporte = string.Format(Properties.Resources.Reporte_NombreEmpresa, division),
                    NombreReporte = Properties.Resources.ReporteConsumoCorral_Titulo,
                    SubTitulo     = subtitulo.ToString(),
                    MostrarLogo   = true,
                };
                GeneraExcel(exportarPrincipal, exportarDetalle, exportarTotales);
            }
        }