以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]多表交叉统计 增加统计历史保存  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=96194)

--  作者:jyh7081
--  发布时间:2017/2/15 11:17:00
--  [求助]多表交叉统计 增加统计历史保存
在”有点色“老师的 帮助下,重新设计了 多表交叉统计 窗口,还存在下列问题,请老师再出手指教:
1、如果对统计列要统计平均数如何改代码;
2、双击“统计管理”列表框的值,把“统计管理”数据表中的当前行,赋值给统计窗口的各个“CheckedComboBox”;
3、当“添加分析表”选中两个表时,“数据分析列”不能动态显示选中表的所有列,只能选中一个表的列;


图片点击可在新窗口打开查看此主题相关图片如下:360截图20170215082102975.jpg
图片点击可在新窗口打开查看

附件:
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:2017-2-14多表统计-例子ok.table




--  作者:有点色
--  发布时间:2017/2/15 11:52:00
--  

代码一样。

 

1、如果勾选,那么就执行平均数的统计代码;

 

2、去表格查找对应的行,然后给左边逐个赋值进去;

 

3、

 

If  e.Form.Controls("CheckedComboBox5").Text <> "" Then
    Dim rstr As String
    For Each tname As String In e.Form.Controls("CheckedComboBox5").Text.split("|")
        For Each c As Col In Tables(tname).Cols
            rstr = rstr & c.Name & "|"
        Next     
    Next
   
    rstr =rstr.Trim("|")
    Dim cmb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox8")
    cmb.ComboList = rstr
End If


--  作者:jyh7081
--  发布时间:2017/2/15 14:34:00
--  
谢谢老师,你提示的两点都解决了。(麻烦给审核一下,谢谢!)

就是当“添加分析表”选中两个表时,不出统计结果,不知什么原因?

附件:
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:2017-2-14多表统计-例子ok.table

[此贴子已经被作者于2017/2/15 14:57:57编辑过]

--  作者:有点蓝
--  发布时间:2017/2/15 16:02:00
--  
http://www.foxtable.com/webhelp/scr/1627.htm

帮助最后,看同名列的处理

--  作者:有点色
--  发布时间:2017/2/15 16:14:00
--  

Dim sql As String = ""
For Each s As String In e.Form.Controls("CheckedComboBox5").text.Split("|")
    sql &= " select * from {" & s & "} union all"
Next
sql = "select * from {分析数据} a inner join (" & sql.substring(0, sql.Length-9) & ") As b on a.公历年月日 = b.时间"
\'msgbox(sql)
Dim b As New crossTableBuilder("统计表1", sql)
For Each s As String In e.Form.Controls("CheckedComboBox6").text.Split("|")
    b.HGroups.AddDef(s) \'添加列用于垂直分组
Next
For Each s As String In e.Form.Controls("CheckedComboBox7").text.Split("|")
    b.VGroups.AddDef(s) \'添加列用于水平分组
Next
\'For Each s As String In e.Form.Controls("CheckedComboBox8").text.Split("|")
\'b.Totals.AddDef(s) \'添加列用于统计
\'Next

For Each s As String In e.Form.Controls("CheckedComboBox8").text.Split("|")
    If e.Form.Controls("CheckBox5").checked = True Then   \'平均数统计
        b.Totals.AddDef(s,AggregateEnum.Average)
    Else
        b.Totals.AddDef(s)  \'累计统计
    End If
Next

b.Decimals = 2

If e.Form.Controls("CheckBox1").checked = True Then   \'水平方向生成汇总
    b.HorizontalTotal = True
End If
If e.Form.Controls("CheckBox2").checked = True Then   \'垂直方向生成汇总
    b.VerticalTotal = True
End If
If e.Form.Controls("CheckBox3").checked = True Then   \'自动生成汇总模式
    b.Subtotal = True
End If

b.Filter = e.Form.Controls("TextBox1").Text

b.Build \'生成统计表
MainTable = Tables("统计表1") \'打开生成的统计表
\'Tables("统计_Table1").DataSource= b.BuildDataSource   \'统计表放入指定窗口表


