コード例 #1
0
        /// <summary>
        /// Compares a set of standards against a result and produces a string of the achieved standards
        /// </summary>
        /// <param name="standard">Standard to be compared against, can be null.</param>
        /// <param name="result">Result to be compared, can be null</param>
        /// <returns>Will always return false if standard is null</returns>
        public static string getStandardShortString(AEvent Event, ResultValue result)
        {
            if (result == null)
            {
                return(string.Empty);
            }

            if (Event == null)
            {
                return(string.Empty);
            }

            // will always return false if there is no result to compare against
            if (result.HasValue( ) == false)
            {
                return(string.Empty);
            }

            string temp = string.Empty;

            if (Event.CountyBestPerformance.HasValue( ))
            {
                if (result.isTime( ))
                {
                    if (Event.CountyBestPerformance.RawValue >= result.RawValue)
                    {
                        temp += "CBP" + " / ";
                    }
                }
                else if (result.isDistance( ))
                {
                    if (Event.CountyBestPerformance.RawValue <= result.RawValue)
                    {
                        temp += "CBP" + " / ";
                    }
                }
                else
                {
                    throw new ArgumentException("Result must have a declared ValueType", "result");
                }
            }


            IEnumerable <Standard> standards = Event.Standards;

            if (result.isTime( ))
            {
                standards = standards.OrderBy(s => s.StandardValue.RawValue);
            }
            else if (result.isDistance( ))
            {
                standards = standards.OrderByDescending(s => s.StandardValue.RawValue);
            }
            else
            {
                throw new ArgumentException("Result must have a declared ValueType", "result");
            }

            foreach (Standard standard in standards)
            {
                if (standard == null)
                {
                    continue;
                }

                // will always be false if there are no standards
                if (!hasStandards(standard))
                {
                    continue;
                }

                // TODO add a check for standards values to have a defined ValueType

                if (result.isTime( ))
                {
                    // check for standard
                    if (standard.StandardValue.HasValue( ))
                    {
                        if (standard.StandardValue.RawValue >= result.RawValue)
                        {
                            temp += standard.ShortName + " / ";
                            break;
                        }
                    }
                }
                else if (result.isDistance( ))
                {
                    // check for standard
                    if (standard.StandardValue.HasValue( ))
                    {
                        if (standard.StandardValue.RawValue <= result.RawValue)
                        {
                            temp += standard.ShortName + " / ";
                            break;
                        }
                    }
                }
            }

            if (temp.EndsWith(" / "))
            {
                return(temp.Remove(temp.Length - 3, 3));
            }
            else
            {
                return(temp);
            }
        }
コード例 #2
0
        /// <summary>
        /// Compares a set of standards against a result
        /// </summary>
        /// <param name="standard">Standard to be compared against, can be null.</param>
        /// <param name="result">Result to be compared, can be null</param>
        /// <returns>Will always return false if standard is null</returns>
        public static bool achievedStandard(AEvent Event, ResultValue result)
        {
            if (result == null)
            {
                return(false);
            }

            if (Event == null)
            {
                return(false);
            }

            if (Event.CountyBestPerformance.HasValue( ))
            {
                if (result.isTime( ))
                {
                    if (Event.CountyBestPerformance.RawValue >= result.RawValue)
                    {
                        return(true);
                    }
                }
                else if (result.isDistance( ))
                {
                    if (Event.CountyBestPerformance.RawValue <= result.RawValue)
                    {
                        return(true);
                    }
                }
                else
                {
                    throw new ArgumentException("Result must have a declared ValueType", "result");
                }
            }

            foreach (Standard standard in Event.Standards)
            {
                if (standard == null)
                {
                    return(false);
                }

                // will always be false if there are no standards
                if (!hasStandards(standard))
                {
                    return(false);
                }

                // will always return false if there is no result to compare against
                if (!result.HasValue( ))
                {
                    return(false);
                }

                // TODO add a check for standards values to have a defined ValueType

                if (result.isTime( ))
                {
                    if (standard.StandardValue.HasValue( ))
                    {
                        if (standard.StandardValue.RawValue >= result.RawValue)
                        {
                            return(true);
                        }
                    }
                }
                else if (result.isDistance( ))
                {
                    if (standard.StandardValue.HasValue( ))
                    {
                        if (standard.StandardValue.RawValue <= result.RawValue)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    throw new ArgumentException("Result must have a declared ValueType", "result");
                }
            }

            // did not achieve any standards
            return(false);
        }