29 lines
1.2 KiB
C#
29 lines
1.2 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Platform.Storage;
|
|
using LehrerApp.Desktop.ViewModels.Students;
|
|
|
|
namespace LehrerApp.Desktop.Views.Students;
|
|
|
|
public partial class StudentReportDialog : Window
|
|
{
|
|
public StudentReportDialog()
|
|
{
|
|
InitializeComponent();
|
|
Closing += (_, e) => e.Cancel = DataContext is StudentReportDialogViewModel { IsGenerating: true };
|
|
}
|
|
private void OnClose(object? sender, RoutedEventArgs e) => Close();
|
|
private async void OnGenerate(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is not StudentReportDialogViewModel vm) return;
|
|
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
|
{
|
|
Title = "Schülerbericht speichern", SuggestedFileName = vm.SuggestedFileName,
|
|
DefaultExtension = "pdf", FileTypeChoices = [new FilePickerFileType("PDF") { Patterns = ["*.pdf"] }],
|
|
});
|
|
if (file is null) return;
|
|
if (await vm.GenerateAsync(file.Path.LocalPath))
|
|
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(file.Path.LocalPath) { UseShellExecute = true });
|
|
}
|
|
}
|