using System;
|
using System.IO;
|
using System.Windows;
|
using System.Windows.Controls;
|
using HMI.Core.Api;
|
using HMI.Core.Setting;
|
using HMI.Core.Util;
|
using HMI.UI.Util;
|
using Microsoft.Win32;
|
|
namespace HMI.SettingControl
|
{
|
/// <summary>
|
/// SystemConfig.xaml 的交互逻辑
|
/// </summary>
|
public partial class SystemConfig : UserControl, IFolderOwner, IConfigManager
|
{
|
private string BaseFolder;
|
private SystemSettingModel Model;
|
public SystemConfig()
|
{
|
InitializeComponent();
|
}
|
|
public object GetConfig()
|
{
|
return SystemSetting.Instance;
|
}
|
|
public void ResetConfig()
|
{
|
Model = new SystemSettingModel();
|
BeanUtil.Copy(SystemSetting.Instance, Model);
|
DataContext = Model;
|
}
|
|
public void SaveConfig()
|
{
|
SystemSettingModel settingModel = (SystemSettingModel)DataContext;
|
XmlHelper.SerializeToXml(Path.Combine(PathHelper.SettingFolder, "SystemConfig.xml"), settingModel);
|
SystemSetting.ReLoad();
|
}
|
|
public void SetBaseFolder(string folder)
|
{
|
this.BaseFolder = folder;
|
}
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
{
|
Button btn = sender as Button;
|
switch (btn.Name)
|
{
|
case "BtnIcon":
|
OpenSelectIcon();
|
break;
|
case "BtnLoginLogo":
|
OpenSelectIcon2();
|
break;
|
default:
|
break;
|
}
|
}
|
|
private void OpenSelectIcon()
|
{
|
string BasePath = PathHelper.IconFolder;
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
openFileDialog.Filter = "(*.*)|*.*";
|
openFileDialog.InitialDirectory = BasePath;
|
openFileDialog.Title = this.lang("App.SelectPic");
|
openFileDialog.Multiselect = false;
|
|
if (openFileDialog.ShowDialog() == true)
|
{
|
string FileName = openFileDialog.FileName;
|
if (!FileName.StartsWith(BasePath))
|
{
|
ToastHelper.Warning(Window.GetWindow(this), this.lang("App.IconMustInFolder"));
|
}
|
else
|
{
|
Model.LogoPath = FileName.Replace(BasePath, ".");
|
}
|
}
|
}
|
|
private void OpenSelectIcon2()
|
{
|
string BasePath = PathHelper.IconFolder;
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
openFileDialog.Filter = "(*.*)|*.*";
|
openFileDialog.InitialDirectory = BasePath;
|
openFileDialog.Title = this.lang("App.SelectPic");
|
openFileDialog.Multiselect = false;
|
|
if (openFileDialog.ShowDialog() == true)
|
{
|
string FileName = openFileDialog.FileName;
|
if (!FileName.StartsWith(BasePath))
|
{
|
ToastHelper.Warning(Window.GetWindow(this), this.lang("App.IconMustInFolder"));
|
}
|
else
|
{
|
Model.LoginLogoPath = FileName.Replace(BasePath, ".");
|
}
|
}
|
}
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
{
|
CbLang.ItemsSource = LangUtil.langs;
|
ResetConfig();
|
Loaded -= UserControl_Loaded;
|
}
|
}
|
}
|