private void setData(Pessoa.Model.Pessoa p) { pessoa = p; pessoaWithoutModify = p; nomeTb.Text = p.nome; cpfTb.Text = p.cpf; dataNascimentoTb.Text = p.dataNascimento.ToString(); cepTb.Text = p.endereco != null ? p.endereco.cep : ""; numeroTb.Text = p.endereco != null?p.endereco.numero.ToString() : ""; if (p.GetType().Name.Contains(typeof(Pessoa.Model.Aluno).Name)) { tipoCb.SelectedItem = "Aluno"; Pessoa.Model.Aluno aluno = (Model.Aluno)alunoDao.getById(p.id); matriculaTb.Text = aluno.matricula; } else if (p.GetType().Name.Contains(typeof(Pessoa.Model.Usuario).Name)) { tipoCb.SelectedItem = "Usuário"; Model.Usuario usuario = (Model.Usuario)usuarioDao.getById(p.id); loginTb.Text = usuario.login; senhaTb.Text = usuario.senha; } else { tipoCb.SelectedItem = "Autor"; Model.Autor autor = (Model.Autor)autorDao.getById(p.id); siteTb.Text = autor.site; } handleFields(); }
private string getTipoPessoa(Pessoa.Model.Pessoa p) { if (p.GetType().Name.Contains(typeof(Pessoa.Model.Usuario).Name)) { return("Usuário"); } else if (p.GetType().Name.Contains(typeof(Pessoa.Model.Aluno).Name)) { return("Aluno"); } else { return("Autor"); } }
private void handleFields() { string tipo = tipoCb.SelectedItem.ToString(); switch (tipo.ToLower()) { case "usuário": matriculaTb.Enabled = false; siteTb.Enabled = false; loginTb.Enabled = true; senhaTb.Enabled = true; loginLb.Text += " *"; senhaLb.Text += " *"; matriculaLb.Text = matriculaLb.Text.Replace(" *", ""); //O patch abaixo foi feito para o caso de edição e criação //de qualquer tipo de pessoa no mesmo formulario //Se nao for nulo if (pessoa != null) { //Se o tipo for diferente de usuario if (pessoa.GetType() != typeof(Model.Usuario)) { //Troca para usuario, criando uma nova instancia pessoa = new Model.Usuario(); } } else { //Caso seja nulo instancia um novo usuario pessoa = new Model.Usuario(); } break; case "aluno": siteTb.Enabled = false; loginTb.Enabled = false; senhaTb.Enabled = false; matriculaTb.Enabled = true; if (pessoa != null) { if (pessoa.GetType() != typeof(Model.Aluno)) { pessoa = new Model.Aluno(); } } else { pessoa = new Model.Aluno(); } loginLb.Text = loginLb.Text.Replace(" *", ""); senhaLb.Text = senhaLb.Text.Replace(" *", "");; matriculaLb.Text += " *"; break; case "autor": siteTb.Enabled = true; loginTb.Enabled = false; senhaTb.Enabled = false; matriculaTb.Enabled = false; if (pessoa != null) { if (pessoa.GetType() != typeof(Model.Autor)) { pessoa = new Model.Autor(); } } else { pessoa = new Model.Autor(); } loginLb.Text = loginLb.Text.Replace(" *", ""); senhaLb.Text = senhaLb.Text.Replace(" *", ""); matriculaLb.Text = matriculaLb.Text.Replace(" *", ""); break; default: siteTb.Enabled = false; loginTb.Enabled = false; senhaTb.Enabled = false; matriculaTb.Enabled = false; pessoa = null; break; } }