using CapMachine.Core; using CapMachine.Wpf.Models; using CapMachine.Wpf.Models.PPCalc; using CapMachine.Wpf.Services; using Prism.Commands; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Win32; using System.Windows.Controls; using System.Windows.Forms; using NPOI.HPSF; namespace CapMachine.Wpf.ViewModels { public class DialogSuperHeatCoolConfigViewModel : DialogViewModel { public DialogSuperHeatCoolConfigViewModel(PPCService pPCService) { Title = "过热度/过冷度设置"; PPCService = pPCService; SuperHeatCoolConfig = PPCService.SuperHeatCoolConfig; CryogenComboBoxList = new List() { new ComboBoxModel(){Key="0",Text="R134a" }, new ComboBoxModel(){Key="1",Text="R1234yf" }, }; } private List _CryogenComboBoxList; /// /// 制冷剂下拉框列表 /// public List CryogenComboBoxList { get { return _CryogenComboBoxList; } set { _CryogenComboBoxList = value; RaisePropertyChanged(); } } /// /// 当前的过热度和过冷度的配置 /// public SuperHeatCoolConfigModel SuperHeatCoolConfig { get; set; } private DelegateCommand _OpenSuperHeatCoolPathCmd; /// /// 打开过热度和过冷度的文件指令 /// public DelegateCommand OpenSuperHeatCoolPathCmd { set { _OpenSuperHeatCoolPathCmd = value; } get { if (_OpenSuperHeatCoolPathCmd == null) { _OpenSuperHeatCoolPathCmd = new DelegateCommand(() => OpenSuperHeatCoolPathCmdMethod()); } return _OpenSuperHeatCoolPathCmd; } } /// /// 打开过热度和过冷度的文件文件信息 /// private void OpenSuperHeatCoolPathCmdMethod() { //DbcFilePath try { var TargetFilePath = GetFilePath(); if (!string.IsNullOrEmpty(TargetFilePath)) { SuperHeatCoolConfig.FluidsPath = TargetFilePath; } //System.Diagnostics.Process.Start(fileName);//打开指定路径下的文件 } catch (Exception ex) { System.Windows.MessageBox.Show("可能未选择文件路径", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand); } } /// /// 获取保存文件的路径 /// /// public string GetFilePath() { using (var folderBrowserDialog = new FolderBrowserDialog()) { folderBrowserDialog.Description = "请选择一个文件夹"; folderBrowserDialog.ShowNewFolderButton = true; if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string selectedPath = folderBrowserDialog.SelectedPath; // 处理选中的文件夹路径 return selectedPath; } else { return null; } } } private string name; /// /// 名称 /// public string Name { get { return name; } set { name = value; RaisePropertyChanged(); } } private DelegateCommand saveCmd; /// /// 保存命令 /// public DelegateCommand SaveCmd { set { saveCmd = value; } get { if (saveCmd == null) { saveCmd = new DelegateCommand(() => SaveCmdMethod()); } return saveCmd; } } /// /// 保存命令方法 /// /// private void SaveCmdMethod() { DialogParameters pars = new DialogParameters { { "Name", Name } }; RaiseRequestClose(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK, pars)); } private DelegateCommand cancelCmd; /// /// 保存命令 /// public DelegateCommand CancelCmd { set { cancelCmd = value; } get { if (cancelCmd == null) { cancelCmd = new DelegateCommand(() => CancelCmdMethod()); } return cancelCmd; } } public PPCService PPCService { get; } /// /// 取消命令方法 /// /// private void CancelCmdMethod() { RaiseRequestClose(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel)); } /// /// 窗口打开时的传递的参数 /// /// public override void OnDialogOpened(IDialogParameters parameters) { //Name = parameters.GetValue("Name"); } } }