
<H1><B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>Working</FONT></SPAN> with <SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN> <SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN> in .Net </B></H1>
<P></P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Overview</B></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P>This article will walk through some of the functionalities in <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> and how to bind a report in visual studio .Net.</P>
<P></P>
<P>First section covers the functionalities in <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> and second section covers how to integrate <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> with .Net. </P>
<P></P>
<P></P>
<H1><A name=_Toc151185801><FONT color=#004cd5>Create a Simple Application</FONT></A></H1>
<P><FONT color=#004cd5></FONT></P>
<H2><A name=_Toc151185802><FONT color=#004cd5>Create a Web Application and Add a </FONT><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN><FONT color=#004cd5> Report</FONT></A></H2>
<P>1. Open the Visual Studio .Net.</P>
<P>2. On the <B style="mso-bidi-font-weight: normal">File</B> menu, click <B style="mso-bidi-font-weight: normal">New</B> then click <B style="mso-bidi-font-weight: normal">Website</B>.</P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CreateApplication1.jpg"></P>
<P><B style="mso-bidi-font-weight: normal">3. </B>Right click on solution, click <B style="mso-bidi-font-weight: normal">Add New Item </B>then click<B style="mso-bidi-font-weight: normal"> <SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN> Report.</B></P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CreateApplication2.jpg"> </P>
<H1><A name=_Toc150151752></A><A name=_Toc150151852></A><A name=_Toc150152043></A><A name=_Toc151185803><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN><FONT color=#004cd5> </FONT><SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN><FONT color=#004cd5> 10.0</FONT></A></H1>
<P><B style="mso-bidi-font-weight: normal"><FONT color=#004cd5></FONT></B></P>
<H2><A name=_Toc150151753></A><A name=_Toc150151853></A><A name=_Toc150152044></A><A name=_Toc151185804><FONT color=#004cd5>Bind Source to </FONT><SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN></A></H2>
<P>After creating <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN>report (.rpt) file, the first thing to do is set data source to the report.</P>
<P></P>
<P>1. Click on <B style="mso-bidi-font-weight: normal">Field Explorer</B>.</P>
<P>2. Right click on <B style="mso-bidi-font-weight: normal">Database Fields,</B> click on <B style="mso-bidi-font-weight: normal">Database Expert.</B></P>
<P>3. Click on <B style="mso-bidi-font-weight: normal">Create New Connection</B> and select one of the sources.</P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/BindSource1.jpg"> </P>
<P>Some of the sources for <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN>report</P>
<P><B style="mso-bidi-font-weight: normal">1. </B><B style="mso-bidi-font-weight: normal">Tables in a database</B></P>
<P>Bind tables of a database as source to a report using wizard in the <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>. Data will be automatically populated in the report.</P>
<P><B style="mso-bidi-font-weight: normal">1. </B><B style="mso-bidi-font-weight: normal">Stored Procedure in database</B></P>
<P>Create a stored procedure and bind the stored procedure to the report using wizard in the <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P><B style="mso-bidi-font-weight: normal">2. </B><B style="mso-bidi-font-weight: normal">Objects in .Net</B></P>
<P>Create object in .net and this can be passed as a source to the <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P><B style="mso-bidi-font-weight: normal">3. </B><B style="mso-bidi-font-weight: normal">Xmlschema</B></P>
<P>Create an xmlschema and bind that schema as a source to the <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<H2><A name=_Toc151185805><FONT color=#004cd5>Sub </FONT><SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN></A></H2>
<P>Sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> are very much useful in building <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>. Segregate the main report into various sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P></P>
<P>Main advantage of the sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> is</P>
<P>1. Same sub report can be useful in multiple <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>. Re usability of sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> can be done.</P>
<P>2. If we segregate main report into sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>, it will be very simpler to build <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P></P>
<H2><A name=_Toc151185806><FONT color=#004cd5>Formula Fields</FONT></A></H2>
<P>This is a very good option provided by the <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>. Formula fields are very much useful to format input data.</P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Example:</B></P>
<P>There are two fields �state� and �city� in database. In the report if both fields have to be displayed as comma separated</P>
<P></P>
<P>1. Click on <B style="mso-bidi-font-weight: normal">field explorer</B>.</P>
<P>2. Right click on <B style="mso-bidi-font-weight: normal">formula fields</B> and click new.</P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/FormulaField1.jpg"> </P>
<P>3. Give a name to the formula field.</P>
<P>4. Three sections will be visible in the formula workshop</P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/FormulaField2.jpg"> </P>
<P>4.1. First section contains <B style="mso-bidi-font-weight: normal">�Report Fields�</B> and <B style="mso-bidi-font-weight: normal">�Database Fields�</B>. <B style="mso-bidi-font-weight: normal">�Report fields�</B> contains all the fields which were used in the report. <B style="mso-bidi-font-weight: normal">�Database Fields�</B> contains all the fields which were available as data source to the report.</P>
<P>4.2. Second section contains all the functions available.</P>
<P>4.3. Third section contains operators such as �=�,�<� and syntax for variable declaration.</P>
<P></P>
<P>5. In the first section expand data source, table name, and fields will be visible. </P>
<P>6. Double click on �state� and �city� fields. Selected fields will be visible in the intermediate section. Edit the code as shown below<B>.</B></P>
<P><B><I>{Table.City} & ", " & {Table.State}</I></B></P>
<P>7. Save the formula field.</P>
<P>8. Place the formula field on <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P></P>
<P>For formula fields, code can be written in two syntaxes. </P>
<P>1. <B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN> syntax: </B>This is the syntax is provided by <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P>2. <B style="mso-bidi-font-weight: normal">Basic syntax:</B> This is VB syntax. </P>
<P>Change the type of the syntax in the drop down shown in the formula workshop.</P>
<P></P>
<H2><A name=_Toc151185807><FONT color=#004cd5>Functions in Formula Fields</FONT></A></H2>
<P>In the formula workshop one of the sections contains functions available to format formula fields.</P>
<P></P>
<P></P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Example1:</B></P>
<P>If input string case has to be changed to proper case use �propercase� function under strings section.</P>
<P>1. Create a formula field.</P>
<P>2. Select <B style="mso-bidi-font-weight: normal">�propercase�</B> function under strings section.</P>
<P>3. Double click on the function.</P>
<P>4. Select the �Name� field from the database fields.</P>
<P>5. Double click on the �Name� field.</P>
<P>6. The following code will return input string in proper case.</P>
<P></P>
<P><B><I>propercase({Name})</I></B></P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Example2:</B></P>
<P>If input parameter type has to be converted to currency following convert function will be useful.</P>
<P></P>
<P>1. Create a formula field.</P>
<P>2. Select <B style="mso-bidi-font-weight: normal">�ccur�</B> function under strings section.</P>
<P>3. Double click on the function.</P>
<P>4. Select the �Amount� field from the database fields.</P>
<P>5. Double click on the �Amount� field.</P>
<P></P>
<P><B><I>ccur({Amount})</I></B></P>
<P></P>
<P>Various functions are available according to significance, like mathematical functions were available under �Math� section and strings related functions were available under �Strings� section.</P>
<P></P>
<H2><A name=_Toc151185808><FONT color=#004cd5>Sections in </FONT><SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN></A></H2>
<P>There are 5 basic sections in <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P><B style="mso-bidi-font-weight: normal">1. </B><B style="mso-bidi-font-weight: normal">Report header</B></P>
<P>This section will appear on top of the report and only once in a report.</P>
<P><B style="mso-bidi-font-weight: normal">2. </B><B style="mso-bidi-font-weight: normal">Page header</B></P>
<P>This section will appear on top of the page and only once per page.</P>
<P><B style="mso-bidi-font-weight: normal">3. </B><B style="mso-bidi-font-weight: normal">Detail section</B></P>
<P>This section allows repetition of data. </P>
<P><B style="mso-bidi-font-weight: normal">4. </B><B style="mso-bidi-font-weight: normal">Page footer</B></P>
<P>This section will appear on bottom of the page and only once in a report.</P>
<P><B style="mso-bidi-font-weight: normal">5. </B><B style="mso-bidi-font-weight: normal">Report footer</B></P>
<P>This section will appear on bottom of the report and only once in report.</P>
<P><SPAN class=search-highlight><STRONG><FONT color=#ff0000>Crystal</FONT></STRONG></SPAN> report allows adding multiple sections in a report.</P>
<P>1. Right click on any of the section header. </P>
<P>2. Click <B style="mso-bidi-font-weight: normal">Insert section below</B>.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><IMG style="WIDTH: 519px; HEIGHT: 396px" alt="Sample screenshot" src="Crystal_Reports_in_net/SubReport1.jpg" width=576 height=435> </P>
<H2><A name=_Toc151185809><FONT color=#004cd5>Show Data of a sub report in Multiple Pages</FONT></A></H2>
<P>Each sub report will be like an object. Sub report which contains data will be in a single page, instead of breaking into multiple pages. </P>
<P></P>
<P>1. Right click on sub report.</P>
<P>2. Uncheck <B style="mso-bidi-font-weight: normal">keep object together</B>.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/MultiplePages1.jpg"></P>
<P>By this option data will placed in multiple pages.</P>
<H2><A name=_Toc151185810><FONT color=#004cd5>Group By</FONT></A></H2>
<P>This option is similar to the group by option in sqlserver. If data has to be grouped by a particular field this option will be useful.</P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Example:</B></P>
<P>There are two fields in data base �month� and �amount�. Requirement is, in the report amount earned has to be shown per month. </P>
<P></P>
<P>1. In the main menu click on <B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>crystal</FONT></SPAN> <SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN></B>.</P>
<P>2. Click <B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN></B>.</P>
<P>3. Click on <B style="mso-bidi-font-weight: normal">Group expert option</B>.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal"><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/GroupBy1.jpg"> </B></P>
<P>4. Select �Month� field from the fields shown.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/GroupBy2.jpg"> </P>
<P>Two new sections will appear in the report, group header and group footer. The use of these sections will be same as header and footer as mention in the sections. </P>
<P></P>
<H2><A name=_Toc151185811><FONT color=#004cd5>Summary Fields</FONT></A></H2>
<P>This is an extended option of group by. We will discuss this option with same example discussed in group by section.</P>
<P></P>
<P>In the example (Discussed in <B style="mso-bidi-font-weight: normal">Group By</B> section), after grouping the data according to month, if sum of the amount earned per month has to be displayed this option will be useful. </P>
<P></P>
<P>1. In the main menu click on <B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>crystal</FONT></SPAN> <SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN></B>.</P>
<P>2. Click on <B style="mso-bidi-font-weight: normal">insert</B> option.</P>
<P>3. Click on <B style="mso-bidi-font-weight: normal">summary</B> option.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal"><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/Summary1.jpg" width=494 height=432> </B></P>
<P>4. Select a database field in the <B style="mso-bidi-font-weight: normal">�Choose the field to summarize�</B> drop down.</P>
<P>5. Select an expression from <B style="mso-bidi-font-weight: normal">�Calculate the summary�</B> drop down.</P>
<P>6. Click �<B style="mso-bidi-font-weight: normal">ok</B>�. Summary field will be added in the report.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/Summary2.jpg"> </P>
<P><B style="mso-bidi-font-weight: normal">Note:</B></P>
<P>To get sum of a field, it should be numeric, if not other than mathematical expressions can be used. </P>
<P></P>
<H2><A name=_Toc151185812><FONT color=#004cd5>Hierarchal Grouping</FONT></A></H2>
<P>This option will be useful to group data hieratically.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal">Example:</B></P>
<P>Simple example where this option will be useful is employee manager relation. There are two fields in database.</P>
<P></P>
<P><B style="mso-bidi-font-weight: normal"><U>Employee Manager</U></B></P>
<P>Emp1 ---</P>
<P>Emp2 Emp1</P>
<P>Emp3 Emp1</P>
<P>Emp4 Emp2</P>
<P>Emp5 Emp2</P>
<P>Emp6 Emp3</P>
<P>Emp7 Emp3</P>
<P>Emp8 Emp1</P>
<P></P>
<P></P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Requirement: </B></P>
<P>Emp1</P>
<P> Emp2</P>
<P> Emp4</P>
<P> Emp5</P>
<P> Emp3</P>
<P> Emp6</P>
<P> Emp7</P>
<P> Emp8</P>
<P></P>
<P>Above format shows data in hierarchal relation between employee and manager.</P>
<P></P>
<P>1. First group the data (As discussed in <B style="mso-bidi-font-weight: normal">Group By</B> section) on employee field.</P>
<P>2. In the main menu click on <B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN> <SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN></B>.</P>
<P>3. Click on <B style="mso-bidi-font-weight: normal">Report</B> option.</P>
<P>4. Click on <B style="mso-bidi-font-weight: normal">Hierarchal Grouping Option</B>.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/HierarichalGrouping1.jpg"> </P>
<P>5. Check <B style="mso-bidi-font-weight: normal">�Sort Data Hieratically�</B> option.</P>
<P>6. Select a field from <B style="mso-bidi-font-weight: normal">�Parent Id field�</B> drop down.</P>
<P>7. Set <B style="mso-bidi-font-weight: normal">�Group Indent�</B> as �0.35�.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/HierarichalGrouping2.jpg"> </P>
<P><B style="mso-bidi-font-weight: normal">Note:</B></P>
<P>Manager data should be sub set of employee data.</P>
<P>Data type of both fields should be same.</P>
<P></P>
<H2><A name=_Toc151185813><FONT color=#004cd5>Build a Cover Page</FONT></A></H2>
<P>A simple example for this is, if report name should come at the starting of the report in a separate page</P>
<P>1. Build a sub report which contains report name.</P>
<P>2. Place the sub report in the main report in <B style="mso-bidi-font-weight: normal">Report Header</B> section.</P>
<P>3. Right click on the sub report section header.</P>
<P>4. Click on <B style="mso-bidi-font-weight: normal">Section Expert</B> option.</P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal"><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CoverPage1.jpg"> </B></P>
<P>5. Check <B style="mso-bidi-font-weight: normal">�New Page After�</B> option.</P>
<P><B style="mso-bidi-font-weight: normal"><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CoverPage2.jpg" width=531 height=432></B></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P>6. Click <B style="mso-bidi-font-weight: normal">�Ok�</B>.</P>
<P>7. This sub report will be added as first page of the report.</P>
<P></P>
<H2><A name=_Toc151185814><FONT color=#004cd5>Shared Variables</FONT></A></H2>
<P>These variables can be accessible globally i.e. through out the report. If a shared variable has been declared in of the sub report, it can accessible in the successive sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P></P>
<P>The syntax to declare variables will be available in the <B style="mso-bidi-font-weight: normal">operator section</B> of the <B style="mso-bidi-font-weight: normal">Formula Workshop</B>.</P>
<P></P>
<P>Example:</P>
<P>1. A report contains two sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> subreport1, subreport2.</P>
<P>2. Filed amount is useful in subreport2. </P>
<P>3. Declare shared variable in subreport1. </P>
<P>4. Create a formula field in subreport1.</P>
<P>5. Write following lines of code.</P>
<P><B><I>shared currencyvar x := {Amount};</I></B></P>
<P>6. Use the same variable in subreport2. </P>
<P>7. Declare a shared variable of same data type which was in subreport1.</P>
<P>8. Create a formula field in Subreport2. Write following lines of code.</P>
<P><B><I>shared currencyvar z;</I></B></P>
<P><B><I>shared currencyVar x;</I></B></P>
<P><B><I>z := x;</I></B></P>
<P>9. By above few lines of code value in �x� has been assigned to �z�.</P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Note:</B></P>
<P>1. Data type of both the shared variables should be same.</P>
<P>2. Shared variable which are going to access globally should be loaded first. In the above case subreport1 should be loaded first and subreport2 should be loaded later in the main report, because variable declared in the subrerpot1 are going to access globally.</P>
<P></P>
<H2><A name=_Toc151185815><FONT color=#004cd5>Custom Functions</FONT></A></H2>
<P>We can create custom functions apart from the functions available in the formula workshop.</P>
<P></P>
<P>1. In the main menu click on <B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN> <SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN></B>.</P>
<P>2. Select <B style="mso-bidi-font-weight: normal">Report</B> option.</P>
<P>3. Select <B style="mso-bidi-font-weight: normal">Selection Formula</B> option.</P>
<P>4. Select <B style="mso-bidi-font-weight: normal">Group </B>option. </P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CustomFunctions1.jpg"></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P>5. Right click on <B style="mso-bidi-font-weight: normal">Report Custom Functions</B>.</P>
<P>6. Select <B style="mso-bidi-font-weight: normal">New</B> option.</P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CustomFunctions2.jpg"></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P>7. Following screen will be shown.</P>
<P><IMG alt="Sample screenshot" src="Crystal_Reports_in_net/CustomFunctions3.jpg"></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal">8. </B>Add following lines of code in the Middle section.<B style="mso-bidi-font-weight: normal"></B></P>
<P><B style="mso-bidi-font-weight: normal"><I>Function Mult(i As number, j as number) As Number</I></B></P>
<P><B style="mso-bidi-font-weight: normal"><I>Dim i As number</I></B></P>
<P><B style="mso-bidi-font-weight: normal"><I>Dim j As number</I></B></P>
<P><B style="mso-bidi-font-weight: normal"><I>Dim expr As number</I></B></P>
<P><B style="mso-bidi-font-weight: normal"><I>expr = i * j</I></B></P>
<P><B style="mso-bidi-font-weight: normal"><I>End Function</I></B><B style="mso-bidi-font-weight: normal"></B></P>
<P>9. Above few lines of code will create a function, which have two input parameters and return a value. </P>
<P></P>
<P>To create functions, code can be written in either <SPAN class=search-highlight><STRONG><FONT color=#ff0000>crystal</FONT></STRONG></SPAN> syntax or VB syntax. To change the syntax option will be available in the menu of formula workshop.</P>
<H1><A name=_Toc150151754></A><A name=_Toc150151854></A><A name=_Toc150152045></A><A name=_Toc151185816><FONT color=#ff0000><SPAN class=search-highlight>Crystal</SPAN><SPAN class=search-highlight>Reports</SPAN></FONT><FONT color=#004cd5>.Net</FONT></A></H1>
<P><FONT color=#004cd5></FONT></P>
<H2><A name=_Toc151185817><FONT color=#004cd5>Report Document</FONT></A></H2>
<P>Namespace required:</P>
<P><B><I>Imports</I></B><B><I> <SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN>Decisions.<FONT color=#ff0000><SPAN class=search-highlight>Crystal</SPAN><SPAN class=search-highlight>Reports</SPAN></FONT>.Engine</I></B></P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Reportdocument</B> is the main object through which <STRONG><FONT color=#ff0000><SPAN class=search-highlight>crystal</SPAN><SPAN class=search-highlight>reports</SPAN></FONT></STRONG> can be accessed. </P>
<P><B>Reportdocument</B> object will be useful to </P>
<P>1. Load a report.</P>
<P>2. Set data source to a report.</P>
<P>3. Export a report.</P>
<P></P>
<P>Dataset, Datatable, datareader or collection any one of the listed objects can be passed as data source to the report.</P>
<P></P>
<P><B><I>Dim report As New ReportDocument()</I></B></P>
<P><I><B>report.Load(</B></I><I><B>"C:\report.rpt")</B></I></P>
<P><I><B>report.SetDataSource(datatable)</B></I></P>
<P><B style="mso-bidi-font-weight: normal"></B></P>
<H2><A name=_Toc151185818><FONT color=#004cd5>Sub Report</FONT></A></H2>
<P>A report can have any number of sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>. Data source can be set to sub report using the reportdocument object of the main report container.</P>
<P></P>
<P><B><I>Dim report As New ReportDocument()</I></B></P>
<P><B><I>report.Load(</I></B><B><I>"C:\report.rpt")</I></B></P>
<P></P>
<P>Example:</P>
<P>If the main report contains 3 sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>, </P>
<P>1. Load report document object with main report (report.rpt) as described in the �Report Document� section.</P>
<P>2. With following lines of code data source can be set to sub <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN>.</P>
<P></P>
<P><I><B>report.Sub<SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN>.Item(</B></I><I><B>"Subreport1").SetDataSource(datatable1)</B></I></P>
<P><I><B>report.Sub<SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN>.Item(</B></I><I><B>"Subreport2").SetDataSource(datatable2)</B></I></P>
<P><I><B>report.Sub<SPAN class=search-highlight><FONT color=#ff0000>reports</FONT></SPAN>.Item(</B></I><I><B>"Subreport3").SetDataSource(datatable3)</B></I></P>
<P></P>
<P><B style="mso-bidi-font-weight: normal">Note:</B></P>
<P>A sub report can not contain another sub report. </P>
<H2><A name=_Toc151185819><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN><FONT color=#004cd5>reportviewer</FONT></A></H2>
<P><B style="mso-bidi-font-weight: normal"><SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN>reportviewer</B> is useful to view the report on a webpage.After setting datasource to the report and sub<SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> the following code is required to bind the report to <SPAN class=search-highlight><STRONG><FONT color=#ff0000>Crystal</FONT></STRONG></SPAN>reportviewer.</P>
<P></P>
<P><B><I><SPAN class=search-highlight><FONT color=#ff0000>crystal</FONT></SPAN>reportviewer.<SPAN class=search-highlight><FONT color=#ff0000>ReportS</FONT></SPAN>ource = report</I></B></P>
<P></P>
<H2><A name=_Toc151185820><FONT color=#004cd5>Export to PDF</FONT></A></H2>
<P>Namespace required: </P>
<P><B><I>Imports <SPAN class=search-highlight><FONT color=#ff0000>Crystal</FONT></SPAN>Decisions.Shared</I></B></P>
<P></P>
<P>To export a report as a pdf document the following code will be useful.</P>
<P>1. Load <B style="mso-bidi-font-weight: normal">report document</B> object with main report(report.rpt).</P>
<P>2. Write following lines of code.</P>
<P></P>
<P><B><I>Dim exportOptions As New ExportOptions</I></B></P>
<P><B><I>Dim diskFileDestinationOptions As New DiskFileDestinationOptions()</I></B></P>
<P><B><I>Dim formatTypeOptions As New PdfRtfWordFormatOptions()</I></B> <B style="mso-bidi-font-weight: normal"></B>
<P>
<P><B><I></I></B></P>
<P><B style="mso-bidi-font-weight: normal"></B></P><SPAN style="FONT-FAMILY: 'Book Antiqua'; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><SPAN><SPAN><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><SPAN><SPAN><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><SPAN><SPAN><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><SPAN><SPAN><SPAN style="FONT-FAMILY: 'Book Antiqua'"><SPAN style="FONT-FAMILY: 'Book Antiqua'">
<P></P><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3>3.</FONT><SPAN style="FONT: 7pt 'Times New Roman'"> <FONT size=3><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'">�diskFileDestinationOptions�</B><SPAN style="FONT-FAMILY: 'Book Antiqua'"> is required to set the path and name of the destination file.<?xml:namespace prefix = o /><o:p></o:p></FONT>
<P></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><FONT size=3><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><STRONG><EM>diskFileDestinationOptions.DiskFileName = </EM></STRONG><SPAN style="COLOR: maroon"><STRONG><EM>"C:\report.pdf"</EM></STRONG><SPAN style="FONT-FAMILY: 'Book Antiqua'; COLOR: maroon"><o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'; COLOR: maroon"><FONT size=3><o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; tab-stops: list 1.25in; mso-list: l19 level1 lfo26" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3>4.</FONT><SPAN style="FONT: 7pt 'Times New Roman'"> <FONT size=3><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'">�exportOptions�</B><SPAN style="FONT-FAMILY: 'Book Antiqua'"> is required to set exporttype and destination file options.<o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3><STRONG><EM>exportOptions.ExportDestinationType = ExportDestinationType.DiskFile<o:p></o:p></EM></STRONG></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><FONT size=3><STRONG><EM>exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat<o:p></o:p></EM></STRONG></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><FONT size=3><STRONG><EM>exportOptions.DestinationOptions = diskFileDestinationOptions<o:p></o:p></EM></STRONG></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><FONT size=3><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><STRONG><EM>exportOptions.FormatOptions = formatTypeOptions</EM></STRONG><SPAN style="FONT-FAMILY: 'Book Antiqua'"><o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.25in; tab-stops: list 1.25in; mso-list: l19 level1 lfo26" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3>5.</FONT><SPAN style="FONT: 7pt 'Times New Roman'"> <SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3>After setting the type of export and destinationfile options following few lines of cede is required to export the report to the specified destation path.<o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><FONT size=3><SPAN style="FONT-FAMILY: 'Book Antiqua'; mso-highlight: silver"><STRONG><EM>report.Export(exportOptions)</EM></STRONG><SPAN style="FONT-FAMILY: 'Book Antiqua'"><o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></B></P>
<H2 style="TEXT-INDENT: 0in; MARGIN: 12pt 0in 3pt"><A name=_Toc151185821><SPAN style="FONT-STYLE: normal; FONT-FAMILY: 'Book Antiqua'; COLOR: #0066cc"><FONT size=5>Access Fields in <SPAN class=search-highlight><FONT color=#ff0000>Reports</FONT></SPAN></FONT></A><SPAN style="FONT-STYLE: normal; FONT-FAMILY: 'Book Antiqua'; COLOR: #0066cc"><o:p></o:p></H2>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3>Fields in <SPAN class=search-highlight><STRONG><FONT color=#ff0000>reports</FONT></STRONG></SPAN> can be accessed through .Net.<o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3>Example: <o:p></o:p></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3><SPAN style="mso-tab-count: 1"> If a field in report has to be enabled or disabled according to input, it can be accessible through code in .Net.</FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="mso-tab-count: 1"><FONT size=3 face="Times New Roman"> </FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-highlight: silver"><SPAN><STRONG><EM>report.ReportDefinition.Sections(<SPAN style="COLOR: maroon">"Section1").ReportObjects(<SPAN style="COLOR: maroon">"Field1").ObjectFormat.EnableSuppress = <SPAN style="COLOR: blue">True</EM></STRONG><SPAN style="COLOR: maroon"><SPAN style="COLOR: blue"><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="mso-tab-count: 1"><FONT size=3 face="Times New Roman"> </FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3 face="Times New Roman">Using <B style="mso-bidi-font-weight: normal">Report Definition</B> object, sections in a report can be accessible. Using <B style="mso-bidi-font-weight: normal">sections</B> report objects can be accessible. Report object contains all the fields in a section. <B style="mso-bidi-font-weight: normal">Object Format</B> contains all the properties available for the fields. </FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><FONT size=3><FONT face="Times New Roman"> <o:p></o:p></FONT></FONT></P>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3 face="Times New Roman">By above few lines of code a field in a report can be enabled or disabled.</FONT></P>
<H1 style="MARGIN: 12pt 0in 3pt"><A name=_Toc151185822><SPAN style="COLOR: #0066cc"><FONT face=Arial>References</FONT></A><SPAN style="COLOR: #0066cc"><o:p></o:p></H1>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt 0.25in" class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> <o:p></o:p></FONT></B></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l27 level1 lfo29" class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'"><A href="http://www.crystalreportsbook.com/CrystalReportsXI.asp"><SPAN style="mso-ansi-font-size: 12.0pt; mso-ascii-font-family: 'Book Antiqua'; mso-hansi-font-family: 'Book Antiqua'"><U><FONT size=3><FONT color=#004cd5>http://www.</FONT><FONT color=#ff0000><SPAN class=search-highlight>crystal</SPAN><SPAN class=search-highlight>reports</SPAN></FONT><FONT color=#004cd5>book.com/</FONT><FONT color=#ff0000><SPAN class=search-highlight>Crystal</SPAN><SPAN class=search-highlight>Reports</SPAN></FONT><FONT color=#004cd5>XI.asp</FONT></FONT></U></A><o:p></o:p></B>
<LI style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l27 level1 lfo29" class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'"><A href="http://support.businessobjects.com/communityCS/TechnicalPapers/crnet_exportandprintreport.pdf"><SPAN style="mso-ansi-font-size: 12.0pt; mso-ascii-font-family: 'Book Antiqua'; mso-hansi-font-family: 'Book Antiqua'"><U><FONT color=#004cd5 size=3>http://support.businessobjects.com/communityCS/TechnicalPapers/crnet_exportandprintreport.pdf</FONT></U></A><o:p></o:p></B>
<LI style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt; tab-stops: list .5in; mso-list: l27 level1 lfo29" class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'"><A href="http://support.businessobjects.com/communityCS/TechnicalPapers/cr_connection_advantages.pdf"><SPAN style="mso-ansi-font-size: 12.0pt; mso-ascii-font-family: 'Book Antiqua'; mso-hansi-font-family: 'Book Antiqua'"><U><FONT color=#004cd5 size=3>http://support.businessobjects.com/communityCS/TechnicalPapers/cr_connection_advantages.pdf</FONT></U></A><o:p></o:p></B></LI></OL>
<P style="TEXT-ALIGN: justify; MARGIN: 0in 0in 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 'Book Antiqua'"><FONT size=3> </FONT></B></P></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>