Ejemplo n.º 1
0
        private void GetTrackingDetails(string html)
        {
            if (this.IsInternational)
            {
                var obj = JObject.Parse(html);

                if (obj["sonucAciklama"].ToString().ToLower().Contains("bulunamadı"))
                {
                    Tracking = null;
                    return;
                }

                Tracking.Code        = this.Code;
                Tracking.Factory     = CargoFactories.PttInternational;
                Tracking.DeliveredBy = Functions.TidyText(obj["teslim_alan"].ToString());
                Tracking.ShippedUnit = " - ";
                Tracking.ArrivalUnit = " - ";
                Tracking.ShippedAt   = null;
                try
                {
                    JArray array = obj["dongu"] as JArray;
                    for (int i = 0; i < array.Count; i++)
                    {
                        var obj2 = array[i] as JObject;
                        Tracking.ShippedUnit = Functions.TidyText(array[0]["islemYeri"].ToString());
                        Tracking.ArrivalUnit = !string.IsNullOrEmpty(obj["teslim_alan"].ToString()) ? Functions.TidyText(array[array.Count - 1]["islemYeri"].ToString()) : " - ";
                        Tracking.ShippedAt   = Convert.ToDateTime(array[0]["tarih"].ToString());
                        Tracking.LastState   = array[array.Count - 1]["yapilanIslem"].ToString();
                        var movement = new Movement();
                        try
                        {
                            movement.Location = Functions.TidyText(obj2["ofis"].ToString()) + " - " + Functions.TidyText(obj2["islemYeri"].ToString());
                        }
                        catch { }
                        movement.Date  = Convert.ToDateTime(obj2["tarih"].ToString());
                        movement.State = obj2["yapilanIslem"].ToString();
                        if (movement.State.ToLower().Contains("teslim edildi"))
                        {
                            Tracking.IsDelivered = true;
                        }
                        Tracking.Movements.Insert(0, movement);
                    }
                }
                catch (Exception) { }
            }
            else
            {
                var obj = JObject.Parse(html);
                if (obj["sonucAciklama"].ToString().ToLower().Contains("bulunamadı"))
                {
                    Tracking = null;
                    return;
                }

                Tracking.Code        = this.Code;
                Tracking.Factory     = CargoFactories.Ptt;
                Tracking.DeliveredBy = Functions.TidyText(obj["TESALAN"].ToString());
                Tracking.ShippedUnit = Functions.TidyText(obj["IMERK"].ToString());
                Tracking.ArrivalUnit = Functions.TidyText(obj["VMERK"].ToString());
                string dateString = obj["ITARIH"].ToString();
                Tracking.ShippedAt = Extensions.GetDate(dateString.Substring(6) + "." + dateString.Substring(4, 2) + "." + dateString.Substring(0, 4));
                try
                {
                    JArray array = obj["dongu"] as JArray;
                    for (int i = 0; i < array.Count; i++)
                    {
                        var obj2     = array[i] as JObject;
                        var movement = new Movement();
                        try
                        {
                            movement.Location = Functions.TidyText(obj2["IMERK"].ToString());
                        }
                        catch { }
                        movement.Date  = Extensions.GetDate(obj2["ITARIH"].ToString());
                        movement.State = obj2["ISLEM"].ToString();
                        if (movement.State.ToLower().Contains("teslim edildi"))
                        {
                            Tracking.IsDelivered = true;
                        }
                        Tracking.Movements.Insert(0, movement);
                    }
                }
                catch (Exception) { }
            }
        }