Пример #1
0
 public void PercentButton()
 {
     if (String.IsNullOrEmpty(Operator))
     {
         decimal result = Convert.ToDecimal(FirstOperand.FullPart);
         result = (result == 0 ? (decimal)(1f / 100f) : (decimal)(result / 100));
         FirstOperand.Equal(result);
     }
     else
     {
         decimal result = Convert.ToDecimal(SecondOperand.FullPart);
         result = (result == 0 ? (decimal)(1f / 100f) : (decimal)(result / 100));
         SecondOperand.Equal(result);
     }
     NotifyOfPropertyChange(() => Result);
 }
Пример #2
0
        public void EqualButton()
        {
            decimal result;

            Expression = Result;
            try
            {
                switch (Operator)
                {
                case "+":
                    result        = Convert.ToDecimal(FirstOperand.FullPart) + Convert.ToDecimal(SecondOperand.FullPart);
                    SecondOperand = new Operand();
                    FirstOperand.Equal(result);
                    Operator = "";
                    break;

                case "-":
                    result        = Convert.ToDecimal(FirstOperand.FullPart) - Convert.ToDecimal(SecondOperand.FullPart);
                    SecondOperand = new Operand();
                    FirstOperand.Equal(result);
                    Operator = "";
                    break;

                case "*":
                    result        = Convert.ToDecimal(FirstOperand.FullPart) * Convert.ToDecimal(SecondOperand.FullPart);
                    SecondOperand = new Operand();
                    FirstOperand.Equal(result);
                    Operator = "";
                    break;

                case "/":
                    result        = Convert.ToDecimal(FirstOperand.FullPart) / Convert.ToDecimal(SecondOperand.FullPart);
                    SecondOperand = new Operand();
                    FirstOperand.Equal(result);
                    Operator = "";
                    break;

                default:
                    return;
                }
                NotifyOfPropertyChange(() => Result);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }