|
|
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.Utils;
|
|
|
using POSV.ShoppingCart;
|
|
|
using POSV.MessageEvent;
|
|
|
using POSV.Entity;
|
|
|
|
|
|
namespace POSV.Bill
|
|
|
{
|
|
|
[ToolboxItem(true)]
|
|
|
public partial class SharedControl : AbstractBill
|
|
|
{
|
|
|
public SharedControl()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
{
|
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
SetStyle(ControlStyles.Selectable , true);
|
|
|
|
|
|
this.txtAmount.Multiline = false;
|
|
|
this.txtAmount.Focus();
|
|
|
this.txtAmount.Select();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs e)
|
|
|
{
|
|
|
e.Graphics.Clear(Focused ? SystemColors.Control : SystemColors.Control);
|
|
|
}
|
|
|
|
|
|
protected override void OnGotFocus(EventArgs e)
|
|
|
{
|
|
|
Invalidate();
|
|
|
base.OnGotFocus(e);
|
|
|
}
|
|
|
|
|
|
protected override void OnLostFocus(EventArgs e)
|
|
|
{
|
|
|
base.OnLostFocus(e);
|
|
|
Invalidate();
|
|
|
}
|
|
|
|
|
|
public override void SetFocus()
|
|
|
{
|
|
|
this.txtAmount.Focus();
|
|
|
this.txtAmount.SelectAll();
|
|
|
}
|
|
|
|
|
|
|
|
|
public override bool Focused
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (this.ActiveControl == null)
|
|
|
{
|
|
|
this.ActiveControl = this.txtAmount;
|
|
|
}
|
|
|
|
|
|
return this.ActiveControl.Focused;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 订单对象
|
|
|
/// </summary>
|
|
|
private OrderObject _orderObject = null;
|
|
|
|
|
|
public override void BindUi(OrderObject orderObject)
|
|
|
{
|
|
|
if (orderObject == null) return;
|
|
|
|
|
|
this._orderObject = orderObject;
|
|
|
|
|
|
//不抹零
|
|
|
this._orderObject.MalingAmount = 0;
|
|
|
|
|
|
//不找零
|
|
|
this._orderObject.ChangeAmount = 0;
|
|
|
|
|
|
//未收金额
|
|
|
var unpaidAmount = this._orderObject.PaidAmount - this._orderObject.ReceivedAmount;
|
|
|
|
|
|
//将当前应收金额赋值
|
|
|
//支付方式固定金额,如果大于0,则设置支付金额为固定金额,比如3元优惠券,默认带出固定金额3元
|
|
|
var payMode = this.Tag as PayMode;
|
|
|
if(payMode.FixeAmount > 0)
|
|
|
{
|
|
|
this.txtAmount.Text = payMode.FixeAmount.ToString();
|
|
|
this.txtAmount.ReadOnly = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.txtAmount.ReadOnly = false;
|
|
|
this.txtAmount.Text = unpaidAmount >= 0 ? unpaidAmount.ToString() : "0";
|
|
|
}
|
|
|
|
|
|
this.txtAmount.SelectAll();
|
|
|
|
|
|
//刷新支付汇总清单
|
|
|
this.billSummary1.Refresh(orderObject);
|
|
|
//刷新支付列表
|
|
|
this.billGrid1.RefreshGrid(this._orderObject.Pays);
|
|
|
|
|
|
}
|
|
|
|
|
|
private bool VerifyInputValue()
|
|
|
{
|
|
|
if (this._orderObject == null)
|
|
|
{
|
|
|
MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY , new Tuple<bool , string>(true , "订单数据错误啦,请拍个照..."));
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//输入是否满足结账条件:消费明细中实收金额的合计 = 主单中的实收金额
|
|
|
var isVerify = this._orderObject.Pays.Sum(x => x.PaidAmount) >= this._orderObject.PaidAmount;
|
|
|
|
|
|
//满足结账条件
|
|
|
if (isVerify)
|
|
|
{
|
|
|
MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY , new Tuple<bool , string>(true , "满足结账条件,点击完成结账"));
|
|
|
this.txtAmount.SelectAll();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//操作员输入的实收金额
|
|
|
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 false;
|
|
|
}
|
|
|
|
|
|
//未收金额
|
|
|
var unpaidAmount = this._orderObject.PaidAmount - this._orderObject.ReceivedAmount;
|
|
|
|
|
|
var payMode = this.Tag as PayMode;
|
|
|
if (inputMoney > unpaidAmount)
|
|
|
{
|
|
|
|
|
|
//如果是固定金额默认设置规定额
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
this.txtAmount.Focus();
|
|
|
this.txtAmount.SelectAll();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//如果不是固定金额
|
|
|
MsgEvent.Send(Constant.PAY_MESSAGE_EVENT_NOTIFY, new Tuple<bool, string>(false, "金额不允许大于" + unpaidAmount + "..."));
|
|
|
this.txtAmount.Focus();
|
|
|
this.txtAmount.SelectAll();
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 操作是否验证通过
|
|
|
/// </summary>
|
|
|
private bool PaymentVerify = false;
|
|
|
private void OnKeyboardBefore(object sender , BillKeyboardEventArgs e)
|
|
|
{
|
|
|
this.PaymentVerify = VerifyInputValue();
|
|
|
}
|
|
|
|
|
|
private void AddOtherPayType()
|
|
|
{
|
|
|
//实收金额,操作员录入的金额
|
|
|
decimal inputMoney = this.txtAmount.DecimalValue;
|
|
|
|
|
|
var payMode = this.Tag as PayMode;
|
|
|
|
|
|
//验证是否已经存在当前支付方式
|
|
|
if(this._orderObject.Pays.Exists(x => x.No == payMode.No))
|
|
|
{
|
|
|
var dialog = new DialogForm("提示", string.Format("已存在<{0}>,是否确定再次添加?", payMode.Name), MessageBoxIcon.Question, MessageBoxButtons.OKCancel);
|
|
|
if(dialog.ShowDialog(this) != DialogResult.OK)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//构建支付方式
|
|
|
PayItem item = OrderUtils.ToPayItem(payMode);
|
|
|
|
|
|
//租户ID
|
|
|
item.TenantId = Global.Instance.Authc.TenantId;
|
|
|
|
|
|
//订单号
|
|
|
item.OrderId = this._orderObject.Id;
|
|
|
item.TradeNo = this._orderObject.TradeNo;
|
|
|
//未收金额
|
|
|
var unpaidAmount = this._orderObject.PaidAmount - this._orderObject.ReceivedAmount;
|
|
|
|
|
|
if (inputMoney > unpaidAmount)
|
|
|
{
|
|
|
item.PaidAmount = unpaidAmount;
|
|
|
this._orderObject.OverAmount = inputMoney- unpaidAmount;
|
|
|
}
|
|
|
else {
|
|
|
//实收金额
|
|
|
item.PaidAmount = inputMoney;
|
|
|
}
|
|
|
//找零金额
|
|
|
item.ChangeAmount = 0;
|
|
|
//已收金额 = 收银员输入的金额 - 找零,真正意义上实际收款金额
|
|
|
item.Amount = (inputMoney - 0);
|
|
|
//溢收金额
|
|
|
item.OverAmount = this._orderObject.OverAmount;
|
|
|
item.CardNo = "";
|
|
|
|
|
|
item.Memo = string.Empty;
|
|
|
item.TradeVoucherNo = string.Empty;
|
|
|
|
|
|
item.Status = (int)OrderPaymentStatus.已付款;
|
|
|
item.StatusDesc = payMode.Name;
|
|
|
|
|
|
//将新的支付压入支付清单
|
|
|
this._orderObject.Pays.Add(item);
|
|
|
|
|
|
//刷新界面数据
|
|
|
this.billSummary1.Refresh(this._orderObject);
|
|
|
this.billGrid1.RefreshGrid(this._orderObject.Pays);
|
|
|
|
|
|
//未收金额
|
|
|
unpaidAmount = this._orderObject.PaidAmount - this._orderObject.ReceivedAmount;
|
|
|
|
|
|
//如果是固定金额默认设置规定额
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
this.txtAmount.Text = payMode.FixeAmount.ToString();
|
|
|
this.txtAmount.ReadOnly = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.txtAmount.ReadOnly = false;
|
|
|
this.txtAmount.Text = unpaidAmount < 0 ? "0" : unpaidAmount.ToString();
|
|
|
}
|
|
|
|
|
|
//this.txtAmount.Text = unpaidAmount < 0 ? "0" : unpaidAmount.ToString();
|
|
|
|
|
|
this.txtAmount.Focus();
|
|
|
this.txtAmount.SelectAll();
|
|
|
}
|
|
|
|
|
|
|
|
|
private void OnKeyboardAfter(object sender , BillKeyboardEventArgs e)
|
|
|
{
|
|
|
//支付方式固定金额,如果大于0,则设置支付金额为固定金额,比如3元优惠券,默认带出固定金额3元
|
|
|
var payMode = this.Tag as PayMode;
|
|
|
switch (e.KeyCode)
|
|
|
{
|
|
|
case "clear":
|
|
|
//如果当前焦点控件是输入框
|
|
|
if (this.ActiveControl is TextBox)
|
|
|
{
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
var activeControl = this.ActiveControl as TextBox;
|
|
|
activeControl.Text = string.Empty;
|
|
|
}
|
|
|
break;
|
|
|
case "accept":
|
|
|
//验证通过
|
|
|
if (this.PaymentVerify)
|
|
|
{
|
|
|
AddOtherPayType();
|
|
|
}
|
|
|
break;
|
|
|
case "100":
|
|
|
{
|
|
|
//如果当前焦点控件是输入框
|
|
|
if (this.ActiveControl is TextBox)
|
|
|
{
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
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)
|
|
|
{
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
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)
|
|
|
{
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
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)
|
|
|
{
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
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 OnPaymentRowDeleteClick(object sender , PaymentRowDeleteClickEventArgs e)
|
|
|
{
|
|
|
if (this._orderObject.Pays.Exists(x => x.Id == e.ObjectId))
|
|
|
{
|
|
|
var _oldItem = this._orderObject.Pays.Find(x => x.Id == e.ObjectId);
|
|
|
//删除已经存在的支付方式
|
|
|
this._orderObject.Pays.Remove(_oldItem);
|
|
|
if (_oldItem.OverAmount > 0)
|
|
|
{
|
|
|
//删除付款列表重新计算溢收
|
|
|
this._orderObject.OverAmount = this._orderObject.OverAmount - _oldItem.OverAmount;
|
|
|
}
|
|
|
else {
|
|
|
if (this._orderObject.Pays.Count > 0) {
|
|
|
var lastItem = this._orderObject.Pays[this._orderObject.Pays.Count - 1];
|
|
|
if (lastItem.OverAmount > 0 && lastItem.OverAmount >= _oldItem.PaidAmount)
|
|
|
{
|
|
|
lastItem.PaidAmount = lastItem.PaidAmount + _oldItem.PaidAmount;
|
|
|
lastItem.OverAmount = lastItem.OverAmount - _oldItem.PaidAmount;
|
|
|
this._orderObject.OverAmount = lastItem.OverAmount;
|
|
|
}
|
|
|
else if (lastItem.OverAmount > 0 && lastItem.OverAmount < _oldItem.PaidAmount)
|
|
|
{
|
|
|
lastItem.PaidAmount = lastItem.Amount;
|
|
|
lastItem.OverAmount = 0;
|
|
|
this._orderObject.OverAmount = 0;
|
|
|
}
|
|
|
else {
|
|
|
this._orderObject.OverAmount = 0;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
this._orderObject.OverAmount = 0;
|
|
|
}
|
|
|
}
|
|
|
//刷新界面数据
|
|
|
this.billSummary1.Refresh(this._orderObject);
|
|
|
this.billGrid1.RefreshGrid(this._orderObject.Pays);
|
|
|
|
|
|
//未收金额
|
|
|
var unpaidAmount = this._orderObject.ReceivableAmount - this._orderObject.ReceivedAmount;
|
|
|
|
|
|
var payMode = this.Tag as PayMode;
|
|
|
//如果是固定金额默认设置规定额
|
|
|
if (payMode.FixeAmount > 0)
|
|
|
{
|
|
|
this.txtAmount.Text = payMode.FixeAmount.ToString();
|
|
|
this.txtAmount.ReadOnly = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.txtAmount.ReadOnly = false;
|
|
|
this.txtAmount.Text = unpaidAmount < 0 ? "0" : unpaidAmount.ToString();
|
|
|
}
|
|
|
|
|
|
this.txtAmount.Focus();
|
|
|
this.txtAmount.SelectAll();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public override void SimulateKeyboard(BillKeyboardEventArgs e)
|
|
|
{
|
|
|
base.SimulateKeyboard(e);
|
|
|
|
|
|
this.OnKeyboardBefore(this.billKeyboard1 , e);
|
|
|
|
|
|
if (this.PaymentVerify)
|
|
|
{
|
|
|
this.OnKeyboardAfter(this.billKeyboard1 , e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public override void Clear()
|
|
|
{
|
|
|
base.Clear();
|
|
|
|
|
|
this.txtAmount.Text = string.Empty;
|
|
|
|
|
|
this._orderObject = null;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|