public void TestMethod_KLine() { //SQLCEWrapper _sqlCeWrapper = new SQLCEWrapper(); //_sqlCeWrapper.CreateDatabase(); //_sqlCeWrapper.CreateKLineTable(); string filePath = Path.Combine(Environment.CurrentDirectory, "TestKine.sdf"); if(File.Exists(filePath)) { File.Delete(filePath); } DateTime startTime = new DateTime(2015, 1, 1); DateTime endTime = new DateTime(2015, 12, 31); List<IStockKLine> kLines = ExampleStockKLineMin1(startTime, endTime).ToList(); System.Diagnostics.Debug.Print(string.Format("KLine data count is {0}", kLines.Count)); KLineRepository repository = new KLineRepository(filePath); repository.AddRange(kLines); //_sqlCeWrapper.InsertIntoDatas(kLines); List<IStockKLine> getKLines = repository.Get(kLines[60].Time, kLines[120].Time).ToList(); Assert.IsTrue(repository.Exists(kLines[0])); Assert.IsFalse(repository.Exists(GetUpdateData(kLines[0].Time.AddYears(1)))); var updateData = GetUpdateData(kLines[0].Time); repository.UpdateRange(new IStockKLine[] { updateData }); IList<IStockKLine> result0 = repository.GetAll().ToList(); Assert.IsTrue(repository.Exists(updateData)); List<IStockKLine> updateKLines = GetUpdateDatas(kLines).ToList(); repository.UpdateRange(updateKLines); //string p_strSQL = "SELECT * FROM KLineTable;"; //DataSet dataSet = _sqlCeWrapper.SelectDataSet(p_strSQL); IList<IStockKLine> result = repository.GetAll().ToList(); //if (dataSet != null && dataSet.Tables.Count > 0) //{ // foreach (DataTable table in dataSet.Tables) // System.Diagnostics.Debug.Print(string.Format("table Rows count is {0}", table.Rows.Count)); //} if(result != null && result.Count > 0) { System.Diagnostics.Debug.Print(string.Format("KLine Data count is {0}", result.Count)); } Assert.AreEqual(kLines.Count, result.Count); //_sqlCeWrapper.DeleteDatabase(); }
public void Update(KLineType type, string stockCode, IEnumerable<IStockKLine> kLines) { ThrowIfTypeNotSupport(type); if (type == KLineType.Day) { string dbFilePath = new Day1KLineFile(stockCode).GetFilePath(); KLineRepository repository = new KLineRepository(dbFilePath); repository.UpdateRange(kLines); } else { Year1KLineFile file = null; if (type == KLineType.Min1) { file = new Min1KLineFile(stockCode); } else { file = new Min5KLineFile(stockCode); } var packages = file.SplitToPackages(kLines); // 插入所有数据 foreach (var package in packages) { // 获取数据文件路径 string dbFilePath = file.GetFilePath(package); KLineRepository repository = new KLineRepository(dbFilePath); repository.UpdateRange(package.Items); } } }