Full Trust European Hosting

BLOG about Full Trust Hosting and Its Technology - Dedicated to European Windows Hosting Customer

Crystal Report Hosting - HostForLIFE :: Alternate Row Color in Crystal Report

clock August 31, 2021 08:58 by author Peter

Most of the time while developing reports people wonder how to have alternating row colors in the report like below.


There is a cool trick to it.
 

Go to the format section of the Details. Click the Color Tab. Then click the button next to the Background Color CheckBox.

In the formula editor of background color, type the following:



if RecordNumber mod 2 = 0 then crSilver else crNoColor.

Save and close the editor.
 
And now when you run the report you will see alternate colors of silver and white in the details section.



Crystal Report Hosting - HostForLIFE :: How to Print a Crystal Report Programmatically in ASP.NET?

clock August 6, 2021 08:42 by author Peter

You can print a Crystal Report using the print option of Crystal Report Viewer. However, there are occasions when you want your application to print a report directly to the printer without viewing the report in Crystal Report Viewer.
 

The ReportDocument class provides PrintToPrinter method that may be used to print a CR direct to the printer. If no printer is selected, the default printer will be used to send the printing pages to.
 
The PrintToPrinter method takes four parameters.
 
nCopies : Indicates the number of copies to print.
collated : Indicates whether to collate the pages.
startPageN : Indicates the first page to print.
endPageN : Indicates the last page to print.
 
The following steps will guide you to achieve the same:
    Add a crystal report (.cr) file to your ASP.NET application.
    Add a report instance on the page level.
        Dim report As MyReport = New MyReport

    Populate reports data on Page_Init
        ' Get data in a DataSet or DataTable  
          
        Dim ds As DataSet = GetData()  
        ' Fill report with the data  
        report.SetDataSource(ds)

    Print Report
        report.PrintToPrinter(1, False, 0, 0)


If you wish to print a certain page range, change the last two parameters From To page number.
 
If you want to set page margins, you need to create a PageMargin object and set PrintOptions of the ReportDocument.
 
The following code sets page margins and printer name:
    Dim margins As PageMargins =  Report.PrintOptions.PageMargins  
       margins.bottomMargin = 200  
       margins.leftMargin = 200  
       margins.rightMargin = 50  
       margins.topMargin = 100  
       Report.PrintOptions.ApplyPageMargins(margins)  
       
       ' Select the printer name  
       Report.PrintOptions.PrinterName = printerName



Crystal Report Hosting - HostForLIFE.eu :: BackgroundWorker and Crystal Reports

clock September 12, 2019 12:22 by author Peter

I have a DBClass that is responsible for executing database queries and SPs.


Here is the code snippet that shows how to use a background thread to get data and generate reports. This is useful when the main thread of your applications is doing something else, data entry and you want reports to be generated in the background.
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Threading; 
namespace myCryst 

    public partial class Form1 : Form 
    { 
        DataSet ds; 
        frmCryst f = new frmCryst(); 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e) 
        { 
            bgWorker.ReportProgress(10); 
            Thread.Sleep(164); 
            bgWorker.ReportProgress(20); 
            Thread.Sleep(164); 
            bgWorker.ReportProgress(30); 
            Thread.Sleep(164); 
            ds = DBClass.ExecQuery("select * from students"); 
            bgWorker.ReportProgress(40); 
            Thread.Sleep(164); 
            bgWorker.ReportProgress(50); 
            Thread.Sleep(164); 
            bgWorker.ReportProgress(70); 
            Thread.Sleep(164); 
            bgWorker.ReportProgress(95); 
            Thread.Sleep(164); 
            bgWorker.ReportProgress(100); 
        } 
        private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) 
        { 
            this.progressBar1.Value = e.ProgressPercentage; 
        } 
        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
        { 
            showCrystalReport(); 
        } 
        private void button1_Click(object sender, EventArgs e) 
        { 
            bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged); 
            bgWorker.WorkerReportsProgress = true; 
            bgWorker.RunWorkerAsync(); 
        } 
        private void showCrystalReport() 
        { 
            CrystalReport1 c = new CrystalReport1(); 
            Reportds d = new Reportds(); 
            d.Tables[0].Merge(ds.Tables["tab"]); 
            frmCryst f = new frmCryst(); 
            c.SetDataSource(d); 
            f.crystRep.ReportSource = c; 
            f.Show(); 
        } 
        private void button2_Click(object sender, EventArgs e) 
        { 
            Application.Exit(); 
        } 
    } 
}



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Tag cloud

Sign in