Dim dr As DataRow = e.DataRow Select Case e.DataCol.Name Case "费用计算式","费率","金额","专业编号" If e.DataRow.IsNull("费用计算式") = False Then Dim str As String = e.DataRow("费用计算式") Dim pattern As String = "{.+?}" Dim rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) For Each match As System.Text.RegularExpressions.Match In rgx.Matches(str) Dim fdr = e.DataTable.Find("序号 = '" & match.Value.trim("{","}") & "'" & iif(dr.IsNull("专业编号"), ""," And 专业编号 = '" & dr("专业编号") & "'")) If fdr IsNot Nothing Then str = str.replace(match.Value, fdr("金额")) End If Next pattern = "\[\.+?\]" rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) For Each match As System.Text.RegularExpressions.Match In rgx.Matches(str) str = str.replace(match.Value, e.DataRow(match.Value.trim("[","]"))) Next If TryEval(str, e.DataRow) Then e.DataRow("金额") = Eval2(str,e.DataRow) Else msgbox("计算公式有错误,请核对!") End If End If Dim flt1 As String = "清单类别 = '分部分项' And 项目编码 <> ''" & iif(dr.IsNull("专业编号"), ""," And 专业编号 = '" & dr("专业编号") & "'") Dim flt2 As String = " 清单类别 = '技术措施' And 项目编码 <> ''" & iif(dr.IsNull("专业编号"), ""," And 专业编号 = '" & dr("专业编号") & "'") If dr("费用名称") = "工程量清单分部分项工程费" Then dr("金额") = DataTables("合同清单").Compute("Sum(合价)",flt1) ElseIf dr("费用名称") = "施工技术措施项目费" Then dr("金额") = DataTables("合同清单").Compute("Sum(合价)",flt2) ElseIf dr("费用名称") = "分部分项(人工费+机械费)" Then dr("金额") = DataTables("合同清单").Compute("Sum(其中_人工费)",flt1) + DataTables("合同清单").Compute("Sum(其中_机械费)",flt1) ElseIf dr("费用名称") = "技措项目(人工费+机械费)" Then dr("金额") = DataTables("合同清单").Compute("Sum(其中_人工费)",flt2) + DataTables("合同清单").Compute("Sum(其中_机械费)",flt2) End If End Select
|