public Cliente retornaCliente() { string codFilmeSelecionado = escolhaClienteDataGridView.CurrentRow.Cells[0].Value.ToString(); ClienteCrud clienteCrud = new ClienteCrud(); return(clienteCrud.ObterCliente(Convert.ToInt32(codFilmeSelecionado))); }
protected void gridDados_RowCommand(object sender, GridViewCommandEventArgs e) { var cliente = new ClienteCrud(); var objeCliente = new ClienteModel(); var id = Convert.ToInt32(e.CommandArgument); hdn.Value = id.ToString(); switch (e.CommandName) { case "Excluir": cliente.Delete(id); gridDados.DataBind(); break; case "Editar": CarregarModal(id); ModalUpdate.Show(); break; default: break; } }
private void deleteToolStripButton_Click(object sender, EventArgs e) { try { int linhaSelecionada = Convert.ToInt32(clientesDataGridView1.CurrentRow.Cells[0].Value.ToString()); ClienteCrud crud = new ClienteCrud(); if (MessageBox.Show("Confirma a exclusão do cliente?", "Atenção!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if ((crud.Delete(linhaSelecionada))) { MessageBox.Show("Cliente deletado!"); CarregaGrid(); } else { MessageBox.Show("Ocorreu um erro!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void addClientBtn_Click(object sender, EventArgs e) { if (!CheckCamposPreenchidos()) { MessageBox.Show("Há campos obrigatórios não preenchidos!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { Cliente novoCliente = new Cliente { Nome = addClientName.Text, Email = addClientEmail.Text, Telefone = AddTelmkTxt.Text }; //impedindo inserção de CPF repetido LocadoraContext db = new LocadoraContext(); try { if (!ValidaCpf.IsCpf(addCpfTxtmsk.Text)) { MessageBox.Show("CPF inválido!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string testeCpf = (from cliente in db.Clientes where cliente.Cpf == addCpfTxtmsk.Text select cliente.Cpf).SingleOrDefault(); if (testeCpf != null) { MessageBox.Show("CPF já cadastrado no sistema!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { novoCliente.Cpf = addCpfTxtmsk.Text; } ///////////////////////////////////// } ClienteCrud clCrud = new ClienteCrud(); if (clCrud.Insert(novoCliente)) { MessageBox.Show("Cliente inserido com sucesso!"); this.Hide(); } else { MessageBox.Show("Ocorreu um erro! Tente novamente"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void CarregarModal(int id) { var user = new ClienteCrud(); var objUser = user.PesquisarPorId(id); txtNomeModal.Text = objUser.Nome; txtEmailModal.Text = objUser.Email; txtDataNascModal.Text = objUser.DataNascimento.ToString(); }
public void FormCadastro_InsertItem() { var db = new ClienteCrud(); var item = new ClienteModel(); TryUpdateModel(item); if (ModelState.IsValid) { db.InsertOrUpdate(item); gridDados.DataBind(); } }
private void editClientBtn_Click(object sender, EventArgs e) { ClienteCrud crud = new ClienteCrud(); Cliente novoCliente = new Cliente(); try { //impedindo inserção de CPF repetido LocadoraContext db = new LocadoraContext(); if (!ValidaCpf.IsCpf(editCpfTxtmsk.Text)) { MessageBox.Show("CPF inválido!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { string testeCpf = (from cliente in db.Clientes where cliente.Cpf == editCpfTxtmsk.Text select cliente.Cpf).SingleOrDefault(); if (testeCpf != null && testeCpf != cliente.Cpf) { MessageBox.Show("CPF já cadastrado no sistema!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { novoCliente.Cpf = editCpfTxtmsk.Text; } } novoCliente.Email = editClientEmail.Text; novoCliente.Nome = editClientName.Text; novoCliente.Telefone = editTelmkTxt.Text; if (crud.Atualizar(cliente, novoCliente)) { MessageBox.Show("Cliente atualizado!", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); } else { MessageBox.Show("Ocorreu um erro!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void btnSalvar_Click(object sender, EventArgs e) { var cliente = new ClienteCrud(); var objCliente = new ClienteModel(); objCliente.Id = Convert.ToInt32(hdn.Value); objCliente.Nome = txtNomeModal.Text; objCliente.Email = txtEmailModal.Text; objCliente.DataNascimento = Convert.ToDateTime(txtDataNascModal.Text); cliente.InsertOrUpdate(objCliente); gridDados.DataBind(); }
public EditCliente(int codCliente) { InitializeComponent(); try { ClienteCrud crud = new ClienteCrud(); cliente = crud.ObterCliente(codCliente); editClientName.Text = cliente.Nome; editCpfTxtmsk.Text = cliente.Cpf; editClientEmail.Text = cliente.Email; editTelmkTxt.Text = cliente.Telefone; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btn_CrudCliente_Click(object sender, EventArgs e) { ClienteCrud clienteCrud = new ClienteCrud(); clienteCrud.Show(); }
public IQueryable <ClienteModel> CarregarGrid() { var db = new ClienteCrud(); return(db.CarregarDados()); }