Esempio n. 1
0
        public void CreateBasicCompetition()
        {
            var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 6);

            Assert.AreEqual("Örebro Mästerskapen", competitionObject.Name);
            Assert.AreEqual("20160217", competitionObject.Date);
            Assert.AreEqual(6, competitionObject.Rounds);
        }
Esempio n. 2
0
        public void AddDiverToCompetition()
        {
            var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 6);
            var diver = new Diver(4, "Klas", "Uganda", 59, "Man", 3);

            competitionObject.AddDiver(diver);
            Assert.AreEqual(1, competitionObject.ListDiver.Count);

            competitionObject.AddDiver(diver);
            Assert.AreEqual(1, competitionObject.ListDiver.Count);

            var diver2 = new Diver(7, "Stefan", "Uganda", 14, "Man", 6);

            competitionObject.AddDiver(diver2);
            Assert.AreEqual(2, competitionObject.ListDiver.Count);

            var diver3 = new Diver();

            competitionObject.AddDiver(diver3);
            Assert.AreEqual(2, competitionObject.ListDiver.Count);
        }
Esempio n. 3
0
        public void TestFullCompetition()
        {
            var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 3);

            var diver = new Diver(4, "Klas", "Uganda", 59, "Man", 3);
            var diver2 = new Diver(5, "Susanna", "Sweden", 27, "Kvinna", 12);
            var diver3 = new Diver(2, "Klas-Göran", "Sweden", 22, "Man", 321);
            competitionObject.AddDiver(diver);
            competitionObject.AddDiver(diver2);
            competitionObject.AddDiver(diver3);

            Assert.AreEqual(3, competitionObject.ListDiver.Count);

            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(2, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(3, 1.2f, 0, 3, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);

            var dive4 = new Dive(4, 2.6f, 0, 1, diver2.DiverId);
            var dive5 = new Dive(5, 3.7f, 0, 2, diver2.DiverId);
            var dive6 = new Dive(6, 9.2f, 0, 3, diver2.DiverId);
            diver2.AddDive(dive4);
            diver2.AddDive(dive5);
            diver2.AddDive(dive6);

            var dive7 = new Dive(7, 4.9f, 0, 1, diver3.DiverId);
            var dive8 = new Dive(8, 6.2f, 0, 2, diver3.DiverId);
            var dive9 = new Dive(9, 1.2f, 0, 3, diver3.DiverId);
            diver3.AddDive(dive7);
            diver3.AddDive(dive8);
            diver3.AddDive(dive9);

            if (competitionObject.CheckIfSameAmountOfDives())
            {
                var allRefScores = new List<Score>();
                var score1 = new Score(5.5f);
                var score2 = new Score(2.5f);
                var score3 = new Score(8.0f);
                var score4 = new Score(5.0f);
                var score5 = new Score(2.5f);
                allRefScores.Add(score1);
                allRefScores.Add(score2);
                allRefScores.Add(score3);
                allRefScores.Add(score4);
                allRefScores.Add(score5);
                for (var i = 0; i < competitionObject.Rounds; i++)
                {
                    foreach (var contestant in competitionObject.ListDiver)
                    {
                        contestant.ListDive[i].TotalPoints.CalculateCompleteScore(allRefScores, contestant.ListDive[i].Type.Difficulty);
                    }
                }
                foreach (var contestant in competitionObject.ListDiver)
                {
                    contestant.SummarizeDivePoints();
                }
                Assert.AreEqual("Susanna", competitionObject.GetWinner());
            }
        }
Esempio n. 4
0
 public static void CreateCompetition()
 {
     Clear();
     GlobalDiveOrder = 1;
     WriteLine("Enter competition details:");
     var newCompetition = new Competition();
     Write("Name: ");
     newCompetition.Name = ReadLine();
     Write("Date: ");
     newCompetition.Date = ReadLine();
     Write("Location: ");
     newCompetition.Location = ReadLine();
     Write("Type: ");
     newCompetition.Type = ReadLine();
     Write("Rounds: ");
     newCompetition.Rounds = Convert.ToInt32(ReadLine());
     TempCompetition = newCompetition;
     WriteLine("\n");
 }
