Example #1
0
 private void lbPassedCompetitionChart_SelectedIndexChanged(object sender, EventArgs e)
 {
     lbResults.Items.Clear();
     selectedCompetition = (Competition)lbPassedCompetitionChart.SelectedItem;
     lbGolfPlayers.DataSource = Methods.GetPlayersInPassedCompetition(selectedCompetition.Id);
 }
Example #2
0
        private void DropAllPlayers()
        {
            DialogResult dropAllPlayers = MessageBox.Show("Vänligen bekräfta om du önskar att avboka spelaranas golftid och skicka ett meddelande om detta till dem.", "Vill du avboka spelarna?", MessageBoxButtons.OKCancel);
            if (dropAllPlayers == DialogResult.OK)
            {
                selectedCompetition = (Competition)lbCompetitionChart.SelectedItem;
                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
                try
                {
                    string sql = "UPDATE golfround SET player = null WHERE date = '" + selectedCompetition.startDate + "'";
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                    int antal = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Det finns inga spelare att avboka");
                }
                finally
                {
                    conn.Close();
                }

            }
            else if (dropAllPlayers == DialogResult.Cancel)
            { }
        }
Example #3
0
        private void lbCompetitionChart_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbPlayerHasGolfround.Items.Clear();
            selectedCompetition = (Competition)lbCompetitionChart.SelectedItem;
            lbPlayersInCompetition.DataSource = Methods.GetPlayersInCompetition(selectedCompetition.Id);

            NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true;");
            try
            {
                conn.Open();
                NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM player JOIN golfround ON player.golfid = golfround.player JOIN competition ON golfround.date = competition.startdate WHERE competition.startdate = '" + selectedCompetition.startDate + "'", conn);
                NpgsqlDataReader dr = command.ExecuteReader();
                while (dr.Read())
                {
                //    MessageBox.Show((dr["firstname"] + " " + dr["lastname"]));
                    lbPlayerHasGolfround.Items.Add(dr["firstname"] + " " + dr["lastname"]);
                }
            }
            finally
            {

                conn.Close();
            }
        }
Example #4
0
        private void DeleteCompetition()
        {
            selectedCompetition = (Competition)lbCompetitionChart.SelectedItem;
            DialogResult dropCompetition = MessageBox.Show("Vill du verkligen ta bort den markerade tävlingen?", "Ta bort tävling", MessageBoxButtons.OKCancel);
            if (dropCompetition == DialogResult.OK)
            {
                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true;");
                try
                {
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand(("DELETE FROM competition WHERE competition.id = " + selectedCompetition.Id + ""), conn);

                    int numberOfAffectedRows = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {

                    conn.Close();
                    MessageBox.Show("Tävlingen är nu borttagen.");
                }
            }
            else if (dropCompetition == DialogResult.Cancel)
            { }
        }
Example #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            selectedCompetition = (Competition)lbCompetitionChart.SelectedItem;
            selectedPlayer = (Player)lbSinglePlayers.SelectedItem;

            NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
            try
            {
                conn.Open();
                NpgsqlCommand command = new NpgsqlCommand("INSERT INTO player_competition (competition_id, player_id) VALUES (" + selectedCompetition.Id + "," + selectedPlayer.golfId + ")", conn);
                int antal = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
            lbPlayersInCompetition.DataSource = Methods.GetPlayersInCompetition(selectedCompetition.Id);
        }
Example #6
0
        private void btnGetResult_Click(object sender, EventArgs e)
        {
            if (rbClassA.Checked == true)
            {
                lbResults.Items.Clear();
                selectedCompetition = (Competition)lbPassedCompetitionChart.SelectedItem;
                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
                try
                {
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand("SELECT *, result FROM player JOIN player_competition ON player.golfid = player_competition.player_id AND player_competition.competition_id = " + selectedCompetition.Id + " ORDER BY result", conn);
                    NpgsqlDataReader dr = command.ExecuteReader();
                    while (dr.Read())
                    {

                        if (0 <= Convert.ToInt32(dr["handicap"]) && selectedCompetition.classA >= Convert.ToInt32(dr["handicap"]))
                        {
                            lbResults.Items.Add(dr["firstname"] + " " + dr["lastname"] + " " + dr["result"]);
                        }
                        else
                        {
                        }
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
                if (rbClassB.Checked == true)
            {
                lbResults.Items.Clear();
                selectedCompetition = (Competition)lbPassedCompetitionChart.SelectedItem;
                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
                try
                {
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand("SELECT firstname, lastname, handicap, result FROM player JOIN player_competition ON player.golfid = player_competition.player_id AND player_competition.competition_id = " + selectedCompetition.Id + " ORDER BY result", conn);
                    NpgsqlDataReader dr = command.ExecuteReader();
                    while (dr.Read())
                    {

                        if (Convert.ToInt32(dr["handicap"]) > selectedCompetition.classA && Convert.ToInt32(dr["handicap"]) <= selectedCompetition.classB)
                        {
                            lbResults.Items.Add(dr["firstname"] + " " + dr["lastname"] + " " + dr["result"]);
                        }
                        else
                        {
                        }
                    }
                }
                finally
                {
                    conn.Close();
                }
                }

                if (rbClassC.Checked == true)
                {
                    lbResults.Items.Clear();
                    selectedCompetition = (Competition)lbPassedCompetitionChart.SelectedItem;
                    NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
                    try
                    {
                        conn.Open();
                        NpgsqlCommand command = new NpgsqlCommand("SELECT firstname, lastname, handicap, result FROM player JOIN player_competition ON player.golfid = player_competition.player_id AND player_competition.competition_id = " + selectedCompetition.Id + " ORDER BY result", conn);
                        NpgsqlDataReader dr = command.ExecuteReader();
                        while (dr.Read())
                        {

                            if (Convert.ToInt32(dr["handicap"]) > selectedCompetition.classB)
                            {
                                lbResults.Items.Add(dr["firstname"] + " " + dr["lastname"] + " " + dr["result"]);
                            }
                            else
                            {
                            }
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }

            }
        }
Example #7
0
        private void btnDropPlayerFromComp_Click(object sender, EventArgs e)
        {
            selectedPlayer = (Player)lbPlayersInCompetition.SelectedItem;
            selectedCompetition = (Competition)lbCompetitionChart.SelectedItem;

            NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
            try
            {
                string sql = "DELETE FROM player_competition WHERE competition_id = " + selectedCompetition.Id + " AND player_id = " + selectedPlayer.golfId + "";
                conn.Open();
                NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                int antal = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }
            finally
            {
                MessageBox.Show("Du har nu avbokat spelaren från tävlingen.");
                lbPlayersInCompetition.DataSource = Methods.GetPlayersInCompetition(selectedCompetition.Id);
                conn.Close();
            }
        }
Example #8
0
        private void btnAddResult_Click(object sender, EventArgs e)
        {
            int result = Convert.ToInt32(txtAddResult.Text);
            selectedPlayer = (Player)lbGolfPlayers.SelectedItem;
            selectedCompetition = (Competition)lbPassedCompetitionChart.SelectedItem;

            NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
            try
            {
                string sql = "UPDATE player_competition SET result = " + result + " WHERE player_id = " + selectedPlayer.golfId + " AND competition_id = " + selectedCompetition.Id + "";
                conn.Open();
                NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                int antal = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
                txtAddResult.Clear();
            }
        }