static int InitCPXX(string filePath) { StreamReader srReadFile = new StreamReader(filePath); List <CPXXMMDD> cPXXMMDDs = new List <CPXXMMDD>(); //循环读入 using (var db = new MKTContext()) { db.CPXXMMDDs.Delete(); while (!srReadFile.EndOfStream) { string strReadLine = srReadFile.ReadLine(); //读取每行数据 string[] strArr = strReadLine.Replace(" ", "").Split('|'); try { CPXXMMDD cPXXMMDD = CPXXMMDDParse(strArr); cPXXMMDDs.Add(cPXXMMDD); } catch (Exception e) { Console.WriteLine(e); } } srReadFile.Close(); db.CPXXMMDDs.AddRange(cPXXMMDDs); db.SaveChanges(); } Console.WriteLine("CPXX初始化结束"); return(0); }
static HashSet <int> InitMKT(string filePath) { MKTdict = new Dictionary <string, MKTDT>(); StreamReader srReadFile = new StreamReader(filePath); List <MKTDT> mKTDTs = new List <MKTDT>(); HashSet <string> mktstr = new HashSet <string>() { "018009", "113013", "019009", "511010", "511020", "511030" }; HashSet <int> lines = new HashSet <int>(); //循环读入 using (var db = new MKTContext()) { db.MKTDTs.Delete(); int i = 0;//标记行号 string txt = srReadFile.ReadToEnd(); srReadFile.Close(); string[] lineSet = txt.Split('\n'); foreach (string strReadLine in lineSet) { string[] strArr = strReadLine.Replace(" ", "").Split('|'); if (strArr.Length >= 2 && mktstr.Contains(strArr[1])) { MKTDT mkt = MKTDTParse(strArr); if (mkt != null) { db.MKTDTs.Add(mkt); lines.Add(i); MKTdict.Add(strArr[1], mkt);//将mkt存储到临时变量里 } } i++; } db.SaveChanges(); } return(lines); }
/** * 更新脚本 **/ static public int JobMKT(string strReadFilePath, HashSet <int> lines) { using (var db = new MKTContext()) { try { StreamReader srReadFile = new StreamReader(strReadFilePath, Encoding.Default); string txt = srReadFile.ReadToEnd(); srReadFile.Close(); string[] lineSet = txt.Split('\n'); int i = 0; //标记行号 foreach (string strReadLine in lineSet) { if (lines.Contains(i)) { string[] strArr = strReadLine.Replace(" ", "").Split('|'); MKTDT mkt = MKTDTParse(strArr); if (mkt != null && !SelfDefineEquals(mkt, MKTdict[strArr[1]])) { MKTdict[strArr[1]] = mkt; db.MKTDTs.Where(c => c.SecurityID == mkt.SecurityID).Update(c => new MKTDT() { MDStreamID = mkt.MDStreamID, SecurityID = mkt.SecurityID, Symbol = mkt.Symbol, TradeVolume = mkt.TradeVolume, TotalValueTraded = mkt.TotalValueTraded, PreClosePx = mkt.PreClosePx, OpenPrice = mkt.OpenPrice, HighPrice = mkt.HighPrice, LowPrice = mkt.LowPrice, TradePrice = mkt.TradePrice, ClosePx = mkt.ClosePx, BuyPrice1 = mkt.BuyPrice1, BuyVolume1 = mkt.BuyVolume1, SellPrice1 = mkt.SellPrice1, SellVolume1 = mkt.SellVolume1, BuyPrice2 = mkt.BuyPrice2, BuyVolume2 = mkt.BuyVolume2, SellPrice2 = mkt.SellPrice2, SellVolume2 = mkt.SellVolume2, BuyPrice3 = mkt.BuyPrice3, BuyVolume3 = mkt.BuyVolume3, SellPrice3 = mkt.SellPrice3, SellVolume3 = mkt.SellVolume3, BuyPrice4 = mkt.BuyPrice4, BuyVolume4 = mkt.BuyVolume4, SellPrice4 = mkt.SellPrice4, SellVolume4 = mkt.SellVolume4, BuyPrice5 = mkt.BuyPrice5, BuyVolume5 = mkt.BuyVolume5, SellPrice5 = mkt.SellPrice5, SellVolume5 = mkt.SellVolume5, PreCloseIOPV = mkt.PreCloseIOPV, IOPV = mkt.IOPV, TradingPhaseCode = mkt.TradingPhaseCode, Timestamp = mkt.Timestamp }); Console.WriteLine(mkt.SecurityID + " " + mkt.TradePrice + " " + mkt.Timestamp); //屏幕打印每行数据 } } i++; // 行号+1 } db.SaveChanges(); }catch (Exception e) { Console.WriteLine(e); } } return(1); }