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.

351 lines
12 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 POSV.ShoppingCart;
using POSV.Entity;
using DevComponents.DotNetBar;
using System.Threading;
using POSV.MessageEvent;
using System.Threading.Tasks;
namespace POSV.Bill
{
public partial class BillControl : BaseUserControl
{
private Dictionary<string, AbstractBill> _bills = null;
/// <summary>
/// 收银方式集合
/// </summary>
private Dictionary<string, SuperTabItem> _tabs = null;
/// <summary>
/// 当前选择的付款类型
/// </summary>
private PayMode _currentPayMode = null;
/// <summary>
/// 当期订单对象
/// </summary>
private OrderObject _orderObject = null;
/// <summary>
/// 当前选中的
/// </summary>
private SuperTabItem _currentTabItem = null;
public BillControl()
{
InitializeComponent();
//注册结算支付事件通知
MsgEvent.RemoveListener(Constant.ORDER_PAYMENT_FINISHED, this.OrderFinishedEventNotify);
MsgEvent.Receive(Constant.ORDER_PAYMENT_FINISHED, this.OrderFinishedEventNotify);
this._tabs = new Dictionary<string, SuperTabItem>();
this.tabPayMode.SelectedTabChanging -= OnTabPayModeSelectedTabChanging;
this.tabPayMode.SelectedTabChanging += OnTabPayModeSelectedTabChanging;
this.tabPayMode.SelectedTabChanged -= OnTabPayModeSelectedTabChanged;
this.tabPayMode.SelectedTabChanged += OnTabPayModeSelectedTabChanged;
this._bills = new Dictionary<string, AbstractBill>();
//现金
this._bills.Add("01", new CashControl());
//享迷卡
this._bills.Add("49", new MCardControl());
//会员卡
this._bills.Add("02", new MCardControl());
//合码支付,支持微信、支付宝
this._bills.Add("00", new MPayControl());
#region subin 2023-07-01 add
//通联支付
this._bills.Add("50", new AllinPayControl());
#endregion
}
protected virtual void OrderFinishedEventNotify(object sender, MsgEventArgs args)
{
this.Invoke(new Action(() =>
{
//如果是合码支付取00
var payModeNo = Constant.HEMA_PAY.Contains(this._currentPayMode.No) ? Constant.HEMA_CODE : this._currentPayMode.No;
var bill = this._bills[payModeNo];
if (bill != null)
{
bill.Clear();
}
}));
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
}
private void OnTabPayModeSelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e)
{
if (e.NewValue != null && e.NewValue.Tag != null)
{
var payMode = e.NewValue.Tag as PayMode;
this._currentPayMode = payMode;
if (RefreshUiLock)
{
this.RefreshUi(this._dataSource, payMode, this._orderObject);
}
}
}
private void OnTabPayModeSelectedTabChanging(object sender, SuperTabStripSelectedTabChangingEventArgs e) { }
private List<PayMode> _dataSource = null;
private List<PayMode> _pagingdataSource = new List<PayMode>();
private int PageNumber = 0;
private bool PagingButton = false;
private bool RefreshUiLock = true;
public void RefreshUi(List<PayMode> dataSource, PayMode selected, OrderObject orderObject)
{
try
{
if (RefreshUiLock)
{
RefreshUiLock = false;
//如果是合码支付取00
var payModeNo = Constant.HEMA_PAY.Contains(selected.No) ? Constant.HEMA_CODE : selected.No;
//1、判断支付方式是否存本页
if (!this._tabs.ContainsKey(payModeNo))
{
//2、判断是否需分页
if (dataSource.Count >= 8)
{
_pagingdataSource.Clear();
_tabs.Clear();
this.tabPayMode.Tabs.Clear();
ButtonItem buttonItem = new DevComponents.DotNetBar.ButtonItem();
this.tabPayMode.Tabs.AddRange(new DevComponents.DotNetBar.BaseItem[] {
buttonItem});
buttonItem.Image = global::POSV.Properties.Resources.up;
buttonItem.Name = "UpPayType";
buttonItem.Text = "";
buttonItem.Click += ButtonItem_Click;
PagingButton = true;
var _data = dataSource.FirstOrDefault(f => f.No.Equals(selected.No));
_pagingdataSource.Add(_data);
//3、分页
_pagingdataSource.AddRange(dataSource.Where(f => !f.No.Equals(_data.No)).Skip(PageNumber * 8).Take(7).ToList());
}
else
{
_pagingdataSource = dataSource;
}
}
this._dataSource = dataSource;
this._orderObject = orderObject;
this.tabPayMode.Visible = false;
AbstractBill bill = null;
foreach (var mode in this._pagingdataSource)
{
if (!this._tabs.ContainsKey(mode.No))
{
//支付宝和微信并入合码支付
if (Constant.HEMA_PAY.Contains(mode.No))
{
//尚未添加合码支付
if (!this._tabs.ContainsKey(Constant.HEMA_CODE))
{
SuperTabItem tab = this.tabPayMode.CreateTab("合码支付");
tab.Tag = mode;
tab.FixedTabSize = new Size(0, 45);
this._tabs.Add(Constant.HEMA_CODE, tab);
}
}
else
{
SuperTabItem tab = this.tabPayMode.CreateTab(mode.Name);
tab.Tag = mode;
tab.FixedTabSize = new Size(0, 45);
this._tabs.Add(mode.No, tab);
}
}
}
if (PagingButton)
{
PagingButton = false;
ButtonItem buttonItem = new DevComponents.DotNetBar.ButtonItem();
this.tabPayMode.Tabs.AddRange(new DevComponents.DotNetBar.BaseItem[] {
buttonItem});
buttonItem.Image = global::POSV.Properties.Resources.below;
buttonItem.Name = "BelowPayType";
buttonItem.Click += ButtonItem_Click;
buttonItem.Text = "";
}
this._currentTabItem = this._tabs[payModeNo];
this.tabPayMode.SelectedTab = this._currentTabItem;
//如果不需要系统特殊处理
int attached = this.tabPayMode.SelectedTab.AttachedControl.Controls.Count;
if (attached == 0)
{
if (!this._bills.ContainsKey(payModeNo))
{
this._bills.Add(payModeNo, new SharedControl());
}
bill = this._bills[payModeNo];
bill.Dock = DockStyle.Fill;
this.tabPayMode.SelectedTab.AttachedControl.Controls.Add(bill);
}
else
{
bill = this.tabPayMode.SelectedTab.AttachedControl.Controls[0] as AbstractBill;
bill.Dock = DockStyle.Fill;
}
if (bill != null)
{
//绑定收银方式
var mode = this.tabPayMode.SelectedTab.Tag as PayMode;
this._currentPayMode = mode;
bill.Tag = mode;
//设置焦点
bill.SetFocus();
bill.PayNo = mode.No;
//绑定数据
bill.BindUi(this._orderObject);
}
if (this.tabPayMode.Tabs.Count == 1)
{
this.tabPayMode.TabsVisible = false;
this.tabPayMode.FixedTabSize = new Size(0, 45);
}
else
{
this.tabPayMode.TabsVisible = true;
this.tabPayMode.FixedTabSize = new Size(130, 45);
}
this.tabPayMode.Visible = true;
//设置焦点
bill.SetFocus();
//享迷卡
if (!"49".Equals(selected.No))
{
this._bills["49"].Close();
}
else
{
//读卡器控制
if (!"02".Equals(selected.No))
{
if (this._bills.ContainsKey("02"))
{
this._bills["02"].Close();
}
}
}
}
}
catch (Exception)
{
RefreshUiLock = true;
}
finally { RefreshUiLock = true; }
}
private void ButtonItem_Click(object sender, EventArgs e)
{
var _btn = sender as ButtonItem;
if (_btn == null)
{
return;
}
switch (_btn.Name)
{
case "UpPayType":
if (PageNumber == 0)
{
return;
}
PageNumber--;
this._tabs.Clear();
this.RefreshUi(this._dataSource, this._dataSource.Skip(PageNumber * 8).Take(1).FirstOrDefault(), this._orderObject);
break;
case "BelowPayType":
if ((PageNumber + 1) * 8 > this._dataSource.Count)
{
return;
}
PageNumber++;
this._tabs.Clear();
this.RefreshUi(this._dataSource, this._dataSource.Skip(PageNumber * 8).Take(1).FirstOrDefault(), this._orderObject);
break;
default:
break;
}
}
public void SimulateKeyboard()
{
//如果是合码支付取00
var payModeNo = Constant.HEMA_PAY.Contains(this._currentPayMode.No) ? Constant.HEMA_CODE : this._currentPayMode.No;
var bill = this._bills[payModeNo];
bill.SimulateKeyboard(new BillKeyboardEventArgs("accept"));
}
}
}