以下代码红字部分非常耗时,有好的办法吗?
Dim dtp As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker_截止日期")
Dim tb As WinForm.Table = e.Form.Controls("Table1")
Dim t As Table = tb.Table
Dim dt As DataTable
If dtp.Value = Nothing Then
MessageBox.Show("请选选择截止日期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
Dim cmd_工序表 As New SQLCommand
cmd_工序表.C
cmd_工序表.C ommandText = "S elect * From {工序合并表} Where 起始时间 < '" & dtp.Value.AddDays(1) & " '"
dt = cmd_工序表.ExecuteReader()
Forms("进度条独立窗口").Show '打开进度条独立窗口
Dim p As WinForm.ProgressBar '定义进度条
Dim Lab1 As WinForm.Label
p = Forms("进度条独立窗口").Controls("ProgressBar")
Lab1 = Forms("进度条独立窗口").Controls("Label1")
Lab1.Text = "正在加载截止日期前的工序合并表全部数据..."
Application.DoEvents() '即刻暂停代码的执行,重新绘制控件后,继续执行代码.
Dim t1 As Date = Date.Now
Dim drs As List(Of DataRow) = dt.Select("", "卷号,起始时间") '指定母卷号计算
If drs.Count=1 Then
drs(0)("库存标记") = True
Else
For i As Integer = 1 To drs.Count - 1
p.Maximum = drs.Count '设置最大值
p.Minimum = 0 '设置最小值
If i Mod 100 = 0 Then '每运算100条更新一次进度条
p.Value = i '当前值为已经完成的行数
Lab1.Text = "工序合并表加载完成,开始计算..." & i + 1 & " / " & drs.Count
Application.DoEvents() '即刻暂停代码的执行,重新绘制控件后,继续执行代码
ElseIf i=drs.Count-1 '当i为最大值减1时
p.Value = drs.Count '当前值直接等于最大值
Lab1.Text = "完成全表库存标记计算,正在保存数据..." & i + 1 & " / " & drs.Count
Application.DoEvents() '即刻暂停代码的执行,重新绘制控件后,继续执行代码
End If
If drs(i)("卷号").Contains(drs(i-1)("卷号")) Then
drs(i-1)("库存标记") = False
Else
drs(i-1)("库存标记") = True
End If
Next
drs(drs.Count-1)("库存标记") = True
End If
Forms("进度条独立窗口").Close
MessageBox.Show("完成全表库存计算!耗时: " & (Date.Now - t1).TotalSeconds & "秒,请不要频繁操作.", "提示",MessageBoxButtons.ok, MessageBoxIcon.Information)
t.DataSource = dt
End If