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.MessageEvent; using DevComponents.DotNetBar; using DevComponents.DotNetBar.Metro; using POSV.Template; using POS.Language.Language; namespace POSV.Component { [ToolboxItem(true)] public partial class ShortcutControl : BaseUserControl { /// /// 数据库的模块数据 /// private List _dataSource = null; private List _items = null; public ShortcutControl() { InitializeComponent(); this.BackColor = Color.Transparent; //订购界面变更通知事件 MsgEvent.RemoveListener(Constant.SHORTCUT_CHANGED_NOTIFY , this.MenuChangedEventNotify); MsgEvent.Receive(Constant.SHORTCUT_CHANGED_NOTIFY , this.MenuChangedEventNotify); } protected void MenuChangedEventNotify(object sender , MsgEventArgs args) { this.Invoke(new Action(() => { if (args.Data is List) { var data = args.Data as List; this._dataSource = data; RefreshUi(); } })); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; var resources = new List(); //获取数据库的数据 using (var db = Global.Instance.OpenDataBase) { this._dataSource = db.Query().ToList(); resources = db.Query().ToList(); } this._dataSource.ForEach(x => { var resource = resources.FirstOrDefault(r => r.Id == x.ResourceId); if (resource != null) { x.PermissionCode = string.IsNullOrEmpty(resource.PermissionCode) ? string.Empty : resource.PermissionCode; } }); //如果数据库数据为空 if (this._dataSource == null) { this._dataSource = new List(); } if(this._items == null) { this._items = new List(); } RefreshUi(); } public void RefreshUi() { this._items.Clear(); this.shortcutItemPanel.Items.Clear(); ItemContainer ic = new ItemContainer(); ic.MultiLine = true; ic.Orientation = eOrientation.Vertical; ic.ItemSpacing = 0; ic.TitleStyle.Class = "MetroTileGroupTitle"; //加载菜单显示区域为主菜单的数据 var lists = this._dataSource.FindAll(x => !string.IsNullOrEmpty(x.ParentId)); lists.Sort((x , y) => (x.OrderNo.CompareTo(y.OrderNo))); foreach (ShortcutMenu entity in lists) { //超出可显示区域不加载 if((ic.SubItems.Count * 55 + 55) > this.Height) { break; } MetroTileItem item = new MetroTileItem(); item.TileStyle.PaddingLeft = item.TileStyle.PaddingRight = -2; item.OptionGroup = "ShortcutMenu"; item.TileStyle.Font = GetFont(entity.FontSize); item.TileStyle.TextAlignment = eStyleTextAlignment.Center; switch (entity.KeyCode) { case "数量加": { //➕ if(string.IsNullOrEmpty(entity.Alias) || "➕".Equals(entity.Alias)) { item.Text = string.Empty; item.Symbol = "\uf067"; item.SymbolSize = 0; item.ImageIndent = new Point(0 , 0); item.ImageTextAlignment = ContentAlignment.MiddleCenter; item.ItemAlignment = eItemAlignment.Center; } else { item.Text = entity.Alias; } //item.Symbol = (string.IsNullOrEmpty(entity.Alias) || "➕".Equals(entity.Alias)) ? "\u2795" : entity.Alias; } break; case "数量减": { //➖ if (string.IsNullOrEmpty(entity.Alias) || "➖".Equals(entity.Alias)) { item.Text = string.Empty; item.Symbol = "\uf068"; item.SymbolSize = 0; item.ImageIndent = new Point(0 , 0); item.ImageTextAlignment = ContentAlignment.MiddleCenter; item.ItemAlignment = eItemAlignment.Center; } else { item.Text = entity.Alias; } } break; default: { item.Text = LangProxy.ToLang( string.IsNullOrEmpty(entity.Alias) ? entity.Name : entity.Alias); } break; } item.TileStyle.TextColor = ColorTranslator.FromHtml(entity.Color3); item.TileStyle.BackColor = ColorTranslator.FromHtml(entity.Color1); item.TileStyle.BackColor2 = ColorTranslator.FromHtml(entity.Color1); item.TileStyle.BorderColor = Color.Transparent; item.TileStyle.BorderColor2 = Color.Transparent; item.TileSize = new Size(base.Width , 55); item.Tag = entity; this._items.Add(item); item.MouseDown += OnShortcutMouseDown; ic.SubItems.Add(item); } this.shortcutItemPanel.Items.Add(ic); this.shortcutItemPanel.Invalidate(); } private void OnShortcutMouseDown(object sender , MouseEventArgs e) { MetroTileItem item = (MetroTileItem)sender; item.Checked = false; var module = item.Tag as ShortcutMenu; this.OnMenuMouseDown(new MenuEventArgs(item , module.OrderNo, module.KeyCode , module.KeyData , module)); } public List Items { get { return this._items; } } public event MenuEventHandler MenuMouseDown; protected virtual void OnMenuMouseDown(MenuEventArgs e) { MenuMouseDown?.Invoke(this , e); } private Font GetFont(string fontSize) { Font result = Constant.DEFAULT_FONT; ModuleFont font = ModuleFont.默认; Enum.TryParse(fontSize , out font); switch (font) { case ModuleFont.默认: { result = Constant.DEFAULT_FONT; } break; case ModuleFont.正常: { result = Constant.NORMAL_FONT; } break; case ModuleFont.小字: { result = Constant.SMALL_FONT; } break; case ModuleFont.大字: { result = Constant.BIG_FONT; } break; } return result; } } }