public int InsertStkKLine(TupleValue <string, StockHead> stkInfo, bool isConvert, bool isComposite, bool useTDXFile, KLineType kLineType, bool haveRecord = true) { string fileFullName = stkInfo.Value1; StockHead stkHead = stkInfo.Value2; string tableName = BLL.GetKLineDBTableName(kLineType, isComposite); DateTime existMaxDay = DateTime.MinValue; DataTable insTable = _dbo.GetEmptyTable(tableName); if (haveRecord) { if (isConvert) { _dbo.DeleteTable(tableName, stkHead); } else { existMaxDay = _dbo.FindMaxExistTradeDay(tableName, stkHead); } } if (useTDXFile) { this.LoadDayLineFileData_TDXDayFile(fileFullName, stkHead, existMaxDay, ref insTable); } else { this.LoadDayLineFileData_exportFile(fileFullName, stkHead, existMaxDay, ref insTable); } _dbo.BulkWriteTable(insTable, DataRowState.Added); return(insTable.Rows.Count); }
/// <summary>获取个股的所有收盘价 /// </summary> /// <param name="stkCode">股票代码</param> /// <param name="isComposite">是否指数</param> /// <param name="startDay">开始日期</param> /// <param name="endDay">结束日期</param> /// <returns></returns> public Dictionary <DateTime, decimal> GetDayCloseValue(string stkCode, bool isComposite, DateTime startDay = default(DateTime), DateTime endDay = default(DateTime)) { DataTable closePrice = _dbo.GetStockAllPrice(BLL.GetKLineDBTableName(KLineType.Day, isComposite), stkCode, new List <ValueType> { ValueType.Close }, startDay, endDay); Dictionary <DateTime, decimal> ret = SysFunction.GetColDictionary <DateTime, decimal>(closePrice, 0, 1); return(ret); }
public void TruncateStkKLine(KLineType kLineType, bool isComposite) { string tableName = BLL.GetKLineDBTableName(kLineType, isComposite); _dbo.TruncateTable(tableName); }
private void bkgDataImport_DoWork(object sender, DoWorkEventArgs e) { // < 覆盖,指数,TDX文件,K线级别 > TupleValue <bool, bool, bool, KLineType> arg = (TupleValue <bool, bool, bool, KLineType>)e.Argument; BLLDataImport bllDaImpt = new BLLDataImport(CommProp.ConnectionString); bool isConvert = arg.Value1; bool isComposite = arg.Value2; bool useTDXFile = arg.Value3; KLineType kLineType = arg.Value4; UIInProcess(true); _processCancel = false; if (useTDXFile) { this.LoadFileList_TDXDayFile(isComposite); } else { this.LoadFileList_exportFile(); } // List<TupleValue<完整文件名, StockHead>> List <TupleValue <string, StockHead> > lstStockData = bllDaImpt.LoadMrkTypeAndCodeFromDataFile(AllFile, isComposite, useTDXFile); if (lstStockData.Count > 0) { Stopwatch stopWatch = Stopwatch.StartNew(); try { bllDaImpt.OpenConnection(); int count = lstStockData.Count; int insLineCount = 0; string msgString = string.Empty; // 显示百分比提示信息 Action <int, int, int> showMsg = ((per, all, lineCnt) => { SysFunction.BackspaceInConsole(msgString, txtConsole); msgString = string.Format("{0} / {1},已导入:{2} 行)", per, all, lineCnt.ToString("N0")); Console.Write(msgString); }); Console.Write("正在导入...("); // 是否需要删表动作,如果表中无记录,则省去 Delete 动作 bool haveRecord = bllDaImpt.GetTableRecordCount(BLL.GetKLineDBTableName(kLineType, isComposite)) > 0; for (int i = 0; i < count; i++) { showMsg(i + 1, count, insLineCount); // TupleValue<完整文件名, StockHead> TupleValue <string, StockHead> stkData = lstStockData[i]; insLineCount += bllDaImpt.InsertStkKLine(stkData, isConvert, isComposite, useTDXFile, kLineType, haveRecord); // 最后一批完成后,再刷一下 if (i == count - 1) { showMsg(i + 1, count, insLineCount); } if (_processCancel) { break; } } if (_processCancel) { Console.WriteLine(" 导入终止!"); } else { Console.WriteLine(" 导入完成!"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { bllDaImpt.CloseConnection(); _processCancel = false; Console.WriteLine("总耗时:{0}", stopWatch.Elapsed); } } UIInProcess(false); }