예제 #1
0
        public bool ExcluirBL(EmprestimoMov instancia)
        {
            /*criar as regras de negocio*/
            EmprestimoMovDA varDA = new EmprestimoMovDA();

            return varDA.ExcluirDA(instancia);
        }
예제 #2
0
        public string EditarBL(EmprestimoMov instancia)
        {
            EmprestimoMovDA varDA = new EmprestimoMovDA();

            if (varDA.EditarDA(instancia))
            {
                DateTime hoje = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateTime diaD = instancia.DataPrevistaEmprestimo ?? hoje;
                TimeSpan data = hoje - diaD;
                int diasAtraso = data.Days;

                if (utils.ComparaIntComZero(diasAtraso.ToString()) > 0)
                {
                    //cadastrar titulo da multa
                    decimal multa = utils.ComparaDecimalComZero(this.LerParametro(1, "F"));
                    Int32 tipoDocumento = utils.ComparaIntComZero(this.LerParametro(4, "F"));
                    Int32 portadorId = utils.ComparaIntComZero(this.LerParametro(5, "F"));

                    multa = multa * diasAtraso;
                    int prazo = utils.ComparaIntComZero(this.LerParametro(6, "F"));
                    prazo = (prazo < 1 ? 7 : prazo);

                    TitulosBL titBL = new TitulosBL();
                    Titulos titulos = new Titulos();

                    titulos.Numero = titBL.RetornaNovoNumero();
                    titulos.Parcela = 1;
                    titulos.Pessoaid = instancia.PessoaId;
                    titulos.DataEmissao = hoje;
                    titulos.DataVencimento = hoje.AddDays(prazo);
                    titulos.Valor = multa;
                    titulos.TipoDocumentoId = tipoDocumento;
                    titulos.Portadorid = portadorId;
                    titulos.Tipo = "R";

                    titulos.Obs = "Titulo gerado automaticamente, devido ao atraso de " + utils.ComparaIntComZero(diasAtraso.ToString())
                        + " dia(s) na devolução do exemplar " + instancia.Titulo;

                    if (titBL.InserirBL(titulos))
                        return "Exemplar devolvido com atraso. Foi gerado o título " + titulos.Numero + " no valor de R$" + titulos.Valor;

                }

                return "Devolução realizada com sucesso!";
            }
            else
                return "false";
        }
예제 #3
0
        public bool ExcluirDA(EmprestimoMov instancia)
        {
            SqlParameter[] paramsToSP = new SqlParameter[1];

            paramsToSP[0] = new SqlParameter("@id", instancia.Id);

            try
            {
                SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["conexao"].ToString(),
                                            CommandType.StoredProcedure, "stp_delete_emprestimoMov", paramsToSP);

                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
예제 #4
0
        public EmprestimoMov Carregar(int id)
        {
            EmprestimoMov volta = new EmprestimoMov();
            volta.Id = -1;

            StringBuilder consulta = new StringBuilder(@"SELECT * FROM EMPRESTIMOMOV WHERE ID = " + id.ToString());
            int i = -1;
            SqlDataReader dr = SqlHelper.ExecuteReader(ConfigurationManager.ConnectionStrings["conexao"].ToString(),
                                                                CommandType.Text, consulta.ToString());
            if (dr.Read())
            {
                volta.Id = id;
                volta.EmprestimoId = int.Parse(dr["EMPRESTIMOID"].ToString());
                volta.DataDevolucao = DateTime.Parse(dr["DATADEVOLUCAO"].ToString());
                volta.DataEmprestimo = DateTime.Parse(dr["DATAEMPRESTIMO"].ToString());
                volta.DataPrevistaEmprestimo = DateTime.Parse(dr["DATAPREVISTAEMPRESTIMO"].ToString());
            }
            return volta;
        }
예제 #5
0
        public bool EditarDA(EmprestimoMov instancia)
        {
            SqlParameter[] paramsToSP = new SqlParameter[5];

            paramsToSP[0] = new SqlParameter("@emprestimoid", instancia.EmprestimoId);
            paramsToSP[1] = new SqlParameter("@dataemprestimo", instancia.DataEmprestimo);
            paramsToSP[2] = new SqlParameter("@datadevolucao", instancia.DataDevolucao);
            paramsToSP[3] = new SqlParameter("@dataprevistaemprestimo", instancia.DataPrevistaEmprestimo);
            paramsToSP[4] = new SqlParameter("@id", instancia.Id);

            try
            {

                SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["conexao"].ToString(),
                                           CommandType.StoredProcedure, "stp_update_emprestimoMov", paramsToSP);

                return true;

            }
            catch (Exception e)
            {
                return false;
            }
        }
