338 lines
9.4 KiB
C#
338 lines
9.4 KiB
C#
using BaseCalculator;
|
||
using System;
|
||
using System.Diagnostics.Eventing.Reader;
|
||
using System.Linq.Expressions;
|
||
using System.Windows.Forms;
|
||
|
||
namespace palopa.rur
|
||
{
|
||
public partial class Form1 : Form
|
||
{
|
||
public Form1()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void button6_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void button46_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Clear();
|
||
textBox2.Clear();
|
||
textBox1.Focus();
|
||
}
|
||
|
||
private void button25_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "1";
|
||
|
||
}
|
||
|
||
private void button29_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "4";
|
||
}
|
||
|
||
private void button38_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "0";
|
||
}
|
||
|
||
private void button41_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "MR";
|
||
}
|
||
|
||
private void Выражение_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void label2_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void button44_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.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.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.Mult(a, b);
|
||
|
||
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("/"))
|
||
{
|
||
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("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 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("³"))
|
||
|
||
{
|
||
string[] parts = expression.Split('³');
|
||
if (parts.Length == 2)
|
||
{
|
||
double a = double.Parse(parts[0]);
|
||
|
||
|
||
double result = CalcClass.Cube(a);
|
||
|
||
textBox2.Text = result.ToString();
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
textBox2.Text = $"Ошибка: неверный формат выражения";
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
textBox2.Text = $"Ошибка: {ex.Message}";
|
||
}
|
||
}
|
||
|
||
|
||
private void button26_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "2";
|
||
}
|
||
|
||
private void button27_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "3";
|
||
}
|
||
|
||
private void button30_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "5";
|
||
}
|
||
|
||
private void button31_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "6";
|
||
}
|
||
|
||
private void button33_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "7";
|
||
}
|
||
|
||
private void button34_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "8";
|
||
}
|
||
|
||
private void button35_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "9";
|
||
}
|
||
|
||
private void button40_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "+";
|
||
}
|
||
|
||
private void button36_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "-";
|
||
}
|
||
|
||
private void button32_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "*";
|
||
}
|
||
|
||
private void button39_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "Mod";
|
||
}
|
||
|
||
private void button28_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "/";
|
||
}
|
||
|
||
private void button47_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "(";
|
||
}
|
||
|
||
private void button48_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += ")";
|
||
}
|
||
|
||
private void button45_Click(object sender, EventArgs e)
|
||
{
|
||
if (!string.IsNullOrEmpty(textBox1.Text))
|
||
{
|
||
textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
|
||
}
|
||
}
|
||
|
||
private void button42_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void button49_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "sin";
|
||
}
|
||
|
||
private void button50_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "cos";
|
||
}
|
||
|
||
private void button51_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "e";
|
||
}
|
||
|
||
private void button52_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "²";
|
||
}
|
||
|
||
private void button53_Click(object sender, EventArgs e)
|
||
{
|
||
textBox1.Text += "³";
|
||
}
|
||
}
|
||
}
|
||
|