Tải bản đầy đủ - 0 (trang)
Chapter 28. Custom Report Definition Language (RDL) Generators and Customizing Report Definition

Chapter 28. Custom Report Definition Language (RDL) Generators and Customizing Report Definition

Tải bản đầy đủ - 0trang

blankreportandcreatesareport'sRDLpiecebypiece,using

XmlTextWriter.

WeusethetermRDLtemplatedescribesanXMLthatconforms

toanRDLschema,butdoesnotnecessarilydescribea

functionalreport.Thischapterdemonstrateshowtocreateand

reusetheRDLtemplate.Forsimplicity,thesampleusesmostof

theRDLfromthetemplateandcustomizesjustafewfields,

suchas,,and.

Supposethatthegoalistocreateawebapplicationthatwill

useanRDLtemplateandwillprogrammaticallymodifythis

template,basedonuserinput.

Thetemplateisareportwithathree-columntable.The

applicationallowscustomizingthetemplate'squeryandthe

template'sconnectionstring.Forsimplicity,theapplicationonly

usesthefirstthreefieldsfromaqueryandconsidersallofthe

fieldsbeingtheSystem.Stringtype.

Tocreateatemplate,youcanleverageReportDesignerand

startwithasimplereportthatconnectstotheAdventureWorks

database,selectsthreefieldsfromanyofthetables,and

displaysresultsinatablereportitem.

Afterthereportiscompleted,youcanconvertittoanRDL

template:

1. Right-clickonthereportinSolutionExplorerandselectView

Codeorviewthereport'sRDLfileinatexteditor.



Note

Theaccompanyingcodecontainschangestothe

valuetoSELECTF1,F2,F3FROMTBL;

however,thevalueofthisnodeisirrelevantbecause

itgetscompletelyreplacedbythesample



application.Youcandecideifcompletereplacement

ofisdesirableforeachindividual

template.



2. EdittheRDLandreplaceeveryoccurrenceofthefirstquery

fieldnamewithsomeuniquevalue,suchasF1.Repeatthe

procedurefortherestofthefields(F2andF3,respectively).

Whengoingthroughthereplacementprocess,pleasekeep

inmindthatReportDesigneraddsspacesbetween

capitalizations(thatis,OrderIdgetschangedtoOrderId).This

happenswhenReportDesignerassignsvaluesforthe

rowreportitems.



TheresultingRDL/XMLshouldlooksimilartothefollowing(only

keypointsareshown):



[Viewfullwidth]



...



DataSource=localhost;InitialCatalog=AdventureWorks;Integrate



...



















F1



true

=Fields!F1.V







...

















true

F1







...



...





...







SELECTF1,F2,F3FROMTBL
DataSource







System.String

F1



...





>



Afterchangesarecompleted,youcandeploythisRDLtemplate.

BecauseanRDLtemplateconformstoRDLspecifications,SSRS

doesnot"complain"aboutsuchdeploymentdespitethefact

thatthisisnotreallyafunctionalreport.

Toachievethedesiredfunctionality,thesampleusesthe

followingnamespaces:

System.IOtoaccessstreamhandling,particularlythe

MemoryStreamclass

ReportService2005tointeractwithSSRStoretrieveatemplate



andtostoreareport

System.Web.Services.ProtocolstohandleSOAPexceptions

System.XmltoaccessXMLhandling,particularlytheXmlDocument



class

System.Data.SqlClienttovalidateaqueryandgetfieldnames



First,thesampleloadsatemplateanddisplaysaconnection

stringandthequery(CommandText)fromthetemplate:



byte[]reportDefinition=rs.GetReportDefinition(templatePath);

MemoryStreamstream=newMemoryStream(reportDefinition);

System.Xml.XmlDocumentdoc=newSystem.Xml.XmlDocument();

doc.Load(stream);

