• 大小: 0.37M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-27
  • 语言: C#
  • 标签: 股票  获取  

资源简介

能够实时获取股票数据

资源截图

代码片段和文件信息

using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string one;
        private void button1_Click(object sender EventArgs e)
        {
           
           // try
            //{
                one = (textBox1.Text.Substring(0 3));
                if (one == “600“ || one == “601“ || one == “603“ || one == “900“)
                {
                    one = “sh“ + textBox1.Text;
                   
                    timer1.Start();
                }
                else if (one == “000“ || one == “200“)
                {
                    one = “sz“ + textBox1.Text;
                   
                    timer1.Start();
                }
                else
                {
                    //textBox1.Text = “请输入股票代码“;
                }

           // }
            //catch
           // {
              //  textBox1.Text = “请输入股票代码“;
            //}
        }
        private void getHTMLbyWebRequest(string strUrl)
        {
            Encoding encoding = System.Text.Encoding.Default;
            WebRequest request = WebRequest.Create(strUrl);
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);//导入gb2312
            encoding = Encoding.GetEncoding(“GB2312“);//貌似用GB2312就可以
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream encoding);
            string responseFromServer = reader.ReadToEnd();
            responseFromServer=responseFromServer.Replace(“var hq_str_“““);
            responseFromServer = responseFromServer.Trim().Replace(“00\“;“ ““);
            responseFromServer = responseFromServer.Replace(“=\““ ““);            
            string[] strn = responseFromServer.Split(‘‘);
            string[] strm = {“代码:““名称:““今日开盘价:““昨日收盘价:““当前价格:““今日最高价:““今日最低价:““竞买价,即“买一”报价:““竞卖价,即“卖一”报价:““成交的股票数:““成交金额:““买一:““买一价:““买二:““买二价:““买三:““买三价:“
                     “买四:““买四价:““买五:““买五价:““卖一:““卖一价:““卖二:““卖二价:““卖三:““卖三价:““卖四:““卖四价:““卖五:““卖五价:““日期:““时间:“};
            Hashtable hs = new Hashtable();
            for(int i = 0; i < strm.Length; i++)
            {
                hs.Add(strm[i] strn[i]); 
            }
            int j = 0;
            foreach (System.Windows.Forms.Control control in this.Controls)//遍历groupBox2上的所有控件   

            {
                if (control is System.Windows.Forms.Label)

                {
                    if (j < strm.Length) { 
                    control.Text = strm[j]+strn[j];
                    j++;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-11-05 17:12  WindowsFormsApp2\
     目录           0  2020-11-05 10:42  WindowsFormsApp2\.vs\
     目录           0  2020-11-05 13:38  WindowsFormsApp2\.vs\WindowsFormsApp2\
     目录           0  2020-11-05 13:38  WindowsFormsApp2\.vs\WindowsFormsApp2\DesignTimeBuild\
     文件       72664  2020-11-05 13:38  WindowsFormsApp2\.vs\WindowsFormsApp2\DesignTimeBuild\.dtbcache.v2
     目录           0  2020-11-05 10:42  WindowsFormsApp2\.vs\WindowsFormsApp2\v16\
     文件       33280  2020-11-05 17:12  WindowsFormsApp2\.vs\WindowsFormsApp2\v16\.suo
     文件       20984  2020-11-05 17:12  WindowsFormsApp2\Form1.Designer.cs
     文件        4437  2020-11-05 15:21  WindowsFormsApp2\Form1.cs
     文件        2816  2020-11-05 15:21  WindowsFormsApp2\Form1.resx
     文件         603  2020-11-05 10:42  WindowsFormsApp2\Program.cs
     目录           0  2020-11-05 15:20  WindowsFormsApp2\Properties\
     目录           0  2020-11-05 15:21  WindowsFormsApp2\Properties\PublishProfiles\
     文件         431  2020-11-05 15:21  WindowsFormsApp2\Properties\PublishProfiles\FolderProfile.pubxml
     文件         203  2020-11-05 15:21  WindowsFormsApp2\Properties\PublishProfiles\FolderProfile.pubxml.user
     文件         242  2020-11-05 10:42  WindowsFormsApp2\WindowsFormsApp2.csproj
     文件         452  2020-11-05 15:21  WindowsFormsApp2\WindowsFormsApp2.csproj.user
     文件        1137  2020-11-05 10:42  WindowsFormsApp2\WindowsFormsApp2.sln
     目录           0  2020-11-05 15:21  WindowsFormsApp2\bin\
     目录           0  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\
     目录           0  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\
     文件         440  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\WindowsFormsApp2.deps.json
     文件       15872  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\WindowsFormsApp2.dll
     文件      174592  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\WindowsFormsApp2.exe
     文件       13800  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\WindowsFormsApp2.pdb
     文件         190  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\WindowsFormsApp2.runtimeconfig.dev.json
     文件         161  2020-11-05 15:20  WindowsFormsApp2\bin\Debug\netcoreapp3.1\WindowsFormsApp2.runtimeconfig.json
     目录           0  2020-11-05 15:21  WindowsFormsApp2\bin\Release\
     目录           0  2020-11-05 15:21  WindowsFormsApp2\bin\Release\netcoreapp3.1\
     文件         440  2020-11-05 15:21  WindowsFormsApp2\bin\Release\netcoreapp3.1\WindowsFormsApp2.deps.json
     文件       15360  2020-11-05 15:21  WindowsFormsApp2\bin\Release\netcoreapp3.1\WindowsFormsApp2.dll
............此处省略44个文件信息

评论

共有 条评论