/// <summary> /// 解析基金买卖盘结果,填充到对象中 /// </summary> /// <param name="fi"></param> /// <param name="originalResult"></param> private void PaseFundMarketPriceResult(FundInfo fi, String originalResult) { QueryResult queryResult = JSON.parse <QueryResult>(originalResult); if (queryResult != null && queryResult.results != null && queryResult.results.Count > 0) { List <Object> resultList = queryResult.results[0]; fi.fundCode = (String)resultList[0]; fi.currPrice = Convert.ToSingle(resultList[30]); fi.currPercentageIncrease = Convert.ToSingle(resultList[36]); fi.dealAmount = Convert.ToSingle(resultList[32]); //fi.fieldAmount = Convert.ToSingle(resultList[34]); fi.fundName = (String)resultList[1]; fi.buy1Price = Convert.ToSingle(resultList[16]); } }
/// <summary> /// 初始化时从文件读数据 /// </summary> private int loadFundFile() { this.Invoke(new CallBackDelegateParam(ShowStatus), new Object[] { "正在加载文件信息..." }); //先加载排除的基金列表 FileStream aFile = new FileStream("exp.txt", FileMode.Open); StreamReader sr = new StreamReader(aFile); String strLine = sr.ReadLine(); while (strLine != null) { if (!expFundInfoDict.ContainsKey(strLine)) { expFundInfoDict.Add(strLine, "1"); } strLine = sr.ReadLine(); } sr.Close(); //加载基金列表 String path = "a.xlsx"; DataSet fileData = ExcelReader.ToDataTable(path); for (int i = 0; i < fileData.Tables[0].Rows.Count; i++) { FundInfo fi = new funds.FundInfo(); fi.fundCode = fileData.Tables[0].Rows[i][0].ToString(); if (fi.fundCode == "" || expFundInfoDict.ContainsKey(fi.fundCode)) { continue; } Dictionary <String, StockInfo> stockList = new Dictionary <String, StockInfo>(); fi.stockList = stockList; //重仓股仓位 try { fi.stockPosition = Convert.ToSingle(fileData.Tables[0].Rows[i][23]) / 100; fi.unHeavyStockPosition = fi.stockPosition - Convert.ToSingle(fileData.Tables[0].Rows[i][22]) / 100; //加载最新净值(一般是上一交易日的净值) if (fileData.Tables[0].Rows[i][24].ToString() == "") { continue; } fi.fundYesterDayValue = Convert.ToSingle(fileData.Tables[0].Rows[i][24]); //加载前十重仓股 for (int j = 0; j < 10; j++) { StockInfo stockInfo = new StockInfo(); stockInfo.stockCode = (String)fileData.Tables[0].Rows[i][2 * j + 2]; if (stockInfo.stockCode.Length != 6) { break; } if (!gStockPriceDict.ContainsKey(stockInfo.stockCode)) { gStockPriceDict.Add(stockInfo.stockCode, 0); } if (fileData.Tables[0].Rows[i][2 * j + 3] != null) { stockInfo.stockAmount = Convert.ToSingle(fileData.Tables[0].Rows[i][2 * j + 3]) / 100; } //加载到全局信息 stockList.Add(stockInfo.stockCode, stockInfo); } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); continue; } //加载到全局变量 gFundInfoDict.Add(fi.fundCode.Split('.')[0], fi); //申赎状态,基金类型,如果为空,不影响加到全局变量 try { fi.buyAndSaleStatus = fileData.Tables[0].Rows[i][25].ToString(); fi.fundStyle = fileData.Tables[0].Rows[i][26].ToString(); //按类型加载基金全局变量 if ("股票型基金".Equals(fi.fundStyle)) { gStockFundInfoDict.Add((String)fileData.Tables[0].Rows[i][0], fi); } else if ("债券型基金".Equals(fi.fundStyle)) { gBondsFundInfoDict.Add((String)fileData.Tables[0].Rows[i][0], fi); } else if ("混合型基金".Equals(fi.fundStyle)) { gMixFundInfoDict.Add((String)fileData.Tables[0].Rows[i][0], fi); } else if ("国际(QDII)基金".Equals(fi.fundStyle)) { gQDIIFundInfoDict.Add((String)fileData.Tables[0].Rows[i][0], fi); } } catch { } } //读取指数基金信息 DataSet indexFundFileData = ExcelReader.ToDataTable("index_fund.xlsx"); for (int i = 0; i < indexFundFileData.Tables[0].Rows.Count; i++) { if (indexFundFileData.Tables[0].Rows[i][0] == DBNull.Value) { continue; } String fundCode = (String)indexFundFileData.Tables[0].Rows[i][0]; fundCode = fundCode.Replace(".OF", ""); if (!gFundInfoDict.ContainsKey(fundCode)) { continue; } String indexCode = (String)indexFundFileData.Tables[0].Rows[i][2]; if (!indexCode.EndsWith("SH") && !indexCode.EndsWith("SZ")) { continue; } FundInfo fi = gFundInfoDict[fundCode]; if (fi == null) { continue; } fi.isIndexFund = true; fi.indexCode = indexCode; if (!gStockPriceDict.ContainsKey(indexCode)) { gStockPriceDict.Add(indexCode, 0); } } //如果有就读取 if (File.Exists(yesterdayEstimateValueFileName)) { FileStream fs = new FileStream(yesterdayEstimateValueFileName, FileMode.Open, FileAccess.Read); StreamReader streamReader = new StreamReader(fs); string line = streamReader.ReadLine(); while (line != null && line.Contains("|")) { string[] info = line.Split('|'); if (info[1].Length > 1) { FundInfo tempFundInfo = gFundInfoDict[info[0]]; if (tempFundInfo != null) { try { tempFundInfo.yesterdayEstimateValue = (float)Convert.ToDouble(info[1]); } catch (Exception ex) { } } } line = streamReader.ReadLine(); } } else { //没有则创建 FileStream fs = new FileStream(yesterdayEstimateValueFileName, FileMode.CreateNew); fs.Close(); } return(gFundInfoDict.Count); }