--  作者:jyh7081
--  发布时间:2017/2/15 16:30:00
--  [求助]
老师,还是不行呀。

另外,让关联的[时间]列在下拉列表不显示行不行?
[此贴子已经被作者于2017/2/15 16:38:59编辑过]

--  作者:有点色
--  发布时间:2017/2/15 18:08:00
--  

 我测试,没问题。

 

If  e.Form.Controls("CheckedComboBox5").Text <> "" Then
    Dim rstr As String
    For Each tname As String In e.Form.Controls("CheckedComboBox5").Text.split("|")
        For Each c As Col In Tables(tname).Cols
            If rstr.Contains(c.name) = False Then
                rstr = rstr & c.Name & "|"
            End If
        Next
    Next
   
    rstr = rstr.Trim("|")
    Dim cmb As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox8")
    cmb.ComboList = rstr
End If


--  作者:jyh7081
--  发布时间:2017/2/15 20:01:00
--  

老师,我把代码都写进窗口了,并保存了两个例子。你双击一下,第二个确实没有内容,也没报错,但应该同第一个统计内容相同才对。

另外,7楼的代码加上这句“ For Each c As Col In Tables(tname).Cols”后,就不出选择项了。

 


图片点击可在新窗口打开查看此主题相关图片如下:image 1.jpg
图片点击可在新窗口打开查看

 

附件:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:2017-2-14多表统计-例子ok - 副本.table


--  作者:有点色
--  发布时间:2017/2/16 2:47:00
--  

Dim sql As String = ""
Dim ls_cols As New List(of String)
For Each tname As String In e.Form.Controls("CheckedComboBox5").Text.split("|")
    For Each c As Col In Tables(tname).Cols
        If ls_cols.Contains(c.name) = False Then
            ls_cols.add(c.Name)
        End If
    Next
Next

For Each s As String In e.Form.Controls("CheckedComboBox5").text.Split("|")
    Dim tmp As String = ""
    For Each cname As String In ls_Cols
        If Tables(s).Cols.Contains(cname) Then
            tmp &= "[" & cname & "] As [" & cname & "],"
        Else
            tmp &= "0 as [" & cname & "],"
        End If
    Next
    sql &= " select " & tmp.trim(",") & " from {" & s & "} union all"
Next
sql = "select * from {分析数据} a inner join (" & sql.substring(0, sql.Length-9) & ") As b on a.公历年月日 = b.时间"
output.show(sql)
Dim b As New crossTableBuilder("统计表1", sql)
For Each s As String In e.Form.Controls("CheckedComboBox6").text.Split("|")
    b.HGroups.AddDef(s) \'添加列用于垂直分组
Next
For Each s As String In e.Form.Controls("CheckedComboBox7").text.Split("|")
    b.VGroups.AddDef(s) \'添加列用于水平分组
Next

For Each s As String In e.Form.Controls("CheckedComboBox8").text.Split("|")
    If e.Form.Controls("CheckBox5").checked = True Then   \'平均数统计
        b.Totals.AddDef(s,AggregateEnum.Average)
    Else
        b.Totals.AddDef(s)  \'累计统计
    End If
Next

b.Decimals = 2

If e.Form.Controls("CheckBox1").checked = True Then   \'水平方向生成汇总
    b.HorizontalTotal = True
End If
If e.Form.Controls("CheckBox2").checked = True Then   \'垂直方向生成汇总
    b.VerticalTotal = True
End If
If e.Form.Controls("CheckBox3").checked = True Then   \'自动生成汇总模式
    b.Subtotal = True
End If

b.Filter = e.Form.Controls("TextBox1").Text

b.Build \'生成统计表
MainTable = Tables("统计表1") \'打开生成的统计表
\'Tables("统计_Table1").DataSource= b.BuildDataSource   \'统计表放入指定窗口表


--  作者:jyh7081
--  发布时间:2017/2/16 11:01:00
--  
还有一点问题,就是当勾选汇总方式后,汇总行的小数点总是显示4位,“ b.Decimals = 2 “放到哪里对汇总行都不起作用。


图片点击可在新窗口打开查看此主题相关图片如下:6666.jpg
图片点击可在新窗口打开查看