109 lines
4.1 KiB
C#
109 lines
4.1 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
public class UserSettingsManager
|
|
{
|
|
#region Speicher-Properties
|
|
public string DruckerSWS { get; set; } = "";
|
|
public string DruckerEtikett { get; set; } = "";
|
|
public string DruckerTourenListe { 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 LocationGroupBoxStatistik { get; set; } = new Point(0, 0);
|
|
public Point LocationGroupBoxSaison { get; set; } = new Point(0, 0);
|
|
public Point LocationGroupBoxContainer { get; set; } = new Point(0, 0);
|
|
public Point LocationButtonNeuerUser { get; set; } = new Point(0, 0);
|
|
public Point LocationButtonNeuerAuftrag { get; set; } = new Point(0, 0);
|
|
public Point LocationButtonNeueInventur { get; set; } = new Point(0, 0);
|
|
public Point LocationButtonNeuerStand { get; set; } = new Point(0, 0);
|
|
public Point LocationButtonNeueAufgabe { get; set; } = new Point(0, 0);
|
|
public Byte[] OLV_State { get; set; }
|
|
//TODO: UserSetting Properties eintragen und in EinstellungsScreen abrufen.
|
|
|
|
|
|
#endregion
|
|
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<UserSettingsManager>(json);
|
|
if (loadedSettings != null)
|
|
{
|
|
DruckerSWS = loadedSettings.DruckerSWS;
|
|
DruckerEtikett = loadedSettings.DruckerEtikett;
|
|
DruckerTourenListe = loadedSettings.DruckerTourenListe;
|
|
CopiesSWS = loadedSettings.CopiesSWS;
|
|
Hintergrund = loadedSettings.Hintergrund;
|
|
Beladeband = loadedSettings.Beladeband;
|
|
Waschstrasse = loadedSettings.Waschstrasse;
|
|
Presse = loadedSettings.Presse;
|
|
Hubband = loadedSettings.Hubband;
|
|
Trockner = loadedSettings.Trockner;
|
|
Entladeband = loadedSettings.Entladeband;
|
|
LocationGroupBoxStatistik = loadedSettings.LocationGroupBoxStatistik;
|
|
LocationGroupBoxSaison = loadedSettings.LocationGroupBoxSaison;
|
|
LocationGroupBoxContainer = loadedSettings.LocationGroupBoxContainer;
|
|
LocationButtonNeuerUser = loadedSettings.LocationButtonNeuerUser;
|
|
LocationButtonNeuerAuftrag = loadedSettings.LocationButtonNeuerAuftrag;
|
|
LocationButtonNeueInventur = loadedSettings.LocationButtonNeueInventur;
|
|
LocationButtonNeuerStand = loadedSettings.LocationButtonNeuerStand;
|
|
LocationButtonNeueAufgabe = loadedSettings.LocationButtonNeueAufgabe;
|
|
|
|
OLV_State = loadedSettings.OLV_State;
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
|