老师:如何在窗口的 SelectedIndexChanged 事件中判断是否汇总行,如果是汇总行则提示,否则执行代码
程序代码如下,但是,当选择汇总行后会报错,为规避此情况,需要加个判断,但我试了几次,不行,您给指导一下
Dim tab As WinForm.TabControl = e.Form.Controls("TabControl1")
If tab.SelectedIndex = 2 Then
If Tables("查询 业绩窗口_Table3").rows.count > 0 Then
Dim DR1 As DataRow = Tables("查询 业绩窗口_Table3").Current.DataRow
Dim DR2 As String = DR1("销售顾问")
If Tables("查询 业绩窗口_Table3").cols.count > 5 Then
Dim bd1 As New GroupTableBuilder("统计表1",DataTables("商品车销售基础表"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("关联索引二列","关联索引二列")
bd1.Groups.AddDef("销售顾问","销售顾问")
bd1.Groups.AddDef("客户姓名","客户姓名")
bd1.Groups.AddDef("车型","车型")
bd1.Totals.AddDef("裸车利润")
bd1.Totals.AddDef("上牌利润")
bd1.Totals.AddDef("保险利润")
bd1.Totals.AddDef("装具利润","装俱利润")
bd1.Totals.AddDef("贷款利润","金融利润")
bd1.Totals.AddDef("二手车销售利润","置换利润")
bd1.Totals.AddDef("边际利润")
bd1.Totals.AddDef("利润总额","综合利润")
bd1.Totals.AddDef("关联索引二列",AggregateEnum.Count,"结算数量") '对结项数量进行统计
bd1.Filter = "销售顾问 = '"& DR2 &"'and 结算日期 >= #" & e.Form.Controls("DateTimePicker5").Value & "# And 结算日期 <= #" & e.Form.Controls("DateTimePicker6").value & "# "
If bd1.Filter >"" Then
dt1 = bd1.BuildDataSource()
Tables("查询 业绩窗口_Table2").DataSource = dt1
DataTables("查询 业绩窗口_Table2").DataCols("裸车利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("上牌利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("保险利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("装俱利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("金融利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("置换利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("边际利润").SetFormat("#,###.00")
DataTables("查询 业绩窗口_Table2").DataCols("综合利润").SetFormat("#,###.00")
Dim t As Table = Tables("查询 业绩窗口_Table2") '汇总
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = True
t.TreeVisible = True
t.SpillNode = True
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "*"
g.TotalOn = "结算数量,裸车利润,上牌利润,保险利润,装俱利润,金融利润,置换利润,边际利润,综合利润"
g.Caption = "总计"
t.SubtotalGroups.Add(g)
Tables("查询 业绩窗口_Table2").SetColVisibleWidth("销售顾问|70|结算数量|70|客户姓名|120|车型|100|裸车利润|90|上牌利润|90|保险利润|90|装俱利润|90|金融利润|90|置换利润|90|边际利润|100|综合利润|100") '设置列的宽度和位置
t.Subtotal()
End If
ElseIf DR1.IsNull("销售顾问")=False And Tables("查询 业绩窗口_Table3").cols.count < 5 Then
Dim bd11 As New GroupTableBuilder("统计表3",DataTables("商品车销售基础表"))
Dim dt11 As fxDataSource
bd11.Groups.AddDef("关联索引二列","关联索引二列")
bd11.Groups.AddDef("销售顾问","销售顾问")
bd11.Groups.AddDef("客户姓名","客户姓名")
bd11.Groups.AddDef("车型","车型")
bd11.Groups.AddDef("订车日期",DateGroupEnum.None,"订车日期")
bd11.Totals.AddDef("车型",AggregateEnum.Count,"新增数量") '对结项数量进行统计
bd11.Filter = "销售顾问 = '"& DR2 &"'and 订车日期 >= #" & e.Form.Controls("DateTimePicker5").Value & "# And 订车日期 <= #" & e.Form.Controls("DateTimePicker6").value & "# "
dt11 = bd11.BuildDataSource()
Dim bd12 As New GroupTableBuilder("统计表4",DataTables("商品车销售基础表"))
Dim dt12 As fxDataSource
bd12.Groups.AddDef("关联索引二列","关联索引二列")
bd12.Groups.AddDef("销售顾问","销售顾问")
bd12.Groups.AddDef("客户姓名","客户姓名")
bd12.Groups.AddDef("车型","车型")
bd12.Groups.AddDef("订车日期",DateGroupEnum.None,"订车日期")
bd12.Groups.AddDef("退单日期",DateGroupEnum.None,"退单日期")
bd12.Groups.AddDef("退单原因",DateGroupEnum.None,"退单原因")
bd12.Totals.AddDef("车型",AggregateEnum.Count,"退单数量") '对结项数量进行统计
bd12.Filter = " 销售顾问 = '"& DR2 &"'and 退单日期 >= #" & e.Form.Controls("DateTimePicker5").Value & "# And 退单日期 <= #" & e.Form.Controls("DateTimePicker6").value & "# "
If bd12.Filter >"" Then
dt12 = bd12.BuildDataSource()
Dim nms As String() = {"关联索引二列","销售顾问","客户姓名","车型","订车日期"} '指定连接列
dt11.Combine(nms,dt12,nms) '合并统计数据
Tables("查询 业绩窗口_Table2").DataSource = dt11
Dim t As Table = Tables("查询 业绩窗口_Table2") '汇总
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = True
t.TreeVisible = True
t.SpillNode = True
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "*"
g.TOTALOn = "新增数量,退单数量"
g.Caption = "总计"
t.SubtotalGroups.Add(g)
Tables("查询 业绩窗口_Table2").SetColVisibleWidth("销售顾问|70|客户姓名|120|车型|100|订车日期|90|新增数量|50|退单日期|90|退单数量|50|退单原因|500|") '设置列的宽度和位置
t.Subtotal()
End If
End If
End If
End If