public bool HasValue() { if (Value == null) { return(false); } return(Value.HasValue()); }
/// <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); } }
/// <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); }
protected override AResult addResult(int Rank, ACompetitor Competitor, ResultValue resultValue, string VestNumber = "") { AResult newResult; // Check that this competitor hasn't already got a result if (Competitor != null) { if (hasResultFor(Competitor)) { throw new ArgumentException("This competitor already has a result in this race!"); } } if (Rank == 0) { Rank = getNextResultRank(); } // removes any placeholder for this rank removePlaceholder(Rank); if (!isRankAvailable(Rank)) #if (ReorderResults) { makeSpaceForResult(Rank); } #else { throw new ArgumentException(string.Format("Rank {0} has already been used", Rank)); } #endif // No competitor or value if (Competitor == null && !resultValue.HasValue()) { //newResult = new Result(ResultTypeDescription.Placeholder) { Event = this, Rank = Rank }; newResult = new Result() { Event = this, Rank = Rank, VestNumber = DM.VestNumber.MakeFromString(VestNumber) }; AddResult(newResult); return(newResult); } // No competitor but does have a value if (Competitor == null && resultValue.HasValue()) { //newResult = new Result(ResultTypeDescription.ValuePlaceholder) { Event = this, Rank = Rank, Value = resultValue }; newResult = new Result() { Event = this, Rank = Rank, Value = resultValue, VestNumber = DM.VestNumber.MakeFromString(VestNumber) }; AddResult(newResult); return(newResult); } // Competitor but no result value if (Competitor != null && !resultValue.HasValue()) { //newResult = new Result(ResultTypeDescription.Competative) { Event = this, Rank = Rank, Competitor = Competitor }; newResult = new Result() { Event = this, Rank = Rank, Competitor = Competitor }; AddResult(newResult); return(newResult); } // Competitor and result value if (Competitor != null && resultValue.HasValue()) { //newResult = new Result(ResultTypeDescription.CompetativeWithValue) { Event = this, Competitor = Competitor, Rank = Rank, Value = resultValue }; newResult = new Result() { Event = this, Competitor = Competitor, Rank = Rank, Value = resultValue }; AddResult(newResult); return(newResult); } throw new ArgumentException("Unknown exception when adding a result"); }