diff --git a/LeanderShiftPlannerV2/FileIO/TimesheetIO.cs b/LeanderShiftPlannerV2/FileIO/TimesheetIO.cs
index 3f00e09..283502f 100644
--- a/LeanderShiftPlannerV2/FileIO/TimesheetIO.cs
+++ b/LeanderShiftPlannerV2/FileIO/TimesheetIO.cs
@@ -86,8 +86,8 @@ public static class TimesheetIO
foreach ((DateTime, DateTime, bool) tuple in timesheet.Value)
{
- worksheet.Cells[17 + tuple.Item1.Day, 2].Value = tuple.Item1.Hour + (tuple.Item1.Minute == 0 ? ":00" : tuple.Item1.Minute.ToString());
- worksheet.Cells[17 + tuple.Item1.Day, 3].Value = tuple.Item2.Hour + (tuple.Item2.Minute == 0 ? ":00" : tuple.Item1.Minute.ToString());
+ worksheet.Cells[17 + tuple.Item1.Day, 2].Value = tuple.Item1.Hour + ":" + (tuple.Item1.Minute == 0 ? "00" : tuple.Item1.Minute.ToString());
+ worksheet.Cells[17 + tuple.Item1.Day, 3].Value = tuple.Item2.Hour + ":" + (tuple.Item2.Minute == 0 ? "00" : tuple.Item1.Minute.ToString());
if (tuple.Item3) worksheet.Cells[17 + tuple.Item1.Day, 5].Value = "1:00";
}
diff --git a/LeanderShiftPlannerV2/LeanderShiftPlannerV2.csproj b/LeanderShiftPlannerV2/LeanderShiftPlannerV2.csproj
index ca2c199..426bcc6 100644
--- a/LeanderShiftPlannerV2/LeanderShiftPlannerV2.csproj
+++ b/LeanderShiftPlannerV2/LeanderShiftPlannerV2.csproj
@@ -25,6 +25,7 @@
All
+
@@ -43,4 +44,8 @@
+
+
+
+
diff --git a/LeanderShiftPlannerV2/Model/Person.cs b/LeanderShiftPlannerV2/Model/Person.cs
index f31b8f3..3635582 100644
--- a/LeanderShiftPlannerV2/Model/Person.cs
+++ b/LeanderShiftPlannerV2/Model/Person.cs
@@ -12,6 +12,7 @@ namespace LeanderShiftPlannerV2.Model
private string _firstFirstName = null!;
private string _surname = null!;
private int _hours;
+ private string _timeSheetSource;
private ObservableCollection _shifts;
[XmlIgnore]
@@ -30,11 +31,12 @@ namespace LeanderShiftPlannerV2.Model
_timesheets = new List();
}
- public Person(string firstFirstName, string surname, int hours)
+ 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();
_timesheets = new List();
}
@@ -69,6 +71,16 @@ namespace LeanderShiftPlannerV2.Model
}
}
+ public string TimeSheetSource
+ {
+ get => _timeSheetSource;
+ set
+ {
+ _timeSheetSource = value;
+ OnPropertyChanged(nameof(TimeSheetSource));
+ }
+ }
+
[XmlIgnore]
public string ShiftsString
{
diff --git a/LeanderShiftPlannerV2/Service/PersonService.cs b/LeanderShiftPlannerV2/Service/PersonService.cs
index 1925bd2..76c5f5e 100644
--- a/LeanderShiftPlannerV2/Service/PersonService.cs
+++ b/LeanderShiftPlannerV2/Service/PersonService.cs
@@ -1,7 +1,9 @@
-using LeanderShiftPlannerV2.FileIO;
+using System;
+using LeanderShiftPlannerV2.FileIO;
using LeanderShiftPlannerV2.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using LeanderShiftPlannerV2.Util;
namespace LeanderShiftPlannerV2.Service
{
@@ -9,11 +11,17 @@ namespace LeanderShiftPlannerV2.Service
{
private readonly AppService _appService;
private readonly ObservableCollection _persons;
+ private readonly List _randomTimeSheets;
+ private readonly List _googleTimeSheets;
+ private readonly List _randomGoogleTimeSheets;
public PersonService(AppService appService)
{
this._appService = appService;
_persons = new ObservableCollection();
+ _randomTimeSheets = new List();
+ _googleTimeSheets = new List();
+ _randomGoogleTimeSheets = new List();
LoadPersonsFromFile();
}
@@ -22,6 +30,7 @@ namespace LeanderShiftPlannerV2.Service
foreach (Person person in LoadDataFromFile.LoadPersons())
{
_persons.Add(person);
+ AddToTimeSheetList(person);
}
}
@@ -30,14 +39,30 @@ namespace LeanderShiftPlannerV2.Service
return _persons;
}
- public Person AddNewPerson(string firstName, string surname, string hours)
+ public List GetRandomTimeSheetList()
{
- Person newPerson = new Person(firstName, surname, int.Parse(hours));
+ return _randomTimeSheets;
+ }
+
+ public List GetGoogleTimeSheetList()
+ {
+ return _googleTimeSheets;
+ }
+
+ public List GetRandomGoogleTimeSheetList()
+ {
+ return _randomGoogleTimeSheets;
+ }
+
+ public Person AddNewPerson(string firstName, string surname, string hours, string timeSheetSource)
+ {
+ Person newPerson = new Person(firstName, surname, int.Parse(hours), timeSheetSource);
_persons.Add(newPerson);
+ AddToTimeSheetList(newPerson);
return newPerson;
}
- public void EditPerson(Person person, string? firstName, string? surname, int? hours)
+ public void EditPerson(Person person, string? firstName, string? surname, int? hours, string? timeSheetSource)
{
if (firstName != null)
{
@@ -53,6 +78,35 @@ namespace LeanderShiftPlannerV2.Service
{
person.Hours = (int)hours;
}
+
+ if (timeSheetSource != null)
+ {
+ person.TimeSheetSource = timeSheetSource;
+ }
+
+ AddToTimeSheetList(person);
+ }
+
+ private void AddToTimeSheetList(Person person)
+ {
+ if (person.TimeSheetSource == Constants.TimeSheetSourceRandom)
+ {
+ _randomTimeSheets.Add(person);
+ _googleTimeSheets.Remove(person);
+ _randomGoogleTimeSheets.Remove(person);
+ }
+ else if (person.TimeSheetSource == Constants.TimeSheetSourceGoogle)
+ {
+ _randomTimeSheets.Remove(person);
+ _googleTimeSheets.Add(person);
+ _randomGoogleTimeSheets.Remove(person);
+ }
+ else if (person.TimeSheetSource == Constants.TimeSheetSourceRandomGoogle)
+ {
+ _randomGoogleTimeSheets.Remove(person);
+ _googleTimeSheets.Remove(person);
+ _randomGoogleTimeSheets.Add(person);
+ }
}
public void DeletePerson(Person person)
diff --git a/LeanderShiftPlannerV2/Service/TimesheetService.cs b/LeanderShiftPlannerV2/Service/TimesheetService.cs
index 9e5d909..26942aa 100644
--- a/LeanderShiftPlannerV2/Service/TimesheetService.cs
+++ b/LeanderShiftPlannerV2/Service/TimesheetService.cs
@@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Nodes;
+using System.Threading;
using System.Threading.Tasks;
using LeanderShiftPlannerV2.Model;
using LeanderShiftPlannerV2.Util;
+using Google.Apis.Auth.OAuth2;
+using Google.Apis.Calendar.v3;
+using Google.Apis.Services;
namespace LeanderShiftPlannerV2.Service;
@@ -15,15 +20,90 @@ public class TimesheetService
private readonly AppService _appService;
private const string HolidayApiUriPart1 = "https://feiertage-api.de/api/?jahr=";
private const string HolidayApiUriPart2 = "&nur_land=";
+ private const string GoogleClientId = "823920428427-ub5n9a9dkfpuvjlut4eneg2058so49o3.apps.googleusercontent.com";
+ private const string GoogleClientSecret = "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";
public TimesheetService(AppService appService)
{
_appService = appService;
}
- public async Task GenerateTimeSheets()
+ public async Task GenerateGoogleTimeSheets(List persons)
{
- List persons = _appService.PersonService.GetPersonList().ToList();
+ string[] scopes = { CalendarService.Scope.CalendarReadonly };
+ const string applicationName = "LeanderShiftPlanner";
+
+ ClientSecrets clientSecrets = new ClientSecrets();
+ clientSecrets.ClientId = GoogleClientId;
+ clientSecrets.ClientSecret = GoogleClientSecret;
+ UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(clientSecrets, scopes, "user", CancellationToken.None);
+
+ // Erstelle den CalendarService
+ var service = new CalendarService(new BaseClientService.Initializer()
+ {
+ HttpClientInitializer = credential,
+ ApplicationName = applicationName,
+ });
+
+ foreach (string month in Constants.Months)
+ {
+ if (month == Constants.Months[0]) continue;
+ List<(DateTime, DateTime, bool)> timesheetValue = new List<(DateTime, DateTime, bool)>();
+
+ // Aktuelles Datum
+ DateTime now = DateTime.Now;
+ // Erster Tag des aktuellen Monats (00:00:00 Uhr)
+ DateTime firstDayOfMonth = new DateTime(now.Year, Constants.Months.IndexOf(month), 1, 0, 0, 0);
+ // Letzter Tag des aktuellen Monats (23:59:59 Uhr)
+ DateTime lastDayOfMonth = new DateTime(now.Year, Constants.Months.IndexOf(month), DateTime.DaysInMonth(now.Year, Constants.Months.IndexOf(month)),
+ 23, 59, 59);
+
+ foreach (Person person in persons)
+ {
+ // Beispiel: Liste die nächsten 10 Ereignisse im ITM Kalender auf
+ var requestItm = service.Events.List("on089es7kq4ugi3rqvslkn7720@group.calendar.google.com");
+ requestItm.TimeMinDateTimeOffset = firstDayOfMonth;
+ requestItm.TimeMaxDateTimeOffset = lastDayOfMonth;
+ requestItm.SingleEvents = true;
+
+ var requestWebService = service.Events.List("s4rdo3uk2on8ualv1goaktbiec@group.calendar.google.com");
+ requestWebService.TimeMinDateTimeOffset = firstDayOfMonth;
+ requestWebService.TimeMaxDateTimeOffset = lastDayOfMonth;
+ requestWebService.SingleEvents = true;
+
+ var eventsItm = await requestItm.ExecuteAsync();
+ var eventsWebService = await requestWebService.ExecuteAsync();
+
+ foreach (var eventItem in eventsItm.Items)
+ {
+ if (eventItem.Start.DateTime == null || eventItem.End.DateTime == null) continue;
+ if (eventItem.Summary.Contains(person.FirstName))
+ {
+ DateTime dayStart = (DateTime) eventItem.Start.DateTime;
+ DateTime dayEnd = (DateTime) eventItem.End.DateTime;
+ timesheetValue.Add((dayStart, dayEnd, false));
+ }
+ }
+
+ foreach (var eventItem in eventsWebService.Items)
+ {
+ if (eventItem.Start.DateTime == null || eventItem.End.DateTime == null) continue;
+ if (eventItem.Summary.Contains(person.FirstName))
+ {
+ DateTime dayStart = (DateTime) eventItem.Start.DateTime;
+ DateTime dayEnd = (DateTime) eventItem.End.DateTime;
+ timesheetValue.Add((dayStart, dayEnd, false));
+ }
+ }
+
+ person.Timesheets.Add(new Timesheet(month, timesheetValue));
+ }
+ }
+ }
+
+ public async Task GenerateRandomTimeSheets(List persons)
+ {
+ //List persons = _appService.PersonService.GetPersonList().ToList();
foreach (Person person in persons)
{
diff --git a/LeanderShiftPlannerV2/Util/Constants.cs b/LeanderShiftPlannerV2/Util/Constants.cs
index a8ef658..e825fb3 100644
--- a/LeanderShiftPlannerV2/Util/Constants.cs
+++ b/LeanderShiftPlannerV2/Util/Constants.cs
@@ -17,6 +17,10 @@ namespace LeanderShiftPlannerV2.Util
public const string FontPath = @"Resources/font/Emblem.ttf";
// TimeSheets
+ public static readonly string TimeSheetSourceRandom = "Random";
+ public static readonly string TimeSheetSourceGoogle = "Google";
+ public static readonly string TimeSheetSourceRandomGoogle = "RandomGoogle";
+
public static readonly List Months = new List
{
"ERROR!",
diff --git a/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml b/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml
index 0ee8a91..753be68 100644
--- a/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml
+++ b/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml
@@ -15,10 +15,11 @@
-
+
-
+
+
@@ -26,10 +27,11 @@
-
+
-
+
+
diff --git a/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml.cs b/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml.cs
index 1a90e6b..dc1c72b 100644
--- a/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml.cs
+++ b/LeanderShiftPlannerV2/View/LeanderShiftPlannerView/LeanderShiftPlannerMainWindow.axaml.cs
@@ -129,14 +129,18 @@ public partial class LeanderShiftPlannerMainWindow : Window
{
try
{
- await _appService.TimesheetService.GenerateTimeSheets();
+ ProgressbarCalculaion.IsIndeterminate = true;
+ await _appService.TimesheetService.GenerateGoogleTimeSheets(_appService.PersonService.GetGoogleTimeSheetList());
+ ProgressbarCalculaion.IsIndeterminate = false;
+
int error = TimesheetIO.ExportTimesheets(_appService.PersonService.GetPersonList().ToList());
+ if (error == 1) ViewService.ShowGeneralError(this).ErrorText = "There was an error exporting the timesheets.";
+ if (error == 2) ViewService.ShowGeneralError(this).ErrorText = "There was an error creating the timesheets.";
- if (error == 1) ;
}
catch (Exception exception)
{
- ViewService.ShowGeneralError(this).ErrorText = exception.Message;
+ Console.WriteLine(exception);
}
}
diff --git a/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml b/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml
index e34fae1..23e4495 100644
--- a/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml
+++ b/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml
@@ -8,7 +8,7 @@
-
+
@@ -17,9 +17,12 @@
+
+
+
-
+
diff --git a/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml.cs b/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml.cs
index 096ccda..0705829 100644
--- a/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml.cs
+++ b/LeanderShiftPlannerV2/View/PersonView/PersonCreator.axaml.cs
@@ -15,14 +15,18 @@ public partial class PersonCreator : Window
InitializeComponent();
this._appService = appService;
+ ComboBoxTimeSheetSource.Items.Add(Constants.TimeSheetSourceRandom);
+ ComboBoxTimeSheetSource.Items.Add(Constants.TimeSheetSourceGoogle);
+ ComboBoxTimeSheetSource.Items.Add(Constants.TimeSheetSourceRandomGoogle);
}
private void ButtonCreatePerson_Click(object sender, RoutedEventArgs e)
{
if (TextBoxName.Text != "" && TextBoxHours.Text != "" && TextBoxSurname.Text != ""
- && TextBoxName.Text != null && TextBoxHours.Text != null && TextBoxSurname.Text != null)
+ && TextBoxName.Text != null && TextBoxHours.Text != null && TextBoxSurname.Text != null
+ && ComboBoxTimeSheetSource.SelectedItem != null)
{
- _appService.PersonService.AddNewPerson(TextBoxName.Text, TextBoxSurname.Text, TextBoxHours.Text);
+ _appService.PersonService.AddNewPerson(TextBoxName.Text, TextBoxSurname.Text, TextBoxHours.Text, ComboBoxTimeSheetSource.SelectedItem.ToString()!);
this.Close();
}
else
diff --git a/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml b/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml
index 9ce87fe..98fedb3 100644
--- a/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml
+++ b/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml
@@ -8,7 +8,7 @@
-
+
@@ -17,6 +17,9 @@
+
+
+
diff --git a/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml.cs b/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml.cs
index 139cdaa..3fd4b63 100644
--- a/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml.cs
+++ b/LeanderShiftPlannerV2/View/PersonView/PersonEditor.axaml.cs
@@ -22,19 +22,24 @@ public partial class PersonEditor : Window
TextBoxName.Text = _model.FirstName;
TextBoxSurname.Text = _model.Surname;
TextBoxHours.Text = _model.Hours.ToString();
+
+ ComboBoxTimeSheetSource.Items.Add(Constants.TimeSheetSourceRandom);
+ ComboBoxTimeSheetSource.Items.Add(Constants.TimeSheetSourceGoogle);
+ ComboBoxTimeSheetSource.Items.Add(Constants.TimeSheetSourceRandomGoogle);
}
private void ButtonEditPerson_Click(object sender, RoutedEventArgs e)
{
if (TextBoxName.Text != "" && TextBoxHours.Text != "" && TextBoxSurname.Text != ""
- && TextBoxName.Text != null && TextBoxHours.Text != null && TextBoxSurname.Text != null)
+ && TextBoxName.Text != null && TextBoxHours.Text != null && TextBoxSurname.Text != null
+ && ComboBoxTimeSheetSource.SelectedItem != null)
{
- _appService.PersonService.EditPerson(_model, TextBoxName.Text, TextBoxSurname.Text, int.Parse(TextBoxHours.Text));
+ _appService.PersonService.EditPerson(_model, TextBoxName.Text, TextBoxSurname.Text, int.Parse(TextBoxHours.Text), ComboBoxTimeSheetSource.SelectedItem.ToString()!);
this.Close();
}
else
{
- //TODO: Error, no input!
+ ViewService.ShowNoInputError(this);
}
}