Exemplo n.º 1
0
 private void btnOperator_Click(object sender, EventArgs e)
 {
     if (lblDisplay.Text is "Error")
     {
         return;
     }
     if (isAfterOperater)
     {
         return;
     }
     operate = ((Button)sender).Text;
     if (!isfirstOperater)
     {
         if (lblDisplay.Text is "Error")
         {
             return;
         }
         string secondOperand = lblDisplay.Text;
         string result        = engine.calculate(operate, firstOperand, secondOperand);
         if (result is "E" || result.Length > 8)
         {
             lblDisplay.Text = "Error";
         }
         else
         {
             lblDisplay.Text = result;
         }
     }
Exemplo n.º 2
0
 private void btnOperator_Click(object sender, EventArgs e)
 {
     if (lblDisplay.Text is "Error")
     {
         return;
     }
     if (isAfterOperater)
     {
         operate = ((Button)sender).Text;
         return;
     }
     if (have2)
     {
         if (lblDisplay.Text is "Error")
         {
             return;
         }
         secondOperand = lblDisplay.Text;
         string result = ku.calculate(operate, firstOperand, secondOperand);
         if (result is "E" || result.Length > 8)
         {
             lblDisplay.Text = "Error";
         }
         else
         {
             lblDisplay.Text = result;
         }
         isAfterEqual = true;
         have2        = false;
     }
Exemplo n.º 3
0
        private void btnOperator_Click(object sender, EventArgs e)
        {
            if (lblDisplay.Text is "Error")
            {
                return;
            }
            if (isOperater)
            {
                string secondOperand = lblDisplay.Text;
                string result        = engine.calculate(operate, firstOperand, secondOperand);
                lblDisplay.Text = result;
            }
            if (isAfterOperater)
            {
                return;
            }
            operate = ((Button)sender).Text;
            switch (operate)
            {
            case "+":
            case "-":
            case "X":
            case "÷":
                firstOperand    = lblDisplay.Text;
                isAfterOperater = true;
                break;

            case "%":
                // your code here
                engine.calculate(operate, firstOperand, "0");
                break;

            case "1/x":
                engine.calculate(operate, firstOperand, "0");
                break;

            case "√":
                engine.calculate(operate, firstOperand, "0");
                break;
            }
            //อัพละทำไมไม่ขึ้น
            isAllowBack = false;
            isOperater  = true;
        }
Exemplo n.º 4
0
        private void btnOperator_Click(object sender, EventArgs e)
        {
            if (lblDisplay.Text == "Error")
            {
                return;
            }
            if (isAfterOperater)
            {
                return;
            }
            if (firstOperand != null)
            {
                string secondOperand = lblDisplay.Text;
                string result        = engine.calculate(operate, firstOperand, secondOperand);
                if (result == "E" || result.Length > 8)
                {
                    lblDisplay.Text = "Error";
                }
                else
                {
                    lblDisplay.Text = result;
                }
                firstOperand = lblDisplay.Text;
            }

            operate = ((Button)sender).Text;
            switch (operate)
            {
            case "+":
            case "-":
            case "X":
            case "÷":
                firstOperand    = lblDisplay.Text;
                isAfterOperater = true;
                break;

            case "%":
            case "√":
                break;
            }
            isAllowBack = false;
        }
Exemplo n.º 5
0
        private void btnEqual_Click(object sender, EventArgs e)
        {
            if (lblDisplay.Text is "Error")
            {
                return;
            }
            string secondOperand = lblDisplay.Text;
            string result        = engine.calculate(operate, firstOperand, secondOperand); //

            if (result is "E" || result.Length > 8)                                        //ถ้าค่าเกิน8จะError
            {
                lblDisplay.Text = "Error";
            }
Exemplo n.º 6
0
        private void btnOperator_Click(object sender, EventArgs e)
        {
            if (lblDisplay.Text is "Error")
            {
                return;
            }
            if (isAfterOperater)
            {
                return;
            }

            operateOfMod = operate;
            operate      = ((Button)sender).Text;

            if (firstOperand != null)
            {
                secondOperand = lblDisplay.Text;
                if (operate == "%")
                {
                    isMod           = true;
                    resultMod       = engine.calculate(operate, firstOperand, lblDisplay.Text);
                    firstNum        = firstOperand;
                    lblDisplay.Text = resultMod;
                    operate         = operateOfMod;
                }
                else
                {
                    string result = engine.calculate(operate, firstOperand, secondOperand);
                    if (result is "E" || result.Length > 8)
                    {
                        lblDisplay.Text = "Error";
                    }
                    else
                    {
                        lblDisplay.Text = result;
                        firstOperand    = result;
                    }
                }
Exemplo n.º 7
0
        private void btnEqual_Click(object sender, EventArgs e)
        {
            if (lblDisplay.Text is "Error")
            {
                return;
            }
            string secondOperand = lblDisplay.Text;
            string result        = calculate.calculate(operate, firstOperand, secondOperand);

            /*      if (operate == "√")
             *    {
             *        result= (Math.Sqrt(Convert.ToDouble(secondOperand))).ToString();
             *
             *    }*/
            if (result is "E" || result.Length > 8)
            {
                lblDisplay.Text = "Error";
            }
Exemplo n.º 8
0
 private void btnOperator_Click(object sender, EventArgs e)
 {
     if (secondOperandClicked && isAfterOperater == false)
     {
         if (lblDisplay.Text is "Error")
         {
             return;
         }
         string secondOperand = lblDisplay.Text;
         string result        = cal.calculate(operate, firstOperand, secondOperand);
         if (result is "E" || result.Length > 8)
         {
             lblDisplay.Text = "Error";
         }
         else
         {
             lblDisplay.Text = result;
         }
         isAfterEqual         = true;
         secondOperandClicked = false;
     }
Exemplo n.º 9
0
        private void btnOperator_Click(object sender, EventArgs e)
        {
            operate = ((Button)sender).Text;

            if (firstOperand == "0" || firstOperand == null)
            {
                firstOperand = lblDisplay.Text;
                result       = firstOperand;
            }
            else
            {
                if (isAfterEqual)
                {
                    firstOperand = lblDisplay.Text;
                }
                else
                {
                    secondOperand = lblDisplay.Text;
                }

                result = ce.calculate(operate, firstOperand, secondOperand);
            }

            if (lblDisplay.Text is "Error")
            {
                return;
            }
            if (result == "E" || result.Length > 8)
            {
                lblDisplay.Text = "Error";
            }
            else
            {
                lblDisplay.Text = result;
            }

            switch (operate)
            {
            case "+":
            case "-":
            case "X":
            case "÷":
                firstOperand    = lblDisplay.Text;
                isAfterOperater = true;
                tempOperate     = operate;
                break;

            case "%":
                pcFlag          = true;
                lblDisplay.Text = ce.calculate(operate, firstOperand, secondOperand);

                break;

            case "1/x":
            case "√":
                firstOperand    = lblDisplay.Text;
                result          = ce.calculate(operate, firstOperand, "0");
                lblDisplay.Text = result;
                //secondOperand = result;
                break;
            }
            hasDot      = false;
            isAllowBack = false;
        }
Exemplo n.º 10
0
        private void btnOperator_Click(object sender, EventArgs e)
        {
            string secondOperand = "0";

            operate = ((Button)sender).Text;
            if (((Button)sender).Text != "%")
            {
                operated = operate;
            }
            if (lblDisplay.Text is "Error")
            {
                return;
            }
            if (isAfterOperater)
            {
                return;
            }
            if (twotime)
            {
                Console.WriteLine(firstOperand);
                Console.WriteLine(secondOperand);
                if (((Button)sender).Text == "%")
                {
                    secondOperand   = ((Convert.ToDouble(firstOperand) / 100) * Convert.ToDouble(lblDisplay.Text)).ToString();
                    lblDisplay.Text = secondOperand;
                }
                if (((Button)sender).Text == "+")
                {
                    firstOperand = secondOperand;
                }
                Console.WriteLine(secondOperand);
                Console.WriteLine(operated);
                secondOperand = lblDisplay.Text;
                string result = engine.calculate(operated, firstOperand, secondOperand);
                firstOperand    = result;
                operate         = ((Button)sender).Text;
                lblDisplay.Text = result;
                twotimeop       = true;
                secondOperand   = "0";
                return;
            }
            twotime      = true;
            twotimeop    = true;
            firstOperand = lblDisplay.Text;
            switch (((Button)sender).Text)
            {
            case "+":
                break;

            case "-":
                break;

            case "x":
                break;

            case "÷":
                isAfterOperater = true;
                break;

            case "%":
                lblDisplay.Text = engine.calculate(operate, firstOperand, secondOperand);
                Console.WriteLine(operate);
                break;
            }
            isAllowBack = false;
            Console.WriteLine((Button)sender);
        }