Exemplo n.º 1
0
        private void SetDataSourceLocation(ReportConnectionInfo info, ReportDocument crystalReportDocument)
        {
            foreach (IConnectionInfo connectInfo in crystalReportDocument.DataSourceConnections)
            {
                connectInfo.SetConnection(info.Server, info.Database, info.Username, info.Password);
            }

            //Create a new Database Table to replace the reports current table.
            var boTable = new CrystalDecisions.ReportAppServer.DataDefModel.Table();

            //boMainPropertyBag: These hold the attributes of the tables ConnectionInfo object
            PropertyBag boMainPropertyBag = new PropertyBag();
            //boInnerPropertyBag: These hold the attributes for the QE_LogonProperties
            //In the main property bag (boMainPropertyBag)
            PropertyBag boInnerPropertyBag = new PropertyBag();

            //Set the attributes for the boInnerPropertyBag
            boInnerPropertyBag.Add("Database", info.Database);
            boInnerPropertyBag.Add("DSN", info.Server);
            boInnerPropertyBag.Add("SSOKey", "");
            boInnerPropertyBag.Add("Trusted_Connection", (info.IntegratedSecurity ? "True" : "False"));
            boInnerPropertyBag.Add("UseDSNProperties", "False");

            //Set the attributes for the boMainPropertyBag
            boMainPropertyBag.Add("Database DLL", "crdb_odbc.dll");
            boMainPropertyBag.Add("QE_DatabaseName", info.Database);
            boMainPropertyBag.Add("QE_DatabaseType", "ODBC (RDO)");
            //Add the QE_LogonProperties we set in the boInnerPropertyBag Object
            boMainPropertyBag.Add("QE_LogonProperties", boInnerPropertyBag);
            boMainPropertyBag.Add("QE_ServerDescription", info.Server);
            boMainPropertyBag.Add("QE_SQLDB", "True");
            boMainPropertyBag.Add("SSO Enabled", (info.IntegratedSecurity ? "True" : "False"));

            //Create a new ConnectionInfo object
            var boConnectionInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();

            //Pass the database properties to a connection info object
            boConnectionInfo.Attributes = boMainPropertyBag;
            //Set the connection kind
            boConnectionInfo.Kind     = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
            boConnectionInfo.UserName = info.Username;
            boConnectionInfo.Password = info.Password;
            boTable.ConnectionInfo    = boConnectionInfo;

            CrystalDecisions.ReportAppServer.DataDefModel.Tables boTables = ReportClientDocument.DatabaseController.Database.Tables;

            foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table in boTables)
            {
                boTable.Name          = table.Name;
                boTable.QualifiedName = table.QualifiedName;
                boTable.Alias         = table.Alias;
                ReportClientDocument.DatabaseController.SetTableLocation(table, boTable);
            }

            //Verify the database after adding substituting the new table.
            //To ensure that the table updates properly when adding Command tables or Stored Procedures.
            //VerifyDatabase();
        }
Exemplo n.º 2
0
        private void GetTable(CrystalDecisions.ReportAppServer.DataDefModel.Table table, XmlWriter writer)
        {
            writer.WriteStartElement("Table");

            writer.WriteAttributeString("Alias", table.Alias);
            writer.WriteAttributeString("ClassName", table.ClassName);
            writer.WriteAttributeString("Name", table.Name);

            writer.WriteStartElement("ConnectionInfo");
            foreach (string propertyId in table.ConnectionInfo.Attributes.PropertyIDs)
            {
                // make attribute name safe for XML
                string attributeName = propertyId.Replace(" ", "_");

                writer.WriteAttributeString(attributeName, table.ConnectionInfo.Attributes[propertyId].ToString());
            }

            writer.WriteAttributeString("UserName", table.ConnectionInfo.UserName);
            writer.WriteAttributeString("Password", table.ConnectionInfo.Password);
            writer.WriteEndElement();

            var commandTable = table as CRDataDefModel.CommandTable;

            if (commandTable != null)
            {
                var cmdTable = commandTable;
                writer.WriteStartElement("Command");
                writer.WriteString(cmdTable.CommandText);
                writer.WriteEndElement();
            }

            writer.WriteStartElement("Fields");

            foreach (CrystalDecisions.ReportAppServer.DataDefModel.Field fd in table.DataFields)
            {
                GetFieldDefinition(fd, writer);
            }

            writer.WriteEndElement();

            writer.WriteEndElement();
        }