Keine Code-Optimierung verwenden
StaticResource "TransparentColor" hinzugefügt
This commit is contained in:
2024-10-14 09:54:06 +02:00
parent 5f2bf8b385
commit e4d3fb2d82
14 changed files with 183 additions and 132 deletions

View File

@@ -1,6 +1,4 @@

namespace Jugenddienst_Stunden;
namespace Jugenddienst_Stunden;
/// <summary>
/// Die Hauptanwendungsklasse.
@@ -13,72 +11,7 @@ public partial class App : Application {
public App() {
InitializeComponent();
//UnhandledException: Wird gefangen, wenn eine Ausnahme in einem beliebigen nicht verwalteten Thread außerhalb des individuellen Kontexts auftritt.
AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
if (e.ExceptionObject is Exception ex) {
HandleException(ex);
}
};
//UnobservedTaskException: Wird ausgelöst, wenn eine Ausnahme in einem asynchronen Task auftritt und nicht behandelt wird.
TaskScheduler.UnobservedTaskException += (sender, e) => {
HandleException(e.Exception);
e.SetObserved();
};
//Dispatcher: Hilft bei der Handhabung von UI-bezogenen Ausnahmen innerhalb des UI-Threads.
if (Current?.Dispatcher != null) {
Current.Dispatcher.Dispatch(async () => {
try {
// Anwendungscode hier
await Task.CompletedTask; // Dummy await to avoid CS1998
} catch (Exception ex) {
HandleException(ex);
}
});
}
MainPage = new AppShell();
}
private void HandleException(Exception ex) {
// Fehlerbehandlungscode
Console.WriteLine($"Globale Ausnahme: {ex?.Message}");
// Optional: Logging oder Benutzerbenachrichtigung
}
//protected override Window CreateWindow(IActivationState activationState) =>
//new Window(new AppShell()) {
// Width = 500,
// Height = 900
//};
// protected override Window CreateWindow(IActivationState activationState) {
// Window window = base.CreateWindow(activationState);
// window.Activated += Window_Activated;
// return window;
// }
// private async void Window_Activated(object sender, EventArgs e) {
//#if WINDOWS
// const int DefaultWidth = 500;
// const int DefaultHeight = 900;
// var window = sender as Window;
// // change window size.
// window.Width = DefaultWidth;
// window.Height = DefaultHeight;
// // give it some time to complete window resizing task.
// await window.Dispatcher.DispatchAsync(() => { });
// var disp = DeviceDisplay.Current.MainDisplayInfo;
// // move to screen center
// //window.X = (disp.Width / disp.Density - window.Width) / 2;
// //window.Y = (disp.Height / disp.Density - window.Height) / 2;
//#endif
// }
}

View File

