Пример #1
0
 public void AssessDive(Score score, Dive dive)
 {
     //Console.WriteLine($"Give points to dive {dive.DiveCode} by {dive.DiverId}");
     //var score = AddRefereeScore();
     var assessment = new Assessment(score, dive, this);
     var str = ClientNetworkHandler.SendAndReceive(assessment);
     //Console.WriteLine(str);
 }
Пример #2
0
        public void TestCalculateTotalPoints()
        {
            var dive = new Dive(1, new DiveType(1, "100a", 1.5f), -1, 4, 3);
            Assert.AreEqual(dive.TotalPoints.Value, -1.0f);

            for (var i = 0; i < 5; i++)
            {
                var assessment = new Assessment(i, new Score(5.0f + i), dive, new Referee());
                dive.Assessments.Add(assessment);
            }

            Assert.IsNotEmpty(dive.Assessments);
            Assert.AreEqual(dive.Assessments.Count, 5);

            var scores = dive.Assessments.Select(assessment => assessment.Point).ToList();

            dive.TotalPoints.CalculateCompleteScore(scores, dive.Type.Difficulty);

            /* Points in assessment-list
             5, 6, 7, 8, 9 -> lowest(5) and highest(9) gets removed. Left: 6, 7, 8.
             Totalpoints = 6 + 7 + 8 * 1.5f = 31.5 points
             */
            Assert.AreEqual(dive.TotalPoints.Value, 31.5f);
        }
Пример #3
0
        public static List<Assessment> GetAssessments(int diveId)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            var sql = $"SELECT * FROM assessment WHERE DIVE = {diveId}";

            using (var sqlConnection = ConnectToDatabase())
            {
                var assessments = new List<Assessment>();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var tempAssessment = new Assessment(
                            tableReader.GetInt32("Id"),
                            tableReader.GetFloat("Points"),
                            tableReader.GetInt32("Dive"),
                            tableReader.GetInt32("Referee"),
                            tableReader.GetInt32("Competition")
                            );
                        assessments.Add(tempAssessment);
                    }
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return assessments;
            }
        }
Пример #4
0
        public static void InsertAssessment(Assessment assessment)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "INSERT INTO assessment(Points, Dive, Referee, Competition) " +
                               "VALUES (@Points, @Dive, @Referee, @Competition)";

            using (var sqlConnection = ConnectToDatabase())
            {
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    sqlQuery.Parameters.AddWithValue("@Points", assessment.Point.Value);
                    sqlQuery.Parameters.AddWithValue("@Dive", assessment.DiveId);
                    sqlQuery.Parameters.AddWithValue("@Referee", assessment.RefereeId);
                    sqlQuery.Parameters.AddWithValue("@Competition", assessment.CompetitionId);

                    var result = sqlQuery.ExecuteNonQuery();
                    Logger.Info("{0} rows affected", result);
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
            }
        }
Пример #5
0
        public static Dive CurrentDive = new Dive(); // Överför färdigbedömt hopp till databasen

        #endregion Fields

        #region Methods

        public static void AddAssessment(Assessment assessment)
        {
            assessment.CompetitionId = ActiveCompetition.Id;
            assessment.DiveId = CurrentDive.Id;
            CurrentDive.Assessments.Add(assessment);
        }
Пример #6
0
 private void OnEventClickSendButton(object sender, EventArgs e)
 {
     try
     {
         if (RefereeAssessment.refScoreTextBox.Text.Length == 0)
             throw new FormatException();
         var dialogResult = MessageBox.Show(
             $"Skicka {RefereeAssessment.refScoreTextBox.Text} poäng?",
                 "Skicka poäng", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             var refScore = RefereeAssessment.refScoreTextBox.Text;
             var judgeScore = float.Parse(refScore, CultureInfo.InvariantCulture.NumberFormat);
             var score = new Score(judgeScore);
             var dive = new Dive();
             var assessment = new Assessment(score, dive, LoggedInUser);
             var str = ClientNetworkHandler.SendAndReceive(assessment);
             MessageBox.Show($"{judgeScore} poäng skickad", "Meddelande");
         }
     }
     catch (FormatException)
     {
         ErrorMessageBox("Ogiltig inmatning", "Ange poäng!");
     }
     RefereeAssessment.RefSendScoreButton.Enabled = false;
     var tDive = WaitForDiveToJudge();
     RefereeAssessment.RefereeCurrentDiveInfoLabel.Text = tDive.ToString();
     SystemSounds.Beep.Play();
     RefereeAssessment.RefSendScoreButton.Enabled = true;
 }