瀏覽代碼

сделала валидацию и кнопки, остались тесты

Алёна Плотникова 3 年之前
父節點
當前提交
00e6710eab

+ 20 - 0
UnitTestProject/Properties/AssemblyInfo.cs

@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("UnitTestProject")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("UnitTestProject")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+[assembly: ComVisible(false)]
+
+[assembly: Guid("ed2ce15b-f12a-48ad-b736-3eafcf217a42")]
+
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 14 - 0
UnitTestProject/UnitTest1.cs

@@ -0,0 +1,14 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+
+namespace UnitTestProject
+{
+    [TestClass]
+    public class UnitTest1
+    {
+        [TestMethod]
+        public void TestMethod1()
+        {
+        }
+    }
+}

+ 68 - 0
UnitTestProject/UnitTestProject.csproj

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props')" />
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{ED2CE15B-F12A-48AD-B736-3EAFCF217A42}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>UnitTestProject</RootNamespace>
+    <AssemblyName>UnitTestProject</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
+    <IsCodedUITest>False</IsCodedUITest>
+    <TestProjectType>UnitTest</TestProjectType>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="UnitTest1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их.  Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.props'))" />
+    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets'))" />
+  </Target>
+  <Import Project="..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.2.7\build\net45\MSTest.TestAdapter.targets')" />
+</Project>

+ 5 - 0
UnitTestProject/packages.config

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="MSTest.TestAdapter" version="2.2.7" targetFramework="net472" />
+  <package id="MSTest.TestFramework" version="2.2.7" targetFramework="net472" />
+</packages>

+ 6 - 0
numbersystem.sln

@@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.32112.339
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "numbersystem", "numbersystem\numbersystem.csproj", "{64379BA7-F7D5-4318-A174-21F1BF9FF92E}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "UnitTestProject\UnitTestProject.csproj", "{ED2CE15B-F12A-48AD-B736-3EAFCF217A42}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
 		{64379BA7-F7D5-4318-A174-21F1BF9FF92E}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{64379BA7-F7D5-4318-A174-21F1BF9FF92E}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{64379BA7-F7D5-4318-A174-21F1BF9FF92E}.Release|Any CPU.Build.0 = Release|Any CPU
