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.Entity; using POSV.ShoppingCart; using DevComponents.DotNetBar; using DevComponents.DotNetBar.Metro; using POSV.Utils; namespace POSV.Business { public partial class SuitPanelEx : AbstractFlyoutPanelEx { /// /// 套餐主菜的信息,道菜加价后主菜单价会改变 /// private readonly OrderItem _master = null; /// /// 选中行数据 /// private readonly List _selected = null; /// /// 道菜 /// private List _suitList = null; /// /// 道菜明细 /// private List _suitDetailList = null; /// /// 权限控制码 /// private string _permissionCode = string.Empty; /// /// 授权人权限信息 /// private Tuple , Worker> _authz = null; public SuitPanelEx(List rows , string permissionCode , Tuple , Worker> authz = null) { InitializeComponent(); this._selected = rows; //操作功能的权限码 this._permissionCode = permissionCode; //授权人综合信息 this._authz = authz; //套餐主菜的信息,道菜加价后主菜单价会改变 var _parent = this._selected.Find(x => x.RowState == OrderRowState.套餐主); if (_parent != null) { this._master = ObjectUtils.Copy(_parent); } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; //商品ID var productId = this._master.ProductId; lock (Global.Instance.SyncLock) { using (var db = Global.Instance.OpenDataBase) { this._suitList = db.Query("where productId = @0" , productId).ToList(); this._suitDetailList = db.Fetch(string.Format(SqlConstant.SuitExt , productId)); } } if (this._suitList == null) { this._suitList = new List(); } if (this._suitDetailList == null) { this._suitDetailList = new List(); } this.BuilderAll(); } private void BuilderAll() { this.metroTilePanel.Items.Clear(); this.metroTilePanel.BackgroundStyle.Class = "MetroTileGroupTitle"; this.metroTilePanel.LayoutOrientation = eOrientation.Horizontal; foreach (var suit in this._suitList) { ItemContainer itemContainer = new ItemContainer(); itemContainer.Name = suit.No; itemContainer.Orientation = eOrientation.Horizontal; itemContainer.MultiLine = true; itemContainer.TitleStyle.Class = "MetroTileGroupTitle"; itemContainer.TitleText = suit.Name; itemContainer.ItemSpacing = 0; ElementStyle style = (ElementStyle)itemContainer.TitleStyle; style.Font = Constant.BIG_FONT; style.TextColor = Color.Black; style.BackColor = Color.Bisque; style.PaddingBottom = -1; style.PaddingLeft = style.PaddingRight = -1; this.BuilderSuitDetail(itemContainer , suit); this.metroTilePanel.Items.Add(itemContainer); } this.metroTilePanel.Invalidate(); } private void BuilderSuitDetail(ItemContainer itemContainer , ProductSuit suit) { var lists = this._suitDetailList.FindAll(x => x.SuitId == suit.Id); foreach (var detail in lists) { MetroTileItem tileItem = new MetroTileItem(); tileItem.OptionGroup = detail.SuitId; tileItem.TileSize = new Size(90 , 60); tileItem.TileStyle.Font = Constant.DEFAULT_FONT; tileItem.TitleTextAlignment = ContentAlignment.BottomCenter; tileItem.TitleTextFont = Constant.NORMAL_FONT; tileItem.TileStyle.PaddingLeft = tileItem.TileStyle.PaddingRight = -1; tileItem.TileStyle.TextAlignment = eStyleTextAlignment.Center; tileItem.TileStyle.TextLineAlignment = eStyleTextAlignment.Center; if (detail.AddPrice > 0) { tileItem.TileStyle.TextLineAlignment = eStyleTextAlignment.Near; tileItem.TitleText = string.Format("{0}{1}*{2}" , Constant.CNY,detail.AddPrice,detail.Quantity); tileItem.TileStyle.PaddingBottom = -1; } if(detail.SpecCount > 1) { tileItem.Text = string.Format("{0}[{1}]" , detail.Name , detail.SpecName); } else { tileItem.Text = string.Format("{0}" , detail.Name); } //查找具体的单个套菜明细 var obj = this._selected.Find(x => x.SuitId.Equals(detail.SuitId) && x.SpecId.Equals(detail.SpecId)); tileItem.Checked = (obj != null); tileItem.TileColor = tileItem.Checked ? eMetroTileColor.RedOrange : eMetroTileColor.Coffee; tileItem.Tag = detail; tileItem.MouseDown += TileItemMouseDown; tileItem.CheckedChanged += TileItemCheckedChanged; itemContainer.SubItems.Add(tileItem); } } private void TileItemMouseDown(object sender , MouseEventArgs e) { MetroTileItem item = (MetroTileItem)sender; item.Checked = true; } private void TileItemCheckedChanged(object sender , EventArgs e) { MetroTileItem item = (MetroTileItem)sender; if (item.Checked) { item.TileColor = eMetroTileColor.RedOrange; var newItem = item.Tag as SuitExt; //查找具体的单个套菜明细 var oldItem = this._selected.Find(x => x.SuitId.Equals(newItem.SuitId)); //将当前SuitExt序列化 var json = JsonUtils.Serialize(newItem); //反序列化为ProductExt对象 var product = JsonUtils.Deserialize(json); oldItem.ProductExt = product; oldItem.SalePrice = product.Price; //默认情况下,零售价和售价一样,零售价主要解决前台售价为0的商品,需要录入的售价 oldItem.Price = product.Price; //默认情况下,折后单价和零售价一样 oldItem.DiscountPrice = product.Price; //单品最低售价 oldItem.MinPrice = product.MinPrice; //会员价 oldItem.MemberPrice = product.MemberPrice; //会员价(原) oldItem.MemberSalePrice = product.MemberPrice; //批发价 oldItem.DispatchPrice = product.DispatchPrice; //第三方价 oldItem.OtherPrice = product.OtherPrice; //商品ID oldItem.ProductId = product.Id; //商品编号 oldItem.ProductNo = product.No; //单品名称 oldItem.Name = product.Name; //单品简称 oldItem.ShortName = product.ShortName; //规格ID oldItem.SpecId = product.SpecId; //规格名称 oldItem.SpecName = product.SpecName; //品类ID oldItem.TypeId = product.TypeId; //品类名称 oldItem.TypeName = product.TypeName; //商品单位ID oldItem.ProductUnitId = product.UnitId; //商品单位名称 oldItem.ProductUnitName = product.UnitName; //厨打标识 oldItem.Chuda = product.Chuda; oldItem.ChudaFlag = product.ChudaFlag; oldItem.ChudaQty = 0; //出品标识 oldItem.Chupin = product.Chupin; oldItem.ChupinFlag = product.ChupinFlag; oldItem.ChupinQty = 0; //厨打标签标示 oldItem.ChuDaLabel = product.ChuDaLabel; oldItem.ChuDaLabelFlag = product.ChuDaLabelFlag; oldItem.ChuDaLabelQty = 0; //标签标识 oldItem.LabelPrintFlag = product.LabelPrintFlag; oldItem.LabelQty = 0; //厨显标示 oldItem.Chuxian = product.Chuxian; oldItem.ChuxianFlag = product.ChuxianFlag; oldItem.ChuxianQty = 0; oldItem.ChuxianTime = product.ChuxianTime; //kds出品 oldItem.KdsChupin = product.KdsChupin; oldItem.KdsChupinFlag = product.KdsChupinFlag; oldItem.KdsChupinQty = 0; oldItem.KdsChupinTime = product.KdsChupinTime; oldItem.RowState = OrderRowState.套餐明; //道菜ID oldItem.SuitId = newItem.SuitId; //道菜基准数量 oldItem.SuitQuantity = newItem.Quantity; //道菜基准加价 oldItem.SuitAddPrice = newItem.AddPrice; //道菜基准加价 = 主菜数量 * 道菜基准单价 oldItem.SuitAmount = this._master.Quantity * newItem.AddPrice; //道菜数量随主菜变化而增加 oldItem.Quantity = this._master.Quantity * oldItem.SuitQuantity; //清除做法记录 oldItem.Flavors.Clear(); //通知主界面改变 this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify , oldItem)); } else { item.TileColor = eMetroTileColor.Coffee; } } } }