From d90ff5b8bddce0f5409365e487b7623fae4a51a7 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Sun, 18 Feb 2024 00:38:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StartServerWPF.Models/DataProModelArray.cs | 34 ++++++++++ .../StartServerWPF.Models.csproj | 1 + .../ViewModels/AddWorkAreaDialogViewModel.cs | 2 +- .../ViewModels/DataProcessViewModel.cs | 28 +++++++++ .../ViewModels/SetParamViewModel.cs | 62 +++++++++++++++++-- .../Views/DataProcessView.xaml | 48 ++++++++------ .../Views/SetParamView.xaml | 23 +++---- .../serverprogram/workarea/Workarea.json | 4 +- 8 files changed, 163 insertions(+), 39 deletions(-) create mode 100644 StartServerWPF.Models/DataProModelArray.cs diff --git a/StartServerWPF.Models/DataProModelArray.cs b/StartServerWPF.Models/DataProModelArray.cs new file mode 100644 index 0000000..18f3716 --- /dev/null +++ b/StartServerWPF.Models/DataProModelArray.cs @@ -0,0 +1,34 @@ +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StartServerWPF.Models +{ + public class DataProModelArray + { + public int selectIndex { get; set; } + public List dataProModels { get; set; } + } + + public class DataProModel: BindableBase + { + private string name; + private string dataPath; + private string resultPath; + private string startTime; + private string endTime; + + public string Name { get => name; set => SetProperty(ref name, value); } + + public string DataPath { get => dataPath; set => SetProperty(ref dataPath, value); } + + public string ResultPath { get => resultPath; set => SetProperty(ref resultPath, value); } + + public string StartTime { get => startTime; set => SetProperty(ref startTime, value); } + + public string EndTime { get => endTime; set => SetProperty(ref endTime, value); } + } +} diff --git a/StartServerWPF.Models/StartServerWPF.Models.csproj b/StartServerWPF.Models/StartServerWPF.Models.csproj index 862b166..21f7542 100644 --- a/StartServerWPF.Models/StartServerWPF.Models.csproj +++ b/StartServerWPF.Models/StartServerWPF.Models.csproj @@ -55,6 +55,7 @@ + diff --git a/StartServerWPF.Modules.Main/ViewModels/AddWorkAreaDialogViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/AddWorkAreaDialogViewModel.cs index 4b9a6ba..dd26447 100644 --- a/StartServerWPF.Modules.Main/ViewModels/AddWorkAreaDialogViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/AddWorkAreaDialogViewModel.cs @@ -91,7 +91,7 @@ namespace StartServerWPF.Modules.Main.ViewModels workareaModel.savepath = WorkAreaPath; workareaModel.workareaname = WorkAreaName; //生成工区默认配置文件 - File.WriteAllText(Path.Combine(WorkAreaPath, Path.GetFileName(WorkAreaPath) + ".json"), JsonConvert.SerializeObject(workareaModel)); + File.WriteAllText(Path.Combine(WorkAreaPath, Path.GetFileName(WorkAreaPath) + ".json"), JsonConvert.SerializeObject(workareaModel, Formatting.Indented)); dialog.Parameters.Add("param1", workareas); RequestClose?.Invoke( dialog); } diff --git a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs index 8921fa5..1f84947 100644 --- a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Drawing.Drawing2D; using System.IO; using System.Linq; using System.Text; @@ -114,6 +115,33 @@ namespace StartServerWPF.Modules.Main.ViewModels WareaSelectedIndex = _workareasModelArray.selectIndex; }); + public DelegateCommand SaveCommand => new(() => + { + + DataProModelArray dataProModelArray = new DataProModelArray(); + dataProModelArray.selectIndex = 0; + dataProModelArray.dataProModels = new List(); + dataProModelArray.dataProModels.Add(new DataProModel + { + Name = DateTime.Now.ToString("d"), + DataPath = DataPath, + ResultPath = SavePath, + StartTime = DateTime.Now.ToString("G"), + EndTime = DateTime.Now.ToString("G") + }); + string jsonStr = JsonConvert.SerializeObject(dataProModelArray, Formatting.Indented); + var model = _workareasModelArray.workarea[WareaSelectedIndex]; + + File.WriteAllText(Path.Combine( model.filepath, "datapro.json"), jsonStr); + }); + + + + public DelegateCommand DeleteCommand => new(() => + { + + }); + public DelegateCommand SelectFileCommand => new((obj) => { diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs index a1e32b2..ffa8f0e 100644 --- a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs @@ -42,7 +42,7 @@ namespace StartServerWPF.Modules.Main.ViewModels string apmttime2dFile = string.Empty; private readonly IDialogService _dialogService; private SystemConfigModel _systemConfig; - private readonly WorkareasModelArray _workareasModelArray; + private WorkareasModelArray _workareasModelArray; private ObservableCollection _workareaNameSource; public ObservableCollection WorkareaNameSource { @@ -60,13 +60,23 @@ namespace StartServerWPF.Modules.Main.ViewModels try { var area = _workareasModelArray.workarea[value]; + WareaModel.savepath = area.filepath; string file = Path.Combine(area.filepath, Path.GetFileName(area.filepath) + ".json"); string json = File.ReadAllText(file); WareaModel = JsonConvert.DeserializeObject(json); } catch (Exception ex) { - MessageBox.Show("当前工区目录配置文件不存在," + ex.Message); + //生成工区默认配置文件 + string str = File.ReadAllText(Path.Combine(JsonParser.workareaPath, "Workarea.json")); + string path = WareaModel.savepath; + WareaModel = JsonConvert.DeserializeObject(str); + WareaModel.savepath = path; + string file = Path.Combine(path, Path.GetFileName(path) + ".json"); + WareaModel.workareaname = Path.GetFileName(WareaModel.savepath); + + File.WriteAllText(file, JsonConvert.SerializeObject(WareaModel)); + //MessageBox.Show("当前工区目录配置文件不存在," + ex.Message); } _workareasModelArray.selectIndex = value; } @@ -97,12 +107,10 @@ namespace StartServerWPF.Modules.Main.ViewModels { apmStationFile = string.Empty; apmttime2dFile = string.Empty; - // WareaModel.apmModel = ; }); public DelegateCommand AddItemCommand => new(() => { - DialogParameters param = new DialogParameters(); // param.Add("type", 1);// 编辑 _dialogService.ShowDialog("AddWorkAreaDialog", @@ -129,6 +137,47 @@ namespace StartServerWPF.Modules.Main.ViewModels })); }); + public DelegateCommand ImportCommand => new(() => + { + System.Windows.Forms.OpenFileDialog fbd = new System.Windows.Forms.OpenFileDialog(); + fbd.Multiselect = false; + fbd.Filter = ".json|*.json|.txt|*.txt"; + if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + try + { + string jsonStr = File.ReadAllText(fbd.FileName); + _workareasModelArray = JsonConvert.DeserializeObject(jsonStr); + WorkareaNameSource = new ObservableCollection(); + _workareasModelArray.workarea.Select(n => n.workareaname).ToList().ForEach(a => WorkareaNameSource.Add(a)); + WareaSelectedIndex = _workareasModelArray.selectIndex; + var item = _workareasModelArray.workarea[_workareasModelArray.selectIndex]; + string areaPath = Path.Combine(item.filepath, Path.GetFileName(item.filepath) + ".json"); + var currentWorkarea = new WorkareaModel(); + if (File.Exists(areaPath)) + { + string workarea = File.ReadAllText(areaPath); + currentWorkarea = JsonConvert.DeserializeObject(workarea); + if (currentWorkarea.StationConfig.Stations == null) + { + currentWorkarea.StationConfig.Stations = currentWorkarea.CreateStationFromCSV(Path.Combine(JsonParser.workareaPath, currentWorkarea.apmModel.station), currentWorkarea.StationConfig.Location) + ?.Select(a => new StationState { IsEnable = a.Enable, Name = a.Num }).ToList(); + } + WareaModel = currentWorkarea; + } + else + { + MessageBox.Show("工区配置文件不存在!"); + } + } + catch (Exception ex) + { + + MessageBox.Show("导入工区失败," + ex); + } + } + }); + public DelegateCommand DeleteItemCommand => new(() => { if (MessageBox.Show($"删除{WareaModel.workareaname}工区所有文件?", "提示", MessageBoxButton.OKCancel, @@ -144,6 +193,7 @@ namespace StartServerWPF.Modules.Main.ViewModels WareaSelectedIndex =0; } }); + public DelegateCommand SelectFileCommand => new((obj) => { string para = obj.ToString(); @@ -222,7 +272,7 @@ namespace StartServerWPF.Modules.Main.ViewModels station = string.Join(",", _wareaModel.StationConfig.Stations.Where(p => p.IsEnable).Select(n => n.Name)) } }; - JsonParser.WriteSystemConfigFile(Path.Combine(_wareaModel.savepath, "Workarea.json"), _wareaModel); + JsonParser.WriteSystemConfigFile(Path.Combine(_wareaModel.savepath, Path.GetFileName(_wareaModel.savepath) + ".json"), _wareaModel); var curWorkarea = JsonParser.DeepCopy(_wareaModel); if (!string.IsNullOrEmpty(apmStationFile)) @@ -234,7 +284,7 @@ namespace StartServerWPF.Modules.Main.ViewModels } apmStationFile = null; } - if(!string.IsNullOrEmpty(apmttime2dFile)) + if (!string.IsNullOrEmpty(apmttime2dFile)) { string destFileName = Path.GetFullPath(Path.Combine(curWorkarea.savepath, curWorkarea.apmModel.ttime[0].ttime2d)); if (destFileName != apmttime2dFile) diff --git a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml index 74ac600..35bc126 100644 --- a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml +++ b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml @@ -50,17 +50,23 @@ -