WheresMyMoney/WheresMyMoney.Maui/AddPlannedPaymentPage.xaml.cs
Kapitan 2d69a4b018
Some checks failed
Gitea/WheresMyMoney/pipeline/head There was a failure building this commit
Version 1.0.3
- Modify planned payment
- minor bug fixes
2025-01-26 14:53:16 +01:00

50 lines
1.5 KiB
C#

using System.Globalization;
using WheresMyMoney.Maui.Core;
namespace WheresMyMoney.Maui;
public partial class AddPlannedPaymentPage : ContentPage
{
public AddPlannedPaymentPage()
{
InitializeComponent();
RepeatPicker.SelectedIndex = 2;
}
private async void Add_OnClicked(object? sender, EventArgs e)
{
if (!decimal.TryParse(AmountEntry.Text, NumberStyles.Currency, CultureInfo.CurrentCulture,
out var amount)) return;
var isSubscription = SubscriptionSwitch.IsToggled;
var every = -1;
var reoccurenceType = (ReoccurenceType)RepeatPicker.SelectedIndex;
if (isSubscription)
{
isSubscription = int.TryParse(EveryEntry.Text, out every) && every > 0;
}
Repository.Instance.InsertPlannedPayment(amount, NameEntry.Text, StartDateEntry.Date,
!isSubscription || IndefiniteSwitch.IsToggled ? null : EndDateEntry.Date,
isSubscription, isSubscription ? every : null,
isSubscription ? reoccurenceType : null);
await Navigation.PopModalAsync();
}
private void NameEntry_OnCompleted(object? sender, EventArgs e)
{
if (SubscriptionSwitch.IsToggled)
{
EveryEntry.Focus();
}
else
{
EveryEntry_OnCompleted(sender, e);
}
}
private void EveryEntry_OnCompleted(object? sender, EventArgs e)
{
this.AmountEntry.Focus();
}
}