Пример #1
0
        /// <summary>
        /// Handler for operations with two arguments
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CalculateTwoArguments(object sender, EventArgs e)
        {
            try
            {
                string InputOne = ValueOneInput.Text;
                string InputTwo = ValueTwoInput.Text;

                if (InputOne.Length == 0 || InputTwo.Length == 0)
                {
                    throw new Exception("Argument missing");
                }

                string senderName    = ((Button)sender).Name;
                string operationName = senderName.Replace("Button", "");

                double firstValue  = MyValidator.ValidateAndConvertToDouble(ValueOneInput.Text);
                double secondValue = MyValidator.ValidateAndConvertToDouble(ValueTwoInput.Text);

                ITwoArgumentsCalculator Calculator = TwoArgumentsFactory.CreateCalculator(operationName);
                var calculateResult = Calculator.Calculate(firstValue, secondValue);

                OutputField.Text = calculateResult.ToString();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Error");
            }
        }
Пример #2
0
 private void Calculate(object sender, EventArgs e)
 {
     try
     {
         double firstNumber  = Convert.ToDouble(this.textBox1.Text);
         double secondNumber = Convert.ToDouble(this.textBox2.Text);
         double result;
         ITwoArgumentsCalculator calculator = TwoArgumentsFactory.CreateCalculator(((Button)sender).Name);
         result        = calculator.calculate(firstNumber, secondNumber);
         textBox3.Text = result.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }