|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Windows.Forms;
|
|
|
using POSV.ShoppingCart;
|
|
|
using POSV.Entity;
|
|
|
using DevComponents.DotNetBar;
|
|
|
using DevComponents.DotNetBar.Metro;
|
|
|
using POSV.Utils;
|
|
|
using POSV.Component;
|
|
|
using POSV.Template;
|
|
|
using POS.Language.Language;
|
|
|
|
|
|
namespace POSV.Business
|
|
|
{
|
|
|
public partial class FlavorPanelEx : AbstractFlyoutPanelEx
|
|
|
{
|
|
|
private int DefaultCategoryItemWidth = 93;
|
|
|
|
|
|
private Size DefaultMainMenuSize = Size.Empty;
|
|
|
|
|
|
private int DefaultPaddingLeftRight = -2;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 选中行数据
|
|
|
/// </summary>
|
|
|
private readonly OrderItem _orderItem = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 权限控制码
|
|
|
/// </summary>
|
|
|
private string _permissionCode = string.Empty;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 授权人权限信息
|
|
|
/// </summary>
|
|
|
private Tuple<decimal , decimal , List<string> , Worker> _authz = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 做法类型数据源
|
|
|
/// </summary>
|
|
|
private List<ProductMakeType> _makeTypeList = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 做法数据源
|
|
|
/// </summary>
|
|
|
private List<ProductMakeDetail> _makeDetailList = null;
|
|
|
|
|
|
private MetroTileItem _currentFlavorItem = null;
|
|
|
|
|
|
public FlavorPanelEx(OrderItem item , string permissionCode , Tuple<decimal , decimal , List<string> , Worker> authz = null)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
this._orderItem = item;
|
|
|
|
|
|
this.bottomPanel.Text = this._orderItem.Name;
|
|
|
|
|
|
//当前只有一个分类,暂不显示
|
|
|
this.tabControl.TabsVisible = false;
|
|
|
|
|
|
this.Height = this.Height - 30;
|
|
|
|
|
|
//操作功能的权限码
|
|
|
this._permissionCode = permissionCode;
|
|
|
|
|
|
//授权人综合信息
|
|
|
this._authz = authz;
|
|
|
|
|
|
}
|
|
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
{
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
this.SetStyle(ControlStyles.Selectable , true);
|
|
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
|
|
this._makeTypeList = new List<ProductMakeType>();
|
|
|
ProductMakeType productMakeType = new ProductMakeType();
|
|
|
productMakeType.SeqNo = -10;
|
|
|
productMakeType.Name = LangProxy.ToLang("全部");
|
|
|
this._makeTypeList.Add(productMakeType);
|
|
|
//做法分类数据源
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
|
{
|
|
|
List<ProductMakeType> makeTypeListTemp = db.Query<ProductMakeType>().OrderBy(x => x.SeqNo).ToList();
|
|
|
if (makeTypeListTemp != null)
|
|
|
{
|
|
|
this._makeTypeList.AddRange(makeTypeListTemp);
|
|
|
}
|
|
|
}
|
|
|
//做法分类
|
|
|
this.mainCategoryPage.OnPageChange += OnMainCategoryPageChange;
|
|
|
DefaultMainMenuSize = new Size(DefaultCategoryItemWidth, this.mainCategoryPage.Height);
|
|
|
//做法数据源
|
|
|
this._makeDetailList = BusinessUtils.Instance.GetMakesByProductId(this._orderItem.ProductId);
|
|
|
|
|
|
//已选择的做法
|
|
|
this.RefreshSelected(this._orderItem.Flavors ,null);
|
|
|
|
|
|
//加载全部做法
|
|
|
this.RefreshMain();
|
|
|
}
|
|
|
private void OnMainCategoryPageChange(object sender, EventArgs e)
|
|
|
{
|
|
|
RefreshMain();
|
|
|
}
|
|
|
|
|
|
private void RefreshMain()
|
|
|
{
|
|
|
ItemContainer ic = new ItemContainer();
|
|
|
|
|
|
MetroTileItem firstItem = null;
|
|
|
if (this._makeTypeList != null && this._makeTypeList.Count > 0)
|
|
|
{
|
|
|
this.mainCategoryPage.TotalCount = this._makeTypeList.Count;
|
|
|
this.mainCategoryPage.itemWidth = DefaultCategoryItemWidth;
|
|
|
//分页
|
|
|
var pageTypeList = this.mainCategoryPage.ListPager<ProductMakeType>(this._makeTypeList);
|
|
|
|
|
|
ic.MultiLine = false;
|
|
|
ic.ItemSpacing = 1;
|
|
|
ic.ResizeItemsToFit = false; //很关键
|
|
|
|
|
|
foreach (var type in pageTypeList)
|
|
|
{
|
|
|
MetroTileItem item = new MetroTileItem();
|
|
|
|
|
|
item.CheckBehavior = eMetroTileCheckBehavior.None;
|
|
|
item.Checked = false;
|
|
|
|
|
|
item.OptionGroup = "MainMenu";
|
|
|
|
|
|
item.TileStyle.TextAlignment = eStyleTextAlignment.Center;
|
|
|
item.Text = type.Name;
|
|
|
item.TileSize = DefaultMainMenuSize;
|
|
|
|
|
|
item.TileStyle.TextColor = Color.White;
|
|
|
item.TileStyle.BackColor = ColorTranslator.FromHtml("#333333");
|
|
|
item.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333");
|
|
|
item.TileStyle.BorderColor = Color.Transparent;
|
|
|
item.TileStyle.BorderColor2 = Color.Transparent;
|
|
|
|
|
|
item.TileStyle.PaddingLeft = DefaultPaddingLeftRight;
|
|
|
item.TileStyle.PaddingRight = DefaultPaddingLeftRight;
|
|
|
|
|
|
item.Tag = type;
|
|
|
|
|
|
if (firstItem == null)
|
|
|
{
|
|
|
firstItem = item;
|
|
|
}
|
|
|
|
|
|
item.MouseDown += OnMainMenuMouseDown;
|
|
|
item.CheckedChanged += OnMainItemCheckedChange;
|
|
|
ic.SubItems.Add(item);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
this.mainCategoryPage.RefreshUI(ic);
|
|
|
|
|
|
if (firstItem != null)
|
|
|
{
|
|
|
firstItem.Checked = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 加载子菜单
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void OnMainMenuMouseDown(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
|
obj.Checked = true;
|
|
|
}
|
|
|
|
|
|
private void OnMainItemCheckedChange(object sender, EventArgs e)
|
|
|
{
|
|
|
MetroTileItem obj = sender as MetroTileItem;
|
|
|
if (obj.Checked)
|
|
|
{
|
|
|
obj.TileStyle.BackColor = ColorTranslator.FromHtml("#993366");
|
|
|
obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#993366");
|
|
|
|
|
|
//加载子类
|
|
|
var type = obj.Tag as ProductMakeType;
|
|
|
//加载大类下商品
|
|
|
LoadMaterialDetail(type);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
obj.TileStyle.BackColor = ColorTranslator.FromHtml("#333333");
|
|
|
obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void LoadMaterialDetail(ProductMakeType type)
|
|
|
{
|
|
|
this.BuilderAll(type);
|
|
|
}
|
|
|
|
|
|
private void BuilderAll(ProductMakeType type)
|
|
|
{
|
|
|
//this.metroTilePanel.Items.Clear();
|
|
|
|
|
|
//ItemContainer itemContainer = new ItemContainer();
|
|
|
//itemContainer.ItemSpacing = 0;
|
|
|
//itemContainer.Orientation = eOrientation.Vertical;
|
|
|
//itemContainer.MultiLine = true;
|
|
|
//itemContainer.TitleStyle.Class = "MetroTileGroupTitle";
|
|
|
|
|
|
//ElementStyle style = (ElementStyle)itemContainer.TitleStyle;
|
|
|
//style.Font = Constant.BIG_FONT;
|
|
|
//style.TextColor = Color.Black;
|
|
|
//style.PaddingBottom = -1;
|
|
|
//style.PaddingLeft = style.PaddingRight = -1;
|
|
|
//if (type!=null && !string.IsNullOrEmpty(type.Id)) {
|
|
|
// BuilderMakeDetail(itemContainer, type);
|
|
|
//}
|
|
|
//else {
|
|
|
// foreach (var makeType in this._makeTypeList)
|
|
|
// {
|
|
|
// BuilderMakeDetail(itemContainer, makeType);
|
|
|
// }
|
|
|
//}
|
|
|
//this.metroTilePanel.Items.Add(itemContainer);
|
|
|
//this.metroTilePanel.Invalidate();
|
|
|
var lists = new List<ProductMakeDetail>();
|
|
|
if (string.IsNullOrEmpty(type.Id))
|
|
|
{
|
|
|
lists = this._makeDetailList;
|
|
|
}
|
|
|
else {
|
|
|
lists = this._makeDetailList.FindAll(x => x.TypeId == type.Id);
|
|
|
}
|
|
|
//做法数据源
|
|
|
//List<ProductMakeDetail> _makeDetailList = BusinessUtils.Instance.GetMakesByProductId(orderItem.ProductId);
|
|
|
this.makeControl.BindDataSource(lists, 1);
|
|
|
}
|
|
|
|
|
|
private void BuilderMakeDetail(ItemContainer itemContainer , ProductMakeType type)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(type.Id)) {
|
|
|
//如果是全部做法直接返回
|
|
|
return;
|
|
|
}
|
|
|
var lists = this._makeDetailList.FindAll(x => x.TypeId == type.Id);
|
|
|
|
|
|
//是否已经选择该做法
|
|
|
//var flavors = this._orderItem.Flavors;
|
|
|
|
|
|
|
|
|
foreach (var detail in lists)
|
|
|
{
|
|
|
|
|
|
MetroTileItem tileItem = new MetroTileItem();
|
|
|
|
|
|
tileItem.TileStyle.PaddingLeft = tileItem.TileStyle.PaddingRight = -1;
|
|
|
|
|
|
if (type.IsRadio == 1)
|
|
|
{
|
|
|
tileItem.OptionGroup = detail.TypeId;
|
|
|
//做法单选或者多选情况下的Key
|
|
|
tileItem.Description = detail.TypeId;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tileItem.OptionGroup = string.Empty;
|
|
|
//做法单选或者多选情况下的Key
|
|
|
tileItem.Description = detail.Id;
|
|
|
}
|
|
|
|
|
|
tileItem.SymbolColor = Color.Empty;
|
|
|
tileItem.TileSize = new Size(79, 50);
|
|
|
tileItem.TileStyle.CornerType = eCornerType.Square;
|
|
|
tileItem.TileStyle.Font = Constant.NORMAL_FONT;
|
|
|
|
|
|
tileItem.TileStyle.TextAlignment = eStyleTextAlignment.Center;
|
|
|
tileItem.TileStyle.TextLineAlignment = eStyleTextAlignment.Center;
|
|
|
|
|
|
if (detail.AddPrice > 0)
|
|
|
{
|
|
|
tileItem.TitleText = string.Format("{0}{1}" , Constant.CNY , detail.AddPrice);
|
|
|
|
|
|
tileItem.TitleTextAlignment = ContentAlignment.BottomCenter;
|
|
|
tileItem.TitleTextFont = Constant.SMALL_FONT;
|
|
|
|
|
|
tileItem.TileStyle.TextLineAlignment = eStyleTextAlignment.Near;
|
|
|
}
|
|
|
|
|
|
//做法名称
|
|
|
tileItem.Text = detail.Memo;
|
|
|
//做法分类对应的背景颜色
|
|
|
tileItem.TileStyle.BackColor = tileItem.TileStyle.BackColor2 = ColorTranslator.FromHtml(type.Color);
|
|
|
//去除边框颜色
|
|
|
tileItem.TileStyle.BorderColor = tileItem.TileStyle.BorderColor2 = Color.Transparent;
|
|
|
|
|
|
//将当前的对象缓存到Tag中,为鼠标操作提供支持
|
|
|
FlavorItem flavor = new FlavorItem();
|
|
|
|
|
|
flavor.Id = IdWorkerUtils.Instance.NextId();
|
|
|
|
|
|
//做法单选或者多选情况下的Key
|
|
|
flavor.Group = tileItem.Description;
|
|
|
flavor.TenantId = this._orderItem.TenantId;
|
|
|
flavor.TradeNo = this._orderItem.TradeNo;
|
|
|
|
|
|
flavor.OrderId = this._orderItem.OrderId;
|
|
|
flavor.ItemId = this._orderItem.Id;
|
|
|
|
|
|
flavor.Name = detail.Memo;
|
|
|
flavor.MakeId = detail.Id;
|
|
|
flavor.Code = detail.No;
|
|
|
flavor.QtyFlag = detail.QtyFlag;
|
|
|
flavor.Price = detail.AddPrice;
|
|
|
|
|
|
|
|
|
flavor.Type = type.Type;
|
|
|
flavor.IsRadio = type.IsRadio;
|
|
|
|
|
|
tileItem.Tag = flavor;
|
|
|
|
|
|
|
|
|
tileItem.MouseDown += TileItemMouseDown;
|
|
|
tileItem.CheckedChanged += TileItemCheckedChanged;
|
|
|
|
|
|
|
|
|
itemContainer.SubItems.Add(tileItem);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void RefreshSelected(List<FlavorItem> items,FlavorItem newItem)
|
|
|
{
|
|
|
//清空历史数据
|
|
|
this.itemPanel.Items.Clear();
|
|
|
|
|
|
ItemContainer ic = new ItemContainer();
|
|
|
|
|
|
ic.MultiLine = true;
|
|
|
ic.ItemSpacing = 0;
|
|
|
ic.LayoutOrientation = eOrientation.Horizontal;
|
|
|
|
|
|
foreach(var entity in items)
|
|
|
{
|
|
|
MetroTileItem item = this.GetItemTemplate();
|
|
|
|
|
|
item.TileStyle.Font = Constant.NORMAL_FONT;
|
|
|
item.TitleTextAlignment = ContentAlignment.BottomCenter;
|
|
|
item.TitleTextFont = Constant.SMALL_FONT;
|
|
|
item.TileStyle.TextLineAlignment = eStyleTextAlignment.Near;
|
|
|
item.TileStyle.TextAlignment = eStyleTextAlignment.Center;
|
|
|
|
|
|
if (entity.Price > 0)
|
|
|
{
|
|
|
item.TitleText = string.Format("{0}{1}*{2}" , Constant.CNY, entity.Price , entity.Quantity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
item.TitleText = string.Format("{0}" , entity.Quantity.ToString());
|
|
|
}
|
|
|
|
|
|
|
|
|
item.Text = entity.Name;
|
|
|
|
|
|
//做法分类对应的背景颜色
|
|
|
item.TileStyle.BackColor = item.TileStyle.BackColor2 = ColorTranslator.FromHtml(entity.Color);
|
|
|
//去除边框颜色
|
|
|
item.TileStyle.BorderColor = item.TileStyle.BorderColor2 = Color.Transparent;
|
|
|
|
|
|
item.EnableMarkup = true;
|
|
|
|
|
|
if (newItem != null && newItem.Group.Equals(entity.Group))
|
|
|
{
|
|
|
item.Checked = true;
|
|
|
|
|
|
this._currentFlavorItem = item;
|
|
|
}
|
|
|
|
|
|
item.MouseDown += OnSelectedItemMouseDown;
|
|
|
|
|
|
item.Tag = entity;
|
|
|
|
|
|
ic.SubItems.Add(item);
|
|
|
}
|
|
|
|
|
|
this.itemPanel.Items.Add(ic);
|
|
|
this.itemPanel.Invalidate();
|
|
|
}
|
|
|
|
|
|
private void OnSelectedItemMouseDown(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
if (sender is MetroTileItem)
|
|
|
{
|
|
|
var item = sender as MetroTileItem;
|
|
|
var flavor = item.Tag as FlavorItem;
|
|
|
|
|
|
this._orderItem.Flavors.Remove(flavor);
|
|
|
|
|
|
this._currentFlavorItem = null;
|
|
|
|
|
|
//通知主界面改变
|
|
|
this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify, this._orderItem));
|
|
|
//刷新已选择做法
|
|
|
this.RefreshSelected(this._orderItem.Flavors, null);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private MetroTileItem GetItemTemplate()
|
|
|
{
|
|
|
MetroTileItem template = new MetroTileItem();
|
|
|
|
|
|
template.TileStyle.PaddingLeft = template.TileStyle.PaddingRight = -2;
|
|
|
|
|
|
template.EnableMarkup = true;
|
|
|
template.OptionGroup = "Flavors";
|
|
|
|
|
|
template.TileStyle.Font = Constant.NORMAL_FONT;
|
|
|
|
|
|
//显示大小
|
|
|
template.TileSize = new Size(79 , 55);
|
|
|
|
|
|
template.MouseDown += OnItemMouseDown;
|
|
|
|
|
|
return template;
|
|
|
}
|
|
|
|
|
|
private void OnItemMouseDown(object sender , MouseEventArgs e)
|
|
|
{
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
{
|
|
|
MetroTileItem item = (MetroTileItem)sender;
|
|
|
|
|
|
item.Checked = !item.Checked;
|
|
|
|
|
|
//标识为当前活跃,便于数量修改
|
|
|
item.Checked = true;
|
|
|
item.TileColor = eMetroTileColor.Coffee;
|
|
|
|
|
|
this._currentFlavorItem = item;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void TileItemMouseDown(object sender , MouseEventArgs e)
|
|
|
{
|
|
|
MetroTileItem item = (MetroTileItem)sender;
|
|
|
|
|
|
var newItem = ObjectUtils.Copy<FlavorItem>(item.Tag as FlavorItem);
|
|
|
|
|
|
//当前的位置
|
|
|
int inx = this._orderItem.Flavors.Count;
|
|
|
//如果做法中已经包含当前操作的,调整数量
|
|
|
if (this._orderItem.Flavors.Exists(x => x.Group == newItem.Group))
|
|
|
{
|
|
|
var _oldItem = this._orderItem.Flavors.Find(x => x.Group == newItem.Group);
|
|
|
//在当前的位置
|
|
|
inx = this._orderItem.Flavors.IndexOf(_oldItem);
|
|
|
//如果单选,基准数量重置为1,否则基准数量自动加1
|
|
|
if (newItem.IsRadio == 1)
|
|
|
{
|
|
|
newItem.BaseQuantity = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
newItem.BaseQuantity = _oldItem.BaseQuantity + 1;
|
|
|
}
|
|
|
//删除
|
|
|
this._orderItem.Flavors.Remove(_oldItem);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//基准数量
|
|
|
newItem.BaseQuantity = 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newItem.OrderItemQuantity = this._orderItem.Quantity;
|
|
|
|
|
|
|
|
|
//存入新位置
|
|
|
this._orderItem.Flavors.Insert(inx, newItem);
|
|
|
//通知主界面改变
|
|
|
this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify , this._orderItem));
|
|
|
//刷新已选择做法
|
|
|
this.RefreshSelected(this._orderItem.Flavors,newItem);
|
|
|
}
|
|
|
|
|
|
private void TileItemCheckedChanged(object sender , EventArgs e)
|
|
|
{
|
|
|
MetroTileItem item = (MetroTileItem)sender;
|
|
|
}
|
|
|
|
|
|
private void FlavorItemDeleteAll(object sender , EventArgs e)
|
|
|
{
|
|
|
this._currentFlavorItem = null;
|
|
|
|
|
|
this._orderItem.Flavors.Clear();
|
|
|
|
|
|
//通知主界面改变
|
|
|
this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify , this._orderItem));
|
|
|
//刷新已选择做法
|
|
|
this.RefreshSelected(this._orderItem.Flavors,null);
|
|
|
}
|
|
|
|
|
|
private void OnCloseClick(object sender, EventArgs e)
|
|
|
{
|
|
|
this.OnCancelButtonClick(null);
|
|
|
}
|
|
|
|
|
|
//手工做法
|
|
|
private void OnHandClick(object sender, EventArgs e)
|
|
|
{
|
|
|
TxtKeyboardForm txtForm = new TxtKeyboardForm(string.Empty);
|
|
|
txtForm.NotifyChanged += (o, args) =>
|
|
|
{
|
|
|
switch (args.Action)
|
|
|
{
|
|
|
case NotifyAction.Accept:
|
|
|
{
|
|
|
var result = args.Data as string;
|
|
|
BuildHandFlavor(result);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
txtForm.ShowDialog();
|
|
|
}
|
|
|
|
|
|
private void BuildHandFlavor(string name)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
FlavorItem flavor = new FlavorItem();
|
|
|
|
|
|
flavor.Id = IdWorkerUtils.Instance.NextId();
|
|
|
|
|
|
//做法单选或者多选情况下的Key
|
|
|
flavor.Group = flavor.Id;
|
|
|
flavor.TenantId = this._orderItem.TenantId;
|
|
|
flavor.TradeNo = this._orderItem.TradeNo;
|
|
|
|
|
|
flavor.OrderId = this._orderItem.OrderId;
|
|
|
flavor.ItemId = this._orderItem.Id;
|
|
|
|
|
|
flavor.Name = name;
|
|
|
flavor.MakeId = flavor.Id;
|
|
|
flavor.Code = "000";
|
|
|
flavor.QtyFlag = 1;
|
|
|
flavor.Price = 0.00M;
|
|
|
|
|
|
|
|
|
flavor.Type = 0;
|
|
|
flavor.IsRadio = 1;
|
|
|
flavor.Hand = 1;
|
|
|
|
|
|
//当前的位置
|
|
|
int inx = this._orderItem.Flavors.Count;
|
|
|
//基准数量
|
|
|
flavor.BaseQuantity = 1;
|
|
|
|
|
|
flavor.OrderItemQuantity = this._orderItem.Quantity;
|
|
|
|
|
|
|
|
|
//存入新位置
|
|
|
this._orderItem.Flavors.Insert(inx, flavor);
|
|
|
//通知主界面改变
|
|
|
this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify, this._orderItem));
|
|
|
//刷新已选择做法
|
|
|
this.RefreshSelected(this._orderItem.Flavors, flavor);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 选择做法事件
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void OnProductMakeCheckedChanged(object sender, Template.Component.ProductMakeEventArgs e)
|
|
|
{
|
|
|
//MetroTileItem item = (MetroTileItem)sender;
|
|
|
var make = e.ProductMakeDetail;
|
|
|
//获取做法类型
|
|
|
var type = BusinessUtils.Instance.GetMakeTypeById(make.TypeId);
|
|
|
if (type == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
var newItem = new FlavorItem();
|
|
|
newItem.Id = IdWorkerUtils.Instance.NextId();
|
|
|
|
|
|
|
|
|
newItem.TenantId = this._orderItem.TenantId;
|
|
|
newItem.TradeNo = this._orderItem.TradeNo;
|
|
|
|
|
|
newItem.OrderId = this._orderItem.OrderId;
|
|
|
newItem.ItemId = this._orderItem.Id;
|
|
|
|
|
|
newItem.Name = make.Memo;
|
|
|
newItem.MakeId = make.Id;
|
|
|
newItem.Code = make.No;
|
|
|
newItem.QtyFlag = make.QtyFlag;
|
|
|
newItem.Price = make.AddPrice;
|
|
|
|
|
|
|
|
|
newItem.Type = type.Type;
|
|
|
newItem.IsRadio = type.IsRadio;
|
|
|
|
|
|
//做法单选或者多选情况下的Key
|
|
|
if (newItem.IsRadio == 1)
|
|
|
{
|
|
|
newItem.Group = make.TypeId;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
newItem.Group = make.Id;
|
|
|
}
|
|
|
|
|
|
//当前的位置
|
|
|
int inx = this._orderItem.Flavors.Count;
|
|
|
//如果做法中已经包含当前操作的,调整数量
|
|
|
if (this._orderItem.Flavors.Exists(x => x.Group == newItem.Group))
|
|
|
{
|
|
|
var _oldItem = this._orderItem.Flavors.Find(x => x.Group == newItem.Group);
|
|
|
//在当前的位置
|
|
|
inx = this._orderItem.Flavors.IndexOf(_oldItem);
|
|
|
//如果单选,基准数量重置为1,否则基准数量自动加1
|
|
|
if (newItem.IsRadio == 1)
|
|
|
{
|
|
|
newItem.BaseQuantity = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
newItem.BaseQuantity = _oldItem.BaseQuantity + 1;
|
|
|
}
|
|
|
//删除
|
|
|
this._orderItem.Flavors.Remove(_oldItem);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//基准数量
|
|
|
newItem.BaseQuantity = 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newItem.OrderItemQuantity = this._orderItem.Quantity;
|
|
|
|
|
|
|
|
|
//存入新位置
|
|
|
this._orderItem.Flavors.Insert(inx, newItem);
|
|
|
//通知主界面改变
|
|
|
this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify, this._orderItem));
|
|
|
//刷新已选择做法
|
|
|
this.RefreshSelected(this._orderItem.Flavors, newItem);
|
|
|
}
|
|
|
}
|
|
|
}
|