/// *************************************************************************************
        /// NOMBRE: Generar_Reporte
        ///
        /// DESCRIPCIÓN: Método que invoca la generación del reporte.
        ///
        /// PARÁMETROS: Nombre_Plantilla_Reporte.- Nombre del archivo del Crystal Report.
        ///             Nombre_Reporte_Generar.- Nombre que tendrá el reporte generado.
        ///
        /// USUARIO CREO: Juan Alberto Hernández Negrete.
        /// FECHA CREO: 3/Mayo/2011 18:15 p.m.
        /// USUARIO MODIFICO:
        /// FECHA MODIFICO:
        /// CAUSA MODIFICACIÓN:
        /// *************************************************************************************
        protected void Generar_Reporte(ref DataSet Ds_Datos, String Nombre_Plantilla_Reporte)
        {
            ReportDocument Reporte = new ReportDocument(); //Variable de tipo reporte.
            String         Ruta    = String.Empty;         //Variable que almacenara la ruta del archivo del crystal report.

            try
            {
                Ruta = (Nombre_Plantilla_Reporte);
                Reporte.Load(Ruta);

                if (Ds_Datos is DataSet)
                {
                    if (Ds_Datos.Tables.Count > 0)
                    {
                        Reporte.SetDataSource(Ds_Datos);
                        Frm_Rpt_Mostrar_Reporte_ Frm_Mostrar_Reporte = new Frm_Rpt_Mostrar_Reporte_();
                        Frm_Mostrar_Reporte.P_Reporte = Reporte;
                        Frm_Mostrar_Reporte.ShowDialog(this);
                    }
                }
            }
            catch (Exception Ex)
            {
                throw new Exception("Error al generar el reporte. Error: [" + Ex.Message + "]");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Ds_Datos"></param>
        /// <param name="Nombre_Plantilla_Reporte"></param>
        protected void Generar_Reporte(ref DataTable Ds_Datos, String Nombre_Plantilla_Reporte)
        {
            ReportDocument Reporte = new ReportDocument(); //Variable de tipo reporte.

            String Ruta = String.Empty;                    //Variable que almacenara la ruta del archivo del crystal report.

            try
            {
                Reporte.Load(Nombre_Plantilla_Reporte);

                if (Ds_Datos.Rows.Count > 0)
                {
                    Reporte.SetDataSource(Ds_Datos);

                    ParameterFieldDefinitions Parametros = Reporte.DataDefinition.ParameterFields;
                    ParameterFieldDefinition  Parametro;
                    ParameterDiscreteValue    Valor   = new ParameterDiscreteValue();
                    ParameterValues           Valores = new ParameterValues();

                    List <object[]> objParametros = new List <object[]>();

                    objParametros.Add(new object[] { Dtp_Fecha_Inicio.Value, "Periodo_Inicial" });
                    objParametros.Add(new object[] { Dtp_Fecha_Termino.Value, "Periodo_Final" });
                    objParametros.Add(new object[] { string.Empty, "Estatus" });
                    objParametros.Add(new object[] { DateTime.Now, "Fecha_Creo" });
                    objParametros.Add(new object[] { MDI_Frm_Apl_Principal.Nombre_Usuario, "Usuario_Creo" });

                    if (Cmb_Turnos.SelectedIndex > 0)
                    {
                        objParametros.Add(new object[] { Cmb_Turnos.Text, "Turno" });
                    }
                    else
                    {
                        objParametros.Add(new object[] { string.Empty, "Turno" });
                    }

                    if (Cmb_Cajas.SelectedIndex > 0)
                    {
                        objParametros.Add(new object[] { Cmb_Cajas.Text, "No_Caja" });
                    }
                    else
                    {
                        objParametros.Add(new object[] { string.Empty, "No_Caja" });
                    }

                    if (Cmb_Lugar_Venta.SelectedIndex > 0)
                    {
                        objParametros.Add(new object[] { Cmb_Lugar_Venta.Text, "Lugar_Venta" });
                    }
                    else
                    {
                        objParametros.Add(new object[] { string.Empty, "Lugar_Venta" });
                    }

                    if (Cmb_Museo.SelectedIndex > 0)
                    {
                        objParametros.Add(new object[] { Cmb_Museo.Text, "Museo" });
                    }
                    else
                    {
                        objParametros.Add(new object[] { string.Empty, "Museo" });
                    }

                    if (!string.IsNullOrEmpty(Txt_Folio_Venta.Text))
                    {
                        objParametros.Add(new object[] { Txt_Folio_Venta.Text, "Folio" });
                    }
                    else
                    {
                        objParametros.Add(new object[] { string.Empty, "Folio" });
                    }

                    if (Cmb_Producto.SelectedIndex > 0)
                    {
                        objParametros.Add(new object[] { Cmb_Producto.Text, "Tarifa" });
                    }
                    else
                    {
                        objParametros.Add(new object[] { string.Empty, "Tarifa" });
                    }

                    foreach (object[] objParametro in objParametros)
                    {
                        Parametro = Parametros[objParametro[1].ToString()];
                        Valores   = Parametro.CurrentValues;
                        Valores.Clear();

                        Valor.Value = objParametro[0];
                        Valores.Add(Valor);
                        Parametro.ApplyCurrentValues(Valores);
                    }

                    Frm_Rpt_Mostrar_Reporte_ Frm_Mostrar_Reporte = new Frm_Rpt_Mostrar_Reporte_();

                    Frm_Mostrar_Reporte.P_Reporte = Reporte;
                    Frm_Mostrar_Reporte.ShowDialog(this);
                }
            }
            catch (Exception Ex)
            {
                throw new Exception("Error al generar el reporte. Error: [" + Ex.Message + "]");
            }
        }