|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using DevComponents.DotNetBar;
|
|
|
|
|
using POSV.Bill;
|
|
|
|
|
using POSV.Card;
|
|
|
|
|
using POSV.Entity;
|
|
|
|
|
using POSV.MessageEvent;
|
|
|
|
|
using POSV.ShoppingCart;
|
|
|
|
|
using POSV.Utils;
|
|
|
|
|
|
|
|
|
|
namespace POSV
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 废弃,请勿修改!!!!!!!!!!!!!!!!!!
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class BillForm : BusinessForm
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 收银方式集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Dictionary<string , SuperTabItem> _tabs = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前选择的收银方式
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SuperTabItem _currentTabItem = null;
|
|
|
|
|
|
|
|
|
|
private List<PayType> _payTypeList = null;
|
|
|
|
|
|
|
|
|
|
private List<PayMode> _payModeList = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前选择的收银方式
|
|
|
|
|
/// </summary>
|
|
|
|
|
private PayType _currentPayType = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前选择的付款类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
private PayMode _currentPayMode = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前选择的付款类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly string _defaultSelected = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当期订单对象的复制对象,避免取消结账污染元数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
private OrderObject _orderObject = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 支付窗口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="no">PayMode的No</param>
|
|
|
|
|
public BillForm(string payModeNo , OrderObject orderObject)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
MsgEvent.RemoveListener(Constant.PAY_MESSAGE_EVENT_NOTIFY , MessageEventNotify);
|
|
|
|
|
MsgEvent.Receive(Constant.PAY_MESSAGE_EVENT_NOTIFY , MessageEventNotify);
|
|
|
|
|
|
|
|
|
|
MsgEvent.RemoveListener(Constant.PAY_AUTO_EVENT_NOTIFY , FinishedEventNotify);
|
|
|
|
|
MsgEvent.Receive(Constant.PAY_AUTO_EVENT_NOTIFY , FinishedEventNotify);
|
|
|
|
|
|
|
|
|
|
this._defaultSelected = payModeNo;
|
|
|
|
|
|
|
|
|
|
//复制新对象,避免取消后污染原对象
|
|
|
|
|
this._orderObject = ObjectUtils.Copy<OrderObject>(orderObject);
|
|
|
|
|
|
|
|
|
|
this._tabs = new Dictionary<string , SuperTabItem>();
|
|
|
|
|
|
|
|
|
|
this.ImeMode = ImeMode.Disable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InitializePayType();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作提示
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="args"></param>
|
|
|
|
|
protected virtual void MessageEventNotify(object sender , MsgEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if(args.Data!=null && args.Data is Tuple<bool , string>)
|
|
|
|
|
{
|
|
|
|
|
var data = args.Data as Tuple<bool , string>;
|
|
|
|
|
|
|
|
|
|
this.ShowMessage(this.lblInfo , data.Item2 , data.Item1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void FinishedEventNotify(object sender , MsgEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke(new Action(() => {
|
|
|
|
|
this.OnFinishedClick(this.ButtonAccept , EventArgs.Empty);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializePayType()
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
|
|
|
|
sw.Start();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//获取付款方式列表
|
|
|
|
|
this._payTypeList = OrderUtils.GetPayTypeList();
|
|
|
|
|
//获取收银方式列表,获取前台展示
|
|
|
|
|
this._payModeList = OrderUtils.GetPayModeList().FindAll(x => x.FrontFlag == 1);
|
|
|
|
|
|
|
|
|
|
//获取默认的收银
|
|
|
|
|
if (!string.IsNullOrEmpty(this._defaultSelected))
|
|
|
|
|
{
|
|
|
|
|
if (Constant.HEMA_CODE.Equals(this._defaultSelected))
|
|
|
|
|
{
|
|
|
|
|
this._currentPayMode = this._payModeList.FirstOrDefault(x => Constant.HEMA_PAY.Contains(x.No));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this._currentPayMode = this._payModeList.FirstOrDefault(x => x.No.Equals(this._defaultSelected));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//选择默认
|
|
|
|
|
if (this._currentPayMode == null)
|
|
|
|
|
{
|
|
|
|
|
this._currentPayMode = OrderUtils.GetDefaultPayMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//加载收银方式
|
|
|
|
|
int inx = 0;
|
|
|
|
|
foreach (var type in this._payTypeList)
|
|
|
|
|
{
|
|
|
|
|
//如果收银标识中有可用的支付方式
|
|
|
|
|
if (this._payModeList.Exists(x => x.TypeId == type.Id))
|
|
|
|
|
{
|
|
|
|
|
var tabText = type.Name;
|
|
|
|
|
if (this._payModeList.Count(x => x.TypeId == type.Id) == 1)
|
|
|
|
|
{
|
|
|
|
|
var mode = this._payModeList.First(x => x.TypeId == type.Id);
|
|
|
|
|
tabText = mode.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tab = this.tabPayType.CreateTab(tabText);
|
|
|
|
|
tab.Tag = type;
|
|
|
|
|
tab.FixedTabSize = new Size(100 , 45);
|
|
|
|
|
|
|
|
|
|
this._tabs.Add(type.Id , tab);
|
|
|
|
|
|
|
|
|
|
//选择默认付款类型
|
|
|
|
|
if (type.Id.Equals(this._currentPayMode.TypeId))
|
|
|
|
|
{
|
|
|
|
|
this._currentTabItem = tab;
|
|
|
|
|
|
|
|
|
|
this._currentPayType = type;
|
|
|
|
|
}
|
|
|
|
|
inx++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.tabPayType.SelectedTabChanging += OnTabPayTypeSelectedTabChanging;
|
|
|
|
|
this.tabPayType.SelectedTabChanged += OnTabPayTypeSelectedTabChanged;
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.Error(ex , "初始化收银方式异常");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
sw.Stop();
|
|
|
|
|
LOGGER.Info("InitializePayType耗时<{0}>" , sw.ElapsedMilliseconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
|
|
|
|
|
|
this.tabPayType.SelectedTab = this._currentTabItem;
|
|
|
|
|
|
|
|
|
|
this.RefreshUi(this._currentPayType);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshUi(PayType payType)
|
|
|
|
|
{
|
|
|
|
|
this._currentTabItem = this._tabs[payType.Id];
|
|
|
|
|
|
|
|
|
|
this.tabPayType.SelectedTab = this._currentTabItem;
|
|
|
|
|
|
|
|
|
|
BillControl bill = null;
|
|
|
|
|
|
|
|
|
|
int attached = this.tabPayType.SelectedTab.AttachedControl.Controls.Count;
|
|
|
|
|
if (attached == 0)
|
|
|
|
|
{
|
|
|
|
|
bill = new BillControl();
|
|
|
|
|
|
|
|
|
|
bill.Dock = DockStyle.Fill;
|
|
|
|
|
this.tabPayType.SelectedTab.AttachedControl.Controls.Add(bill);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bill = this.tabPayType.SelectedTab.AttachedControl.Controls[0] as BillControl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取收银方式列表
|
|
|
|
|
var data = this._payModeList.FindAll(x => x.TypeId == payType.Id);
|
|
|
|
|
|
|
|
|
|
bill.RefreshUi(data , this._currentPayMode , this._orderObject);
|
|
|
|
|
|
|
|
|
|
this.ActiveControl = bill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTabPayTypeSelectedTabChanged(object sender , SuperTabStripSelectedTabChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.NewValue != null && e.NewValue.Tag != null)
|
|
|
|
|
{
|
|
|
|
|
var payType = e.NewValue.Tag as PayType;
|
|
|
|
|
|
|
|
|
|
this.RefreshUi(payType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTabPayTypeSelectedTabChanging(object sender , SuperTabStripSelectedTabChangingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.NewValue != null && e.NewValue.Tag != null)
|
|
|
|
|
{
|
|
|
|
|
var payType = e.NewValue.Tag as PayType;
|
|
|
|
|
|
|
|
|
|
//获取当前付款类型下的全部收银方式
|
|
|
|
|
var modes = this._payModeList.FindAll(x => x.TypeId == payType.Id);
|
|
|
|
|
|
|
|
|
|
//判断当前收银方式是否包含,如果不包含自动选择第一个为当前收银方式
|
|
|
|
|
if (!modes.Exists(x=>x.No == this._currentPayMode.No))
|
|
|
|
|
{
|
|
|
|
|
this._currentPayMode = modes.First<PayMode>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCloseTouchClick(object sender , EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//先关闭父窗体
|
|
|
|
|
if (this.Owner != null)
|
|
|
|
|
{
|
|
|
|
|
this.Owner.Close();
|
|
|
|
|
}
|
|
|
|
|
//再关闭当前窗体
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnEscapeClick(object sender , EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnCloseTouchClick(sender , e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnFinishedClick(object sender , EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var billControl = this._currentTabItem.AttachedControl.Controls[0] as BillControl;
|
|
|
|
|
|
|
|
|
|
billControl.SimulateKeyboard();
|
|
|
|
|
|
|
|
|
|
var button = sender as ButtonX;
|
|
|
|
|
|
|
|
|
|
//输入是否满足结账条件:应收金额 = 实际收款金额 - 找零金额
|
|
|
|
|
bool isVerify = (this._orderObject.ReceivableAmount == (this._orderObject.PaidAmount - this._orderObject.ChangeAmount));
|
|
|
|
|
|
|
|
|
|
//满足结账条件
|
|
|
|
|
if (isVerify)
|
|
|
|
|
{
|
|
|
|
|
this.ShowMessage(this.lblInfo , "满足结账条件" , false);
|
|
|
|
|
//默认支付成功
|
|
|
|
|
bool isPaySuccess = true;
|
|
|
|
|
|
|
|
|
|
//查找会员卡支付列表,如果有会员卡先扣会员卡钱
|
|
|
|
|
var cards = this._orderObject.Pays.FindAll(x => x.No.Equals("02"));
|
|
|
|
|
//包含会员卡支付,构建会员卡扣款列表
|
|
|
|
|
if (cards.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//交易参考号
|
|
|
|
|
string tradeVoucherNo = string.Empty;
|
|
|
|
|
|
|
|
|
|
//扣款卡列表
|
|
|
|
|
var payCards = new List<PayInfo>();
|
|
|
|
|
foreach (var card in cards)
|
|
|
|
|
{
|
|
|
|
|
PayInfo c = new PayInfo();
|
|
|
|
|
c.PrePayment = card.PrePayNo;
|
|
|
|
|
c.CardNo = card.CardNo;
|
|
|
|
|
c.Amount = Convert.ToInt32(card.Amount * 100);
|
|
|
|
|
c.IsNoPwd = card.UseConfirmed ? 0 : 1;
|
|
|
|
|
c.Passwd = card.Passwd;
|
|
|
|
|
|
|
|
|
|
payCards.Add(c);
|
|
|
|
|
|
|
|
|
|
tradeVoucherNo = card.TradeVoucherNo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var request = new CardTradePayRequest();
|
|
|
|
|
|
|
|
|
|
request.TradeNo = this._orderObject.TradeNo;
|
|
|
|
|
request.CardNo = this._orderObject.Member == null ? string.Empty : this._orderObject.Member.CurrentCard.CardNo;
|
|
|
|
|
request.CardTypeNo = this._orderObject.Member == null ? string.Empty : this._orderObject.Member.CurrentCard.CardTypeNo;
|
|
|
|
|
request.CardLevelNo = this._orderObject.Member == null ? string.Empty : this._orderObject.Member.CurrentCard.CardLevelNo;
|
|
|
|
|
|
|
|
|
|
request.TradeVoucherNo = tradeVoucherNo;
|
|
|
|
|
|
|
|
|
|
request.TotalAmount = Convert.ToInt32(this._orderObject.Amount * 100);
|
|
|
|
|
|
|
|
|
|
request.PointAmount = 0;
|
|
|
|
|
|
|
|
|
|
request.PayCardAmount = payCards.Sum(x=>x.Amount);
|
|
|
|
|
|
|
|
|
|
request.DiscountAmount = 0;
|
|
|
|
|
request.PointFlag = 0;
|
|
|
|
|
request.PointValue = 0;
|
|
|
|
|
|
|
|
|
|
request.PayInfo = payCards;
|
|
|
|
|
|
|
|
|
|
request.ShopNo = Global.Instance.Authc.StoreNo;
|
|
|
|
|
request.WorkerNo = Global.Instance.Worker.No;
|
|
|
|
|
request.PosNo = Global.Instance.Authc.PosNo;
|
|
|
|
|
|
|
|
|
|
var payResult = CardUtils.CardTradePay(request);
|
|
|
|
|
|
|
|
|
|
if (payResult.Item1)
|
|
|
|
|
{
|
|
|
|
|
//调整每张卡的扣款状态
|
|
|
|
|
foreach (var card in cards)
|
|
|
|
|
{
|
|
|
|
|
card.Status = (int)OrderPaymentStatus.已付款;
|
|
|
|
|
card.StatusDesc = payResult.Item2;
|
|
|
|
|
|
|
|
|
|
card.PayTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
this.ShowMessage(this.lblInfo , payResult.Item2 , false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//会员卡扣款清单,用于打印
|
|
|
|
|
this._orderObject.CardPayResult = payResult.Item3;
|
|
|
|
|
|
|
|
|
|
//会员卡扣款成功
|
|
|
|
|
isPaySuccess = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//会员卡扣款失败
|
|
|
|
|
isPaySuccess = false;
|
|
|
|
|
|
|
|
|
|
this.ShowMessage(this.lblInfo , payResult.Item2 , true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//支付成功
|
|
|
|
|
if (isPaySuccess)
|
|
|
|
|
{
|
|
|
|
|
//整单状态
|
|
|
|
|
this._orderObject.OrderStatus = OrderStatus.已完成;
|
|
|
|
|
//整单支付状态
|
|
|
|
|
this._orderObject.PaymentStatus = OrderPaymentStatus.已付款;
|
|
|
|
|
//通知主界面结账成功
|
|
|
|
|
MsgEvent.Send(Constant.ORDER_PAYMENT_NOTIFY , this._orderObject);
|
|
|
|
|
|
|
|
|
|
this.OnEscapeClick(this.ButtonCancel , EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.ShowMessage(this.lblInfo,"不满足结账条件" , false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCloseClick(object sender , EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnCloseTouchClick(sender , e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|