Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="info">Object containing info about contest</param>
 /// <param name="judges">List of judges</param>
 /// <param name="contestants">list of contestants</param>
 public Contest(ContestInfo info, JudgeList judges, ContestantList contestants, SubContestBranchList subContestBranches)
 {
     this.Info               = info;
     this.Judges             = judges;
     this.Contestants        = contestants;
     this.SubContestBranches = subContestBranches;
 }
Exemplo n.º 2
0
 public Contest(ContestInfo info, JudgeList judges, ContestantList contestants)
 {
     this.Info          = info;
     this.Judges        = judges;
     this.Contestants   = contestants;
     SubContestBranches = new SubContestBranchList();
 }
Exemplo n.º 3
0
 //
 // Default constructor
 //
 public Contest()
 {
     Info               = new ContestInfo();
     Judges             = new JudgeList();
     Contestants        = new ContestantList();
     SubContestBranches = new SubContestBranchList();
 }
Exemplo n.º 4
0
        public long PushContestInfo(ContestInfo contestInfo)
        {
            string table = "contest";

            var name      = contestInfo.Name;
            var city      = contestInfo.City;
            var arena     = contestInfo.Arena;
            var startDate = contestInfo.StartDate;
            var endDate   = contestInfo.EndDate;

            string query = $"INSERT INTO {table} ";

            query += $"(name, city, arena, startDate, endDate) ";
            query += $"VALUES(";
            query += $"'{name}','{city}','{arena}','{Helpers.SQLDateFormat(startDate)}','{Helpers.SQLDateFormat(endDate)}'";
            query += $")";

            long lastInsertedId = ExecuteQuery(query);

            return(lastInsertedId);
        }
Exemplo n.º 5
0
        public void GoToCreateSubContest()
        {
            // Kolla så att data är korrekt formatterat
            bool stringAreValid = false;

            if (CheckDataInput.StringCheckFormat(View.TextBoxName.Text))
            {
                if (CheckDataInput.StringCheckFormat(View.TextBoxCity.Text))
                {
                    if (CheckDataInput.StringCheckFormat(View.TextBoxArena.Text))
                    {
                        stringAreValid = true;
                    }
                    else
                    {
                        MessageBox.Show("Simhallsnamn är ej giltigt.");
                    }
                }
                else
                {
                    MessageBox.Show("Stadsnamn är ej giltigt.");
                }
            }
            else
            {
                MessageBox.Show("Tävlingsnamn är ej giltigt.");
            }

            bool areDatesSet = false;

            // The dates have DateTime.MinValue if they have not been set manually
            if (StartDate != DateTime.MinValue)
            {
                if (EndDate != DateTime.MinValue)
                {
                    areDatesSet = true;
                }
                else
                {
                    MessageBox.Show("Välj slutdatum.");
                }
            }
            else
            {
                MessageBox.Show("Välj startdatum.");
            }


            // check if any judges or contestans have been added to the contest
            bool areListsFilled = false;

            if (ContestJudgeList.Count > 2)
            {
                if (ContestContestantList.Count > 1)
                {
                    areListsFilled = true;
                }
                else
                {
                    MessageBox.Show("Måste minst vara 2 deltagare på en tävling.");
                }
            }
            else
            {
                MessageBox.Show("Måste minst vara 3 domare på en tävling.");
            }


            // if everything is okay, create the contest and move to subcontestview
            if (stringAreValid && areDatesSet && areListsFilled)
            {
                ContestInfo contestInfo = new ContestInfo(View.TextBoxName.Text, View.TextBoxCity.Text, StartDate, EndDate, View.TextBoxArena.Text);

                // Listorna byggs upp med hjälp av listboxarna.

                Contest contest = new Contest(contestInfo, ContestJudgeList, ContestContestantList);

                CreateSubContestView createSubContestView = new CreateSubContestView();

                CreateSubContestPresenter createSubContestPresenter = new CreateSubContestPresenter(createSubContestView, window, contest);

                window.ChangePanel(createSubContestView, View);
            }
        }
        /// <summary>
        /// Listens for messages from a client
        /// </summary>
        public void ClientThread()
        {
            string msg = "";

            try
            {
                NetworkStream = Client.GetStream();
                StreamReader  = new StreamReader(NetworkStream);
                StreamWriter  = new StreamWriter(NetworkStream);

                ContestInfo info = contestPresenter.CurrentContest.Info;
                msg = "contest:" + info.Name + "|" + info.City + "|" + info.Arena;
                // contest: Example Event|Lyon|Arena

                StreamWriter.WriteLine(msg);
                StreamWriter.Flush();

                while (true)
                {
                    // read what the client has to say
                    msg = StreamReader.ReadLine();

                    if (msg == null || msg.StartsWith("quit"))
                    {
                        break;
                    }
                    else if (msg.StartsWith("Login:"******"denied");
                            StreamWriter.Flush();
                        }
                    }
                    else if (msg.StartsWith("Points:"))
                    {
                        Points = msg.Substring(7);
                        AddPointToList(Points.ToString());
                    }
                }
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
            }
            finally
            {
                if (!IsHost)
                {
                    Client.Close();

                    foreach (var client in Server.ClientList)
                    {
                        if (this == client)
                        {
                            Server.ClientList.Remove(client);
                            break;
                        }
                    }
                    Server.UpdateJudgeListView();
                    ThreadClient.Abort();
                }
            }
        }