You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
8.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 数据库的模块数据
/// </summary>
private List<ShortcutMenu> _dataSource = null;
private List<MetroTileItem> _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<ShortcutMenu>)
{
var data = args.Data as List<ShortcutMenu>;
this._dataSource = data;
RefreshUi();
}
}));
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
var resources = new List<Resources>();
//获取数据库的数据
using (var db = Global.Instance.OpenDataBase)
{
this._dataSource = db.Query<ShortcutMenu>().ToList();
resources = db.Query<Resources>().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<ShortcutMenu>();
}
if(this._items == null)
{
this._items = new List<MetroTileItem>();
}
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<MetroTileItem> 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<ModuleFont>(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;
}
}
}