예제 #1
0
        public bool VerificarRenovacao(EmprestimoInformation emprestimo, bool modoAluno)
        {
            try
            {
                cn.Open();

                SqlCommand verificarRenovacao = new SqlCommand("EmprestimosAlunoMorto_VerificarRenovacao", cn);
                verificarRenovacao.CommandType = CommandType.StoredProcedure;

                verificarRenovacao.Parameters.AddWithValue("@tombo", emprestimo.Tombo);
                verificarRenovacao.Parameters.AddWithValue("@idAluno", emprestimo.IdAluno);
                verificarRenovacao.Parameters.AddWithValue("@modoAluno", modoAluno);
                verificarRenovacao.Parameters.AddWithValue("@idFunc", emprestimo.IdFuncionario);

                return(Convert.ToBoolean(verificarRenovacao.ExecuteScalar()));
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
예제 #2
0
        public void DesfazerRenovacao(EmprestimoInformation emprestimo, bool modoAluno)
        {
            try
            {
                cn.Open();

                SqlCommand desfazerRenovacao = new SqlCommand("EmprestimosAlunoMorto_DesfazerRenovacao", cn);
                desfazerRenovacao.CommandType = CommandType.StoredProcedure;

                desfazerRenovacao.Parameters.AddWithValue("@tombo", emprestimo.Tombo);
                desfazerRenovacao.Parameters.AddWithValue("@emprestimo", emprestimo.Retirada);
                desfazerRenovacao.Parameters.AddWithValue("@devolucao", emprestimo.Devolucao);
                desfazerRenovacao.Parameters.AddWithValue("@rm", emprestimo.Rm);
                if (emprestimo.NomeProfessor is null)
                {
                    desfazerRenovacao.Parameters.AddWithValue("@nomeFunc", "");
                }
                else
                {
                    desfazerRenovacao.Parameters.AddWithValue("@nomeFunc", emprestimo.NomeProfessor);
                }

                desfazerRenovacao.Parameters.AddWithValue("@ModoAluno", modoAluno);

                desfazerRenovacao.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
예제 #3
0
        public void RealizarEmprestimo(EmprestimoInformation emprestimo, bool aluno, bool ficha, ref string erro)
        {
            if ((Convert.ToDateTime(emprestimo.Devolucao) - Convert.ToDateTime(emprestimo.Retirada)).Days < 7)
            {
                erro = "Tempo Insuficiente!";
                throw new Exception("É preciso selecionar um dia igual ou superior a 7 dias!");
            }

            emprestimosDAL.RealizarEmprestimo(emprestimo, aluno, ficha, ref erro);
        }
예제 #4
0
        public void ExcluirEmprestimo(EmprestimoInformation emprestimo, bool aluno)
        {
            SqlTransaction t = null;

            try
            {
                cn.Open();

                SqlCommand realizarEmprestimo;

                t = cn.BeginTransaction(IsolationLevel.Serializable);

                realizarEmprestimo             = new SqlCommand("Emprestimos_DeletarEmprestimo", cn, t);
                realizarEmprestimo.CommandType = CommandType.StoredProcedure;

                realizarEmprestimo.Parameters.AddWithValue("@Tombo", emprestimo.Tombo);
                realizarEmprestimo.Parameters.AddWithValue("@retirada", emprestimo.Retirada);
                realizarEmprestimo.Parameters.AddWithValue("@devolucao", emprestimo.Devolucao);
                realizarEmprestimo.Parameters.AddWithValue("@aluno", aluno);

                if (aluno)
                {
                    realizarEmprestimo.Parameters.AddWithValue("@idLeitor", emprestimo.IdAluno);
                    realizarEmprestimo.Parameters.AddWithValue("@serie", emprestimo.Rm + " - " + emprestimo.Modulo + " - " + emprestimo.Curso);
                }
                else
                {
                    realizarEmprestimo.Parameters.AddWithValue("@idLeitor", emprestimo.IdFuncionario);
                    realizarEmprestimo.Parameters.AddWithValue("@serie", emprestimo.Funcao);
                }

                realizarEmprestimo.ExecuteNonQuery();

                t.Commit();
            }
            catch (SqlException ex)
            {
                t.Rollback();
                throw new Exception(ex.Message);
            }
            finally { cn.Close(); }
        }
예제 #5
0
        public void RealizarEmprestimo(EmprestimoInformation emprestimo, bool aluno, bool ficha, ref string erro)
        {
            SqlTransaction t = null;

            try
            {
                cn.Open();

                SqlCommand realizarEmprestimo;

                SqlCommand verificarDia = new SqlCommand("Emprestimo_DiaLeitorEspecial", cn);
                verificarDia.CommandType = CommandType.StoredProcedure;

                verificarDia.Parameters.AddWithValue("@devolucao", emprestimo.Devolucao);

                bool acesso = Convert.ToBoolean(verificarDia.ExecuteScalar());

                if (!acesso)
                {
                    erro = "Dia Não Letivo!";
                    throw new Exception("O dia escolhido não é um dia letivo!");
                }

                t = cn.BeginTransaction(IsolationLevel.Serializable);
                if (aluno)
                {
                    SqlCommand permitirEmprestimo = new SqlCommand(@"SELECT COUNT(*)
                                                                        FROM MULTAS
                                                                            WHERE ID_Aluno = " + emprestimo.IdAluno, cn, t);

                    int resultado = Convert.ToInt32(permitirEmprestimo.ExecuteScalar());

                    if (resultado > 0)
                    {
                        erro = "Dívida Pendente!";
                        throw new Exception("O aluno possui dívidas pendentes e não pode emprestar livros!");
                    }

                    realizarEmprestimo             = new SqlCommand("Emprestimos_RealziarEmprestimoAluno", cn, t);
                    realizarEmprestimo.CommandType = CommandType.StoredProcedure;

                    realizarEmprestimo.Parameters.AddWithValue("@idAluno", emprestimo.IdAluno);
                    realizarEmprestimo.Parameters.AddWithValue("@RM", emprestimo.Rm);
                    realizarEmprestimo.Parameters.AddWithValue("@NomeAluno", emprestimo.NomeAluno);
                    realizarEmprestimo.Parameters.AddWithValue("@Curso", emprestimo.Curso);
                    realizarEmprestimo.Parameters.AddWithValue("@Modulo", emprestimo.Modulo);
                }
                else
                {
                    realizarEmprestimo             = new SqlCommand("Emprestimos_RealziarEmprestimoFuncionario", cn, t);
                    realizarEmprestimo.CommandType = CommandType.StoredProcedure;

                    realizarEmprestimo.Parameters.AddWithValue("@idFuncionario", emprestimo.IdFuncionario);
                    realizarEmprestimo.Parameters.AddWithValue("@Nome", emprestimo.NomeProfessor);
                    realizarEmprestimo.Parameters.AddWithValue("@Funcao", emprestimo.Funcao);
                }

                realizarEmprestimo.Parameters.AddWithValue("@IdLivro", emprestimo.IdLivro);
                realizarEmprestimo.Parameters.AddWithValue("@nomeLivro", emprestimo.NomeLivro);
                realizarEmprestimo.Parameters.AddWithValue("@Localizacao", emprestimo.Localizacao);
                realizarEmprestimo.Parameters.AddWithValue("@Ano", emprestimo.Ano);
                realizarEmprestimo.Parameters.AddWithValue("@Autor", emprestimo.Autor);
                realizarEmprestimo.Parameters.AddWithValue("@Tombo", emprestimo.Tombo);
                realizarEmprestimo.Parameters.AddWithValue("@Retirada", emprestimo.Retirada);
                realizarEmprestimo.Parameters.AddWithValue("@Devolucao", emprestimo.Devolucao);
                realizarEmprestimo.ExecuteNonQuery();

                if (ficha)
                {
                    SqlCommand gerarFicha = new SqlCommand(@"FeichaCatalografica_GerarAnotacao", cn, t);
                    gerarFicha.CommandType = CommandType.StoredProcedure;

                    gerarFicha.Parameters.AddWithValue("@retirada", emprestimo.Retirada);
                    gerarFicha.Parameters.AddWithValue("@idLivro", emprestimo.IdLivro);
                    gerarFicha.Parameters.AddWithValue("@autor", emprestimo.Autor);
                    gerarFicha.Parameters.AddWithValue("@tombo", emprestimo.Tombo);

                    if (emprestimo.NomeAluno == null || emprestimo.NomeAluno == "")
                    {
                        gerarFicha.Parameters.AddWithValue("@aluno", "");
                    }
                    else
                    {
                        gerarFicha.Parameters.AddWithValue("@aluno", emprestimo.NomeAluno);
                    }

                    gerarFicha.Parameters.AddWithValue("@serie", emprestimo.Serie);
                    gerarFicha.Parameters.AddWithValue("@Devolucao", emprestimo.Devolucao);

                    if (emprestimo.NomeProfessor == "" || emprestimo.NomeProfessor == null)
                    {
                        gerarFicha.Parameters.AddWithValue("@Professor", "");
                    }
                    else
                    {
                        gerarFicha.Parameters.AddWithValue("@Professor", emprestimo.NomeProfessor);
                    }

                    if (emprestimo.Funcao == "" || emprestimo.Funcao == null)
                    {
                        gerarFicha.Parameters.AddWithValue("@Funcao", "");
                    }
                    else
                    {
                        gerarFicha.Parameters.AddWithValue("@Funcao", emprestimo.Funcao);
                    }

                    gerarFicha.Parameters.AddWithValue("@modoAluno", aluno);


                    gerarFicha.ExecuteNonQuery();
                }
                t.Commit();
            }
            catch (SqlException ex)
            {
                t.Rollback();
                throw new Exception(ex.Message);
            }
            finally { cn.Close(); }
        }
예제 #6
0
 public void ExcluirEmprestimo(EmprestimoInformation emprestimo, bool aluno)
 {
     emprestimosDAL.ExcluirEmprestimo(emprestimo, aluno);
 }
예제 #7
0
 public void DesfazerRenovacao(EmprestimoInformation emprestimo, bool modoAluno)
 {
     emprestimoMortoDAL.DesfazerRenovacao(emprestimo, modoAluno);
 }
예제 #8
0
 public bool verificarRenovacao(EmprestimoInformation emprestimo, bool modoAluno)
 {
     return(emprestimoMortoDAL.VerificarRenovacao(emprestimo, modoAluno));
 }
예제 #9
0
        private void BtnDesfazer_Click(object sender, EventArgs e)
        {
            string erro = "Erro Não Previsto!";

            try
            {
                if (lblIdMorto.Text == "0")
                {
                    erro = "Empréstimo Não Selecionado!";
                    throw new Exception("É preciso selecionar um empréstimo para desfazê-lo!");
                }

                if (emprestimosMortoBLL.VerificarDisponibilidade(lblIdLivro.Text))
                {
                    erro = "Livro Emprestado!";
                    throw new Exception("O livro agora está emprestado!");
                }


                if (modoAluno)
                {
                    if (lblIdAluno.Text == "0")
                    {
                        erro = "Nenhum Empréstimo Selecionado!";
                        throw new Exception("Selecione um aluno para desfazer o empréstimo!");
                    }



                    if (MessageBox.Show("Desfazer o empréstimo de " + lblNomeLivro.Text + " para " + lblNome.Text + "?", "Desfazer Empréstimo!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        string serie = lblModulo.Text + " - " + lblCurso.Text;
                        emprestimo = new EmprestimoInformation(Convert.ToInt32(lblIdAluno.Text),
                                                               Convert.ToInt32(lblRM.Text),
                                                               lblNome.Text,
                                                               lblCurso.Text,
                                                               Convert.ToInt32(lblModulo.Text),
                                                               Convert.ToInt32(lblIdLivro.Text),
                                                               lblNomeLivro.Text,
                                                               lblLocalizacaoLivro.Text,
                                                               lblAnoLivro.Text,
                                                               lblAutorLivro.Text,
                                                               Convert.ToInt32(lblTomboLivro.Text),
                                                               Convert.ToDateTime(lblDataEmprestimo.Text),
                                                               Convert.ToDateTime(lblDataDevolucao.Text),
                                                               serie);

                        if (emprestimosMortoBLL.verificarRenovacao(emprestimo, modoAluno))
                        {
                            emprestimosMortoBLL.DesfazerRenovacao(emprestimo, modoAluno);
                        }
                        else
                        {
                            emprestimosBLL.RealizarEmprestimo(emprestimo, modoAluno, false, ref erro);
                        }

                        emprestimosMortoBLL.ExcluirMorto(lblIdMorto.Text, modoAluno);
                        MessageBox.Show("O empréstimo foi desfeito!", "Empréstimo Desfeito!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        lblIdAluno.Text = "0";
                        AtualizadaGrid();
                        lblNomeLivro.Text        = "";
                        lblLocalizacaoLivro.Text = "";
                        lblAnoLivro.Text         = "";
                        lblAutorLivro.Text       = "";
                        lblTomboLivro.Text       = "";
                    }
                }
                else
                {
                    if (lblIdFuncionario.Text == "0")
                    {
                        erro = "Nenhum Empréstimo Selecionado!";
                        throw new Exception("Selecione um funcionário para desfazer o emprestimo!");
                    }

                    if (MessageBox.Show("Emprestar o livro " + lblNomeLivro.Text + " para " + lblNomeFuncionario.Text + "?", "Empréstimo de Livro", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        string serie = "-----";
                        emprestimo = new EmprestimoInformation(Convert.ToInt32(lblIdFuncionario.Text),
                                                               lblNomeFuncionario.Text,
                                                               lblFuncao.Text,
                                                               Convert.ToInt32(lblIdLivro.Text),
                                                               lblNomeLivro.Text,
                                                               lblLocalizacaoLivro.Text,
                                                               lblAnoLivro.Text,
                                                               lblAutorLivro.Text,
                                                               Convert.ToInt32(lblTomboLivro.Text),
                                                               Convert.ToDateTime(lblDataEmprestimo.Text),
                                                               Convert.ToDateTime(lblDataDevolucao.Text),
                                                               serie);

                        if (emprestimosMortoBLL.verificarRenovacao(emprestimo, modoAluno))
                        {
                            emprestimosMortoBLL.DesfazerRenovacao(emprestimo, modoAluno);
                        }
                        else
                        {
                            emprestimosBLL.RealizarEmprestimo(emprestimo, modoAluno, false, ref erro);
                        }

                        emprestimosMortoBLL.ExcluirMorto(lblIdMorto.Text, modoAluno);
                        MessageBox.Show("O Livro " + lblNomeLivro.Text + " foi emprestado para " + lblNomeFuncionario.Text + "!", "Livro Emprestado!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        AtualizadaGrid();
                        lblIdAluno.Text          = "0";
                        lblNomeLivro.Text        = "";
                        lblLocalizacaoLivro.Text = "";
                        lblAnoLivro.Text         = "";
                        lblAutorLivro.Text       = "";
                        lblTomboLivro.Text       = "";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, erro, MessageBoxButtons.OK, MessageBoxIcon.Error);
                erro = "Erro Não Previsto!";
            }
        }