Beispiel #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     //MessageBox.Show(dGridRaces.SelectedRows[0].Cells[0].Value.ToString());
     if (dGridRaces.SelectedRows.Count > 0)
     {
         if (MessageBox.Show("Are you sure you wish to delete?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             try
             {
                 EditRaces newWindow = new EditRaces(fontSize);
                 int       raceId    = Convert.ToInt32(dGridRaces.SelectedRows[0].Cells[0].Value);
                 Race      obj       = conn.Races.SingleOrDefault(E => E.Id == raceId);
                 conn.Races.DeleteOnSubmit(obj);
                 conn.SubmitChanges();
                 this.Close();
                 newWindow.Show();
             }
             catch (SqlException)
             {
                 MessageBox.Show("Cannot delete. Subraces exist using this race.");
             }
             catch (Exception exc)
             {
                 MessageBox.Show(exc.ToString());
             }
         }
     }
 }
Beispiel #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            EditRaces newWindow = new EditRaces(fontSize);
            //MessageBox.Show(dGridRaces.SelectedRows[0].Cells[1].Value.ToString());
            AddRace f = new AddRace(true, Convert.ToInt32(dGridRaces.SelectedRows[0].Cells[0].Value));

            f.ButtonText = "Update";
            f.RaceName   = dGridRaces.SelectedRows[0].Cells[1].Value.ToString();
            f.Str        = dGridRaces.SelectedRows[0].Cells[3].Value.ToString();
            f.Dex        = dGridRaces.SelectedRows[0].Cells[4].Value.ToString();
            f.Con        = dGridRaces.SelectedRows[0].Cells[5].Value.ToString();
            f.Int        = dGridRaces.SelectedRows[0].Cells[6].Value.ToString();
            f.Wis        = dGridRaces.SelectedRows[0].Cells[7].Value.ToString();
            f.Cha        = dGridRaces.SelectedRows[0].Cells[8].Value.ToString();
            f.ShowDialog();
            this.Close();
            newWindow.Show();
        }
 private void editRacesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Edit.EditRaces races = new Edit.EditRaces(fontSize);
     races.Show();
 }
        /// <summary>
        /// Adds a new race using query. Will close the original Edit Races window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAccept_Click_1(object sender, EventArgs e)
        {
            //For more information: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/how-to-connect-to-a-database
            DnDataSetDataContext db = new DnDataSetDataContext();

            //Table<Race> Races = db.GetTable<Race>();
            if (txtName.Text == "")
            {
                MessageBox.Show("Invalid name");
            }
            else
            {
                EditRaces n = new EditRaces(fontSize);
                if (beingEdited == false)
                {
                    Race race = new Race
                    {
                        Name         = txtName.Text,
                        Strength     = Convert.ToInt32(txtStr.Text),
                        Dexterity    = Convert.ToInt32(txtDex.Text),
                        Constitution = Convert.ToInt32(txtCon.Text),
                        Intelligence = Convert.ToInt32(txtInt.Text),
                        Wisdom       = Convert.ToInt32(txtWis.Text),
                        Charisma     = Convert.ToInt32(txtCha.Text)
                    };

                    db.Races.InsertOnSubmit(race);
                    db.SubmitChanges();

                    n.Show();

                    this.Close();
                }
                else
                {
                    var query =
                        from race in db.Races
                        where race.Id == raceID
                        select race;

                    foreach (Race races in query)
                    {
                        races.Name         = txtName.Text;
                        races.Strength     = Convert.ToInt32(txtStr.Text);
                        races.Dexterity    = Convert.ToInt32(txtDex.Text);
                        races.Constitution = Convert.ToInt32(txtCon.Text);
                        races.Intelligence = Convert.ToInt32(txtInt.Text);
                        races.Wisdom       = Convert.ToInt32(txtWis.Text);
                        races.Charisma     = Convert.ToInt32(txtCha.Text);
                    }
                    try
                    {
                        db.SubmitChanges();
                        this.Close();
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show($"Error: {exc}");
                    }
                }
                DialogResult = DialogResult.OK;
            }
        }