From 4f686ff5d09444e10b62a04e8def652491792bcd Mon Sep 17 00:00:00 2001 From: mzhifa Date: Thu, 7 Mar 2024 23:12:02 +0800 Subject: [PATCH] =?UTF-8?q?1=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=EF=BC=9B=202=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/DataProcessViewModel.cs | 42 ++++++++++++++++--- .../Views/DataProcessView.xaml | 1 + 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs index a9643b6..1324bb9 100644 --- a/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/DataProcessViewModel.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Drawing.Drawing2D; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -194,6 +195,17 @@ namespace StartServerWPF.Modules.Main.ViewModels DataSelectedIndex = 0; }; }); + public DelegateCommand CleanDataCommand => new(() => + { + //清除临时文件 + string temPath = Path.GetPathRoot(SavePath) + "temPath"; + if (Directory.Exists(temPath)) + { + Directory.Delete(temPath, true); + } + MessageBox.Show("清除成功!"); + + }); public DelegateCommand SaveCommand => new(() => { var item = NameSource[DataSelectedIndex]; @@ -232,7 +244,6 @@ namespace StartServerWPF.Modules.Main.ViewModels { DataPath = path; } - } }); @@ -255,13 +266,32 @@ namespace StartServerWPF.Modules.Main.ViewModels return; } DateTime dateTime = StartSelectedDate; - string temPath = Path.GetPathRoot(_workareaModel.savepath) + "temPath"; - //清除临时文件 - if (Directory.Exists(temPath)) + string temPath = Path.GetPathRoot(SavePath) + "temPath"; + + if (!Directory.Exists(temPath)) + { + Directory.CreateDirectory(temPath); + } + if (ApmsEventSource.Count > 0) { - Directory.Delete(temPath, true); + ApmsEventSource.Clear(); } - Directory.CreateDirectory(temPath); + var fileName = Directory.GetFiles(SavePath, "*.index", SearchOption.AllDirectories); + + foreach (var file in fileName) + { + bool flag= DateTime.TryParseExact(Path.GetFileNameWithoutExtension(file), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture, + DateTimeStyles.None, out DateTime da); + if (flag && StartSelectedDate.Date <= da && EndSelectedDate.Date >= da) + { + if (File.Exists(file)) + { + File.Delete(file); + } + } + + } + Task.Run(() => { IsBusy = false; diff --git a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml index 1b800f8..9daeed3 100644 --- a/StartServerWPF.Modules.Main/Views/DataProcessView.xaml +++ b/StartServerWPF.Modules.Main/Views/DataProcessView.xaml @@ -110,6 +110,7 @@ +