91 lines
2.6 KiB
C#
91 lines
2.6 KiB
C#
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 ICSharpCode.SharpZipLib.Zip;
|
|
using ICSharpCode.SharpZipLib.Core;
|
|
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))
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|