/// <summary> /// 导入数据 /// </summary> public bool doMergeToRepository() { showBeginMessage("开始合并数据..."); if (repository == null) { repository = new IndicatorRepository(FileUtils.GetDirectory(props.Get <String>("repository"))); repository.Initilization(); } String datapath = FileUtils.GetDirectory(props.Get <String>("datapath")); DirectoryInfo dInfo = new DirectoryInfo(datapath); FileInfo[] fInfos = dInfo.GetFiles("*.scv"); if (fInfos == null || fInfos.Length <= 0) { showResultMessage("没有需要导入的新文件", 1); return(false); } try { foreach (FileInfo fInfo in fInfos) { String code = fInfo.Name.Substring(3, 6); TimeSerialsDataSet ds = repository[code]; KLine kline = ds.DayKLine; if (ds == null) { continue; } showProgressMessage(code); CSVFile csvFile = new CSVFile(); csvFile.Load(fInfo.FullName, Encoding.UTF8, false, ","); List <String> lines = csvFile.Lines; for (int i = lines.Count - 1; i >= 0; i--) { if (lines[i] == null || lines[i].Trim() == "") { continue; } String[] ss = lines[i].Split(','); if (ss == null || ss.Length < 7) { continue; } DateTime d = DateUtils.Parse(ss[0]); KLineItem item = kline[d]; if (item != null) { break; } double[] v = new double[6]; for (int j = 0; j < v.Length; j++) { v[j] = double.Parse(ss[j + 1]); } item = new KLineItem(); item.Date = d; item.SetValue <double>("OPEN", v[0]); item.SetValue <double>("HIGH", v[1]); item.SetValue <double>("LOW", v[2]); item.SetValue <double>("CLOSE", v[3]); item.SetValue <double>("VOLUME", v[4]); item.SetValue <double>("TURNOVER", v[5]); kline.Add(item); } ds.Save("kline", TimeUnit.day); } showResultMessage(""); return(true); } catch (Exception e) { showResultMessage("导入失败", -1, e.Message); return(false); } }