Example #1
0
 private List<FlightForeign> getListFlights(bool IsRoundTrip)
 {
     List<FlightForeign> li = new List<FlightForeign>();
     try
     {
         bool isRoundTrip = true;
         if (blocks[0].inBound == null || blocks[0].inBound.Items == null || blocks[0].inBound.Items.Count == 0)
             isRoundTrip = false;
         if (IsRoundTrip != isRoundTrip)
             return li;
         int id = 0;
         if (IsRoundTrip)
         {
             foreach (ItemTemp it in blocks[0].outBound.Items)
             {
                 foreach (ItemTemp it1 in blocks[0].inBound.Items)
                 {
                     FlightForeign f = new FlightForeign();
                     f.Id = id;
                     id++;
                     f.Source = AirLineName.tiger;
                     //chieu di
                     OutInBoundForeign outBoundForeign = new OutInBoundForeign();
                     outBoundForeign.Segments = Convert2ListSegmentForeign(it.Segments);
                     f.outBoundForeign = outBoundForeign;
                     //chieu ve
                     OutInBoundForeign inBoundForeign = new OutInBoundForeign();
                     inBoundForeign.Segments = Convert2ListSegmentForeign(it1.Segments);
                     f.inBoundForeign = inBoundForeign;
                     li.Add(f);
                     f.PriceBaseOut = it.prices[0].price;
                     f.PriceBaseIn = it1.prices[0].price;
                 }
             }
         }
         else
         {
             foreach (ItemTemp it in blocks[0].outBound.Items)
             {
                 FlightForeign f = new FlightForeign();
                 f.Id = id;
                 id++;
                 f.Source = AirLineName.tiger;
                 //chieu di
                 OutInBoundForeign outBoundForeign = new OutInBoundForeign();
                 outBoundForeign.Segments = Convert2ListSegmentForeign(it.Segments);
                 f.outBoundForeign = outBoundForeign;
                 f.PriceBaseOut = it.prices[0].price;
                 li.Add(f);
             }
         }
     }
     catch { }
     return li;
 }
Example #2
0
        private List<SegmentForeign> getSegments(DateTime date, HtmlNode node, OutInBoundForeign outInBound)
        {
            if (node == null)
            {
                return null;
            }
            List<SegmentForeign> segments = new List<SegmentForeign>();
            SegmentForeign s = new SegmentForeign();
            HtmlNodeCollection nodeAirLines = node.SelectNodes("div[1]/div");
            if(nodeAirLines==null||nodeAirLines.Count==0)
                nodeAirLines = node.SelectNodes("div[1]");
            List<string> AirLines = new List<string>();
            foreach (HtmlNode node1 in nodeAirLines)
            {
                string t = node1.SelectSingleNode("img").Attributes["alt"].Value;
                AirLines.Add(t);
            }
            var note2 = node.SelectSingleNode("div[2]/div[4]");
            List<string> listFlightNo = getListFlightNo(note2.InnerText.Replace("\r\n", ""));
            HtmlNode nodeTemp = node.SelectSingleNode("div[2]/div[6]");
            List<HtmlNode> collectionSegments = nodeTemp.SelectNodes("div").Where(i => i.SelectNodes("b") != null).ToList();
            int indexAirLine = 0, indexFlyNo = 0;
            foreach (HtmlNode node11 in collectionSegments)
            {
                if (node11.InnerText.StartsWith("Layover: "))
                {
                    s.LayOver = node11.InnerText.Replace("Layover: ", "").Trim();
                    segments.Add(s);
                }
                else if (node11.InnerText.StartsWith("Total trip time: "))
                {
                    segments.Add(s);
                    outInBound.TotalTime = node11.InnerText.Replace("Total trip time: ", "").Trim();
                }
                else
                {
                    s = new SegmentForeign();
                    string t1 = node11.SelectSingleNode("b").InnerText;
                    int k = t1.IndexOf(" to ");
                    s.Departure = t1.Substring(0, k).Trim();
                    s.Arrive = t1.Substring(k + 4).Trim();
                    node11.RemoveChild(node11.SelectSingleNode("b"));
                    string detail = node11.InnerHtml.Replace("\r\n", " ").Replace("<br>", ",");
                    detail = detail.Replace("Depart", "");
                    detail = detail.Replace("Arrive", ",");
                    detail = detail.Replace("Duration:", "");
                    string[] details = detail.Split(',');
                    s.Class = details[1].Trim();
                    s.FlightNo = listFlightNo[indexFlyNo];
                    indexFlyNo++;
                    string layOver = "";
                    DateTime newDepartTime = date;
                    if (segments.Count > 0)
                    {
                        if (segments.Last().LayOver.Length > 6)
                        {
                            layOver = segments.Last().LayOver.Substring(segments.Last().LayOver.Length - 7);
                        }
                        newDepartTime = segments.Last().ArriveTime;
                    }
                    s.DepartureTime = DateTimeHelper.getDateAbacusDepartTime(newDepartTime, details[3], layOver);
                    s.Duration = details[5].Trim();
                    //lay ngay den
                    s.ArriveTime = DateTimeHelper.getDateAbacusArriveTime(s.DepartureTime, details[4].Trim());

                    s.AirLine = AirLines[indexAirLine];
                    indexAirLine++;
                    if (indexAirLine >= AirLines.Count)
                    {
                        indexAirLine = AirLines.Count - 1;
                    }
                }

            }
            return segments;
        }