public void UpdateStockBase(StockBase stock)
 {
     using (var context = ContainerHelper.Instance.Resolve<IRepositoryContext>())
     {
         //添加新的股票基础数据
         context.UnitOfWork.RegisterModified<StockBase>(stock);
         context.UnitOfWork.Commit();
     }
 }
Beispiel #2
0
        public void RefreshStockBase()
        {
            StockBase stockBase = stockservice.GetStockBaseBySymbol(m_Symbol);

            var request = WebRequest.Create(m_EastUrl) as HttpWebRequest;
            var response = request.GetResponse() as HttpWebResponse;
            var sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
            string html = sr.ReadToEnd();

            bool newStockBase = false;
            if (stockBase == null)
            {
                newStockBase = true;
                stockBase = new StockBase();
            }

            string reg = @"<title>.*?</title>";
            string name = Regex.Match(html, reg).Value.Split(new string[] { @"title>" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</title>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">上市时间</td><td class=""vds"">.*?</td>";
            string listingDate = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">总股本</td><td class=""vds""><span id=""prozgb"" .*?></span>.*?</td>";
            string totalCapital = Regex.Match(html, reg).Value.Split(new string[] { @"</span>" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">流通股</td><td class=""vds ls""><span id=""proltgb"" .*?></span>.*?</td>";
            string floatingCapital = Regex.Match(html, reg).Value.Split(new string[] { @"</span>" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd""><a href=.*? target=""_blank"">每股收益(.*?一.*?)</a></td><td class=""vds"">.*?</td>";
            string epsOne = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd""><a href=.*? target=""_blank"">每股净资产</a></td><td class=""vds"">.*?</td>";
            string naps = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd""><a href=.*? target=""_blank"">净资产收益率</a></td>\r\n.*?\t.*?<td>.*?</td>";
            string roe = Regex.Match(html, reg).Value.Split(new string[] { @"<td>" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">营业收入</td><td class=""vds"">.*?</td>";
            string br = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd""><a href=.*? target=""_blank"">营业收入增长率</a></td><td class=""vds"">.*?</td>";
            string irbr = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd""><a href=.*? target=""_blank"">销售毛利率</a></td><td class=""vds ls"">.*?</td>";
            string profitmargi = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds ls"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">净利润</td><td class=""vds"">.*?</td>";
            string np = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">净利润增长率</td><td class=""vds"">.*?</td>";
            string irnp = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];
            reg = @"<td class=""hd"">每股未分配利润</td><td class=""vds ls"">.*?</td></tr>";
            string upps = Regex.Match(html, reg).Value.Split(new string[] { @"<td class=""vds ls"">" }, StringSplitOptions.RemoveEmptyEntries)[1].Split(new string[] { @"</td>" }, StringSplitOptions.RemoveEmptyEntries)[0];

            stockBase.Symbol = m_Symbol;
            stockBase.Name = name.Split('(')[0];
            stockBase.ListingDate = Convert.ToDateTime(listingDate);
            stockBase.TotalCapital = ChangeUnit(totalCapital);
            stockBase.FloatingCapital = ChangeUnit(floatingCapital);
            stockBase.EPSOne = ChangeUnit(epsOne);
            stockBase.NAPS = ChangeUnit(naps);
            stockBase.ROE = ChangeUnit(roe);
            stockBase.BR = ChangeUnit(br);
            stockBase.IRBR = ChangeUnit(irbr);
            stockBase.Profitmargi = ChangeUnit(profitmargi);
            stockBase.NP = ChangeUnit(np);
            stockBase.IRNP = ChangeUnit(irnp);
            stockBase.UPPS = ChangeUnit(upps);

            if (newStockBase)
            {
                stockservice.ImportStockBase(stockBase);
            }
            else
            {
                stockservice.UpdateStockBase(stockBase);
            }
        }