Exemplo n.º 1
0
        private void AddDiverToList(Diver diver, bool isSync)
        {
            ListViewItem item1 = new ListViewItem();

            item1.Text = diver.Name;

            if (isSync)
            {
                item1.SubItems.Add("");
                item1.SubItems.Add("");
                item1.SubItems.Add("");
                item1.SubItems.Add(diver.Id.ToString());
            }
            else
            {
                item1.SubItems.Add(diver.Country);
                item1.SubItems.Add(diver.Age.ToString());
                item1.SubItems.Add(newDiverSelectGender.Text);
                item1.SubItems.Add(diver.Id.ToString());
            }

            listViewDivers.Items.Add(item1);

            item1.Checked = true;
            item1.EnsureVisible();
        }
Exemplo n.º 2
0
        /// <summary>
        /// lägger till hoppare i databasen
        /// </summary>
        /// <returns>Returnerar hopparens auto increment ID</returns>
        public static int AddDiverToDatabase(Diver d1)
        {
            //ansluter till databasen
            MySqlConnection conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                //lägger till hopparen i databasen
                MySqlCommand comm = conn.CreateCommand();
                comm.CommandText = "INSERT INTO diver(name, age, sex, country) VALUES(@name, @age, @sex, @country)";

                comm.Parameters.AddWithValue("@name", d1.Name);
                comm.Parameters.AddWithValue("@age", d1.Age);
                comm.Parameters.AddWithValue("@sex", d1.Sex);
                comm.Parameters.AddWithValue("@country", d1.Country);
                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];
                string  id  = row["id"].ToString();

                conn.Close();
                d1.Id = Int32.Parse(id);
                return(Int32.Parse(id));
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Söker i databasen efter en specifik domare och returnerar den
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Judge or NULL</returns>
        public static Diver GetSpecificDiverFromDatabase(int id)
        {
            Diver d    = new Diver();
            var   conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                string sql = "SELECT * FROM diver WHERE id=" + id.ToString();
                var    cmd = new MySqlCommand(sql, conn);
                var    dr  = cmd.ExecuteReader();
                var    dt  = new DataTable();
                dt.Load(dr);

                //om en hoppare hittas returneras den, annars NULL
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        d.Id   = Int32.Parse(row["id"].ToString());
                        d.Name = row["name"].ToString();
                    }
                    conn.Close();
                    return(d);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// lägger till hoppare i databasen
        /// </summary>
        /// <returns>Returnerar hopparens auto increment ID</returns>
        public static int AddDiverToDatabase(Diver d1)
        {
            //ansluter till databasen
            MySqlConnection conn = Database.ConnectToDatabase();
            if (conn != null)
            {
                //lägger till hopparen i databasen
                MySqlCommand comm = conn.CreateCommand();
                comm.CommandText = "INSERT INTO diver(name, age, sex, country) VALUES(@name, @age, @sex, @country)";

                comm.Parameters.AddWithValue("@name", d1.Name);
                comm.Parameters.AddWithValue("@age", d1.Age);
                comm.Parameters.AddWithValue("@sex", d1.Sex);
                comm.Parameters.AddWithValue("@country", d1.Country);
                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];
                string id = row["id"].ToString();

                conn.Close();
                d1.Id = Int32.Parse(id);
                return Int32.Parse(id);
            }
            else
            {
                return -1;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Lägger till en ny hoppare i databasen och i listViewDivers
        /// </summary>
        /// <param name="newDiverSelectGender"></param>
        /// <param name="newDiverName"></param>
        /// <param name="newDiverAge"></param>
        /// <param name="newDiverCountry"></param>
        /// <param name="listViewDivers"></param>
        /// <param name="radioButtonMale"></param>
        /// <param name="radioButtonFemale"></param>
        public static void AddNewDiver(ComboBox newDiverSelectGender, TextBox newDiverName, TextBox newDiverAge, TextBox newDiverCountry, ListView listViewDivers, RadioButton radioButtonMale, RadioButton radioButtonFemale)
        {
            //fel hantering, måste ange giltigt namn och nationalitet
            if (newDiverName.Text.CompareTo("Namn") == 0 || newDiverCountry.Text.CompareTo("Nationalitet") == 0 || newDiverSelectGender.Text.Length == 0)
            {
                MessageBox.Show("Fel inmatning, försök igen");
            }
            else
            {
                int gender = -1;
                if (newDiverSelectGender.Text.CompareTo("Man") == 0)
                {
                    gender = 0;
                }
                else
                {
                    gender = 1;
                }

                //lägger till den nya hopparen i databasen
                Diver diver = new Diver();
                try
                {
                    diver = new Diver(newDiverName.Text, Int32.Parse(newDiverAge.Text), gender, newDiverCountry.Text);
                }
                catch (FormatException e)
                {
                    MessageBox.Show("Du har angivit fel format, försök igen", "Fel format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int ID = Database.AddDiverToDatabase(diver);
                diver.Id = ID;

                //lägger till den nya hopparen i listan
                if ((radioButtonMale.Checked && newDiverSelectGender.Text.CompareTo("Man") == 0) || (radioButtonFemale.Checked && newDiverSelectGender.Text.CompareTo("Kvinna") == 0))
                {
                    ListViewItem item1 = new ListViewItem();
                    item1.Text = diver.Name;
                    listViewDivers.Items.Add(item1);

                    item1.SubItems.Add(diver.Country);
                    item1.SubItems.Add(diver.Age.ToString());
                    if (gender == 0)
                    {
                        item1.SubItems.Add("M");
                    }
                    else
                    {
                        item1.SubItems.Add("F");
                    }
                    item1.SubItems.Add(diver.Id.ToString());
                }
            }

            //restore textbox
            newDiverName.Text    = "Namn";
            newDiverAge.Text     = "Ålder";
            newDiverCountry.Text = "Nationalitet";
        }
Exemplo n.º 6
0
 private void addDiverToEvent_Click(object sender, EventArgs e)
 {
     foreach(ListViewItem item in listViewDivers.CheckedItems)
     {
         Diver d = new Diver(Int32.Parse(item.Text), item.SubItems[1].Text, Int32.Parse(item.SubItems[3].Text), Int32.Parse(item.SubItems[4].Text), item.SubItems[2].Text);
         diverList.Add(d);
     }
     this.Close();
 }
Exemplo n.º 7
0
        public Dive(int ID, Diver person, Contest comp, DiveType diveType)
        {
            this.Id       = ID;
            this._diver   = person;
            this._contest = comp;
            _diveType     = diveType;

            Scores = new List <Score>();
        }
Exemplo n.º 8
0
 public Dive(int ID, Diver person, double difficulty, Contest comp)
 {
     this.Id = ID;
     this._diver = person;
     this.Difficulty = difficulty;
     this._contest = comp;
     Scores = new List<Score>();
     _diveType = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 9
0
 private void addDiverToEvent_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in listViewDivers.CheckedItems)
     {
         Diver d = new Diver(Int32.Parse(item.Text), item.SubItems[1].Text, Int32.Parse(item.SubItems[3].Text), Int32.Parse(item.SubItems[4].Text), item.SubItems[2].Text);
         diverList.Add(d);
     }
     this.Close();
 }
Exemplo n.º 10
0
 public Dive()
 {
     this.Id = -1;
     this._diver = null;
     this.Difficulty = 0.0;
     this._contest = null;
     Scores = new List<Score>();
     _diveType = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 11
0
        public Dive(int ID, Diver person, Contest comp, DiveType diveType)
        {
            this.Id = ID;
            this._diver = person;
            this._contest = comp;
            _diveType = diveType;

            Scores = new List<Score>();
        }
Exemplo n.º 12
0
 public Dive()
 {
     this.Id         = -1;
     this._diver     = null;
     this.Difficulty = 0.0;
     this._contest   = null;
     Scores          = new List <Score>();
     _diveType       = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 13
0
 public Dive(int ID, Diver person, double difficulty, Contest comp)
 {
     this.Id         = ID;
     this._diver     = person;
     this.Difficulty = difficulty;
     this._contest   = comp;
     Scores          = new List <Score>();
     _diveType       = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 14
0
        void listViewDivers_DragDrop(object sender, DragEventArgs e)
        {
            var pos = listViewDivers.PointToClient(new Point(e.X, e.Y));
            var hit = listViewDivers.HitTest(pos);

            if (hit.Item != null)
            {
                var    dragItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
                Random random   = new Random(int.Parse(Guid.NewGuid().ToString().Substring(0, 8), System.Globalization.NumberStyles.HexNumber));
                int    newId    = random.Next(1, Int32.MaxValue);
                Diver  d1       = new Diver(newId, dragItem.Text + " & " +
                                            hit.Item.Text);
                AddDiverToList(d1, true);
            }
        }
Exemplo n.º 15
0
        public void RunScoreDive()
        {
            Assert.LessOrEqual(_divers[0].Dives[0].Score, 30);

            Diver tDiver = new Diver(-1, "Greger");
            Dive tDive = new Dive(-1, tDiver, 1, _contest);
            tDiver.AddDive(tDive);
            tDive.AddScore(new Score(0, tDive, _judges[0], 1));
            tDive.AddScore(new Score(0, tDive, _judges[1], 5));
            tDive.AddScore(new Score(0, tDive, _judges[2], 5));
            tDive.AddScore(new Score(0, tDive, _judges[3], 5));
            tDive.AddScore(new Score(0, tDive, _judges[4], 10));

            Assert.AreEqual(tDive.Score, 15);
        }
Exemplo n.º 16
0
        //VARIT OKLART VÄLDIGT LÄNGE NU? STATUS?
        //*** THOMAS - RESULT (EJ KLAR)

        /*
         * public static void SetDiveTotalScore(int diveID)
         * {
         *  MySqlConnection conn = ConnectToDatabase();
         *  string sql = "";
         *
         *  if (conn != null)
         *  {
         *      sql = "UPDATE dive SET totalScore=" * **CalculateScore().totalScore * **"WHERE id=" + diveID + ";";
         *      var cmd = new MySqlCommand(sql, conn);
         *      var dr = cmd.ExecuteNonQuery();
         *  }
         *
         *  else
         *  {
         *      MessageBox.Show("Anslutningen till databasen misslyckades", "Fel", MessageBoxButtons.OK, MessageBoxIcon.Error);
         *      return;
         *  }
         * }
         */

        //public static List<Diver> GetDiveTotalScore(int eventID, ListView listViewResult)
        //{
        //    List<Diver> divers = new List<Diver>();
        //    List<double> points = new List<double>();

        //    MySqlConnection conn = ConnectToDatabase();
        //    if (conn != null)
        //    {
        //        Diver d;
        //        // HÄMTAR ENDAST DEM SOM HOPPAT
        //        string sql = "SELECT diver.name, IFNULL(sum(dive.totalScore),0) AS totalScore FROM diver, dive WHERE dive.eventId =" + eventID + "AND diver.id = dive.diverId GROUP BY diver.name;";
        //        var cmd = new MySqlCommand(sql, conn);
        //        var dr = cmd.ExecuteReader();
        //        var dt = new DataTable();
        //        dt.Load(dr);

        //        //HÄMTAR DE SOM INTE HOPPAT
        //        /*
        //        string sql =

        //        SELECT diver.name
        //        FROM diver
        //        WHERE event_diver.eventId = " + eventID + " AND
        //        event_diver.diverId NOT IN(SELECT dive.diverId FROM dive);


        //        */

        //        foreach (DataRow row in dt.Rows)
        //        {
        //            ListViewItem item1 = new ListViewItem();
        //            item1.Text = row["name"].ToString();
        //            listViewResult.Items.Add(item1);
        //            item1.SubItems.Add(row["totalScore"].ToString());
        //        }
        //    }
        //    return divers;
        //}

        #endregion

        #region Event_diver
        public static void GetDiversInContest(int eventID, ListView listViewResult = null)
        {
            List <Diver> divers = new List <Diver>();

            try
            {
                MySqlConnection conn = ConnectToDatabase();
                if (conn != null)
                {
                    Diver  d;
                    string sql = "SELECT * FROM (SELECT diver.id AS id, diver.name AS name, sum(dive.totalScore) as totalScore FROM diver, dive WHERE dive.diverId = diver.id AND diver.id IN (SELECT diverId FROM event_diver WHERE event_diver.eventId=" + eventID + ") AND dive.eventId = " + eventID + " GROUP BY diver.id) AS Result ORDER BY totalScore DESC;";
                    var    cmd = new MySqlCommand(sql, conn);
                    var    dr  = cmd.ExecuteReader();
                    var    dt  = new DataTable();
                    dt.Load(dr);

                    foreach (DataRow row in dt.Rows)
                    {
                        d = new Diver(Int32.Parse(row["id"].ToString()), row["name"].ToString());
                        divers.Add(d);

                        sql = "SELECT totalScore FROM dive WHERE diverId=" + d.Id + " AND eventId=" + eventID;
                        var cmd2 = new MySqlCommand(sql, conn);

                        var dr2 = cmd2.ExecuteReader();
                        var dt2 = new DataTable();
                        dt2.Load(dr2);

                        double summa = 0;

                        foreach (DataRow row2 in dt2.Rows)
                        {
                            summa += Double.Parse(row2["totalScore"].ToString());
                        }

                        ListViewItem item = new ListViewItem();
                        item.Text = summa.ToString();
                        item.SubItems.Add(d.Name);
                        listViewResult.Items.Add(item);
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Exemplo n.º 17
0
        public void RunScoreGreaterThanMax()
        {
            Assert.AreEqual(1, 1);
            return;

            Diver tDiver = new Diver(-1, "Gregers kompis");
            Dive tDive = new Dive(-1, tDiver, 1, _contest);
            tDiver.AddDive(tDive);
            tDive.AddScore(new Score(0, tDive, _judges[0], 11));
            tDive.AddScore(new Score(0, tDive, _judges[1], 11));
            tDive.AddScore(new Score(0, tDive, _judges[2], 11));
            tDive.AddScore(new Score(0, tDive, _judges[3], 11));
            tDive.AddScore(new Score(0, tDive, _judges[4], 11));

            //Assert.AreEqual(tDive.Score, 30);
        }
Exemplo n.º 18
0
        public static List <Diver> GetDivers(int ColumnIndex)
        {
            string sql       = "";
            var    diverList = new List <Diver>();

            switch (ColumnIndex)
            {
            case 0:
                sql = "SELECT * FROM diver ORDER BY name";
                break;

            case 1:
                sql = "SELECT * FROM diver ORDER BY country";
                break;

            case 2:
                sql = "SELECT * FROM diver ORDER BY age";
                break;
            }

            var conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                var cmd = new MySqlCommand(sql, conn);
                var dr  = cmd.ExecuteReader();
                var dt  = new DataTable();
                dt.Load(dr);

                foreach (DataRow row in dt.Rows)
                {
                    var tmp = new Diver(Int32.Parse(row["id"].ToString()), row["name"].ToString(), Int32.Parse(row["age"].ToString()), Int32.Parse(row["sex"].ToString()), row["country"].ToString());
                    diverList.Add(tmp);
                }

                conn.Close();
            }

            return(diverList);
        }
Exemplo n.º 19
0
        public static List <Diver> GetDiversInEvent(int eventID, ListView listViewResult = null)
        {
            List <Diver> divers = new List <Diver>();

            MySqlConnection conn = ConnectToDatabase();

            if (conn != null)
            {
                Diver  d;
                string sql = "SELECT * FROM diver WHERE id IN (SELECT diverId FROM event_diver WHERE event_diver.eventId=" + eventID + ") ORDER BY id DESC;"; //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)
                {
                    d = new Diver(Int32.Parse(row["id"].ToString()), row["name"].ToString());
                    divers.Add(d);
                }
                conn.Close();
            }
            return(divers);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Lägg till en hoppare på eventet
 /// </summary>
 /// <param name="diver"></param>
 public void AddDiver(Diver diver)
 {
     Divers.Add(diver);
 }
Exemplo n.º 21
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;
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Lägger till en ny hoppare i databasen och i listViewDivers
        /// </summary>
        /// <param name="newDiverSelectGender"></param>
        /// <param name="newDiverName"></param>
        /// <param name="newDiverAge"></param>
        /// <param name="newDiverCountry"></param>
        /// <param name="listViewDivers"></param>
        /// <param name="radioButtonMale"></param>
        /// <param name="radioButtonFemale"></param>
        public static void AddNewDiver(ComboBox newDiverSelectGender, TextBox newDiverName, TextBox newDiverAge, TextBox newDiverCountry, ListView listViewDivers, RadioButton radioButtonMale, RadioButton radioButtonFemale)
        {
            //fel hantering, måste ange giltigt namn och nationalitet
            if (newDiverName.Text.CompareTo("Namn") == 0 || newDiverCountry.Text.CompareTo("Nationalitet") == 0 || newDiverSelectGender.Text.Length == 0)
            {
                MessageBox.Show("Fel inmatning, försök igen");
            }
            else
            {
                int gender = -1;
                if (newDiverSelectGender.Text.CompareTo("Man") == 0)
                {
                    gender = 0;
                }
                else
                {
                    gender = 1;
                }

                //lägger till den nya hopparen i databasen
                Diver diver = new Diver();
                try
                {
                    diver = new Diver(newDiverName.Text, Int32.Parse(newDiverAge.Text), gender, newDiverCountry.Text);
                }
                catch (FormatException e)
                {
                    MessageBox.Show("Du har angivit fel format, försök igen", "Fel format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int ID = Database.AddDiverToDatabase(diver);
                diver.Id = ID;

                //lägger till den nya hopparen i listan
                if ((radioButtonMale.Checked && newDiverSelectGender.Text.CompareTo("Man") == 0) || (radioButtonFemale.Checked && newDiverSelectGender.Text.CompareTo("Kvinna") == 0))
                {
                    ListViewItem item1 = new ListViewItem();
                    item1.Text = diver.Name;
                    listViewDivers.Items.Add(item1);

                    item1.SubItems.Add(diver.Country);
                    item1.SubItems.Add(diver.Age.ToString());
                    if (gender == 0)
                    {
                        item1.SubItems.Add("M");
                    }
                    else
                    {
                        item1.SubItems.Add("F");
                    }
                    item1.SubItems.Add(diver.Id.ToString());
                }
            }

            //restore textbox
            newDiverName.Text = "Namn";
            newDiverAge.Text = "Ålder";
            newDiverCountry.Text = "Nationalitet";
        }
Exemplo n.º 23
0
        public static void GetDiversInContest(int eventID, ListView listViewResult = null)
        {
            List<Diver> divers = new List<Diver>();
            try
            {
                MySqlConnection conn = ConnectToDatabase();
                if (conn != null)
                {
                    Diver d;
                    string sql = "SELECT * FROM (SELECT diver.id AS id, diver.name AS name, sum(dive.totalScore) as totalScore FROM diver, dive WHERE dive.diverId = diver.id AND diver.id IN (SELECT diverId FROM event_diver WHERE event_diver.eventId=" + eventID + ") AND dive.eventId = " + eventID + " GROUP BY diver.id) AS Result ORDER BY totalScore DESC;";
                    var cmd = new MySqlCommand(sql, conn);
                    var dr = cmd.ExecuteReader();
                    var dt = new DataTable();
                    dt.Load(dr);

                    foreach (DataRow row in dt.Rows)
                    {
                        d = new Diver(Int32.Parse(row["id"].ToString()), row["name"].ToString());
                        divers.Add(d);

                        sql = "SELECT totalScore FROM dive WHERE diverId=" + d.Id + " AND eventId=" + eventID;
                        var cmd2 = new MySqlCommand(sql, conn);

                        var dr2 = cmd2.ExecuteReader();
                        var dt2 = new DataTable();
                        dt2.Load(dr2);

                        double summa = 0;

                        foreach (DataRow row2 in dt2.Rows)
                        {
                            summa += Double.Parse(row2["totalScore"].ToString());
                        }

                        ListViewItem item = new ListViewItem();
                        item.Text = summa.ToString();
                        item.SubItems.Add(d.Name);
                        listViewResult.Items.Add(item);
                    }
                    conn.Close();
                }
            }
            catch(Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Exemplo n.º 24
0
        public static List<Diver> GetDivers(int ColumnIndex)
        {
            string sql = "";
            var diverList = new List<Diver>();

            switch(ColumnIndex)
            {
                case 0:
                    sql = "SELECT * FROM diver ORDER BY name";
                    break;

                case 1:
                    sql = "SELECT * FROM diver ORDER BY country";
                    break;

                case 2:
                    sql = "SELECT * FROM diver ORDER BY age";
                    break;
            }

            var conn = Database.ConnectToDatabase();
            if(conn != null)
            {
                var cmd = new MySqlCommand(sql, conn);
                var dr = cmd.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);

                foreach (DataRow row in dt.Rows)
                {
                    var tmp = new Diver(Int32.Parse(row["id"].ToString()), row["name"].ToString(), Int32.Parse(row["age"].ToString()), Int32.Parse(row["sex"].ToString()), row["country"].ToString());
                    diverList.Add(tmp);
                }

                conn.Close();
            }

            return diverList;
        }
Exemplo n.º 25
0
        public static List<Diver> GetDiversInEvent(int eventID, ListView listViewResult = null)
        {
            List<Diver> divers = new List<Diver>();

            MySqlConnection conn = ConnectToDatabase();
            if (conn != null)
            {
                Diver d;
                string sql = "SELECT * FROM diver WHERE id IN (SELECT diverId FROM event_diver WHERE event_diver.eventId=" + eventID + ") ORDER BY id DESC;"; //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)
                {
                    d = new Diver(Int32.Parse(row["id"].ToString()), row["name"].ToString());
                    divers.Add(d);
                }
                conn.Close();
            }
            return divers;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Söker i databasen efter en specifik domare och returnerar den
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Judge or NULL</returns>
        public static Diver GetSpecificDiverFromDatabase(int id)
        {
            Diver d = new Diver();
            var conn = Database.ConnectToDatabase();
            if(conn != null)
            {
                string sql = "SELECT * FROM diver WHERE id=" + id.ToString();
                var cmd = new MySqlCommand(sql, conn);
                var dr = cmd.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);

                //om en hoppare hittas returneras den, annars NULL
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        d.Id = Int32.Parse(row["id"].ToString());
                        d.Name = row["name"].ToString();
                    }
                    conn.Close();
                    return d;
                }
                else
                {
                    return null;
                }
            }
            return null;
        }
Exemplo n.º 27
0
 /// <summary>
 /// Lägg till en hoppare på eventet
 /// </summary>
 /// <param name="diver"></param>
 public void AddDiver(Diver diver)
 {
     Divers.Add(diver);
 }
Exemplo n.º 28
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;
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Ritar upp en panel med information om ett hopp.
        /// Layout-sketch:
        ///
        ///     [Namn]
        ///     ([DD])  [Hopp-typ]      [Hopp-poäng]
        ///     [] [] [] [] [] < Domarpoäng
        ///
        /// </summary>
        /// <param name="diver">Hoppare</param>
        /// <param name="round">Vilket hopp i ordningen</param>
        /// <returns></returns>
        public static Panel DivePanel(Diver diver, int round, int judgeCount, EventHandler UpdateScoreDelegate)
        {
            Init();

            Dive dive = diver.Dives[round];

            FontFamily fontFamily = new FontFamily("Cambria");

            Font fontName = new Font(
                fontFamily,
                15,
                FontStyle.Bold,
                GraphicsUnit.Pixel);

            Font fontScore = new Font(
                fontFamily,
                18,
                FontStyle.Bold,
                GraphicsUnit.Pixel);

            int   pWidth = 402;
            Panel p      = new Panel();

            p.Width     = pWidth;
            p.Height    = 74;
            p.BackColor = _colors[1];
            p.Anchor    = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;

            Panel panelBorder = new Panel();

            panelBorder.BackColor = _colors[0];
            panelBorder.Height    = 2;
            panelBorder.Width     = p.Width;
            panelBorder.Top       = p.Height - 2;
            panelBorder.Left      = 0;
            panelBorder.Anchor    = AnchorStyles.Left | AnchorStyles.Right;
            p.Controls.Add(panelBorder);

            //Fulhax
            Panel panelCover = new Panel();

            panelCover.BackColor = _colors[1];
            panelCover.Top       = 0;
            panelCover.Left      = 0;
            panelCover.Width     = 17;
            panelCover.Height    = p.Height;
            p.Controls.Add(panelCover);
            panelCover.BringToFront();

            Label name = new Label();

            name.Text      = diver.Name;
            name.Top       = 2;
            name.Left      = 20;
            name.Font      = fontName;
            name.ForeColor = Color.White;

            p.Controls.Add(name);


            Label difficulty = new Label();

            difficulty.Text        = "[" + dive.Difficulty + "] " + dive.Name;
            difficulty.Top         = 22;
            difficulty.Left        = 20;
            difficulty.AutoSize    = true;
            difficulty.MaximumSize = new Size(p.Width - 60, 22);
            difficulty.ForeColor   = Color.White;
            difficulty.Font        = new Font(fontName, FontStyle.Regular);

            p.Controls.Add(difficulty);


            Label points = new Label();

            points.Text      = "";
            points.Left      = p.Width - points.Width - 10;
            points.Top       = 10;
            points.Font      = fontName;
            points.TextAlign = ContentAlignment.MiddleRight;
            points.ForeColor = Color.White;
            points.Name      = "Points";
            points.Anchor    = AnchorStyles.Right;

            p.Controls.Add(points);

            Panel scorePanel = new Panel();

            scorePanel.Width     = pWidth;
            scorePanel.Height    = 30;
            scorePanel.Left      = 0;
            scorePanel.Top       = 45;
            scorePanel.BackColor = Color.Transparent;
            scorePanel.Tag       = points;

            for (int i = 0; i < judgeCount; i++)
            {
                TextBox tb = new TextBox();
                tb.Text         = " ";
                tb.Left         = 24 + i * 40;
                tb.Width        = 32;
                tb.Height       = 22;
                tb.TextAlign    = HorizontalAlignment.Center;
                tb.BorderStyle  = BorderStyle.None;
                tb.BackColor    = _colors[1];
                tb.ForeColor    = Color.White;
                tb.Font         = fontScore;
                tb.Name         = "Score";
                tb.ReadOnly     = true;
                tb.TextChanged += UpdateScoreDelegate;
                tb.GotFocus    += tb_GotFocus;

                scorePanel.Controls.Add(tb);
            }

            p.Controls.Add(scorePanel);

            return(p);
        }