74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System.IO;
|
|
using System.Collections.Generic;
|
|
using XMLParser.Contract;
|
|
using XMLParser.Model;
|
|
using System;
|
|
using System.Text;
|
|
|
|
namespace XMLParser.Functions.ProtokollWriter
|
|
{
|
|
public class HTMLProtkollWriter : IProtokollWriter
|
|
{
|
|
FileStream handle = null;
|
|
Dictionary<ECalculatedResult,string> headertitles = null;
|
|
public HTMLProtkollWriter(Dictionary<ECalculatedResult, string> headertitles)
|
|
{
|
|
handle = File.Create("./data.html");
|
|
this.headertitles = headertitles;
|
|
}
|
|
internal void writeToFile(string content)
|
|
{
|
|
content += Environment.NewLine;
|
|
byte[] bytes = Encoding.UTF8.GetBytes(content);
|
|
handle.Write(bytes,0,bytes.Length);
|
|
handle.Flush();
|
|
}
|
|
|
|
void writeHTMLHeader()
|
|
{
|
|
writeToFile("<html>");
|
|
writeToFile("<head>");
|
|
writeToFile("</head>");
|
|
writeToFile("<body>");
|
|
}
|
|
|
|
void writeHTMLFooter()
|
|
{
|
|
writeToFile("</body>");
|
|
writeToFile("</html>");
|
|
}
|
|
|
|
public void WriteEntry(Dictionary<ECalculatedResult, decimal> calculated, List<KanalObjekt> inspektionenAmTag)
|
|
{
|
|
writeHTMLHeader();
|
|
|
|
writeToFile("<table border='2'>");
|
|
List<ECalculatedResult> avaibleHeaders = new List<ECalculatedResult>();
|
|
string result = "<tr>";
|
|
foreach(var s in calculated.Keys)
|
|
{
|
|
avaibleHeaders.Add(s);
|
|
result += "<td>"+calculated[s]+ "</td>";
|
|
}
|
|
result += "</tr>";
|
|
|
|
makeHeaderTitlesInHtml(avaibleHeaders);
|
|
writeToFile(result);
|
|
writeToFile("</table>");
|
|
writeHTMLFooter();
|
|
|
|
}
|
|
|
|
private void makeHeaderTitlesInHtml(List<ECalculatedResult> avaibleHeaders)
|
|
{
|
|
writeToFile("<tr>");
|
|
foreach(ECalculatedResult s in avaibleHeaders)
|
|
{
|
|
writeToFile("<td>");
|
|
writeToFile(headertitles[s]);
|
|
writeToFile("</td>");
|
|
}
|
|
writeToFile("</tr>");
|
|
}
|
|
}
|
|
} |