txtConnection.Text=doc.GetElementsByTagName("ConnectString")[

txtQuery.Text=doc.GetElementsByTagName("CommandText")[0].Inne



Asanextseriesofsteps,thesample



1. CollectsanupdatedstringandaqueryfromtheUIandreplacestheorig

theRDLtemplate



doc.GetElementsByTagName("ConnectString")[0].InnerXml=txtCo

doc.GetElementsByTagName("CommandText")[0].InnerXml=txtQuer



2. Executesaquerytovalidatethequerysyntax



SqlConnectioncon=newSqlConnection(txtConnection.Text);

con.Open();

System.Data.SqlClient.SqlCommandcmd=newSqlCommand(txtQuer

SqlDataReaderreader=cmd.ExecuteReader();



3. Getsthenamesoffieldsandreplacestemplatestringswithfieldnames



reader.Read();

StringstrTmp=doc.InnerXml.Replace("F1",reader.GetName(0))

strTmp=strTmp.Replace("F2",reader.GetName(1));

strTmp=strTmp.Replace("F3",reader.GetName(2));

doc.InnerXml=strTmp;



4. Writestheresultofchangesasareporttoaspecifiedlocation

MemoryStreamstream=newMemoryStream();

doc.Save(stream);

Byte[]definition=stream.ToArray();

stream.Close();



Warning[]warnings=

rs.CreateReport(txtResultName.Text,txtResultPath.Text,f

definition,

null);



Afterthefinalreportisdeployed,itcanbeusedjustlikeany

report.Thepurposeofthesampleistodemonstratethebasic

capabilitiesofanRDLgeneration.Thesampleprovides

rudimentaryerrorhandlingandcanusesomeperformance

improvements.Forexample,youcanfindbetteralternativesto

validateaqueryandtoretrievefieldsthanexecutinga

SqlDataReader.



Summary

ReportDefinitionLanguage(RDL)isanXML-basedlanguage

usedtodescribereports.BecauseXMLisdesignedtosimplify

dataexchangebetweenapplications,soisanRDL.Althoughan

additionofanadhocreportingtool(ReportBuilder)

significantlyreducedtheneedtowriteRDLgenerators,inafew

casesinwhichtheneedexists,.NETXMLhandlingfunctionality

providesaproductivityboosterforanRDLgeneration.



PartV:Appendices

InThisPart







APPENDIXAReferencesandAdditionalReading







APPENDIXBGlossary







APPENDIXCFAQ



AppendixA.ReferencesandAdditional

Reading



BertucciPaul.MicrosoftSQLServerHighAvailability.Sams

Publishing,2004,ISBN:0672326256.

http://www.samspublishing.com/title/0672326256.

HirtAllanwithCathanCook,KimberlyL.Tripp,andFrank

McBath.Microsoft®SQLServerTM2000HighAvailability.

MicrosoftPress,2003,ISBN:0-7356-1920-4.

http://www.microsoft.com/MSPress/books/6515.asp.

Microsoft.Course2944:UpdatingYourReportingSkillsto

Microsoft®SQLServerTM2005ReportingServices.Microsoft

Corporation,2005.

https://www.microsoftelearning.com/eLearning/offerDetail.aspx?

offerPriceId=66793.

Microsoft.SQLServer2005BooksOnline.Microsoft

Corporation,2005.Downloadfrom

http://www.microsoft.com/downloads/details.aspx?

FamilyID=be6a2c5d-00df-4220-b13329c1e0b6585f&displaylang=enoraccessonlineat

http://msdn2.microsoft.com/en-us/library/ms203721(enus,sql.90).aspx.

MisnerStacia.Microsoft®SQLServerTM2000Reporting

ServicesStepbyStep.MicrosoftPress,2005,ISBN:0-73562106-3.http://www.microsoft.com/MSPress/books/7304.asp.

JackobsonReed.MicrosoftSQLServer2000AnalysisServices

StepbyStep.MicrosoftPress,2000,ISBN:0-7356-0904-7.

http://www.microsoft.com/MSPress/books/4076.asp.

PlattDavidS.IntroducingMicrosoft®.NET,ThirdEdition.

MicrosoftPress,2003,ISBN:0-7356-1918-2.

http://www.microsoft.com/MSPress/books/6475.asp.

ScalabilityExperts,Inc.MicrosoftSQLServer2005:Changing



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 28. Custom Report Definition Language (RDL) Generators and Customizing Report Definition

Tải bản đầy đủ ngay(0 tr)

×