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.

409 lines
20 KiB
C#

using JwKdsV.Core;
using JwKdsV.Core.DisplaySetting;
using JwKdsV.Core.MessageEvent;
using JwKdsV.Core.Utils;
using JwKdsV.Entity;
using JwKdsV.Entity.Normal;
using POSV.Common;
using POSV.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JwKdsV.Business
{
public partial class SettingsForm : Form
{
private Dictionary<string, Config> initData = new Dictionary<string, Config>();
public SettingsForm()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.pTitleFontCom.DataSource = System.Enum.GetNames(typeof(SystemFont));
this.pContentFontCom.DataSource = System.Enum.GetNames(typeof(SystemFont));
this.pBottomFontCom.DataSource = System.Enum.GetNames(typeof(SystemFont));
this.orderFontSizeCom.DataSource = System.Enum.GetNames(typeof(SystemFont));
this.cCategoryNameFontCom.DataSource = System.Enum.GetNames(typeof(SystemFont));
LoadSetting();
}
private void LoadSetting()
{
var defaultDic = Core.ConfigConstant.Business_DefaultValue();
initData = SettingApi.LoadSettingsAndSaveDefault(defaultDic);
InstallCategoryDualList();
InitializeSettingUI();
}
private void InstallCategoryDualList()
{
List<ProductType> typeList = null;
using(var db = Core.Global.Instance.OpenDataBase)
{
typeList = db.Fetch<ProductType>();
}
this.dualListBox1.DataSource = typeList;
this.dualListBox1.DisplayMember = "Name";
this.dualListBox1.ValueMember = "Id";
}
/// <summary>
/// 初始化界面
/// </summary>
/// <param name="data"></param>
private void InitializeSettingUI()
{
foreach (var key in initData.Keys)
{
var values = initData[key].Values;
if (string.IsNullOrEmpty(values)) continue;
switch (key)
{
case Core.ConfigConstant.CONFIG_BUSINESS_DISPLAYWAY://厨显方式
{
switch (values)
{
case "order":
this.orderRadio.Checked = true;
break;
case "product":
this.productRadio.Checked = true;
break;
case "category":
this.categoryRadio.Checked = true;
break;
}
}
break;
case Core.ConfigConstant.CONFIG_BUSINESS_ORDERSTYLE://厨显整单样式
{
if (!string.IsNullOrEmpty(values))
{
var style = JsonUtils.Deserialize<OrderShowStyle>(values);
orderRowNumSpinners.DefaultValue = style.Row;
orderColumnNumSpinners.DefaultValue = style.Column;
orderFontSizeCom.Text = style.FontSize.ToString();
orderFontColorCom.Color = ColorTranslator.FromHtml(style.FontColor);
orderPerRowsCom.DefaultValue = style.PerRows;
}
}
break;
case Core.ConfigConstant.CONFIG_BUSINESS_ORDERITEMSTYLE://厨显单品样式
{
if (!string.IsNullOrEmpty(values))
{
var style = JsonUtils.Deserialize<ProductShowStyle>(values);
this.pWidthCom.DefaultValue = style.Width;
this.pHeightCom.DefaultValue = style.Height;
//标题
var titleStyle = style.Title;
this.pTitleRatioCom.DefaultValue = titleStyle.Ratio;
this.pTitleFontCom.Text = titleStyle.FontSize.ToString();
this.pTitleFontColorCom.Color = ColorTranslator.FromHtml(titleStyle.FontColor);
this.pTitleContentCom.Text = titleStyle.Content;
//内容
var contentStyle = style.Content;
this.pContentRatioCom.DefaultValue = contentStyle.Ratio;
this.pContentFontCom.Text = contentStyle.FontSize.ToString();
this.pContentFontColorCom.Color = ColorTranslator.FromHtml(contentStyle.FontColor);
this.pContentContentCom.Text = contentStyle.Content;
//底部
var bottomStyle = style.Bottom;
this.pBottomRatioCom.DefaultValue = bottomStyle.Ratio;
this.pBottomFontCom.Text = bottomStyle.FontSize.ToString();
this.pBottomFontColorCom.Color = ColorTranslator.FromHtml(bottomStyle.FontColor);
this.pBottomContentCom.Text = bottomStyle.Content;
}
}
break;
case Core.ConfigConstant.CONFIG_BUSINESS_CATEGORYSTYLE://分类泳道展示样式
if (!string.IsNullOrEmpty(values))
{
var style = JsonUtils.Deserialize<CategoryShowStyle>(values);
cRowNumSpinners.DefaultValue = style.Row;
cColumnNumSpinners.DefaultValue = style.Column;
this.cCategoryNameFontColorCom.Color = ColorTranslator.FromHtml(style.CategoryFontColor);
this.cCategoryNameFontCom.Text = style.CategoryFontSize.ToString();
this.cCategoryNameBackColorCom.Color = ColorTranslator.FromHtml(style.CategoryBackColor);
this.dualListBox1.SelectedValues = style.ShowCategorys;
this.cLaneWidthCom.Text = style.LaneWidthCustom;
}
break;
case Core.ConfigConstant.CONFIG_BUSINESS_TICKETNUM://票号显示位数
this.ticketNumCom.DefaultValue = DecimalUtils.GetDecimal(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_TIMEOUTWARN://超时提醒开关
this.timeOutWarnCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_CHUPINCONFIRM://出品提示
this.chupinConfirmCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_SHOWWAIMAI://不显示外卖单
this.mainShowWaimaiCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_KDSBACKGROUNDCOLOR: //kds背景颜色
this.kdsColorCom.Color = ColorTranslator.FromHtml(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_ORDERNORMALCOLOR: // 项目正常颜色
this.normalColorCom.Color = ColorTranslator.FromHtml(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_ONEWARNCOLOR: //1级预警颜色
this.oneWarnColorCom.Color = ColorTranslator.FromHtml(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_TWOWARNCOLOR: //2级预警颜色
this.twoWarnColorCom.Color = ColorTranslator.FromHtml(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_KDSCATEGORY: //kds类型
{
KDSCategory kdsCategory = KDSCategory.;
Enum.TryParse<KDSCategory>(values, out kdsCategory);
switch (kdsCategory)
{
case KDSCategory.:
this.chuxianButton.Checked = true;
break;
case KDSCategory.:
this.chupinButton.Checked = true;
break;
}
}
break;
case Core.ConfigConstant.CONFIG_BUSINESS_SERVICECENTER_IP://服务中心IP
this.serviceIpCom.Text = values;
break;
case Core.ConfigConstant.CONFIG_BUSINESS_SERVICECENTER_PORT://服务中心端口
this.servicePortCom.Text = values;
break;
case Core.ConfigConstant.CONFIG_BUSINESS_ORDERSHOWDESKNO://订单显示桌号
this.orderShowDeskNoCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_ENABLE_ORDERNO://订单使用订单序号
this.orderEnableOrderNoCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_MAKECOLOR://做法特殊颜色
this.makeColorCom.Color = ColorTranslator.FromHtml(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_NEWORDERSOUND://新订单语音提醒
this.newOrderSoundCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_MAINSHOWTODAY://主界面显示今日统计
this.mainShowTodayCom.Checked = values == "true";
break;
case Core.ConfigConstant.CONFIG_BUSINESS_HUADANCOLOR://已划单背景颜色
this.huadanColorCom.Color = ColorTranslator.FromHtml(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_CHUPINHISTORYDATATIME://显示历史出品记录时间间隔值
this.chupinHistoryDataTimeCom.DefaultValue = DecimalUtils.GetDecimal(values);
break;
case Core.ConfigConstant.CONFIG_BUSINESS_WAITCHUPINDATATIME://显示待出品记录时间间隔值
this.waitChupinDataTimeCom.DefaultValue = DecimalUtils.GetDecimal(values);
break;
}
}
}
public Tuple<bool, string> SaveChange(List<Config> changes)
{
SettingApi.SaveSettings(changes);
MsgEvent.Send(Core.Constant.STYLECHANGED, null);
return new Tuple<bool, string>(true, "保存成功");
}
/// <summary>
/// 获取变更内容
/// </summary>
/// <returns></returns>
public List<Config> GetChange()
{
List<Config> result = new List<Config>();
Dictionary<string, string> newSettingDic = GetSettings();
foreach (var key in newSettingDic.Keys)
{
var newValues = newSettingDic[key];
if (!newValues.Equals(initData[key].Values))
{
var changeConfig = ObjectUtils.Copy(initData[key]);
changeConfig.Values = newValues;
result.Add(changeConfig);
}
}
return result;
}
public Dictionary<string, string> GetSettings()
{
Dictionary<string, string> result = new Dictionary<string, string>();
//厨显方式
string displayWay = "order";
if (this.orderRadio.Checked)
{
displayWay = "order";
}
else if (this.productRadio.Checked)
{
displayWay = "product";
}
else if (this.categoryRadio.Checked)
{
displayWay = "category";
}
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_DISPLAYWAY, displayWay);
//厨显整单样式
OrderShowStyle orderStyle = new OrderShowStyle();
orderStyle.Row = DecimalUtils.GetInt(this.orderRowNumSpinners.NumValue);
orderStyle.Column = DecimalUtils.GetInt(this.orderColumnNumSpinners.NumValue);
orderStyle.FontSize = (SystemFont)Enum.Parse(typeof(SystemFont), this.orderFontSizeCom.Text);
orderStyle.FontColor = ColorTranslator.ToHtml(orderFontColorCom.Color);
orderStyle.PerRows = DecimalUtils.GetInt(this.orderPerRowsCom.NumValue);
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_ORDERSTYLE, JsonUtils.Serialize(orderStyle));
//厨显单品样式
ProductShowStyle pStyle = new ProductShowStyle();
pStyle.Width = DecimalUtils.GetInt(this.pWidthCom.NumValue);
pStyle.Height = DecimalUtils.GetInt(this.pHeightCom.NumValue);
//标题
var title = new ProductShowItem();
title.Ratio = DecimalUtils.GetInt(this.pTitleRatioCom.NumValue);
title.FontSize = (SystemFont)Enum.Parse(typeof(SystemFont), this.pTitleFontCom.Text);
title.FontColor = ColorTranslator.ToHtml(pTitleFontColorCom.Color);
title.Content = this.pTitleContentCom.Text;
pStyle.Title = title;
//内容
var content = new ProductShowItem();
content.Ratio = DecimalUtils.GetInt(this.pContentRatioCom.NumValue);
content.FontSize = (SystemFont)Enum.Parse(typeof(SystemFont), this.pContentFontCom.Text);
content.FontColor = ColorTranslator.ToHtml(pContentFontColorCom.Color);
content.Content = this.pContentContentCom.Text;
pStyle.Content = content;
//底部
var bottom = new ProductShowItem();
bottom.Ratio = DecimalUtils.GetInt(this.pBottomRatioCom.NumValue);
bottom.FontSize = (SystemFont)Enum.Parse(typeof(SystemFont), this.pBottomFontCom.Text);
bottom.FontColor = ColorTranslator.ToHtml(pBottomFontColorCom.Color);
bottom.Content = this.pBottomContentCom.Text;
pStyle.Bottom = bottom;
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_ORDERITEMSTYLE, JsonUtils.Serialize(pStyle));
//分类泳道展示样式
CategoryShowStyle cStyle = new CategoryShowStyle();
cStyle.Row = DecimalUtils.GetInt(this.cRowNumSpinners.NumValue);
cStyle.Column = DecimalUtils.GetInt(this.cColumnNumSpinners.NumValue);
cStyle.CategoryFontColor = ColorTranslator.ToHtml(this.cCategoryNameFontColorCom.Color);
cStyle.CategoryFontSize = (SystemFont)Enum.Parse(typeof(SystemFont), this.cCategoryNameFontCom.Text);
cStyle.CategoryBackColor = ColorTranslator.ToHtml(this.cCategoryNameBackColorCom.Color);
cStyle.LaneWidthCustom = this.cLaneWidthCom.Text.Trim();
List<string> showCategorys = new List<string>();
var selectCategory = this.dualListBox1.SelectedValues as List<object>;
foreach (var temp in selectCategory)
{
var type = temp as ProductType;
showCategorys.Add(type.Id);
}
cStyle.ShowCategorys = showCategorys;
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_CATEGORYSTYLE, JsonUtils.Serialize(cStyle));
//票号显示位数
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_TICKETNUM, this.ticketNumCom.NumValue.ToString());
//超时提醒开关
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_TIMEOUTWARN, this.timeOutWarnCom.Checked.ToString().ToLower());
//出品提示
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_CHUPINCONFIRM, this.chupinConfirmCom.Checked.ToString().ToLower());
//不显示外卖单
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_SHOWWAIMAI, this.mainShowWaimaiCom.Checked.ToString().ToLower());
//kds背景颜色
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_KDSBACKGROUNDCOLOR, ColorTranslator.ToHtml(this.kdsColorCom.Color));
//项目正常颜色
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_ORDERNORMALCOLOR, ColorTranslator.ToHtml(this.normalColorCom.Color));
//1级预警颜色
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_ONEWARNCOLOR, ColorTranslator.ToHtml(this.oneWarnColorCom.Color));
//2级预警颜色
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_TWOWARNCOLOR, ColorTranslator.ToHtml(this.twoWarnColorCom.Color));
//kds类型
string kdsCategory = KDSCategory..ToString();
if (this.chupinButton.Checked)
{
kdsCategory = KDSCategory..ToString();
}
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_KDSCATEGORY, kdsCategory);
//服务中心IP
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_SERVICECENTER_IP, this.serviceIpCom.Text.Trim());
//服务中心端口
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_SERVICECENTER_PORT, this.servicePortCom.Text.Trim());
//订单显示桌号
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_ORDERSHOWDESKNO, this.orderShowDeskNoCom.Checked.ToString().ToLower());
//订单使用订单序号
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_ENABLE_ORDERNO, this.orderEnableOrderNoCom.Checked.ToString().ToLower());
//做法特殊颜色
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_MAKECOLOR, ColorTranslator.ToHtml(this.makeColorCom.Color));
//新订单语音提醒
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_NEWORDERSOUND, this.newOrderSoundCom.Checked.ToString().ToLower());
//主界面显示今日统计
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_MAINSHOWTODAY, this.mainShowTodayCom.Checked.ToString().ToLower());
//已划单背景颜色
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_HUADANCOLOR, ColorTranslator.ToHtml(this.huadanColorCom.Color));
//显示历史出品记录时间间隔值
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_CHUPINHISTORYDATATIME, this.chupinHistoryDataTimeCom.NumValue.ToString());
//显示待出品记录时间间隔值
result.Add(Core.ConfigConstant.CONFIG_BUSINESS_WAITCHUPINDATATIME, this.waitChupinDataTimeCom.NumValue.ToString());
return result;
}
private void OnContentLabelClick(object sender, EventArgs e)
{
var label = sender as Label;
var targetControl = this.ActiveControl;
if (targetControl is TextBox)
{
var target = string.Format("@{0}@", label.Text);
if (targetControl.Text.Contains(target))
{
targetControl.Text = targetControl.Text.Replace(target, "");
}
else
{
targetControl.Text += string.Format("@{0}@", label.Text);
}
}
}
private void OnSaveClick(object sender, EventArgs e)
{
var changes = GetChange();
if(changes != null && changes.Count > 0)
{
SaveChange(changes);
}
MessageBox.Show("保存成功");
}
private void OnCancelClick(object sender, EventArgs e)
{
this.Close();
}
}
}