如何在Winform应用程序中生成产品收据? [英] How to generate product receipt in winform application?

查看:104
本文介绍了如何在Winform应用程序中生成产品收据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用Winform应用程序,我有一个gridview,其中包含用户已购买的产品列表。

I am working on a winform application for the first time and I have a gridview which contains a list of products users have bought.

我的打印按钮位于单击该按钮,用户可以生成类似于以下的收据:

I have a Print button on click which allows the user to generate a receipt like the one below:

因此,我在这里感到困惑,是应该使用 winform默认RDLC还是Crystal Report,还是应该生成PDF,然后将其打印出来作为收据,但是我不确定PDF是否适合用于

So here I am confused whether I should use "winform default RDLC or Crystal Report" or whether I should generate PDF and then let it print out as receipt, but I am not sure if PDF is a good option for receipt generation or not.

对于Crystal Report,我读到我需要安装它,而客户端(将使用此桌面应用程序的客户端)必须安装Crystal Report,并且

For Crystal Report, I have read that I need to install it and client (who will use this desktop application) had to install Crystal Report and also there is some licensing involve with Crystal Report which I don't want.

另外,如果我使用Crystal Report,则不确定是否可能。 e生成的收据正好在上面(使用表格格式),会很复杂吗?

Also if I use Crystal Report then I am not sure if it would be possible to generate exactly above receipt (with table formatting) and will it be complicated?

收据有点复杂,是否有更好的工具或方法,或者我应该如何生成我在上图中显示的收据?

Receipt is bit complicated so is there a better tool or way, or how should I generate receipt I have shown in above image?

更新: 打印纸的总大小为:7.50厘米,用户希望在中心打印所有内容。

Update : Printing paper total size is : 7.50 centimeter and user wants to print all the content in center.

Discount = FinalAmount - MRP;

输入客户名称,手机号码,账单号码,付款方式

我有一个Excel文件,其中包含产品列表,并且对于每个产品,我都有类似 ProductId,ProductName,MRP,税务信息,例如CGST,SGST

I am having a Excel file which contains list of products and with each products I have information like ProductId,ProductName,MRP,Tax information like CGST,SGST.

根据产品ID从excel文件填充gridview的代码:

 using (OleDbConnection cnnxls = new OleDbConnection(strConn))
                    using (OleDbDataAdapter oda = new OleDbDataAdapter(query, cnnxls))
                    {
                        oda.Fill(dtProductList);
                        DataColumnCollection columns = dtProductList.Columns;
                        if (!columns.Contains("FinalAmount"))
                        {
                            dtProductList.Columns.Add(new DataColumn() { ColumnName = "FinalAmount", DataType = typeof(decimal) });
                        }

                        if (!columns.Contains("Quantity"))
                        {
                            dtProductList.Columns.Add(new DataColumn() { ColumnName = "Quantity", DataType = typeof(int) });
                        }
                        DataRow lastRow = dtProductList.Rows[dtProductList.Rows.Count - 1];
                        lastRow["FinalAmount"] = Convert.ToDecimal(lastRow["MRP"]);
                        lastRow["Quantity"] = 1;
                    }

推荐答案

生成并打印收据

您可以使用任何报表设计器工具(如RDLC报表或Crystal报表)生成报表。 RDLC报告足够好。您可以在不显示打印对话框的情况下打印RDLC报告。您也可以轻松地手动或使用代码导出RDLC报告

You can use any report designer tool like RDLC Reports or Crystal Reports to generate a report. RDLC reports are good enough. You can print the RDLC report with or without showing the print dialog. You can also easily export the RDLC report manually or using the code.

如果出于任何原因您不想使用报告工具,则可以考虑使用运行轻松生成HTML报告T4模板

If for any reason you don't want to use a reporting tool, as another option you can consider generating HTML report easily using Run-time T4 templates.

使用RDLC报告,如何在单个单元格中显示多个字段

您可以轻松地使用表达式在单个单元格中显示多个值。另外,您也可以在单个行组中使用行,并在单个列中显示不同的字段。

You can easily use an expression to show multiple values in a single cell. Also as another option, you can use rows in a single row group and show different fields in a single column.

示例1-RDLC-在使用表达式的单个列

以下步骤显示了如何使用表达式在单个列中显示多个字段。我假设您已经设置了数据源,并具有 ProductName UnitPrice Quantity 字段。然后,请按照下列步骤操作:

The following steps show you how you can display multiple fields in a single column using expression. I assume you have set up the data source and have ProductName, UnitPrice and Quantity fields. Then, follow these steps:


  1. 从报表设计的工具箱中删除

  2. 在第一列第一数据行(而不是标题行)中,右键单击并选择 ProductName 图片

  3. 选择第二列的标题并输入单价/数量图像

  4. 在第二列第一数据行中,右键单击并选择 Expression 。 (图像

  5. 在在表达式窗口中,输入所需的表达式,例如:

  1. Drop a Table from toolbox on the report design surface.
  2. In first column, first data row (not the header row), right click and choose ProductName (image)
  3. Select the header of the second column and type UnitPrice/Quantity (image)
  4. In second column, first data row, right click and choose Expression. (image)
  5. In the expression window, enter the desired expression, for example:

= UnitPrice:& Field!UnitPrice.Value.ToString()&系统。环境。新行数量:和字段!Quantity.Value.ToString()

示例2-RDLC -使用行组在单个列中显示多个字段

以下步骤向您展示了如何在单个列中显示多个字段。我假设您已经设置了数据源,并具有 ProductName UnitPrice Quantity 字段。然后,请按照下列步骤操作:

The following steps show you how you can display multiple fields in a single column. I assume you have set up the data source and have ProductName, UnitPrice and Quantity fields. Then, follow these steps:


  1. 从报表设计的工具箱中删除

  2. 在第一列第一数据行(而不是标题行)中,右键单击并选择 ProductName 图片

  3. 选择第二列的标题并输入单价/数量图像

  4. 右键单击第一个数据行的行标题,然后选择插入行内部组-下方图像

  5. 在第二列第一行数据中,右键单击并选择 UnitPrice 。 (图像

  6. 点击 [UnitPrice] ,然后按 Home 并键入 UnitPrice:图片

  7. 在下一行中对数量执行相同的操作

  8. 如果组中需要另一行,请重复步骤3。
    您可以通过选择单元格并设置来设置单元格的边框。 BorderStyle 分别用于顶部,左侧,底部和右侧。

  1. Drop a Table from toolbox on the report design surface.
  2. In first column, first data row (not the header row), right click and choose ProductName (image)
  3. Select the header of the second column and type UnitPrice/Quantity (image)
  4. Right click on row header of the first data row and choose Insert RowInside Group - Below (image)
  5. In second column, first data row, right click and choose UnitPrice. (image)
  6. Click on the [UnitPrice], and then press Home and type UnitPrice: (image)
  7. Do the same for Quantity, in the next row in the group.
  8. If you need another row in the group, repeat step 3. You can setup borders of the cells by selecting them and setting BorderStyle individually for top, left, bottom and right.

下载

您可以在此处使用表达式克隆或下载示例:

You can clone or download an example using expression here:

  • repository
  • zip file

这篇关于如何在Winform应用程序中生成产品收据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