Pergunta

I have written an application in c# and now i want to print its content in form of invoice as shown in figure i want to print costumer data only once but jobs he has asked to be performed on his car shown in datagrid view should be there in form of list with labour and total labour at the end of invoice. some people suggested to use crystal reports I have never used them so looking for a simpler solution cutting it short how can we print required values from formalt text

Foi útil?

Solução

The easiest and quickest solution is to use the Visual Basic PowerPack's PrintForm control (You can use it in C# projects as well).

http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx

Just drag the control on to your form then from code call

printForm1.Print();

This will print whatever is on the form, so just design your report on a form then call that code, and you're done.

Outras dicas

The last time I needed to print a few fields from a C# form, I simply created a Bitmap image using the "Bitmap" and "Graphics" object, and used "PrintDocument" to print it.

The layout of the printed report is done in code by specifying coordinates of the elements to be printed. It's cheap and dirty, but works.

You can use a local SSRS report (.rdlc extension). There should be a new item template under "Reporting" for creating the report. The report is displayed in Winforms using the Report viewer control (the control can also be used in a WPF application using a WindowsFormsHost). The only downside is a required dependency that must be installed with your application. Here is the redistributable package for the 2010 report viewer.

A plus is the report can easily be hosted in an SSRS instance if/when it will need to be viewed from a browser. The viewer can also render reports locally that are hosted in an SSRS instance.

There are plenty of guides online for using the report viewer depending on the data source to use for populating the report. The following example is using a generic list as the datasource. The "labels" in the new ReportDataSource line has to be the same as the name of the Dataset in the report definition. The properties of the generic object must also match the column names of the Dataset.

    public ReportViewer(IEnumerable<UnprocessedLabel> labels)
    {
        InitializeComponent();

        var reportViewer = new Microsoft.Reporting.WinForms.ReportViewer { ProcessingMode = ProcessingMode.Local };
        reportViewer.LocalReport.ReportPath = System.IO.Path.GetDirectoryName(Application.ResourceAssembly.Location) + "\\UnprocessedPalletLabel.rdlc";
        var ds = new ReportDataSource("labels", labels);
        reportViewer.LocalReport.DataSources.Add(ds);
        reportViewer.RefreshReport();
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top