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.

289 lines
9.9 KiB
C#

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.Component;
using POSV.ShoppingCart;
using POSV.Utils;
using POSV.Entity;
using POS.Language.Language;
namespace POSV.Business
{
public partial class QuantityPanelEx : AbstractFlyoutPanelEx
{
/// <summary>
/// 当前选择的记录,单品议价依赖
/// </summary>
private OrderItem _orderItem = null;
/// <summary>
/// 权限控制码
/// </summary>
private string _permissionCode = string.Empty;
/// <summary>
/// 授权人权限信息
/// </summary>
private Tuple<decimal, decimal, List<string>, Worker> _authz = null;
/// <summary>
/// 授权界面或者录入界面切换
/// </summary>
private AuthOperator _auth = AuthOperator.None;
public QuantityPanelEx(OrderItem item , string permissionCode, AuthOperator auth = AuthOperator., Tuple<decimal, decimal, List<string>, Worker> authz = null)
{
InitializeComponent();
this._orderItem = item;
this.tabControl.TabsVisible = false;
this.Height = this.Height - 30;
//操作功能的权限码
this._permissionCode = permissionCode;
//授权人综合信息
this._authz = authz;
//外部传入的操作
this._auth = auth;
//定义授权界面的操作事件
this.authPanel.ButtonClick += OnAuthzButtonClick;
//默认校验权限控制码
this.authPanel.ExpectValidate(this._permissionCode);
}
/// <summary>
/// 授权事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAuthzButtonClick(object sender, AuthEventArgs e)
{
switch (e.Action)
{
case AuthAction.Close:
{
this.OnCancelButtonClick(new FlyoutEventArgs(FlyoutAction.Cancel, e.KeyCode, null));
}
break;
case AuthAction.Cancel:
{
this.tabControl.SelectedTab = null;
this.tabControl.SelectedTab = this.tabInput;
}
break;
case AuthAction.Accept:
{
if (e.Data is Tuple<decimal, decimal, List<string>, Worker>)
{
this._authz = e.Data as Tuple<decimal, decimal, List<string>, Worker>;
var logInfo = string.Format(LangProxy.ToLang("操作由[{0},{1}]授权"), this._authz.Item4.No, this._authz.Item4.Name);
LogUtils.WriteLog(LogAction., logInfo, this._authz.Item4.No, this._orderItem.TradeNo);
this.tabControl.SelectedTab = null;
this.tabControl.SelectedTab = this.tabInput;
this.ShowMessage(this.lblInfo, logInfo);
}
}
break;
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.SetStyle(ControlStyles.Selectable , true);
if (this.DesignMode) return;
//允许输入小数数量
bool allowInputDigit = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_NOT_ALLOW_INPUT_DIGIT , true);
this.touchButtonX11.Lock = !allowInputDigit;
this.touchButtonX11.LockSize = new Size(26 , 26);
this.txtQuantity.AllowDecimalSeparator = allowInputDigit;
//设置小数位数
if (allowInputDigit)
{
this.txtQuantity.MaxDecimalDigit = Global.Instance.GlobalConfigIntValue(ConfigConstant.CASHIER_QUANTITY_DIGIT , 2);
}
this.ShowMessage(this.lblInfo , string.Format(this.lblInfo.Tag.ToString() , this._orderItem.Name));
this.txtQuantity.Text = this._orderItem.Quantity.ToString();
this.ActiveControl = this.txtQuantity;
this.txtQuantity.Multiline = false;
this.txtQuantity.Focus();
this.txtQuantity.SelectAll();
this.tabControl.SelectedTab = null;
switch (this._auth)
{
case AuthOperator.:
{
this.tabControl.SelectedTab = this.tabInput;
}
break;
case AuthOperator.:
{
this.tabControl.SelectedTab = this.tabAuthc;
}
break;
}
}
private void OnTouchClick(object sender , Component.TouchEventArgs e)
{
switch (e.Value)
{
case "clear":
{
this.txtQuantity.Text = string.Empty;
this.txtQuantity.Focus();
}
break;
case "accept":
if (this.txtQuantity.DecimalValue > 0)
{
bool isGo = true;
//添加沽清业务规则
SaleClear saleClear = null;
if (SaleClearUtils.Instance.Maps.ContainsKey(this._orderItem.ProductId))
{
saleClear = SaleClearUtils.Instance.Maps[this._orderItem.ProductId];
}
//是否参与沽清
bool isSaleClear = SaleClearUtils.Instance.CheckSaleClear(saleClear);
//参与沽清,已经售完
if (isSaleClear)
{
//沽清剩余数量没有了
if (saleClear.Quantity <= 0)
{
isGo = false;
this.ShowMessage(this.lblInfo , LangProxy.ToLang("沽清售完了") , true);
}
if (isGo)
{
if(saleClear.Quantity <= this.txtQuantity.DecimalValue)
{
isGo = false;
this.ShowMessage(this.lblInfo , LangProxy.ToLang("沽清剩余数量不足") , true);
}
}
}
if (isGo)
{
if (isSaleClear)
{
saleClear.SaleQuantity += (this.txtQuantity.DecimalValue - this._orderItem.Quantity);
SaleClearUtils.Instance.Maps[this._orderItem.ProductId] = saleClear;
}
this._orderItem.Quantity = this.txtQuantity.DecimalValue;
this.OnAcceptButtonClick(new FlyoutEventArgs(FlyoutAction.Accept , e.Value , this._orderItem));
}
}
else
{
this.ShowMessage(this.lblInfo , LangProxy.ToLang("不允许销售数量为零") , true);
}
break;
default:
InputSimulatorUtils.SendKey(KeyCodes.Map[e.Value]);
break;
}
}
/// <summary>
/// 输入框值更改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnInputValueChanged(object sender , EnterEventArg e)
{
if (this.txtQuantity.DecimalValue > 0)
{
this.ShowMessage(this.lblInfo,string.Format(this.lblInfo.Tag.ToString() , this._orderItem.Name) , false);
}
}
/// <summary>
/// 输入框的回车事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnQuantityEnterClick(object sender , EnterEventArg e)
{
this.OnTouchClick(this.touchButtonX4 , new TouchEventArgs(this.touchButtonX4.KeyCode));
}
private void OnTabChanged(object sender, DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs e)
{
var tab = this.tabControl.SelectedTab;
var opt = AuthOperator.None;
Enum.TryParse(tab.Tag.ToString(), out opt);
switch (opt)
{
case AuthOperator.:
{
this.ActiveControl = this.authPanel;
//设置焦点
this.authPanel.SetFocus();
}
break;
case AuthOperator.:
{
this.ActiveControl = this.txtQuantity;
this.txtQuantity.Multiline = false;
this.txtQuantity.Focus();
this.txtQuantity.SelectAll();
}
break;
}
}
private void OnTabChanging(object sender, DevComponents.DotNetBar.SuperTabStripSelectedTabChangingEventArgs e)
{
//是否开启授权
e.Cancel = !Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_AUTO_LOCK_DISABLE, false);
}
}
}