private void BtnAdd_Click(object sender, EventArgs e) { // Add Lootbox into database LootboxClass lb = new LootboxClass() { Theme = txtTheme.Text, Name = txtName.Text, Contents = txtContents.Text, Description = txtDescription.Text, Price = Convert.ToDouble(txtPrice.Text) }; try { if (existingLootbox != null) { lb.LootboxID = existingLootbox.LootboxID; LootboxDB.Update(lb); MessageBox.Show("Lootbox Updated!"); } else { LootboxDB.Add(lb); MessageBox.Show("Lootbox added!"); } Close(); } catch (SqlException) { MessageBox.Show("Error, Try Again."); } }
private void BtnDeleteBox_Click(object sender, EventArgs e) { //List<LootboxClass> boxs = LootboxDB.GetAllLootboxes(); LootboxClass box = lstLootBox.SelectedItem as LootboxClass; LootboxDB.Delete(box); PopulateForm(); }
private void Populate_lstLootBox() { List <LootboxClass> boxes = LootboxDB.GetAllLootboxes(); boxes = boxes.OrderBy(box => box.Name).ToList(); lstLootBox.DataSource = boxes; lstLootBox.DisplayMember = nameof(LootboxClass.Name); }
private void PopulateLootboxListbox() { List <LootboxClass> lootboxes = LootboxDB.GetAllLootboxes(); lootboxes = lootboxes.OrderBy(lb => lb.Name).ToList(); foreach (LootboxClass ltbx in lootboxes) { lstLootBox.Items.Add(ltbx).ToString(); } }