예제 #1
0
        /// <summary>
        /// Checks the input for errors.
        /// Check for Non Numerical Data and Input out of range errors
        /// </summary>
        /// <returns>INPUT_VALIDATION_FLAG</returns>
        /// <param name="input">User Input as a string.</param>
        /// <param name="outputNum">Output number is the number that gets initialised if input is an integer.</param>
        /// <param name="minNum">Minimum number.</param>
        /// <param name="maxNum">Max number.</param>
        protected INPUT_VALIDATION_FLAG CheckInputForErrors(string input, ref int outputNum, int minNum, int maxNum, INPUT_FIELD inputField)
        {
            INPUT_VALIDATION_FLAG inputFlag = INPUT_VALIDATION_FLAG.INPUT_OK;

            // Check degrees1 if data has been entered
            if (!NoDataEntered(input))
            {
                if (NonNumericalDataEntered(input, ref outputNum))
                {
                    inputFlag = INPUT_VALIDATION_FLAG.NON_NUMERICAL_DATA_ENTERED;
                }
                else if (NumberOutOfRange(maxNum, minNum, outputNum))
                {
                    if (inputField == INPUT_FIELD.DEGREES)
                    {
                        inputFlag = INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_DEGREES;
                    }
                    else if (inputField == INPUT_FIELD.MINUTES)
                    {
                        inputFlag = INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_MINUTES;
                    }
                    else
                    {
                        inputFlag = INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_SECONDS;
                    }
                }
            }

            return(inputFlag);
        }
