Esempio n. 1
0
        public void PopulateETFStatDetails(Share s, HtmlDocument doc)
        {
            ETFInfo info = new ETFInfo();

            var profileTableQuery = from t in doc.DocumentNode.Descendants("table")
                                    where t.Id == "yfncsumtab"
                                    select t;

            var profileTable = profileTableQuery.FirstOrDefault();

            if (profileTable != null)
            {
                var businessSummaryTableQuery = from t in profileTable.Descendants("table")
                                                where t.InnerText.Contains("Fund Overview")
                                                select t;
                var businessSummaryTable = businessSummaryTableQuery.FirstOrDefault();

                if (businessSummaryTable != null)
                {
                    var fundDetailTable = businessSummaryTable.NextSibling;

                    if (fundDetailTable != null)
                    {
                        var trLine = from tr in fundDetailTable.Descendants("tr")
                                     select tr;

                        var trLineArray = trLine.ToArray();

                        info.Category   = HttpUtility.HtmlDecode(trLineArray[1].LastChild.InnerText);
                        info.FundFamily = HttpUtility.HtmlDecode(trLineArray[2].LastChild.InnerText);

                        var netAssetString = HttpUtility.HtmlDecode(trLineArray[3].LastChild.InnerText);

                        netAssetString = netAssetString.Replace("M", "");

                        double netAsset;

                        if (double.TryParse(netAssetString, out netAsset))
                        {
                            info.NetAssetM = netAsset;
                        }


                        var yieldString = HttpUtility.HtmlDecode(trLineArray[4].LastChild.InnerText);

                        yieldString = yieldString.Replace("%", "");

                        double yield;

                        if (double.TryParse(yieldString, out yield))
                        {
                            info.YieldPercentage = yield;
                        }
                        info.InceptionDate = HttpUtility.HtmlDecode(trLineArray[5].LastChild.InnerText);
                    }

                    Share s2 = _sBLL.GetByID(s.Id);
                    s2.Industry = info.Category;
                    _sBLL.Update(s2);

                    ETFInfoBLL eBLL   = new ETFInfoBLL(_unit);
                    ETFInfo    eInfo2 = eBLL.GetByShareID(s.Id);

                    if (eInfo2 != null)
                    {
                        eInfo2.Category        = info.Category;
                        eInfo2.FundFamily      = info.FundFamily;
                        eInfo2.InceptionDate   = info.InceptionDate;
                        eInfo2.NetAssetM       = info.NetAssetM;
                        eInfo2.YieldPercentage = info.YieldPercentage;

                        eBLL.Update(eInfo2);
                    }
                    else
                    {
                        eInfo2         = info;
                        eInfo2.ShareId = s.Id;
                        eBLL.Create(eInfo2);
                    }
                }
            }
        }