C# 简易POS零售系统架构设计源码(4)
作者:C/S框架网  发布日期:2011/05/09 12:16:08
C# 简易POS零售系统架构设计源码(4)


PosTerminal.cs

C# Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace CSFramework.Tech2011.PosTerminal
{
   /// <summary>
   /// 收银台管理类
   /// 收银终端设备:PosTerminal
   /// </summary>
   public class PosTerminal
   {
      private IMonitor _Monitor = null; //收银台监视器
      private IPrinter _Printer = null; //小票打印机
      private ICashier _Cashier = null; //钱箱
      private IStockDataView _StockDataShow = null;//已输入货品清单
      
      public IMonitor PosMonitor { get { return _Monitor; } }
      public IPrinter PosPrinter { get { return _Printer; } }
      public ICashier PosCashier { get { return _Cashier; } }
      public IStockDataView PosStockDataView { get { return _StockDataShow; } }
      
      /// <summary>
      /// 创建一个收银台管理类
      /// </summary>
      public PosTerminal(ICashier cashier, IMonitor monitor, IPrinter printer, IStockDataView stockDataView)
      {
         _Monitor = monitor;
         _Printer = printer;
         _Cashier = cashier;
         _StockDataShow = stockDataView;
      }
      
      public bool Pay(decimal amount)
      {
         decimal rcv = this._StockDataShow.GetReceivableAmount();
         if (amount > rcv)
         {
            _Cashier.OpenDoor(); //打开钱箱
            _Cashier.AcceptMoney(amount); //收钱
            _Cashier.CloseDoor();//关闭钱箱
            
            _StockDataShow.Clear(); //收款收毕清空货品列表,重新启动收钱任务
            
            _Monitor.ShowMessage("Thank you!", "已收:" amount.ToString());
            _Printer.Print("Thanks!");
            return true;
         }
         else
         {
            _Monitor.ShowMessage("not enough money!", "应收:" rcv.ToString());
            return false;
         }
      }
      
      /// <summary>
      /// 检查系统/硬件连接
      /// </summary>
      public void CheckSystem()
      {
         if (_Monitor != null)
         _Monitor.ShowMessage("Welcome!", "");
         
         if (_Printer != null)
         _Printer.Print("Test Printer.... ok!");
         
         if (_Cashier != null) //检查钱箱
         {
            _Cashier.AcceptMoney(0);
            _Cashier.OpenDoor();
            _Cashier.CloseDoor();
         }
      }
      
      public void PrintStockInfo(Stock stock)
      {
         if (_Printer != null)
         _Printer.Print(stock.Name " Price: " stock.Price.ToString());
      }
      
      /// <summary>
      /// 当输入一个货品,要显示当前货品名称及应收金额
      /// </summary>
      public void ShowStockInfo(Stock stock)
      {
         decimal amt = _StockDataShow.GetReceivableAmount();
         _Monitor.ShowMessage(stock.Name " Price: " stock.Price.ToString(), "应收:" amt.ToString());
      }
      
      /// <summary>
      /// 输入货品
      /// </summary>
      public void AddStock(Stock stock, int qty)
      {
         this.PosStockDataView.AddStock(stock, qty); //加入货品队列
         this.PrintStockInfo(stock); //打印小票
         this.ShowStockInfo(stock); //显示货品
      }
      
      /// <summary>
      /// 重置收银台
      /// </summary>
      public void Reset()
      {
         _Monitor.Reset();
         _Cashier.Reset();
         _Printer.Reset();
         _StockDataShow.Clear();
         CheckSystem();
      }
   }
   
}


//来源:C/S框架网(www.csframework.com) QQ:1980854898


 

上一篇 下一篇