예제 #1
0
        public Retorno SalvarConfiguracao(tbConfiguracao objConfiguracao, int intFunCodigo)
        {
            var objRetorno   = new Retorno();
            var strValidacao = ValidaConfiguracao(objConfiguracao);

            try
            {
                if (strValidacao == string.Empty)
                {
                    var objConfiguracaoContexto = _objCtx.tbConfiguracao.FirstOrDefault();
                    _objCtx.Entry(objConfiguracaoContexto).CurrentValues.SetValues(objConfiguracao);
                    _objCtx.SaveChanges();
                    using (var objBll = new Auditoria(ref _objCtx, ref _objTransacao))
                        objBll.SalvarAuditoria(objConfiguracao.cfg_codigo, enOperacao.Alteracao, objConfiguracao, intFunCodigo);
                    objRetorno = RetornaConfiguracao();
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = strValidacao;
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #2
0
        public Retorno RetornaListaPedidoEntrega(bool blnProducao, bool blnEntrega, bool blnFinalizado, bool blnExcluido, int intFunCodigo, int intCaiCodigo, int intSkip, int intTake)
        {
            var objRetorno = new Retorno();

            try
            {
                List <int> arrCaiCodigo = new List <int>();
                if (intCaiCodigo > 0)
                {
                    arrCaiCodigo.Add(intCaiCodigo);
                }
                else
                {
                    arrCaiCodigo = _objCtx.tbCaixa.AsNoTracking()
                                   .Where(cai => cai.cai_dataFechamento == null)
                                   .Select(cai => cai.cai_codigo)
                                   .ToList();
                }

                var arrPedido = _objCtx.tbPedido.Include(fun => fun.tbFuncionarioEntregador)
                                .Include(ppr => ppr.tbPedidoProduto)
                                .Include(fpg => fpg.tbFormaPagamento).AsNoTracking()
                                .Where(ped => ped.ped_origem == "E" && arrCaiCodigo.Contains(ped.cai_codigo)).AsQueryable();
                if (!blnProducao)
                {
                    arrPedido = arrPedido.Where(ped => ped.ped_status != "P").AsQueryable();
                }
                if (!blnEntrega)
                {
                    arrPedido = arrPedido.Where(ped => ped.ped_status != "E").AsQueryable();
                }
                if (!blnFinalizado)
                {
                    arrPedido = arrPedido.Where(ped => ped.ped_status != "F").AsQueryable();
                }
                if (!blnExcluido)
                {
                    arrPedido = arrPedido.Where(ped => ped.ped_status != "X").AsQueryable();
                }
                if (intFunCodigo > 0)
                {
                    arrPedido = arrPedido.Where(ped => ped.fun_funcionarioEntregador == intFunCodigo).AsQueryable();
                }

                objRetorno.intCodigoErro = 0;
                if (intSkip == 0)
                {
                    objRetorno.intQtdeRegistro = arrPedido.Count();
                }
                objRetorno.objRetorno = arrPedido.OrderBy(ped => ped.ped_codigo).Skip(intSkip).Take(intTake).ToList();
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #3
0
        public Retorno RetornaPedidoComanda(int intNumero)
        {
            var objRetorno = new Retorno();

            try
            {
                tbMesa objMesa = null;
                objMesa = _objCtx.tbMesa.AsNoTracking().Include(ped => ped.tbPedido.tbFuncionario).FirstOrDefault(mes => mes.mes_numero == intNumero);
                if (objMesa != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objMesa;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #4
0
        public Retorno RetornaListaClienteGrupo(string strCodigo, string strNome, int intSkip, int intTake)
        {
            var objRetorno = new Retorno();

            try
            {
                var arrClienteGrupo = _objCtx.tbClienteGrupo.AsNoTracking().AsQueryable();
                if (!string.IsNullOrWhiteSpace(strCodigo))
                {
                    int intCodigo = Convert.ToInt32(strCodigo);
                    arrClienteGrupo = arrClienteGrupo.Where(cgr => cgr.cgr_codigo == intCodigo).AsQueryable();
                }
                if (!string.IsNullOrWhiteSpace(strNome))
                {
                    arrClienteGrupo = arrClienteGrupo.Where(cgr => cgr.cgr_nome.Contains(strNome)).AsQueryable();
                }
                objRetorno.intCodigoErro = 0;
                if (intSkip == 0)
                {
                    objRetorno.intQtdeRegistro = arrClienteGrupo.Count();
                }
                objRetorno.objRetorno = arrClienteGrupo.OrderByDescending(cgr => cgr.cgr_codigo).Skip(intSkip).Take(intTake).ToList();
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #5
0
        public Retorno RetornaListaMesa(string strParametro, bool blnLivre = true, bool blnOcupado = true)
        {
            var objRetorno = new Retorno();

            try
            {
                var query = _objCtx.tbMesa.AsNoTracking().OrderBy(mes => mes.mes_codigo).AsQueryable();
                if (!blnLivre)
                {
                    query = query.Where(mes => mes.mes_status != enStatusMesa.L.ToString()).AsQueryable();
                }
                if (!blnOcupado)
                {
                    query = query.Where(ped => ped.mes_status != enStatusMesa.O.ToString()).AsQueryable();
                }
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = query.OrderBy(mes => mes.mes_codigo).ToList();
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #6
0
        public Retorno SalvarEntregador(tbPedido objPedido, int intFunCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                objPedido.tbFuncionarioEntregador = null;
                objPedido.tbPedidoProduto         = null;
                objPedido.tbFormaPagamento        = null;
                objPedido.ped_status      = enStatusPedido.E.ToString();//"E";
                objPedido.ped_dataEntrega = DateTime.Now;
                var objPedidoContexto = _objCtx.tbPedido.FirstOrDefault(ped => ped.ped_codigo == objPedido.ped_codigo);
                _objCtx.Entry(objPedidoContexto).CurrentValues.SetValues(objPedido);
                _objCtx.SaveChanges();
                using (var objBll = new Auditoria(ref _objCtx, ref _objTransacao))
                    objBll.SalvarAuditoria(objPedido.ped_codigo, enOperacao.Outro, objPedido, intFunCodigo);
                objRetorno = RetornaPedido(objPedido.ped_codigo, null, enOrigemPedido.Entrega);
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #7
0
        public Retorno RetornaPedido(int intCodigo, enNavegacao?enDirecao, enOrigemPedido enOrigem)
        {
            var objRetorno = new Retorno();

            try
            {
                var      strOrigem = ((char)enOrigem).ToString();
                tbPedido objPedido = null;
                if (enDirecao == null)
                {
                    objPedido = _objCtx.tbPedido.AsNoTracking().Include(ppr => ppr.tbPedidoProduto.Select(pro => pro.tbProduto))
                                .Include(cli => cli.tbCliente)
                                .Include(cen => cen.tbCliente.tbClienteEndereco.Select(bai => bai.tbBairro))
                                .Include(ctl => ctl.tbCliente.tbClienteTelefone)
                                .Include(fun => fun.tbFuncionarioEntregador)
                                .Include(fpg => fpg.tbFormaPagamento)
                                .FirstOrDefault(ped => ped.ped_codigo == intCodigo && ped.ped_origem == strOrigem);
                }
                if (enDirecao == enNavegacao.Proximo)
                {
                    objPedido = _objCtx.tbPedido.AsNoTracking().Include(ppr => ppr.tbPedidoProduto.Select(pro => pro.tbProduto))
                                .Include(cli => cli.tbCliente)
                                .Include(cen => cen.tbCliente.tbClienteEndereco.Select(bai => bai.tbBairro))
                                .Include(ctl => ctl.tbCliente.tbClienteTelefone)
                                .Include(fun => fun.tbFuncionarioEntregador)
                                .Include(fpg => fpg.tbFormaPagamento)
                                .Where(ped => ped.ped_codigo > intCodigo && ped.ped_origem == strOrigem)
                                .OrderBy(ped => ped.ped_codigo).FirstOrDefault();
                }
                if (enDirecao == enNavegacao.Anterior)
                {
                    objPedido = _objCtx.tbPedido.AsNoTracking().Include(ppr => ppr.tbPedidoProduto.Select(pro => pro.tbProduto))
                                .Include(cli => cli.tbCliente)
                                .Include(cen => cen.tbCliente.tbClienteEndereco.Select(bai => bai.tbBairro))
                                .Include(ctl => ctl.tbCliente.tbClienteTelefone)
                                .Include(fun => fun.tbFuncionarioEntregador)
                                .Include(fpg => fpg.tbFormaPagamento)
                                .Where(ped => ped.ped_codigo < intCodigo && ped.ped_origem == strOrigem)
                                .OrderByDescending(ped => ped.ped_codigo).FirstOrDefault();
                }
                if (objPedido != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objPedido;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #8
0
        public Retorno RetornaListaAuditoria(int intCodRegistro, object objTabela)
        {
            var objRetorno = new Retorno();

            try
            {
                var strNomeTabela = objTabela.GetType().Name.Split('_')[0];
                var arrAuditoria  = _objCtx.tbAuditoria
                                    .Include(audo => audo.tbAuditoriaOperacao)
                                    .Include(fun => fun.tbFuncionario).AsNoTracking()
                                    .Where(aud => aud.aud_nomeTabela == strNomeTabela && aud.aud_codigoRegistro == intCodRegistro)
                                    .OrderBy(aud => aud.aud_codigo)
                                    .ToList();
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = arrAuditoria;
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #9
0
        public Retorno RetornaListaFormaPagamento(string strCodigo, string strNome, int intSkip, int intTake)
        {
            var objRetorno = new Retorno();

            try
            {
                var arrFormaPagamento = _objCtx.tbFormaPagamento.AsNoTracking().Include(fpt => fpt.tbFormaPagamentoTipo).AsQueryable();
                if (!string.IsNullOrWhiteSpace(strCodigo))
                {
                    int intCodigo = Convert.ToInt32(strCodigo);
                    arrFormaPagamento = arrFormaPagamento.Where(fpg => fpg.fpg_codigo == intCodigo).AsQueryable();
                }
                if (!string.IsNullOrWhiteSpace(strNome))
                {
                    arrFormaPagamento = arrFormaPagamento.Where(fpg => fpg.fpg_descricao.Contains(strNome)).AsQueryable();
                }
                objRetorno.intCodigoErro = 0;
                if (intSkip == 0)
                {
                    objRetorno.intQtdeRegistro = arrFormaPagamento.Count();
                }
                objRetorno.objRetorno = arrFormaPagamento.OrderByDescending(fpg => fpg.fpg_codigo).Skip(intSkip).Take(intTake).ToList();
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #10
0
        public Retorno RetornaConfiguracao()
        {
            var objRetorno = new Retorno();

            try
            {
                var objConfiguracao = _objCtx.tbConfiguracao.AsNoTracking().FirstOrDefault();
                if (objConfiguracao != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objConfiguracao;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #11
0
        public Retorno ExcluirCliente(int intCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                //Cria um contexto isolado para a trasacao de exclusao
                using (var objContexto = new EFContexto())
                {
                    //Inicia uma transacao no contexto isolado
                    using (var transacao = objContexto.Database.BeginTransaction())
                    {
                        try
                        {
                            var objCliente = objContexto.tbCliente.Include(cen => cen.tbClienteEndereco)
                                             .Include(ctl => ctl.tbClienteTelefone).FirstOrDefault(cli => cli.cli_codigo == intCodigo);
                            if (objCliente != null)
                            {
                                objContexto.tbClienteEndereco.RemoveRange(objCliente.tbClienteEndereco);
                                objContexto.tbClienteTelefone.RemoveRange(objCliente.tbClienteTelefone);
                                objContexto.tbCliente.Remove(objCliente);
                                objContexto.SaveChanges();
                                transacao.Commit();

                                objRetorno.intCodigoErro = 0;
                                objRetorno.objRetorno    = true;
                            }
                            else
                            {
                                objRetorno.intCodigoErro = 48;
                                objRetorno.strMsgErro    = "Cliente não encontrado para exclusão";
                            }
                        }
                        catch (Exception)
                        {
                            //Se deu erro é porque o perfil tem  registros relacionado
                            transacao.Rollback();
                            objRetorno.intCodigoErro = 48;
                            objRetorno.strMsgErro    = "Cliente não pode ser excluido pois há registros relacionados ao mesmo";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #12
0
        public Retorno FecharMesa(tbMesa objMesa, int intFunCodigo)
        {
            var objRetorno   = new Retorno();
            var strValidacao = ValidaFechamentoMesa(objMesa);

            try
            {
                if (strValidacao == string.Empty)
                {
                    if (objMesa.tbPedido.ped_codigo > 0)
                    {
                        objMesa.tbPedido.ped_status = enStatusPedido.F.ToString();
                        using (var objBllPedido = new Pedidos())
                        {
                            objRetorno = objBllPedido.SalvarPedido(objMesa.tbPedido, enOrigemPedido.Comanda, intFunCodigo);
                        }
                        if (objRetorno.intCodigoErro == 0)
                        {
                            objMesa.tbPedido   = null;
                            objMesa.mes_status = enStatusMesa.L.ToString();//"L";
                            objMesa.ped_codigo = null;
                            var objMesaContexto = _objCtx.tbMesa.FirstOrDefault(mes => mes.mes_codigo == objMesa.mes_codigo);
                            _objCtx.Entry(objMesaContexto).CurrentValues.SetValues(objMesa);
                            _objCtx.SaveChanges();
                            using (var objBll = new Auditoria(ref _objCtx, ref _objTransacao))
                                objBll.SalvarAuditoria(objMesa.mes_codigo, enOperacao.Outro, objMesa, intFunCodigo);

                            objRetorno = RetornaMesa(objMesa.mes_codigo);
                        }
                    }
                    else
                    {
                        objRetorno.intCodigoErro = 48;
                        objRetorno.strMsgErro    = "Pedido não encontrado!";
                    }
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = strValidacao;
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #13
0
        public Retorno ExcluirFornecedor(int intCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                //Cria um contexto isolado para a trasacao de exclusao
                using (var objContexto = new EFContexto())
                {
                    //Inicia uma transacao no contexto isolado
                    using (var transacao = objContexto.Database.BeginTransaction())
                    {
                        try
                        {
                            var objFornecedor = objContexto.tbFornecedor.FirstOrDefault(forn => forn.for_codigo == intCodigo);
                            if (objFornecedor != null)
                            {
                                //Tenta excluir o perfil no contexto isolado
                                objContexto.tbFornecedor.Remove(objFornecedor);
                                objContexto.SaveChanges();
                                transacao.Commit();

                                objRetorno.intCodigoErro = 0;
                                objRetorno.objRetorno    = true;
                            }
                            else
                            {
                                objRetorno.intCodigoErro = 48;
                                objRetorno.strMsgErro    = "Fornecedor não encontrado para exclusão";
                            }
                        }
                        catch (Exception)
                        {
                            //Se deu erro é porque o perfil tem  registros relacionado
                            transacao.Rollback();
                            objRetorno.intCodigoErro = 48;
                            objRetorno.strMsgErro    = "Fornecedor não pode ser excluido pois há registros relacionados ao mesmo";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #14
0
        public Retorno RetornaCliente(int intCodigo, enNavegacao?enDirecao)
        {
            var objRetorno = new Retorno();

            try
            {
                tbCliente objCliente = null;
                if (enDirecao == null)
                {
                    objCliente = _objCtx.tbCliente.Include(cen => cen.tbClienteEndereco.Select(bai => bai.tbBairro))
                                 .Include(ctl => ctl.tbClienteTelefone).Include(cgr => cgr.tbClienteGrupo)
                                 .AsNoTracking()
                                 .FirstOrDefault(cli => cli.cli_codigo == intCodigo || cli.tbClienteTelefone.Any(ctl => ctl.ctl_numero.Equals(intCodigo.ToString())));
                }
                if (enDirecao == enNavegacao.Proximo)
                {
                    objCliente = _objCtx.tbCliente.Include(cen => cen.tbClienteEndereco.Select(bai => bai.tbBairro))
                                 .Include(ctl => ctl.tbClienteTelefone)
                                 .Include(cgr => cgr.tbClienteGrupo).AsNoTracking()
                                 .Where(cli => cli.cli_codigo > intCodigo)
                                 .OrderBy(cli => cli.cli_codigo).FirstOrDefault();
                }
                if (enDirecao == enNavegacao.Anterior)
                {
                    objCliente = _objCtx.tbCliente.Include(cen => cen.tbClienteEndereco.Select(bai => bai.tbBairro))
                                 .Include(ctl => ctl.tbClienteTelefone)
                                 .Include(cgr => cgr.tbClienteGrupo).AsNoTracking()
                                 .Where(cli => cli.cli_codigo < intCodigo)
                                 .OrderByDescending(cli => cli.cli_codigo).FirstOrDefault();
                }
                if (objCliente != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objCliente;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #15
0
        public Retorno ExcluirProdutoGrupo(int intCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                using (var objContexto = new EFContexto())
                {
                    using (var transacao = objContexto.Database.BeginTransaction())
                    {
                        try
                        {
                            var objProdutoGrupo = objContexto.tbProdutoGrupo.Include(psgr => psgr.tbProdutoSubGrupo).FirstOrDefault(pgr => pgr.pgr_codigo == intCodigo);
                            if (objProdutoGrupo != null)
                            {
                                objContexto.tbProdutoSubGrupo.RemoveRange(objProdutoGrupo.tbProdutoSubGrupo);
                                objContexto.tbProdutoGrupo.Remove(objProdutoGrupo);
                                objContexto.SaveChanges();
                                transacao.Commit();

                                objRetorno.intCodigoErro = 0;
                                objRetorno.objRetorno    = true;
                            }
                            else
                            {
                                objRetorno.intCodigoErro = 48;
                                objRetorno.strMsgErro    = "Produto Grupo não encontrado para exclusão";
                            }
                        }
                        catch (Exception)
                        {
                            transacao.Rollback();
                            objRetorno.intCodigoErro = 48;
                            objRetorno.strMsgErro    = "Produto Grupo não pode ser excluido pois há registros relacionados ao mesmo";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #16
0
        public Retorno RetornaFuncionario(int intCodigo, enNavegacao?enDirecao)
        {
            var objRetorno = new Retorno();

            try
            {
                tbFuncionario objFuncionario = null;
                if (enDirecao == null)
                {
                    objFuncionario = _objCtx.tbFuncionario.Include(pac => pac.tbPerfilAcesso)
                                     .AsNoTracking()
                                     .FirstOrDefault(fun => fun.fun_codigo == intCodigo);
                }
                if (enDirecao == enNavegacao.Proximo)
                {
                    objFuncionario = _objCtx.tbFuncionario
                                     .Include(pac => pac.tbPerfilAcesso).AsNoTracking()
                                     .Where(fun => fun.fun_codigo > intCodigo)
                                     .OrderBy(fun => fun.fun_codigo).FirstOrDefault();
                }
                if (enDirecao == enNavegacao.Anterior)
                {
                    objFuncionario = _objCtx.tbFuncionario
                                     .Include(pac => pac.tbPerfilAcesso).AsNoTracking()
                                     .Where(fun => fun.fun_codigo < intCodigo)
                                     .OrderByDescending(fun => fun.fun_codigo).FirstOrDefault();
                }
                if (objFuncionario != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objFuncionario;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #17
0
        public Retorno ExcluirFormaPagamento(int intCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                using (var objContexto = new EFContexto())
                {
                    using (var transacao = objContexto.Database.BeginTransaction())
                    {
                        try
                        {
                            var objFormaPagamento = objContexto.tbFormaPagamento.FirstOrDefault(fpg => fpg.fpg_codigo == intCodigo);
                            if (objFormaPagamento != null)
                            {
                                objContexto.tbFormaPagamento.Remove(objFormaPagamento);
                                objContexto.SaveChanges();
                                transacao.Commit();

                                objRetorno.intCodigoErro = 0;
                                objRetorno.objRetorno    = true;
                            }
                            else
                            {
                                objRetorno.intCodigoErro = 48;
                                objRetorno.strMsgErro    = "FormaPagamento não encontrado para exclusão";
                            }
                        }
                        catch (Exception)
                        {
                            transacao.Rollback();
                            objRetorno.intCodigoErro = 48;
                            objRetorno.strMsgErro    = "FormaPagamento não pode ser excluido pois há registros relacionados ao mesmo.";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #18
0
        public Retorno RetornaFornecedor(int intCodigo, enNavegacao?enDirecao)
        {
            var objRetorno = new Retorno();

            try
            {
                tbFornecedor objFornecedor = null;
                if (enDirecao == null)
                {
                    objFornecedor = _objCtx.tbFornecedor
                                    .AsNoTracking()
                                    .FirstOrDefault(forn => forn.for_codigo == intCodigo);
                }
                if (enDirecao == enNavegacao.Proximo)
                {
                    objFornecedor = _objCtx.tbFornecedor.AsNoTracking()
                                    .Where(forn => forn.for_codigo > intCodigo)
                                    .OrderBy(forn => forn.for_codigo).FirstOrDefault();
                }
                if (enDirecao == enNavegacao.Anterior)
                {
                    objFornecedor = _objCtx.tbFornecedor.AsNoTracking()
                                    .Where(forn => forn.for_codigo < intCodigo)
                                    .OrderByDescending(forn => forn.for_codigo).FirstOrDefault();
                }
                if (objFornecedor != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objFornecedor;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #19
0
        public Retorno RetornaProdutoGrupo(int intCodigo, enNavegacao?enDirecao)
        {
            var objRetorno = new Retorno();

            try
            {
                tbProdutoGrupo objProdutoGrupo = null;
                if (enDirecao == null)
                {
                    objProdutoGrupo = _objCtx.tbProdutoGrupo.Include(psgr => psgr.tbProdutoSubGrupo)
                                      .AsNoTracking()
                                      .FirstOrDefault(pgr => pgr.pgr_codigo == intCodigo);
                }
                if (enDirecao == enNavegacao.Proximo)
                {
                    objProdutoGrupo = _objCtx.tbProdutoGrupo.Include(psgr => psgr.tbProdutoSubGrupo).AsNoTracking()
                                      .Where(pgr => pgr.pgr_codigo > intCodigo)
                                      .OrderBy(pgr => pgr.pgr_codigo).FirstOrDefault();
                }
                if (enDirecao == enNavegacao.Anterior)
                {
                    objProdutoGrupo = _objCtx.tbProdutoGrupo.Include(psgr => psgr.tbProdutoSubGrupo).AsNoTracking()
                                      .Where(pgr => pgr.pgr_codigo < intCodigo)
                                      .OrderByDescending(pgr => pgr.pgr_codigo).FirstOrDefault();
                }
                if (objProdutoGrupo != null)
                {
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objProdutoGrupo;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #20
0
        public Retorno RetornaMesa(int intCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                var objMesa = _objCtx.tbMesa.AsNoTracking().Include(ped => ped.tbPedido.tbPedidoProduto.Select(pro => pro.tbProduto))
                              .Include(fpg => fpg.tbPedido.tbFormaPagamento)
                              .FirstOrDefault(mes => mes.mes_codigo == intCodigo);
                if (objMesa != null)
                {
                    if (objMesa.tbPedido == null)
                    {
                        objMesa.tbPedido = new tbPedido
                        {
                            ped_data        = DateTime.Now,
                            cli_codigo      = 1,
                            ped_numeroMesa  = objMesa.mes_numero,
                            tbPedidoProduto = new List <tbPedidoProduto>()
                        };

                        var objPedidoProduto = new tbPedidoProduto {
                            tbProduto = new tbProduto()
                        };
                        objMesa.tbPedido.tbPedidoProduto.Add(objPedidoProduto);
                    }
                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objMesa;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #21
0
        public Retorno ExcluirPedido(int intCodigo, string strMotivoCancelamento, int intFunCodigo)
        {
            var objRetorno = new Retorno();

            try
            {
                var objPedido = _objCtx.tbPedido.FirstOrDefault(ped => ped.ped_codigo == intCodigo);
                if (objPedido != null)
                {
                    //Verificar se o caixa que refere o pedido está aberto, se não estiver, não permitir o fechamento
                    var objCaixa = _objCtx.tbCaixa.FirstOrDefault(cai => cai.cai_codigo == objPedido.cai_codigo && cai.cai_dataFechamento == null);
                    if (objCaixa != null)
                    {
                        objPedido.ped_status             = enStatusPedido.X.ToString();//"X";
                        objPedido.ped_motivoCancelamento = strMotivoCancelamento;
                        _objCtx.Entry(objPedido).State   = EntityState.Modified;
                        _objCtx.SaveChanges();
                        using (var objBll = new Auditoria(ref _objCtx, ref _objTransacao))
                            objBll.SalvarAuditoria(objPedido.ped_codigo, enOperacao.Exclusao, objPedido, intFunCodigo);

                        objRetorno.intCodigoErro = 0;
                        objRetorno.objRetorno    = true;
                    }
                    else
                    {
                        objRetorno.intCodigoErro = 48;
                        objRetorno.strMsgErro    = "O caixa referente ao pedido está fechado!";
                    }
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Pedido não encontrado para exclusão";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #22
0
        public Retorno RetornaPedidoMesa(int intNumero, string strTerminal)
        {
            var objRetorno = new Retorno();

            try
            {
                tbMesa objMesa = null;
                objMesa = _objCtx.tbMesa.AsNoTracking().Include(ped => ped.tbPedido.tbFuncionario)
                          .Include(ped => ped.tbPedido.tbFormaPagamento)
                          .Include(ped => ped.tbPedido.tbPedidoProduto.Select(pro => pro.tbProduto))
                          .FirstOrDefault(mes => mes.mes_numero == intNumero);
                if (objMesa != null)
                {
                    //Seleciona a mesa no banco de dados

                    var objMesaContexto = _objCtx.tbMesa.FirstOrDefault(mes => mes.mes_terminal == strTerminal);
                    if (objMesaContexto != null && objMesaContexto.mes_numero != intNumero)
                    {
                        objMesaContexto.mes_terminal         = null;
                        _objCtx.Entry(objMesaContexto).State = EntityState.Modified;
                    }

                    objMesa.mes_terminal         = strTerminal;
                    _objCtx.Entry(objMesa).State = EntityState.Modified;
                    _objCtx.SaveChanges();

                    objRetorno.intCodigoErro = 0;
                    objRetorno.objRetorno    = objMesa;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = "Registro não encontrado";
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #23
0
        public Retorno SalvarFuncionario(tbFuncionario objFuncionario, int intFunCodigo)
        {
            var objRetorno   = new Retorno();
            var strValidacao = ValidaFuncionario(objFuncionario);

            try
            {
                if (strValidacao == string.Empty)
                {
                    objFuncionario.tbPerfilAcesso = null;
                    enOperacao enTipoOperacao;
                    if (objFuncionario.fun_codigo == 0)
                    {
                        enTipoOperacao = enOperacao.Inclusao;
                        _objCtx.tbFuncionario.Add(objFuncionario);
                    }
                    else
                    {
                        enTipoOperacao = enOperacao.Alteracao;
                        var objFuncionarioContexto = _objCtx.tbFuncionario.FirstOrDefault(fun => fun.fun_codigo == objFuncionario.fun_codigo);
                        _objCtx.Entry(objFuncionarioContexto).CurrentValues.SetValues(objFuncionario);
                    }
                    _objCtx.SaveChanges();
                    using (var objBll = new Auditoria(ref _objCtx, ref _objTransacao))
                        objBll.SalvarAuditoria(objFuncionario.fun_codigo, enTipoOperacao, objFuncionario, intFunCodigo);
                    objRetorno.intCodigoErro = 0;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = strValidacao;
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #24
0
        public Retorno SalvarCidade(tbCidade objCidade, int intFunCodigo)
        {
            var objRetorno   = new Retorno();
            var strValidacao = ValidaCidade(objCidade);

            try
            {
                if (strValidacao == string.Empty)
                {
                    enOperacao enTipoOperacao;
                    if (objCidade.cid_codigo == 0)
                    {
                        enTipoOperacao = enOperacao.Inclusao;
                        _objCtx.tbCidade.Add(objCidade);
                    }
                    else
                    {
                        enTipoOperacao = enOperacao.Alteracao;
                        var objCidadeContexto = _objCtx.tbCidade.FirstOrDefault(cid => cid.cid_codigo == objCidade.cid_codigo);
                        _objCtx.Entry(objCidadeContexto).CurrentValues.SetValues(objCidade);
                    }
                    _objCtx.SaveChanges();
                    using (var objBll = new Auditoria(ref _objCtx, ref _objTransacao))
                        objBll.SalvarAuditoria(objCidade.cid_codigo, enTipoOperacao, objCidade, intFunCodigo);
                    objRetorno.intCodigoErro = 0;
                }
                else
                {
                    objRetorno.intCodigoErro = 48;
                    objRetorno.strMsgErro    = strValidacao;
                }
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #25
0
        public Retorno RetornaListaMesa(int?intNumero, bool blnLivre = true, bool blnOcupado = true, string strTerminal = "")
        {
            var objRetorno = new Retorno();

            try
            {
                if (!string.IsNullOrWhiteSpace(strTerminal))
                {
                    //Limpa a seleção da mesa no banco de dados
                    _objCtx.tbMesa.Where(mes => mes.mes_terminal == strTerminal).ToList().ForEach(mes =>
                    {
                        mes.mes_terminal = null;
                    });
                    _objCtx.SaveChanges();
                }

                var query = _objCtx.tbMesa.AsNoTracking().OrderBy(mes => mes.mes_numero).AsQueryable();
                if (intNumero != null && intNumero > 0)
                {
                    query = query.Where(mes => mes.mes_numero == intNumero).AsQueryable();
                }
                if (!blnLivre)
                {
                    query = query.Where(mes => mes.mes_status != enStatusMesa.L.ToString()).AsQueryable();
                }
                if (!blnOcupado)
                {
                    query = query.Where(ped => ped.mes_status != enStatusMesa.O.ToString()).AsQueryable();
                }
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = query.OrderBy(mes => mes.mes_numero).ToList();
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #26
0
        public Retorno RetornaListaFormaPagamentoTipo()
        {
            var objRetorno = new Retorno();

            try
            {
                var arrFormaPagamentoTipo = _objCtx.tbFormaPagamentoTipo.AsNoTracking()
                                            .OrderBy(fpt => fpt.fpt_codigo)
                                            .ToList();
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = arrFormaPagamentoTipo;
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #27
0
        public Retorno RetornaListaProdutoGrupo()
        {
            var objRetorno = new Retorno();

            try
            {
                var arrProdutoGrupo = _objCtx.tbProdutoGrupo.Include(psgr => psgr.tbProdutoSubGrupo).AsNoTracking()
                                      .OrderBy(pgr => pgr.pgr_nome)
                                      .ToList();
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = arrProdutoGrupo;
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #28
0
        public Retorno RetornaListaEstado()
        {
            var objRetorno = new Retorno();

            try
            {
                var arrEstado = _objCtx.tbEstado.Include(cid => cid.tbCidade).AsNoTracking()
                                .OrderBy(est => est.est_nome)
                                .ToList();
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = arrEstado;
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #29
0
        public Retorno RetornaListaBairro()
        {
            var objRetorno = new Retorno();

            try
            {
                var arrBairro = _objCtx.tbBairro.AsNoTracking()
                                .OrderBy(bai => bai.bai_nome)
                                .ToList();
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = arrBairro;
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }
예제 #30
0
        public Retorno RetornaListaPerfilAcesso()
        {
            var objRetorno = new Retorno();

            try
            {
                var arrPerfilAcesso = _objCtx.tbPerfilAcesso.AsNoTracking()
                                      .OrderBy(pac => pac.pac_descricao)
                                      .ToList();
                objRetorno.intCodigoErro = 0;
                objRetorno.objRetorno    = arrPerfilAcesso;
            }
            catch (Exception ex)
            {
                FrameworkUtil.LogErro(ex);
                objRetorno.intCodigoErro        = 16;
                objRetorno.strMsgErro           = ex.Message;
                objRetorno.strExceptionToString = ex.ToString();
            }
            return(objRetorno);
        }