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.

339 lines
11 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using POSV.Entity;
using POSV.Language;
using POSV.MessageEvent;
using POSV.Tabs;
using POSV.Component;
using System.Threading;
namespace POSV
{
public partial class TableTemplate : AbstractForm
{
/// <summary>
/// 计时器
/// </summary>
private System.Timers.Timer timer;
/// <summary>
/// 主控菜单
/// </summary>
private MainControlBox _mainControlBox = null;
/// <summary>
/// 桌台界面
/// </summary>
private TableMenuItem _tableMenuItem = null;
/// <summary>
/// 点餐界面
/// </summary>
private DishMenuItem _dishMenuItem = null;
/// <summary>
/// 参数界面
/// </summary>
private SettingMenuItem _settingMenuItem = null;
public TableTemplate()
{
InitializeComponent();
//初始化主控菜单
this._mainControlBox = this.InitializeControlBox();
this._mainControlBox.Dock = DockStyle.Top;
//默认加载桌台界面,必须优先初始化
this._tableMenuItem = new TableMenuItem();
this._tableMenuItem.Dock = DockStyle.Fill;
this._tableMenuItem.Visible = true;
//点菜界面通知事件
MsgEvent.Receive(Constant.TABLE_ORDER_DISHS_NOTIFY , this.TableOrderDishsEventNotify);
this.tabControl.SelectedTabChanging += OnTabControlSelectedTabChanging;
this.tabControl.SelectedTabChanged += OnTabControlSelectedTabChanged;
//默认选择桌台界面
this.tabControl.SelectedTab = null;
this.tabControl.SelectedTab = tabTable;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this.Text = LangUtils.Instance.GetString("Application.Title");
Task.Factory.StartNew(() =>
{
this.Invoke(new Action(() =>
{
this._dishMenuItem = new DishMenuItem();
this._dishMenuItem.Dock = DockStyle.Fill;
this._dishMenuItem.Visible = false;
}));
}).ContinueWith(task =>
{
this.Invoke(new Action(() =>
{
this._settingMenuItem = new SettingMenuItem();
this._settingMenuItem.Dock = DockStyle.Fill;
this._settingMenuItem.Visible = true;
}));
}).ContinueWith(task =>
{
this.Invoke(new Action(() =>
{
}));
}).ContinueWith(task =>
{
this.Invoke(new Action(() =>
{
//定时器
this.timer = new System.Timers.Timer(60000);//定时周期2秒
this.timer.Elapsed += TimerElapsed;//到60秒了做的事件
this.timer.AutoReset = true; //是否不断重复定时器操作
this.timer.Start();
}));
});
}
#region 头部按钮事件
protected override void OnControlBoxIconClick(object sender, EventArgs e)
{
bool isGo = true;
if (isGo)
{
MsgEvent.Send(Constant.TABLE_ORDER_DISHS_NOTIFY, null);
}
}
protected override void OnControlBoxMinimizedClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
protected override void OnControlBoxCloseClick(object sender, EventArgs e)
{
this.Close();
}
#endregion
/// <summary>
/// 点单界面切换通知事件
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void TableOrderDishsEventNotify(object sender , MsgEventArgs args)
{
this.Invoke(new Action(() =>
{
//通过桌台选择进入,视为桌台模式
if (args.Data is Table)
{
//当前选择的桌台
var table = args.Data as Table;
//点菜界面提供[返回]桌台按钮功能
this._mainControlBox.IconBox = true;
//当前选中的Tab
var tabItem = this.tabControl.SelectedTab;
//当前选中Tab对应的容器
var tabPanel = this.tabControl.SelectedPanel;
//是否有可用的容器
if (tabPanel.Controls.ContainsKey(tabItem.Description))
{
//加载业务控件的容器
var container = tabPanel.Controls[tabItem.Description] as DoubleBufferPanelX;
//将点菜控件压入
if (!container.Controls.Contains(this._dishMenuItem))
{
container.Controls.Add(this._dishMenuItem);
}
}
//隐藏桌台控件
this._tableMenuItem.Visible = false;
//显示点菜控件
this._dishMenuItem.Visible = true;
this._dishMenuItem.Dock = DockStyle.Fill;
}
else
{
//关闭返回按钮
this._mainControlBox.IconBox = false;
//隐藏点菜控件
this._dishMenuItem.Visible = false;
//显示桌台控件
this._tableMenuItem.Visible = true;
this._tableMenuItem.Dock = DockStyle.Fill;
}
}));
}
private SuperTabControlPanel SelectedPanel(bool mainControlBox = true)
{
var tabItem = this.tabControl.SelectedTab;
var tabPanel = this.tabControl.SelectedPanel;
//添加操作区容器
if (!tabPanel.Controls.ContainsKey(tabItem.Description))
{
var container = new DoubleBufferPanelX();
container.Name = tabItem.Description;
container.Text = "加载中,请稍候...";
container.Dock = DockStyle.Fill;
tabPanel.Controls.Add(container);
}
//显示主控菜单
if (mainControlBox)
{
if (!tabPanel.Controls.Contains(this._mainControlBox))
{
tabPanel.Controls.Add(this._mainControlBox);
}
}
return tabPanel;
}
private void OnTabControlSelectedTabChanged(object sender , DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs e)
{
var item = e.NewValue as SuperTabItem;
var tab = TabCollection.LOGO;
Enum.TryParse<TabCollection>(item.Tag == null ? "LOGO" : item.Tag.ToString(), out tab);
var tabPanel = this.SelectedPanel();
switch (tab)
{
case TabCollection.:
{
//是否有可用的容器
if (tabPanel.Controls.ContainsKey(item.Description))
{
var container = tabPanel.Controls[item.Description] as DoubleBufferPanelX;
//将桌台呈现出来
if (!container.Controls.Contains(this._tableMenuItem))
{
container.Controls.Add(this._tableMenuItem);
}
}
}
break;
case TabCollection.:
{
//var container = new DoubleBufferPanelX();
//container.Dock = DockStyle.Fill;
//superTabControlPanel5.Controls.Add(container);
//superTabControlPanel5.Controls.Add(this.mainControlBox);
}
break;
case TabCollection.:
{
//是否有可用的容器
if (tabPanel.Controls.ContainsKey(item.Description))
{
var container = tabPanel.Controls[item.Description] as DoubleBufferPanelX;
//将设置界面呈现出来
if (!container.Controls.Contains(this._settingMenuItem))
{
container.Controls.Add(this._settingMenuItem);
}
}
}
break;
default:
{
//是否有可用的容器
if (tabPanel.Controls.ContainsKey(item.Description))
{
var container = tabPanel.Controls[item.Description] as DoubleBufferPanelX;
LOGGER.Info(container.Name + "");
}
}
break;
}
}
private void OnTabControlSelectedTabChanging(object sender , DevComponents.DotNetBar.SuperTabStripSelectedTabChangingEventArgs e)
{
var item = sender as SuperTabItem;
//var tab = TabCollection.LOGO;
//Enum.TryParse<TabCollection>(item.Tag == null ? "LOGO" : item.Tag.ToString() , out tab);
//switch (tab)
//{
// case TabCollection.LOGO:
// {
// e.Cancel = true;
// }
// break;
// default:
// {
// e.Cancel = false;
// }
// break;
//}
}
void TimerElapsed(object sender , System.Timers.ElapsedEventArgs e)
{
Task.Factory.StartNew(() =>
{
this.Invoke(new Action(() =>
{
//刷新桌台界面
this._tableMenuItem.RefreshUi();
}));
});
}
}
public enum TabCollection
{
LOGO = -1,
= 0,
= 1,
= 2,
= 3,
= 4,
= 5,
= 6,
= 7,
= 8
}
}