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 DevComponents.DotNetBar.Metro; using DevComponents.DotNetBar; using POSV.MessageEvent; namespace POSV.Business { public partial class MSpecPanelEx : AbstractFlyoutPanelEx { /// /// 选中行数据 /// private readonly OrderItem _orderItem = null; /// /// 权限控制码 /// private string _permissionCode = string.Empty; /// /// 授权人权限信息 /// private Tuple , Worker> _authz = null; /// /// 规格数据源 /// private List _specList = null; /// /// 键盘、方向键 /// private KeyboardAction _action = KeyboardAction.None; /// /// 当前焦点索引 /// private int _index = 0; /// /// 当前焦点单品 /// private MetroTileItem _curr = null; public MSpecPanelEx(OrderItem item , string permissionCode , Tuple , Worker> authz = null) { InitializeComponent(); this._orderItem = item; //操作功能的权限码 this._permissionCode = permissionCode; //授权人综合信息 this._authz = authz; //规格键盘通知事件 MsgEvent.RemoveListener(Constant.SPEC_KEYBOARD_NOTIFY , this.SpecKeyboardEventNotify); MsgEvent.Receive(Constant.SPEC_KEYBOARD_NOTIFY , this.SpecKeyboardEventNotify); } protected void SpecKeyboardEventNotify(object sender , MsgEventArgs args) { if (args != null && args.Data != null) { Enum.TryParse(args.Data.ToString() , out this._action); switch (this._action) { case KeyboardAction.Left: { if (this.itemPanel.Items.Count > 0) { var container = this.itemPanel.Items[0] as ItemContainer; int subItems = container.SubItems.Count; //只有一个单品 if (subItems == 1) { //当前操作的 this._index = 0; this._curr = container.SubItems[this._index] as MetroTileItem; this.UpdateSelectedStyle(this._curr); } if (this._index - 1 >= 0) { //当前操作的,重置样式 var focus = container.SubItems[this._index] as MetroTileItem; this.ResetMetroTileItemStyle(focus); //当前操作的 this._index = this._index - 1; this._curr = container.SubItems[this._index] as MetroTileItem; this.UpdateSelectedStyle(this._curr); } } } break; case KeyboardAction.Right: { if (this.itemPanel.Items.Count > 0) { var container = this.itemPanel.Items[0] as ItemContainer; int subItems = container.SubItems.Count; //只有一个单品 if (subItems == 1) { //当前操作的 this._index = 0; this._curr = container.SubItems[this._index] as MetroTileItem; this.UpdateSelectedStyle(this._curr); } if (this._index + 1 < subItems) { //重置当前样式 var focus = container.SubItems[this._index] as MetroTileItem; this.ResetMetroTileItemStyle(focus); //当前操作的 this._index = this._index + 1; this._curr = container.SubItems[this._index] as MetroTileItem; this.UpdateSelectedStyle(this._curr); } } } break; case KeyboardAction.Enter: { if (this._curr != null) { // LOGGER.Info(">>>>>>" + this._curr.Text); // LOGGER.Info(">>>>>>" + this._curr.DisplayRectangle); // LOGGER.Info(">>>>>>" + this._curr.Bounds); // LOGGER.Info(">>>>>>" + this.Parent); // LOGGER.Info(">>>>>>" + this); var r = this.RectangleToScreen(this.DisplayRectangle); var e = new MouseEventArgs(MouseButtons.Left , 1 , r.Left + 5 , r.Top + 5 , 0); this.TileItemMouseDown(this._curr , e); } } break; } } } public void ResetMetroTileItemStyle(MetroTileItem item) { //背景颜色 item.TileColor = eMetroTileColor.Coffee; //去除边框颜色 item.TileStyle.BorderColor = Color.Transparent; item.TileStyle.BorderColor2 = Color.Transparent; } public void UpdateSelectedStyle(MetroTileItem item) { //背景颜色 item.TileColor = eMetroTileColor.DarkGreen; item.TileStyle.BorderColor = Color.Transparent; item.TileStyle.BorderColor2 = Color.Transparent; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.SetStyle(ControlStyles.Selectable , true); if (this.DesignMode) return; this._curr = null; lock (Global.Instance.SyncLock) { //规格数据源 using (var db = Global.Instance.OpenDataBase) { this._specList = db.Query("where productId = @0 and deleteFlag = 0" , this._orderItem.ProductExt.Id).OrderBy(x => x.No).ToList(); } } if (this._specList == null) { this._specList = new List(); } BuilderAll(); } private void BuilderAll() { //清空历史数据 this.itemPanel.Items.Clear(); ItemContainer ic = new ItemContainer(); ic.MultiLine = true; ic.ItemSpacing = 0; ic.LayoutOrientation = eOrientation.Horizontal; foreach (var entity in this._specList) { MetroTileItem tileItem = new MetroTileItem(); tileItem.TileStyle.PaddingLeft = tileItem.TileStyle.PaddingRight = -1; tileItem.OptionGroup = "Specs"; tileItem.SymbolColor = Color.Empty; tileItem.TileSize = new Size(94 , 60); tileItem.TileStyle.CornerType = eCornerType.Square; tileItem.TileStyle.TextAlignment = eStyleTextAlignment.Center; tileItem.TileStyle.TextLineAlignment = eStyleTextAlignment.Near; tileItem.TitleText = Constant.CNY + entity.Price.ToString(); tileItem.TitleTextAlignment = ContentAlignment.BottomCenter; tileItem.TitleTextFont = Constant.NORMAL_FONT; //规格名称 tileItem.Text = entity.Name; //背景颜色 tileItem.TileColor = eMetroTileColor.Coffee; //去除边框颜色 tileItem.TileStyle.BorderColor = Color.Transparent; tileItem.TileStyle.BorderColor2 = Color.Transparent; if (entity.Id.Equals(this._orderItem.SpecId)) { tileItem.Checked = true; } tileItem.Tag = entity; tileItem.MouseDown += TileItemMouseDown; ic.SubItems.Add(tileItem); } this.itemPanel.Items.Add(ic); this.itemPanel.Invalidate(); } private void TileItemMouseDown(object sender , MouseEventArgs e) { MetroTileItem item = (MetroTileItem)sender; item.Checked = true; var newItem = item.Tag as ProductSpec; //修改商品价格信息 this._orderItem.ProductExt.Price = newItem.Price; this._orderItem.ProductExt.CostPrice = newItem.CostPrice; this._orderItem.ProductExt.MinPrice = newItem.MinPrice; this._orderItem.ProductExt.MemberPrice = newItem.MemberPrice; this._orderItem.ProductExt.PurchasePrice = newItem.PurchasePrice; this._orderItem.ProductExt.OtherPrice = newItem.OtherPrice; this._orderItem.ProductExt.DispatchPrice = newItem.DispatchPrice; this._orderItem.ProductExt.SpecId = newItem.Id; this._orderItem.ProductExt.SpecName = newItem.Name; //修改行记录中涉及到的规格信息 this._orderItem.Price = this._orderItem.ProductExt.Price; this._orderItem.MemberPrice = this._orderItem.ProductExt.MemberPrice; this._orderItem.MemberSalePrice = this._orderItem.ProductExt.MemberPrice; this._orderItem.SalePrice = this._orderItem.ProductExt.Price; this._orderItem.MinPrice = this._orderItem.ProductExt.MinPrice; this._orderItem.SpecId = this._orderItem.ProductExt.SpecId; this._orderItem.SpecName = this._orderItem.ProductExt.SpecName; //通知主界面改变 this.OnNotifyChanged(new FlyoutEventArgs(FlyoutAction.Notify , this._orderItem)); } } }