98 lines
3 KiB
C#
98 lines
3 KiB
C#
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using Livia.Properties;
|
|
using Livia.Utility.DependencyInjection;
|
|
using Livia.ViewModels;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Ookii.Dialogs.Wpf;
|
|
|
|
namespace Livia.Views;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for SelectReportModuleDialog.xaml
|
|
/// </summary>
|
|
public partial class SelectReportModuleDialog
|
|
{
|
|
public static string FilterString { get; set; } = "PDF|*.pdf";
|
|
private readonly ILogger _logger;
|
|
private readonly SelectReportModuleWindowViewModel _viewModel;
|
|
|
|
public SelectReportModuleDialog()
|
|
{
|
|
_logger = ActivatorUtilities.GetServiceOrCreateInstance<ILogger>(ServiceProviderFactory.ServiceProvider);
|
|
_viewModel = ActivatorUtilities.CreateInstance<SelectReportModuleWindowViewModel>(ServiceProviderFactory.ServiceProvider);
|
|
DataContext = _viewModel;
|
|
_viewModel.OnRequestClose += (_, _) => Close();
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void WindowClosing(object sender, CancelEventArgs e)
|
|
{
|
|
_viewModel.Dispose();
|
|
}
|
|
|
|
private void TitleBarMouseLeftButtonDown(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DragMove();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
_logger.LogError(exception, "Error dragging window, sender = {sender}, event = {event}", sender, e);
|
|
}
|
|
}
|
|
|
|
public async void ConfirmButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!_viewModel.CheckReportNameValid())
|
|
return;
|
|
|
|
ConfirmButton.IsEnabled = false;
|
|
|
|
string name = _viewModel.PatientInfoManager.AnonymousMode ? "Anonymous" : _viewModel.PatientInfoManager.PatientName;
|
|
VistaSaveFileDialog dialog = new()
|
|
{
|
|
OverwritePrompt = true,
|
|
CheckFileExists = true,
|
|
CheckPathExists = true,
|
|
AddExtension = true,
|
|
FileName = $"{name}_{_viewModel.ReportName}".Trim(Path.GetInvalidFileNameChars()),
|
|
Filter = FilterString,
|
|
DefaultExt = ".pdf"
|
|
};
|
|
|
|
if (dialog.ShowDialog() ?? false)
|
|
{
|
|
try
|
|
{
|
|
if (await _viewModel.SelectReportModule(dialog.FileName))
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
_logger.LogError(exception, $"Error SelectReportModule, FileName = {dialog.FileName}");
|
|
}
|
|
}
|
|
|
|
if (!Settings.Default.ShowSelectReportModuleDialog)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
ConfirmButton.IsEnabled = true;
|
|
}
|
|
|
|
private void ReportNameTextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
double scale = string.Equals(ReportName.Text, SelectReportModuleWindowViewModel.DefaultReportName) ? 1d : 0d;
|
|
ReportName.SetValue(HintAssist.FloatingScaleProperty, scale);
|
|
}
|
|
} |