public void Inserir(Contato contato) { DbConnection conexao = DAOUtils.GetConexao(); DbCommand comando = DAOUtils.GetComando(conexao); comando.CommandType = CommandType.Text; comando.CommandText = "INSERT INTO CONTATOS(NOME,EMAIL,TELEFONE) VALUES (@nome, @email, @telefone)"; comando.Parameters.Add(DAOUtils.GetParametro("@nome", contato.Nome)); comando.Parameters.Add(DAOUtils.GetParametro("@email", contato.Email)); comando.Parameters.Add(DAOUtils.GetParametro("@telefone", contato.Telefone)); comando.ExecuteNonQuery(); //insert não retorna nada }
public void Atualizar(Contato contato) { DbConnection conexao = DAOUtils.GetConexao(); DbCommand comando = DAOUtils.GetComando(conexao); comando.CommandType = CommandType.Text; comando.CommandText = "UPDATE CONTATOS SET NOME = @nome,EMAIL = @email ,TELEFONE = @telefone WHERE ID = @id "; comando.Parameters.Add(DAOUtils.GetParametro("@nome", contato.Nome)); comando.Parameters.Add(DAOUtils.GetParametro("@email", contato.Email)); comando.Parameters.Add(DAOUtils.GetParametro("@telefone", contato.Telefone)); comando.Parameters.Add(DAOUtils.GetParametro("@id", contato.Id)); comando.ExecuteNonQuery(); }
private void btnAlterar_Click(object sender, EventArgs e) { Contato contatoEditar = new Contato { Id = (int)dgvAgenda.CurrentRow.Cells[0].Value, Nome = dgvAgenda.CurrentRow.Cells[1].Value.ToString(), Email = dgvAgenda.CurrentRow.Cells[2].Value.ToString(), Telefone = (int)dgvAgenda.CurrentRow.Cells[3].Value }; frmIncluirAlterarContato form = new frmIncluirAlterarContato(contatoEditar); form.ShowDialog(); CarregarDataGridView(); }
private void btnSalvar_Click(object sender, EventArgs e) { ContatoDAO contatoDao = new ContatoDAO(); if(this.contato == null) { //registro novo Contato contato = new Contato { Nome = txbNome.Text, Email = txbEmail.Text, Telefone = Convert.ToInt32(txbTelefone.Text) }; contatoDao.Inserir(contato); } else { //atualizar registro this.contato.Nome = txbNome.Text; this.contato.Email = txbEmail.Text; this.contato.Telefone = Convert.ToInt32(txbTelefone.Text); contatoDao.Atualizar(this.contato); } this.Close(); }
public frmIncluirAlterarContato(Contato contato = null) { this.contato = contato; InitializeComponent(); }