123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- namespace HistoryView.ViewModels.Regions.SettingSubs;
- internal partial class ConfigFileViewModel : ObservableObject
- {
- public ConfigFileViewModel(MessageBoxHelper messageBox, IDialogService dialogService, TemperatureConfigs temperatureConfigs, UserInformation user, HubSender sender)
- {
- this._sender = sender;
- this._messageBox = messageBox;
- this._dialogService = dialogService;
- this.TemperatureConfigs = temperatureConfigs;
- this.UserInfo = user;
- this.IsEditable = true;
- }
- private readonly HubSender _sender;
- private readonly MessageBoxHelper _messageBox;
- private readonly IDialogService _dialogService;
- [ObservableProperty]
- private TemperatureConfigs _temperatureConfigs;
- [ObservableProperty]
- private TempConfig? _Selected;
- [ObservableProperty]
- private UserInformation? _UserInfo;
- [ObservableProperty]
- private bool _IsEditable;
- [RelayCommand]
- private void Load()
- {
- this._dialogService.Show("File", new DialogParameters(), GetPara);
- }
- partial void OnSelectedChanged(TempConfig? value)
- {
- if (value is null)
- return;
- if (this.TemperatureConfigs.CurrentConfigFile is null)
- return;
- this.IsEditable = (value != this.TemperatureConfigs.CurrentConfigFile.ConfigFile);
- }
- [RelayCommand]
- private async Task ReadCurrentAndSave()
- {
- if (!this._sender.QueryMini8Data(out TempConfig? config) || config is null)
- {
- await _messageBox.ShowAsync("Error", icon: MessageBoxImage.Error);
- return;
- }
- config.ConfigName += "-Saved";
- IDialogParameters para = new DialogParameters
- {
- { "ConfigEditor", config }
- };
- this._dialogService.Show("ConfigEditor", para, null);
- }
- [RelayCommand]
- private void SelectCurrent()
- {
- if (this.TemperatureConfigs is null || this.TemperatureConfigs.CurrentConfigFile is null)
- return;
- this.Selected = this.TemperatureConfigs.CurrentConfigFile.ConfigFile;
- }
- [RelayCommand]
- private void Edit()
- {
- if (this.Selected is null)
- return;
- IDialogParameters para = new DialogParameters
- {
- { "ConfigEditor", this.Selected }
- };
- this._dialogService.Show("ConfigEditor", para, null);
- }
- [RelayCommand]
- private void Remove()
- {
- if (this.Selected is null)
- return;
- if (string.IsNullOrEmpty(this.Selected.ConfigName))
- return;
- var t = this._messageBox.ShowAsync($"{Selected.ConfigName} ?", MessageBoxButton.YesNo, MessageBoxImage.Question).Result;
- if (t.Result != ButtonResult.Yes)
- return;
- _sender.RemoveFile(this.Selected.ConfigName);
- }
- [RelayCommand]
- private void SetAsCurrent()
- {
- if (this.Selected is null)
- return;
- if (_messageBox is null)
- return;
- var t = this._messageBox.ShowAsync($"{Selected.ConfigName} {App.Current.FindResource("SetConfigAsCurrent")}", MessageBoxButton.YesNo, MessageBoxImage.Question).Result;
- if (t.Result != ButtonResult.Yes)
- return;
- this._sender.SetConfigFile(this.Selected.ConfigName);
- }
- [RelayCommand]
- private void Compare()
- {
- IDialogParameters para = new DialogParameters
- {
- { "Source", this.Selected! }
- };
- this._dialogService.Show("Compare", para, GetPara);
- }
- private void GetPara(IDialogResult dialogResult)
- {
- if (!dialogResult.Parameters.TryGetValue<FileInfo>("File", out FileInfo? file) || file is null)
- return;
- _sender.LoadNewFile(file.FullName);
- }
- }
|