예제 #6
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            EmprestimosBL empBL = new EmprestimosBL();
            Emprestimos emp = new Emprestimos();

            emp.Id = utils.ComparaIntComZero(hfId.Value);

            emp.ExemplarId = utils.ComparaIntComZero(hfIdExemplar.Value);
            emp.PessoaId = utils.ComparaIntComZero(hfIdPessoa.Value);

            //a pessoa esta devendo?
            PessoasBL people = new PessoasBL();
            int fiado = people.EstaDevendo(emp.PessoaId);
            if (fiado > 0)
            {
                ExibirMensagem("Esta pessoa possui títulos em abeto com a Instituição e não pode emprestar este exemplar!");
                txtExemplar.Focus();
                return;  //throw new Exception(); //tem um jeito melhor de sair do metodo?
            }

            if (emp.Id > 0)
            { //editando == devolvendo
                if (this.Master.VerificaPermissaoUsuario("EDITAR"))
                {
                    empBL.EditarBL(emp);
                    //editar a movimentacao
                    EmprestimoMovBL emovBL = new EmprestimoMovBL();
                    EmprestimoMov mov = empBL.CarregaEmpNaoDevolvido(emp.Id);
                    if (mov.Id > 0)
                    {
                        DateTime hoje = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                        mov.DataDevolucao = hoje;
                        if (hoje > mov.DataPrevistaEmprestimo)
                        { //entregou atrasado? I shall have your money...

                           DateTime diaD = mov.DataPrevistaEmprestimo ?? hoje; //convertendo DateTime? para DateTime com opcao de setar valor padrao
                            TimeSpan span = hoje - diaD;
                            int multa = this.LerParametro(1, "F");
                            double valor = multa * span.TotalDays;

                            //cadastrar titulo da multa
                            TitulosBL titBL = new TitulosBL();
                            Titulos titulos = new Titulos();

                            titulos.Numero = titBL.NovoNumero();
                            titulos.Parcela = 1;
                            titulos.Pessoaid = emp.PessoaId;
                            titulos.DataEmissao = hoje;

                            int prazo = this.LerParametro(6, "F");
                            prazo = (prazo < 1 ? 7: prazo);
                            titulos.DataVencimento = hoje.AddDays(prazo);
                            titulos.Valor = Convert.ToDecimal(valor);
                            titulos.TipoDocumentoId = this.LerParametro(4, "F");
                            ExemplaresBL exb = new ExemplaresBL();
                            Exemplares ex = exb.LerBL(emp.ExemplarId);

                            titulos.Obs = "Titulo gerado automaticamente, devido ao atraso de " + Convert.ToInt16(span.TotalDays).ToString()
                                + " dia(s) na devolução do exemplar " + emp.Id.ToString() + " - " + ex.Obras.Titulo;

                            titulos.Portadorid = this.LerParametro(5, "F");
                            titulos.Tipo = "R";

                            titBL.InserirBL(titulos);
                        }
                        emovBL.EditarBL(mov);
                    }
                }
                else
                    Response.Redirect("~/erroPermissao.aspx?nomeUsuario=" + ((Label)Master.FindControl("lblNomeUsuario")).Text + "&usuOperacao=operação", true);
            }
            else
            { //inserindo == emprestando
                if (this.Master.VerificaPermissaoUsuario("INSERIR"))
                {

                    //Quantidade máxima de exemplares emprestado:
                    int param = this.LerParametro(1, "B");
                    if (param >= 0)
                    {
                        if (empBL.QuantosLivrosEmprestados(emp.PessoaId) > param)
                        {

                            ExibirMensagem(lblDesPessoa.Text + " já atingiu o limite máximo de empréstimos simultâneos.");
                            txtPessoa.Focus();
                            return; //                            throw new Exception(); //tem um jeito melhor de sair do metodo?
                        }
                    }

                    int meuid = empBL.InserirBL(emp);
                    //inserir a movimentacao
                    EmprestimoMovBL emovBL = new EmprestimoMovBL();
                    EmprestimoMov mov = new EmprestimoMov();
                    mov.EmprestimoId = meuid;
                    mov.DataDevolucao = null;
                    mov.DataEmprestimo = Convert.ToDateTime(txtdataInicio.Text);
                    mov.DataPrevistaEmprestimo = Convert.ToDateTime(txtdataPrevisao.Text);
                    emovBL.InserirBL(mov);
                }
                else
                    Response.Redirect("~/erroPermissao.aspx?nomeUsuario=" + ((Label)Master.FindControl("lblNomeUsuario")).Text + "&usuOperacao=operação", true);
            }

            // usuarios.DtInicio = Convert.ToDateTime(txtDtInicio.Text);
            Response.Redirect("viewReserva.aspx");
        }
