private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { GameArray ga = new GameArray(); var thisobject = listBox1.SelectedItem as GameArray; textBox1.Text = thisobject.Seed; nameBox.Text = thisobject.Name; }
//D public void DeleteFromDb(GameArray o) { using (Context context = new Context()) { var objecttoRemove = context.GameArrays.Find(o); context.GameArrays.Remove(objecttoRemove); context.SaveChanges(); } }
//TODO: //C public void AddToDB(GameArray o) { using (Context context = new Context()) { var objecttoAdd = o as GameArray; context.GameArrays.Add(o); context.SaveChanges(); } }
void Populate() { listBox1.ResetText(); GameArray ga = new GameArray(); using (Context conn = new Context()) { listBox1.DataSource = conn.GameArrays.ToList(); listBox1.DisplayMember = "Name"; } }
private void Delete_Click(object sender, System.EventArgs e) { GameArray ga = new GameArray(); var deleteme = listBox1.SelectedItem as GameArray; try { ga.DeleteFromDb(deleteme); } catch { MessageBox.Show("Error Removing"); } Populate(); }
private void saveButton_Click(object sender, EventArgs e) { try { SeedString = textBox1.Text; GameArray ga = new GameArray { Name = nameBox.Text.ToString(), Seed = SeedString }; ga.AddToDB(ga); } catch { MessageBox.Show("Error Saving"); } Populate(); }
//R //U public void UpdateDb(GameArray o) { using (Context context = new Context()) { } }