93 Commits

Author SHA1 Message Date
fierke eea7b9f628 [fix:] sentence was too long 2026-06-04 19:15:03 +02:00
fierke a784e598de [chore:] forgot to 'git add' these... 2026-06-04 19:12:52 +02:00
fierke 66596b530b [feat:] im- and export (pdf/json) 2026-06-04 18:59:01 +02:00
fierke 5ef41b21b0 [gui:] buttons for im- and exporting 2026-06-04 18:58:32 +02:00
fierke c291ed1788 [file:] included fonts 2026-06-04 18:58:03 +02:00
fierke 78d25e6231 [fix:] Sport ids 2026-06-01 21:28:07 +02:00
fierke 73af2039ba [file:] added fonts 2026-06-01 21:27:29 +02:00
fierke c5be9d2c6e [feat:] frontend to edit courses (ai-slop) 2026-06-01 17:00:55 +02:00
fierke c46417c56d [chore:] single-semester-side limiting of courses 2026-06-01 17:00:39 +02:00
fierke 895c55a52f [chore:] cleaned up some rubbish 2026-06-01 13:14:03 +02:00
fierke e54e2e7840 [chore:] logo integration 2026-06-01 12:45:35 +02:00
fierke 0a710bea8b [chore:] window icon integration 2026-06-01 12:28:59 +02:00
fierke d4de543d71 [file:] added logo.ico 2026-06-01 12:25:33 +02:00
fierke a0eac4ae95 Merge pull request '[chore:] better crafting' (#5) from bettercrafting into main
Reviewed-on: #5
2026-05-30 11:33:11 +00:00
fierke 22e9377062 [chore:] better crafting 2026-05-29 12:52:02 +02:00
fierke 11e6aab8fd [fix:] removed triple-calling of OptimizeStudentWishCoverage() 2026-04-22 07:25:46 +02:00
fierke 13f313d4a0 Merge remote-tracking branch 'origin/main' 2026-04-21 14:14:07 +02:00
fierke 64951c579f [fix:] massive bug that prevented correct course crafting (sports's id was always 0) 2026-04-21 14:13:54 +02:00
fierke 4130c36335 [chore:] import function that won't be called 2026-04-21 14:13:14 +02:00
fierke 7f2fc99d0b [gui:] import-button in the menu 2026-04-21 14:12:54 +02:00
fierke eb640ff749 [chore:] file picker, but currently not using the file itself 2026-04-21 14:12:40 +02:00
fierke 54a564df04 [chore:] tiny little comment to prevent confusion 2026-04-21 14:11:51 +02:00
fierke 71dc63f2a2 [file:] added logo 2026-04-18 16:04:14 +02:00
fierke 68f673c8d7 Update README.md 2026-04-15 11:48:44 +00:00
fierke d5b7fd7af3 [file:] uploaded app-screenshots 2026-04-15 13:45:37 +02:00
fierke 573e7c86e8 [fix:] course amount per semester synchronized with NumCoursesPerSemester, fixing #1 2026-04-15 13:22:12 +02:00
fierke a1bf573a07 [chore:] updated version 2026-03-19 08:53:53 +01:00
fierke 525f3fb4ae Update README.md 2026-03-19 07:52:11 +00:00
fierke 9f298d8ce8 [chore:] implemented csv-export access from gui 2026-03-19 08:49:03 +01:00
fierke 11d9c641a6 [chore:] cleanup 2026-03-19 08:48:51 +01:00
fierke c2f7adc1d0 [fix:] typo 2026-03-19 08:48:34 +01:00
fierke c19f96ea37 [chore:] added results to Student.Result 2026-03-19 08:48:24 +01:00
fierke 9bbde62d70 [feat:] csv-exporter (basic implementation) 2026-03-19 08:48:01 +01:00
fierke a83f97828c [chore:] changed Student.Result-Field-Type to array 2026-03-19 08:47:38 +01:00
fierke 44654dd784 [gui:] added csv-export placeholder button 2026-03-18 14:37:23 +01:00
fierke 410055c9f2 [chore:] tiny improvements for ux 2026-03-18 14:33:45 +01:00
fierke ce75d8aa0b [gui:] re-renamed to spplus since it looks better :D 2026-03-18 14:33:33 +01:00
fierke be436f1b1c [feat:] voting numbers (total count) visible after importing 2026-03-18 14:24:49 +01:00
fierke 14c11b81b6 [gui:] added label for voting numbers 2026-03-18 14:24:31 +01:00
fierke dd38b91d68 [fix:] inconsistent gui 2026-03-18 14:19:12 +01:00
fierke 987f27fcbc [fix]: inconsistent course creation when changing NumCoursePerSemester 2026-03-18 14:13:16 +01:00
fierke 42ecde799c [chore:] removed some dirt 2026-03-18 08:36:00 +01:00
fierke ce70d86fd3 [fix:] semester delivery updated to perform better results 2026-03-18 08:35:48 +01:00
fierke ea280ea05d [feat:] max courses per semester changeable 2026-03-17 14:34:24 +01:00
fierke c2e230ca48 [fix:] gui-inconsistencies 2026-03-17 14:15:35 +01:00
fierke 30317dd1bb [fix:] course list refreshing after automated default loading 2026-03-17 14:10:13 +01:00
fierke 6753acc04f [chore:] working ai-slop movement for better compensation 2026-03-17 14:08:19 +01:00
fierke 4468651373 [chore:] removed some unneccessary comments 2026-03-17 13:56:48 +01:00
fierke b6de508ea0 [chore:] removed ai-slop-test-crafting-function 2026-03-17 13:55:07 +01:00
fierke d70770e2f0 Merge remote-tracking branch 'origin/main' 2026-03-17 13:52:46 +01:00
fierke 2c2f2d2d94 [feat:] initial course calculation method (!) 2026-03-17 13:49:25 +01:00
fierke c5a234cea7 [chore:] main-window accessible from outside 2026-03-17 13:49:08 +01:00
fierke c6f9994c25 [gui:] new places for logs 2026-03-17 13:48:43 +01:00
fierke 6f1ffd40b6 Update README.md 2026-03-09 07:27:24 +00:00
fierke 8ab928be7c [chore:] removed alternative courses (since it's not needed) 2026-03-06 09:31:28 +01:00
fierke 30c8b2ef92 [gui:] added pdf export button (unfunctional) 2026-03-06 07:58:21 +01:00
fierke 24416dc345 [chore:] import initial courses after app started 2026-03-03 15:25:36 +01:00
fierke 8bfa22451e [chore:] improved, but not good craft()-method 2026-03-03 15:22:36 +01:00
fierke 8be9a9a925 [fix:] changed name when changing id 👀 2026-03-03 15:01:31 +01:00
fierke d1f5444caf [fix:] generated courses got not cleared before crafting-renewal 2026-03-03 15:00:58 +01:00
fierke aec57d7d9d [chore:] error-count overview after crafting courses 2026-03-03 14:58:23 +01:00
fierke 2f18629e83 [chore:] course instance collection 2026-03-03 08:59:01 +01:00
fierke 5f44e63129 [sec:] require additional "yes" if clearing course list 2026-03-03 08:19:19 +01:00
fierke 0df27f7e50 [fix:] MessageBox-WindowPosition (startup) 2026-03-03 08:18:19 +01:00
fierke df282d1164 [chore:] deleting from course list 2026-03-03 08:14:24 +01:00
fierke af2ad3dab7 [chore:] delete alternative names from sport courses 2026-03-02 10:55:38 +01:00
fierke 8672b09ff0 [fix:] UI-inconsistencies 2026-03-01 12:07:40 +01:00
fierke d23c8870ed [chore:] added course edit functionality 2026-03-01 12:05:51 +01:00
fierke 1bfd2f5219 Merge remote-tracking branch 'origin/main' 2026-02-28 18:26:12 +01:00
fierke 77ca5aa1ff [fix:] spplus crashed when not selecting any file 2026-02-28 18:26:02 +01:00
fierke 12606d45fb [chore:] result gui 2026-02-28 18:14:48 +01:00
fierke ce1eeab166 [chore:] implemented RefreshResultView() 2026-02-28 18:14:31 +01:00
fierke 4ac8182cf2 [chore:] removed unused variable/ fixed typo 2026-02-28 18:14:10 +01:00
fierke 3cdfb61586 [chore:] implemented initial crafting functio 2026-02-28 18:13:42 +01:00
fierke e3d504ceb7 [chore:] added initial BtnCraftCourses-Handler 2026-02-27 12:27:50 +01:00
fierke 99a6bdd473 [chore:] added gui-item names 2026-02-27 12:26:19 +01:00
fierke 8b92b32e60 [init:] added CourseCrafter-Class 2026-02-27 12:26:03 +01:00
fierke 5868ca882b [chore:] struct improvements and default-course-importer 2026-02-27 11:07:32 +01:00
fierke b3e8c7ee5e [chore:] implemented button handlers for course view and gui refresh functions 2026-02-27 11:07:13 +01:00
fierke 6b769f413c [chore:] added gui for course overview 2026-02-27 11:04:29 +01:00
fierke b772e29084 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	structs.cs
2026-02-21 15:45:22 +01:00
fierke 8b0703f25e added info about currently existing features 2026-02-19 11:16:04 +00:00
fierke 1b07d0e2ab [chore:] implemented student view 2026-02-18 15:13:11 +01:00
fierke 6a08694753 [chore:] implemented importer call with FilePicker 2026-02-18 14:44:39 +01:00
fierke fabefabe0f [chore:] small type fixes 2026-02-18 14:44:20 +01:00
fierke a572fdf72b [chore:] ListBox got named 2026-02-18 14:43:53 +01:00
fierke a855f0664a [init:] added initial Student-Importer 2026-02-18 14:43:39 +01:00
fierke f8f5140d47 [chore:] better info view (was maximized) 2026-02-18 14:12:57 +01:00
fierke e9c7b61ced [chore:] added student-id 2026-02-18 14:12:42 +01:00
fierke e27a6b88d4 Merge remote-tracking branch 'origin/main' 2026-02-17 09:30:55 +01:00
fierke 70c028aee7 [chore:] initial click-handlers 2026-02-17 09:30:40 +01:00
fierke bbfe6299b5 [chore:] added basic ui 2026-02-17 09:30:24 +01:00
fierke 8a8803395f [fix:] comment, BIG BIG change 2026-02-09 20:06:14 +01:00
20 changed files with 2761 additions and 126 deletions
+77
View File
@@ -0,0 +1,77 @@
using System;
using System.IO;
using PdfSharp.Drawing;
using PdfSharp.Fonts;
namespace spplus;
/// <summary>
/// Custom font resolver for PdfSharp that loads fonts from the res/fonts directory.
/// </summary>
public class CustomFontResolver : IFontResolver
{
private static string? _fontPath;
public CustomFontResolver()
{
// Try to locate the fonts directory
var basePath = AppDomain.CurrentDomain.BaseDirectory;
var possiblePaths = new[]
{
Path.Combine(basePath, "res", "fonts"),
Path.Combine(basePath, "fonts"),
Path.Combine(Directory.GetCurrentDirectory(), "res", "fonts"),
Path.Combine(Directory.GetCurrentDirectory(), "fonts"),
};
foreach (var path in possiblePaths)
{
if (Directory.Exists(path))
{
_fontPath = path;
break;
}
}
if (_fontPath == null)
{
throw new DirectoryNotFoundException(
$"Font directory not found. Searched: {string.Join(", ", possiblePaths)}");
}
}
public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
{
// Map family name to font file
var fileName = familyName switch
{
"Cantarell" => isBold
? isItalic ? "Cantarell-BoldItalic.ttf" : "Cantarell-Bold.ttf"
: isItalic ? "Cantarell-Italic.ttf" : "Cantarell-Regular.ttf",
_ => isBold
? isItalic ? "Cantarell-BoldItalic.ttf" : "Cantarell-Bold.ttf"
: isItalic ? "Cantarell-Italic.ttf" : "Cantarell-Regular.ttf"
};
var fontPath = Path.Combine(_fontPath, fileName);
if (!File.Exists(fontPath))
{
throw new FileNotFoundException($"Font file not found: {fontPath}");
}
// Return a FontResolverInfo with the font path
return new FontResolverInfo(fontPath);
}
public byte[]? GetFont(string faceName)
{
// faceName is the path returned by ResolveTypeface
if (File.Exists(faceName))
{
return File.ReadAllBytes(faceName);
}
return null;
}
}
+222 -9
View File
@@ -3,8 +3,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="spplus.MainWindow"
Title="SP+">
x:Class="spplus.MainWindow" WindowState="Maximized" Icon="res/logo.ico"
Title="spplus">
<Border>
<Grid RowDefinitions="30,*">
<Menu Background="#50888888">
@@ -12,6 +12,7 @@
<!-- <MenuItem Click="MnuSettings_OnClick" x:Name="MnuSettings" Header="Einstellungen" /> -->
<!-- <Separator /> -->
<MenuItem x:Name="MnuExpSettings" Header="Einstellungen exportieren" Click="MnuExpSettings_OnClick" />
<MenuItem x:Name="MnuImpResult" Header="Berechnung importieren" Click="MnuImpResult_OnClick" />
<MenuItem x:Name="MnuExit" Header="Beenden" Click="MnuExit_OnClick"/>
</MenuItem>
<MenuItem Header="Hilfe">
@@ -20,7 +21,7 @@
<MenuItem Header="Über" x:Name="MnuAbout" Click="MnuAbout_OnClick" />
</MenuItem>
</Menu>
<TabControl Grid.Row="1">
<TabControl x:Name="TclMainView" Grid.Row="1" TabStripPlacement="Left">
<TabItem>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
@@ -28,7 +29,72 @@
<Label FontSize="20" Content="Planung" VerticalContentAlignment="Center" />
</StackPanel>
</TabItem.Header>
<Grid RowDefinitions="2*,*,*">
<Grid ColumnDefinitions="*,2*" RowDefinitions="*,*">
<Button Grid.RowSpan="2" Margin="0,10,0,0" x:Name="BtnImport" VerticalAlignment="Top" Height="50" HorizontalAlignment="Stretch" Click="BtnImport_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Import" Width="36" Height="36" />
<Label Content="Importieren..." VerticalContentAlignment="Center" FontSize="15"
FontWeight="Bold" />
</StackPanel>
</Button>
<Button Grid.RowSpan="2" Margin="0,00,0,10" x:Name="BtnCraftCourses" VerticalAlignment="Bottom" Height="50" HorizontalAlignment="Stretch" Click="BtnCraftCourses_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Pickaxe" Width="36" Height="36" />
<Label Content="Kurse basteln" VerticalContentAlignment="Center" FontSize="15"
FontWeight="Bold" />
</StackPanel>
</Button>
<ListBox Grid.RowSpan="2" x:Name="LbStudentsImported" SelectionChanged="LbStudentsImported_OnSelectionChanged" Margin="0,70,0,70" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></ListBox>
<StackPanel Grid.Column="1" Grid.Row="0" Margin="10,10,10,10" Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,3*">
<Label Content="ID"></Label>
<TextBox Grid.Column="1" x:Name="TbStudentID" TextChanged="TbStudentID_OnTextChanged"></TextBox>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Name"></Label>
<TextBox Grid.Column="1" x:Name="TbStudentName" TextChanged="TbStudentName_OnTextChanged"></TextBox>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Sport 1"></Label>
<Label Grid.Column="1" x:Name="LblSport1"></Label>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Sport 2"></Label>
<Label Grid.Column="1" x:Name="LblSport2"></Label>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Sport 3"></Label>
<Label Grid.Column="1" x:Name="LblSport3"></Label>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Sport 4"></Label>
<Label Grid.Column="1" x:Name="LblSport4"></Label>
</Grid>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="1" Margin="10,10,10,10" Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,3*">
<Label Content="Anzahl Einträge"></Label>
<Label Grid.Column="1" x:Name="LblStudentAmount"></Label>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Anzahl gewählte Kurse"></Label>
<Label Grid.Column="1" x:Name="LblSelectedAmount"></Label>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Wahlzahlen"></Label>
<Label Grid.Column="1" x:Name="LblNumVoted"></Label>
</Grid>
</StackPanel>
</Grid>
@@ -40,22 +106,169 @@
<Label FontSize="20" Content="Kurse" VerticalContentAlignment="Center" />
</StackPanel>
</TabItem.Header>
<Grid RowDefinitions="2*,*,*">
<Grid ColumnDefinitions="*,2*">
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal" Spacing="10">
<Button Margin="0,10,0,0" x:Name="BtnImportDefaultCourses" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnImportDefaultCourses_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Import" Width="24" Height="24" />
<Label Content="Standardkurse importieren..." VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
<Button Margin="0,10,0,0" x:Name="BtnDeleteSinleCourse" Background="#99963434" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnDeleteSinleCourse_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Trash2" Width="24" Height="24" />
<Label Content="Ausgewähltes entfernen" VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
<Button Margin="0,10,0,0" x:Name="BtnClearCourseList" Background="#99963434" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnClearCourseList_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Trash" Width="24" Height="24" />
<Label Content="Liste leeren" VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
</StackPanel>
<ListBox Grid.Column="0" x:Name="LbSportCourses" SelectionChanged="LbSportCourses_OnSelectionChanged" Margin="0,55,0,0" />
<StackPanel Grid.Column="1" Grid.Row="0" Margin="10,10,10,10" Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,3*">
<Label Content="ID"></Label>
<Label Grid.Column="1" x:Name="LblSportID"></Label>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Name"></Label>
<TextBox Grid.Column="1" x:Name="TbSportName" TextChanged="TbSportName_OnTextChanged"></TextBox>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Maximale Schüler*innenanzahl"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxStudents" ValueChanged="NudSportMaxStudents_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Minimale Schüler*innenanzahl"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudSportMinStudents" ValueChanged="NudSportMinStudents_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Anzahl Angebote Semester 1"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem1" ValueChanged="NudAmountCoursesSem1_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Anzahl Angebote Semester 2"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem2" ValueChanged="NudAmountCoursesSem2_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Anzahl Angebote Semester 3"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem3" ValueChanged="NudAmountCoursesSem3_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Anzahl Angebote Semester 4"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem4" ValueChanged="NudAmountCoursesSem4_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Alternativbezeichnungen"></Label>
<StackPanel Grid.Column="1" Orientation="Vertical">
<Grid ColumnDefinitions="*,50,50">
<TextBox Grid.Column="0" Height="35" HorizontalAlignment="Stretch" x:Name="TbSportAlternativeName"></TextBox>
<Button Grid.Column="1" Margin="5,0,0,0" x:Name="BtnAlternativeNameAdd" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeNameAdd_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Plus" Width="24" Height="24" />
</StackPanel>
</Button>
<Button Grid.Column="2" Margin="5,0,0,0" x:Name="BtnAlternativeNameRemove" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeNameRemove_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Minus" Width="24" Height="24" />
</StackPanel>
</Button>
</Grid>
<ListBox Margin="0,5,0,0" x:Name="LbAlternativeNames">
</ListBox>
</StackPanel>
</Grid>
<Line />
<Grid ColumnDefinitions="*,3*">
<Label Content="Maximale Sportkursanzahl Semester 1"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxPerSemester1" ValueChanged="NudSportMaxPerSemester1_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Maximale Sportkursanzahl Semester 2"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxPerSemester2" ValueChanged="NudSportMaxPerSemester2_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Maximale Sportkursanzahl Semester 3"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxPerSemester3" ValueChanged="NudSportMaxPerSemester3_OnValueChanged"></NumericUpDown>
</Grid>
<Grid ColumnDefinitions="*,3*">
<Label Content="Maximale Sportkursanzahl Semester 4"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxPerSemester4" ValueChanged="NudSportMaxPerSemester4_OnValueChanged"></NumericUpDown>
</Grid>
</StackPanel>
</Grid>
</TabItem>
<TabItem>
<TabItem x:Name="TbiResults">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Sparkles" Width="32" Height="32" Size="32" />
<Label FontSize="20" Content="Ergebnisse" VerticalContentAlignment="Center" />
</StackPanel>
</TabItem.Header>
<Grid RowDefinitions="2*,*,*">
<Grid ColumnDefinitions="*,*" RowDefinitions="100,2*,*">
<ListBox Grid.RowSpan="2" x:Name="LbResult" Margin="0,10,10,10" PointerPressed="LbResult_OnPointerPressed">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Ändern" x:Name="MnuChange" />
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
<Grid Grid.Row="0" Grid.Column="1" RowDefinitions="*,*" ColumnDefinitions="*,*">
<Button Grid.Row="0" Grid.Column="0" Margin="0,10,5,0" x:Name="BtnExportCoursePDF" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCoursePDF_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="FileText" Width="24" Height="24" />
<Label Content="Export (PDF)..." VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
<Button Grid.Row="0" Grid.Column="1" Margin="5,10,0,0" x:Name="BtnExportCourseCSV" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCourseCSV_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="FileJson" Width="24" Height="24" />
<Label Content="Export (CSV)..." VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
<Button Grid.Row="1" Grid.Column="0" Margin="0,5,5,0" x:Name="BtnExportConfiguration" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="MnuExpSettings_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="FileJson" Width="24" Height="24" />
<Label Content="Konfiguration exportieren..." VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
<Button Grid.Row="1" Grid.Column="1" Margin="5,5,0,0" x:Name="BtnImportResults" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="MnuImpResult_OnClick" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Import" Width="24" Height="24" />
<Label Content="Ergebnisse importieren..." VerticalContentAlignment="Center" FontSize="12"
FontWeight="Bold" />
</StackPanel>
</Button>
</Grid>
<ScrollViewer Grid.Row="1" Grid.Column="1" Margin="0,5,0,10" Background="#44CCCCCC">
<TextBlock x:Name="TbResultStatistics"></TextBlock>
</ScrollViewer>
<ScrollViewer Grid.Row="2" Grid.Column="1" Margin="0,0,0,10" Background="#44CCCCCC">
<TextBlock x:Name="TbResultTextout" FontFamily="Consolas"></TextBlock>
</ScrollViewer>
<ScrollViewer Grid.Row="2" Grid.Column="0" Margin="0,0,10,10" Background="#44CCCCCC">
<TextBlock x:Name="TbResultLog" FontFamily="Consolas"></TextBlock>
</ScrollViewer>
</Grid>
</TabItem>
</TabControl>
+606 -6
View File
@@ -1,20 +1,151 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
namespace spplus;
public partial class MainWindow : Window
{
public static MainWindow Instance { get; set; }
public static string ApplicationVersion = "v1.2.24";
private sealed class ResultEntry
{
public Student Student { get; }
public int Semester { get; }
public string CourseName { get; }
public ResultEntry(Student student, int semester, string? courseName)
{
Student = student;
Semester = semester;
CourseName = courseName ?? string.Empty;
}
public override string ToString()
{
return $"{Student.Name} ({Student.ID}) - {Semester}. Semester: {CourseName}";
}
}
public MainWindow()
{
InitializeComponent();
Settings.ImportInitial();
Instance = this;
RefreshCoursesList();
try
{
NudSportMaxPerSemester1.Value = Settings.Instance.NumCoursesPerSemester[0];
NudSportMaxPerSemester2.Value = Settings.Instance.NumCoursesPerSemester[1];
NudSportMaxPerSemester3.Value = Settings.Instance.NumCoursesPerSemester[2];
NudSportMaxPerSemester4.Value = Settings.Instance.NumCoursesPerSemester[3];
} catch {}
}
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
private void RegenerateContextMenu()
{
var res = MessageBox.Show(this, "Dieses Feature ist noch nicht implementiert", "Fehlend");
MnuChange.Items.Clear();
foreach (var sport in Settings.Instance.Sports)
{
var item = new MenuItem { Header = sport.Name };
item.Click += (_, _) => ChangeStudentCourse(sport);
MnuChange.Items.Add(item);
}
}
private void ChangeStudentCourse(Sport targetSport)
{
if (LbResult.SelectedItem is not ResultEntry selectedEntry)
return;
try
{
if (ApplyStudentCourseChange(selectedEntry.Student, selectedEntry.Semester, targetSport))
{
CourseCrafter.ReloadResult();
RefreshResultView();
RegenerateContextMenu();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
}
}
private bool ApplyStudentCourseChange(Student student, int semester, Sport targetSport)
{
if (semester < 1 || semester > 4)
return false;
var semesterCourses = CourseCrafter.GeneratedCourses
.Where(course => course.Semester == semester)
.ToList();
var currentCourses = semesterCourses
.Where(course => course.Instance.Students.Contains(student.ID))
.ToList();
CourseCrafter.CourseInstance? targetCourse = currentCourses
.FirstOrDefault(course => course.Instance.Sport.Name == targetSport.Name)
.Instance;
if (targetCourse == null)
{
targetCourse = semesterCourses
.Where(course => course.Instance.Sport.Name == targetSport.Name)
.OrderBy(course => course.Instance.Students.Count)
.Select(course => course.Instance)
.FirstOrDefault();
}
bool changed = false;
foreach (var course in currentCourses)
{
if (targetCourse != null && ReferenceEquals(course.Instance, targetCourse))
continue;
if (course.Instance.Students.Remove(student.ID))
changed = true;
}
int removedEmptyCourses = CourseCrafter.GeneratedCourses.RemoveAll(course =>
course.Semester == semester &&
course.Instance.Students.Count == 0 &&
!ReferenceEquals(course.Instance, targetCourse));
if (removedEmptyCourses > 0)
changed = true;
if (targetCourse == null)
{
var newCourse = new CourseCrafter.CourseInstance
{
Sport = targetSport,
Students = new List<string> { student.ID }
};
CourseCrafter.GeneratedCourses.Add((semester, newCourse));
changed = true;
}
else if (!targetCourse.Students.Contains(student.ID))
{
targetCourse.Students.Add(student.ID);
changed = true;
}
return changed;
}
private async void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
{
await ExportConfigurationAsync();
}
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
@@ -29,7 +160,7 @@ public partial class MainWindow : Window
Process.Start(new ProcessStartInfo
{
FileName = "https://git.mypapercloud.de/fierke/spplus/wiki",
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
UseShellExecute = true
});
}
catch (Exception ex)
@@ -45,7 +176,7 @@ public partial class MainWindow : Window
Process.Start(new ProcessStartInfo
{
FileName = "https://git.mypapercloud.de/fierke/spplus",
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
UseShellExecute = true
});
}
catch (Exception ex)
@@ -57,11 +188,480 @@ public partial class MainWindow : Window
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();
tb.Text = "Spplus v1.0.0\n(c)2026 MyPapertown, Elias Fierke";
TextBlock tb = new()
{
Text = $"spplus {MainWindow.ApplicationVersion}\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();
List<(Sport, List<string>)> initial_sportlist = new();
foreach (var sp in Settings.Instance.Sports)
{
initial_sportlist.Add((sp, new()));
}
foreach (Student s in Settings.Instance.Students)
{
foreach (var sp in s.SelectedCourseNames)
{
foreach (var item in initial_sportlist)
{
if (item.Item1.AlternativeNames.Contains(sp))
{
item.Item2.Add(s.ID);
break;
}
}
}
}
LblNumVoted.Content = "";
foreach (var s in initial_sportlist)
{
LblNumVoted.Content += $"{s.Item1.Name}: {s.Item2.Count}\n";
}
}
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
{
CourseCrafter.Craft();
RefreshResultView();
TclMainView.SelectedIndex = 2;
//TbiResults.Focus();
}
private void LbResult_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (!e.GetCurrentPoint(LbResult).Properties.IsRightButtonPressed)
return;
if (e.Source is Control control && control.DataContext is ResultEntry entry)
{
LbResult.SelectedItem = entry;
}
else
{
LbResult.SelectedItem = null;
}
}
private void RefreshResultView()
{
LbResult.Items.Clear();
foreach (Student s in Settings.Instance.Students)
{
try
{
for(int i = 0; i<s.Result.Length;i++)
{
LbResult.Items.Add(new ResultEntry(s, i + 1, 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).ID = 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);
}
RegenerateContextMenu();
}
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;
RegenerateContextMenu();
} 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 async void BtnClearCourseList_OnClick(object? sender, RoutedEventArgs e)
{
var result = await MessageBox.Show(this,
"Möchten Sie wirklich alle Kurse löschen?\n Dies kann nicht rückgängig gemacht werden.",
"Wirklich fortfahren?", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
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){}
}
private async void BtnExportCoursePDF_OnClick(object? sender, RoutedEventArgs e)
{
var topLevel = GetTopLevel(this);
var file = await topLevel!.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "PDF-Datei speichern",
SuggestedFileName = "spplus_kurse.pdf",
SuggestedFileType = new FilePickerFileType(".pdf-Datei")
{
Patterns = new[] { "*.pdf" }
}
});
if (file == null) return;
PdfExportUtility.ExportGeneratedCourses(file.Path.LocalPath);
}
private void NudSportMaxPerSemester1_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
try
{
Settings.Instance.NumCoursesPerSemester[0] = Convert.ToInt32(NudSportMaxPerSemester1.Value);
} catch {}
}
private void NudSportMaxPerSemester2_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
try
{
Settings.Instance.NumCoursesPerSemester[1] = Convert.ToInt32(NudSportMaxPerSemester2.Value);
} catch {}
}
private void NudSportMaxPerSemester3_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
try
{
Settings.Instance.NumCoursesPerSemester[2] = Convert.ToInt32(NudSportMaxPerSemester3.Value);
} catch {}
}
private void NudSportMaxPerSemester4_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
try
{
Settings.Instance.NumCoursesPerSemester[3] = Convert.ToInt32(NudSportMaxPerSemester4.Value);
} catch {}
}
private async void BtnExportCourseCSV_OnClick(object? sender, RoutedEventArgs e)
{
var topLevel = GetTopLevel(this);
var file = await topLevel!.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "CSV-Datei speichern",
SuggestedFileName = "spplus_ergebnisse.json",
SuggestedFileType = new FilePickerFileType(".json-Datei")
{
Patterns = new[] { "*.json" }
}
});
if (file == null) return;
ExportUtility.ExportResultsToJson(file.Path.LocalPath);
}
private async void MnuImpResult_OnClick(object? sender, RoutedEventArgs e)
{
var topLevel = GetTopLevel(this);
var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Ergebnis-CSV laden",
AllowMultiple = false,
FileTypeFilter = new[]
{
new FilePickerFileType(".json-Datei")
{
Patterns = new[] { "*.json" }
}
}
});
if (file == null || file.Count == 0) return;
var imported = import.ImportResultFromJson(file[0].Path.LocalPath.ToString());
if (imported != null && imported.Count > 0)
{
CourseCrafter.GeneratedCourses = imported
.OrderBy(c => c.Semester)
.ThenBy(c => c.Instance.Sport.Name)
.ToList();
CourseCrafter.ReloadResult();
RefreshResultView();
}
}
private async System.Threading.Tasks.Task ExportConfigurationAsync()
{
var topLevel = GetTopLevel(this);
var file = await topLevel!.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Konfiguration speichern",
SuggestedFileName = "spplus_konfiguration.json",
SuggestedFileType = new FilePickerFileType(".json-Datei")
{
Patterns = new[] { "*.json" }
}
});
if (file == null) return;
ExportUtility.ExportConfigurationToJson(file.Path.LocalPath);
}
}
+2 -2
View File
@@ -2,8 +2,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" SizeToContent="WidthAndHeight"
x:Class="spplus.MessageBox"
mc:Ignorable="d" SizeToContent="WidthAndHeight" Icon="res/logo.ico"
x:Class="spplus.MessageBox" WindowStartupLocation="CenterScreen"
Title="MessageBox">
<StackPanel>
<TextBlock Name="Text" Margin="10" TextWrapping="Wrap" />
+521
View File
@@ -0,0 +1,521 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
namespace spplus;
public static class PdfExportUtility
{
private const string FontFamily = "Cantarell";
private const double Margin = 36.0;
private const double FooterHeight = 28.0;
private static readonly XBrush FooterBrush = XBrushes.Gray;
public static void ExportGeneratedCourses(string filepath)
{
var document = new PdfDocument
{
Info =
{
Title = "spplus - generierte Kurse",
Author = "spplus",
Creator = "spplus"
}
};
var courses = CourseCrafter.GeneratedCourses
.OrderBy(course => course.Semester)
.ThenBy(course => course.Instance.Sport.Name)
.ToList();
if (courses.Count == 0)
{
RenderEmptyDocument(document);
document.Save(filepath);
return;
}
var studentsById = Settings.Instance.Students
.GroupBy(student => student.ID, StringComparer.OrdinalIgnoreCase)
.ToDictionary(group => group.Key, group => group.First(), StringComparer.OrdinalIgnoreCase);
foreach (var course in courses)
{
RenderCourse(document, course, studentsById);
}
RenderMissingStudentsReport(document, studentsById, courses);
document.Save(filepath);
}
private static void RenderMissingStudentsReport(
PdfDocument document,
IReadOnlyDictionary<string, Student> studentsById,
IReadOnlyList<(int Semester, CourseCrafter.CourseInstance Instance)> courses)
{
var assignedSemesters = studentsById.Values
.ToDictionary(student => student.ID, _ => new bool[4], StringComparer.OrdinalIgnoreCase);
foreach (var course in courses)
{
if (course.Semester < 1 || course.Semester > 4)
continue;
foreach (var studentId in course.Instance.Students)
{
if (assignedSemesters.TryGetValue(studentId, out var assignment))
assignment[course.Semester - 1] = true;
}
}
var missingStudents = studentsById.Values
.Where(student => assignedSemesters.TryGetValue(student.ID, out var assignment) && assignment.Any(a => !a))
.OrderBy(student => student.Name)
.ThenBy(student => student.ID)
.ToList();
var columns = new double[] { 30.0, 90.0, 190.0, 40.0, 40.0, 40.0, 40.0 };
var headerRow = new[] { "Nr.", "ID", "Name", "Sem1", "Sem2", "Sem3", "Sem4" };
int rowIndex = 0;
int pageIndex = 0;
while (rowIndex < missingStudents.Count || pageIndex == 0)
{
var page = document.AddPage();
ConfigurePage(page);
using var gfx = XGraphics.FromPdfPage(page);
var titleFont = new XFont(FontFamily, 18, XFontStyleEx.Bold);
var subtitleFont = new XFont(FontFamily, 10, XFontStyleEx.Regular);
var tableHeaderFont = new XFont(FontFamily, 9, XFontStyleEx.Bold);
var tableBodyFont = new XFont(FontFamily, 8.5, XFontStyleEx.Regular);
double pageWidth = page.Width.Point;
double pageHeight = page.Height.Point;
double contentWidth = pageWidth - (Margin * 2);
double contentBottom = pageHeight - Margin - FooterHeight;
double y = Margin;
var headerTitle = pageIndex == 0
? "Nicht zugeordnete Schülerinnen und Schüler"
: "Fortsetzung: Nicht zugeordnete Schülerinnen und Schüler";
gfx.DrawString(headerTitle, titleFont, XBrushes.Black,
new XRect(Margin, y, contentWidth, 24), XStringFormats.TopLeft);
y += 26;
if (pageIndex == 0)
{
gfx.DrawString("Inkludiert nur SuS, die in mindestens einem Semester keine Zuordnung erhalten haben.",
subtitleFont, XBrushes.Gray, new XRect(Margin, y, contentWidth, 20), XStringFormats.TopLeft);
y += 24;
}
if (missingStudents.Count == 0)
{
var bodyFont = new XFont(FontFamily, 11, XFontStyleEx.Regular);
gfx.DrawString("Alle Schülerinnen und Schüler sind in allen vier Semestern zugeordnet.", bodyFont, XBrushes.Black,
new XRect(Margin, y, contentWidth, 20), XStringFormats.TopLeft);
DrawFooter(gfx, page);
break;
}
y += DrawTableRow(gfx, y, columns, headerRow, tableHeaderFont, fillHeader: true);
while (rowIndex < missingStudents.Count)
{
var student = missingStudents[rowIndex];
var assignment = assignedSemesters[student.ID];
var row = BuildMissingStudentRow(rowIndex + 1, student, assignment);
double rowHeight = MeasureRowHeight(gfx, columns, row, tableBodyFont);
if (y + rowHeight > contentBottom)
break;
y += DrawTableRow(gfx, y, columns, row, tableBodyFont, fillHeader: false);
rowIndex++;
}
DrawFooter(gfx, page);
pageIndex++;
if (rowIndex >= missingStudents.Count)
break;
}
}
private static string[] BuildMissingStudentRow(int rowNumber, Student student, bool[] assignment)
{
return new[]
{
rowNumber.ToString(),
student.ID,
student.Name,
assignment[0] ? string.Empty : "X",
assignment[1] ? string.Empty : "X",
assignment[2] ? string.Empty : "X",
assignment[3] ? string.Empty : "X",
};
}
private static void RenderEmptyDocument(PdfDocument document)
{
var page = document.AddPage();
ConfigurePage(page);
using var gfx = XGraphics.FromPdfPage(page);
var titleFont = new XFont(FontFamily, 18, XFontStyleEx.Bold);
var bodyFont = new XFont(FontFamily, 11, XFontStyleEx.Regular);
gfx.DrawString("spplus", titleFont, XBrushes.Black,
new XRect(Margin, Margin, page.Width.Point - Margin * 2, 24), XStringFormats.TopLeft);
gfx.DrawString("Es wurden keine generierten Kurse gefunden.", bodyFont, XBrushes.Black,
new XRect(Margin, Margin + 34, page.Width.Point - Margin * 2, 24), XStringFormats.TopLeft);
DrawFooter(gfx, page);
}
private static void RenderCourse(
PdfDocument document,
(int Semester, CourseCrafter.CourseInstance Instance) course,
IReadOnlyDictionary<string, Student> studentsById)
{
var studentIds = course.Instance.Students.ToList();
int index = 0;
int pageIndex = 0;
do
{
var page = document.AddPage();
ConfigurePage(page);
using var gfx = XGraphics.FromPdfPage(page);
var titleFont = new XFont(FontFamily, 18, XFontStyleEx.Bold);
var subtitleFont = new XFont(FontFamily, 10, XFontStyleEx.Regular);
var labelFont = new XFont(FontFamily, 9, XFontStyleEx.Bold);
var valueFont = new XFont(FontFamily, 9, XFontStyleEx.Regular);
var tableHeaderFont = new XFont(FontFamily, 9, XFontStyleEx.Bold);
var tableBodyFont = new XFont(FontFamily, 8.5, XFontStyleEx.Regular);
double pageWidth = page.Width.Point;
double pageHeight = page.Height.Point;
double contentWidth = pageWidth - (Margin * 2);
double contentBottom = pageHeight - Margin - FooterHeight;
double y = Margin;
var headerTitle = $"Sem. {course.Semester} - {course.Instance.Sport.Name}";
if (pageIndex > 0)
headerTitle += " (Fortsetzung)";
gfx.DrawString(headerTitle, titleFont, XBrushes.Black,
new XRect(Margin, y, contentWidth, 24), XStringFormats.TopLeft);
y += 26;
gfx.DrawString($"{course.Instance.Students.Count} Schülerinnen und Schüler", subtitleFont,
XBrushes.Gray, new XRect(Margin, y, contentWidth, 18), XStringFormats.TopLeft);
y += 24;
y = DrawInfoRows(gfx, y, contentWidth, labelFont, valueFont, course);
y += 10;
var columns = GetTableColumns(contentWidth);
var headerRow = new[]
{
"Nr.",
"ID",
"Name",
};
y += DrawTableRow(gfx, y, columns, headerRow, tableHeaderFont, fillHeader: true);
if (studentIds.Count == 0)
{
var emptyFont = new XFont(FontFamily, 9, XFontStyleEx.Italic);
gfx.DrawString("Keine Schülerinnen und Schüler zugeordnet.", emptyFont, XBrushes.Gray,
new XRect(Margin + 6, y + 8, contentWidth - 12, 20), XStringFormats.TopLeft);
}
else
{
while (index < studentIds.Count)
{
if (!studentsById.TryGetValue(studentIds[index], out var student))
student = new Student { ID = studentIds[index] };
var row = BuildStudentRow(index + 1, student);
double rowHeight = MeasureRowHeight(gfx, columns, row, tableBodyFont);
if (y + rowHeight > contentBottom)
break;
y += DrawTableRow(gfx, y, columns, row, tableBodyFont, fillHeader: false);
index++;
}
}
DrawFooter(gfx, page);
pageIndex++;
} while (index < studentIds.Count);
}
private static double DrawInfoRows(
XGraphics gfx,
double startY,
double contentWidth,
XFont labelFont,
XFont valueFont,
(int Semester, CourseCrafter.CourseInstance Instance) course)
{
double y = startY;
double labelWidth = 160.0;
double valueWidth = contentWidth - labelWidth;
double rowPadding = 4.0;
var rows = new List<(string Label, string Value)>
{
("Kurs-ID", course.Instance.Sport.ID.ToString()),
("Kursname", course.Instance.Sport.Name),
("Semester", course.Semester.ToString()),
("Anzahl SuS", course.Instance.Students.Count.ToString()),
("Min / Max", $"{course.Instance.Sport.MinStudents} / {course.Instance.Sport.MaxStudents}"),
("Semesterangebote", string.Join(", ", course.Instance.Sport.Semester.Select((count, idx) => $"S{idx + 1}:{count}"))),
("Alternativnamen", course.Instance.Sport.AlternativeNames.Count == 0
? "-"
: string.Join(", ", course.Instance.Sport.AlternativeNames))
};
foreach (var row in rows)
{
double rowHeight = MeasureInfoRowHeight(gfx, labelFont, valueFont, labelWidth, valueWidth, row.Label, row.Value);
gfx.DrawRectangle(XPens.LightGray, Margin, y, labelWidth, rowHeight);
gfx.DrawRectangle(XPens.LightGray, Margin + labelWidth, y, valueWidth, rowHeight);
DrawWrappedText(gfx, row.Label, labelFont, XBrushes.Black, Margin + 4, y + rowPadding, labelWidth - 8);
DrawWrappedText(gfx, row.Value, valueFont, XBrushes.Black, Margin + labelWidth + 4, y + rowPadding, valueWidth - 8);
y += rowHeight;
}
return y;
}
private static double MeasureInfoRowHeight(
XGraphics gfx,
XFont labelFont,
XFont valueFont,
double labelWidth,
double valueWidth,
string label,
string value)
{
double labelHeight = MeasureWrappedTextHeight(gfx, label, labelFont, labelWidth - 8);
double valueHeight = MeasureWrappedTextHeight(gfx, value, valueFont, valueWidth - 8);
return Math.Max(labelHeight, valueHeight) + 8.0;
}
private static string[] BuildStudentRow(int rowNumber, Student student)
{
return new[]
{
rowNumber.ToString(),
student.ID,
student.Name,
};
}
private static string GetCourseName(Student student, int index)
{
if (index < 0 || index >= student.SelectedCourseNames.Count)
return string.Empty;
return student.SelectedCourseNames[index];
}
private static double[] GetTableColumns(double contentWidth)
{
return new[]
{
30.0,
75.0,
145.0
};
}
private static double DrawTableRow(
XGraphics gfx,
double startY,
double[] columns,
IReadOnlyList<string> values,
XFont font,
bool fillHeader)
{
const double padding = 4.0;
double rowHeight = MeasureRowHeight(gfx, columns, values, font);
double x = Margin;
for (int i = 0; i < columns.Length; i++)
{
double width = columns[i];
var rect = new XRect(x, startY, width, rowHeight);
gfx.DrawRectangle(XPens.LightGray, rect);
if (fillHeader)
gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(235, 235, 235)), rect);
gfx.DrawRectangle(XPens.LightGray, rect);
var lines = WrapText(gfx, values[i], font, width - (padding * 2));
double lineHeight = font.GetHeight();
double textY = startY + padding;
foreach (var line in lines)
{
gfx.DrawString(line, font, XBrushes.Black,
new XRect(x + padding, textY, width - (padding * 2), lineHeight), XStringFormats.TopLeft);
textY += lineHeight;
}
x += width;
}
return rowHeight;
}
private static double MeasureRowHeight(
XGraphics gfx,
double[] columns,
IReadOnlyList<string> values,
XFont font)
{
const double padding = 4.0;
double maxHeight = font.GetHeight() + (padding * 2);
for (int i = 0; i < columns.Length; i++)
{
double height = MeasureWrappedTextHeight(gfx, values[i], font, columns[i] - (padding * 2)) + (padding * 2);
if (height > maxHeight)
maxHeight = height;
}
return maxHeight;
}
private static double MeasureWrappedTextHeight(XGraphics gfx, string text, XFont font, double width)
{
var lines = WrapText(gfx, text, font, width);
return lines.Count * font.GetHeight();
}
private static List<string> WrapText(XGraphics gfx, string? text, XFont font, double maxWidth)
{
var result = new List<string>();
if (string.IsNullOrWhiteSpace(text))
{
result.Add(string.Empty);
return result;
}
foreach (var paragraph in text.Replace("\r", string.Empty).Split('\n'))
{
if (string.IsNullOrWhiteSpace(paragraph))
{
result.Add(string.Empty);
continue;
}
string current = string.Empty;
foreach (var token in paragraph.Split(' ', StringSplitOptions.RemoveEmptyEntries))
{
foreach (var wordPart in SplitWordIfNeeded(gfx, token, font, maxWidth))
{
var candidate = string.IsNullOrEmpty(current) ? wordPart : $"{current} {wordPart}";
if (gfx.MeasureString(candidate, font).Width <= maxWidth)
{
current = candidate;
}
else
{
if (!string.IsNullOrEmpty(current))
result.Add(current);
current = wordPart;
}
}
}
if (!string.IsNullOrEmpty(current))
result.Add(current);
}
return result.Count == 0 ? new List<string> { string.Empty } : result;
}
private static IEnumerable<string> SplitWordIfNeeded(XGraphics gfx, string word, XFont font, double maxWidth)
{
if (gfx.MeasureString(word, font).Width <= maxWidth)
{
yield return word;
yield break;
}
string chunk = string.Empty;
foreach (char c in word)
{
string candidate = chunk + c;
if (chunk.Length > 0 && gfx.MeasureString(candidate, font).Width > maxWidth)
{
yield return chunk;
chunk = c.ToString();
}
else
{
chunk = candidate;
}
}
if (!string.IsNullOrEmpty(chunk))
yield return chunk;
}
private static void DrawWrappedText(
XGraphics gfx,
string? text,
XFont font,
XBrush brush,
double x,
double y,
double width)
{
double lineHeight = font.GetHeight();
foreach (var line in WrapText(gfx, text, font, width))
{
gfx.DrawString(line, font, brush, new XRect(x, y, width, lineHeight), XStringFormats.TopLeft);
y += lineHeight;
}
}
private static void DrawFooter(XGraphics gfx, PdfPage page)
{
var footerFont = new XFont(FontFamily, 7, XFontStyleEx.Regular);
double width = page.Width.Point - (Margin * 2);
double x = Margin;
double baseY = page.Height.Point - Margin + 2;
gfx.DrawString("generated by spplus", footerFont, FooterBrush,
new XRect(x, baseY, width, 9), XStringFormats.Center);
gfx.DrawString("(c) 2026 MyPapertown", footerFont, FooterBrush,
new XRect(x, baseY + 8, width, 9), XStringFormats.Center);
gfx.DrawString("www.mypapercloud.de/spplus", footerFont, FooterBrush,
new XRect(x, baseY + 16, width, 9), XStringFormats.Center);
}
private static void ConfigurePage(PdfPage page)
{
page.Size = PageSize.A4;
page.Orientation = PageOrientation.Portrait;
}
}
+10 -2
View File
@@ -1,5 +1,7 @@
using Avalonia;
using System;
using PdfSharp;
using PdfSharp.Fonts;
namespace spplus;
@@ -9,8 +11,14 @@ class Program
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
public static void Main(string[] args)
{
// Initialize PdfSharp font resolver before any PDF operations
GlobalFontSettings.FontResolver = new CustomFontResolver();
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
+15 -7
View File
@@ -1,13 +1,19 @@
# SP+
Interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch SuS.
Plattformunabhängiger (Windows, Linux, Mac), interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch SuS.
## (future) Features
* Import von CSV-Dateien mit Kurswahl
* Wahlansicht
* Statistiken
* Pflege von Sportkursen (inkl. Kürzel/ alternativen Bezeichnungen)
* Fehleransicht für nicht-existente, aber gewählte Kurse
![spplus-Hauptbildschirm](img/spplus_planung.png)
## Features
* \+ Import von CSV-Dateien mit Kurswahl
* \+ Wahlansicht
* \+ Statistiken
* \+ Pflege von Sportkursen (inkl. Kürzel/ alternativen Bezeichnungen)
* \+ CSV-Export
* ~ Fehleransicht für nicht-existente, aber gewählte Kurse
* ~ PDF-Export
\+ Vorhanden, ~ Pending
## Nutzung
* Build from source:
@@ -17,3 +23,5 @@ Interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch
* Suche `spplus` bzw. `spplus.exe` und führe aus
* Linux/MacOS evl.: `chmod +x spplus`
![spplus-Sportkursübersicht](img/spplus_sport.png)
+914
View File
@@ -0,0 +1,914 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace spplus;
public class CourseCrafter
{
public class CourseInstance
{
public Sport Sport = null!;
public int Remaining;
public List<string> Students = new();
}
public static List<(int Semester, CourseInstance Instance)> GeneratedCourses
= new();
private static Sport? ResolveSportFromCourseName(string courseName)
{
if (string.IsNullOrWhiteSpace(courseName) ||
string.Equals(courseName, "null", StringComparison.OrdinalIgnoreCase))
{
return null;
}
return Settings.Instance.Sports.FirstOrDefault(sport =>
string.Equals(sport.Name, courseName, StringComparison.OrdinalIgnoreCase) ||
sport.AlternativeNames.Any(alt => string.Equals(alt, courseName, StringComparison.OrdinalIgnoreCase)));
}
public static void RebuildGeneratedCoursesFromResults(IEnumerable<Student> importedResults)
{
var importedById = importedResults
.Where(student => !string.IsNullOrWhiteSpace(student.ID))
.GroupBy(student => student.ID, StringComparer.OrdinalIgnoreCase)
.ToDictionary(group => group.Key, group => group.First(), StringComparer.OrdinalIgnoreCase);
var generatedCourses = new Dictionary<(int Semester, string SportName), CourseInstance>();
foreach (var student in Settings.Instance.Students)
{
if (!importedById.TryGetValue(student.ID, out var importedStudent))
continue;
for (int semesterIndex = 0; semesterIndex < 4; semesterIndex++)
{
if (importedStudent.Result.Length <= semesterIndex)
continue;
var resultName = importedStudent.Result[semesterIndex];
var sport = ResolveSportFromCourseName(resultName);
if (sport == null)
continue;
var key = (semesterIndex + 1, sport.Name);
if (!generatedCourses.TryGetValue(key, out var course))
{
course = new CourseInstance
{
Sport = sport,
Students = new List<string>()
};
generatedCourses[key] = course;
}
if (!course.Students.Contains(student.ID))
course.Students.Add(student.ID);
}
}
GeneratedCourses = generatedCourses
.Select(entry => (Semester: entry.Key.Semester, Instance: entry.Value))
.OrderBy(course => course.Semester)
.ThenBy(course => course.Instance.Sport.Name)
.ToList();
}
public static void Craft()
{
GeneratedCourses = new();
int globalCount = 0;
List<(Sport, List<string>)> initial_sportlist = new();
List<string>[] students_in_semester = new List<string>[4] { new(), new(), new(), new() };
foreach (var sp in Settings.Instance.Sports)
{
initial_sportlist.Add((sp, new()));
}
foreach (Student s in Settings.Instance.Students)
{
foreach (var sp in s.SelectedCourseNames)
{
foreach (var item in initial_sportlist)
{
if (item.Item1.AlternativeNames.Contains(sp))
{
item.Item2.Add(s.ID);
break;
}
}
}
}
while (!requestExit())
{
Console.WriteLine($"Calculating... ({globalCount})");
foreach (var item in initial_sportlist)
{
if (item.Item2.Count >= item.Item1.MinStudents)
{
int semester = getSemesterForSport(item.Item1, item.Item2);
if (semester <= 0) goto semeq0;
var inst = new CourseInstance();
inst.Sport = item.Item1;
inst.Students = new List<string>();
for (int i = item.Item2.Count - 1; i >= 0; i--)
{
if (inst.Students.Count >= inst.Sport.MaxStudents)
break;
string stud = item.Item2[i];
if (!students_in_semester[semester - 1].Contains(stud))
{
inst.Students.Add(stud);
students_in_semester[semester - 1].Add(stud);
item.Item2.RemoveAt(i);
}
}
if (inst.Students.Count < getEffectiveMinStudents(inst.Sport, semester))
{
// Rückgängig machen
foreach (var s in inst.Students)
{
students_in_semester[semester - 1].Remove(s);
item.Item2.Add(s);
}
continue; // Kurs nicht erstellen
}
GeneratedCourses.Add((semester, inst));
}
semeq0: ;
}
}
FillExistingCourses();
// Kurs umdisponieren (besser verteilen)
bool changed;
int maxIterations = 20;
int iteration = 0;
do
{
changed = false;
iteration++;
var sports = GeneratedCourses
.GroupBy(c => c.Instance.Sport.Name);
foreach (var sportGroup in sports)
{
var courses = sportGroup.ToList();
for (int i = 0; i < courses.Count; i++)
{
for (int j = 0; j < courses.Count; j++)
{
if (i == j) continue;
var cA = courses[i];
var cB = courses[j];
if (cA.Instance.Students.Count <= cB.Instance.Students.Count + 1)
continue;
for (int k = cA.Instance.Students.Count - 1; k >= 0; k--)
{
string stud = cA.Instance.Students[k];
if (!isStudentFree(cB.Semester, stud))
continue;
if (cB.Instance.Students.Count >= cB.Instance.Sport.MaxStudents)
continue;
// Quellkurs darf nicht unter effektives Min fallen
if (cA.Instance.Students.Count - 1 < getEffectiveMinStudents(cA.Instance.Sport, cA.Semester))
continue;
cA.Instance.Students.RemoveAt(k);
students_in_semester[cA.Semester - 1].Remove(stud);
cB.Instance.Students.Add(stud);
students_in_semester[cB.Semester - 1].Add(stud);
changed = true;
break;
}
}
}
}
} while (changed && iteration < maxIterations);
// --- Kurse nachträglich aufteilen, um NumCoursesPerSemester exakt zu erreichen ---
for (int semester = 1; semester <= 4; semester++)
{
int cancel = 0;
while (GeneratedCourses.Count(c => c.Semester == semester) < Settings.Instance.NumCoursesPerSemester[semester-1])
{
cancel++;
if (cancel >= 20) break;
var candidate = GeneratedCourses
.Where(c => c.Semester == semester)
.Where(c => c.Instance.Students.Count >= getEffectiveMinStudents(c.Instance.Sport, c.Semester) * 2)
.Where(c =>
{
int sportCount = GeneratedCourses.Count(g =>
g.Semester == semester &&
g.Instance.Sport.Name == c.Instance.Sport.Name);
int allowed = c.Instance.Sport.Semester[semester - 1];
return sportCount < allowed;
})
.OrderByDescending(c => c.Instance.Students.Count)
.FirstOrDefault();
if (candidate.Instance == null)
break;
var students = candidate.Instance.Students;
int totalStudents = students.Count;
int movedCount = totalStudents / 2;
int remainingCount = totalStudents - movedCount;
if (movedCount < getEffectiveMinStudents(candidate.Instance.Sport, candidate.Semester) ||
remainingCount < getEffectiveMinStudents(candidate.Instance.Sport, candidate.Semester))
{
break;
}
var newCourse = new CourseInstance
{
Sport = candidate.Instance.Sport,
Students = new List<string>()
};
var moved = students
.Skip(remainingCount)
.Take(movedCount)
.ToList();
foreach (var s in moved)
{
candidate.Instance.Students.Remove(s);
newCourse.Students.Add(s);
}
GeneratedCourses.Add((semester, newCourse));
}
}
bool rescueChanged;
do
{
rescueChanged = FillExistingCourses();
foreach (var item in initial_sportlist)
{
if (TryCreateRescueCourse(item.Item1, item.Item2))
{
rescueChanged = true;
}
}
} while (rescueChanged);
OptimizeStudentWishCoverage();
// --- Ringtausch: Schüler mit 4 Wünschen aber < 4 Zuteilungen neu zuordnen ---
foreach (var student in Settings.Instance.Students)
{
if (student.SelectedCourseNames.Count < 4)
continue;
var currentAssignments = GetAssignmentsBySemester(student.ID);
int currentCount = currentAssignments.Count(a => a != null);
if (currentCount >= 4)
continue;
// Alle aktuellen Zuteilungen entfernen (temporär)
foreach (var assignment in currentAssignments)
{
if (assignment == null) continue;
assignment.Value.Instance.Students.Remove(student.ID);
students_in_semester[assignment.Value.Semester - 1].Remove(student.ID);
}
// Alle gewünschten Sports ermitteln
var desiredSports = student.SelectedCourseNames
.Select(ResolveSportFromSelection)
.Where(s => s != null)
.DistinctBy(s => s!.Name)
.Select(s => s!)
.ToList();
// Kandidatenkurse pro Semester: Kurse mit freiem Platz, die einem Wunschsport entsprechen
var candidatesPerSemester = new List<(int Semester, CourseInstance Instance)>[4];
for (int si = 0; si < 4; si++)
{
candidatesPerSemester[si] = GeneratedCourses
.Where(c => c.Semester == si + 1)
.Where(c => c.Instance.Students.Count < c.Instance.Sport.MaxStudents)
.Where(c => desiredSports.Any(ds => ds.Name == c.Instance.Sport.Name))
.ToList();
candidatesPerSemester[si].Insert(0, default); // default = kein Kurs
}
(int Semester, CourseInstance Instance)?[] bestAssignment = currentAssignments;
int bestScore = currentCount;
int s0 = candidatesPerSemester[0].Count;
int s1 = candidatesPerSemester[1].Count;
int s2 = candidatesPerSemester[2].Count;
int s3 = candidatesPerSemester[3].Count;
var sportSelectedCounts = student.SelectedCourseNames
.Select(ResolveSportFromSelection)
.Where(sp => sp != null)
.GroupBy(sp => sp!.Name)
.ToDictionary(g => g.Key, g => g.Count());
for (int i0 = 0; i0 < s0; i0++)
for (int i1 = 0; i1 < s1; i1++)
for (int i2 = 0; i2 < s2; i2++)
for (int i3 = 0; i3 < s3; i3++)
{
var c0 = candidatesPerSemester[0][i0];
var c1 = candidatesPerSemester[1][i1];
var c2 = candidatesPerSemester[2][i2];
var c3 = candidatesPerSemester[3][i3];
var chosen = new (int Semester, CourseInstance Instance)?[]
{
c0.Instance != null ? (c0.Semester, c0.Instance) : null,
c1.Instance != null ? (c1.Semester, c1.Instance) : null,
c2.Instance != null ? (c2.Semester, c2.Instance) : null,
c3.Instance != null ? (c3.Semester, c3.Instance) : null
};
bool valid = true;
var sportUsageCounts = new Dictionary<string, int>();
for (int si = 0; si < 4; si++)
{
if (chosen[si] == null) continue;
string sportName = chosen[si]!.Value.Instance.Sport.Name;
sportUsageCounts.TryGetValue(sportName, out int used);
int allowed = sportSelectedCounts.GetValueOrDefault(sportName, 0);
if (used >= allowed) { valid = false; break; }
sportUsageCounts[sportName] = used + 1;
}
if (!valid) continue;
int score = chosen.Count(c => c != null);
if (score > bestScore)
{
bestScore = score;
bestAssignment = chosen;
}
}
// Beste Zuteilung anwenden
foreach (var assignment in bestAssignment)
{
if (assignment == null) continue;
assignment.Value.Instance.Students.Add(student.ID);
students_in_semester[assignment.Value.Semester - 1].Add(student.ID);
}
}
// ---------------------------------------------------------------------------
// Lokale Hilfsfunktionen
// ---------------------------------------------------------------------------
int getEffectiveMinStudents(Sport sport, int semester)
{
int reduction = (semester >= 3) ? 2 : 0;
return Math.Max(1, sport.MinStudents - reduction);
}
bool isStudentFree(int semester, string studentID)
{
foreach (var inst in GeneratedCourses)
{
if (semester != inst.Semester) continue;
foreach (string stud in inst.Instance.Students)
{
if (stud == studentID) return false;
}
}
return true;
}
bool requestExit()
{
globalCount++;
int sum = Settings.Instance.NumCoursesPerSemester[0] + Settings.Instance.NumCoursesPerSemester[1] +
Settings.Instance.NumCoursesPerSemester[2] + Settings.Instance.NumCoursesPerSemester[3];
if (GeneratedCourses.Count >= sum) return true;
int low = 0;
foreach (var item in initial_sportlist)
{
if (item.Item2.Count < item.Item1.MinStudents) low++;
}
if (low >= initial_sportlist.Count) return true;
if (globalCount >= 20) return true;
return false;
}
int total_missing = 0;
foreach (var tuple in initial_sportlist)
{
int[] missingPerSemester = new int[4];
foreach (var studentId in tuple.Item2.Distinct())
{
for (int semesterIndex = 0; semesterIndex < 4; semesterIndex++)
{
if (!students_in_semester[semesterIndex].Contains(studentId))
{
missingPerSemester[semesterIndex]++;
total_missing++;
}
}
}
MainWindow.Instance.TbResultTextout.Text +=
$"{tuple.Item1}: {tuple.Item2.Count} remaining ({missingPerSemester[0]},{missingPerSemester[1]},{missingPerSemester[2]},{missingPerSemester[3]})\n";
}
MainWindow.Instance.TbResultTextout.Text += $"\n total remaining: {total_missing}";
bool FillExistingCourses()
{
bool changed = false;
foreach (var item in initial_sportlist)
{
if (item.Item2.Count == 0)
continue;
foreach (var ci in GeneratedCourses
.Where(ci => ci.Instance.Sport.Name == item.Item1.Name)
.OrderBy(ci => ci.Instance.Students.Count))
{
int semester = ci.Semester;
List<string> added = new();
foreach (string stud in item.Item2)
{
if (ci.Instance.Students.Count >= ci.Instance.Sport.MaxStudents)
break;
if (students_in_semester[semester - 1].Contains(stud))
continue;
ci.Instance.Students.Add(stud);
students_in_semester[semester - 1].Add(stud);
added.Add(stud);
}
foreach (string s in added)
{
item.Item2.Remove(s);
changed = true;
}
}
}
return changed;
}
bool TryCreateRescueCourse(Sport sport, List<string> remainingStudents)
{
if (remainingStudents.Count == 0)
return false;
for (int semester = 1; semester <= 4; semester++)
{
int semesterIndex = semester - 1;
if (sport.Semester[semesterIndex] == 0)
continue;
int sportCoursesInSemester = GeneratedCourses.Count(c =>
c.Semester == semester && c.Instance.Sport.Name == sport.Name);
if (sportCoursesInSemester >= sport.Semester[semesterIndex])
continue;
if (GeneratedCourses.Count(c => c.Semester == semester) >= Settings.Instance.NumCoursesPerSemester[semester-1])
continue;
var directlyPlaceable = remainingStudents
.Distinct()
.Where(studentId => !students_in_semester[semesterIndex].Contains(studentId))
.ToList();
var donorMoves = new List<((int Semester, CourseInstance Instance) Course, string StudentId)>();
foreach (var course in GeneratedCourses
.Where(c => c.Instance.Sport.Name == sport.Name && c.Semester != semester)
.OrderByDescending(c => c.Instance.Students.Count))
{
int movableCount = course.Instance.Students.Count - getEffectiveMinStudents(sport, course.Semester);
if (movableCount <= 0)
continue;
foreach (var studentId in course.Instance.Students.ToList())
{
if (movableCount <= 0)
break;
if (students_in_semester[semesterIndex].Contains(studentId))
continue;
donorMoves.Add((course, studentId));
movableCount--;
}
}
if (directlyPlaceable.Count + donorMoves.Count < getEffectiveMinStudents(sport, semester))
continue;
var newCourse = new CourseInstance
{
Sport = sport,
Students = new List<string>()
};
foreach (var studentId in directlyPlaceable)
{
if (newCourse.Students.Count >= sport.MaxStudents)
break;
newCourse.Students.Add(studentId);
}
foreach (var move in donorMoves)
{
if (newCourse.Students.Count >= sport.MaxStudents)
break;
if (newCourse.Students.Contains(move.StudentId))
continue;
move.Course.Instance.Students.Remove(move.StudentId);
students_in_semester[move.Course.Semester - 1].Remove(move.StudentId);
newCourse.Students.Add(move.StudentId);
}
if (newCourse.Students.Count < getEffectiveMinStudents(sport, semester))
continue;
foreach (var studentId in newCourse.Students)
{
remainingStudents.Remove(studentId);
students_in_semester[semesterIndex].Add(studentId);
}
GeneratedCourses.Add((semester, newCourse));
return true;
}
return false;
}
void OptimizeStudentWishCoverage()
{
bool changed;
int iterations = 0;
do
{
changed = false;
iterations++;
foreach (var student in Settings.Instance.Students)
{
if (TryImproveStudentCoverage(student))
{
changed = true;
}
}
} while (changed && iterations < 20);
}
bool TryImproveStudentCoverage(Student student)
{
var assignments = GetAssignmentsBySemester(student.ID);
if (assignments.All(a => a != null))
return false;
var openSemesters = Enumerable.Range(0, 4)
.Where(i => assignments[i] == null)
.Select(i => i + 1)
.ToList();
if (openSemesters.Count == 0)
return false;
var assignedSports = assignments
.Where(a => a != null)
.Select(a => a!.Value.Instance.Sport.Name)
.ToHashSet();
var preferredSports = student.SelectedCourseNames
.Select(ResolveSportFromSelection)
.Where(sport => sport != null)
.DistinctBy(sport => sport!.Name)
.Select(sport => sport!)
.Where(sport => !assignedSports.Contains(sport.Name))
.ToList();
foreach (var desiredSport in preferredSports)
{
for (int sourceSemester = 1; sourceSemester <= 4; sourceSemester++)
{
var currentCourse = assignments[sourceSemester - 1];
if (currentCourse == null)
continue;
var currentCourseValue = currentCourse.Value;
var desiredCourse = GeneratedCourses
.FirstOrDefault(course =>
course.Semester == sourceSemester &&
course.Instance.Sport.Name == desiredSport.Name &&
course.Instance.Students.Count < course.Instance.Sport.MaxStudents);
if (desiredCourse.Instance == null)
continue;
foreach (var targetSemester in openSemesters)
{
var relocationTarget = GeneratedCourses
.FirstOrDefault(course =>
course.Semester == targetSemester &&
course.Instance.Sport.Name == currentCourseValue.Instance.Sport.Name &&
course.Instance.Students.Count < course.Instance.Sport.MaxStudents);
if (relocationTarget.Instance == null)
continue;
if (!CanRelocateStudent(student.ID, currentCourseValue, relocationTarget))
continue;
currentCourseValue.Instance.Students.Remove(student.ID);
students_in_semester[sourceSemester - 1].Remove(student.ID);
relocationTarget.Instance.Students.Add(student.ID);
students_in_semester[targetSemester - 1].Add(student.ID);
desiredCourse.Instance.Students.Add(student.ID);
students_in_semester[sourceSemester - 1].Add(student.ID);
return true;
}
}
}
return false;
}
bool CanRelocateStudent(
string studentId,
(int Semester, CourseInstance Instance) sourceCourse,
(int Semester, CourseInstance Instance) targetCourse)
{
if (sourceCourse.Semester == targetCourse.Semester)
return false;
if (sourceCourse.Instance.Students.Count - 1 < getEffectiveMinStudents(sourceCourse.Instance.Sport, sourceCourse.Semester))
return false;
if (targetCourse.Instance.Students.Count >= targetCourse.Instance.Sport.MaxStudents)
return false;
if (!isStudentFree(targetCourse.Semester, studentId))
return false;
return true;
}
(int Semester, CourseInstance Instance)?[] GetAssignmentsBySemester(string studentId)
{
var assignments = new (int Semester, CourseInstance Instance)?[4];
foreach (var course in GeneratedCourses)
{
if (course.Instance.Students.Contains(studentId))
{
assignments[course.Semester - 1] = course;
}
}
return assignments;
}
Sport? ResolveSportFromSelection(string selectedCourseName)
{
return ResolveSportFromCourseName(selectedCourseName);
}
int getSemesterForSport(Sport sp, List<string> interestedStudents)
{
int[] totalCoursesPerSemester = new int[4];
foreach (var inst in GeneratedCourses)
totalCoursesPerSemester[inst.Semester - 1]++;
int bestSem = 0;
int minCourses = int.MaxValue;
int maxFreeInterestedStudents = -1;
for (int i = 0; i < 4; i++)
{
if (sp.Semester[i] == 0)
continue;
int semesterNumber = i + 1;
int sportCoursesInThisSemester = GeneratedCourses
.Count(g => g.Semester == semesterNumber &&
g.Instance.Sport.Name == sp.Name);
if (sportCoursesInThisSemester >= sp.Semester[i])
continue;
if (totalCoursesPerSemester[i] >= Settings.Instance.NumCoursesPerSemester[i])
continue;
int freeInterestedStudents = interestedStudents
.Distinct()
.Count(studentId => !students_in_semester[i].Contains(studentId));
if (freeInterestedStudents < getEffectiveMinStudents(sp, semesterNumber))
continue;
if (freeInterestedStudents > maxFreeInterestedStudents ||
(freeInterestedStudents == maxFreeInterestedStudents &&
totalCoursesPerSemester[i] < minCourses))
{
maxFreeInterestedStudents = freeInterestedStudents;
minCourses = totalCoursesPerSemester[i];
bestSem = semesterNumber;
}
}
return bestSem;
}
ReloadResult();
}
public static void ReloadResult()
{
var errors = ValidateCourses(GeneratedCourses);
if (errors.Count == 0)
{
MainWindow.Instance.TbResultLog.Text = "--- Alle generierten Kursen erfüllen die gegebenen Voraussetzungen ---";
}
else
{
MainWindow.Instance.TbResultLog.Text = "--- Bei der Generierung sind folgende Fehler aufgetreten: ---\n\n";
foreach (var e in errors)
MainWindow.Instance.TbResultLog.Text += e + "\n";
}
foreach (var student in Settings.Instance.Students)
{
student.Result = new string[4];
}
foreach (var course in GeneratedCourses)
{
foreach (var student in Settings.Instance.Students)
{
if (course.Instance.Students.Contains(student.ID))
{
student.Result[course.Semester - 1] = course.Instance.Sport.Name;
}
}
}
}
public static string GenerateStatistics()
{
GeneratedCourses.Sort((x,y) => x.Semester.CompareTo(y.Semester) );
string sb = $"Generierte Kurse: {GeneratedCourses.Count}\n\n";
foreach (var genc in GeneratedCourses)
{
sb += $"Sem. {genc.Semester}: {genc.Instance.Sport.Name} ({genc.Instance.Students.Count} SuS)\n";
}
return sb;
}
public static List<string> ValidateCourses(List<(int Semester, CourseInstance Instance)> courses)
{
List<string> errors = new();
// --- 1. Min/Max + Semester erlaubt ---
foreach (var tuple in courses)
{
int semester = tuple.Semester;
var inst = tuple.Instance;
var sport = inst.Sport;
if (inst.Students.Count < sport.MinStudents)
{
errors.Add($"[Min] {sport.Name} (Sem {semester}): {inst.Students.Count} < {sport.MinStudents}");
}
if (inst.Students.Count > sport.MaxStudents)
{
errors.Add($"[Max] {sport.Name} (Sem {semester}): {inst.Students.Count} > {sport.MaxStudents}");
}
if (sport.Semester[semester - 1] == 0)
{
errors.Add($"[Semester] {sport.Name} darf nicht in Semester {semester} stattfinden");
}
// --- doppelte Schüler im selben Kurs ---
for (int i = 0; i < inst.Students.Count; i++)
{
for (int j = i + 1; j < inst.Students.Count; j++)
{
if (inst.Students[i] == inst.Students[j])
{
errors.Add($"[Kurs-Duplikat] {inst.Students[i]} mehrfach in {sport.Name} (Sem {semester})");
}
}
}
}
// --- 2. Schüler doppelt im Semester ---
for (int sem = 1; sem <= 4; sem++)
{
List<string> students = new();
foreach (var tuple in courses)
{
if (tuple.Semester != sem) continue;
foreach (var stud in tuple.Instance.Students)
{
// prüfen ob schon drin
bool exists = false;
foreach (var s in students)
{
if (s == stud)
{
exists = true;
break;
}
}
if (exists)
{
errors.Add($"[Doppelt] Schüler {stud} doppelt in Semester {sem}");
}
else
{
students.Add(stud);
}
}
}
}
// --- 3. Sport-Angebote pro Semester zählen ---
// (ohne Dictionary: wir iterieren über alle Kurse und zählen jeweils erneut)
foreach (var tuple in courses)
{
int semester = tuple.Semester;
var sport = tuple.Instance.Sport;
int count = 0;
foreach (var other in courses)
{
if (other.Semester == semester &&
other.Instance.Sport.Name == sport.Name)
{
count++;
}
}
int allowed = sport.Semester[semester - 1];
if (count > allowed)
{
errors.Add($"[Sport-Semester] {sport.Name} in Sem {semester}: {count} Kurse > erlaubt {allowed}");
}
}
return errors;
}
}
+67
View File
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.Json;
namespace spplus;
public static class ExportUtility
{
private sealed class ConfigurationExport
{
public List<Sport> Sports { get; set; } = [];
public int[] NumCoursesPerSemester { get; set; } = [];
}
public static void ExportToCSV(string filepath)
{
char separator = ',';
string header = $"SchuelerID{separator}Sem1{separator}Sem2{separator}Sem3{separator}Sem4";
string output = header + "\n";
foreach (var student in Settings.Instance.Students)
{
output += $"{student.ID}{separator}{student.Result[0]}{separator}{student.Result[1]}{separator}{student.Result[2]}{separator}{student.Result[3]}\n";
}
File.WriteAllText(filepath, output);
}
private sealed class ResultExportEntry
{
public int Semester { get; set; }
public string SportName { get; set; } = string.Empty;
public List<string> Students { get; set; } = new();
}
public static void ExportResultsToJson(string filepath)
{
var list = CourseCrafter.GeneratedCourses
.Select(g => new ResultExportEntry
{
Semester = g.Semester,
SportName = g.Instance.Sport.Name,
Students = g.Instance.Students.ToList()
})
.ToList();
var json = JsonSerializer.Serialize(list, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(filepath, json);
}
public static void ExportConfigurationToJson(string filepath)
{
var export = new ConfigurationExport
{
Sports = Settings.Instance.Sports,
NumCoursesPerSemester = Settings.Instance.NumCoursesPerSemester
};
var json = JsonSerializer.Serialize(export, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(filepath, json);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

+128
View File
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Linq;
namespace spplus;
public static class import
{
public static List<Student> ImportStudentsFromFile(string path)
{
var dict = new Dictionary<string, (string Name, List<string> Courses)>();
foreach (var line in File.ReadLines(path).Skip(1)) // Header überspringen
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split(',');
if (parts.Length < 3)
continue;
string nameWithId = parts[0].Trim();
string course = parts[2].Replace("(2)", "").Replace("(3)", "").Replace("(4)", "").Trim();
int open = nameWithId.LastIndexOf('(');
int close = nameWithId.LastIndexOf(')');
if (open < 0 || close < 0 || close <= open)
continue;
string name = nameWithId[..open].Trim();
string id = nameWithId[(open + 1)..close].Trim();
if (!dict.ContainsKey(id))
dict[id] = (name, new List<string>());
dict[id].Courses.Add(course);
}
var result = new List<Student>();
foreach (var (id, data) in dict)
{
var student = new Student(id, data.Name, data.Courses);
result.Add(student);
}
return result;
}
public static List<Student> ImportResultFromFile(string path)
{
var dict = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
foreach (var line in File.ReadLines(path).Skip(1)) // Header überspringen
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split(',', StringSplitOptions.None);
if (parts.Length < 5)
continue;
var studentId = parts[0].Trim();
dict[studentId] = new[]
{
parts[1].Trim(),
parts[2].Trim(),
parts[3].Trim(),
parts[4].Trim()
};
}
return dict
.Select(entry => new Student(entry.Key, string.Empty, new List<string>())
{
Result = entry.Value
})
.ToList();
}
private sealed class ResultImportEntry
{
public int Semester { get; set; }
public string SportName { get; set; } = string.Empty;
public List<string> Students { get; set; } = new();
}
public static List<(int Semester, CourseCrafter.CourseInstance Instance)> ImportResultFromJson(string path)
{
try
{
var json = File.ReadAllText(path);
var entries = JsonSerializer.Deserialize<List<ResultImportEntry>>(json);
if (entries == null) return new();
var result = new List<(int Semester, CourseCrafter.CourseInstance Instance)>();
foreach (var e in entries)
{
if (string.IsNullOrWhiteSpace(e.SportName))
continue;
var sport = Settings.Instance.Sports.FirstOrDefault(s =>
string.Equals(s.Name, e.SportName, StringComparison.OrdinalIgnoreCase) ||
s.AlternativeNames.Any(a => string.Equals(a, e.SportName, StringComparison.OrdinalIgnoreCase)));
if (sport == null)
continue;
var ci = new CourseCrafter.CourseInstance
{
Sport = sport,
Students = e.Students.Distinct().ToList()
};
result.Add((e.Semester, ci));
}
return result;
}
catch
{
return new();
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

+34
View File
@@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>res/logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
@@ -19,4 +20,37 @@
</PackageReference>
<PackageReference Include="Lucide.Avalonia" Version="0.1.35"/>
</ItemGroup>
<ItemGroup>
<Reference Include="PdfSharp">
<HintPath>lib/pdfsharp/PdfSharp.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="PdfSharp.System">
<HintPath>lib/pdfsharp/PdfSharp.System.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
<HintPath>lib/pdfsharp/Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<None Remove="res\logo.ico"/>
<AvaloniaResource Include="res\logo.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AvaloniaResource>
<None Remove="res\logo.png"/>
<AvaloniaResource Include="res\logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AvaloniaResource>
</ItemGroup>
<ItemGroup>
<None Include="res/fonts/*.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
+79 -14
View File
@@ -1,50 +1,81 @@
using System.Collections.Generic;
using Avalonia.Data;
namespace spplus;
public abstract class Sport
public class Sport
{
public int ID { get; set; } = 0;
public string Name { get; set; } = "Neuer Kurs"; // Kursname
public int MaxCoursesPerSemester { get; set; } = 1; // Maximale Anzahl an Kursen pro Semester
public int MaxStudents { get; set; } = 20; // Maximale Anzahl an Schülern pro Kurs
public int MaxStudents { get; set; } = 25; // Maximale Anzahl an Schülern pro Kurs
public int MinStudents { get; set; } = 5; // Minimale Anzahl an Schülern pro Kurs
public int[] Semester { get; set; } = [1, 2, 3, 4]; // Angebot in diesen Semestern
public int[] Semester { get; set; } = [2, 2, 2, 2]; // Maximale Anzahl an Angeboten in den jeweiligen Index-Semestern (0 => 1. Semester)
public List<string> AlternativeNames { get; set; } = new();
//public List<int> AlternativeCourses { get; set; } = new();
protected Sport()
{
}
protected Sport(string name)
public Sport(string name)
{
Name = name;
}
protected Sport(string name, int maxCoursesPerSemester, int maxStudents, int minStudents, int[] semester)
public Sport(string name, int maxCoursesPerSemester, int maxStudents, int minStudents, int[] semester, List<string> alternativeNames)
{
Name = name;
MaxCoursesPerSemester = maxCoursesPerSemester;
MaxStudents = maxStudents;
MinStudents = minStudents;
Semester = semester;
AlternativeNames = alternativeNames;
}
// public void AddAlternativeSport(int id)
// {
// AlternativeCourses.Add(id);
// }
//
// public void ClearAlternativeSport()
// {
// AlternativeCourses.Clear();
// }
public override string ToString()
{
var alt = "";
foreach (var s in AlternativeNames)
{
alt += s + ", ";
}
return $"{Name} ({alt})";
}
}
public abstract class Student
public class Student
{
public string Name { get; set; } = ""; // Name des Schülers
public Sport[] SelectedCourses { get; set; } = new Sport[4]; // Kurswahl
public List<string>? Result { get; set; } = null;
public string ID { get; set; } = ""; // ID des Schüler (z.B. NolteSeb)
public string Name { get; set; } = ""; // Name des Schülers
public List<string> SelectedCourseNames { get; set; } = new();
public string[] Result { get; set; } = new string[4];
protected Student()
public Student()
{
}
protected Student(string name, Sport[] selectedCourses)
public override string ToString()
{
return $"{Name} ({ID})";
}
public Student(string id, string name, List<string> selectedCoursesNames)
{
ID = id;
Name = name;
SelectedCourses = selectedCourses;
SelectedCourseNames = selectedCoursesNames;
}
}
@@ -54,6 +85,7 @@ public class Settings
public List<Student> Students { get; set; } = [];
public List<Sport> Sports { get; set; } = [];
public int[] NumCoursesPerSemester { get; set; } = [10,10,11,11]; // Exact Amount of courses, not a maximum
public Settings()
{
@@ -64,4 +96,37 @@ public class Settings
{
// Hier importieren...
}
public static void ImportInitial()
{
Instance.Sports.Clear();
int id = 1;
Instance.Sports.Add(new Sport("Tischtennis"){ ID = id++, AlternativeNames = {"Sport_TT"}});
Instance.Sports.Add(new Sport("Badminton"){ ID = id++, AlternativeNames = {"Sport_BM"}});
Instance.Sports.Add(new Sport("Gymnastik/Tanz"){ ID = id++, AlternativeNames = {"Sport_Gym"}});
Instance.Sports.Add(new Sport("Schwimmen"){ ID = id++, AlternativeNames = {"Sport_SW"}, Semester = [1, 1, 1, 1], MaxStudents = 18});
Instance.Sports.Add(new Sport("Bouldern"){ ID = id++, AlternativeNames = {"Sport_BO"}, Semester = [1, 1, 1, 1]});
Instance.Sports.Add(new Sport("Basketball"){ ID = id++, AlternativeNames = {"Sport_BS"}});
Instance.Sports.Add(new Sport("Fitness"){ ID = id++, AlternativeNames = {"Sport_Fit"}});
Instance.Sports.Add(new Sport("Fußball"){ ID = id++, AlternativeNames = {"Sport_Fuß"}, Semester = [1, 0, 1, 0]});
Instance.Sports.Add(new Sport("Handball"){ ID = id++, AlternativeNames = {"Sport_HB"}});
Instance.Sports.Add(new Sport("Leichtathletik"){ ID = id++, AlternativeNames = {"Sport_LA"}, Semester = [1, 0, 1, 0], MaxStudents = 18});
Instance.Sports.Add(new Sport("Tennis"){ ID = id++, AlternativeNames = {"Sport_Te"}});
Instance.Sports.Add(new Sport("Turnen"){ ID = id++, AlternativeNames = {"Sport_Tur"}});
Instance.Sports.Add(new Sport("Volleyball"){ ID = id++, AlternativeNames = {"Sport_VB"}});
}
public static string? GetSportNameFromID(int id)
{
foreach (var s in Instance.Sports)
{
if (s.ID == id)
{
return s.Name;
}
}
return null;
}
}