using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.IO; using POSV.Printer; using System.Threading.Tasks; using NLog; using POSV.Entity; using POSV.ShoppingCart; using POSV.MessageEvent; using POSV.Utils; using POSV.Helper; using POS.Language.Language; using POSV.Payment.Abmcs; namespace POSV.Bill { /// /// 农行BMP的MIS,尚未开发完,客户暂时不支持MIS键盘 /// [ToolboxItem(true)] public partial class AbmcsMisControl : AbstractBill { private static Logger logger = NLog.LogManager.GetCurrentClassLogger(); /// /// 倒计时时长 /// private const int TIMER_INTERVAL = 1000; /// /// 操作是否验证通过 /// private bool PaymentVerify = false; /// /// 当前的支付方式 /// private PayMode CurrentPayMode = null; public AbmcsMisControl() { InitializeComponent(); PayStep1.Text = " " + LangProxy.ToLang("密码键盘") + "
" + LangProxy.ToLang("连接密码键盘") + " "; PayStep2.Text = "" + LangProxy.ToLang("发起扣款") + "
" + LangProxy.ToLang("发起扣款请求") + " "; PayStep3.Text = "" + LangProxy.ToLang("确认结果") + "
" + LangProxy.ToLang("确认扣款结果") + " "; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); SetStyle(ControlStyles.Selectable, true); this.txtAmount.Multiline = false; this.txtAmount.Focus(); this.txtAmount.Select(); } /// /// 订单对象 /// private OrderObject _orderObject = null; public override void BindUi(OrderObject orderObject) { if (orderObject == null) return; if (orderObject == null) return; //重新扫码,恢复初始值 this.PayStep1.Value = 0; this.PayStep2.Value = 0; this.PayStep3.Value = 0; MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY, new Tuple(true, "请输入付款金额...")); this._orderObject = orderObject; //银行卡支付不允许抹零 this._orderObject.MalingAmount = 0; //银行卡支付不允许找零 this._orderObject.ChangeAmount = 0; //将当前应收金额赋值 this.txtAmount.Focus(); //未收金额 var unpaidAmount = this._orderObject.PaidAmount - this._orderObject.ReceivedAmount; //将当前应收金额赋值 this.txtAmount.Text = unpaidAmount >= 0 ? unpaidAmount.ToString() : "0"; this.txtAmount.SelectAll(); //刷新支付汇总清单 this.billSummary1.Refresh(orderObject); } public override void SetFocus() { this.txtAmount.Focus(); this.txtAmount.SelectAll(); } private void OnKeyboardAfter(object sender, BillKeyboardEventArgs e) { switch (e.KeyCode) { case "clear": //如果当前焦点控件是输入框 if (this.ActiveControl is TextBox) { var activeControl = this.ActiveControl as TextBox; activeControl.Text = string.Empty; } break; case "accept": //验证通过 if (this.PaymentVerify) { this.PayStep1.Value = this.PayStep1.Maximum; //消费 Trans1("1"); } break; case "100": { //如果当前焦点控件是输入框 if (this.ActiveControl is TextBox) { var activeControl = this.ActiveControl as TextBox; activeControl.Text = string.Empty; } InputSimulatorUtils.SendKey(KeyCodes.Map["1"]); InputSimulatorUtils.SendKey(KeyCodes.Map["0"]); InputSimulatorUtils.SendKey(KeyCodes.Map["0"]); } break; case "50": { //如果当前焦点控件是输入框 if (this.ActiveControl is TextBox) { var activeControl = this.ActiveControl as TextBox; activeControl.Text = string.Empty; } InputSimulatorUtils.SendKey(KeyCodes.Map["5"]); InputSimulatorUtils.SendKey(KeyCodes.Map["0"]); } break; case "20": { //如果当前焦点控件是输入框 if (this.ActiveControl is TextBox) { var activeControl = this.ActiveControl as TextBox; activeControl.Text = string.Empty; } InputSimulatorUtils.SendKey(KeyCodes.Map["2"]); InputSimulatorUtils.SendKey(KeyCodes.Map["0"]); } break; case "10": { //如果当前焦点控件是输入框 if (this.ActiveControl is TextBox) { var activeControl = this.ActiveControl as TextBox; activeControl.Text = string.Empty; } InputSimulatorUtils.SendKey(KeyCodes.Map["1"]); InputSimulatorUtils.SendKey(KeyCodes.Map["0"]); } break; default: { InputSimulatorUtils.SendKey(KeyCodes.Map[e.KeyCode]); } break; } } private void OnKeyboardBefore(object sender, BillKeyboardEventArgs e) { this.PaymentVerify = false; this.CurrentPayMode = OrderUtils.GetPayMode("03"); ; if (this._orderObject == null) { MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY, new Tuple(true, "订单数据错误啦,请拍个照...")); return; } decimal inputMoney = this.txtAmount.DecimalValue; if (inputMoney < 0) { MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY, new Tuple(false, "请输入金额...")); this.txtAmount.Focus(); this.txtAmount.SelectAll(); return; } this.PaymentVerify = true; } delegate int Abmcs(string strIn, StringBuilder strOut); /// /// 消费 /// private void Trans1(string transCode) { } private void Print() { string fileName = string.Format(@"landiccbmispos\{0}", "P_TackSingle.txt"); string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName); if (File.Exists(filePath)) { string[] lines = File.ReadAllLines(filePath, System.Text.Encoding.Default); var sb = new StringBuilder(); var pobject = PrintHelper.GetTicketPrinterObject(true,false); ; List content = new List(); for (int i = 0; i < lines.Length; i++) { var str = lines[i]; switch (str) { case "#CUT#": { logger.Info("打印小票切纸动作"); //切纸 var p = new PrintContent(); p.Format = RowFormat.Line; p.Content = new StringBuilder().Append(ParseEscPosCommand("29,86,66")); content.Add(p); } break; case "#LDSIGN#": { logger.Info("打印ElecSign.bmp签名图片"); } break; case "#ODBMP#": { logger.Info("打印ConsumeOD.bmp图片"); } break; case "#QRBMP#": { logger.Info("打印PublicQR.bmp图片"); } break; default: { var p = new PrintContent(); p.Format = RowFormat.Line; p.Content = new StringBuilder().Append(str); p.AlignStyle = AlignStyle.居左; p.FontStyle = Printer.FontStyle.正常字体; p.BitmapFile = string.Empty; content.Add(p); logger.Info(str); } break; } } if (true) { //切纸 var p = new PrintContent(); p.Format = RowFormat.Line; p.Content = new StringBuilder().Append(ParseEscPosCommand("29,86,66")); content.Add(p); } //启动新任务 Task.Factory.StartNew(() => { PrinterUtils.PrintContent(pobject, content); }); } else { logger.Warn(filePath + "不存在"); } } private string ParseEscPosCommand(string command) { string[] array = command.Split(','); List bytList = new List(); foreach (var s in array) { bytList.Add(Convert.ToByte(s.Trim())); } return Encoding.Default.GetString(bytList.ToArray()); } } }