예제 #7
0
        protected void btnRenovar_Click(object sender, EventArgs e)
        {
            EmprestimosBL empBL = new EmprestimosBL();
            Emprestimos emp = new Emprestimos();

            emp.Id = utils.ComparaIntComZero(hfId.Value);
            emp.PessoaId = utils.ComparaIntComZero(hfIdPessoa.Value);

            //a pessoa esta devendo?
            PessoasBL people = new PessoasBL();
            int fiado = people.EstaDevendo(emp.PessoaId);
            if (fiado > 0)
            {
                ExibirMensagem("Esta pessoa possui títulos em abeto com a Instituição e não pode renovar este exemplar!");
                txtExemplar.Focus();
                return;  //throw new Exception(); //tem um jeito melhor de sair do metodo?
            }

            //Quantidade máxima de renovações:
            int param = this.LerParametro(2, "B");
            if (param >= 0)
            {
                if (empBL.QtdRenovacoes(emp.Id) > param)
                {
                    ExibirMensagem("Este exemplar não pode mais ser renovado para esta pessoa!");
                    txtExemplar.Focus();
                    return;  //throw new Exception(); //tem um jeito melhor de sair do metodo?
                }
            }

            //chegou aqui? vamos renovar!
            //renovar consiste em editar o atual e setar a data de devolucao, e inserir um novo
            EmprestimoMovBL emovBL = new EmprestimoMovBL();
            EmprestimoMov mov = empBL.CarregaEmpNaoDevolvido(emp.Id);
            if (mov.Id > 0)
            {
                DateTime hoje = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateTime previsao = mov.DataPrevistaEmprestimo ?? hoje; //convertendo DateTime? para DateTime
                if (DateTime.Compare(previsao, hoje) > 0)
                {
                    mov.DataDevolucao = DateTime.Now;
                    emovBL.EditarBL(mov);
                    mov = new EmprestimoMov();
                    mov.EmprestimoId = emp.Id;
                    mov.DataEmprestimo = DateTime.Now;
                    param = this.LerParametro(4, "B");
                    DateTime lol = DateTime.Now;
                    if (param > 0)
                        lol = DateTime.Now.AddDays(param);
                    mov.DataPrevistaEmprestimo = lol;
                    mov.DataDevolucao = null;
                    emovBL.InserirBL(mov);
                }
                else
                {
                    ExibirMensagem("Exemplar atrasado não pode ser renovado!");
                    txtExemplar.Focus();
                    return;
                }
            }
            Response.Redirect("viewReserva.aspx");
        }
