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.

495 lines
21 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.Utils;
using POSV.ShoppingCart;
using POSV.Component;
using POSV.Entity;
namespace POSV.Business
{
[ToolboxItem(false)]
public partial class BargainPanelEx : AbstractFlyoutPanelEx
{
/// <summary>
/// 操作员默认的最大折扣率
/// </summary>
private decimal MaxDiscountRate = Global.Instance.Worker.MaxDiscountRate;
/// <summary>
/// 议价后的新的价格
/// </summary>
private decimal NewAmount = 0;
/// <summary>
/// 当前选择的记录,单品议价依赖
/// </summary>
private OrderItem _orderItem = null;
/// <summary>
/// 整单的记录,,整单议价依赖
/// </summary>
private OrderObject _orderObject = null;
/// <summary>
/// 按键操作
/// </summary>
private ModuleKeyCode _keyCode = ModuleKeyCode.None;
/// <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;
private BargainPanelEx()
{
InitializeComponent();
this.tabControl.TabsVisible = false;
this.Height = this.Height - 30;
}
public BargainPanelEx(ModuleKeyCode keyCode , OrderItem orderItem , OrderObject orderObject, string permissionCode , AuthOperator auth = AuthOperator., Tuple<decimal , decimal , List<string> , Worker> authz = null ) :this()
{
this._orderItem = orderItem;
this._orderObject = orderObject;
this._keyCode = keyCode;
//操作功能的权限码
this._permissionCode = permissionCode;
//授权人综合信息
this._authz = authz;
//如果授权人存在,说明是外部传入,当前操作按照授权人的最高折扣率
if(this._authz != null)
{
this.MaxDiscountRate = this._authz.Item1;
}
//外部传入的操作
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("操作由[{0},{1}]授权" , this._authz.Item4.No , this._authz.Item4.Name);
LogUtils.WriteLog(LogAction. , logInfo , this._authz.Item4.No,this._orderObject.TradeNo);
//修改为授权人的最大折扣率
this.MaxDiscountRate = this._authz.Item1;
this.tabControl.SelectedTab = null;
this.tabControl.SelectedTab = this.tabInput;
this.ShowMessage(this.lblInfo , logInfo);
}
}
break;
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this.SetStyle(ControlStyles.Selectable, true);
switch (this._keyCode)
{
case ModuleKeyCode.:
{
//移除 整单折扣和单品议价
this.tableLayoutPanel.Controls.Remove(this.touchButtonX13);
this.tableLayoutPanel.Controls.Remove(this.touchButtonX5);
//在[3,2]位置添加整单议价
this.tableLayoutPanel.Controls.Add(this.touchButtonX13 , 3 , 2);
this.tableLayoutPanel.SetRowSpan(this.touchButtonX13 , 2);
this.touchButtonX13.Text = "确定";
}
break;
case ModuleKeyCode.:
{
this.tableLayoutPanel.Controls.Remove(this.touchButtonX13);
this.tableLayoutPanel.SetRowSpan(this.touchButtonX5 , 2);
this.touchButtonX5.Text = "确定";
}
break;
}
this.txtBargain.Multiline = false;
this.txtBargain.Focus();
this.txtBargain.SelectAll();
this.ActiveControl = this.txtBargain;
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.txtBargain.Text = string.Empty;
this.txtBargain.Focus();
}
break;
case "close":
{
this.OnCancelButtonClick(new FlyoutEventArgs(FlyoutAction.Cancel , e.Value , null));
}
break;
case "item":
{
if(this._orderItem == null)
{
this.ShowMessage(this.lblInfo , "单品议价当前不可用" , true);
}
else
{
//目前暂不支持议价金额高于售价 && this.txtBargain.DecimalValue <= this._orderItem.Price
if (this.txtBargain.DecimalValue > 0)
{
//是否开启允许低于最低售价销售
bool allowMinPriceSale = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_ALLOW_MIN_PRICE_SALE , false);
//最低售价销售或者权限不足时提示,收银员确认是否继续
bool isGo = true;
if (string.IsNullOrEmpty(this.txtBargain.Text.Trim()))
{
this.ShowMessage(this.lblInfo , "请输入议价金额...." , true);
isGo = false;
}
//当前售价的最高优惠
decimal maxDiscountAmount = this._orderItem.Price * (1 - this.MaxDiscountRate);
//议价后的优惠金额
var bargainAmount = this._orderItem.Price - this.NewAmount;
if (isGo && bargainAmount > maxDiscountAmount)
{
isGo = false;
string info = string.Format("权限不足,议价不低于{0}元" , OrderUtils.ToRound(this._orderItem.Price * this.MaxDiscountRate));
if(this._authz == null)
{
this.ShowMessage(this.lblInfo , info , true);
this.authPanel.SetTitle("单品议价");
//期望的折扣率
decimal expectDiscountRate = this.NewAmount / this._orderItem.Price;
this.authPanel.ExpectValidate(this._permissionCode , expectDiscountRate);
//等待授权操作
this.tabControl.SelectedTab = null;
this.tabControl.SelectedTab = this.tabAuthc;
}
else
{
info = string.Format("授权人权限不足,议价不低于{0}元" , OrderUtils.ToRound(this._orderItem.Price * this.MaxDiscountRate));
this.ShowMessage(this.lblInfo , info , true);
this.txtBargain.SelectAll();
this.txtBargain.Focus();
}
}
//允许低于最低售价
if (isGo && allowMinPriceSale)
{
//低于最低售价销售时提示
bool allowMinPriceSaleNofity = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_MIN_PRICE_SALE_NOTIFY , false);
//低于最低售价销售时提示
if (isGo && allowMinPriceSaleNofity && this.NewAmount < this._orderItem.MinPrice)
{
var dialog = new DialogForm("销售提示信息" , "您确定要低于最低售价销售?" , MessageBoxIcon.Warning , MessageBoxButtons.OKCancel);
if (DialogResult.Cancel == dialog.ShowDialog())
{
isGo = false;
}
}
}
if (isGo && this.NewAmount < this._orderItem.MinPrice)
{
this.ShowMessage(this.lblInfo , "不允许低于最低售价销售" , true);
isGo = false;
}
if (isGo)
{
//单品议价
var promotion = new PromotionItem();
//标识
promotion.Id = IdWorkerUtils.Instance.NextId();
//租户ID
promotion.TenantId = this._orderItem.TenantId;
//订单ID
promotion.OrderId = this._orderItem.OrderId;
//订单编号
promotion.TradeNo = this._orderItem.TradeNo;
//单品编号
promotion.ItemId = this._orderItem.Id;
//类型
promotion.PromotionType = PromotionType.;
//折扣率
promotion.DiscountRate = OrderUtils.ToDiscountPrice(this.NewAmount / this._orderItem.Price);
promotion.DiscountPrice = this.NewAmount;
//是否启用
promotion.Enabled = false;
this.OnAcceptButtonClick(new FlyoutEventArgs(FlyoutAction.Accept , e.Value , promotion));
}
}
else
{
string message = string.Empty;
if (this.txtBargain.DecimalValue == 0)
{
message = "请输入议价金额...";
}
else
{
message = string.Format("议价不允许高于售价{0}元" , this._orderItem.Price);
}
this.ShowMessage(this.lblInfo , message , true);
}
}
}
break;
case "order":
{
if (this._orderObject == null)
{
this.ShowMessage(this.lblInfo , "整单议价当前不可用" , true);
}
else
{
//目前暂不支持议价金额高于总价 && this.txtBargain.DecimalValue <= this._orderObject.Amount
if (this.txtBargain.DecimalValue > 0)
{
//整单议价不控制最低售价
//最低售价销售时提示,收银员确认是否继续
bool isGo = true;
if (string.IsNullOrEmpty(this.txtBargain.Text.Trim()))
{
this.ShowMessage(this.lblInfo , "请输入议价金额...." , true);
isGo = false;
}
//当前售价的最高优惠
decimal maxDiscountAmount = this._orderObject.Amount * (1 - this.MaxDiscountRate);
//议价后的优惠金额
var bargainAmount = this._orderObject.Amount - this.NewAmount;
if (isGo && bargainAmount > maxDiscountAmount)
{
isGo = false;
string info = string.Format("权限不足,总价不低于{0}元" , OrderUtils.ToRound(this._orderObject.Amount * this.MaxDiscountRate));
if (this._authz == null)
{
this.ShowMessage(this.lblInfo , info , true);
this.authPanel.SetTitle("整单议价");
//期望的折扣率
decimal expectDiscountRate = this.NewAmount / this._orderObject.Amount;
this.authPanel.ExpectValidate(this._permissionCode , expectDiscountRate);
//等待授权操作
this.tabControl.SelectedTab = null;
this.tabControl.SelectedTab = this.tabAuthc;
}
else
{
info = string.Format("授权人权限不足,议价不低于{0}元" , OrderUtils.ToRound(this._orderObject.Amount * this.MaxDiscountRate));
this.ShowMessage(this.lblInfo , info , true);
this.txtBargain.SelectAll();
this.txtBargain.Focus();
}
}
if (isGo)
{
//整单议价
var promotion = new PromotionOrder();
//标识
promotion.Id = IdWorkerUtils.Instance.NextId();
//租户ID
promotion.TenantId = this._orderObject.TenantId;
//订单ID
promotion.OrderId = this._orderObject.Id;
//订单编号
promotion.TradeNo = this._orderObject.TradeNo;
//单品编号
promotion.ItemId = string.Empty;
//类型
promotion.PromotionType = PromotionType.;
//折扣率
promotion.DiscountRate = OrderUtils.ToRound(this.NewAmount / this._orderObject.Amount);
//优惠前金额
promotion.Amount = this._orderObject.Amount;
//优惠金额
promotion.DiscountAmount = this._orderObject.Amount - this.NewAmount;
//整单议价后的金额
promotion.ReceivableAmount = this.NewAmount;
//是否启用
promotion.Enabled = false;
this.OnAcceptButtonClick(new FlyoutEventArgs(FlyoutAction.Accept , e.Value , promotion));
}
}
else
{
string message = string.Empty;
if (this.txtBargain.DecimalValue == 0)
{
message = "请输入议价金额....";
}
else
{
message = string.Format("议价不允许高于总价{0}元" , this._orderObject.Amount);
}
this.ShowMessage(this.lblInfo , message , true);
}
}
}
break;
default:
InputSimulatorUtils.SendKey(KeyCodes.Map[e.Value]);
break;
}
}
private void OnValueChanged(object sender , EnterEventArg e)
{
//议价后新的价格
this.NewAmount = this.txtBargain.DecimalValue;
}
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.txtBargain;
this.txtBargain.Multiline = false;
this.txtBargain.Focus();
this.txtBargain.SelectAll();
}
break;
}
}
private void OnTabChanging(object sender , DevComponents.DotNetBar.SuperTabStripSelectedTabChangingEventArgs e)
{
//是否开启授权
e.Cancel = !Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_AUTO_LOCK_DISABLE , false);
}
}
}