Ejemplo n.º 1
0
        public void WriteData(IndustryInfo data)
        {
            var cmd = new SqlCommand($"INSERT INTO IndustryRanking(Code, Exchange, Name, Industry, Rank) VALUES (@Code, @Exchange, @Name, @Industry, @Rank)");

            cmd.Parameters.AddRange(new[] {
                new SqlParameter("@Code", data.Code),
                new SqlParameter("@Exchange", data.Exchange.ToString()),
                new SqlParameter("@Name", data.Name),
                new SqlParameter("@Industry", data.Industry),
                new SqlParameter("@Rank", data.Rank)
            });

            SqlServer.Instance.ExcuteSQL(new [] {
                new SqlCommand($"delete from IndustryRanking where Code = '{data.Code}' and Exchange='{data.Exchange}'"),
                cmd
            });
        }
Ejemplo n.º 2
0
        private void Compute()
        {
            var industry = string.Empty;

            Thread.Sleep(300);

            var doc = web.Document as mshtml.HTMLDocument;

            if (doc == null)
            {
                Console.WriteLine("doc is null.");
                return;
            }
            IHTMLElement mainPanel = doc.getElementById("sfw_table");

            if (mainPanel == null)
            {
                // 读取错误。
                Console.WriteLine("读取错误。");
                return;
            }
            var title = doc.getElementsByTagName("span");

            foreach (IHTMLElement child in title)
            {
                if (child.className != null && child.className.Contains("quote_title_0"))
                {
                    industry = child.innerText;
                }
            }

            IndustryInfo si = new IndustryInfo();

            si.Name = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[1] as IHTMLElement).children[0] as IHTMLElement).innerText;
            var r1CodeString = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[1] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href").ToString().Replace("http://quote.eastmoney.com/", string.Empty).Replace(".html", string.Empty);

            si.Exchange = r1CodeString.Substring(0, 2);
            si.Code     = r1CodeString.Substring(2);
            si.Rank     = 1;
            si.Industry = industry;
            WriteData(si);

            si.Name = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[2] as IHTMLElement).children[0] as IHTMLElement).innerText;
            var r2CodeString = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[2] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href").ToString().Replace("http://quote.eastmoney.com/", string.Empty).Replace(".html", string.Empty);

            si.Exchange = r2CodeString.Substring(0, 2);
            si.Code     = r2CodeString.Substring(2);
            si.Rank     = 2;
            WriteData(si);

            si.Name = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[3] as IHTMLElement).children[0] as IHTMLElement).innerText;
            var r3CodeString = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[3] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href").ToString().Replace("http://quote.eastmoney.com/", string.Empty).Replace(".html", string.Empty);

            si.Exchange = r3CodeString.Substring(0, 2);
            si.Code     = r3CodeString.Substring(2);
            si.Rank     = 3;
            WriteData(si);

            si.Name = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[4] as IHTMLElement).children[0] as IHTMLElement).innerText;
            var r4CodeString = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[4] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href").ToString().Replace("http://quote.eastmoney.com/", string.Empty).Replace(".html", string.Empty);

            si.Exchange = r4CodeString.Substring(0, 2);
            si.Code     = r4CodeString.Substring(2);
            si.Rank     = 4;
            WriteData(si);

            si.Name = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[5] as IHTMLElement).children[0] as IHTMLElement).innerText;
            var r5CodeString = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[5] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href").ToString().Replace("http://quote.eastmoney.com/", string.Empty).Replace(".html", string.Empty);

            si.Exchange = r5CodeString.Substring(0, 2);
            si.Code     = r5CodeString.Substring(2);
            si.Rank     = 5;
            WriteData(si);

            si.Name = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[6] as IHTMLElement).children[0] as IHTMLElement).innerText;
            var r6CodeString = ((((mainPanel.children[0] as IHTMLElement).children[0] as IHTMLElement).children[6] as IHTMLElement).children[0] as IHTMLElement).getAttribute("href").ToString().Replace("http://quote.eastmoney.com/", string.Empty).Replace(".html", string.Empty);

            si.Exchange = r6CodeString.Substring(0, 2);
            si.Code     = r6CodeString.Substring(2);
            si.Rank     = 6;
            WriteData(si);
        }