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.
434 lines
14 KiB
C#
434 lines
14 KiB
C#
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 DevComponents.DotNetBar.Metro;
|
|
using POSV.Bean;
|
|
using DevComponents.DotNetBar;
|
|
using POSV.Utils;
|
|
using System.Threading.Tasks;
|
|
using POSV.Entity;
|
|
using POSV.Helper;
|
|
|
|
namespace POSV.Component
|
|
{
|
|
[ToolboxItem(true)]
|
|
public partial class TableAttributeX : BaseUserControl
|
|
{
|
|
/// <summary>
|
|
/// 绑定的数据源
|
|
/// </summary>
|
|
private List<TableAttribute> _dataSource = null;
|
|
|
|
/// <summary>
|
|
/// 当前选择的项
|
|
/// </summary>
|
|
private MetroTileItem _selectedItem = null;
|
|
|
|
public TableAttributeX()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.BackColor = Color.Transparent;
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
Rectangle rect = new Rectangle(0 , 0 , this.Width , this.Height);
|
|
ControlPaint.DrawBorder(e.Graphics , rect , Color.Transparent , ButtonBorderStyle.Solid);
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
this.Height = (this.Visible ? this.ItemHeight : 0);
|
|
|
|
this.InitTableStatus();
|
|
|
|
this.InitTableAttribute();
|
|
|
|
this.BindDataSource();
|
|
}
|
|
|
|
private void InitTableAttribute()
|
|
{
|
|
try
|
|
{
|
|
this._dataSource = new List<TableAttribute>();
|
|
|
|
var entity = new TableAttribute();
|
|
entity.Id = Constant.ALL_TABLE_TAG;
|
|
entity.Name = "全部";
|
|
entity.Expression = string.Empty;
|
|
entity.TableStatus = -1;
|
|
this._dataSource.Add(entity);
|
|
|
|
entity = new TableAttribute();
|
|
entity.Id = IdWorkerUtils.Instance.NextId();
|
|
entity.Name = "4人桌";
|
|
entity.Expression = " = 4 ";
|
|
entity.TableStatus = -1;
|
|
this._dataSource.Add(entity);
|
|
|
|
entity = new TableAttribute();
|
|
entity.Id = IdWorkerUtils.Instance.NextId();
|
|
entity.Name = "6人桌";
|
|
entity.Expression = " = 6 ";
|
|
entity.TableStatus = -1;
|
|
this._dataSource.Add(entity);
|
|
|
|
entity = new TableAttribute();
|
|
entity.Id = IdWorkerUtils.Instance.NextId();
|
|
entity.Name = "8人以上";
|
|
entity.Expression = " >= 8 ";
|
|
entity.TableStatus = -1;
|
|
this._dataSource.Add(entity);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LOGGER.Error(ex , "加载桌台属性异常");
|
|
}
|
|
}
|
|
|
|
|
|
private void InitTableStatus()
|
|
{
|
|
this.leftPanel.Controls.Clear();
|
|
|
|
var dic = EnumHelper.EnumSortedDictionary(typeof(TableStatus));
|
|
dic.Reverse();
|
|
foreach (var item in dic)
|
|
{
|
|
var ctrl = new TouchLabelX();
|
|
|
|
ctrl.Font = new System.Drawing.Font("宋体" , 10.5F , System.Drawing.FontStyle.Regular , System.Drawing.GraphicsUnit.Point , ((byte)(134)));
|
|
ctrl.SymbolColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))) , ((int)(((byte)(0)))) , ((int)(((byte)(0)))));
|
|
ctrl.SymbolSize = 10F;
|
|
ctrl.Tag = item.Key;
|
|
ctrl.Text = item.Value;
|
|
ctrl.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
|
|
ctrl.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
|
|
|
|
ctrl.Symbol = "\uf10c";
|
|
ctrl.Dock = DockStyle.Right;
|
|
ctrl.Width = 55;
|
|
|
|
ctrl.TouchClick += this.OnTableStatusTouchClick;
|
|
|
|
this.leftPanel.Controls.Add(ctrl);
|
|
}
|
|
|
|
this.leftPanel.AutoSize = true;
|
|
}
|
|
|
|
|
|
private void BindDataSource()
|
|
{
|
|
try
|
|
{
|
|
if (this._dataSource == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
//总记录
|
|
this.TotalCount = this._dataSource.Count;
|
|
//每页的显示数量
|
|
this.PageSize = this.Rows * this.Columns;
|
|
|
|
//清空历史数据
|
|
itemPanel.Items.Clear();
|
|
|
|
this.itemPanel.Font = this.GetSystemFont(this.FontSize);
|
|
|
|
var pager = this.ListPager(this._dataSource);
|
|
|
|
ItemContainer ic = new ItemContainer();
|
|
|
|
ic.MultiLine = (this.Rows > 1);
|
|
ic.ItemSpacing = 2;
|
|
ic.LayoutOrientation = eOrientation.Horizontal;
|
|
|
|
foreach (var entity in pager)
|
|
{
|
|
MetroTileItem item = this.GetItemTemplate();
|
|
|
|
item.Name = entity.Id;
|
|
|
|
item.Checked = false;
|
|
|
|
//绑定到Tag属性
|
|
item.Tag = entity;
|
|
|
|
//绑定编码到TitleText属性
|
|
//item.TitleText = entity.No;
|
|
|
|
//绑定名称到Text属性
|
|
item.Text = entity.Name;
|
|
|
|
ic.SubItems.Add(item);
|
|
|
|
if (this._selectedItem == null)
|
|
{
|
|
this._selectedItem = item;
|
|
}
|
|
}
|
|
|
|
this.itemPanel.Items.Add(ic);
|
|
this.itemPanel.Invalidate();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LOGGER.Error(ex , "绑定桌台数据源异常");
|
|
}
|
|
finally
|
|
{
|
|
if (this._selectedItem != null)
|
|
{
|
|
//选中情况下的文字颜色
|
|
this._selectedItem.TileStyle.TextColor = ColorTranslator.FromHtml(this.TextColor2);
|
|
this._selectedItem.TitleTextColor = ColorTranslator.FromHtml(this.TextColor2);
|
|
//选中情况下的背景颜色
|
|
this._selectedItem.TileStyle.BackColor = ColorTranslator.FromHtml(this.BackColor2);
|
|
this._selectedItem.TileStyle.BackColor2 = ColorTranslator.FromHtml(this.BackColor2);
|
|
//边框颜色
|
|
this._selectedItem.TileStyle.BorderColor = ColorTranslator.FromHtml(this.BackColor2);
|
|
this._selectedItem.TileStyle.BorderColor2 = ColorTranslator.FromHtml(this.BackColor2);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private MetroTileItem GetItemTemplate()
|
|
{
|
|
MetroTileItem template = new MetroTileItem();
|
|
|
|
template.TileStyle.PaddingLeft = template.TileStyle.PaddingRight = -2;
|
|
|
|
template.EnableMarkup = true;
|
|
template.OptionGroup = "TableAttributeX";
|
|
template.CheckBehavior = eMetroTileCheckBehavior.LeftMouseButtonClick;
|
|
|
|
template.TileStyle.Font = itemPanel.Font;
|
|
//对齐方式
|
|
template.TileStyle.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
|
|
template.TileStyle.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
|
|
//正常情况下的文字颜色
|
|
template.TileStyle.TextColor = ColorTranslator.FromHtml(this.TextColor1);
|
|
template.TitleTextColor = ColorTranslator.FromHtml(this.TextColor1);
|
|
//正常情况下的背景颜色
|
|
template.TileStyle.BackColor = ColorTranslator.FromHtml(this.BackColor1);
|
|
template.TileStyle.BackColor2 = ColorTranslator.FromHtml(this.BackColor1);
|
|
//无边框
|
|
template.TileStyle.BorderColor = Color.Transparent;
|
|
template.TileStyle.BorderColor2 = Color.Transparent;
|
|
|
|
template.TileStyle.BorderWidth = 1;
|
|
template.TileStyle.CornerDiameter = 6;
|
|
template.TileStyle.CornerType = eCornerType.Rounded;
|
|
|
|
|
|
//显示大小
|
|
template.TileSize = new Size(this.ItemWidth , this.ItemHeight);
|
|
|
|
template.MouseDown += OnMouseDown;
|
|
|
|
return template;
|
|
}
|
|
|
|
private void OnMouseDown(object sender , MouseEventArgs e)
|
|
{
|
|
MetroTileItem current = (MetroTileItem)sender;
|
|
current.Checked = false;
|
|
|
|
foreach (BaseItem item in current.Parent.SubItems)
|
|
{
|
|
if (item == current)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
MetroTileItem b = item as MetroTileItem;
|
|
if (b != null && b.OptionGroup == current.OptionGroup)
|
|
{
|
|
//正常情况下的文字颜色
|
|
b.TileStyle.TextColor = ColorTranslator.FromHtml(this.TextColor1);
|
|
b.TitleTextColor = ColorTranslator.FromHtml(this.TextColor1);
|
|
//正常情况下的背景颜色
|
|
b.TileStyle.BackColor = ColorTranslator.FromHtml(this.BackColor1);
|
|
b.TileStyle.BackColor2 = ColorTranslator.FromHtml(this.BackColor1);
|
|
//无边框
|
|
b.TileStyle.BorderColor = Color.Transparent;
|
|
b.TileStyle.BorderColor2 = Color.Transparent;
|
|
}
|
|
}
|
|
|
|
this._selectedItem = current;
|
|
|
|
//选中情况下的文字颜色
|
|
current.TileStyle.TextColor = ColorTranslator.FromHtml(this.TextColor2);
|
|
current.TitleTextColor = ColorTranslator.FromHtml(this.TextColor2);
|
|
//选中情况下的背景颜色
|
|
current.TileStyle.BackColor = ColorTranslator.FromHtml(this.BackColor2);
|
|
current.TileStyle.BackColor2 = ColorTranslator.FromHtml(this.BackColor2);
|
|
//边框颜色
|
|
current.TileStyle.BorderColor = ColorTranslator.FromHtml(this.BackColor2);
|
|
current.TileStyle.BorderColor2 = ColorTranslator.FromHtml(this.BackColor2);
|
|
|
|
|
|
OnTableAttributeCheckedChanged(new TableAttributeEventArgs((TableAttribute)current.Tag));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前选择的桌台属性
|
|
/// </summary>
|
|
public TableAttribute SelectedTableAttribute => this._selectedItem.Tag as TableAttribute;
|
|
|
|
public event TableAttributeEventHandler TableAttributeCheckedChanged;
|
|
protected virtual void OnTableAttributeCheckedChanged(TableAttributeEventArgs e)
|
|
{
|
|
TableAttributeCheckedChanged?.Invoke(this , e);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页List数据
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public List<TableAttribute> ListPager(List<TableAttribute> data)
|
|
{
|
|
var result = new List<TableAttribute>();
|
|
|
|
result.AddRange(data.Skip((this.PageNumber - 1) * this.PageSize).Take(this.PageSize));
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 每页的大小
|
|
/// </summary>
|
|
public int PageSize { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 总页数
|
|
/// </summary>
|
|
public int PageCount => this.PageSize <= 0 ? 0 : ((this.TotalCount + this.PageSize - 1) / this.PageSize);
|
|
|
|
/// <summary>
|
|
/// 当前页码
|
|
/// </summary>
|
|
public int PageNumber { get; set; }
|
|
|
|
/// <summary>
|
|
/// 总数量
|
|
/// </summary>
|
|
public int TotalCount { get; private set; }
|
|
|
|
public int Rows { get; } = 1;
|
|
|
|
public int Columns { get; } = 4;
|
|
|
|
/// <summary>
|
|
/// 宽度
|
|
/// </summary>
|
|
public int ItemWidth { get; } = 90;
|
|
|
|
/// <summary>
|
|
/// 高度
|
|
/// </summary>
|
|
public int ItemHeight { get; } = 45;
|
|
|
|
/// <summary>
|
|
/// 正常背景颜色
|
|
/// </summary>
|
|
public string BackColor1 { get; set; } = ColorTranslator.ToHtml(Color.Transparent);
|
|
|
|
/// <summary>
|
|
/// 选中后背景颜色
|
|
/// </summary>
|
|
public string BackColor2 { get; set; } = ColorTranslator.ToHtml(Color.DimGray);
|
|
|
|
/// <summary>
|
|
/// 字体大小
|
|
/// </summary>
|
|
public SystemFont FontSize { get; set; } = SystemFont.默认;
|
|
|
|
/// <summary>
|
|
/// 正常文字颜色
|
|
/// </summary>
|
|
public string TextColor1 { get; set; } = ColorTranslator.ToHtml(Color.Black);
|
|
|
|
/// <summary>
|
|
/// 选中的颜色
|
|
/// </summary>
|
|
public string TextColor2 { get; set; } = ColorTranslator.ToHtml(Color.White);
|
|
|
|
|
|
private void OnTableStatusTouchClick(object sender , EventArgs e)
|
|
{
|
|
var current = sender as TouchLabelX;
|
|
|
|
var items = this.leftPanel.Controls;
|
|
foreach(var item in items)
|
|
{
|
|
if (item == current) continue;
|
|
|
|
((TouchLabelX)item).Symbol = "\uf10c";
|
|
}
|
|
|
|
current.Symbol = "\uf111";
|
|
|
|
|
|
var selected = (TableAttribute)this._selectedItem.Tag;
|
|
|
|
selected.TableStatus = Convert.ToInt16(current.Tag);
|
|
|
|
OnTableAttributeCheckedChanged(new TableAttributeEventArgs(selected));
|
|
}
|
|
}
|
|
|
|
public delegate void TableAttributeEventHandler(object sender , TableAttributeEventArgs e);
|
|
|
|
public class TableAttributeEventArgs : EventArgs
|
|
{
|
|
public TableAttribute Data;
|
|
public TableAttributeEventArgs(TableAttribute data)
|
|
{
|
|
this.Data = data;
|
|
}
|
|
}
|
|
|
|
public class TableAttribute
|
|
{
|
|
/// <summary>
|
|
/// 本地主键
|
|
/// </summary>
|
|
public string Id { get; set; }
|
|
|
|
/// <summary>
|
|
/// 名称
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// 条件表达式
|
|
/// </summary>
|
|
public string Expression { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// 桌台状态
|
|
/// </summary>
|
|
public int TableStatus { get; set; } = -1;
|
|
}
|
|
}
|