Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.");
- }
- }
- 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();
- }
- }
- }
- 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);
- }
- }
Add Comment
Please, Sign In to add comment