Exemplo n.º 1
0
        static void procesarAgregarParada()
        {
            unigisData.wsGetGuias data = new unigisData.wsGetGuias();
            var           json         = data.getNuevasParadas();
            NuevasParadas datos        = new JavaScriptSerializer().Deserialize <NuevasParadas>(json);

            if (datos.success)
            {
                unigisws.Service unigis = new unigisws.Service();
                unigis.Timeout = 10 * 60 * 1000;

                try
                {
                    foreach (NuevaParada nuevaParada in datos.collection_Paradas)
                    {
                        Console.WriteLine("Viaje: " + nuevaParada.viajeId.ToString());
                        unigisws.AgregarParadaViajeResponse[] paradaResponse = unigis.AgregarParadaViaje("1234", Convert.ToInt32(nuevaParada.viajeId), nuevaParada.Paradas.ToArray());

                        for (int i = 0; i < paradaResponse.Count(); i++)
                        {
                            if (paradaResponse[i].IdParada <= 0)
                            {
                                Console.WriteLine("ViajeId: " + nuevaParada.viajeId.ToString() + "Guía: " + paradaResponse[i].RefDocumento + " ERROR: " + paradaResponse[i].IdParada.ToString());
                            }
                            else
                            {
                                string error = data.updateParadaId(nuevaParada.viajeId, paradaResponse[i].IdParada.ToString(), paradaResponse[i].RefDocumento.ToString());
                                Console.WriteLine("ViajeId: " + nuevaParada.viajeId.ToString() + " ParadaId: " + paradaResponse[i].IdParada.ToString() + " Resultado Update: " + error);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            else
            {
                Console.WriteLine(datos.msg);
            }
        }
Exemplo n.º 2
0
        static void enviarGuias()
        {
            string fechaCortediasAdicionales = ConfigurationManager.AppSettings["fechaCortediasAdicionales"];
            string fechaCorteHora            = ConfigurationManager.AppSettings["fechaCorteHora"];
            string pathLog = ConfigurationManager.AppSettings["pathLog"].ToString();

            //Crear instancia para guardar log
            utils utils = new utils();

            int      contador = 1;
            string   date     = "";
            DateTime dt       = DateTime.Now;

            unigisData.wsGetGuias data = new unigisData.wsGetGuias();
            date = dt.AddDays(Convert.ToDouble(fechaCortediasAdicionales)).ToString("yyyyMMdd") + " " + fechaCorteHora;
            //date = dt.ToString("yyyyMMdd") + " 12:00:00";
            data.Timeout = 10 * 60 * 1000;
            var json         = data.getGuias(date);
            var JSSerializer = new JavaScriptSerializer();

            JSSerializer.MaxJsonLength = Int32.MaxValue;
            Orders ordersData = JSSerializer.Deserialize <Orders>(json);

            if (ordersData.success)
            {
                string guid_registro = "";
                string prevReg       = "";
                List <unigisws.pOrdenPedido> orders = new List <unigisws.pOrdenPedido>();
                unigisws.Service             unigis = new unigisws.Service();
                unigis.Timeout = 10 * 60 * 1000;

                try
                {
                    foreach (var orderData in ordersData.collection_Orders)
                    {
                        unigisws.pOrdenPedido            order        = new unigisws.pOrdenPedido();
                        unigisws.pOrdenPedidoItem        orderItem    = new unigisws.pOrdenPedidoItem();
                        unigisws.pCliente                clientData   = new unigisws.pCliente();
                        unigisws.pProducto               productData  = new unigisws.pProducto();
                        unigisws.CampoValor              dynamicCamp  = new unigisws.CampoValor();
                        List <unigisws.pOrdenPedidoItem> orderItems   = new List <unigisws.pOrdenPedidoItem>();
                        List <unigisws.CampoValor>       dynamicCamps = new List <unigisws.CampoValor>();

                        try
                        {
                            guid_registro = orderData.guid_registro;

                            if (orderData.RefDocumento == prevReg)
                            {
                                int index = orders.FindLastIndex(o => o.RefDocumento == orderData.RefDocumento);
                                orderItem.RefDocumento = orderData.Items_pOrdenPedidoItem_RefDocumento;
                                orderItem.Descripcion  = orderData.Items_pOrdenPedidoItem_Producto_Descripcion;

                                productData.RefProducto          = orderData.Items_pOrdenPedidoItem_Producto_RefProducto;
                                productData.Descripcion          = orderData.Items_pOrdenPedidoItem_Producto_Descripcion;
                                productData.Alto                 = orderData.Items_pOrdenPedidoItem_Producto_Alto;
                                productData.Ancho                = orderData.Items_pOrdenPedidoItem_Producto_Ancho;
                                productData.Profundidad          = orderData.Items_pOrdenPedidoItem_Producto_Profundidad;
                                productData.Rotacion             = orderData.Items_pOrdenPedidoItem_Producto_RotacionPermitida;
                                productData.RotacionesPermitidas = orderData.Items_pOrdenPedidoItem_Producto_RotacionPermitida;
                                productData.Apilable             = orderData.Items_pOrdenPedidoItem_Producto_Apilable;
                                productData.Peso                 = orderData.Items_pOrdenPedidoItem_Peso;
                                productData.Volumen              = orderData.Items_pOrdenPedidoItem_Volumen;
                                orderItem.Producto               = productData;

                                if (orderData.Items_pOrdenPedidoItem_Cantidad.HasValue)
                                {
                                    orderItem.Cantidad = orderData.Items_pOrdenPedidoItem_Cantidad.Value;
                                }
                                orderItem.Volumen      = orderData.Items_pOrdenPedidoItem_Volumen;
                                orderItem.Peso         = orderData.Items_pOrdenPedidoItem_Peso;
                                orderItem.Bulto        = orderData.Items_pOrdenPedidoItem_Bulto;
                                orderItem.Pallets      = orderData.Items_pOrdenPedidoItem_Pallets;
                                orderItem.ImporteCosto = orderData.Items_pOrdenPedidoItem_ImporteCosto;
                                orderItem.FechaEntrega = orderData.Items_pOrdenPedidoItem_FechaEntrega;
                                //Getting Existing Items from Order
                                var existingItems = orders[index].Items.ToArray();
                                for (var i = 0; i < existingItems.Length; i++)
                                {
                                    orderItems.Add(existingItems[i]);
                                }
                                //Adding the new one
                                orderItems.Add(orderItem);
                                orders[index].Items = orderItems.ToArray();
                            }

                            if (contador > 1)
                            {
                                Console.WriteLine((contador - 1).ToString() + " " + prevReg);
                            }

                            if (((orderData.RefDocumento != prevReg) && (prevReg != "")) || ((contador == ordersData.collection_Orders.Count()) && (ordersData.collection_Orders.Count() > 1)))
                            {
                                //sincronizar registro
                                int resp = unigis.CrearOrdenesPedido("10:Feb:2017 \"This is an Example!\"", orders.ToArray());
                                Console.WriteLine(resp.ToString());
                                if (resp == 1)
                                {
                                    string error = data.updateGuiaCargada(orders[0].RefDocumento, guid_registro);
                                    Console.WriteLine(error);
                                }
                                //inicializar orden
                                orders = new List <unigisws.pOrdenPedido>();
                            }

                            if (orderData.RefDocumento != prevReg)
                            {
                                order.Tipo         = orderData.TipoGuia;
                                order.RefDocumento = orderData.RefDocumento;
                                //Se comenta a peticion del proveedor
                                if (orderData.FechaEntrega.HasValue)
                                {
                                    //nuevaParada.Fecha = orderData.Fecha.Value;
                                    order.Fecha = orderData.FechaEntrega.Value;
                                }
                                order.FechaEntrega         = orderData.FechaEntrega;
                                order.FechaEntregaOriginal = orderData.FechaEntregaOriginal;
                                clientData.RefCliente      = orderData.Cliente_RefCliente;

                                clientData.RazonSocial  = orderData.Cliente_RazonSocial;
                                clientData.Telefono     = orderData.Cliente_Telefono;
                                clientData.EMail        = orderData.Cliente_Email;
                                clientData.Contacto     = orderData.Cliente_Contacto;
                                clientData.Direccion    = orderData.Cliente_Direccion;
                                clientData.Calle        = orderData.Cliente_Calle;
                                clientData.NumeroPuerta = orderData.Cliente_NumeroPuerta;
                                clientData.Barrio       = orderData.Cliente_Barrio;
                                clientData.Localidad    = orderData.Cliente_Localidad;
                                clientData.Partido      = orderData.Cliente_Partido;
                                clientData.Provincia    = orderData.Cliente_Provincia;
                                clientData.Pais         = orderData.Cliente_Pais;

                                //clientData.Latitud = orderData.Cliente_Latitud;
                                //clientData.Longitud = orderData.Cliente_Longitud;
                                clientData.RefDomicilioExterno = orderData.Cliente_RefDomicilioExterno;


                                clientData.DomicilioDescripcion = orderData.Cliente_DomicilioDescripcion;
                                clientData.InicioHorario1       = orderData.Cliente_InicioHorario1;
                                clientData.FinHorario1          = orderData.Cliente_FinHorario1;
                                clientData.TiempoEspera         = orderData.Cliente_TiempoEspera;
                                order.Cliente         = clientData;
                                order.Telefono        = orderData.Telefono;
                                order.Descripcion     = orderData.Descripcion;
                                order.CodigoSucursal  = orderData.CodigoSucursal;
                                order.CodigoOperacion = orderData.CodigoSucursal;
                                order.TipoPedido      = orderData.TipoPedido;
                                order.Estado          = orderData.Estado;
                                order.Direccion       = orderData.Direccion;
                                order.Calle           = orderData.Calle;
                                order.NroPuerta       = orderData.NroPuerta;
                                order.Barrio          = orderData.Barrio;
                                order.Localidad       = orderData.Localidad;
                                order.Partido         = orderData.Partido;
                                order.Provincia       = orderData.Provincia;
                                order.Pais            = orderData.Pais;
                                order.CodigoPostal    = orderData.CodigoPostal;
                                order.InicioHorario1  = orderData.InicioHorario1;
                                order.FinHorario1     = orderData.FinHorario1;
                                order.TiempoEspera    = orderData.TiempoEspera;
                                order.Volumen         = orderData.Volumen;
                                order.Peso            = orderData.Peso;
                                order.Bulto           = orderData.Bulto;
                                order.Pallets         = orderData.Pallets;
                                //nuevaParada.Latitud = orderData.Latitud;
                                //nuevaParada.Longitud = orderData.Longitud;
                                order.Observaciones    = orderData.Observaciones;
                                order.Email            = orderData.Email;
                                order.Categoria        = orderData.Categoria;
                                order.Prioridad        = orderData.Prioridad;
                                order.cargaExclusiva   = orderData.cargaExclusiva == "NO" ? false : true;
                                orderItem.RefDocumento = orderData.Items_pOrdenPedidoItem_RefDocumento;

                                productData.RefProducto          = orderData.Items_pOrdenPedidoItem_Producto_RefProducto;
                                productData.Descripcion          = orderData.Items_pOrdenPedidoItem_Producto_Descripcion;
                                productData.Alto                 = orderData.Items_pOrdenPedidoItem_Producto_Alto;
                                productData.Ancho                = orderData.Items_pOrdenPedidoItem_Producto_Ancho;
                                productData.Profundidad          = orderData.Items_pOrdenPedidoItem_Producto_Profundidad;
                                productData.Rotacion             = orderData.Items_pOrdenPedidoItem_Producto_RotacionPermitida;
                                productData.RotacionesPermitidas = orderData.Items_pOrdenPedidoItem_Producto_RotacionPermitida;
                                productData.Apilable             = orderData.Items_pOrdenPedidoItem_Producto_Apilable;
                                productData.Peso                 = orderData.Items_pOrdenPedidoItem_Peso;
                                productData.Volumen              = orderData.Items_pOrdenPedidoItem_Volumen;


                                orderItem.Producto = productData;
                                if (orderData.Items_pOrdenPedidoItem_Cantidad.HasValue)
                                {
                                    orderItem.Cantidad = orderData.Items_pOrdenPedidoItem_Cantidad.Value;
                                }
                                orderItem.Descripcion  = orderData.Items_pOrdenPedidoItem_Producto_Descripcion;
                                orderItem.Volumen      = orderData.Items_pOrdenPedidoItem_Volumen;
                                orderItem.Peso         = orderData.Items_pOrdenPedidoItem_Peso;
                                orderItem.Bulto        = orderData.Items_pOrdenPedidoItem_Bulto;
                                orderItem.Pallets      = orderData.Items_pOrdenPedidoItem_Pallets;
                                orderItem.ImporteCosto = orderData.Items_pOrdenPedidoItem_ImporteCosto;
                                orderItem.FechaEntrega = orderData.Items_pOrdenPedidoItem_FechaEntrega;
                                orderItems.Add(orderItem);
                                order.Items       = orderItems.ToArray();
                                dynamicCamp.Campo = orderData.CampoDinamico_Campo;
                                dynamicCamp.Valor = orderData.CampoDinamico_Valor;
                                dynamicCamps.Add(dynamicCamp);
                                order.CampoDinamico = dynamicCamps.ToArray();
                                orders.Add(order);
                            }

                            //sincronizar cuando el resultado sea un solo registro o el ultimo
                            if (((contador == 1) && (contador == ordersData.collection_Orders.Count()) && (ordersData.collection_Orders.Count() > 0)) ||
                                ((contador == ordersData.collection_Orders.Count()) && (ordersData.collection_Orders.Count() > 1)))
                            {
                                if ((contador == ordersData.collection_Orders.Count()) && (ordersData.collection_Orders.Count() > 1))
                                {
                                    Console.WriteLine(contador.ToString() + " " + prevReg);
                                }
                                //sincronizar registro
                                int resp = unigis.CrearOrdenesPedido("10:Feb:2017 \"This is an Example!\"", orders.ToArray());
                                Console.WriteLine(resp.ToString());
                                if (resp == 1)
                                {
                                    string error = data.updateGuiaCargada(orders[0].RefDocumento, guid_registro);
                                    Console.WriteLine(error);
                                }
                                //inicializar orden
                                orders = new List <unigisws.pOrdenPedido>();
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(orderData.RefDocumento + " " + e.Message + " " + utils.guardarLog(orderData.RefDocumento + ": " + e.Message, pathLog)); // nuevaParada error
                        }

                        contador++;
                        prevReg = orderData.RefDocumento; //Sticker anterior
                    }
                    //foreach (var k in orders)
                    //{
                    //    Console.Write(k.RefDocumento + Environment.NewLine);
                    //    for (int s = 0; s < k.Items.Length; s++)
                    //    {
                    //        Console.Write(k.Items[s].Volumen + Environment.NewLine);
                    //    }
                    //}

                    /*
                     * int resp = unigis.CrearOrdenesPedido("10:Feb:2017 \"This is an Example!\"", orders.ToArray());
                     * Console.WriteLine(resp);
                     */
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + " " + utils.guardarLog(e.Message, pathLog)); // orders error
                }
            }
            else
            {
                Console.WriteLine(ordersData.msg);
            }
        }