using System; using System.Drawing; using System.IO; using System.Text.Json; public class UserSettingsManager { public string DruckerSWS { get; set; } = ""; public string DruckerEtikett { get; set; } = ""; public decimal CopiesSWS { get; set; } = 0; public Color Hintergrund { get; set; } = Color.Black; public Color Beladeband { get; set; } = Color.Yellow; public Color Waschstrasse { get; set; } = Color.White; public Color Presse { get; set; } = Color.Red; public Color Hubband { get; set; } = Color.LightBlue; public Color Trockner { get; set; } = Color.Green; public Color Entladeband { get; set; } = Color.Violet; public Point LocationGroupBox { get; set; } = new Point(0, 0); public Point LocationButtonNeuerUser { get; set; } = new Point(0, 0); public Point LocationButtonNeuerAuftrag { get; set; } = new Point(0, 0); //TODO: UserSetting Properties eintragen und in EinstellungsScreen abrufen. private readonly string _configPath; public UserSettingsManager() { _configPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Kilian Wirl GmbH", "Verwaltung", "settings.json"); } public void Load() { try { if (File.Exists(_configPath)) { string json = File.ReadAllText(_configPath); var loadedSettings = JsonSerializer.Deserialize(json); if (loadedSettings != null) { DruckerSWS = loadedSettings.DruckerSWS; DruckerEtikett = loadedSettings.DruckerEtikett; CopiesSWS = loadedSettings.CopiesSWS; Hintergrund = loadedSettings.Hintergrund; Beladeband = loadedSettings.Beladeband; Waschstrasse = loadedSettings.Waschstrasse; Presse = loadedSettings.Presse; Hubband = loadedSettings.Hubband; Trockner = loadedSettings.Trockner; Entladeband = loadedSettings.Entladeband; LocationGroupBox = loadedSettings.LocationGroupBox; LocationButtonNeuerUser = loadedSettings.LocationButtonNeuerUser; LocationButtonNeuerAuftrag = loadedSettings.LocationButtonNeuerAuftrag; // Weitere Properties hier zuweisen //TODO: Weitere Properties von oben hier zuweisen } } } catch { /* Alte Datei kaputt → Defaults */ } } public void Save() { try { Directory.CreateDirectory(Path.GetDirectoryName(_configPath)); string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(_configPath, json); } catch (Exception ex) { // Fallback: LocalAppData string fallbackPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Kilian Wirl GmbH", "Verwaltung", "settings.json"); Directory.CreateDirectory(Path.GetDirectoryName(fallbackPath)); string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(fallbackPath, json); } } }