コード例 #1
0
 void PreencheAtributosAve(Ave a)
 {
     txtVenenoso.Text    = a.Venenoso ? "Sim" : "Não";
     txtAlimentacao.Text = a.Alimentacao.ToString();
     txtRapina.Text      = a.Rapina ? "Possui" : "Não Possui";
     foreach (Button item in gridAves.Children)
     {
         item.IsEnabled = true;
     }
 }
コード例 #2
0
        private void btnCadastraAve_Click(object sender, RoutedEventArgs e)
        {
            DateTime data;

            try
            {
                data = Convert.ToDateTime(dtNascimento.Text);
            }
            catch
            {
                MessageBox.Show("Formato incorreto para data");
                return;
            }
            try
            {
                Ave animal = null;
                if (!btnCisne.IsEnabled)
                {
                    animal = new CisneNegro(txtNome.Text, data, cbSexo.SelectedItem.ToString(), (CoresAve)cbColoracaoAve.SelectedItem);
                }
                else if (!btnKiwi.IsEnabled)
                {
                    animal = new Kiwi(txtNome.Text, data, cbSexo.SelectedItem.ToString(), (CoresAve)cbColoracaoAve.SelectedItem);
                }
                else if (!btnAquila.IsEnabled)
                {
                    animal = new AquilaAudax(txtNome.Text, data, cbSexo.SelectedItem.ToString(), (CoresAve)cbColoracaoAve.SelectedItem);
                }
                else
                {
                    MessageBox.Show("Selecione uma espécie para cadastrar");
                    return;
                }
                arvore.Insere(animal);
                File.AppendAllText("Animais.txt", $"{animal.Especie}|{animal.Nome}|{animal.Nascimento}|{animal.Sexo}|{animal.Coloracao}\n");


                MessageBox.Show("Cadastro efetuado com sucesso!");
                LimpaCampos();
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
            }
        }