一个合同可能多次续签,续签后在此合同的新合同编号列写上新合同的编号,两个表,分别合同明细、合同合并,合同合并表中截止日期是续签后最后一份合同的截止日期,以下的代码是逐层查找并计算,如果续签次数超过10次、甚至以上代码就会很长,有无改进办法?
If e.DataCol.name = "合同编号" Then
Dim dr As DataRow = DataTables("合同明细").find("合同编号 = '" & e.DataRow("合同编号") & "'")
If dr IsNot Nothing Then
If dr.Isnull("新合同编号") = True Then
e.DataRow("截止日期") = dr("截止日期")
e.DataRow("合同金额") = dr("合同金额")
e.DataRow("发货金额") = dr("发货金额")
Else
Dim dr1 As DataRow = DataTables("合同明细").find("合同编号 = '" & dr("合同编号") & "'")
If dr IsNot Nothing Then
If dr1.Isnull("新合同编号") = True Then
e.DataRow("截止日期") = dr1("截止日期")
e.DataRow("合同金额") = dr1("合同金额")
e.DataRow("发货金额") = dr1("发货金额")
Else
Dim dr2 As DataRow = DataTables("合同明细").find("合同编号 = '" & dr1("合同编号") & "'")
If dr2 IsNot Nothing Then
If dr2.Isnull("新合同编号") = True Then
e.DataRow("截止日期") = dr2("截止日期")
e.DataRow("合同金额") = dr2("合同金额")
e.DataRow("发货金额") = dr2("发货金额")
Else
Dim dr3 As DataRow = DataTables("合同明细").find("合同编号 = '" & dr2("合同编号") & "'")
If dr3 IsNot Nothing Then
If dr.Isnull("新合同编号") = True Then
e.DataRow("截止日期") = dr3("截止日期")
e.DataRow("合同金额") = dr3("合同金额")
e.DataRow("发货金额") = dr3("发货金额")
End If
End If
End If
End If
End If
End If
End If