142 lines
3.5 KiB
C#
142 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Xml.Serialization;
|
|
using LeanderShiftPlannerV2.Util;
|
|
|
|
namespace LeanderShiftPlannerV2.Model
|
|
{
|
|
[Serializable]
|
|
public class Person : INotifyPropertyChanged
|
|
{
|
|
private string _firstFirstName = null!;
|
|
private string _surname = null!;
|
|
private int _hours;
|
|
private string _timeSheetSource;
|
|
private ObservableCollection<Shift> _shifts;
|
|
|
|
[XmlIgnore]
|
|
private List<Timesheet> _timesheets;
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
protected void OnPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
public Person()
|
|
{
|
|
_shifts = new ObservableCollection<Shift>();
|
|
_timesheets = new List<Timesheet>();
|
|
}
|
|
|
|
public Person(string firstFirstName, string surname, int hours, string timeSheetSource)
|
|
{
|
|
this._firstFirstName = firstFirstName;
|
|
this._surname = surname;
|
|
this._hours = hours;
|
|
this._timeSheetSource = timeSheetSource;
|
|
_shifts = new ObservableCollection<Shift>();
|
|
_timesheets = new List<Timesheet>();
|
|
}
|
|
|
|
public string FirstName
|
|
{
|
|
get => _firstFirstName;
|
|
set
|
|
{
|
|
_firstFirstName = value;
|
|
OnPropertyChanged(nameof(FirstName));
|
|
}
|
|
}
|
|
|
|
public string Surname
|
|
{
|
|
get => _surname;
|
|
set
|
|
{
|
|
_surname = value;
|
|
OnPropertyChanged(nameof(Surname));
|
|
}
|
|
}
|
|
|
|
public int Hours
|
|
{
|
|
get => _hours;
|
|
set
|
|
{
|
|
_hours = value;
|
|
OnPropertyChanged(nameof(Hours));
|
|
}
|
|
}
|
|
|
|
public string TimeSheetSource
|
|
{
|
|
get => _timeSheetSource;
|
|
set
|
|
{
|
|
_timeSheetSource = value;
|
|
OnPropertyChanged(nameof(TimeSheetSource));
|
|
}
|
|
}
|
|
|
|
[XmlIgnore]
|
|
public string ShiftsString
|
|
{
|
|
get
|
|
{
|
|
string result = "";
|
|
|
|
foreach (Shift shift in _shifts)
|
|
result += shift.Day + " " + shift.ShiftInDay + "; ";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
[XmlIgnore]
|
|
public List<Timesheet> Timesheets
|
|
{
|
|
get => _timesheets;
|
|
set => _timesheets = value;
|
|
}
|
|
|
|
[XmlIgnore] public ObservableCollection<Shift> Shifts => _shifts;
|
|
|
|
public void AddShift(Shift shift)
|
|
{
|
|
_shifts.Add(shift);
|
|
OnPropertyChanged(nameof(ShiftsString));
|
|
}
|
|
|
|
public void RemoveShift(Shift shift)
|
|
{
|
|
_shifts.Remove(shift);
|
|
OnPropertyChanged(nameof(ShiftsString));
|
|
}
|
|
|
|
public void ClearShifts()
|
|
{
|
|
_shifts.Clear();
|
|
OnPropertyChanged(nameof(ShiftsString));
|
|
}
|
|
|
|
override
|
|
public string ToString()
|
|
{
|
|
return _firstFirstName;
|
|
}
|
|
|
|
public Timesheet GetTimeSheetByMonth(string month)
|
|
{
|
|
foreach (Timesheet timesheet in _timesheets)
|
|
{
|
|
if (timesheet.Month == month) return timesheet;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
} |