private cadastro Save(cadastro dados) { try { connectionString = new MySqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); connectionString.Open(); MySqlCommand command = new MySqlCommand("INSERT INTO cadastro(RA,Nome,Email,DataNasc,Telefone,Curso,Semestre,CEP,Endereco,Cidade,Estado,Sexo,Interno) " + "VALUES('" + dados.RA + "','" + dados.Nome + "','" + dados.Email + "','" + dados.DataNasc.ToString("yyyy-MM-dd HH:mm:ss") + "','" + dados.Telefone + "','" + dados.Curso + "','" + dados.Semestre + "','" + dados.CEP + "','" + dados.Endereco + "','" + dados.Cidade + "','" + dados.Estado + "','" + dados.Sexo + "','" + dados.Interno + "');", connectionString); command.ExecuteNonQuery(); connectionString.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } return(dados); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,CPF,Endereco,Email,Telefone,Descricao")] cadastro cadastro) { if (id != cadastro.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cadastro); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!cadastroExists(cadastro.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cadastro)); }
private void button2_Click(object sender, EventArgs e) { /* Conexao inserir = new Conexao(); * inserir.Insert();*/ this.Hide(); cadastro abrir = new cadastro(); abrir.ShowDialog(); }
public async Task <IActionResult> Create([Bind("Id,Nome,CPF,Endereco,Email,Telefone,Descricao")] cadastro cadastro) { if (ModelState.IsValid) { _context.Add(cadastro); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cadastro)); }
public ActionResult Cadastro(cadastro dados) { try { cadastroBusiness.NovoCadastro(dados); } catch (Exception ex) { return(new HttpStatusCodeResult(404, ex.Message)); } return(Json(dados, JsonRequestBehavior.AllowGet)); }
private void editar(Cliente cliente) { cadastro clienteEditar = new cadastro(); if ( txtNome.Text.Trim() == string.Empty || txtCpf.Text.Trim() == string.Empty || txtRua.Text.Trim() == string.Empty || txtNumero.Text.Trim() == string.Empty || txtCidade.Text.Trim() == string.Empty || txtPedido.Text.Trim() == string.Empty || txtCodigo.Text.Trim() == string.Empty || txtQuantidade.Text.Trim() == string.Empty || txtValor.Text.Trim() == string.Empty || txtDescricao.Text.Trim() == string.Empty ) { MessageBox.Show("Edição inválida preencha todos os campos!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Error); txtNome.BackColor = Color.Red; txtCpf.BackColor = Color.Red; txtRua.BackColor = Color.Red; txtNumero.BackColor = Color.Red; txtCidade.BackColor = Color.Red; txtPedido.BackColor = Color.Red; txtCodigo.BackColor = Color.Red; txtQuantidade.BackColor = Color.Red; txtValor.BackColor = Color.Red; txtDescricao.BackColor = Color.Red; } else { cliente.id = Convert.ToInt32(txtId.Text); cliente.cpf = txtCpf.Text; cliente.nome = txtNome.Text; cliente.rua = txtRua.Text; cliente.numero = txtNumero.Text; cliente.cidade = txtCidade.Text; cliente.numeroDePedido = txtPedido.Text; cliente.codigo = txtCodigo.Text; cliente.quantidade = txtQuantidade.Text; cliente.valor = txtValor.Text; cliente.descricao = txtDescricao.Text; clienteEditar.editar(cliente); MessageBox.Show("Pedido modificado com SUCESSO!"); limparFormulario(); listar(); } }
private void salvar(Cliente cliente) { cadastro clienteCadastrar = new cadastro(); if ( txtNome.Text.Trim() == string.Empty || txtCpf.Text.Trim() == string.Empty || txtRua.Text.Trim() == string.Empty || txtNumero.Text.Trim() == string.Empty || txtCidade.Text.Trim() == string.Empty || txtPedido.Text.Trim() == string.Empty || txtCodigo.Text.Trim() == string.Empty || txtQuantidade.Text.Trim() == string.Empty || txtValor.Text.Trim() == string.Empty || txtDescricao.Text.Trim() == string.Empty ) { MessageBox.Show("Cadastro inválido preencha todos os campos!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Error); txtNome.BackColor = Color.Red; txtCpf.BackColor = Color.Red; txtRua.BackColor = Color.Red; txtNumero.BackColor = Color.Red; txtCidade.BackColor = Color.Red; txtPedido.BackColor = Color.Red; txtCodigo.BackColor = Color.Red; txtQuantidade.BackColor = Color.Red; txtValor.BackColor = Color.Red; txtDescricao.BackColor = Color.Red; } else { cliente.cpf = txtCpf.Text; cliente.nome = txtNome.Text; cliente.rua = txtRua.Text; cliente.numero = txtNumero.Text; cliente.cidade = txtCidade.Text; cliente.numeroDePedido = txtPedido.Text; cliente.codigo = txtCodigo.Text; cliente.quantidade = txtQuantidade.Text; cliente.valor = txtValor.Text; cliente.descricao = txtDescricao.Text; clienteCadastrar.salvar(cliente); MessageBox.Show("Pedido feito com sucesso!"); limparFormulario(); } }
private void excluir(Cliente cliente) { cadastro clienteExluir = new cadastro(); if (txtId.Text.Trim() == string.Empty) { MessageBox.Show("Selecione um cadastro da LISTA para excluir!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (MessageBox.Show("Deseja realmente excluir este cadastro?", "Alerta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { limparFormulario(); } else { cliente.id = Convert.ToInt32(txtId.Text); clienteExluir.excluir(cliente); limparFormulario(); listar(); MessageBox.Show("Cadastro excluido com sucesso!"); } }
public cadastro NovoCadastro(cadastro dados) { if (string.IsNullOrEmpty(dados.RA.ToString()) && dados.RA.ToString().Length >= 7) { throw new Exception("Favor preencher o RA!"); } if (string.IsNullOrEmpty(dados.Nome)) { throw new Exception("Favor informar o Nome!"); } if (string.IsNullOrEmpty(dados.Email)) { throw new Exception("Favor informar o Email!"); } if (string.IsNullOrEmpty(dados.Telefone)) { throw new Exception("Favor informar o Telefone!"); } if (string.IsNullOrEmpty(dados.CEP)) { throw new Exception("Favor informar o CEP!"); } if (string.IsNullOrEmpty(dados.Endereco)) { throw new Exception("Favor informar o Endereço!"); } if (string.IsNullOrEmpty(dados.Cidade)) { throw new Exception("Favor informar o Cidade!"); } if (string.IsNullOrEmpty(dados.Estado)) { throw new Exception("Favor informar o Estado!"); } if (string.IsNullOrEmpty(dados.Curso) && dados.Curso != "0") { throw new Exception("Favor informar o Curso!"); } if (string.IsNullOrEmpty(dados.Semestre) && dados.Semestre != "0") { throw new Exception("Favor informar o Semestre!"); } if (!dados.Sexo.Equals("F") && !dados.Sexo.Equals("M")) { throw new Exception("Favor informar o Sexo!"); } try { Save(dados); return(dados); } catch (Exception ex) { throw new Exception(ex.Message); } }