c# - 销售点申请收据打印

标签 c# point-of-sale

我正在开发一个零售管理软件的小项目,该项目将使用 POS 打印机(我想这就是我们所说的)。我最终需要为其创建一个账单。但我被困在这里,无法继续。因此,假设如果我以适当尺寸(POS 账单宽度)的单独表格生成账单,我是否能够正确打印它? 我正在使用 C# 和 .NET 4.0 框架。我对POS机了解不多。我正在为一个真正需要基本软件模型的本地小客户工作。我也是新人,请大家帮帮忙。

如果我的问题不清楚,请告诉我,我会尽力阐述我的想法。

最佳答案

我知道这是一篇旧文章,但对于那些仍在寻找解决方案的人,我可以告诉你我做了什么。

在花了很多时间研究 OPOS 和 POS for .Net 之后,我最终放弃了这些,只使用内置的 System.Drawing.Printing 库。 .Net 的 OPOS 和 POS 最终很难工作,并且最终无法像内置库那样工作。

我使用的是 Epson TM-T20II 收据打印机。

这里有一些对我来说效果很好的代码。

public static void PrintReceiptForTransaction()
    {

        PrintDocument recordDoc = new PrintDocument();

        recordDoc.DocumentName = "Customer Receipt";
        recordDoc.PrintPage += new PrintPageEventHandler(ReceiptPrinter.PrintReceiptPage); // function below
        recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
        // Comment if debugging 
        PrinterSettings ps = new PrinterSettings();
        ps.PrinterName = "EPSON TM-T20II Receipt";
        recordDoc.PrinterSettings = ps;
        recordDoc.Print();
        // --------------------------------------

        // Uncomment if debugging - shows dialog instead
        //PrintPreviewDialog printPrvDlg = new PrintPreviewDialog();
        //printPrvDlg.Document = recordDoc;
        //printPrvDlg.Width = 1200;
        //printPrvDlg.Height = 800;
        //printPrvDlg.ShowDialog();
        // --------------------------------------

        recordDoc.Dispose();

    }


private static void PrintReceiptPage(object sender, PrintPageEventArgs e)
    {
        float x = 10;
        float y = 5;
        float width = 270.0F; // max width I found through trial and error
        float height = 0F;

        Font drawFontArial12Bold = new Font("Arial", 12, FontStyle.Bold);
        Font drawFontArial10Regular = new Font("Arial", 10, FontStyle.Regular);
        SolidBrush drawBrush = new SolidBrush(Color.Black);

        // Set format of string.
        StringFormat drawFormatCenter = new StringFormat();
        drawFormatCenter.Alignment = StringAlignment.Center;
        StringFormat drawFormatLeft = new StringFormat();
        drawFormatLeft.Alignment = StringAlignment.Near;
        StringFormat drawFormatRight = new StringFormat();
        drawFormatRight.Alignment = StringAlignment.Far;

        // Draw string to screen.
        string text = "Company Name";
        e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
        y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

        text = "Address";
        e.Graphics.DrawString(text, drawFontArial10Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
        y += e.Graphics.MeasureString(text, drawFontArial10Regular).Height;

        // ... and so on

 }

希望它可以帮助人们跳过自定义驱动程序的所有困惑。 :)

关于c# - 销售点申请收据打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7402154/

相关文章:

c# - net 2.0中不同类型结构的排序列表

c# - 从c#dll中读取方法

c - 方法的位标志参数如何工作(Ansi C/C)?

c# - Microsoft 服务点无法检测到打印机

c# - MICROS 3700 ResPosApiWeb API客户端配置记录

c# - Response.End() 和 CompleteRequest()

c# - 在 DataGridViewImageColumn 绑定(bind)文本字段中显示图像

PHP打印热敏收据打印机

c# - 我可以在 switch 语句中使用变量吗?

javascript - 是否可以仅使用客户端语言构建 Web 应用程序?