private void salvarBtn_Click(object sender, EventArgs e) { if (validateForm()) { if (opt == App.CrudOpt.CADASTRAR) { categoria = new Model.Categoria(); categoria.nome = nomeTb.Text; categoriaDao.add(categoria); } else { categoria.nome = nomeTb.Text; categoriaDao.update(categoria); } categoriaDao.saveChanges(); if (Owner != null) { CategoriaFrame cf = (CategoriaFrame)Owner; cf.clean(); } MessageBox.Show("Salvo com sucesso !"); this.Close(); } }
public List <Livro> getLivroByNomeOrIsbnOrCategoria(string nomeIsbn, Categoria.Model.Categoria cat) { try{ if (cat != null) { if (nomeIsbn.Equals("")) { return(this.ctx.livros.Include("Categoria").Include("Editora").Include("Autor") .Where(l => l.categoria.id == cat.id).ToList()); } else { return(this.ctx.livros.Include("Categoria").Include("Editora").Include("Autor") .Where(l => (l.nome.Contains(nomeIsbn) || l.isbn.Contains(nomeIsbn)) && l.categoria.id == cat.id).ToList()); } } else { return(this.ctx.livros.Include("Categoria").Include("Editora").Include("Autor") .Where(l => (l.nome.Contains(nomeIsbn) || l.isbn.Contains(nomeIsbn))).ToList()); } }catch { return(null); } }
private void enviarBtn_Click(object sender, EventArgs e) { if (validateForm()) { Editora.Model.Editora editora = null; Categoria.Model.Categoria categoria = null; Pessoa.Model.Autor autor = (Pessoa.Model.Autor)autorCb.SelectedItem; if (categoriaCb.SelectedItem != null) { categoria = (Categoria.Model.Categoria)categoriaCb.SelectedItem; } if (editoraCb.SelectedItem != null) { editora = (Editora.Model.Editora)editoraCb.SelectedItem; } if (opt == App.CrudOpt.CADASTRAR) { livro = new Model.Livro(); livro.nome = nomeTb.Text; livro.isbn = isbnTb.Text; livro.edicao = edicaoTb.Text; livro.autor = autor; livro.editora = editora; livro.categoria = categoria; livro.quantidade = (int)quantidadeNm.Value; livroDao.add(livro); } else { livro.nome = nomeTb.Text; livro.isbn = isbnTb.Text; livro.edicao = edicaoTb.Text; livro.autor = autor; livro.editora = editora; livro.categoria = categoria; livro.quantidade = (int)quantidadeNm.Value; livroDao.update(livro); } livroDao.saveChanges(); if (Owner != null) { LivroFrame lf = (LivroFrame)Owner; lf.clean(); } MessageBox.Show("Salvo com sucesso !"); this.Close(); } }
private void buscarBtn_Click(object sender, EventArgs e) { string livroTxt = livroTb.Text; Categoria.Model.Categoria cat = (Categoria.Model.Categoria)categoriaCb.SelectedItem; List <Model.Livro> livros = livroDao.getLivroByNomeOrIsbnOrCategoria(livroTxt, cat); if (livros.Count > 0) { this.populateGrid(livros); } else { MessageBox.Show("Livro não encontrado !"); } }
private void setData(Categoria.Model.Categoria c) { this.categoria = c; nomeTb.Text = c.nome; }