zaaReloaded2/zaaReloaded2/Formatter/Formatter.cs

138 lines
3.8 KiB
C#
Raw Normal View History

2015-07-13 21:57:35 +00:00
/* Formatter.cs
* part of zaaReloaded2
*
* Copyright 2015 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 System.Diagnostics;
2015-07-13 21:57:35 +00:00
using Microsoft.Office.Interop.Word;
using zaaReloaded2.LabModel;
using zaaReloaded2.Controller;
using zaaReloaded2.Controller.Elements;
2015-07-13 21:57:35 +00:00
namespace zaaReloaded2.Formatter
{
/// <summary>
/// Formats and writes a <see cref="Laboratory"/> to a Word document.
/// </summary>
public class Formatter
2015-07-13 21:57:35 +00:00
{
#region Properties
public Settings Settings { get; set; }
2015-07-13 21:57:35 +00:00
/// <summary>
/// Gets the working Word document.
/// </summary>
public Document Document { get; private set; }
2015-07-13 21:57:35 +00:00
/// <summary>
/// Gets or sets the <see cref="Laboratory"/> that shall be
/// formatted.
/// </summary>
public Laboratory Laboratory
{
[DebuggerStepThrough]
get
{
return _laboratory;
}
set
{
_laboratory = value;
_timePointFormatters = new TimePointFormatterDictionary();
foreach (TimePoint tp in _laboratory.TimePoints.Values)
{
_timePointFormatters[tp.TimeStamp] =
new TimePointFormatter(tp, Settings.ReferenceStyle);
2015-07-13 21:57:35 +00:00
}
}
}
/// <summary>
/// Gets the current working set of TimePointFormatters.
/// </summary>
public Dictionary<DateTime, TimePointFormatter> WorkingTimePoints { get; private set; }
2015-07-13 21:57:35 +00:00
#endregion
#region Constructors
2015-07-13 21:57:35 +00:00
public Formatter()
{
Settings = new Settings();
2015-07-13 21:57:35 +00:00
}
public Formatter(Document document)
: this()
{
Document = document;
}
2015-07-13 21:57:35 +00:00
#endregion
#region Public methods
/// <summary>
/// Formats the laboratory and writes it to a Word document.
/// </summary>
/// <param name="document">Word document to write to (at the
/// current position of the cursor).</param>
public void Run()
2015-07-13 21:57:35 +00:00
{
foreach (ElementBase element in Settings.Elements)
{
element.Run(this);
}
2015-07-13 21:57:35 +00:00
}
/// <summary>
/// Selects all time points for the first day in the
/// laboratory.
/// </summary>
public void SelectFirstDay()
{
DateTime first = _timePointFormatters.First().Key;
WorkingTimePoints = _timePointFormatters
.Where(kv => kv.Key.Date == first.Date)
.ToDictionary(kv => kv.Key, kv => kv.Value);
}
/// <summary>
/// Selects all time points for the first day in the
/// laboratory.
/// </summary>
public void SelectLastDay()
{
DateTime last = _timePointFormatters.Last().Key;
WorkingTimePoints = _timePointFormatters
.Where(kv => kv.Key.Date == last.Date)
.ToDictionary(kv => kv.Key, kv => kv.Value);
}
2015-07-13 21:57:35 +00:00
#endregion
#region Fields
TimePointFormatterDictionary _timePointFormatters;
2015-07-13 21:57:35 +00:00
Laboratory _laboratory;
#endregion
}
}