KlassenDLL im Main integriert
This commit is contained in:
89
SanSystem/Database/Datenbank.cs
Normal file
89
SanSystem/Database/Datenbank.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xaml;
|
||||
using System.IO.Compression;
|
||||
using System.Diagnostics;
|
||||
using KlassenBIB;
|
||||
using SanShared.Exceptions;
|
||||
|
||||
namespace Database
|
||||
{
|
||||
public class Datenbank
|
||||
{
|
||||
public string pfad;
|
||||
public string projekt;
|
||||
public static readonly Datenbank instance = new Datenbank();
|
||||
public static Datenbank Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
TeufelDB = new KlassenBIB.DB();
|
||||
string filepath = "";
|
||||
filepath = Path.Combine(pfad, "projekte", "TeufelDB.xaml");
|
||||
|
||||
if(!Directory.Exists(Path.Combine(pfad,"projekte")))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(pfad, "projekte"));
|
||||
return;
|
||||
}
|
||||
if (File.Exists(filepath))
|
||||
TeufelDB = XamlServices.Load(filepath) as KlassenBIB.DB;
|
||||
}
|
||||
|
||||
public KlassenBIB.Projekt loadedProjekt = null;
|
||||
//public KlassenBIB.MainDataBase MainDatenbank = null;
|
||||
public KlassenBIB.DB TeufelDB = null;
|
||||
|
||||
public Datenbank()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private string projektpfad = string.Empty;
|
||||
public bool LoadProjekt(string projekt)
|
||||
{
|
||||
this.projekt = projekt;
|
||||
loadedProjekt = Datenbank.Instance.TeufelDB.Projekte.Find(x => x.Nummer != null && x.Nummer.Equals(projekt));
|
||||
|
||||
string filepath = Path.Combine(pfad, "projekte", "TeufelDB.xaml");
|
||||
if (!File.Exists(filepath))
|
||||
{
|
||||
if (!Directory.Exists("./projekte")) return true;
|
||||
UpdateDatabase.UpdateNewGuids();
|
||||
|
||||
UpdateDatabase.TransferAuftraggeber();
|
||||
UpdateDatabase.MakeNewDatabaseSystem();
|
||||
} else
|
||||
{
|
||||
//UpdateDatabase.GenerateNewBeziehungen();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InitProjekt(Projekt projekt,string projektpfad)
|
||||
{
|
||||
this.projektpfad = Path.Combine(projektpfad,string.Format("{0}.xaml",projekt.Nummer));
|
||||
loadedProjekt = projekt;
|
||||
SaveProjekt();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SaveProjekt()
|
||||
{
|
||||
string filepath = Path.Combine(pfad, "projekte", "TeufelDB.xaml");
|
||||
Trace.WriteLine(filepath);
|
||||
XamlServices.Save(filepath, TeufelDB);
|
||||
}
|
||||
}
|
||||
}
|
||||
124
SanSystem/Database/UpdateDatabase.cs
Normal file
124
SanSystem/Database/UpdateDatabase.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using KlassenBIB;
|
||||
using SanShared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xaml;
|
||||
|
||||
namespace Database
|
||||
{
|
||||
class UpdateDatabase
|
||||
{
|
||||
public static void UpdateNewGuids()
|
||||
{
|
||||
if (Datenbank.Instance.loadedProjekt == null) return;
|
||||
foreach(var entries in Datenbank.Instance.loadedProjekt.Objekte)
|
||||
{
|
||||
|
||||
if(entries.Guid.Equals(Guid.Empty))
|
||||
entries.Guid = Guid.NewGuid();
|
||||
|
||||
|
||||
foreach(var sanierungen in entries.Sanierung)
|
||||
{
|
||||
if (sanierungen.Guid.Equals(Guid.Empty))
|
||||
sanierungen.Guid = Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void MakeNewDatabaseSystem()
|
||||
{
|
||||
List<string> projekte = new List<string>();
|
||||
|
||||
Projekt tempProjekt = null;
|
||||
foreach (DirectoryInfo projekt in (new DirectoryInfo("./projekte").GetDirectories()))
|
||||
{
|
||||
projekte.Add(projekt.Name);
|
||||
}
|
||||
|
||||
foreach (string t in projekte)
|
||||
{
|
||||
string filepath = Path.Combine("projekte", t, string.Format("{0}.xaml", t));
|
||||
if (!File.Exists(filepath)) continue;
|
||||
tempProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt;
|
||||
Datenbank.Instance.TeufelDB.Projekte.Add(tempProjekt);
|
||||
|
||||
//var x = Datenbank.Instance.MainDatenbank.AuftraggeberListe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void GenerateNewBeziehungen()
|
||||
{
|
||||
string imprägnierungsnummer = "";
|
||||
foreach(Projekt projekt in Datenbank.Instance.TeufelDB.Projekte)
|
||||
{
|
||||
projekt.Auftraggeber = Datenbank.Instance.TeufelDB.Auftraggeber.Find(x => x.Name.Equals(projekt.Auftraggeber.Name));
|
||||
foreach(Inspektionsobjekt inspektionsobjekt in projekt.Objekte)
|
||||
{
|
||||
if(inspektionsobjekt.Sanierung.Count > 0)
|
||||
{
|
||||
foreach(var sanierung in inspektionsobjekt.Sanierung)
|
||||
{
|
||||
if(sanierung is KlassenBIB.InlinerSanierung)
|
||||
{
|
||||
KlassenBIB.InlinerSanierung san = (sanierung as KlassenBIB.InlinerSanierung);
|
||||
if (!(san.Imprägnierungsbericht is KlassenBIB.WerkseitigImprägniert)) continue;
|
||||
KlassenBIB.WerkseitigImprägniert werkseitigImprägniert = (KlassenBIB.WerkseitigImprägniert)san.Imprägnierungsbericht;
|
||||
imprägnierungsnummer = werkseitigImprägniert.Imprägniernummer;
|
||||
//san.Imprägnierungsbericht = null;
|
||||
san.Imprägnierungsbericht = Datenbank.Instance.TeufelDB.Imprägnierungen.Find(x => x.Imprägniernummer.Equals(imprägnierungsnummer));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Debugger.Break();
|
||||
}
|
||||
|
||||
public static void TransferAuftraggeber()
|
||||
{
|
||||
/*
|
||||
List<string> projekte = new List<string>();
|
||||
List<IAuftraggeber> auftraggebers = new List<IAuftraggeber>();
|
||||
Projekt tempProjekt = null;
|
||||
foreach(DirectoryInfo projekt in (new DirectoryInfo("./projekte").GetDirectories()))
|
||||
{
|
||||
projekte.Add(projekt.Name);
|
||||
}
|
||||
|
||||
foreach(string t in projekte)
|
||||
{
|
||||
string filepath = Path.Combine("projekte", t, string.Format("{0}.xaml", t));
|
||||
if (!File.Exists(filepath)) continue;
|
||||
tempProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt;
|
||||
|
||||
//auftraggebers.Add(tempProjekt.Auftraggeber);
|
||||
if (tempProjekt.Auftraggeber.Name == null && tempProjekt.Auftraggeber.Ort == null && tempProjekt.Auftraggeber.Ansprechpartner == null) continue;
|
||||
IAuftraggeber test = Datenbank.Instance.MainDatenbank.AuftraggeberListe.Find(x =>x.Name.Equals(tempProjekt.Auftraggeber.Name));
|
||||
if (test != null)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Datenbank.Instance.MainDatenbank.AuftraggeberListe.Add(tempProjekt.Auftraggeber);
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user