private void buttonSalvar_Click(object sender, EventArgs e) { if (!VerificarCampos()) { Helper.ShowErro("Preencha os campos para prosseguir!"); return; } funcionario.Nome = textBoxNome.Text; funcionario.Cpf = textBoxCpf.Text; funcionario.Email = textBoxEmail.Text; RetornoOperacao retorno; if (funcionario.Codfuncionario == 0) { retorno = funcionarioController.Save(funcionario); } else { retorno = funcionarioController.Edit(funcionario); } if (retorno.Sucesso) { Helper.ShowSucesso(retorno.Menssagem); Sucesso = true; Close(); } else { Helper.ShowErro(retorno.Menssagem); } }
private void Button_Click(object sender, RoutedEventArgs e) { String cpf = TreatCpf(edtCpf.Text); String nome = edtNome.Text; String sobrenome = edtSobrenome.Text; String email = edtEmail.Text; String senha = edtPassword.Text; Boolean ativo = chkAtivo.IsChecked.Value; Boolean admin = chkAdmin.IsChecked.Value; try { if (cpf.Equals("")) { throw new Exception("Por favor preencha o campo CPF."); } if (!long.TryParse(cpf, out Int64 n) || cpf.Length != 11) { throw new Exception("CPF inválido"); } if (nome.Equals("")) { throw new Exception("Por favor preencha o campo Nome."); } this.funcionario.Cpf = cpf; this.funcionario.Nome = nome; this.funcionario.Sobrenome = sobrenome; this.funcionario.Email = email; if (senha != "") { this.funcionario.Senha = senha; } this.funcionario.Ativo = ativo; this.funcionario.Administrador = admin; controller.Edit(this.funcionario); MessageBox.Show("Funcionário atualizado com sucesso!"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }