133 lines
5.4 KiB
C#
133 lines
5.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Models;
|
|
using ProtokollWriterContract;
|
|
using System.Diagnostics;
|
|
|
|
namespace ProtokollWriter {
|
|
/// Erstellt eine Städtler und Beck Dichtheitsprüfdatei
|
|
public class SBTextFileWriter : IProtokollWriter
|
|
{
|
|
string[] content;
|
|
ArrayList newFile = new ArrayList();
|
|
int prüfungsnummer = 0;
|
|
string targetFile;
|
|
Inspektionsobjekt inspObjekt;
|
|
|
|
Hashtable hashtable = new Hashtable() {
|
|
{"DATUM",""},
|
|
{"PROJEKTNR","" },
|
|
{"PRUEFNR","" },
|
|
{"AUFTRAGGEBER_NAME","" },
|
|
{"AUFTRAGGEBER_STRASSE","" },
|
|
{"AUFTRAGGEBER_ORT","" },
|
|
{"AUFTRAGGEBER_TEL","" },
|
|
{"BAUVORHABEN_STRASSE","" },
|
|
{"BAUVORHABEN_ORT","" },
|
|
{"BAUVORHABEN_STANDORT","" },
|
|
{"MESSDATEI","" },
|
|
{"DN","" },
|
|
{"LAENGE","" },
|
|
{"VOLUMEN","" },
|
|
{"HALTUNGNR","" },
|
|
{"VONSCHACHT","" },
|
|
{"BISSCHACHT","" },
|
|
{"PRUEFRESULTAT","" },
|
|
{"BEMERKUNG","" }
|
|
};
|
|
|
|
|
|
public void WriteProtokoll(Inspektionsobjekt inspektionsobjekt, uint prüfungsnummer)
|
|
{
|
|
inspObjekt = inspektionsobjekt;
|
|
this.prüfungsnummer = (int)prüfungsnummer;
|
|
this.targetFile = string.Format("{0}_{1}.txt",inspObjekt.Objektname,inspObjekt.UntereSchacht);
|
|
Ersetzen();
|
|
ReadVorlage();
|
|
WriteFile();
|
|
}
|
|
|
|
void ReadVorlage() {
|
|
content = File.ReadAllLines("./vorlage.txt",Encoding.Default);
|
|
|
|
}
|
|
|
|
string getPrüfnummer() {
|
|
return "";
|
|
//string[] pruefung = inspObjekt.PressureTests[prüfungsnummer].prüfdatum.Split('.');
|
|
//return string.Format("{0}{1}{2}-{3}", pruefung[2], pruefung[1], pruefung[0],prüfungsnummer);
|
|
}
|
|
|
|
double getPruefVolumen() {
|
|
double durchmesser = ((double)inspObjekt.Durchmesser / 2)/1000;
|
|
double laenge = (double)inspObjekt.ObjektLänge;
|
|
double Volumen = Math.PI * (durchmesser * durchmesser) * laenge;
|
|
Volumen = Math.Round(Volumen, 3);
|
|
return Volumen;
|
|
}
|
|
|
|
void Ersetzen() {
|
|
hashtable["DATUM"] = "heute";//inspObjekt.PressureTests[prüfungsnummer].prüfdatum;
|
|
hashtable["PRUEFNR"] = getPrüfnummer();
|
|
hashtable["DN"] = inspObjekt.Durchmesser;
|
|
hashtable["LAENGE"] = inspObjekt.ObjektLänge;
|
|
hashtable["VOLUMEN"] = getPruefVolumen();
|
|
hashtable["AUFTRAGGEBER_NAME"] = inspObjekt.Bauvorhaben.Auftraggeber.Name;
|
|
hashtable["AUFTRAGGEBER_STRASSE"] = inspObjekt.Bauvorhaben.Auftraggeber.Strasse;
|
|
hashtable["AUFTRAGGEBER_ORT"] = inspObjekt.Bauvorhaben.Auftraggeber.Ort;
|
|
hashtable["AUFTRAGGEBER_TEL"] = inspObjekt.Bauvorhaben.Auftraggeber.Tel;
|
|
hashtable["VONSCHACHT"] = inspObjekt.ObereSchacht;
|
|
hashtable["BISSCHACHT"] = inspObjekt.UntereSchacht;
|
|
hashtable["PROJEKTNR"] = "000";//Projektnummer;
|
|
hashtable["HALTUNGNR"] = inspObjekt.Objektname != null ? inspObjekt.Objektname : inspObjekt.ObereSchacht;
|
|
hashtable["MESSDATEI"] = inspObjekt.Objektname != null ? inspObjekt.Objektname : inspObjekt.ObereSchacht;
|
|
hashtable["BAUVORHABEN_STRASSE"] = inspObjekt.Bauvorhaben.Strasse;
|
|
hashtable["BAUVORHABEN_ORT"] = inspObjekt.Bauvorhaben.Ort;
|
|
hashtable["BAUVORHABEN_STANDORT"] = inspObjekt.Bauvorhaben.Strasse;
|
|
hashtable["BEMERKUNG"] = inspObjekt.Bemerkung;
|
|
hashtable["PRUEFRESULTAT"] = "Cool";//inspObjekt.PressureTests[prüfungsnummer].Bestanden ? "Prüfung Bestanden" : "Prüfung N I C H T Bestanden";
|
|
}
|
|
void WriteFile() {
|
|
string zeile;
|
|
for(int i = 0; i < content.Length; i++) {
|
|
zeile = content[i];
|
|
if(zeile.Contains("{")) {
|
|
int start = zeile.IndexOf("{");
|
|
int ende = zeile.IndexOf("}");
|
|
string cmd = zeile.Substring(start+1,(ende-start) -1);
|
|
|
|
if(hashtable.ContainsKey(cmd)) {
|
|
string rep = "{"+cmd+"}";
|
|
string n = zeile.Replace(rep,hashtable[cmd].ToString());
|
|
zeile = n;
|
|
} else {
|
|
if(cmd.StartsWith("@")) {
|
|
string n = "";
|
|
|
|
//foreach(MeasureData data in inspObjekt.PressureTests[prüfungsnummer].Measuredatas) {
|
|
// n = string.Format("{0}{1} = {2};{3};{4};{5}\r\n",n,data.EintragID,data.EintragID+2,data.Datum,data.Pressure,data.MeasureType);
|
|
//}
|
|
zeile = n;
|
|
}
|
|
}
|
|
}
|
|
newFile.Add(zeile);
|
|
}
|
|
File.WriteAllLines(targetFile,FileConverter(newFile),Encoding.Default);
|
|
}
|
|
string[] FileConverter(ArrayList content) {
|
|
string[] result = new string[content.Count];
|
|
int counter = 0;
|
|
foreach(var x in content) {
|
|
string c = (string)x;
|
|
result[counter] = c;
|
|
counter++;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|