Boa tarde, sou novo nessa área. Tenho de criar os botões Incluir, Alterar e Excluir de um sistema de vendas. Estou usando o tableAdapter e já consegui fazer o botão Incluir dá seguinte forma:
private void btnInserir_Click(object sender, EventArgs e)
{
btnInserir.Enabled = false;
btnAlterar.Enabled = false;
btnExcluir.Enabled = false;
btnGravar.Enabled = true;
btnCancelar.Enabled = true;
txtNome.Enabled = true;
txtCPF.Enabled = true;
txtEndereco.Enabled = true;
txtTelefone.Enabled = true;
pessoasTableAdapter taPessoa = new pessoasTableAdapter();
string novoID;
int valorCodigo;
novoID = taPessoa.UltimoID().ToString();
if (int.TryParse(novoID.ToString(), out valorCodigo)) {
txtCodigo.Text = (valorCodigo + 1).ToString();
}
else
{
MessageBox.Show("Código com valor inválido. Tente novamente.");
}
}
Sendo que é necessário a confirmação com o botão Gravar, que fiz da seguinte forma:
private void btnGravar_Click(object sender, EventArgs e)
{
pessoasTableAdapter taPessoa = new pessoasTableAdapter();
taPessoa.Insert(txtCodigo.Text, txtNome.Text, txtTelefone.Text, txtEndereco.Text, txtCPF.Text, txtFiado.Text);
Limpar_Caixas();
string novoID;
int valorCodigo;
novoID = taPessoa.UltimoID().ToString();
if (int.TryParse(novoID.ToString(), out valorCodigo))
{
txtCodigo.Text = (valorCodigo + 1).ToString();
}
else
{
MessageBox.Show("Código com valor inválido. Tente novamente.");
}
}
private void Limpar_Caixas()
{
foreach(Control ctr in this.Controls)
{
if(ctr is TextBox)
{
(ctr as TextBox).Clear();
}
}
}
Agora estou tendo problemas com o botão excluir:
private void btnExcluir_Click(object sender, EventArgs e)
{
pessoasTableAdapter taPessoa = new pessoasTableAdapter();
DataTable dtPessoa;
dtPessoa = taPessoa.PesquisaPessoa(txtCodigo.Text);
if (dtPessoa.Rows.Count == 0)
{
MessageBox.Show("Pessoa não cadastrada.");
}
else
{
txtCodigo.Text = dtPessoa.Rows[0]["idPessoa"].ToString();
txtNome.Text = dtPessoa.Rows[0]["nomePessoa"].ToString();
txtEndereco.Text = dtPessoa.Rows[0]["enderecoPessoa"].ToString();
txtCPF.Text = dtPessoa.Rows[0]["cpfPessoa"].ToString();
txtTelefone.Text = dtPessoa.Rows[0]["telefonePessoa"].ToString();
txtFiado.Text = dtPessoa.Rows[0]["fiado"].ToString();
}
if (MessageBox.Show("Confirma exclusão?", "Excluindo...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
taPessoa.Delete(txtCodigo.Text, txtNome.Text, txtEndereco.Text, txtTelefone.Text, txtCPF.Text, txtFiado.Text);
}
}
Ao inserir o código da pessoa, aparece todas as informações e uma janela para confirmar a exclusão. Ao clicar em sim, nada acontece. O que fazer?