예제 #2
0
        /// <summary>
        /// Checks all input for Null entry data and Non-numerical data.
        /// Returns INPUT_VALIDATION_FLAG enum to indicate the status of the input
        /// If data passes all the tests then INPUT_OK is returned
        /// </summary>
        /// <returns>INPUT_VALIDATION_FLAG.</returns>
        private INPUT_VALIDATION_FLAG CheckAllInput()
        {
            INPUT_VALIDATION_FLAG inputFlag = INPUT_VALIDATION_FLAG.INPUT_OK;

            // check for no data entered
            if (NoDataEnteredAngle(_degrees1, _minutes1, _seconds1) && NoDataEnteredAngle(_degrees2, _minutes2, _seconds2))
            {
                return(INPUT_VALIDATION_FLAG.NO_INPUT_ENTERED);
            }

            inputFlag = CheckInputForErrors(_degrees1, ref _degreesInt1, 0, 360, INPUT_FIELD.DEGREES);

            if (inputFlag != INPUT_VALIDATION_FLAG.INPUT_OK)
            {
                return(inputFlag);
            }

            inputFlag = CheckInputForErrors(_degrees2, ref _degreesInt2, 0, 360, INPUT_FIELD.DEGREES);

            if (inputFlag != INPUT_VALIDATION_FLAG.INPUT_OK)
            {
                return(inputFlag);
            }

            inputFlag = CheckInputForErrors(_minutes1, ref _minutesInt1, 0, 60, INPUT_FIELD.MINUTES);

            if (inputFlag != INPUT_VALIDATION_FLAG.INPUT_OK)
            {
                return(inputFlag);
            }

            inputFlag = CheckInputForErrors(_minutes2, ref _minutesInt2, 0, 60, INPUT_FIELD.MINUTES);

            if (inputFlag != INPUT_VALIDATION_FLAG.INPUT_OK)
            {
                return(inputFlag);
            }

            inputFlag = CheckInputForErrors(_seconds1, ref _secondsInt1, 0, 60, INPUT_FIELD.SECONDS);

            if (inputFlag != INPUT_VALIDATION_FLAG.INPUT_OK)
            {
                return(inputFlag);
            }

            inputFlag = CheckInputForErrors(_seconds2, ref _secondsInt2, 0, 60, INPUT_FIELD.SECONDS);

            if (inputFlag != INPUT_VALIDATION_FLAG.INPUT_OK)
            {
                return(inputFlag);
            }

            return(inputFlag);
        }
        /// <summary>
        /// Displays the error message according to Error type.
        /// </summary>
        /// <param name="errorType">Error type.</param>
        private async void DisplayErrorMessage(INPUT_VALIDATION_FLAG errorType)
        {
            switch (errorType)
            {
            case INPUT_VALIDATION_FLAG.NO_INPUT_ENTERED:
                await _pageService.DisplayAlert("No Data Entered", "Please enter some data", "Ok");

                break;

            case INPUT_VALIDATION_FLAG.NO_DISTANCE_INPUT_ENTERED:
                await _pageService.DisplayAlert("No Distance Data Entered", "Please enter some data in the Distance field", "Ok");

                break;

            case INPUT_VALIDATION_FLAG.NO_BEARING_DATA_ENTERED:
                await _pageService.DisplayAlert("No Bearing Data Entered", "Please enter some data in the Degrees, Minutes or Seconds field", "Ok");

                break;

            case INPUT_VALIDATION_FLAG.NON_NUMERICAL_DATA_ENTERED:
                await _pageService.DisplayAlert("Data Entry Error", "Non-numerical data entered, please enter numerical data only", "Ok");

                break;

            case INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_DEGREES:
                await _pageService.DisplayAlert("Out of Range Error", "Please enter a value between 0 and 359 in the degrees field", "Ok");

                break;

            case INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_MINUTES:
                await _pageService.DisplayAlert("Out of Range Error", "Please enter a value between 0 and 59 in the minutes field", "Ok");

                break;

            case INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_SECONDS:
                await _pageService.DisplayAlert("Out of Range Error", "Please enter a value between 0 and 59 in the seconds field", "Ok");

                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Is the data input ok.
        /// Need to check for no data entered in all fields.
        /// Need to check for data entry in distance field.
        /// Need to check for data entry in at least one of bearing fields.
        /// Check format is correct - numerical format and in specified ranges for bearing data
        /// </summary>
        /// <returns><c>true</c>, if data input ok was ised, <c>false</c> otherwise.</returns>
        private bool IsDataInputOk()
        {
            INPUT_VALIDATION_FLAG errorTypeFlag = INPUT_VALIDATION_FLAG.INPUT_OK;
            bool dataOk = true;

            if (NoDataEntered(_distanceInput) && NoDataEnteredAngle(_degreesInput, _minuteInput, _secondInput))
            {
                // No Data entered in both distance and bearing fields
                errorTypeFlag = INPUT_VALIDATION_FLAG.NO_INPUT_ENTERED;
                dataOk        = false;
            }
            else if (NoDataEntered(_distanceInput))
            {
                // No Data entered in distance field
                errorTypeFlag = INPUT_VALIDATION_FLAG.NO_DISTANCE_INPUT_ENTERED;
                dataOk        = false;
            }
            else if (NonNumericalDoubleDataEntered(_distanceInput, ref _distanceDoubleInput))
            {
                // String Data/Non-Numerical data entered.
                // Distance input is tested here and _distanceDoubleInput is initialised if correct double input.
                errorTypeFlag = INPUT_VALIDATION_FLAG.NON_NUMERICAL_DATA_ENTERED;
                dataOk        = false;
            }
            else if (NoDataEnteredAngle(_degreesInput, _minuteInput, _secondInput))
            {
                // No Bearing Data entered
                errorTypeFlag = INPUT_VALIDATION_FLAG.NO_BEARING_DATA_ENTERED;
                dataOk        = false;
            }
            else
            {
                if (!NoDataEntered(_degreesInput))
                {
                    if (NonNumericalDataEntered(_degreesInput, ref _degreeIntInput))
                    {
                        // Incorrect data entered in Degrees field.
                        errorTypeFlag = INPUT_VALIDATION_FLAG.NON_NUMERICAL_DATA_ENTERED;
                        dataOk        = false;
                    }
                    else if (NumberOutOfRange(360, 0, _degreeIntInput))
                    {
                        // Degrees out of range error.
                        errorTypeFlag = INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_DEGREES;
                        dataOk        = false;
                    }
                }

                if (!NoDataEntered(_minuteInput))
                {
                    if (NonNumericalDataEntered(_minuteInput, ref _minuteIntInput))
                    {
                        // Incorrect data entered in Minutes field.
                        errorTypeFlag = INPUT_VALIDATION_FLAG.NON_NUMERICAL_DATA_ENTERED;
                        dataOk        = false;
                    }
                    else if (NumberOutOfRange(60, 0, _minuteIntInput))
                    {
                        // Degrees out of range error.
                        errorTypeFlag = INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_MINUTES;
                        dataOk        = false;
                    }
                }

                if (!NoDataEntered(_secondInput))
                {
                    if (NonNumericalDataEntered(_secondInput, ref _secondIntInput))
                    {
                        // Incorrect data entered in Secondss field.
                        errorTypeFlag = INPUT_VALIDATION_FLAG.NON_NUMERICAL_DATA_ENTERED;
                        dataOk        = false;
                    }
                    else if (NumberOutOfRange(60, 0, _secondIntInput))
                    {
                        // Degrees out of range error.
                        errorTypeFlag = INPUT_VALIDATION_FLAG.NUMBER_OUT_OF_RANGE_SECONDS;
                        dataOk        = false;
                    }
                }
            }

            // Display error message if data input error found
            if (!dataOk)
            {
                DisplayErrorMessage(errorTypeFlag);
            }

            return(dataOk);
        }