private void EqualsButton_Click(object sender, RoutedEventArgs e)
        {
            double newNumber;

            expressionLabel.Content = $"{expressionLabel.Content}=";
            if (double.TryParse(resultLabel.Content.ToString(), out newNumber))
            {
                switch (selectedOperator)
                {
                case SelectedOperator.Addtion:
                    result = SimpleMath.Add(lastNumber, newNumber);
                    break;

                case SelectedOperator.Subtraction:
                    result = SimpleMath.Sub(lastNumber, newNumber);
                    break;

                case SelectedOperator.Multiplication:
                    result = SimpleMath.Mul(lastNumber, newNumber);
                    break;

                case SelectedOperator.Division:
                    result = SimpleMath.Div(lastNumber, newNumber);
                    break;
                }

                resultLabel.Content = result.ToString();

                equalsClicked = true;
            }
        }
예제 #2
0
        private void EqualButton_Click(object sender, RoutedEventArgs e)
        {
            double newNumber;

            if (double.TryParse(resultLabel.Content.ToString(), out newNumber))
            {
                switch (selectedOperator)
                {
                case SelectedOperator.Addition:
                    result = SimpleMath.Add(lastNumber, newNumber);
                    break;

                case SelectedOperator.Substraction:
                    result = SimpleMath.Sub(lastNumber, newNumber);
                    break;

                case SelectedOperator.Multiplication:
                    result = SimpleMath.Multiply(lastNumber, newNumber);
                    break;

                case SelectedOperator.Division:
                    result = SimpleMath.Divide(lastNumber, newNumber);
                    break;

                default:
                    break;
                }

                resultLabel.Content = result.ToString();
            }
        }
예제 #3
0
        // = 버튼
        private void EqualButton_Click(object sender, RoutedEventArgs e)
        {
            double newNumber = 0;
            double result    = double.Parse(resultLable.Content.ToString());


            if (double.TryParse(resultLable.Content.ToString(), out newNumber))
            {
                switch (selectedOperator)
                {
                case SelectedOperator.Addition:
                    result = SimpleMath.Add(lastValue, newNumber);
                    state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString());
                    resultexp.Content = "";
                    break;

                case SelectedOperator.Substraction:
                    result = SimpleMath.Sub(lastValue, newNumber);
                    state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString());
                    resultexp.Content = "";
                    break;

                case SelectedOperator.Multipication:
                    result = SimpleMath.Mul(lastValue, newNumber);
                    state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString());
                    resultexp.Content = "";
                    break;

                case SelectedOperator.Division:
                    result = SimpleMath.Div(lastValue, newNumber);
                    state.Items.Add(resultexp.Content.ToString() + newNumber + "=" + result.ToString());
                    resultexp.Content = "";
                    break;
                }
                resultLable.Content = result.ToString();
                lastValue           = 0;
                tmp   = 0;
                Flag  = 0;
                Flag2 = 0;
            }
        }
