示例#1
0
 void PreencheAtributosMamisfero(Mamifero m)
 {
     txtVenenoso.Text              = m.Venenoso ? "Sim" : "Não";
     txtAlimentacao.Text           = m.Alimentacao.ToString();
     txtMarsupial.Text             = m.Marsupial ? "Sim" : "Não";
     txtPelo.Text                  = m.Pelo ? "Possui" : "Não Possui";
     txtQtdeMamas.Text             = m.qtdeMamas.ToString();
     cbCoresPeloPele.SelectedIndex = 0;
     foreach (Button item in gridMamiferos.Children)
     {
         item.IsEnabled = true;
     }
 }
示例#2
0
        private void btnCadastraMamifero_Click(object sender, RoutedEventArgs e)
        {
            DateTime data;

            try
            {
                data = Convert.ToDateTime(dtNascimento.Text);
            }
            catch
            {
                MessageBox.Show("Formato incorreto para data");
                return;
            }
            try
            {
                Mamifero animal = null;
                if (!btnCoala.IsEnabled)
                {
                    animal = new Coala(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }
                else if (!btnCanguru.IsEnabled)
                {
                    animal = new CanguruVermelho(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }
                else if (!btnMorcego.IsEnabled)
                {
                    animal = new MorcegoGigante(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }
                else if (!btnOrnitorrinco.IsEnabled)
                {
                    animal = new Ornintorrinco(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }
                else if (!btnDingo.IsEnabled)
                {
                    animal = new Dingo(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }
                else if (!btnTasmania.IsEnabled)
                {
                    animal = new DemonioDaTasmania(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }
                else if (!btnElefante.IsEnabled)
                {
                    animal = new ElefanteMarinho(txtNome.Text, data, cbSexo.SelectedItem.ToString(), cbCoresPeloPele.SelectedItem.ToString());
                }

                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.CorPeleo}\n");

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