干度2的计算和多日期历史数据的选择的增加
This commit is contained in:
@@ -132,6 +132,20 @@ namespace CapMachine.Wpf.ViewModels
|
||||
set { _IsLeftDrawerOpen = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
private bool _IsBusy;
|
||||
public bool IsBusy
|
||||
{
|
||||
get { return _IsBusy; }
|
||||
set { _IsBusy = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
private string _BusyMessage = "正在加载,请稍候...";
|
||||
public string BusyMessage
|
||||
{
|
||||
get { return _BusyMessage; }
|
||||
set { _BusyMessage = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -417,7 +431,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// <summary>
|
||||
/// 获取试验数据的命令的执行方法
|
||||
/// </summary>
|
||||
private void HistoryDataFileCmdMethod()
|
||||
private async void HistoryDataFileCmdMethod()
|
||||
{
|
||||
if (SelectedHistoryExp == null)
|
||||
{
|
||||
@@ -449,58 +463,82 @@ namespace CapMachine.Wpf.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
CsvRecordModels = new List<CsvRecordModel>();
|
||||
BusyMessage = "正在加载CSV数据,请稍候...";
|
||||
IsBusy = true;
|
||||
|
||||
var loaded = new List<CsvRecordModel>();
|
||||
string errorText = string.Empty;
|
||||
|
||||
stopwatch.Start();
|
||||
|
||||
var errors = new StringBuilder();
|
||||
foreach (var f in files)
|
||||
try
|
||||
{
|
||||
try
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (f == null) continue;
|
||||
if (string.IsNullOrWhiteSpace(f.FilePath))
|
||||
var errors = new StringBuilder();
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
errors.AppendLine("发现空的文件地址");
|
||||
continue;
|
||||
}
|
||||
if (!File.Exists(f.FilePath))
|
||||
{
|
||||
errors.AppendLine($"没有发现地址对应的文件: {f.FilePath}");
|
||||
continue;
|
||||
}
|
||||
var f = files[i];
|
||||
try
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
BusyMessage = $"正在加载({i + 1}/{files.Count}):{System.IO.Path.GetFileName(f?.FilePath)}";
|
||||
});
|
||||
|
||||
var rec = ReadCsvFile(f.FilePath);
|
||||
if (rec != null && rec.Count > 0)
|
||||
{
|
||||
CsvRecordModels.AddRange(rec);
|
||||
if (f == null) continue;
|
||||
if (string.IsNullOrWhiteSpace(f.FilePath))
|
||||
{
|
||||
errors.AppendLine("发现空的文件地址");
|
||||
continue;
|
||||
}
|
||||
if (!File.Exists(f.FilePath))
|
||||
{
|
||||
errors.AppendLine($"没有发现地址对应的文件: {f.FilePath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var rec = ReadCsvFile(f.FilePath);
|
||||
if (rec != null && rec.Count > 0)
|
||||
{
|
||||
loaded.AddRange(rec);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errors.AppendLine($"读取CSV失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
errorText = errors.ToString();
|
||||
});
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(errorText))
|
||||
{
|
||||
errors.AppendLine($"读取CSV失败: {ex.Message}");
|
||||
System.Windows.MessageBox.Show(errorText, "读取提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
|
||||
CsvRecordModels = new List<CsvRecordModel>();
|
||||
if (loaded != null && loaded.Count > 0)
|
||||
{
|
||||
CsvRecordModels = loaded
|
||||
.Where(r => r != null)
|
||||
.OrderBy(r => r.CreateTime)
|
||||
.ToList();
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
EventAggregator.GetEvent<HistoryDataToChartEvent>().Publish(new HistoryDataToChartMsg() { Machine = "History", Data = CsvRecordModels });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.Length > 0)
|
||||
finally
|
||||
{
|
||||
System.Windows.MessageBox.Show(errors.ToString(), "读取提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine("加载CSV数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
|
||||
stopwatch.Reset();
|
||||
IsBusy = false;
|
||||
IsLeftDrawerOpen = false;
|
||||
}
|
||||
|
||||
if (CsvRecordModels.Count > 0)
|
||||
{
|
||||
CsvRecordModels = CsvRecordModels
|
||||
.Where(r => r != null)
|
||||
.OrderBy(r => r.CreateTime)
|
||||
.ToList();
|
||||
EventAggregator.GetEvent<HistoryDataToChartEvent>().Publish(new HistoryDataToChartMsg() { Machine = "History", Data = CsvRecordModels });
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine("加载CSV数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
|
||||
stopwatch.Reset();
|
||||
|
||||
IsLeftDrawerOpen = false;
|
||||
|
||||
}
|
||||
|
||||
private List<CsvRecordModel> ReadCsvFile(string filePath)
|
||||
|
||||
Reference in New Issue
Block a user