WIP Software anpassen

This commit is contained in:
HuskyTeufel
2020-07-03 11:54:10 +02:00
parent 79256c17e8
commit a961767fdd
5 changed files with 39 additions and 117 deletions

View File

@@ -52,12 +52,15 @@ namespace Database
} }
private string projektpfad = string.Empty; private string projektpfad = string.Empty;
public bool LoadProjekt(string projekt, string projektpfad) public bool LoadProjekt(string projekt)
{ {
this.projekt = projekt; this.projekt = projekt;
loadedProjekt = Datenbank.Instance.TeufelDB.Projekte.Find(x => x.Nummer != null && x.Nummer.Equals(projekt));
//Debugger.Break();
//UnPackProject("18-850","willyteufelchen"); //UnPackProject("18-850","willyteufelchen");
//PackSystem("./projekte/18-850.zip", "./projekte/18-850","willyteufelchen"); //PackSystem("./projekte/18-850.zip", "./projekte/18-850","willyteufelchen");
/*
string filepath = Path.Combine(projektpfad, string.Format("{0}.xaml", projekt)); string filepath = Path.Combine(projektpfad, string.Format("{0}.xaml", projekt));
this.projektpfad = filepath; this.projektpfad = filepath;
if (File.Exists(filepath)) if (File.Exists(filepath))
@@ -77,10 +80,15 @@ namespace Database
else else
loadedProjekt = new KlassenBIB.Projekt(); loadedProjekt = new KlassenBIB.Projekt();
UpdateDatabase.UpdateNewGuids(); */
UpdateDatabase.TransferAuftraggeber(); if (!File.Exists("./projekte/TeufelDB.xaml"))
UpdateDatabase.MakeNewDatabaseSystem(); {
UpdateDatabase.TransferSanierteObjekte(); UpdateDatabase.UpdateNewGuids();
UpdateDatabase.TransferSanierteObjekte();
UpdateDatabase.TransferAuftraggeber();
UpdateDatabase.MakeNewDatabaseSystem();
}
return true; return true;
} }
@@ -92,108 +100,6 @@ namespace Database
return true; return true;
} }
private void UnPackProject(string projekt, string password = "")
{
if (!Directory.Exists("./temp")) Directory.CreateDirectory("./temp");
ZipFile zf = null;
try
{
FileStream fs = File.OpenRead(Path.Combine("projekte", string.Format("{0}.zip", projekt)));
zf = new ZipFile(fs);
if (!password.Equals("")) zf.Password = password;
foreach(ZipEntry zipEntry in zf)
{
if (!zipEntry.IsFile) continue;
string entryFileName = zipEntry.Name;
byte[] buffer = new byte[4096];
Stream zipStream = zf.GetInputStream(zipEntry);
string fullZipToPath = Path.Combine("./temp/", entryFileName);
string directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0) Directory.CreateDirectory(directoryName);
using (FileStream streamWriter = File.Create(fullZipToPath))
{
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
finally
{
if(zf != null)
{
zf.IsStreamOwner = true;
zf.Close();
}
}
}
public bool CreateProjekt(string projektnummer)
{
string filepath = Path.Combine(pfad, projektnummer);
if (File.Exists(filepath)) return false;
using (MemoryStream memoryStream = new MemoryStream())
{
using (ZipArchive archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
var demoFile = archive.CreateEntry("daten/foo.txt");
using (var entryStream = demoFile.Open())
{
XamlServices.Save(entryStream, loadedProjekt);
}
}
using (var fileStream = new FileStream("./test.zip", FileMode.Create))
{
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(fileStream);
}
}
return true;
}
private void PackSystem(string outPathName, string folderName, string password = "")
{
FileStream fsOut = File.Create(outPathName);
ZipOutputStream zipStream = new ZipOutputStream(fsOut);
zipStream.SetLevel(3);
if (!password.Equals("")) zipStream.Password = password;
int folderOffset = folderName.Length +(folderName.EndsWith("\\") ? 0 : 1);
CompressFolder(folderName, zipStream, folderOffset);
zipStream.IsStreamOwner = true;
zipStream.Close();
}
private void CompressFolder(string path, ZipOutputStream zipStream, int folderOffset)
{
string[] files = Directory.GetFiles(path);
foreach(string filename in files)
{
FileInfo fi = new FileInfo(filename);
string entryName = filename.Substring(folderOffset);
entryName = ZipEntry.CleanName(entryName);
ZipEntry newEntry = new ZipEntry(entryName);
newEntry.DateTime = fi.LastWriteTime;
newEntry.Size = fi.Length;
zipStream.PutNextEntry(newEntry);
byte[] buffer = new byte[4096];
using (FileStream streamReader = File.OpenRead(filename))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
string[] folders = Directory.GetDirectories(path);
foreach(string folder in folders)
{
CompressFolder(folder, zipStream, folderOffset);
}
}
public void Test() public void Test()
{ {
@@ -218,8 +124,8 @@ namespace Database
public void SaveProjekt() public void SaveProjekt()
{ {
XamlServices.Save("./projekte/MainDatenbank.xaml", MainDatenbank); //XamlServices.Save("./projekte/MainDatenbank.xaml", MainDatenbank);
XamlServices.Save(projektpfad, loadedProjekt); //XamlServices.Save(projektpfad, loadedProjekt);
XamlServices.Save("./projekte/TeufelDB.xaml", TeufelDB); XamlServices.Save("./projekte/TeufelDB.xaml", TeufelDB);
} }
} }

View File

@@ -151,7 +151,7 @@ namespace Database
} }
} }
} }
Debugger.Break(); //Debugger.Break();
} }
public static void TransferAuftraggeber() public static void TransferAuftraggeber()

