163 lines
7.0 KiB
C#
163 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using TBF.BenchControl;
|
|
|
|
namespace TBF.BenchControl.ResultsWriters.Basic
|
|
{
|
|
public class Writer : Generic.IComponent, IOperation, GenericDevices.IResultsWriter
|
|
{
|
|
readonly WriterCfg writerCfg;
|
|
public Generic.IComponentCfg Cfg { get { return writerCfg; } }
|
|
|
|
public static void ResetStaticProperties() { }
|
|
|
|
public string Name { get { return writerCfg.Name; } }
|
|
|
|
/// <summary>
|
|
/// Results to print
|
|
/// </summary>
|
|
IList<Entities.TestResult> results;
|
|
DateTime now;
|
|
StreamWriter writer;
|
|
|
|
public Writer(WriterCfg cfg)
|
|
{
|
|
if (cfg == null) throw new ArgumentNullException("cfg");
|
|
this.writerCfg = cfg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the test cycle results into a file, Events: Event.ResultsWritten
|
|
/// </summary>
|
|
/// <param name="results">Results to write into the file</param>
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation WriteResultsOp(IList<Entities.TestResult> results)
|
|
{
|
|
if ((results == null) || (results.Count == 0))
|
|
{
|
|
writer = null;
|
|
return this;
|
|
}
|
|
|
|
this.results = results;
|
|
now = DateTime.Now;
|
|
try
|
|
{
|
|
string dayDirectory = string.Format("{0}Results\\{1}-{2}-{3}", Program.HomeDir,
|
|
now.Year, now.Month.ToString("D2"), now.Day.ToString("D2"));
|
|
string fileName = string.Format("{0}\\{1}-{2}.txt", dayDirectory,
|
|
now.Hour.ToString("D2"), now.Minute.ToString("D2"));
|
|
Directory.CreateDirectory(dayDirectory);
|
|
writer = new StreamWriter(System.IO.File.Create(fileName));
|
|
}
|
|
catch
|
|
{
|
|
writer = null;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
if (writer == null) return;
|
|
|
|
writer.WriteLine("Staatlich anerkante Prüfstelle für Meßgeräte für Wasser WB2");
|
|
writer.WriteLine("");
|
|
writer.WriteLine(string.Format(" PROTOKOLL Nummer {0}", 0));
|
|
writer.WriteLine("");
|
|
writer.WriteLine("Ver. 3/13");
|
|
writer.WriteLine(string.Format("Datum / Zeit : {0}.{1}.{2} {3}:{4} Seite : 1/1",
|
|
now.Day.ToString("D2"),
|
|
now.Month.ToString("D2"),
|
|
now.Year.ToString("D4"),
|
|
now.Hour.ToString("D2"),
|
|
now.Minute.ToString("D2")));
|
|
writer.WriteLine(string.Format("Wasserzähler Type : {0}", results[0].ProcedureName));
|
|
writer.WriteLine("Gerät Nr. : 1");
|
|
writer.WriteLine(string.Format("Benutzer : {0}", Entities.User.CurrentUser.Name));
|
|
writer.Write("Impulsrate : ");
|
|
for (int i = 0; i < Program.WMsCount; i++)
|
|
{
|
|
//writer.Write(results[0].
|
|
}
|
|
writer.WriteLine("Bereich : 22,9 °C 947 mbar 43 %");
|
|
writer.WriteLine("");
|
|
writer.WriteLine("Test Metode MIDFehler Durchfluss Test Zeit T1 T2 Dichte Masse Druck Volume Bor");
|
|
writer.WriteLine(" [%] [m3/h] [s] [°C] [°C] [kg/m3] [kg] [MPa] [L] [m3/h]");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
|
|
foreach (var tr in results)
|
|
{
|
|
if (tr.MetersKind == Entities.MetersKind.Single)
|
|
{
|
|
writer.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}",
|
|
tr.Name,
|
|
tr.Method,
|
|
tr.Meters[0].VolumeErrorPct,
|
|
tr.FlowMass,
|
|
tr.Time,
|
|
tr.TempInAvrg,
|
|
tr.TempDivAvrg,
|
|
tr.DensityOut,
|
|
tr.MassDiff,
|
|
tr.PressInAvrg,
|
|
tr.PressOutAvrg,
|
|
tr.VolumeCTV));
|
|
}
|
|
else if (tr.MetersKind == Entities.MetersKind.Combined)
|
|
{
|
|
writer.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}",
|
|
tr.Name,
|
|
tr.Method,
|
|
tr.CombinedMeters[0].VolumeErrorPct,
|
|
tr.FlowMass,
|
|
tr.Time,
|
|
tr.TempInAvrg,
|
|
tr.TempDivAvrg,
|
|
tr.DensityOut,
|
|
tr.MassDiff,
|
|
tr.PressInAvrg,
|
|
tr.PressOutAvrg,
|
|
tr.VolumeCTV));
|
|
}
|
|
}
|
|
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
writer.WriteLine("No| Zähler Nr| Test. Volume [L] | Zählerabweichung [%] | Messunsicherheit k=2 |Prüfergebnis");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
writer.WriteLine(" Qmin Qt Qmax Qmin Qt Qmax Qmin Qt Qmax");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>Event.ResultsWritten</returns>
|
|
public Event Run()
|
|
{
|
|
return Event.ResultsWritten;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
if (writer == null) return;
|
|
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
writer.WriteLine("");
|
|
writer.WriteLine("Hersteller : Bemerkung : M - Prüfung gegen Waage");
|
|
writer.WriteLine(" V - Prüfung gegen MID");
|
|
writer.WriteLine(" P - Start / Stopp");
|
|
writer.WriteLine(" F - Fliegender Start");
|
|
writer.WriteLine(" S - Impulskompensation");
|
|
writer.WriteLine(" C - Impulszählung");
|
|
writer.WriteLine("");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
|
|
if (writer != null) writer.Close();
|
|
writer = null;
|
|
}
|
|
}
|
|
}
|