Barcodes speichern
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_about_ios.png'}" />
|
||||
|
||||
<ShellContent
|
||||
Title="About"
|
||||
Title="Login"
|
||||
ContentTemplate="{DataTemplate views:AboutPage}"
|
||||
Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_about_ios.png'}" />
|
||||
</TabBar>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZXing.QrCode.Internal;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models
|
||||
{
|
||||
@@ -14,6 +15,8 @@ namespace Jugenddienst_Stunden.Models
|
||||
public static async Task<string> GetApiDataWithAuthAsync(string url, string token) {
|
||||
using (HttpClient client = new HttpClient()) {
|
||||
try {
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
// Hinzufügen des Bearer-Tokens zum Authorization-Header
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Jugenddienst_Stunden.Models {
|
||||
public Dictionary<int,NominalWeek> nominal_week_api;
|
||||
//public List<string> time_line;
|
||||
public string zeit_total;
|
||||
public Dictionary<int,decimal> zeit_total_daily;
|
||||
public Dictionary<int,decimal>? zeit_total_daily;
|
||||
//public List<string> wochensumme;
|
||||
public string overtime_month;
|
||||
public string overtime;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
public class Operator {
|
||||
public class Operator : ObservableObject {
|
||||
public string id;
|
||||
public string name;
|
||||
public string surname;
|
||||
@@ -23,5 +27,29 @@ namespace Jugenddienst_Stunden.Models {
|
||||
public string year;
|
||||
//public List<int>? timetable;
|
||||
|
||||
|
||||
|
||||
|
||||
public static async Task<Operator> LoadData(string apiKey) {
|
||||
//var apiKey = Preferences.Default.Get("apiKey", "");
|
||||
Operator OperatorVar = new Operator();
|
||||
//Operator operator = new Operator();
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
//throw new Exception("Keine Internetverbindung");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
||||
if (data != null) {
|
||||
OperatorVar = Newtonsoft.Json.JsonConvert.DeserializeObject<Operator>(data);
|
||||
Preferences.Default.Set("name", OperatorVar.name);
|
||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||
}
|
||||
|
||||
}
|
||||
return OperatorVar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,48 @@
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Maui.Networking;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
internal class Stunde : ObservableObject {
|
||||
|
||||
private static readonly string BaseAddress = "http://hours.dauni.mine.nu:81";
|
||||
//private static readonly string apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Christine
|
||||
public static string apiKey = "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Damian
|
||||
private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
|
||||
//Katharina
|
||||
public static string apiKey = Preferences.Default.Get("apiKey", "MTAyfEJZZnB1L3VwcnhoVms0dDlLZENPZWtUVy85b3xodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
|
||||
//Damian
|
||||
//public static string apiKey = Preferences.Default.Get("apiKey", "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
|
||||
//private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
public static async Task<Hours> LoadData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
//throw new Exception("Keine Internetverbindung");
|
||||
} else {
|
||||
string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", tokendata.apiKey);
|
||||
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
//Preferences.Default.Set("name", hours.operator_api.name);
|
||||
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
||||
|
||||
|
||||
}
|
||||
return hours;
|
||||
|
||||
23
Jugenddienst Stunden/Models/TokenData.cs
Normal file
23
Jugenddienst Stunden/Models/TokenData.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
class TokenData {
|
||||
public string token { get; set; }
|
||||
public string apiKey { get; set; }
|
||||
public string url { get; set; }
|
||||
public string operator_id { get; set; }
|
||||
|
||||
public TokenData(string apiKey) {
|
||||
string dat = Encoding.UTF8.GetString(System.Convert.FromBase64String(apiKey));
|
||||
this.token = dat.Split('|')[1]; ;
|
||||
this.url = dat.Split('|')[2]; ;
|
||||
this.operator_id = dat.Split('|')[0]; ;
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,21 @@ namespace Jugenddienst_Stunden.ViewModels {
|
||||
internal class AboutViewModel {
|
||||
public string Title => AppInfo.Name;
|
||||
public string Version => AppInfo.VersionString;
|
||||
public string MoreInfoUrl => "https://aka.ms/maui";
|
||||
public string Message => "This app is written in XAML and C# with .NET MAUI.";
|
||||
public ICommand ShowMoreInfoCommand { get; }
|
||||
|
||||
public string Message => "Scanne den QR-Code von deinem Benutzerprofil auf der Stundenseite.";
|
||||
|
||||
|
||||
|
||||
public AboutViewModel() {
|
||||
ShowMoreInfoCommand = new AsyncRelayCommand(ShowMoreInfo);
|
||||
}
|
||||
|
||||
async Task ShowMoreInfo() =>
|
||||
await Launcher.Default.OpenAsync(MoreInfoUrl);
|
||||
|
||||
//private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
||||
// var first = e.Results?.FirstOrDefault();
|
||||
// if (first is null) {
|
||||
// return;
|
||||
// }
|
||||
// System.Windows.Application.Current.Dispatcher.DispatchAsync(async () => {
|
||||
// await DisplayAlert("Scan-Ergebnis", $"Barcode: {first.Value}", "OK");
|
||||
// });
|
||||
//}
|
||||
|
||||
//private async void SetupBarcodeScanner() {
|
||||
// try {
|
||||
|
||||
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui.Networking;
|
||||
using ZXing.Net.Maui;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels {
|
||||
@@ -33,6 +34,7 @@ namespace Jugenddienst_Stunden.ViewModels {
|
||||
public string OvertimeMonth {
|
||||
get => _hour.overtime_month;
|
||||
}
|
||||
public string Title { get; set; } = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
||||
|
||||
public StundenViewModel() {
|
||||
_hour = new Models.Hours();
|
||||
@@ -45,6 +47,7 @@ namespace Jugenddienst_Stunden.ViewModels {
|
||||
public async Task LoadData() {
|
||||
_hour = await Models.Stunde.LoadData();
|
||||
Models.Hours Hours = new Models.Hours();
|
||||
//Title = _hour.operator_api.name + " " + _hour.operator_api.surname;
|
||||
RefreshProperties();
|
||||
}
|
||||
|
||||
@@ -55,6 +58,7 @@ namespace Jugenddienst_Stunden.ViewModels {
|
||||
OnPropertyChanged(nameof(ZeitCalculated));
|
||||
OnPropertyChanged(nameof(ZeitDone));
|
||||
OnPropertyChanged(nameof(Hours));
|
||||
OnPropertyChanged(nameof(Title));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,17 +19,15 @@
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<Label Text="{Binding Message}" />
|
||||
<Button Text="Learn more..." Command="{Binding ShowMoreInfoCommand}" />
|
||||
|
||||
<!--<scanner:CameraView x:Name="barcodeScannerView"
|
||||
OnDetectionFinished="BarcodesDetected"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
VerticalOptions="FillAndExpand" />-->
|
||||
|
||||
|
||||
|
||||
<zxing:CameraBarcodeReaderView x:Name="barcodeScannerView"
|
||||
BarcodesDetected="BarcodesDetected"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
VerticalOptions="FillAndExpand" />
|
||||
VerticalOptions="FillAndExpand"
|
||||
Margin="0,60,0,0"/>
|
||||
</VerticalStackLayout>
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Jugenddienst_Stunden.Models;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System.Collections.Generic;
|
||||
using ZXing.Net.Maui;
|
||||
@@ -21,15 +22,31 @@ public partial class AboutPage : ContentPage {
|
||||
|
||||
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
||||
//var first = e.Results?.FirstOrDefault();
|
||||
|
||||
var currentTime = DateTime.Now;
|
||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||
_lastDetectionTime = currentTime;
|
||||
foreach (var barcode in e.Results) {
|
||||
MainThread.InvokeOnMainThreadAsync(() => {
|
||||
DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||
if (Preferences.Default.Get("apiKey", "") != barcode.Value) {
|
||||
MainThread.InvokeOnMainThreadAsync(async() => {
|
||||
//DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||
Preferences.Default.Set("apiKey", barcode.Value);
|
||||
|
||||
Models.Stunde.apiKey = barcode.Value;
|
||||
|
||||
var op = await Models.Operator.LoadData(barcode.Value);
|
||||
Preferences.Default.Set("name", op.name);
|
||||
Preferences.Default.Set("surname", op.surname);
|
||||
DisplayAlert("Neuer Barcode erkannt", op.name + " " + op.surname, "OK");
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
MainThread.InvokeOnMainThreadAsync(() => {
|
||||
DisplayAlert("Barcode bereits vorhanden",
|
||||
Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", ""),
|
||||
"OK");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
|
||||
x:Class="Jugenddienst_Stunden.Views.StundenPage"
|
||||
Title="StundenPage">
|
||||
Title="{Binding Title}">
|
||||
|
||||
<ContentPage.BindingContext>
|
||||
<models:StundenViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<VerticalStackLayout Spacing="10" Margin="15">
|
||||
<Label Text="{Binding Message}" />
|
||||
|
||||
@@ -20,11 +22,11 @@
|
||||
<Label Text="Überstunden Jahr:" Grid.Row="4" />
|
||||
|
||||
|
||||
<Label BackgroundColor="AliceBlue" Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Nominal}" />
|
||||
<Label BackgroundColor="AliceBlue" Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitDone}" />
|
||||
<Label BackgroundColor="AliceBlue" Grid.Row="2" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitCalculated}" />
|
||||
<Label BackgroundColor="AliceBlue" Grid.Row="3" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding OvertimeMonth}" />
|
||||
<Label BackgroundColor="AliceBlue" Grid.Row="4" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Overtime}" />
|
||||
<Label Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Nominal}" />
|
||||
<Label Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitDone}" />
|
||||
<Label Grid.Row="2" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitCalculated}" />
|
||||
<Label Grid.Row="3" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding OvertimeMonth}" />
|
||||
<Label Grid.Row="4" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Overtime}" />
|
||||
</Grid>
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
||||
@@ -1,9 +1,12 @@
|
||||
namespace Jugenddienst_Stunden.Views;
|
||||
|
||||
public partial class StundenPage : ContentPage
|
||||
{
|
||||
public StundenPage()
|
||||
{
|
||||
public partial class StundenPage : ContentPage {
|
||||
public StundenPage() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAppearing() {
|
||||
base.OnAppearing();
|
||||
Title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user