简体   繁体   English

打印发票C#Winforms

[英]Print Invoice C# Winforms

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. 我已经在c#中编写了一个应用程序,现在我想以发票的形式打印其内容,如图所示我想只打印一次客户数据,但他要求在他的汽车上执行的数据网格视图中显示的工作应该在那里发票末尾有劳动力和总劳动力的清单。 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 form 有些人建议使用水晶报告,我从来没有使用它们,所以寻找一个更简单的解决方案,简化它如何从表格中打印所需的值 替代文字

The easiest and quickest solution is to use the Visual Basic PowerPack's PrintForm control (You can use it in C# projects as well). 最简单,最快捷的解决方案是使用Visual Basic PowerPack的PrintForm控件(您也可以在C#项目中使用它)。

http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx 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. 这将打印表单上的任何内容,因此只需在表单上设计您的报表然后调用该代码,您就完成了。

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. 我最后一次需要从C#表单打印几个字段时,我只是使用“Bitmap”和“Graphics”对象创建了一个Bitmap图像,并使用“PrintDocument”来打印它。

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). 您可以使用本地SSRS报告(.rdlc扩展名)。 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). 报告使用报告查看器控件显示在Winforms中(该控件也可以在使用WindowsFormsHost的WPF应用程序中使用)。 The only downside is a required dependency that must be installed with your application. 唯一的缺点是必须与您的应用程序一起安装的必需依赖项。 Here is the redistributable package for the 2010 report viewer. 以下是2010年报告查看器的可再发行组件包。

A plus is the report can easily be hosted in an SSRS instance if/when it will need to be viewed from a browser. 如果需要从浏览器查看报告,则可以轻松地在SSRS实例中托管报告。 The viewer can also render reports locally that are hosted in an SSRS instance. 查看器还可以在本地呈现SSRS实例中托管的报告。

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. 新ReportDataSource行中的“标签”必须与报表定义中的数据集名称相同。 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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM