0% found this document useful (0 votes)
12 views

UNIT5 User Control Crystal Report Setup Project

The document provides a comprehensive guide on creating and using User Controls in C#, highlighting their advantages such as code reusability and time-saving. It also covers the steps to create a User Control, add properties, methods, and events, and details the process of integrating Crystal Reports for generating various types of reports. Additionally, it explains the structure of Crystal Reports and the use of formulas and summary fields for enhanced reporting capabilities.

Uploaded by

vivekkanet11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

UNIT5 User Control Crystal Report Setup Project

The document provides a comprehensive guide on creating and using User Controls in C#, highlighting their advantages such as code reusability and time-saving. It also covers the steps to create a User Control, add properties, methods, and events, and details the process of integrating Crystal Reports for generating various types of reports. Additionally, it explains the structure of Crystal Reports and the use of formulas and summary fields for enhanced reporting capabilities.

Uploaded by

vivekkanet11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Programming With C# BCA/IT- 4th SSSDIIT

Q.1 Steps to create a USER CONTROL and using user control in


windows project as components.
Why we make User control?

This Provide additional re-use flexibility with large scale web project. It’s also help to
find bug and resolve bug in short time.
If you want some changes in your code then you have to write code at one place (user
control) that effect in every web form or every Form of window application.
Using this technique you can save your extra effort and also save your time.

Adding a Property to user control

The above steps are making a one user control now we can add a property of that
control using get and set method.
Syntax

public <data type> < property name>


{
get
{
// return value who is read-only
}
set
{
// set value who is write-only
}
}

Example

class Number
{
private int number;
public int Anumber // Property
{
get
{
return number;
}
set
{
number = value;
1
}
}
}

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
Adding a method to user control
We can got a manual method to the particular user control using write a simple method
in user control’s code window
Example

public void show()


{
MessageBox.Show("Hello AvadhTutor");
}

After writing method we can use that method like other methods in our windows form.

Adding event to user control

Just like a method we can also add an event to user control using EventHandler class.
Example

public void addevent()


{
txtname.Click += new EventHandler(OnClick);
}
public void OnClick(object sender, EventArgs e)
{
MessageBox.Show("AVADHTUTOR : This is the click event");
}

Q.2 User control Complete Steps

Creating a New User Control

The following is the procedure for creating a new User Control.

1. Create a new Windows Forms Control Library project from the list of templates
available and name it "TimerTickControl".

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

2. The following screen will appear for designing our control:

3
3. Add a label control to your form and name it "lblTimerTick" and clear its Text
Property.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

4. Now to add an Icon to the control we will add an image to the project by right-clicking
the project then select "Add" -> "Existing Item" then select the image then select "Set it
Build Action" -> "Embedded Resource" from the Properties.
5. Rename "UserControl1.cs" to "TimerTick.cs".

6. To add an Icon to the control use the ToolboxBitmap attribute to provide your
Control a visual appearance.

