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.
256 lines
8.4 KiB
C#
256 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using DevComponents.DotNetBar;
|
|
using POSV.Component;
|
|
using System.ComponentModel;
|
|
using POSV.Utils;
|
|
using System.Threading;
|
|
using System.Reflection;
|
|
using POS.Language.Language;
|
|
|
|
namespace POSV
|
|
{
|
|
public partial class SettingsForm : BusinessForm
|
|
{
|
|
private Dictionary<SettingContent , SuperTabItem> tabs = null;
|
|
|
|
private Dictionary<SettingContent , AbstractSettings> settings = null;
|
|
|
|
/// <summary>
|
|
/// 当前选择的配置项
|
|
/// </summary>
|
|
private SuperTabItem _currentTabItem = null;
|
|
|
|
public SettingsForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.controlBox.ForeColor = System.Drawing.Color.White;
|
|
|
|
this.tabs = new Dictionary<SettingContent , SuperTabItem>();
|
|
this.settings = new Dictionary<SettingContent , AbstractSettings>();
|
|
|
|
InitializeSettings();
|
|
}
|
|
|
|
|
|
private void InitializeSettings()
|
|
{
|
|
this.superTabControl.Tabs.Clear();
|
|
|
|
//构建TabItem标签,动态加载内容
|
|
foreach (SettingContent content in Enum.GetValues(typeof(SettingContent)))
|
|
{
|
|
var tab = this.superTabControl.CreateTab(LangProxy.ToLang(content.ToString()));
|
|
tab.Tag = content;
|
|
|
|
this.tabs.Add(content , tab);
|
|
|
|
this.settings.Add(content , null);
|
|
|
|
if (this._currentTabItem == null)
|
|
{
|
|
this._currentTabItem = tab;
|
|
}
|
|
|
|
Thread.Sleep(2);
|
|
}
|
|
|
|
this.superTabControl.SelectedTabChanging += OnSelectedTabChanging;
|
|
this.superTabControl.SelectedTabChanged += OnSelectedTabChanged;
|
|
|
|
|
|
}
|
|
|
|
private void RefreshUi(SettingContent tag)
|
|
{
|
|
var result = this.settings[tag];
|
|
if (result == null)
|
|
{
|
|
switch (tag)
|
|
{
|
|
case SettingContent.收银界面设置:
|
|
{
|
|
result = new POSV.Component.LayoutSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.收银功能设置:
|
|
{
|
|
result = new POSV.Component.CategorySettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.操作功能设置:
|
|
{
|
|
result = new POSV.Component.ModuleSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
|
|
case SettingContent.收银参数设置:
|
|
{
|
|
result = new POSV.Component.CashierSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.外设参数设置:
|
|
{
|
|
result = new POSV.Component.PeripheralSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.小票打印设置:
|
|
{
|
|
result = new POSV.Component.PrinterSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.标签打印设置:
|
|
{
|
|
result = new POSV.Component.LabelPrinterSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.电子秤设置:
|
|
{
|
|
result = new POSV.Component.WeightSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
case SettingContent.商场接口配置:
|
|
{
|
|
result = new POSV.Component.ShopApiConfigSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
result = new POSV.Component.OtherSettings();
|
|
result.Dock = DockStyle.Fill;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
result.Tag = tag;
|
|
|
|
this.settings[tag] = result;
|
|
this.tabs[tag].AttachedControl.Controls.Add(result);
|
|
|
|
this._currentTabItem = this.tabs[tag];
|
|
this.superTabControl.SelectedTab = this._currentTabItem;
|
|
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
RefreshUi(SettingContent.收银界面设置);
|
|
}
|
|
|
|
|
|
private void OnSelectedTabChanged(object sender , DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs e)
|
|
{
|
|
if (e.NewValue != null && e.NewValue.Tag != null)
|
|
{
|
|
var settings = SettingContent.收银界面设置;
|
|
Enum.TryParse(e.NewValue.Tag.ToString() , out settings);
|
|
|
|
this.RefreshUi(settings);
|
|
}
|
|
}
|
|
|
|
private void OnSelectedTabChanging(object sender , DevComponents.DotNetBar.SuperTabStripSelectedTabChangingEventArgs e)
|
|
{
|
|
if (e.OldValue != null && e.OldValue.Tag is SettingContent)
|
|
{
|
|
var content = SettingContent.收银界面设置;
|
|
Enum.TryParse(e.OldValue.Tag.ToString() , out content);
|
|
|
|
var settings = this.settings[content];
|
|
if(settings != null)
|
|
{
|
|
var newValue = settings.NewChanged();
|
|
if (newValue.Any())
|
|
{
|
|
string message = "您修改了[" + e.OldValue.Text + "]的参数,是否要保存?";
|
|
DialogForm dialog = new DialogForm("参数变更" , message , MessageBoxIcon.Warning , MessageBoxButtons.YesNo);
|
|
DialogResult result = dialog.ShowDialog();
|
|
if (DialogResult.Yes == result)
|
|
{
|
|
settings.SaveChanged(newValue);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void FormClose()
|
|
{
|
|
OnControlBoxCloseClick(this , EventArgs.Empty);
|
|
}
|
|
|
|
private void OnControlBoxCloseClick(object sender , EventArgs e)
|
|
{
|
|
if (this.Owner != null)
|
|
{
|
|
this.Owner.Close();
|
|
}
|
|
|
|
this.Close();
|
|
}
|
|
|
|
private void OnControlBoxWindowMoveClick(object sender , MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnControlBoxKeyboardClick(object sender , EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
KeyboardType keyboardType = KeyboardType.数字;
|
|
Type type = this.ActiveControl.GetType();
|
|
PropertyInfo pinfo = type.GetProperty("Keyboard");
|
|
if (pinfo != null)
|
|
{
|
|
keyboardType = (KeyboardType)pinfo.GetValue(this.ActiveControl , null);
|
|
}
|
|
|
|
var keyboard = Application.OpenForms["VirtualKeyboard"];
|
|
if (keyboard == null)
|
|
{
|
|
keyboard = new VirtualKeyboard(keyboardType);
|
|
}
|
|
|
|
((VirtualKeyboard)keyboard).ShowVirtualKeyboard(this , keyboardType);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LOGGER.Error(ex , "打开屏幕键盘异常");
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum SettingContent
|
|
{
|
|
收银界面设置 = 0,
|
|
收银功能设置 = 1,
|
|
操作功能设置 = 2,
|
|
收银参数设置 = 3,
|
|
小票打印设置 = 4,
|
|
标签打印设置 = 5,
|
|
外设参数设置 = 6,
|
|
//移动支付设置 = 7
|
|
电子秤设置 = 8,
|
|
商场接口配置 = 9
|
|
}
|
|
}
|