Example #1
0
 private void WriteData(LiteStockInfo data)
 {
     Console.WriteLine($"[{pos}/{codeList.Count}]{data.Exchange}{data.Code}, {data.Name}, {data.Industry}");
     try
     {
         SqlServer.Instance.ExcuteSQL(new[]
         {
             new SqlCommand($"delete from StockIndustry where Code = '{data.Code}' and Exchange ='{data.Exchange}'"),
             new SqlCommand($"INSERT INTO StockIndustry(Code, Exchange, Name, Industry, ROE, IndustryROE, href) VALUES ('{data.Code}', '{data.Exchange}', '{data.Name}', '{data.Industry}', {data.ROE}, {data.IndustryROE}, '{data.Href}')")
         });
     }
     catch (Exception ex) { Console.WriteLine($"WriteData.Exception::{ex.Message}"); }
 }
Example #2
0
        private void Compute()
        {
            var doc = web.Document as mshtml.HTMLDocument;

            if (doc == null)
            {
                Console.WriteLine("doc is null.");
                return;
            }
            var name = doc.getElementById("name") == null ? string.Empty : doc.getElementById("name").innerText;

            IHTMLElement mainPanel = doc.getElementById("cwzbDataBox");

            LiteStockInfo si = new LiteStockInfo();

            if (mainPanel == null)
            {
                // 读取错误。
                Console.WriteLine("读取错误。");
                return;
            }
            int retryCount  = 0;
            var industry    = string.Empty;
            var roe         = string.Empty;
            var industryROE = string.Empty;
            var href        = "#";

retry:
            try
            {
                Thread.Sleep(50);
                industry    = (((mainPanel.children[1] as IHTMLElement).children[0] as IHTMLElement).children[0] as IHTMLElement).innerText;            // 行业
                roe         = ((mainPanel.children[0] as IHTMLElement).children[8] as IHTMLElement).innerText;                                          // ROE
                industryROE = ((mainPanel.children[1] as IHTMLElement).children[8] as IHTMLElement).innerText;                                          // 行业平均ROE
                href        = (((mainPanel.children[1] as IHTMLElement).children[0] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href"); // href
                if (industry == string.Empty)
                {
                    if (retryCount <= 5)
                    {
                        Thread.Sleep(100);
                        retryCount++;
                        goto retry;
                    }
                }
            }
            catch
            {
                if (retryCount <= 5)
                {
                    retryCount++;
                    goto retry;
                }
            }
            si.Name     = name;
            si.Code     = codeList[pos].Substring(2);
            si.Exchange = codeList[pos].Substring(0, 2);
            si.Industry = industry.Replace("%", string.Empty);
            decimal.TryParse(roe.Replace("%", string.Empty), out decimal _roe);
            si.ROE = _roe;
            decimal.TryParse(industryROE.Replace("%", string.Empty), out decimal _industryROE);
            si.IndustryROE = _industryROE;
            si.Href        = href;

            WriteData(si);
        }