另外做个按钮,按钮代码:
Dim st As Date = Date.Now
'DataTables("表A").StopRedraw()
Dim drs As List(of DataRow) = DataTables("表A").Select("","日期")
For i As Integer = 0 To drs.count -1
Dim dr As DataRow = drs(i)
Dim y As Integer = dr("日期").year
Dim m As Integer = dr("日期").Month
Dim d As Integer = dr("日期").day
Dim year As String = IIF(m=12 And d>=26,y+1,y)
Dim month As String = IIF(d>=26,IIF(m=12,1,M+1),m)
Dim EndDate As Date = new Date(year, month, 26)
Dim StartDate As Date = EndDate.AddMonths(-1)
Dim YeatDate As Date = New Date()
If i = 0 Then '如果是第一行
dr("新水1_月用量") = dr("新水_天用量") '
dr("新水1_年用量") = dr("新水_天用量")
Else
Dim lastdate As Date = drs(i-1)("日期")
Dim y1 As Integer = lastdate.year
Dim m1 As Integer = lastdate.Month
Dim d1 As Integer = lastdate.day
y1 = IIF(m1=12 And d1>=26,y1+1,y1)
If lastDate >= StartDate AndAlso lastDate < EndDate Then ' 如果和上一行是同月
dr("新水1_月用量") = dr("新水_天用量") + drs(i-1)("新水1_月用量")
Else '如果和上一行不是同月
dr("新水1_月用量") = dr("新水_天用量")
End If
If y1 = y Then '如果和上一行同年
dr("新水1_年用量") = dr("新水_天用量") + drs(i-1)("新水1_年用量")
Else
dr("新水1_年用量") = dr("新水_天用量")
End If
End If
Next
'DataTables("表a").ResumeRedraw()
MessageBox.Show("方法1耗时: " & (Date.Now - st).TotalSeconds & "秒")
[此贴子已经被作者于2013-9-8 11:42:01编辑过]