示例#1
0
        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");
        }