Beispiel #1
0
        private void btnReport_Click(object sender, EventArgs e)
        {
            CR_MHTuDen rp = new CR_MHTuDen();

            CrystalDecisions.Shared.ParameterValues        myValue    = new CrystalDecisions.Shared.ParameterValues();
            CrystalDecisions.Shared.ParameterDiscreteValue PDVTuNgay  = new CrystalDecisions.Shared.ParameterDiscreteValue();
            CrystalDecisions.Shared.ParameterDiscreteValue PDVDenNgay = new CrystalDecisions.Shared.ParameterDiscreteValue();


            CrystalDecisions.Shared.ConnectionInfo con = new CrystalDecisions.Shared.ConnectionInfo();
            con.ServerName   = frmDangnhap.SV;
            con.DatabaseName = frmDangnhap.DB;
            con.UserID       = frmDangnhap.ID;
            con.Password     = frmDangnhap.PASS;

            TableLogOnInfo table = new TableLogOnInfo();

            table.ConnectionInfo = con;
            rp.Database.Tables[0].ApplyLogOnInfo(table);

            PDVTuNgay.Value = this.txtDayStart.Value;
            myValue.Add(PDVTuNgay);
            rp.DataDefinition.ParameterFields["@TUNGAY"].ApplyCurrentValues(myValue);
            myValue.Clear();

            PDVDenNgay.Value = this.txtDayEnd.Value;
            myValue.Add(PDVDenNgay);
            rp.DataDefinition.ParameterFields["@DENNGAY"].ApplyCurrentValues(myValue);
            myValue.Clear();


            this.crystalReportViewer1.ReportSource = rp;
        }
Beispiel #2
0
    ///
    ///This function is called by the "Logon" function. It loops through the report tables and applies the connection information to each table.
    ///

    private bool ApplyLogon(CrystalDecisions.CrystalReports.Engine.ReportDocument cr,
                            CrystalDecisions.Shared.ConnectionInfo ci)
    {
// This function is called by the "Logon" function
// It loops through the report tables and applies
// the connection information to each table.

// Declare the TableLogOnInfo object and a table object for use later.
        CrystalDecisions.Shared.TableLogOnInfo li;
// For each table apply connection info.

        foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in cr.Database.Tables)
        {
            li = tbl.LogOnInfo;
            li.ConnectionInfo.ServerName   = ci.ServerName;
            li.ConnectionInfo.DatabaseName = ci.DatabaseName;
            li.ConnectionInfo.UserID       = ci.UserID;
            li.ConnectionInfo.Password     = ci.Password;
            tbl.ApplyLogOnInfo(li);
            tbl.Location = ci.DatabaseName + ".dbo." + tbl.Name;

// Verify that the logon was successful.
// If TestConnectivity returns false, correct table locations.
            if (!tbl.TestConnectivity())
            {
                return(false);
            }
        }
        return(true);
    }
