コード例 #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());
             }
         }
     }
 }
コード例 #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dGrid.SelectedRows.Count > 0)
     {
         if (MessageBox.Show("Are you sure you wish to delete?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             int     raceId = Convert.ToInt32(dGrid.SelectedRows[0].Cells[0].Value);
             Subrace obj    = conn.Subraces.SingleOrDefault(E => E.Id == raceId);
             conn.Subraces.DeleteOnSubmit(obj);
             conn.SubmitChanges();
         }
     }
     LoadData(fontSize);
 }
コード例 #3
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" || cbBoxRace.Text == "")
            {
                MessageBox.Show("Missing required information");
            }
            else
            {
                if (beingEdited == false)
                {
                    var query = from race in db.Races
                                where race.Name == cbBoxRace.Text
                                select race.Id;

                    //Sets the race foreign key
                    foreach (int ID in query)
                    {
                        raceID = ID;
                    }

                    Subrace sub = new Subrace
                    {
                        Name         = txtName.Text,
                        RaceId       = raceID,
                        Speed        = Convert.ToInt32(txtSpeed.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.Subraces.InsertOnSubmit(sub);
                    db.SubmitChanges();
                    this.Close();
                }
                else
                {
                    //updates race ID if necessary
                    var raceQuery = from race in db.Races
                                    where race.Name == cbBoxRace.Text
                                    select race.Id;

                    foreach (int id in raceQuery)
                    {
                        raceID = id;
                    }

                    var query = from subrace in db.Subraces
                                where subrace.Id == id
                                select subrace;

                    foreach (Subrace sub in query)
                    {
                        sub.RaceId       = raceID;
                        sub.Name         = txtName.Text;
                        sub.Speed        = (int)txtSpeed.Value;
                        sub.Strength     = (int)txtStr.Value;
                        sub.Dexterity    = (int)txtDex.Value;
                        sub.Constitution = (int)txtCon.Value;
                        sub.Intelligence = (int)txtInt.Value;
                        sub.Wisdom       = (int)txtWis.Value;
                        sub.Charisma     = (int)txtCha.Value;
                    }
                    try
                    {
                        db.SubmitChanges();
                        this.Close();
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show($"Error: {exc}");
                    }
                }
                DialogResult = DialogResult.OK;
            }
        }