public int AtualizaDados(PessoaEntidade entidade) { int resultado = -1; using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "UPDATE TB_PESSOA SET NOME=@nome, BAIRRO=@bairro, ENTIDADE=@entidade, CPF=@cpf, RG=@rg, EMAIL=@email WHERE ID_PESSOA = @id"; cmd.Prepare(); cmd.Parameters.AddWithValue("@Id", entidade.IdPessoa); cmd.Parameters.AddWithValue("@nome", entidade.Nome); cmd.Parameters.AddWithValue("@bairro", entidade.Bairro); cmd.Parameters.AddWithValue("@entidade", entidade.Entidade); cmd.Parameters.AddWithValue("@cpf", entidade.Cpf); cmd.Parameters.AddWithValue("@rg", entidade.Rg); cmd.Parameters.AddWithValue("@email", entidade.Email); try { resultado = cmd.ExecuteNonQuery(); } catch (SQLiteException ex) { throw ex; } finally { conn.Close(); } } } return(resultado); }
public void Inserir(PessoaEntidade Pessoa) { using (NpgsqlConnection conexao = new NpgsqlConnection(this.connectionString)) { conexao.Open(); NpgsqlCommand comando = new NpgsqlCommand(); comando.CommandText = "INSERT INTO pessoas (id, cpf_cnpj, nome, apto, id_condominio, senha, email, telefone, celular, permissao, status) " + " VALUES(@id, @cpf_cnpj, @nome, @apto, @id_condominio, @senha, @email, @telefone, @celular, @permissao, @status)"; comando.Connection = conexao; comando.Parameters.AddWithValue("id", Pessoa.id); comando.Parameters.AddWithValue("cpf_cnpj", Pessoa.cpf_cnpj); comando.Parameters.AddWithValue("nome", Pessoa.nome); comando.Parameters.AddWithValue("apto", Pessoa.apto); comando.Parameters.AddWithValue("id_condominio", Pessoa.id_condominio); comando.Parameters.AddWithValue("senha", Pessoa.senha); comando.Parameters.AddWithValue("email", Pessoa.email); comando.Parameters.AddWithValue("telefone", Pessoa.telefone); comando.Parameters.AddWithValue("celular", Pessoa.celular); comando.Parameters.AddWithValue("permissao", Pessoa.permissao); comando.Parameters.AddWithValue("status", Pessoa.status); comando.ExecuteNonQuery(); } }
public void Alterar(PessoaEntidade Pessoa) { using (NpgsqlConnection conexao = new NpgsqlConnection(this.connectionString)) { conexao.Open(); NpgsqlCommand comando = new NpgsqlCommand(); comando.CommandText = "UPDATE pessoas " + "SET cpf_cnpj = @cpf_cnpj," + "nome = @nome," + "apto = @apto," + "id_condominio = @id_condominio," + "senha = @senha," + "email = @email," + "telefone = @telefone," + "celular = @celular, " + "permissao = @permissao," + "status = @status " + "WHERE id = @id;"; comando.Connection = conexao; comando.Parameters.AddWithValue("id", Pessoa.id.ToString()); comando.Parameters.AddWithValue("cpf_cnpj", Pessoa.cpf_cnpj); comando.Parameters.AddWithValue("nome", Pessoa.nome); comando.Parameters.AddWithValue("apto", Pessoa.apto); comando.Parameters.AddWithValue("id_condominio", Pessoa.id_condominio.ToString()); comando.Parameters.AddWithValue("senha", Pessoa.senha); comando.Parameters.AddWithValue("email", Pessoa.email); comando.Parameters.AddWithValue("telefone", Pessoa.telefone); comando.Parameters.AddWithValue("celular", Pessoa.celular); comando.Parameters.AddWithValue("permissao", Pessoa.permissao); comando.Parameters.AddWithValue("status", Pessoa.status); comando.ExecuteNonQuery(); } }
public int DeletaDados(PessoaEntidade entidade) { int resultado = -1; using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "DELETE FROM TB_PESSOA WHERE ID_PESSOA = @Id; " + "DELETE FROM TB_PESSOA_LISTA_PRESENCA WHERE ID_PESSOA = @Id"; cmd.Prepare(); cmd.Parameters.AddWithValue("@Id", entidade.IdPessoa); try { resultado = cmd.ExecuteNonQuery(); } catch (SQLiteException ex) { throw ex; } finally { conn.Close(); } } } return(resultado); }
public void AlteraPessoa() { PessoaEntidade pessoa = new PessoaEntidade() { id = Guid.Parse("7edafe64-f996-4ba9-8f8c-2eb1367a6ca6"), cpf_cnpj = "1234567910", nome = "Pessoa Teste - Altera", apto = "1150B", id_condominio = Guid.Parse("7edafe64-f996-4ba9-8f8c-2eb1367a6ca6"), senha = "123456 - Altera", email = "*****@*****.**", telefone = "1130303030", celular = "11998765432", permissao = 0, status = 0 }; try { PessoaRepositorio pessoaRepositorio = new PessoaRepositorio(str); pessoaRepositorio.Alterar(pessoa); Assert.IsTrue(true); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public FormPessoa(PessoaEntidade entidade, int?idListaPresenca) { InitializeComponent(); _entidade = entidade; _idListaPresenca = idListaPresenca; this.CenterToScreen(); }
public PessoaEntidade Procurar(Guid id) { using (NpgsqlConnection conexao = new NpgsqlConnection(this.connectionString)) { conexao.Open(); NpgsqlCommand comando = new NpgsqlCommand(); comando.CommandText = "SELECT * FROM pessoas " + "WHERE id = @id;"; comando.Connection = conexao; comando.Parameters.AddWithValue("id", id.ToString()); PessoaEntidade Pessoa = new PessoaEntidade(); using (NpgsqlDataReader SqlData = comando.ExecuteReader()) { if (SqlData.Read()) { Pessoa.id = Guid.Parse(String.Format("{0}", SqlData["id"])); Pessoa.cpf_cnpj = String.Format("{0}", SqlData["cpf_cnpj"]); Pessoa.nome = String.Format("{0}", SqlData["nome"]); Pessoa.apto = String.Format("{0}", SqlData["apto"]); Pessoa.id_condominio = Guid.Parse(String.Format("{0}", SqlData["id_condominio"])); Pessoa.senha = String.Format("{0}", SqlData["senha"]); Pessoa.email = String.Format("{0}", SqlData["email"]); Pessoa.telefone = String.Format("{0}", SqlData["telefone"]); Pessoa.celular = String.Format("{0}", SqlData["celular"]); Pessoa.permissao = (int)SqlData["permissao"]; Pessoa.status = (int)SqlData["status"]; } } return(Pessoa); } }
public PessoaEntidade Procura(Guid id) { PessoaEntidade pessoa = this.pessoaRepossitorio.Procurar(id); pessoa.telefone = "(" + pessoa.telefone.Substring(0, 3) + ") " + pessoa.telefone.Substring(3, 4) + "-" + pessoa.telefone.Substring(7, 4); pessoa.celular = "(" + pessoa.celular.Substring(0, 3) + ") " + pessoa.celular.Substring(3, 5) + "-" + pessoa.celular.Substring(8, 4); pessoa.cpf_cnpj = pessoa.cpf_cnpj.Substring(0, 3) + '.' + pessoa.cpf_cnpj.Substring(3, 3) + '.' + pessoa.cpf_cnpj.Substring(6, 3) + '-' + pessoa.cpf_cnpj.Substring(9, 2); return(pessoa); }
private void btnSalvar_Click(object sender, EventArgs e) { if (ValidaDados()) { try { var entidade = new PessoaEntidade { IdPessoa = int.Parse(txtId.Text), Nome = txtNome.Text, Bairro = txtBairro.Text, Entidade = txtEntidade.Text, Cpf = maskedTextBox1.Text, Rg = txtRG.Text, Email = txtEmail.Text, }; if (operacao == "incluir") { if (IncluirDados(entidade) > 0) { MessageBox.Show("Dados incluídos com sucesso."); Close(); } else { MessageBox.Show("Os dados não foram incluídos."); } } else { if (AtualizaDados(entidade) > 0) { MessageBox.Show("Dados atualizados com sucesso."); Close(); } else { MessageBox.Show("Os dados não foram atualizados."); Close(); } } } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); Close(); } } else { MessageBox.Show("Preencha o formulário corretamente"); } }
public ActionResult EditarApto(Guid id, string apto) { string str = ConfigurationManager.ConnectionStrings["conexao"].ToString(); PessoaRepositorio pessoaRepositorio = new PessoaRepositorio(str); PessoaAplicacao pessoaAplicacao = new PessoaAplicacao(pessoaRepositorio); PessoaEntidade pessoa = pessoaAplicacao.Procura(id); pessoa.apto = apto; pessoaAplicacao.Altera(pessoa); Index(); return(View("Index")); }
private void btnIncluir_Click(object sender, EventArgs e) { try { PessoaEntidade _entidade = null; var formEvento = new FormPessoa(_entidade, null); formEvento.ShowDialog(); CarregaDados(); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } }
public void Procurar() { Guid Id = Guid.Parse("7edafe64-f996-4ba9-8f8c-2eb1367a6ca6"); try { PessoaRepositorio pessoaRepositorio = new PessoaRepositorio(str); PessoaEntidade pessoa = pessoaRepositorio.Procurar(Id); Assert.IsTrue(true); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void ProcurarPessoasApartirEmailSenha() { String email = "*****@*****.**"; String senha = "123456"; try { PessoaRepositorio pessoaRepositorio = new PessoaRepositorio(str); PessoaEntidade pessoa = pessoaRepositorio.ProcurarPessoasApartirEmailSenha(email, senha); Assert.IsTrue(true); } catch (Exception ex) { Assert.Fail(ex.Message); } }
private PessoaEntidade GetDadosDoGrid() { try { int linha; linha = dataGridView1.CurrentRow.Index; var entidade = new PessoaEntidade(); entidade.IdPessoa = Convert.ToInt32(dataGridView1[0, linha].Value); entidade.Nome = dataGridView1[1, linha].Value.ToString(); entidade.Bairro = dataGridView1[2, linha].Value.ToString(); entidade.Entidade = dataGridView1[3, linha].Value.ToString(); entidade.Cpf = dataGridView1[4, linha].Value.ToString(); entidade.Rg = dataGridView1[5, linha].Value.ToString(); entidade.Email = dataGridView1[6, linha].Value.ToString(); return(entidade); } catch (Exception ex) { throw ex; } }
public void Inserir(PessoaEntidade pessoa) { if (string.IsNullOrEmpty(pessoa.nome)) { throw new ApplicationException("Nome invalido"); } if (string.IsNullOrEmpty(pessoa.cpf_cnpj)) { throw new ApplicationException("CPF invalido"); } else { pessoa.cpf_cnpj = SemFormatacao(pessoa.cpf_cnpj); if (!ValidarCpf(pessoa.cpf_cnpj)) { throw new ApplicationException("CPF invalido"); } } if (string.IsNullOrEmpty(pessoa.apto)) { throw new ApplicationException("Apartamento invalido"); } if (string.IsNullOrEmpty(pessoa.email) || !pessoa.email.Contains("@") || !pessoa.email.Contains(".")) { throw new ApplicationException("Email invalido"); } if (string.IsNullOrEmpty(pessoa.id_condominio.ToString())) { throw new ApplicationException("Apartamento invalido"); } if (string.IsNullOrEmpty(pessoa.senha) || pessoa.senha.Length < 8) { throw new ApplicationException("Senha invalido"); } pessoa.telefone = SemFormatacao(pessoa.telefone); pessoa.celular = SemFormatacao(pessoa.celular); pessoa.status = 0; pessoa.permissao = 0; this.pessoaRepossitorio.Inserir(pessoa); }
public ActionResult Alterar(PessoaEntidade pessoa, string senha) { pessoa.id = (Guid)Session["usuario"]; pessoa.id_condominio = (Guid)Session["Condominio"]; string str = ConfigurationManager.ConnectionStrings["conexao"].ToString(); PessoaRepositorio pessoaRepositorio = new PessoaRepositorio(str); PessoaAplicacao pessoaAplicacao = new PessoaAplicacao(pessoaRepositorio); if (pessoaAplicacao.Login(pessoa.email, senha) != null) { if (pessoa.senha == null) { pessoa.senha = senha; } object Permisao = Session["Permission"]; pessoa.permissao = Permisao.ToString() == "ADM" ? 1:0; pessoa.status = 1; pessoaAplicacao.Altera(pessoa); } Index(); return(View("Index")); }
public int IncluirDados(PessoaEntidade entidade) { int resultado = -1; using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "INSERT INTO TB_PESSOA(NOME, BAIRRO, ENTIDADE, CPF, RG, EMAIL) VALUES (@nome,@bairro,@entidade,@cpf,@rg,@email)"; cmd.Prepare(); cmd.Parameters.AddWithValue("@nome", entidade.Nome); cmd.Parameters.AddWithValue("@bairro", entidade.Bairro); cmd.Parameters.AddWithValue("@entidade", entidade.Entidade); cmd.Parameters.AddWithValue("@cpf", entidade.Cpf); cmd.Parameters.AddWithValue("@rg", entidade.Rg); cmd.Parameters.AddWithValue("@email", entidade.Email); try { resultado = cmd.ExecuteNonQuery(); } catch (SQLiteException ex) { throw ex; } finally { conn.Close(); } } } if (_idListaPresenca != null) { IncluirPessoaLista(); } return(resultado); }
public PessoaEntidade ProcurarPessoasApartirEmailSenha(string email, string senha) { using (NpgsqlConnection conexao = new NpgsqlConnection(this.connectionString)) { conexao.Open(); NpgsqlCommand comando = new NpgsqlCommand(); comando.CommandText = "SELECT id, nome, id_condominio, permissao, status " + "FROM pessoas " + "WHERE status <> 3 " + "AND email = @email " + "AND senha = @senha;"; comando.Connection = conexao; comando.Parameters.AddWithValue("email", email); comando.Parameters.AddWithValue("senha", senha); PessoaEntidade pessoas = new PessoaEntidade(); using (NpgsqlDataReader SqlData = comando.ExecuteReader()) { if (SqlData.Read()) { pessoas.id = Guid.Parse(SqlData.GetString(0)); pessoas.nome = String.Format("{0}", SqlData["nome"]); pessoas.id_condominio = Guid.Parse(String.Format("{0}", SqlData["id_condominio"])); pessoas.permissao = (int)SqlData["permissao"]; pessoas.status = (int)SqlData["status"]; } else { return(null); } } return(pessoas); } }