Ejemplo n.º 1
0
        /// <summary>
        /// Makes this object render itself as an RDL Report type to an XmlWriter instance.
        /// It calls upon all objects immediately beneath it (TableHeader, TableGroup,
        /// TableDetails, Datasets, ReportParameters) to render themselves also.
        /// </summary>
        /// <returns>A Byte array containing the raw RDL data.</returns>
        public Byte[] Render2010()
        {
            // Styles for the textboxes
            ReportingServicesStyle _textboxStyle14pt = new ReportingServicesStyle(
                ReportingServicesStyle.TextBoxStyle.TabularReport14pt);
            ReportingServicesStyle _textboxStyle10pt = new ReportingServicesStyle(
                ReportingServicesStyle.TextBoxStyle.TabularReport10pt);

            _xmlWriter.WriteStartDocument();

            _xmlWriter.WriteStartElement("Report");
            _xmlWriter.WriteAttributeString("xmlns",
                                            "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition");
            _xmlWriter.WriteAttributeString("xmlns:cl",
                                            "http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition");

            RdlRender.AddLine(_xmlWriter, "AutoRefresh", "0");
            // DataSources
            _xmlWriter.WriteStartElement("DataSources");
            _xmlWriter.WriteStartElement("DataSource");
            _xmlWriter.WriteAttributeString("Name", "DataSource1");
            RdlRender.AddLine(_xmlWriter, "DataSourceReference", "/" + _dataSource);

            /*_xmlWriter.WriteStartElement("ConnectionProperties");
             * RdlRender.AddLine( _xmlWriter, "DataProvider", "SQL");
             * RdlRender.AddLine( _xmlWriter, "ConnectString", _dbConnectionString);
             * RdlRender.AddLine( _xmlWriter, "IntegratedSecurity", "false");
             * RdlRender.AddLine( _xmlWriter, "Prompt", "false");
             * _xmlWriter.WriteEndElement(); // ConnectionProperties */
            _xmlWriter.WriteEndElement(); // DataSource
            _xmlWriter.WriteEndElement(); // DataSources

            // Datasets
            _xmlWriter.WriteStartElement("DataSets");
            foreach (Dataset CurrentDataSet in _datasetList)
            {
                CurrentDataSet.Render2010(_xmlWriter);
            }
            _xmlWriter.WriteEndElement(); //DataSets

            //ReportSections
            _xmlWriter.WriteStartElement("ReportSections");
            //ReportSection
            _xmlWriter.WriteStartElement("ReportSection");



            _xmlWriter.WriteStartElement("Body");
            RdlRender.AddLine(_xmlWriter, "Height", "5in");

            _xmlWriter.WriteStartElement("ReportItems");
            _xmlWriter.WriteStartElement("Tablix");
            _xmlWriter.WriteAttributeString("Name", "Table1");
            RdlRender.AddLine(_xmlWriter, "DataSetName", "TableDataSet");
            RdlRender.AddLine(_xmlWriter, "NoRowsMessage", Resource.GetString("RES_REPORT_NOROWSRETURNED"));
            RdlRender.AddLine(_xmlWriter, "Top", "0in");
            RdlRender.AddLine(_xmlWriter, "Left", ".5in");
            RdlRender.AddLine(_xmlWriter, "Height", "0in");
            RdlRender.AddLine(_xmlWriter, "Width", "6in");

            _xmlWriter.WriteStartElement("TablixBody");

            // Write table columns
            _xmlWriter.WriteStartElement("TablixColumns");
            for (int i = 0; i < _fieldDataItems.Count; i++)
            {
                _xmlWriter.WriteStartElement("TablixColumn");
                RdlRender.AddLine(_xmlWriter, "Width", "1.5in");
                _xmlWriter.WriteEndElement(); // TablixColumn
            }
            _xmlWriter.WriteEndElement();     // TablixColumns

            // Write table rows
            _xmlWriter.WriteStartElement("TablixRows");

            // TableHeader
            _tableHeader.Render2010(_xmlWriter);

            // TableGroups
            if (_tableGroupList != null && _tableGroupList.Count > 0)
            {
                foreach (TableGroup group in _tableGroupList)
                {
                    group.Render2010(_xmlWriter);
                }
            }

            // TableDetails
            if (_isSummaryReport == false)
            {
                _tableDetails.Render2010(_xmlWriter);
            }



            // TableFooter
            _tableFooter.Render2010(_xmlWriter);

            _xmlWriter.WriteEndElement(); // TablixRows

            _xmlWriter.WriteEndElement(); // TablixBody
            _xmlWriter.WriteStartElement("TablixColumnHierarchy");
            _xmlWriter.WriteStartElement("TablixMembers");
            for (int i = 0; i < _fieldDataItems.Count; i++)
            {
                _xmlWriter.WriteStartElement("TablixMember");
                _xmlWriter.WriteEndElement(); // TablixMember
            }
            _xmlWriter.WriteEndElement();     // TablixMembers

            _xmlWriter.WriteEndElement();     // TablixColumnHierarchy


            _xmlWriter.WriteStartElement("TablixRowHierarchy");
            _xmlWriter.WriteStartElement("TablixMembers");

            //Add Header row member
            _xmlWriter.WriteStartElement("TablixMember");
            RdlRender.AddLine(_xmlWriter, "KeepWithGroup", "After");
            RdlRender.AddLine(_xmlWriter, "FixedData", "true");
            RdlRender.AddLine(_xmlWriter, "RepeatOnNewPage", "true");
            RdlRender.AddLine(_xmlWriter, "KeepTogether", "true");
            _xmlWriter.WriteEndElement(); // TablixMember

            //Add Group and details hierarchy members
            if (_tableGroupList != null && _tableGroupList.Count > 0)
            {
                for (int i = 0; i < _tableGroupList.Count; i++)//
                {
                    _xmlWriter.WriteStartElement("TablixMember");
                    _xmlWriter.WriteStartElement("Group");
                    _xmlWriter.WriteAttributeString("Name", "Grouping" + _tableGroupList[i].Name);
                    if (_tableGroupList[i].IsDataMapDisplayedGroup) // check if data map neds displaying
                    {
                        RdlRender.AddLine(_xmlWriter, "DocumentMapLabel", "=Fields!" + _tableGroupList[i].Name + ".Value");
                    }
                    if (_isPageOnFirstItem && i == 0)
                    {
                        _xmlWriter.WriteStartElement("PageBreak");
                        RdlRender.AddLine(_xmlWriter, "BreakLocation", "Between");
                        _xmlWriter.WriteEndElement(); // PageBreak
                    }

                    _xmlWriter.WriteStartElement("GroupExpressions");
                    RdlRender.AddLine(_xmlWriter, "GroupExpression", "=Fields!" + _tableGroupList[i].Name + ".Value");
                    _xmlWriter.WriteEndElement(); // GroupExpressions
                    _xmlWriter.WriteEndElement(); // Group

                    _xmlWriter.WriteStartElement("SortExpressions");
                    _xmlWriter.WriteStartElement("SortExpression");

                    RdlRender.AddLine(_xmlWriter, "Value", "=Fields!" + _tableGroupList[i].Name + ".Value");
                    //RdlRender.AddLine(xmlWriter, "Direction", "Ascending");
                    _xmlWriter.WriteEndElement(); // SortExpression
                    _xmlWriter.WriteEndElement(); // SortExpressions
                    _xmlWriter.WriteStartElement("TablixMembers");
                    _xmlWriter.WriteStartElement("TablixMember");
                    if (i > 0 && _isDrillDown)
                    {
                        _xmlWriter.WriteStartElement("Visibility");
                        RdlRender.AddLine(_xmlWriter, "Hidden", "true");
                        RdlRender.AddLine(_xmlWriter, "ToggleItem", "Group" + _tableGroupList[i - 1].Name);
                        _xmlWriter.WriteEndElement(); // Visibility
                    }
                    RdlRender.AddLine(_xmlWriter, "KeepWithGroup", "After");
                    RdlRender.AddLine(_xmlWriter, "KeepTogether", "true");
                    _xmlWriter.WriteEndElement(); // TablixMember
                }
            }

            // TableDetails
            if (_isSummaryReport == false)
            {
                _xmlWriter.WriteStartElement("TablixMember");
                _xmlWriter.WriteStartElement("Group");
                _xmlWriter.WriteAttributeString("Name", "Table1_Details_Group");
                //if (_isDataMapDisplayedGroup == true) // check if data map neds displaying
                //{
                //    RdlRender.AddLine(xmlWriter, "Label", "=Fields!" + _name + ".Value");
                //}
                RdlRender.AddLine(_xmlWriter, "DataElementName", "Detail");
                _xmlWriter.WriteEndElement(); // Group


                _xmlWriter.WriteStartElement("TablixMembers");
                _xmlWriter.WriteStartElement("TablixMember");
                if (_isDrillDown)
                {
                    _xmlWriter.WriteStartElement("Visibility");
                    RdlRender.AddLine(_xmlWriter, "Hidden", "true");
                    RdlRender.AddLine(_xmlWriter, "ToggleItem", "Group" + _tableGroupList[_tableGroupList.Count - 1].Name);
                    _xmlWriter.WriteEndElement(); // Visibility
                }
                _xmlWriter.WriteEndElement();     // TablixMember
                _xmlWriter.WriteEndElement();     // TablixMembers
                RdlRender.AddLine(_xmlWriter, "DataElementName", "Detail_Collection");
                RdlRender.AddLine(_xmlWriter, "DataElementOutput", "Output");
                RdlRender.AddLine(_xmlWriter, "KeepTogether", "true");
                _xmlWriter.WriteEndElement(); // TablixMember
            }

            //Close down the group hierarchies
            if (_tableGroupList != null && _tableGroupList.Count > 0)
            {
                for (int i = 0; i < _tableGroupList.Count; i++) //
                {
                    _xmlWriter.WriteEndElement();               // TablixMembers
                    _xmlWriter.WriteEndElement();               // TablixMember
                }
            }

            //Add Footer report name member
            _xmlWriter.WriteStartElement("TablixMember");
            RdlRender.AddLine(_xmlWriter, "KeepWithGroup", "Before");
            RdlRender.AddLine(_xmlWriter, "RepeatOnNewPage", "true");
            RdlRender.AddLine(_xmlWriter, "KeepTogether", "true");
            _xmlWriter.WriteEndElement(); // TablixMember

            //Add Footer filter selections
            for (int i = 0; i < _noOfFilters; i++)
            {
                _xmlWriter.WriteStartElement("TablixMember");
                RdlRender.AddLine(_xmlWriter, "KeepWithGroup", "Before");
                RdlRender.AddLine(_xmlWriter, "RepeatOnNewPage", "true");
                RdlRender.AddLine(_xmlWriter, "KeepTogether", "true");
                _xmlWriter.WriteEndElement(); // TablixMember
            }

            _xmlWriter.WriteEndElement(); // TablixMembers
            _xmlWriter.WriteEndElement(); // TablixRowHierarchy



            _xmlWriter.WriteStartElement("Style");
            _xmlWriter.WriteEndElement();



            _xmlWriter.WriteEndElement(); // Tablix

            foreach (Chart currentChart in _chartList)
            {
                currentChart.Render2010(_xmlWriter);
            }

            _xmlWriter.WriteEndElement(); // ReportItems
            _xmlWriter.WriteEndElement(); // Body

            RdlRender.AddLine(_xmlWriter, "Width", (_selectedDataItems.Count * 1.5 < 11.5)?"11.5in":(_selectedDataItems.Count * 1.5).ToString() + "in");



            _xmlWriter.WriteStartElement("Page");
            _xmlWriter.WriteStartElement("PageHeader");


            _xmlWriter.WriteStartElement("ReportItems");

            RdlRender.AddTextbox2010(_xmlWriter, "TitleTextbox", "DWP Small Systems Ad Hoc Reporting System",
                                     _textboxStyle14pt, "Left", "0.3cm", "2in", "6in", "true", "0.95cm", "2", "",
                                     "", "", "", "", "", "", "");

            RdlRender.AddTextbox2010(_xmlWriter, "PageHeader", "=Globals!ReportName", _textboxStyle14pt,
                                     "Left", "2.85714cm", "0.5in", "6in", "true", "1cm", "", "", "",
                                     "", "", "", "", "", "");

            RdlRender.AddImage2010(_xmlWriter, "Image1", "2.59259cm", "1.5in",
                                   "0.5in", "Embedded", "Esf", "AutoSize");
            int    ParameterCount = 0;
            int    X = 0;
            string ParameterHeight = "";

            foreach (String _parameterName in _parameterList)
            {
                ParameterCount++;
                X = ParameterCount;
                X = X + 3;
                ParameterHeight = X.ToString() + "cm";
                RdlRender.AddTextbox2010(_xmlWriter, "Parameter" + ParameterCount.ToString(), _parameterName, _textboxStyle14pt,
                                         "Left", ParameterHeight, "0.5in", "6in", "true", "1cm", "", "", "",
                                         "", "", "", "", "", "");
            }
            _xmlWriter.WriteEndElement(); // ReportItems
            X = ParameterCount;
            X = X + 4;
            ParameterHeight = X.ToString() + ".8cm";
            RdlRender.AddLine(_xmlWriter, "PrintOnLastPage", "true");
            RdlRender.AddLine(_xmlWriter, "PrintOnFirstPage", "true");
            RdlRender.AddLine(_xmlWriter, "Height", ParameterHeight);
            _xmlWriter.WriteEndElement(); // PagHeader


            // Report footer
            _xmlWriter.WriteStartElement("PageFooter");
            RdlRender.AddLine(_xmlWriter, "Height", "1.0cm");
            RdlRender.AddLine(_xmlWriter, "PrintOnFirstPage", "true");
            RdlRender.AddLine(_xmlWriter, "PrintOnLastPage", "true");
            _xmlWriter.WriteStartElement("ReportItems");

            RdlRender.AddTextbox2010(_xmlWriter, "UserTextBox", "=Parameters!ReportUserName.Value",
                                     _textboxStyle10pt, "", "0.25cm", "1.0cm", "6.00cm", "true", "0.5cm", "1",
                                     "", "", "", "", "", "", "", "");
            RdlRender.AddTextbox2010(_xmlWriter, "ExecutionTimeTextBox", "=Globals!ExecutionTime",
                                     _textboxStyle10pt, "", "0.25cm", "7.00cm", "6.00cm", "true", "0.5cm", "1",
                                     "", "", "", "", "", "", "", "");
            RdlRender.AddTextbox2010(_xmlWriter, "PageNumberTextBox", "=Globals!PageNumber",
                                     _textboxStyle10pt, "", "0.25cm", "15.00cm", "3.00cm", "true", "0.5cm", "1",
                                     "", "", "", "", "", "", "", "");

            _xmlWriter.WriteEndElement(); // ReportItems
            _xmlWriter.WriteEndElement(); // PageFooter


            _xmlWriter.WriteEndElement(); // Page

            _xmlWriter.WriteEndElement(); // RepoetSection
            _xmlWriter.WriteEndElement(); // ReportSections


            //Add a report parameter for user id

            _xmlWriter.WriteStartElement("ReportParameters");


            _xmlWriter.WriteStartElement("ReportParameter");
            _xmlWriter.WriteAttributeString("Name", "ReportUserName");
            // Render relevant data type
            RdlRender.AddLine(_xmlWriter, "DataType", "String");
            RdlRender.AddLine(_xmlWriter, "Prompt", "User Name");
            RdlRender.AddLine(_xmlWriter, "Hidden", "true");
            _xmlWriter.WriteEndElement(); // ReportParameter

            _xmlWriter.WriteStartElement("ReportParameter");
            _xmlWriter.WriteAttributeString("Name", "ReportUserCode");
            // Render relevant data type
            RdlRender.AddLine(_xmlWriter, "DataType", "String");
            RdlRender.AddLine(_xmlWriter, "Prompt", "User Name");
            RdlRender.AddLine(_xmlWriter, "Hidden", "true");
            _xmlWriter.WriteEndElement(); // ReportParameter

            // ReportParameters
            if (_reportParametersList != null && _reportParametersList.Count > 0)
            {
                foreach (ReportParameter CurrentParameter in _reportParametersList)
                {
                    CurrentParameter.Render2010(_xmlWriter);
                }
            }
            _xmlWriter.WriteEndElement();



            // EmbeddedImages
            _xmlWriter.WriteStartElement("EmbeddedImages");
            _xmlWriter.WriteStartElement("EmbeddedImage");
            _xmlWriter.WriteAttributeString("Name", "Esf");
            RdlRender.AddLine(_xmlWriter, "MIMEType", "image/bmp");
            _xmlWriter.WriteStartElement("ImageData");

            // Image data
            FileStream ImageStream = new FileStream(
                HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["SmallSystemsLogoImage"]), FileMode.Open, FileAccess.Read);

            byte[] ImageByteArray = new byte[ImageStream.Length];
            ImageStream.Read(ImageByteArray, 0, (int)ImageStream.Length);
            ImageStream.Close();
            _xmlWriter.WriteBase64(ImageByteArray, 0, ImageByteArray.Length);

            _xmlWriter.WriteEndElement(); // ImageData
            _xmlWriter.WriteEndElement(); // EmbeddedImage
            _xmlWriter.WriteEndElement(); // EmbeddedImages

            RdlRender.AddLine(_xmlWriter, "ConsumeContainerWhitespace", "true");
            _xmlWriter.WriteEndElement(); // Report
            _xmlWriter.WriteEndDocument();
            //****TESTING*************
            // _xmlWriter.Flush();
            // XmlDocument doc = RdlRender.CreateXmlDocument(_memoryStream);
            //*****************/
            _xmlWriter.Flush();

            _memoryStream.Close();
            return(_memoryStream.ToArray());// GetBuffer();

            //_stream.Close();
            // return new byte[0];
        }