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); }