在 C 中使用 POS 打印机打印收据#

Print Receipt using POS printer in C#

提问人: 提问时间:11/13/2023 更新时间:11/13/2023 访问量:48

问:

您好,我有一个库存管理系统,可以在其中打印收据。

  1. 我无法将更多项目添加到要打印的列表中,因为工作表变成了 2 页,而结束部分转到下一页
  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);
        }


    }

以上是我的代码......我希望能够直接打印到打印机并显示打印对话框和选择

RDLC设计和尺寸设置的图像 Image of rdlc Page setup size

C# 打印 RDLC 销售点

评论

0赞 11/13/2023
我不知道怎么回事..我是新手..你能给我一些想法或代码吗,我应该在哪里更改它们,我提供的代码
0赞 jdweng 11/13/2023
检查设备管理器中是否有为打印机安装的驱动程序。
0赞 11/13/2023
检查我安装了打印机附带的驱动程序,但打印即将到来,我需要正确设置代码中的尺寸。这就是我需要帮助的地方
0赞 jdweng 11/14/2023
纸张尺寸有哪些选项?除了自定义,还有滚动选项吗?尝试下载最新的打印机驱动程序。较旧的驱动程序中可能存在错误。
0赞 11/14/2023
是的,我使用的是 80 毫米热敏纸卷

答: 暂无答案