Example #1
0
        ///CADASTRAR
        public static bool Cadastrar(EDITORA pEDITORA)
        {
            using (BibliotecaVirtualEntities oDB = new BibliotecaVirtualEntities())
            {

                //String de Seleção do usuário
                var ConsultaEDITORA = (from CA in oDB.EDITORA
                                     where CA.NOME == pEDITORA.NOME
                                     select CA).SingleOrDefault();

                //Se a consulta retorna NULA ele cadastra o usuário
                if (ConsultaEDITORA == null)
                {
                    try
                    {
                        oDB.EDITORA.Add(pEDITORA);
                        oDB.SaveChanges();
                        oDB.Dispose();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
 public void Alterar(EDITORA oEditora, bool attach = true)
 {
     if (attach)
     {
         odb.Entry(oEditora).State = System.Data.Entity.EntityState.Modified;
     }
     odb.SaveChanges();
 }
Example #3
0
 public bool Cadastrar(EDITORA oEDITORA)
 {
     if (EditoraMetod.Cadastrar(oEDITORA))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #4
0
 public bool Alterar(EDITORA oEDITORA)
 {
     if (EditoraMetod.Alterar(oEDITORA))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #5
0
 public bool Cadastrar(EDITORA oEDITORA)
 {
     if (EditoraMetod.Cadastrar(oEDITORA))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #6
0
 public bool Alterar(EDITORA oEDITORA)
 {
     if (EditoraMetod.Alterar(oEDITORA))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #7
0
        ///ALTERAR
        public static bool Alterar(EDITORA pEDITORA)
        {
            var oDB = new BibliotecaVirtualEntities();

            //String de Seleção do usuário
            var ConsultaEDITORA = (from CA in oDB.EDITORA
                                 where CA.NOME == pEDITORA.NOME
                                 select CA).SingleOrDefault();

            //Se a consulta não retorna NULA ele atualiza o usuário
            if (ConsultaEDITORA != null)
            {
                try
                {
                    ConsultaEDITORA.NOME = pEDITORA.NOME;
                    ConsultaEDITORA.BAIRRO = pEDITORA.BAIRRO;
                    ConsultaEDITORA.CEP = pEDITORA.CEP;
                    ConsultaEDITORA.CIDADE = pEDITORA.CIDADE;
                    ConsultaEDITORA.EMAIL = pEDITORA.EMAIL;
                    ConsultaEDITORA.ENDERECO = pEDITORA.ENDERECO;
                    ConsultaEDITORA.TEL_1 = pEDITORA.TEL_1;
                    ConsultaEDITORA.TEL_2 = pEDITORA.TEL_2;
                    ConsultaEDITORA.PAIS = pEDITORA.PAIS;
                    ConsultaEDITORA.UF = pEDITORA.UF;

                    oDB.SaveChanges();
                    oDB.Dispose();
                }
                catch (Exception)
                {
                    throw;
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Example #8
0
        public ActionResult CriarLivro(vw_LIVRO oLivro, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                List <EDITORA> Editoras     = _repositoryE.ListarEditoras();
                List <AUTOR>   Autores      = _repositoryA.ListarAutores();
                List <GENERO>  Generos      = _repositoryG.ListarGeneros();
                LIVRO          LivroGravar  = new LIVRO();
                GENERO         GeneroAtual  = new GENERO();
                EDITORA        EditoraAtual = new EDITORA();
                AUTOR          AutorAtual   = new AUTOR();

                #region UploadArquivo
                int ups = Request.Files.Count;
                if (ups > 0)
                {
                    upload = Request.Files[0];
                    if (upload.ContentLength > 0)
                    {
                        string path = Server.MapPath("~/Uploads/");
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        LivroGravar.ImagemCaminho = "~/Uploads/" + upload.FileName;
                        upload.SaveAs(path + Path.GetFileName(upload.FileName));
                    }
                }
                #endregion


                LivroGravar.ISBN           = oLivro.ISBN;
                LivroGravar.Sinopse        = oLivro.Sinopse;
                LivroGravar.Titulo         = oLivro.Titulo;
                LivroGravar.DataPublicacao = oLivro.DataPublicacao;
                #region GENERO
                GeneroAtual = Generos.Where(x => x.NomeGenero.ToLower() == oLivro.NomeGenero.ToLower()).Select(x => x).FirstOrDefault();
                if (GeneroAtual != null)
                {
                    LivroGravar.IDGenero = GeneroAtual.ID;
                }
                else
                {
                    GENERO novogenero = new GENERO()
                    {
                        NomeGenero = oLivro.NomeGenero
                    };
                    _repositoryG.Incluir(novogenero);
                    GeneroAtual          = novogenero;
                    LivroGravar.IDGenero = novogenero.ID;
                }

                #endregion
                #region Autor
                AutorAtual = Autores.Where(x => x.NomeAutor.ToLower() == oLivro.NomeAutor.ToLower()).Select(x => x).FirstOrDefault();
                if (AutorAtual != null)
                {
                    LivroGravar.IDAutor = AutorAtual.ID;
                }
                else
                {
                    AUTOR novoautor = new AUTOR()
                    {
                        NomeAutor = oLivro.NomeAutor
                    };
                    _repositoryA.Incluir(novoautor);
                    AutorAtual          = novoautor;
                    LivroGravar.IDAutor = novoautor.ID;
                }

                #endregion
                #region Editora
                EditoraAtual = Editoras.Where(x => x.Editora.ToLower() == oLivro.Editora.ToLower()).Select(x => x).FirstOrDefault();
                if (EditoraAtual != null)
                {
                    LivroGravar.IDEditora = EditoraAtual.ID;
                }
                else
                {
                    EDITORA novaeditora = new EDITORA()
                    {
                        Editora = oLivro.Editora
                    };
                    _repositoryE.Incluir(novaeditora);
                    EditoraAtual          = novaeditora;
                    LivroGravar.IDEditora = novaeditora.ID;
                }

                #endregion

                _repository.Incluir(LivroGravar);

                return(RedirectToAction("Estante"));
            }

            return(View(oLivro));
        }
Example #9
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (VerificaControles())
            {
                LIVRO oLivro = new LIVRO();

                oLivro.TITULO        = txtTitulo.Text;
                oLivro.VOLUME        = Convert.ToInt32(txtVolume.Text);
                oLivro.DATA_PUBLIC   = dtp_Publicacao.Value;
                oLivro.QTD_EXMPLARES = Convert.ToInt32(txtQuantidade.Text);
                oLivro.SUMARIO       = txtSumario.Text;
                oLivro.QTD_DISP_EMPR = Convert.ToInt32(txtQuantidade.Text);
                oLivro.ID_EDITORA    = cmbEditora.SelectedIndex;


                CAutor.CAutorClient oProxy = new CAutor.CAutorClient();
                oProxy.Open();

                AUTOR xAutor  = oProxy.SelecionarNome(cmbAutor1.Text);
                AUTOR xAutor2 = oProxy.SelecionarNome(cmbAutor2.Text);

                oLivro.AUTOR.Add(xAutor);
                oLivro.AUTOR.Add(xAutor2);

                oProxy.Close();



                CEditora.CEditoraClient oProxy2 = new CEditora.CEditoraClient();
                oProxy2.Open();

                EDITORA xEditora = oProxy2.SelecionarNome(cmbEditora.Text);
                oLivro.EDITORA = xEditora;

                oProxy2.Close();



                CGenero.CGeneroClient oProxy3 = new CGenero.CGeneroClient();
                oProxy3.Open();

                GENERO xGenero = oProxy3.SelecionarDescricao(cmbGenero1.Text);
                oLivro.GENERO.Add(xGenero);

                oProxy3.Close();



                //oLivro.QTD_DISP_EMPR = ??????????
                //oLivro.ID_EDITORA = cmbEditora.SelectedIndex;
                //oLivro.GENERO =
                //oLivro.Emprestimo = ???????????
                //oLivro.RESERVA = ???????


                CLivro.CLivroClient oProxy4 = new CLivro.CLivroClient();
                oProxy4.Open();

                if (var == 0)
                {
                    try
                    {
                        if (oProxy4.Cadastrar(oLivro))
                        {
                            MessageBox.Show("Cadastro realizado com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();
                        }
                        else
                        {
                            if (MessageBox.Show("Livro existente! Deseja carregar os dados do livro?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                string var = oLivro.TITULO;

                                btnSalvar.Enabled = false;

                                btnDeletar.Enabled = true;

                                btnAlterar.Enabled = true;



                                LIVRO xLivro = oProxy4.SelecionarTitulo(var);

                                int var2 = xLivro.ID_LIVRO;

                                txtTitulo.Text = xLivro.TITULO;
                                //???????? = oLivro.QTD_DISP_EMPR;
                                txtQuantidade.Text   = xLivro.QTD_EXMPLARES.ToString();
                                txtSumario.Text      = xLivro.SUMARIO;
                                dtp_Publicacao.Value = xLivro.DATA_PUBLIC;
                                cmbEditora.Text      = xLivro.EDITORA.NOME;
                                cmbAutor1.Text       = xLivro.AUTOR.ElementAt(0).NOME;
                                cmbAutor2.Text       = xLivro.AUTOR.ElementAt(1).NOME;
                                cmbGenero1.Text      = xLivro.GENERO.ElementAt(0).DESCRICAO;
                                //???????? = .GENERO;
                                //???????? = oLivro.Emprestimo;
                                //???????? = oLivro.RESERVA;
                                txtID.Text = Convert.ToString(var2);


                                DesabilitaCampos();
                            }
                            else
                            {
                                LimpaCampos();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    try
                    {
                        if (oProxy4.Alterar(oLivro))
                        {
                            MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();

                            btnAlterar.Enabled = false;

                            HabilitaCampos();

                            var = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Preencha todos os campos!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        ///BOTÃO SALVAR
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (VerificaControles())
            {
                EDITORA oEditora = new EDITORA();

                oEditora.NOME = txtNome.Text;
                oEditora.BAIRRO = txtBairro.Text;
                oEditora.CEP = txtCEP.Text;
                oEditora.CIDADE = txtCidade.Text;
                oEditora.EMAIL = txtEmail.Text;
                oEditora.ENDERECO = txtEnd.Text;
                oEditora.TEL_1 = txtTel1.Text;
                oEditora.TEL_2 = txtTel2.Text;
                oEditora.PAIS = cmbPais.SelectedItem.ToString();
                oEditora.UF = cmbUF.SelectedItem.ToString();

                CEditora.CEditoraClient oProxy = new CEditora.CEditoraClient();
                oProxy.Open();

                if (var == 0)
                {
                    try
                    {
                        if (oProxy.Cadastrar(oEditora))
                        {
                            MessageBox.Show("Cadastro realizado com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();
                        }
                        else
                        {
                            if (MessageBox.Show("Editora existente! Deseja carregar os dados da Editora?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {

                                btnSalvar.Enabled = false;

                                btnDeletar.Enabled = true;

                                btnAlterar.Enabled = true;

                                EDITORA xEditora= oProxy.SelecionarNome(oEditora.NOME);

                                txtNome.Text = xEditora.NOME;
                                txtBairro.Text = xEditora.BAIRRO;
                                txtCEP.Text = xEditora.CEP;
                                txtCidade.Text = xEditora.CIDADE;
                                txtEmail.Text = xEditora.EMAIL;
                                txtEnd.Text = xEditora.ENDERECO;
                                txtTel1.Text = xEditora.TEL_1;
                                txtTel2.Text = xEditora.TEL_2;
                                cmbPais.SelectedItem = xEditora.PAIS;
                                cmbUF.SelectedItem = xEditora.UF;
                                txtID.Text = Convert.ToString(xEditora.ID_EDITORA);

                                DesabilitaCampos();

                            }
                            else
                            {
                                LimpaCampos();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                else
                {
                    try
                    {
                        if (oProxy.Alterar(oEditora))
                        {
                            MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();

                            btnAlterar.Enabled = false;

                            HabilitaCampos();

                            var = 0;

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

            }
            else
            {
                MessageBox.Show("Preencha todos os campos!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #11
0
        ///BOTÃO SALVAR


        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (VerificaControles())
            {
                EDITORA oEditora = new EDITORA();

                oEditora.NOME     = txtNome.Text;
                oEditora.BAIRRO   = txtBairro.Text;
                oEditora.CEP      = txtCEP.Text;
                oEditora.CIDADE   = txtCidade.Text;
                oEditora.EMAIL    = txtEmail.Text;
                oEditora.ENDERECO = txtEnd.Text;
                oEditora.TEL_1    = txtTel1.Text;
                oEditora.TEL_2    = txtTel2.Text;
                oEditora.PAIS     = cmbPais.SelectedItem.ToString();
                oEditora.UF       = cmbUF.SelectedItem.ToString();


                CEditora.CEditoraClient oProxy = new CEditora.CEditoraClient();
                oProxy.Open();


                if (var == 0)
                {
                    try
                    {
                        if (oProxy.Cadastrar(oEditora))
                        {
                            MessageBox.Show("Cadastro realizado com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();
                        }
                        else
                        {
                            if (MessageBox.Show("Editora existente! Deseja carregar os dados da Editora?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                btnSalvar.Enabled = false;

                                btnDeletar.Enabled = true;

                                btnAlterar.Enabled = true;

                                EDITORA xEditora = oProxy.SelecionarNome(oEditora.NOME);

                                txtNome.Text         = xEditora.NOME;
                                txtBairro.Text       = xEditora.BAIRRO;
                                txtCEP.Text          = xEditora.CEP;
                                txtCidade.Text       = xEditora.CIDADE;
                                txtEmail.Text        = xEditora.EMAIL;
                                txtEnd.Text          = xEditora.ENDERECO;
                                txtTel1.Text         = xEditora.TEL_1;
                                txtTel2.Text         = xEditora.TEL_2;
                                cmbPais.SelectedItem = xEditora.PAIS;
                                cmbUF.SelectedItem   = xEditora.UF;
                                txtID.Text           = Convert.ToString(xEditora.ID_EDITORA);


                                DesabilitaCampos();
                            }
                            else
                            {
                                LimpaCampos();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                else
                {
                    try
                    {
                        if (oProxy.Alterar(oEditora))
                        {
                            MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();

                            btnAlterar.Enabled = false;

                            HabilitaCampos();

                            var = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Preencha todos os campos!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #12
0
        ///PROCURAR

        private void btnProcurar_Click(object sender, EventArgs e)
        {
            if (cmbPesquisa.SelectedIndex == 0)
            {
                int var = Convert.ToInt32(txtPesquisa.Text);
                CEditora.CEditoraClient oProxy = new CEditora.CEditoraClient();
                oProxy.Open();

                if (oProxy.Selecionar(var) != null)
                {
                    EDITORA oEditora = oProxy.Selecionar(var);

                    txtNome.Text         = oEditora.NOME;
                    txtBairro.Text       = oEditora.BAIRRO;
                    txtCEP.Text          = oEditora.CEP;
                    txtCidade.Text       = oEditora.CIDADE;
                    txtEmail.Text        = oEditora.EMAIL;
                    txtEnd.Text          = oEditora.ENDERECO;
                    txtTel1.Text         = oEditora.TEL_1;
                    txtTel2.Text         = oEditora.TEL_2;
                    cmbPais.SelectedItem = oEditora.PAIS;
                    cmbUF.SelectedItem   = oEditora.UF;
                    txtID.Text           = Convert.ToString(oEditora.ID_EDITORA);

                    DesabilitaCampos();

                    btnAlterar.Enabled = true;

                    btnDeletar.Enabled = true;

                    btnSalvar.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Editora não encontrada!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                CEditora.CEditoraClient oProxy = new CEditora.CEditoraClient();
                oProxy.Open();

                if (oProxy.SelecionarNome(txtPesquisa.Text) != null)
                {
                    EDITORA oEditora = oProxy.SelecionarNome(txtPesquisa.Text);

                    txtNome.Text         = oEditora.NOME;
                    txtBairro.Text       = oEditora.BAIRRO;
                    txtCEP.Text          = oEditora.CEP;
                    txtCidade.Text       = oEditora.CIDADE;
                    txtEmail.Text        = oEditora.EMAIL;
                    txtEnd.Text          = oEditora.ENDERECO;
                    txtTel1.Text         = oEditora.TEL_1;
                    txtTel2.Text         = oEditora.TEL_2;
                    cmbPais.SelectedItem = oEditora.PAIS;
                    cmbUF.SelectedItem   = oEditora.UF;
                    txtID.Text           = Convert.ToString(oEditora.ID_EDITORA);

                    DesabilitaCampos();

                    btnAlterar.Enabled = true;

                    btnDeletar.Enabled = true;

                    btnSalvar.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Editora não encontrada!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 public void Excluir(EDITORA oEditora)
 {
     odb.EDITORA.Attach(oEditora);
     odb.EDITORA.Remove(oEditora);
     odb.SaveChanges();
 }
 public void Incluir(EDITORA oEditora)
 {
     odb.EDITORA.Add(oEditora);
     odb.SaveChanges();
 }