Exemple #1
0
        public bool CreatePerson()
        {
            if (CheckDataInput() == true)
            {
                int    ID = 1;
                Person p  = null;

                if (Role == "judge")
                {
                    p = new Judge(ID, TextBoxFirstName.Text, TextBoxLastName.Text, int.Parse(TextBoxAge.Text), TextBoxEmail.Text, ComboBoxGender.SelectedItem.ToString(), TextBoxSSN.Text, TextBoxAddress.Text);
                }
                else
                {
                    p = new Contestant(ID, TextBoxFirstName.Text, TextBoxLastName.Text, int.Parse(TextBoxAge.Text), TextBoxEmail.Text, ComboBoxGender.SelectedItem.ToString(), TextBoxSSN.Text, TextBoxAddress.Text);
                }

                PersonList.Add(p);

                ClearInputs();

                MessageBox.Show("En ny person har skapats!");
                return(true);
            }

            return(false);
        }
Exemple #2
0
        public static List <Judge> GetJudges()
        {
            var judgeList = new List <Judge>();

            var conn = ConnectToDatabase();

            if (conn != null)
            {
                var cmd = new MySqlCommand("SELECT * FROM judge ORDER BY id", conn);
                var dr  = cmd.ExecuteReader();
                var dt  = new DataTable();
                dt.Load(dr);

                foreach (DataRow row in dt.Rows)
                {
                    var tmp = new Judge(Int32.Parse(row["id"].ToString()), row["name"].ToString());
                    judgeList.Add(tmp);
                }
                return(judgeList);
            }

            else
            {
                MessageBox.Show("Anslutningen till databasen misslyckades", "Fel", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(judgeList);
        }
Exemple #3
0
        /// <summary>
        /// lägger till domare i databasen
        /// </summary>
        /// <returns>returnerar TRUE om det lyckas annars FALSE</returns>
        public static int AddJudgeToDatabase(Judge j1)
        {
            //ansluter till databasen
            MySqlConnection conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                string id = "";
                //lägger till domaren i databasen
                MySqlCommand comm = conn.CreateCommand();
                comm.CommandText = "INSERT INTO judge(name) VALUES(@name)";
                comm.Parameters.AddWithValue("@name", j1.GetJudgeName());
                comm.ExecuteNonQuery();
                comm.CommandText = "SELECT LAST_INSERT_ID() AS id";
                var dr = comm.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);
                DataRow row = dt.Rows[0];
                id = row["id"].ToString();

                conn.Close();
                return(Int32.Parse(id));
            }
            else
            {
                MessageBox.Show("Anslutningen till databasen misslyckades", "Fel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }
        }
        /// <summary>
        /// Skapa ett poäng för CurrentDive och lägg till det i Dive
        /// Skicka poängen till domarklienterna om server
        /// Skicka poängen till server om client
        /// </summary>
        /// <param name="points"></param>
        /// <param name="judgeIndex"></param>
        /// <param name="broadcastScore"></param>
        /// <returns></returns>
        private Score CreateScoreForDive(double points, int judgeIndex, bool broadcastScore = true, int roundIndex = -1, int diverIndex = -1)
        {
            if (roundIndex == -1)
            {
                roundIndex = CurrentRoundIndex;
            }

            if (diverIndex == -1)
            {
                diverIndex = CurrentDiverIndex;
            }

            Console.WriteLine(Mode.ToString() + " Scoring: " + points + " for index: " + judgeIndex + " with broadcast:" + broadcastScore.ToString());
            Console.WriteLine(Mode.ToString() + " judgeIndex: " + _currentJudgeIndex + ", roundIndex: " + roundIndex + ", diverIndex: " + diverIndex);

            Judge scoringJudge = Judges[judgeIndex];

            Score score = new Score(Divers[diverIndex].Dives[roundIndex], scoringJudge, points);

            Divers[diverIndex].Dives[roundIndex].AddScore(score); //Add score to current dive

            _view.PopulateScoreInput(score, judgeIndex, diverIndex, roundIndex);

            SkipToNonClientJudges(broadcastScore);

            if (Mode == ViewMode.Client && broadcastScore)
            {
                Console.WriteLine(Mode.ToString() + " Commiting score to client (is client)");
                _judgeClient.CommitScore(_clientJudgeIndex, score);
                _view.ToggleControls(false);
            }
            else if (Mode == ViewMode.Standalone)
            {
                Console.WriteLine(Mode.ToString() + " Broadcasting score (is server)");
                JudgeServer.BroadcastScore(score, roundIndex, diverIndex);
            }

            if (CurrentDive.Scores.Count == CurrentEvent.Judges.Count && Mode == ViewMode.Standalone)
            {
                _view.CurrentDiveScore = CurrentDive.Score;

                Database.AddScoreToDive(CurrentDive.Scores, CurrentDive);

                CurrentJudgeIndex = 0;
                CurrentDiverIndex++;

                SendStatusToClient();
                if (CurrentDiverIndex >= Divers.Count)
                {
                    CurrentDiverIndex = 0;
                    CurrentRoundIndex++;
                }
                _view.CompleteDive();
            }
            return(score);
        }
Exemple #5
0
        /// <summary>
        /// Add a judge from the DB to the contest
        /// </summary>
        public void AddJudgeToContest()
        {
            try
            {
                // Collect the chosen judge
                var judgeFirstName = View.ListViewGlobalJudges.SelectedItems[0].SubItems[0].Text;

                var  judgeLastName = View.ListViewGlobalJudges.SelectedItems[0].SubItems[1].Text;
                bool isAdded       = false;

                // Check if judge is already added to the contest
                foreach (var j in ContestJudgeList)
                {
                    if (String.Equals(j.FirstName, judgeFirstName) && String.Equals(j.LastName, judgeLastName))
                    {
                        isAdded = true;
                        MessageBox.Show("Domare är redan tillagd!");
                        break;
                    }
                }

                // Collect the correct Judge object
                Judge judgeToBeAdded = null;

                if (!isAdded)
                {
                    foreach (var j in GlobalJudgeList)
                    {
                        if (String.Equals(j.FirstName, judgeFirstName) && String.Equals(j.LastName, judgeLastName))
                        {
                            judgeToBeAdded = j;
                        }
                    }

                    if (judgeToBeAdded != null)
                    {
                        ContestJudgeList.Add(judgeToBeAdded);
                    }
                }

                UpdateListViews();
            }

            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Välj en domare!");
            }
        }
Exemple #6
0
        /// <summary>
        /// Lägger till en domare i databasen och i listViewJudge
        /// </summary>
        /// <param name="newJudgeName"></param>
        /// <param name="listViewJudge"></param>
        public static void AddNewJudge(TextBox newJudgeName, ListView listViewJudge)
        {
            //lägger till den nya domaren i databasen
            Judge judge = new Judge(newJudgeName.Text);
            int   ID    = Database.AddJudgeToDatabase(judge);

            ListViewItem item1 = new ListViewItem();

            item1.Text = ID.ToString();
            listViewJudge.Items.Add(item1);

            item1.SubItems.Add(judge.Name);

            //restore textbox
            newJudgeName.Text = "Namn";
        }
        /// <summary>
        /// Checks the given email and password against the database
        /// </summary>
        /// <returns>true if login is succesful</returns>
        private bool TryCredentials()
        {
            tbUserName.BackColor = Color.White;

            Email = tbUserName.Text;

            Auth     auth = new Auth();
            Database db   = new Database();

            if (db.MailBelongsToOnePerson(Email))
            {
                string hashedPass = Helpers.SHA1Hash(tbPassword.Text);

                string password = db.FetchPasswordFromEmail(Email);

                if (auth.PasswordsMatch(hashedPass, password))
                {
                    foreach (var j in db.FetchJudges())
                    {
                        if (j.Email == Email)
                        {
                            Judge = j;
                            break;
                        }
                    }
                    // this should not happen
                    if (Judge == null)
                    {
                        MessageBox.Show("Login failed...");
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    tbPassword.BackColor = Color.Red;
                }
            }
            else
            {
                tbUserName.BackColor = Color.Red;
                Email = "";
            }

            return(false);
        }
        private void PushJudge(Judge judge, long contestID)
        {
            // Table info
            string table = "judge";

            // Contest info
            var personID = judge.ID;

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

            query += $"(personID, contestID) ";
            query += $"VALUES(";
            query += $"'{personID}','{contestID}'";
            query += $")";

            ExecuteQuery(query);
        }
Exemple #9
0
        /// <summary>
        /// Remove a added judge from the contest
        /// </summary>
        public void RemoveJudgeFromContest()
        {
            try
            {
                // Collect the chosen judge, gets the full name of the judge
                var judgeName = View.ListViewLocalJudges.SelectedItems[0].SubItems[0].Text + " " + View.ListViewLocalJudges.SelectedItems[0].SubItems[1].Text;

                Judge judgeToBeRemoved = null;

                // if you are the judge creating the contest, you cannot be removed.
                if (judgeName != window.CurrentJudge.GetFullName())
                {
                    // find the right Judge object
                    foreach (var j in ContestJudgeList)
                    {
                        if (String.Equals(j.GetFullName(), judgeName))
                        {
                            judgeToBeRemoved = j;
                        }
                    }

                    // remove from contestlist
                    ContestJudgeList.Remove(judgeToBeRemoved);

                    UpdateListViews();
                }
                else
                {
                    MessageBox.Show("Du kan inte ta bort dig själv!");
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Välj en domare!");
            }
        }
        public JudgeList FetchJudges()
        {
            DataTable judgeDataTable = FetchSpecifiedRole("judge");

            // Iterate through data table and add too person list
            JudgeList judgeList = new JudgeList();

            foreach (DataRow row in judgeDataTable.Rows)
            {
                Judge judge = new Judge
                {
                    ID        = Int32.Parse(row["id"].ToString()),
                    FirstName = row["firstName"].ToString(),
                    LastName  = row["lastName"].ToString(),
                    Age       = Int32.Parse(row["age"].ToString()),
                    Gender    = row["gender"].ToString(),
                    Email     = row["email"].ToString()
                };

                judgeList.Add(judge);
            }

            return(judgeList);
        }
Exemple #11
0
        public static List <Judge> GetJudgesInEvent(int eventID)
        {
            List <Judge> judges = new List <Judge>();

            MySqlConnection conn = ConnectToDatabase();

            if (conn != null)
            {
                Judge  j;
                string sql = "SELECT * FROM judge WHERE id IN (SELECT judgeId FROM event_judge WHERE eventId=" + eventID + ")"; //RADERA: ORDER BY id DESC, endast för "resultat"
                var    cmd = new MySqlCommand(sql, conn);
                var    dr  = cmd.ExecuteReader();
                var    dt  = new DataTable();
                dt.Load(dr);

                foreach (DataRow row in dt.Rows)
                {
                    j = new Judge(Int32.Parse(row["id"].ToString()), row["name"].ToString());
                    judges.Add(j);
                }
                conn.Close();
            }
            return(judges);
        }
 public Score(double value, Judge judge)
 {
     this.Value = value;
     this.Judge = judge;
 }
Exemple #13
0
 public Score(Dive d, Judge j, double points)
 {
     this.dive   = d;
     this.judge  = j;
     this.Points = points;
 }
Exemple #14
0
 /// <summary>
 /// Lägg till en domare på eventet
 /// </summary>
 /// <param name="judge"></param>
 public void AddJudge(Judge judge)
 {
     Judges.Add(judge);
 }
Exemple #15
0
        /// <summary>
        /// Skapar en Contest med hoppare, hopp och domare
        /// </summary>
        /// <param name="textBox1"></param>
        /// <param name="textBox2"></param>
        /// <param name="dateTimePicker1"></param>
        /// <param name="numericUpDown1"></param>
        /// <param name="radioButton1meter"></param>
        /// <param name="radioButton3meter"></param>
        /// <param name="radioButton5meter"></param>
        /// <param name="radioButton7meter"></param>
        /// <param name="radioButton10meter"></param>
        /// <param name="radioButtonSingle"></param>
        /// <param name="radioButtonSync"></param>
        /// <param name="radioButtonMale"></param>
        /// <param name="radioButtonFemale"></param>
        /// <param name="listViewDivers"></param>
        /// <param name="listViewJudge"></param>
        /// <param name="successfully"></param>
        /// <param name="errorlabel"></param>
        /// <param name="dataGridViewList"></param>
        public static void AddNewEventToDatabase(TextBox textBox1, TextBox textBox2, DateTimePicker dateTimePicker1, NumericUpDown numericUpDown1, RadioButton radioButton1meter, RadioButton radioButton3meter, RadioButton radioButton5meter, RadioButton radioButton7meter, RadioButton radioButton10meter, RadioButton radioButtonSingle, RadioButton radioButtonSync, RadioButton radioButtonMale, RadioButton radioButtonFemale, ListView listViewDivers, ListView listViewJudge, Label successfully, Label errorlabel, List <DataGridView> dataGridViewList)
        {
            string eventName;
            string location;
            string date;
            int    diveCount;
            int    discipline = -1;
            int    sync       = -1;
            int    sex        = -1;

            eventName = textBox1.Text;
            location  = textBox2.Text;
            date      = dateTimePicker1.Value.ToString("yyyy-MM-dd");
            diveCount = (int)numericUpDown1.Value;

            //discipline
            if (radioButton1meter.Checked)
            {
                discipline = 0;
            }
            else if (radioButton3meter.Checked)
            {
                discipline = 1;
            }
            else if (radioButton5meter.Checked)
            {
                discipline = 2;
            }
            else if (radioButton7meter.Checked)
            {
                discipline = 3;
            }
            else if (radioButton10meter.Checked)
            {
                discipline = 4;
            }

            //sync: single = 0, sync = 1
            if (radioButtonSingle.Checked)
            {
                sync = 0;
            }
            else if (radioButtonSync.Checked)
            {
                sync = 1;
            }

            //sex: male = 0, female = 1
            if (radioButtonMale.Checked)
            {
                sex = 0;
            }
            else if (radioButtonFemale.Checked)
            {
                sex = 1;
            }

            //lägger till eventet i databasen
            Contest ev = new Contest(eventName, date, location, discipline, sync, diveCount, sex);

            //hämtar dommare och hoppare från tabellerna
            List <Judge> addJudgesToEvent = new List <Judge>();
            List <Diver> addDiversToEvent = new List <Diver>();
            Diver        d;
            Judge        j;
            string       gender;
            int          g;

            foreach (ListViewItem item in listViewDivers.CheckedItems)
            {
                gender = item.SubItems[3].Text;
                if (gender.CompareTo("M") == 0)
                {
                    g = 0;
                }
                else
                {
                    g = 1;
                }
                d = new Diver(Int32.Parse(item.SubItems[4].Text), item.SubItems[0].Text, Int32.Parse(item.SubItems[2].Text), g, item.SubItems[1].Text);
                addDiversToEvent.Add(d);
            }
            ev.AddDivers(addDiversToEvent);

            foreach (ListViewItem item in listViewJudge.CheckedItems)
            {
                j = new Judge(Int32.Parse(item.SubItems[0].Text), item.SubItems[1].Text);
                addJudgesToEvent.Add(j);
            }
            ev.AddJudges(addJudgesToEvent);

            int code = Database.AddEventToDatabase(ev);

            //om inmatningen lyckades
            if (code == 1)
            {
                int eventID = Database.GetLatestAddedEventID();

                DiveType dType = new DiveType();
                int      diverID = -1, dNumber, diveTypeID;
                string   dPosition;

                MySqlConnection conn;
                using (conn = Database.ConnectToDatabase())
                {
                    for (int i = 0; i < dataGridViewList.Count; i++)
                    {
                        //antal rader i en DataGridView
                        for (int rad = 0; rad < dataGridViewList[i].RowCount; rad++)
                        {
                            //diver ID
                            diverID = Int32.Parse(dataGridViewList[i].Tag.ToString());
                            //DiveNo
                            dNumber   = Int32.Parse(dataGridViewList[i].Rows[rad].Cells[1].Value.ToString());
                            dPosition = dataGridViewList[i].Rows[rad].Cells[0].Value.ToString();

                            dType.No = dNumber;

                            SetDiveTypeHeight(dType, radioButton1meter, radioButton3meter, radioButton5meter, radioButton7meter, radioButton10meter);
                            SetDiveTypePosition(dType, dPosition);

                            diveTypeID = Database.AddDiveTypeToDatabase(dType, conn);
                            Database.AddDiveToDiver(dType, eventID, rad + 1, diveTypeID, diverID, conn);
                        }
                    }
                }

                successfully.Visible = true;
            }
            else if (code == -1)
            {
                successfully.Visible = false;
                errorlabel.Text      = "Identical event already exist";
                errorlabel.Visible   = true;;
            }
            else
            {
                successfully.Visible = false;
                errorlabel.Text      = "An error occoured, try again";
                errorlabel.Visible   = true;
            }
        }
Exemple #16
0
        public static void GetScoresToDives(Contest contest)
        {
            MySqlConnection conn = Database.ConnectToDatabase();
            MySqlCommand    comm = new MySqlCommand();
            string          sql  = "";

            comm = conn.CreateCommand();

            if (conn != null)
            {
                foreach (Diver diver in contest.Divers)
                {
                    //hämtar alla Scores som finns på hopparen
                    sql = "SELECT * FROM score WHERE diveId IN (SELECT id FROM dive WHERE diverId=" + diver.Id + " AND eventId=" + contest.Id + ") ORDER BY id";
                    comm.CommandText = sql;
                    MySqlDataReader dr = comm.ExecuteReader();
                    DataTable       dt = new DataTable();

                    dt.Load(dr);
                    int count     = 0;
                    int diveCount = 1;

                    Score currentScore = new Score();
                    Dive  currentDive  = new Dive();
                    Judge currentJudge = new Judge();


                    //Alla scores som finns på alla hoppen
                    foreach (DataRow row in dt.Rows)
                    {
                        if (count < diver.Dives.Count)
                        {
                            foreach (Judge judge in contest.Judges)
                            {
                                if (judge.Id.ToString().CompareTo(row["judgeId"].ToString()) == 0)
                                {
                                    currentJudge = judge;
                                }
                            }
                            try
                            {
                                currentDive = diver.Dives[count];
                            }
                            catch (IndexOutOfRangeException) { }

                            currentScore = new Score(Int32.Parse(row["id"].ToString()), currentDive, currentJudge, Double.Parse(row["point"].ToString()));
                            diver.Dives[count].AddScore(currentScore);


                            if (diveCount == contest.Judges.Count)
                            {
                                count++;
                                diveCount = 1;
                            }
                            else
                            {
                                diveCount++;
                            }
                        }
                    }
                }
            }
        }