private void Button1_Click(object sender, EventArgs e) { try { validar.Campo(txtProduto.Text); string termo = cbTermo.Text; if (termo.Equals("Id")) { dtvProd.DataSource = operacao.pegaProdutoId(int.Parse(txtProduto.Text)); MessageBox.Show(operacao.getMensagem); } else { if (termo.Equals("Marca")) { dtvProd.DataSource = operacao.pegaProdutoMarca(txtProduto.Text); MessageBox.Show(operacao.getMensagem); } else { dtvProd.DataSource = operacao.pegaProdutoNome(txtProduto.Text); MessageBox.Show(operacao.getMensagem); } } } catch (ArgumentException) { MessageBox.Show("Preencha o campo", "Entrada invalida", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException) { MessageBox.Show("Insira um numero Inteiro", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private DataTable tabelaFinal(string termo) { if (termo.Equals("Id")) { return(operacao.pegaProdutoId(int.Parse(txtProduto.Text))); } else { if (termo.Equals("Marca")) { return(operacao.pegaProdutoMarca(txtProduto.Text)); } else { return(operacao.pegaProdutoNome(txtProduto.Text)); } } }