以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 数据统计 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187590) |
-- 作者:nuoyan89 -- 发布时间:2023/7/29 10:07:00 -- 数据统计 老师,我的窗口表是用以下“生产临时表的代码”的代码生成的临时表如图2,我想把生产排产表中按照:使用设备、成品编码、月份、生产日期、领用数量等汇总后,把值显示到窗口表中,但是表事件的代码提示异常,如图1,请帮忙看看,谢谢 生成临时表的代码: Dim dtb As New DataTableBuilder("统计") dtb.AddDef("使用设备", GetType(String), 250) dtb.AddDef("设备名称", GetType(String), 250) dtb.AddDef("最小量", GetType(Double), 32) dtb.AddDef("最大量", GetType(Double), 32) dtb.AddDef("领用总量", GetType(Double), 32) dtb.Build() Dim s As String = e.form.controls("月份1").Text Dim d As Date = CDate(s.Insert(4, "-") & "-01") Dim d2 As Date = New Date(d.Year, d.Month, Date.DaysInMonth(d.Year, d.Month)) For i As Integer = d.Day To d2.Day dtb.AddDef(i, GetType(Date)) Next DataTables("使用监控台_现存量").DataCols.Add("使用设备", GetType(String), 100) DataTables("使用监控台_现存量").DataCols.Add("设备名称", GetType(String), 200) Tables("使用监控台_现存量").DataSource = dtb.BuildDataSource() Dim Cols1() As String = {"使用设备", "设备名称"} Dim Cols2() As String = {"使用设备", "设备名称"} For Each dr1 As DataRow In DataTables("设备状态表").sqlSelect("[使用设备] like \'%A%\' and [使用状态] = \'使用中\'") Dim dr2 As DataRow = DataTables("使用监控台_现存量").AddNew() For i As Integer = 0 To Cols1.Length - 1 dr2(Cols2(i)) = dr1(Cols1(i)) Next Next 表事件: If e.DataCol.Name = "使用设备" Then Dim s As String = e.form.controls("月份1").Text Dim d As Date = CDate(s.Insert(4, "-") & "-01") Dim d2 As Date = New Date(d.Year, d.Month, Date.DaysInMonth(d.Year, d.Month)) Dim dict As New Dictionary(Of String, String) For i As Integer = d.Day To d2.Day e.DataRow(i) = Nothing Dim dc As DataCol = e.DataTable.DataCols(i) dict.Add(dc.Caption, dc.Name) Next Dim b As New SQLGroupTableBuilder("统计表1", "油类切消液明细") b.C b.Groups.AddDef("使用设备") b.Groups.AddDef("材料编码") b.Groups.AddDef("领用日期", DateGroupEnum.None) b.Totals.AddDef("领用数量") b.Filter = "使用设备 = \'" & e.DataRow("使用设备") & "\'" Dim dt As DataTable = b.Build(True) For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "yyyy-MM-dd") If dict.ContainsKey(cn) Then e.DataRow(dict(cn)) = dr("领用数量") End If Next End If |
-- 作者:有点蓝 -- 发布时间:2023/7/29 10:11:00 -- 字典添加了重复的键,调试 For i As Integer = d.Day To d2.Day e.DataRow(i) = Nothing Dim dc As DataCol = e.DataTable.DataCols(i) msgbox(dc.Caption & "--" & dc.Name) dict.Add(dc.Caption, dc.Name) Next [此贴子已经被作者于2023/7/29 10:10:54编辑过]
|
-- 作者:nuoyan89 -- 发布时间:2023/7/29 11:07:00 -- 老师,已找到原因,但是结果没有,如图1(但要求和的表里是有值的,如图2) If e.DataCol.Name = "使用设备" Then Dim s As String = e.form.controls("月份1").Text Dim d As Date = CDate(s.Insert(4, "-") & "-01") Dim d2 As Date = New Date(d.Year, d.Month, Date.DaysInMonth(d.Year, d.Month)) Dim dict As New Dictionary(Of String, String) Dim b As New SQLGroupTableBuilder("统计表1", "油类切消液明细") b.C b.Groups.AddDef("使用设备") b.Groups.AddDef("材料编码") b.Groups.AddDef("领用日期", DateGroupEnum.None) b.Totals.AddDef("领用数量") b.Filter = "使用设备 = \'" & e.DataRow("使用设备") & "\'" Dim dt As DataTable = b.Build(True) For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "yyyy-MM-dd") If dict.ContainsKey(cn) Then e.DataRow(dict(cn)) = dr("领用数量") End If Next End If [此贴子已经被作者于2023/7/29 11:08:27编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/7/29 11:19:00 -- 还是要继续2楼的调试,看看msgbox(dc.Caption & "--" & dc.Name)弹出的列标题是什么 下面的列标题又是什么? For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "yyyy-MM-dd") msgbox(cn) If dict.ContainsKey(cn) Then e.DataRow(dict(cn)) = dr("领用数量") End If Next |
-- 作者:nuoyan89 -- 发布时间:2023/7/29 11:43:00 -- 应该是临时表的日期(只显示”日“)和要统计的那个领用日期格式不一样(年、月、日) |
-- 作者:有点蓝 -- 发布时间:2023/7/29 11:45:00 -- 自己想办法改为一样 |
-- 作者:nuoyan89 -- 发布时间:2023/7/29 11:48:00 -- 格式化日期的昨天就开始在研究,还是没研究得了,我把被汇总的那个领用日期也改成天,如代码2,也不行 代码1: Dim s As String = e.form.controls("月份1").Text Dim d As Date = CDate(s.Insert(4, "-") & "-01") Dim d2 As Date = New Date(d.Year, d.Month, Date.DaysInMonth(d.Year, d.Month)) For i As Integer = d.Day To d2.Day dtb.AddDef(i, GetType(Date)) Next 代码2: For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "d") [此贴子已经被作者于2023/7/29 12:56:18编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/7/29 13:19:00 -- 还是基础没学好 方法1、 For i As Integer = d.Day To d2.Day dtb.AddDef(format(new date(d.year,d.month,i), "yyyy_MM_dd"), GetType(Date)) Next …… For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "yyyy_MM_dd") 2、 do while d <= d2 dtb.AddDef(format(d, "yyyy_MM_dd"), GetType(Date)) d=d.adddays(1) loop …… For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "yyyy_MM_dd") 3、 For Each dr As DataRow In dt.DataRows Dim cn As String = dr("领用日期").day |
-- 作者:nuoyan89 -- 发布时间:2023/7/29 14:17:00 -- 是的,目前还是处于比较单一的逻辑关系,老师,变更之后临时表已按照年、月、日显示了,但是对应的值还是没有按照日期进行显示汇总(问题如3楼)。谢谢 求和的代码: Dim s As String = e.form.controls("月份1").Text Dim d As Date = CDate(s.Insert(4, "-") & "-01") Dim d2 As Date = New Date(d.Year, d.Month, Date.DaysInMonth(d.Year, d.Month)) Dim dict As New Dictionary(Of String, String) Dim b As New SQLGroupTableBuilder("统计表1", "油类切消液明细") b.C b.Groups.AddDef("使用设备") b.Groups.AddDef("材料编码") b.Groups.AddDef("领用日期", DateGroupEnum.None) b.Totals.AddDef("领用数量") b.Filter = "使用设备 = \'" & e.DataRow("使用设备") & "\'" Dim dt As DataTable = b.Build(True) For Each dr As DataRow In dt.DataRows Dim cn As String = format(dr("领用日期"), "yyyy-MM-dd") If dict.ContainsKey(cn) Then e.DataRow(dict(cn)) = dr("领用数量") End If Next |
-- 作者:有点蓝 -- 发布时间:2023/7/29 14:21:00 -- 调试方法前面都有,自行调试 |