-- 作者:susu312
-- 发布时间:2018/10/10 8:09:00
--
以下是引用有点蓝在2018/10/9 23:35:00的发言: 贴出出错按钮的完整代码
\'\'定义数据三个统计1\\2\\3的数据字典,便于引用显示值 Dim dmp1 = Tables("统计1").cols("分组列").DataMap Dim dmp2 = Tables("统计2").cols("分组列").DataMap Dim b1 As New SQLCrossTableBuilder("统计表1","person") Dim b2 As New SQLCrossTableBuilder("统计表2","history") \'\'数据库指定 b1.C b2.C \'\'设置合并 Dim dt1 As fxDataSource Dim dt2 As fxDataSource \'\'设置水平分组 Dim count1 As Integer = 0 For Each r As Row In Tables("统计1").Rows If r.IsNull("分组列")=False Then If r.IsNull("日期分组")=False Then b1.HGroups.AddDef(r("分组列"), DateGroupEnum.Year, r("标题") ) b2.HGroups.AddDef(r("分组列"), DateGroupEnum.Year, r("标题") ) Else b1.HGroups.AddDef(r("分组列"),r("标题") )\'添加列用于水平分组 b2.HGroups.AddDef(r("分组列"), DateGroupEnum.Year, r("标题") ) End If Else count1 = count1 +1 Continue For End If Next \'\'判断是否没有选择水平分组列 \'If count1= 0 OrElse count1 = Tables("统计1").Rows.Count Then \'MessageBox.Show("请选择水平分组列", "提示", MessageBoxButtons.ok, MessageBoxIcon.Information) \'Return \'End If
\'\'设置垂直分组 count判断的是为空的列 Dim count As Integer = 0 For Each r As Row In Tables("统计2").Rows If r.IsNull("分组列")=False Then count=count+1 End If Next
\'\'判断是否没有选择垂直分组列 If count = 0 OrElse count = Tables("统计2").Rows.Count Then MessageBox.Show("请选择垂直分组列", "提示", MessageBoxButtons.ok, MessageBoxIcon.Information) Return End If \'\'如果只有一组垂直分组列,就给加模式 If count=1 Then For Each r As Row In Tables("统计2").Rows If r.IsNull("分组列") =False Then r("模式") =dmp2( r("分组列")) & "_{0}" b1.VGroups.AddDef(r("分组列"), r("模式")) b2.VGroups.AddDef(r("分组列"), r("模式")) Exit For End If Next
Else For Each r As Row In Tables("统计2").Rows If r.IsNull("分组列")=False Then If r.IsNull("模式")=False Then b1.VGroups.AddDef( r("分组列"), r("模式")) b2.VGroups.AddDef( r("分组列"), r("模式")) Else b1.VGroups.AddDef(r("分组列")) \'添加列用于垂直分组 b2.VGroups.AddDef(r("分组列")) \'添加列用于垂直分组 End If End If Next End If \'
\'\'设置统计 \'\'避免用户跳过几行开始输入的问题 For Each r As Row In Tables("统计2").Rows If r.IsNull("分组列") =False Then b1.Totals.AddDef(r("分组列"), AggregateEnum.Count) \'添加列用于统计 b2.Totals.AddDef(r("分组列"), AggregateEnum.Count) \'添加列用于统计 Exit For End If Next
\'\'设置统计选项 If e.Form.Controls("CheckBox1").Checked = True Then \'水平方向生成汇总 b1.HorizontalTotal = True b2.HorizontalTotal = True End If If e.Form.Controls("CheckBox2").Checked = True Then \'垂直方向生成汇总 b1.VerticalTotal = True b2.VerticalTotal = True End If
\'\'获取统计条件 \'条件 \'\' 获取登录用户单位的辅助列名称,加载时以这个辅助列为条件 Dim organFuZhu As String="" Dim dr2 As DataRow dr2 = DataTables("organList").Find("[organName] = \'" & _UserOrgan & "\'") \'否则在单位表查找同名的单位行,将找到的行赋值给变量dr If dr2 IsNot Nothing Then \'如果找到了同名的单位行,也就是dr不是Nothing organFuZhu = dr2("fuZhu") Else Messagebox.show("登录用户的所属单位不存在!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) Return End If
\'\'\'设定filter的全局条件是基于已经加载的表进行查询 Dim filter As String = "" If _UserRole = "查询员" Then filter = "" Else filter = "fuZhu Like \'" & organFuZhu & "%\'" filter= filter & "And " filter= filter & "len(fuZhu)<= " & organFuZhu.length+5 End If
If vars("filter") = "" Then b1.Filter=filter b2.Filter=filter Else b1.Filter=vars("filter") b2.Filter=vars("filter") End If
If e.Form.Controls("RadioButton2").checked = True Then \'\'如何实时库+历史库被选中 \'\'设置合并 dt1 = b1.BuildDataSource() dt2 = b2.BuildDataSource() dt1.Combine("单位",dt2,"单位") \'将历史库统计数据和实时库统计数据组合到一起 \'\'\'在另外一个窗口打开统计表 forms("统计表").Open Dim t As Table = forms("统计表").controls("Table1").Table t.DataSource = dt1 If e.Form.Controls("CheckBox1").Checked = True OrElse e.Form.Controls("CheckBox2").Checked = True Then \'\'移动合计列 For Each c As Col In t.Cols If c.Name ="合计" Then c.Move(t.Cols.Count-1) End If Next \'\'设置表格居中 For Each c As Col In t.Cols c.TextAlign = TextAlignEnum.Center Next \'\'设置合计列相加 For Each r As Row In t.Rows r("合计") = r("合计1")+r("合计") Next \'\'删除多余的合计列 t.Cols.Remove("合计1") End If t.Select(-1,-1) Else \'\'\'在另外一个窗口打开统计表 forms("统计表").Open Dim t As Table = forms("统计表").controls("Table1").Table t.DataSource = b1.BuildDataSource() For Each c As Col In t.Cols c.TextAlign = TextAlignEnum.Center Next t.Select(-1,-1) End If e.Form.Close
|