using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApp5
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private decimal xxx;
private char opteration;
private uint count;
private bool click_clear;
public MainWindow()
{
xxx = (decimal)0.0;
count = 0;
opteration = '+';
click_clear = false;
InitializeComponent();
}
private void Clear_Click(object sender, RoutedEventArgs e)
{
click_clear = true;
TextBox textbox = tb;
textbox.Text = "";
label.Content = "";
label_Copy.Content = "";
xxx = 0;
count = 0;
}
private void _0_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '0';
}
private void _1_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '1';
}
private void _2_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '2';
}
private void _3_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '3';
}
private void _4_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '4';
}
private void _5_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '5';
}
private void _6_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '6';
}
private void Button_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '7';
}
private void _8_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '8';
}
private void _9_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += '9';
}
private void _00_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
textbox.Text += "00";
}
private void Dot_b_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
if (textbox.Text.Contains('.'))
;
else
textbox.Text += '.';
}
private void Add_Click(object sender, RoutedEventArgs e)
{
count++;
Label mylab = label;
if (tb.Text.Equals(""))
{
mylab.Content = "";
mylab.Content = '+';
opteration = (char)mylab.Content;
}
else {
switch (opteration)
{
case '+':
try
{
xxx += Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '-':
try
{
xxx -= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '*':
try
{
if (0 == count)
xxx = 1;
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '/':
try
{
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
}
mylab.Content = "";
mylab.Content = '+';
opteration = (char)mylab.Content;
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
click_clear = false;
}
private void Sub_Click(object sender, RoutedEventArgs e)
{
count++;
Label mylab = label;
if (tb.Text.Equals(""))
{
mylab.Content = "";
mylab.Content = '-';
opteration = (char)mylab.Content;
}
else
{
switch (opteration)
{
case '+':
try
{
xxx += Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '-':
try
{
xxx -= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '*':
try
{
if (0 == count)
xxx = 1;
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '/':
try
{
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
}
mylab.Content = "";
mylab.Content = '-';
opteration = (char)mylab.Content;
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
click_clear = false;
}
private void Mul_Click(object sender, RoutedEventArgs e)
{
count++;
Label mylab = label;
if (tb.Text.Equals(""))
{
mylab.Content = "";
mylab.Content = '*';
opteration = (char)mylab.Content;
}
else
{
switch (opteration)
{
case '+':
try
{
xxx += Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '-':
try
{
xxx -= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '*':
try
{
if (0 == count || click_clear)
xxx = 1;
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '/':
try
{
if (0 == count || click_clear)
xxx = Convert.ToDecimal(tb.Text);
else
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
}
mylab.Content = "";
mylab.Content = '*';
opteration = (char)mylab.Content;
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
click_clear = false;
}
private void Div_Click(object sender, RoutedEventArgs e)
{
count++;
Label mylab = label;
if (tb.Text.Equals(""))
{
mylab.Content = "";
mylab.Content = '/';
opteration = (char)mylab.Content;
}
else
{
switch (opteration)
{
case '+':
try
{
xxx += Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '-':
try
{
xxx -= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '*':
try
{
if (0 == count || click_clear)
xxx = 1;
xxx *= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
case '/':
try
{
if (0 == count || click_clear)
xxx = Convert.ToDecimal(tb.Text);
else
xxx /= Convert.ToDecimal(tb.Text);
}
catch (Exception ee)
{
}
break;
}
mylab.Content = "";
mylab.Content = '/';
opteration = (char)mylab.Content;
}
tb.Text = "";
label_Copy.Content = xxx.ToString();
click_clear = false;
}
private void Delete_Click(object sender, RoutedEventArgs e)
{
TextBox textbox = tb;
try {
if (textbox.Text.Length > 0)
textbox.Text = textbox.Text.Substring(0, textbox.Text.Length - 1);
}
catch (Exception ee) {
}
}
private void Result_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Unable use!");
}
}
}