Teacher editor

This commit is contained in:
2023-03-12 17:52:17 +01:00
Unverified
parent 95364c8a31
commit 3cc4ea5b4b
28 changed files with 947 additions and 93 deletions

View File

@@ -12,6 +12,20 @@ namespace TimetableDesigner.Core
public string Name { get; set; }
public string Description { get; set; }
public IDictionary<TimetableDay, TimetableSpanCollection> AvailabilityHours { get; set; }
#endregion
#region CONSTRUCTORS
public Teacher()
{
Name = string.Empty;
Description = string.Empty;
AvailabilityHours = new Dictionary<TimetableDay, TimetableSpanCollection>();
}
#endregion
}

View File

@@ -6,7 +6,8 @@ using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public struct TimetableDay
[Serializable]
public class TimetableDay
{
#region PROPERTIES

View File

@@ -3,7 +3,7 @@
namespace TimetableDesigner.Core
{
[Serializable]
public struct TimetableSlot
public class TimetableSpan
{
#region PROPERTIES
@@ -16,7 +16,7 @@ namespace TimetableDesigner.Core
#region CONSTRUCTORS
public TimetableSlot(TimeOnly from, TimeOnly to)
public TimetableSpan(TimeOnly from, TimeOnly to)
{
if (to <= from)
{
@@ -33,29 +33,29 @@ namespace TimetableDesigner.Core
#region PUBLIC METHODS
internal TimetableSlotsCollision CheckCollision(TimetableSlot slot)
internal TimetableSpansCollision CheckCollision(TimetableSpan slot)
{
if (slot.To <= this.From)
{
return TimetableSlotsCollision.CheckedSlotBefore;
return TimetableSpansCollision.CheckedSlotBefore;
}
else if (this.To <= slot.From)
{
return TimetableSlotsCollision.CheckedSlotAfter;
return TimetableSpansCollision.CheckedSlotAfter;
}
else
{
if (this.From < slot.From && slot.To < this.To)
{
return TimetableSlotsCollision.CheckedSlotIn;
return TimetableSpansCollision.CheckedSlotIn;
}
else if (this.From < slot.From && slot.From < this.To && this.To < slot.To)
{
return TimetableSlotsCollision.CheckedSlotFromIn;
return TimetableSpansCollision.CheckedSlotFromIn;
}
else if (slot.From < this.From && this.From < slot.To && slot.To < this.To)
{
return TimetableSlotsCollision.CheckedSlotToIn;
return TimetableSpansCollision.CheckedSlotToIn;
}
else
{
@@ -64,7 +64,7 @@ namespace TimetableDesigner.Core
}
}
public override bool Equals(object? obj) => obj is TimetableSlot slot && From == slot.From && To == slot.To;
public override bool Equals(object? obj) => obj is TimetableSpan slot && From == slot.From && To == slot.To;
public override int GetHashCode() => HashCode.Combine(From, To);

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
public class TimetableSpanCollection : ICollection<TimetableSpan>
{
#region FIELDS
private IList<TimetableSpan> _list;
#endregion
#region PROPERTIES
public int Count => _list.Count;
public bool IsReadOnly => _list.IsReadOnly;
#endregion
#region CONSTRUCTORS
public TimetableSpanCollection()
{
_list = new List<TimetableSpan>();
}
#endregion
#region PUBLIC METHODS
public void Add(TimetableSpan item)
{
int i = 0;
if (Count > 0)
{
bool done = false;
while (i < Count && !done)
{
switch (item.CheckCollision(_list.ElementAt(i)))
{
case TimetableSpansCollision.CheckedSlotBefore: i++; break;
case TimetableSpansCollision.CheckedSlotAfter: done ^= true; break;
default: throw new ArgumentException("Slot collide with another slot");
}
}
}
_list.Insert(i, item);
}
public void Clear() => _list.Clear();
public bool Contains(TimetableSpan item) => _list.Contains(item);
public void CopyTo(TimetableSpan[] array, int arrayIndex) => _list.CopyTo(array, arrayIndex);
public IEnumerator<TimetableSpan> GetEnumerator() => _list.GetEnumerator();
public bool Remove(TimetableSpan item) => _list.Remove(item);
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_list).GetEnumerator();
#endregion
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace TimetableDesigner.Core
{
internal enum TimetableSlotsCollision
internal enum TimetableSpansCollision
{
CheckedSlotBefore,
CheckedSlotAfter,

View File

@@ -12,7 +12,7 @@ namespace TimetableDesigner.Core
#region FIELDS
private List<TimetableDay> _days;
private List<TimetableSlot> _slots;
private TimetableSpanCollection _slots;
#endregion
@@ -21,7 +21,7 @@ namespace TimetableDesigner.Core
#region PROPERTIES
public IEnumerable<TimetableDay> Days => _days;
public IEnumerable<TimetableSlot> Slots => _slots;
public IEnumerable<TimetableSpan> Slots => _slots;
#endregion
@@ -32,7 +32,7 @@ namespace TimetableDesigner.Core
public TimetableTemplate()
{
_days = new List<TimetableDay>();
_slots = new List<TimetableSlot>();
_slots = new TimetableSpanCollection();
}
#endregion
@@ -41,39 +41,13 @@ namespace TimetableDesigner.Core
#region PUBLIC METHODS
public void AddDay(TimetableDay name)
{
_days.Add(name);
}
public void AddDay(TimetableDay name) => _days.Add(name);
public bool RemoveDay(TimetableDay day)
{
return _days.Remove(day);
}
public bool RemoveDay(TimetableDay day) => _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 void AddSlot(TimetableSpan slot) => _slots.Add(slot);
public bool RemoveSlot(TimetableSlot slot)
{
return _slots.Remove(slot);
}
public bool RemoveSlot(TimetableSpan slot) => _slots.Remove(slot);
#endregion
}