Beispiel #1
0
        private void Operator_Clicked(object sender, EventArgs e) // When an operator is clicked
        {
            Button button = (Button)sender;


            if (textBox1.Text != "0")
            {
                textBox1.Text += button.Text;
                Sign           = button.Text; // Assigning the last operator clicked to the field Name of SIGN

                values += button.Text;        // Adding the operator to the values
            }
            Count++;                          // Incrementing the count as the operator button is been clicked

            if (Count >= 2)                   // if the operator has been clicked 2 or more times calculation is automatically processed
            {
                try
                {
                    var removeLastOperator = values.Remove(values.Length - 1);                            // Removes the last Operator Calculation is done based on the two values provided

                    var listOfDoubles = Utils.ExtractValuesFromString(removeLastOperator);                // Returns the extracted values from a string as a list of double

                    Calculator calculatorData = new Calculator(listOfDoubles[0], listOfDoubles[1], Sign); // An Object is created of the Calculator class

                    var result = calc.Calculate(calculatorData);                                          // Calls the calculate method of the CalculatorRepository class and returns the result


                    textBox2.Text = result.ToString(); // Adding the result to the screen

                    values = result.ToString() + Sign; // Updating the values
                }
                catch (Exception) { } // Making sure there are no crashes to the based on exceptions generated
            }
        }
        public int CalculateValue(GlobalEnums.OperatorsEnum operatorsEnum, int firstValue, int secondValue)
        {
            int result = _serviceAccessor(operatorsEnum).PerformOperation(firstValue, secondValue);

            _iCalculatorRepository.Calculate(operatorsEnum, result);
            return(result);
        }
Beispiel #3
0
 private void SubmitClick(object sender, EventArgs e)
 {
     try
     {
         string response = string.Empty;
         if (!_isDev)
         {
             response = _httpRepo.InvokeService(_serviceUrl, "GET", string.Empty, "application/json", null);
         }
         else
         {
             //Modify the path accordingly
             response = System.IO.File.ReadAllText(@"E:\DemoCalculatorClient\DemoCalculatorClient\Result.json");
         }
         if (!string.IsNullOrEmpty(response))
         {
             var opModel = JsonUtil.Deserialize <Operation>(response);
             opModel.Result = _calRepo.Calculate(opModel);
             _logger.AppendLog(opModel.ToString());
         }
     }
     catch (Exception ex)
     {
         _logger.AppendLog(ex.Message);
     }
 }