Beispiel #3
0
        public frmRelBasicos(string pArquivo, string pTitulo)
        {
            InitializeComponent();

            relArquivo = pArquivo;
            relTitulo  = pTitulo;

            this.Text = pTitulo;

            //Objeto com informações de conexão para as tabelas do rpt
            conexaoCrystal              = new CrystalDecisions.Shared.ConnectionInfo();
            conexaoCrystal.ServerName   = @"(local)\SQLEXPRESS";
            conexaoCrystal.UserID       = "sa";
            conexaoCrystal.Password     = "******";
            conexaoCrystal.DatabaseName = "Copa2010";

            //Carregar o arquivo do rpt pArquivo
            CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            report.Load(Application.StartupPath + @"..\..\..\Relatorios\" + relArquivo);

            //Informe o rpt com as informações de conexão
            CrystalDecisions.Shared.TableLogOnInfo logonInfo = new CrystalDecisions.Shared.TableLogOnInfo();
            logonInfo.ConnectionInfo = conexaoCrystal;

            foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
            {
                table.LogOnInfo.ConnectionInfo = conexaoCrystal;
                table.ApplyLogOnInfo(logonInfo);
            }

            //Liga ao Visualizador
            crvRel.ReportSource = report;
        }
Beispiel #4
0
        //public rpt()
        //{

        //}
        public void ConnectionInfo(ReportDocument _rpt)
        {
            //string[] strConnection = ConfigurationManager.ConnectionStrings[("csApp")].ConnectionString.Split(new char[] { ';' });
            _DBcon d = new _DBcon();

            string[] strConnection = d.getConnectionString().Split(new char[] { ';' });

            Database oCRDb     = _rpt.Database;
            Tables   oCRTables = oCRDb.Tables;

            CrystalDecisions.CrystalReports.Engine.Table oCRTable = default(CrystalDecisions.CrystalReports.Engine.Table);
            TableLogOnInfo oCRTableLogonInfo = default(CrystalDecisions.Shared.TableLogOnInfo);
            ConnectionInfo oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

            oCRConnectionInfo.ServerName   = strConnection[0].Split(new char[] { '=' }).GetValue(1).ToString();
            oCRConnectionInfo.DatabaseName = strConnection[1].Split(new char[] { '=' }).GetValue(1).ToString();
            oCRConnectionInfo.Password     = strConnection[4].Split(new char[] { '=' }).GetValue(1).ToString();
            oCRConnectionInfo.UserID       = strConnection[3].Split(new char[] { '=' }).GetValue(1).ToString();

            for (int i = 0; i < oCRTables.Count; i++)
            {
                oCRTable          = oCRTables[i];
                oCRTableLogonInfo = oCRTable.LogOnInfo;
                oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
                oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);
                if (oCRTable.TestConnectivity())
                {
                    //' If there is a "." in the location then remove the
                    // ' beginning of the fully qualified location.
                    //' Example "dbo.northwind.customers" would become
                    //' "customers".
                    oCRTable.Location = oCRTable.Location.Substring(oCRTable.Location.LastIndexOf(".") + 1);
                }
            }

            for (int i = 0; i < _rpt.Subreports.Count; i++)
            {
                {
                    oCRDb     = _rpt.OpenSubreport(_rpt.Subreports[i].Name).Database;
                    oCRTables = oCRDb.Tables;
                    foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in oCRTables)
                    {
                        oCRTableLogonInfo = aTable.LogOnInfo;
                        oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
                        aTable.ApplyLogOnInfo(oCRTableLogonInfo);
                        if (aTable.TestConnectivity())
                        {
                            //' If there is a "." in the location then remove the
                            // ' beginning of the fully qualified location.
                            //' Example "dbo.northwind.customers" would become
                            //' "customers".
                            aTable.Location = aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1);
                        }
                    }
                }
            }
            _rpt.Refresh();
        }
        private void SetLogon()
        {
            ConnectionInfo info = GetConnectionInfo("Padrao");

            for (int i = 0; i < reportDoc.DataSourceConnections.Count; i++)
            {
                reportDoc.DataSourceConnections[i].SetConnection(info.ServerName,
                                                                 info.DatabaseName,
                                                                 info.UserID,
                                                                 info.Password);
            }
        }
        private ConnectionInfo GetConnectionInfo(string connectionName)
        {
            var connStrBuilder =
                new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionName].ToString());

            var info = new ConnectionInfo
            {
                UserID       = connStrBuilder.UserID,
                Password     = connStrBuilder.Password,
                ServerName   = connStrBuilder.DataSource,
                DatabaseName = connStrBuilder.InitialCatalog
            };

            return(info);
        }
Beispiel #7
0
        private void btnVisualizar_Click(object sender, EventArgs e)
        {
            //Objeto com informações de conexão para as tabelas do rpt
            conexaoCrystal              = new CrystalDecisions.Shared.ConnectionInfo();
            conexaoCrystal.ServerName   = @"(local)\SQLEXPRESS";
            conexaoCrystal.UserID       = "sa";
            conexaoCrystal.Password     = "******";
            conexaoCrystal.DatabaseName = "Copa2010";

            //Carregar o arquivo do rpt pArquivo
            CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            report.Load(Application.StartupPath + @"..\..\..\Relatorios\relJogadores.rpt");

            //Alimenta os parametros
            ParameterField pEquipe;

            pEquipe = report.ParameterFields["pEquipe"];

            try
            {
                if (cbEquipe.SelectedValue.ToString().Trim() != "0")
                {
                    pEquipe.CurrentValues.AddValue(cbEquipe.GetItemText(cbEquipe.SelectedItem));
                }
                else
                {
                    pEquipe.CurrentValues.AddValue("");
                }
            }
            catch (Exception ex)
            {
                Console.Write("Erro: " + ex.Message.ToString());
            }

            //Informe o rpt com as informações de conexão
            CrystalDecisions.Shared.TableLogOnInfo logonInfo = new CrystalDecisions.Shared.TableLogOnInfo();
            logonInfo.ConnectionInfo = conexaoCrystal;

            foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
            {
                table.LogOnInfo.ConnectionInfo = conexaoCrystal;
                table.ApplyLogOnInfo(logonInfo);
            }

            //Liga ao Visualizador
            this.crvRelJogadores.ReportSource = report;
        }
