下面的代码实现了组合统计,交果如下:
此主题相关图片如下:微信图片_20220901150441.jpg
我想下拉选择空白选项,如图分类统计出所有数据,此效果已实现,我想实现选项中e.Form.Controls("ComboBox1").Value.Split("-")(0) = DataTables("分类").DataRows(0)("分类")就只统计月租缴费组列的数据,临时缴费组列的不统计,同理,下拉选项中e.Form.Controls("ComboBox1").Value.Split("-")(0) = DataTables("分类").DataRows(1)("分类")就只统计临时缴费组列的数据,月租缴费组列的不统计,改为红色注识的代码全部没数据显示,改为红色没识代码效果如图,请教应如何改?
Case "所有收费汇总"
If e.Form.Controls("StartDate").Value = Nothing OrElse e.Form.Controls("EndDate").Value = Nothing Then '当日期为空取消保存操作
messagebox.show("请选择起止日期")
Return
End If
With Tables("安费用所属期查询统计_Table1")
.SubtotalGroups.Clear()
LockBaseMainForm() '锁定主界面
.StopRedraw()
Dim cmd As New SQLCommand
cmd.CommandText = "Select * Fro m {缴费情况} Where [_Identify] Is null"
Dim dt0 As DataTable = cmd.ExecuteReader()
If dt0.DataCols.Contains("查询_月租_所属日期") = False Then
dt0.DataCols.add("查询_月租_所属日期", GetType(Date))
End If
If dt0.DataCols.Contains("查询_月租缴费_业主缴费金额") = False Then
dt0.DataCols.add("查询_月租缴费_业主缴费金额", GetType(Double))
End If
If dt0.DataCols.Contains("查询_月租缴费_租户缴费金额") = False Then
dt0.DataCols.add("查询_月租缴费_租户缴费金额", GetType(Double))
End If
If dt0.DataCols.Contains("查询_月租缴费_外来缴费金额") = False Then
dt0.DataCols.add("查询_月租缴费_外来缴费金额", GetType(Double))
End If
Dim Filter1 As String
With e.Form.Controls("ComboBox1")
If .Value IsNot Nothing Then
Dim Parts() As String = .Value.Split("-")
If Parts(0) = DataTables("分类").DataRows(0)("分类") Then
Filter1 = "分类 = '" & Parts(0) & "'"
If Parts.length > 1 Then
Filter1 = Filter1 & " And 明细分类 = '" & Parts(1) & "'"
End If
End If
ElseIf .Value Is Nothing Then
Filter1 = "分类 = '" & DataTables("分类").DataRows(0)("分类") & "'"
End If
End With
With e.Form.Controls("StartDate")
If .Value IsNot Nothing Then
If Filter1 > "" Then
Filter1 = Filter1 & " And "
End If
Filter1 = Filter1 & "[缴费_月租_起计日期] >= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter1 > "" Then
Filter1 = Filter1 & " And "
End If
Filter1 = Filter1 & "[缴费_月租_止计日期] <= #" & .Value & "#"
End If
End With
With e.Form.Controls("DropBox1")
If .Value IsNot Nothing Then
If Filter1 > "" Then
Filter1 = Filter1 & " And "
End If
Filter1 = Filter1 & "车牌号码 = '" & .Value & "'"
End If
End With
' If (e.Form.Controls("ComboBox1").Value.Split("-")(0) = DataTables("分类").DataRows(0)("分类") Or e.Form.Controls("ComboBox1").Value Is Nothing) And Filter1 > "" Then
If Filter1 > "" Then
Dim drs0 As List(Of DataRow) = DataTables("缴费情况").SQLSelect(Filter1)
Dim a As Integer
For a = 0 To drs0.count - 1
Dim b As Integer
For b = 0 To drs0(a)("缴费_月租_缴费月数") - 1
Dim da0 As DataRow = dt0.AddNew()
da0("分类") = drs0(a)("分类")
da0("明细分类") = drs0(a)("明细分类")
da0("住址_巷") = drs0(a)("住址_巷")
da0("住址_号") = drs0(a)("住址_号")
da0("住址_房") = drs0(a)("住址_房")
da0("姓名") = drs0(a)("姓名")
da0("手机号码") = drs0(a)("手机号码")
da0("车牌号码") = drs0(a)("车牌号码")
da0("缴费_月租_起计日期") = "#" & drs0(a)("缴费_月租_起计日期") & "#"
da0("缴费_月租_止计日期") = "#" & drs0(a)("缴费_月租_止计日期") & "#"
da0("查询_月租_所属日期") = drs0(a)("缴费_月租_起计日期").AddMonths(b)
da0("缴费_月租_月租单价") = drs0(a)("缴费_月租_月租单价")
If da0("明细分类") = DataTables("用户明细分类").DataRows(0)("用户明细分类") Then
da0("查询_月租缴费_业主缴费金额") = drs0(a)("缴费_月租_月租单价")
ElseIf da0("明细分类") = DataTables("用户明细分类").DataRows(1)("用户明细分类") Then
da0("查询_月租缴费_租户缴费金额") = drs0(a)("缴费_月租_月租单价")
ElseIf da0("明细分类") = DataTables("用户明细分类").DataRows(2)("用户明细分类") Then
da0("查询_月租缴费_外来缴费金额") = drs0(a)("缴费_月租_月租单价")
End If
Next
Next
Dim bc As New GroupTableBuilder("统计表2", dt0)
Dim dt1 As fxDataSource
bc.Filter = Filter1
bc.Groups.AddDef("查询_月租_所属日期", DateGroupEnum.Year, "年")
bc.Groups.AddDef("查询_月租_所属日期", DateGroupEnum.Month, "月")
bc.Totals.AddDef("查询_月租缴费_业主缴费金额")
bc.Totals.AddDef("查询_月租缴费_租户缴费金额")
bc.Totals.AddDef("查询_月租缴费_外来缴费金额")
dt1 = bc.BuildDataSource()
Dim cmd01 As New SQLCommand
cmd01.CommandText = "Select * Fro m {缴费情况} Where [_Identify] Is null"
Dim dt01 As DataTable = cmd01.ExecuteReader()
If dt01.DataCols.Contains("查询_临时缴费_亲情缴费金额") = False Then
dt01.DataCols.add("查询_临时缴费_亲情缴费金额", GetType(Double))
End If
If dt01.DataCols.Contains("查询_临时缴费_外来缴费金额") = False Then
dt01.DataCols.add("查询_临时缴费_外来缴费金额", GetType(Double))
End If
Dim Filter2 As String
With e.Form.Controls("ComboBox1")
If .Value IsNot Nothing Then
Dim Parts() As String = .Value.Split("-")
If Parts(0) = DataTables("分类").DataRows(1)("分类") Then
Filter2 = "分类 = '" & Parts(0) & "'"
If Parts.length > 1 Then
Filter2 = Filter2 & " And 明细分类 = '" & Parts(1) & "'"
End If
End If
ElseIf .Value Is Nothing Then
Filter2 = "分类 = '" & DataTables("分类").DataRows(1)("分类") & "'"
End If
End With
If e.Form.Controls("StartDate").Value IsNot Nothing Then
If Filter2 > "" Then
Filter2 = Filter2 & " And "
End If
Filter2 = Filter2 & "[日期] >= #" & e.Form.Controls("StartDate").Value & "#"
End If
If e.Form.Controls("EndDate").Value IsNot Nothing Then
If Filter2 > "" Then
Filter2 = Filter2 & " And "
End If
Filter2 = Filter2 & "[日期] <= #" & e.Form.Controls("EndDate").Value & "#"
End If
With e.Form.Controls("DropBox1")
If .Value IsNot Nothing Then
If Filter2 > "" Then
Filter2 = Filter2 & " And "
End If
Filter2 = Filter2 & "车牌号码 = '" & .Value & "'"
End If
End With
' If (e.Form.Controls("ComboBox1").Value.Split("-")(0) = DataTables("分类").DataRows(1)("分类") Or e.Form.Controls("ComboBox1").Value Is Nothing) And Filter2 > "" Then
If Filter2 > "" Then
Dim drs01 As List(Of DataRow) = DataTables("缴费情况").SQLSelect(Filter2)
Dim a01 As Integer
For a01 = 0 To drs01.count - 1
Dim b As Integer
Dim da01 As DataRow = dt01.AddNew()
da01("日期") = drs01(a01)("日期")
da01("分类") = drs01(a01)("分类")
da01("明细分类") = drs01(a01)("明细分类")
da01("住址_巷") = drs01(a01)("住址_巷")
da01("住址_号") = drs01(a01)("住址_号")
da01("住址_房") = drs01(a01)("住址_房")
da01("姓名") = drs01(a01)("姓名")
da01("手机号码") = drs01(a01)("手机号码")
da01("车牌号码") = drs01(a01)("车牌号码")
If da01("明细分类") = DataTables("用户明细分类").DataRows(3)("用户明细分类") Then
da01("查询_临时缴费_亲情缴费金额") = drs01(a01)("缴费_临时停放_缴费金额")
ElseIf da01("明细分类") = DataTables("用户明细分类").DataRows(4)("用户明细分类") Then
da01("查询_临时缴费_外来缴费金额") = drs01(a01)("缴费_临时停放_缴费金额")
End If
Next
Dim bc1 As New GroupTableBuilder("统计表3", dt01)
Dim dt2 As fxDataSource
bc1.Filter = Filter2
bc1.Groups.AddDef("日期", DateGroupEnum.Year, "年")
bc1.Groups.AddDef("日期", DateGroupEnum.Month, "月")
bc1.Totals.AddDef("查询_临时缴费_亲情缴费金额")
bc1.Totals.AddDef("查询_临时缴费_外来缴费金额")
dt2 = bc1.BuildDataSource()
Dim Filter3 As String
With e.Form.Controls("ComboBox1")
If .Value Is Nothing Then
Filter3 = "[分类] = '" & DataTables("分类").DataRows(2)("分类") & "' Or [分类] = '" & DataTables("分类").DataRows(3)("分类") & "'"
End If
End With
If e.Form.Controls("StartDate").Value IsNot Nothing Then
If Filter3 > "" Then
Filter3 = Filter3 & " And "
End If
Filter3 = Filter3 & "[日期] >= #" & e.Form.Controls("StartDate").Value & "#"
End If
If e.Form.Controls("EndDate").Value IsNot Nothing Then
If Filter3 > "" Then
Filter3 = Filter3 & " And "
End If
Filter3 = Filter3 & "[日期] <= #" & e.Form.Controls("EndDate").Value & "#"
End If
If Filter3 > "" Then
Dim bc2 As New SQLGroupTableBuilder("统计表4", "缴费情况")
Dim dt3 As fxDataSource
bc2.Filter = Filter3
bc2.Groups.AddDef("日期", DateGroupEnum.Year, "年")
bc2.Groups.AddDef("日期", DateGroupEnum.Month, "月")
bc2.Totals.AddDef("缴费_其他收入_金额")
dt3 = bc2.BuildDataSource()
Dim nms As String() = {"年", "月"} '指定连接列
dt1.Combine(nms, dt2, nms) '将销售统计数据组合到进货统计数据
dt1.Combine(nms, dt3, nms) '将销售统计数据组合到进货统计数据
.DataSource = dt1
DataTables("安费用所属期查询统计_Table1").DataCols.Add("当月总收入", GetType(Double), "IsNull([查询_月租缴费_业主缴费金额],0) + IsNull([查询_月租缴费_租户缴费金额],0) + IsNull([查询_月租缴费_外来缴费金额],0) + IsNull([查询_临时缴费_亲情缴费金额],0) + ISNULL([查询_临时缴费_外来缴费金额],0) + ISNULL([缴费_其他收入_金额],0)")
Dim g1 As New Subtotalgroup
g1.GroupOn = "年" '分组列为客户列
g1.TotalOn = "查询_月租缴费_业主缴费金额,查询_月租缴费_租户缴费金额,查询_月租缴费_外来缴费金额,查询_临时缴费_亲情缴费金额,查询_临时缴费_外来缴费金额,缴费_其他收入_金额,当月总收入" '对数量和金额进行统计
g1.Caption = "本年累计"
.SubtotalGroups.Add(g1)
'定义总计分组
Dim g2 As New Subtotalgroup
g2.GroupOn = "*"
g2.TotalOn = "查询_月租缴费_业主缴费金额,查询_月租缴费_租户缴费金额,查询_月租缴费_外来缴费金额,查询_临时缴费_亲情缴费金额,查询_临时缴费_外来缴费金额,缴费_其他收入_金额,当月总收入"
.SubtotalGroups.Add(g2)
.Subtotal() '生成汇总模式
.SetColVisibleWidth("年|70|月|60|查询_月租缴费_业主缴费金额|90|查询_月租缴费_租户缴费金额|90|查询_月租缴费_外来缴费金额|90|查询_临时缴费_亲情缴费金额|90|查询_临时缴费_外来缴费金额|90|缴费_其他收入_金额|90|当月总收入|110")
.SetHeaderRowHeight(0, 25, 25)
.DataTable.DataCols("查询_月租缴费_业主缴费金额").SetFormat("#,###.##")
.DataTable.DataCols("查询_月租缴费_租户缴费金额").SetFormat("#,###.##")
.DataTable.DataCols("查询_月租缴费_外来缴费金额").SetFormat("#,###.##")
.DataTable.DataCols("查询_临时缴费_亲情缴费金额").SetFormat("#,###.##")
.DataTable.DataCols("查询_临时缴费_外来缴费金额").SetFormat("#,###.##")
.DataTable.DataCols("缴费_其他收入_金额").SetFormat("#,###.##")
.DataTable.DataCols("当月总收入").SetFormat("#,###.##")
.ResumeRedraw()
UnLockBaseMainForm() '解锁主界面
End If
End If
End If
End With