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 POSV.Component;
using POSV.Utils;
using POS.Language.Language;
namespace POSV.Business
{
[ToolboxItem(false)]
public partial class ErectPanelEx : AbstractFlyoutPanelEx
{
///
/// 操作员默认的最大折扣率
///
private decimal MaxDiscountRate = Global.Instance.Worker.MaxDiscountRate;
///
/// 当前选择的记录,单品立减依赖
///
private OrderItem _orderItem = null;
///
/// 立减的金额
///
private decimal NewAmount = 0;
///
/// 整单的记录,,整单立减依赖
///
private OrderObject _orderObject = null;
///
/// 按键操作
///
private ModuleKeyCode _keyCode = ModuleKeyCode.None;
///
/// 权限控制码
///
private string _permissionCode = string.Empty;
///
/// 授权人权限信息
///
private Tuple, Worker> _authz = null;
///
/// 授权界面或者录入界面切换
///
private AuthOperator _auth = AuthOperator.None;
public ErectPanelEx()
{
InitializeComponent();
this.tabControl.TabsVisible = false;
this.Height = this.Height - 30;
}
public ErectPanelEx(ModuleKeyCode keyCode, OrderItem orderItem, OrderObject orderObject, string permissionCode, AuthOperator auth = AuthOperator.输入操作, Tuple, 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);
}
///
/// 授权事件
///
///
///
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, Worker>)
{
this._authz = e.Data as Tuple, 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._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 = LangProxy.ToLang("确定");
}
break;
case ModuleKeyCode.单品立减:
{
this.tableLayoutPanel.Controls.Remove(this.touchButtonX13);
this.tableLayoutPanel.SetRowSpan(this.touchButtonX5, 2);
this.touchButtonX5.Text = LangProxy.ToLang("确定");
}
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 OnValueChanged(object sender, Component.EnterEventArg e)
{
//立减的金额
this.NewAmount = this.txtBargain.DecimalValue;
}
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":
{
//单品议价
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.DiscountAmount = this.NewAmount;
//是否启用
promotion.Enabled = false;
this.OnAcceptButtonClick(new FlyoutEventArgs(FlyoutAction.Accept, e.Value, promotion));
}
break;
case "order":
{
//单品议价
var promotion = new PromotionOrder();
//标识
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.DiscountAmount = this.NewAmount;
//是否启用
promotion.Enabled = false;
this.OnAcceptButtonClick(new FlyoutEventArgs(FlyoutAction.Accept, e.Value, promotion));
}
break;
default:
InputSimulatorUtils.SendKey(KeyCodes.Map[e.Value]);
break;
}
}
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);
}
}
}