Settings so halb und a bissi aufgeräumt ...
This commit is contained in:
@@ -17,17 +17,17 @@ public static class MauiProgram {
|
|||||||
})
|
})
|
||||||
.UseBarcodeReader();
|
.UseBarcodeReader();
|
||||||
|
|
||||||
//Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cHM6Ly9zdHVuZGVuLmpkLWxhbmEtdGlzZW5zLml0L2FwcGFwaQ==");
|
#if DEBUG
|
||||||
//Preferences.Default.Set("name", "Default: Lea");
|
//Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
||||||
|
//Preferences.Default.Set("name", "Testserver: Lea");
|
||||||
//Preferences.Default.Set("surname", "Mair");
|
//Preferences.Default.Set("surname", "Mair");
|
||||||
//Preferences.Default.Set("EmployeeId", 3);
|
//Preferences.Default.Set("EmployeeId", 3);
|
||||||
//Preferences.Default.Set("apiUrl", "https://stunden.jd-lana-tisens.it/appapi");
|
//Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
||||||
|
|
||||||
#if DEBUG
|
Preferences.Default.Set("apiKey", "MTQxfHNkdFptQkNZTXlPT3ZyMHNBZDl0UnVxNExMRXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||||
Preferences.Default.Set("apiKey", "M3xneWlWNG85TmNIcmo1NnpxWkxVYS9JMDBFRlV8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
Preferences.Default.Set("name", "Testserver: Isabell");
|
||||||
Preferences.Default.Set("name", "Testserver: Lea");
|
Preferences.Default.Set("surname", "Biasi");
|
||||||
Preferences.Default.Set("surname", "Mair");
|
Preferences.Default.Set("EmployeeId", 141);
|
||||||
Preferences.Default.Set("EmployeeId", 3);
|
|
||||||
Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
||||||
|
|
||||||
builder.Logging.AddDebug();
|
builder.Logging.AddDebug();
|
||||||
|
|||||||
@@ -1,148 +0,0 @@
|
|||||||
using Jugenddienst_Stunden.Types;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
|
||||||
|
|
||||||
class Auth {
|
|
||||||
public static async Task<string?> GetApiDataWithAuthAsync(string url, string token) {
|
|
||||||
// Erstellen eines HttpClient-Objekts
|
|
||||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
// Senden der Anfrage und Abrufen der Antwort
|
|
||||||
using (HttpResponseMessage HttpResponseMessage = await client.GetAsync(url).ConfigureAwait(false)) {
|
|
||||||
// Überprüfen, ob die Anfrage erfolgreich war
|
|
||||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
|
||||||
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
|
||||||
// Lesen und Rückgabe der Antwort als String
|
|
||||||
string responseData = await HttpContent.ReadAsStringAsync();
|
|
||||||
return responseData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Stundeneintrag speichern
|
|
||||||
/// </summary>
|
|
||||||
public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
|
|
||||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
|
||||||
|
|
||||||
//Uhrzeiten sollten sinnvolle Werte haben
|
|
||||||
if (item.TimeSpanVon == item.TimeSpanBis) {
|
|
||||||
throw new Exception("Beginn und Ende sind gleich");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.TimeSpanBis < item.TimeSpanVon) {
|
|
||||||
throw new Exception("Ende ist vor Beginn");
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeSpan span = TimeSpan.Zero;
|
|
||||||
span += item.TimeSpanBis - item.TimeSpanVon;
|
|
||||||
if (span.Hours > 10) {
|
|
||||||
//Hier vielleicht eine Abfrage, ob mehr als 10 Stunden gesund sind?
|
|
||||||
}
|
|
||||||
|
|
||||||
//Gemeinde ist ein Pflichtfeld
|
|
||||||
if (item.GemeindeAktiv == null) {
|
|
||||||
throw new Exception("Gemeinde nicht gewählt");
|
|
||||||
}
|
|
||||||
//Projekt ist ein Pflichtfeld
|
|
||||||
if (item.ProjektAktiv == null) {
|
|
||||||
throw new Exception("Projekt nicht gewählt");
|
|
||||||
}
|
|
||||||
//Keine Beschreibung
|
|
||||||
if (string.IsNullOrEmpty(item.description)) {
|
|
||||||
throw new Exception("Keine Beschreibung");
|
|
||||||
}
|
|
||||||
//try {
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
|
||||||
|
|
||||||
string json = JsonSerializer.Serialize<DayTime>(item);
|
|
||||||
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
|
||||||
if (isNewItem)
|
|
||||||
response = await client.PostAsync(url, content);
|
|
||||||
else
|
|
||||||
response = await client.PutAsync(url, content);
|
|
||||||
|
|
||||||
//if (response.IsSuccessStatusCode)
|
|
||||||
// Debug.WriteLine(@"\tTodoItem successfully saved.");
|
|
||||||
if (!response.IsSuccessStatusCode) {
|
|
||||||
throw new Exception("Fehler beim Speichern " + response.Content);
|
|
||||||
}
|
|
||||||
//} catch (Exception ex) {
|
|
||||||
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task DeleteItemAsync(string url, string token) {
|
|
||||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
|
||||||
|
|
||||||
//try {
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
|
||||||
|
|
||||||
HttpResponseMessage response = await client.DeleteAsync(url);
|
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
throw new Exception("Fehler beim Löschen " + response.Content);
|
|
||||||
//if (response.IsSuccessStatusCode)
|
|
||||||
// Debug.WriteLine(@"\tTodoItem successfully deleted.");
|
|
||||||
//} catch (Exception ex) {
|
|
||||||
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<User> AuthUserPass(string user, string pass, string url) {
|
|
||||||
|
|
||||||
var values = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "user", user },
|
|
||||||
{ "pass", pass }
|
|
||||||
};
|
|
||||||
|
|
||||||
var content = new FormUrlEncodedContent(values);
|
|
||||||
|
|
||||||
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
||||||
|
|
||||||
// Senden der Anfrage und Abrufen der Antwort
|
|
||||||
using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) {
|
|
||||||
// Überprüfen, ob die Anfrage erfolgreich war
|
|
||||||
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
|
||||||
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
|
||||||
// Lesen und Rückgabe der Antwort als String
|
|
||||||
|
|
||||||
string responseData = await HttpContent.ReadAsStringAsync();
|
|
||||||
User userData = System.Text.Json.JsonSerializer.Deserialize<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
return userData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
180
Jugenddienst Stunden/Models/BaseFunc.cs
Normal file
180
Jugenddienst Stunden/Models/BaseFunc.cs
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
using Jugenddienst_Stunden.Types;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Jugenddienst_Stunden.Models;
|
||||||
|
|
||||||
|
internal static class BaseFunc {
|
||||||
|
|
||||||
|
|
||||||
|
internal static async Task<string> GetApiDataWithAuthAsync(string url, string token) {
|
||||||
|
|
||||||
|
if (Connectivity.Current.NetworkAccess == NetworkAccess.None)
|
||||||
|
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(token))
|
||||||
|
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||||
|
|
||||||
|
// Erstellen eines HttpClient-Objekts
|
||||||
|
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Senden der Anfrage und Abrufen der Antwort
|
||||||
|
using (HttpResponseMessage HttpResponseMessage = await client.GetAsync(url).ConfigureAwait(false)) {
|
||||||
|
var byteArray = await HttpResponseMessage.Content.ReadAsByteArrayAsync();
|
||||||
|
string responseData = Encoding.UTF8.GetString(byteArray);
|
||||||
|
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
||||||
|
//responseData = await HttpContent.ReadAsStringAsync();
|
||||||
|
}
|
||||||
|
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||||
|
return responseData;
|
||||||
|
} else {
|
||||||
|
var options = new JsonDocumentOptions {
|
||||||
|
AllowTrailingCommas = true
|
||||||
|
};
|
||||||
|
using (JsonDocument doc = JsonDocument.Parse(responseData, options)) {
|
||||||
|
JsonElement root = doc.RootElement;
|
||||||
|
string message = root.GetProperty("message").GetString() ?? throw new Exception("Fehler: 'message' ist null.");
|
||||||
|
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
internal static async Task<User> AuthUserPass(string user, string pass, string url) {
|
||||||
|
|
||||||
|
var values = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "user", user },
|
||||||
|
{ "pass", pass }
|
||||||
|
};
|
||||||
|
|
||||||
|
var content = new FormUrlEncodedContent(values);
|
||||||
|
|
||||||
|
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||||
|
|
||||||
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
|
|
||||||
|
// Senden der Anfrage und Abrufen der Antwort
|
||||||
|
using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) {
|
||||||
|
if (!HttpResponseMessage.IsSuccessStatusCode)
|
||||||
|
throw new Exception("Fehler beim Einloggen " + HttpResponseMessage.Content);
|
||||||
|
|
||||||
|
// Überprüfen, ob die Anfrage erfolgreich war
|
||||||
|
if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) {
|
||||||
|
using (HttpContent HttpContent = HttpResponseMessage.Content) {
|
||||||
|
// Lesen und Rückgabe der Antwort als String
|
||||||
|
|
||||||
|
string responseData = await HttpContent.ReadAsStringAsync();
|
||||||
|
User userData = System.Text.Json.JsonSerializer.Deserialize<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
internal static HoursBase Load(string filename) {
|
||||||
|
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||||
|
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||||
|
|
||||||
|
return
|
||||||
|
new() {
|
||||||
|
//Filename = Path.GetFileName(filename),
|
||||||
|
//Text = File.ReadAllText(filename),
|
||||||
|
Date = File.GetLastWriteTime(filename)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stundeneintrag speichern
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
|
||||||
|
|
||||||
|
|
||||||
|
//Uhrzeiten sollten sinnvolle Werte haben
|
||||||
|
if (item.TimeSpanVon == item.TimeSpanBis) {
|
||||||
|
throw new Exception("Beginn und Ende sind gleich");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.TimeSpanBis < item.TimeSpanVon) {
|
||||||
|
throw new Exception("Ende ist vor Beginn");
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeSpan span = TimeSpan.Zero;
|
||||||
|
span += item.TimeSpanBis - item.TimeSpanVon;
|
||||||
|
if (span.Hours > 10) {
|
||||||
|
//Hier vielleicht eine Abfrage, ob mehr als 10 Stunden gesund sind?
|
||||||
|
//Das müsste aber das ViewModel machen
|
||||||
|
}
|
||||||
|
|
||||||
|
//Gemeinde ist ein Pflichtfeld
|
||||||
|
if (item.GemeindeAktiv == null) {
|
||||||
|
throw new Exception("Gemeinde nicht gewählt");
|
||||||
|
}
|
||||||
|
//Projekt ist ein Pflichtfeld
|
||||||
|
if (item.ProjektAktiv == null) {
|
||||||
|
throw new Exception("Projekt nicht gewählt");
|
||||||
|
}
|
||||||
|
//Keine Beschreibung
|
||||||
|
if (string.IsNullOrEmpty(item.Description)) {
|
||||||
|
throw new Exception("Keine Beschreibung");
|
||||||
|
}
|
||||||
|
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||||
|
//HttpClient client = new HttpClient();
|
||||||
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
|
//string json = JsonSerializer.Serialize<DayTime>(item);
|
||||||
|
string json = JsonConvert.SerializeObject(item);
|
||||||
|
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
HttpResponseMessage? response = null;
|
||||||
|
if (isNewItem)
|
||||||
|
response = await client.PostAsync(url, content);
|
||||||
|
else
|
||||||
|
response = await client.PutAsync(url, content);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode) {
|
||||||
|
throw new Exception("Fehler beim Speichern " + response.Content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static async Task DeleteItemAsync(string url, string token) {
|
||||||
|
using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||||
|
|
||||||
|
//HttpClient client = new HttpClient();
|
||||||
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
|
HttpResponseMessage response = await client.DeleteAsync(url);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
throw new Exception("Fehler beim Löschen " + response.Content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
125
Jugenddienst Stunden/Models/HoursBase.cs
Normal file
125
Jugenddienst Stunden/Models/HoursBase.cs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
using Jugenddienst_Stunden.Types;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace Jugenddienst_Stunden.Models;
|
||||||
|
|
||||||
|
internal class HoursBase {
|
||||||
|
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
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", "");
|
||||||
|
|
||||||
|
internal static TokenData tokendata = new TokenData(apiKey);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Einstellungen
|
||||||
|
/// </summary>
|
||||||
|
internal async Task<Settings> LoadSettings() {
|
||||||
|
|
||||||
|
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?settings", tokendata.ApiKey);
|
||||||
|
|
||||||
|
Settings _settings = JsonConvert.DeserializeObject<Settings>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
|
||||||
|
return _settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Daten laden
|
||||||
|
/// </summary>
|
||||||
|
internal async Task<Hours> LoadData() {
|
||||||
|
|
||||||
|
Hours hours = new Hours();
|
||||||
|
|
||||||
|
var tokendata = new TokenData(apiKey);
|
||||||
|
|
||||||
|
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?hours", tokendata.ApiKey);
|
||||||
|
|
||||||
|
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
|
||||||
|
return hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Basisdaten: Mitarbeiterdaten, Projekte, Gemeinden, Freistellungen.
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task<Hours> LoadBasicData() {
|
||||||
|
|
||||||
|
Hours hours = new Hours();
|
||||||
|
|
||||||
|
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?basic", tokendata.ApiKey);
|
||||||
|
|
||||||
|
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
|
||||||
|
return hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Operator> LoadOperator(string apiKey) {
|
||||||
|
|
||||||
|
Operator OperatorVar = new Operator();
|
||||||
|
|
||||||
|
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url, tokendata.ApiKey);
|
||||||
|
|
||||||
|
OperatorVar = JsonConvert.DeserializeObject<Operator>(data);
|
||||||
|
Preferences.Default.Set("name", OperatorVar.name);
|
||||||
|
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||||
|
Preferences.Default.Set("apiUrl", tokendata.Url);
|
||||||
|
|
||||||
|
return OperatorVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Zeiten eines Tages holen
|
||||||
|
/// </summary>
|
||||||
|
internal async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||||
|
|
||||||
|
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.ApiKey);
|
||||||
|
|
||||||
|
//List<DayTime> daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
List<DayTime> daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
|
||||||
|
//List<DayTime> daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
|
||||||
|
return daytimes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Einzelnen Stundeneintrag holen
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task<DayTime> LoadEntry(int id) {
|
||||||
|
|
||||||
|
string data = await BaseFunc.GetApiDataWithAuthAsync(tokendata.Url + "?id=" + id, tokendata.ApiKey);
|
||||||
|
|
||||||
|
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||||
|
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||||
|
hours.TimeSpanVon = hours.Begin.ToTimeSpan();
|
||||||
|
hours.TimeSpanBis = hours.End.ToTimeSpan();
|
||||||
|
|
||||||
|
return hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Eintrag speichern
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||||
|
|
||||||
|
bool isNew = false;
|
||||||
|
if (stunde.Id == null)
|
||||||
|
isNew = true;
|
||||||
|
await BaseFunc.SaveItemAsync(tokendata.Url, tokendata.ApiKey, stunde, isNew);
|
||||||
|
|
||||||
|
return stunde;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Eintrag löschen
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task DeleteEntry(DayTime stunde) {
|
||||||
|
await BaseFunc.DeleteItemAsync(tokendata.Url + "/entry/" + stunde.Id, tokendata.ApiKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace Jugenddienst_Stunden.Models;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
|
||||||
internal class Note {
|
internal class Note {
|
||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
|
||||||
using Jugenddienst_Stunden.ViewModels;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
namespace Jugenddienst_Stunden.Models;
|
||||||
public class Operator : ObservableObject {
|
internal class Operator : HoursBase {
|
||||||
public string? id;
|
public string? id;
|
||||||
public string? name;
|
public string? name;
|
||||||
public string? surname;
|
public string? surname;
|
||||||
@@ -22,31 +19,5 @@ public class Operator : ObservableObject {
|
|||||||
|
|
||||||
public event EventHandler<string>? AlertEvent;
|
public event EventHandler<string>? AlertEvent;
|
||||||
|
|
||||||
public static async Task<Operator> LoadData(string apiKey) {
|
|
||||||
|
|
||||||
Operator OperatorVar = 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);
|
|
||||||
|
|
||||||
//try {
|
|
||||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
|
||||||
if (data == "\"Lalala\"") {
|
|
||||||
throw new Exception("Problem mit Token");
|
|
||||||
}
|
|
||||||
if (data != "null") {
|
|
||||||
OperatorVar = JsonConvert.DeserializeObject<Operator>(data);
|
|
||||||
Preferences.Default.Set("name", OperatorVar.name);
|
|
||||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
|
||||||
Preferences.Default.Set("apiUrl", tokendata.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return OperatorVar;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,211 +0,0 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Jugenddienst_Stunden.Types;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using Jugenddienst_Stunden.Exceptions;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
|
||||||
|
|
||||||
internal class Stunde : ObservableObject {
|
|
||||||
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
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() {
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(apiKey)) {
|
|
||||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
|
||||||
}
|
|
||||||
|
|
||||||
Hours hours = new Hours();
|
|
||||||
|
|
||||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
|
||||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
|
||||||
} else {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
if (data == "\"Lalala\"") {
|
|
||||||
throw new Exception("Problem mit Token");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data == null) {
|
|
||||||
throw new Exception("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
|
|
||||||
}
|
|
||||||
return hours;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Einstellungen
|
|
||||||
/// </summary>
|
|
||||||
public static async Task<Settings> LoadSettings()
|
|
||||||
{
|
|
||||||
|
|
||||||
Settings settings;
|
|
||||||
|
|
||||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None)
|
|
||||||
{
|
|
||||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var tokendata = new TokenData(apiKey);
|
|
||||||
|
|
||||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?settings", tokendata.apiKey);
|
|
||||||
|
|
||||||
if (data == "null")
|
|
||||||
{
|
|
||||||
throw new Exception("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
if (data == "\"Lalala\"")
|
|
||||||
{
|
|
||||||
throw new Exception("Problem mit Token");
|
|
||||||
}
|
|
||||||
if (data == null)
|
|
||||||
{
|
|
||||||
throw new Exception("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
settings = JsonConvert.DeserializeObject<Settings>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
|
|
||||||
}
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Basisdaten: Mitarbeiterdaten, Projekte, Gemeinden, Freistellungen.
|
|
||||||
/// </summary>
|
|
||||||
public static async Task<Hours> LoadBasicData() {
|
|
||||||
|
|
||||||
Hours hours = new Hours();
|
|
||||||
|
|
||||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
|
||||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
|
||||||
} else {
|
|
||||||
var tokendata = new TokenData(apiKey);
|
|
||||||
|
|
||||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?basic", tokendata.apiKey);
|
|
||||||
|
|
||||||
if (data == "null") {
|
|
||||||
throw new Exception("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
if (data == "\"Lalala\"") {
|
|
||||||
throw new Exception("Problem mit Token");
|
|
||||||
}
|
|
||||||
if (data == null) {
|
|
||||||
throw new Exception("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
|
|
||||||
}
|
|
||||||
return hours;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Zeiten eines Tages holen
|
|
||||||
/// </summary>
|
|
||||||
public static async Task<ObservableCollection<DayTime>> LoadDay(DateTime date) {
|
|
||||||
if (string.IsNullOrEmpty(apiKey)) {
|
|
||||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
|
||||||
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var tokendata = new TokenData(apiKey);
|
|
||||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
|
|
||||||
|
|
||||||
if (data == "null") {
|
|
||||||
throw new NoDataException("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
|
|
||||||
}
|
|
||||||
if (data == "\"Lalala\"") {
|
|
||||||
throw new Exception("Problem mit Token");
|
|
||||||
}
|
|
||||||
if (data == null) {
|
|
||||||
throw new NoDataException("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ObservableCollection<DayTime> daytimes = System.Text.Json.JsonSerializer.Deserialize<ObservableCollection<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
//daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
|
|
||||||
//List<DayTime> daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
|
|
||||||
return daytimes;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Einzelnen Stundeneintrag holen
|
|
||||||
/// </summary>
|
|
||||||
public static async Task<DayTime> LoadEntry(int id) {
|
|
||||||
|
|
||||||
var tokendata = new TokenData(apiKey);
|
|
||||||
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
|
|
||||||
|
|
||||||
if (data == null) {
|
|
||||||
throw new Exception("Keine Daten erhalten");
|
|
||||||
}
|
|
||||||
|
|
||||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
|
||||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
|
||||||
hours.TimeSpanVon = hours.begin.ToTimeSpan();
|
|
||||||
hours.TimeSpanBis = hours.end.ToTimeSpan();
|
|
||||||
|
|
||||||
return hours;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Stunde Load(string filename) {
|
|
||||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
|
||||||
|
|
||||||
if (!File.Exists(filename))
|
|
||||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
|
||||||
|
|
||||||
return
|
|
||||||
new() {
|
|
||||||
//Filename = Path.GetFileName(filename),
|
|
||||||
//Text = File.ReadAllText(filename),
|
|
||||||
Date = File.GetLastWriteTime(filename)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Eintrag speichern
|
|
||||||
/// </summary>
|
|
||||||
public static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
|
||||||
|
|
||||||
var tokendata = new TokenData(apiKey);
|
|
||||||
bool isNew = false;
|
|
||||||
if (stunde.id == null)
|
|
||||||
isNew = true;
|
|
||||||
await Auth.SaveItemAsync(tokendata.url, tokendata.apiKey, stunde, isNew);
|
|
||||||
|
|
||||||
return stunde;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Eintrag löschen
|
|
||||||
/// </summary>
|
|
||||||
public static async Task DeleteEntry(DayTime stunde) {
|
|
||||||
var tokendata = new TokenData(apiKey);
|
|
||||||
await Auth.DeleteItemAsync(tokendata.url + "/entry/" + stunde.id, tokendata.apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,17 +3,17 @@
|
|||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
namespace Jugenddienst_Stunden.Models;
|
||||||
|
|
||||||
class TokenData {
|
internal class TokenData {
|
||||||
public string token { get; set; }
|
public string Token { get; set; }
|
||||||
public string apiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
public string url { get; set; }
|
public string Url { get; set; }
|
||||||
public string operator_id { get; set; }
|
public string Operator_id { get; set; }
|
||||||
|
|
||||||
public TokenData(string ak) {
|
public TokenData(string ak) {
|
||||||
string dat = Encoding.UTF8.GetString(Convert.FromBase64String(ak));
|
string dat = Encoding.UTF8.GetString(Convert.FromBase64String(ak));
|
||||||
token = dat.Split('|')[1]; ;
|
Token = dat.Split('|')[1]; ;
|
||||||
url = dat.Split('|')[2]; ;
|
Url = dat.Split('|')[2]; ;
|
||||||
operator_id = dat.Split('|')[0]; ;
|
Operator_id = dat.Split('|')[0]; ;
|
||||||
apiKey = ak;
|
ApiKey = ak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
|
||||||
public struct Base {
|
|
||||||
public Collection<Projekt>? Projekte { get; set; }
|
|
||||||
public Collection<Gemeinde>? Gemeinden { get; set; }
|
|
||||||
public Collection<Freistellung>? Freistellungen { get; set; }
|
|
||||||
public int EmployeeId { get; set; }
|
|
||||||
|
|
||||||
public Hours Hours { get; set; }
|
|
||||||
public List<DayTime> daytime { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
using System.Collections.ObjectModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a day time entry for an employee.
|
/// Represents a day time entry for an employee.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DayTime
|
public class DayTime {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ID des Stundeneintrages
|
/// ID des Stundeneintrages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mitarbeiter-ID
|
/// Mitarbeiter-ID
|
||||||
@@ -19,92 +19,76 @@ public class DayTime
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Der betreffende Tag
|
/// Der betreffende Tag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime day { get; set; }
|
public DateTime Day { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Der Wochentag
|
/// Der Wochentag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int wday { get; set; }
|
public int Wday { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Arbeitsbeginn
|
/// Arbeitsbeginn
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeOnly begin { get; set; }
|
public TimeOnly Begin { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Arbeitsende
|
/// Arbeitsende
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeOnly end { get; set; }
|
public TimeOnly End { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Beschreibung der Arbeit
|
/// Beschreibung der Tätigkeit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Freistellung
|
/// Freistellung
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? free { get; set; }
|
public string? Free { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Freisetellung genehmigt?
|
/// Freistellung genehmigt?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? approved { get; set; }
|
public bool? Approved { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sollte nix sein
|
|
||||||
/// </summary>
|
|
||||||
public int? type { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Das gewählte Projekt
|
/// Das gewählte Projekt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? projekt { get; set; }
|
public int? Projekt { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Die gewählte Gemeinde
|
/// Die gewählte Gemeinde
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? gemeinde { get; set; }
|
public int? Gemeinde { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Nachtstunden
|
/// Nachtstunden
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeOnly night { get; set; }
|
public TimeOnly Night { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Summe Arbeitszeit (inklusive Nachstunden mit Faktor)
|
/// Summe Arbeitszeit (inklusive Nachstunden mit Faktor)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, TimeOnly> total { get; set; }
|
public Dictionary<string, TimeOnly> Total { get; set; }
|
||||||
public TimeOnly end_print { get; set; }
|
|
||||||
|
public TimeOnly End_print { get; set; }
|
||||||
public TimeSpan TimeSpanVon { get; set; }
|
public TimeSpan TimeSpanVon { get; set; }
|
||||||
public TimeSpan TimeSpanBis { 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; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the active Gemeinde based on the gemeinde ID.
|
/// Gets the active Gemeinde based on the gemeinde ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Gemeinde GemeindeAktiv { get; set; }
|
public Gemeinde? GemeindeAktiv { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the active Projekt based on the projekt ID.
|
/// Gets the active Projekt based on the projekt ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Projekt ProjektAktiv { get; set; }
|
public Projekt? ProjektAktiv { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the active Freistellung based on the Freistellung ID
|
/// Gets the active Freistellung based on the Freistellung ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Freistellung FreistellungAktiv { get; set; }
|
public Freistellung? FreistellungAktiv { get; set; }
|
||||||
|
|
||||||
public bool ProjektAktivSet { get; set; } = false;
|
|
||||||
public bool GemeindeAktivSet { get; set; } = false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class Gemeinde {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Eindeutige Id der Gemeinde.
|
/// Eindeutige Id der Gemeinde.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name der Gemeinde.
|
/// Name der Gemeinde.
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
|
|
||||||
public class Hours : ObservableObject {
|
internal class Hours : ObservableObject {
|
||||||
public string? zeit;
|
public string? Zeit;
|
||||||
public string? nominal;
|
public string? Nominal;
|
||||||
//public Dictionary<DateOnly,NominalDay> nominal_day_api;
|
//public Dictionary<DateOnly,NominalDay> nominal_day_api;
|
||||||
public List<NominalDay>? nominal_day_api;
|
public List<NominalDay>? Nominal_day_api;
|
||||||
//public Dictionary<int,NominalWeek> nominal_week_api;
|
//public Dictionary<int,NominalWeek> nominal_week_api;
|
||||||
public List<NominalWeek>? nominal_week_api;
|
public List<NominalWeek>? Nominal_week_api;
|
||||||
//public List<string> time_line;
|
//public List<string> time_line;
|
||||||
public string? zeit_total;
|
public string? Zeit_total;
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/29449641/deserialize-json-when-a-value-can-be-an-object-or-an-empty-array/29450279#29450279
|
//https://stackoverflow.com/questions/29449641/deserialize-json-when-a-value-can-be-an-object-or-an-empty-array/29450279#29450279
|
||||||
//[JsonConverter(typeof(JsonSingleOrEmptyArrayConverter<Hours>))]
|
//[JsonConverter(typeof(JsonSingleOrEmptyArrayConverter<Hours>))]
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
using System;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
using System.Collections.Generic;
|
internal class NominalDay {
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
|
||||||
public class NominalDay {
|
|
||||||
public int day_number;
|
public int day_number;
|
||||||
public int month_number;
|
public int month_number;
|
||||||
public decimal hours;
|
public decimal hours;
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
using System;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
internal class NominalWeek {
|
||||||
|
public int Week_number;
|
||||||
public class NominalWeek
|
public decimal Hours;
|
||||||
{
|
}
|
||||||
public int week_number;
|
|
||||||
public decimal hours;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class Projekt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holt oder setzt die eindeutige ID des Projekts.
|
/// Holt oder setzt die eindeutige ID des Projekts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holt oder setzt den Namen des Projekts.
|
/// Holt oder setzt den Namen des Projekts.
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
using System.Collections.ObjectModel;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Einstellungen
|
/// Einstellungen
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Settings
|
public class Settings {
|
||||||
{
|
/// <summary>
|
||||||
|
/// Sind Projekte aktiv?
|
||||||
|
/// </summary>
|
||||||
public bool ProjektAktivSet { get; set; }
|
public bool ProjektAktivSet { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sind Gemeinden aktiv?
|
||||||
|
/// </summary>
|
||||||
public bool GemeindeAktivSet { get; set; }
|
public bool GemeindeAktivSet { get; set; }
|
||||||
public Collection<Projekt> Projekte { get; set; }
|
|
||||||
public Collection<Gemeinde> Gemeinden { get; set; }
|
/// <summary>
|
||||||
public Collection<Freistellung> Freistellungen { get; set; }
|
/// Liste der Projekte
|
||||||
|
/// </summary>
|
||||||
|
public List<Projekt>? Projekte { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Liste der Gemeinden
|
||||||
|
/// </summary>
|
||||||
|
public List<Gemeinde>? Gemeinden { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Liste der Freistellungen
|
||||||
|
/// </summary>
|
||||||
|
public List<Freistellung>? Freistellungen { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Summe der geleisteten Stunden.
|
/// Summe der geleisteten Stunden.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct TimeDay {
|
internal struct TimeDay {
|
||||||
public int Day { get; set; }
|
public int Day { get; set; }
|
||||||
public decimal Hours { get; set; }
|
public decimal Hours { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
using System;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
internal class Timetable {
|
||||||
|
|
||||||
internal class Timetable
|
|
||||||
{
|
|
||||||
public List<TimetableEntry> timetable;
|
public List<TimetableEntry> timetable;
|
||||||
public decimal wochensumme;
|
public decimal wochensumme;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
using System;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Types;
|
internal class TimetableEntry {
|
||||||
|
public List<TimeOnly>? Von;
|
||||||
internal class TimetableEntry
|
public List<TimeOnly>? Bis;
|
||||||
{
|
public decimal Summe { get; set; }
|
||||||
public List<TimeOnly>? von;
|
}
|
||||||
public List<TimeOnly>? bis;
|
|
||||||
public decimal summe { get; set; }
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
using System;
|
namespace Jugenddienst_Stunden.Types;
|
||||||
using System.Collections.Generic;
|
internal class User {
|
||||||
using System.Linq;
|
public int Id { get; set; }
|
||||||
using System.Text;
|
public string Name { get; set; }
|
||||||
using System.Threading.Tasks;
|
public string Surname { get; set; }
|
||||||
|
public string Token { get; set; }
|
||||||
namespace Jugenddienst_Stunden.Types;
|
|
||||||
public class User {
|
|
||||||
public int id { get; set; }
|
|
||||||
public string name { get; set; }
|
|
||||||
public string surname { get; set; }
|
|
||||||
public string token { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,100 +1,68 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Jugenddienst_Stunden.Models;
|
||||||
using Jugenddienst_Stunden.Types;
|
using Jugenddienst_Stunden.Types;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.ViewModels;
|
namespace Jugenddienst_Stunden.ViewModels;
|
||||||
internal class StundeViewModel : ObservableObject, IQueryAttributable
|
public class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||||
{
|
|
||||||
|
|
||||||
public int id { get; set; }
|
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Title { get; set; } = "Eintrag bearbeiten";
|
||||||
public string SubTitle { get; set; } = DateTime.Today.ToString("dddd, d. MMMM yyyy");
|
public string SubTitle { get; set; } = DateTime.Today.ToString("dddd, d. MMMM yyyy");
|
||||||
|
|
||||||
private Settings _settings;
|
private HoursBase HoursBase = new HoursBase();
|
||||||
public Settings Settings
|
internal Settings Settings = new Settings();
|
||||||
{
|
|
||||||
get => _settings; set
|
|
||||||
{
|
|
||||||
if (_settings != value)
|
|
||||||
{
|
|
||||||
_settings = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private DayTime _stunde;
|
|
||||||
public DayTime Stunde
|
|
||||||
{
|
|
||||||
get => _stunde;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_stunde != value)
|
|
||||||
{
|
|
||||||
_stunde = value;
|
|
||||||
OnPropertyChanged(nameof(Stunde));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Title { get; set; } = "Eintrag bearbeiten";
|
|
||||||
|
|
||||||
public event EventHandler<string> AlertEvent;
|
public event EventHandler<string> AlertEvent;
|
||||||
public event EventHandler<string> InfoEvent;
|
public event EventHandler<string> InfoEvent;
|
||||||
public event Func<string, string, Task<bool>> ConfirmEvent;
|
public event Func<string, string, Task<bool>> ConfirmEvent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gemeinden für die Auswahlliste
|
||||||
|
/// </summary>
|
||||||
|
public List<Gemeinde> OptionsGemeinde { get; private set; }
|
||||||
|
|
||||||
public ObservableCollection<Gemeinde> OptionsGemeinde { get; private set; }
|
/// <summary>
|
||||||
public ObservableCollection<Projekt> OptionsProjekt { get; private set; }
|
/// Projekte für die Auswahlliste
|
||||||
public ObservableCollection<Freistellung> OptionsFreistellung { get; private set; }
|
/// </summary>
|
||||||
public ObservableCollection<DayTime> DayTimes { get; set; }
|
public List<Projekt> OptionsProjekt { get; private set; }
|
||||||
|
|
||||||
//private Gemeinde _selectedGemeinde;
|
/// <summary>
|
||||||
public Gemeinde SelectedOptionGemeinde
|
/// Freistellungen für die Auswahlliste
|
||||||
{
|
/// </summary>
|
||||||
get => _stunde.GemeindeAktiv;
|
public List<Freistellung> OptionsFreistellung { get; private set; }
|
||||||
set
|
|
||||||
{
|
/// <summary>
|
||||||
if (_stunde.GemeindeAktiv != value)
|
/// Vorhandene Zeiten anzeigen, wenn neuer Eintrag erstellt wird
|
||||||
{
|
/// </summary>
|
||||||
//_selectedGemeinde = value;
|
public List<DayTime> DayTimes { get; set; }
|
||||||
_stunde.GemeindeAktiv = value;
|
|
||||||
OnPropertyChanged(nameof(SelectedOptionGemeinde));
|
private DayTime _dayTime;
|
||||||
}
|
/// <summary>
|
||||||
|
/// Aktueller Stundeneintrag
|
||||||
|
/// </summary>
|
||||||
|
public DayTime DayTime {
|
||||||
|
get => _dayTime;
|
||||||
|
set {
|
||||||
|
if (_dayTime != value) {
|
||||||
|
_dayTime = value;
|
||||||
|
|
||||||
|
}OnPropertyChanged(nameof(DayTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private Projekt _selectedProjekt;
|
|
||||||
public Projekt SelectedOptionProjekt
|
|
||||||
{
|
|
||||||
get => _stunde.ProjektAktiv;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_stunde.ProjektAktiv != value)
|
|
||||||
{
|
|
||||||
//_selectedProjekt = value;
|
|
||||||
_stunde.ProjektAktiv = value;
|
|
||||||
OnPropertyChanged(nameof(SelectedOptionProjekt));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//private Freistellung _selectedFreistellung;
|
|
||||||
public Freistellung SelectedOptionFreistellung
|
|
||||||
{
|
|
||||||
get => _stunde.FreistellungAktiv;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_stunde.FreistellungAktiv != value)
|
|
||||||
{
|
|
||||||
_stunde.FreistellungAktiv = value;
|
|
||||||
OnPropertyChanged(nameof(SelectedOptionFreistellung));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dürfen Gemeinden verwendet werden?
|
||||||
|
/// </summary>
|
||||||
|
public bool GemeindeAktivSet { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dürfen Projekte verwendet werden?
|
||||||
|
/// </summary>
|
||||||
|
public bool ProjektAktivSet { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -104,156 +72,131 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable
|
|||||||
//public ICommand LoadDataCommand { get; private set; }
|
//public ICommand LoadDataCommand { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public StundeViewModel()
|
public StundeViewModel() {
|
||||||
{
|
DayTime = new DayTime();
|
||||||
_stunde = new DayTime();
|
|
||||||
|
|
||||||
SaveCommand = new AsyncRelayCommand(Save);
|
SaveCommand = new AsyncRelayCommand(Save);
|
||||||
//DeleteCommand = new AsyncRelayCommand(Delete);
|
//DeleteCommand = new AsyncRelayCommand(Delete);
|
||||||
DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
|
DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
|
||||||
|
LoadSettingsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StundeViewModel(DayTime stunde)
|
public StundeViewModel(DayTime stunde) {
|
||||||
{
|
DayTime = new DayTime();
|
||||||
_stunde = stunde;
|
|
||||||
|
|
||||||
SaveCommand = new AsyncRelayCommand(Save);
|
SaveCommand = new AsyncRelayCommand(Save);
|
||||||
DeleteConfirmCommand = new AsyncRelayCommand(DeleteConfirm);
|
DeleteConfirmCommand = new AsyncRelayCommand(DeleteConfirm);
|
||||||
|
LoadSettingsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadData()
|
private async void LoadSettingsAsync() {
|
||||||
{
|
Settings = await HoursBase.LoadSettings();
|
||||||
try
|
|
||||||
{
|
OptionsGemeinde = Settings.Gemeinden;
|
||||||
Hours _hours = await Models.Stunde.LoadBasicData();
|
OptionsProjekt = Settings.Projekte;
|
||||||
OptionsProjekt = new ObservableCollection<Projekt>(_hours.Projekte);
|
OptionsFreistellung = Settings.Freistellungen;
|
||||||
OptionsGemeinde = new ObservableCollection<Gemeinde>(_hours.Gemeinden);
|
|
||||||
OptionsFreistellung = new ObservableCollection<Freistellung>(_hours.Freistellungen);
|
GemeindeAktivSet = Settings.GemeindeAktivSet;
|
||||||
|
ProjektAktivSet = Settings.ProjektAktivSet;
|
||||||
|
|
||||||
OnPropertyChanged(nameof(OptionsGemeinde));
|
OnPropertyChanged(nameof(OptionsGemeinde));
|
||||||
OnPropertyChanged(nameof(OptionsProjekt));
|
|
||||||
OnPropertyChanged(nameof(OptionsFreistellung));
|
OnPropertyChanged(nameof(OptionsFreistellung));
|
||||||
_stunde.EmployeeId = _hours.EmployeeId;
|
OnPropertyChanged(nameof(OptionsProjekt));
|
||||||
|
|
||||||
|
OnPropertyChanged(nameof(GemeindeAktivSet));
|
||||||
|
OnPropertyChanged(nameof(ProjektAktivSet));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
private async Task LoadData() {
|
||||||
|
try {
|
||||||
|
Hours _hours = await Models.HoursBase.LoadBasicData();
|
||||||
|
DayTime.EmployeeId = _hours.EmployeeId;
|
||||||
|
} catch (Exception e) {
|
||||||
AlertEvent?.Invoke(this, e.Message);
|
AlertEvent?.Invoke(this, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task Save()
|
async Task Save() {
|
||||||
{
|
|
||||||
bool exceptionOccurred = false;
|
bool exceptionOccurred = false;
|
||||||
try
|
try {
|
||||||
{
|
await Models.HoursBase.SaveEntry(DayTime);
|
||||||
await Models.Stunde.SaveEntry(_stunde);
|
} catch (Exception e) {
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
AlertEvent?.Invoke(this, e.Message);
|
AlertEvent?.Invoke(this, e.Message);
|
||||||
exceptionOccurred = true;
|
exceptionOccurred = true;
|
||||||
}
|
}
|
||||||
if (!exceptionOccurred)
|
if (!exceptionOccurred) {
|
||||||
{
|
if (DayTime.Id != null) {
|
||||||
if (_stunde.id != null)
|
await Shell.Current.GoToAsync($"..?saved={DayTime.Id}");
|
||||||
{
|
} else {
|
||||||
await Shell.Current.GoToAsync($"..?saved={_stunde.id}");
|
await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Delete()
|
private async Task Delete() {
|
||||||
{
|
await Models.HoursBase.DeleteEntry(DayTime);
|
||||||
await Models.Stunde.DeleteEntry(_stunde);
|
await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}");
|
||||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DeleteConfirm()
|
private async Task DeleteConfirm() {
|
||||||
{
|
if (ConfirmEvent != null) {
|
||||||
if (ConfirmEvent != null)
|
|
||||||
{
|
|
||||||
bool answer = await ConfirmEvent.Invoke("Achtung", "Löschen kann nicht ungeschehen gemacht werden. Fortfahren?");
|
bool answer = await ConfirmEvent.Invoke("Achtung", "Löschen kann nicht ungeschehen gemacht werden. Fortfahren?");
|
||||||
if (answer)
|
if (answer) {
|
||||||
{
|
|
||||||
//Löschen
|
//Löschen
|
||||||
await Models.Stunde.DeleteEntry(_stunde);
|
await Models.HoursBase.DeleteEntry(DayTime);
|
||||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
await Shell.Current.GoToAsync($"..?date={DayTime.Day.ToString("yyyy-MM-dd")}");
|
||||||
}
|
} else { //nicht Löschen
|
||||||
else
|
|
||||||
{ //nicht Löschen
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task LoadSettings()
|
|
||||||
{
|
|
||||||
Settings = await Models.Stunde.LoadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Anwenden der Query-Parameter
|
/// Anwenden der Query-Parameter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
|
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||||
{
|
|
||||||
await LoadSettings();
|
|
||||||
var probe = query;
|
var probe = query;
|
||||||
if (query.ContainsKey("load"))
|
if (query.ContainsKey("load")) {
|
||||||
{
|
|
||||||
|
|
||||||
//DateTime heute = DateTime.Now;
|
//DateTime heute = DateTime.Now;
|
||||||
Stunde = await Models.Stunde.LoadEntry(Convert.ToInt32(query["load"]));
|
_dayTime = await Models.HoursBase.LoadEntry(Convert.ToInt32(query["load"]));
|
||||||
if (System.String.IsNullOrEmpty(Stunde.description))
|
if (System.String.IsNullOrEmpty(DayTime.Description)) {
|
||||||
{
|
|
||||||
AlertEvent?.Invoke(this, "Eintrag hat keine Daten zurückgegeben");
|
AlertEvent?.Invoke(this, "Eintrag hat keine Daten zurückgegeben");
|
||||||
}
|
}
|
||||||
SubTitle = Stunde.day.ToString("dddd, d. MMMM yyyy");
|
SubTitle = DayTime.Day.ToString("dddd, d. MMMM yyyy");
|
||||||
|
|
||||||
OptionsProjekt = new ObservableCollection<Projekt>(Stunde.Projekte);
|
|
||||||
OptionsGemeinde = new ObservableCollection<Gemeinde>(Stunde.Gemeinden);
|
|
||||||
OptionsFreistellung = new ObservableCollection<Freistellung>(Stunde.Freistellungen);
|
|
||||||
OnPropertyChanged(nameof(OptionsGemeinde));
|
|
||||||
OnPropertyChanged(nameof(OptionsProjekt));
|
|
||||||
OnPropertyChanged(nameof(OptionsFreistellung));
|
|
||||||
|
|
||||||
//OptionsProjekt.FirstOrDefault(x => x.Id == _stunde.projekt);
|
_dayTime.GemeindeAktiv = OptionsGemeinde.FirstOrDefault(Gemeinde => Gemeinde.Id == DayTime.Gemeinde) ?? new Gemeinde();
|
||||||
|
|
||||||
SelectedOptionGemeinde = OptionsGemeinde.FirstOrDefault(item => item.Id == Stunde.gemeinde) ?? new Gemeinde();
|
_dayTime.ProjektAktiv = OptionsProjekt.FirstOrDefault(Projekt => Projekt.Id == DayTime.Projekt) ?? new Projekt();
|
||||||
OnPropertyChanged(nameof(SelectedOptionGemeinde));
|
|
||||||
|
|
||||||
SelectedOptionProjekt = OptionsProjekt.FirstOrDefault(Projekt => Projekt.Id == Stunde.projekt) ?? new Projekt();
|
_dayTime.FreistellungAktiv = OptionsFreistellung.FirstOrDefault(Freistellung => Freistellung.Id == DayTime.Free) ?? new Freistellung();
|
||||||
OnPropertyChanged(nameof(SelectedOptionProjekt));
|
|
||||||
|
|
||||||
SelectedOptionFreistellung = OptionsFreistellung.FirstOrDefault(Freistellung => Freistellung.Id == Stunde.free) ?? new Freistellung();
|
|
||||||
OnPropertyChanged(nameof(SelectedOptionFreistellung));
|
|
||||||
|
|
||||||
|
OnPropertyChanged(nameof(DayTime));
|
||||||
|
|
||||||
OnPropertyChanged(nameof(SubTitle));
|
OnPropertyChanged(nameof(SubTitle));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (query.ContainsKey("date"))
|
if (query.ContainsKey("date")) {
|
||||||
{
|
|
||||||
Title = "Neuer Eintrag";
|
Title = "Neuer Eintrag";
|
||||||
|
|
||||||
DateTime _date = DateTime.ParseExact((string)query["date"], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
|
DateTime _date = DateTime.ParseExact((string)query["date"], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
//Bei neuem Eintrag die vorhandenen des gleichen Tages anzeigen
|
//Bei neuem Eintrag die vorhandenen des gleichen Tages anzeigen
|
||||||
try
|
try {
|
||||||
{
|
DayTimes = await HoursBase.LoadDay(_date);
|
||||||
DayTimes = await Models.Stunde.LoadDay(_date);
|
} catch (Exception) {
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
//Ein Tag ohne Einträge gibt eine Fehlermeldung,
|
//Ein Tag ohne Einträge gibt eine Fehlermeldung,
|
||||||
//die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht
|
//die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht
|
||||||
}
|
}
|
||||||
|
|
||||||
_stunde.day = _date;
|
DayTime.Day = _date;
|
||||||
SubTitle = _date.ToString("dddd, d. MMMM yyyy");
|
SubTitle = _date.ToString("dddd, d. MMMM yyyy");
|
||||||
|
|
||||||
_ = LoadData();
|
_ = LoadData();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Jugenddienst_Stunden.Models;
|
||||||
using Jugenddienst_Stunden.Types;
|
using Jugenddienst_Stunden.Types;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
@@ -10,15 +11,12 @@ using System.Windows.Input;
|
|||||||
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.ViewModels;
|
namespace Jugenddienst_Stunden.ViewModels;
|
||||||
internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged
|
/// <summary>
|
||||||
{
|
/// Stundenliste
|
||||||
public string Name => AppInfo.Name;
|
/// </summary>
|
||||||
public string Surname => AppInfo.VersionString;
|
internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged {
|
||||||
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 string LoadOverview => "Lade Summen für " + DateTime.Today.ToString("MMMM");
|
||||||
//public static DateTime GetDay = DateTime.Today;
|
|
||||||
//public string ShowDay => "Zeit an Tag " + GetDay.ToString("ddd d. MMM") + ": ";
|
|
||||||
|
|
||||||
public ICommand NewEntryCommand { get; }
|
public ICommand NewEntryCommand { get; }
|
||||||
public ICommand SelectEntryCommand { get; }
|
public ICommand SelectEntryCommand { get; }
|
||||||
@@ -30,32 +28,19 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
public event EventHandler<string> AlertEvent;
|
public event EventHandler<string> AlertEvent;
|
||||||
public event EventHandler<string> InfoEvent;
|
public event EventHandler<string> InfoEvent;
|
||||||
|
|
||||||
private Settings Settings { get; set; }
|
private HoursBase HoursBase = new HoursBase();
|
||||||
|
internal Settings Settings = new Settings();
|
||||||
|
|
||||||
private bool isRefreshing;
|
|
||||||
public bool IsRefreshing
|
|
||||||
{
|
|
||||||
get => isRefreshing;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (isRefreshing != value)
|
|
||||||
{
|
|
||||||
isRefreshing = value;
|
|
||||||
OnPropertyChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string _title = Preferences.Default.Get("name", "") + " " + Preferences.Default.Get("surname", "");
|
|
||||||
public string Title
|
private string _title = HoursBase.name + " " + HoursBase.surname;
|
||||||
{
|
public string Title {
|
||||||
get => _title;
|
get => _title;
|
||||||
set => SetProperty(ref _title, value);
|
set => SetProperty(ref _title, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hours _hour;
|
private Hours _hour;
|
||||||
public Hours Hours
|
public Hours Hours {
|
||||||
{
|
|
||||||
get => _hour;
|
get => _hour;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,26 +52,26 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Liste der Tageszeiten
|
/// Liste der Tageszeiten
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private ObservableCollection<DayTime> _dayTimes = new ObservableCollection<DayTime>();
|
private List<DayTime> _dayTimes = new List<DayTime>();
|
||||||
public ObservableCollection<DayTime> DayTimes
|
public List<DayTime> DayTimes {
|
||||||
{
|
|
||||||
get => _dayTimes;
|
get => _dayTimes;
|
||||||
set => SetProperty(ref _dayTimes, value);
|
set {
|
||||||
|
SetProperty(ref _dayTimes, value);
|
||||||
|
OnPropertyChanged(nameof(DayTimes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mindest-Datum für den Datepicker
|
/// Mindest-Datum für den Datepicker
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime MinimumDate
|
public DateTime MinimumDate {
|
||||||
{
|
|
||||||
get => DateTime.Today.AddDays(-365);
|
get => DateTime.Today.AddDays(-365);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Höchst-Datum für den Datepicker
|
/// Höchst-Datum für den Datepicker
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime MaximumDate
|
public DateTime MaximumDate {
|
||||||
{
|
|
||||||
get => DateTime.Today.AddDays(60);
|
get => DateTime.Today.AddDays(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,13 +79,10 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
/// Heutiges Datum, wenn das Datum geändert wird, wird auch der Tag geladen
|
/// Heutiges Datum, wenn das Datum geändert wird, wird auch der Tag geladen
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DateTime dateToday = DateTime.Today;
|
private DateTime dateToday = DateTime.Today;
|
||||||
public DateTime DateToday
|
public DateTime DateToday {
|
||||||
{
|
|
||||||
get => dateToday;
|
get => dateToday;
|
||||||
set
|
set {
|
||||||
{
|
if (dateToday != value) {
|
||||||
if (dateToday != value)
|
|
||||||
{
|
|
||||||
dateToday = value;
|
dateToday = value;
|
||||||
//GetDay = value;
|
//GetDay = value;
|
||||||
//OnPropertyChanged();
|
//OnPropertyChanged();
|
||||||
@@ -113,56 +95,69 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Monatsübersicht: Geleistete Stunden
|
/// Monatsübersicht: Geleistete Stunden
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ZeitCalculated
|
public string? ZeitCalculated {
|
||||||
{
|
get => Hours.Zeit_total;
|
||||||
get => _hour.zeit_total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Monatsübersicht: Sollstunden
|
/// Monatsübersicht: Sollstunden
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Nominal
|
public string? Nominal {
|
||||||
{
|
get => Hours.Nominal;
|
||||||
get => _hour.nominal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Monatsübersicht: Differenz zwischen Soll und geleisteten Stunden
|
/// Monatsübersicht: Differenz zwischen Soll und geleisteten Stunden
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Overtime
|
public string? Overtime {
|
||||||
{
|
get => Hours.overtime;
|
||||||
get => _hour.overtime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Monatsübersicht: Restüberstunden insgesamt
|
/// Monatsübersicht: Restüberstunden insgesamt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OvertimeMonth
|
public string OvertimeMonth {
|
||||||
{
|
get => Hours.overtime_month;
|
||||||
get => _hour.overtime_month;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Monatsübersicht: Resturlaub
|
/// Monatsübersicht: Resturlaub
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Holiday
|
public string Holiday {
|
||||||
{
|
get => Hours.holiday;
|
||||||
get => _hour.holiday;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Seite neu laden
|
||||||
|
/// </summary>
|
||||||
|
private bool isRefreshing;
|
||||||
|
public bool IsRefreshing {
|
||||||
|
get => isRefreshing;
|
||||||
|
set {
|
||||||
|
if (isRefreshing != value) {
|
||||||
|
isRefreshing = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dürfen Gemeinden verwendet werden?
|
||||||
|
/// </summary>
|
||||||
|
public bool GemeindeAktivSet { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dürfen Projekte verwendet werden?
|
||||||
|
/// </summary>
|
||||||
|
public bool ProjektAktivSet { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CTOR
|
/// CTOR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StundenViewModel()
|
public StundenViewModel() {
|
||||||
{
|
_hour = new Hours();
|
||||||
|
|
||||||
_hour = new Types.Hours();
|
|
||||||
|
|
||||||
LoadDataCommand = new AsyncRelayCommand(LoadData);
|
LoadDataCommand = new AsyncRelayCommand(LoadData);
|
||||||
NewEntryCommand = new AsyncRelayCommand(NewEntryAsync);
|
NewEntryCommand = new AsyncRelayCommand(NewEntryAsync);
|
||||||
@@ -171,18 +166,24 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
RefreshCommand = new Command(async () => await RefreshItemsAsync());
|
RefreshCommand = new Command(async () => await RefreshItemsAsync());
|
||||||
|
|
||||||
Task task = LoadDay(DateTime.Today);
|
Task task = LoadDay(DateTime.Today);
|
||||||
|
LoadSettingsAsync();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void LoadSettingsAsync() {
|
||||||
|
Settings = await HoursBase.LoadSettings();
|
||||||
|
|
||||||
|
GemeindeAktivSet = Settings.GemeindeAktivSet;
|
||||||
|
ProjektAktivSet = Settings.ProjektAktivSet;
|
||||||
|
|
||||||
|
OnPropertyChanged(nameof(GemeindeAktivSet));
|
||||||
|
OnPropertyChanged(nameof(ProjektAktivSet));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Öffnet eine neue Stundeneingabe
|
/// Öffnet eine neue Stundeneingabe
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
private async Task NewEntryAsync() {
|
||||||
private async Task NewEntryAsync()
|
|
||||||
{
|
|
||||||
//Hier muss das Datum übergeben werden
|
//Hier muss das Datum übergeben werden
|
||||||
//await Shell.Current.GoToAsync(nameof(Views.StundePage));
|
//await Shell.Current.GoToAsync(nameof(Views.StundePage));
|
||||||
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?date={dateToday:yyyy-MM-dd}");
|
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?date={dateToday:yyyy-MM-dd}");
|
||||||
@@ -191,99 +192,72 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Öffnet eine bestehende Stundeneingabe
|
/// Öffnet eine bestehende Stundeneingabe
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entry"></param>
|
private async Task SelectEntryAsync(DayTime entry) {
|
||||||
/// <returns></returns>
|
if (entry != null && entry.Id != null) {
|
||||||
private async Task SelectEntryAsync(DayTime entry)
|
|
||||||
{
|
|
||||||
if (entry != null && entry.id != null)
|
|
||||||
{
|
|
||||||
//var navigationParameters = new Dictionary<string, object> { { "load", entry.id } };
|
//var navigationParameters = new Dictionary<string, object> { { "load", entry.id } };
|
||||||
//await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}", navigationParameters);
|
//await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}", navigationParameters);
|
||||||
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?load={entry.id}");
|
await Shell.Current.GoToAsync($"{nameof(Views.StundePage)}?load={entry.Id}");
|
||||||
}
|
} else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
|
||||||
else AlertEvent?.Invoke(this, "Auswahl enthält keine Daten");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RefreshList()
|
private async Task RefreshList() {
|
||||||
{
|
|
||||||
OnPropertyChanged(nameof(DayTimes));
|
OnPropertyChanged(nameof(DayTimes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lädt die Monatssummen für die Übersicht
|
/// Lädt die Monatssummen für die Übersicht
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
private async Task LoadData() {
|
||||||
private async Task LoadData()
|
try {
|
||||||
{
|
_hour = await HoursBase.LoadData();
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
_hour = await Models.Stunde.LoadData();
|
|
||||||
RefreshProperties();
|
RefreshProperties();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
AlertEvent?.Invoke(this, e.Message);
|
AlertEvent?.Invoke(this, e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lädt die Arbeitszeiten für einen Tag
|
/// Lädt die Arbeitszeiten für einen Tag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="date"></param>
|
public async Task LoadDay(DateTime date) {
|
||||||
/// <returns></returns>
|
|
||||||
public async Task LoadDay(DateTime date)
|
|
||||||
{
|
|
||||||
DayTotal = new TimeOnly(0);
|
DayTotal = new TimeOnly(0);
|
||||||
|
LoadSettingsAsync();
|
||||||
try
|
try {
|
||||||
{
|
DayTimes = await HoursBase.LoadDay(date);
|
||||||
await LoadSettings();
|
|
||||||
DayTimes = await Models.Stunde.LoadDay(date);
|
|
||||||
|
|
||||||
//TODO: Hier muss noch die Berechnung der Stunden erfolgen
|
//TODO: Hier muss noch die Berechnung der Stunden erfolgen
|
||||||
//Es werden im Moment nur die eingetragenen Stunden gezählt
|
//Es werden im Moment nur die eingetragenen Stunden gezählt
|
||||||
//Auf der Website bekommt der Benutzer hingegen die berechneten Stunden angezeigt (Nachstunden außerhalb des Stundenplanes zählen mehr ...)
|
//Auf der Website bekommt der Benutzer hingegen die berechneten Stunden angezeigt (Nachstunden außerhalb des Stundenplanes zählen mehr ...)
|
||||||
|
|
||||||
TimeSpan span = TimeSpan.Zero;
|
TimeSpan span = TimeSpan.Zero;
|
||||||
foreach (DayTime dt in DayTimes)
|
foreach (DayTime dt in DayTimes) {
|
||||||
{
|
span += dt.End - dt.Begin;
|
||||||
span += dt.end - dt.begin;
|
|
||||||
}
|
}
|
||||||
DayTotal = TimeOnly.FromTimeSpan(span);
|
DayTotal = TimeOnly.FromTimeSpan(span);
|
||||||
|
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
DayTimes = new List<DayTime>();
|
||||||
{
|
|
||||||
DayTimes = new ObservableCollection<DayTime>();
|
|
||||||
//TODO: hier könnte auch ein Fehler kommen, dann wäre InfoEvent falsch.
|
//TODO: hier könnte auch ein Fehler kommen, dann wäre InfoEvent falsch.
|
||||||
InfoEvent?.Invoke(this, e.Message);
|
InfoEvent?.Invoke(this, e.Message);
|
||||||
}
|
} finally {
|
||||||
finally
|
|
||||||
{
|
|
||||||
OnPropertyChanged(nameof(DayTotal));
|
OnPropertyChanged(nameof(DayTotal));
|
||||||
//OnPropertyChanged(nameof(DayTimes));
|
//OnPropertyChanged(nameof(DayTimes));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadSettings()
|
|
||||||
{
|
|
||||||
Settings = await Models.Stunde.LoadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
|
|
||||||
{
|
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||||
if (query.ContainsKey("date"))
|
if (query.ContainsKey("date")) {
|
||||||
{
|
|
||||||
await LoadDay(Convert.ToDateTime(query["date"]));
|
await LoadDay(Convert.ToDateTime(query["date"]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task RefreshItemsAsync()
|
private async Task RefreshItemsAsync() {
|
||||||
{
|
|
||||||
IsRefreshing = true;
|
IsRefreshing = true;
|
||||||
|
|
||||||
// Fügen Sie hier die Logik zum Aktualisieren der Daten hinzu
|
// Fügen Sie hier die Logik zum Aktualisieren der Daten hinzu
|
||||||
@@ -296,8 +270,7 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Refreshes all properties
|
/// Refreshes all properties
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RefreshProperties()
|
private void RefreshProperties() {
|
||||||
{
|
|
||||||
OnPropertyChanged(nameof(Nominal));
|
OnPropertyChanged(nameof(Nominal));
|
||||||
OnPropertyChanged(nameof(Overtime));
|
OnPropertyChanged(nameof(Overtime));
|
||||||
OnPropertyChanged(nameof(OvertimeMonth));
|
OnPropertyChanged(nameof(OvertimeMonth));
|
||||||
@@ -309,14 +282,10 @@ internal class StundenViewModel : ObservableObject, IQueryAttributable, INotifyP
|
|||||||
OnPropertyChanged(nameof(MaximumDate));
|
OnPropertyChanged(nameof(MaximumDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
base.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
AlertEvent?.Invoke(this, ex.Message);
|
AlertEvent?.Invoke(this, ex.Message);
|
||||||
//Console.WriteLine($"Fehler bei OnPropertyChanged: {ex.Message}");
|
//Console.WriteLine($"Fehler bei OnPropertyChanged: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,19 +49,19 @@ public partial class LoginPage : ContentPage {
|
|||||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||||
_lastDetectionTime = currentTime;
|
_lastDetectionTime = currentTime;
|
||||||
foreach (var barcode in e.Results) {
|
foreach (var barcode in e.Results) {
|
||||||
if (Stunde.apiKey != barcode.Value) {
|
if (HoursBase.apiKey != barcode.Value) {
|
||||||
_ = MainThread.InvokeOnMainThreadAsync(async () => {
|
_ = MainThread.InvokeOnMainThreadAsync(async () => {
|
||||||
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
//await DisplayAlert("Barcode erkannt", $"Barcode: {barcode.Format} - {barcode.Value}", "OK");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var tokendata = new TokenData(barcode.Value);
|
var tokendata = new TokenData(barcode.Value);
|
||||||
var op = await Models.Operator.LoadData(barcode.Value);
|
var op = await Models.HoursBase.LoadOperator(barcode.Value);
|
||||||
Models.Stunde.apiKey = barcode.Value;
|
Models.HoursBase.apiKey = barcode.Value;
|
||||||
Models.Stunde.name = op.name;
|
Models.HoursBase.name = op.name;
|
||||||
Models.Stunde.surname = op.surname;
|
Models.HoursBase.surname = op.surname;
|
||||||
Models.Stunde.EmployeeId = int.Parse(op.id);
|
Models.HoursBase.EmployeeId = int.Parse(op.id);
|
||||||
Title = op.name + " " + op.surname;
|
Title = op.name + " " + op.surname;
|
||||||
ServerLabel.Text = "Server: " + tokendata.url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||||
|
|
||||||
Preferences.Default.Set("apiKey", barcode.Value);
|
Preferences.Default.Set("apiKey", barcode.Value);
|
||||||
Preferences.Default.Set("name", op.name);
|
Preferences.Default.Set("name", op.name);
|
||||||
@@ -122,18 +122,18 @@ public partial class LoginPage : ContentPage {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Types.User response = await Auth.AuthUserPass(username, password, server);
|
Types.User response = await BaseFunc.AuthUserPass(username, password, server);
|
||||||
|
|
||||||
var tokendata = new TokenData(response.token);
|
var tokendata = new TokenData(response.Token);
|
||||||
var op = await Models.Operator.LoadData(response.token);
|
var op = await Models.HoursBase.LoadOperator(response.Token);
|
||||||
Models.Stunde.apiKey = response.token;
|
Models.HoursBase.apiKey = response.Token;
|
||||||
Models.Stunde.name = op.name;
|
Models.HoursBase.name = op.name;
|
||||||
Models.Stunde.surname = op.surname;
|
Models.HoursBase.surname = op.surname;
|
||||||
Models.Stunde.EmployeeId = int.Parse(op.id);
|
Models.HoursBase.EmployeeId = int.Parse(op.id);
|
||||||
Title = op.name + " " + op.surname;
|
Title = op.name + " " + op.surname;
|
||||||
ServerLabel.Text = "Server: " + tokendata.url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
ServerLabel.Text = "Server: " + tokendata.Url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||||
|
|
||||||
Preferences.Default.Set("apiKey", response.token);
|
Preferences.Default.Set("apiKey", response.Token);
|
||||||
Preferences.Default.Set("name", op.name);
|
Preferences.Default.Set("name", op.name);
|
||||||
Preferences.Default.Set("surname", op.surname);
|
Preferences.Default.Set("surname", op.surname);
|
||||||
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
|
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
|
||||||
|
|||||||
@@ -25,12 +25,12 @@
|
|||||||
|
|
||||||
<HorizontalStackLayout>
|
<HorizontalStackLayout>
|
||||||
<Label Text="Beginn" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,0" MinimumWidthRequest="60"></Label>
|
<Label Text="Beginn" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,0" MinimumWidthRequest="60"></Label>
|
||||||
<TimePicker x:Name="TimeBegin" HorizontalOptions="Center" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding Stunde.TimeSpanVon}" Margin="0,0,0,-5" />
|
<TimePicker x:Name="TimeBegin" HorizontalOptions="Center" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding DayTime.TimeSpanVon}" Margin="0,0,0,-5" />
|
||||||
</HorizontalStackLayout>
|
</HorizontalStackLayout>
|
||||||
|
|
||||||
<HorizontalStackLayout>
|
<HorizontalStackLayout>
|
||||||
<Label Text="Ende" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,0" MinimumWidthRequest="60"></Label>
|
<Label Text="Ende" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,0" MinimumWidthRequest="60"></Label>
|
||||||
<TimePicker x:Name="TimeEnd" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding Stunde.TimeSpanBis}" Margin="0,0,0,-5" />
|
<TimePicker x:Name="TimeEnd" Format="HH:mm" MinimumWidthRequest="80" Time="{Binding DayTime.TimeSpanBis}" Margin="0,0,0,-5" />
|
||||||
</HorizontalStackLayout>
|
</HorizontalStackLayout>
|
||||||
|
|
||||||
</FlexLayout>
|
</FlexLayout>
|
||||||
@@ -38,21 +38,21 @@
|
|||||||
|
|
||||||
<Frame Padding="5,2,5,10">
|
<Frame Padding="5,2,5,10">
|
||||||
<Grid ColumnDefinitions="*,*,*">
|
<Grid ColumnDefinitions="*,*,*">
|
||||||
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}" SelectedItem="{Binding SelectedOptionGemeinde, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="0" IsVisible="{Binding Settings.GemeindeAktivSet}">
|
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding OptionsGemeinde}" SelectedItem="{Binding DayTime.GemeindeAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="0" IsVisible="{Binding GemeindeAktivSet}">
|
||||||
</Picker>
|
</Picker>
|
||||||
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding SelectedOptionProjekt, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="1" IsVisible="{Binding Settings.ProjektAktivSet}">
|
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding DayTime.ProjektAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="1" IsVisible="{Binding ProjektAktivSet}">
|
||||||
</Picker>
|
</Picker>
|
||||||
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding SelectedOptionFreistellung, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="2" >
|
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding DayTime.FreistellungAktiv, Mode=TwoWay}" ItemDisplayBinding="{Binding Name}" Grid.Column="2" >
|
||||||
</Picker>
|
</Picker>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Frame>
|
</Frame>
|
||||||
|
|
||||||
<Editor Placeholder="Beschreibung" Text="{Binding Stunde.description}" MinimumHeightRequest="40" AutoSize="TextChanges" FontSize="18" />
|
<Editor Placeholder="Beschreibung" Text="{Binding DayTime.Description}" MinimumHeightRequest="40" AutoSize="TextChanges" FontSize="18" />
|
||||||
|
|
||||||
|
|
||||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
||||||
<Button Text="Speichern" Command="{Binding SaveCommand}" />
|
<Button Text="Speichern" Command="{Binding SaveCommand}" />
|
||||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" IsEnabled="{Binding Stunde.id, Converter={StaticResource IntBoolConverter}}" />
|
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" IsEnabled="{Binding DayTime.Id, Converter={StaticResource IntBoolConverter}}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<BoxView HeightRequest="1" Margin="5,10"/>
|
<BoxView HeightRequest="1" Margin="5,10"/>
|
||||||
@@ -81,15 +81,15 @@
|
|||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<HorizontalStackLayout Grid.Row="0" Grid.Column="0">
|
<HorizontalStackLayout Grid.Row="0" Grid.Column="0">
|
||||||
<Label Grid.Column="0" Text="{Binding begin}"/>
|
<Label Grid.Column="0" Text="{Binding Begin}"/>
|
||||||
<Label Text="bis" Padding="5,0,5,0"/>
|
<Label Text="bis" Padding="5,0,5,0"/>
|
||||||
<Label Text="{Binding end}"/>
|
<Label Text="{Binding End}"/>
|
||||||
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0"/>
|
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}"/>
|
||||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0"/>
|
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}"/>
|
||||||
<Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0"/>
|
<Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0"/>
|
||||||
</HorizontalStackLayout>
|
</HorizontalStackLayout>
|
||||||
|
|
||||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
|
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Description}" Padding="0,0,0,15"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
|
|||||||
@@ -74,15 +74,15 @@
|
|||||||
|
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<HorizontalStackLayout Grid.Row="0" HorizontalOptions="FillAndExpand">
|
<HorizontalStackLayout Grid.Row="0" HorizontalOptions="FillAndExpand">
|
||||||
<Label Grid.Column="0" Text="{Binding begin}" />
|
<Label Grid.Column="0" Text="{Binding Begin}" />
|
||||||
<Label Text="bis" Padding="5,0,5,0" />
|
<Label Text="bis" Padding="5,0,5,0" />
|
||||||
<Label Text="{Binding end}" />
|
<Label Text="{Binding End}" />
|
||||||
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding GemeindeAktivSet}" />
|
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.GemeindeAktivSet}" />
|
||||||
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding ProjektAktivSet}" />
|
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ProjektAktivSet}" />
|
||||||
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0" />
|
<Label Text="{Binding FreistellungAktiv.Id}" Margin="10,0,0,0" />
|
||||||
</HorizontalStackLayout>
|
</HorizontalStackLayout>
|
||||||
|
|
||||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
|
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Description}" Padding="0,0,0,15"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
|
|||||||
Reference in New Issue
Block a user