示例#1
0
        private void BtnAddArmy_Click(object sender, EventArgs e)
        {
            Army army = new Army()
            {
                ArmyName = txtAddArmy.Text
            };

            ArmyDb.Add(army);
            MessageBox.Show($"{army.ArmyName} added");
            UpdateComboBox();
        }
示例#2
0
        private void btnDeleteArmy_Click(object sender, EventArgs e)
        {
            Army selectedArmy = ArmyDb.GetArmy((string)cbArmies.SelectedItem);

            using (ConfirmDialog dialog = new ConfirmDialog())
            {
                dialog.ShowDialog();

                if (dialog.DialogResult == DialogResult.Yes)
                {
                    ArmyDb.Delete(selectedArmy);
                    UpdateComboBox();
                }
            }
        }
示例#3
0
        private void UpdateComboBox()
        {
            cbArmies.Items.Clear();

            List <Army> allArmies = ArmyDb.GetAllArmies();

            if (allArmies.Count > 0)
            {
                cbArmies.Enabled = true;

                for (int i = 0; i < allArmies.Count; i++)
                {
                    cbArmies.Items.Add(allArmies[i].ArmyName);
                }
            }
            else
            {
                cbArmies.Enabled = false;
            }
        }