2015-07-13 21:57:35 +00:00
|
|
|
|
/* TimePointFormatter.cs
|
|
|
|
|
* part of zaaReloaded2
|
|
|
|
|
*
|
2018-02-13 08:28:44 +00:00
|
|
|
|
* Copyright 2015-2018 Daniel Kraus
|
2015-07-13 21:57:35 +00:00
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
{
|
2015-08-05 20:04:07 +00:00
|
|
|
|
#region Static methods
|
|
|
|
|
|
2015-08-09 19:21:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Builds a header paragraph from a Date,
|
|
|
|
|
/// but only if the Date structure has a value.
|
|
|
|
|
/// </summary>
|
2015-08-05 20:04:07 +00:00
|
|
|
|
public static string DateHeader(DateTime date)
|
|
|
|
|
{
|
2015-08-09 19:21:56 +00:00
|
|
|
|
if (date != _nullTimeStamp.Date)
|
|
|
|
|
{
|
|
|
|
|
return FormatHeader(date.ToShortDateString());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
2015-08-05 20:04:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-09 19:21:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Builds a header paragraph from a DateTime structure,
|
|
|
|
|
/// but only if the DateTime structure has a value.
|
|
|
|
|
/// </summary>
|
2015-08-05 20:04:07 +00:00
|
|
|
|
public static string DateAndTimeHeader(DateTime dateTime)
|
|
|
|
|
{
|
2015-08-09 19:21:56 +00:00
|
|
|
|
if (dateTime != _nullTimeStamp)
|
|
|
|
|
{
|
|
|
|
|
return FormatHeader(dateTime.ToString());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return String.Empty;
|
|
|
|
|
}
|
2015-08-05 20:04:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private static methods
|
|
|
|
|
|
|
|
|
|
static string FormatHeader(string text)
|
|
|
|
|
{
|
2015-08-16 03:17:24 +00:00
|
|
|
|
return String.Format("<style:{0}>Laborwerte vom {1}:{2}<style:{3}>",
|
|
|
|
|
// Environment.NewLine,
|
2015-08-15 18:14:24 +00:00
|
|
|
|
Properties.Settings.Default.StyleHeader,
|
2015-08-05 20:04:07 +00:00
|
|
|
|
text,
|
2015-08-15 18:14:24 +00:00
|
|
|
|
Environment.NewLine,
|
|
|
|
|
Properties.Settings.Default.StyleParagraph
|
2015-08-05 20:04:07 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2015-07-13 21:57:35 +00:00
|
|
|
|
#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>
|
2015-08-24 21:17:49 +00:00
|
|
|
|
public TimePointFormatter(TimePoint timePoint,
|
|
|
|
|
ReferenceStyle referenceStyle,
|
2017-03-03 15:20:15 +00:00
|
|
|
|
AbnormalStyle abnormalStyle,
|
|
|
|
|
bool preferVerboseMolar)
|
2015-07-13 21:57:35 +00:00
|
|
|
|
{
|
|
|
|
|
TimeStamp = timePoint.TimeStamp;
|
|
|
|
|
ItemFormatters = new ItemFormatterDictionary();
|
|
|
|
|
foreach (LabItem item in timePoint.Items.Values)
|
|
|
|
|
{
|
2015-08-24 21:17:49 +00:00
|
|
|
|
ItemFormatters[item.QualifiedName] = new ItemFormatter(
|
2017-03-03 15:20:15 +00:00
|
|
|
|
item, referenceStyle, abnormalStyle, preferVerboseMolar);
|
2015-07-13 21:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
public bool ContainsItem(string itemName)
|
|
|
|
|
{
|
|
|
|
|
return ItemFormatters.ContainsKey(itemName);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 12:33:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a header text line with the time point's date.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetDateHeader()
|
|
|
|
|
{
|
2015-08-05 20:04:07 +00:00
|
|
|
|
return DateHeader(TimeStamp);
|
2015-07-25 12:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a header text line with the time point's date
|
|
|
|
|
/// and time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetDateAndTimeHeader()
|
|
|
|
|
{
|
2015-08-05 20:04:07 +00:00
|
|
|
|
return DateAndTimeHeader(TimeStamp);
|
2015-07-25 12:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 21:57:35 +00:00
|
|
|
|
#endregion
|
2015-08-09 19:21:56 +00:00
|
|
|
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
static readonly DateTime _nullTimeStamp = new DateTime();
|
|
|
|
|
|
|
|
|
|
#endregion
|
2015-07-13 21:57:35 +00:00
|
|
|
|
}
|
2015-07-25 12:33:48 +00:00
|
|
|
|
}
|