+		{ED2CE15B-F12A-48AD-B736-3EAFCF217A42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{ED2CE15B-F12A-48AD-B736-3EAFCF217A42}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{ED2CE15B-F12A-48AD-B736-3EAFCF217A42}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{ED2CE15B-F12A-48AD-B736-3EAFCF217A42}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 49 - 25
numbersystem/MainWindow.xaml

@@ -55,53 +55,77 @@
                         <ComboBoxItem Content="Шестнадцатиричная"/>
                     </ComboBox>
                     <Button x:Name="ca" 
-                            Content="CA" Grid.Row="5" Grid.Column="0"/>
+                            Content="CA" Grid.Row="5" Grid.Column="0"
+                            Click="ca_Click"/>
                     <Button x:Name="zero" 
-                            Content="0" Grid.Row="5" Grid.Column="1"/>
+                            Content="0" Grid.Row="5" Grid.Column="1"
+                            Click="zero_Click"/>
                     <Button x:Name="erase" 
-                            Content="⌫" Grid.Row="5" Grid.Column="2"/>
+                            Content="⌫" Grid.Row="5" Grid.Column="2"
+                            Click="erase_Click"/>
                     <Button x:Name="one" 
-                            Content="1" Grid.Row="4" Grid.Column="0"/>
+                            Content="1" Grid.Row="4" Grid.Column="0"
+                            Click="one_Click"/>
                     <Button x:Name="two" 
-                            Content="2" Grid.Row="4" Grid.Column="1"/>
+                            Content="2" Grid.Row="4" Grid.Column="1"
+                            Click="two_Click"/>
                     <Button x:Name="three" 
-                            Content="3" Grid.Row="4" Grid.Column="2"/>
+                            Content="3" Grid.Row="4" Grid.Column="2"
+                            Click="three_Click"/>
                     <Button x:Name="four" 
-                            Content="4" Grid.Row="3" Grid.Column="0"/>
+                            Content="4" Grid.Row="3" Grid.Column="0"
+                            Click="four_Click"/>
                     <Button x:Name="five" 
-                            Content="5" Grid.Row="3" Grid.Column="1"/>
+                            Content="5" Grid.Row="3" Grid.Column="1"
+                            Click="five_Click"/>
                     <Button x:Name="six" 
-                            Content="6" Grid.Row="3" Grid.Column="2"/>
+                            Content="6" Grid.Row="3" Grid.Column="2"
+                            Click="six_Click"/>
                     <Button x:Name="seven" 
-                            Content="7" Grid.Row="2" Grid.Column="0"/>
+                            Content="7" Grid.Row="2" Grid.Column="0"
+                            Click="seven_Click"/>
                     <Button x:Name="eight" 
-                            Content="8" Grid.Row="2" Grid.Column="1"/>
+                            Content="8" Grid.Row="2" Grid.Column="1"
+                            Click="eight_Click"/>
                     <Button x:Name="nine" 
-                            Content="9" Grid.Row="2" Grid.Column="2"/>
+                            Content="9" Grid.Row="2" Grid.Column="2"
+                            Click="nine_Click"/>
                     <Button x:Name="a" 
-                            Content="A" Grid.Row="6" Grid.Column="0" Background="#6c6cdf"/>
+                            Content="A" Grid.Row="6" Grid.Column="0" Background="#6c6cdf"
+                            Click="a_Click"/>
                     <Button x:Name="b" 
-                            Content="B" Grid.Row="6" Grid.Column="1" Background="#6c6cdf"/>
+                            Content="B" Grid.Row="6" Grid.Column="1" Background="#6c6cdf"
+                            Click="b_Click"/>
                     <Button x:Name="c" 
-                            Content="C" Grid.Row="6" Grid.Column="2" Background="#6c6cdf"/>
+                            Content="C" Grid.Row="6" Grid.Column="2" Background="#6c6cdf"
+                            Click="c_Click"/>
                     <Button x:Name="d" 
-                            Content="D" Grid.Row="7" Grid.Column="0" Background="#6c6cdf"/>
+                            Content="D" Grid.Row="7" Grid.Column="0" Background="#6c6cdf"
+                            Click="d_Click"/>
                     <Button x:Name="e" 
-                            Content="E" Grid.Row="7" Grid.Column="1" Background="#6c6cdf"/>
+                            Content="E" Grid.Row="7" Grid.Column="1" Background="#6c6cdf"
+                            Click="e_Click"/>
                     <Button x:Name="f" 
-                            Content="F" Grid.Row="7" Grid.Column="2" Background="#6c6cdf"/>
+                            Content="F" Grid.Row="7" Grid.Column="2" Background="#6c6cdf"
+                            Click="f_Click"/>
                     <Button x:Name="plus" 
-                            Content="+" Grid.Row="2" Grid.Column="3" Background="#4040bf"/>
+                            Content="+" Grid.Row="2" Grid.Column="3" Background="#4040bf"
+                            Click="plus_Click"/>
                     <Button x:Name="minus" 
-                            Content="-" Grid.Row="3" Grid.Column="3" Background="#4040bf"/>
+                            Content="-" Grid.Row="3" Grid.Column="3" Background="#4040bf"
+                            Click="minus_Click"/>
                     <Button x:Name="multiply" 
-                            Content="×" Grid.Row="4" Grid.Column="3" Background="#4040bf"/>
+                            Content="×" Grid.Row="4" Grid.Column="3" Background="#4040bf"
+                            Click="multiply_Click"/>
                     <Button x:Name="division" 
-                            Content="÷" Grid.Row="5" Grid.Column="3" Background="#4040bf"/>
+                            Content="÷" Grid.Row="5" Grid.Column="3" Background="#4040bf"
+                            Click="division_Click"/>
                     <Button x:Name="remains" 
-                            Content="%" Grid.Row="6" Grid.Column="3" Background="#4040bf"/>
+                            Content="%" Grid.Row="6" Grid.Column="3" Background="#4040bf"
+                            Click="remains_Click"/>
                     <Button x:Name="equal" 
-                            Content="=" Grid.Row="7" Grid.Column="3" Background="#4040bf"/>
+                            Content="=" Grid.Row="7" Grid.Column="3" Background="#4040bf"
+                            Click="equal_Click"/>
                 </Grid>
             </TabItem>
             <TabItem Header="История" FontFamily="Montserrat Light" Height="19" VerticalAlignment="Top">
@@ -110,7 +134,7 @@
                         <DataGrid.Columns>
                             <DataGridTextColumn Header="Запрос" Binding="{Binding inquiry}" Width="Auto"/>
                             <DataGridTextColumn Header="Результат" Binding="{Binding result}" Width="Auto"/>
-                            <DataGridTextColumn Header="Основание СС" Binding="{Binding notation}" Width="Auto"/>
+                            <DataGridTextColumn Header="СС" Binding="{Binding notation}" Width="*"/>
                         </DataGrid.Columns>
                     </DataGrid>
                 </Grid>

+ 440 - 110
numbersystem/MainWindow.xaml.cs

@@ -110,140 +110,152 @@ namespace numbersystem
             // при нажатии на знаки операций
             if(e.Text == "+" || e.Text == "-" || e.Text == "/" || e.Text == "*" || e.Text == "%")
             {
-                str.Text += " ";
-                str.Text += e.Text;
-                str.Text += " ";
+                if (str.Text != "")
+                {
+                    if (str.Text[str.Text.Length - 1] != ' ')
+                    {
+                        str.Text += " ";
+                        str.Text += e.Text;
+                        str.Text += " ";
+                    }
+                }
             }
 
             // при нажатии на "равно"
             if(e.Text == "=")
             {
-                if(ss == 0)
+                if (str.Text != "")
                 {
-                    MessageBox.Show("Не выбрана система счисления");
-                    return;
-                }
-
-                // записываем выражение в переменную
-                expression = str.Text;
-
-                // разбиваем строку на массив
-                string[] arr = expression.Split(' ');
-
-                try
-                {
-                    // перебираем массив и считаем высокоприоритетные операции
-                    for (int i = 0; i < arr.Length; i++)
+                    if (str.Text[str.Text.Length - 1] != ' ')
                     {
-                        // умножение
-                        if (arr[i] == "*")
+                        if (ss == 0)
                         {
-                            if (arr[i - 1] == "_")
-                            {
-                                arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
-                                arr[i - 2] = "_";
-                                arr[i + 1] = "_";
-                            }
-                            else
-                            {
-                                arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
-                                arr[i - 1] = "_";
-                                arr[i + 1] = "_";
-                            }
+                            MessageBox.Show("Не выбрана система счисления");
+                            return;
                         }
-                        // деление
-                        else if (arr[i] == "/")
+
+                        // записываем выражение в переменную
+                        expression = str.Text;
+
+                        // разбиваем строку на массив
+                        string[] arr = expression.Split(' ');
+
+                        try
                         {
-                            if (arr[i - 1] == "_")
+                            // перебираем массив и считаем высокоприоритетные операции
+                            for (int i = 0; i < arr.Length; i++)
                             {
-                                arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
-                                arr[i - 2] = "_";
-                                arr[i + 1] = "_";
+                                // умножение
+                                if (arr[i] == "*")
+                                {
+                                    if (arr[i - 1] == "_")
+                                    {
+                                        arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
+                                        arr[i - 2] = "_";
+                                        arr[i + 1] = "_";
+                                    }
+                                    else
+                                    {
+                                        arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
+                                        arr[i - 1] = "_";
+                                        arr[i + 1] = "_";
+                                    }
+                                }
+                                // деление
+                                else if (arr[i] == "/")
+                                {
+                                    if (arr[i - 1] == "_")
+                                    {
+                                        arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
+                                        arr[i - 2] = "_";
+                                        arr[i + 1] = "_";
+                                    }
+                                    else
+                                    {
+                                        arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
+                                        arr[i - 1] = "_";
+                                        arr[i + 1] = "_";
+                                    }
+                                }
+                                // остаток от деления
+                                else if (arr[i] == "%")
+                                {
+                                    if (arr[i - 1] == "_")
+                                    {
+                                        arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
+                                        arr[i - 2] = "_";
+                                        arr[i + 1] = "_";
+                                    }
+                                    else
+                                    {
+                                        arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
+                                        arr[i - 1] = "_";
+                                        arr[i + 1] = "_";
+                                    }
+                                }
                             }
-                            else
-                            {
-                                arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
-                                arr[i - 1] = "_";
-                                arr[i + 1] = "_";
-                            }
-                        }
-                        // остаток от деления
-                        else if (arr[i] == "%")
-                        {
-                            if (arr[i - 1] == "_")
+
+                            // узнаем размер будущего массива
+                            int l = 0;
+                            for (int i = 0; i < arr.Length; i++)
                             {
-                                arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
-                                arr[i - 2] = "_";
-                                arr[i + 1] = "_";
+                                if (arr[i] != "_")
+                                {
+                                    l++;
+                                }
                             }
-                            else
+
+                            // записать в новый массив результат предыдущего шага
+                            string[] arr2 = new string[l];
+                            int j = 0;
+                            for (int i = 0; i < arr.Length; i++)
                             {
-                                arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
-                                arr[i - 1] = "_";
-                                arr[i + 1] = "_";
+                                if (arr[i] != "_")
+                                {
+                                    arr2[j] = arr[i];
+                                    j++;
+                                }
                             }
-                        }
-                    }
 
-                    // узнаем размер будущего массива
-                    int l = 0;
-                    for (int i = 0; i < arr.Length; i++)
-                    {
-                        if (arr[i] != "_")
-                        {
-                            l++;
-                        }
-                    }
+                            // первое число массива присваиваем переменной
+                            res = Convert.ToInt32(arr2[0], ss);
 
-                    // записать в новый массив результат предыдущего шага
-                    string[] arr2 = new string[l];
-                    int j = 0;
-                    for (int i = 0; i < arr.Length; i++)
-                    {
-                        if (arr[i] != "_")
-                        {
-                            arr2[j] = arr[i];
-                            j++;
-                        }
-                    }
+                            // перебираем массив и считаем остальные операции
+                            for (int i = 1; i < arr2.Length; i++)
+                            {
+                                // сложение
+                                if (arr2[i] == "+")
+                                {
+                                    res += Convert.ToInt32(arr2[i + 1], ss);
+                                }
+                                // вычитание
+                                else if (arr2[i] == "-")
+                                {
+                                    res -= Convert.ToInt32(arr2[i + 1], ss);
+                                }
+                            }
 
-                    // первое число массива присваиваем переменной
-                    res = Convert.ToInt32(arr2[0], ss);
+                            // выводим результат
+                            str.Text = Convert.ToString(res, ss);
 
-                    // перебираем массив и считаем остальные операции
-                    for (int i = 1; i < arr2.Length; i++)
-                    {
-                        // сложение
-                        if (arr2[i] == "+")
-                        {
-                            res += Convert.ToInt32(arr2[i + 1], ss);
+                            // добавляем вычисление в бд
+                            history record = new history()
+                            {
+                                inquiry = expression,
+                                result = Convert.ToString(res, ss),
+                                notation = Convert.ToString(ss)
+                            };
+                            _context.history.Add(record);
+                            _context.SaveChanges();
+                            Load();
+                            Diagram();
+                            dia.Series = SeriesCollection;
                         }
-                        // вычитание
-                        else if (arr2[i] == "-")
+                        catch (Exception ex)
                         {
-                            res -= Convert.ToInt32(arr2[i + 1], ss);
+                            MessageBox.Show(ex.ToString());
                         }
                     }
-
-                    // выводим результат
-                    str.Text = Convert.ToString(res, ss);
-
-                    // добавляем вычисление в бд
-                    history record = new history()
-                    {
-                        inquiry = expression,
-                        result = Convert.ToString(res, ss),
-                        notation = Convert.ToString(ss)
-                    };
-                    _context.history.Add(record);
-                    _context.SaveChanges();
-                    Load();
-                    Diagram();
-                    dia.Series = SeriesCollection;
-                }
-                catch (Exception ex)
-                {
-                    MessageBox.Show(ex.ToString());
                 }
             }
         }
