销售点申请收据打印

发布于 2024-12-04 11:26:13 字数 231 浏览 1 评论 0原文

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

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

I am working on a small project for a Retail Management Software, which will be using a POS printer (I think that's what we call it). I need a create a bill for it in the end. But i am stuck here, and not able to proceed. So suppose if I generate my bill in a separate form with appropriate dimensions (of width of POS bills), will i be able to print it properly?
I am using C# and .NET 4.0 framework. I don't have much knowledge about POS devices. I am working for really a small local client which needs a basic model of software. I am also a fresher so please help me out.

If my question is not clear, let me know i will try to elaborate my thought.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謸气贵蔟 2024-12-11 11:26:13

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

在花了很多时间研究 OPOS 和 POS for .Net 之后,我最终放弃了这些,只使用内置的 System.Drawing.Printing 库。 OPOS 和 .Net 的 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

 }

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

I know this is an old post, but for those still looking for a solution, I can tell you what I did.

After spending many hours messing with OPOS and POS for .Net, I ended up just abandoning those and just using the built-in System.Drawing.Printing libraries. The OPOS and POS for .Net ended up being a pain to get working and ultimately didn't work as well as the built-in libraries.

I'm using an Epson TM-T20II receipt printer.

Here's some code that worked well for me.

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

 }

Hopefully it helps someone skip all the messing around with custom drivers. :)

迷路的信 2024-12-11 11:26:13

好吧,我设计了一个 POS 应用程序(在 Delphi 中),尽管打印收据或账单存在很多小问题,但这并不是什么复杂的事情。我只是简单地打印收据,像任何其他打印机一样打印,不同之处在于您发送 30-38 个字符长的行(取决于打印机驱动程序、字体和大小)。首先,您可以使用两种方法进行打印:发送 Ascii 字符并发送特定打印机的打印机命令(设置字体样式、颜色等),或者第二种方法是使用 C# 设置字体、大小等,如打印到任何其他普通/桌面打印机。

您可以尝试按照页面示例和我的建议进行打印:
http://ondotnet.com/pub/a/dotnet/2002 /06/24/printing.html

Well I designed a POS application (in Delphi) and altough there are many little issues with printing a receipt or a bill it´s not rocket science. I just print a receipt by simply, well, printing like any other printer, the difference is that you send lines of 30-38 characters long (depending on the printer driver, font and size). To start, you could print using 2 methods: Sending Ascii characters and sending printer commands (to set the font style, color, etc) for that specific printer or the second method is to set the font, size, etc using C# like printing to any other normal/desktop printer.

You could try printing following the example of the page and my suggestions:
http://ondotnet.com/pub/a/dotnet/2002/06/24/printing.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文