138 lines
4.2 KiB
C#
138 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Logof_Client;
|
|
|
|
public class Settings
|
|
{
|
|
public static Settings _instance = new();
|
|
public AddressSets addressSets = new();
|
|
public Customers customers = new();
|
|
|
|
public string settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"logofclient", "config.json");
|
|
|
|
public Settings()
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
|
|
public static void Save()
|
|
{
|
|
if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"logofclient")))
|
|
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"logofclient"));
|
|
if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path;
|
|
|
|
var json = JsonConvert.SerializeObject(_instance);
|
|
File.WriteAllText(_instance.settingsPath, json);
|
|
}
|
|
|
|
public static void Load()
|
|
{
|
|
if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path;
|
|
|
|
try
|
|
{
|
|
var contents = File.ReadAllText(_instance.settingsPath);
|
|
_instance = JsonConvert.DeserializeObject<Settings>(contents);
|
|
MainWindow._instance.RefreshCustomerItems();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
Console.WriteLine(ex.StackTrace);
|
|
Console.WriteLine("Error while reading settings. Generating new...");
|
|
_instance = new Settings();
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Global
|
|
{
|
|
public static Global _instance;
|
|
|
|
public Global()
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
public string config_path { get; set; } = "";
|
|
|
|
public static void Save()
|
|
{
|
|
if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"logofclient")))
|
|
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
|
"logofclient"));
|
|
var json = JsonConvert.SerializeObject(_instance, Formatting.Indented);
|
|
File.WriteAllText(
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
|
"global.config"), json);
|
|
}
|
|
|
|
public static void Load()
|
|
{
|
|
// if (!File.Exists(Path.Combine(
|
|
// Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
|
// "global.config")))
|
|
// File.Create(Path.Combine(
|
|
// Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
|
// "global.config"));
|
|
try
|
|
{
|
|
var contents = File.ReadAllText(Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
|
"global.config"));
|
|
_instance = JsonConvert.DeserializeObject<Global>(contents);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
Console.WriteLine(ex.StackTrace);
|
|
Console.WriteLine("Error while reading global settings. Generating new...");
|
|
_instance = new Global();
|
|
Save();
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Customers
|
|
{
|
|
public List<Customer> customers = new();
|
|
public int current { get; set; } = 0;
|
|
}
|
|
|
|
public class Customer
|
|
{
|
|
public Customer()
|
|
{
|
|
var highestID = 0;
|
|
foreach (var customer in Settings._instance.customers.customers)
|
|
if (customer.ID > highestID)
|
|
highestID = customer.ID;
|
|
|
|
ID = highestID + 1;
|
|
}
|
|
|
|
public string name { get; set; } = "";
|
|
public string description { get; set; } = "";
|
|
public AddressPatch patch { get; set; }
|
|
public char separator { get; set; } = ',';
|
|
public int ID { get; }
|
|
|
|
public static int GetIDByCustomerListItem(string item_content)
|
|
{
|
|
var id = item_content.Split(" - ")[0];
|
|
return int.Parse(id);
|
|
}
|
|
}
|
|
|
|
public class AddressSets
|
|
{
|
|
public List<KasAddressList> addresses = new();
|
|
} |