diff --git a/AquaCare.Controller/PflegeController.cs b/AquaCare.Controller/PflegeController.cs index e5ef6c3..48ffd6b 100644 --- a/AquaCare.Controller/PflegeController.cs +++ b/AquaCare.Controller/PflegeController.cs @@ -3,15 +3,19 @@ using AquaCare.Persistence; namespace AquaCare.Controller { + // Controller-Klasse für die Verwaltung und Speicherung von Pflegemaßnahmen und Messwerten public class PflegeController { + // Referenz auf die Datenbank private readonly Datenbank _db; + // Konstruktor: Übergibt die Datenbankinstanz public PflegeController(Datenbank db) { _db = db; } + // Speichert einen neuen Pflege- bzw. Werte-Eintrag in der Datenbank public bool SavePflegeTask(DateTime datum, bool gefuettert, bool filterReinigen, bool wasserWechseln, double temperatur, double phWert, double nitrat, double ammoniak) { @@ -29,15 +33,16 @@ namespace AquaCare.Controller Ammoniak = ammoniak }; - _db.AddValue(wert); + _db.AddValue(wert); // Eintrag in die Datenbank speichern return true; } catch { - return false; + return false; // Fehler beim Speichern } } + // Gibt alle gespeicherten Werte als Liste zurück public List GetAllWerte() { return _db.GetValuesAsObjects(); diff --git a/AquaCare.Controller/WerteController.cs b/AquaCare.Controller/WerteController.cs index af1e71e..47a424d 100644 --- a/AquaCare.Controller/WerteController.cs +++ b/AquaCare.Controller/WerteController.cs @@ -3,15 +3,19 @@ using AquaCare.Persistence; namespace AquaCare.Controller { + // Controller-Klasse für das Laden der gespeicherten Werte aus der Datenbank public class WerteController { + // Referenz auf die Datenbank private readonly Datenbank _db; + // Konstruktor: Übergibt die Datenbankinstanz public WerteController(Datenbank db) { _db = db; } + // Lädt alle gespeicherten Werte als Liste public List LoadWerte() { return _db.GetValuesAsObjects(); diff --git a/AquaCare.Model/Werte.cs b/AquaCare.Model/Werte.cs index f1be2b2..0f836f4 100644 --- a/AquaCare.Model/Werte.cs +++ b/AquaCare.Model/Werte.cs @@ -1,14 +1,23 @@ namespace AquaCare.Model { + // Modellklasse für einen Messwert- bzw. Pflegeeintrag public class Werte { + // Datum und Uhrzeit des Eintrags public DateTime Datum { get; set; } + // Wurde gefüttert? public bool Gefuettert { get; set; } + // Wurde der Filter gereinigt? public bool FilterReinigen { get; set; } + // Wurde Wasser gewechselt? public bool WasserWechseln { get; set; } + // Temperatur in °C public double Temperatur { get; set; } + // pH-Wert public double PhWert { get; set; } + // Nitratwert in mg/l public double Nitrat { get; set; } + // Ammoniakwert in mg/l public double Ammoniak { get; set; } } } \ No newline at end of file diff --git a/AquaCare.Persistence/AquaCare.Persistence.csproj b/AquaCare.Persistence/AquaCare.Persistence.csproj index c892249..139592f 100644 --- a/AquaCare.Persistence/AquaCare.Persistence.csproj +++ b/AquaCare.Persistence/AquaCare.Persistence.csproj @@ -1,14 +1,20 @@ - + + net9.0 enable + + diff --git a/AquaCare.Persistence/Datenbank.cs b/AquaCare.Persistence/Datenbank.cs index b8dc17f..153e83d 100644 --- a/AquaCare.Persistence/Datenbank.cs +++ b/AquaCare.Persistence/Datenbank.cs @@ -6,24 +6,30 @@ using AquaCare.Model; namespace AquaCare.Persistence { + // Klasse für den Datenbankzugriff (SQLite) public class Datenbank { + // Pfad zum Ordner, in dem die Datenbank liegt private static readonly string PersistencePath = Path.GetDirectoryName( typeof(Datenbank).Assembly.Location) ?? throw new InvalidOperationException("Assembly location not found"); + // Pfad zur SQLite-Datenbankdatei private static readonly string DbPath = Path.Combine( PersistencePath, "..", "..", "..", "..", "AquaCare.Persistence", "AquaCareDatenbank.db"); + // Verbindungszeichenfolge für SQLite private string ConnectionString => $"Data Source={DbPath}"; + // Konstruktor: Prüft, ob die Datenbank existiert, und legt sie ggf. an public Datenbank() { EnsureDatabaseExists(); } + // Stellt sicher, dass die Datenbank und der Ordner existieren private void EnsureDatabaseExists() { var directory = Path.GetDirectoryName(DbPath); @@ -38,6 +44,7 @@ namespace AquaCare.Persistence } } + // Legt eine neue Datenbank mit der Tabelle "Werte" an private void InitializeNewDatabase() { using var connection = new SqliteConnection(ConnectionString); @@ -58,6 +65,7 @@ namespace AquaCare.Persistence command.ExecuteNonQuery(); } + // Fügt einen neuen Werte-Datensatz in die Datenbank ein public void AddValue(Werte wert) { using var connection = new SqliteConnection(ConnectionString); @@ -85,6 +93,7 @@ namespace AquaCare.Persistence command.ExecuteNonQuery(); } + // Gibt alle Werte als Liste von Objekten zurück public List GetValuesAsObjects() { var werte = new List(); diff --git a/AquaCare.View/App.axaml.cs b/AquaCare.View/App.axaml.cs index e67249c..6d77b1a 100644 --- a/AquaCare.View/App.axaml.cs +++ b/AquaCare.View/App.axaml.cs @@ -4,15 +4,19 @@ using Avalonia.Markup.Xaml; namespace AquaCare.View; +// Einstiegspunkt für die Avalonia-Anwendung public partial class App : Application { + // Initialisiert die Anwendung und lädt die XAML-Ressourcen public override void Initialize() { AvaloniaXamlLoader.Load(this); } + // Wird nach Abschluss der Framework-Initialisierung aufgerufen public override void OnFrameworkInitializationCompleted() { + // Setzt das Hauptfenster, wenn die Anwendung als klassische Desktop-App läuft if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow(); diff --git a/AquaCare.View/AquaCare.View.csproj b/AquaCare.View/AquaCare.View.csproj index 42f8e53..674e627 100644 --- a/AquaCare.View/AquaCare.View.csproj +++ b/AquaCare.View/AquaCare.View.csproj @@ -8,37 +8,34 @@ true + - - - - - - - None - All - - - - + + + + + + + None + All + + + + + + + - - - - - - - diff --git a/AquaCare.View/EinstellungenWindow.axaml.cs b/AquaCare.View/EinstellungenWindow.axaml.cs index a9002f8..a3a92e2 100644 --- a/AquaCare.View/EinstellungenWindow.axaml.cs +++ b/AquaCare.View/EinstellungenWindow.axaml.cs @@ -2,11 +2,13 @@ using Avalonia.Controls; namespace AquaCare.View { + // Fenster für die Einstellungen der Anwendung public partial class EinstellungenWindow : Window { + // Konstruktor: Initialisiert das Einstellungsfenster public EinstellungenWindow() { - InitializeComponent(); + InitializeComponent(); // Initialisiert die UI-Komponenten } } } diff --git a/AquaCare.View/MainWindow.axaml b/AquaCare.View/MainWindow.axaml index 8cccede..9ec60ba 100644 --- a/AquaCare.View/MainWindow.axaml +++ b/AquaCare.View/MainWindow.axaml @@ -1,3 +1,7 @@ + - + - + @@ -21,35 +25,34 @@ - - + + - + + - + - - - + - +