Example #1
0
        public static List <Dictionary <String, String> > montaLivroOfertasCompleto(
            LivroOfertasBase livroOferta, int sentido, int casasDecimais)
        {
            List <Dictionary <String, String> > mensagem =
                new List <Dictionary <String, String> >();

            List <LOFDadosOferta> livro = null;

            if (sentido == LivroOfertasBase.LIVRO_COMPRA)
            {
                livro = livroOferta.getLivroCompra();
            }
            else
            {
                livro = livroOferta.getLivroVenda();
            }


            for (int posicao = 0; posicao < livro.Count; posicao++)
            {
                LOFDadosOferta item = livro[posicao];

                item.Posicao = posicao;

                mensagem.Add(LOFDadosOferta.montarRegistroOferta(ConstantesMDS.HTTP_OFERTAS_TIPO_ACAO_INCLUIR, item, casasDecimais));
            }

            return(mensagem);
        }
Example #2
0
        public static List <Dictionary <String, String> > montaLivroAgregadoCompleto(
            LivroOfertasBase livroOfertaAgregado, int sentido, int casasDecimais)
        {
            List <Dictionary <String, String> > mensagem =
                new List <Dictionary <String, String> >();

            List <LOAGrupoOfertas> agregado = null;

            if (sentido == LivroOfertasBase.LIVRO_COMPRA)
            {
                agregado = livroOfertaAgregado.getAgregadoCompra();
            }
            else
            {
                agregado = livroOfertaAgregado.getAgregadoVenda();
            }


            for (int posicao = 0; posicao < agregado.Count; posicao++)
            {
                LOAGrupoOfertas grupo = agregado[posicao];

                //Decimal preco = grupo.Preco;
                long quantidade = grupo.Quantidade;
                long qtdeOrdens = grupo.QtdeOrdens;

                String preco = "";
                if (grupo.Preco == ConstantesMDS.PRECO_LIVRO_OFERTAS_MIN_VALUE ||
                    grupo.Preco == ConstantesMDS.PRECO_LIVRO_OFERTAS_MAX_VALUE)
                {
                    preco = ConstantesMDS.DESCRICAO_OFERTA_ABERTURA;
                }
                else
                {
                    if (grupo.Preco != Decimal.Zero)
                    {
                        preco = String.Format("{0:f" + casasDecimais + "}", grupo.Preco).Replace('.', ',');
                    }
                }

                Dictionary <String, String> itemMensagem = new Dictionary <String, String>();

                itemMensagem.Add(
                    ConstantesMDS.HTTP_OFERTAS_ACAO,
                    String.Format("{0:d}", ConstantesMDS.HTTP_OFERTAS_TIPO_ACAO_INCLUIR));
                itemMensagem.Add(
                    ConstantesMDS.HTTP_OFERTAS_POSICAO,
                    String.Format("{0:d}", posicao));
                itemMensagem.Add(
                    ConstantesMDS.HTTP_OFERTAS_PRECO,
                    preco);
                itemMensagem.Add(
                    ConstantesMDS.HTTP_OFERTAS_QUANTIDADE,
                    String.Format("{0:d}", quantidade));
                itemMensagem.Add(
                    ConstantesMDS.HTTP_OFERTAS_QTDE_ORDENS,
                    String.Format("{0:d}", qtdeOrdens));

                mensagem.Add(itemMensagem);
            }

            return(mensagem);
        }
Example #3
0
        public static List <LOAItemOferta> alteraOferta(List <LOAGrupoOfertas> agregado,
                                                        List <LOFDadosOferta> livro,
                                                        LOFDadosOferta oferta,
                                                        int sentido)
        {
            List <LOAItemOferta> retorno = new List <LOAItemOferta>();
            Decimal preco = oferta.Preco;

            if (logger.IsDebugEnabled)
            {
                logger.Debug("Altera oferta [" + oferta.IDOferta + "][" + oferta.Preco + "][" + oferta.Quantidade + "] pos [" + oferta.Posicao + "]");
            }

            LOFDadosOferta old = livro[oferta.Posicao];

            old.Posicao = oferta.Posicao;

            // Se for alteracao da oferta sem mudar o preco
            if (old.Preco.CompareTo(oferta.Preco) == 0)
            {
                livro[oferta.Posicao] = oferta;

                for (int i = 0; i < agregado.Count; i++)
                {
                    LOAGrupoOfertas grupo = agregado[i];

                    if (grupo.Preco.CompareTo(oferta.Preco) == 0)
                    {
                        LOAItemOferta itemOferta = new LOAItemOferta();
                        LOAGrupoOfertas.alteraOferta(grupo, old, oferta);

                        agregado[i] = grupo;

                        itemOferta.Acao       = ConstantesMDS.HTTP_OFERTAS_TIPO_ACAO_ALTERAR;
                        itemOferta.Indice     = i;
                        itemOferta.Quantidade = grupo.Quantidade;
                        itemOferta.Preco      = preco;
                        itemOferta.QtdeOrdens = grupo.QtdeOrdens;

                        retorno.Add(itemOferta);
                        return(retorno);
                    }
                }

                logger.Error("alteraOferta(): Nao encontrou indice para o grupo de preco [" + oferta.Preco + "]");
            }
            else
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("alteraoferta: [" + old.IDOferta + "] mudou para [" +
                                 oferta.IDOferta + "] preco [" +
                                 old.Preco + "]->[" + oferta.Preco + "]");
                }
                List <LOAItemOferta> itemsOfertas = LivroOfertasBase.removeOferta(agregado, livro, old);
                if (itemsOfertas.Count > 0)
                {
                    retorno.AddRange(itemsOfertas);
                }

                itemsOfertas = LivroOfertasBase.insereOferta(agregado, livro, oferta, sentido);
                if (itemsOfertas.Count > 0)
                {
                    retorno.AddRange(itemsOfertas);
                }
            }

            return(retorno);
        }