提问人: 提问时间:11/13/2023 更新时间:11/13/2023 访问量:48
在 C 中使用 POS 打印机打印收据#
Print Receipt using POS printer in C#
问:
您好,我有一个库存管理系统,可以在其中打印收据。
- 我无法将更多项目添加到要打印的列表中,因为工作表变成了 2 页,而结束部分转到下一页
- 我的宽度是 3 英寸,高度可以根据内容而有所不同 .my 打印机名称是 XP-365b 3.是的,我安装了80c驱动程序用于收据打印
我在下面附上一些我的图片 1.RDLC报表设置 2.代码
public partial class frmReceipt : Form
{
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
DBConnection dbcon = new DBConnection();
SqlDataReader dr;
string store = "";
string address = "";
string mobile = "";
frmPOS f;
public frmReceipt(frmPOS frm)
{
InitializeComponent();
cn = new SqlConnection(dbcon.MyConnection());
f = frm;
this.KeyPreview = true;
// Fetch store and address values from the database
FetchStoreAndAddress();
// Now, you can use the 'store' and 'address' variables in your form.
}
private void frmReceipt_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
private void FetchStoreAndAddress()
{
cn.Open();
cm = new SqlCommand("SELECT store, address, mobile FROM tblStore", cn);
dr = cm.ExecuteReader();
if (dr.Read())
{
store = dr["store"].ToString();
address = dr["address"].ToString();
mobile = dr["mobile"].ToString();
}
dr.Close();
cn.Close();
}
public void LoadReport(string pcash, string pchange, string pdiscall, string ptype)
{
ReportDataSource rptDataSource;
try
{
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\Report1.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
DataSet1 ds = new DataSet1();
SqlDataAdapter da = new SqlDataAdapter();
cn.Open();
da.SelectCommand = new SqlCommand("Select c.id, c.transno, c.pcode, c.price, c.qty, c.disc, c.total, c.sdate, c.status, p.pdesc from tblCart as c inner join tblProduct as p on p.pcode = c.pcode where transno like '" + f.lblTransno.Text + "'", cn);
da.Fill(ds.Tables["dtSold"]);
cn.Close();
ReportParameter pDiscount = new ReportParameter("pDiscount", f.lblDiscount.Text);
ReportParameter pTotal = new ReportParameter("pTotal", f.lblTotal.Text);
ReportParameter pCash = new ReportParameter("pCash", pcash);
ReportParameter pChange = new ReportParameter("pChange", pchange);
ReportParameter pStore = new ReportParameter("pStore", store);
ReportParameter pAddress = new ReportParameter("pAddress", address);
ReportParameter pMobile = new ReportParameter("pMobile", mobile);
ReportParameter pTransaction = new ReportParameter("pTransaction", "Invoice #: " + f.lblTransno.Text);
ReportParameter pCashier = new ReportParameter("pCashier", f.lblUser.Text);
ReportParameter pShopcode = new ReportParameter("pShopcode", f.cboShopCode.Text);
ReportParameter pDiscall = new ReportParameter("pDiscall", pdiscall);
ReportParameter pType = new ReportParameter("pType", ptype);
reportViewer1.LocalReport.SetParameters(pDiscount);
reportViewer1.LocalReport.SetParameters(pTotal);
reportViewer1.LocalReport.SetParameters(pCash);
reportViewer1.LocalReport.SetParameters(pChange);
reportViewer1.LocalReport.SetParameters(pStore);
reportViewer1.LocalReport.SetParameters(pAddress);
reportViewer1.LocalReport.SetParameters(pMobile);
reportViewer1.LocalReport.SetParameters(pTransaction);
reportViewer1.LocalReport.SetParameters(pCashier);
reportViewer1.LocalReport.SetParameters(pShopcode);
reportViewer1.LocalReport.SetParameters(pDiscall);
reportViewer1.LocalReport.SetParameters(pType);
rptDataSource = new ReportDataSource("DataSet1", ds.Tables["dtSold"]);
reportViewer1.LocalReport.DataSources.Add(rptDataSource);
reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
reportViewer1.ZoomMode = ZoomMode.Percent;
reportViewer1.ZoomPercent = 100;
// Print the report
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message);
}
}
以上是我的代码......我希望能够直接打印到打印机并显示打印对话框和选择
答: 暂无答案
评论