calculator/Form1.cs
2025-12-01 14:10:45 +04:00

330 lines
9.0 KiB
C#

using BaseCalculator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Aksinchev
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button19_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 += "1";
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text += "2";
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "9";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
}
private void button20_Click(object sender, EventArgs e)
{
textBox1.Text += "*";
}
private void button6_Click(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += "(";
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += ")";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button18_Click(object sender, EventArgs e)
{
textBox1.Text += "-";
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "mod";
}
private void button25_Click(object sender, EventArgs e)
{
try
{
string expression = textBox1.Text;
AnalaizerClass.expression = expression;
if (!AnalaizerClass.CheckCurrency())
{
textBox2.Text = $"Ошибка:";
return;
}
expression = expression.Replace(" ", "").Replace("(", "").Replace(")", "");
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 if (expression.Contains("³"))
{
string[] parts = expression.Split('³');
if (parts.Length == 2)
{
double a = double.Parse(parts[0]);
double result = CalcClass.Cube(a);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("²"))
{
string[] parts = expression.Split('²');
if (parts.Length == 2)
{
double a = double.Parse(parts[0]);
double result = CalcClass.Square(a);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("sin"))
{
string[] parts = expression.Split(new string[] { "sin" }, StringSplitOptions.None);
if (parts.Length == 2)
{
double a = double.Parse(parts[0].Trim());
double result = CalcClass.Sinus(a);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("cos"))
{
string[] parts = expression.Split(new string[] { "cos" }, StringSplitOptions.None);
if (parts.Length == 2)
{
double a = double.Parse(parts[0].Trim());
double result = CalcClass.Cosinus(a);
textBox2.Text = result.ToString();
}
}
else if (expression.Contains("e"))
{
string[] parts = expression.Split('e');
if (parts.Length == 2)
{
double a = double.Parse(parts[0]);
double result = CalcClass.Exp(a);
textBox2.Text = result.ToString();
}
}
else
{
textBox2.Text = "Ошибка неверный формат выражения";
}
}
catch (Exception ex)
{
textBox2.Text = $"Ошибка: {ex.Message}";
}
}
private void button22_Click(object sender, EventArgs e)
{
textBox1.Text += "³";
}
private void button26_Click(object sender, EventArgs e)
{
textBox1.Text += "²";
}
private void button27_Click(object sender, EventArgs e)
{
textBox1.Text += "sin";
}
private void button28_Click(object sender, EventArgs e)
{
textBox1.Text += "cos";
}
private void button29_Click(object sender, EventArgs e)
{
textBox1.Text += "e";
}
}
}