|
|

楼主 |
发表于 2009/5/4 08:53:05
|
显示全部楼层
部分关键代码如下:
’下面做展开计算,从顶层到最底层
DoNextLevel:
MySqLcalling = “select * from ERPTemp where 状态<>1 order by 产品编号”
If Myrs.State = 1 Then Myrs.Close
Set Myrs = Nothing
Myrs.Open MySqLcalling, MyDE, adOpenStatic, adLockBatchOptimistic
If Not Myrs.BOF Then
Myrs.MoveFirst
产品编号 = -1
Do Until Myrs.EOF
If Myrs(“状态”) = 2 Then
Myrs(“状态”) = 0
GoTo ReachNewRecord
End If
If 产品编号<>Myrs(“产品编号”) Then
产品编号 = Myrs(“产品编号”)
MysqlERP =“select 产品编号,材料编号,材料用量,材料提前准备日数 from产品材料构成表where 产品编号=”& Myrs(“产品编号”)
If MyDE.State= 0 Then MyDE
.Open
If MyRsERP.State = 1 Then MyRsERP.Close
MyRsERP.Open MysqlERP,
MyDE, adOpenForwardOnly, adLockReadOnly
End If
If Not MyRsERP.BOF Then
MyRsERP.MoveFirst
Do Until MyRsERP.EOF
TheNeededMonth = DateDiff(“m”, Now, DateAdd(“d”, -MyRsERP(“材料提前准备日数”), Now()))
If TheNeededMonth< 1 Then TheNeededMonth = 0
If TheNeededMonth>12 Then TheNeededMonth = 12
If ERPbyWeek Then
’by week
TheNeededMonth = DateDiff(“WW”, Now, DateAdd(“d”, -MyRsERP(“材料提前准备日数”), Now()))
If TheNeededMonth< 1 Then TheNeededMonth = 0
If TheNeededMonth > 52 Then TheNeededMonth = 52
End If
Myrsbookmark = Myrs.Bookmark
Myrs数量 = Myrs(“数量”)
Myrs.AddNew
Myrs(“分组序号”) = 4
Myrs(“分组”) = “需求量”
Myrs(“状态”) =“2”
Myrs(“产品编号”)=
MyRsERP(“材料编号”)
Myrs(“数量”) = MyRsERP(“材料用量”) * Myrs数量
Myrs(“日期”) = DateAdd(“d”, -MyRsERP(“材料提前准备日数”), Now())
Myrs(“月份”) =
TheNeededMonth
Myrs.Bookmark = Myrsbookmark
MyRsERP.MoveNext
Loop
Else
Myrs(“状态”) = 1
End If
Myrs(“状态”) = 1
ReachNewRecord:
Myrs.MoveNext
Loop
MyRsERP.Close
Myrs.UpdateBatch
Myrs.Close
ERPlevel = ERPlevel + 1
DoEvents
If ERPStop Then GoTo ErrorHandle
If CalcLevel = -1 Then
GoTo DoNextLevel
Else
If ERPlevel< CalcLevel Then GoTo DoNextLevel
End If
Else
’OK, 结束
End If |
|