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