private void btnAddPlayerToCouple_Click(object sender, EventArgs e)
        {
            selectedPlayer = (Player)lbPlayers2.SelectedItem;
            selectedCouple = (Couple)lbCoupleChart.SelectedItem;

            for (int x = 0; x < lbPlayerInCouple.Items.Count; x++) //ser till så att inte fler än 4 kan vara med i samma grupp
            {
                lbPlayerInCouple.SetSelected(x, true);
            }
            if (lbPlayerInCouple.Items.Count >= 2)
            {
                MessageBox.Show("Du kan inte lägga till fler spelare");
            }
            else
            {
                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 couple_id = " + selectedCouple.coupleId + " WHERE golfid = (" + selectedPlayer.golfId + " )", conn);
                    int           antal   = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
                lbPlayerInCouple.DataSource = Methods.GetPlayerInCouple(selectedCouple.coupleId);
                lbPlayers2.DataSource       = Methods.GetAvailablePlayersToCouple();
                lbPlayers.DataSource        = Methods.GetAvailablePlayers();
            }
        }
        private void btnDeleteCouple_Click(object sender, EventArgs e)
        {
            DialogResult dropCouple = MessageBox.Show("Vill du verkligen ta bort det markerade paret?", "Ta bort Par", MessageBoxButtons.OKCancel);

            if (dropCouple == DialogResult.OK)
            {
                selectedCouple = (Couple)lbCoupleChart.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 couple WHERE id = " + selectedCouple.coupleId + "";
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                    int           antal   = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
                lbCoupleChart.DataSource = Methods.GetCouples();
                lbPlayers2.DataSource    = Methods.GetAvailablePlayersToCouple();
            }
            else if (dropCouple == DialogResult.Cancel)
            {
            }
        }
Example #3
0
        public static List <Couple> GetCouples() //hämtar alla par
        {
            List <Couple>            coupleList = new List <Couple>();
            ConnectionStringSettings settings   = ConfigurationManager.ConnectionStrings[conString];
            NpgsqlConnection         conn       = new NpgsqlConnection(settings.ConnectionString);

            conn.Open();
            NpgsqlCommand    command = new NpgsqlCommand("SELECT * FROM couple ORDER BY name", conn);
            NpgsqlDataReader dr      = command.ExecuteReader();

            while (dr.Read())
            {
                Couple couples = new Couple
                {
                    coupleId   = (int)dr["id"],
                    coupleName = (string)dr["name"],
                };
                coupleList.Add(couples);
            }
            conn.Close();
            return(coupleList);
        }
        private void btnDeletePlayerFromCouple_Click(object sender, EventArgs e)
        {
            selectedPlayer = (Player)lbPlayerInCouple.SelectedItem;
            selectedCouple = (Couple)lbCoupleChart.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 SET couple_id = null WHERE couple_id = " + selectedCouple.coupleId + " 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();
            }
            lbPlayerInCouple.DataSource = Methods.GetPlayerInCouple(selectedCouple.coupleId);
            lbPlayers2.DataSource       = Methods.GetAvailablePlayersToCouple();
        }
 private void lbCoupleChart_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedCouple = (Couple)lbCoupleChart.SelectedItem;
     lbPlayerInCouple.DataSource = Methods.GetPlayerInCouple(selectedCouple.coupleId);
 }
Example #6
0
        private void btnAddPlayerToCouple_Click(object sender, EventArgs e)
        {
            selectedPlayer = (Player)lbPlayers2.SelectedItem;
            selectedCouple = (Couple)lbCoupleChart.SelectedItem;

            for (int x = 0; x < lbPlayerInCouple.Items.Count; x++) //ser till så att inte fler än 4 kan vara med i samma grupp
            {
                lbPlayerInCouple.SetSelected(x, true);
            }
            if (lbPlayerInCouple.Items.Count >= 2)
            {
                MessageBox.Show("Du kan inte lägga till fler spelare");
            }
            else
            {
                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 couple_id = " + selectedCouple.coupleId + " WHERE golfid = (" + selectedPlayer.golfId + " )", conn);
                    int antal = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
                lbPlayerInCouple.DataSource = Methods.GetPlayerInCouple(selectedCouple.coupleId);
                lbPlayers2.DataSource = Methods.GetAvailablePlayersToCouple();
                lbPlayers.DataSource = Methods.GetAvailablePlayers();
            }
        }
Example #7
0
 private void lbCoupleChart_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedCouple = (Couple)lbCoupleChart.SelectedItem;
     lbPlayerInCouple.DataSource = Methods.GetPlayerInCouple(selectedCouple.coupleId);
 }
Example #8
0
 private void btnDeletePlayerFromCouple_Click(object sender, EventArgs e)
 {
     selectedPlayer = (Player)lbPlayerInCouple.SelectedItem;
     selectedCouple = (Couple)lbCoupleChart.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 SET couple_id = null WHERE couple_id = " + selectedCouple.coupleId + " 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();
     }
     lbPlayerInCouple.DataSource = Methods.GetPlayerInCouple(selectedCouple.coupleId);
     lbPlayers2.DataSource = Methods.GetAvailablePlayersToCouple();
 }
Example #9
0
 private void btnDeleteCouple_Click(object sender, EventArgs e)
 {
     DialogResult dropCouple = MessageBox.Show("Vill du verkligen ta bort det markerade paret?", "Ta bort Par", MessageBoxButtons.OKCancel);
     if (dropCouple == DialogResult.OK)
     {
         selectedCouple = (Couple)lbCoupleChart.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 couple WHERE id = " + selectedCouple.coupleId + "";
             conn.Open();
             NpgsqlCommand command = new NpgsqlCommand(sql, conn);
             int antal = command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
         finally
         {
             conn.Close();
         }
         lbCoupleChart.DataSource = Methods.GetCouples();
         lbPlayers2.DataSource = Methods.GetAvailablePlayersToCouple();
     }
     else if (dropCouple == DialogResult.Cancel)
     { }
 }