tbf/TBF/BenchControl/DataContainers/Density/Component.cs

76 lines
3.4 KiB
C#

///
/// Copyright (c) 2019-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.Resources;
namespace TBF.BenchControl.DataContainers.Density
{
/// <summary>
/// Holds measured (true) density value.
/// </summary>
public class Component : ComponentBase, GenericDevices.IHasCalendarEvents
{
private static readonly ILog log = LogManager.GetLogger(typeof(Component));
public override string ToString() { return string.Format("{0}({1})", this.GetType().Namespace.Substring(32), Cfg.ToString(1)); }
readonly ComponentCfg myCfg;
public double RealDensity { get { return myCfg.RealDensity; } }
public double AtTemperature { get { return myCfg.AtTemperature; } }
public Component()
{
}
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
myCfg = cfg as ComponentCfg;
/// This is to use data in formulas
Config.Data.RealDensity = RealDensity;
Config.Data.AtTemperature = AtTemperature;
/// This is to have data in reports
Results.WMeterRsltItemSpec.RealDensity = RealDensity;
Results.WMeterRsltItemSpec.AtTemperature = AtTemperature;
log.Debug(this.ToString());
}
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
{
DateTime calibrationDue = myCfg.CalibValidDate;
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
if (calibrationDue > TBF.UI.Constants.MinDate)
{
/// Calibration due date calendar event
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
{
/// Weekly reminders (last 5 weeks)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
false));
}
if (DateTime.Now.Date <= calibrationDue.Date)
{
/// Daily reminders (last 5 days)
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
string.Format(Strings.Calibration_due_date_is_0,
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
true));
}
}
return calendarEvents;
}
}
}