Beispiel #8
0
        /// <summary>
        /// We can dynamic change the report provider by this function
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseName"></param>
        /// <param name="userID"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private static TableLogOnInfo GetSQLTableLogOnInfo(string serverName, string databaseName, string userID, string password)
        {
            CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag connectionAttributes = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
            connectionAttributes.EnsureCapacity(11);
            connectionAttributes.Add("Connect Timeout", "15");
            connectionAttributes.Add("Data Source", serverName);
            connectionAttributes.Add("General Timeout", "0");
            connectionAttributes.Add("Initial Catalog", databaseName);
            connectionAttributes.Add("Integrated Security", false);
            connectionAttributes.Add("Locale Identifier", "1033");
            connectionAttributes.Add("OLE DB Services", "-5");
            //connectionAttributes.Add("Provider", "SQLNCLI11");
            connectionAttributes.Add("Provider", "SQLOLEDB");
            connectionAttributes.Add("Tag with column collation when possible", "0");
            connectionAttributes.Add("Use DSN Default Properties", false);
            connectionAttributes.Add("Use Encryption for Data", "0");

            connectionAttributes.Add("Trust Server Certificate", 0);
            connectionAttributes.Add("DataTypeCompatibility", 0);
            connectionAttributes.Add("Auto Translate", -1);
            connectionAttributes.Add("Application Intent", "READWRITE");

            DbConnectionAttributes attributes = new DbConnectionAttributes();

            attributes.Collection.Add(new NameValuePair2("Database DLL", "crdb_ado.dll"));
            attributes.Collection.Add(new NameValuePair2("QE_DatabaseName", databaseName));
            attributes.Collection.Add(new NameValuePair2("QE_DatabaseType", "OLE DB (ADO)"));
            attributes.Collection.Add(new NameValuePair2("QE_LogonProperties", connectionAttributes));
            attributes.Collection.Add(new NameValuePair2("QE_ServerDescription", serverName));
            attributes.Collection.Add(new NameValuePair2("SSO Enabled", false));
            attributes.Collection.Add(new NameValuePair2("QE_SQLDB", true));
            attributes.Collection.Add(new NameValuePair2("Owner", "dbo"));


            CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
            connectionInfo.Attributes   = attributes;
            connectionInfo.ServerName   = serverName;
            connectionInfo.UserID       = userID;
            connectionInfo.Password     = password;
            connectionInfo.DatabaseName = databaseName;
            connectionInfo.Type         = ConnectionInfoType.SQL;

            TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();

            tableLogOnInfo.ConnectionInfo = connectionInfo;
            return(tableLogOnInfo);
        }
