| | |
| | | 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, IConfigManager |
| | | public partial class SystemConfig : UserControl, IFolderOwner, IConfigManager |
| | | { |
| | | private string BaseFolder; |
| | | private SystemSettingModel Model; |
| | | public SystemConfig() |
| | | { |
| | | var model = new SystemSettingModel(); |
| | | BeanUtil.Copy(SystemSetting.Instance, model); |
| | | DataContext = model; |
| | | InitializeComponent(); |
| | | } |
| | | |
| | |
| | | |
| | | public void ResetConfig() |
| | | { |
| | | var model = new SystemSettingModel(); |
| | | BeanUtil.Copy(SystemSetting.Instance, model); |
| | | DataContext = model; |
| | | Model = new SystemSettingModel(); |
| | | BeanUtil.Copy(SystemSetting.Instance, Model); |
| | | DataContext = Model; |
| | | } |
| | | |
| | | public void SaveConfig() |
| | | { |
| | | SystemSettingModel settingModel = (SystemSettingModel)DataContext; |
| | | XmlHelper.SerializeToXml(PathHelper.ConfigFolder + "\\SystemConfig.xml", settingModel); |
| | | XmlHelper.SerializeToXml(Path.Combine(PathHelper.SettingFolder, "SystemConfig.xml"), settingModel); |
| | | SystemSetting.ReLoad(); |
| | | } |
| | | |
| | | private void Button_Click(object sender, System.Windows.RoutedEventArgs e) |
| | | public void SetBaseFolder(string folder) |
| | | { |
| | | try |
| | | this.BaseFolder = folder; |
| | | } |
| | | |
| | | private void Button_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | Button btn = sender as Button; |
| | | switch (btn.Name) |
| | | { |
| | | case "BtnIcon": |
| | | OpenSelectIcon(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | catch (Exception ex) |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | this.Error($"保存失败!{ex.Message}"); |
| | | 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 UserControl_Loaded(object sender, RoutedEventArgs e) |
| | | { |
| | | CbLang.ItemsSource = LangUtil.langs; |
| | | ResetConfig(); |
| | | Loaded -= UserControl_Loaded; |
| | | } |
| | | } |
| | | } |