Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共16 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:增加两日期之间统计数量代码

1楼
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

谢谢!

2楼
caoxy 发表于:2011/3/26 7:23:00

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

3楼
狐狸爸爸 发表于: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编辑过]
4楼
caoxy 发表于:2011/3/26 9:39:00
出现错误:从字符串“#02/01/2011”到类型“Date”的转换无效
5楼
狐狸爸爸 发表于:2011/3/26 9:53:00
我手误,漏掉了个#, 应该:
 
Dim dt1 AS Date = #02/01/2011#  '开始日期
Dim dt2 AS Date = #12/31/2011#  '结束日期



6楼
caoxy 发表于:2011/3/26 11:20:00

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

7楼
狐狸爸爸 发表于:2011/3/26 11:38:00

这是不可能的事情

8楼
caoxy 发表于:2011/3/26 12:10:00

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

 

9楼
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 & "#"

10楼
caoxy 发表于:2011/3/26 13:41:00

请师傅帮忙呀

 

共16 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02344 s, 2 queries.