Beispiel #1
0
        ///ALTERAR
        public static bool Alterar(GENERO pGENERO)
        {
            var oDB = new BibliotecaVirtualEntities();

            //String de Seleção do usuário
            var ConsultaGENERO = (from CA in oDB.GENERO
                                   where CA.DESCRICAO == pGENERO.DESCRICAO
                                   select CA).SingleOrDefault();

            //Se a consulta não retorna NULA ele atualiza o usuário
            if (ConsultaGENERO != null)
            {
                try
                {
                    ConsultaGENERO.DESCRICAO = pGENERO.DESCRICAO;
                    ConsultaGENERO.ANDAR = pGENERO.ANDAR;
                    ConsultaGENERO.CORREDOR = pGENERO.CORREDOR;
                    ConsultaGENERO.PRETELEIRA = pGENERO.PRETELEIRA;

                    oDB.SaveChanges();
                    oDB.Dispose();
                }
                catch (Exception)
                {
                    throw;
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #2
0
        ///CADASTRAR
        public static bool Cadastrar(GENERO pGENERO)
        {
            using (BibliotecaVirtualEntities oDB = new BibliotecaVirtualEntities())
            {

                //String de Seleção do usuário
                var ConsultaGENERO = (from CA in oDB.GENERO
                                       where CA.DESCRICAO == pGENERO.DESCRICAO
                                       select CA).SingleOrDefault();

                //Se a consulta retorna NULA ele cadastra o usuário
                if (ConsultaGENERO == null)
                {
                    try
                    {
                        oDB.GENERO.Add(pGENERO);
                        oDB.SaveChanges();
                        oDB.Dispose();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
Beispiel #3
0
        ///ALTERAR


        public static bool Alterar(GENERO pGENERO)
        {
            var oDB = new BibliotecaVirtualEntities();

            //String de Seleção do usuário
            var ConsultaGENERO = (from CA in oDB.GENERO
                                  where CA.DESCRICAO == pGENERO.DESCRICAO
                                  select CA).SingleOrDefault();

            //Se a consulta não retorna NULA ele atualiza o usuário
            if (ConsultaGENERO != null)
            {
                try
                {
                    ConsultaGENERO.DESCRICAO  = pGENERO.DESCRICAO;
                    ConsultaGENERO.ANDAR      = pGENERO.ANDAR;
                    ConsultaGENERO.CORREDOR   = pGENERO.CORREDOR;
                    ConsultaGENERO.PRETELEIRA = pGENERO.PRETELEIRA;


                    oDB.SaveChanges();
                    oDB.Dispose();
                }
                catch (Exception)
                {
                    throw;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        ///CADASTRAR

        public static bool Cadastrar(GENERO pGENERO)
        {
            using (BibliotecaVirtualEntities oDB = new BibliotecaVirtualEntities())
            {
                //String de Seleção do usuário
                var ConsultaGENERO = (from CA in oDB.GENERO
                                      where CA.DESCRICAO == pGENERO.DESCRICAO
                                      select CA).SingleOrDefault();

                //Se a consulta retorna NULA ele cadastra o usuário
                if (ConsultaGENERO == null)
                {
                    try
                    {
                        oDB.GENERO.Add(pGENERO);
                        oDB.SaveChanges();
                        oDB.Dispose();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #5
0
 public bool Cadastrar(GENERO oGENERO)
 {
     if (GeneroMetod.Cadastrar(oGENERO))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #6
0
 public bool Alterar(GENERO oGENERO)
 {
     if (GeneroMetod.Alterar(oGENERO))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #7
0
        ///DELETAR


        public static bool Deletar(int IDGENERO)
        {
            var oDB = new BibliotecaVirtualEntities();

            GENERO oGENERO = (from Seleciona in oDB.GENERO where Seleciona.ID_GENERO == IDGENERO select Seleciona).SingleOrDefault();

            oDB.GENERO.Remove(oGENERO);
            oDB.SaveChanges();
            oDB.Dispose();

            return(true);
        }
        private void btnProcurarLivro_Click(object sender, EventArgs e)
        {
            if (cmbPesquisaLivro.SelectedIndex == 0)
            {
                int var2 = Convert.ToInt32(txtProcurarLivro.Text);

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

                if (oProxy2.SelecionarID(var2) != null)
                {
                    LIVRO oLivro = oProxy2.SelecionarID(var2);

                    txtIDLivro.Text = Convert.ToString(oLivro.ID_LIVRO);
                    txtTitulo.Text = oLivro.TITULO;
                    txtVolume.Text = Convert.ToString(oLivro.VOLUME);

                    AUTOR oAutor1 = new AUTOR();

                    oAutor1 = oLivro.AUTOR.First();

                    txtAutor1.Text = oAutor1.NOME;

                    /*
                    try
                    {
                        AUTOR oAutor2 = new AUTOR();

                        oAutor2 = oLivro.AUTOR.ElementAtOrDefault<AUTOR>(1);

                        txtAutor1.Text = oAutor2.NOME;
                    }
                    catch
                    {

                    }*/

                    dtp_Publicacao.Value = oLivro.DATA_PUBLIC;

                    /*GENERO oGenero = new GENERO();

                    oGenero = oLivro.GENERO.ElementAtOrDefault<GENERO>(0);

                    txtGenero.Text = oGenero.DESCRICAO;*/

                    try
                    {
                        txtEditora.Text = oLivro.EDITORA.NOME;

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

                }
                else
                {
                    MessageBox.Show("Livro não encontrado!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
            else if (cmbPesquisa.SelectedIndex == 1)
            {
                CLivro.CLivroClient oProxy2 = new CLivro.CLivroClient();
                oProxy2.Open();

                if (oProxy2.SelecionarTitulo(txtProcurarLivro.Text) != null)
                {
                    LIVRO oLivro = oProxy2.SelecionarTitulo(txtProcurarLivro.Text);

                    txtIDLivro.Text = Convert.ToString(oLivro.ID_LIVRO);
                    txtTitulo.Text = oLivro.TITULO;
                    txtVolume.Text = Convert.ToString(oLivro.VOLUME);

                    AUTOR oAutor1 = new AUTOR();

                    oAutor1 = oLivro.AUTOR.ElementAtOrDefault<AUTOR>(0);

                    txtAutor1.Text = oAutor1.NOME;

                    /*
                    try
                    {
                        AUTOR oAutor2 = new AUTOR();

                        oAutor2 = oLivro.AUTOR.ElementAtOrDefault<AUTOR>(1);

                        txtAutor1.Text = oAutor2.NOME;
                    }
                    catch
                    {

                    }*/

                    dtp_Publicacao.Value = oLivro.DATA_PUBLIC;

                    GENERO oGenero = new GENERO();

                    oGenero = oLivro.GENERO.ElementAtOrDefault<GENERO>(0);

                    txtGenero.Text = oGenero.DESCRICAO;

                    txtEditora.Text = oLivro.EDITORA.NOME;
                }
                else
                {
                    MessageBox.Show("Livro não encontrado!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        ///BOTÃO SALVAR
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (VerificaControles())
            {
                GENERO oGenero = new GENERO();

                oGenero.DESCRICAO = txtDescricao.Text;
                oGenero.PRETELEIRA= cmbPrateleira.SelectedItem.ToString();
                oGenero.CORREDOR = cmbCorredor.SelectedItem.ToString();
                oGenero.ANDAR= cmbAndar.SelectedItem.ToString();

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

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

                                btnSalvar.Enabled = false;

                                btnDeletar.Enabled = true;

                                btnAlterar.Enabled = true;

                                GENERO xGenero = oProxy.SelecionarDescricao(oGenero.DESCRICAO);

                                txtID.Text = Convert.ToString(xGenero.ID_GENERO);
                                txtDescricao.Text = xGenero.DESCRICAO;
                                cmbAndar.SelectedItem = xGenero.ANDAR;
                                cmbCorredor.SelectedItem = xGenero.CORREDOR;
                                cmbPrateleira.SelectedItem = xGenero.PRETELEIRA;

                                DesabilitaCampos();

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

                else
                {
                    try
                    {
                        if (oProxy.Alterar(oGenero))
                        {
                            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);
            }
        }