实战-资源构成列表
jangogo @ 2010-5-14 11:29:00
注意: 具体代码请参看内部测试源码-> apps-> Sheeta-> source->utf-8->cost->bomlist.asp\ bomlist.sc.asp 已经有详细的注释,所以这里只对一些相关的大致说明
bomlist.asp 代码说明:
1.Sheeta.onpazuready=init;( 框架加载完后调用初始化的函数)
2, 在init()函数里调用tplRev(xD,isSaveToDB)读取模板的函数
3,在tplRev(xD,isSaveToDB)函数调用makeReport()构建报表的函数
4.在makeReport()函数里调用 getData()获取数据的函数
5.在getData()里调用 buildDiv(tx)显示数据的函数
我们要了解几条一般性的原则 :
1: 减少和 SC/ 服务器的交互次数,能够一次返回数据的,尽量一次完成
2: sc里面的过程要尽量简单
3 : sc里面过快速完成数据的处理过程 ,减少用户等待的时间 ,否则就要分次完成
4: sc里面不要使用大循环,尽量使用 recordset记录集的 getstring方法
程序逻辑:
首先我们要加载资源构成列表的模板:模板有两个可能的存在,一个是在用户的本地数据库 tpl 表里面,这是用户自定义的模板,另一个是在我们的数据服务器上,这是我们提供的默认模板 ; 我们先从用户的数据库中查找是否有资源构成的模板 ,将其数据取出来返回给前台 ,如果数据库中没有模板,那么就要从我们的服务器上下载一个模板下来,同时将模板保存到用户的数据库中,以方便下次使用,就不需要从服务器上重新下载,然后根据模板里面的字段顺序查找数据, 将数据缓存在页面的一个数组里, 根据模板里的页面信息,显示第一页的数据,当用户在滚动滚动条的时候在显示后面的数据.
第一步:获取模板 :
在页面初始化方法init()里查找模板
var xDoc=Sheeta.readXML(Pazu.fly( 'getInitValue()' ));
查找数据的sc代码:
function getInitValue()
on error resume next
dim s
s= "<T><![CDATA[" & GetOneVL_( "select top 1 tpl from tpl where [module]='cost' and uid='' and ttype='other' and tname='bomlist' order by version desc" , False ) & "]]></T>"
getInitValue=XML_(s & ErrXML_(err))
end function
sql语句中"module"
模板的模块, "ttype" 是模板的类型, 目前ttype类型有报表(report),单据(bill),发票(invoice),凭证(voucher),
账薄 (ledger),其它(other),"tname" 是模板的名字.
查找出来的数据是下面这样的:
<? xml version = "1.0" encoding = "utf-8" ?> < root xmlns:o = "urn:schemas-microsoft-com:office:office" xmlns:x = "urn:schemas-microsoft-com:office:excel" > < TABLE class = "tblGenFixed " style = "FONT-SIZE: 10pt; WIDTH: 696px" xmlns = "http://www.w3.org/TR/REC-html40" prop = "{module:'cost',ttype:'other',tname:'bomlist',version:'1',title:'资源构成列表',uid:'',rptmenu:'0,0,0,0,'}" pagesetup = "{paper:'A4',orientation:1,marginTop:'mm',marginLeft:'mm',header:'1:2',footer:'4',gridline:'1',nopreview:'0',noprintersel:'0',printer:'',datarows:'20'};" >
< TBODY >
< TR class = "firstrow " style = "HEIGHT: 1px" >
< TD style = "WIDTH: 1px" > </ TD >
< TD style = "WIDTH: 58px" > </ TD >
< TD style = "WIDTH: 110px" > </ TD >
< TD style = "WIDTH: 54px" > </ TD >
< TD style = "WIDTH: 39px" > </ TD >
< TD style = "WIDTH: 72px" > </ TD >
< TD style = "WIDTH: 110px" > </ TD >
< TD style = "WIDTH: 52px" > </ TD >
< TD style = "WIDTH: 80px" > </ TD >
< TD style = "WIDTH: 60px" > </ TD >
< TD style = "WIDTH: 60px" > </ TD > </ TR >
< TR style = "DISPLAY: block; HEIGHT: 38px" >
< TD > </ TD >
< TD class = "fb s2 a2 " style = "FONT-SIZE: 12pt" colSpan = "10" > 资源构成列表 </ TD > </ TR >
< TR style = "HEIGHT: 20px" >
< TD class = "s1 " > </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 货品代码 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 货品名称 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 货品数量 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 类型 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 成本代码 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 成本名称 </ TD >
< TD class = "s3 " style = "BACKGROUND-COLOR: #f1e3a7" > 科目代码 </ TD >
< TD class = "s3 " style = "BACKGROUND-COLOR: #f1e3a7" > 科目名称 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 数量 </ TD >
< TD class = "s3 a2 " style = "BACKGROUND-COLOR: #f1e3a7" > 金额 </ TD > </ TR >
< TR style = "HEIGHT: 20px" >
< TD class = "s1 " > </ TD >
< TD class = "s3 " > ?货品代码 </ TD >
< TD class = "s3 " > ?货品名称 </ TD >
< TD class = "s3 a1 " > ?货品数量 </ TD >
< TD class = "s3 " > ?类型 </ TD >
< TD class = "s3 " > ?成本代码 </ TD >
< TD class = "s3 " > ?成本名称 </ TD >
< TD class = "s3 " > ?科目代码 </ TD >
< TD class = "s3 " > ?科目名称 </ TD >
< TD class = "s3 a1 " > ?数量 </ TD >
< TD class = "s3 a1 " > ?金额 </ TD > </ TR > </ TBODY > </ TABLE > </ root >
如果模板是从数据库查找出来的就是保存在tpl表里的tpl这一列中是一个完整的xml字符串,在我们的服务器的默认模板则是以xml文件保存的,其中TABLE节点我们添加了一些属性prop 保存了模板的一些信息臂如,模块,名字,版本,标题等, pagesetup 属性则保存了一些页面信息,如页面大小,页头,页脚,每页显示多少行等。这些信息是在内部测试系统中 ->会计->报表->报表设计器所设置和保存的
如果用户的数据库没有查找到模板,那么就用ajax从我们的服务器上下载一个模板下来,服务器的模板保存在apps->Sheeta->template->cn->cost文件夹中
第二步:获取数据:
页面读取数据的方法
function getData(){
var xDoc=Sheeta.readXML(Pazu.fly( 'readBomList("' +flds+ '","' +fldx+ '")' ));
}
sc后台代码:
function readBomList(fs,fx)
s= "<S>" & CD(rs.GetString(2,-1,vbtab,chr(10), "" )) & "</S>"
readBomList=XML_(s & s1 & errXML_(err))
end function
其中ado记录集
GetString() 方法的说明:
rs.GetString(format,rows,coldel,rowdel,nullexpr) Format: 数字格式,一般为 2 或者为空, coldel - 用作列分隔符的 rowdel - 用作行分隔符, nullexpr - 当列为空时所使用的,当有很多条记录时,一般使用ADO原生的GetString()方法,因为其效率相对来说要高很多. 如果我们alert()方法返回的数据将是这样的: