-- [求助]统计一个横轴、纵轴的二维统计,代码好像没什么错,但结果是算出0,,不知何故?
\'清除上一次统计结果
DataTables("二维表统计结果").DeleteFor("")
Dim X As WinForm.ComboBox = e.Form.Controls("XText")
Dim Y As WinForm.ComboBox = e.Form.Controls("YText")
\'用于存第一行的对应指标
Dim colsNames As New List(Of String)
\'同时选定两个指标时才做运算
If (X.Value IsNot Nothing And Y.Value IsNot Nothing) Then
\'构造年龄字典
Dim nl As New Dictionary(Of Integer, String)
nl.Add(1,"40岁及以下")
nl.Add(2,"45岁-41岁")
nl.Add(3,"50岁-46岁")
nl.Add(4,"51岁及以上")
\'构造性别字典
Dim xb As New Dictionary(Of Integer, String)
xb.Add(1,"男")
xb.Add(2,"女")
\'构造民族字典
Dim mz As New Dictionary(Of Integer, String)
mz.Add(1,"汉族")
mz.Add(2,"蒙古族")
mz.Add(3,"回族")
mz.Add(4,"藏族")
mz.Add(5,"维吾尔族")
mz.Add(6,"其他")
\'构造学历字典
Dim xl As New Dictionary(Of Integer, String)
xl.Add(1,"研究生及以上") \'1开头
xl.Add(2,"本专科学历") \'2开头
xl.Add(3,"中专及以下") \'4开头和其他
\'构造政治面貌字典
Dim zzmm As New Dictionary(Of Integer, String)
zzmm.Add(1,"中共党员") \'包含入党日期
zzmm.Add(2,"其他")
\'构造职务级别字典
Dim zwjb As New Dictionary(Of Integer, String)
zwjb.Add(1,"正处级")
zwjb.Add(2,"副处级")
zwjb.Add(3,"正科级")
zwjb.Add(4,"副科级")
zwjb.Add(5,"科员")
Dim YResult As String
\'构造Y轴的列名
Select Case Y.Value
Case "年龄"
For Each nli As String In nl.Values
colsNames.Add(nli)
Next
YResult = Y.Value
Case "性别"
For Each xbi As String In xb.Values
colsNames.Add(xbi)
Next
YResult = Y.Value
Case "民族"
For Each mzi As String In mz.Values
colsNames.Add(mzi)
Next
YResult = Y.Value
Case "学历"
For Each xli As String In xl.Values
colsNames.Add(xli)
Next
YResult = Y.Value
Case "政治面貌"
For Each zzmmi As String In zzmm.Values
colsNames.Add(zzmmi)
Next
YResult = Y.Value
Case "职务级别"
For Each zwjbi As String In zwjb.Values
colsNames.Add(zwjbi)
Next
YResult = Y.Value
End Select
\'将第一行的值设定
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Dim i As Integer = 1
For Each nmy As String In colsNames
Tables("二维表统计结果").Rows(0)(i) = nmy
i = i + 1
Next
Dim filter As String = "" \'用于拼接查询条件
Dim j As Integer = 1 \'用于计算行数
Dim Sum As Double
\'构造X轴的列名
Select Case X.Value
Case "年龄"
For Each nlj As String In nl.Values
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Tables("二维表统计结果").Rows(j)(0) = nlj \'第一列赋值
For k As Integer = 0 To colsNames.Count -1
filter = "" \'清空前一次的查询条件
Sum = 0 \'将前一次统计结果归零
Dim Date1,Date2 As Date
Select Case nlj
Case "40岁及以下"
Date1 = Date.Now.AddYears(-40)
filter = "出生日期 >= \'" & format(Date1, "yyyyMMdd") & "\'"
Case "45岁-41岁"
Date1 = Date.Now.AddYears(-41)
Date2 = Date.Now.AddYears(-45)
filter = "出生日期 >= \'" & format(Date2, "yyyyMMdd") & "\' And 出生日期 <= \'" & format(Date1, "yyyyMMdd") & "\'"
Case "50岁-46岁"
Date1 = Date.Now.AddYears(-46)
Date2 = Date.Now.AddYears(-50)
filter = "出生日期 >= \'" & format(Date2, "yyyyMMdd") & "\' And 出生日期 <= \'" & format(Date1, "yyyyMMdd") & "\'"
Case "51岁及以上"
Date1 = Date.Now.AddYears(-51)
filter = "出生日期 <= \'" & format(Date1, "yyyyMMdd") & "\'"
End Select
Select Case YResult
Case "年龄"
filter = filter & Functions.Execute("SetDateStr", colsNames(k))
Case "性别"
filter = filter & " And " & "性别 = \'" & colsNames(k) & "\'"
Case "民族"
filter = filter & " And " & "民族 = \'" & colsNames(k) & "\'"
Case "学历"
If colsNames(k) = "研究生及以上" Then
filter = filter & " And " & "全日制学历代码 like \'1%\'"
ElseIf colsNames(k) = "本专科学历" Then
filter = filter & " And " & "全日制学历代码 like \'2%\'"
Else
filter = filter & " And " & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Case "政治面貌"
If colsNames(k) = "中共党员" Then
filter = filter & " And " & "入党时间 IS NOT NULL"
Else
filter = filter & " And " & "入党时间 IS NULL"
End If
Case "职务级别"
filter = filter & " And " & "现任行政级别 = \'" & colsNames(k) & "\'"
End Select
Sum = Tables("基本情况").Compute("Count(姓名)", """" & filter & """")
Tables("二维表统计结果").Rows(j)(k+1) = Sum
\'MessageBox.Show( """" + filter + """","提示") \'测试用途
Next
j = j + 1
Next
Case "性别"
For Each xbj As String In xb.Values
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Tables("二维表统计结果").Rows(j)(0) = xbj \'第一列赋值
For k As Integer = 0 To colsNames.Count -1
filter = "" \'清空前一次的查询条件
Sum = 0 \'将前一次统计结果归零
filter = filter & "性别 = \'" & xbj & "\'"
Select Case YResult
Case "年龄"
filter = filter & Functions.Execute("SetDateStr", colsNames(k))
Case "性别"
filter = filter & " And " & "性别 = \'" & colsNames(k) & "\'"
Case "民族"
filter = filter & " And " & "民族 = \'" & colsNames(k) & "\'"
Case "学历"
If colsNames(k) = "研究生及以上" Then
filter = filter & " And " & "全日制学历代码 like \'1%\'"
ElseIf colsNames(k) = "本专科学历" Then
filter = filter & " And " & "全日制学历代码 like \'2%\'"
Else
filter = filter & " And " & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Case "政治面貌"
If colsNames(k) = "中共党员" Then
filter = filter & " And " & "入党时间 IS NOT NULL"
Else
filter = filter & " And " & "入党时间 IS NULL"
End If
Case "职务级别"
filter = filter & " And " & "现任行政级别 = \'" & colsNames(k) & "\'"
End Select
Sum = Tables("基本情况").Compute("Count(姓名)", """" & filter & """")
Tables("二维表统计结果").Rows(j)(k+1) = Sum
\'MessageBox.Show( """" & filter & """" & "结果是:" & Sum,"提示") \'测试用途
Next
j = j + 1
Next
Case "民族"
For Each mzj As String In mz.Values
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Tables("二维表统计结果").Rows(j)(0) = mzj \'第一列赋值
For k As Integer = 0 To colsNames.Count -1
filter = "" \'清空前一次的查询条件
Sum = 0 \'将前一次统计结果归零
filter = filter & "民族 = \'" & mzj & "\'"
Select Case YResult
Case "年龄"
filter = filter & Functions.Execute("SetDateStr", colsNames(k))
Case "性别"
filter = filter & " And " & "性别 = \'" & colsNames(k) & "\'"
Case "民族"
filter = filter & " And " & "民族 = \'" & colsNames(k) & "\'"
Case "学历"
If colsNames(k) = "研究生及以上" Then
filter = filter & " And " & "全日制学历代码 like \'1%\'"
ElseIf colsNames(k) = "本专科学历" Then
filter = filter & " And " & "全日制学历代码 like \'2%\'"
Else
filter = filter & " And " & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Case "政治面貌"
If colsNames(k) = "中共党员" Then
filter = filter & " And " & "入党时间 IS NOT NULL"
Else
filter = filter & " And " & "入党时间 IS NULL"
End If
Case "职务级别"
filter = filter & " And " & "现任行政级别 = \'" & colsNames(k) & "\'"
End Select
Sum = Tables("基本情况").Compute("Count(姓名)", """" & filter & """")
Tables("二维表统计结果").Rows(j)(k+1) = Sum
Next
j = j + 1
Next
Case "学历"
For Each xlj As String In xl.Values
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Tables("二维表统计结果").Rows(j)(0) = xlj \'第一列赋值
For k As Integer = 0 To colsNames.Count -1
filter = "" \'清空前一次的查询条件
Sum = 0 \'将前一次统计结果归零
If xlj = "研究生及以上" Then
filter = filter & "全日制学历代码 like \'1%\'"
ElseIf xlj = "本专科学历" Then
filter = filter & "全日制学历代码 like \'2%\'"
Else
filter = filter & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Select Case YResult
Case "年龄"
filter = filter & Functions.Execute("SetDateStr", colsNames(k))
Case "性别"
filter = filter & " And " & "性别 = \'" & colsNames(k) & "\'"
Case "民族"
filter = filter & " And " & "民族 = \'" & colsNames(k) & "\'"
Case "学历"
If colsNames(k) = "研究生及以上" Then
filter = filter & " And " & "全日制学历代码 like \'1%\'"
ElseIf colsNames(k) = "本专科学历" Then
filter = filter & " And " & "全日制学历代码 like \'2%\'"
Else
filter = filter & " And " & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Case "政治面貌"
If colsNames(k) = "中共党员" Then
filter = filter & " And " & "入党时间 IS NOT NULL"
Else
filter = filter & " And " & "入党时间 IS NULL"
End If
Case "职务级别"
filter = filter & " And " & "现任行政级别 = \'" & colsNames(k) & "\'"
End Select
Sum = Tables("基本情况").Compute("Count(姓名)", """" & filter & """")
Tables("二维表统计结果").Rows(j)(k+1) = Sum
Next
j = j + 1
Next
Case "政治面貌"
For Each zzmmj As String In zzmm.Values
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Tables("二维表统计结果").Rows(j)(0) = zzmmj \'第一列赋值
For k As Integer = 0 To colsNames.Count -1
filter = "" \'清空前一次的查询条件
Sum = 0 \'将前一次统计结果归零
If zzmmj = "中共党员" Then
filter = filter & "入党时间 IS NOT NULL"
Else
filter = filter & "入党时间 IS NULL"
End If
Select Case YResult
Case "年龄"
filter = filter & Functions.Execute("SetDateStr", colsNames(k))
Case "性别"
filter = filter & " And " & "性别 = \'" & colsNames(k) & "\'"
Case "民族"
filter = filter & " And " & "民族 = \'" & colsNames(k) & "\'"
Case "学历"
If colsNames(k) = "研究生及以上" Then
filter = filter & " And " & "全日制学历代码 like \'1%\'"
ElseIf colsNames(k) = "本专科学历" Then
filter = filter & " And " & "全日制学历代码 like \'2%\'"
Else
filter = filter & " And " & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Case "政治面貌"
If colsNames(k) = "中共党员" Then
filter = filter & " And " & "入党时间 IS NOT NULL"
Else
filter = filter & " And " & "入党时间 IS NULL"
End If
Case "职务级别"
filter = filter & " And " & "现任行政级别 = \'" & colsNames(k) & "\'"
End Select
Sum = Tables("基本情况").Compute("Count(姓名)", """" & filter & """")
Tables("二维表统计结果").Rows(j)(k+1) = Sum
Next
j = j + 1
Next
Case "职务级别"
For Each zwjbj As String In zwjb.Values
Tables("二维表统计结果").Rows.AddNew() \'增加一行
Tables("二维表统计结果").Rows(j)(0) = zwjbj \'第一列赋值
For k As Integer = 0 To colsNames.Count -1
filter = "" \'清空前一次的查询条件
Sum = 0 \'将前一次统计结果归零
filter = filter & "现任行政级别 = \'" & zwjbj & "\'"
Select Case YResult
Case "年龄"
filter = filter & Functions.Execute("SetDateStr", colsNames(k))
Case "性别"
filter = filter & " And " & "性别 = \'" & colsNames(k) & "\'"
Case "民族"
filter = filter & " And " & "民族 = \'" & colsNames(k) & "\'"
Case "学历"
If colsNames(k) = "研究生及以上" Then
filter = filter & " And " & "全日制学历代码 like \'1%\'"
ElseIf colsNames(k) = "本专科学历" Then
filter = filter & " And " & "全日制学历代码 like \'2%\'"
Else
filter = filter & " And " & "全日制学历代码 not like \'1%\'" & " And " & "全日制学历代码 not like \'2%\'"
End If
Case "政治面貌"
If colsNames(k) = "中共党员" Then
filter = filter & " And " & "入党时间 IS NOT NULL"
Else
filter = filter & " And " & "入党时间 IS NULL"
End If
Case "职务级别"
filter = filter & " And " & "现任行政级别 = \'" & colsNames(k) & "\'"
End Select
Sum = Tables("基本情况").Compute("Count(姓名)", """" & filter & """")
Tables("二维表统计结果").Rows(j)(k+1) = Sum
Next
j = j + 1
Next
End Select
Forms("二维表统计指标").Close()\'关闭弹出框
Forms("二维表统计结果").Open()\'显示统计结果
Else
MessageBox.Show("请选择横轴和纵轴的统计指标", "提示")
End If
MainTable = Tables("背景")