Initial commit

This commit is contained in:
ReiMerc 2023-03-09 14:47:11 +01:00
commit 4a840f9923
9 changed files with 472 additions and 0 deletions

25
LommeReimar.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LommeReimar", "LommeReimar\LommeReimar.csproj", "{9BC628C7-B8B0-4A28-BEAA-F142543727C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9BC628C7-B8B0-4A28-BEAA-F142543727C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BC628C7-B8B0-4A28-BEAA-F142543727C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BC628C7-B8B0-4A28-BEAA-F142543727C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BC628C7-B8B0-4A28-BEAA-F142543727C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E2ACF97-BF60-46C0-809C-1AD50B1F4F1D}
EndGlobalSection
EndGlobal

27
LommeReimar/App.xaml Normal file
View File

@ -0,0 +1,27 @@
<Application x:Class="LommeReimar.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LommeReimar"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="Button" x:Key="StandardButton">
<Setter Property="FontSize" Value="24px" />
<Setter Property="Margin" Value="5px" />
</Style>
<Style TargetType="Button" x:Key="OperatorButton">
<Setter Property="FontSize" Value="24px" />
<Setter Property="Margin" Value="5px" />
<Setter Property="Background" Value="#FFA000" />
</Style>
<Style TargetType="Button" x:Key="NumberButton">
<Setter Property="FontSize" Value="24px" />
<Setter Property="Margin" Value="5px" />
<Setter Property="Background" Value="#424242" />
<Setter Property="Foreground" Value="White" />
</Style>
</Application.Resources>
</Application>

17
LommeReimar/App.xaml.cs Normal file
View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace LommeReimar
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<ApplicationDefinition Update="App.xaml">
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Page Update="MainWindow.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>

View File

@ -0,0 +1,145 @@
using System;
using System.Globalization;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace LommeReimar
{
public partial class LommeReimarViewModel : ObservableObject
{
public enum Operator
{
PLUS = '+',
MINUS = '-',
TIMES = '×',
DIVIDE = '÷',
}
private decimal? firstNumber;
[ObservableProperty]
private decimal currentNumber;
[ObservableProperty]
private Operator? currentOperator;
private bool isDecimal;
public LommeReimarViewModel()
{
firstNumber = null;
currentNumber = 0;
isDecimal = false;
currentOperator = null;
}
[RelayCommand]
public void NumberClick(string number)
{
if (isDecimal)
{
string str = CurrentNumber.ToString();
if (!str.Contains(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator))
str += NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
CurrentNumber = decimal.Parse(str + number);
}
else
{
CurrentNumber *= 10;
CurrentNumber += decimal.Parse(number);
}
}
[RelayCommand]
public void OperatorClick(string op)
{
switch (op)
{
case "+":
CurrentOperator = Operator.PLUS;
break;
case "-":
CurrentOperator = Operator.MINUS;
break;
case "×":
CurrentOperator = Operator.TIMES;
break;
case "÷":
CurrentOperator = Operator.DIVIDE;
break;
default:
return;
}
firstNumber = CurrentNumber;
CurrentNumber = 0;
isDecimal = false;
}
[RelayCommand]
public void EqualsClick()
{
if (firstNumber is null) return;
switch (CurrentOperator)
{
case Operator.PLUS:
CurrentNumber = (decimal)(firstNumber + CurrentNumber);
break;
case Operator.MINUS:
CurrentNumber = (decimal)(firstNumber - CurrentNumber);
break;
case Operator.TIMES:
CurrentNumber = (decimal)(firstNumber * CurrentNumber);
break;
case Operator.DIVIDE:
CurrentNumber = (decimal)(firstNumber / CurrentNumber);
break;
}
}
[RelayCommand]
public void InvertClick()
{
CurrentNumber = -CurrentNumber;
}
[RelayCommand]
public void ClearClick()
{
firstNumber = null;
CurrentNumber = 0;
CurrentOperator = null;
isDecimal = false;
}
[RelayCommand]
public void DecimalClick()
{
isDecimal = true;
}
[RelayCommand]
public void PercentageClick()
{
if (firstNumber is null || CurrentOperator is null) return;
switch (CurrentOperator)
{
case Operator.PLUS:
CurrentNumber = (decimal)(firstNumber + CurrentNumber / 100 * firstNumber);
break;
case Operator.MINUS:
CurrentNumber = (decimal)(firstNumber - CurrentNumber / 100 * firstNumber);
break;
case Operator.TIMES:
CurrentNumber = (decimal)(firstNumber * CurrentNumber / 100);
break;
case Operator.DIVIDE:
CurrentNumber = (decimal)(firstNumber / CurrentNumber * 100);
break;
}
}
}
}

