Bei neuem Eintrag die vorhandenen anzeigen.

This commit is contained in:
2024-10-12 17:42:33 +02:00
parent e2f029893e
commit a2559da934
3 changed files with 59 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input;
using Jugenddienst_Stunden.Types; using Jugenddienst_Stunden.Types;
using System.Collections.ObjectModel; 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 { internal class StundeViewModel : ObservableObject, IQueryAttributable {
@@ -15,6 +16,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
private DayTime _stunde; private DayTime _stunde;
public DayTime Stunde { get => _stunde; } public DayTime Stunde { get => _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;
@@ -60,7 +62,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
} }
} }
public List<DayTime> DayTimes {get;set; }
public ICommand SaveCommand { get; private set; } public ICommand SaveCommand { get; private set; }
@@ -137,7 +139,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
//DateTime heute = DateTime.Now; //DateTime heute = DateTime.Now;
_stunde = await Models.Stunde.LoadEntry(Convert.ToInt32(query["load"])); _stunde = await Models.Stunde.LoadEntry(Convert.ToInt32(query["load"]));
if (String.IsNullOrEmpty(_stunde.description)) { if (System.String.IsNullOrEmpty(_stunde.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. MMM. yyyy"); SubTitle = _stunde.day.ToString("dddd, d. MMM. yyyy");
@@ -165,10 +167,21 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
} }
if (query.ContainsKey("date")) { if (query.ContainsKey("date")) {
SubTitle = DateTime.ParseExact((string)query["date"], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).ToString("dddd, d. MMM. yyyy"); Title = "Neuer Eintrag";
_stunde.day = 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
DayTimes = await Models.Stunde.LoadDay(_date);
_stunde.day = _date;
SubTitle = _date.ToString("dddd, d. MMM. yyyy");
_ = LoadData(); _ = LoadData();
OnPropertyChanged(nameof(Title));
OnPropertyChanged(nameof(SubTitle)); OnPropertyChanged(nameof(SubTitle));
OnPropertyChanged(nameof(DayTimes));
} }
} }

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels" xmlns:models="clr-namespace:Jugenddienst_Stunden.ViewModels"
x:Class="Jugenddienst_Stunden.Views.StundePage" x:Class="Jugenddienst_Stunden.Views.StundePage"
Title="Eintrag bearbeiten"> Title="{Binding Title}">
<ContentPage.BindingContext> <ContentPage.BindingContext>
<models:StundeViewModel /> <models:StundeViewModel />
@@ -45,5 +45,46 @@
<Button Text="Speichern" Command="{Binding SaveCommand}" /> <Button Text="Speichern" Command="{Binding SaveCommand}" />
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" /> <Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" />
</Grid> </Grid>
<BoxView HeightRequest="1" Color="Red" Margin="5,10"/>
<CollectionView
ItemsSource="{Binding DayTimes}"
x:Name="stundeItems" Margin="0"
HeightRequest="350"
SelectionMode="Single"
SelectionChangedCommand="{Binding SelectEntryCommand}"
SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="0" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="5,10,5,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<HorizontalStackLayout Grid.Row="0" Grid.Column="0">
<Label Grid.Column="0" Text="{Binding begin}"/>
<Label Text="bis" Padding="5,0,5,0"/>
<Label Text="{Binding end}"/>
<Label Text="{Binding GemeindeAktiv.Name}" Margin="10,0,0,0"/>
<Label Text="{Binding ProjektAktiv.Name}" Margin="10,0,0,0"/>
<Label Text="{Binding FreistellungAktiv.Name}" Margin="10,0,0,0"/>
</HorizontalStackLayout>
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding description}" Padding="0,0,0,15"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout> </VerticalStackLayout>
</ContentPage> </ContentPage>

View File

@@ -5,7 +5,6 @@ namespace Jugenddienst_Stunden.Views;
public partial class StundePage : ContentPage { public partial class StundePage : ContentPage {
public ICommand DeleteConfirmCommand { get; }
public StundePage() { public StundePage() {
InitializeComponent(); InitializeComponent();