CalculatorStudio/Form1.cs
2025-11-28 15:23:18 +04:00

209 lines
5.5 KiB
C#

using BaseCalculator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Siluyanov
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "2";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text += "9";
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
}
private void button20_Click(object sender, EventArgs e)
{
textBox1.Text += "+";
}
private void button19_Click(object sender, EventArgs e)
{
textBox1.Text += "-";
}
private void button18_Click(object sender, EventArgs e)
{
textBox1.Text += "*";
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text += "/";
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text += "Mod";
}
private void button24_Click(object sender, EventArgs e)
{
try
{
string expression = textBox1.Text;
if (expression.Contains("-"))
{
string[] parts = expression.Split('-');
if (parts.Length == 2)
{
long a = long.Parse(parts[0]);
long b = long.Parse(parts[1]);
int result = CalcClass.Sub(a, b);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("+"))
{
string[] parts = expression.Split('+');
if (parts.Length == 2)
{
long a = long.Parse(parts[0]);
long b = long.Parse(parts[1]);
int result = CalcClass.Add(a, b);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("*"))
{
string[] parts = expression.Split('*');
if (parts.Length == 2)
{
long a = long.Parse(parts[0]);
long b = long.Parse(parts[1]);
int result = CalcClass.Mult(a, b);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("/"))
{
string[] parts = expression.Split('/');
if (parts.Length == 2)
{
long a = long.Parse(parts[0]);
long b = long.Parse(parts[1]);
int result = CalcClass.Div(a, b);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("Mod"))
{
string[] parts = expression.Split(new string[] { "Mod" }, StringSplitOptions.None);
if (parts.Length == 2)
{
long a = long.Parse(parts[0].Trim());
long b = long.Parse(parts[1].Trim());
if (b==0)
{
textBox2.Text = "Ошибка: деление на ноль в операции Mod";
return;
}
int result = CalcClass.Mod(a, b);
textBox2.Text = result.ToString();
}
else
{
textBox2.Text = "Ошибка: неверный формат выражения для Mod";
}
}
else
{
textBox2.Text = "Ошибка неверный формат выражения";
}
}
catch (Exception ex)
{
textBox2.Text = $"Ошибка: {ex.Message}";
}
}
}
}