哪位高手帮忙优化下代码。Tables("窗口1_Table3")是查询表。(二个表查询的)
Tables("窗口1_Table3").Fill("Select {车辆费用}.[_Identify],业务编号,客户,{车辆费用}.作业日期,关单号,{车辆费用}.箱型箱量,[流向_提箱点],[流向_门点],[流向_还箱点],支出项目,金额,收款人,{车辆费用}.审核号,{车辆费用}.审核日期,审核 From {业务大表} Inner JOIN {车辆费用} ON {车辆费用}.[业务编号] = {业务大表}.[编号] WHERE {车辆费用}.[_Identify] Is Null","ZHANG",True)
总感觉这么做属于非主流。
If e.form.controls("收款人").value = "" Then
messagebox.show("请输入或选择收款人.")
Return
End If
If Tables("窗口1_Table3").Current Is Nothing Then
MessageBox.Show("无数据!")
Return
End If
Dim sum As Double = Tables("窗口1_Table3").Compute("Sum(金额)")
Dim Result As DialogResult
Result = MessageBox.Show("确认审核.金额为" & sum, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim drs As List(Of DataRow) = DataTables("窗口1_Table3").Select("")
For Each dr As DataRow In drs
Dim zn As String = dr("审核")
If zn =True Then
MessageBox.Show("包含已审核,审核失败.")
Return
Exit For
End If
Next
Tables("已审核费用").Filter = ""
Tables("已审核费用").Sort = ""
With Tables("已审核费用")
.Position = .Rows.Count - 1
End With
Dim d As Date = Date.Today
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1)
Dim ld As Date = New Date(y,m,Days)
Dim bh As String = "CL" & Format(d,"yyMM")
Dim idx As Integer
Dim max As String
Dim dr8 As DataRow = DataTables("编号").DataRows(0)
max = dr8("车辆审核号")
If max > "" Then
If max.StartsWith(bh) Then
idx = CInt(max.Substring(6,3)) + 1
Else
idx = 1
End If
Else
idx = 1
End If
dr8("车辆审核号")=bh & Format(idx,"000")
dr8.save()
Dim r As Row = Tables("已审核费用").AddNew
r("审核号") = dr8("车辆审核号")
r("类别")= "支出"
r("审核金额")= sum
r("摘要")= "出车费运费及代付费用"
r("科目")= "业务支出"
r("收付款人")= e.form.controls("收款人").value
r.Save()
Dim ids As String
For Each dr1 As DataRow In DataTables("窗口1_Table3").DataRows
ids = ids & "," & dr1("_Identify")
dr1("审核") = True
dr1("审核号")= r("审核号")
dr1("审核日期") = Date.Today
Next
ids= ids.Trim(",")
Dim dt1 As DataTable
Dim cmd1 As New SQLCommand
cmd1.C
cmd1.CommandText = "Select [_Identify],审核,审核号,审核日期 From {车辆费用} Where [_Identify] In (" & ids & ")"
dt1 = cmd1.ExecuteReader(True)
For Each d2 As DataRow In dt1.DataRows
d2("审核") = True
d2("审核号")= r("审核号")
d2("审核日期") = Date.Today
Next
dt1.Save()
End If