Foxtable(狐表)用户栏目专家坐堂 → 按日/周/月/季,如何设置汇总


  共有5194人关注过本帖树形打印复制链接

主题:按日/周/月/季,如何设置汇总

帅哥哟,离线,有人找我吗?
狐狸爸爸
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/12/6 8:10:00 [显示全部帖子]


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/12/6 11:09:00 [显示全部帖子]

我把当日的也写好了:
 
 
Dim d As Date = e.Form.Controls("DateTimePicker1").value
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim dt1 As New Date(y, m, 1) '按月统计
Dim q As Integer = math.Ceiling(d.month / 3)
Dim dt2 As New Date(y, 3 * (q - 1) + 1, 1) '获取该季度的第一天
Dim dt3 As New Date(y, 3 * q, Date.DaysInMonth(2011,3 * q)) '获取该季度的最后一天
Dim filter As String = ""
DataTables("汇总").StopRedraw
DataTables("汇总").DataRows.Clear
For Each xh As String In DataTables("库存流水帐").GetValues("型号", "型号 is not null")
    Dim ndr As DataRow = DataTables("汇总").AddNew
    ndr("型号") = xh
    filter = "型号 = '" & xh & "' and 时间 >= #" & dt1 & "# and 时间 < #" & dt1.AddMonths(1) & "#"
    ndr("入库统计_本月累计入库") = DataTables("库存流水帐").Compute("sum(入库数量)", filter)
    ndr("出库统计_本月累计出库") = DataTables("库存流水帐").Compute("sum(出库数量)", filter)
    filter = "型号 = '" & xh & "' and 时间 >= #" & dt2 & "# and 时间 < #" & dt3.AddDays(1) & "#"
    ndr("入库统计_本季累计入库") = DataTables("库存流水帐").Compute("sum(出库数量)", filter)
    filter = "型号 = '" & xh & "' and 时间 = #" & d & "#"
    ndr("入库统计_本日入库") = DataTables("库存流水帐").Compute("sum(入库数量)", filter)
    ndr("出库统计_当日出库") = DataTables("库存流水帐").Compute("sum(出库数量)", filter)
Next
DataTables("汇总").ResumeRedraw


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/12/6 11:15:00 [显示全部帖子]

本周的也加上了:

 

Dim d As Date = "11/1/2013"  '这是你输入的日期
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim w As Integer = d.DayOfWeek '算出今天是星期几
Dim dt1 As New Date(y, m, 1) '按月统计
Dim q As Integer = math.Ceiling(d.month / 3)
Dim dt2 As New Date(y, 3 * (q - 1) + 1, 1) '获取该季度的第一天
Dim dt3 As New Date(y, 3 * q, Date.DaysInMonth(2011,3 * q)) '获取该季度的最后一天
Dim dt4 As Date = d.AddDays(-w) '获取本周的第一天
Dim dt5 As Date = d.AddDays(6 - w) '获取本周的最后一天
Dim filter As String = ""
DataTables("汇总").StopRedraw
DataTables("汇总").DataRows.Clear
For Each xh As String In DataTables("库存流水帐").GetValues("型号", "型号 is not null")
    Dim ndr As DataRow = DataTables("汇总").AddNew
    ndr("型号") = xh
    filter = "型号 = '" & xh & "' and 时间 >= #" & dt1 & "# and 时间 < #" & dt1.AddMonths(1) & "#"
    ndr("入库统计_本月累计入库") = DataTables("库存流水帐").Compute("sum(入库数量)", filter)
    ndr("出库统计_本月累计出库") = DataTables("库存流水帐").Compute("sum(出库数量)", filter)
    filter = "型号 = '" & xh & "' and 时间 >= #" & dt2 & "# and 时间 < #" & dt3.AddDays(1) & "#"
    ndr("入库统计_本季累计入库") = DataTables("库存流水帐").Compute("sum(出库数量)", filter)
    filter = "型号 = '" & xh & "' and 时间 = #" & d & "#"
    ndr("入库统计_本日入库") = DataTables("库存流水帐").Compute("sum(入库数量)", filter)
    ndr("出库统计_当日出库") = DataTables("库存流水帐").Compute("sum(出库数量)", filter)
    filter = "型号 = '" & xh & "' and 时间 >= #" & dt4 & "# and 时间 <= #" & dt5 & "#"
    ndr("入库统计_本周累计入库") = DataTables("库存流水帐").Compute("sum(入库数量)", filter)
Next
DataTables("汇总").ResumeRedraw


 回到顶部