Asp数据库操作类【原创】

  很久以前写了个asp操作类,就研究java去了,前段时间由于要帮朋友弄个东西,又捡起那个类一看,唉~还是差点什么,于是,改写了一下:
None.gif <%
None.gif
// 基本操作类
None.gif

None.gif
// 清缓存
None.gif
Response.Expires =- 1000 ;
None.gifResponse.CacheControl
= " no-cache " ;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 用Javascript实现的一个数据库操作类
InBlock.gif * @author zxub
InBlock.gif * 修改于2005-11-24
ExpandedBlockEnd.gif 
*/

None.gif
function  DBOperate()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {        
InBlock.gif    
this.connString=""; //连接字符串
InBlock.gif
    this.connString="Provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath("/sms/dbo/aaa@163.com/#data.asp");
InBlock.gif    
//this.connString="driver={SQL SERVER};server=localhost;database=user;uid=study;pwd=study;";
InBlock.gif
    this.conn; //数据库连接对象
InBlock.gif
    this.rs;   //数据集    
InBlock.gif
    this.cursorType=1//纪录集移动方式:
InBlock.gif
                     //0为只读,当前数据记录只能向下移动;
InBlock.gif
                     //1为只读,当前数据记录可自由移动;
InBlock.gif
                     //2为可读写,当前数据记录可自由移动;
InBlock.gif
                     //3为可读写,当前数据记录可自由移动,可看到新增记录
InBlock.gif
                     //RS.MoveFirst(),RS.MoveLast(),RS.MoveNext(),RS.MovePrevious().
InBlock.gif
                     //RS.Move(n) 方法:从当前位置移动n条记录,n>0为正向,n<0为反向,
InBlock.gif
                     //RS.Move(n,1) 方法:从第一条纪录处移动n条记录,n>0,后面的参数只能为1
InBlock.gif
    this.lockType=1//纪录集锁定方式:
InBlock.gif
                     //1为缺省锁定类型,记录集是只读的,不能修改记录
InBlock.gif
                     //2为悲观锁定,当修改记录时,数据提供者将尝试锁定记录以确保成功地编辑记录。只要编辑一开始,则立即锁住记录。
InBlock.gif
                     //3为乐观锁定,直到用Update方法提交更新记录时才锁定记录。
InBlock.gif
                     //4为批量乐观锁定,允许修改多个记录,只有调用UpdateBatch方法后才锁定记录。
InBlock.gif
    //*************************************************************************
InBlock.gif
    //当分页的时候,计算totalRecordCount和totalPageCount
InBlock.gif
    //*************************************************************************
InBlock.gif
    this.totalRecordCount=0;  //纪录集总纪录数,开始由于没纪录集,所以为0
InBlock.gif
    this.pageSize=10;    //每页最大纪录数,默认为10
InBlock.gif
    this.totalPageCount=0;  //最大页数.    
InBlock.gif
    //*************************************************************************
InBlock.gif
    this.currentPageID=1;  //当前页码,默认为1
InBlock.gif
    this.currentPageTag="CurrentPageID";
InBlock.gif    
this.gotoPageName="?";  //显示纪录的页面名称,默认为当前页面
InBlock.gif
    this.recordIndexInPage=0;  //用于分页时的数据下移
InBlock.gif
    
InBlock.gif    
//打开数据库
InBlock.gif
    this.openDatabase=function(_dbPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif        
if (_dbPath!=undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.connString="Provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath(_dbPath);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.conn=Server.CreateObject("ADODB.Connection");
InBlock.gif            
this.conn.Open(this.connString);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch (e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"数据库连接错误!");
InBlock.gif            Response.End();
ExpandedSubBlockEnd.gif        }
            
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//关闭数据库
InBlock.gif
    this.closeDatabase=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (this.rs!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.rs.Close();
InBlock.gif            
this.rs=null;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
if (this.conn!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.conn.Close();
InBlock.gif            
this.conn=null;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//获取一个数据集对象
InBlock.gif
    this.getRecordSet=function(_sqlString)  
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (this.conn!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var i=Request.QueryString(this.currentPageTag).Count;
InBlock.gif            
if (i>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.currentPageID=parseInt(Request.QueryString(this.currentPageTag));
InBlock.gif                
if (this.currentPageID<=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.closeDatabase();
InBlock.gif                    Response.Write(
"页码超出合法范围!");
InBlock.gif                    Response.End();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.rs=Server.CreateObject("ADODB.RecordSet");    
InBlock.gif            
this.rs.Open(_sqlString,this.conn,this.cursorType,this.lockType);                
InBlock.gif            
this.totalRecordCount=this.rs.RecordCount;
InBlock.gif            
this.totalPageCount=Math.ceil(this.totalRecordCount/this.pageSize);
InBlock.gif            
var endPage=this.totalPageCount;
InBlock.gif            
if (endPage==0) endPage=1;
InBlock.gif            
if (this.currentPageID>endPage)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.closeDatabase();
InBlock.gif                Response.Write(
"页码超出合法范围!"+this.pageSize);
InBlock.gif                Response.End();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//指针位置调整
InBlock.gif
            if (!this.rsIsEmpty() && this.currentPageID>1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.rs.MoveFirst();                    
InBlock.gif                
this.rs.Move((this.currentPageID-1)*this.pageSize,1);
ExpandedSubBlockEnd.gif            }
                
ExpandedSubBlockEnd.gif        }
                
InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"没有连接到数据库!");
InBlock.gif            Response.End();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//判断分页的时候记录是否已到一页的末尾
InBlock.gif
    this.isPageEnd=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.rs.moveNext();
InBlock.gif        
this.recordIndexInPage++;
InBlock.gif        
if (this.recordIndexInPage<this.pageSize)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{                
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return true;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//关闭数据集对象
InBlock.gif
    this.closeRecordSet=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (this.rs!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.rs.Close();
InBlock.gif            
this.rs=null;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//执行SQL语句,用于执行添加、删除、修改操作
InBlock.gif
    this.executeSql=function(_sqlString)  
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (this.conn!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.conn.Execute(_sqlString);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"没有连接到数据库!");
InBlock.gif            Response.End();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
this.addNewAndReturnPK=function(_parameterMap,_tableName,_pkName)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{       
InBlock.gif        
var returnValue="";
InBlock.gif        
if (this.rs==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.rs=Server.CreateObject("ADODB.RecordSet");
InBlock.gif            
this.rs.ActiveConnection=this.conn;
InBlock.gif            
this.rs.CursorType=this.cursorType;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.rs.LockType=3;
InBlock.gif        
this.rs.Source=_tableName;
InBlock.gif        
this.rs.Open();
InBlock.gif        
this.rs.AddNew();
InBlock.gif        
var keys=_parameterMap.keys();        
InBlock.gif        
for (var i=0;i<keys.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Response.Write(keys[i]+":");
InBlock.gif
            //Response.Write(_parameterMap.get(keys[i])+"<br>");
InBlock.gif
            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.rs(keys[i])=_parameterMap.get(keys[i]);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{}
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.rs.Update();
InBlock.gif        returnValue
=this.rs(_pkName).value;
InBlock.gif        
this.rs.Close();
InBlock.gif        
this.rs.LockType=this.lockType;    
InBlock.gif        
this.rs.Open();
InBlock.gif        
return returnValue;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
this.updateRecord=function(_parameterMap,_tableName,_pkValue,_pkName)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (this.rs==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.rs=Server.CreateObject("ADODB.RecordSet");
InBlock.gif            
this.rs.ActiveConnection=this.conn;
InBlock.gif            
this.rs.CursorType=this.cursorType;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.rs.LockType=3;
InBlock.gif        
this.rs.Source=_tableName;
InBlock.gif        
this.rs.Open();
InBlock.gif        
this.rs.Find(_pkName+"="+_pkValue);
InBlock.gif        
var keys=_parameterMap.keys();
InBlock.gif        
for (var i=0;i<keys.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.rs(keys[i])=_parameterMap.get(keys[i]);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{}            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.rs.Update();
InBlock.gif        
this.rs.Close();
InBlock.gif        
this.rs.LockType=this.lockType;    
InBlock.gif        
this.rs.Open();
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//判断获取的数据集对象是否为空
InBlock.gif
    this.rsIsEmpty=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (this.rs!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((this.rs.BOF) && (this.rs.EOF))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//RS is empty
InBlock.gif
                return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//RS not empty
InBlock.gif
                return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"没有连接到数据库!");
InBlock.gif            Response.End();
ExpandedSubBlockEnd.gif        }
            
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//打印分页导航条
InBlock.gif
    this.setRecordNavigator=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{            
InBlock.gif        
var previousPageID=this.currentPageID-1;
InBlock.gif        
var nextPageID=this.currentPageID+1;
InBlock.gif        
var homePage=1;
InBlock.gif        
var endPage=this.totalPageCount;
InBlock.gif        
//************************************************************
InBlock.gif
        //分页操作如下,8为每页记录数
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//*var obj=getConn("select * from modules",8);
InBlock.gif        while (!obj.rs.eof)
InBlock.gif        {
InBlock.gif            Response.Write(obj.rs("name").value+"<br>");
InBlock.gif            if (obj.isPageEnd()) break;
InBlock.gif        }
InBlock.gif        obj.setRecordNavigator();
InBlock.gif        obj.closeDatabase();
ExpandedSubBlockEnd.gif        obj=null;
*/

InBlock.gif        
//************************************************************            
InBlock.gif
        var navigatorString="";
InBlock.gif        navigatorString
+="<table width=\"100%\" height=\"25\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:12px\">";
InBlock.gif        navigatorString
+="<tr>";
InBlock.gif        navigatorString
+="<td align=\"right\" valign=\"middle\">合计 <strong><font color=\"#FF0000\">";
InBlock.gif        navigatorString
+=this.totalRecordCount;
InBlock.gif        navigatorString
+="</font></strong> 个 | ";
InBlock.gif        
if (this.currentPageID==homePage)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            navigatorString
+="<A disabled>首页</A> <A disabled>上一页</A> ";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            navigatorString
+="<A href="+this.gotoPageName+this.currentPageTag+"="+homePage+">首页</A> <A href="+this.gotoPageName+this.currentPageTag+"="+previousPageID+">上一页</A> ";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
if (this.currentPageID==endPage)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            navigatorString
+="<A disabled>下一页</A> <A disabled>尾页</A> </td>";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            navigatorString
+="<A href="+this.gotoPageName+this.currentPageTag+"="+nextPageID+">下一页</A> <A href="+this.gotoPageName+this.currentPageTag+"="+endPage+">尾页</A> </td>";
ExpandedSubBlockEnd.gif        }

InBlock.gif        navigatorString
+="<td width=\"140\" align=\"center\" valign=\"middle\">页次:<strong><font color=\"#FF0000\">";
InBlock.gif        navigatorString
+=this.currentPageID;
InBlock.gif        navigatorString
+="</font>/";
InBlock.gif        navigatorString
+=this.totalPageCount+"&nbsp;";
InBlock.gif        navigatorString
+=this.pageSize+"</strong>个/页 </td>"
InBlock.gif        navigatorString
+="<td width=\"36\" align=\"right\" valign=\"middle\">转到: </td>"
InBlock.gif        navigatorString
+="<td width=\"76\" align=\"left\" valign=\"middle\">";
InBlock.gif        navigatorString
+="<select name=CurrentPage style='font-size:12px;width:60px' οnchange=\"document.location=\'"+this.gotoPageName+this.currentPageTag+"=\'+this.options[this.selectedIndex].value\">";
InBlock.gif        
for (i=1;i<=this.totalPageCount;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(this.currentPageID==i)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                navigatorString
+="<option selected value="+i+">第"+i+"页</option>"
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                navigatorString
+="<option value="+i+">第"+i+"页</option>"
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        navigatorString
+="</select>"
InBlock.gif        navigatorString
+="</td>";
InBlock.gif        navigatorString
+="</tr>";
InBlock.gif        navigatorString
+="</table>"    
InBlock.gif        
if (endPage>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(navigatorString);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
%>
None.gif
<!------------------------------------------------------------------------------------------------->
None.gif
<%
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 字符串截取
InBlock.gif * _inputString:要截取的字符串
InBlock.gif * _appendString:截取后附加的字符串,如dot.gif
InBlock.gif * _cutLen:截取的字符数,一个全角字符及汉字占2个字符
ExpandedBlockEnd.gif 
*/

None.gif
function  cutString(_inputString,_appendString,_cutLen)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    _inputString
=String(_inputString);
InBlock.gif    _appendString
=String(_appendString);
InBlock.gif    
var _factLen=0,_tempString="",i;
InBlock.gif    
var strLength=_inputString.length;
InBlock.gif    
for (i=0;i<strLength;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (_inputString.charCodeAt(i)>255)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _factLen
+=2;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _factLen
+=1;
ExpandedSubBlockEnd.gif        }
               
InBlock.gif        
if (_factLen>_cutLen)
InBlock.gif            
break;              
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _tempString
+=_inputString.substr(i,1);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch (e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
break;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
if (_factLen>_cutLen)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        _tempString
+=_appendString;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return _tempString;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 换行及回车的显示
InBlock.gif * _string:要显示的部分
ExpandedBlockEnd.gif 
*/

None.gif
function  alignString(_string)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
return String(_string).replace( /[\" \"]/g,"&nbsp;").replace( /[\" \"]/g,"&nbsp;&nbsp;").replace(/[\r]/g,"<br>");
ExpandedBlockEnd.gif}

None.gif
%>
None.gif
<!----------------------------------------------------------------------------------------------------------->
None.gif
<%
None.gif
None.gif
// 基于基础类的扩展操作函数
None.gif

None.gif
function  addNewAndReturnPK(_parameterMap,_tableName,_pkName)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var returnValue="";
InBlock.gif    
if (_pkName==undefined) _pkName="id";
InBlock.gif    
var object=new DBOperate();
InBlock.gif    object.openDatabase();
InBlock.gif    returnValue
=object.addNewAndReturnPK(_parameterMap,_tableName,_pkName);
InBlock.gif    object.closeDatabase();
InBlock.gif    object
=null;
InBlock.gif    
return returnValue;
ExpandedBlockEnd.gif}

None.gif
None.gif
function  updateRecord(_parameterMap,_tableName,_pkValue,_pkName)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if (_pkName==undefined) _pkName="id";
InBlock.gif    
var object=new DBOperate();
InBlock.gif    object.openDatabase();
InBlock.gif    returnValue
=object.updateRecord(_parameterMap,_tableName,_pkValue,_pkName);
InBlock.gif    object.closeDatabase();
InBlock.gif    object
=null;    
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 执行一条sql语句
InBlock.gif * _sqlString:要执行的sql语句
ExpandedBlockEnd.gif 
*/

None.gif
function  execSql(_sqlString)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var object=new DBOperate();
InBlock.gif    object.openDatabase();    
InBlock.gif    object.executeSql(_sqlString);
InBlock.gif    object.closeDatabase();
InBlock.gif    object
=null;
ExpandedBlockEnd.gif}

None.gif    
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 批处理执行sql语句,传递一个数组(Array),数组里存放sql语句
InBlock.gif * _sqlArr:存放sql语句的数组
ExpandedBlockEnd.gif 
*/

None.gif
function  execBatchSql(_sqlArr)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var object=new DBOperate();
InBlock.gif    object.openDatabase();
InBlock.gif    object.conn.BeginTrans();
InBlock.gif    
for (var i=0;i<_sqlArr.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{        
InBlock.gif        object.conn.Execute(_sqlArr[i]);
InBlock.gif        
if (object.conn.Errors.Count>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            object.conn.Errors.Clear();
InBlock.gif            object.conn.RollBackTrans();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    object.conn.CommitTrans();
InBlock.gif    object.closeDatabase();
InBlock.gif    object
=null;
ExpandedBlockEnd.gif}

ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 获取一个指定的数据库操作对象,并进而获取一个数据集对象
InBlock.gif * _sqlString:一条select语句,用于获取数据集
InBlock.gif * _pageSize:数据集分页大小,若要获取所有,则该项不填
InBlock.gif * _curPageTag:指定分页标记名称,不填,则用默认
ExpandedBlockEnd.gif 
*/
     
None.gif
function  getConn(_sqlString,_pageSize,_curPageTag)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var object=new DBOperate();
InBlock.gif    
if (_curPageTag!=undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        object.currentPageTag
=_curPageTag;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
if (_pageSize!=undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        object.pageSize
=_pageSize;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        object.pageSize
=999990;
ExpandedSubBlockEnd.gif    }
    
InBlock.gif    object.openDatabase();
InBlock.gif    object.getRecordSet(_sqlString);         
InBlock.gif    
return object;
ExpandedBlockEnd.gif}

None.gif
None.gif
function  getRecordData(_sqlString,_fieldArray)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var returnValue=new Array();
InBlock.gif    
var object=new DBOperate();
InBlock.gif    object.openDatabase();    
InBlock.gif    object.getRecordSet(_sqlString); 
InBlock.gif    
if (_fieldArray==undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
while (!object.rs.eof)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var data=new HashTable();
InBlock.gif            
for (var i=0;i<object.rs.fields.count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (object.rs(i).value==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    data.put(object.rs(i).name,
"");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    data.put(object.rs(i).name,object.rs(i).value);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            returnValue.push(data);
InBlock.gif            object.rs.moveNext();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
while (!object.rs.eof)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var data=new HashTable();            
InBlock.gif            
for (var i=0;i<_fieldArray.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (object.rs(_fieldArray[i]).value==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    data.put(_fieldArray[i],
"");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    data.put(_fieldArray[i],object.rs(_fieldArray[i]).value);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            returnValue.push(data);
InBlock.gif            object.rs.moveNext();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    object.closeDatabase(); 
InBlock.gif    
return returnValue;
ExpandedBlockEnd.gif}

None.gif
// 获取参数,行成Map,执行持久化
None.gif

None.gif
// 获取post及get的数据,形成map返回
None.gif
function  parametersToMap()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var returnMap=new HashTable();        
InBlock.gif    
var parameter;
InBlock.gif    
for (var posts=new Enumerator(Request.Form);!posts.atEnd();posts.moveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        parameter
=posts.item();
InBlock.gif        returnMap.put(parameter,Request.Form(parameter));
ExpandedSubBlockEnd.gif    }

InBlock.gif    
for (var gets=new Enumerator(Request.QueryString);!gets.atEnd();gets.moveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        parameter
=gets.item();
InBlock.gif        returnMap.put(parameter,Request.QueryString(parameter));
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return returnMap;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 获取记录并形成map返回,若_pkValue为"",则获取表结构
InBlock.gif * _entityName:数据表名称
InBlock.gif * _pkValue:数据表的主键值,默认主键名称为"id"
ExpandedBlockEnd.gif 
*/

None.gif
function  getEntityMap(_entityName,_pkValue,_pkName)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {        
InBlock.gif    
if (_pkName==undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        _pkName
="id";
ExpandedSubBlockEnd.gif    }

InBlock.gif    
var returnMap=new HashTable();
InBlock.gif    
var sqlString;
InBlock.gif    
var sqlString="select top 1 * from "+_entityName;
InBlock.gif    
var columns=getConn(sqlString,1);
InBlock.gif    
for (var i=0;i<columns.rs.fields.count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//returnMap.put(columns.rs(i).name,columns.rs.Fields(i).Type);
InBlock.gif
        returnMap.put(columns.rs(i).name,"");
ExpandedSubBlockEnd.gif    }

InBlock.gif    
//获取表结构完成    
InBlock.gif
    //若_pkValue有值,则再获取所需数据
InBlock.gif
    if (_pkValue!=undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{          
InBlock.gif        sqlString
="select * from "+_entityName+" where "+_pkName+"="+_pkValue;            
InBlock.gif        entity
=getConn(sqlString,1);
InBlock.gif        
if (!entity.rsIsEmpty())
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (var j=0;j<entity.rs.fields.count;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (entity.rs(j).value==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    returnMap.put(entity.rs(j).name,
"");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{                        
InBlock.gif                    returnMap.put(entity.rs(j).name,entity.rs(j).value);
InBlock.gif                    
if ((""+entity.rs(j).value).indexOf("UTC")>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
var getDate=new Date(entity.rs(j).value)
InBlock.gif                        
var dateString=getDate.getYear()+"-"+(getDate.getMonth()+1)+"-"+getDate.getDate();
InBlock.gif                        returnMap.put(entity.rs(j).name,dateString);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        entity.closeDatabase();
InBlock.gif        entity
=null;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var keys=returnMap.keys();
InBlock.gif        
for (var j=0;j<keys.length;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            returnMap.put(keys[j],
"");
ExpandedSubBlockEnd.gif        }
     
ExpandedSubBlockEnd.gif    }

InBlock.gif    columns.closeDatabase();
InBlock.gif    columns
=null;
InBlock.gif    
return returnMap;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 获取post及get的数据,根据是否存在"id"字段进行更新或插入操作
InBlock.gif * _entityName:要操作的数据表名
ExpandedBlockEnd.gif 
*/

None.gif
function  parametersToEntity(_entityName,_return,_parameters)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {   
InBlock.gif    
if (_parameters==undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        _parameters
=parametersToMap();
ExpandedSubBlockEnd.gif    }
    
InBlock.gif    
if (!_parameters.containsKey("action")) return;
InBlock.gif    checkEntityPermission(_parameters.get(
"action"));    
InBlock.gif    mapToEntity(_parameters,_entityName,_return);        
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * 指定map到数据库的操作映射
InBlock.gif * _map:指定的map
InBlock.gif * _entityName:数据表名
ExpandedBlockEnd.gif 
*/

None.gif
function  mapToEntity(_map,_entityName,_return)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if (_return==undefined)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        _return
=1;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
var sqlString="";
InBlock.gif    
var action=_map.get("action");
InBlock.gif    
if (action=="" || action==nullreturn;
InBlock.gif    _map.remove(
"action");
InBlock.gif    checkEntityPermission(action);
InBlock.gif    
if (action=="insert" || action=="ins"//添加记录
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{        
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _map.remove(
"id");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch (e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{}     
InBlock.gif        
var nodeId=addNewAndReturnPK(_map,_entityName);        
InBlock.gif        Response.Write('
<script language="javascript">alert("添加记录成功!");');
InBlock.gif        
if (parseInt(_return)>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write('history.go(
-'+_return+');');
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write('document.location
="'+_return+'";');
ExpandedSubBlockEnd.gif        }

InBlock.gif        Response.Write('
</script>');
InBlock.gif        
return;
ExpandedSubBlockEnd.gif    }
 
InBlock.gif    
if (action=="update" && _map.containsKey("id")) //修改记录
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{           
InBlock.gif        
var id=_map.get("id");
InBlock.gif        _map.remove(
"id");        
InBlock.gif        updateRecord(_map,_entityName,id);       
InBlock.gif        Response.Write('
<script language="javascript">alert("更新记录成功!");');
InBlock.gif        
if (parseInt(_return)>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write('history.go(
-'+_return+');');
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write('document.location
="'+_return+'";');
ExpandedSubBlockEnd.gif        }

InBlock.gif        Response.Write('
</script>');
InBlock.gif        
return;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
if (action=="delete" && _map.containsKey("id")) //删除记录
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{  
InBlock.gif        sqlString
="delete from "+_entityName+" where id="+parseInt(_map.get("id"));            
InBlock.gif        execSql(sqlString);
InBlock.gif        Response.Write('
<script language="javascript">alert("删除记录成功!");');
InBlock.gif        
if (parseInt(_return)>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write('history.go(
-'+_return+');');
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write('document.location
="'+_return+'";');
ExpandedSubBlockEnd.gif        }

InBlock.gif        Response.Write('
</script>');
InBlock.gif        
return;
ExpandedSubBlockEnd.gif    }
   
ExpandedBlockEnd.gif}

None.gif
%>
None.gif
<!------------------------------------------------------------------------------------------------------->
None.gif
<%     
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * HashTable的javascript实现
InBlock.gif * @author zxub
InBlock.gif * 2005-8-18
ExpandedBlockEnd.gif 
*/

None.gif
None.gif
function  HashTable()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
//表对象
InBlock.gif
    this.hashtable=new Array();
InBlock.gif
InBlock.gif    
//清空表
InBlock.gif
    this.clear=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.hashtable=new Array();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//获取表长度
InBlock.gif
    this.size=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif         
var size=0;
InBlock.gif         
for (var i in this.hashtable)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif             
if (this.hashtable[i]!=null)
InBlock.gif                 size
++;
ExpandedSubBlockEnd.gif         }

InBlock.gif         
return size;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//判断表是否为空
InBlock.gif
    this.isEmpty=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif         
return (this.size()==0)?true:false;
ExpandedSubBlockEnd.gif    }
 
InBlock.gif
InBlock.gif
InBlock.gif    
//插入数据
InBlock.gif
    this.put=function(_key,_value)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (_key==null || _value==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
throw "NullPointerException {" + _key + "},{" + _value + "}";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.hashtable[_key]=_value;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//删除键值
InBlock.gif
    this.remove=function(_key)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.hashtable[_key]=null;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//获取所选键的键值
InBlock.gif
    this.get=function(_key)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return this.hashtable[_key];
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
this.getKeyByValue=function(_value)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var keys=this.keys();
InBlock.gif        
var key="";
InBlock.gif        
for (var i=0;i<keys.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.get(keys[i])==_value)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                key
=keys[i];
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return key;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//获取键名数组
InBlock.gif
    this.keys=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var keys = new Array();
InBlock.gif        
for (var i in this.hashtable)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.hashtable[i]!=null)
InBlock.gif                keys.push(i);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return keys;
ExpandedSubBlockEnd.gif    }
   
InBlock.gif
InBlock.gif    
//获取键值数组
InBlock.gif
    this.values=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var values=new Array();
InBlock.gif        
for (var i in this.hashtable)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.hashtable[i] != null)
InBlock.gif                values.push(
this.hashtable[i]);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return values;
ExpandedSubBlockEnd.gif    }
    
InBlock.gif
InBlock.gif    
//判断表中是否存在一个选定键名
InBlock.gif
    this.containsKey=function(_key)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var exists=false;
InBlock.gif        
for (var i in this.hashtable)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (i==_key && this.hashtable[i]!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                exists
=true;
InBlock.gif                
break;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return exists;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//判断表中是否存在键值为当前值的键
InBlock.gif
    this.containsValue=function(_value)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var contains=false;
InBlock.gif        
if (_value!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (var i in this.hashtable)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (this.hashtable[i]==_value)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    contains
=true;
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return contains;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//获取表中数据字符串表现形式
InBlock.gif
    this.toString=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var result="";
InBlock.gif        
for (var i in this.hashtable)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (this.hashtable[i] != null)
InBlock.gif                result
+=""+i+":"+this.hashtable[i]+"<br>";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return result;
ExpandedSubBlockEnd.gif    }
  
ExpandedBlockEnd.gif}

None.gif
%>
None.gif
<!------------------------------------------------------------------------------------------------------->
None.gif
<%
ExpandedBlockStart.gifContractedBlock.gif
/**/ /**
InBlock.gif * md5加密
ExpandedBlockEnd.gif 
*/

ExpandedBlockStart.gifContractedBlock.gif
function  md5(sMessage)  dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function RotateLeft(lValue, iShiftBits) dot.gifreturn (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits)); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function AddUnsigned(lX,lY) dot.gif{
InBlock.gif    
var lX4,lY4,lX8,lY8,lResult;
InBlock.gif    lX8 
= (lX & 0x80000000);
InBlock.gif    lY8 
= (lY & 0x80000000);
InBlock.gif    lX4 
= (lX & 0x40000000);
InBlock.gif    lY4 
= (lY & 0x40000000);
InBlock.gif    lResult 
= (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
InBlock.gif    
if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (lX4 | lY4) dot.gif{
InBlock.gif    
if (lResult & 0x40000000return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
InBlock.gif    
else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
ExpandedSubBlockEnd.gif    }
 else return (lResult ^ lX8 ^ lY8);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
function F(x,y,z) dot.gifreturn (x & y) | ((~x) & z); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function G(x,y,z) dot.gifreturn (x & z) | (y & (~z)); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function H(x,y,z) dot.gifreturn (x ^ y ^ z); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function I(x,y,z) dot.gifreturn (y ^ (x | (~z))); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function FF(a,b,c,d,x,s,ac) dot.gif{
InBlock.gif    a 
= AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
InBlock.gif    
return AddUnsigned(RotateLeft(a, s), b);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
function GG(a,b,c,d,x,s,ac) dot.gif{
InBlock.gif    a 
= AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
InBlock.gif    
return AddUnsigned(RotateLeft(a, s), b);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
function HH(a,b,c,d,x,s,ac) dot.gif{
InBlock.gif    a 
= AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
InBlock.gif    
return AddUnsigned(RotateLeft(a, s), b);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
function II(a,b,c,d,x,s,ac) dot.gif{
InBlock.gif    a 
= AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
InBlock.gif    
return AddUnsigned(RotateLeft(a, s), b);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
function ConvertToWordArray(sMessage) dot.gif{
InBlock.gif    
var lWordCount;
InBlock.gif    
var lMessageLength = sMessage.length;
InBlock.gif    
var lNumberOfWords_temp1=lMessageLength + 8;
InBlock.gif    
var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
InBlock.gif    
var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
InBlock.gif    
var lWordArray=Array(lNumberOfWords-1);
InBlock.gif    
var lBytePosition = 0;
InBlock.gif    
var lByteCount = 0;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
while ( lByteCount < lMessageLength ) dot.gif{
InBlock.gif    lWordCount 
= (lByteCount-(lByteCount % 4))/4;
InBlock.gif    lBytePosition 
= (lByteCount % 4)*8;
InBlock.gif    lWordArray[lWordCount] 
= (lWordArray[lWordCount] | (sMessage.charCodeAt(lByteCount)<<lBytePosition));
InBlock.gif    lByteCount
++;
ExpandedSubBlockEnd.gif    }

InBlock.gif    lWordCount 
= (lByteCount-(lByteCount % 4))/4;
InBlock.gif    lBytePosition 
= (lByteCount % 4)*8;
InBlock.gif    lWordArray[lWordCount] 
= lWordArray[lWordCount] | (0x80<<lBytePosition);
InBlock.gif    lWordArray[lNumberOfWords
-2= lMessageLength<<3;
InBlock.gif    lWordArray[lNumberOfWords
-1= lMessageLength>>>29;
InBlock.gif    
return lWordArray;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
function WordToHex(lValue) dot.gif{
InBlock.gif    
var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for (lCount = 0;lCount<=3;lCount++dot.gif{
InBlock.gif    lByte 
= (lValue>>>(lCount*8)) & 255;
InBlock.gif    WordToHexValue_temp 
= "0" + lByte.toString(16);
InBlock.gif    WordToHexValue 
= WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return WordToHexValue;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
var x=Array();
InBlock.gif    
var k,AA,BB,CC,DD,a,b,c,d
InBlock.gif    
var S11=7, S12=12, S13=17, S14=22;
InBlock.gif    
var S21=5, S22=9 , S23=14, S24=20;
InBlock.gif    
var S31=4, S32=11, S33=16, S34=23;
InBlock.gif    
var S41=6, S42=10, S43=15, S44=21;
InBlock.gif    x 
= ConvertToWordArray(sMessage);
InBlock.gif    a 
= 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for (k=0;k<x.length;k+=16dot.gif{
InBlock.gif    AA
=a; BB=b; CC=c; DD=d;
InBlock.gif    a
=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
InBlock.gif    d
=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
InBlock.gif    c
=FF(c,d,a,b,x[k+2], S13,0x242070DB);
InBlock.gif    b
=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
InBlock.gif    a
=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
InBlock.gif    d
=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
InBlock.gif    c
=FF(c,d,a,b,x[k+6], S13,0xA8304613);
InBlock.gif    b
=FF(b,c,d,a,x[k+7], S14,0xFD469501);
InBlock.gif    a
=FF(a,b,c,d,x[k+8], S11,0x698098D8);
InBlock.gif    d
=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
InBlock.gif    c
=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
InBlock.gif    b
=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
InBlock.gif    a
=FF(a,b,c,d,x[k+12],S11,0x6B901122);
InBlock.gif    d
=FF(d,a,b,c,x[k+13],S12,0xFD987193);
InBlock.gif    c
=FF(c,d,a,b,x[k+14],S13,0xA679438E);
InBlock.gif    b
=FF(b,c,d,a,x[k+15],S14,0x49B40821);
InBlock.gif    a
=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
InBlock.gif    d
=GG(d,a,b,c,x[k+6], S22,0xC040B340);
InBlock.gif    c
=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
InBlock.gif    b
=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
InBlock.gif    a
=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
InBlock.gif    d
=GG(d,a,b,c,x[k+10],S22,0x2441453);
InBlock.gif    c
=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
InBlock.gif    b
=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
InBlock.gif    a
=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
InBlock.gif    d
=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
InBlock.gif    c
=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
InBlock.gif    b
=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
InBlock.gif    a
=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
InBlock.gif    d
=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
InBlock.gif    c
=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
InBlock.gif    b
=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
InBlock.gif    a
=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
InBlock.gif    d
=HH(d,a,b,c,x[k+8], S32,0x8771F681);
InBlock.gif    c
=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
InBlock.gif    b
=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
InBlock.gif    a
=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
InBlock.gif    d
=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
InBlock.gif    c
=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
InBlock.gif    b
=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
InBlock.gif    a
=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
InBlock.gif    d
=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
InBlock.gif    c
=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
InBlock.gif    b
=HH(b,c,d,a,x[k+6], S34,0x4881D05);
InBlock.gif    a
=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
InBlock.gif    d
=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
InBlock.gif    c
=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
InBlock.gif    b
=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
InBlock.gif    a
=II(a,b,c,d,x[k+0], S41,0xF4292244);
InBlock.gif    d
=II(d,a,b,c,x[k+7], S42,0x432AFF97);
InBlock.gif    c
=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
InBlock.gif    b
=II(b,c,d,a,x[k+5], S44,0xFC93A039);
InBlock.gif    a
=II(a,b,c,d,x[k+12],S41,0x655B59C3);
InBlock.gif    d
=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
InBlock.gif    c
=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
InBlock.gif    b
=II(b,c,d,a,x[k+1], S44,0x85845DD1);
InBlock.gif    a
=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
InBlock.gif    d
=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
InBlock.gif    c
=II(c,d,a,b,x[k+6], S43,0xA3014314);
InBlock.gif    b
=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
InBlock.gif    a
=II(a,b,c,d,x[k+4], S41,0xF7537E82);
InBlock.gif    d
=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
InBlock.gif    c
=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
InBlock.gif    b
=II(b,c,d,a,x[k+9], S44,0xEB86D391);
InBlock.gif    a
=AddUnsigned(a,AA); b=AddUnsigned(b,BB); c=AddUnsigned(c,CC); d=AddUnsigned(d,DD);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
var temp= WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
InBlock.gif    
return temp.toLowerCase();
ExpandedBlockEnd.gif}

None.gif
%>
None.gif
<%
None.gif
function  showGetMap(_map)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    Response.Write('
<script language="javascript">');
InBlock.gif    Response.Write('
function setValue(objectName,value)');
ExpandedSubBlockStart.gifContractedSubBlock.gif    Response.Write('
dot.gif{');
InBlock.gif    Response.Write('
if (!document.getElementById(objectName)) return;');
InBlock.gif    Response.Write('
var object=document.getElementById(objectName);');
ExpandedSubBlockStart.gifContractedSubBlock.gif    Response.Write('
if (object.type=="text" || object.type=="textarea" || object.type=="hidden"dot.gif{object.value=value;}');
InBlock.gif    Response.Write('
else if (object.type=="select-one")');
ExpandedSubBlockStart.gifContractedSubBlock.gif    Response.Write('
dot.gif{');
InBlock.gif    Response.Write('
var selectOptions=object.options;');
InBlock.gif    Response.Write('
for (var i=0;i<selectOptions.length;i++)');
ExpandedSubBlockStart.gifContractedSubBlock.gif    Response.Write('
dot.gif{');
ExpandedSubBlockStart.gifContractedSubBlock.gif    Response.Write('
if (selectOptions[i].value==value) dot.gif{object.selectedIndex=i;break;}');
ExpandedSubBlockEnd.gif    Response.Write('}
');
ExpandedSubBlockEnd.gif    Response.Write('}
');
ExpandedSubBlockEnd.gif    Response.Write('}
');
InBlock.gif    Response.Write('window.onload
=function()');
ExpandedSubBlockStart.gifContractedSubBlock.gif    Response.Write('
dot.gif{');
InBlock.gif    
var keys=_map.keys();
InBlock.gif    
for (var i=0;i<keys.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        Response.Write('setValue(
"'+keys[i]+'","'+_map.get(keys[i])+'");');        
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    Response.Write('}
');
InBlock.gif    Response.Write('
</script>');
ExpandedBlockEnd.gif}

None.gif
%>
None.gif
<%
None.gif
// sql语句防注入
None.gif
function  safeguard()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var dangerousString="'|;|and|(|)|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare";
InBlock.gif    
var dangerousArray=dangerousString.split("|");
InBlock.gif    
var killIp=true;
InBlock.gif    
var writeSql=true;
InBlock.gif    
var inIp=getIp();
InBlock.gif    
if (killIp)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var alert=false;
InBlock.gif        
var history=getConn("select * from sqlIn where inIp='"+inIp+"'",99999,"##");
InBlock.gif        
while (!history.rs.eof)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (history.rs("killIp").value=="true")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                alert
=true;
InBlock.gif                
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            history.rs.moveNext();
ExpandedSubBlockEnd.gif        }

InBlock.gif        history.closeDatabase();
InBlock.gif        history
=null;
InBlock.gif        
if (alert)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.write(
"<Script Language=JavaScript>alert('由于你曾经意图修改数据库,你的Ip已经被本系统自动锁定!如想正常访问本站请和管理员联系!');</Script>");
InBlock.gif            Response.End();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
var parameters=parametersToMap();
InBlock.gif    
var keys=parameters.keys();
InBlock.gif    
for (var i=0;i<keys.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
for (var j=0;j<dangerousArray.length;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((parameters.get(keys[i])+"").toLowerCase().indexOf(dangerousArray[j])>-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (writeSql)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
var sqlString="Insert into sqlIn (inIp,visitUrl,inKey,inValue,killIp) values('"+inIp+"','"+Request.ServerVariables("URL")+"','"+keys[i]+"','"+(parameters.get(keys[i])+"").replace( /[\']/g,"\"")+"','true')";
InBlock.gif                    execSql(sqlString);
InBlock.gif                }
InBlock.gif                Response.Write(
"<Script Language=JavaScript>alert('请不要在参数中包含非法字符尝试注入!');</Script>");
InBlock.gif                Response.Write(
"非法操作!系统做了如下记录:<br>");
InBlock.gif                Response.Write(
"操作IP:"+inIp+"<br>");
InBlock.gif                now=new Date(); 
InBlock.gif                H=now.getHours(); 
InBlock.gif                M=now.getMinutes(); 
InBlock.gif                S=now.getSeconds(); 
InBlock.gif                timestr=(H<10)?(
"0"+H):H; 
InBlock.gif                timestr+=
":";
InBlock.gif                timestr+=(M<10)?(
"0"+M):M; 
InBlock.gif                timestr+=
":"
InBlock.gif                timestr+=(S<10)?(
"0"+S):S;
InBlock.gif                Response.Write(
"操作时间:"+timestr+"<br>");
InBlock.gif                Response.Write(
"操作页面:"+Request.ServerVariables("URL")+"<br>");                
InBlock.gif                Response.Write(
"提交参数:"+keys[i]+"<br>");
InBlock.gif                Response.Write(
"提交数据:"+parameters.get(keys[i]));
InBlock.gif                Response.End();
InBlock.gif            }
InBlock.gif        }        
InBlock.gif    }
InBlock.gif}
InBlock.gif%>
InBlock.gif<!------------------------------------------------------------------------------------------------->
InBlock.gif<%
InBlock.gif//获取客户端参数
InBlock.gif
InBlock.giffunction getIp()
InBlock.gif{
InBlock.gif    var ip=Request.ServerVariables(
"HTTP_X_FORWARDED_FOR");    
InBlock.gif    if ((ip+
"").indexOf(".")<0)
InBlock.gif    {
InBlock.gif        ip=Request.ServerVariables(
"REMOTE_ADDR");
InBlock.gif    }
InBlock.gif    return ip;
InBlock.gif}
InBlock.gif
InBlock.giffunction getOS()
InBlock.gif{
InBlock.gif    var os=Request.ServerVariables(
"OS");
InBlock.gif    if ((
""+os)=="undefined")
InBlock.gif    {
InBlock.gif        os=
"WIN2003?";
InBlock.gif    }
InBlock.gif    return os;
InBlock.gif}
InBlock.gif
InBlock.gif//递归创建文件夹
InBlock.giffunction createFolder(folderPath)
InBlock.gif{
InBlock.gif    var entry;
InBlock.gif    var path=
"";
InBlock.gif    var f;
InBlock.gif    var fso=Server.CreateObject(
"Scripting.FileSystemObject");
InBlock.gif    for (var entries=new Enumerator(folderPath.split(
"/"));!entries.atEnd();entries.moveNext())
InBlock.gif    {
InBlock.gif        path+=(
"/"+entries.item());
InBlock.gif        if (!fso.folderexists(Server.mappath(path)))
InBlock.gif        {
InBlock.gif            f = fso.CreateFolder(Server.mappath(path));
InBlock.gif        }        
InBlock.gif    }
InBlock.gif}
InBlock.gif
InBlock.giffunction getNowTimeString()
InBlock.gif{
InBlock.gif    var now=new Date();
InBlock.gif    return now.getYear()+
"-"+(now.getMonth()+1)+"-"+now.getDate();   
InBlock.gif}
InBlock.gif
InBlock.giffunction fixDate(_dateString)
InBlock.gif{
InBlock.gif    var d=new Date(_dateString);
InBlock.gif    return d.getYear()+
"-"+(d.getMonth()+1)+"-"+d.getDate();
InBlock.gif}
InBlock.gif%>

  里面还有些扩展应用,注意Map这个概念,和java里的map是一样。具体能否看懂,我就不管了,多说无益,放在这里,可以自己参考下。

转载于:https://www.cnblogs.com/zxub/archive/2006/02/19/333614.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值