以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 求代码优化 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=81774) |
-- 作者:kgdce -- 发布时间:2016/3/5 11:32:00 -- 求代码优化 下面这段代码分组顺序不同,表显示的结果不同,能否简化这段程序,实现按照选择的次序(可能先选性别再选民族,也有可能也选民族再选性别)进行分组 Dim cmbt1 As String = cmb1.SelectedText Dim cmbt2 As String = cmb2.SelectedText Dim cmbt3 As String = cmb3.SelectedText Dim cmbt4 As String = cmb4.SelectedText Dim cmbt5 As String = cmb5.SelectedText Dim sg As New GroupTableBuilder("T分dj",datatables("统考dj")) Select Case cmbt1 \'范围 Case "区" sg.Groups.AddDef("qx") \'根据区县分组 Case "校" sg.Groups.AddDef("qx") \' sg.Groups.AddDef("xx") \'根据学校分组 Case "师" sg.Groups.AddDef("qx") \' sg.Groups.AddDef("xx") \' sg.Groups.AddDef("jx") \'根据教师分组 End Select Select Case cmbt5 Case "类别-民族-性别" If cmbt2 = "是" Then sg.Groups.AddDef("lb") \'根据类别分组 End If If cmbt3 = "是" Then sg.Groups.AddDef("mz") \'根据民族分组 End If If cmbt4 = "是" Then sg.Groups.AddDef("xb") \'根据性别分组 End If Case "类别-性别-民族" If cmbt2 = "是" Then sg.Groups.AddDef("lb") \'根据类别分组 End If If cmbt4 = "是" Then sg.Groups.AddDef("xb") \'根据性别分组 End If If cmbt3 = "是" Then sg.Groups.AddDef("mz") \'根据民族分组 End If Case "性别-类别-民族" If cmbt4 = "是" Then sg.Groups.AddDef("xb") \'根据性别分组 End If If cmbt2 = "是" Then sg.Groups.AddDef("lb") \'根据类别分组 End If If cmbt3 = "是" Then sg.Groups.AddDef("mz") \'根据民族分组 End If Case "性别-民族-类别" If cmbt4 = "是" Then sg.Groups.AddDef("xb") \'根据性别分组 End If If cmbt3 = "是" Then sg.Groups.AddDef("mz") \'根据民族分组 End If If cmbt2 = "是" Then sg.Groups.AddDef("lb") \'根据类别分组 End If Case "民族-类别-性别" If cmbt3 = "是" Then sg.Groups.AddDef("mz") \'根据民族分组 End If If cmbt2 = "是" Then sg.Groups.AddDef("lb") \'根据类别分组 End If If cmbt4 = "是" Then sg.Groups.AddDef("xb") \'根据性别分组 End If Case "民族-性别-类别" If cmbt3 = "是" Then sg.Groups.AddDef("mz") \'根据民族分组 End If If cmbt4 = "是" Then sg.Groups.AddDef("xb") \'根据性别分组 End If If cmbt2 = "是" Then sg.Groups.AddDef("lb") \'根据类别分组 End If End Select Tables("T分综合分析_table1").DataSource = DataTables("T分dj")
[此贴子已经被作者于2016/3/5 11:59:54编辑过]
|
-- 作者:Hyphen -- 发布时间:2016/3/5 11:59:00 -- Dim cmbt1 As String = cmb1.SelectedText Dim cmbt2 As String = cmb2.SelectedText Dim cmbt3 As String = cmb3.SelectedText Dim cmbt4 As String = cmb4.SelectedText Dim cmbt5 As String = cmb5.SelectedText Dim dict As new Dictionary(of String,String) dict.Add("类别",new String(1) {cmbt2,"lb"}) dict.Add("民族",new String(1) {cmbt3,"mz"}) dict.Add("性别",new String(1) {cmbt4,"xb"}) Dim sg As New GroupTableBuilder("T分dj","统考dj") Select Case cmbt1 \'范围 Case "区" sg.Groups.AddDef("qx") \'根据区县分组 Case "校" sg.Groups.AddDef("qx") \' sg.Groups.AddDef("xx") \'根据学校分组 Case "师" sg.Groups.AddDef("qx") \' sg.Groups.AddDef("xx") \' sg.Groups.AddDef("jx") \'根据教师分组 End Select Dim tmp() As String = cmbt5.Split("-") For i As Integer =0 To tmp.Length - 1 Then Dim v = dict(tmp(i)) If v(0) = "是" Then sg.Groups.AddDef(v(1)) Next Tables("T分综合分析_table1").DataSource = DataTables("T分dj")
|