0
我是新來的c#,目前正在製作POS
應用程序女巫可以打印收據。我使用reportviewer組件創建收據。我正在工作。但我無法直接傳遞打印命令。當它是預覽我必須按Print Button manually.
,但我需要自動打印without a preview.
這裏是我的代碼的開始。有沒有什麼辦法與PrintDocument
或我怎麼能自動打印此reportviewer
綁定這個repotviewr
如何在沒有預覽的情況下打印Reportviewer
打開FormReceipt
DateTime thisDay = DateTime.Today;
FormReceipt frmReceipt = new FormReceipt(order, String.Format("{0:n}", totalAmmount), String.Format("{0:n}", paidammount), String.Format("{0:n}",change), thisDay.ToString("g"), discount.ToString());
frmReceipt.ShowDialog();
設置參數和綁定源
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
using Microsoft.Reporting.WinForms;
namespace Pos
{
public partial class FormReceipt : MetroFramework.Forms.MetroForm
{
List<Receipt> _list;
string _total, _cash, _change, _date, _user, _discount;
public FormReceipt(List<Receipt> datasource, string total,string cash, string change, string date, string discount)
{
InitializeComponent();
_list = datasource;
_total = total;
_cash = cash;
_change = change;
_date = date;
_user = Sessiondata.user;
_discount = discount;
}
private void FormReceipt_Load(object sender, EventArgs e)
{
ReceiptBindingSource.DataSource = _list;
Microsoft.Reporting.WinForms.ReportParameter[] para = new Microsoft.Reporting.WinForms.ReportParameter[]{
new Microsoft.Reporting.WinForms.ReportParameter("pTotal",_total),
new Microsoft.Reporting.WinForms.ReportParameter("pCash",_cash),
new Microsoft.Reporting.WinForms.ReportParameter("pChange",_change),
new Microsoft.Reporting.WinForms.ReportParameter("pDate",_date),
new Microsoft.Reporting.WinForms.ReportParameter("pUser",_user),
new Microsoft.Reporting.WinForms.ReportParameter("pItems",_list.Count.ToString()),
new Microsoft.Reporting.WinForms.ReportParameter("pDiscount",_discount+"%")
};
this.reportViewer1.LocalReport.SetParameters(para);
this.reportViewer1.RefreshReport();
}
private void reportViewer1_Load(object sender, EventArgs e)
{
}
}
}