稍稍改了一下,应该可以通用的吧。
Dim name As String = MainTable.Name
If name.Contains("村级") Then
Dim dt As DataTable = DataTables("出生")
Dim y,m As Integer
y = name.Replace("村级","").Replace("月","").Split("年")(0)
m = name.Replace("村级","").Replace("月","").Split("年")(1)
Dim d As Date = New Date(y,m,1)
Dim d1 As Date = New Date(y,m,Date.DaysInMonth(y,m))
MainTable.DataTable.DataRows.Clear
Dim arys As List(Of String()) = dt.GetUniqueValues("", "单位名称", "组名称")
For Each ary As String() In arys
Dim r As Row = MainTable.AddNew
r("单位") = ary(0)
r("组名称") = ary(1)
Dim filter As String = "单位名称 = '" & ary(0) & "' And 组名称 = '" & ary(1) & "'"
r("总人口数") = DataTables("总人口").Compute("Count(_Identify)", filter & " And 出生日期 <= #" & d1 & "#") - DataTables("迁入").Compute("Count(_Identify)", filter & " And 变动日期 > #" & d1 & "#") + DataTables("迁出").Compute("Count(_Identify)", filter & " And 迁出日期 > #" & d1 & "#") + DataTables("死亡").Compute("Count(_Identify)", filter & " And 死亡日期 > #" & d1 & "#")
r("出生_总数") = dt.Compute("Count(_Identify)", filter & " And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("出生_政策内_一孩") = dt.Compute("Count(_Identify)", filter & " And 子女政策属性 = '政策内' And 子女孩次 = 1 And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("出生_政策内_二孩") = dt.Compute("Count(_Identify)", filter & " And 子女政策属性 = '政策内' And 子女孩次 = 2 And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("出生_政策内_多孩") = dt.Compute("Count(_Identify)", filter & " And 子女政策属性 = '政策内' And 子女孩次 > 2 And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("出生_政策外_一孩") = dt.Compute("Count(_Identify)", filter & " And 子女政策属性 = '政策外' And 子女孩次 = 1 And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("出生_政策外_二孩") = dt.Compute("Count(_Identify)", filter & " And 子女政策属性 = '政策外' And 子女孩次 = 2 And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("出生_政策外_多孩") = dt.Compute("Count(_Identify)", filter & " And 子女政策属性 = '政策外' And 子女孩次 > 2 And 子女出生日期 >= #" & d & "# And 子女出生日期 <= #" & d1 & "#")
r("元月份以来节育手术人数_总数") = DataTables("手术").Compute("Count(_Identify)", filter & " And 手术日期 >= #" & d & "# And 手术日期 <= #" & d1 & "#")
r("元月份以来节育手术人数_其中_上环") = DataTables("手术").Compute("Count(_Identify)", filter & "And 手术类型 = '带铜宫内节育器' And 手术日期 >= #" & d & "# And 手术日期 <= #" & d1 & "#")
r("元月份以来节育手术人数_其中_绝育") = DataTables("手术").Compute("Count(_Identify)", filter & "And (手术类型 = '男性绝育术' Or 手术类型 = '女性绝育术') And 手术日期 >= #" & d & "# And 手术日期 <= #" & d1 & "#")
r("元月份以来节育手术人数_其中_人工流产") = DataTables("手术").Compute("Count(_Identify)", filter & "And 手术类型 = '人工流产' And 手术日期 >= #" & d & "# And 手术日期 <= #" & d1 & "#")
'r("已婚未育妇女_总数") = DataTables("妇女信息").Compute("Count(_Identify)", filter & " And 结婚日期 <= #" & d1 & "# And 末孩出生日期 > #" & d1 & "# and (现有男孩数 = '0' And 现有女孩数 = '0')")
r("死亡人数") = DataTables("死亡").Compute("Count(_Identify)", filter & " And 死亡日期 <= #" & d1 & "#")
r("自增人数") = r("出生_总数") - r("死亡人数")
r("迁移_迁入人数") = DataTables("迁入").Compute("Count(_Identify)", filter & " And 变动日期 <= #" & d1 & "#")
r("迁移_迁出人数") = DataTables("迁出").Compute("Count(_Identify)", filter & " And 迁出日期 <= #" & d1 & "#")
r("元月份以来新婚对数") = DataTables("新婚").Compute("Count(_Identify)", filter & " And 结婚日期 >= #" & New Date(y,1,1) & "# And 结婚日期 <= #" & d1 & "#")
Next
Dim nr As Row = MainTable.AddNew
nr("单位") = "合计"
For i As Integer = 2 To MainTable.Cols.Count - 1
nr(MainTable.Cols(i).Name) = MainTable.Compute("Sum(" & MainTable.Cols(i).Name & ")")
Next
End If