Beispiel #9
0
//Check whether crytal report can login to the server
    private bool Logon(CrystalDecisions.CrystalReports.Engine.ReportDocument cr, string server, string database,
                       string user_id, string password)
    {
// Declare and instantiate a new connection info object.
        CrystalDecisions.Shared.ConnectionInfo ci;
        ci = new CrystalDecisions.Shared.ConnectionInfo();

        ci.ServerName   = server;
        ci.DatabaseName = database;
        ci.UserID       = user_id;
        ci.Password     = password; //password;
// ci.IntegratedSecurity = false;

// If the ApplyLogon function fails then return a false for this function.
// We are applying logon information to the main report at this stage.
        if (!ApplyLogon(cr, ci))
        {
            return(false);
        }

// Declare a subreport object.
        CrystalDecisions.CrystalReports.Engine.SubreportObject subobj;

// Loop through all the report objects and locate subreports.
// If a subreport is found then apply logon information to
// the subreport.
        foreach (CrystalDecisions.CrystalReports.Engine.ReportObject obj in cr.ReportDefinition.ReportObjects)
        {
            if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
            {
                subobj = (CrystalDecisions.CrystalReports.Engine.SubreportObject)obj;
                if (!ApplyLogon(cr.OpenSubreport(subobj.SubreportName), ci))
                {
                    return(false);
                }
            }
        }

// Return True if the code runs to this stage.
        return(true);
    }
 public void SetDatabase(ReportDocument Rpt)
 {
     CrystalDecisions.CrystalReports.Engine.Database crDatabase;
     CrystalDecisions.CrystalReports.Engine.Tables crTables;
     CrystalDecisions.Shared.TableLogOnInfos MyTableLogOnInfos = new CrystalDecisions.Shared.TableLogOnInfos();
     CrystalDecisions.Shared.TableLogOnInfo MyTableLogOnInfo = new CrystalDecisions.Shared.TableLogOnInfo();
     CrystalDecisions.Shared.ConnectionInfo MyConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
     //conStr = Session["Connectionstring"].ToString();
     MyTableLogOnInfo.ConnectionInfo = SetConnectionString(MyConnectionInfo, ConnectionString);
     MyTableLogOnInfos.Add(MyTableLogOnInfo);
     AdminActivityCRViewer.LogOnInfo = MyTableLogOnInfos;
     crDatabase = Rpt.Database;
     crTables = crDatabase.Tables;
     foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
     {
         MyTableLogOnInfo = crTable.LogOnInfo;
         MyTableLogOnInfo.ConnectionInfo = MyConnectionInfo;
         crTable.ApplyLogOnInfo(MyTableLogOnInfo);
     }
     setParameters(Rpt);
 }
Beispiel #11
0
    private bool Logon(CrystalDecisions.CrystalReports.Engine.ReportDocument cr, string server, string database, string user_id, string password)
    {
        // Declare and instantiate a new connection info object.
        CrystalDecisions.Shared.ConnectionInfo ci;
        ci = new CrystalDecisions.Shared.ConnectionInfo();

        ci.ServerName = server;
        ci.DatabaseName = database;
        ci.UserID = user_id;
        ci.Password = password;//password;
        //  ci.IntegratedSecurity = false;

        // If the ApplyLogon function fails then return a false for this function.
        // We are applying logon information to the main report at this stage.
        if (!ApplyLogon(cr, ci))
        {
            return false;
        }

        // Declare a subreport object.
        CrystalDecisions.CrystalReports.Engine.SubreportObject subobj;

        // Loop through all the report objects and locate subreports.
        // If a subreport is found then apply logon information to
        // the subreport.
        foreach (CrystalDecisions.CrystalReports.Engine.ReportObject obj in cr.ReportDefinition.ReportObjects)
        {
            if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
            {
                subobj = (CrystalDecisions.CrystalReports.Engine.SubreportObject)obj;
                if (!ApplyLogon(cr.OpenSubreport(subobj.SubreportName), ci))
                {
                    return false;
                }
            }
        }

        // Return True if the code runs to this stage.
        return true;

    }
