Ejemplo n.º 1
0
        public string[] VerificarExportacaoPedidos(string cpfCnpj, int tipoUsuario, byte[] pedido)
        {
            int aut;

            if ((aut = Autenticar(cpfCnpj, tipoUsuario)) > 0)
            {
                string[] resultado = UtilsExportacaoPedido.VerificarExportacaoPedidos(pedido);

                return(resultado);
            }
            else
            {
                return(new string[] { "1", GetDescrErroAutenticacao(aut) });
            }
        }
Ejemplo n.º 2
0
        public string[] EnviarPedidosFornecedor(string cpfCnpj, int tipoUsuario, byte[] pedido)
        {
            int aut;

            if ((aut = Autenticar(cpfCnpj, tipoUsuario)) > 0)
            {
                //Importa
                string[] resultado = UtilsExportacaoPedido.Importar(pedido);

                return(resultado);
            }
            else
            {
                return(new string[] { "1", GetDescrErroAutenticacao(aut) });
            }
        }
        public IHttpActionResult ConsultarSituacaoExportacaoPedido(int idPedido, int idFornecedor)
        {
            using (var sessao = new GDATransaction())
            {
                try
                {
                    sessao.BeginTransaction();

                    var validacao = this.ValidarExistenciaPedidoFornecedor(sessao, idPedido, idFornecedor);

                    if (validacao != null)
                    {
                        return(validacao);
                    }

                    var fornecedor = FornecedorDAO.Instance.GetElement(sessao, (uint)idFornecedor);
                    var loja       = LojaDAO.Instance.GetElement(UserInfo.GetUserInfo.IdLoja);

                    Dictionary <uint, bool> pedido = new Dictionary <uint, bool>();
                    pedido.Add((uint)idPedido, true);

                    byte[] buffer        = UtilsExportacaoPedido.ConfigurarExportacao(pedido, new uint[] { });
                    var    urlFornecedor = $"{fornecedor.UrlSistema.ToLower().Substring(0, fornecedor.UrlSistema.ToLower().LastIndexOf("/webglass")).TrimEnd('/')}/service/wsexportacaopedido.asmx";

                    object[] parametros = new object[] { loja.Cnpj, 1, buffer };

                    object retorno = WebService.ChamarWebService(urlFornecedor, "SyncService", "VerificarExportacaoPedidos", parametros);

                    UtilsExportacaoPedido.AtualizarPedidosExportacao(sessao, retorno as string[]);

                    sessao.Commit();
                    sessao.Close();

                    return(this.Aceito("A situação do pedido foi atualizada."));
                }
                catch (Exception ex)
                {
                    sessao.Rollback();
                    sessao.Close();
                    return(this.ErroValidacao("Falha ao consultar situação.", ex));
                }
            }
        }
        public IHttpActionResult ExportarPedidos(PedidosExportarDto dados)
        {
            using (var sessao = new GDATransaction())
            {
                try
                {
                    sessao.BeginTransaction();

                    var validacao = this.ValidarExportacaoPedido(sessao, dados);

                    if (validacao != null)
                    {
                        return(validacao);
                    }

                    var fornecedor = FornecedorDAO.Instance.GetElement(sessao, (uint)(dados.IdFornecedor ?? 0));
                    var loja       = LojaDAO.Instance.GetElement(sessao, UserInfo.GetUserInfo.IdLoja);

                    Dictionary <uint, bool>         idsPedidosComOuSemBeneficiamentos = new Dictionary <uint, bool>();
                    Dictionary <uint, List <uint> > idsPedidosProdutosPedido          = new Dictionary <uint, List <uint> >();
                    List <uint> idsProdutosPedidos = new List <uint>();
                    List <uint> idsProdutosPedido  = new List <uint>();

                    foreach (var pedido in dados.Pedidos)
                    {
                        idsPedidosComOuSemBeneficiamentos.Add(
                            (uint)(pedido.IdPedido ?? 0),
                            pedido.ExportarBeneficiamento.GetValueOrDefault(false));

                        idsProdutosPedido = pedido.IdsProdutoPedido.Select(idpp => (uint)idpp).ToList();

                        idsPedidosProdutosPedido.Add((uint)(pedido.IdPedido ?? 0), idsProdutosPedido);

                        idsProdutosPedidos.AddRange(idsProdutosPedido);
                    }

                    uint[] listaIdsPedidos = new uint[idsPedidosComOuSemBeneficiamentos.Count];
                    idsPedidosComOuSemBeneficiamentos.Keys.CopyTo(listaIdsPedidos, 0);

                    byte[] buffer = UtilsExportacaoPedido.ConfigurarExportacao(idsPedidosComOuSemBeneficiamentos, idsProdutosPedidos.ToArray());

                    UtilsExportacaoPedido.CriarExportacao((uint)fornecedor.IdFornec, listaIdsPedidos, idsPedidosProdutosPedido);

                    var urlFornecedor = $"{fornecedor.UrlSistema.ToLower().Substring(0, fornecedor.UrlSistema.ToLower().LastIndexOf("/webglass")).TrimEnd('/')}/service/wsexportacaopedido.asmx";

                    object[] parametros        = new object[] { loja.Cnpj, 1, buffer };
                    var      retornoWebService = WebService.ChamarWebService(urlFornecedor, "SyncService", "EnviarPedidosFornecedor", parametros);

                    string[] dadosRetorno = retornoWebService as string[];

                    UtilsExportacaoPedido.ProcessarDadosExportacao(sessao, dadosRetorno, idsPedidosComOuSemBeneficiamentos);

                    sessao.Commit();
                    sessao.Close();

                    return(this.Ok(dadosRetorno[1]));
                }
                catch (Exception e)
                {
                    sessao.Rollback();
                    sessao.Close();
                    return(this.ErroValidacao("Erro ao exportar pedidos.", e));
                }
            }
        }