Büroexporter geschrieben

Bug behoben, falls der Ordner von K2000 nicht excistiert
This commit is contained in:
Husky
2021-07-04 18:40:30 +02:00
parent 5e1738d96e
commit cdde5f5004
6 changed files with 250 additions and 12 deletions

View File

@@ -0,0 +1,83 @@
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));
}
}
}
}
});
}
}
}

View File

@@ -116,6 +116,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BüroExporter.cs" />
<Compile Include="Dongle.cs" />
<Compile Include="Einstellungen\ObjecteListSetting.cs" />
<Compile Include="Einstellungen\Settings.cs" />
@@ -520,4 +521,4 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\ILMerge.3.0.41\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ILMerge.3.0.41\build\ILMerge.props'))" />
</Target>
</Project>
</Project>

View File

@@ -63,15 +63,24 @@ namespace SanSystem
if (txt_schachtnummer.Text == "")
{
bool found = false;
foreach(string directory in Directory.EnumerateDirectories(@"C:\K2000w\BILDER"))
try
{
if(directory.Contains(Global.Instance.ProjektNummer))
IEnumerable<string> directories = Directory.EnumerateDirectories(@"C:\K2000w\BILDER");
foreach (string directory in directories)
{
found = true;
openFileDialog.InitialDirectory = directory;
break;
if(directory.Contains(Global.Instance.ProjektNummer))
{
found = true;
openFileDialog.InitialDirectory = directory;
break;
}
}
}
catch(DirectoryNotFoundException)
{
// Do Nothing
}
if(!found)
{
openFileDialog.InitialDirectory = @"C:\K2000w\BILDER";

View File

@@ -49,8 +49,9 @@
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatus_projekt_Label = new System.Windows.Forms.ToolStripStatusLabel();
this.toolstrip_gesamtLiner = new System.Windows.Forms.ToolStripStatusLabel();
this.update = new UpdateLib.Updater();
this.toolstrip_messages = new System.Windows.Forms.ToolStripStatusLabel();
this.update = new UpdateLib.Updater();
this.exportFürBüroErstellenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mainmenu.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -80,7 +81,8 @@
this.öffnenToolStripMenuItem,
this.stammdatenImportierenToolStripMenuItem,
this.auftraggeberToolStripMenuItem,
this.prefixSuffixToolStripMenuItem});
this.prefixSuffixToolStripMenuItem,
this.exportFürBüroErstellenToolStripMenuItem});
this.projektToolStripMenuItem.Name = "projektToolStripMenuItem";
this.projektToolStripMenuItem.Size = new System.Drawing.Size(71, 25);
this.projektToolStripMenuItem.Text = "Projekt";
@@ -201,10 +203,6 @@
this.toolstrip_gesamtLiner.Size = new System.Drawing.Size(111, 17);
this.toolstrip_gesamtLiner.Text = "Insgesammt Einbau";
//
// update
//
this.update.UpdateUrl = "http://home.cosysda.de/sanverwaltung/UpdateInfo.dat";
//
// toolstrip_messages
//
this.toolstrip_messages.Name = "toolstrip_messages";
@@ -212,6 +210,17 @@
this.toolstrip_messages.Size = new System.Drawing.Size(16, 17);
this.toolstrip_messages.Text = "...";
//
// update
//
this.update.UpdateUrl = "http://home.cosysda.de/sanverwaltung/UpdateInfo.dat";
//
// exportFürBüroErstellenToolStripMenuItem
//
this.exportFürBüroErstellenToolStripMenuItem.Name = "exportFürBüroErstellenToolStripMenuItem";
this.exportFürBüroErstellenToolStripMenuItem.Size = new System.Drawing.Size(254, 26);
this.exportFürBüroErstellenToolStripMenuItem.Text = "Export für Büro erstellen";
this.exportFürBüroErstellenToolStripMenuItem.Click += new System.EventHandler(this.exportFürBüroErstellenToolStripMenuItem_Click);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -257,6 +266,7 @@
private System.Windows.Forms.ToolStripMenuItem prefixSuffixToolStripMenuItem;
private UpdateLib.Updater update;
private System.Windows.Forms.ToolStripStatusLabel toolstrip_messages;
private System.Windows.Forms.ToolStripMenuItem exportFürBüroErstellenToolStripMenuItem;
}
}

View File

@@ -362,5 +362,21 @@ namespace SanSystem
FrmPrefixSuffix frmPrefixSuffix = new FrmPrefixSuffix();
frmPrefixSuffix.ShowDialog();
}
private void exportFürBüroErstellenToolStripMenuItem_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog fdb = new FolderBrowserDialog())
{
if(fdb.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(fdb.SelectedPath))
{
OnExportedExecuted(fdb.SelectedPath);
}
}
}
private async void OnExportedExecuted(string destinationPath)
{
await BüroExporter.ExportAsync(Datenbank.Instance.loadedProjekt,destinationPath);
}
}
}