Beispiel #12
0
        public ActionResult PrintPO(string id)
        {
            try
            {
                string[] parameters = id.Split('|');

                string oConnStr = ConfigurationManager.ConnectionStrings["MHConnStr"].ToString();
                string rutaRpt  = "";
                byte[] response = null;

                string ImgPath = "";

                switch (parameters[1])
                {
                case "Pes":
                    ImgPath = ConfigurationManager.AppSettings["ProductImgPath"].ToString();
                    rutaRpt = Server.MapPath(ConfigurationManager.AppSettings["ProductRptNameES"].ToString());
                    break;

                case "Pen":
                    ImgPath = ConfigurationManager.AppSettings["ProductImgPath"].ToString();
                    rutaRpt = Server.MapPath(ConfigurationManager.AppSettings["ProductRptNameEN"].ToString());
                    break;

                case "Mes":
                    ImgPath = ConfigurationManager.AppSettings["MaterialImgPath"].ToString();
                    rutaRpt = Server.MapPath(ConfigurationManager.AppSettings["MaterialRptNameES"].ToString());
                    break;

                case "Men":
                    ImgPath = ConfigurationManager.AppSettings["MaterialImgPath"].ToString();
                    rutaRpt = Server.MapPath(ConfigurationManager.AppSettings["MaterialRptNameEN"].ToString());
                    break;

                default:
                    break;
                }

                //if (parameters[1] == "P")
                //{
                //    ImgPath = ConfigurationManager.AppSettings["ProductImgPath"].ToString();
                //    rutaRpt = Server.MapPath(ConfigurationManager.AppSettings["ProductRptName"].ToString());
                //}
                //else
                //{
                //    ImgPath = ConfigurationManager.AppSettings["MaterialImgPath"].ToString();
                //    rutaRpt = Server.MapPath(ConfigurationManager.AppSettings["MaterialRptName"].ToString());
                //}

                ReportDocument             rpt          = new ReportDocument();
                SqlConnectionStringBuilder oConnBuilder = new SqlConnectionStringBuilder(oConnStr);

                rpt.Load(rutaRpt);

                ParameterDiscreteValue pedidoDiscreteValue = new ParameterDiscreteValue();
                pedidoDiscreteValue.Value = parameters[0];
                rpt.SetParameterValue("pedido", pedidoDiscreteValue);

                ParameterDiscreteValue rutaImgDiscreteValue = new ParameterDiscreteValue();
                rutaImgDiscreteValue.Value = ImgPath;
                rpt.SetParameterValue("rutaImg", rutaImgDiscreteValue);

                CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
                connectionInfo.DatabaseName = oConnBuilder.InitialCatalog;
                connectionInfo.UserID       = oConnBuilder.UserID;
                connectionInfo.Password     = oConnBuilder.Password;
                connectionInfo.ServerName   = oConnBuilder.DataSource;

                Tables tables = rpt.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
                {
                    CrystalDecisions.Shared.TableLogOnInfo tableLogonInfo = table.LogOnInfo;
                    tableLogonInfo.ConnectionInfo = connectionInfo;
                    table.ApplyLogOnInfo(tableLogonInfo);
                }

                for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
                {
                    rpt.DataSourceConnections[i].SetConnection(oConnBuilder.DataSource, oConnBuilder.InitialCatalog, oConnBuilder.UserID, oConnBuilder.Password);
                }

                rpt.SetDatabaseLogon(oConnBuilder.UserID, oConnBuilder.Password, oConnBuilder.DataSource, oConnBuilder.InitialCatalog);


                using (Stream strMemory = rpt.ExportToStream(ExportFormatType.PortableDocFormat))
                {
                    response = new byte[strMemory.Length];

                    strMemory.Read(response, 0, (int)strMemory.Length);
                }

                return(new FileContentResult(response, "application/pdf"));
            }
            catch (Exception ex)
            {
                string error = ex.Message + " :::---::: " + ex.StackTrace;

                System.Text.ASCIIEncoding codificador = new System.Text.ASCIIEncoding();
                byte[] response = codificador.GetBytes(error);

                return(new FileContentResult(response, "text/plain"));
            }
        }
        void previewID()
        {
            try
            {
                CrystalDecisions.CrystalReports.Engine.ReportDocument objReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                CrystalDecisions.Shared.TableLogOnInfos crtableLogoninfos = new CrystalDecisions.Shared.TableLogOnInfos();

                CrystalDecisions.Shared.TableLogOnInfo ConInfo = new CrystalDecisions.Shared.TableLogOnInfo();

                CrystalDecisions.Shared.ConnectionInfo crConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

                CrystalDecisions.CrystalReports.Engine.Tables CrTables;

                CrystalDecisions.Shared.ParameterValues crParameterValues = new CrystalDecisions.Shared.ParameterValues();

                CrystalDecisions.Shared.ParameterDiscreteValue crParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();

                //objReport.Load(LoadReport());

                objReport.Load(_path + _reportName_Outside);

                string sUserID = "sa";

                string sPassword = "******";

                string sServerName = "192.168.1.42";

                string sDatabaseName = "HRIS";


                crConnectionInfo.ServerName = sServerName;

                crConnectionInfo.DatabaseName = sDatabaseName;

                crConnectionInfo.UserID = sUserID;

                crConnectionInfo.Password = sPassword;


                CrTables = objReport.Database.Tables;

                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    ConInfo = CrTable.LogOnInfo;

                    ConInfo.ConnectionInfo = crConnectionInfo;

                    CrTable.ApplyLogOnInfo(ConInfo);
                }

                reportViewer.ViewerCore.ReportSource = objReport;

                //rekta print
                //objReport.PrintToPrinter(1, true, 0, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #14
0
        /// <summary>
        /// Genera el reporte
        /// </summary>
        /// <param name="reportPath">Ruta del reporte</param>
        /// <param name="outputPath">Regresa el reporte</param>
        /// <param name="fechaInicial">Valor fecha inicial</param>
        /// <param name="fechaFinal">Valor fecha final</param>
        /// <param name="oficinaVentas">Código de la oficina</param>
        /// <param name="Usuario">Código del usuario</param>
        /// <param name="_Company">Objeto de SAP</param>
        /// <param name="msgError">Mensaje de error</param>
        /// <returns>true/false</returns>
        public bool RunReport(string reportPath, string outputPath, DateTime fechaInicial, DateTime fechaFinal, string oficinaVentas, SAPbobsCOM.Company _Company, ref string msgError)
        {
            msgError = string.Empty;
            if (System.IO.File.Exists(outputPath))
            {
                try
                {
                    System.IO.File.Delete(outputPath);
                }
                catch (Exception ex)
                {
                    throw new Exception("No se pudo reemplazar el archivo " + System.IO.Path.GetFileName(outputPath) + ", revise que no se esté ejecutando.");
                }
            }
            try
            {
                rpt = new ReportDocument();

                loginfo              = new CrystalDecisions.Shared.ConnectionInfo();
                loginfo.ServerName   = _Company.Server;
                loginfo.DatabaseName = _Company.CompanyDB;
                loginfo.UserID       = _Company.DbUserName;
                loginfo.Password     = Extensor.Configuracion.PBD.PBD; //ConfigurationManager.AppSettings["PBD"].ToString();

                rpt.Load(reportPath);
                Actualiza(ref rpt, loginfo);

                rpt.SetParameterValue("@FechaInicial", fechaInicial);
                rpt.SetParameterValue("@FechaFinal", fechaFinal);
                rpt.SetParameterValue("@AlmacenOficina", oficinaVentas);
                //rpt.SetParameterValue("@Usuario", Usuario);


                CrystalDecisions.Shared.DiskFileDestinationOptions filedest = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                CrystalDecisions.Shared.ExportOptions o = default(CrystalDecisions.Shared.ExportOptions);
                o = new CrystalDecisions.Shared.ExportOptions();

                ExportOptions opt = new ExportOptions();

                opt = rpt.ExportOptions;

                o.ExportFormatType      = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                o.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                filedest.DiskFileName   = outputPath;


                o.ExportDestinationOptions = (ExportDestinationOptions)filedest.Clone();

                rpt.Export(o);
                o = null;

                filedest = null;
                rpt.Dispose();
                rpt.Close();


                opt = null;
                rpt = null;

                return(true);
            }
            catch (Exception ex)
            {
                msgError = "No se creó el archivo: " + ex.Message + Environment.NewLine +
                           "Detalles: " + ex.InnerException.Message;
                return(false);
            }
        }
Beispiel #15
0
    private bool ApplyLogon(CrystalDecisions.CrystalReports.Engine.ReportDocument cr, CrystalDecisions.Shared.ConnectionInfo ci)
    {
        // This function is called by the "Logon" function
        // It loops through the report tables and applies
        // the connection information to each table.

        // Declare the TableLogOnInfo object and a table object for use later.
        CrystalDecisions.Shared.TableLogOnInfo li;
        // For each table apply connection info.

        foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in cr.Database.Tables)
        {
            li = tbl.LogOnInfo;
            li.ConnectionInfo.ServerName   = ci.ServerName;
            li.ConnectionInfo.DatabaseName = ci.DatabaseName;
            li.ConnectionInfo.UserID       = ci.UserID;
            li.ConnectionInfo.Password     = ci.Password;
            tbl.ApplyLogOnInfo(li);
            tbl.Location = ci.DatabaseName + ".dbo." + tbl.Name;

            // Verify that the logon was successful.
            // If TestConnectivity returns false, correct table locations.
            if (!tbl.TestConnectivity())
            {
                return(false);
                // If there is a "." in the location then remove the
                // beginning of the fully qualified location.
                // Example "dbo.northwind.customers" would become
                // "customers".

                /*	if (tbl.Location.IndexOf(".") > 0)
                 *  {
                 *      tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1);
                 *  }
                 *  else
                 *  {
                 *      // If the location is not returning as a fully
                 *      // qualified location we still set it to tbl.location
                 *      // because Crystal Reports 9 installed on top of .NET
                 *      // can *store* fully qualified names but will only *return*
                 *      // the table name itself.
                 *      tbl.Location = tbl.Location;
                 *
                 *  }*/
            }
        }
        return(true);
    }