149 lines
5.9 KiB
C#
149 lines
5.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Data;
|
|
using System.IO;
|
|
|
|
namespace DTS.Reports
|
|
{
|
|
public class ChannelCalibrationList : ReportBase
|
|
{
|
|
public enum Fields
|
|
{
|
|
Location,
|
|
SensorAxis,
|
|
SerialNo,
|
|
Cal,
|
|
NextCal
|
|
}
|
|
public class ChannelHelper
|
|
{
|
|
public enum ResultStatus
|
|
{
|
|
OK,
|
|
Overdue,
|
|
Warn
|
|
}
|
|
public string Location { get; set; }
|
|
public string SensorAxis { get; set; }
|
|
public string SerialNo { get; set; }
|
|
public string SerialNumberWithAxis { get; set; }
|
|
public string Cal { get; set; }
|
|
public string NextCal { get; set; }
|
|
public ResultStatus CalStatus { get; set; }
|
|
public ChannelHelper() { Location = ""; SensorAxis = ""; SerialNo = ""; Cal = ""; NextCal = ""; }
|
|
public ChannelHelper(string location, string sensorAxis, string serialNo, string cal, string nextCal)
|
|
{
|
|
Location = location;
|
|
SensorAxis = sensorAxis;
|
|
SerialNo = serialNo;
|
|
Cal = cal;
|
|
NextCal = nextCal;
|
|
}
|
|
}
|
|
public ChannelCalibrationList()
|
|
{
|
|
|
|
}
|
|
|
|
public static string GetReportFilenamePath(string reportPath, string testId)
|
|
{
|
|
var filename = "ChannelCalibrationList.xlsx";
|
|
if (false == string.IsNullOrEmpty(testId))
|
|
filename = $"{testId} " + filename;
|
|
return Path.Combine(reportPath, filename);
|
|
}
|
|
public void DoReport(ChannelHelper[] channels, string outputFileName, string folderNameId, string sensitivityDisplayFormat,
|
|
bool generateExcelReports, bool generatePDFReports)
|
|
{
|
|
var dtStyles = new DataTable();
|
|
using (var dt = new DataTable())
|
|
{
|
|
dt.TableName = "List";
|
|
|
|
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
|
foreach (var field in fields)
|
|
{
|
|
var c = dt.Columns.Add(field.ToString());
|
|
var c2 = dtStyles.Columns.Add(field.ToString(), typeof(int));
|
|
switch (field)
|
|
{
|
|
default: c.DataType = typeof(string); break;
|
|
}
|
|
}
|
|
foreach (var ch in channels)
|
|
{
|
|
var row = dt.NewRow();
|
|
var row2 = dtStyles.NewRow();
|
|
foreach (var field in fields)
|
|
{
|
|
object o = null;
|
|
row2[field.ToString()] = -1;
|
|
switch (field)
|
|
{
|
|
case Fields.Cal: o = ch.Cal; break;
|
|
case Fields.Location: o = ch.Location; break;
|
|
case Fields.NextCal:
|
|
o = ch.NextCal;
|
|
if ((!string.IsNullOrWhiteSpace(ch.NextCal)) && (ch.NextCal != "--"))
|
|
{
|
|
switch (ch.CalStatus)
|
|
{
|
|
case ChannelHelper.ResultStatus.OK:
|
|
row2[field.ToString()] = (int)FillStyles.Pass;
|
|
break;
|
|
case ChannelHelper.ResultStatus.Warn:
|
|
row2[field.ToString()] = (int)FillStyles.Warn;
|
|
break;
|
|
case ChannelHelper.ResultStatus.Overdue:
|
|
row2[field.ToString()] = (int)FillStyles.Fail;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case Fields.SensorAxis: o = ch.SensorAxis; break;
|
|
case Fields.SerialNo: o = ch.SerialNo; break;
|
|
}
|
|
row[field.ToString()] = o;
|
|
}
|
|
dt.Rows.Add(row);
|
|
dtStyles.Rows.Add(row2);
|
|
}
|
|
|
|
if (File.Exists(outputFileName))
|
|
{
|
|
ReportFileWillBeOverwritten(outputFileName);
|
|
try
|
|
{
|
|
File.Delete(outputFileName);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
ReportFileInUse(outputFileName);
|
|
}
|
|
}
|
|
|
|
|
|
TemplateFilename = GetReportFilenamePath(GetTemplateReportPath(), string.Empty);
|
|
OutputFilename = outputFileName;
|
|
|
|
if (generateExcelReports)
|
|
{
|
|
OutputReport(new DataTable[] { dt }, new DataTable[] { dtStyles });
|
|
CopyReportIfNeeded(folderNameId, outputFileName);
|
|
}
|
|
|
|
if (generatePDFReports)
|
|
{
|
|
//Make a PDF with the same name
|
|
outputFileName = outputFileName.Replace(".xlsx", ".pdf");
|
|
//Don't overwrite the Excel file that may be the filled-in template.
|
|
DestinationTemplateFilename = OutputFilename.Replace(".xlsx", Common.Constants.TEMP_FILE_EXTENSION);
|
|
OutputFilename = outputFileName;
|
|
OutputReportPDF(new DataTable[] { dt }, new DataTable[] { dtStyles }, sensitivityDisplayFormat);
|
|
CopyReportIfNeeded(folderNameId, outputFileName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|