diff --git a/Txgy.EWS.Client.PageModule/ViewModels/ReportViewModel.cs b/Txgy.EWS.Client.PageModule/ViewModels/ReportViewModel.cs
index 625bffc..a3427d4 100644
--- a/Txgy.EWS.Client.PageModule/ViewModels/ReportViewModel.cs
+++ b/Txgy.EWS.Client.PageModule/ViewModels/ReportViewModel.cs
@@ -75,6 +75,12 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
public int dayFreqImageHeight = 585;
public int reportDayListFirstRow = 35;
public int reportEventListCols = 10;
+ private class SearchProgressInfo
+ {
+ public int CompletedCount { get; set; }
+ public int TotalCount { get; set; }
+ public string Message { get; set; }
+ }
///
/// 查询模式:0:自定义查询;1:日报;2:周报;3:月报
///
@@ -260,6 +266,80 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
SetProperty(ref _maxEnergy, value);
}
}
+ private bool _isSearching;
+
+ public bool IsSearching
+ {
+ get { return _isSearching; }
+ set
+ {
+ if (SetProperty(ref _isSearching, value))
+ {
+ SearchProgressVisibility = value ? Visibility.Visible : Visibility.Collapsed;
+ RaisePropertyChanged(nameof(IsSearchEnabled));
+ }
+ }
+ }
+
+ public bool IsSearchEnabled
+ {
+ get { return !IsSearching; }
+ }
+
+ private Visibility _searchProgressVisibility = Visibility.Collapsed;
+
+ public Visibility SearchProgressVisibility
+ {
+ get { return _searchProgressVisibility; }
+ set
+ {
+ SetProperty(ref _searchProgressVisibility, value);
+ }
+ }
+
+ private bool _searchProgressIndeterminate = true;
+
+ public bool SearchProgressIndeterminate
+ {
+ get { return _searchProgressIndeterminate; }
+ set
+ {
+ SetProperty(ref _searchProgressIndeterminate, value);
+ }
+ }
+
+ private double _searchProgressValue;
+
+ public double SearchProgressValue
+ {
+ get { return _searchProgressValue; }
+ set
+ {
+ SetProperty(ref _searchProgressValue, value);
+ }
+ }
+
+ private string _searchProgressText = "";
+
+ public string SearchProgressText
+ {
+ get { return _searchProgressText; }
+ set
+ {
+ SetProperty(ref _searchProgressText, value);
+ }
+ }
+
+ private string _searchProgressPercentText = "";
+
+ public string SearchProgressPercentText
+ {
+ get { return _searchProgressPercentText; }
+ set
+ {
+ SetProperty(ref _searchProgressPercentText, value);
+ }
+ }
private string _likeCondition;
public string LikeCondition
@@ -325,78 +405,123 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
}
public ICommand SelectEventListCommand
{
- get => new DelegateCommand((rView) =>
+ get => new DelegateCommand(async (rView) => await ExecuteSelectEventListAsync(rView));
+ }
+ public ICommand SelectDayCommand
+ {
+ get => new DelegateCommand(async (rView) => await ExecuteSelectDayAsync(rView));
+ }
+
+ private async Task ExecuteSelectEventListAsync(ReportView rView)
+ {
+ if (IsSearching)
{
- SelectType = 0;
- DateTime st = TimeFC.Cond1;
- DateTime et = TimeFC.Cond2;
- var results = SearchEvents(st, et);
+ return;
+ }
- if (results != null)
- {
- SelectResult = new ObservableCollection(results);
- //FreqChart = CreateDayFreqImage(results, st, st.ToString("D", culture));
- //freqBytes = BitmapHelper.ConvertToBytes(ExportToBitmap(FreqChart, dayFreqImageWidth, dayFreqImageHeight));
- var mes = results.Where(rs => rs.Energy >= MiddleEnergy).ToList();
- //new ReportPlanImage().DrawPlanClipToFile(mes);
- MiddleEnergyEvents = mes;
- MiddleEventCount = mes.Count();
- if (mes.Count > 0)
- {
- ReportPlanImage rpi = new ReportPlanImage();
- //rpi.DrawPlanClipToDrawVisual(mes, (int)rView.canvasPlan.ActualWidth, (int)rView.canvasPlan.ActualHeight);
- rpi.Draw(mes, rView.canvasPlan.ActualWidth, rView.canvasPlan.ActualHeight);
- //rView.canvasPlan = rpi.host;
- rView.canvasPlan.Children.Clear();
- rView.canvasPlan.Children.Add(rpi.host);
- CreateStereoChart(mes);
- }
- }
- });
+ SelectType = 0;
+ DateTime st = TimeFC.Cond1;
+ DateTime et = TimeFC.Cond2;
+ await ExecuteSearchAsync(rView, st, et, false);
}
- public ICommand SelectDayCommand
+
+ private async Task ExecuteSelectDayAsync(ReportView rView)
{
- get => new DelegateCommand((rView) =>
+ if (IsSearching)
{
- SelectType = 1;
- //日报起始时刻
- DateTime drstarttime = GlobalConfig.DailyReportStartTime;
- Console.WriteLine(GlobalConfig.DailyReportStartTime.ToString());
- DateTime st = new DateTime(TimeFC.Cond1.Year, TimeFC.Cond1.Month, TimeFC.Cond1.Day,
- drstarttime.Hour, drstarttime.Minute, drstarttime.Second);
+ return;
+ }
- var results = SearchEvents(st, st.AddSeconds(86399));
+ SelectType = 1;
+ DateTime drstarttime = GlobalConfig.DailyReportStartTime;
+ DateTime st = new DateTime(TimeFC.Cond1.Year, TimeFC.Cond1.Month, TimeFC.Cond1.Day,
+ drstarttime.Hour, drstarttime.Minute, drstarttime.Second);
+ await ExecuteSearchAsync(rView, st, st.AddSeconds(86399), true);
+ }
- if (results != null)
- {
- SelectResult = new ObservableCollection(results);
+ private async Task ExecuteSearchAsync(ReportView rView, DateTime st, DateTime et, bool createDayFreq)
+ {
+ try
+ {
+ IsSearching = true;
+ ResetSearchProgress("正在查询事件数据...");
+ var progress = new Progress(UpdateSearchProgress);
+ var results = await SearchEventsAsync(st, et, progress);
+ ApplySearchResults(rView, results, st, createDayFreq);
+ }
+ catch (Exception ex)
+ {
+ HandyControl.Controls.MessageBox.Show("查询失败:" + ex.Message);
+ }
+ finally
+ {
+ IsSearching = false;
+ }
+ }
- FreqChart = CreateDayFreqImage(results, st, st.ToString("D", culture));
- //freqBytes = BitmapHelper.ConvertToBytes(ExportToBitmap(FreqChart, dayFreqImageWidth, dayFreqImageHeight));
+ private void ApplySearchResults(ReportView rView, List results, DateTime st, bool createDayFreq)
+ {
+ if (results == null)
+ {
+ return;
+ }
- var mes = results.Where(rs => rs.Energy >= MiddleEnergy).ToList();
- //new ReportPlanImage().DrawPlanClipToFile(mes);
- MiddleEnergyEvents = mes;
- MiddleEventCount = mes.Count();
- if (mes.Count > 0)
- {
- ReportPlanImage rpi = new ReportPlanImage();
- //rpi.DrawPlanClipToDrawVisual(mes, (int)rView.canvasPlan.ActualWidth, (int)rView.canvasPlan.ActualHeight);
- rpi.Draw(mes, rView.canvasPlan.ActualWidth, rView.canvasPlan.ActualHeight);
- //rView.canvasPlan = rpi.host;
- rView.canvasPlan.Children.Clear();
- rView.canvasPlan.Children.Add(rpi.host);
+ SelectResult = new ObservableCollection(results);
+ SearchCount = results.Count;
+ UpdateEnergyStats(results);
- CreateStereoChart(mes);
+ if (createDayFreq)
+ {
+ FreqChart = CreateDayFreqImage(results, st, st.ToString("D", culture));
+ }
- }
-
- //rView.canvasPlan.
- //dayMiddleEventPlanBytes = new ReportPlanImage().DrawPlanClipToFile(mes);
+ var mes = results.Where(rs => rs.Energy >= MiddleEnergy).ToList();
+ MiddleEnergyEvents = mes;
+ MiddleEventCount = mes.Count();
+ if (mes.Count > 0 && rView != null)
+ {
+ ReportPlanImage rpi = new ReportPlanImage();
+ rpi.Draw(mes, rView.canvasPlan.ActualWidth, rView.canvasPlan.ActualHeight);
+ rView.canvasPlan.Children.Clear();
+ rView.canvasPlan.Children.Add(rpi.host);
+ CreateStereoChart(mes);
+ }
+ }
+ private void ResetSearchProgress(string message)
+ {
+ SearchProgressIndeterminate = true;
+ SearchProgressValue = 0;
+ SearchProgressPercentText = "";
+ SearchProgressText = message;
+ }
+ private void UpdateSearchProgress(SearchProgressInfo progress)
+ {
+ if (progress == null)
+ {
+ return;
+ }
+
+ if (progress.TotalCount <= 0)
+ {
+ SearchProgressIndeterminate = progress.Message != "未查询到事件";
+ SearchProgressValue = 0;
+ SearchProgressPercentText = progress.Message == "未查询到事件" ? "0%" : "";
+ SearchProgressText = progress.Message;
+ if (progress.Message == "未查询到事件")
+ {
+ SearchCount = 0;
}
- });
+ return;
+ }
+
+ double percent = Math.Round(progress.CompletedCount * 100.0 / progress.TotalCount, 0);
+ SearchCount = progress.TotalCount;
+ SearchProgressIndeterminate = false;
+ SearchProgressValue = percent;
+ SearchProgressPercentText = percent.ToString("F0") + "%";
+ SearchProgressText = progress.Message + " " + progress.CompletedCount + "/" + progress.TotalCount;
}
///
@@ -583,7 +708,20 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
StereoChart.View3D.PointLineSeries3D.Add(plsEvent3d);
stereoChart.EndUpdate();
}
+ private Task> SearchEventsAsync(DateTime searchStartTime, DateTime searchEndTime, IProgress progress)
+ {
+ return Task.Run(() => SearchEventsCore(searchStartTime, searchEndTime, progress));
+ }
+
public List SearchEvents(DateTime searchStartTime, DateTime searchEndTime)
+ {
+ var results = SearchEventsCore(searchStartTime, searchEndTime, null);
+ SearchCount = results.Count;
+ UpdateEnergyStats(results);
+ return results;
+ }
+
+ private List SearchEventsCore(DateTime searchStartTime, DateTime searchEndTime, IProgress progress)
{
List results = new List();
string findStr = "select * from " + GlobalConfig.UseResultTable;
@@ -624,10 +762,30 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
{
}
}
+ if (progress != null)
+ {
+ progress.Report(new SearchProgressInfo
+ {
+ CompletedCount = 0,
+ TotalCount = 0,
+ Message = "正在查询事件数据..."
+ });
+ }
var list = fsqlTencent.Select()
.WithSql(findStr).ToList();
+ int totalCount = list == null ? 0 : list.Count;
+ if (progress != null)
+ {
+ progress.Report(new SearchProgressInfo
+ {
+ CompletedCount = 0,
+ TotalCount = totalCount,
+ Message = totalCount == 0 ? "未查询到事件" : "正在计算震源机制"
+ });
+ }
if (list != null)
{
+ int completedCount = 0;
foreach (var item in list)
{
GridItemEventResult se = new GridItemEventResult(item, true);
@@ -683,10 +841,18 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
se.Direction = curMmEvent.Direction;
se.SetEnergy();
results.Add(se);
+ completedCount++;
+ if (progress != null)
+ {
+ progress.Report(new SearchProgressInfo
+ {
+ CompletedCount = completedCount,
+ TotalCount = totalCount,
+ Message = "正在计算震源机制"
+ });
+ }
}
}
- SearchCount = results.Count;
- UpdateEnergyStats(results);
return results;
}
diff --git a/Txgy.EWS.Client.PageModule/Views/ReportView.xaml b/Txgy.EWS.Client.PageModule/Views/ReportView.xaml
index 7c7c29e..7a9b048 100644
--- a/Txgy.EWS.Client.PageModule/Views/ReportView.xaml
+++ b/Txgy.EWS.Client.PageModule/Views/ReportView.xaml
@@ -450,6 +450,7 @@
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Command="{Binding SelectEventListCommand}"
CommandParameter="{Binding ElementName=rView}"
+ IsEnabled="{Binding IsSearchEnabled}"
Cursor="Hand" />
@@ -535,6 +541,26 @@
Width="60"
Text="{Binding MaxEnergy, StringFormat={}{0:F0}J}" />
+
+
+
+