Initial commit

This commit is contained in:
2024-08-20 01:37:51 +02:00
commit 68ccf23f01
62 changed files with 2121 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
using BarcodeScanning;
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 AboutViewModel() {
ShowMoreInfoCommand = new AsyncRelayCommand(ShowMoreInfo);
}
async Task ShowMoreInfo() =>
await Launcher.Default.OpenAsync(MoreInfoUrl);
private static void BarcodesDetected(object sender, OnDetectionFinishedEventArg e) {
if (e.BarcodeResults.Length > 0) {
// Hier verarbeiten Sie den erkannten Barcode
Console.WriteLine($"Detected barcode: {e.BarcodeResults.GetType()} {e.BarcodeResults.ToString()}");
}
}
}
}

View File

@@ -0,0 +1,65 @@
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Input;
namespace Jugenddienst_Stunden.ViewModels {
internal class NoteViewModel : ObservableObject, IQueryAttributable {
private Models.Note _note;
public string Text {
get => _note.Text;
set {
if (_note.Text != value) {
_note.Text = value;
OnPropertyChanged();
}
}
}
public DateTime Date => _note.Date;
public string Identifier => _note.Filename;
public ICommand SaveCommand { get; private set; }
public ICommand DeleteCommand { get; private set; }
public NoteViewModel() {
_note = new Models.Note();
SaveCommand = new AsyncRelayCommand(Save);
DeleteCommand = new AsyncRelayCommand(Delete);
}
public NoteViewModel(Models.Note note) {
_note = note;
SaveCommand = new AsyncRelayCommand(Save);
DeleteCommand = new AsyncRelayCommand(Delete);
}
private async Task Save() {
_note.Date = DateTime.Now;
_note.Save();
await Shell.Current.GoToAsync($"..?saved={_note.Filename}");
}
private async Task Delete() {
_note.Delete();
await Shell.Current.GoToAsync($"..?deleted={_note.Filename}");
}
void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
if (query.ContainsKey("load")) {
_note = Models.Note.Load(query["load"].ToString());
RefreshProperties();
}
}
public void Reload() {
_note = Models.Note.Load(_note.Filename);
RefreshProperties();
}
private void RefreshProperties() {
OnPropertyChanged(nameof(Text));
OnPropertyChanged(nameof(Date));
}
}
}

View File

@@ -0,0 +1,51 @@
using CommunityToolkit.Mvvm.Input;
using Jugenddienst_Stunden.Models;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace Jugenddienst_Stunden.ViewModels;
internal class NotesViewModel : IQueryAttributable {
public ObservableCollection<ViewModels.NoteViewModel> AllNotes { get; }
public ICommand NewCommand { get; }
public ICommand SelectNoteCommand { get; }
public NotesViewModel() {
AllNotes = new ObservableCollection<ViewModels.NoteViewModel>(Models.Note.LoadAll().Select(n => new NoteViewModel(n)));
NewCommand = new AsyncRelayCommand(NewNoteAsync);
SelectNoteCommand = new AsyncRelayCommand<ViewModels.NoteViewModel>(SelectNoteAsync);
}
private async Task NewNoteAsync() {
await Shell.Current.GoToAsync(nameof(Views.NotePage));
}
private async Task SelectNoteAsync(ViewModels.NoteViewModel note) {
if (note != null)
await Shell.Current.GoToAsync($"{nameof(Views.NotePage)}?load={note.Identifier}");
}
void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
if (query.ContainsKey("deleted")) {
string noteId = query["deleted"].ToString();
NoteViewModel matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
// If note exists, delete it
if (matchedNote != null)
AllNotes.Remove(matchedNote);
} else if (query.ContainsKey("saved")) {
string noteId = query["saved"].ToString();
NoteViewModel matchedNote = AllNotes.Where((n) => n.Identifier == noteId).FirstOrDefault();
// If note is found, update it
if (matchedNote != null) {
matchedNote.Reload();
AllNotes.Move(AllNotes.IndexOf(matchedNote), 0);
}
// If note isn't found, it's new; add it.
else
AllNotes.Insert(0, new NoteViewModel(Note.Load(noteId)));
}
}
}

View File

@@ -0,0 +1,49 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows.Input;
namespace Jugenddienst_Stunden.ViewModels {
internal class StundenViewModel : ObservableObject {
public string Name => AppInfo.Name;
public string Surname => AppInfo.VersionString;
public string MoreInfoUrl => "https://aka.ms/maui";
public string Message => "Hier werden deine geleisteten Arbeitsstunden aufgelistet";
public ICommand LoadDataCommand { get; private set; }
public object Stunden { get; }
private Models.Hours _hour;
public Models.Hours Hours {
get => _hour;
}
public string Nominal {
get => _hour.nominal;
}
public string Overtime {
get => _hour.overtime;
}
public string OvertimeMonth {
get => _hour.overtime_month;
}
public StundenViewModel() {
_hour = new Models.Hours();
LoadDataCommand = new AsyncRelayCommand(LoadData);
}
//public async Task LoadData() =>
// await Models.Stunde.LoadData();
public async Task LoadData() {
_hour = await Models.Stunde.LoadData();
RefreshProperties();
}
private void RefreshProperties() {
OnPropertyChanged(nameof(Nominal));
OnPropertyChanged(nameof(Overtime));
OnPropertyChanged(nameof(OvertimeMonth));
}
}
}