private List<SegmentForeign> Convert2ListSegmentForeign(List<SegmentTemp> list)
 {
     List<SegmentForeign> li = new List<SegmentForeign>();
     foreach (SegmentTemp st in list)
     {
         SegmentForeign s = new SegmentForeign();
         s.AirLine = st.AirLine;
         s.Departure = st.Departure;
         s.Arrive = st.Arrive;
         s.FlightNo = st.flightNo;
         s.DepartureTime = st.departureTime;
         s.ArriveTime = st.arriveTime;
         s.LayOver = st.layOver;
         s.Class = st.Class;
         s.Duration = st.duration;
         li.Add(s);
     }
     return li;
 }
Beispiel #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;
        }