报表页查询改为异步并显示进度

master
tayttt 5 days ago
parent 6ad2e7e227
commit 651b3b0be7

@ -75,6 +75,12 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
public int dayFreqImageHeight = 585; public int dayFreqImageHeight = 585;
public int reportDayListFirstRow = 35; public int reportDayListFirstRow = 35;
public int reportEventListCols = 10; public int reportEventListCols = 10;
private class SearchProgressInfo
{
public int CompletedCount { get; set; }
public int TotalCount { get; set; }
public string Message { get; set; }
}
/// <summary> /// <summary>
/// 查询模式0自定义查询1日报2周报3月报 /// 查询模式0自定义查询1日报2周报3月报
/// </summary> /// </summary>
@ -260,6 +266,80 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
SetProperty(ref _maxEnergy, value); 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; private string _likeCondition;
public string LikeCondition public string LikeCondition
@ -325,78 +405,123 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
} }
public ICommand SelectEventListCommand public ICommand SelectEventListCommand
{ {
get => new DelegateCommand<ReportView>((rView) => get => new DelegateCommand<ReportView>(async (rView) => await ExecuteSelectEventListAsync(rView));
}
public ICommand SelectDayCommand
{ {
SelectType = 0; get => new DelegateCommand<ReportView>(async (rView) => await ExecuteSelectDayAsync(rView));
DateTime st = TimeFC.Cond1; }
DateTime et = TimeFC.Cond2;
var results = SearchEvents(st, et);
if (results != null) private async Task ExecuteSelectEventListAsync(ReportView rView)
{ {
SelectResult = new ObservableCollection<GridItemEventResult>(results); if (IsSearching)
//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(); return;
//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<ReportView>((rView) => if (IsSearching)
{ {
return;
}
SelectType = 1; SelectType = 1;
//日报起始时刻
DateTime drstarttime = GlobalConfig.DailyReportStartTime; DateTime drstarttime = GlobalConfig.DailyReportStartTime;
Console.WriteLine(GlobalConfig.DailyReportStartTime.ToString());
DateTime st = new DateTime(TimeFC.Cond1.Year, TimeFC.Cond1.Month, TimeFC.Cond1.Day, DateTime st = new DateTime(TimeFC.Cond1.Year, TimeFC.Cond1.Month, TimeFC.Cond1.Day,
drstarttime.Hour, drstarttime.Minute, drstarttime.Second); drstarttime.Hour, drstarttime.Minute, drstarttime.Second);
await ExecuteSearchAsync(rView, st, st.AddSeconds(86399), true);
}
var results = SearchEvents(st, st.AddSeconds(86399)); private async Task ExecuteSearchAsync(ReportView rView, DateTime st, DateTime et, bool createDayFreq)
{
try
{
IsSearching = true;
ResetSearchProgress("正在查询事件数据...");
var progress = new Progress<SearchProgressInfo>(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;
}
}
if (results != null) private void ApplySearchResults(ReportView rView, List<GridItemEventResult> results, DateTime st, bool createDayFreq)
{
if (results == null)
{ {
return;
}
SelectResult = new ObservableCollection<GridItemEventResult>(results); SelectResult = new ObservableCollection<GridItemEventResult>(results);
SearchCount = results.Count;
UpdateEnergyStats(results);
if (createDayFreq)
{
FreqChart = CreateDayFreqImage(results, st, st.ToString("D", culture)); FreqChart = CreateDayFreqImage(results, st, st.ToString("D", culture));
//freqBytes = BitmapHelper.ConvertToBytes(ExportToBitmap(FreqChart, dayFreqImageWidth, dayFreqImageHeight)); }
var mes = results.Where(rs => rs.Energy >= MiddleEnergy).ToList(); var mes = results.Where(rs => rs.Energy >= MiddleEnergy).ToList();
//new ReportPlanImage().DrawPlanClipToFile(mes);
MiddleEnergyEvents = mes; MiddleEnergyEvents = mes;
MiddleEventCount = mes.Count(); MiddleEventCount = mes.Count();
if (mes.Count > 0) if (mes.Count > 0 && rView != null)
{ {
ReportPlanImage rpi = new ReportPlanImage(); ReportPlanImage rpi = new ReportPlanImage();
//rpi.DrawPlanClipToDrawVisual(mes, (int)rView.canvasPlan.ActualWidth, (int)rView.canvasPlan.ActualHeight);
rpi.Draw(mes, rView.canvasPlan.ActualWidth, rView.canvasPlan.ActualHeight); rpi.Draw(mes, rView.canvasPlan.ActualWidth, rView.canvasPlan.ActualHeight);
//rView.canvasPlan = rpi.host;
rView.canvasPlan.Children.Clear(); rView.canvasPlan.Children.Clear();
rView.canvasPlan.Children.Add(rpi.host); rView.canvasPlan.Children.Add(rpi.host);
CreateStereoChart(mes); CreateStereoChart(mes);
}
} }
//rView.canvasPlan. private void ResetSearchProgress(string message)
//dayMiddleEventPlanBytes = new ReportPlanImage().DrawPlanClipToFile(mes); {
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;
} }
/// <summary> /// <summary>
@ -583,7 +708,20 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
StereoChart.View3D.PointLineSeries3D.Add(plsEvent3d); StereoChart.View3D.PointLineSeries3D.Add(plsEvent3d);
stereoChart.EndUpdate(); stereoChart.EndUpdate();
} }
private Task<List<GridItemEventResult>> SearchEventsAsync(DateTime searchStartTime, DateTime searchEndTime, IProgress<SearchProgressInfo> progress)
{
return Task.Run(() => SearchEventsCore(searchStartTime, searchEndTime, progress));
}
public List<GridItemEventResult> SearchEvents(DateTime searchStartTime, DateTime searchEndTime) public List<GridItemEventResult> SearchEvents(DateTime searchStartTime, DateTime searchEndTime)
{
var results = SearchEventsCore(searchStartTime, searchEndTime, null);
SearchCount = results.Count;
UpdateEnergyStats(results);
return results;
}
private List<GridItemEventResult> SearchEventsCore(DateTime searchStartTime, DateTime searchEndTime, IProgress<SearchProgressInfo> progress)
{ {
List<GridItemEventResult> results = new List<GridItemEventResult>(); List<GridItemEventResult> results = new List<GridItemEventResult>();
string findStr = "select * from " + GlobalConfig.UseResultTable; 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<RemoteRealtimeResultEntity>() var list = fsqlTencent.Select<RemoteRealtimeResultEntity>()
.WithSql(findStr).ToList(); .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) if (list != null)
{ {
int completedCount = 0;
foreach (var item in list) foreach (var item in list)
{ {
GridItemEventResult se = new GridItemEventResult(item, true); GridItemEventResult se = new GridItemEventResult(item, true);
@ -683,10 +841,18 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
se.Direction = curMmEvent.Direction; se.Direction = curMmEvent.Direction;
se.SetEnergy(); se.SetEnergy();
results.Add(se); results.Add(se);
completedCount++;
if (progress != null)
{
progress.Report(new SearchProgressInfo
{
CompletedCount = completedCount,
TotalCount = totalCount,
Message = "正在计算震源机制"
});
}
} }
} }
SearchCount = results.Count;
UpdateEnergyStats(results);
return results; return results;
} }

@ -450,6 +450,7 @@
Style="{StaticResource MaterialDesignRaisedDarkButton}" Style="{StaticResource MaterialDesignRaisedDarkButton}"
Command="{Binding SelectEventListCommand}" Command="{Binding SelectEventListCommand}"
CommandParameter="{Binding ElementName=rView}" CommandParameter="{Binding ElementName=rView}"
IsEnabled="{Binding IsSearchEnabled}"
Cursor="Hand" /> Cursor="Hand" />
<Button Grid.Column="1" <Button Grid.Column="1"
Width="70" Width="70"
@ -459,6 +460,7 @@
Style="{StaticResource MaterialDesignRaisedDarkButton}" Style="{StaticResource MaterialDesignRaisedDarkButton}"
Command="{Binding SelectDayCommand}" Command="{Binding SelectDayCommand}"
CommandParameter="{Binding ElementName=rView}" CommandParameter="{Binding ElementName=rView}"
IsEnabled="{Binding IsSearchEnabled}"
Cursor="Hand" /> Cursor="Hand" />
<Button Grid.Column="2" <Button Grid.Column="2"
Width="70" Width="70"
@ -468,6 +470,7 @@
Style="{StaticResource MaterialDesignRaisedDarkButton}" Style="{StaticResource MaterialDesignRaisedDarkButton}"
Command="{Binding ExportDayFileExcelCmd}" Command="{Binding ExportDayFileExcelCmd}"
CommandParameter="{Binding ElementName=contentStereo}" CommandParameter="{Binding ElementName=contentStereo}"
IsEnabled="{Binding IsSearchEnabled}"
Cursor="Hand" /> Cursor="Hand" />
<Button Grid.Column="2" <Button Grid.Column="2"
Width="70" Width="70"
@ -476,6 +479,7 @@
FontSize="16" FontSize="16"
Command="{Binding ExportWeekListFileExcelCmd}" Command="{Binding ExportWeekListFileExcelCmd}"
CommandParameter="{Binding ElementName=contentStereo}" CommandParameter="{Binding ElementName=contentStereo}"
IsEnabled="{Binding IsSearchEnabled}"
Style="{StaticResource MaterialDesignRaisedDarkButton}" Style="{StaticResource MaterialDesignRaisedDarkButton}"
Cursor="Hand" /> Cursor="Hand" />
<Button Grid.Column="3" <Button Grid.Column="3"
@ -483,6 +487,7 @@
Height="34" Height="34"
Content="月报" Content="月报"
FontSize="16" FontSize="16"
IsEnabled="{Binding IsSearchEnabled}"
Style="{StaticResource MaterialDesignRaisedDarkButton}" /> Style="{StaticResource MaterialDesignRaisedDarkButton}" />
<Button Grid.Row="1" <Button Grid.Row="1"
@ -493,6 +498,7 @@
FontSize="16" FontSize="16"
Style="{StaticResource MaterialDesignRaisedDarkButton}" Style="{StaticResource MaterialDesignRaisedDarkButton}"
Command="{Binding ExportEventListFileExcelCmd}" Command="{Binding ExportEventListFileExcelCmd}"
IsEnabled="{Binding IsSearchEnabled}"
CommandParameter="{Binding ElementName=rView}" /> CommandParameter="{Binding ElementName=rView}" />
</Grid> </Grid>
</Grid> </Grid>
@ -535,6 +541,26 @@
Width="60" Width="60"
Text="{Binding MaxEnergy, StringFormat={}{0:F0}J}" /> Text="{Binding MaxEnergy, StringFormat={}{0:F0}J}" />
</WrapPanel> </WrapPanel>
<WrapPanel Margin="20,4,0,0"
VerticalAlignment="Center"
Visibility="{Binding SearchProgressVisibility}">
<hc:CircleProgressBar Width="44"
Height="44"
Margin="0,0,10,0"
Minimum="0"
Maximum="100"
Value="{Binding SearchProgressValue}"
Text="{Binding SearchProgressPercentText}"
FontSize="10"
ShowText="True"
IsIndeterminate="{Binding SearchProgressIndeterminate}"
ArcThickness="8"
Style="{StaticResource ProgressBarWarningCircle}" />
<TextBlock VerticalAlignment="Center"
Foreground="Black"
FontSize="14"
Text="{Binding SearchProgressText}" />
</WrapPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>

Loading…
Cancel
Save