Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htmlNode"></param>
        /// <returns></returns>
        private List<SegmentTemp> getListSegments(HtmlNode htmlNode)
        {
            List<SegmentTemp> liS = null;
            try
            {
                liS = new List<SegmentTemp>();
                int id = 1;
                try
                {
                    SegmentTemp prevS = null;
                    HtmlNodeCollection ncTable=htmlNode.SelectNodes(".//div[@class='stops-overlay']/table");
                    foreach (HtmlNode nodeS in ncTable)
                    {
                        HtmlNode nodeSTemp = nodeS.SelectSingleNode("tbody");
                        SegmentTemp s = new SegmentTemp();
                        s.flightNo = nodeSTemp.SelectSingleNode("tr[1]/td[2]").InnerText;
                        s.AirLine = s.flightNo.Substring(0, 2);
                        string departDate = nodeSTemp.SelectSingleNode("tr[2]/td[2]").InnerText;
                        string departTime=nodeSTemp.SelectSingleNode("tr[3]/td[2]").InnerText.Split('-')[1];
                        s.departureTime =DateTime.Parse(departDate+" "+departTime, CultureInfo.GetCultureInfo("en-gb"));
                        s.arriveTime = DateTime.Parse(departDate + nodeSTemp.SelectSingleNode("tr[4]/td[2]").InnerText.Split('-')[1], CultureInfo.GetCultureInfo("en-gb"));

                        s.Departure = nodeSTemp.SelectSingleNode("tr[3]/td[2]").InnerText.Split('-')[0];
                        s.Arrive = nodeSTemp.SelectSingleNode("tr[4]/td[2]").InnerText.Split('-')[0];
                        s.duration = nodeSTemp.SelectSingleNode("tr[5]/td[2]").InnerText;
                        if(prevS!=null)
                        {
                            prevS.layOver = nodeSTemp.SelectSingleNode("tr[6]/td[2]").InnerText; ;
                        }
                        //check lai ngay den
                        s.arriveTime =DateTimeHelper.getDateAbacusArriveTime(s.departureTime, s.arriveTime.ToString());
                        prevS = s;
                        s.Id = id;
                        liS.Add(s);
                        id++;
                    }
                }
                catch { }
            }
            catch { }
            return liS;
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htmlNode"></param>
        /// <returns></returns>
        private List<SegmentTemp> getListSegments(DateTime dateDepartReturn,HtmlNode htmlNode)
        {
            List<SegmentTemp> liS = null;
            try
            {
                liS = new List<SegmentTemp>();
                int id = 1;
                try
                {
                    HtmlNode nodeSpan = htmlNode.SelectSingleNode("div[1]/div[last()]/p/div[@class='block']/span[@class='hotspot']");
                    if (nodeSpan == null)
                        nodeSpan = htmlNode.SelectSingleNode("div[1]/div[last()]/p/div[@class='hotspot']");
                    string detailAllSegments = HttpUtility.HtmlDecode(nodeSpan.Attributes["onmouseover"].Value);
                    #region dinh dang xau
                    //bay thang
                    //                "javascript:SKYSALES.tooltip.show(\'<b>FD  642</b><br/><span style=\"font-size:10px;" +
                    //"\">Operated by Thai AirAsia</span></b><br/></b><br/>0700(DMK) - 0840(HAN)<br/>Est" +
                    //"imated flight time: 1 hours 40 minutes\',\'250\');"

                    //1 diem dung
                    //@"javascript:SKYSALES.tooltip.show('<b>FD  651</b><br/><span style=""font-size:10px;"">
                    //Operated by Thai AirAsia</span></b><br/></b><br/>0945(SGN) - 1110(DMK)<br/>
                    //Estimated flight time: 1 hours 25 minutes<br/><br/>
                    //Transit in Bangkok - Don Mueang : 2 hours 15 minutes<br/><br/>
                    //<b>FD  355</b><br/><span style=""font-size:10px;"">Operated by Thai AirAsia</span></b><br/>
                    //</b><br/>1325(DMK) - 1635(SIN)<br/>Estimated flight time: 2 hours 10 minutes','350');"
                    #endregion
                    //string pattern = @"<b>(?<FlightNo>\w{2}  \d+)</b>.+(?<DepartArrival>d{4}\(\w{3}\).{3}d{4}\(\w{3}\))"
                    //    + @".+imated flight time: (?<TotalHour>\d+) hours (?<TotalMin>\d)+ minutes.+"
                    //    + @"(Transit in (?<LayOver>\w+ - \w+) : (?<LayOverHour>\d+) hours (?<LayOverMin>\d+) minutes)*";
                    string patternFlyNo = @"<b>(?<FlightNo>\w{2}  \d+)</b>";
                    Regex regexFlyNo = new Regex(patternFlyNo);
                    string patternDepartReturn = @"(?<DepartTime>\d{4})\((?<DepartCode>\w{3})\) - (?<ArrivalTime>\d{4})\((?<ArrivalCode>\w{3})\)";
                    Regex regexDepartReturn = new Regex(patternDepartReturn);
                    string patternTotalTime = @"imated flight time: (?<TotalHour>\d+) hours (?<TotalMin>\d+) minutes";
                    Regex regexTotalTime = new Regex(patternTotalTime);
                    //Transit in Bangkok - Don Mueang : 2 hours 15 minutes
                    string patternLayOver = @"Transit in (?<LayOver>[\w\s]+ - [\w\s]+) : (?<LayOverHour>\d+) hours (?<LayOverMin>\d+) minutes";
                    Regex regexLayOver = new Regex(patternLayOver);
                    MatchCollection mcFlyNo = regexFlyNo.Matches(detailAllSegments);
                    MatchCollection mcDepartReturn = regexDepartReturn.Matches(detailAllSegments);
                    MatchCollection mcTotalTime = regexTotalTime.Matches(detailAllSegments);
                    MatchCollection mcLayOver = regexLayOver.Matches(detailAllSegments);
                    int index = 0;
                    foreach (Match m in mcFlyNo)
                    {
                        SegmentTemp s = new SegmentTemp();
                        s.flightNo = m.Groups["FlightNo"].Value;
                        s.AirLine = s.flightNo.Substring(0, 2);
                        s.duration = string.Format("{0}h{1}m", mcTotalTime[index].Groups["TotalHour"].Value, mcTotalTime[index].Groups["TotalMin"].Value);
                        if (mcLayOver != null && mcLayOver.Count > index)
                            s.layOver = string.Format("{0} - {1}h{2}m", mcLayOver[index].Groups["LayOver"].Value, mcLayOver[index].Groups["LayOverHour"].Value, mcLayOver[index].Groups["LayOverMin"].Value);
                        s.Departure = mcDepartReturn[index].Groups["DepartCode"].Value;
                        s.Arrive = mcDepartReturn[index].Groups["ArrivalCode"].Value;
                        string time=string.Format("{0}:{1}",mcDepartReturn[index].Groups["DepartTime"].Value.Substring(0,2),mcDepartReturn[index].Groups["DepartTime"].Value.Substring(2,2));
                        DateTime newDateDepartreturn = dateDepartReturn;
                        string layOver = "";
                        if (liS.Count > 0)
                        {
                            newDateDepartreturn = liS.Last().arriveTime;
                            layOver = liS.Last().layOver.Substring(liS.Last().layOver.IndexOf('@')+1);
                        }
                        s.departureTime = DateTimeHelper.getDateAbacusDepartTime(newDateDepartreturn,time,layOver);
                        time = string.Format("{0}:{1}", mcDepartReturn[index].Groups["ArrivalTime"].Value.Substring(0, 2), mcDepartReturn[index].Groups["ArrivalTime"].Value.Substring(2, 2));
                        s.arriveTime = DateTimeHelper.getDateAbacusArriveTime(s.departureTime, time);
                        index++;
                        s.Id = id;
                        liS.Add(s);
                    }
                    id++;
                }
                catch { }
            }
            catch { }
            return liS;
        }