162 lines
7.2 KiB
C#
162 lines
7.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Data;
|
|
using DTS.Common.Interface.Channels;
|
|
using DTS.Common.Interface.Sensors;
|
|
|
|
namespace DTS.Reports
|
|
{
|
|
public class DASLayout : ReportBase
|
|
{
|
|
|
|
|
|
|
|
public class ChannelHelper
|
|
{
|
|
public int DCH { get; set; }
|
|
public string Module { get; set; }
|
|
public string Channel { get; set; }
|
|
public string Description { get; set; }
|
|
public string SensorSerial { get; set; }
|
|
public string Sensitivity { get; set; }
|
|
public string ISOCode { get; set; }
|
|
public string Range { get; set; }
|
|
public string SquibFireMode { get; set; }
|
|
public string Filter { get; set; }
|
|
public string Voltage { get; set; }
|
|
public string LevelTrigger { get; set; }
|
|
public double DelayMS { get; set; }
|
|
public double DurationMS { get; set; }
|
|
public int ChannelType { get; set; }
|
|
// holds a reference to the group channel, done as part of
|
|
// 13100 Generate Test Setup report during check channels function, needed to verify polarity settings prior to running test
|
|
public IGroupChannel GroupChannel { get; set; }
|
|
// holds a reference to the sensor calibration, done as part of
|
|
// 13100 Generate Test Setup report during check channels function, needed to verify polarity settings prior to running test
|
|
public ISensorCalibration Calibration { get; set; }
|
|
}
|
|
public enum Fields
|
|
{
|
|
DCH,
|
|
Module,
|
|
Channel,
|
|
Description,
|
|
Sensor,
|
|
ISOCode,
|
|
Range,
|
|
SquibFireMode,
|
|
Sens,
|
|
Filter,
|
|
Delay,
|
|
Volt,
|
|
Duration,
|
|
Trigger,
|
|
ChannelType
|
|
}
|
|
public DASLayout()
|
|
{
|
|
|
|
}
|
|
|
|
public static string GetReportFilenamePath(string reportPath, string serialNumberDAS, string testId)
|
|
{
|
|
var filename = "DAS Layout.xlsx";
|
|
if (false == string.IsNullOrEmpty(testId))
|
|
filename = string.Format("{1} {0} - {2}Layout.xlsx", serialNumberDAS, testId, GetFilenameTimeStamp());
|
|
return System.IO.Path.Combine(reportPath, filename);
|
|
}
|
|
|
|
public void DoReport(ChannelHelper[] channels, string outputFileName, string folderNameId, string sensitivityDisplayFormat,
|
|
bool generateExcelReports, bool generatePDFReports)
|
|
{
|
|
using (var dt = new DataTable())
|
|
{
|
|
dt.TableName = "Layout";
|
|
|
|
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
|
foreach (var field in fields)
|
|
{
|
|
var c = dt.Columns.Add(field.ToString());
|
|
switch (field)
|
|
{
|
|
case Fields.Channel: c.DataType = typeof(string); break;
|
|
case Fields.DCH: c.DataType = typeof(int); break;
|
|
case Fields.Delay: c.DataType = typeof(double); break;
|
|
case Fields.Description: c.DataType = typeof(string); break;
|
|
case Fields.Duration: c.DataType = typeof(double); break;
|
|
case Fields.Filter: c.DataType = typeof(string); break;
|
|
case Fields.ISOCode: c.DataType = typeof(string); break;
|
|
case Fields.Module: c.DataType = typeof(string); break;
|
|
case Fields.Range: c.DataType = typeof(string); break;
|
|
case Fields.Sens: c.DataType = typeof(string); break;
|
|
case Fields.Sensor: c.DataType = typeof(string); break;
|
|
case Fields.SquibFireMode: c.DataType = typeof(string); break;
|
|
case Fields.Trigger: c.DataType = typeof(string); break;
|
|
case Fields.Volt: c.DataType = typeof(string); break;
|
|
case Fields.ChannelType: c.DataType = typeof(int); break;
|
|
}
|
|
}
|
|
foreach (var ch in channels)
|
|
{
|
|
var row = dt.NewRow();
|
|
foreach (var field in fields)
|
|
{
|
|
object o = null;
|
|
switch (field)
|
|
{
|
|
case Fields.ChannelType: o = ch.ChannelType; break;
|
|
case Fields.Channel: o = ch.Channel; break;
|
|
case Fields.DCH: o = ch.DCH; break;
|
|
case Fields.Delay: o = ch.DelayMS; break;
|
|
case Fields.Description: o = ch.Description; break;
|
|
case Fields.Duration: o = ch.DurationMS; break;
|
|
case Fields.Filter: o = ch.Filter; break;
|
|
case Fields.ISOCode: o = ch.ISOCode; break;
|
|
case Fields.Module: o = ch.Module; break;
|
|
case Fields.Range: o = ch.Range; break;
|
|
case Fields.Sens: o = ch.Sensitivity; break;
|
|
case Fields.Sensor: o = ch.SensorSerial; break;
|
|
case Fields.SquibFireMode: o = ch.SquibFireMode; break;
|
|
case Fields.Trigger: o = ch.LevelTrigger; break;
|
|
case Fields.Volt: o = ch.Voltage; break;
|
|
}
|
|
row[field.ToString()] = o;
|
|
}
|
|
dt.Rows.Add(row);
|
|
}
|
|
TemplateFilename = GetReportFilenamePath(GetTemplateReportPath(), string.Empty, string.Empty);
|
|
OutputFilename = outputFileName;
|
|
|
|
if (System.IO.File.Exists(outputFileName))
|
|
{
|
|
ReportFileWillBeOverwritten(outputFileName);
|
|
try
|
|
{
|
|
System.IO.File.Delete(outputFileName);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
ReportFileInUse(outputFileName);
|
|
}
|
|
}
|
|
if (generateExcelReports)
|
|
{
|
|
OutputReport(new DataTable[] { dt }, null);
|
|
CopyReportIfNeeded(folderNameId, outputFileName);
|
|
}
|
|
|
|
if (generatePDFReports)
|
|
{
|
|
//PDF
|
|
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 }, null, sensitivityDisplayFormat);
|
|
CopyReportIfNeeded(folderNameId, outputFileName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|