View File

@@ -95,7 +95,7 @@ namespace SanSystem
string pfad = Path.Combine(Projektpfad); string pfad = Path.Combine(Projektpfad);
if (!Directory.Exists(pfad)) Directory.CreateDirectory(pfad); if (!Directory.Exists(pfad)) Directory.CreateDirectory(pfad);
Database.Datenbank.Instance.LoadProjekt(ProjektNummer, Projektpfad); Database.Datenbank.Instance.LoadProjekt(ProjektNummer);
} }
void LadeRegistry() void LadeRegistry()

View File

@@ -36,7 +36,7 @@ namespace SanSystem
if (!Directory.Exists(Global.Instance.Projektpfad)) Directory.CreateDirectory(Global.Instance.Projektpfad); if (!Directory.Exists(Global.Instance.Projektpfad)) Directory.CreateDirectory(Global.Instance.Projektpfad);
try try
{ {
Datenbank.Instance.LoadProjekt(Global.Instance.ProjektNummer, Global.Instance.Projektpfad);// Path.Combine(Global.Instance.Projektpfad,"18-850.xaml")); Datenbank.Instance.LoadProjekt(Global.Instance.ProjektNummer);// Path.Combine(Global.Instance.Projektpfad,"18-850.xaml"));
} }
catch(DataBaseVersionMismatchException ex) catch(DataBaseVersionMismatchException ex)
{ {

View File

@@ -1,7 +1,10 @@
using System; using Database;
using KlassenBIB;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -27,9 +30,21 @@ namespace SanSystem
private void frmProjektList_Load(object sender, EventArgs e) private void frmProjektList_Load(object sender, EventArgs e)
{ {
foreach(DirectoryInfo projekte in (new DirectoryInfo("./projekte").GetDirectories())) foreach(Projekt projekt in Datenbank.Instance.TeufelDB.Projekte)
{ {
lb_projekte.Items.Add(projekte.Name); if (projekt.Nummer == null)
{
Datenbank.Instance.TeufelDB.Projekte.Remove(projekt);
if(Debugger.IsAttached)
{
Debugger.Break();
}
else
{
continue;
}
}
lb_projekte.Items.Add(projekt.Nummer);
} }
} }
@@ -37,13 +52,14 @@ namespace SanSystem
{ {
string projekt = (string)lb_projekte.SelectedItem; string projekt = (string)lb_projekte.SelectedItem;
if (projekt == null) return; if (projekt == null) return;
/*
if(Database.Datenbank.Instance.projekt != projekt) if(Database.Datenbank.Instance.projekt != projekt)
{ {
Database.Datenbank.Instance.SaveProjekt(); Database.Datenbank.Instance.SaveProjekt();
Global.Instance.ProjektNummer = projekt; Global.Instance.ProjektNummer = projekt;
Database.Datenbank.Instance.LoadProjekt(projekt, Global.Instance.Projektpfad); Database.Datenbank.Instance.LoadProjekt(projekt);
} }
*/
this.Close(); this.Close();
} }
} }