Beispiel #1
0
 /// <summary>
 ///  processing a click on "equal" button where is the main choice of further operations and functions
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void equal_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length > 0 && textBox2.Text.Length > 0) // textBox is not empty
     {
         if (textBox3.Text.Length == 0 || flag > 0)
         {
             textBox3.Text = textBox1.Text;
             secondNumber  = Convert.ToDouble(textBox3.Text);
             firstNumber   = Convert.ToDouble(textBox2.Text);
             ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator(Operation);
             result = calculator.Calculate(firstNumber, secondNumber);
             def1();
         }
         else
         {
             textBox2.Text = textBox1.Text;
             secondNumber  = Convert.ToDouble(textBox3.Text);
             firstNumber   = Convert.ToDouble(textBox2.Text);
             ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator(Operation);
             result = calculator.Calculate(firstNumber, secondNumber);
             def1();
         }
     }
     else
     {
         textBox1.Focus();
     }
     textBox1.Focus();
 }
Beispiel #2
0
        private void proc_Click(object sender, EventArgs e)
        {
            flag++;
            textBox3.Text = textBox1.Text + "%";
            secondNumber  = Convert.ToDouble(textBox1.Text);
            firstNumber   = Convert.ToDouble(textBox2.Text);
            ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator("proc");

            result        = calculator.Calculate(firstNumber, secondNumber);
            textBox1.Text = Convert.ToString(result);
        }
        public ActionResult Index(
            double firstNumber,
            double secondNumber,
            string operation)
        {
            string[] arr = { "Mult", "Div", "Plus", "Minus", "Max" };
            double   result;

            if (arr.Contains(operation))
            {
                ITwoArgCalculator calculator = TwoArgFactory.CreateObjectOrientedCalculator(operation);
                result = calculator.Calculate(firstNumber, secondNumber);
            }
            else
            {
                IOneArgCalculator calculator = OneArgFactory.CreateObjectOrientedCalculator(operation);
                result = calculator.Calculate(firstNumber);
            }

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "Mult", Text = "Multiply"
                },
                new SelectListItem()
                {
                    Value = "Plus", Text = "Sum"
                },
                new SelectListItem()
                {
                    Value = "Minus", Text = "Minus"
                },
                new SelectListItem()
                {
                    Value = "Div", Text = "Division"
                },
                new SelectListItem()
                {
                    Value = "Exp", Text = "Exponent"
                },
                new SelectListItem()
                {
                    Value = "Max", Text = "Maximum"
                },
            };
            return(View());
        }
 private void button15_Click(object sender, EventArgs e)
 {
     b = Convert.ToDouble(textBox1.Text);
     if (Operation == ("Div") && b == 0)
     {
         MessageBox.Show("Деление на ноль невозможно");
         textBox1.Clear();
     }
     else
     {
         ITwoArgCalculator calculator = TwoArgFactory.CreateObjectOrientedCalculator(Operation);
         double            res        = calculator.Calculate(a, b);
         textBox1.Text = res.ToString();
     }
 }
        public ActionResult Index(
            double firstNumber,
            double secondNumber,
            string operation)
        {
            string[] arr = { "mult", "div", "plus", "minus" };
            double   result;

            if (arr.Contains(operation))
            {
                ITwoArgCalculator calculator = TwoArgFactory.CreateCalculator(operation);
                result = calculator.Calculate(firstNumber, secondNumber);
            }
            else
            {
                IOneArgCalculator calculator = OneArgFactory.CreateCalculator(operation);
                result = calculator.Calculate(firstNumber);
            }

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "mult", Text = "multiply"
                },
                new SelectListItem()
                {
                    Value = "plus", Text = "sum"
                },
                new SelectListItem()
                {
                    Value = "minus", Text = "minus"
                },
                new SelectListItem()
                {
                    Value = "div", Text = "division"
                },
                new SelectListItem()
                {
                    Value = "sin", Text = "sin"
                },
                new SelectListItem()
                {
                    Value = "cos", Text = "cos"
                },
                new SelectListItem()
                {
                    Value = "tg", Text = "tg"
                },
                new SelectListItem()
                {
                    Value = "ctg", Text = "ctg"
                },
                new SelectListItem()
                {
                    Value = "sqrt", Text = "sqrt"
                }
            };
            return(View());
        }