using DevComponents.DotNetBar; using DevComponents.DotNetBar.Controls; using DevComponents.DotNetBar.Metro; using POS.Language.Language; using POSV.Card; using POSV.Entity; using POSV.ShoppingCart; using POSV.Utils; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace POSV.Component { public partial class DeskNoForm : BusinessForm { /// /// 数据源 /// private List _dataSource = null; private OrderObject _orderObject = null; private static int _DEFAULTITEMHIGHT = 80; private static int _DEFAULTCOLUMNS = 5; private int DefaultCategoryItemWidth = 87; private Size DefaultMainMenuSize = Size.Empty; private int DefaultPaddingLeftRight = -2; private Table selectTable =null; /// /// 餐桌类型数据源 /// private List _tableTypeList = null; /// /// 餐桌区域数据源 /// private List _tableAreaList = null; private Dictionary AreaMap = new Dictionary(); public DeskNoForm(OrderObject orderObject) { InitializeComponent(); _orderObject = orderObject; this.superTabControl1.SelectedTabIndex = 0; this.ActiveControl = this.txtDeskNo; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) return; Task.Factory.StartNew(() => { this.Invoke(new Action(() => { InstallDeskTypeAndNo(); })); }); } /// /// 加载当前门店后台设置的餐桌 /// private void InstallDeskTypeAndNo() { ///按餐桌区域选择 var autoDeskArea = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_CHECKAUTOOPENDESKAREA, false); if (autoDeskArea) { this.textMobile.Text = this._orderObject.Ext1; this.superTabItem1.Visible = false; if (this._orderObject.OrderType == OrderType.外带) { this.superTabItem2.Visible = false; } this.textMobile.Visible = true; this._tableAreaList = new List(); TableArea tableArea = new TableArea(); tableArea.Id = ""; tableArea.Name = LangProxy.ToLang("全部"); this._tableAreaList.Add(tableArea); //做法分类数据源 using (var db = Global.Instance.OpenDataBase) { List tableAreaListTemp = db.Query().OrderBy(x => x.No).ToList(); if (tableAreaListTemp != null) { this._tableAreaList.AddRange(tableAreaListTemp); } foreach (TableArea area in tableAreaListTemp) { AreaMap.Add(area.Id, area.Name); } } //做法分类 this.mainCategoryPage.OnPageChange += OnMainCategoryPageChange; DefaultMainMenuSize = new Size(DefaultCategoryItemWidth, this.mainCategoryPage.Height); } else { this._tableTypeList = new List(); TableType tableArea = new TableType(); this.superTabItem3.Visible = false; tableArea.Id = ""; tableArea.Name = LangProxy.ToLang("全部"); this._tableTypeList.Add(tableArea); //做法分类数据源 using (var db = Global.Instance.OpenDataBase) { List tableAreaListTemp = db.Query().OrderBy(x => x.No).ToList(); if (tableAreaListTemp != null) { this._tableTypeList.AddRange(tableAreaListTemp); } } //做法分类 this.mainCategoryPage.OnPageChange += OnMainCategoryPageChange; DefaultMainMenuSize = new Size(DefaultCategoryItemWidth, this.mainCategoryPage.Height); } //加载全部做法 this.RefreshMain(); } private void OnMainCategoryPageChange(object sender, EventArgs e) { PageNumber = 1; RefreshMain(); } private void RefreshMain() { ItemContainer ic = new ItemContainer(); MetroTileItem firstItem = null; ///按餐桌区域选择 var autoDeskArea = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_CHECKAUTOOPENDESKAREA, false); if (autoDeskArea) { if (this._tableAreaList != null && this._tableAreaList.Count > 0) { this.mainCategoryPage.TotalCount = this._tableAreaList.Count; this.mainCategoryPage.itemWidth = DefaultCategoryItemWidth; //分页 var pageTypeList = this.mainCategoryPage.ListPager(this._tableAreaList); ic.MultiLine = false; ic.ItemSpacing = 1; ic.ResizeItemsToFit = false; //很关键 foreach (var type in pageTypeList) { MetroTileItem item = new MetroTileItem(); item.CheckBehavior = eMetroTileCheckBehavior.None; item.Checked = false; item.OptionGroup = "tableType"; item.TileStyle.TextAlignment = eStyleTextAlignment.Center; item.Text = type.Name; item.TileSize = DefaultMainMenuSize; item.TileStyle.TextColor = Color.White; item.TileStyle.BackColor = ColorTranslator.FromHtml("#333333"); item.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333"); item.TileStyle.BorderColor = Color.Transparent; item.TileStyle.BorderColor2 = Color.Transparent; item.TileStyle.PaddingLeft = DefaultPaddingLeftRight; item.TileStyle.PaddingRight = DefaultPaddingLeftRight; item.Tag = type; if (firstItem == null) { firstItem = item; } item.MouseDown += OnMainMenuMouseDown; item.CheckedChanged += OnMainItemCheckedChange; ic.SubItems.Add(item); } } this.mainCategoryPage.RefreshUI(ic); if (firstItem != null) { firstItem.Checked = true; } } else { if (this._tableTypeList != null && this._tableTypeList.Count > 0) { this.mainCategoryPage.TotalCount = this._tableTypeList.Count; this.mainCategoryPage.itemWidth = DefaultCategoryItemWidth; //分页 var pageTypeList = this.mainCategoryPage.ListPager(this._tableTypeList); ic.MultiLine = false; ic.ItemSpacing = 1; ic.ResizeItemsToFit = false; //很关键 foreach (var type in pageTypeList) { MetroTileItem item = new MetroTileItem(); item.CheckBehavior = eMetroTileCheckBehavior.None; item.Checked = false; item.OptionGroup = "tableType"; item.TileStyle.TextAlignment = eStyleTextAlignment.Center; item.Text = type.Name; item.TileSize = DefaultMainMenuSize; item.TileStyle.TextColor = Color.White; item.TileStyle.BackColor = ColorTranslator.FromHtml("#333333"); item.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333"); item.TileStyle.BorderColor = Color.Transparent; item.TileStyle.BorderColor2 = Color.Transparent; item.TileStyle.PaddingLeft = DefaultPaddingLeftRight; item.TileStyle.PaddingRight = DefaultPaddingLeftRight; item.Tag = type; if (firstItem == null) { firstItem = item; } item.MouseDown += OnMainMenuMouseDown; item.CheckedChanged += OnMainItemCheckedChange; ic.SubItems.Add(item); } } this.mainCategoryPage.RefreshUI(ic); if (firstItem != null) { firstItem.Checked = true; } } } /// /// 加载子菜单 /// /// /// private void OnMainMenuMouseDown(object sender, MouseEventArgs e) { MetroTileItem obj = sender as MetroTileItem; obj.Checked = true; } private void OnMainItemCheckedChange(object sender, EventArgs e) { MetroTileItem obj = sender as MetroTileItem; if (obj.Checked) { obj.TileStyle.BackColor = ColorTranslator.FromHtml("#993366"); obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#993366"); ///按餐桌区域选择 var autoDeskArea = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_CHECKAUTOOPENDESKAREA, false); if (autoDeskArea) { //加载子类 var type = obj.Tag as TableArea; //加载大类下商品 LoadTableDetail(type.Id); } else { //加载子类 var type = obj.Tag as TableType; //加载大类下商品 LoadTableDetail(type.Id); } } else { obj.TileStyle.BackColor = ColorTranslator.FromHtml("#333333"); obj.TileStyle.BackColor2 = ColorTranslator.FromHtml("#333333"); } } private void OnCloseTouchClick(object sender, TouchEventArgs e) { this.Close(); } private void OnKeyBoardTouchAfter(object sender, KeyboardEventArgs e) { this.txtDeskNo.Focus(); this.ActiveControl = this.txtDeskNo; switch (e.KeyCode) { case "clear": //如果当前焦点控件是输入框 if (this.ActiveControl is TextBoxX) { var activeControl = this.ActiveControl as TextBoxX; activeControl.Text = string.Empty; } break; case "accept": //验证通过 { //ValidatePollCode(); var deskNo = this.txtDeskNo.Text.Trim(); this.OnAcceptButtonClick(new TransparentEventArgs(TransparentAction.Accept, "deskNo", new Tuple(deskNo, deskNo,""))); this.DialogResult = DialogResult.OK; OnCloseTouchClick(this, null); } break; default: { InputSimulatorUtils.SendKey(KeyCodes.Map[e.KeyCode]); } break; } } private void OnKeyBoardTouchAfterMobile(object sender, KeyboardEventArgs e) { this.textMobile.Focus(); this.ActiveControl = this.textMobile; switch (e.KeyCode) { case "clear": //如果当前焦点控件是输入框 if (this.ActiveControl is TextBoxX) { var activeControl = this.ActiveControl as TextBoxX; activeControl.Text = string.Empty; } break; case "accept": //验证通过 { if (this._orderObject.OrderType == OrderType.堂食) { //ValidatePollCode(); var Mobile = this.textMobile.Text.Trim(); if (selectTable == null) { this.labelX3.Text = LangProxy.ToLang("请选择餐桌"); return; } this.OnAcceptButtonClick(new TransparentEventArgs(TransparentAction.Accept, "deskNo", new Tuple(selectTable.No, string.Format("{0}#{1}", AreaMap[selectTable.AreaId], selectTable.Name), Mobile))); } else { var Mobile = this.textMobile.Text.Trim(); this.OnAcceptButtonClick(new TransparentEventArgs(TransparentAction.Accept, "deskNo", new Tuple(null, null, Mobile))); } this.DialogResult = DialogResult.OK; OnCloseTouchClick(this, null); } break; default: { InputSimulatorUtils.SendKey(KeyCodes.Map[e.KeyCode]); } break; } } /// /// 类型切换 /// /// /// private void LoadTableDetail(string typeId) { PageNumber = 1; List
tableList = null; if("".Equals(typeId)) { //加载所有餐桌 using(var db = Global.Instance.OpenDataBase) { tableList = db.Query
("order by no").ToList(); } } else { ///按餐桌区域选择 var autoDeskArea = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_CHECKAUTOOPENDESKAREA, false); if (autoDeskArea) { using (var db = Global.Instance.OpenDataBase) { tableList = db.Query
("where areaId = @0 order by no", typeId).ToList(); } } else { using (var db = Global.Instance.OpenDataBase) { tableList = db.Query
("where typeId = @0 order by no", typeId).ToList(); } } } //取消如果有桌子就选中桌子,这样不利于牌号等餐 //if(tableList.Count > 0) //{ // this.superTabControl1.SelectedTabIndex = 1; //} BindDataSource(tableList); } private MetroTileItem GetTableItemTemplate() { MetroTileItem template = new MetroTileItem(); template.TileStyle.PaddingLeft = template.TileStyle.PaddingRight = -2; template.EnableMarkup = true; template.OptionGroup = "table"; template.TileStyle.Font = this.deskNoPanel.Font; //this.itemPanel1.ResizeItemsToFit = false; this.deskNoPanel.BackgroundStyle.Class = "MetroTileGroupTitle";//很关键 template.TileStyle.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center; template.TileStyle.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near; template.TitleTextAlignment = ContentAlignment.BottomCenter; template.TitleTextFont = new Font("宋体", 12f); template.TileStyle.TextColor = Color.White; template.TitleTextColor = Color.White; template.TileStyle.BackColor = Color.DarkGreen; template.TileStyle.BackColor2 = Color.DarkGreen; template.TileStyle.BorderWidth = 1; template.TileStyle.BorderColor = Color.DarkGreen; template.TileStyle.BorderColor2 = Color.DarkGreen; //显示大小 template.TileSize = new Size(this.deskNoPanel.Width / _DEFAULTCOLUMNS, _DEFAULTITEMHIGHT); //圆角 template.TileStyle.CornerType = DevComponents.DotNetBar.eCornerType.Rounded; template.MouseDown += OnItemMouseDown; return template; } public void BindDataSource(List
dataSource, KeyboardAction action = KeyboardAction.None) { this._dataSource = dataSource; if (this._dataSource == null) { this._dataSource = new List
(); } //总数量 this.TotalCount = dataSource.Count; //每页的显示数量 this.PageSize = this.Rows * this.Columns; //清空历史数据 this.deskNoPanel.Items.Clear(); //复制新的数据源,进行分页运算 var merge = TableMerge.Merge(this.Rows, this.Columns, dataSource, false); var pager = ListPager(merge); ItemContainer ic = new ItemContainer(); ic.MultiLine = true; ic.ItemSpacing = 0; ic.LayoutOrientation = eOrientation.Horizontal; foreach (Table entity in pager) { MetroTileItem item = this.GetTableItemTemplate(); item.Name = entity.Id; item.Tag = entity; item.Checked = false; switch (entity.Name) { case Constant.PREV_PAGER: { item.Image = POSV.Properties.Resources.left; item.ImageTextAlignment = System.Drawing.ContentAlignment.MiddleCenter; item.TileStyle.BackColor = Color.DimGray; item.TileStyle.BackColor2 = Color.DimGray; item.TileStyle.BorderColor = Color.DimGray; item.TileStyle.BorderColor2 = Color.DimGray; } break; case Constant.NEXT_PAGER: { item.Image = POSV.Properties.Resources.right; item.ImageTextAlignment = System.Drawing.ContentAlignment.MiddleCenter; item.TileStyle.BackColor = Color.DimGray; item.TileStyle.BackColor2 = Color.DimGray; item.TileStyle.BorderColor = Color.DimGray; item.TileStyle.BorderColor2 = Color.DimGray; } break; default: { item.Text = entity.Name; item.TitleText = entity.Number + "人"; } break; } ic.SubItems.Add(item); } this.deskNoPanel.Items.Add(ic); this.deskNoPanel.Invalidate(); } /// /// 分页List数据 /// /// /// public List
ListPager(List
data) { var result = new List
(); result.AddRange(data.Skip((this.PageNumber - 1) * this.PageSize).Take(this.PageSize)); return result; } private void OnItemMouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { MetroTileItem item = (MetroTileItem)sender; var table = item.Tag as Table; switch (table.Name) { case Constant.PREV_PAGER: { this.PageNumber = table.Pager; this.BindDataSource(this._dataSource); } break; case Constant.NEXT_PAGER: { this.PageNumber = table.Pager; this.BindDataSource(this._dataSource); } break; default: { var autoDeskArea = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CASHIER_CHECKAUTOOPENDESKAREA, false); if (autoDeskArea) { selectTable = table; this.superTabControl1.SelectedTab = this.superTabItem3; } else { this.OnAcceptButtonClick(new TransparentEventArgs(TransparentAction.Accept, "deskNo", new Tuple(table.No, table.Name,""))); this.DialogResult = DialogResult.OK; OnCloseTouchClick(this, null); } } break; } } } private int _columns = _DEFAULTCOLUMNS; /// /// 每一行显示的数量 /// public int Columns { get { return _columns; } set { _columns = (value <= 0 ? 1 : value); } } /// ///品类默认行数 /// public int Rows => this.deskNoPanel.Height / _DEFAULTITEMHIGHT; /// /// 每页的大小 /// public int PageSize { get; private set; } /// /// 总页数 /// public int PageCount => this.PageSize <= 0 ? 0 : ((this.TotalCount + this.PageSize - 1) / this.PageSize); /// /// 当前页码 /// public int PageNumber { get; set; } /// /// 总数量 /// public int TotalCount { get; private set; } } }