⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlds_1.txt

📁 Delphi 应用举例
💻 TXT
字号:
"var xmldb_vers='1.0';"
"var xml_ready=false;"
"var szRowState='RowState',szUni='string.uni',szNested='nested',szTrue='true',szFalse='false',szDel='2',szNew='4',szOrg='1',szMod='8',szDetUpd='64';"
"var szErr_HasDets='Cannot delete master record with details.';"
"var szErr_Invalid='Invalid action';"
"var DecPoint='.';var s= (25/10).toString();var p=s.indexOf('.');DecPoint=p>0?'.':',';"
"new xmlRowSet(null,null,null);"
"xmlRowSet.prototype.parent=null;"
"xmlRowSet.prototype.linkFld=null;"
"xmlRowSet.prototype.pDets=null;"
"xmlRowSet.prototype.noDel=0;xmlRowSet.prototype.noIns=0;xmlRowSet.prototype.noUpd=0;"
"xmlRowSet.prototype.InitRowSet=InitRowSet;"
"xmlRowSet.prototype.notify=function(reason){if(this.regobjs==null)return;var j;for(j=0;j<this.regobjs.length;j++)this.regobjs[j].refr(reason);}"
"xmlRowSet.prototype.forcepost=DsForcePost;"
"xmlRowSet.prototype.regobj=function(obj){if(this.regobjs==null)this.regobjs=new Array();this.regobjs[this.regobjs.length]=obj;}"
"xmlRowSet.prototype.DeltaChanges=null;"
"xmlRowSet.prototype.resetDets=resetDets;"
"xmlRowSet.prototype.del=delRow;"
"xmlRowSet.prototype.ins=insRow;"
"xmlRowSet.prototype.upd=updRow;"
"xmlRowSet.prototype.first=function(){return this.setPos(0);}"
"xmlRowSet.prototype.next=function(){return this.setPos(this.pos+1);}"
"xmlRowSet.prototype.prev=function(){return this.setPos(this.pos-1);}"
"xmlRowSet.prototype.last=function(){return this.setPos(this.RowCnt-1);}"
"xmlRowSet.prototype.setPos=function(pos){if(pos>=this.RowCnt||pos<0||this.RowCnt==0){this.resetDets();return 1;}if(this.pos!=pos){this.pos=pos;this.resetDets();} this.notify(0);return 0;}"
"xmlRowSet.prototype.getRow=function(pos){return this.idx.row(pos);}"
"xmlRowSet.prototype.makeRow=makeRow;"
"xmlRowSet.prototype.RowState=RowState;"
"xmlRowSet.prototype.insert=dsInsert;"
"xmlRowSet.prototype.modify=dsModify;"
"xmlRowSet.prototype.deletex=dsDelete;"
"xmlRowSet.prototype.undo=dsUndo;"
"xmlRowSet.prototype.sort=function(n){this.idx.sort(n);this.first();this.notify(1);}"
"xmlRowSet.prototype.getDelta=function(){return this.DeltaChanges.make();}"
"xmlRowSet.prototype.Apply=null;"
"xmlRowSet.prototype.MakePermanent=function(){this.DeltaChanges.reset();this.notify(1);this.resetDets();}"
"xmlRowSet.prototype.BeforePost=function(a,r){return r;}"
"xmlRowSet.prototype.AfterPost=function(a,r){return r;}"
"xmlRowSet.prototype.OnError=function(s){alert(s);return 1;}"
"xmlRowSet.prototype.OnNewRow=function(){return null;}"
"xmlRowSet.prototype.BeforeApply=function(){return 1;}"
"function xmlRowSet(doc, parent, linkFld) "
"{this.doc=doc;"
"if(doc==null){if(parent!=null)this.doc=parent.doc; else return null;}"
"if(this.doc==''){if(parent==null)alert('Invalid XML-packet.'); return null;}"
"this.root=null;"
"if(parent!=null){this.parent=parent;this.linkFld=linkFld;this.InitRowSet=InitDetailRowSet;}"
"this.MetaData=null;this.RowData=null;this.FieldCnt=0;this.FieldData=null;"
"this.pos=0;this.RowCnt=0;"
"this.Fields=new Fields();"
"this.InitRowSet();"
"this.pos=-1;"
"this.first();"
"return this;}"
"function InitRowSet()"
"{if(this.doc==null||this.doc=='')return;"
"var i;"
"this.root=this.doc.documentElement;"
"if(this.root==null)return;"
"if(this.root.tagName=='DATAPACKET'){"
" this.MetaData=this.root.childNodes.item(0); "
" this.RowData=this.root.childNodes.item(1);"
" this.RowCnt=this.RowData.childNodes.length;"
" this.FieldData=this.MetaData.childNodes.item(0);"
" this.FieldCnt=this.FieldData.childNodes.length;"
" var des;"
" for(i=0;i<this.FieldCnt;i++){des=new FldDes(this,this.FieldData.childNodes.item(i));if(des)this.Fields.Add(des);} "
"}"
"else{this.RowData=this.root;this.RowCnt=this.RowData.childNodes.length;}"
""
"var params=this.MetaData.childNodes.item(1);"
""
"if(params.getAttribute('READONLY')!=null){this.noDel=1;this.noIns=1;this.noUpd=1;}"
"for(i=0;i<params.childNodes.length;i++)"
"{var p=params.childNodes.item(i);var n=p.getAttribute('Name');var v=p.getAttribute('Value');"
" if(n!=null&&v!=null)if(n=='DISABLE_DELETES')this.noDel=1;else if(n=='DISABLE_INSERTS')this.noIns=1;else if(n=='DISABLE_EDITS')this.noUpd=1;"
"}"
"this.DeltaChanges=new DeltaChanges(this);"
"this.Apply=dsApply;"
"this.idx=new idx(this);"
"}"
"function InitDetailRowSet()"
"{ var i;"
"var parent=this.parent;"
"var fd=parent.FieldData.childNodes;"
"var l=fd.length; "
"this.FieldData=parent.Fields.Field[this.linkFld].node.childNodes.item(0);"
"if(this.FieldData==null)return;"
"this.FieldCnt=this.FieldData.childNodes.length ;  "
"var des;"
"for(i=0;i<this.FieldCnt;i++){des=new FldDes(this,this.FieldData.childNodes.item(i));if(des)this.Fields.Add(des);}"
"if(parent.pDets==null)parent.pDets=new Array();"
"parent.pDets[parent.pDets.length]=this;"
"this.DeltaChanges=parent.DeltaChanges;"
"parent.resetDets();"
"this.idx=new idx(this);"
"this.noDel=parent.noDel;this.noIns=parent.noIns;this.noUpd=parent.noUpd;"
"}"
"function findcnode(n,t)"
"{if(n==null)return null;"
"var j,l=n.childNodes.length;"
"for(j=0;j<l;j++)if(n.childNodes.item(j).tagName==t)return n.childNodes.item(j);"
"return null;}"
"function resetDets()"
"{if (this.pDets==null) return;"
"var i,l=this.pDets.length;"
"for(i=0;i<l;i++)"
"{ var rsd=this.pDets[i];"
" var row=this.idx.row(this.pos);"
" var det=findcnode(row,rsd.linkFld);"
" rsd.RowData=det;"
" rsd.RowCnt=(det==null)?0:det.childNodes.length;"
" if(rsd.idx) rsd.idx.sort(null);"
" rsd.first();"
"rsd.resetDets();"
" rsd.notify(2);}}"
"function dsApply(frm,el)"
"{"
"if(frm==null||el==null||this.forcepost()!=0||this.DeltaChanges.row.length==0)return;"
"if (this.BeforeApply()==0)return;"
"var delta=this.getDelta();"
"if(delta.childNodes.item(1).childNodes.length==0) return;"
"el.value=(delta.xml!=null)?delta.xml:delta.xmlstr();"
"frm.submit();"
"}"
"function dsInsert(prow,bFollow)"
"{if (this.noIns){return this.OnError(szErr_Invalid);}"
"prow=this.BeforePost(1,prow);"
"if(prow==null) return 1;"
"var spos=this.pos;"
"var pN=this.ins();"
"if(pN==null) return 1;"
"var r=this.idx.row(this.pos);"
"r.setAttribute(szRowState,szNew);"
"this.upd(prow);"
"if(this.pDets){"
"var i,l=this.Fields.Cnt;"
"for(i=0;i<l;i++){if(this.Fields.Fieldx[i].Type==szNested){var el=this.doc.createElement(this.Fields.Fieldx[i].iname);r.appendChild(el);}}"
"}"
"if (bFollow==0)this.pos=spos;"
"this.resetDets();"
"this.DeltaChanges.add(szNew,pN,null,this);"
"this.idx.chg=1;"
"this.AfterPost(1,prow);"
"return 0;}"
"function dsModify(p,prow)"
"{if(this.noUpd){return this.OnError(szErr_Invalid);}"
"prow=this.BeforePost(3,prow);"
"if(prow==null) return 1;"
"var pO,pM; "
"var spos=this.pos; this.pos=p;"
"var i,l;"
"pM=this.idx.row(p);"
"var rstate=pM.getAttribute(szRowState);"
"if(rstate!=szNew){"
" pO=pM.cloneNode(0);l=pM.childNodes.length;"
" for(i=0;i<l;i++)pO.appendChild(pM.childNodes.item(i).cloneNode(0));"
" pM.setAttribute(szRowState,szMod);"
" this.upd(prow);"
" this.DeltaChanges.add(szMod,pM,pO,this);"
"}else this.upd(prow); "
"this.pos=spos;"
"this.idx.chg=1;"
"this.AfterPost(3,prow);"
"return 0;}"
"function dsDelete(p)"
"{if(this.noDel){return this.OnError(szErr_Invalid);}"
"var r=this.idx.row(p); "
"r=this.BeforePost(2,r);"
"if(r==null)return 1;"
"var spos=this.pos; this.pos=p;"
"var i,l=r.childNodes.length;"
"if(l&&this.pDets)"
" for(i=0;i<this.pDets.length;i++){var det=findcnode(r,this.pDets[i].linkFld);if(det&&det.childNodes.length>0)return this.OnError(szErr_HasDets);}"
"r.setAttribute(szRowState,szDel);"
"var pD=this.del();"
"if(p<spos) this.pos=spos-1;"
"this.resetDets();"
"this.DeltaChanges.add(szDel,pD,null,this);"
"this.idx.chg=1;"
"this.AfterPost(2,null);"
"return 0;}"
"function updRow(prow)"
"{var i,f,v,r=this.idx.row(this.pos);"
"if(r==null)return r;"
"for(i=0;i<this.Fields.Cnt;i++){f=this.Fields.Fieldx[i];v=prow[f.name];if (v!=null) f.put(r,v);}"
"this.notify(1);"
"return r;"
"}"
"function makeRow()"
"{var i,f,v,r=this.idx.row(this.pos);"
"if(r==null)return r;"
"var RowBuf=new Array();"
"for(i=0;i<this.Fields.Cnt;i++){f=this.Fields.Fieldx[i];v=null;if(f.bAsAttr)v=r.getAttribute(f.iname);if(v!=null)RowBuf[f.name]=v;}"
"return RowBuf;}"
"function insRow()"
"{if(this.FieldData==null)return null;"
"var rname='ROW';"
"def=this.OnNewRow();"
"if(this.linkFld)rname+=this.linkFld;"
"var r=this.doc.createElement(rname);"
"var i,f;"
"for(i=0;i<this.Fields.Cnt;i++){    "
" var F;"
" f=this.Fields.Fieldx[i];"
" if(f.bAsAttr==0){var T=this.doc.createTextNode('');F=this.doc.createElement(f.iname);F.appendChild(T); r.appendChild(F);}"
" else if(def&&def[f.name]!=null)r.setAttribute(def[f.name]);"
"}"
"if(this.RowData==null)this.RowData=this.doc.createElement(this.linkFld);"
"this.RowData.appendChild(r);"
"this.RowCnt++;"
"this.pos=this.RowCnt-1;"
"this.idx.add(this.pos);"
"return r;}"
"function delRow()"
"{var r=this.idx.row(this.pos);"
"if(r==null)return null;"
"var pos=this.pos;"
"this.RowData.removeChild(r);"
"this.idx.rem(pos);"
"if(pos==this.RowCnt-1&&pos>0)this.pos=pos-1;"
"this.RowCnt--;      "
"this.notify(1); "
"return r;}"
"function RowState(pos)"
"{var r=this.idx.row(pos);"
"if(r==null)return '';"
"var st=r.getAttribute(szRowState);"
"if(st==null||st=='')return '';"
"var v=parseInt(st,10);"
"if(v==2)st='D';if(v==4)st='I';if(v==8)st='M';if(v==64)st='DU';"
"return st;}"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -