var Config,SetConfig,DB,Page,$,$$,Login,htmlEntity;
var IO;
var Folder;
var File;
Config={
conn:new String(Application("Conn"))
};
SetConfig = function (config, args) {
if (args) {
for (var proto in args) {
config[proto] = args[proto];
}
}
return config;
}
Page=function(p,pc,size,prefix,suffix){
p<1?p=1:p;
p>pc?p=pc:p;
size>pc?size=pc:size;
this.getCode=function(cssNormal,cssSelect){
var code="";
if(pc<=size){
for(var i = 1;i<=pc; i++){
if(i==p){
code += ' <span'+(cssSelect?' class="'+cssSelect+'"':'')+'>'+i+'</span> ';
}else{
code += ' <a'+(cssNormal?' class="'+cssNormal+'"':'')+' href="'+prefix+i+suffix+'">'+i+'</a> ';
}
}
}else{
var minx = (size/2).toFixed(0);
var sinx = p-minx+1;
sinx=(sinx>1 ? sinx:1); //开始
einx=(pc+1>sinx+size?sinx+size:pc+1); //结束
for(var i=sinx;i<einx;i++){
if(i==p){
code += ' <span'+(cssSelect?' class="'+cssSelect+'"':'')+'>'+i+'</span> ';
}else{
code += ' <a'+(cssNormal?' class="'+cssNormal+'"':'')+' href="'+prefix+i+suffix+'">'+i+'</a> ';
}
}
}
return code;
}
this.getPrev=function(css){
return p>1?'<a'+(css?' class="'+css+'"':'')+' href="'+prefix+(p-1)+suffix+'">上一页</a>':'';
}
this.getNext=function(css){
return p<pc?'<a'+(css?' class="'+css+'"':'')+' href="'+prefix+(p+1)+suffix+'">下一页</a>':'';
}
}
DAO=function(){
var obj=this;
obj.List={}
obj.List.Page={
PS:25,//pagesize
AP:1,//abspagecode
PC:0,//pagecount
RC:0 //recordCount
}
obj.Reader=function(sql)
{
this.Rs=Server.CreateObject("Adodb.RecordSet");
this.Rs.Open(sql,Config.conn,1,1);
}
obj.Reader.Read=function()
{
if(this.Rs.EOF)
{
return false;
}else{
var Record={};
for(var i=0;i<this.Rs.Fields.Count;i++){
Record[this.Rs.Fields.Item(i).Name] = this.Rs.Fields.Item(i).Value;
}
this.Rs.MoveNext();
return Record;
}
}
obj.Reader.Close=function()
{
this.Rs.Close();
this.Rs=null;
}
obj.List.Config={};
//不够优化还要重构
obj.List.Get=function(){
var config = obj.List.Config =new SetConfig({
fields:" * ",
table:null,
where:" 1=1 ",
sort:" ID desc ",
pk:" ID "
},arguments[0]);
var RC=obj.GetRecord("select count("+config.pk+") as [count] from "+config.table+
" where "+config.where).count;
var _MOD=RC%obj.List.Page.PS;
if(_MOD==0){
obj.List.Page.PC=RC/obj.List.Page.PS;
}else{
obj.List.Page.PC=(RC-_MOD)/obj.List.Page.PS+1;
}
obj.List.Page.RC=RC;
}
obj.List.GetDataTable=function(p){
var config = obj.List.Config;
obj.List.Page.AP=p;
var sql=null;
if(p>1){
sql="select top "+obj.List.Page.PS+" "+config.fields+
" from "+config.table+" where "+config.where+
" and "+config.pk+
" not in(select top "+(p-1)*obj.List.Page.PS+" "+config.pk+
" from "+config.table+" where "+config.where+
" order by "+config.sort+") order by "+config.sort;
}else{
sql="select top "+obj.List.Page.PS+" "+config.fields+
" from "+config.table+" where "+config.where+" order by "+config.sort;
}
var returnArr=[];
var Conn=Server.CreateObject("ADODB.Connection");
Conn.Open(Config.conn);
var Rs=Server.CreateObject("ADODB.RecordSet");
Rs.Open(sql,Conn,1,1);
while(!Rs.EOF){
var Record={};
for(var i=0;i<Rs.Fields.Count;i++){
Record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
returnArr.push(Record);
Rs.MoveNext();
}
Rs.Close();
Rs=null;
Conn.Close();
Conn=null;
return returnArr;
}
obj.GetRecord = function(sql){
var Record=null;
var Conn=Server.CreateObject("ADODB.Connection");
Conn.Open(Config.conn);
var Rs=Server.CreateObject("ADODB.RecordSet");
Rs.Open(sql,Conn,1,1);
if(Rs.RecordCount==1){
Record={};
for(var i=0;i<Rs.Fields.Count;i++){
Record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
}
Rs.Close();
Rs=null;
Conn.Close();
Conn=null;
return Record;
}
obj.ExecuteSQL=function(sql){
var Conn=Server.CreateObject("ADODB.RecordSet");
Conn.Open(Config.conn);
Conn.Execute(sql);
Conn.Close();
Conn=null;
}
obj.ADDRecord=function(sql,json){
var Conn=Server.CreateObject("ADODB.Connection");
Conn.Open(Config.conn);
var Rs=Server.CreateObject("ADODB.RecordSet");
Rs.Open(sql,Conn,3,2);
Rs.AddNew();
for(var inx in json){
Rs(inx).Value = json[inx];
}
Rs.Update();
Rs.Close();
Rs=null;
Conn.Close();
Conn=null;
}
obj.UpdateRecord = function(sql,json){
var Conn=Server.CreateObject("ADODB.Connection");
Conn.Open(Config.conn);
var Rs=Server.CreateObject("ADODB.RecordSet");
Rs.Open(sql,Conn,3,2);
for(var inx in json){
Rs(inx).Value = json[inx];
}
Rs.Update();
Rs.Close();
Rs=null;
Conn.Close();
Conn=null;
}
};
var FSO = new ActiveXObject("Scripting.FileSystemObject");
IO={};
IO.File={
Read:function(path){
var ForReading = 1;
var File=FSO.OpenTextFile(path,ForReading);
return File.ReadAll();
},
Create:function(path){
var File = FSO.CreateTextFile(path, true);
File.Write(content);
File.Close();
},
Exist:function(path){
return FSO.FileExists(path);
},
Delete:function(path){
if(this.Exist(path)){
FSO.DeleteFile(path);
}
}
}
IO.Folder={
Create:function(path){
FSO.CreateFolder(path);
},
Delete:function(path){
if(this.Exist(path)){
FSO.DeleteFolder(path);
}
},
Exist:function(path){
return FSO.FolderExists(path);
}
}
File=IO.File;
Folder=IO.Folder;
DB=new DAO();
$=function(format,data){
var returnstr="";
for(var i=0;i<data.length;i++){
var temhtml=format.replace('[i]',i+1);
for(var key in data[i]){
temhtml=temhtml.replace('{'+key+'}',data[i][key]);
}
returnstr+=temhtml;
}
return returnstr;
}
$$=function(format,data){
var returnstr="";
var inx=0;
for(var i=0;i<format.length;i++){
if(inx>=data.length) break;
if(!format[i].num) format[i].num=100;
for(var j=0;j<format[i].num;j++){
var temhtml=format[i].html.replace('[i]',inx+1);
for(var key in data[i]){
temhtml=temhtml.replace('{'+key+'}',data[i][key]);
}
returnstr+=temhtml;
if(++inx>=data.length) break;
}
}
return returnstr;
}
htmlEntity=function(html){
html=html||" ";
html=html
.replace(/\&/g,"&")
.replace(/</g,"<")
.replace(/>/g,">")
.replace(/"/g,""")
.replace(/'/g,"'");
return html;
}
entityHtml=function(entity){
entity=entity
.replace(/\&/g,"&")
.replace(/\</g,"<")
.replace(/\>/g,">")
.replace(/\"/g,'"')
.replace(/\'/g,"'");
return entity;
}