You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

320 lines
11 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 农行BMP的MIS尚未开发完客户暂时不支持MIS键盘
/// </summary>
[ToolboxItem(true)]
public partial class AbmcsMisControl : AbstractBill
{
private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
/// <summary>
/// 倒计时时长
/// </summary>
private const int TIMER_INTERVAL = 1000;
/// <summary>
/// 操作是否验证通过
/// </summary>
private bool PaymentVerify = false;
/// <summary>
/// 当前的支付方式
/// </summary>
private PayMode CurrentPayMode = null;
public AbmcsMisControl()
{
InitializeComponent();
PayStep1.Text = "<font size=\"+3\"><b> " + LangProxy.ToLang("密码键盘") + " </b></font><br/><font size=\"-1\"> " + LangProxy.ToLang("连接密码键盘") + " </font>";
PayStep2.Text = "<font size=\"+3\"><b>" + LangProxy.ToLang("发起扣款") + "</b></font><br/><font size=\"-1\">" + LangProxy.ToLang("发起扣款请求") + " </font>";
PayStep3.Text = "<font size=\"+3\"><b>" + LangProxy.ToLang("确认结果") + "</b></font><br/><font size=\"-1\">" + LangProxy.ToLang("确认扣款结果") + " </font>";
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
SetStyle(ControlStyles.Selectable, true);
this.txtAmount.Multiline = false;
this.txtAmount.Focus();
this.txtAmount.Select();
}
/// <summary>
/// 订单对象
/// </summary>
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<bool, string>(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<bool, string>(true, "订单数据错误啦,请拍个照..."));
return;
}
decimal inputMoney = this.txtAmount.DecimalValue;
if (inputMoney < 0)
{
MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY, new Tuple<bool, string>(false, "请输入金额..."));
this.txtAmount.Focus();
this.txtAmount.SelectAll();
return;
}
this.PaymentVerify = true;
}
delegate int Abmcs(string strIn, StringBuilder strOut);
/// <summary>
/// 消费
/// </summary>
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<PrintContent> content = new List<PrintContent>();
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<byte> bytList = new List<byte>();
foreach (var s in array)
{
bytList.Add(Convert.ToByte(s.Trim()));
}
return Encoding.Default.GetString(bytList.ToArray());
}
}
}