Dim st As Date = Date.Now
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim ct AS Integer
Dim ct1 AS Integer
Dim ct2 AS Integer
Dim ct3 AS Integer
Dim ct4 AS Integer
Dim ct5 AS Integer
Dim ct6 AS Integer
cmd.C
cmd.CommandText="select * from aec00000 where centercode='0100' and requiredate between '2011-02-27' and '2011-03-10'"
dt=cmd.ExecuteReader()
For Each dr As DataRow In dt.datarows
Dim d1 As Date=dr("requiredate")
Dim d2 As Date
Dim d3 As Date
Dim wk As Byte=d1.DayOfWeek
If wk=2 Then '如果总装日期是周二,那么
d2=dr("requiredate").AddDays(-3)
d3=dr("requiredate").AddDays(-5)
Else If wk=5 Then '如果总装日期是周五,那么
d2=dr("requiredate").AddDays(-2)
d3=dr("requiredate").AddDays(-4)
Else '如果总装日期是周一?周三?周四或周六?周日,那么
d2=dr("requiredate").AddDays(-2)
d3=dr("requiredate").AddDays(-5)
End If
'-总装线日期设定
cmd.CommandText="update aeg00000 set inputdate='"& d1 &"',outputdate='"& d1 &"' from aeg00000 where GTcode='"& dr("planid") &"' And childlevel=0 And deptcode='0148'"
ct1=cmd.ExecuteNonQuery()
'-装配一线日期设定
cmd.CommandText="update aeg00000 set inputdate='"& d1 &"',outputdate='"& d1 &"' from aeg00000 where GTcode='"& dr("planid") &"' And childlevel=1 And deptcode='0102'"
ct2=cmd.ExecuteNonQuery()
'-装配组件日期设定
cmd.CommandText="update aeg00000 set inputdate='"& d2 &"',outputdate='"& d2 &"' from aeg00000 where GTcode='"& dr("planid") &"' And workcentercode='010212'"
ct3=cmd.ExecuteNonQuery()
'-装配二线日期设定
cmd.CommandText="update aeg00000 set inputdate='"& d2 &"',outputdate='"& d2 &"' from aeg00000 where GTcode='"& dr("planid") &"' And childlevel=1 And deptcode='0143'"
ct4=cmd.ExecuteNonQuery()
'-成型一车间日期设定
cmd.CommandText="update aeg00000 set inputdate='"& d2 &"',outputdate='"& d2 &"' from aeg00000 where GTcode='"& dr("planid") &"' And deptcode='0112'"
ct5=cmd.ExecuteNonQuery()
'-成型二车间日期设定
cmd.CommandText="update aeg00000 set inputdate='"& d3 &"',outputdate='"& d2 &"' from aeg00000 where GTcode='"& dr("planid") &"' And deptcode='0113'"
ct6=cmd.ExecuteNonQuery()
Next
ct=ct1+ct2+ct3+ct4+ct5+ct6
Messagebox.Show( "本次操作总共影响" & ct & "行!耗时: " & (Date.Now - st).TotalSeconds & "秒")