예제 #4
0
        }//이벤트 등록

        //연산자 함수
        private void OperationButton_Click(object sender, RoutedEventArgs e)
        {
            //lastValue = double.Parse(resultLable.Content.ToString());
            //resultLable.Content = "0";

            if (double.TryParse(resultLable.Content.ToString(), out lastValue))
            {
                resultLable.Content = "0";
            }
            if (sender == addButton)
            {
                if (Flag == 0)
                {
                    selectedOperator   = SelectedOperator.Addition;
                    resultexp.Content += lastValue + "+";
                    Flag++;
                    result = lastValue;
                    tmp   += lastValue;
                    Flag2  = 1;
                }
                else
                {
                    if (Flag2 == 1)
                    {
                        selectedOperator = SelectedOperator.Addition;
                        tmp = SimpleMath.Add(tmp, lastValue);
                        resultexp.Content += lastValue + "+";
                    }
                    else if (Flag2 == 2)
                    {
                        selectedOperator = SelectedOperator.Addition;
                        tmp = SimpleMath.Sub(tmp, lastValue);
                        resultexp.Content += lastValue + "+";
                    }
                    else if (Flag2 == 3)
                    {
                        selectedOperator = SelectedOperator.Addition;
                        tmp = SimpleMath.Mul(tmp, lastValue);
                        resultexp.Content += lastValue + "+";
                    }
                    else
                    {
                        selectedOperator = SelectedOperator.Addition;
                        tmp = SimpleMath.Div(tmp, lastValue);
                        resultexp.Content += lastValue + "+";
                    }
                }
                Flag2 = 1;
            }
            if (sender == subButton)
            {
                if (Flag == 0)
                {
                    selectedOperator   = SelectedOperator.Substraction;
                    resultexp.Content += lastValue + "-";
                    Flag++;
                    result = lastValue;
                    tmp   += lastValue;
                    Flag2  = 2;
                }
                else
                {
                    if (Flag2 == 1)
                    {
                        selectedOperator = SelectedOperator.Substraction;
                        tmp = SimpleMath.Add(tmp, lastValue);
                        resultexp.Content += lastValue + "-";
                    }
                    else if (Flag2 == 2)
                    {
                        selectedOperator = SelectedOperator.Substraction;
                        tmp = SimpleMath.Sub(tmp, lastValue);
                        resultexp.Content += lastValue + "-";
                    }
                    else if (Flag2 == 3)
                    {
                        selectedOperator = SelectedOperator.Substraction;
                        tmp = SimpleMath.Mul(tmp, lastValue);
                        resultexp.Content += lastValue + "-";
                    }
                    else
                    {
                        selectedOperator = SelectedOperator.Substraction;
                        tmp = SimpleMath.Div(tmp, lastValue);
                        resultexp.Content += lastValue + "-";
                    }
                }
                Flag2 = 2;
            }

            if (sender == mulButton)
            {
                if (Flag == 0)
                {
                    selectedOperator   = SelectedOperator.Multipication;
                    resultexp.Content += lastValue + "*";
                    Flag++;
                    result = lastValue;
                    tmp    = lastValue;
                    Flag2  = 3;
                }
                else
                {
                    if (Flag2 == 1)
                    {
                        selectedOperator = SelectedOperator.Multipication;
                        tmp = SimpleMath.Add(tmp, lastValue);
                        resultexp.Content += lastValue + "*";
                    }
                    else if (Flag2 == 2)
                    {
                        selectedOperator = SelectedOperator.Multipication;
                        tmp = SimpleMath.Sub(tmp, lastValue);
                        resultexp.Content += lastValue + "*";
                    }
                    else if (Flag2 == 3)
                    {
                        selectedOperator = SelectedOperator.Multipication;
                        tmp = SimpleMath.Mul(tmp, lastValue);
                        resultexp.Content += lastValue + "*";
                    }
                    else
                    {
                        selectedOperator = SelectedOperator.Multipication;
                        tmp = SimpleMath.Div(tmp, lastValue);
                        resultexp.Content += lastValue + "*";
                    }
                }
                Flag2 = 3;
            }
            if (sender == divButton)
            {
                if (Flag == 0)
                {
                    selectedOperator   = SelectedOperator.Division;
                    resultexp.Content += lastValue + "/";
                    Flag++;
                    result = lastValue;
                    tmp    = lastValue;
                    Flag2  = 4;
                }
                else
                {
                    if (Flag2 == 1)
                    {
                        selectedOperator = SelectedOperator.Division;
                        tmp = SimpleMath.Add(tmp, lastValue);
                        resultexp.Content += lastValue + "/";
                    }
                    else if (Flag2 == 2)
                    {
                        selectedOperator = SelectedOperator.Division;
                        tmp = SimpleMath.Sub(tmp, lastValue);
                        resultexp.Content += lastValue + "/";
                    }
                    else if (Flag2 == 3)
                    {
                        selectedOperator = SelectedOperator.Division;
                        tmp = SimpleMath.Mul(tmp, lastValue);
                        resultexp.Content += lastValue + "/";
                    }
                    else
                    {
                        selectedOperator = SelectedOperator.Division;
                        tmp = SimpleMath.Div(tmp, lastValue);
                        resultexp.Content += lastValue + "/";
                    }
                }
                Flag2 = 4;
            }
        }