[file:] better folder structuring
This commit is contained in:
209
DataStore/DataStructures.cs
Normal file
209
DataStore/DataStructures.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Logof_Client;
|
||||
|
||||
public class KasAddressList //Address-Set
|
||||
{
|
||||
//public List<KasPersonError> errors = new();
|
||||
public List<KasPerson> KasPersons;
|
||||
|
||||
public KasAddressList(string name)
|
||||
{
|
||||
KasPersons = new List<KasPerson>();
|
||||
Name = name;
|
||||
foreach (var set in Settings._instance.addressSets.addresses)
|
||||
if (Name == set.Name)
|
||||
Name = name + "-new";
|
||||
|
||||
var highest = 0;
|
||||
foreach (var k in Settings._instance.addressSets.addresses)
|
||||
if (highest <= k.ID)
|
||||
highest = k.ID + 1;
|
||||
ID = highest;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = "Neues Address-Set";
|
||||
public int owner_id { get; set; }
|
||||
public int ID { get; }
|
||||
|
||||
public void SetOwner(int owner_id)
|
||||
{
|
||||
this.owner_id = owner_id;
|
||||
}
|
||||
|
||||
public static string GenerateName(string basic_type, bool? is_rest = false)
|
||||
{
|
||||
if (is_rest == true)
|
||||
return basic_type + " - " + DateTime.Now.ToShortDateString() + " - Rest";
|
||||
return basic_type + " - " + DateTime.Now.ToShortDateString();
|
||||
}
|
||||
|
||||
// public void UpdateErrorList(List<KasPersonError> errorList)
|
||||
// {
|
||||
// //errors.Clear();
|
||||
// // foreach (KasPersonError err in errorList)
|
||||
// // {
|
||||
// //
|
||||
// // }
|
||||
// //foreach (var error in errorList) errors.Add(new KasPersonError(error));
|
||||
// }
|
||||
|
||||
public static int GetIDByAddressSetListItem(string listItemName)
|
||||
{
|
||||
var id = listItemName.Split(" - ")[0];
|
||||
return int.Parse(id);
|
||||
}
|
||||
}
|
||||
|
||||
public class KasPerson
|
||||
{
|
||||
public KasPersonError PersonError = null;
|
||||
|
||||
public KasPerson()
|
||||
{
|
||||
id = GenerateNewID(0);
|
||||
refsid = 0;
|
||||
anrede = "";
|
||||
titel = "";
|
||||
vorname = "";
|
||||
adel = "";
|
||||
name = "";
|
||||
namezus = "";
|
||||
anredzus = "";
|
||||
strasse = "";
|
||||
strasse2 = "";
|
||||
plz = "";
|
||||
ort = "";
|
||||
land = "";
|
||||
pplz = "";
|
||||
postfach = "";
|
||||
name1 = "";
|
||||
name2 = "";
|
||||
name3 = "";
|
||||
name4 = "";
|
||||
name5 = "";
|
||||
funktion = "";
|
||||
funktion2 = "";
|
||||
abteilung = "";
|
||||
funktionad = "";
|
||||
}
|
||||
|
||||
public KasPerson(int id, int refsid,
|
||||
string anrede,
|
||||
string titel,
|
||||
string vorname,
|
||||
string adel,
|
||||
string name,
|
||||
string namezus,
|
||||
string anredzus,
|
||||
string strasse,
|
||||
string strasse2,
|
||||
string plz,
|
||||
string ort,
|
||||
string land,
|
||||
string pplz,
|
||||
string postfach,
|
||||
string name1,
|
||||
string name2,
|
||||
string name3,
|
||||
string name4,
|
||||
string name5,
|
||||
string funktion, // ignorieren
|
||||
string funktion2, // ignorieren
|
||||
string abteilung,
|
||||
string funktionad)
|
||||
{
|
||||
this.id = id;
|
||||
this.refsid = refsid;
|
||||
this.anrede = anrede;
|
||||
this.titel = titel;
|
||||
this.vorname = vorname;
|
||||
this.adel = adel;
|
||||
this.name = name;
|
||||
this.namezus = namezus;
|
||||
this.anredzus = anredzus;
|
||||
this.strasse = strasse;
|
||||
this.strasse2 = strasse2;
|
||||
this.plz = plz;
|
||||
this.ort = ort;
|
||||
this.land = land;
|
||||
this.pplz = pplz;
|
||||
this.postfach = postfach;
|
||||
this.name1 = name1;
|
||||
this.name2 = name2;
|
||||
this.name3 = name3;
|
||||
this.name4 = name4;
|
||||
this.name5 = name5;
|
||||
this.funktion = funktion;
|
||||
this.funktion2 = funktion2;
|
||||
this.abteilung = abteilung;
|
||||
this.funktionad = funktionad;
|
||||
}
|
||||
|
||||
public int id { get; set; }
|
||||
public int refsid { get; set; }
|
||||
public string anrede { get; set; }
|
||||
public string titel { get; set; }
|
||||
public string vorname { get; set; }
|
||||
public string adel { get; set; }
|
||||
public string name { get; set; }
|
||||
public string namezus { get; set; }
|
||||
public string anredzus { get; set; }
|
||||
public string strasse { get; set; }
|
||||
public string strasse2 { get; set; }
|
||||
public string plz { get; set; }
|
||||
public string ort { get; set; }
|
||||
public string land { get; set; }
|
||||
public string pplz { get; set; }
|
||||
public string postfach { get; set; }
|
||||
public string name1 { get; set; }
|
||||
public string name2 { get; set; }
|
||||
public string name3 { get; set; }
|
||||
public string name4 { get; set; }
|
||||
public string name5 { get; set; }
|
||||
public string funktion { get; set; }
|
||||
public string funktion2 { get; set; }
|
||||
public string abteilung { get; set; }
|
||||
public string funktionad { get; set; }
|
||||
|
||||
public static int GenerateNewID(int base_id)
|
||||
{
|
||||
//var newid = 100000 + base_id;
|
||||
int highest = 0;
|
||||
foreach (var set in Settings._instance.addressSets.addresses)
|
||||
{
|
||||
foreach (var add in set.KasPersons)
|
||||
{
|
||||
if(add.id >= highest) highest = add.id+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return highest + base_id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public class KasPersonError
|
||||
{
|
||||
public KasPersonError((List<AddressCheck.ErrorTypes>, List<AddressCheck.WarningTypes>) single_result)
|
||||
{
|
||||
//refsid = single_result.Item1;
|
||||
errors = single_result.Item1;
|
||||
warnings = single_result.Item2;
|
||||
}
|
||||
|
||||
//public int refsid { get; set; }
|
||||
public List<AddressCheck.ErrorTypes> errors { get; set; } = new();
|
||||
public List<AddressCheck.WarningTypes> warnings { get; set; } = new();
|
||||
|
||||
public string GetString()
|
||||
{
|
||||
var output = "";
|
||||
foreach (var error in errors) output += error + ", ";
|
||||
|
||||
foreach (var warning in warnings) output += warning + ", ";
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
194
DataStore/Settings.cs
Normal file
194
DataStore/Settings.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
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; } = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"logofclient",
|
||||
"config.json");
|
||||
|
||||
public string wiki_storage_path { get; set; } = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"logofclient",
|
||||
"wiki");
|
||||
|
||||
public List<Country> countries { get; set; } = new();
|
||||
public string font_path { get; set; } = Path.Combine(AppContext.BaseDirectory, "assets", "fonts");
|
||||
|
||||
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 string sender_address { 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();
|
||||
|
||||
public KasAddressList GetAddressSetByID(int ID)
|
||||
{
|
||||
foreach (var i in addresses)
|
||||
if (i.ID == ID)
|
||||
return i;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Country
|
||||
{
|
||||
public Country(string name, string translation, List<string> alternatives)
|
||||
{
|
||||
this.name = name;
|
||||
this.translation = translation;
|
||||
this.alternatives = alternatives;
|
||||
}
|
||||
|
||||
public Country(string name)
|
||||
{
|
||||
this.name = name;
|
||||
translation = "";
|
||||
alternatives = new List<string>();
|
||||
}
|
||||
|
||||
public Country()
|
||||
{
|
||||
}
|
||||
|
||||
public string? name { get; set; }
|
||||
public string translation { get; set; }
|
||||
public List<string> alternatives { get; set; }
|
||||
|
||||
public static Country GetByName(string name)
|
||||
{
|
||||
foreach (var country in Global._instance.countries)
|
||||
if (country.name == name)
|
||||
return country;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user