以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  统计代码无效(蓝色部分),试用版能用,专业版不行.SQL数据库  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=141803)

--  作者:akkio99
--  发布时间:2019/10/11 11:04:00
--  统计代码无效(蓝色部分),试用版能用,专业版不行.SQL数据库

Dim rb1 As WinForm.RadioButton = e.Form.Controls("RadioButton1")



Dim Filter As String
With e.Form.Controls("TextBox3")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter =Filter &   "工程名称 like \'%" & .Value & "%\' "
    End If
End With

With e.Form.Controls("ComboBox1")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter =Filter &   "数据状态 = \'" & .Value & "\' "
    End If 
End With

With e.Form.Controls("TextBox4")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter =Filter &   "委托单位 like \'%" & .Value & "%\' "
    End If
End With

With e.Form.Controls("TextBox1")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter = Filter & "工程代码= \'" & .Value & "\'"
    End If
End With

With e.Form.Controls("TextBox2")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter = Filter & "合同编号= \'" & .Value & "\'"
    End If
End With


With e.Form.Controls("TextBox5")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter = Filter & "样品编号= \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("TextBox6")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If 
        Filter = Filter & "报告编号 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("DateTimePicker1")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If 
        Filter =Filter &  "收样日期 >= \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("DateTimePicker2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If 
        Filter =Filter &  "收样日期 <= \'" & .Value & "\'"
    End If
End With




If Filter > "" Then
Dim db As String 
If e.Form.Controls("RadioButton3").checked="True" Then
db="jcnet2014"
End If
If e.Form.Controls("RadioButton4").checked="True" Then
db="jcnet2015"
End If
If e.Form.Controls("RadioButton5").checked="True" Then
db="jcnet"
End If
If e.Form.Controls("RadioButton6").checked="True" Then
db="jcnet_yj"
End If
If e.Form.Controls("RadioButton7").checked="True" Then
db="jcnet_zx"
End If
If rb1.Checked=True Then
Dim sql As String = "s elect name as 检测项目,ph_num as 样品编号,prt_num as 报告编号,xht_htnum as 合同编号,sy_date as 收样日期,prdate as 打印日期,wt_code as 工程代码,gc_name as 工程名称,wt_unit as 委托单位,(use_ip+1)/(use_ip+1) as 数量,(case when (SUBSTRING(data_ip, 8, 1) = \'1\') then \'已打印\' when (SUBSTRING(data_ip, 7, 1) = \'1\') then \'已批准\' when (SUBSTRING(data_ip, 6, 1) = \'1\') then \'已审核\' when (SUBSTRING(data_ip, 5, 1) = \'1\') then \'已校核\' when (SUBSTRING(data_ip, 4, 1) = \'1\') then \'已出记录\' when (SUBSTRING(data_ip, 3, 1) = \'1\') then \'已试验\' when (SUBSTRING(data_ip, 2, 1) = \'1\') then \'未试验\' when (SUBSTRING(data_ip, 1, 1) = \'1\') then \'待复核\'  Else \'\' end) as 数据状态,(case when note_ip=\'y\' then \'合格\' when note_ip=\'n\' then \'不合格\' else \'\' end ) as 结论,(case when sg=\'y\' then \'见证送检\' when sg=\'p\' then \'普通送检\' else \'其他\' end ) as 送检类型,xht_id as 监管平台ID from { sysdata_view} where DATEDIFF([yyyy], sy_date, GETDATE()) = 0 order by ph_num"
Tables("检测进度_Table1").Fill(sql,db,True)
Tables("检测进度_Table1").filter=filter
Tables("检测进度_table1").AutoSizeCols()
Else
Dim sql As String = "s elect name as 检测项目,ph_num as 样品编号,prt_num as 报告编号,xht_htnum as 合同编号,sy_date as 收样日期,prdate as 打印日期,wt_code as 工程代码,gc_name as 工程名称,wt_unit as 委托单位,(use_ip+1)/(use_ip+1) as 数量,xht_id as 监管平台ID from { sysdata_view} where DATEDIFF([yyyy], sy_date, GETDATE()) = 0 order by ph_num"
Dim b As New CrossTableBuilder("统计",sql,db) 
b.HGroups.AddDef("检测项目")
b.HGroups.AddDef("工程名称")
b.HGroups.AddDef("委托单位")
b.VGroups.AddDef("收样日期",DateGroupEnum.Year,"{0}年")  \'添加日期列用于垂直分组,按年分组
b.VGroups.AddDef("收样日期",DateGroupEnum.month,"{0}月")  \'添加日期列用于垂直分组,按月分组
\'b.VGroups.AddDef("收样日期",DateGroupEnum.day,"{0}日")  \'添加日期列用于垂直分组,按日分组
b.Totals.AddDef("数量")   
b.HorizontalTotal = True
b.VerticalTotal = True
b.Build()
b.Filter=Filter
Tables("检测进度_table1").DataSource = b.build()
With Tables("检测进度_table1")
    .AutoSizeCols()

End With
End If
Else
MessageBox.Show("请至少先选择一个查询条件")
End If

--  作者:有点蓝
--  发布时间:2019/10/11 11:12:00
--  
Dim b As New CrossTableBuilder("统计",sql,db)
b.HGroups.AddDef("检测项目")
b.HGroups.AddDef("工程名称")
b.HGroups.AddDef("委托单位")
b.VGroups.AddDef("收样日期",DateGroupEnum.Year,"{0}年")  \'添加日期列用于垂直分组,按年分组
b.VGroups.AddDef("收样日期",DateGroupEnum.month,"{0}月")  \'添加日期列用于垂直分组,按月分组
\'b.VGroups.AddDef("收样日期",DateGroupEnum.day,"{0}日")  \'添加日期列用于垂直分组,按日分组
b.Totals.AddDef("数量")
b.HorizontalTotal = True
b.VerticalTotal = True
b.Build() ‘这一句去掉
b.Filter=Filter
Tables("检测进度_table1").DataSource = b.BuildDataSource()

--  作者:akkio99
--  发布时间:2019/10/11 11:15:00
--  
这样也不行啊。是一样的,先谢谢了
--  作者:有点蓝
--  发布时间:2019/10/11 11:20:00
--  
这样能不能生成统计表主表?

Dim b As New CrossTableBuilder("统计",sql,db)
b.HGroups.AddDef("检测项目")
b.HGroups.AddDef("工程名称")
b.HGroups.AddDef("委托单位")
b.VGroups.AddDef("收样日期",DateGroupEnum.Year,"{0}年")  \'添加日期列用于垂直分组,按年分组
b.VGroups.AddDef("收样日期",DateGroupEnum.month,"{0}月")  \'添加日期列用于垂直分组,按月分组
\'b.VGroups.AddDef("收样日期",DateGroupEnum.day,"{0}日")  \'添加日期列用于垂直分组,按日分组
b.Totals.AddDef("数量")
b.HorizontalTotal = True
b.VerticalTotal = True
b.Filter=Filter
b.Build()
maintable = tables("统计")

--  作者:akkio99
--  发布时间:2019/10/11 11:43:00
--  
不行呢。 我删除掉“order by ph_num” 就可以了。 原来问题出在这里