以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 主表怎么取子表的字段进行计算 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=173623) |
-- 作者:doumao -- 发布时间:2021/12/8 17:27:00 -- 主表怎么取子表的字段进行计算 装机容量 =子表中 分类为“组件”的数量合计值*主表的组件功率 求大神指点,用了表事件也不行
|
-- 作者:有点蓝 -- 发布时间:2021/12/8 17:42:00 -- 参考:http://www.foxtable.com/webhelp/topics/1453.htm |
-- 作者:doumao -- 发布时间:2021/12/8 20:14:00 -- If e.DataCol.Name = "组件功率" Then If e.NewValue Is Nothing Then e.DataRow("装机容量")=Nothing Else Dim dr As DataRow dr = DataTables("光伏物料清单.物料明细表").Find("[分类] = \'组件\'") Dim m As Double = dr(sum("数量")) If dr IsNot Nothing e.DataRow("装机容量")= m * e.DataRow("组件功率") End If End If End If 玩不懂啊 老大求助
|
-- 作者:liufucan -- 发布时间:2021/12/8 20:21:00 -- 用Compute啊 |
-- 作者:doumao -- 发布时间:2021/12/8 21:18:00 -- 谢谢兄弟 ,太难学了 折腾了一天,想找个师傅学习下。 If e.DataCol.Name = "组件功率" Then If e.NewValue Is Nothing Then e.DataRow("装机容量")=Nothing Else Dim dr As DataRow dr = DataTables("物料明细表").Find("[分类] = \'组件\'") If dr IsNot Nothing Dim sum As Double = Tables("物料明细表").Compute("Sum(数量)", "模板编号 = \'A01\' and 分类 = \'组件\' ") e.DataRow("装机容量")= sum * e.DataRow("组件功率") End If End If End If [此贴子已经被作者于2021/12/8 21:19:21编辑过]
|
-- 作者:liufucan -- 发布时间:2021/12/8 21:22:00 -- Dim dr As DataRow dr = DataTables("物料明细表").Find("[分类] = \'组件\'") Dim m As Double = dr("数量") If dr IsNot Nothing 这些不觉得多余吗
|
-- 作者:有点蓝 -- 发布时间:2021/12/9 8:39:00 -- If e.DataCol.Name = "组件功率" Then If e.NewValue Is Nothing Then e.DataRow("装机容量")=Nothing Else Dim sum As Double = Tables("物料明细表").Compute("Sum(数量)", "模板编号 = \'" & e.DataRow("模板编号") & "\' and 分类 = \'组件\' ") e.DataRow("装机容量")= sum * e.DataRow("组件功率") End If End If [此贴子已经被作者于2021/12/9 8:39:14编辑过]
|
-- 作者:doumao -- 发布时间:2021/12/9 23:52:00 -- 谢谢各位老大! 我子表还有个计算,不知道怎么写了 Select Case DataTables("物料明细表").DataCols("分类") Case "横一" 当分类为横一时,取主表的横一的数量 \'代码一 Dim ff As Double = Tables("物料明细表").Compute("斜梁数量_横一", 模板编号 = \' e.DataRow("模板编号")\' ) e.DataRow("数量")= ff Case "竖一 竖二" \' 当为竖一 竖二时取主表竖一 竖二之和 Dim ff1 As Double = Tables("物料明细表").Compute("斜梁数量_竖一", 模板编号 = \' e.DataRow("模板编号")\' ) Dim ff2 As Double = Tables("物料明细表").Compute("斜梁数量_竖二", 模板编号 = \' e.DataRow("模板编号")\' )
e.DataRow("数量")= ff1+ff2 End Select 请问这个为什么总是报错呢 [此贴子已经被作者于2021/12/9 23:53:20编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/12/10 8:49:00 -- 代码放到物料明细表的datacolchanged事件 Select Case e.DataCol.name Case "分类" If e.DataRow.isnull("分类") Then e.DataRow("数量") = Nothing Else Dim sum As Integer For Each ss As String In e.DataRow("分类").split(",") Dim s As String = "斜梁数量_" & e.newvalue If Tables("光伏物料清单").cols.contains(s) sum = sum + Tables("光伏物料清单").Compute("sum(" & s & ")", 模板编号 = \' e.DataRow("模板编号")\' ) End If Next e.DataRow("数量")= sum End If End Select |
-- 作者:doumao -- 发布时间:2021/12/10 13:40:00 -- [此贴子已经被作者于2021/12/10 13:40:03编辑过]
|