Esempio n. 5
0
        public static void InsertAssignment(Competition competition, Referee referee)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "INSERT INTO Assignment (Competition, Referee) " +
                               "VALUES (@competitionId, @refereeId)";

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

                    sqlQuery.Parameters.AddWithValue("@competitionId", competition.Id);
                    sqlQuery.Parameters.AddWithValue("@refereeId", referee.Id);
                    var result = sqlQuery.ExecuteNonQuery();
                    Logger.Info("{0} rows affected", result);
                }
            }
            Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
        }
Esempio n. 6
0
        public static void InsertCompetition(Competition competition)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "INSERT INTO competition (Name, Date, Location, Type, Rounds) " +
                               "VALUES (@Name, @Date, @Location, @Type, @Rounds)";

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

                    sqlQuery.Parameters.AddWithValue("@Name", competition.Name);
                    sqlQuery.Parameters.AddWithValue("@Date", competition.Date);
                    sqlQuery.Parameters.AddWithValue("@Location", competition.Location);
                    sqlQuery.Parameters.AddWithValue("@Type", competition.Type);
                    sqlQuery.Parameters.AddWithValue("@Rounds", competition.Rounds);

                    var result = sqlQuery.ExecuteNonQuery();
                    Logger.Info("{0} rows affected", result);
                }
                competition.Id = GetCompetitionId();
                InsertAllAssignment(competition);
                InsertAllDives(competition);
            }
            Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
        }
Esempio n. 7
0
 public static void InsertAllAssignment(Competition competition)
 {
     foreach (var referee in competition.ListReferee)
     {
         InsertAssignment(competition, referee);
     }
 }
Esempio n. 8
0
        public static void InsertAllDives(Competition competition)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "INSERT INTO dive (TotalPoints, diveOrder, Diver, Competition, Divetype) " +
                               "VALUES (@TotalPoints, @diveOrder, @Diver, @Competition, @DiveType)";

            using (var sqlConnection = ConnectToDatabase())
            {
                var result = 0;
                foreach (var diver in competition.ListDiver)
                {
                    foreach (var dive in diver.ListDive)
                    {
                        using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                        {
                            Logger.Info("Running Query: \"{0}\"", sql);

                            sqlQuery.Parameters.AddWithValue("@DiveType", GetDiveType(dive.Type.Code).Id);
                            sqlQuery.Parameters.AddWithValue("@TotalPoints", dive.TotalPoints.Value);
                            sqlQuery.Parameters.AddWithValue("@diveOrder", dive.Order);
                            sqlQuery.Parameters.AddWithValue("@Diver", diver.Id);
                            sqlQuery.Parameters.AddWithValue("@Competition", competition.Id);

                            result += sqlQuery.ExecuteNonQuery();
                        }
                    }
                }
                Logger.Info("{0} rows affected", result);
            }
            Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
        }
Esempio n. 9
0
 public void AddCompetition(Competition competition)
 {
     SendToServer(competition);
 }
Esempio n. 10
0
        public static Competition GetCompetition(int id)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            var sql = $"SELECT * FROM competition WHERE id = {id}";

            using (var sqlConnection = ConnectToDatabase())
            {
                var competition = new Competition();

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

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        competition = new Competition(
                            tableReader.GetInt32("ID"),
                            tableReader.GetString("Name"),
                            tableReader.GetString("Date"),
                            tableReader.GetString("Location"),
                            tableReader.GetString("Type"),
                            tableReader.GetInt32("Rounds"));
                    }
                }
                // Hämtar divers och deras dives
                var dives = GetAllDiveByCompetitionId(competition.Id);
                var divers = GetDivers();
                foreach (var diver in divers)
                {
                    foreach (var dive in dives)
                    {
                        if (dive.DiverId == diver.Id && dive.CompetitionId == competition.Id)
                        {
                            diver.ListDive.Add(dive);
                        }
                    }
                    if (diver.ListDive.Count > 0)
                    {
                        competition.ListDiver.Add(diver);
                    }
                }
                // Hämtar judges
                competition.ListReferee = GetAssignedRefereesByCompetition(competition.Id);

                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return competition;
            }
        }
