/* 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 { /// /// Creates a list of ItemFormatter objects from a TimePoint. /// public class TimePointFormatter { #region Static methods /// /// Builds a header paragraph from a Date, /// but only if the Date structure has a value. /// public static string DateHeader(DateTime date) { if (date != _nullTimeStamp.Date) { return FormatHeader(date.ToShortDateString()); } else { return String.Empty; } } /// /// Builds a header paragraph from a DateTime structure, /// but only if the DateTime structure has a value. /// 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("Laborwerte vom {1}:{2}", // Environment.NewLine, Properties.Settings.Default.StyleHeader, text, Environment.NewLine, Properties.Settings.Default.StyleParagraph ); } #endregion #region Properties /// /// Gets the time stamp of the from which this /// TimePointFormatter was built. /// public DateTime TimeStamp { get; private set; } /// /// Gets a dictionary of ItemFormatter objects that wrap LabItems. /// The QualifiedName of each LabItem is used as key. /// public IItemFormatterDictionary ItemFormatters { get; private set; } #endregion #region Constructor /// /// Creates a new TimePointFormatter object using a given /// . /// /// TimePoint whose LabItems will be /// used to create ItemFormatter objects. 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); } /// /// Creates a header text line with the time point's date. /// /// public string GetDateHeader() { return DateHeader(TimeStamp); } /// /// Creates a header text line with the time point's date /// and time. /// /// public string GetDateAndTimeHeader() { return DateAndTimeHeader(TimeStamp); } #endregion #region Fields static readonly DateTime _nullTimeStamp = new DateTime(); #endregion } }