Created
November 28, 2024 12:42
-
-
Save barrybtw/9762224b480ee15fde5c8225ff66484d to your computer and use it in GitHub Desktop.
Investerings Guiden - Det bedste projekt af dem alle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:local="clr-namespace:InvesteringsGuiden" | |
x:Class="InvesteringsGuiden.App"> | |
<Application.Resources> | |
<ResourceDictionary> | |
<local:AlternatingRowConverter x:Key="AlternatingRowConverter" /> | |
</ResourceDictionary> | |
</Application.Resources> | |
</Application> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace InvesteringsGuiden; | |
public partial class App : Application | |
{ | |
public App() | |
{ | |
InitializeComponent(); | |
MainPage = new AppShell(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<Shell | |
x:Class="InvesteringsGuiden.AppShell" | |
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:local="clr-namespace:InvesteringsGuiden" | |
Shell.FlyoutBehavior="Disabled" | |
Title="InvesteringsGuiden"> | |
<ShellContent | |
Title="Home" | |
ContentTemplate="{DataTemplate local:MainPage}" | |
Route="MainPage" /> | |
</Shell> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace InvesteringsGuiden; | |
public partial class AppShell : Shell | |
{ | |
public AppShell() | |
{ | |
InitializeComponent(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
x:Class="InvesteringsGuiden.MainPage" | |
Title="Investerings guiden til din aktiesparekonto!"> | |
<ScrollView> | |
<StackLayout Padding="20" Spacing="15"> | |
<Label Text="Månedlig indbetaling:" /> | |
<Entry x:Name="MonthlyDepositEntry" Keyboard="Numeric" Placeholder="Indtast beløb" /> | |
<Label Text="Antal år frem:" /> | |
<Entry x:Name="YearsEntry" Keyboard="Numeric" Placeholder="Indtast antal år" /> | |
<Label Text="Årlig stigning (%):" /> | |
<Entry x:Name="AnnualIncreaseEntry" Keyboard="Numeric" Placeholder="Indtast procent" /> | |
<Button Text="Beregn" BackgroundColor="Bisque" Clicked="OnCalculateClicked" /> | |
<Label x:Name="ResultLabel" Text="Resultatet vises her." TextColor="Blue" /> | |
<!-- Excel-stil tabel --> | |
<CollectionView ItemsSource="{Binding MonthlyDataCollection}" SelectionMode="None"> | |
<CollectionView.Header> | |
<Grid BackgroundColor="#f0f0f0" Padding="5"> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="150" /> | |
<ColumnDefinition Width="200" /> | |
<ColumnDefinition Width="200" /> | |
<ColumnDefinition Width="200" /> | |
<ColumnDefinition Width="200" /> | |
</Grid.ColumnDefinitions> | |
<Label Text="Måned" Grid.Column="0" FontAttributes="Bold" /> | |
<Label Text="Saldo" Grid.Column="1" FontAttributes="Bold" /> | |
<Label Text="Månedlig Profit" Grid.Column="2" FontAttributes="Bold" /> | |
<Label Text="Total Profit" Grid.Column="3" FontAttributes="Bold" /> | |
<Label Text="Betalt Skat" Grid.Column="4" FontAttributes="Bold" /> | |
</Grid> | |
</CollectionView.Header> | |
<CollectionView.ItemTemplate> | |
<DataTemplate> | |
<Grid Padding="5" RowSpacing="2" | |
BackgroundColor="{Binding Month, Converter={StaticResource AlternatingRowConverter}}"> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="150" /> | |
<ColumnDefinition Width="200" /> | |
<ColumnDefinition Width="200" /> | |
<ColumnDefinition Width="200" /> | |
<ColumnDefinition Width="200" /> | |
</Grid.ColumnDefinitions> | |
<BoxView BackgroundColor="#e0e0e0" HeightRequest="1" Grid.ColumnSpan="5" /> | |
<Label Text="{Binding Month}" Grid.Column="0" /> | |
<Label Text="{Binding Balance, StringFormat='{0:C}'}" Grid.Column="1" /> | |
<Label Text="{Binding MonthlyProfit, StringFormat='{0:C}'}" Grid.Column="2" /> | |
<Label Text="{Binding TotalProfit, StringFormat='{0:C}'}" Grid.Column="3" /> | |
<Label Text="{Binding TaxPaid, StringFormat='{0:C}'}" Grid.Column="4" /> | |
</Grid> | |
</DataTemplate> | |
</CollectionView.ItemTemplate> | |
</CollectionView> | |
</StackLayout> | |
</ScrollView> | |
</ContentPage> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.ObjectModel; | |
namespace InvesteringsGuiden; | |
public partial class MainPage : ContentPage | |
{ | |
public ObservableCollection<MonthlyData> MonthlyDataCollection { get; set; } | |
public MainPage() | |
{ | |
InitializeComponent(); | |
MonthlyDataCollection = new ObservableCollection<MonthlyData>(); | |
BindingContext = this; | |
} | |
private void OnCalculateClicked(object sender, EventArgs e) | |
{ | |
MonthlyDataCollection.Clear(); | |
if (!decimal.TryParse(MonthlyDepositEntry.Text, out var monthlyDeposit) || | |
!int.TryParse(YearsEntry.Text, out var years) || | |
!double.TryParse(AnnualIncreaseEntry.Text, out var annualIncrease)) | |
{ | |
ResultLabel.Text = "Ugyldigt input. Prøv igen."; | |
return; | |
} | |
const decimal maxDepositLimit = 135900m; | |
const double taxRate = 0.17; | |
// Konverter årlig stigning til månedlig stigning | |
var monthlyRate = Math.Pow(1 + annualIncrease / 100, 1.0 / 12) - 1; | |
decimal totalSavings = 0; | |
decimal totalTaxPaid = 0; | |
decimal totalProfit = 0; | |
for (var year = 1; year <= years; year++) | |
{ | |
// Beregn hvor meget man må indbetale dette år | |
var maxAllowedDeposit = Math.Max(0, maxDepositLimit - totalSavings); | |
var actualMonthlyDeposit = Math.Min(monthlyDeposit, maxAllowedDeposit / 12); | |
decimal annualProfit = 0; | |
for (var month = 1; month <= 12; month++) | |
{ | |
var monthlyProfit = totalSavings * (decimal)monthlyRate; | |
annualProfit += monthlyProfit; | |
totalProfit += monthlyProfit; | |
totalSavings += monthlyProfit + actualMonthlyDeposit; | |
MonthlyDataCollection.Add(new MonthlyData | |
{ | |
Month = (year - 1) * 12 + month, | |
Balance = totalSavings, | |
MonthlyProfit = monthlyProfit, | |
TotalProfit = totalProfit, | |
TaxPaid = totalTaxPaid | |
}); | |
} | |
decimal taxForYear = annualProfit * (decimal)taxRate; | |
totalTaxPaid += taxForYear; | |
totalSavings -= taxForYear; | |
} | |
ResultLabel.Text = $"Beregningen er færdig! Se resultaterne nedenfor."; | |
} | |
} | |
public class MonthlyData | |
{ | |
public int Month { get; set; } | |
public decimal Balance { get; set; } | |
public decimal MonthlyProfit { get; set; } | |
public decimal TotalProfit { get; set; } | |
public decimal TaxPaid { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Logging; | |
namespace InvesteringsGuiden; | |
public static class MauiProgram | |
{ | |
public static MauiApp CreateMauiApp() | |
{ | |
var builder = MauiApp.CreateBuilder(); | |
builder | |
.UseMauiApp<App>() | |
.ConfigureFonts(fonts => | |
{ | |
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | |
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); | |
}); | |
#if DEBUG | |
builder.Logging.AddDebug(); | |
#endif | |
return builder.Build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment