private sub getbomlist() dim mbomtop as collection '这里保存了顶级产成品 dim i as integer dim j as integer dim m as cbomreturnvalue dim mlast as cbomvalue dim bfind as boolean
set mbomtop = new collection
'装入顶级产成品
loadbomtop mbomtop
'对顶级产品进行下级的判断
for i = 1 to mbomtop.count '最后一个参数为1,表示一个单位的产成品 call calcnextbom(mbomtop.item(i), mbomtop.item(i), "1") next i
for i = 1 to mbomreturn.count '处理一下最终结果,如果没有在collection里面发现相同的assbom及bompoint,则新增加一个,如果已发现,仅只是数量相加 set m = mbomreturn(i)
'查找是否已加入 bfind = false for j = 1 to mbomreturnlast.count set mlast = mbomreturnlast(j)
if trim(mlast.assbom) = trim(m.assbom) and trim(mlast.bompoint) = trim(m.bompoint) then '如果发现有相同的,则加入相关数字 mlast.quantity = mlast.quantity + calcexpression(m.expression) bfind = true end if
next j
if bfind = false then '如果没有找到 set mlast = new cbomvalue mlast.assbom = trim(m.assbom) mlast.bompoint = trim(m.bompoint) mlast.quantity = calcexpression(trim(m.expression))
mbomreturnlast.add mlast
end if next i
'所有操作完毕 end sub
private sub loadbomtop(byref bomtop as collection) '装入顶级产成品,并返回到bomtop中 '即存储过程中getbomlist中的第一个游标的创建@bomtop
dim i as integer dim j as integer dim n as integer
dim bmark as boolean '这只是一个标识符,表明是否发现非顶级 dim bmarkadd as boolean '用于判断是否已加入到bomtop中的标识
'判断方法,如果assbom不在bompoint中,那就是顶级了 dim sbomassbom as string
for i = 1 to mbom.count sbomassbom = trim(mbom.item(i).assbom)
'再进行循环 bmark = false
for j = 1 to mbom.count if sbomassbom = trim(mbom.item(j).bompoint) then bmark = true end if next j
if bmark = false then '如果没有发现有相同的,则bomtop加入
'加入前需要进行判断是否已加入
for n = 1 to bomtop.count if bomtop.item(n) = sbomassbom then bmarkadd = true end if next n
if bmarkadd = false then '如果没有加入过,则加入 bomtop.add sbomassbom end if end if next i
end sub
'getbomtruelist的存储过程用vb来描述 private sub calcnextbom(sassbom as string, sasspoint as string, sexp as string) dim dquan as double dim sexpression as string dim spoint as string
dim i as integer dim mbomreturnvalue as cbomreturnvalue
for i = 1 to mbompoint.count '判断是否为明细级 if isdetailpoint(trim(mbompoint.item(i).bompoint)) = true then '如果是明细级,则加入到cbomreturnvalue set mbomreturnvalue = new cbomreturnvalue mbomreturnvalue.assbom = trim(sassbom) mbomreturnvalue.bompoint = trim(mbompoint.item(i).bompoint) '构建表达式 mbomreturnvalue.expression = sexp & "*" & trim(cstr(mbompoint.item(i).quantity))
'如果不是明细项,则再次递归,注意传入的第一个参数,总是顶级bom,仅作标识符用 call calcnextbom(sassbom, trim(mbompoint.item(i).bompoint), sexp & "*" & trim(cstr(mbompoint.item(i).quantity))) end if
next i
end sub
private sub loadnextpoint(byref bompoint as collection, byval pointname as string) '相当于getbomtruelist中的游标中的select distinct point,sl from te where assbom = @pointname
dim i as integer dim j as integer
dim bmark as boolean dim mpointvalue as cpointvalue
for i = 1 to mbom.count bmark = false if trim(mbom.item(i).assbom) = trim(pointname) then '判断是否已加入 for j = 1 to bompoint.count if trim(bompoint.item(j).bompoint) = trim(mbom.item(i).bompoint) and bompoint.item(j).quantity = mbom.item(i).quantity then bmark = true end if next j if bmark = false then '表示没有加入 set mpointvalue = new cpointvalue mpointvalue.bompoint = trim(mbom.item(i).bompoint) mpointvalue.quantity = mbom.item(i).quantity bompoint.add mpointvalue end if
end if next i
end sub
private function isdetailpoint(byval pointname as string) as boolean '判断是否为底级半成品
'只需要判断pointname不在mbom的assbom项中即可
dim i as integer
for i = 1 to mbom.count if trim(mbom.item(i).assbom) = trim(pointname) then '如果找到了,直接返回false,并退出函数 isdetailpoint = false exit function end if next i
'如果到了这里还没有找到,那么就肯定是底级了 isdetailpoint = true end function
public function calcexpression(strexp as string) as double '计算处理中的表达式,注意,只有乘法
dim sitemexp() as string
dim dreturnvalue as double dim iindex as integer
sitemexp = split(trim(strexp), "*")
if ubound(sitemexp) < 0 then calcexpression = 0 else
dreturnvalue = 1 for iindex = 0 to ubound(sitemexp) if trim(sitemexp(iindex)) = "" then sitemexp(iindex) = 0 end if
dreturnvalue = dreturnvalue * cdbl(sitemexp(iindex)) next iindex
calcexpression = dreturnvalue
end if
end function
类模块一:类名:cbomreturnvalue
option explicit
'保持属性值的局部变量 private mvarassbom as string '局部复制 private mvarbompoint as string '局部复制 private mvarquantity as double '局部复制 private mvarexpression as string '局部复制 public property let expression(byval vdata as string) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.expression = 5 mvarexpression = vdata end property
public property get expression() as string '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.expression expression = mvarexpression end property
public property let quantity(byval vdata as double) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.quantity = 5 mvarquantity = vdata end property
public property get quantity() as double '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.quantity quantity = mvarquantity end property
public property let bompoint(byval vdata as string) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.bompoint = 5 mvarbompoint = vdata end property
public property get bompoint() as string '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.bompoint bompoint = mvarbompoint end property
public property let assbom(byval vdata as string) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.assbom = 5 mvarassbom = vdata end property
public property get assbom() as string '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.assbom assbom = mvarassbom end property
类模块二:类名:cbomvalue
option explicit
'保持属性值的局部变量 private mvarassbom as string '局部复制 private mvarbompoint as string '局部复制 private mvarquantity as double '局部复制 public property let quantity(byval vdata as double) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.quantity = 5 mvarquantity = vdata end property
public property get quantity() as double '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.quantity quantity = mvarquantity end property
public property let bompoint(byval vdata as string) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.bompoint = 5 mvarbompoint = vdata end property
public property get bompoint() as string '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.bompoint bompoint = mvarbompoint end property
public property let assbom(byval vdata as string) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.assbom = 5 mvarassbom = vdata end property
public property get assbom() as string '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.assbom assbom = mvarassbom end property
类模块三:类名:cpointvalue
option explicit
'保持属性值的局部变量 private mvarbompoint as string '局部复制 private mvarquantity as double '局部复制 public property let quantity(byval vdata as double) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.quantity = 5 mvarquantity = vdata end property
public property get quantity() as double '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.quantity quantity = mvarquantity end property
public property let bompoint(byval vdata as string) '向属性指派值时使用,位于赋值语句的左边。 'syntax: x.bompoint = 5 mvarbompoint = vdata end property
public property get bompoint() as string '检索属性值时使用,位于赋值语句的右边。 'syntax: debug.print x.bompoint bompoint = mvarbompoint end property