Ejemplo n.º 1
0
 private void lbTeamChart_SelectedIndexChanged(object sender, EventArgs e)
 {
     label12.Text = Convert.ToString(lbTeamChart.SelectedItem.ToString()) + "";
     selectedTeam = (Team)lbTeamChart.SelectedItem;
     lbPlayerInTeam.DataSource = Methods.GetPlayerInTeam(selectedTeam.teamId);
 }
Ejemplo n.º 2
0
        //Denna kod låg här tidigare, den fungerar och därför kommenterar jag endast bort den istället för att radera
        /*     selectedPlayer = (Player)lbPlayers.SelectedItem;
            selectedTeam = (Team)lbTeamChart.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("UPDATE player SET team_id = " + selectedTeam.teamId + " WHERE golfid = (" + selectedPlayer.golfId + " )", conn);
                int antal = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
            lbPlayerInTeam.DataSource = Methods.GetPlayerInTeam(selectedTeam.teamId);
            lbPlayers.DataSource = Methods.GetAvailablePlayers();
        }*/
        private void btnDeletePlayerFromTeam_Click(object sender, EventArgs e)
        {
            selectedPlayer = (Player)lbPlayerInTeam.SelectedItem;
            selectedTeam = (Team)lbTeamChart.SelectedItem;

            DialogResult dropPlayerFromTeam = MessageBox.Show("Vill du verkligen ta bort den markerade spelaren från laget?", "Ta bort spelare", MessageBoxButtons.OKCancel);
            if (dropPlayerFromTeam == DialogResult.OK)
            {

                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
                try
                {
                    string sql = "UPDATE player SET team_id = null WHERE team_id = " + selectedTeam.teamId + " AND golfid = " + selectedPlayer.golfId + "";
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                    int antal = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
                lbPlayerInTeam.DataSource = Methods.GetPlayerInTeam(selectedTeam.teamId);
                lbPlayers.DataSource = Methods.GetAvailablePlayers();
                MessageBox.Show("Spelaren är nu borttagen från laget.");
            }
            else if (dropPlayerFromTeam == DialogResult.Cancel)
            { }
        }
Ejemplo n.º 3
0
        private void btnDeleteTeam_Click(object sender, EventArgs e)
        {
            DialogResult dropTeam = MessageBox.Show("Vill du verkligen ta bort det markerade laget?", "Ta bort lag", MessageBoxButtons.OKCancel);
            if (dropTeam == DialogResult.OK)
            {
                selectedTeam = (Team)lbTeamChart.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 team WHERE id = " + selectedTeam.teamId + "";
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                    int antal = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }

                lbTeamChart.DataSource = Methods.GetTeams();
                lbPlayers.DataSource = Methods.GetAvailablePlayers();
            }
            else if (dropTeam == DialogResult.Cancel)
            { }
        }
Ejemplo n.º 4
0
        private void btnAddPlayerToTeam_Click(object sender, EventArgs e)
        {
            for (int x = 0; x < lbPlayerInTeam.Items.Count; x++) //ser till så att inte fler än 4 kan vara med i samma grupp
            {
                lbPlayerInTeam.SetSelected(x, true);
            }
            if (lbPlayerInTeam.Items.Count >= 4)
            {
                MessageBox.Show("Du kan inte lägga till fler spelare");
            }
            else
            {
                selectedTeam = (Team)lbTeamChart.SelectedItem;
                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");

                selectedPlayer = (Player)lbPlayers.SelectedItem;
                selectedTeam = (Team)lbTeamChart.SelectedItem;
                try
                {
                    conn.Open();
                    NpgsqlCommand command1 = new NpgsqlCommand("UPDATE player SET team_id = " + selectedTeam.teamId + " WHERE golfid = (" + selectedPlayer.golfId + " )", conn);
                    int antal = command1.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
                lbPlayerInTeam.DataSource = Methods.GetPlayerInTeam(selectedTeam.teamId);
                lbPlayers.DataSource = Methods.GetAvailablePlayers();
            }
        }