Showing posts with label C# Crystal Report Tutorials. Show all posts
Showing posts with label C# Crystal Report Tutorials. Show all posts

Monday, February 8, 2016

C# Crystal Report Tutorial In Urdu - How to use Stored Procedure with Parameters In Crystal Report


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;
        }
    }
}

Thursday, February 4, 2016

C# Crystal Report Tutorial In Urdu - How to use Stored Procedure in Crystal Report


Code here

Form - Form1.cs code
using System;
using System.Windows.Forms;

namespace CrystalReportDemo2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ExitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void ShowReport1Button_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.LoadReport = @"Reports\Report1.rpt";
            reportForm.ShowDialog();
        }

        private void ShowReport2Button_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.LoadReport = @"Reports\Report2.rpt";
            reportForm.ShowDialog();
        }
    }
}
Form - ReportForm.cs code
using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace CrystalReportDemo2
{
    public partial class ReportForm : Form
    {
        public ReportForm()
        {
            InitializeComponent();
        }

        public string LoadReport { get; set; }

        private void ReportForm_Load(object sender, EventArgs e)
        {
            ShowReport(this.LoadReport);
        }

        private void ShowReport(string report)
        {
            ReportDocument rdoc = new ReportDocument();

            rdoc.Load(report);

            ReportCrystalReportViewer.ReportSource = rdoc;
        }
    }
}

Wednesday, February 3, 2016

C# Crystal Report Tutorial In Urdu - Basics (Create Crystal Report & use in your project)


Code here

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace CrystalReportDemo1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ShowReport();
        }

        private void ShowReport()
        {
            ReportDocument rdoc = new ReportDocument();

            //string appPath = Application.StartupPath;
            //string reportPath = @"Reports\Report.rpt";

            //string reportFullPath = Path.Combine(appPath, reportPath);


            // Or you can write the following code
            rdoc.Load(@"Reports\Report.rpt");

            crystalReportViewer1.ReportSource = rdoc;
        }
    }
}