Project creation, basics

This commit is contained in:
2023-03-12 12:32:26 +01:00
Unverified
commit 95364c8a31
68 changed files with 3517 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public class Class
{
#region PROPERTIES
public string Name { get; set; }
public string Description { get; set; }
public Teacher Teacher { get; set; }
public Subgroup Subgroup { get; set; }
public Classroom Classroom { get; set; }
#endregion
}
}

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public class Classroom
{
#region PROPERTIES
public string Name { get; set; }
public string Description { get; set; }
public bool IsCapacityLimited { get; set; }
public uint Capacity { get; set; }
#endregion
#region CONSTRUCTORS
public Classroom()
{
Name = string.Empty;
Description = string.Empty;
IsCapacityLimited = false;
Capacity = 1;
}
#endregion
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public class Group
{
#region PROPERTIES
public string Name { get; set; }
public string Description { get; set; }
public Subgroup MainSubgroup { get; set; }
public ICollection<Subgroup> AssignedSubgroups { get; set; }
#endregion
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
[Serializable]
public class Project
{
#region PROPERTIES
public string Name { get; set; }
public string Author { get; set; }
public string Description { get; set; }
public TimetableTemplate TimetableTemplate { get; set; }
public ICollection<Classroom> Classrooms { get; set; }
public ICollection<Teacher> Teachers { get; set; }
public ICollection<Group> Groups { get; set; }
public ICollection<Subgroup> Subgroups { get; set; }
public ICollection<Class> Classes { get; set; }
#endregion
#region CONSTRUCTORS
public Project()
{
Name = string.Empty;
Author = string.Empty;
Description = string.Empty;
TimetableTemplate = new TimetableTemplate();
Classrooms = new List<Classroom>();
Teachers = new List<Teacher>();
}
#endregion
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public class Subgroup
{
#region PROPERTIES
public string Name { get; set; }
public string Description { get; set; }
#endregion
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public class Teacher
{
#region PROPERTIES
public string Name { get; set; }
public string Description { get; set; }
#endregion
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public struct TimetableDay
{
#region PROPERTIES
public string Name { get; set; }
#endregion
#region CONSTRUCTORS
public TimetableDay(string name)
{
Name = name;
}
#endregion
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,75 @@
using System;
namespace TimetableDesigner.Core
{
[Serializable]
public struct TimetableSlot
{
#region PROPERTIES
public TimeOnly From { get; private set; }
public TimeOnly To { get; private set; }
#endregion
#region CONSTRUCTORS
public TimetableSlot(TimeOnly from, TimeOnly to)
{
if (to <= from)
{
throw new ArgumentException("\"to\" cannot be less or equal to \"from\"");
}
From = from;
To = to;
}
#endregion
#region PUBLIC METHODS
internal TimetableSlotsCollision CheckCollision(TimetableSlot slot)
{
if (slot.To <= this.From)
{
return TimetableSlotsCollision.CheckedSlotBefore;
}
else if (this.To <= slot.From)
{
return TimetableSlotsCollision.CheckedSlotAfter;
}
else
{
if (this.From < slot.From && slot.To < this.To)
{
return TimetableSlotsCollision.CheckedSlotIn;
}
else if (this.From < slot.From && slot.From < this.To && this.To < slot.To)
{
return TimetableSlotsCollision.CheckedSlotFromIn;
}
else if (slot.From < this.From && this.From < slot.To && slot.To < this.To)
{
return TimetableSlotsCollision.CheckedSlotToIn;
}
else
{
throw new ArgumentException("Unknown collision");
}
}
}
public override bool Equals(object? obj) => obj is TimetableSlot slot && From == slot.From && To == slot.To;
public override int GetHashCode() => HashCode.Combine(From, To);
public override string? ToString() => $"{From}-{To}";
#endregion
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
internal enum TimetableSlotsCollision
{
CheckedSlotBefore,
CheckedSlotAfter,
CheckedSlotIn,
CheckedSlotFromIn,
CheckedSlotToIn
}
}

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
[Serializable]
public class TimetableTemplate
{
#region FIELDS
private List<TimetableDay> _days;
private List<TimetableSlot> _slots;
#endregion
#region PROPERTIES
public IEnumerable<TimetableDay> Days => _days;
public IEnumerable<TimetableSlot> Slots => _slots;
#endregion
#region CONSTRUCTORS
public TimetableTemplate()
{
_days = new List<TimetableDay>();
_slots = new List<TimetableSlot>();
}
#endregion
#region PUBLIC METHODS
public void AddDay(TimetableDay name)
{
_days.Add(name);
}
public bool RemoveDay(TimetableDay day)
{
return _days.Remove(day);
}
public void AddSlot(TimetableSlot slot)
{
int i = 0;
if (_slots.Count > 0)
{
bool done = false;
while (i < _slots.Count && !done)
{
switch (slot.CheckCollision(_slots[i]))
{
case TimetableSlotsCollision.CheckedSlotBefore: i++; break;
case TimetableSlotsCollision.CheckedSlotAfter: done ^= true; break;
default: throw new ArgumentException("Slot collide with another slot");
}
}
}
_slots.Insert(i, slot);
}
public bool RemoveSlot(TimetableSlot slot)
{
return _slots.Remove(slot);
}
#endregion
}
}