192
LommeReimar/MainWindow.xaml Normal file
View File

@ -0,0 +1,192 @@
<Window x:Class="LommeReimar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:c="clr-namespace:LommeReimar"
mc:Ignorable="d"
Title="LommeReimar" Height="450" Width="300"
Background="#616161"
FontFamily="Consolas">
<Window.Resources>
<c:LommeReimarViewModel x:Key="myDataSource" />
</Window.Resources>
<Grid Margin="5px" DataContext="{StaticResource myDataSource}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1.5*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="4"
Background="#212121"
Foreground="White"
Margin="5"
Padding="10"
TextAlignment="Right"
FontSize="32px"
VerticalAlignment="Center"
>
<Run Text="{ Binding CurrentNumber }" />
</TextBlock>
<Button
Grid.Row="1"
Grid.Column="0"
Content="C"
Command="{ Binding ClearClickCommand }"
Style="{ StaticResource StandardButton }"
/>
<Button
Grid.Row="1"
Grid.Column="1"
Content="±"
Command="{ Binding InvertClickCommand }"
Style="{ StaticResource StandardButton }"
/>
<Button
Grid.Row="1"
Grid.Column="2"
Content="%"
Command="{ Binding PercentageClickCommand }"
Style="{ StaticResource StandardButton }"
/>
<Button
Grid.Row="1"
Grid.Column="3"
Content="÷"
Command="{ Binding OperatorClickCommand }"
CommandParameter="÷"
Style="{ StaticResource OperatorButton }"
/>
<Button
Grid.Row="2"
Grid.Column="0"
Content="7"
Command="{ Binding NumberClickCommand }"
CommandParameter="7"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="2"
Grid.Column="1"
Content="8"
Command="{ Binding NumberClickCommand }"
CommandParameter="8"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="2"
Grid.Column="2"
Content="9"
Command="{ Binding NumberClickCommand }"
CommandParameter="9"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="2"
Grid.Column="3"
Content="×"
Command="{ Binding OperatorClickCommand }"
CommandParameter="×"
Style="{ StaticResource OperatorButton }"
/>
<Button
Grid.Row="3"
Grid.Column="0"
Content="4"
Command="{ Binding NumberClickCommand }"
CommandParameter="4"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="3"
Grid.Column="1"
Content="5"
Command="{ Binding NumberClickCommand }"
CommandParameter="5"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="3"
Grid.Column="2"
Content="6"
Command="{ Binding NumberClickCommand }"
CommandParameter="6"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="3"
Grid.Column="3"
Content=""
Command="{ Binding OperatorClickCommand }"
CommandParameter="-"
Style="{ StaticResource OperatorButton }"
/>
<Button
Grid.Row="4"
Grid.Column="0"
Content="1"
Command="{ Binding NumberClickCommand }"
CommandParameter="1"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="4"
Grid.Column="1"
Content="2"
Command="{ Binding NumberClickCommand }"
CommandParameter="2"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="4"
Grid.Column="2"
Content="3"
Command="{ Binding NumberClickCommand }"
CommandParameter="3"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="4"
Grid.Column="3"
Content="+"
Command="{ Binding OperatorClickCommand }"
CommandParameter="+"
Style="{ StaticResource OperatorButton }"
/>
<Button
Grid.Row="5"
Grid.Column="0"
Grid.ColumnSpan="2"
Content="0"
Command="{ Binding NumberClickCommand }"
CommandParameter="0"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="5"
Grid.Column="2"
Content=","
Command="{ Binding DecimalClickCommand }"
Style="{ StaticResource NumberButton }"
/>
<Button
Grid.Row="5"
Grid.Column="3"
Content="="
Command="{ Binding EqualsClickCommand }"
Style="{ StaticResource OperatorButton }"
/>
</Grid>
</Window>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LommeReimar
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}