private void btnExcluir_Click(object sender, EventArgs e) { if (dgvListar.SelectedRows.Count < 0) { MessageBox.Show("Por favor, selecione uma linha"); } else { if (MessageBox.Show("Tem certeza que deseja excluir?", "Excluir", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Time timeSeleciondo = new Time(); timeSeleciondo = dgvListar.SelectedRows[0].DataBoundItem as Time; TimeNegocios tc = new TimeNegocios(); string idTime = timeSeleciondo.IdTime; string retorno = tc.excluir(idTime); try { Convert.ToInt32(retorno); MessageBox.Show("Time excluído"); } catch (Exception ex) { MessageBox.Show("" + ex); } pesquisarTimes(); } } }
private void btnCadastrar_Click(object sender, EventArgs e) { TimeNegocios tn = new TimeNegocios(); string resultado = null;; string mensagem = null; Time t = new Time(); t.IdTime = txtID.Text; t.nome = txtNome.Text; t.professorResponsavel = txtProfessorResponsavel.Text; try { if (escolhaSelecao == Escolha.Alterar) { t.IdTime = txtID.Text; resultado = tn.alterar(t); mensagem = "Time atualizado: "; } if (escolhaSelecao == Escolha.Cadastrar) { resultado = tn.inserir(t); mensagem = "Time cadastrado!"; } Convert.ToInt32(resultado); MessageBox.Show(mensagem + " ID: " + resultado); this.Hide(); } catch (Exception ex) { throw; } }
public void pesquisarTimes() { TimeNegocios tn = new TimeNegocios(); TimeColecao tc = tn.pesquisarTodos(); dgvListar.DataSource = null; dgvListar.DataSource = tc; dgvListar.Refresh(); dgvListar.Update(); }