private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { WPFdataGrid.DataGridControl wPFdataGrid = elementHost1.Child as WPFdataGrid.DataGridControl; var dataGridView = wPFdataGrid.grid; string recordDeleteConformationMessage = $@"This Record will be Deleted, [ PName: ""{pokemon.PName}"", Type 1: ""{pokemon.Type1}"", Type 2: ""{pokemon.Type2}"" ] "; DialogResult result = System.Windows.Forms.MessageBox.Show(recordDeleteConformationMessage, "Confirmation, Do You Still Want to Delete?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { try { using (Pokemon db = new Pokemon()) { var pokemonToDelete = from p in db.PokemonBaseStats where p.PName == pokemon.PName select p; var pokemonCapRateToDelete = from p in db.PokemonCapRates where p.PName == pokemon.PName select p; foreach (var monster in pokemonToDelete) { db.PokemonBaseStats.Remove(monster); } foreach (var monster in pokemonCapRateToDelete) { db.PokemonCapRates.Remove(monster); } db.SaveChanges(); } //delete the record from the Book table refreshToolStripMenuItem.PerformClick(); dataGridView.SelectedIndex = -1; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show($" Data: {ex.Data} \n Source: {ex.Source} \n " + $"Message: {ex.Message} \n Inner Error: {ex.InnerException} \n Target Site: {ex.TargetSite} \n Stack Trace: {ex.StackTrace} \n " + $"Result Code: {ex.HResult} \n {ex.HelpLink}"); } } }
private void addToolStripMenuItem_Click(object sender, EventArgs e) { if (EventArgs.Cancel != true) { try { using (var context = new Pokemon()) { //create Book object PokemonBaseStat pokemonToAdd = new PokemonBaseStat(); //assign its properties pokemonToAdd.PName = pokemon.PName; pokemonToAdd.HP = pokemon.HP; pokemonToAdd.Attack = pokemon.Attack; pokemonToAdd.Defense = pokemon.Defense; pokemonToAdd.SPAttack = pokemon.SPAttack; pokemonToAdd.SPDefense = pokemon.SPDefense; pokemonToAdd.Speed = pokemon.Speed; pokemonToAdd.Type1 = pokemon.Type1; pokemonToAdd.Type2 = pokemon.Type2; pokemonToAdd.PokemonCapRate = pokemon.PokemonCapRate; //add the Book to the object set Books context.PokemonBaseStats.Add(pokemonToAdd); //save change to the database context.SaveChanges(); } refreshToolStripMenuItem.PerformClick(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show($" Data: {ex.Data} \n Source: {ex.Source} \n " + $"Message: {ex.Message} \n Inner Error: {ex.InnerException} \n Target Site: {ex.TargetSite} \n Stack Trace: {ex.StackTrace} \n " + $"Result Code: {ex.HResult} \n {ex.HelpLink}"); } } }
private void updateToolStripMenuItem_Click(object sender, EventArgs e) { WPFdataGrid.DataGridControl wPFdataGrid = elementHost1.Child as WPFdataGrid.DataGridControl; var dataGridView = wPFdataGrid.grid; Pokemon = new Pokemon(); if (EventArgs.Cancel != true) { //pokemon entity var pokemonToUpdate = from p in Pokemon.PokemonBaseStats where p.PName == pokemon.PName select p; foreach (var monster in pokemonToUpdate) { monster.HP = pokemon.HP; monster.Attack = pokemon.Attack; monster.Defense = pokemon.Defense; monster.SPAttack = pokemon.SPAttack; monster.SPDefense = monster.SPDefense; monster.Speed = pokemon.Speed; if (pokemon.Type1 != "") { monster.Type1 = pokemon.Type1; } else if (pokemon.Type1 == "") { monster.Type1 = null; } if (pokemon.Type2 != "") { monster.Type2 = pokemon.Type2; } else if (pokemon.Type2 == "") { monster.Type2 = null; } monster.PokemonCapRate.CapRate = pokemon.PokemonCapRate.CapRate; monster.PokemonCapRate.ExpDrop = pokemon.PokemonCapRate.ExpDrop; } try { dataGridView.CommitEdit(); //pokemon entity save changes Pokemon.SaveChanges(); if (pokemonCapRates.Count > 0) { pokemonCapRates.RemoveAll(p => p.PName == pokemonCapRate.PName); } refreshToolStripMenuItem.PerformClick(); dataGridView.SelectedIndex = -1; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show($" Data: {ex.Data} \n Source: {ex.Source} \n " + $"Message: {ex.Message} \n Inner Error: {ex.InnerException} \n Target Site: {ex.TargetSite} \n Stack Trace: {ex.StackTrace} \n " + $"Result Code: {ex.HResult} \n {ex.HelpLink}"); } } else { System.Windows.Forms.MessageBox.Show(EventArgs.Error, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }