commit 4a840f9923684b938b1b71ff00c202d9bf20f73d Author: ReiMerc Date: Thu Mar 9 14:47:11 2023 +0100 Initial commit diff --git a/LommeReimar.sln b/LommeReimar.sln new file mode 100644 index 0000000..5b3933a --- /dev/null +++ b/LommeReimar.sln @@ -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 diff --git a/LommeReimar/App.xaml b/LommeReimar/App.xaml new file mode 100644 index 0000000..9e2f31b --- /dev/null +++ b/LommeReimar/App.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/LommeReimar/App.xaml.cs b/LommeReimar/App.xaml.cs new file mode 100644 index 0000000..74ad44f --- /dev/null +++ b/LommeReimar/App.xaml.cs @@ -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 +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/LommeReimar/AssemblyInfo.cs b/LommeReimar/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/LommeReimar/AssemblyInfo.cs @@ -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) +)] diff --git a/LommeReimar/LommeReimar.csproj b/LommeReimar/LommeReimar.csproj new file mode 100644 index 0000000..2623758 --- /dev/null +++ b/LommeReimar/LommeReimar.csproj @@ -0,0 +1,14 @@ + + + + WinExe + net7.0-windows + enable + true + + + + + + + diff --git a/LommeReimar/LommeReimar.csproj.user b/LommeReimar/LommeReimar.csproj.user new file mode 100644 index 0000000..644b0a6 --- /dev/null +++ b/LommeReimar/LommeReimar.csproj.user @@ -0,0 +1,14 @@ + + + + + + Designer + + + + + Designer + + + \ No newline at end of file diff --git a/LommeReimar/LommeReimarViewModel.cs b/LommeReimar/LommeReimarViewModel.cs new file mode 100644 index 0000000..4227f98 --- /dev/null +++ b/LommeReimar/LommeReimarViewModel.cs @@ -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; + } + } + } +} diff --git a/LommeReimar/MainWindow.xaml b/LommeReimar/MainWindow.xaml new file mode 100644 index 0000000..ea24fd4 --- /dev/null +++ b/LommeReimar/MainWindow.xaml @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + +