编写POS系统的最佳实践 [英] Best Practice for Writing a POS System

查看:50
本文介绍了编写POS系统的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#组装一个基本的销售点(POS)系统,该系统需要打印到收据打印机并打开现金抽屉.我必须使用Microsoft Point of Service SDK吗?

I'm putting together a basic Point of Sale (POS) system in C# that needs to print to a receipt printer and open a cash drawer. Do I have to use the Microsoft Point of Service SDK?

我一直在尝试使用附带的Windows驱动程序在我的三星打印机上进行打印,并且看来效果很好.我认为尽管其他打印机可​​能不带有Windows驱动程序,然后我还是会卡住?还是我可以简单地使用通用/文本驱动程序"来打印到任何支持它的打印机?

I've been playing around with printing to my Samsung printer using the Windows driver that came with it, and it seems to work great. I assume though that other printers may not come with Windows drivers and then I would be stuck? Or would I be able to simply use the Generic/Text Driver to print to any printer that supports it?

对于收银机,我需要直接将代码发送到COM端口,这对我来说很好,如果这样可以避免帮助客户在该系统上设置OPOS驱动程序的麻烦.

For the cash drawer I would need to send codes directly to the COM port which is fine with me, if it saves me the hassle of helping clients setup OPOS drivers on there systems.

我在这里走错了路吗?

推荐答案

这可能与您正在寻找的答案(!)...稍有不同.

This is probably a slightly different answer to what you were looking for(!)...

在使用外部接口"(例如打印机,现金提取等)时,总是要抽象一些东西.您可能想实施策略-模式策略.

When working with "external interfaces" (e.g. printers, cash draws etc) always abstract things. You probably want to implement strategies - Pattern Strategy.

您为现金提取创建界面:

public interface ICashDrawer
{
    void Open();
}

提供实现:

  • 一种策略是使用COM打开绘图的类
  • 另一个就像调用 Debug.WriteLine 的类一样简单,因此您在开发过程中无需将现金提取连接到PC
  • one strategy is a class that uses COM to open the draw
  • another is something as simple as a class that does a Debug.WriteLine call so you don't need a cash draw connected to your PC during development

例如

public class ComPortCashDrawer : ICashDrawer
{
    public void Open()
    {
        // open via COM port etc
    }
}

public class DebugWriterCashDrawer : ICashDrawer
{
    public void Open()
    {
        Debug.WriteLine("DebugWriterCashDrawer.Open() @ " + DateTime.Now);
    }
}

同样要进行打印,您有一个使用数据的打印界面:

Again for printing you have a print interface that takes the data:

public interface IRecieptPrinter
{
    bool Print(object someData);
}

然后您进行一个或多个实现.

then you make one or more implementations.

  • 基本打印机
  • 专业标签打印机
  • 基于文本的文本保存到文件...

例如

public class BasicRecieptPrinter : IRecieptPrinter
{
    public bool Print(object someData)
    {
        // format for a basic A4 print
        return true; // e.g. success etc
    }
}

public class SpecificXyzRecieptPrinter : IRecieptPrinter
{
    public bool Print(object someData)
    {
        // format for a specific printer
        return true; // e.g. success etc
    }
}

public class PlainTextFileRecieptPrinter : IRecieptPrinter
{
    public bool Print(object someData)
    {
        // Render the data as plain old text or something and save 
         // to a file for development or testing.
        return true; // e.g. success etc
    }
}

关于SDK,如果您出于某种原因发现您需要它,则可以使用SDK编写实现.随着时间的流逝,您可能最终会获得几种与不同的外部设备连接的方式.客户可能会在一天之内获得新的现金提取,等等.

With respect to the SDK, if down the track you find you need it for some reason you write implementations using the SDK. Over time you may end up with several ways to interface with different external devices. The client may get a new cash draw one day etc etc.

很清楚,如果您愿意的话,我可以充实我的意思,但您可能会感到不安.

Is that clear, I can flesh out what I mean if you want but you probably get my drift.

您的应用在启动时便设置了各自的实现,您可能想看看依赖注入,如果您使用容器来解决,您会发现事情变得更容易类型.

Your app sets itself up with the respective implementations at startup, you may want to take a look at Dependency injection as well and you will find things easier if you use a container to resolve the types.

var printer = container.Resolve<IRecieptPrinter>();

PK:-)

这篇关于编写POS系统的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