namespace TimerTickControl
{
[ToolboxBitmap(@"D:\CSharp Project
AvadhTutor\TimerTickControl\TimerTickControl\LiveTimer.bmp")]
public partial class TimerTick : UserControl
{
public TimerTick()
{
InitializeComponent();
}
}
}

7. Add a Timer Component to your project and set its Enabled Property to "True" and
the Interval to "1000".

8. In the Timer_Tick Event add the following code:


4
The following is the complete code:

using System;

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace TimerTickControl
{
[ToolboxBitmap(@"D:\CSharp Project
AvadhTutor\TimerTickControl\TimerTickControl\LiveTimer.bmp")]
public partial class TimerTick : UserControl
{
public TimerTick()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
lblTimerTick.Text = DateTime.Now.ToString();
}
}}

9. Build the solution. You can locate the Path at "\bin\debug\".

 using user control in windows project as components.


10. Now let us try to add the control to the project. Create a new Windows Application Project .

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

11. Now add a reference ("Project" - > "Add Reference") to the DLL by locating it from the Path where it is.
Now the DLL has been added to your project.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
12. Let us add the control to our Toolbox. Add a new tab in control box (here I named it "MyControls").

13. Right-Click on the "My Controls" Tab and select "Choose Items". The following dialog appears:

7
14. Now click "Browse" and select the DLL, the control with the icon is displayed as shown here:

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

15. Click "OK" to add the control to the Toolbox. That is, our control is ready to be added to the project.

16. Now try adding the control to the project by double-clicking on it.

17. Once the control has been added, it will show a running timer text in the control.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

Advantage of using User control

 Code re-usability.
 Time saving.
 Less effort.
 Easy to find Bug and fix it.
 Save memory also.

Q.3 Creating Crystal Reports:


Crystal Report is a Reporting Application that can generate reports from various Data
Sources like Databases , XML files etc.. The Visual Studio.NET Integrated Development
Environment comes with Crystal Reports tools.

The Crystal Reports makes it easy to create simple reports, and also has comprehensive
tools that you need to produce complex or specialized reports in csharp and other
programming languages.

Crystal Reports step by step

Copy and paste the following source code and run your C# project.

Step 1

Create a table in the database. Create a table in the database.

Step 2

Go to the Solution Explorer and right-click on your project name and select

Add -> New Item ->Crystal Report.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

Step 3 Now create a new crystal report document as using the report wizard and
choose an expert Standard. You can see in below figure.

Then Click the Ok Button.

Step 4

From project data ADO.Net DataSet select datatable1 Click the next Button.
10

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

Step 5

Then click on next

Step 6

11 Then click on next button

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

Step 7

Now finally display your report in this format.

12 Step 8

Now add a new .aspx page to display the report

Step 9

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
Now add a Crystal Report Viewer to .aspx then write the report code in the .aspx.cs page

Step 10

Finally run your report and display the Information.

Types of Reports

you can create the following types of reports:


1. Parameterized reports
2. Linked reports
3. Snapshot reports
4. Cached reports
5. Drilldown reports
6. Drill through reports
7. Sub reports
8. Crosstab report.

1. Parameterized reports:-
Parameters reports are the reports which accept parameters to complete the report.

2. Linked reports:-
The linked report is Report Server-side item which provides a link to an existing report on
the server.

3. Snapshot reports:-
Snapshot report is a pre-executed report that contains layout information and query results
that were retrieved at a specific point in time.

4. Cached reports:-
Cached reports are saved for a copy of the processed reports.
13
5. Drilldown reports:-
Drill Down Reports in SSR allowing Users to Show or Hide the Column Data by providing
plus and minus symbols on a text box.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
6. Drillthrough reports:-
The drill-through report is reporting that is open by clicking a link within another report.

7. Subreports:-
SubReport data can be used to display another report in the Main report.

8. CrossTab report:-
A crosstab report provides a different view of data by showing values at the intersection
points of rows and columns. In the Create a Crosstab Report sample, the returned items
appear by Product line, and by Order method.

Q.4 The different sections of a Crystal report

1. Report Header

This section is typically used for the report title and other information you want
to appear at the beginning of the report. It can also be used for charts and cross-
tabs that include data for the entire report.

2. Page Header

This section is typically used for information that you want to appear at the top
of each page. This can include such things as chapter names, the name of the
document, and other similar information. This section can also be used to display
14 field titles above the fields on a report.

3. Details

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
This section is used for the body of the report, and is printed once per record.
The bulk of the report data typically appears in this section.

4. Report Footer

This section is used for information you want to appear only once at the end of
the report (such as grand totals) and for charts and cross-tabs that include data
for the entire report.

5. Page Footer

This section typically contains the page number and any other information you
want to appear on the bottom of each page.

If a group, summary, or subtotal is added to the report, the program creates two
additional sections:

1. Group Header

This section typically holds the group name field, and can be used to display
charts or cross-tabs that include data specific to the group. It is printed once at
the beginning of a group.

2. Group Footer

This section typically holds the summary value, if any, and can be used to display
charts or cross-tabs. It is printed once at the end of a group.
When a group, summary, or subtotal is added, the Group Header area appears
directly above the Details area and the Group Footer area appears directly below
the Details area.

Crystal Reports Formula Field:

Formulas are used to insert data in the report that does not exist with any of the objects. If there
is a need to perform some calculations or to add specialized data in the report, you can use
formulas.

Example − (Emp_details.sal) * 0.15

Common formulas are − Calculations, string functions like UPPERCASE, date functions,
etc.

15 Formula contains two parts in the report −

 Syntax
 Components

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
Syntax is the rules that you follow to organize the components.

The components are used to create formulas.

Crystal Reports has the following types of formulas − Report formulas and conditional
formatting formulas.

Report formulas are used as standalone in a report. Conditional formatting formulas


define the condition on which report formulas are applied.

The situations when formula field is using :

If you have a Crystal Reports with Qty and Price fields and you need an additional field
in your Crystal Reports for Total, that is TOTAL = QTY X PRICE . In these types of
situations you can use the Formula Field in Crystal Reports.

After you create the above Crystal Reports, your CR designer screen is look like the
following picture :

Next step is to create a Formula Field for showing the result of Qty X Price .

Right Click the Formula Field in the Field Explorer and click New. Then you will get an
Input Message Box , type Total in textbox and click Use Editor.

16

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
Now you can see the Formula Editor screen . Here you can enter which formula you
want . Here we want the result of Qty X Price . For that we select OrderDetails.Qty , the
multipy operator (*) and Product.Price . Double click each field for selection.

Now you can see Total Under the Formula Field . Drag the field in to the Crystal Reports
where you want to display Total.

Now the designing part is over and the next step is to call the Crystal Reports in C# and
view it in Crystal Reports Viewer control .

17

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
When you run this program you will get your screen like the following picture.

Summary field in a Crystal report

A summary field can be used to sum, count, and find the maximum/minimum of a
field.

In the Crystal Reports designer view window, right click on the Report Footer , just
below the Total field and select Insert -> Summary .

Then you will get a screen , select the Total from the combo box and select Sum from
next Combo Box , and summary location Grand Total (Report Footer) . Click Ok button

18

Now you can see @Total is just below the Total field in the report Footer.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

When you run this program your screen will look like the following picture.

The Special Field Object in Crystal report

The Special Field object is used for printing all report-related information. For example,
it can print the current page number or the total number of pages. This field was created
as a catch-all for all the miscellaneous types of report information that you need. Table
2-3 lists the available fields and what they mean

Special Field Description


DataDate The date when the report was last refreshed.
DataTime The time when the report was last refreshed.
FileAuthor The file author that is stored with the report.
FileCreationDate The date when the report was created.
Filename The report’s file name.
GroupNumber The current group number.
GroupSelection The group selection formula.
ModificationDate The date the report was last modified.
ModificationTime The time the report was last modified.
PageNofM Prints “Page X of Y”.
PageNumber The current page number.
PrintDate The date the report was printed.
PrintTime The time the report was printed.
RecordNumber The current record number.
RecordSelection The record selection formula.
ReportComments The report comments that are stored with the report.
ReportTitle The report title.
TotalPageCount The total number of pages.

 Create a Set up Project

To create the setup I will use the following 2 steps:


1. Create a Windows Forms application
2. Create a setup and deployment project.
19
Step 1

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
a. Create a Windows Forms application named
"WindowsFormsApplication1".
With simple MessageBox like

Step 2

a. Right-click on the solution and choose "Add" -> "New Project" to add a new setup
project.

Create a "Select project" named "Setup1" from the "Other Project Types -> Visual Studio
installer".

20
Step 3: Select here Setup and Deployment in the left side bar in project types.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

Here we find three options as following:

1. Application Folder
2. User's Desktop
3. User's Program Menu

Step 4: These three options are the three places where we want to copy our setup fules during the
installation process. From here we have to select one option. Suppose I select User's Desktop. Then Right
click on User's Desktop option and select Add-> Project Output. The window will look like as.

Step 5: After clicking on Project Output, a new window will open. Here we select first four options. Now
click on OK.

21

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT
Step 6: After clicking on OK, Rebuild the Setup from Build option in Menu bar like as.

Step 7: After this, let's test our setup by going right clicing on the setup project in
Solution Explorer and click on Install menu item.

Step 8: After copmpleting the installation go on desktop there you will find all files you
have included in the setup on the desktop.

 Types of setup Projects:


o Creating setup projects
 File System Editor
22
 User Interface Editor
 Launch Condition Editor

Setup Projects can work with three different editor as above.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

1. File System Editor:-


Some programs produce and consume specific file types.
You can specify the file types that your program works with; doing so creates a
Windows file association for your file extension with your program.
You can right-click, select View, File Types to see the File Types Editor. Then, right-click
on File Types and select Add File Type.
At this point, you can give the file type a name and then open the Properties window and
specify the file extension.
After you’ve done this, ensure your application handles the args parameter in Main to
open and work with any file that is selected in Windows.

2. User Interface Editor:-


To configure the user interface, right-click the setup project, select View, User Interface.
Each of the User Interface windows has a BannerBitmap property in the Properties
window where you can set the image that appears at the top of the Setup Wizard for
your application.
You have some options for the user interface, but they’re limited in that you can add
only window types that are available via the setup project.
You can right-click the User Interface tree and select Add Dialog to bring up the window.
You have several options to add new windows.
3. Launch Condition Editor:-
A launch condition allows you to ensure that a specific file, registry entry, or application
is installed on the target machine prior to installation.
For example, if you have an application that communicates with Microsoft Excel, you
could add a launch condition that ensures the version of Excel you need is already
installed.
You can also configure the condition to display the error message you want if Excel isn’t
there.
23 The program won’t install if your launch conditions aren’t met.
To configure a launch condition, right-click the setup project and select View, Launch
Condition.

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor


Programming With C# BCA/IT- 4th SSSDIIT

Learn All Programming From


Youtube.com/avadhtutor

C Sharp All Videos


https://www.youtube.com/watch?v=YoA-D_tkVbo&list=PLkx9f4H3tJMLLOfG81ywgpTEJqEg-
sXlz

Blog
pandyaripal.blogspot.com

instagram
instagram.com/avadhtutor

24

Prepared By: Ripal Pandya | Instagram.com/avadhtutor | youtube.com/avadhtutor

You might also like