Sele ct Case e.DataCol.name
Case "审核"
If e.DataRow("结帐") = False Then
Dim dr As DataRow = e.DataRow
Dim cmd1 As New SQLCommand
cmd1.C
cmd1.CommandText = "Sele ct 洽商增加预算额,洽商增加结算额,洽商减少预算额,洽商减少结算额,合同编号 From {洽商汇总} Where 合同编号= '" & e.DataRow("合同编号") & "'" '注意要包括主键列
Dim dt1 As DataTable = cmd1.ExecuteReader() '注意可选参数设置为True
If dt1.DataRows.Count > 0 Then
dr("洽商增加预算额")=dt1.Compute("sum(洽商增加预算额)","合同编号= '" & dr("合同编号") & "'")
dr("洽商增加结算额")=dt1.Compute("sum(洽商增加结算额)","合同编号= '" & dr("合同编号") & "'")
dr("洽商减少预算额")=dt1.Compute("sum(洽商减少预算额)","合同编号= '" & dr("合同编号") & "'")
dr("洽商减少结算额")=dt1.Compute("sum(洽商减少结算额)","合同编号= '" & dr("合同编号") & "'")
Else
dr("洽商增加预算额")=0
dr("洽商增加结算额")=0
dr("洽商减少预算额")=0
dr("洽商减少结算额")=0
End If
Dim cmd2 As New SQLCommand
cmd2.C
cmd2.CommandText = "Sele ct 设计费预算,设计费结算,合同编号 From {设计汇总} Where 合同编号= '" & e.DataRow("合同编号") & "'" '注意要包括主键列
Dim dt2 As DataTable = cmd2.ExecuteReader() '注意可选参数设置为True
If dt2.DataRows.Count > 0 Then
dr("设计费预算")=dt2.Compute("sum(设计费预算)","合同编号='" & e.DataRow("合同编号") & "'")
dr("设计费结算")=dt2.Compute("sum(设计费结算)","合同编号='" & e.DataRow("合同编号") & "'")
Else
dr("设计费预算")=0
dr("设计费结算")=0
End If
Dim cmd3 As New SQLCommand
cmd3.C
cmd3.CommandText = "Sele ct 金额,用途,主类别,往来单位,合同编号 From {收支管理} Where 合同编号= '" & e.DataRow("合同编号") & "'" '注意要包括主键列
Dim dt3 As DataTable = cmd3.ExecuteReader() '注意可选参数设置为True
If dt3.DataRows.Count > 0 Then
dr("质保金实收") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '质保金'")
dr("甲方预付款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '甲方付款' And [主类别] = '预付款'")
dr("甲方进度款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '甲方付款' And [主类别] = '进度款'")
dr("甲方洽商款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '甲方付款' And [主类别] = '洽商款'")
dr("甲方结算款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '甲方付款' And [主类别] = '结算款'")
dr("财务费用") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '公司运营' And [主类别] = '财务费用'")
dr("管理费用") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '公司运营' And [主类别] = '管理费用'")
dr("销售费用") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '公司运营' And [主类别] = '销售费用'")
dr("资质挂靠费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '资质挂靠费'")
dr("总包管理费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '总包管理费'")
dr("交际费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '项目交际费'")
dr("税金") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '税金'")
dr("fa piao费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = 'fa piao费'")
dr("设计费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '设计费'")
dr("财务分摊") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '财务分摊'")
dr("现场经费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '现场经费'")
dr("借款利息") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '借款利息'")
dr("导支piao手续费") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '导支piao手续费'")
dr("实分红1") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '利润分红' and 往来单位 ='闫廷勇'")
dr("实分红2") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '项目运营' And [主类别] = '利润分红' and 往来单位 ='闫春'")
dr("分包预付款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '分包付款' And [主类别] = '预付款'")
dr("分包进度款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '分包付款' And [主类别] = '进度款'")
dr("分包洽商款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '分包付款' And [主类别] = '洽商款'")
dr("分包结算款") = dt3.compute("Sum(金额)","[合同编号]= '" & e.DataRow("合同编号") & "' and [用途] = '分包付款' And [主类别] = '结算款'")
Else
dr("质保金实收") = 0
dr("甲方预付款") = 0
dr("甲方进度款") = 0
dr("甲方洽商款") = 0
dr("甲方结算款") =0
dr("财务费用") =0
dr("管理费用") = 0
dr("销售费用") =0
dr("资质挂靠费") =0
dr("总包管理费") =0
dr("交际费") =0
dr("税金") = 0
dr("fa piao费") = 0
dr("设计费") = 0
dr("财务分摊") = 0
dr("现场经费") =0
dr("借款利息") = 0
dr("导支piao手续费") = 0
dr("实分红1") = 0
dr("实分红2") = 0
dr("分包预付款") = 0
dr("分包进度款") =0
dr("分包洽商款") = 0
dr("分包结算款") = 0
End If
Dim cmd4 As New SQLCommand
cmd4.C
cmd4.CommandText = "Sel ect 已付金额,欠款金额,合同编号 From {采购入库} Where 合同编号= '" & e.DataRow("合同编号") & "'" '注意要包括主键列
Dim dt4 As DataTable = cmd4.ExecuteReader() '注意可选参数设置为True
If dt4.DataRows.Count > 0 Then
dr("材料费") = dt4.Compute("Sum(已付金额)"," 合同编号 = '" & e.DataRow("合同编号") & "'")
dr("材料费欠款") = dt4.Compute("Sum(欠款金额)","合同编号 = '" & e.DataRow("合同编号") & "'")
Else
dr("材料费") = 0
dr("材料费欠款") = 0
End If
Dim cmd5 As New SQLCommand
cmd5.C
cmd5.CommandText = "Sel ect 本次付款,欠款金额,合同编号 From {工资发放} Where 合同编号= '" & e.DataRow("合同编号") & "'" '注意要包括主键列
Dim dt5 As DataTable = cmd5.ExecuteReader() '注意可选参数设置为True
If dt5.DataRows.Count > 0 Then
dr("人工费") = dt5.Compute("sum(本次付款)","[合同编号]='" & e.DataRow("合同编号") & "'")
dr("人工费欠款") = dt5.Compute("sum(欠款金额)","[合同编号]='" & e.DataRow("合同编号") & "'")
Else
dr("人工费") = 0
dr("人工费欠款") = 0
End If
Dim cmd6 As New SQLCommand
cmd6.C
cmd6.CommandText = "Se lect 本次付款,欠款金额,合同编号 From {机具订单} Where 合同编号= '" & e.DataRow("合同编号") & "'" '注意要包括主键列
Dim dt6 As DataTable = cmd6.ExecuteReader() '注意可选参数设置为True
If dt6.DataRows.Count > 0 Then
dr("机械费")=dt6.Compute("sum(本次付款)","合同编号 = '" & e.DataRow("合同编号") & "'")
dr("机具费欠款")=dt6.Compute("sum(欠款金额)","合同编号 = '" & e.DataRow("合同编号") & "'")
Else
dr("机械费")=0
dr("机具费欠款")=0
End If
dr.save
End If
End Se lect
审核列,重置时,有:20行,数据需要从后台统计,每一行,计算后面的数据,大概平均:500行;(未加载的数据)
运行时间:10秒。我是设置在,切换 到当前表,就重置:审核,列的。
请问,老师这样的代码,写法上有没有更优的方法?
还有,统计方式对吗?有没有更快的方法?