372 lines
11 KiB
C#
372 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Platform.Storage;
|
|
|
|
namespace spplus;
|
|
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
var res = MessageBox.Show(this, "Dieses Feature ist noch nicht implementiert", "Fehlend");
|
|
}
|
|
|
|
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
private void MnuHelp_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = "https://git.mypapercloud.de/fierke/spplus/wiki",
|
|
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void MnuGit_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = "https://git.mypapercloud.de/fierke/spplus",
|
|
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void MnuAbout_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
Window w = new();
|
|
w.WindowState = WindowState.Normal;
|
|
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
w.Width = 300;
|
|
w.Height = 120;
|
|
Grid g = new();
|
|
TextBlock tb = new()
|
|
{
|
|
Text = "spplus v1.0.0\n(c)2026 MyPapertown, Elias Fierke"
|
|
};
|
|
g.Children.Add(tb);
|
|
w.Content = g;
|
|
w.Show();
|
|
}
|
|
|
|
private async void BtnImport_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
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;
|
|
if (file.Count == 0) 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();
|
|
int count_selected = 0;
|
|
foreach (var s in Settings.Instance.Students)
|
|
{
|
|
LbStudentsImported.Items.Add(s);
|
|
count_selected += s.SelectedCourseNames.Count;
|
|
}
|
|
LblStudentAmount.Content = Settings.Instance.Students.Count.ToString();
|
|
LblSelectedAmount.Content = count_selected.ToString();
|
|
|
|
|
|
}
|
|
|
|
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
// Craft courses here / call course-crafter
|
|
CourseCrafter.Craft();
|
|
RefreshResultView();
|
|
TbiResults.Focus();
|
|
}
|
|
|
|
private void RefreshResultView()
|
|
{
|
|
LbResult.Items.Clear();
|
|
foreach (Student s in Settings.Instance.Students)
|
|
{
|
|
try
|
|
{
|
|
for(int i = 0; i<s.Result.Count;i++)
|
|
{
|
|
LbResult.Items.Add($"{s.Name} ({s.ID}) - {i+1}. Semester: {s.Result[i]}");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.StackTrace);
|
|
}
|
|
}
|
|
|
|
TbResultStatistics.Text = CourseCrafter.GenerateStatistics();
|
|
}
|
|
|
|
private void LbStudentsImported_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
{
|
|
Prepare();
|
|
var stud = (Student)LbStudentsImported.SelectedItem;
|
|
if (stud == null)
|
|
{
|
|
TbStudentName.Text = string.Empty;
|
|
TbStudentID.Text = string.Empty;
|
|
SetEmpty();
|
|
return;
|
|
};
|
|
|
|
try
|
|
{
|
|
TbStudentName.Text = stud.Name;
|
|
TbStudentID.Text = stud.ID;
|
|
LblSport1.Content = stud.SelectedCourseNames[0];
|
|
LblSport2.Content = stud.SelectedCourseNames[1];
|
|
LblSport3.Content = stud.SelectedCourseNames[2];
|
|
LblSport4.Content = stud.SelectedCourseNames[3];
|
|
}
|
|
catch
|
|
{
|
|
SetEmpty();
|
|
}
|
|
|
|
return;
|
|
|
|
void SetEmpty()
|
|
{
|
|
if(LblSport1.Content == "null") LblSport1.Content = "ungewählt";
|
|
if(LblSport2.Content == "null") LblSport2.Content = "ungewählt";
|
|
if(LblSport3.Content == "null") LblSport3.Content = "ungewählt";
|
|
if(LblSport4.Content == "null") LblSport4.Content = "ungewählt";
|
|
}
|
|
|
|
void Prepare()
|
|
{
|
|
LblSport1.Content = "null";
|
|
LblSport2.Content = "null";
|
|
LblSport3.Content = "null";
|
|
LblSport4.Content = "null";
|
|
}
|
|
|
|
}
|
|
|
|
private void TbStudentName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Student)LbStudentsImported.SelectedItem).Name = TbStudentName.Text;
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
private void TbStudentID_OnTextChanged(object? sender, TextChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Student)LbStudentsImported.SelectedItem).Name = TbStudentID.Text;
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void BtnImportDefaultCourses_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
Settings.ImportInitial();
|
|
RefreshCoursesList();
|
|
}
|
|
|
|
private void RefreshCoursesList()
|
|
{
|
|
LbSportCourses.Items.Clear();
|
|
foreach (var sp in Settings.Instance.Sports)
|
|
{
|
|
LbSportCourses.Items.Add(sp);
|
|
}
|
|
}
|
|
|
|
|
|
private void LbSportCourses_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (LbSportCourses.SelectedItem != null)
|
|
{
|
|
if (LbSportCourses.SelectedItem is Sport item)
|
|
{
|
|
LblSportID.Content = item.ID;
|
|
TbSportName.Text = item.Name;
|
|
NudSportMaxStudents.Value = item.MaxStudents;
|
|
NudSportMinStudents.Value = item.MinStudents;
|
|
NudAmountCoursesSem1.Value = item.Semester[0];
|
|
NudAmountCoursesSem2.Value = item.Semester[1];
|
|
NudAmountCoursesSem3.Value = item.Semester[2];
|
|
NudAmountCoursesSem4.Value = item.Semester[3];
|
|
LbAlternativeCourses.Items.Clear();
|
|
foreach (var alternative in item.AlternativeCourses)
|
|
{
|
|
LbAlternativeCourses.Items.Add(Settings.GetSportNameFromID(alternative));
|
|
}
|
|
LbAlternativeNames.Items.Clear();
|
|
foreach (var alternative in item.AlternativeNames)
|
|
{
|
|
LbAlternativeNames.Items.Add(alternative);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void TbSportName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).Name = TbSportName.Text;
|
|
} catch {}
|
|
}
|
|
|
|
private void NudSportMaxStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).MaxStudents = Convert.ToInt32(NudSportMaxStudents.Value);
|
|
} catch {}
|
|
}
|
|
|
|
private void NudSportMinStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).MinStudents = Convert.ToInt32(NudSportMinStudents.Value);
|
|
} catch {}
|
|
}
|
|
|
|
private void NudAmountCoursesSem1_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).Semester[0] = Convert.ToInt32(NudAmountCoursesSem1.Value);
|
|
} catch {}
|
|
}
|
|
|
|
private void NudAmountCoursesSem2_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).Semester[1] = Convert.ToInt32(NudAmountCoursesSem2.Value);
|
|
} catch {}
|
|
}
|
|
|
|
private void NudAmountCoursesSem3_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).Semester[2] = Convert.ToInt32(NudAmountCoursesSem3.Value);
|
|
} catch {}
|
|
}
|
|
|
|
private void NudAmountCoursesSem4_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).Semester[3] = Convert.ToInt32(NudAmountCoursesSem4.Value);
|
|
} catch {}
|
|
}
|
|
|
|
private void BtnAlternativeCourseAdd_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
|
//TbSportAlternativeCourse.Text = "";
|
|
} catch {}
|
|
}
|
|
|
|
private void BtnAlternativeNameAdd_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
|
LbAlternativeNames.Items.Add(TbSportAlternativeName.Text);
|
|
TbSportAlternativeName.Text = "";
|
|
|
|
int curr_selected = LbSportCourses.SelectedIndex;
|
|
RefreshCoursesList();
|
|
LbSportCourses.SelectedIndex = curr_selected;
|
|
} catch {}
|
|
}
|
|
|
|
private void BtnAlternativeNameRemove_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
//try
|
|
//{
|
|
LbAlternativeNames.Items.Remove(LbAlternativeNames.SelectedItem);
|
|
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Clear();
|
|
foreach (string s in LbAlternativeNames.Items)
|
|
{
|
|
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(s);
|
|
}
|
|
|
|
int curr_selected = LbSportCourses.SelectedIndex;
|
|
RefreshCoursesList();
|
|
LbSportCourses.SelectedIndex = curr_selected;
|
|
//} catch (Exception ex) {}
|
|
}
|
|
|
|
private void BtnClearCourseList_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
Settings.Instance.Sports.Clear();
|
|
RefreshCoursesList();
|
|
}
|
|
|
|
private void BtnDeleteSinleCourse_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Settings.Instance.Sports.Remove(LbSportCourses.SelectedItem as Sport);
|
|
RefreshCoursesList();
|
|
} catch (Exception ex){}
|
|
}
|
|
} |