49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
|
using System.Diagnostics;
|
|||
|
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, out decimal 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)
|
|||
|
{
|
|||
|
AmountEntry.Focus();
|
|||
|
}
|
|||
|
}
|