769 lines
48 KiB
C#
769 lines
48 KiB
C#
using DevExpress.XtraEditors;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.Entity.Migrations;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using DevExpress.Data.Helpers;
|
|
using MES;
|
|
using MES.Entity;
|
|
using WinformGeneralDeveloperFrame.Commons;
|
|
|
|
namespace WinformGeneralDeveloperFrame
|
|
{
|
|
public partial class Test : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
private bool flag = false;
|
|
public Test()
|
|
{
|
|
InitializeComponent();
|
|
GetData();
|
|
}
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
var data = memoEdit1.Text.Split(")".ToCharArray());
|
|
List<stockInfo> list = new List<stockInfo>();
|
|
foreach (var item in data)
|
|
{
|
|
var dd = item.Split("(".ToCharArray());
|
|
if(dd.Length!=2)continue;
|
|
stockInfo info = new stockInfo() { name = dd[0].Replace("\"",""), code = "sz" + dd[1] };
|
|
list.Add(info);
|
|
}
|
|
using (var db = new MESDB())
|
|
{
|
|
db.stockInfo.AddRange(list);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
|
|
private void GetData()
|
|
{
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
while (true)
|
|
{
|
|
if (flag)
|
|
{
|
|
var t1 = Task.Factory.StartNew(() =>
|
|
{
|
|
try
|
|
{
|
|
string url = "http://hq.sinajs.cn/list={0}";
|
|
var list = new MESDB().stockInfo.ToList().Skip(0).Take(200);
|
|
string code = "";
|
|
foreach (var stockInfo in list)
|
|
{
|
|
code += stockInfo.code + ",";
|
|
}
|
|
url = string.Format(url, code);
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
request.Method = "GET";
|
|
request.ContentType = "text/html;charset=UTF-8";
|
|
request.UserAgent = null;
|
|
request.Timeout = 6000;
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
string retString = myStreamReader.ReadToEnd();
|
|
string[] ResData = retString.Split(';');
|
|
List<stockInfo> list1 = new List<stockInfo>();
|
|
foreach (var item in ResData)
|
|
{
|
|
var data = item.Split('=');
|
|
if (data.Length == 2)
|
|
{
|
|
var dd = data[1].Split(',');
|
|
if (dd.Length >= 33)
|
|
{
|
|
stockInfo info = new stockInfo()
|
|
{
|
|
code = data[0].Split('_')[2],
|
|
name = dd[0].Replace("\"", ""),
|
|
startPrice = decimal.Parse(dd[1]),
|
|
olePrice = decimal.Parse(dd[2]),
|
|
nowPrice = decimal.Parse(dd[3]),
|
|
maxPrice = decimal.Parse(dd[4]),
|
|
minPrice = decimal.Parse(dd[5]),
|
|
bidderPrice = decimal.Parse(dd[6]),
|
|
auctionPrice = decimal.Parse(dd[7]),
|
|
turnover = int.Parse(dd[8]),
|
|
turnoverPrice = decimal.Parse(dd[9]),
|
|
buyOneNum = int.Parse(dd[10]),
|
|
buyOnePrice = decimal.Parse(dd[11]),
|
|
buyTwoNum = int.Parse(dd[12]),
|
|
buyTwoPrice = decimal.Parse(dd[13]),
|
|
buyThreeNum = int.Parse(dd[14]),
|
|
buyThreePrice = decimal.Parse(dd[15]),
|
|
buyFourNum = int.Parse(dd[16]),
|
|
buyFourPrice = decimal.Parse(dd[17]),
|
|
buyFiveNum = int.Parse(dd[18]),
|
|
buyFivePrice = decimal.Parse(dd[19]),
|
|
sellOneNum = int.Parse(dd[20]),
|
|
sellOnePrice = decimal.Parse(dd[21]),
|
|
sellTwoNum = int.Parse(dd[22]),
|
|
sellTwoPrice = decimal.Parse(dd[23]),
|
|
sellThreeNum = int.Parse(dd[24]),
|
|
sellThreePrice = decimal.Parse(dd[25]),
|
|
sellFourNum = int.Parse(dd[26]),
|
|
sellFourPrice = decimal.Parse(dd[27]),
|
|
sellFiveNum = int.Parse(dd[28]),
|
|
sellFivePrice = decimal.Parse(dd[29]),
|
|
timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
};
|
|
list1.Add(info);
|
|
}
|
|
}
|
|
}
|
|
using (var db = new MESDB())
|
|
{
|
|
foreach (var info in list1)
|
|
{
|
|
db.stockInfo.AddOrUpdate(info);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.Message.ShowError();
|
|
}
|
|
});
|
|
//var t2 = Task.Factory.StartNew(() =>
|
|
//{
|
|
// try
|
|
// {
|
|
// string url = "http://hq.sinajs.cn/list={0}";
|
|
// var list = new MESDB().stockInfo.ToList().Skip(500).Take(500);
|
|
// string code = "";
|
|
// foreach (var stockInfo in list)
|
|
// {
|
|
// code += stockInfo.code + ",";
|
|
// }
|
|
// url = string.Format(url, code);
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
// request.Method = "GET";
|
|
// request.ContentType = "text/html;charset=UTF-8";
|
|
// request.UserAgent = null;
|
|
// request.Timeout = 6000;
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
// string retString = myStreamReader.ReadToEnd();
|
|
// string[] ResData = retString.Split(';');
|
|
// List<stockInfo> list1 = new List<stockInfo>();
|
|
// foreach (var item in ResData)
|
|
// {
|
|
// var data = item.Split('=');
|
|
// if (data.Length == 2)
|
|
// {
|
|
// var dd = data[1].Split(',');
|
|
// if (dd.Length >= 33)
|
|
// {
|
|
// stockInfo info = new stockInfo()
|
|
// {
|
|
// code = data[0].Split('_')[2],
|
|
// name = dd[0].Replace("\"", ""),
|
|
// startPrice = decimal.Parse(dd[1]),
|
|
// olePrice = decimal.Parse(dd[2]),
|
|
// nowPrice = decimal.Parse(dd[3]),
|
|
// maxPrice = decimal.Parse(dd[4]),
|
|
// minPrice = decimal.Parse(dd[5]),
|
|
// bidderPrice = decimal.Parse(dd[6]),
|
|
// auctionPrice = decimal.Parse(dd[7]),
|
|
// turnover = int.Parse(dd[8]),
|
|
// turnoverPrice = decimal.Parse(dd[9]),
|
|
// buyOneNum = int.Parse(dd[10]),
|
|
// buyOnePrice = decimal.Parse(dd[11]),
|
|
// buyTwoNum = int.Parse(dd[12]),
|
|
// buyTwoPrice = decimal.Parse(dd[13]),
|
|
// buyThreeNum = int.Parse(dd[14]),
|
|
// buyThreePrice = decimal.Parse(dd[15]),
|
|
// buyFourNum = int.Parse(dd[16]),
|
|
// buyFourPrice = decimal.Parse(dd[17]),
|
|
// buyFiveNum = int.Parse(dd[18]),
|
|
// buyFivePrice = decimal.Parse(dd[19]),
|
|
// sellOneNum = int.Parse(dd[20]),
|
|
// sellOnePrice = decimal.Parse(dd[21]),
|
|
// sellTwoNum = int.Parse(dd[22]),
|
|
// sellTwoPrice = decimal.Parse(dd[23]),
|
|
// sellThreeNum = int.Parse(dd[24]),
|
|
// sellThreePrice = decimal.Parse(dd[25]),
|
|
// sellFourNum = int.Parse(dd[26]),
|
|
// sellFourPrice = decimal.Parse(dd[27]),
|
|
// sellFiveNum = int.Parse(dd[28]),
|
|
// sellFivePrice = decimal.Parse(dd[29]),
|
|
// timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
// };
|
|
// list1.Add(info);
|
|
// }
|
|
// }
|
|
// }
|
|
// using (var db = new MESDB())
|
|
// {
|
|
// foreach (var info in list1)
|
|
// {
|
|
// db.stockInfo.AddOrUpdate(info);
|
|
// }
|
|
// db.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.Message.ShowError();
|
|
// }
|
|
//});
|
|
//var t3 = Task.Factory.StartNew(() =>
|
|
//{
|
|
// try
|
|
// {
|
|
// string url = "http://hq.sinajs.cn/list={0}";
|
|
// var list = new MESDB().stockInfo.ToList().Skip(1000).Take(500);
|
|
// string code = "";
|
|
// foreach (var stockInfo in list)
|
|
// {
|
|
// code += stockInfo.code + ",";
|
|
// }
|
|
// url = string.Format(url, code);
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
// request.Method = "GET";
|
|
// request.ContentType = "text/html;charset=UTF-8";
|
|
// request.UserAgent = null;
|
|
// request.Timeout = 6000;
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
// string retString = myStreamReader.ReadToEnd();
|
|
// string[] ResData = retString.Split(';');
|
|
// List<stockInfo> list1 = new List<stockInfo>();
|
|
// foreach (var item in ResData)
|
|
// {
|
|
// var data = item.Split('=');
|
|
// if (data.Length == 2)
|
|
// {
|
|
// var dd = data[1].Split(',');
|
|
// if (dd.Length >= 33)
|
|
// {
|
|
// stockInfo info = new stockInfo()
|
|
// {
|
|
// code = data[0].Split('_')[2],
|
|
// name = dd[0].Replace("\"", ""),
|
|
// startPrice = decimal.Parse(dd[1]),
|
|
// olePrice = decimal.Parse(dd[2]),
|
|
// nowPrice = decimal.Parse(dd[3]),
|
|
// maxPrice = decimal.Parse(dd[4]),
|
|
// minPrice = decimal.Parse(dd[5]),
|
|
// bidderPrice = decimal.Parse(dd[6]),
|
|
// auctionPrice = decimal.Parse(dd[7]),
|
|
// turnover = int.Parse(dd[8]),
|
|
// turnoverPrice = decimal.Parse(dd[9]),
|
|
// buyOneNum = int.Parse(dd[10]),
|
|
// buyOnePrice = decimal.Parse(dd[11]),
|
|
// buyTwoNum = int.Parse(dd[12]),
|
|
// buyTwoPrice = decimal.Parse(dd[13]),
|
|
// buyThreeNum = int.Parse(dd[14]),
|
|
// buyThreePrice = decimal.Parse(dd[15]),
|
|
// buyFourNum = int.Parse(dd[16]),
|
|
// buyFourPrice = decimal.Parse(dd[17]),
|
|
// buyFiveNum = int.Parse(dd[18]),
|
|
// buyFivePrice = decimal.Parse(dd[19]),
|
|
// sellOneNum = int.Parse(dd[20]),
|
|
// sellOnePrice = decimal.Parse(dd[21]),
|
|
// sellTwoNum = int.Parse(dd[22]),
|
|
// sellTwoPrice = decimal.Parse(dd[23]),
|
|
// sellThreeNum = int.Parse(dd[24]),
|
|
// sellThreePrice = decimal.Parse(dd[25]),
|
|
// sellFourNum = int.Parse(dd[26]),
|
|
// sellFourPrice = decimal.Parse(dd[27]),
|
|
// sellFiveNum = int.Parse(dd[28]),
|
|
// sellFivePrice = decimal.Parse(dd[29]),
|
|
// timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
// };
|
|
// list1.Add(info);
|
|
// }
|
|
// }
|
|
// }
|
|
// using (var db = new MESDB())
|
|
// {
|
|
// foreach (var info in list1)
|
|
// {
|
|
// db.stockInfo.AddOrUpdate(info);
|
|
// }
|
|
// db.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.Message.ShowError();
|
|
// }
|
|
//});
|
|
//var t4 = Task.Factory.StartNew(() =>
|
|
//{
|
|
// try
|
|
// {
|
|
// string url = "http://hq.sinajs.cn/list={0}";
|
|
// var list = new MESDB().stockInfo.ToList().Skip(1500).Take(500);
|
|
// string code = "";
|
|
// foreach (var stockInfo in list)
|
|
// {
|
|
// code += stockInfo.code + ",";
|
|
// }
|
|
// url = string.Format(url, code);
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
// request.Method = "GET";
|
|
// request.ContentType = "text/html;charset=UTF-8";
|
|
// request.UserAgent = null;
|
|
// request.Timeout = 6000;
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
// string retString = myStreamReader.ReadToEnd();
|
|
// string[] ResData = retString.Split(';');
|
|
// List<stockInfo> list1 = new List<stockInfo>();
|
|
// foreach (var item in ResData)
|
|
// {
|
|
// var data = item.Split('=');
|
|
// if (data.Length == 2)
|
|
// {
|
|
// var dd = data[1].Split(',');
|
|
// if (dd.Length >= 33)
|
|
// {
|
|
// stockInfo info = new stockInfo()
|
|
// {
|
|
// code = data[0].Split('_')[2],
|
|
// name = dd[0].Replace("\"", ""),
|
|
// startPrice = decimal.Parse(dd[1]),
|
|
// olePrice = decimal.Parse(dd[2]),
|
|
// nowPrice = decimal.Parse(dd[3]),
|
|
// maxPrice = decimal.Parse(dd[4]),
|
|
// minPrice = decimal.Parse(dd[5]),
|
|
// bidderPrice = decimal.Parse(dd[6]),
|
|
// auctionPrice = decimal.Parse(dd[7]),
|
|
// turnover = int.Parse(dd[8]),
|
|
// turnoverPrice = decimal.Parse(dd[9]),
|
|
// buyOneNum = int.Parse(dd[10]),
|
|
// buyOnePrice = decimal.Parse(dd[11]),
|
|
// buyTwoNum = int.Parse(dd[12]),
|
|
// buyTwoPrice = decimal.Parse(dd[13]),
|
|
// buyThreeNum = int.Parse(dd[14]),
|
|
// buyThreePrice = decimal.Parse(dd[15]),
|
|
// buyFourNum = int.Parse(dd[16]),
|
|
// buyFourPrice = decimal.Parse(dd[17]),
|
|
// buyFiveNum = int.Parse(dd[18]),
|
|
// buyFivePrice = decimal.Parse(dd[19]),
|
|
// sellOneNum = int.Parse(dd[20]),
|
|
// sellOnePrice = decimal.Parse(dd[21]),
|
|
// sellTwoNum = int.Parse(dd[22]),
|
|
// sellTwoPrice = decimal.Parse(dd[23]),
|
|
// sellThreeNum = int.Parse(dd[24]),
|
|
// sellThreePrice = decimal.Parse(dd[25]),
|
|
// sellFourNum = int.Parse(dd[26]),
|
|
// sellFourPrice = decimal.Parse(dd[27]),
|
|
// sellFiveNum = int.Parse(dd[28]),
|
|
// sellFivePrice = decimal.Parse(dd[29]),
|
|
// timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
// };
|
|
// list1.Add(info);
|
|
// }
|
|
// }
|
|
// }
|
|
// using (var db = new MESDB())
|
|
// {
|
|
// foreach (var info in list1)
|
|
// {
|
|
// db.stockInfo.AddOrUpdate(info);
|
|
// }
|
|
// db.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.Message.ShowError();
|
|
// }
|
|
//});
|
|
//var t5 = Task.Factory.StartNew(() =>
|
|
//{
|
|
// try
|
|
// {
|
|
// string url = "http://hq.sinajs.cn/list={0}";
|
|
// var list = new MESDB().stockInfo.ToList().Skip(2000).Take(500);
|
|
// string code = "";
|
|
// foreach (var stockInfo in list)
|
|
// {
|
|
// code += stockInfo.code + ",";
|
|
// }
|
|
// url = string.Format(url, code);
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
// request.Method = "GET";
|
|
// request.ContentType = "text/html;charset=UTF-8";
|
|
// request.UserAgent = null;
|
|
// request.Timeout = 6000;
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
// string retString = myStreamReader.ReadToEnd();
|
|
// string[] ResData = retString.Split(';');
|
|
// List<stockInfo> list1 = new List<stockInfo>();
|
|
// foreach (var item in ResData)
|
|
// {
|
|
// var data = item.Split('=');
|
|
// if (data.Length == 2)
|
|
// {
|
|
// var dd = data[1].Split(',');
|
|
// if (dd.Length >= 33)
|
|
// {
|
|
// stockInfo info = new stockInfo()
|
|
// {
|
|
// code = data[0].Split('_')[2],
|
|
// name = dd[0].Replace("\"", ""),
|
|
// startPrice = decimal.Parse(dd[1]),
|
|
// olePrice = decimal.Parse(dd[2]),
|
|
// nowPrice = decimal.Parse(dd[3]),
|
|
// maxPrice = decimal.Parse(dd[4]),
|
|
// minPrice = decimal.Parse(dd[5]),
|
|
// bidderPrice = decimal.Parse(dd[6]),
|
|
// auctionPrice = decimal.Parse(dd[7]),
|
|
// turnover = int.Parse(dd[8]),
|
|
// turnoverPrice = decimal.Parse(dd[9]),
|
|
// buyOneNum = int.Parse(dd[10]),
|
|
// buyOnePrice = decimal.Parse(dd[11]),
|
|
// buyTwoNum = int.Parse(dd[12]),
|
|
// buyTwoPrice = decimal.Parse(dd[13]),
|
|
// buyThreeNum = int.Parse(dd[14]),
|
|
// buyThreePrice = decimal.Parse(dd[15]),
|
|
// buyFourNum = int.Parse(dd[16]),
|
|
// buyFourPrice = decimal.Parse(dd[17]),
|
|
// buyFiveNum = int.Parse(dd[18]),
|
|
// buyFivePrice = decimal.Parse(dd[19]),
|
|
// sellOneNum = int.Parse(dd[20]),
|
|
// sellOnePrice = decimal.Parse(dd[21]),
|
|
// sellTwoNum = int.Parse(dd[22]),
|
|
// sellTwoPrice = decimal.Parse(dd[23]),
|
|
// sellThreeNum = int.Parse(dd[24]),
|
|
// sellThreePrice = decimal.Parse(dd[25]),
|
|
// sellFourNum = int.Parse(dd[26]),
|
|
// sellFourPrice = decimal.Parse(dd[27]),
|
|
// sellFiveNum = int.Parse(dd[28]),
|
|
// sellFivePrice = decimal.Parse(dd[29]),
|
|
// timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
// };
|
|
// list1.Add(info);
|
|
// }
|
|
// }
|
|
// }
|
|
// using (var db = new MESDB())
|
|
// {
|
|
// foreach (var info in list1)
|
|
// {
|
|
// db.stockInfo.AddOrUpdate(info);
|
|
// }
|
|
// db.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.Message.ShowError();
|
|
// }
|
|
//});
|
|
//var t6 = Task.Factory.StartNew(() =>
|
|
//{
|
|
// try
|
|
// {
|
|
// string url = "http://hq.sinajs.cn/list={0}";
|
|
// var list = new MESDB().stockInfo.ToList().Skip(2500).Take(500);
|
|
// string code = "";
|
|
// foreach (var stockInfo in list)
|
|
// {
|
|
// code += stockInfo.code + ",";
|
|
// }
|
|
// url = string.Format(url, code);
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
// request.Method = "GET";
|
|
// request.ContentType = "text/html;charset=UTF-8";
|
|
// request.UserAgent = null;
|
|
// request.Timeout = 6000;
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
// string retString = myStreamReader.ReadToEnd();
|
|
// string[] ResData = retString.Split(';');
|
|
// List<stockInfo> list1 = new List<stockInfo>();
|
|
// foreach (var item in ResData)
|
|
// {
|
|
// var data = item.Split('=');
|
|
// if (data.Length == 2)
|
|
// {
|
|
// var dd = data[1].Split(',');
|
|
// if (dd.Length >= 33)
|
|
// {
|
|
// stockInfo info = new stockInfo()
|
|
// {
|
|
// code = data[0].Split('_')[2],
|
|
// name = dd[0].Replace("\"", ""),
|
|
// startPrice = decimal.Parse(dd[1]),
|
|
// olePrice = decimal.Parse(dd[2]),
|
|
// nowPrice = decimal.Parse(dd[3]),
|
|
// maxPrice = decimal.Parse(dd[4]),
|
|
// minPrice = decimal.Parse(dd[5]),
|
|
// bidderPrice = decimal.Parse(dd[6]),
|
|
// auctionPrice = decimal.Parse(dd[7]),
|
|
// turnover = int.Parse(dd[8]),
|
|
// turnoverPrice = decimal.Parse(dd[9]),
|
|
// buyOneNum = int.Parse(dd[10]),
|
|
// buyOnePrice = decimal.Parse(dd[11]),
|
|
// buyTwoNum = int.Parse(dd[12]),
|
|
// buyTwoPrice = decimal.Parse(dd[13]),
|
|
// buyThreeNum = int.Parse(dd[14]),
|
|
// buyThreePrice = decimal.Parse(dd[15]),
|
|
// buyFourNum = int.Parse(dd[16]),
|
|
// buyFourPrice = decimal.Parse(dd[17]),
|
|
// buyFiveNum = int.Parse(dd[18]),
|
|
// buyFivePrice = decimal.Parse(dd[19]),
|
|
// sellOneNum = int.Parse(dd[20]),
|
|
// sellOnePrice = decimal.Parse(dd[21]),
|
|
// sellTwoNum = int.Parse(dd[22]),
|
|
// sellTwoPrice = decimal.Parse(dd[23]),
|
|
// sellThreeNum = int.Parse(dd[24]),
|
|
// sellThreePrice = decimal.Parse(dd[25]),
|
|
// sellFourNum = int.Parse(dd[26]),
|
|
// sellFourPrice = decimal.Parse(dd[27]),
|
|
// sellFiveNum = int.Parse(dd[28]),
|
|
// sellFivePrice = decimal.Parse(dd[29]),
|
|
// timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
// };
|
|
// list1.Add(info);
|
|
// }
|
|
// }
|
|
// }
|
|
// using (var db = new MESDB())
|
|
// {
|
|
// foreach (var info in list1)
|
|
// {
|
|
// db.stockInfo.AddOrUpdate(info);
|
|
// }
|
|
// db.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.Message.ShowError();
|
|
// }
|
|
//});
|
|
//var t7 = Task.Factory.StartNew(() =>
|
|
//{
|
|
// try
|
|
// {
|
|
// string url = "http://hq.sinajs.cn/list={0}";
|
|
// var list = new MESDB().stockInfo.ToList().Skip(3000).Take(500);
|
|
// string code = "";
|
|
// foreach (var stockInfo in list)
|
|
// {
|
|
// code += stockInfo.code + ",";
|
|
// }
|
|
// url = string.Format(url, code);
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
// request.Method = "GET";
|
|
// request.ContentType = "text/html;charset=UTF-8";
|
|
// request.UserAgent = null;
|
|
// request.Timeout = 6000;
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
// string retString = myStreamReader.ReadToEnd();
|
|
// string[] ResData = retString.Split(';');
|
|
// List<stockInfo> list1 = new List<stockInfo>();
|
|
// foreach (var item in ResData)
|
|
// {
|
|
// var data = item.Split('=');
|
|
// if (data.Length == 2)
|
|
// {
|
|
// var dd = data[1].Split(',');
|
|
// if (dd.Length >= 33)
|
|
// {
|
|
// stockInfo info = new stockInfo()
|
|
// {
|
|
// code = data[0].Split('_')[2],
|
|
// name = dd[0].Replace("\"", ""),
|
|
// startPrice = decimal.Parse(dd[1]),
|
|
// olePrice = decimal.Parse(dd[2]),
|
|
// nowPrice = decimal.Parse(dd[3]),
|
|
// maxPrice = decimal.Parse(dd[4]),
|
|
// minPrice = decimal.Parse(dd[5]),
|
|
// bidderPrice = decimal.Parse(dd[6]),
|
|
// auctionPrice = decimal.Parse(dd[7]),
|
|
// turnover = int.Parse(dd[8]),
|
|
// turnoverPrice = decimal.Parse(dd[9]),
|
|
// buyOneNum = int.Parse(dd[10]),
|
|
// buyOnePrice = decimal.Parse(dd[11]),
|
|
// buyTwoNum = int.Parse(dd[12]),
|
|
// buyTwoPrice = decimal.Parse(dd[13]),
|
|
// buyThreeNum = int.Parse(dd[14]),
|
|
// buyThreePrice = decimal.Parse(dd[15]),
|
|
// buyFourNum = int.Parse(dd[16]),
|
|
// buyFourPrice = decimal.Parse(dd[17]),
|
|
// buyFiveNum = int.Parse(dd[18]),
|
|
// buyFivePrice = decimal.Parse(dd[19]),
|
|
// sellOneNum = int.Parse(dd[20]),
|
|
// sellOnePrice = decimal.Parse(dd[21]),
|
|
// sellTwoNum = int.Parse(dd[22]),
|
|
// sellTwoPrice = decimal.Parse(dd[23]),
|
|
// sellThreeNum = int.Parse(dd[24]),
|
|
// sellThreePrice = decimal.Parse(dd[25]),
|
|
// sellFourNum = int.Parse(dd[26]),
|
|
// sellFourPrice = decimal.Parse(dd[27]),
|
|
// sellFiveNum = int.Parse(dd[28]),
|
|
// sellFivePrice = decimal.Parse(dd[29]),
|
|
// timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
// };
|
|
// list1.Add(info);
|
|
// }
|
|
// }
|
|
// }
|
|
// using (var db = new MESDB())
|
|
// {
|
|
// foreach (var info in list1)
|
|
// {
|
|
// db.stockInfo.AddOrUpdate(info);
|
|
// }
|
|
// db.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.Message.ShowError();
|
|
// }
|
|
//});
|
|
List<Task> listtask = new List<Task>();
|
|
for(int m = 0; m<8; m++)
|
|
{
|
|
int n = m;
|
|
var t=Task.Factory.StartNew(() =>
|
|
{
|
|
try
|
|
{
|
|
string url = "http://hq.sinajs.cn/list={0}";
|
|
var list = new MESDB().stockInfo.ToList().Skip(400*n).Take(400);
|
|
string code = "";
|
|
foreach (var stockInfo in list)
|
|
{
|
|
code += stockInfo.code + ",";
|
|
}
|
|
url = string.Format(url, code);
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
request.Method = "GET";
|
|
request.ContentType = "text/html;charset=UTF-8";
|
|
request.UserAgent = null;
|
|
request.Timeout = 60000;
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.Default);
|
|
string retString = myStreamReader.ReadToEnd();
|
|
string[] ResData = retString.Split(';');
|
|
List<stockInfo> list1 = new List<stockInfo>();
|
|
foreach (var item in ResData)
|
|
{
|
|
var data = item.Split('=');
|
|
if (data.Length == 2)
|
|
{
|
|
var dd = data[1].Split(',');
|
|
if (dd.Length >= 33)
|
|
{
|
|
stockInfo info = new stockInfo()
|
|
{
|
|
code = data[0].Split('_')[2],
|
|
name = dd[0].Replace("\"", ""),
|
|
startPrice = decimal.Parse(dd[1]),
|
|
olePrice = decimal.Parse(dd[2]),
|
|
nowPrice = decimal.Parse(dd[3]),
|
|
maxPrice = decimal.Parse(dd[4]),
|
|
minPrice = decimal.Parse(dd[5]),
|
|
bidderPrice = decimal.Parse(dd[6]),
|
|
auctionPrice = decimal.Parse(dd[7]),
|
|
turnover = int.Parse(dd[8]),
|
|
turnoverPrice = decimal.Parse(dd[9]),
|
|
buyOneNum = int.Parse(dd[10]),
|
|
buyOnePrice = decimal.Parse(dd[11]),
|
|
buyTwoNum = int.Parse(dd[12]),
|
|
buyTwoPrice = decimal.Parse(dd[13]),
|
|
buyThreeNum = int.Parse(dd[14]),
|
|
buyThreePrice = decimal.Parse(dd[15]),
|
|
buyFourNum = int.Parse(dd[16]),
|
|
buyFourPrice = decimal.Parse(dd[17]),
|
|
buyFiveNum = int.Parse(dd[18]),
|
|
buyFivePrice = decimal.Parse(dd[19]),
|
|
sellOneNum = int.Parse(dd[20]),
|
|
sellOnePrice = decimal.Parse(dd[21]),
|
|
sellTwoNum = int.Parse(dd[22]),
|
|
sellTwoPrice = decimal.Parse(dd[23]),
|
|
sellThreeNum = int.Parse(dd[24]),
|
|
sellThreePrice = decimal.Parse(dd[25]),
|
|
sellFourNum = int.Parse(dd[26]),
|
|
sellFourPrice = decimal.Parse(dd[27]),
|
|
sellFiveNum = int.Parse(dd[28]),
|
|
sellFivePrice = decimal.Parse(dd[29]),
|
|
timeStr = DateTime.Parse(dd[30] + " " + dd[31])
|
|
};
|
|
list1.Add(info);
|
|
}
|
|
}
|
|
}
|
|
using (var db = new MESDB())
|
|
{
|
|
foreach (var info in list1)
|
|
{
|
|
db.stockInfo.AddOrUpdate(info);
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var action1 = new Action(() =>
|
|
{
|
|
Show(DateTime.Now + ex.Message + "\r\n");
|
|
});
|
|
this.Invoke(action1);
|
|
}
|
|
});
|
|
listtask.Add(t);
|
|
}
|
|
Task.WaitAll(listtask.ToArray());
|
|
var action= new Action(() =>
|
|
{
|
|
Show(DateTime.Now + ":采集成功" + "\r\n");
|
|
});
|
|
this.Invoke(action);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void Show(string str)
|
|
{
|
|
memoEdit1.MaskBox.AppendText(str);
|
|
}
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|
{
|
|
if (!flag)
|
|
{
|
|
flag = true;
|
|
memoEdit1.MaskBox.AppendText(DateTime.Now+":开始采集" + "\r\n");
|
|
simpleButton2.Text = "停止";
|
|
}
|
|
else
|
|
{
|
|
flag = false;
|
|
memoEdit1.MaskBox.AppendText(DateTime.Now + ":停止采集" + "\r\n");
|
|
simpleButton2.Text = "开始采集";
|
|
}
|
|
}
|
|
}
|
|
} |