jangogo @ 2010-3-17 15:33:00
SC读取数据库用的是ADO对象,效率和ADO有直接的关系。
但是我们应该注意的事情是在SC里面一定要尽量少用Do/Loop 或者 for next 来循环数据集在拼凑字符串返回结果。
这样的效率是非常低的,最好的方法是使用ADO.Recorset对象的GetString方法,一次性生成字符串返回,在前台的JS里面再使用Split分割成数组。
结合JS的对象和动态载入表格的方法可以极大地加快程序的处理速度。
如 固定资产台帐 功能,原来有位同事做的代码如下:
function readAccountInfo(startTime,endTime,dbtype)
on error resume next
dim cn,rsG,rs,rs1,rs2,ss
dim ccode,cname,cplace,cuser,depy,depm,balance,cunit,cdate
dim staffid,pid,acid,debitqty,debit,price,deped
'变动
dim qty,dep,yzh,nvalue
'折旧
dim dep1,cdep1
set cn=GetCN_()
set rsG = GetRS_()
cn.open CNStr_
ss=""
set rs2=GetRS_()
set rs=GetRS_()
set rs1=GetRS_()
'sql = "select ccode from fasub where fatype=2"
sql = "select ccode from fa where fa.ccode <> ' ' order by ccode"
rsG.open sql,cn,1,3
do while not rsG.eof
if err then exit do
'判断固定资产是否有子信息
sql = "select * from fa where ccode='" & rsG("ccode") & "'"
rs.open sql,cn,1,3
if not rs.eof then
cname = rs("cname")
cplace = rs("cplace")
cuser = rs("cuser")
depy = rs("depy")
depm = rs("depm")
balance = rs("balance")
cunit = rs("cunit")
cdate = rs("cdate")
acid = rs("acid")
staffid = ""
pid = ""
debitqty = 1
debit = 0
price = 0
deped = 0
end if
rs.close
'查询统计变动数据
sql = "select fasub.ccode,fasub.DeptStaffID,fasub.PrjID,fasub.acid_fee,SUM(fasub.debitQty-fasub.creditQty) as qty,AVG(fasub.price) as aprice,SUM(fasub.debit-fasub.credit) as sdebit from fasub,accperiod where (fatype=1 or fatype=0) and (fasub.fadate between accperiod.startdate and accperiod.enddate) and fasub.ccode='" & rsG("ccode") & "' and accperiod.period >= '" & startTime & "' and accperiod.period <= '" & endTime & "' group by fasub.ccode,fasub.DeptStaffID,fasub.PrjID,fasub.acid_fee"
rs.open sql,cn,1,3
'查询统计折旧数据
sql="select fasub.ccode,fasub.DeptStaffID,fasub.PrjID,SUM(fasub.creditDep) as sDep from fa,fasub,accperiod where fa.ccode=fasub.ccode and fasub.fatype=3 and (fasub.fadate between accperiod.startdate and accperiod.enddate) and fasub.ccode='" & rsG("ccode") & "' and accperiod.period >= '" & startTime & "' and accperiod.period <= '" & endTime & "' group by fasub.ccode,fasub.DeptStaffID,fasub.PrjID"
'msgbox sql
rs1.open sql,cn,1,3
'sql="select fa.ccode,fa.cname,fa.cplace,fa.cuser,fa.cdate,fa.depm,fa.depy,fa.balance,fa.cunit,fasub.debitQty,fasub.price,fasub.debit,fasub.deped,fasub.acid_fee,fasub.DeptStaffID,fasub.PrjID from fa,fasub where fa.ccode=fasub.ccode and fasub.ccode='" & rsG("ccode") & "' and fasub.fatype=2"
sql = "select fa.ccode,fa.cname,fa.cplace,fa.cuser,fa.cdate,fa.depm,fa.depy,fa.balance,fa.cunit,fasub.debitQty,fasub.price,fasub.debit,fasub.deped,fasub.acid_fee,deptstaff.DeptStaffName,prj.PrjName from fa,fasub,deptstaff,prj where fa.ccode=fasub.ccode and fasub.DeptStaffID=deptstaff.DeptStaffID and fasub.PrjID=prj.PrjID and fasub.ccode='" & rsG("ccode") & "' and fasub.fatype=2"
readAccountInfo=XML_("<PS>" & ss & "</PS>" & errXML_(err))
close_ rs
close_ rs1
close_ rs2
close_ cn
end function
'计算并获取累计折旧
function GetAddUpDep(dbtype,ccode,startperiod,endperiod)
on error resume next
dim cn,rs,sql,rtn
dim fadate,isGoon,speriod,eperiod
dim sp,ep 'period
set cn = GetCN_()
cn.open CNStr_
set rs = GetRS_()
isGoon = true
rtn = 0
dim c
c = "#"
if dbtype = "sqlserver" then
c = "'"
end if
sql = "select count(*) from fasub where fatype=3"
rs.open sql,cn,1,3
if rs.eof then
isGoon = false
end if
rs.close
if isGoon then
sql = "select top 1 * from fasub where fasub.ccode <> ' ' order by fadate asc"
rs.open sql,cn,1,3
if not rs.eof then
fadate = rs("fadate")
end if
rs.close
sql = "select period from accperiod where (" & c & fadate & c & " between startdate and enddate)"
rs.open sql,cn,1,3
if not rs.eof then
speriod = rs("period")
end if
rs.close
sql = "select top 1 * from fasub where fasub.ccode <> ' ' order by fadate desc"
rs.open sql,cn,1,3
if not rs.eof then
fadate = rs("fadate")
end if
rs.close
sql = "select period from accperiod where (" & c & fadate & c & " between startdate and enddate)"
rs.open sql,cn,1,3
if not rs.eof then
eperiod = rs("period")
end if
rs.close
sp = speriod
ep = endperiod
'msgbox eperiod
'查询统计累计折旧数据
sql="select fasub.ccode,fasub.DeptStaffID,fasub.PrjID,SUM(fasub.creditDep) as sDep from fa,fasub,accperiod where fa.ccode=fasub.ccode and fasub.fatype=3 and (fasub.fadate between accperiod.startdate and accperiod.enddate) and fasub.ccode='" & ccode & "' and accperiod.period >= '" & sp & "' and accperiod.period <= '" & ep & "' group by fasub.ccode,fasub.DeptStaffID,fasub.PrjID"