以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]删除行时报错,求大神帮助 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=177622) |
-- 作者:moseser -- 发布时间:2022/5/28 17:35:00 -- [求助]删除行时报错,求大神帮助 .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2022.5.27.2 错误所在事件:表,预计总成本, DataColChanged 详细错误信息: 调用的目标发生了异常。 从字符串“收入”到类型“Double”的转换无效。 输入字符串的格式不正确。 删除table 表的行时,报错 错误所在事件:表,预计总成本, DataColChanged 代码如下: If e.DataCol.name = "计算口径" Or e.DataCol.name = "口径工程量" Dim idx As Integer = Tables("预计总成本").FindRow(e.DataRow) Dim r As Row = Tables("预计总成本").Rows(idx) Dim k_r As DataRow = DataTables("计算口径").find("[计算口径] = \'"& e.NewValue &"\' ") If k_r IsNot Nothing Then r("口径工程量") = K_r("工程量") End If Dim c_r As DataRow = DataTables("预计总成本").Find("标记 = \'三级\'") DataTables("预计总成本").DataCols("合计_收入").RaiseDataColChanged(c_r) End If If e.DataRow.IsNull("序列号") = False Then Select e.DataCol.name Case "归类" Dim contents As List (of String) = DataTables("预计总成本").GetValues("目录编码") Dim i As Integer = Tables("预计总成本").FindRow(e.DataRow) Dim r As Row = Tables("预计总成本").rows(i) \'获取数据变动行 r("目录编码") = e.NewValue & "." & cstr(r("序列号")) r("标记") = "三级" Dim mm As List (Of DataRow) = DataTables("预计总成本").Select("[归类] = \'" & e.NewValue & "\'") r("顺序号") = mm.Count \'解析目录编码 Dim dot1 As Integer = e.NewValue.Indexof(".") Dim f_code As String = left(e.newvalue , Dot1) Dim f_r As DataRow = DataTables("一二级目录").find("序号 = \'" & e.NewValue & "\'") Dim f_name As String = f_r("一级目录") Dim s_name As String = f_r("二级目录") r("所属一级") = f_code If contents.Contains(f_code) = False Then \'没有一级目录,增加一级目录 Tables("预计总成本").AddNew() Dim p As Integer = Tables("预计总成本").Position Dim new_r As Row = Tables("预计总成本").Rows(p) new_r("目录编码") = f_code new_r("目录") = f_name new_r("标记") = "一级" new_r("顺序号") = CInt(f_code) End If If contents.Contains(e.NewValue) = False Then \'没有二级目录,增加二级目录 Tables("预计总成本").AddNew() Dim p As Integer = Tables("预计总成本").Position Dim new_r As Row = Tables("预计总成本").Rows(p) new_r("目录编码") = e.NewValue new_r("目录") = s_name new_r("标记") = "二级" new_r("顺序号") = CInt( CDbl(e.NewValue) * 100) End If \'生成折叠模式 Dim st As New LayerTreeSetting st.PathCol = "目录编码" st.Separator = "." st.TreeCol = "目录" st.SortCol = "顺序号" st.UseStyle = True st.ExpandTo = -1 Tables("预计总成本").ShowGridTree(st) Case "合计_收入" , "合计_成本" ,"工程量_数量" ,"口径工程量" ,"工程量_计" \'先设置三级目录行的计算公式 Dim i As Integer = Tables("预计总成本").FindRow(e.DataRow) Dim r As Row = Tables("预计总成本").rows(i) r("合计_盈亏") = r("合计_收入") - r("合计_成本") If r("工程量_数量") <> 0 AndAlso r.IsNull("工程量_数量") = False Then r("单价_收入") = r("合计_收入") / r("工程量_数量") r("单价_成本") = r("合计_成本") / r("工程量_数量") r("单价_盈亏") = r("合计_盈亏") / r("工程量_数量") Else r("单价_收入") = Nothing r("单价_成本") = Nothing r("单价_盈亏") = Nothing End If If r("口径工程量") <> 0 AndAlso r.IsNull("口径工程量") = False Then r("平米_收入") = r("合计_收入") / r("口径工程量") r("平米_成本") = r("合计_成本") / r("口径工程量") r("平米_盈亏") = r("合计_盈亏") / r("口径工程量") r("工程量_含量") = r("工程量_数量") / r("口径工程量") Else r("平米_收入") = Nothing r("平米_成本") = Nothing r("平米_盈亏") = Nothing r("工程量_含量") = Nothing End If \'Case "工程量_计" \'MessageBox.Show("你好") \'Dim i As Integer = Tables("预计总成本").FindRow(e.DataRow) \'Dim r As Row = Tables("预计总成本").rows(i) \' \'Dim q_str As String = r("归类") \'Dim up_r As DataRow = DataTables("预计总成本").Find("目录编码 = \'"& q_str &"\'" ) \' \'Dim Total_q As Double = DataTables("预计总成本").Compute("sum(工程量_数量)" ,"归类 = \'"& q_str &"\'" ) \'up_r("工程量_数量") = total_q \'MessageBox.Show(total_q) Case "计算口径" Dim i As Integer = Tables("预计总成本").FindRow(e.DataRow) Dim r As Row = Tables("预计总成本").rows(i) Dim f_r As DataRow = DataTables("计算口径").Find("计算口径 = \'"& e.NewValue &"\'") If f_r IsNot Nothing Then r("口径工程量") = f_r("工程量") End If End Select \'遍历二级目录 Dim drs As List (of DataRow) = DataTables("预计总成本").Select("标记 = \'二级\'") For Each dr As DataRow In drs \' MessageBox.Show("你好3") Dim code As String = dr("目录编码") dr("合计_收入") = DataTables("预计总成本").Compute("sum(合计_收入)" ,"归类 = \'"& code &"\'") dr("合计_成本") = DataTables("预计总成本").Compute("sum(合计_成本)" ,"归类 = \'"& code &"\'") dr("合计_盈亏") = dr("合计_收入") - dr("合计_成本") \'MessageBox.Show("你好4") Dim m As Double = DataTables("预计总成本").Compute("sum(工程量_数量)" ,"归类 = \'"& code &"\' and 工程量_计 = true ") dr("工程量_数量") = m \'MessageBox.Show("你好5") \'MessageBox.Show(m) If dr("工程量_数量") <> 0 AndAlso dr.IsNull("工程量_数量") = False Then dr("单价_收入") = dr("合计_收入") / dr("工程量_数量") dr("单价_成本") = dr("合计_成本") / dr("工程量_数量") dr("单价_盈亏") = dr("合计_盈亏") / dr("工程量_数量") Else dr("单价_收入") = Nothing dr("单价_成本") = Nothing dr("单价_盈亏") = Nothing End If If dr("口径工程量") <> 0 AndAlso dr.IsNull("口径工程量") =False dr("平米_收入") = dr("合计_收入") / dr("口径工程量") dr("平米_成本") = dr("合计_成本") / dr("口径工程量") dr("平米_盈亏") = dr("合计_盈亏") / dr("口径工程量") dr("工程量_含量") = dr("工程量_数量") / dr("口径工程量") Else dr("平米_收入") = Nothing dr("平米_成本") = Nothing dr("平米_盈亏") = Nothing dr("工程量_含量") = Nothing End If Next \'遍历一级目录 Dim dr1s As List (of DataRow) = DataTables("预计总成本").Select("标记 = \'一级\'") For Each dr1 As DataRow In dr1s Dim code1 As String = dr1("目录编码") dr1("合计_收入") = DataTables("预计总成本").Compute("sum(合计_收入)" ,"所属一级 = \'"& code1 &"\'") dr1("合计_成本") = DataTables("预计总成本").Compute("sum(合计_成本)" ,"所属一级 = \'"& code1 &"\'") dr1("合计_盈亏") = dr1("合计_收入") - dr1("合计_成本") If dr1("口径工程量") <> 0 AndAlso dr1.IsNull("口径工程量") = False Then dr1("平米_收入") = dr1("合计_收入") / dr1("口径工程量") dr1("平米_成本") = dr1("合计_成本") / dr1("口径工程量") dr1("平米_盈亏") = dr1("合计_盈亏") / dr1("口径工程量") End If Next End If |
-- 作者:有点蓝 -- 发布时间:2022/5/29 19:56:00 -- 调试看哪一句代码出错:http://www.foxtable.com/webhelp/topics/1485.htm 最后一段【\'遍历二级目录\'遍历一级目录】不适合放到表事件处理,这种代码放到窗口按钮还可以。 每个事件都有适用的场合,不是所有功能都能堆积到一个事件使用的。不然何必分那么多事件
|