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;
|
2015-07-15 23:49:17 +00:00
|
|
|
|
using System.Diagnostics;
|
2015-07-13 21:57:35 +00:00
|
|
|
|
using Microsoft.Office.Interop.Word;
|
|
|
|
|
using zaaReloaded2.LabModel;
|
2015-07-15 23:49:17 +00:00
|
|
|
|
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>
|
2015-07-15 23:49:17 +00:00
|
|
|
|
public class Formatter
|
2015-07-13 21:57:35 +00:00
|
|
|
|
{
|
|
|
|
|
#region Properties
|
|
|
|
|
|
2015-07-15 23:49:17 +00:00
|
|
|
|
public Settings Settings { get; set; }
|
2015-07-13 21:57:35 +00:00
|
|
|
|
|
2015-07-14 21:19:41 +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)
|
|
|
|
|
{
|
2015-07-15 23:49:17 +00:00
|
|
|
|
_timePointFormatters[tp.TimeStamp] =
|
|
|
|
|
new TimePointFormatter(tp, Settings.ReferenceStyle);
|
2015-07-13 21:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 21:19:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the current working set of TimePointFormatters.
|
|
|
|
|
/// </summary>
|
2015-07-16 22:23:06 +00:00
|
|
|
|
public Dictionary<DateTime, TimePointFormatter> WorkingTimePoints { get; private set; }
|
2015-07-14 21:19:41 +00:00
|
|
|
|
|
2015-07-13 21:57:35 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2015-07-16 22:23:06 +00:00
|
|
|
|
#region Constructors
|
2015-07-13 21:57:35 +00:00
|
|
|
|
|
|
|
|
|
public Formatter()
|
|
|
|
|
{
|
2015-07-15 23:49:17 +00:00
|
|
|
|
Settings = new Settings();
|
2015-07-13 21:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 21:19:41 +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>
|
2015-07-14 21:19:41 +00:00
|
|
|
|
public void Run()
|
2015-07-13 21:57:35 +00:00
|
|
|
|
{
|
2015-07-15 23:49:17 +00:00
|
|
|
|
foreach (ElementBase element in Settings.Elements)
|
2015-07-14 21:19:41 +00:00
|
|
|
|
{
|
|
|
|
|
element.Run(this);
|
|
|
|
|
}
|
2015-07-13 21:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-16 22:23:06 +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
|
|
|
|
|
|
2015-07-16 22:23:06 +00:00
|
|
|
|
TimePointFormatterDictionary _timePointFormatters;
|
2015-07-13 21:57:35 +00:00
|
|
|
|
Laboratory _laboratory;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|