Files
Kanalsanierungsverwaltung/SanSystem/BüroExporter.cs
Husky cdde5f5004 Büroexporter geschrieben
Bug behoben, falls der Ordner von K2000 nicht excistiert
2021-07-04 18:40:30 +02:00

84 lines
3.4 KiB
C#

using KlassenBIB;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SanSystem
{
static class BüroExporter
{
private static int getNextFotoNumber(string destinationPath,string fotoname)
{
IEnumerable<string> Content = Directory.EnumerateFiles(destinationPath,fotoname);
return Content.Count() + 1;
}
public static Task ExportAsync(Projekt projekt, string destinationPath = "./")
{
return Task.Factory.StartNew(() =>
{
destinationPath = Path.Combine(destinationPath, "EXPORT");
foreach (Inspektionsobjekt d in projekt.Objekte)
{
KlassenBIB.Collections.Sanierung sanierungsliste = d.Sanierung;
if (sanierungsliste.Count < 1) continue;
string tempPath = Path.Combine(destinationPath, "ID" + d.Sanierungsnummer);
if (Directory.Exists(tempPath))
{
try
{
Directory.Delete(tempPath, true);
}
catch (UnauthorizedAccessException)
{
}
}
Directory.CreateDirectory(tempPath);
foreach (Sanierung san in sanierungsliste)
{
if (san is KlassenBIB.InlinerSanierung)
{
// PDF
string sourceDirectory = Path.Combine(Global.Instance.Projektpfad, "Einbauprotokolle", d.Objektbezeichnung + ".pdf");
if (!File.Exists(sourceDirectory))
{
MessageBox.Show("Bitte Bericht erzeugen", "Haltung " + d.Objektbezeichnung + " noch nicht erstellt");
}
else
{
File.Copy(sourceDirectory, tempPath + "/" + d.Objektbezeichnung + ".pdf");
}
}
else if (san is KlassenBIB.SchachtAnbindung)
{
string sourceDirectory = san.CheckVerzeichnisse(Global.Instance.Projektpfad);
SchachtAnbindung fotoDokumentation = (san as SchachtAnbindung);
KlassenBIB.Collections.Bilder fotos = fotoDokumentation.SavedBilders;
foreach (SavedBilder foto in fotos)
{
// Prüfen welche der nächste Freie nummer ist
// Bildname_X, wobei X eine zahl der erhöht wird, angefangen bei 1
int freeFotoNumber = getNextFotoNumber(tempPath, d.Objektbezeichnung + "*.jpg");
string destinationName = string.Format("{0}_{1:d3}.jpg", d.Objektbezeichnung, freeFotoNumber); // 0 ist der Index, d3 => 3 Decimalstellen
File.Copy(foto.Speicherpfad, Path.Combine(tempPath, destinationName));
}
}
}
}
});
}
}
}