Crystal

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Crystal as PDF for free.

More details

  • Words: 1,003
  • Pages: 8
Step 1 :To open the crystal report document, Right Click on your project. Select Add -> Add New Item. New window will appear as below. Give Name to your report.

Step 2:After clicking Open u will see another window giving you options how do you want to create the report, using Report Expert or from Blank Report or from an existing report. Here I am selecting second option i.e. As a Blank Report. Now your Crystal Report Document will get opened. On the left hand side there you will see Field Explorer from where you can interact with database. (If Field Explorer is not there then to open it you can use shortcut key Ctrl + Alt + T) Step 3:Now to select database, (My Database is stored in SQL Server 2000) Right Click on Database Fields in Field Explorer. Select Add/Remove Database -> OLEDB(ADO) ->Make New Connection -> Microsoft OLE DB Provider for SQL Server (As I am using SQL Server 2000). Click on Next and give your connection Information, Click on Next and then Click on Finish.

Now you can add your table/s, view/s which you required for the Report. The window looks like this.

Step 4: Now in your Field Explorer you can see your chosen Table/View. Drag the Fields you want to show in the report in Details Section. The screen will appear as follows.

The fields in Details section are Field Objects and the fields in Page Header, Report Header are Text Objects. Step 5:Now to show this report, Take a form & add a CrystalReportViewer to it.(Just drag CrystalReportViewer from Tool box on the form). For crystal reports add name spaces are important using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine; (Here I am showing report on Page Load, same code can be written on Button Click if wanted.) Now even if we have connected database to report but if we changed database then it is not feasible to create new crystal reports again & again so we can use TableLogOnInfo to connect report to Database programmatically.

Create Object of that as private TableLogOnInfo LogInfo = new TableLogOnInfo(); The function can be written as

private void SetLogonInfo() { try { LogInfo.ConnectionInfo.ServerName=”SerVerName”; LogInfo.ConnectionInfo.UserID=”sa”; LogInfo.ConnectionInfo.Password=”ok” LogInfo.ConnectionInfo.DatabaseName=”CrystalSample”;

}

} catch(Exception ex) { MessageBox.Show(ex.Message); }

Now we need to create object of the report. There are various ways to show report. a) Create one object of Report Document that can be use to every report which are going to be shown on that CrystalreportViewer can be created as ReportDocument O_Report=new ReportDocument(); We can use this object to every report and need to give path while loading the report.as O_Report.Load(@"E:\CrytstalSample\rptShowList.rpt"); b) Create different objects for different reports as rptShowList O_showList = new rptShowList(); (Here I am using second option). Make DataBase Connection as O_Report1.Database.Tables[0].ApplyLogOnInfo(LogInfo); Step 6:Now I want to show AddressList of the users whose number is greater than 15. For that I will fill DataTable with these records and then attach it to the report. DataTable DT = new DataTable(); try { string CmdStr=""; CmdStr = “Select * from Vw_AddressList where User_Number>15”; Connection.Open(); SqlDataAdapter Adpt=new SqlDataAdapter(CmdStr,Connection); DT.Clear(); Adpt.Fill(DT); } catch(Exception ex) { MessageBox.Show(ex.Message); }

finally { Connection.Close(); } Step 7:Now set the above filled DataTable as Reports dataSource. O_showlist.Database.Tables[0].SetDataSource(DT); Step 8: Set the report as crystal report viewer report source to bind report to viewer. CryStalReportViewer1.ReportSource = O_Report1111; CryStalReportViewer1.Zoom(1); How to Change the properties of Fields on report programmatically. The Fields on the Detail section,Formula Fields,group Name Fields are the FieldObjects. We can change it’s properties like font,size programmatically. Get the name from the properties window & create object of that field.get the section number & change it’s properties. e.g. In the above Report User Number and user Streetasddress are the field objects. We can change there properties as FieldObject fUserNumber = FieldObject)o_showlist.Sections3.ReportObjects["Field1"]; fFullName1.ApplyFont(new Font(Arial,8.25F)); Same can be done with Text Object. We can change properties of Formula Field in different way also. O_showlist.DataDefinition.FormulaFields["Header"].Text = “Address List”; Formula Fields:Here I will just give sample of how to use formula field. It’s out of scope to give whole Formula Field Description. In my database I have stored Gender field as “M” or “F” but in report I want to show it as “Male”, “Female” etc. • Right Click on Formula Field -> New • Give Formula Name. The Formula Editor screen will appear as follows-

The left side Section contains database fields there we on which field we want to write formula. Middle section Functions. We can apply different types of functions to Right section is of Operators where we use operators in Now I have written code as – if({Vw_AddressList.Gender})= 'M' then 'Male' else 'Female'

Deploying the Crystal Report Dot Net Application: Step 1:- Right click on Solution -> Add New Project

Select SetUp and Deployment Projects -> Setup Project. Give name to your Setup. Step 2:- To add Exe and other files-

can select is formula. The formula.

In File System, Right click on Appllication Folder (It creates folder at Win/Sys path generally) -> Add -> Project Output -> select Primary output & other needed files. Up to this is general Deployment process. If your application includes Crystal Reports you need to do some extra. a) Adding Merge Module:• Right Click on Setup project -> Add -> Merge Module • Select ‘Crystal_regwiz2003.msm’, Crystal_Managed2003.msm, Crystal_Database_Access2003_enu.msm, •

Crystal_Managed2003.msm Click on Open.

b) Now important thing is that When you run this Set up on another sytem it will give you error of “Keycode32.Dll” The error is due to not giving Registration key to Merge Module File ‘ ‘Crystal_regwiz2003.msm’ To do that Right Click on

‘Crystal_regwiz2003.msm’ and select Properties. In properties select ‘(MergeModuleProperties)’ -> Enter your key at ‘License Key‘. Now the License key can be your Crystal Report product key or you can get it from, Help(Menu of dot net) -> About Microsoft Development Environment. There you will see the string “Crystal Reports for Visual Studio .NET AAP50-GS00000-U7000RN“(can be different for different versions).Your key is 'AAP50-GS00000-U7000RN'. Now build the solution & your set up is ready.

Related Documents

Crystal
June 2020 26
Crystal
November 2019 47
Crystal Callans
April 2020 7
Crystal Structure
June 2020 7
Crystal Treasure
June 2020 15
Sw208js Crystal
August 2019 27