以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  增加两日期之间统计数量代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=9288)

--  作者:caoxy
--  发布时间:2011/3/25 18:34:00
--  增加两日期之间统计数量代码

师傅你好:请帮我加代码

1、在开始日期和结束日期之间统计不同品种的数量;

Dim khs As List(of String) = DataTables("出口处理").GetUniqueValues("用盘单位 > \'\'", "用盘单位")
Dim pds As List(of String) = DataTables("出口处理").GetUniqueValues("品种1  > \'\'", "品种1")
Dim dt AS New DataTableBuilder("处理数量")
dt.AddDef("客户", Gettype(String), 32)
For i As Integer = 2 To 8
    Dim lst As List(of String)  = DataTables("出口处理").GetUniqueValues("品种" & i &  " > \'\'", "品种" & i)
    For Each nm AS String In Lst
        If pds.Contains(nm) = False
            pds.Add(nm)
        End If
    Next
Next
For Each pd As String In pds
    dt.AddDef(pd, Gettype(Integer))
Next
dt.Build
Dim tb AS Table = Tables("处理数量")
Dim Sum AS Integer
For Each kh As String In khs
    Dim r As Row = tb.AddNew()
    r("客户")  = kh
    For Each pd As String In pds
        sum = 0
        For i As Integer = 1 To 8
            sum = sum + DataTables("出口处理").Compute("Sum(数量" & i & ")", "品种" & i & " = \'" & pd & "\' And 用盘单位 = \'"  & kh & "\'")
        Next
        r(pd) = sum
    Next
Next
Dim sr As Row = tb.AddNew()
sr("客户") = "合计"
For Each pd As String In pds
    sum = 0
    For Each r AS Row In tb.Rows
        sum = sum + r(pd)
    Next
    sr(pd) = sum
Next

谢谢!


--  作者:caoxy
--  发布时间:2011/3/26 7:23:00
--  

请师傅帮忙,加一个开始日期和结束日期的统计代码


--  作者:狐狸爸爸
--  发布时间:2011/3/26 7:58:00
--  

加上给GetUniqueValues和Compute加上日期条件就行啊:

 

Dim khs As List(of String) = DataTables("出口处理").GetUniqueValues("用盘单位 > \'\'", "用盘单位")
Dim pds As List(of String) = DataTables("出口处理").GetUniqueValues("品种1  > \'\'", "品种1")
Dim dt1 AS Date = "#02/01/2011" \'开始日期
Dim dt2 AS Date = "#12/31/2011" \'结束日期
Dim rf As String  = " And 日期 >= #" & dt1 & "# And 日期 <= #" & dt2 & "#"

Dim dt AS New DataTableBuilder("处理数量")
dt.AddDef("客户", Gettype(String), 32)
For i As Integer = 2 To 8
    Dim lst As List(of String)  = DataTables("出口处理").GetUniqueValues("品种" & i &  " > \'\'" & rf , "品种" & i)
    For Each nm AS String In Lst
        If pds.Contains(nm) = False
            pds.Add(nm)
        End If
    Next
Next
For Each pd As String In pds
    dt.AddDef(pd, Gettype(Integer))
Next
dt.Build
Dim tb AS Table = Tables("处理数量")
Dim Sum AS Integer
For Each kh As String In khs
    Dim r As Row = tb.AddNew()
    r("客户")  = kh
    For Each pd As String In pds
        sum = 0
        For i As Integer = 1 To 8
            sum = sum + DataTables("出口处理").Compute("Sum(数量" & i & ")", "品种" & i & " = \'" & pd & "\' And 用盘单位 = \'"  & kh & "\'" & rf)
        Next
        r(pd) = sum
    Next
Next
Dim sr As Row = tb.AddNew()
sr("客户") = "合计"
For Each pd As String In pds
    sum = 0
    For Each r AS Row In tb.Rows
        sum = sum + r(pd)
    Next
    sr(pd) = sum
Next

 

[此贴子已经被作者于2011-3-26 8:03:54编辑过]

--  作者:caoxy
--  发布时间:2011/3/26 9:39:00
--  
出现错误:从字符串“#02/01/2011”到类型“Date”的转换无效
--  作者:狐狸爸爸
--  发布时间:2011/3/26 9:53:00
--  
我手误,漏掉了个#, 应该:
 
Dim dt1 AS Date = #02/01/2011#  \'开始日期
Dim dt2 AS Date = #12/31/2011#  \'结束日期




--  作者:caoxy
--  发布时间:2011/3/26 11:20:00
--  

上面代码统计的数据不是开始日期和结束日期之间的数据,而是全部数据


--  作者:狐狸爸爸
--  发布时间:2011/3/26 11:38:00
--  

这是不可能的事情


--  作者:caoxy
--  发布时间:2011/3/26 12:10:00
--  

我在易表上从2011-01-01至2011-03-25统计的数据和上面代码统计的数据一样,也就是对日期选择统计没有效果。

 


--  作者:caoxy
--  发布时间:2011/3/26 12:21:00
--  

是不是这两个日期的限制:

Dim dt1 AS Date = "#02/01/2011#" \'开始日期
Dim dt2 AS Date = "#12/31/2011#" \'结束日期
Dim rf As String  = " And 出单日期 >= #" & dt1 & "# And 出单日期 <= #" & dt2 & "#"


--  作者:caoxy
--  发布时间:2011/3/26 13:41:00
--  

请师傅帮忙呀