Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b3688feca | ||
|
|
7c34192b18 | ||
| d668890370 | |||
| f9ea678e00 |
@@ -18,7 +18,7 @@ namespace LeanderShiftPlannerV2.FileIO
|
||||
if (!Directory.Exists(Constants.ShiftPlanPath)) Directory.CreateDirectory(Constants.ShiftPlanPath);
|
||||
}
|
||||
|
||||
public static SKImage GenerateShiftPlanPng(ShiftPlan shiftPlan)
|
||||
public static SKImage GenerateShiftPlanPng(ShiftPlan shiftPlan, string font)
|
||||
{
|
||||
Dictionary<(int, int), List<string>> names = GetNamesDict(shiftPlan);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace LeanderShiftPlannerV2.FileIO
|
||||
using (SKBitmap bitmap = new SKBitmap(1000, 850))
|
||||
using (SKCanvas canvas = new SKCanvas(bitmap))
|
||||
{
|
||||
SKFont smallTextFont = new SKFont(SKTypeface.FromFile(Constants.FontPath)) { Size = 24 };
|
||||
SKFont smallTextFont = new SKFont(SKTypeface.FromFile($"Resources/font/{font}")) { Size = 24 };
|
||||
SKPaint rectColorGray = new SKPaint
|
||||
{ Color = SKColors.LightGray, Style = SKPaintStyle.Stroke, StrokeWidth = 5 };
|
||||
SKPaint textColorGray = new SKPaint { Color = SKColors.Gray };
|
||||
@@ -40,7 +40,7 @@ namespace LeanderShiftPlannerV2.FileIO
|
||||
canvas.Clear(SKColors.White);
|
||||
|
||||
// Draw Topic
|
||||
using (SKFont topic = new SKFont(SKTypeface.FromFile(Constants.FontPath)))
|
||||
using (SKFont topic = new SKFont(SKTypeface.FromFile($"Resources/font/{font}")))
|
||||
{
|
||||
topic.Size = 40;
|
||||
string text1 = "Schichtplan ";
|
||||
@@ -106,12 +106,13 @@ namespace LeanderShiftPlannerV2.FileIO
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExportShiftPlan(SKImage image, int id)
|
||||
public static void ExportShiftPlan(SKImage image, int id, string font)
|
||||
{
|
||||
CheckFileSystem();
|
||||
|
||||
using SKData data = image.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using FileStream dataStream = File.OpenWrite(Constants.ShiftPlanPath + $"ShiftPlan_{id}.png");
|
||||
if (!Directory.Exists(Constants.ShiftPlanPath + $"/{font}/")) Directory.CreateDirectory(Constants.ShiftPlanPath + $"/{font}/");
|
||||
using FileStream dataStream = File.OpenWrite(Constants.ShiftPlanPath + $"/{font}/" + $"ShiftPlan_{id}.png");
|
||||
data.SaveTo(dataStream);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,9 +86,9 @@ 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());
|
||||
if (tuple.Item3) worksheet.Cells[17 + tuple.Item1.Day, 5].Value = "1:00";
|
||||
worksheet.Cells[16 + tuple.Item1.Day, 2].Value = tuple.Item1.Hour + ":" + (tuple.Item1.Minute == 0 ? "00" : tuple.Item1.Minute.ToString());
|
||||
worksheet.Cells[16 + tuple.Item1.Day, 3].Value = tuple.Item2.Hour + ":" + (tuple.Item2.Minute == 0 ? "00" : tuple.Item1.Minute.ToString());
|
||||
if (tuple.Item3) worksheet.Cells[16 + tuple.Item1.Day, 5].Value = "1:00";
|
||||
}
|
||||
|
||||
for (int i = 17; i <= 47; i++)
|
||||
@@ -98,7 +98,7 @@ public static class TimesheetIO
|
||||
}
|
||||
|
||||
worksheet.Cells[48, 6].Formula = "SUM(F17:F47)";
|
||||
package.SaveAs(new FileInfo(@$"{filePath}/{month}.xlsx"));
|
||||
package.SaveAs(new FileInfo(@$"{filePath}/{Constants.MonthsGerman.IndexOf(month):D2} - {month}.xlsx"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="EPPlus" Version="7.5.3" />
|
||||
<PackageReference Include="Google.Apis.Calendar.v3" Version="1.69.0.3746" />
|
||||
<PackageReference Include="SkiaSharp" Version="3.118.0-preview.2.3" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.118.0-preview.2.3" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="3.118.0-preview.2.3" />
|
||||
@@ -35,6 +36,9 @@
|
||||
<EmbeddedResource Include="Resources\font\Emblem.ttf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\font\Roboto.ttf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\templates\timesheet.xlsx">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
@@ -43,4 +47,8 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\icon\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<UpToDateCheckInput Remove="View\TimeSheetView\TimeSheetView.axaml" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Xml.Serialization;
|
||||
using LeanderShiftPlannerV2.Util;
|
||||
|
||||
namespace LeanderShiftPlannerV2.Model
|
||||
{
|
||||
@@ -12,6 +13,7 @@ namespace LeanderShiftPlannerV2.Model
|
||||
private string _firstFirstName = null!;
|
||||
private string _surname = null!;
|
||||
private int _hours;
|
||||
private string _timeSheetSource;
|
||||
private ObservableCollection<Shift> _shifts;
|
||||
|
||||
[XmlIgnore]
|
||||
@@ -30,11 +32,12 @@ namespace LeanderShiftPlannerV2.Model
|
||||
_timesheets = new List<Timesheet>();
|
||||
}
|
||||
|
||||
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<Shift>();
|
||||
_timesheets = new List<Timesheet>();
|
||||
}
|
||||
@@ -69,6 +72,16 @@ namespace LeanderShiftPlannerV2.Model
|
||||
}
|
||||
}
|
||||
|
||||
public string TimeSheetSource
|
||||
{
|
||||
get => _timeSheetSource;
|
||||
set
|
||||
{
|
||||
_timeSheetSource = value;
|
||||
OnPropertyChanged(nameof(TimeSheetSource));
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public string ShiftsString
|
||||
{
|
||||
@@ -115,5 +128,15 @@ namespace LeanderShiftPlannerV2.Model
|
||||
{
|
||||
return _firstFirstName;
|
||||
}
|
||||
|
||||
public Timesheet GetTimeSheetByMonth(string month)
|
||||
{
|
||||
foreach (Timesheet timesheet in _timesheets)
|
||||
{
|
||||
if (timesheet.Month == month) return timesheet;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
LeanderShiftPlannerV2/Resources/font/Roboto.ttf
Normal file
BIN
LeanderShiftPlannerV2/Resources/font/Roboto.ttf
Normal file
Binary file not shown.
@@ -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<Person> _persons;
|
||||
private readonly List<Person> _randomTimeSheets;
|
||||
private readonly List<Person> _googleTimeSheets;
|
||||
private readonly List<Person> _randomGoogleTimeSheets;
|
||||
|
||||
public PersonService(AppService appService)
|
||||
{
|
||||
this._appService = appService;
|
||||
_persons = new ObservableCollection<Person>();
|
||||
_randomTimeSheets = new List<Person>();
|
||||
_googleTimeSheets = new List<Person>();
|
||||
_randomGoogleTimeSheets = new List<Person>();
|
||||
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<Person> GetRandomTimeSheetList()
|
||||
{
|
||||
Person newPerson = new Person(firstName, surname, int.Parse(hours));
|
||||
return _randomTimeSheets;
|
||||
}
|
||||
|
||||
public List<Person> GetGoogleTimeSheetList()
|
||||
{
|
||||
return _googleTimeSheets;
|
||||
}
|
||||
|
||||
public List<Person> 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)
|
||||
@@ -104,5 +158,13 @@ namespace LeanderShiftPlannerV2.Service
|
||||
RemoveShiftFromPerson(person, shift);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearTimeSheets()
|
||||
{
|
||||
foreach (Person person in _persons)
|
||||
{
|
||||
person.Timesheets.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
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;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace LeanderShiftPlannerV2.Service;
|
||||
|
||||
@@ -15,19 +21,98 @@ 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<Person> persons, bool randomize)
|
||||
{
|
||||
List<Person> 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 (Person person in persons)
|
||||
{
|
||||
List<int> pattern = GetPattern(person);
|
||||
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);
|
||||
|
||||
// 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, (dayEnd.Hour > 13)));
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if (randomize)
|
||||
{
|
||||
CheckForTooMuchHours(person);
|
||||
await CheckForNotEnoughHours(person);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GenerateRandomTimeSheets(List<Person> persons)
|
||||
{
|
||||
foreach (Person person in persons)
|
||||
{
|
||||
List<int> pattern = GetPattern(person.Hours);
|
||||
if (pattern.Count == 0) continue;
|
||||
List<DateTime> holidays = await GetHolidays();
|
||||
List<DateTime> weekends = GetWeekends();
|
||||
@@ -153,33 +238,33 @@ public class TimesheetService
|
||||
return holidays;
|
||||
}
|
||||
|
||||
private List<int> GetPattern(Person person)
|
||||
private List<int> GetPattern(int personHours)
|
||||
{
|
||||
int hours = 0;
|
||||
List<int> pattern = new List<int>();
|
||||
while (hours < person.Hours)
|
||||
while (hours < personHours)
|
||||
{
|
||||
if (hours + 6 <= person.Hours)
|
||||
if (hours + 6 <= personHours)
|
||||
{
|
||||
pattern.Add(6);
|
||||
hours += 6;
|
||||
}
|
||||
else if (hours + 4 <= person.Hours)
|
||||
else if (hours + 4 <= personHours)
|
||||
{
|
||||
pattern.Add(4);
|
||||
hours += 4;
|
||||
}
|
||||
else if (hours + 2 <= person.Hours)
|
||||
else if (hours + 2 <= personHours)
|
||||
{
|
||||
pattern.Add(2);
|
||||
hours += 2;
|
||||
}
|
||||
else if (hours + 1 <= person.Hours)
|
||||
else if (hours + 1 <= personHours)
|
||||
{
|
||||
pattern.Add(1);
|
||||
hours += 1;
|
||||
}
|
||||
else if (hours + 2 > person.Hours)
|
||||
else if (hours + 2 > personHours)
|
||||
{
|
||||
return new List<int>();
|
||||
}
|
||||
@@ -187,4 +272,114 @@ public class TimesheetService
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private void CheckForTooMuchHours(Person person)
|
||||
{
|
||||
foreach (Timesheet timesheet in person.Timesheets)
|
||||
{
|
||||
while (person.Hours * 4 < CalcHours(timesheet))
|
||||
{
|
||||
timesheet.Value.RemoveAt(timesheet.Value.Count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int CalcHours(Timesheet timesheet)
|
||||
{
|
||||
double hours = 0;
|
||||
|
||||
foreach ((DateTime, DateTime, bool) tuple in timesheet.Value)
|
||||
{
|
||||
if (tuple.Item3)
|
||||
{
|
||||
hours += (tuple.Item2 - tuple.Item1).TotalHours - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hours += (tuple.Item2 - tuple.Item1).TotalHours;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) hours;
|
||||
}
|
||||
|
||||
private async Task CheckForNotEnoughHours(Person person)
|
||||
{
|
||||
List<DateTime> holidays = await GetHolidays();
|
||||
List<DateTime> weekends = GetWeekends();
|
||||
|
||||
int monthHours = person.Hours * 4;
|
||||
foreach (string month in Constants.Months)
|
||||
{
|
||||
if (month == Constants.Months[0]) continue;
|
||||
Timesheet timesheet = person.GetTimeSheetByMonth(month);
|
||||
List<(DateTime, DateTime, bool)> timesheetValue = timesheet.Value;
|
||||
|
||||
int currentPersonHours = CalcHours(timesheet);
|
||||
List<int> pattern = GetPattern((person.Hours * 4) - currentPersonHours);
|
||||
|
||||
int currentPatternIndex = 0;
|
||||
int dayOfMonth = 1;
|
||||
int lastDayOfMonth = new DateTime(DateTime.Now.Year, Constants.Months.IndexOf(month), dayOfMonth).AddMonths(1).AddDays(-1).Day;
|
||||
while (currentPersonHours != monthHours)
|
||||
{
|
||||
DateTime currentDay = new DateTime(DateTime.Now.Year, Constants.Months.IndexOf(month), dayOfMonth);
|
||||
if (holidays.Contains(currentDay) || weekends.Contains(currentDay) || CheckForDayIsNotEmpty(currentDay, timesheetValue))
|
||||
{
|
||||
dayOfMonth++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pattern[currentPatternIndex])
|
||||
{
|
||||
case 6:
|
||||
{
|
||||
DateTime dayStart = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 9, 0, 0);
|
||||
DateTime dayEnd = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 16, 0, 0);
|
||||
timesheetValue.Add((dayStart, dayEnd, true));
|
||||
currentPersonHours += 6;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
DateTime dayStart = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 9, 0, 0);
|
||||
DateTime dayEnd = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 13, 0, 0);
|
||||
timesheetValue.Add((dayStart, dayEnd, false));
|
||||
currentPersonHours += 4;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
DateTime dayStart = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 14, 0, 0);
|
||||
DateTime dayEnd = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 16, 0, 0);
|
||||
timesheetValue.Add((dayStart, dayEnd, false));
|
||||
currentPersonHours += 2;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
DateTime dayStart = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 9, 0, 0);
|
||||
DateTime dayEnd = new DateTime(currentDay.Year, currentDay.Month, currentDay.Day, 10, 0, 0);
|
||||
timesheetValue.Add((dayStart, dayEnd, false));
|
||||
currentPersonHours += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dayOfMonth++;
|
||||
if (dayOfMonth > lastDayOfMonth) throw new Exception($"Too many hours for Person {person.FirstName}!");
|
||||
currentPatternIndex = (currentPatternIndex + 1) % pattern.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckForDayIsNotEmpty(DateTime currentDay, List<(DateTime, DateTime, bool)> timesheetValue)
|
||||
{
|
||||
foreach ((DateTime, DateTime, bool) tuple in timesheetValue)
|
||||
{
|
||||
if (tuple.Item1.Date.Day == currentDay.Day) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,15 @@ namespace LeanderShiftPlannerV2.Util
|
||||
public const string ShiftPlanPath = ExportPath + @"/ShiftPlans/";
|
||||
public const string TimesheetPath = ExportPath + "/Timesheets/";
|
||||
public const string TimesheetResource = @"Resources/templates/timesheet.xlsx";
|
||||
public const string FontPath = @"Resources/font/Emblem.ttf";
|
||||
public const string FontPath = @"Resources/font/";
|
||||
public const string FontEmblem = "Emblem.ttf";
|
||||
public const string FontRoboto = "Roboto.ttf";
|
||||
|
||||
// TimeSheets
|
||||
public static readonly string TimeSheetSourceRandom = "Random";
|
||||
public static readonly string TimeSheetSourceGoogle = "Google";
|
||||
public static readonly string TimeSheetSourceRandomGoogle = "RandomGoogle";
|
||||
|
||||
public static readonly List<string> Months = new List<string>
|
||||
{
|
||||
"ERROR!",
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
<ListBox.Template>
|
||||
<ControlTemplate>
|
||||
<DockPanel>
|
||||
<Grid DockPanel.Dock="Top" Height="30" ColumnDefinitions="100,70,1030" Margin="10,0, 0, 0">
|
||||
<Grid DockPanel.Dock="Top" Height="30" ColumnDefinitions="100,70,130,900" Margin="10,0, 0, 0">
|
||||
<TextBlock Grid.Column="0" Text="Name" TextAlignment="Center" Width="100"/>
|
||||
<TextBlock Grid.Column="1" Text="Hours" TextAlignment="Center" Width="70"/>
|
||||
<TextBlock Grid.Column="2" Text="Shifts" TextAlignment="Center" Width="1030"/>
|
||||
<TextBlock Grid.Column="2" Text="TimeSheetSource" TextAlignment="Center" Width="130"/>
|
||||
<TextBlock Grid.Column="3" Text="Shifts" TextAlignment="Center" Width="900"/>
|
||||
</Grid>
|
||||
<ItemsPresenter/>
|
||||
</DockPanel>
|
||||
@@ -26,10 +27,11 @@
|
||||
</ListBox.Template>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid ColumnDefinitions="100,70,1030">
|
||||
<Grid ColumnDefinitions="100,70,130,900">
|
||||
<TextBlock Grid.Column="0" Text="{Binding FirstName, Mode=OneWay}" TextAlignment="Center" Width="100" x:DataType="model:Person"/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Hours, Mode=OneWay}" TextAlignment="Center" Width="70" x:DataType="model:Person"/>
|
||||
<TextBlock Grid.Column="2" Text="{Binding ShiftsString, Mode=OneWay}" TextAlignment="Center" Width="1030" x:DataType="model:Person"/>
|
||||
<TextBlock Grid.Column="2" Text="{Binding TimeSheetSource, Mode=OneWay}" TextAlignment="Center" Width="130" x:DataType="model:Person"/>
|
||||
<TextBlock Grid.Column="3" Text="{Binding ShiftsString, Mode=OneWay}" TextAlignment="Center" Width="900" x:DataType="model:Person"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
@@ -11,6 +11,7 @@ using Avalonia.Threading;
|
||||
using LeanderShiftPlannerV2.FileIO;
|
||||
using LeanderShiftPlannerV2.Model;
|
||||
using LeanderShiftPlannerV2.Service;
|
||||
using LeanderShiftPlannerV2.Util;
|
||||
using LeanderShiftPlannerV2.View.ErrorView;
|
||||
using LeanderShiftPlannerV2.View.LeanderControls;
|
||||
|
||||
@@ -129,14 +130,22 @@ public partial class LeanderShiftPlannerMainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
await _appService.TimesheetService.GenerateTimeSheets();
|
||||
_appService.PersonService.ClearTimeSheets();
|
||||
|
||||
ProgressbarCalculaion.IsIndeterminate = true;
|
||||
await _appService.TimesheetService.GenerateGoogleTimeSheets(_appService.PersonService.GetGoogleTimeSheetList(), false);
|
||||
await _appService.TimesheetService.GenerateGoogleTimeSheets(_appService.PersonService.GetRandomGoogleTimeSheetList(), true);
|
||||
await _appService.TimesheetService.GenerateRandomTimeSheets(_appService.PersonService.GetRandomTimeSheetList());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +165,11 @@ public partial class LeanderShiftPlannerMainWindow : Window
|
||||
private void ButtonSaveShiftPlans_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (ShiftPlan shiftPlan in _appService.ShiftPlanService.GetShiftPlans())
|
||||
ShiftPlanIO.ExportShiftPlan(ShiftPlanIO.GenerateShiftPlanPng(shiftPlan),
|
||||
_appService.ShiftPlanService.GetNextID());
|
||||
{
|
||||
int currentId = _appService.ShiftPlanService.GetNextID();
|
||||
ShiftPlanIO.ExportShiftPlan(ShiftPlanIO.GenerateShiftPlanPng(shiftPlan, Constants.FontEmblem), currentId, Constants.FontEmblem);
|
||||
ShiftPlanIO.ExportShiftPlan(ShiftPlanIO.GenerateShiftPlanPng(shiftPlan ,Constants.FontRoboto), currentId, Constants.FontRoboto);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonStartCalculation_Click(object? sender, RoutedEventArgs e)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<Grid>
|
||||
<Label Content="Create new person" Height="25" VerticalAlignment="Top" Margin="0,15,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
|
||||
|
||||
<Grid ColumnDefinitions="Auto, Auto" RowDefinitions="Auto, Auto, Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Grid ColumnDefinitions="Auto, Auto" RowDefinitions="Auto, Auto, Auto, Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Label Grid.Column="0" Grid.Row="0" Content="Enter person name: " Height="25" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" />
|
||||
<TextBox Grid.Column="1" Grid.Row="0" x:Name="TextBoxName" Height="32" Width="100" HorizontalContentAlignment="Center"/>
|
||||
|
||||
@@ -17,9 +17,12 @@
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="2" Content="Enter person hours: " Height="25" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" />
|
||||
<TextBox Grid.Column="1" Grid.Row="2" x:Name="TextBoxHours" Height="32" Width="100" HorizontalContentAlignment="Center" TextInput="TextBoxHours_PreviewTextInput" />
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="3" Content="Select TimeSheetSource: " Height="25" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" />
|
||||
<ComboBox Grid.Column="1" Grid.Row="3" x:Name="ComboBoxTimeSheetSource" Height="32" Width="100" HorizontalContentAlignment="Center" />
|
||||
</Grid>
|
||||
|
||||
<Button x:Name="ButtonCreatePerson" Content="Create new person" HorizontalContentAlignment="Center" Height="32" Width="125" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,15" Click="ButtonCreatePerson_Click"/>
|
||||
<Button x:Name="ButtonCreatePerson" Content="Create new person" HorizontalContentAlignment="Center" Height="32" Width="150" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,15" Click="ButtonCreatePerson_Click"/>
|
||||
</Grid>
|
||||
|
||||
</Window>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<Grid>
|
||||
<Label Content="Edit person" Height="25" VerticalAlignment="Top" Margin="0,15,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
|
||||
|
||||
<Grid ColumnDefinitions="Auto, Auto" RowDefinitions="Auto, Auto, Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Grid ColumnDefinitions="Auto, Auto" RowDefinitions="Auto, Auto, Auto, Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Label Grid.Column="0" Grid.Row="0" Content="Enter person name: " Height="25" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" />
|
||||
<TextBox Grid.Column="1" Grid.Row="0" x:Name="TextBoxName" Height="32" Width="100" HorizontalContentAlignment="Center"/>
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="2" Content="Enter person hours: " Height="25" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" />
|
||||
<TextBox Grid.Column="1" Grid.Row="2" x:Name="TextBoxHours" Height="32" Width="100" HorizontalContentAlignment="Center" TextInput="TextBoxHours_PreviewTextInput" />
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="3" Content="Select TimeSheetSource: " Height="25" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" />
|
||||
<ComboBox Grid.Column="1" Grid.Row="3" x:Name="ComboBoxTimeSheetSource" Height="32" Width="100" HorizontalContentAlignment="Center" />
|
||||
</Grid>
|
||||
|
||||
<Button x:Name="ButtonEditPerson" Content="Edit person" HorizontalContentAlignment="Center" Height="32" Width="125" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,15" Click="ButtonEditPerson_Click" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Avalonia.Interactivity;
|
||||
using LeanderShiftPlannerV2.FileIO;
|
||||
using LeanderShiftPlannerV2.Model;
|
||||
using LeanderShiftPlannerV2.Service;
|
||||
using LeanderShiftPlannerV2.Util;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace LeanderShiftPlannerV2.View.ShiftPlanView;
|
||||
@@ -19,7 +20,7 @@ public partial class ShiftPlanViewer : Window
|
||||
|
||||
this._appService = appService;
|
||||
this._model = shiftPlan;
|
||||
this._image = ShiftPlanIO.GenerateShiftPlanPng(shiftPlan);
|
||||
this._image = ShiftPlanIO.GenerateShiftPlanPng(shiftPlan, Constants.FontEmblem);
|
||||
|
||||
InitListView();
|
||||
InitImageView();
|
||||
@@ -39,6 +40,8 @@ public partial class ShiftPlanViewer : Window
|
||||
|
||||
private void ButtonSaveShiftPlan_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShiftPlanIO.ExportShiftPlan(_image, _appService.ShiftPlanService.GetNextID());
|
||||
int currentId = _appService.ShiftPlanService.GetNextID();
|
||||
ShiftPlanIO.ExportShiftPlan(_image, currentId, Constants.FontEmblem);
|
||||
ShiftPlanIO.ExportShiftPlan(_image, currentId, Constants.FontRoboto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user