diff --git a/MainWindow.axaml.cs b/MainWindow.axaml.cs index ff0b24d..3bc4416 100644 --- a/MainWindow.axaml.cs +++ b/MainWindow.axaml.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using Avalonia.Controls; using Avalonia.Interactivity; +using Avalonia.Platform.Storage; namespace spplus; @@ -71,9 +73,40 @@ public partial class MainWindow : Window w.Show(); } - private void BtnImport_OnClick(object? sender, RoutedEventArgs e) + private async void BtnImport_OnClick(object? sender, RoutedEventArgs e) { - // CSV Import + var topLevel = GetTopLevel(this); + var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = "CSV-Datei auswählen", + AllowMultiple = false, + FileTypeFilter = new[] + { + new FilePickerFileType(".csv-Datei") + { + Patterns = new[] { "*.csv" } + } + } + }); + + if (file == null) return; + + var imported_students = import.ImportStudentsFromFile(file[0].Path.LocalPath.ToString()); + foreach (var s in imported_students) + { + Settings.Instance.Students.Add(s); + } + RefreshImportedStudentList(); + + } + + private void RefreshImportedStudentList() + { + LbStudentsImported.Items.Clear(); + foreach (var s in Settings.Instance.Students) + { + LbStudentsImported.Items.Add(s); + } } private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)