Загрузка данных
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 _42killer
{
public partial class Form1 : Form
{
public bool isClick = false;
public Form1()
{
InitializeComponent();
}
private void button_symbol_Click(object sender, EventArgs e)
{
if (!textBox_result.Text.Contains(","))
{
textBox_result.Text = textBox_result.Text + ",";
}
}
private void button_remove_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox_result.Text))
{
textBox_result.Text = textBox_result.Text.Remove(textBox_result.Text.Length - 1);
}
}
private void button_0_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "0";
}
private void button_1_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "1";
}
private void button_2_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "2";
}
private void button_3_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "3";
}
private void button_4_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "4";
}
private void button_5_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "5";
}
private void button_6_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "6";
}
private void button_7_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "7";
}
private void button_8_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "8";
}
private void button_9_Click(object sender, EventArgs e)
{
textBox_result.Text = textBox_result.Text + "9";
}
private void button_reset_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox_result.Text))
{
textBox_result.Text = "";
}
}
private void button_getResult_Click(object sender, EventArgs e)
{
char op = ' ';
if (textBox_result.Text.Contains("+")) op = '+';
else if (textBox_result.Text.Contains("-")) op = '-';
else if (textBox_result.Text.Contains("*")) op = '*';
else if (textBox_result.Text.Contains("/")) op = '/';
if (op != ' ')
{
string[] parts = textBox_result.Text.Split(op);
if (parts.Length == 2 && double.TryParse(parts[0], out double num1) && double.TryParse(parts[1], out double num2))
{
double result = 0;
if (op == '+') result = num1 + num2;
else if (op == '-') result = num1 - num2;
else if (op == '*') result = num1 * num2;
else if (op == '/')
{
if (num2 == 0)
{
textBox_result.Text = "Ошибка!";
isClick = false;
return;
}
result = num1 / num2;
}
label_old.Text = textBox_result.Text + "=" + result.ToString();
textBox_result.Text = result.ToString();
isClick = false;
}
}
}
private void button_fun1_Click(object sender, EventArgs e)
{
if (isClick == true)
{
string[] parts = textBox_result.Text.Split('+');
if (parts.Length == 2 && double.TryParse(parts[0], out double num1) && double.TryParse(parts[1], out double num2))
{
double result = num1 + num2;
label_old.Text = textBox_result.Text + "=" + result.ToString();
textBox_result.Text = result.ToString() + "+";
isClick = true;
}
else
{
return;
}
}
else
{
textBox_result.Text = textBox_result.Text + "+";
isClick = true;
}
}
private void button_func2_Click(object sender, EventArgs e)
{
if (isClick == true)
{
string[] parts = textBox_result.Text.Split('-');
if (parts.Length == 2 && double.TryParse(parts[0], out double num1) && double.TryParse(parts[1], out double num2))
{
double result = num1 - num2;
label_old.Text = textBox_result.Text + "=" + result.ToString();
textBox_result.Text = result.ToString() + "-";
isClick = true;
}
else
{
return;
}
}
else
{
textBox_result.Text = textBox_result.Text + "-";
isClick = true;
}
}
private void button_func3_Click(object sender, EventArgs e)
{
if (isClick == true)
{
string[] parts = textBox_result.Text.Split('*');
if (parts.Length == 2 && double.TryParse(parts[0], out double num1) && double.TryParse(parts[1], out double num2))
{
double result = num1 * num2;
label_old.Text = textBox_result.Text + "=" + result.ToString();
textBox_result.Text = result.ToString() + "*";
isClick = true;
}
else
{
return;
}
}
else
{
textBox_result.Text = textBox_result.Text + "*";
isClick = true;
}
}
private void button_func4_Click(object sender, EventArgs e)
{
if (isClick == true)
{
string[] parts = textBox_result.Text.Split('/');
if (parts.Length == 2 && double.TryParse(parts[0], out double num1) && double.TryParse(parts[1], out double num2))
{
if (num2 == 0)
{
textBox_result.Text = "Ошибка!";
isClick = false;
return;
}
double result = num1 / num2;
label_old.Text = textBox_result.Text + "=" + result.ToString();
textBox_result.Text = result.ToString() + "/";
isClick = true;
}
else
{
return;
}
}
else
{
textBox_result.Text = textBox_result.Text + "/";
isClick = true;
}
}
private void button_func5_Click(object sender, EventArgs e)
{
if (double.TryParse(textBox_result.Text, out double num))
{
double result = Math.Pow(num, 2);
label_old.Text = textBox_result.Text + "²=" + result.ToString();
textBox_result.Text = result.ToString();
isClick = false;
}
}
private void button_func6_Click(object sender, EventArgs e)
{
if (double.TryParse(textBox_result.Text, out double num))
{
if (num < 0)
{
textBox_result.Text = "Ошибка!";
isClick = false;
return;
}
double result = Math.Sqrt(num);
label_old.Text = "√(" + num.ToString() + ")=" + result.ToString();
textBox_result.Text = result.ToString();
isClick = false;
}
}
}
}