using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TimetableDesigner.Core; namespace TimetableDesigner.Export { public class ExporterHTML : Exporter { #region CONSTRUCTORS public ExporterHTML(Project project) : base(project) { } #endregion #region PUBLIC METHODS public override void Export(string path) => Export(path, null); public void Export(string path, string? css) { string content = BuildDocument(css); using (StreamWriter writer = new StreamWriter(path)) { writer.WriteLine(content); } } #endregion #region PRIVATE METHODS private string BuildDocument(string? css) { if (css == null) { StringBuilder cssBuilder = new StringBuilder(); cssBuilder.AppendLine("h1 {text-align: center;}"); cssBuilder.AppendLine("table, td, th { border: 1px solid black; border-collapse: collapse; }"); cssBuilder.AppendLine("td, th { padding: 10px; }"); css = cssBuilder.ToString(); } StringBuilder builder = new StringBuilder(); builder.AppendLine(""); builder.AppendLine("
"); builder.AppendLine(""); builder.AppendLine(""); builder.AppendLine(""); if (Groups.Count > 0) { builder.AppendLine("| "); foreach (TimetableDay day in days) { builder.AppendLine($" | {day.Name} | "); } builder.AppendLine("
|---|---|
| {slot} | "); foreach (TimetableDay day in days) { IEnumerable");
foreach (Class slotClass in slotClasses)
{
string group = slotClass.Group is null ? "none" : slotClass.Group.Name;
string teacher = slotClass.Teacher is null ? "none" : slotClass.Teacher.Name;
string classroom = slotClass.Classroom is null ? "none" : slotClass.Classroom.Name;
builder.AppendLine($" "); builder.AppendLine(slotClass.Name); builder.AppendLine(" "); } builder.AppendLine(" | ");
}
builder.AppendLine("