示例#1
0
 private static int getNtpiCategoryIdDb(NTPICategory x)
 {
     if (x != null && x.Name != null)
     {
         using (IDbConnection db = DBConnectionHelper.getConnection()){
             NTPICategory z = db.QueryFirstOrDefault <NTPICategory>(
                 "select * from NearestTransitPoint_Category where name like @name",
                 new { name = x.Name }
                 );
             if (z != null)
             {
                 return(z.Id);
             }
         }
     }
     return(0);
 }
        private List <NTPICategory> getNTPI(HtmlNode row)
        {
            List <NTPICategory> ntpiCategoryList = new List <NTPICategory>();

            if (row != null)
            {
                HtmlNodeCollection transportNodes = row.SelectNodes(".//div[contains(@class, \"transportationDetail\")]");
                if (transportNodes != null)
                {
                    foreach (HtmlNode transportNode in transportNodes)
                    {
                        string       transportCategory = "";
                        NTPICategory ntpiCategory      = new NTPICategory();
                        ntpiCategory.NtpiList = new List <NTPI>();
                        HtmlNode categoryNode = transportNode.SelectSingleNode(".//thead/tr/th[1]");
                        if (categoryNode != null)
                        {
                            transportCategory = categoryNode.ChildNodes[1].InnerHtml.Trim();
                        }
                        ntpiCategory.Name     = transportCategory;
                        ntpiCategory.NtpiList = new List <NTPI>();
                        foreach (HtmlNode trNode in transportNode.SelectNodes(".//tbody/tr"))
                        {
                            NTPI ntpi = new NTPI();
                            ntpi.PropNTPIMapping = new List <PropertyNTPIMapping>();
                            PropertyNTPIMapping propNTPIMap = new PropertyNTPIMapping();
                            propNTPIMap.Property = myUrl.property;
                            //ntpi.category = transportCategory;

                            HtmlNode tdDrive = trNode.SelectSingleNode(".//td[2]");
                            if (tdDrive != null)
                            {
                                ntpi.Drive = Util.parseDouble(tdDrive.InnerHtml.Trim().Split(" ")[0], 0);
                            }

                            HtmlNode tdDistance = trNode.SelectSingleNode(".//td[3]");
                            if (tdDistance != null)
                            {
                                ntpi.distance = Util.parseDouble(tdDistance.InnerHtml.Trim().Split(" ")[0], 0);
                            }

                            HtmlNode transportationNameNode = trNode.SelectSingleNode(".//div[contains(@class, \"transportationName\")]");
                            if (transportationNameNode != null)
                            {
                                HtmlNode transportationNameNodeA = transportationNameNode.SelectSingleNode(".//a");
                                if (transportationNameNodeA != null)
                                {
                                    ntpi.name = transportationNameNodeA.InnerHtml.Trim();
                                }
                                else
                                {
                                    ntpi.name = transportationNameNode.InnerHtml.Trim();
                                }
                            }
                            ntpi.PropNTPIMapping.Add(propNTPIMap);
                            ntpiCategory.NtpiList.Add(ntpi);
                        }
                        ntpiCategoryList.Add(ntpiCategory);
                    }
                }
            }
            return(ntpiCategoryList);
        }