livia-test/Livia/Views/Controls/DataBlockTableControl.xaml.cs
2025-03-28 14:31:53 +08:00

145 lines
5.2 KiB
C#

using System.Windows;
using Livia.Models.Data;
using Livia.Utility.DependencyInjection;
using Livia.ViewModels;
using Livia.Views.Utility;
using Microsoft.Extensions.DependencyInjection;
using Ookii.Dialogs.Wpf;
namespace Livia.Views.Controls;
/// <summary>
/// Interaction logic for DataBlockTableControl.xaml
/// </summary>
public partial class DataBlockTableControl
{
private readonly IWarningSystem _warningSystem;
public DataBlockTableControl()
{
_warningSystem = ActivatorUtilities.GetServiceOrCreateInstance<IWarningSystem>(ServiceProviderFactory.ServiceProvider);
InitializeComponent();
}
private async void LoadDataButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data == null || DataContext is not DataBlockTableViewModel viewModel)
return;
await viewModel.LoadData(data).ConfigureAwait(false);
}
private void CheckReportsButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data == null || data.Key == null)
return;
CheckReportDialog checkReportDialog = new(data.Key, false, data.PatientName ?? "");
checkReportDialog.ShowDialog();
}
private async void DownloadArchiveButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data == null || DataContext is not DataBlockTableViewModel viewModel)
return;
VistaSaveFileDialog dialog = new()
{
OverwritePrompt = true,
CheckFileExists = true,
CheckPathExists = true,
AddExtension = true,
FileName = $"{data.PatientName}_archive",
Filter = "zip|*.zip",
DefaultExt = ".zip"
};
if (!(dialog.ShowDialog() ?? false))
return;
ProgressBarDialog progressBarDialog = new(true);
progressBarDialog.Show();
await progressBarDialog.SetTask(viewModel.DownloadArchive(data, dialog.FileName, progressBarDialog.CancellationToken)).ConfigureAwait(false);
}
private async void DownloadSortedButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data == null || DataContext is not DataBlockTableViewModel viewModel)
return;
VistaSaveFileDialog dialog = new()
{
OverwritePrompt = true,
CheckFileExists = true,
CheckPathExists = true,
AddExtension = true,
FileName = $"{data.PatientName}_sort",
Filter = "zip|*.zip",
DefaultExt = ".zip"
};
if (!(dialog.ShowDialog() ?? false))
return;
ProgressBarDialog progressBarDialog = new(true);
progressBarDialog.Show();
await progressBarDialog.SetTask(viewModel.DownloadSorted(data, dialog.FileName, progressBarDialog.CancellationToken)).ConfigureAwait(false);
}
private async void CancelButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data == null)
return;
bool confirm = _warningSystem.ShowDialog(WarningWindowKind.Confirmation, true, "ConfirmCancelWarning") ?? false;
if (!confirm)
return;
data.SetJobCanceled();
await ((DataBlockTableViewModel)DataContext).CancelData(data);
}
private void SelectSeriesButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data?.Key == null)
return;
SelectSeriesDialog dialog = new(data.Key);
dialog.Show();
}
private async void DeleteDataButtonClick(object sender, RoutedEventArgs e)
{
ServerJobData? data = ViewUtility.GetDataContextFromSender<ServerJobData>(sender);
if (data == null || DataContext is not DataBlockTableViewModel viewModel)
return;
bool confirm = _warningSystem.ShowDialog(WarningWindowKind.Confirmation, true, "ConfirmDeleteWarning") ?? false;
if (!confirm)
return;
ProgressBarDialog progressBarDialog = new(true);
progressBarDialog.Show();
await progressBarDialog.SetTask(viewModel.DeleteData(data, progressBarDialog.CancellationToken)).ConfigureAwait(false);
}
private async void HistoryListDeleteHistoryButtonClick(object sender, RoutedEventArgs e)
{
DataHistory? data = ViewUtility.GetDataContextFromSender<DataHistory>(sender);
if (data == null || DataContext is not DataBlockTableViewModel viewModel)
return;
bool confirm = _warningSystem.ShowDialog(WarningWindowKind.Confirmation, true, "ConfirmDeleteWarning") ?? false;
if (!confirm)
return;
ProgressBarDialog progressBarDialog = new(true);
progressBarDialog.Show();
await progressBarDialog.SetTask(viewModel.DeleteHistory(data, progressBarDialog.CancellationToken)).ConfigureAwait(false);
}
}