Exemplo n.º 1
0
 private static void GetCallBack(IAsyncResult result)
 {
     try
     {
         HttpWebRequest webRequest = result.AsyncState as HttpWebRequest;
         WebResponse    response   = webRequest.EndGetResponse(result);
         StreamReader   stream     = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
         string         webResult  = stream.ReadToEnd();
         Tracking       tracking   = GetTracking(webResult);
         Database.Dispatcher.BeginInvoke(() => SystemTray.ProgressIndicator.IsVisible = false);
         if (tracking == null)
         {
             Database.Dispatcher.BeginInvoke(() =>
             {
                 Database.TrackingDetails.Visibility = Visibility.Collapsed;
                 Database.WarningText.Visibility     = Visibility.Visible;
                 MessageBox.Show("Bu koda ait kayıt bulunamadı!\nTekrar deneyiniz..");
                 Database.TrackingDetails.DataContext = null;
             });
         }
         else
         {
             Database.Dispatcher.BeginInvoke(() =>
             {
                 tracking.LastSearchDate = DateTime.Now;
                 Database.AddToHistory(tracking);
                 Database.TrackingDetails.Visibility  = Visibility.Visible;
                 Database.WarningText.Visibility      = Visibility.Collapsed;
                 Database.TrackingDetails.DataContext = tracking;
             });
         }
     }
     catch (WebException)
     {
         Database.Dispatcher.BeginInvoke(() => MessageBox.Show("Sunucuya bağlanılamıyor..\nTekrar deneyiniz.."));
     }
 }
Exemplo n.º 2
0
 public static void RemoveFromHistory(Tracking tracking)
 {
     History.Remove(tracking);
     Update();
 }
Exemplo n.º 3
0
 public static Tracking GetTracking(string result)
 {
     try
     {
         HtmlDocument doc = new HtmlDocument();
         doc.LoadHtml(result);
         HtmlNode node = doc.DocumentNode;
         if (node.InnerText.Contains("Talebiniz için herhangi bir sonuç bulunamadı"))
         {
             return(null);
         }
         Tracking tracking = new Tracking();
         tracking.Code    = Database.TrackingCode;
         tracking.Factory = Factory;
         doc.LoadHtml(node.SelectSingleNode("//div[@id='table" + tracking.Code + "']").InnerHtml);
         node = doc.DocumentNode;
         tracking.OutputPlace = Function.TidyText(node.SelectSingleNode("//thead[@class='tophead']//th[3]//span[1]").InnerText);
         tracking.InputPlace  = Function.TidyText(node.SelectSingleNode("//thead[@class='tophead']//th[3]//span[2]").InnerText);
         HtmlNodeCollection col         = node.SelectNodes("//tr");
         string             currentDate = "";
         int j = 0;
         for (int i = 2; i < col.Count; i++)
         {
             HtmlNode item = col[i];
             if (item.ParentNode.Name == "thead" && !string.IsNullOrEmpty(item.InnerText.Replace("\r", "").Replace("\n", "").Replace("\t", "")))
             {
                 currentDate = item.SelectSingleNode("./th[1]").InnerText.Trim();
             }
             else if (item.ParentNode.Name == "tbody")
             {
                 j++;
                 Movement movement = new Movement();
                 movement.Location = item.SelectSingleNode("./td[3]").InnerText.Trim();
                 movement.State    = item.SelectSingleNode("./td[2]").InnerText.Trim();
                 movement.Date     = currentDate + " " + item.SelectSingleNode("./td[4]").InnerText.Replace("at", ", ").Replace("  ", " ").Trim();
                 tracking.Movements.Insert(0, movement);
                 if (j == 1)
                 {
                     tracking.LastState = movement.State;
                     if (tracking.LastState.Contains("teslim edildi"))
                     {
                         string teslim = " - ";
                         try
                         {
                             teslim  = Function.TidyText(tracking.LastState.Split(':')[1].Trim());
                             teslim += " (" + movement.Date + ")";
                         }
                         catch (Exception) { }
                         tracking.Receiver = teslim;
                     }
                 }
             }
         }
         tracking.OutputDate = currentDate;
         return(tracking);
     }
     catch (Exception)
     {
         return(null);
     }
 }