diff --git a/Project_Periodensystem.Controller/PeriodensystemController.cs b/Project_Periodensystem.Controller/PeriodensystemController.cs index 49e70ec..a28d875 100644 --- a/Project_Periodensystem.Controller/PeriodensystemController.cs +++ b/Project_Periodensystem.Controller/PeriodensystemController.cs @@ -24,19 +24,19 @@ namespace Project_Periodensystem.Controller } /// - /// Lädt alle Elemente über den Persistence-Layer + /// Lädt alle Elemente über den Persistence-Layer (JETZT MIT DATAMANAGER!) /// private void LoadElements() { try { - // Verwende die korrekte statische Methode aus PeriodicTableData - _elements = PeriodicTableData.Elements.ToList(); - Logger.Log($"Controller: {_elements.Count} Elemente erfolgreich geladen"); + // NEUE METHODE: DataManager statt direkt PeriodicTableData + _elements = DataManager.LoadElements(); + Logger.Log($"Controller: {_elements.Count} Elemente erfolgreich geladen (via DataManager)"); } catch (Exception ex) { - Logger.Log($"EXCEPTION in LoadElements: {ex.Message}"); + Logger.LogException(ex, "LoadElements"); _elements = new List(); } } @@ -50,6 +50,22 @@ namespace Project_Periodensystem.Controller return _elements; } + /// + /// Speichert Elemente persistent (NEUE FUNKTION) + /// + public void SaveElements() + { + try + { + DataManager.SaveElements(_elements); + Logger.Log("Elemente erfolgreich gespeichert"); + } + catch (Exception ex) + { + Logger.LogException(ex, "SaveElements"); + } + } + /// /// Sucht ein Element nach Atomnummer /// diff --git a/Project_Periodensystem.Persistence/DataManager.cs b/Project_Periodensystem.Persistence/DataManager.cs new file mode 100644 index 0000000..0203550 --- /dev/null +++ b/Project_Periodensystem.Persistence/DataManager.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using Project_Periodensystem.Model; + +namespace Project_Periodensystem.Persistence +{ + /// + /// Erweiterte Persistenz - Speichern/Laden von JSON-Dateien + /// + public static class DataManager + { + private static readonly string DataDirectory = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + "Periodensystem"); + + private static readonly string ElementsFile = Path.Combine(DataDirectory, "elements.json"); + private static readonly string SettingsFile = Path.Combine(DataDirectory, "settings.json"); + + /// + /// Speichert Elemente als JSON + /// + public static void SaveElements(List elements) + { + try + { + Directory.CreateDirectory(DataDirectory); + var json = JsonSerializer.Serialize(elements, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(ElementsFile, json); + Logger.Log($"Elemente gespeichert: {elements.Count} Einträge"); + } + catch (Exception ex) + { + Logger.LogException(ex, "SaveElements"); + } + } + + /// + /// Lädt Elemente aus JSON oder Fallback zu eingebauten Daten + /// + public static List LoadElements() + { + try + { + if (File.Exists(ElementsFile)) + { + var json = File.ReadAllText(ElementsFile); + var elements = JsonSerializer.Deserialize>(json); + if (elements != null && elements.Count > 0) + { + Logger.Log($"Elemente aus Datei geladen: {elements.Count}"); + return elements; + } + } + } + catch (Exception ex) + { + Logger.LogException(ex, "LoadElements"); + } + + // Fallback zu eingebauten Daten + Logger.Log("Fallback zu eingebauten Element-Daten"); + return PeriodicTableData.Elements; + } + + /// + /// Speichert Benutzereinstellungen + /// + public static void SaveSettings(AppSettings settings) + { + try + { + Directory.CreateDirectory(DataDirectory); + var json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(SettingsFile, json); + } + catch (Exception ex) + { + Logger.LogException(ex, "SaveSettings"); + } + } + + /// + /// Lädt Benutzereinstellungen + /// + public static AppSettings LoadSettings() + { + try + { + if (File.Exists(SettingsFile)) + { + var json = File.ReadAllText(SettingsFile); + var settings = JsonSerializer.Deserialize(json); + return settings ?? new AppSettings(); + } + } + catch (Exception ex) + { + Logger.LogException(ex, "LoadSettings"); + } + + return new AppSettings(); + } + } + + /// + /// Benutzereinstellungen für Persistenz + /// + public class AppSettings + { + public string LastTheme { get; set; } = "Dark"; + public DateTime LastUsed { get; set; } = DateTime.Now; + public string PreferredLanguage { get; set; } = "German"; + } +} \ No newline at end of file diff --git a/Project_Periodensystem.View/App.axaml.cs b/Project_Periodensystem.View/App.axaml.cs index af02b32..82de003 100644 --- a/Project_Periodensystem.View/App.axaml.cs +++ b/Project_Periodensystem.View/App.axaml.cs @@ -1,7 +1,9 @@ +using System; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Project_Periodensystem.Model; +using Project_Periodensystem.Persistence; namespace Project_Periodensystem.View { @@ -16,14 +18,51 @@ namespace Project_Periodensystem.View { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - // Standard Dark Theme beim Start - RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Dark; + // Settings laden und Theme setzen + var settings = DataManager.LoadSettings(); + // Theme aus Settings setzen + if (settings.LastTheme == "Light") + { + RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Light; + } + else + { + RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Dark; + } + desktop.MainWindow = new MainWindow(); - Logger.Log("Application initialized with Dark theme"); + Logger.Log($"Application initialized with {settings.LastTheme} theme from settings"); + + // Settings beim Beenden speichern + desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnMainWindowClose; + desktop.Exit += OnApplicationExit; } base.OnFrameworkInitializationCompleted(); } + + /// + /// Speichert Settings beim Beenden der App + /// + private void OnApplicationExit(object? sender, ControlledApplicationLifetimeExitEventArgs e) + { + try + { + var settings = new AppSettings + { + LastTheme = RequestedThemeVariant?.ToString() ?? "Dark", + LastUsed = DateTime.Now, + PreferredLanguage = "German" + }; + + DataManager.SaveSettings(settings); + Logger.Log("Settings beim App-Exit gespeichert"); + } + catch (Exception ex) + { + Logger.Log($"EXCEPTION in OnApplicationExit: {ex.Message}"); + } + } } } diff --git a/Project_Periodensystem.View/LandingPage.axaml.cs b/Project_Periodensystem.View/LandingPage.axaml.cs index 4c43f1e..818b1f9 100644 --- a/Project_Periodensystem.View/LandingPage.axaml.cs +++ b/Project_Periodensystem.View/LandingPage.axaml.cs @@ -1,7 +1,9 @@ +using System; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Project_Periodensystem.Model; +using Project_Periodensystem.Persistence; namespace Project_Periodensystem.View { @@ -33,7 +35,7 @@ namespace Project_Periodensystem.View Logger.Log("Navigation zum Periodensystem"); } } - catch (System.Exception ex) + catch (Exception ex) { Logger.Log($"Fehler bei Navigation zum Periodensystem: {ex.Message}"); } @@ -54,14 +56,14 @@ namespace Project_Periodensystem.View Logger.Log("Navigation zur About-Seite"); } } - catch (System.Exception ex) + catch (Exception ex) { Logger.Log($"Fehler bei Navigation zu About: {ex.Message}"); } } /// - /// Event-Handler für Theme-Button + /// Event-Handler für Theme-Button (MIT SETTINGS-SPEICHERUNG) /// private void ThemeButton_Click(object? sender, RoutedEventArgs e) { @@ -81,15 +83,22 @@ namespace Project_Periodensystem.View app.RequestedThemeVariant = newTheme; Logger.Log($"Theme gewechselt zu: {newTheme}"); + + // NEUE FUNKTION: Theme-Einstellung speichern + var settings = DataManager.LoadSettings(); + settings.LastTheme = newTheme.ToString(); + settings.LastUsed = DateTime.Now; + DataManager.SaveSettings(settings); + Logger.Log("Theme-Einstellung gespeichert"); } else { Logger.Log("Application.Current ist null!"); } } - catch (System.Exception ex) + catch (Exception ex) { - Logger.Log($"Fehler beim Theme-Wechsel: {ex.Message}"); + Logger.Log($"EXCEPTION in ThemeButton_Click: {ex.Message}"); } } } diff --git a/Project_Periodensystem.View/PeriodicTablePage.axaml.cs b/Project_Periodensystem.View/PeriodicTablePage.axaml.cs index e46a453..2b2127c 100644 --- a/Project_Periodensystem.View/PeriodicTablePage.axaml.cs +++ b/Project_Periodensystem.View/PeriodicTablePage.axaml.cs @@ -1,13 +1,14 @@ +using System; +using System.Globalization; +using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; using Project_Periodensystem.Controller; using Project_Periodensystem.Model; +using Project_Periodensystem.Persistence; using Project_Periodensystem.View.Converters; -using System; -using System.Globalization; -using System.Linq; namespace Project_Periodensystem.View { @@ -218,5 +219,25 @@ namespace Project_Periodensystem.View Logger.Log($"Fehler bei Navigation zurück: {ex.Message}"); } } + + /// + /// Export-Button für Element-Daten (NEUE FUNKTION) + /// + private void ExportButton_Click(object? sender, RoutedEventArgs e) + { + try + { + var elements = _controller.GetAllElements(); + DataManager.SaveElements(elements); + Logger.Log($"Export: {elements.Count} Elemente als JSON gespeichert"); + + // Optional: Benutzer-Feedback + // ShowMessage("Daten erfolgreich exportiert!"); + } + catch (Exception ex) + { + Logger.Log($"EXCEPTION in ExportButton_Click: {ex.Message}"); + } + } } } diff --git a/Project_Periodensystem.View/projektstruktur.txt b/Project_Periodensystem.View/projektstruktur.txt new file mode 100644 index 0000000..f56239e --- /dev/null +++ b/Project_Periodensystem.View/projektstruktur.txt @@ -0,0 +1,253 @@ +Auflistung der Ordnerpfade +Volumeseriennummer : 00C1-D40F +C:. +¦ AboutPage.axaml +¦ AboutPage.axaml.cs +¦ App.axaml +¦ App.axaml.cs +¦ app.manifest +¦ LandingPage.axaml +¦ LandingPage.axaml.cs +¦ logger.cs +¦ MainWindow.axaml +¦ MainWindow.axaml.cs +¦ PeriodicTablePage.axaml +¦ PeriodicTablePage.axaml.cs +¦ Program.cs +¦ Project_Periodensystem.View.csproj +¦ Project_Periodensystem.View.sln +¦ projektstruktur.txt +¦ ++---bin +¦ +---Debug +¦ +---net8.0 +¦ ¦ app_log.txt +¦ ¦ Avalonia.Base.dll +¦ ¦ Avalonia.Controls.ColorPicker.dll +¦ ¦ Avalonia.Controls.DataGrid.dll +¦ ¦ Avalonia.Controls.dll +¦ ¦ Avalonia.DesignerSupport.dll +¦ ¦ Avalonia.Desktop.dll +¦ ¦ Avalonia.Diagnostics.dll +¦ ¦ Avalonia.Dialogs.dll +¦ ¦ Avalonia.dll +¦ ¦ Avalonia.FreeDesktop.dll +¦ ¦ Avalonia.Markup.dll +¦ ¦ Avalonia.Markup.Xaml.dll +¦ ¦ Avalonia.Metal.dll +¦ ¦ Avalonia.MicroCom.dll +¦ ¦ Avalonia.Native.dll +¦ ¦ Avalonia.OpenGL.dll +¦ ¦ Avalonia.ReactiveUI.dll +¦ ¦ Avalonia.Remote.Protocol.dll +¦ ¦ Avalonia.Skia.dll +¦ ¦ Avalonia.Themes.Fluent.dll +¦ ¦ Avalonia.Themes.Simple.dll +¦ ¦ Avalonia.Win32.dll +¦ ¦ Avalonia.X11.dll +¦ ¦ DynamicData.dll +¦ ¦ HarfBuzzSharp.dll +¦ ¦ MicroCom.Runtime.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.dll +¦ ¦ Microsoft.CodeAnalysis.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.dll +¦ ¦ Microsoft.Win32.SystemEvents.dll +¦ ¦ Project_Periodensystem.Controller.dll +¦ ¦ Project_Periodensystem.Controller.pdb +¦ ¦ Project_Periodensystem.Model.dll +¦ ¦ Project_Periodensystem.Model.pdb +¦ ¦ Project_Periodensystem.Persistence.dll +¦ ¦ Project_Periodensystem.Persistence.pdb +¦ ¦ Project_Periodensystem.View.deps.json +¦ ¦ Project_Periodensystem.View.dll +¦ ¦ Project_Periodensystem.View.exe +¦ ¦ Project_Periodensystem.View.pdb +¦ ¦ Project_Periodensystem.View.runtimeconfig.json +¦ ¦ ReactiveUI.dll +¦ ¦ SkiaSharp.dll +¦ ¦ Splat.dll +¦ ¦ System.Drawing.Common.dll +¦ ¦ System.IO.Pipelines.dll +¦ ¦ System.Reactive.dll +¦ ¦ Tmds.DBus.Protocol.dll +¦ ¦ +¦ +---cs +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---de +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---es +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---fr +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---it +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---ja +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---ko +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---pl +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---pt-BR +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---ru +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---runtimes +¦ ¦ +---linux-arm +¦ ¦ ¦ +---native +¦ ¦ ¦ libHarfBuzzSharp.so +¦ ¦ ¦ libSkiaSharp.so +¦ ¦ ¦ +¦ ¦ +---linux-arm64 +¦ ¦ ¦ +---native +¦ ¦ ¦ libHarfBuzzSharp.so +¦ ¦ ¦ libSkiaSharp.so +¦ ¦ ¦ +¦ ¦ +---linux-musl-x64 +¦ ¦ ¦ +---native +¦ ¦ ¦ libHarfBuzzSharp.so +¦ ¦ ¦ libSkiaSharp.so +¦ ¦ ¦ +¦ ¦ +---linux-x64 +¦ ¦ ¦ +---native +¦ ¦ ¦ libHarfBuzzSharp.so +¦ ¦ ¦ libSkiaSharp.so +¦ ¦ ¦ +¦ ¦ +---osx +¦ ¦ ¦ +---native +¦ ¦ ¦ libAvaloniaNative.dylib +¦ ¦ ¦ libHarfBuzzSharp.dylib +¦ ¦ ¦ libSkiaSharp.dylib +¦ ¦ ¦ +¦ ¦ +---unix +¦ ¦ ¦ +---lib +¦ ¦ ¦ +---net6.0 +¦ ¦ ¦ System.Drawing.Common.dll +¦ ¦ ¦ +¦ ¦ +---win +¦ ¦ ¦ +---lib +¦ ¦ ¦ +---net6.0 +¦ ¦ ¦ Microsoft.Win32.SystemEvents.dll +¦ ¦ ¦ System.Drawing.Common.dll +¦ ¦ ¦ +¦ ¦ +---win-arm64 +¦ ¦ ¦ +---native +¦ ¦ ¦ av_libglesv2.dll +¦ ¦ ¦ libHarfBuzzSharp.dll +¦ ¦ ¦ libSkiaSharp.dll +¦ ¦ ¦ +¦ ¦ +---win-x64 +¦ ¦ ¦ +---native +¦ ¦ ¦ av_libglesv2.dll +¦ ¦ ¦ libHarfBuzzSharp.dll +¦ ¦ ¦ libSkiaSharp.dll +¦ ¦ ¦ +¦ ¦ +---win-x86 +¦ ¦ +---native +¦ ¦ av_libglesv2.dll +¦ ¦ libHarfBuzzSharp.dll +¦ ¦ libSkiaSharp.dll +¦ ¦ +¦ +---tr +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---zh-Hans +¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ ¦ Microsoft.CodeAnalysis.resources.dll +¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ¦ +¦ +---zh-Hant +¦ Microsoft.CodeAnalysis.CSharp.resources.dll +¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll +¦ Microsoft.CodeAnalysis.resources.dll +¦ Microsoft.CodeAnalysis.Scripting.resources.dll +¦ ++---Components +¦ ElementTile.axaml +¦ ElementTile.axaml.cs +¦ ++---Converters +¦ GridPositionConverters.cs +¦ SeriesToColorConverter.cs +¦ ++---obj + ¦ project.assets.json + ¦ project.nuget.cache + ¦ Project_Periodensystem.View.csproj.nuget.dgspec.json + ¦ Project_Periodensystem.View.csproj.nuget.g.props + ¦ Project_Periodensystem.View.csproj.nuget.g.targets + ¦ + +---Debug + +---net8.0 + ¦ .NETCoreApp,Version=v8.0.AssemblyAttributes.cs + ¦ apphost.exe + ¦ Project_.29B724C0.Up2Date + ¦ Project_Periodensystem.View.AssemblyInfo.cs + ¦ Project_Periodensystem.View.AssemblyInfoInputs.cache + ¦ Project_Periodensystem.View.assets.cache + ¦ Project_Periodensystem.View.csproj.AssemblyReference.cache + ¦ Project_Periodensystem.View.csproj.CoreCompileInputs.cache + ¦ Project_Periodensystem.View.csproj.FileListAbsolute.txt + ¦ Project_Periodensystem.View.dll + ¦ Project_Periodensystem.View.GeneratedMSBuildEditorConfig.editorconfig + ¦ Project_Periodensystem.View.genruntimeconfig.cache + ¦ Project_Periodensystem.View.pdb + ¦ + +---Avalonia + ¦ original.dll + ¦ original.pdb + ¦ original.ref.dll + ¦ references + ¦ resources + ¦ Resources.Inputs.cache + ¦ + +---ref + ¦ Project_Periodensystem.View.dll + ¦ + +---refint + Project_Periodensystem.View.dll + diff --git a/project_structure.txt b/project_structure.txt deleted file mode 100644 index 07cdb23..0000000 Binary files a/project_structure.txt and /dev/null differ