Code here
Form - MainForm.cs code
using System;
using System.Windows.Forms;
namespace CrystalReportDemo5
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public enum RegistrationTypes
{
Online = 1,
InPerson = 2,
ByPhone = 3,
Email = 4,
ByPost = 5
}
private void ExitButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void ShowReportButton_Click(object sender, EventArgs e)
{
ReportForm reportForm = new ReportForm();
reportForm.RegistrationType = GetRegistrationType();
reportForm.ShowDialog();
}
private int GetRegistrationType()
{
if (OnlineRadioButton.Checked)
{
return (int)RegistrationTypes.Online;
}
if (InPersonRadioButton.Checked)
{
return (int)RegistrationTypes.InPerson;
}
if (ByPhoneRadioButton.Checked)
{
return (int)RegistrationTypes.ByPhone;
}
if (EmailRadioButton.Checked)
{
return (int)RegistrationTypes.Email;
}
if (ByPostRadioButton.Checked)
{
return (int)RegistrationTypes.ByPost;
}
return 0;
}
}
}
Form - ReportForm.cs code
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
namespace CrystalReportDemo5
{
public partial class ReportForm : Form
{
public ReportForm()
{
InitializeComponent();
}
public int RegistrationType { get; set; }
private void ReportForm_Load(object sender, EventArgs e)
{
DataTable dtReportData = GetData();
ShowReport(dtReportData);
}
private void ShowReport(DataTable dtReportData)
{
CrystalReptViewer.SelectionMode = CrystalDecisions.Windows.Forms.SelectionMode.None;
ReportDocument rdoc = new ReportDocument();
rdoc.Load(@"Reports\Report1.rpt");
rdoc.SetDataSource(dtReportData);
CrystalReptViewer.ReportSource = rdoc;
}
private DataTable GetData()
{
DataTable dtData = new DataTable();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbx"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_ReportShowStudentsByRegistrationType", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
cmd.Parameters.AddWithValue("@RegistrationType", this.RegistrationType);
SqlDataReader reader = cmd.ExecuteReader();
dtData.Load(reader);
}
}
return dtData;
}
}
}