예제 #8
0
        public string RenovarEmprestimoBL(EmprestimoMov empMov, int qtdeDias)
        {
            string erro = null;
            EmprestimoMovDA empMovDA = new EmprestimoMovDA();

            erro = RetornaSituacaoTitulo(empMov.EmprestimoId != null ? (int)empMov.EmprestimoId : 0 );

            if (erro == string.Empty || erro == null)
                if (!empMovDA.RenovarEmprestimo(empMov, qtdeDias))
                    erro = "Não foi possível renovar o título";

            return erro;
        }
예제 #9
0
        private List<EmprestimoMov> CarregarObjEmpMov(SqlDataReader dr)
        {
            List<EmprestimoMov> emprestimoMov = new List<EmprestimoMov>();

            while (dr.Read())
            {
                EmprestimoMov empMov = new EmprestimoMov();
                empMov.Id = int.Parse(dr["ID"].ToString());
                empMov.EmprestimoId = int.Parse(dr["EMPRESTIMOID"].ToString());
                empMov.DataEmprestimo = Convert.ToDateTime(dr["DATAEMPRESTIMO"].ToString());
                empMov.DataDevolucao = utils.ComparaDataComNull(dr["DATADEVOLUCAO"].ToString());
                empMov.DataPrevistaEmprestimo = Convert.ToDateTime(dr["DATAPREVISTAEMPRESTIMO"].ToString());
                empMov.Situacao = dr["SITUACAO"].ToString();
                empMov.QtdeDias = Int16.Parse(dr["QTDDIAS"].ToString());

                Exemplares exemplar = new Exemplares();
                exemplar.Id = int.Parse(dr["IDEXE"].ToString());
                exemplar.Tombo = int.Parse(dr["TOMBO"].ToString());

                empMov.Exemplares = exemplar;

                Obras obras = new Obras();
                obras.Id = int.Parse(dr["IDOBRA"].ToString());
                obras.Codigo = int.Parse(dr["CODIGO"].ToString());
                obras.Titulo = dr["TITULO"].ToString();

                empMov.Obras = obras;

                emprestimoMov.Add(empMov);
            }

            return emprestimoMov;
        }
예제 #10
0
        /// <summary>
        /// Renova o emprestimo. Finaliza o movimento e inclui um novo registro.
        /// </summary>
        /// <param name="pessoaId"></param>
        /// <returns></returns>
        public bool RenovarEmprestimo(EmprestimoMov empMov, int qtdeDias)
        {
            if (EditarDA(empMov))
            {
                EmprestimoMov empMovimento = new EmprestimoMov();
                empMovimento.DataEmprestimo = DateTime.Now;
                empMovimento.EmprestimoId = empMov.EmprestimoId;
                empMovimento.DataPrevistaEmprestimo = DateTime.Now.AddDays(qtdeDias);

                if (InserirDA(empMovimento))
                    return true;
                else
                    return false;
            }
            else
                return false;
        }