Esempio n. 11
0
 public static void SetCompetition(Competition competition)
 {
     ActiveCompetition = competition;
 }
Esempio n. 12
0
        /// <summary>
        ///     Hanterar operationskoder. Skickar tillbaka ett objekt beroende på kod.
        /// </summary>
        /// <param name="obj">Operationskod</param>
        /// <param name="stream">
        /// </param>
        private static MyMessage OperationCodeHandler(string obj)
        {
            var messageOut = new MyMessage();
            try
            {
                Logger.Info($"Executing operationcode: {obj}");
                object tempObject;
                switch (obj)
                {
                    case "GetDivers": // Hämtar diver-lista
                        tempObject = DbHandler.GetDivers();
                        messageOut = Serializer.Serialize(tempObject);
                        break;

                    case "GetLeaderList":
                        messageOut = Serializer.Serialize(CompetitionHandler.ActiveCompetition.ListDiver);
                        break;

                    case "GetDiveTypes":
                        tempObject = DbHandler.GetDiveTypes();
                        messageOut = Serializer.Serialize(tempObject);
                        break;

                    case "GetReferees": // Hämta referee-lista
                        tempObject = DbHandler.GetReferees();
                        messageOut = Serializer.Serialize(tempObject);
                        break;

                    case "GetCompetitions": // Hämtar competition-lista
                        tempObject = DbHandler.GetAvailableCompetitions();
                        messageOut = Serializer.Serialize(tempObject);
                        break;

                    case "IsCurrentDiveDone":   // Hämtar och uppdaterar admins lokala CurrentDive
                        tempObject = CompetitionHandler.CurrentDiveComplete();
                        if ((bool)tempObject)
                        {
                            CompetitionHandler.CurrentDive.CalculateTotalPoints();
                            CompetitionHandler.SendCurrentDiveToDatabaseAndUpdateActiveCompetition();
                        }
                        messageOut = Serializer.Serialize(CompetitionHandler.CurrentDive);
                        break;

                    case "CompetitionComplete":
                        CompetitionHandler.ActiveCompetition = null;
                        messageOut = Serializer.Serialize("Competition Complete");
                        break;

                    default:
                        if (obj[0] == 'G' && obj[1] == 'C' && obj[2] == 'D') // Hämtar CurrentDive
                        {
                            Dive currentDive = null;
                            var userId = int.Parse(obj.Remove(0, 4));

                            if (CompetitionHandler.ActiveCompetition != null)
                            {
                                foreach (var referee in CompetitionHandler.ActiveCompetition.ListReferee)
                                {
                                    if (referee.Id == userId)
                                    {
                                        currentDive = CompetitionHandler.CurrentDive;
                                        Logger.Info("Returning the current dive to referee with id: " + referee.Id);
                                        break;
                                    }
                                }
                            }
                            messageOut = Serializer.Serialize(currentDive);
                        }
                        else if (obj[0] == 'S' && obj[1] == 'C') // Startar competition
                        {
                            var id = int.Parse(obj.Remove(0, 3));
                            CompetitionHandler.SetCompetition(DbHandler.StartCompetition(id));
                            var activeDivesList = CompetitionHandler.GetAllDives();
                            messageOut = Serializer.Serialize(activeDivesList);
                        }
                        else if (obj[0] == 'G' && obj[1] == 'C' && obj[2] == 'C') // Hämtar pågående tävling
                        {
                            var id = int.Parse(obj.Remove(0, 4));
                            var competition = new Competition();
                            if (CompetitionHandler.ActiveCompetition != null)
                            {
                                foreach (var referee in CompetitionHandler.ActiveCompetition.ListReferee)
                                {
                                    if (referee.Id == id)
                                    {
                                        competition = CompetitionHandler.ActiveCompetition;
                                        Logger.Info("Returning the active competition to referee with id: " + referee.Id);
                                        break;
                                    }
                                }
                            }
                            messageOut = Serializer.Serialize(competition);
                        }
                        break;
                }
            }
            catch (ArgumentNullException nullException)
            {
                var str = nullException.Message;
                Logger.Error("ArgumentNullException: " + str);
                messageOut = Serializer.Serialize(str);
            }
            catch (NullReferenceException nullReferenceException)
            {
                var str = nullReferenceException.Message;
                Logger.Error("NullReferenceException: " + str);
                messageOut = Serializer.Serialize(str);
            }
            return messageOut;
        }
