Beta
凯 王 2021-04-22 14:18:45 +08:00
parent 6363a5f553
commit 1fafec0296
5 changed files with 1397 additions and 1807 deletions

View File

@ -11,8 +11,6 @@ namespace MES.Entity
[Table("stock")]
public partial class stockInfo
{
[Key]
[NoEdit("txtcode")]
[ModelBindControl("txtcode")]
public string code{set;get;}
[ModelBindControl("txtname")]
@ -77,6 +75,8 @@ namespace MES.Entity
public decimal sellFivePrice{set;get;}
[ModelBindControl("txttimeStr")]
public DateTime? timeStr{set;get;}=DateTime.Now;
[ModelBindControl("txtid")]
public int id{set;get;}
}
}

View File

@ -48,7 +48,37 @@ namespace MES.Form
{
fieldDictionary.Add("代码","code");
fieldDictionary.Add("名称","name");
fieldDictionary.Add("今日开盘价","startPrice");
fieldDictionary.Add("昨日收盘价","olePrice");
fieldDictionary.Add("当前价格","nowPrice");
fieldDictionary.Add("今日最高价","maxPrice");
fieldDictionary.Add("今日最低价","minPrice");
fieldDictionary.Add("竞买价","bidderPrice");
fieldDictionary.Add("竞卖价","auctionPrice");
fieldDictionary.Add("成交股票数","turnover");
fieldDictionary.Add("成交金额","turnoverPrice");
fieldDictionary.Add("买1数量","buyOneNum");
fieldDictionary.Add("买1价格","buyOnePrice");
fieldDictionary.Add("买2数量","buyTwoNum");
fieldDictionary.Add("买2价格","buyTwoPrice");
fieldDictionary.Add("买3数量","buyThreeNum");
fieldDictionary.Add("买3价格","buyThreePrice");
fieldDictionary.Add("买4数量","buyFourNum");
fieldDictionary.Add("买4价格","buyFourPrice");
fieldDictionary.Add("买5数量","buyFiveNum");
fieldDictionary.Add("买5价格","buyFivePrice");
fieldDictionary.Add("卖1数量","sellOneNum");
fieldDictionary.Add("卖1价格","sellOnePrice");
fieldDictionary.Add("卖2数量","sellTwoNum");
fieldDictionary.Add("卖2价格","sellTwoPrice");
fieldDictionary.Add("卖3数量","sellThreeNum");
fieldDictionary.Add("卖3价格","sellThreePrice");
fieldDictionary.Add("卖4数量","sellFourNum");
fieldDictionary.Add("卖4价格","sellFourPrice");
fieldDictionary.Add("卖5数量","sellFiveNum");
fieldDictionary.Add("卖5价格","sellFivePrice");
fieldDictionary.Add("时间","timeStr");
fieldDictionary.Add("id","id");
}
/// <summary>
/// 保存
@ -86,6 +116,12 @@ namespace MES.Form
/// <returns></returns>
public override bool CheckInput()
{
if(string.IsNullOrEmpty(txtcode.EditValue.ToString()))
{
"代码不能为空".ShowWarning();
txtcode.Focus();
return false;
}
if(string.IsNullOrEmpty(txtname.EditValue.ToString()))
{
"名称不能为空".ShowWarning();
@ -319,13 +355,5 @@ namespace MES.Form
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
using (var con = new MESDB())
{
grdList.DataSource = con.stockInfo.ToList().OrderByDescending(p=>p.turnoverPrice);
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,14 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.Data.Helpers;
@ -47,701 +49,142 @@ namespace WinformGeneralDeveloperFrame
private void GetData()
{
DateTime startTime1=DateTime.Parse("09:30:00");
DateTime endTime1 = DateTime.Parse("11:30:00");
DateTime startTime2 = DateTime.Parse("13:00:00");
DateTime endTime2 = DateTime.Parse("15:00:00");
Task.Factory.StartNew(() =>
{
while (true)
{
if (flag)
{
var t1 = Task.Factory.StartNew(() =>
if (DateTime.Now >= startTime1 && DateTime.Now <= endTime1 || DateTime.Now >= startTime2 && DateTime.Now <= endTime2)
{
try
{
string url = "http://hq.sinajs.cn/list={0}";
var list = new MESDB().stockInfo.ToList().Skip(0).Take(200);
List<Task> listtask = new List<Task>();
int num1 = 0;
int num2 = 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 = 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);
}
}
}
Dictionary<string, stockInfo> stockinfos = null;
List<string> codes = new List<string>();
using (var db = new MESDB())
{
foreach (var info in list1)
num1 = db.stockInfo.GroupBy(P => P.code).ToList().Count;
foreach (var item in db.stockInfo.GroupBy(P => P.code))
{
db.stockInfo.AddOrUpdate(info);
codes.Add(item.Key);
}
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
for (int m = 0; m <= num1 / num2; m++)
{
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)
int n = m;
var t = Task.Factory.StartNew(() =>
{
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)
try
{
var dd = data[1].Split(',');
if (dd.Length >= 33)
string url = "http://hq.sinajs.cn/list={0}";
var list = codes.Skip(num2 * n).Take(num2);
//string code = "";
foreach (var str in list)
{
stockInfo info = new stockInfo()
code += str + ",";
}
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)
{
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);
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())
{
db.stockInfo.AddRange(list1);
db.SaveChanges();
}
}
}
using (var db = new MESDB())
{
foreach (var info in list1)
catch (Exception ex)
{
db.stockInfo.AddOrUpdate(info);
var action1 = new Action(() =>
{
Show(DateTime.Now + ex.Message + "\r\n");
});
this.Invoke(action1);
}
db.SaveChanges();
}
}
catch (Exception ex)
{
var action1 = new Action(() =>
{
Show(DateTime.Now + ex.Message + "\r\n");
});
this.Invoke(action1);
listtask.Add(t);
}
});
listtask.Add(t);
Task.WaitAll(listtask.ToArray());
var action = new Action(() =>
{
Show(DateTime.Now + ":采集成功" + "\r\n");
});
this.Invoke(action);
}
}
Task.WaitAll(listtask.ToArray());
var action= new Action(() =>
else
{
Show(DateTime.Now + ":采集成功" + "\r\n");
});
this.Invoke(action);
}
var action1 = new Action(() =>
{
Show(DateTime.Now + "股票已休市" + "\r\n");
});
this.Invoke(action1);
}
Thread.Sleep(30000);
}
});
}