117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
using CapMachine.Core;
|
||
using CapMachine.Wpf.Models.PPCalc;
|
||
using Prism.Commands;
|
||
using Prism.Services.Dialogs;
|
||
using System;
|
||
using System.Globalization;
|
||
using System.Windows;
|
||
|
||
namespace CapMachine.Wpf.ViewModels
|
||
{
|
||
public class DialogTherdyConfigViewModel : DialogViewModel
|
||
{
|
||
private const string H3TempOffsetConfigKey = "Therdy_H3TempOffset_C";
|
||
|
||
public DialogTherdyConfigViewModel()
|
||
{
|
||
Title = "COP物性参数回差";
|
||
|
||
TherdyConfig = new TherdyConfigModel();
|
||
LoadConfig();
|
||
}
|
||
|
||
public TherdyConfigModel TherdyConfig { get; }
|
||
|
||
private string _h3TempOffsetText = string.Empty;
|
||
public string H3TempOffsetText
|
||
{
|
||
get { return _h3TempOffsetText; }
|
||
set { _h3TempOffsetText = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
private DelegateCommand saveCmd;
|
||
public DelegateCommand SaveCmd
|
||
{
|
||
get
|
||
{
|
||
if (saveCmd == null)
|
||
{
|
||
saveCmd = new DelegateCommand(SaveCmdMethod);
|
||
}
|
||
return saveCmd;
|
||
}
|
||
set { saveCmd = value; }
|
||
}
|
||
|
||
private DelegateCommand cancelCmd;
|
||
public DelegateCommand CancelCmd
|
||
{
|
||
get
|
||
{
|
||
if (cancelCmd == null)
|
||
{
|
||
cancelCmd = new DelegateCommand(CancelCmdMethod);
|
||
}
|
||
return cancelCmd;
|
||
}
|
||
set { cancelCmd = value; }
|
||
}
|
||
|
||
private void LoadConfig()
|
||
{
|
||
try
|
||
{
|
||
string raw = ConfigHelper.GetValue(H3TempOffsetConfigKey);
|
||
if (!string.IsNullOrWhiteSpace(raw) && double.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out var v))
|
||
{
|
||
TherdyConfig.H3TempOffset_C = v;
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
H3TempOffsetText = TherdyConfig.H3TempOffset_C.ToString(CultureInfo.InvariantCulture);
|
||
}
|
||
|
||
private void SaveConfig()
|
||
{
|
||
ConfigHelper.SetValue(H3TempOffsetConfigKey, TherdyConfig.H3TempOffset_C.ToString(CultureInfo.InvariantCulture));
|
||
}
|
||
|
||
private void SaveCmdMethod()
|
||
{
|
||
try
|
||
{
|
||
if (!double.TryParse(H3TempOffsetText, NumberStyles.Float, CultureInfo.InvariantCulture, out var offsetC))
|
||
{
|
||
MessageBox.Show("回差值格式不正确,请输入数字(例如 -10)。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
|
||
TherdyConfig.H3TempOffset_C = offsetC;
|
||
SaveConfig();
|
||
DialogParameters pars = new DialogParameters
|
||
{
|
||
{ "H3TempOffset_C", TherdyConfig.H3TempOffset_C }
|
||
};
|
||
RaiseRequestClose(new DialogResult(ButtonResult.OK, pars));
|
||
}
|
||
catch
|
||
{
|
||
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
|
||
}
|
||
}
|
||
|
||
private void CancelCmdMethod()
|
||
{
|
||
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
|
||
}
|
||
|
||
public override void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
LoadConfig();
|
||
}
|
||
}
|
||
}
|