@@ -1,10 +1,16 @@
namespace Jugenddienst_Stunden {
public partial class AppShell : Shell {
public AppShell() {
InitializeComponent();
namespace Jugenddienst_Stunden;
/// <summary>
/// AppShell.xaml.cs
/// </summary>
public partial class AppShell : Shell {
/// <summary>
/// Initialisiert eine neue Instanz der <see cref="AppShell"/>-Klasse.
/// </summary>
public AppShell() {
InitializeComponent();
Routing.RegisterRoute(nameof(Views.NotePage), typeof(Views.NotePage));
Routing.RegisterRoute(nameof(Views.StundePage), typeof(Views.StundePage));
}
//Seiten, die nicht in der Appshell sichtbar sind, aber trotzdem aufgerufen werden können
Routing.RegisterRoute(nameof(Views.NotePage), typeof(Views.NotePage));
Routing.RegisterRoute(nameof(Views.StundePage), typeof(Views.StundePage));
}
}

View File

@@ -1,13 +1,19 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace Jugenddienst_Stunden.Converter;
/// <summary>
/// Falls ein int als bool dargestellt werden soll
/// </summary>
public class IntBoolConverter : IValueConverter {
/// <summary>
/// Konvertiert einen int in einen bool
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
if (value is int) {
return (int)value != 0;
@@ -15,7 +21,14 @@ public class IntBoolConverter : IValueConverter {
return false;
}
/// <summary>
/// Konvrertiert einen bool in einen int
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
if (value is bool) {
return (bool)value ? 1 : 0;

View File

@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-maccatalyst;net8.0-android</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0-maccatalyst;net8.0-android34.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
@@ -47,19 +46,27 @@
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<Optimize>False</Optimize>
<Deterministic>True</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-maccatalyst|AnyCPU'">
<Optimize>True</Optimize>
<Optimize>False</Optimize>
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<Deterministic>True</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
<Debugger>Xamarin</Debugger>
<DebugSymbols>True</DebugSymbols>
<Optimize>False</Optimize>
<Deterministic>True</Deterministic>
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<AndroidKeyStore>False</AndroidKeyStore>
</PropertyGroup>
<PropertyGroup>
@@ -71,24 +78,35 @@
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION</DefineConstants>
<Deterministic>True</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
<Debugger>Xamarin</Debugger>
<DebugSymbols>True</DebugSymbols>
<DebugSymbols>False</DebugSymbols>
<Optimize>False</Optimize>
<Deterministic>True</Deterministic>
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<RunAOTCompilation>False</RunAOTCompilation>
<PublishTrimmed>False</PublishTrimmed>
<AndroidKeyStore>False</AndroidKeyStore>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-windows10.0.26100.0|AnyCPU'">
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
<ApplicationVersion>5</ApplicationVersion>
<Optimize>False</Optimize>
<Deterministic>True</Deterministic>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
@@ -113,6 +131,10 @@
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.26100.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

View File

@@ -1,9 +1,10 @@
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
using ZXing.Net.Maui.Controls;
using ZXing.Net.Maui.Controls;
namespace Jugenddienst_Stunden;
namespace Jugenddienst_Stunden;
/// <summary>
/// Das Hauptprogramm.
/// </summary>
public static class MauiProgram {
public static MauiApp CreateMauiApp() {
var builder = MauiApp.CreateBuilder();
@@ -15,9 +16,19 @@ public static class MauiProgram {
})
.UseBarcodeReader();
//Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cHM6Ly9zdHVuZGVuLmpkLWxhbmEtdGlzZW5zLml0L2FwcGFwaQ==");
//Preferences.Default.Set("name", "Default: Lea");
//Preferences.Default.Set("surname", "Mair");
//Preferences.Default.Set("EmployeeId", 3);
//Preferences.Default.Set("apiUrl", "https://stunden.jd-lana-tisens.it/appapi");
#if DEBUG
Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
Preferences.Default.Set("name", "Testserver: Lea");
Preferences.Default.Set("surname", "Mair");
Preferences.Default.Set("EmployeeId", 3);
Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
builder.Logging.AddDebug();
#endif

View File

@@ -10,28 +10,16 @@ internal class Stunde : ObservableObject {
public DateTime Date { get; set; }
//Default-Werte zum Testen
public static string apiKey = Preferences.Default.Get("apiKey", "M3xraUdoSktrdGowaUZoaStJbDJLWmIyTFhYeDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
public static int EmployeeId = Preferences.Default.Get("employeeId", 3);
public static string name = Preferences.Default.Get("name", "Vorname");
public static string surname = Preferences.Default.Get("surname", "Nachname");
public static string apiUrl = Preferences.Default.Get("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
public static string apiKey = Preferences.Default.Get("apiKey", "");
public static int EmployeeId = Preferences.Default.Get("employeeId", 0);
public static string name = Preferences.Default.Get("name", "");
public static string surname = Preferences.Default.Get("surname", "");
public static string apiUrl = Preferences.Default.Get("apiUrl", "");
public static async Task<Hours> LoadData() {
////Preferences.Default.Set("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
//Preferences.Default.Set("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cHM6Ly9zdHVuZGVuLmpkLWxhbmEtdGlzZW5zLml0L2FwcGFwaQ==");//Online
//Preferences.Default.Set("name", "Johannes");
//Preferences.Default.Set("surname", "Fink");
//Preferences.Default.Set("EmployeeId", 5);
////Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
//Preferences.Default.Set("apiUrl", "https://stunden.jd-lana-tisens.it/appapi");
apiKey = Preferences.Default.Get("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
EmployeeId = Preferences.Default.Get("employeeId", 5);
name = Preferences.Default.Get("name", "Johannes");
surname = Preferences.Default.Get("surname", "Fink");
apiUrl = Preferences.Default.Get("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
if (string.IsNullOrEmpty(apiKey)) {

View File

@@ -1,8 +1,4 @@
using Microsoft.Maui.LifecycleEvents;
using Microsoft.UI.Xaml;
// To learn more about WinUI, the WinUI project structure,
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace Jugenddienst_Stunden.WinUI {
@@ -18,6 +14,10 @@ namespace Jugenddienst_Stunden.WinUI {
this.InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

View File

@@ -12,7 +12,7 @@
<Properties>
<DisplayName>$placeholder$</DisplayName>
<PublisherDisplayName>User Name</PublisherDisplayName>
<PublisherDisplayName>Daniel Pichler</PublisherDisplayName>
<Logo>$placeholder$.png</Logo>
</Properties>
@@ -41,6 +41,8 @@
<Capabilities>
<rescap:Capability Name="runFullTrust" />
<Capability Name="internetClient"/>
<DeviceCapability Name="webcam"/>
</Capabilities>
</Package>

View File

@@ -13,6 +13,8 @@
<Color x:Key="SecondaryDarkText">#9880e5</Color>
<Color x:Key="Tertiary">#2B0B98</Color>
<Color x:Key="TransparentColor">Transparent</Color>
<Color x:Key="White">White</Color>
<Color x:Key="Black">Black</Color>
<Color x:Key="Magenta">#D600AA</Color>

View File

@@ -6,24 +6,87 @@ namespace Jugenddienst_Stunden.Types;
/// Represents a day time entry for an employee.
/// </summary>
public class DayTime {
/// <summary>
/// ID des Stundeneintrages
/// </summary>
public int? id { get; set; }
/// <summary>
/// Mitarbeiter-ID
/// </summary>
public int EmployeeId { get; set; }
/// <summary>
/// Der betreffende Tag
/// </summary>
public DateTime day { get; set; }
/// <summary>
/// Der Wochentag
/// </summary>
public int wday { get; set; }
/// <summary>
/// Arbeitsbeginn
/// </summary>
public TimeOnly begin { get; set; }
/// <summary>
/// Arbeitsende
/// </summary>
public TimeOnly end { get; set; }
/// <summary>
/// Beschreibung der Arbeit
/// </summary>
public string description { get; set; }
/// <summary>
/// Freistellung
/// </summary>
public string? free { get; set; }
/// <summary>
/// Freisetellung genehmigt?
/// </summary>
public bool? approved { get; set; }
/// <summary>
/// Sollte nix sein
/// </summary>
public int? type { get; set; }
/// <summary>
/// Das gewählte Projekt
/// </summary>
public int? projekt { get; set; }
/// <summary>
/// Die gewählte Gemeinde
/// </summary>
public int? gemeinde { get; set; }
/// <summary>
/// Nachtstunden
/// </summary>
public TimeOnly night { get; set; }
/// <summary>
/// Summe Arbeitszeit (inklusive Nachstunden mit Faktor)
/// </summary>
public Dictionary<string, TimeOnly> total { get; set; }
public TimeOnly end_print { get; set; }
public TimeSpan TimeSpanVon { get; set; }
public TimeSpan TimeSpanBis { get; set; }
/// <summary>
/// Projekte für die Auswahlliste
/// </summary>
public Collection<Projekt> Projekte { get; set; }
/// <summary>
/// Gemeinden für die Auswahlliste
/// </summary>
public Collection<Gemeinde> Gemeinden { get; set; }
public Collection<Freistellung> Freistellungen { get; set; }

View File

@@ -14,12 +14,13 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
public string MoreInfoUrl => "https://aka.ms/maui";
public string Message => "Hier werden deine geleisteten Arbeitsstunden aufgelistet";
public string LoadOverview => "Lade Summen für " + DateTime.Today.ToString("MMMM");
public static DateTime GetDay = DateTime.Today;
//public static DateTime GetDay = DateTime.Today;
//public string ShowDay => "Zeit an Tag " + GetDay.ToString("ddd d. MMM") + ": ";
public ICommand NewEntryCommand { get; }
public ICommand SelectEntryCommand { get; }
public ICommand LoadDataCommand { get; private set; }
public ICommand RefreshListCommand { get; }
public event EventHandler<string> AlertEvent;
public event EventHandler<string> InfoEvent;
@@ -53,14 +54,14 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
/// <summary>
/// Mindest-Datum für den Datepicker
/// </summary>
public static DateTime MinimumDate {
public DateTime MinimumDate {
get => DateTime.Today.AddDays(-365);
}
/// <summary>
/// Höchst-Datum für den Datepicker
/// </summary>
public static DateTime MaximumDate {
public DateTime MaximumDate {
get => DateTime.Today.AddDays(60);
}
@@ -73,7 +74,7 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
set {
if (dateToday != value) {
dateToday = value;
GetDay = value;
//GetDay = value;
//OnPropertyChanged();
_ = LoadDay(value);
}
@@ -132,6 +133,8 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
NewEntryCommand = new AsyncRelayCommand(NewEntryAsync);
SelectEntryCommand = new AsyncRelayCommand<DayTime>(SelectEntryAsync);
RefreshListCommand = new AsyncRelayCommand(RefreshList);
Task task = LoadDay(DateTime.Today);
}
@@ -160,6 +163,10 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
} else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
}
private async Task RefreshList() {
OnPropertyChanged(nameof(DayTimes));
}
/// <summary>
/// Lädt die Monatssummen für die Übersicht
/// </summary>
@@ -200,7 +207,7 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
InfoEvent?.Invoke(this, e.Message);
} finally {
OnPropertyChanged(nameof(DayTotal));
OnPropertyChanged(nameof(DayTimes));
//OnPropertyChanged(nameof(DayTimes));
}
}

View File

@@ -60,6 +60,7 @@ public partial class LoginPage : ContentPage {
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
await Navigation.PopAsync();
} catch (Exception e) {
await DisplayAlert("Fehler", e.Message, "OK");
}

View File

@@ -17,7 +17,9 @@
</ContentPage.Resources>
<ContentPage.ToolbarItems>
<!--<ToolbarItem Text="Lade Liste" Command="{Binding RefreshListCommand}"/>-->
<ToolbarItem Text="Add" IconImageSource="{StaticResource ToolbarIcon}" Command="{Binding NewEntryCommand}" />
</ContentPage.ToolbarItems>
@@ -51,7 +53,7 @@
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Transparent}}" />
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource TransparentColor}}" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Selected">
@@ -77,7 +79,7 @@
<Label Text="{Binding end}"/>
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0"/>
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0"/>
<Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0"/>
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0"/>
</HorizontalStackLayout>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>

View File

@@ -16,7 +16,9 @@ public partial class StundenPage : ContentPage {
vm.AlertEvent += Vm_AlertEvent;
vm.InfoEvent += Vm_InfoEvent;
}
if (!CheckLogin()) {
NavigateToTargetPage();
}
//// Bildschirmh<6D>he abrufen
//var screenHeight = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
@@ -37,17 +39,16 @@ public partial class StundenPage : ContentPage {
/// </summary>
protected override void OnAppearing() {
base.OnAppearing();
Title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
Title = Preferences.Default.Get("name", "Nicht") + " " + Preferences.Default.Get("surname", "eingeloggt");
}
/// <summary>
/// Das ausgew<65>hlte Datum merken
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void OnDateSelected(object sender, DateChangedEventArgs e) {
// DateTime selectedDate = e.NewDate;
//}
private bool CheckLogin() {
return Preferences.Default.Get("apiKey", "") != "";
}
private async void NavigateToTargetPage() {
await Navigation.PushAsync(new LoginPage());
}
}