Пример #1
0
        /// <summary>Crea e riempie l'oggetto rappresentante la spedizione da mandare a TXTango.</summary>
        /// <returns>Insert_new_place_on_trip</returns>
        private Insert_new_place_on_trip TXCreateObject()
        {
            // preparo la spedizione
            PlaceInsert place = new PlaceInsert();

            place.PlaceId  = ConfigurationManager.AppSettings["TXTANGO_ID_PREFIX"] + this.Id;
            place.CustomNr = (int)this.Progressivo;
            string display = this.DestinazioneLocalita + " - " + this.DestinazioneRagSoc;

            if (display.Length >= 50)
            {
                display = display.Substring(0, 45) + "..";
            }
            place.DriverDisplay = display;
            place.OrderSeq      = this.Ordinamento;
            place.Comment       = this.DestinazioneIndirizzo + ", " + this.DestinazioneCAP + " " + this.DestinazioneLocalita + " " + this.DestinazioneProvincia + ", " + this.DestinazioneNazione + " " + this.Note;

            // inserisco la posizione (geo coordinate)
            double latitudine  = double.Parse(this.DestinazioneGeoLoc.Split(',')[0].Replace(".", ","));
            double longitudine = double.Parse(this.DestinazioneGeoLoc.Split(',')[1].Replace(".", ","));

            place.Position = new Position()
            {
                Latitude = latitudine, Longitude = longitudine
            };

            // inserisco l'activity (carico o scarico)
            int activityId = 0;

            if (this.Tipo == ConfigurationManager.AppSettings["TXTEMP_SPEDIZIONE_RITIRO"])
            {
                activityId = Convert.ToInt32(ConfigurationManager.AppSettings["TXTANGO_ACTIVITY_PLACE_LOAD"]);
            }
            else
            {
                activityId = Convert.ToInt32(ConfigurationManager.AppSettings["TXTANGO_ACTIVITY_PLACE_UNLOAD"]);
            }
            place.Activity = new ActivityPlace()
            {
                ID = activityId
            };

            // inserisco la spedizione nel viaggio
            Insert_new_place_on_trip insertPlace = new Insert_new_place_on_trip();

            insertPlace.TripID       = ConfigurationManager.AppSettings["TXTANGO_ID_PREFIX"] + this.IdViaggio;
            insertPlace.TransferDate = null; // è possibile pianificare la data di trasmissione a TXTango
            insertPlace.Places       = new PlaceInsert[] { place };

            return(insertPlace);
        }
Пример #2
0
        /// <summary>Aggiorna la spedizione su TXTango e ritorna l'evento relativo all'aggiornamento.</summary>
        /// <param name="login">L'oggetto login da inviare a TXTango per l'autenticazione della richiesta.</param>
        /// <returns>Eventi</returns>
        public Eventi TXUpdate(TXTango.Login login)
        {
            Eventi evento = null;

            try {
                // geolocalizzo la spedizione
                this.GeoLocalizzaSpedizione();

                // creo la spedizione nel formato TXTango e la invio al webservice
                Insert_new_place_on_trip           insertPlace = this.TXCreateObject();
                ServiceSoapClient                  service     = new ServiceSoapClient();
                PlanningResultInsertNewPlaceOnTrip result      = service.Update_Place_On_Trip(login, insertPlace);
                // creo l'evento e registro le informazioni necessarie
                evento             = new Eventi();
                evento.SyncData    = DateTime.Now;
                evento.SyncTask    = ConfigurationManager.AppSettings["TXTANGO_TASK_UPDATE"];
                evento.SyncTipo    = ConfigurationManager.AppSettings["TXTEMP_TO_TXTango"];
                evento.XmlRequest  = Serializer.SerializeObject(insertPlace, SerializationType.XML);
                evento.XmlResponse = Serializer.SerializeObject(result, SerializationType.XML);
                if (result.Errors.Length > 0)
                {
                    log.Error("Errore TXTango: " + result.Errors[0].ErrorCode.ToString());
                    evento.SyncStato = ConfigurationManager.AppSettings["TXTEMP_STATO_ERRORE"];
                    evento.Stato     = ConfigurationManager.AppSettings["TXTANGO_STATO_NOT_DELIVERED"];
                    evento.Note      = "Vedi XmlResponse per i dettagli sugli errori";
                }
                else
                {
                    evento.Stato     = ConfigurationManager.AppSettings["TXTANGO_STATO_DELIVERED"];
                    evento.SyncStato = ConfigurationManager.AppSettings["TXTEMP_STATO_SINCRONIZZATO"];
                }


                // intercetto gli errori nella geocodifica
            } catch (GeocodingException ex) {
                // loggo l'errore
                log.Error(ex.Message, ex);

                // preparo l'evento di errore
                evento           = new Eventi();
                evento.SyncData  = DateTime.Now;
                evento.SyncTask  = ConfigurationManager.AppSettings["TXTANGO_TASK_UPDATE"];
                evento.SyncTipo  = ConfigurationManager.AppSettings["TXTEMP_TO_TXTango"];
                evento.SyncStato = ConfigurationManager.AppSettings["TXTEMP_STATO_ERRORE"];
                evento.Stato     = ConfigurationManager.AppSettings["TXTANGO_STATO_NOT_DELIVERED"];
                evento.Note      = "Impossibile geocodifcare la spedizione, verificare la correttezza dei campi indirizzo.";

                // invio una mail al responsabile del viaggio
                Boolean  notificationsEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["ENABLE_EMAIL_NOTIFICATIONS"]);
                TXViaggi viaggio = new TXViaggi(this.IdViaggio);
                if (notificationsEnabled && viaggio.MailUtenteCompetenza.Trim() != "")
                {
                    try {
                        List <string> addresses = new List <string>();
                        addresses.Add(viaggio.MailUtenteCompetenza);
                        string subject = "Spedizione nr. " + this.KeySpedizione + " non geolocalizzata.";
                        string body    = "<strong>Attenzione:<br/>Si è verificato un errore nel tentativo di geolocalizzare la spedizione in oggetto.<br/>La spedizione non è stata quindi caricata sul computer di bordo.<br/>E' necessario rivedere e correggere l'indirizzo di destinazione.</strong><br/><br/>";
                        body += "<strong>DATI SPEDIZIONE:</strong><br/>";
                        body += "Viaggio nr: " + viaggio.KeyViaggio + "<br/>";
                        body += "Spedizione nr: " + this.KeySpedizione + "<br/>";
                        body += "Mittente: " + this.MittenteRagSoc + "<br/>";
                        body += "Destinatario: " + this.DestinazioneRagSoc + "<br/>";
                        body += "Destinazione: " + this.DestinazioneIndirizzo.Trim() + ", " + this.DestinazioneCAP.Trim() + " " + this.DestinazioneLocalita.Trim() + " (" + this.DestinazioneProvincia.Trim() + "), " + this.DestinazioneNazione.Trim() + "<br/>";
                        if (this.Tipo == ConfigurationManager.AppSettings["TXTEMP_SPEDIZIONE_RITIRO"])
                        {
                            body += "Tipo: ORDINE DI RITIRO<br/>";
                        }
                        else
                        {
                            body += "Tipo: CONSEGNA<br/>";
                        }
                        body += "Colli: " + this.Colli + "<br/>";
                        body += "Peso: " + this.Peso + "<br/>";
                        body += "Volume: " + this.Volume + "<br/><br/>";

                        Mailer.SendMail(addresses, subject, body);
                    } catch (Exception e) {
                        log.Error(e.Message, e);
                    }
                }
            }

            return(evento);
        }