public void btnPesquisar_Click(object sender, EventArgs e) { try { grdPesquisar.Rows.Clear(); ClienteAction clienteAction = new ClienteAction(); var lista = clienteAction.Lista(txtPesquisarNome.Text); if (lista.Count > 0) { for (int i = 0; i < lista.Count; i++) { grdPesquisar.Rows.Add(); grdPesquisar.Rows[i].Cells["selecionar"].Value = "Exibir"; grdPesquisar.Rows[i].Cells["idCliente"].Value = lista[i].IdCliente.ToString(); grdPesquisar.Rows[i].Cells["nome"].Value = lista[i].Nome.ToString(); } } } catch (Exception ex) { throw new Exception("Houve um erro ao tentar realizar uma operação [" + MethodBase.GetCurrentMethod().ToString() + "]: " + ex.Message); } }
private void btnSalvar_Click(object sender, EventArgs e) { try { if (ValidaCampos() == false) { return; } ClienteAction clienteAction = new ClienteAction(); Cliente cliente = new Cliente(); cliente.IdCliente = Convert.ToInt32(_idCliente); cliente.Nome = txtNome.Text; cliente.Cnh = txtCnh.Text; cliente.Cpf = txtCPF.Text.Replace(".", "").Replace("-", ""); var retorno = clienteAction.Salvar(cliente); if (retorno) { MessageBox.Show("Cliente Cadastrado com Sucesso!", "Cliente", MessageBoxButtons.OK, MessageBoxIcon.Information); btnNovo_Click(null, null); btnPesquisar_Click(null, null); } else { MessageBox.Show("Houve um erro ao Salvar!", "Cliente", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { throw new Exception("Houve um erro ao tentar realizar uma operação [" + MethodBase.GetCurrentMethod().ToString() + "]: " + ex.Message); } }
private void ExibirCliente(int idCliente) { try { ClienteAction clienteAciton = new ClienteAction(); var cliente = clienteAciton.Detalhe(Convert.ToInt32(idCliente)); _idCliente = cliente.IdCliente; txtNome.Text = cliente.Nome; txtCPF.Text = cliente.Cpf; txtCnh.Text = cliente.Cnh; tabControl1.SelectedTab = tabCadastro; } catch (Exception ex) { throw new Exception("Houve um erro ao tentar realizar uma operação [" + MethodBase.GetCurrentMethod().ToString() + "]: " + ex.Message); } }
private void btnExcluir_Click(object sender, EventArgs e) { try { ClienteAction clienteAction = new ClienteAction(); var retorno = clienteAction.Excluir(_idCliente); if (retorno) { MessageBox.Show("Cliente Excluído com Sucesso!", "Cliente", MessageBoxButtons.OK, MessageBoxIcon.Information); btnNovo_Click(null, null); btnPesquisar_Click(null, null); } else { MessageBox.Show("Houve um erro ao excluir Cliente!", "Cliente", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { throw new Exception("Houve um erro ao tentar realizar uma operação [" + MethodBase.GetCurrentMethod().ToString() + "]: " + ex.Message); } }