private void bg_DoWork(object sender, DoWorkEventArgs e) { StreamReader sr = null; Stopwatch sw = new Stopwatch(); Stopwatch swT = new Stopwatch(); //总耗时 swT.Start(); sw.Start(); this.bg.ReportProgress(-1, "正在禁用逐笔成交记录表的索引,请稍候……"); db.DisableOrEnableZhuBiTableIndex("禁用"); sw.Stop(); this.bg.ReportProgress(-1, "禁用逐笔成交记录表的索引耗时" + sw.ElapsedMilliseconds.ToString() + "毫秒"); foreach (DataRow row in this.dt.Rows) { sw.Restart(); if (!bg.CancellationPending) { this.bg.ReportProgress(i, row); //选用不同的插入方式 //TVP表变量方式 if (Main.staticAppSetup["ZbInsertMode"].ToString() == "TVP") { //清空用来保存每个文件主笔成交记录的表 dtRec.Clear(); //读取主笔成交记录文件 sr = new StreamReader(row["文件路径"].ToString()); string nextLine = null; while ((nextLine = sr.ReadLine()) != null) { //解析每行记录 string[] strRec = nextLine.Split(new string[] { "," }, StringSplitOptions.None); DataRow rRec = dtRec.NewRow(); //rRec["证券代码"] = row["证券代码"].ToString(); //rRec["成交日期"] = row["日期"].ToString(); rRec["成交时间"] = strRec[0].ToString(); rRec["成交价格"] = strRec[1]; rRec["买卖"] = strRec[2].ToString(); rRec["成交量"] = strRec[3].ToString(); dtRec.Rows.Add(rRec); } //传入数据库 db.UpdateZhuBi(row["证券代码"].ToString(), row["日期"].ToString(), dtRec); i++; j += dtRec.Rows.Count; } //BULK INSERT 方式 if (Main.staticAppSetup["ZbInsertMode"].ToString() == "BULK") { db.UpdataZhuBi(row["文件路径"].ToString(), row["证券代码"].ToString(), row["日期"].ToString(), Application.StartupPath + "\\逐笔成交.fmt"); i++; } } else { break; } sw.Stop(); this.bg.ReportProgress(-1, "耗时:" + sw.ElapsedMilliseconds.ToString() + "毫秒" + ",总耗时:" + swT.ElapsedMilliseconds.ToString() + "毫秒"); } swT.Stop(); }