@@ -271,5 +283,323 @@ namespace numbersystem
                 }
             }
         }
+
+        // при нажатии на кнопки
+        private void ca_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text = "";
+            str.Focus();
+        }
+
+        private void zero_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '0';
+            str.Focus();
+        }
+
+        private void erase_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text.Length > 0)
+            {
+                if (str.Text[str.Text.Length - 1] == ' ') //если последний символ это знак операции
+                {
+                    for (int i = 0; i < 3; i++)
+                        str.Text = str.Text.Substring(0, str.Text.Length - 1);
+                }
+                else
+                {
+                    str.Text = str.Text.Substring(0, str.Text.Length - 1);
+                }
+            }
+            str.Focus();
+        }
+
+        private void one_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '1';
+            str.Focus();
+        }
+
+        private void two_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '2';
+            str.Focus();
+        }
+
+        private void three_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '3';
+            str.Focus();
+        }
+
+        private void four_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '4';
+            str.Focus();
+        }
+
+        private void five_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '5';
+            str.Focus();
+        }
+
+        private void six_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '6';
+            str.Focus();
+        }
+
+        private void seven_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '7';
+            str.Focus();
+        }
+
+        private void eight_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '8';
+            str.Focus();
+        }
+
+        private void nine_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += '9';
+            str.Focus();
+        }
+
+        private void a_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += 'a';
+            str.Focus();
+        }
+
+        private void b_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += 'b';
+            str.Focus();
+        }
+
+        private void c_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += 'c';
+            str.Focus();
+        }
+
+        private void d_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += 'd';
+            str.Focus();
+        }
+
+        private void e_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += 'e';
+            str.Focus();
+        }
+
+        private void f_Click(object sender, RoutedEventArgs e)
+        {
+            str.Text += 'f';
+            str.Focus();
+        }
+
+        private void plus_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text != "")
+            {
+                if (str.Text[str.Text.Length - 1] != ' ')
+                {
+                    str.Text += " + ";
+                }
+            }
+            str.Focus();
+        }
+
+        private void minus_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text != "")
+            {
+                if (str.Text[str.Text.Length - 1] != ' ')
+                {
+                    str.Text += " - ";
+                }
+            }
+            str.Focus();
+        }
+
+        private void multiply_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text != "")
+            {
+                if (str.Text[str.Text.Length - 1] != ' ')
+                {
+                    str.Text += " * ";
+                }
+            }
+            str.Focus();
+        }
+
+        private void division_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text != "")
+            {
+                if (str.Text[str.Text.Length - 1] != ' ')
+                {
+                    str.Text += " / ";
+                }
+            }
+            str.Focus();
+        }
+
+        private void remains_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text != "")
+            {
+                if (str.Text[str.Text.Length - 1] != ' ')
+                {
+                    str.Text += " % ";
+                }
+            }
+            str.Focus();
+        }
+
+        private void equal_Click(object sender, RoutedEventArgs e)
+        {
+            if (str.Text != "")
+            {
+                if (str.Text[str.Text.Length - 1] != ' ')
+                {
+                    if (ss == 0)
+                    {
+                        MessageBox.Show("Не выбрана система счисления");
+                        return;
+                    }
+
+                    // записываем выражение в переменную
+                    expression = str.Text;
+
+                    // разбиваем строку на массив
+                    string[] arr = expression.Split(' ');
+
+                    try
+                    {
+                        // перебираем массив и считаем высокоприоритетные операции
+                        for (int i = 0; i < arr.Length; i++)
+                        {
+                            // умножение
+                            if (arr[i] == "*")
+                            {
+                                if (arr[i - 1] == "_")
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 2] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                                else
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) * Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 1] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                            }
+                            // деление
+                            else if (arr[i] == "/")
+                            {
+                                if (arr[i - 1] == "_")
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 2] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                                else
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) / Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 1] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                            }
+                            // остаток от деления
+                            else if (arr[i] == "%")
+                            {
+                                if (arr[i - 1] == "_")
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 2], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 2] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                                else
+                                {
+                                    arr[i] = Convert.ToString(Convert.ToInt32(arr[i - 1], ss) % Convert.ToInt32(arr[i + 1], ss), ss);
+                                    arr[i - 1] = "_";
+                                    arr[i + 1] = "_";
+                                }
+                            }
+                        }
+
+                        // узнаем размер будущего массива
+                        int l = 0;
+                        for (int i = 0; i < arr.Length; i++)
+                        {
+                            if (arr[i] != "_")
+                            {
+                                l++;
+                            }
+                        }
+
+                        // записать в новый массив результат предыдущего шага
+                        string[] arr2 = new string[l];
+                        int j = 0;
+                        for (int i = 0; i < arr.Length; i++)
+                        {
+                            if (arr[i] != "_")
+                            {
+                                arr2[j] = arr[i];
+                                j++;
+                            }
+                        }
+
+                        // первое число массива присваиваем переменной
+                        res = Convert.ToInt32(arr2[0], ss);
+
+                        // перебираем массив и считаем остальные операции
+                        for (int i = 1; i < arr2.Length; i++)
+                        {
+                            // сложение
+                            if (arr2[i] == "+")
+                            {
+                                res += Convert.ToInt32(arr2[i + 1], ss);
+                            }
+                            // вычитание
+                            else if (arr2[i] == "-")
+                            {
+                                res -= Convert.ToInt32(arr2[i + 1], ss);
+                            }
+                        }
+
+                        // выводим результат
+                        str.Text = Convert.ToString(res, ss);
+
+                        // добавляем вычисление в бд
+                        history record = new history()
+                        {
+                            inquiry = expression,
+                            result = Convert.ToString(res, ss),
+                            notation = Convert.ToString(ss)
+                        };
+                        _context.history.Add(record);
+                        _context.SaveChanges();
+                        Load();
+                        Diagram();
+                        dia.Series = SeriesCollection;
+                    }
+                    catch (Exception ex)
+                    {
+                        MessageBox.Show(ex.ToString());
+                    }
+                }
+            }
+            str.Focus();
+        }
     }
 }