Ejemplo n.º 1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag(targetTag))
        {
            if (OnTriggerEnterEvent != null)
            {
                OnTriggerEnterEvent.Invoke();
            }

            EventScore score = GetComponent <EventScore>();
            if (score != null)
            {
                score.UpdateEventScore(true);
            }
        }
    }
        private void CreateScoreAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
        {
            EventScore       newScore         = new EventScore(((XPObjectSpace)ObjectSpace).Session);
            EnterEventScores enterEventScores = (EnterEventScores)e.PopupWindowViewCurrentObject;
            DecathalonEvent  selectedEvent    = enterEventScores.Event;

            string expression = selectedEvent.Definition.ScoringParameterGroups.Count > 1 ? "(" : "";

            // TODO: Get Parameter values
            if (selectedEvent.Definition.ScoringParameterGroups.Count == 1 && selectedEvent.Definition.ScoringParameterGroups[0].ScoringParameters.Count == 1)
            {
                // Only one parameter
                expression += enterEventScores.ScoreParameters[0].Value;
            }
            else if (selectedEvent.Definition.ScoringParameterGroups.Count > 0)
            {
                foreach (var paramGroup in selectedEvent.Definition.ScoringParameterGroups.OrderBy(p => p.SequenceNumber))
                {
                    expression += "(";
                    foreach (var param in paramGroup.ScoringParameters.OrderBy(p => p.SequenceNumber))
                    {
                        if (param.Value == 0)
                        {
                            double doubleValue = enterEventScores.ScoreParameters.Where(p => p.Sequence == param.SequenceNumber && p.Group == paramGroup.SequenceNumber).FirstOrDefault().Value;

                            if (param.SequenceNumber == 1)
                            {
                                if (param.OperatorString != "")
                                {
                                    expression += doubleValue + " " + param.OperatorString;
                                }
                                else
                                {
                                    expression += doubleValue;
                                }
                            }
                            else if (param.SequenceNumber == paramGroup.ScoringParameters.Count)
                            {
                                expression += " " + doubleValue;
                            }
                            else
                            {
                                expression += " " + doubleValue + " " + param.OperatorString;
                            }
                        }
                        else
                        {
                            if (param.SequenceNumber == 1)
                            {
                                if (param.OperatorString != "")
                                {
                                    expression += param.Value + " " + param.OperatorString;
                                }
                                else
                                {
                                    expression += param.Value;
                                }
                            }
                            else if (param.SequenceNumber == paramGroup.ScoringParameters.Count)
                            {
                                expression += " " + param.Value;
                            }
                            else
                            {
                                expression += " " + param.Value + " " + param.OperatorString;
                            }
                        }
                    }
                    expression += ") " + paramGroup.OperatorString;
                }
            }

            expression += selectedEvent.Definition.ScoringParameterGroups.Count > 1 ? ")" : "";

            // TODO: Set and show Points and save Score
            var    dt           = new DataTable();
            double points       = 0;
            string resultString = dt.Compute(expression, "").ToString();

            double.TryParse(resultString, out points);

            newScore.Competitor = ObjectSpace.GetObject(enterEventScores.Competitor);
            newScore.Event      = ObjectSpace.GetObject(selectedEvent);
            newScore.SetPoints(points);
            newScore.Notes += Environment.NewLine + "Calculated as: " + expression;

            ObjectSpace.CommitChanges();
        }
 public static EventScore CreateEventScore(int ID, int score, int rank, int eventScore_EventSlice, byte[] rowVersion)
 {
     EventScore eventScore = new EventScore();
     eventScore.Id = ID;
     eventScore.Score = score;
     eventScore.Rank = rank;
     eventScore.EventScore_EventSlice = eventScore_EventSlice;
     eventScore.RowVersion = rowVersion;
     return eventScore;
 }
 public void AddToEventScores(EventScore eventScore)
 {
     base.AddObject("EventScores", eventScore);
 }