예제 #11
0
        /// <summary>
        /// Carrega, da movimentacao de emprestimos, o emprestimo nao devolvido.
        /// </summary>
        /// <param name="id_emprestimo">Id do emprestimo (NÃO DO MOVIMENTACAO)</param>
        /// <returns>O Objeto EmprestimoMov da movimentacao nao devolvida, ou se nao existir, um objeto vazio com id == -1.</returns>
        public EmprestimoMov CarregaEmpNaoDevolvido(int id_emprestimo)
        {
            StringBuilder consulta = new StringBuilder(@"SELECT ID, EMPRESTIMOID, DATAEMPRESTIMO, DATAPREVISTAEMPRESTIMO FROM EMPRESTIMOMOV ");
            consulta.Append(@" WHERE EMPRESTIMOID = {0}");
            consulta.Append(@" AND DATADEVOLUCAO IS NULL ");

            SqlDataReader dr = SqlHelper.ExecuteReader(
                ConfigurationManager.ConnectionStrings["conexao"].ToString(),
                CommandType.Text,
                string.Format(consulta.ToString(), id_emprestimo));
            EmprestimoMov volta = new EmprestimoMov();
            volta.Id = -1;
            if (dr.Read())
            {
                volta.Id = int.Parse(dr["ID"].ToString());
                volta.EmprestimoId = int.Parse(dr["EMPRESTIMOID"].ToString());
                volta.DataEmprestimo = Convert.ToDateTime(dr["DATAEMPRESTIMO"].ToString());
                volta.DataPrevistaEmprestimo = Convert.ToDateTime(dr["DATAPREVISTAEMPRESTIMO"].ToString());
            }
            return volta;
        }
        protected void btnRenovar_Click(object sender, EventArgs e)
        {
            Button btndetails = sender as Button;
            GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
            string empMov_id;
            string emp_id;
            string renovar;
            string qtdeDias;
            string erro;
            empMov_id = dtgExemplar.DataKeys[gvrow.RowIndex][0].ToString();
            emp_id = dtgExemplar.DataKeys[gvrow.RowIndex][1].ToString();
            renovar = gvrow.Cells[4].Text;
            qtdeDias = gvrow.Cells[5].Text;

            //renovar
            if (renovar == "Sim")
            {
                EmprestimoMovBL empMovBL = new EmprestimoMovBL();
                EmprestimoMov empMov = new EmprestimoMov();
                empMov.Id = utils.ComparaIntComZero(empMov_id);
                empMov.EmprestimoId = utils.ComparaIntComZero(emp_id);
                empMov.DataDevolucao = DateTime.Now;
                empMov.DataEmprestimo = null;

                erro = empMovBL.RenovarEmprestimoBL(empMov, utils.ComparaIntComZero(qtdeDias));

                if (erro == null || erro == string.Empty)
                {
                    if (chkReciboRenovacao.Checked)
                        ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),
                                             "WinOpen('/Relatorios/RelRecibos.aspx?emprestimoid=" + empMov.EmprestimoId + "','',600,850);", true);
                    else
                        ExibirMensagem("Renovação realizada com sucesso !");

                    PesquisarCliente(txtCliente.Text);
                }
                else
                    ExibirMensagem(erro);
            }
            else
                ExibirMensagem("Não é possível renovar esse exemplar");
        }
        protected void btnFinOperacoes_Click(object sender, EventArgs e)
        {
            EmprestimosBL empBL = new EmprestimosBL();
            EmprestimoMovBL emovBL = new EmprestimoMovBL();

            if (!empBL.VerificaQtdeMaximaEmprestimo(utils.ComparaIntComZero(hfIdPessoa.Value)))
            {
                ExibirMensagem("O cliente já atingiu o limite máximo de empréstimos permitido!");
                return;
            }

            if (Session["dtItensEmp"] != null)
                dtItensEmp = (DataTable)Session["dtItensEmp"];

            bool v_erro = false;

            foreach (DataRow linha in dtItensEmp.Rows)
            {
                Emprestimos emp = new Emprestimos();
                emp.PessoaId = utils.ComparaIntComZero(hfIdPessoa.Value);
                emp.ExemplarId = utils.ComparaIntComZero((linha["ID"].ToString()));

                emp.Id = empBL.InserirBL(emp);

                if (emp.Id > 0)
                {
                    EmprestimoMov mov = new EmprestimoMov();
                    mov.EmprestimoId = emp.Id;
                    mov.DataEmprestimo = DateTime.Now;
                    mov.DataPrevistaEmprestimo = Convert.ToDateTime((linha["DEVOLUCAO"].ToString()));
                    v_erro = emovBL.InserirBL(mov);
                    if (!v_erro)
                    {
                        if (empBL.ExcluirBL(emp))
                        {
                            ExibirMensagem("Não foi possível concluir o empréstimo. Contate o administrador do sistema.");
                            return;
                        }

                    }
                    else
                        if (chkReciboEmprestimo.Checked)
                            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),
                                         "WinOpen('/Relatorios/RelRecibos.aspx?emprestimoid=" + emp.Id + "','',600,850);", true);
                }
            }

            if (v_erro)
            {
                LimparCamposEmprestimo();
                LimparCamposRenovacao();
                ExibirMensagem("Empréstimo realizado com sucesso!");
            }
        }
        protected void btnFinOpeDev_Click(object sender, EventArgs e)
        {
            if (Session["dtItensDev"] != null)
                dtItensDev = (DataTable)Session["dtItensDev"];

            EmprestimoMovBL emovBL = new EmprestimoMovBL();

            foreach (DataRow linha in dtItensDev.Rows)
            {

                EmprestimoMov mov = new EmprestimoMov();
                mov.Id = utils.ComparaIntComZero(linha["MOVID"].ToString());
                mov.EmprestimoId = utils.ComparaIntComZero(linha["ID"].ToString());
                mov.DataPrevistaEmprestimo = utils.ComparaDataComNull(linha["DEVOLUCAO"].ToString());
                mov.PessoaId = utils.ComparaIntComZero(hfIdPessoaDev.Value);
                mov.Titulo = linha["TITULO"].ToString();
                mov.DataDevolucao = DateTime.Now;

                string retorno = emovBL.EditarBL(mov);
                if (retorno != "false")
                {
                    if (chkReciboDevolucao.Checked)
                        ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),
                                                 "WinOpen('/Relatorios/RelRecibos.aspx?emprestimoid=" + mov.EmprestimoId + "','',600,850);", true);
                    else
                        ExibirMensagem("Devolução realizada com sucesso!");

                    LimparCamposDevolucao();
                    LimparCamposRenovacao();
                    LimparCamposEmprestimo();
                }
                else
                    ExibirMensagem("Não foi possível realizar a devolução. Contate o administrador do sistema.");
            }
        }
        protected void btnRelatorio_Click(object sender, EventArgs e)
        {
            EmprestimoMovBL empMovBL = new EmprestimoMovBL();
            EmprestimoMov empMov = new EmprestimoMov();
            EmprestimosBL empBL = new EmprestimosBL();
            Emprestimos emp = new Emprestimos();

            string PaginaRelatorio = "";

            if (ddlTipo.SelectedValue == "A")
            {
                Session["ldsRel"] = empMovBL.PesquisarRelatorioBL(txtAssociado.Text, txtCodigo.Text, txtDataRetiradaIni.Text, txtDataRetiradaFin.Text, txtDevolucaoIni.Text, txtDevolucaoFim.Text, ddlStatus.SelectedValue.ToString(), "desc").Tables[0];
                PaginaRelatorio = "/Relatorios/RelEmprestimoAcumulado.aspx?Acumulado=Mais&";
            }
            else if (ddlTipo.SelectedValue == "B")
            {
                Session["ldsRel"] = empMovBL.PesquisarRelatorioBL(txtAssociado.Text, txtCodigo.Text, txtDataRetiradaIni.Text, txtDataRetiradaFin.Text, txtDevolucaoIni.Text, txtDevolucaoFim.Text, ddlStatus.SelectedValue.ToString(), "asc").Tables[0];
                PaginaRelatorio = "/Relatorios/RelEmprestimoAcumulado.aspx?Acumulado=Menos&";
            }
            else
            {
                Session["ldsRel"] = empMovBL.PesquisarRelatorioBL(txtAssociado.Text, txtCodigo.Text, txtDataRetiradaIni.Text, txtDataRetiradaFin.Text, txtDevolucaoIni.Text, txtDevolucaoFim.Text, ddlStatus.SelectedValue.ToString()).Tables[0];
                PaginaRelatorio = "/Relatorios/RelEmprestimos.aspx?";
            }
            if (((DataTable)Session["ldsRel"]).Rows.Count != 0)
            {                                                                                                                                                                                                                                                                                                                                                                                                                                           //l//c
                ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "WinOpen('" + PaginaRelatorio + "PessoaId=" + txtAssociado.Text + "&obraId=" + txtCodigo.Text + "&DataRetiradaIni=" + txtDataRetiradaIni.Text + "&DataRetiradaFim=" + txtDataRetiradaFin.Text + "&DevolucaoFim=" + txtDevolucaoFim.Text + "&DevolucaoIni=" + txtDevolucaoIni.Text + "&Status=" + ddlStatus.SelectedValue.ToString() + "','',600,1125);", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('Sua pesquisa não retornou dados.');", true);
            }
        }