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.

215 lines
7.3 KiB
C#

9 months ago
using POSV.Component;
using POSV.MessageEvent;
using POSV.ShoppingCart;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace POSV.Business
{
public partial class CashDialogForm : BusinessForm
{
/// <summary>
/// 现金结算 编码
/// </summary>
private const string PayModeNo = "01";
/// <summary>
/// 操作是否验证通过
/// </summary>
private bool inputVerify = false;
private OrderObject _orderObject = null;
public CashDialogForm(OrderObject orderObject)
{
InitializeComponent();
this._orderObject = orderObject;
this.ActiveControl = this.txtCash;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (DesignMode) return;
this.txtCash.Multiline = false;
this.txtCash.Focus();
this.txtCash.Select();
//应收金额
this.lblReceivableAmount.Text = string.Format(this.lblReceivableAmount.Tag.ToString(),this._orderObject.ReceivableAmount);
//实收金额
this.lblInputAmount.Text = string.Format(this.lblInputAmount.Tag.ToString(), "0.00");
//找零金额
this.lblChangeAmount.Text = string.Format(this.lblChangeAmount.Tag.ToString(), "0.00");
}
private decimal CalculateChangeAmount(decimal inputMoney)
{
if (this._orderObject.Pays == null)
{
this._orderObject.Pays = new List<PayItem>();
}
//待收金额 = 应收金额 - 已收金额
decimal receivableAmount = this._orderObject.PaidAmount - this._orderObject.Pays.FindAll(x => !x.No.Equals(PayModeNo)).Sum(x => x.PaidAmount);
//重新计算找零金额
return inputMoney < receivableAmount ? 0 : (inputMoney - receivableAmount);
}
private void OnKeyBoardTouchAfter(object sender, KeyboardExtEventArgs e)
{
try
{
this.ActiveControl = this.txtCash;
this.txtCash.Focus();
switch (e.KeyCode)
{
case "clear":
{
//如果当前焦点控件是输入框
this.txtCash.Text = string.Empty;
this.txtCash.Focus();
}
break;
case "close":
{
OnCloseClick(sender, EventArgs.Empty);
}
break;
case "accept":
{
//验证通过
if (this.inputVerify)
{
this.OnAcceptButtonClick(new TransparentEventArgs(TransparentAction.Accept, e.KeyCode, this.txtCash.DecimalValue));
this.OnCloseClick(sender, EventArgs.Empty);
}
}
break;
case "100":
{
InputSimulatorUtils.SendKey(KeyCodes.Map["1"]);
InputSimulatorUtils.SendKey(KeyCodes.Map["0"]);
InputSimulatorUtils.SendKey(KeyCodes.Map["0"]);
}
break;
case "50":
{
InputSimulatorUtils.SendKey(KeyCodes.Map["5"]);
InputSimulatorUtils.SendKey(KeyCodes.Map["0"]);
}
break;
case "20":
{
InputSimulatorUtils.SendKey(KeyCodes.Map["2"]);
InputSimulatorUtils.SendKey(KeyCodes.Map["0"]);
}
break;
case "10":
{
InputSimulatorUtils.SendKey(KeyCodes.Map["1"]);
InputSimulatorUtils.SendKey(KeyCodes.Map["0"]);
}
break;
default:
{
InputSimulatorUtils.SendKey(KeyCodes.Map[e.KeyCode]);
}
break;
}
}
finally
{
}
}
private void OnCloseClick(object sender, EventArgs e)
{
if (this.Owner != null)
{
this.Owner.Close();
}
this.Close();
}
private void OnInputValueChanged(object sender, EnterEventArg e)
{
this.inputVerify = false;
if (this._orderObject == null)
{
this.ShowToastNotify(this, "订单数据错误啦,请拍个照...");
//实收金额
this.lblInputAmount.Text = string.Format(this.lblInputAmount.Tag.ToString(), "0.00");
//找零金额
this.lblChangeAmount.Text = string.Format(this.lblChangeAmount.Tag.ToString(), "0.00");
return;
}
decimal inputMoney = this.txtCash.DecimalValue;
if (inputMoney < 0)
{
this.ShowToastNotify(this, "请输入金额...");
//实收金额
this.lblInputAmount.Text = string.Format(this.lblInputAmount.Tag.ToString(), "0.00");
//找零金额
this.lblChangeAmount.Text = string.Format(this.lblChangeAmount.Tag.ToString(), "0.00");
this.txtCash.Focus();
this.txtCash.SelectAll();
return;
}
//计算找零金额
decimal changeAmount = this.CalculateChangeAmount(inputMoney);
//前台收银找零不允许超过100元
bool notAllowMoreOneHundred = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_NOT_ALLOW_MORE_ONE_HUNDRED);
if (notAllowMoreOneHundred && changeAmount > 100)
{
this.ShowToastNotify(this, "找零不允许超过100元...");
//实收金额
this.lblInputAmount.Text = string.Format(this.lblInputAmount.Tag.ToString(), "0.00");
//找零金额
this.lblChangeAmount.Text = string.Format(this.lblChangeAmount.Tag.ToString(), "0.00");
this.txtCash.Focus();
this.txtCash.SelectAll();
return;
}
//实收金额
this.lblInputAmount.Text = string.Format(this.lblInputAmount.Tag.ToString(), inputMoney);
//找零金额
this.lblChangeAmount.Text = string.Format(this.lblChangeAmount.Tag.ToString(), changeAmount);
//找零
this._orderObject.ChangeAmount = changeAmount;
this.inputVerify = true;
}
}
}