Esempio n. 13
0
        public void OnNextStepInCreating(object source, EventArgs args)
        {
            if (IsNullOrEmpty(CompetitionFormInfo.nameBox.Text) ||
                IsNullOrEmpty(CompetitionFormInfo.dateBox.Text) ||
                IsNullOrEmpty(CompetitionFormInfo.locationBox.Text) ||
                IsNullOrEmpty(CompetitionFormInfo.typeBox.Text))
            {
                ErrorMessageBox("Ej komplett information", "Vänligen fyll i samtliga fält");
                return;
            }
            var rounds = 0;
            if (CompetitionFormInfo.radio5Button.Checked)
                rounds = 5;
            else if (CompetitionFormInfo.radio6Button.Checked)
                rounds = 6;

            NewCompetition = new Competition(CompetitionFormInfo.nameBox.Text, CompetitionFormInfo.dateBox.Text, CompetitionFormInfo.locationBox.Text, CompetitionFormInfo.typeBox.Text, rounds);
            InitializeCompForm();
            InitializeRefereeForm();
            //var nextThread = new Thread(CompetitionForm.LoadForm);
            //nextThread.Start();
            CompetitionFormInfo.Close();
            CompetitionForm.LoadForm();
        }
Esempio n. 14
0
 private void OnRefereeClientUpdate(object sender, EventArgs e)
 {
     var activeCompetition =
         (Competition)ClientNetworkHandler.SendAndReceive($"GCC;{LoggedInUser.Id}");
     NewCompetition = activeCompetition;
     RefereeMenu.ActiveCompetitionInfo.Text = activeCompetition.ToString();
     RefereeMenu.ActiveCompetitionDivers.DataSource = activeCompetition.ListDiver;
 }
Esempio n. 15
0
        public void InitializeRunCompetitionForm()
        {
            var tempCompetition = ActivateCompetition.listBox1.SelectedItem;
            NewCompetition = (Competition)tempCompetition;
            ActiveCompetitionDiveIndex = 0;

            RunCompetition.waitForAssessmentsProgressBar.MarqueeAnimationSpeed = 0;
            var tDives = ClientNetworkHandler.SendAndReceive($"SC;{NewCompetition.Id}");

            var diveList = tDives as List<Dive>;
            diveList?.Sort((x, y) => x.Order.CompareTo(y.Order));
            CompetitionDiveList = diveList;
            if (CompetitionDiveList != null)
                foreach (var dive in CompetitionDiveList)
                {
                    if (dive.TotalPoints.Value != -1)
                        ActiveCompetitionDiveIndex++;
                }

            RunCompetition.scoreBoardListBox.DataSource = Admin.GetActiveCompetitionDivers();
            RunCompetition.divesListBox.DataSource = diveList;
            //RunCompetition.listBox1.DisplayMember = "Order";
            if (NewCompetition.ListReferee.Count > 3)
            {
                RunCompetition.Judge4.Text = NewCompetition.ListReferee[3].Name;
                RunCompetition.Judge4.Show();
                RunCompetition.label9.Show();
            }
            if (NewCompetition.ListReferee.Count > 4)
            {
                RunCompetition.Judge5.Text = NewCompetition.ListReferee[4].Name;
                RunCompetition.Judge5.Show();
                RunCompetition.label10.Show();
            }
            RunCompetition.Judge1.Text = NewCompetition.ListReferee[0].Name;
            RunCompetition.Judge2.Text = NewCompetition.ListReferee[1].Name;
            RunCompetition.Judge3.Text = NewCompetition.ListReferee[2].Name;
            RunCompetition.NextAssignmentButton.Enabled = true;
            RunCompetition.LoadForm();
        }