zaaReloaded2/zaaReloaded2/Formatter/TimePointFormatter.cs

156 lines
4.4 KiB
C#
Executable File

/* TimePointFormatter.cs
* part of zaaReloaded2
*
* Copyright 2015-2017 Daniel Kraus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zaaReloaded2.LabModel;
namespace zaaReloaded2.Formatter
{
/// <summary>
/// Creates a list of ItemFormatter objects from a TimePoint.
/// </summary>
public class TimePointFormatter
{
#region Static methods
/// <summary>
/// Builds a header paragraph from a Date,
/// but only if the Date structure has a value.
/// </summary>
public static string DateHeader(DateTime date)
{
if (date != _nullTimeStamp.Date)
{
return FormatHeader(date.ToShortDateString());
}
else
{
return String.Empty;
}
}
/// <summary>
/// Builds a header paragraph from a DateTime structure,
/// but only if the DateTime structure has a value.
/// </summary>
public static string DateAndTimeHeader(DateTime dateTime)
{
if (dateTime != _nullTimeStamp)
{
return FormatHeader(dateTime.ToString());
}
else
{
return String.Empty;
}
}
#endregion
#region Private static methods
static string FormatHeader(string text)
{
return String.Format("<style:{0}>Laborwerte vom {1}:{2}<style:{3}>",
// Environment.NewLine,
Properties.Settings.Default.StyleHeader,
text,
Environment.NewLine,
Properties.Settings.Default.StyleParagraph
);
}
#endregion
#region Properties
/// <summary>
/// Gets the time stamp of the <see cref="TimePoint"/> from which this
/// TimePointFormatter was built.
/// </summary>
public DateTime TimeStamp { get; private set; }
/// <summary>
/// Gets a dictionary of ItemFormatter objects that wrap LabItems.
/// The QualifiedName of each LabItem is used as key.
/// </summary>
public IItemFormatterDictionary ItemFormatters { get; private set; }
#endregion
#region Constructor
/// <summary>
/// Creates a new TimePointFormatter object using a given
/// <paramref name="timePoint"/>.
/// </summary>
/// <param name="timePoint">TimePoint whose LabItems will be
/// used to create ItemFormatter objects.</param>
public TimePointFormatter(TimePoint timePoint,
ReferenceStyle referenceStyle,
AbnormalStyle abnormalStyle)
{
TimeStamp = timePoint.TimeStamp;
ItemFormatters = new ItemFormatterDictionary();
foreach (LabItem item in timePoint.Items.Values)
{
ItemFormatters[item.QualifiedName] = new ItemFormatter(
item, referenceStyle, abnormalStyle);
}
}
#endregion
#region Methods
public bool ContainsItem(string itemName)
{
return ItemFormatters.ContainsKey(itemName);
}
/// <summary>
/// Creates a header text line with the time point's date.
/// </summary>
/// <returns></returns>
public string GetDateHeader()
{
return DateHeader(TimeStamp);
}
/// <summary>
/// Creates a header text line with the time point's date
/// and time.
/// </summary>
/// <returns></returns>
public string GetDateAndTimeHeader()
{
return DateAndTimeHeader(TimeStamp);
}
#endregion
#region Fields
static readonly DateTime _nullTimeStamp = new DateTime();
#endregion
}
}