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

📄 recordset.asp

📁 大家好
💻 ASP
📖 第 1 页 / 共 2 页
字号:
<SCRIPT RUNAT=SERVER LANGUAGE="JavaScript">
// ************************************************************************ 
// MSL : Microsoft Scripting Libary 
// Visual InterDev 6.0 Recordset Object for ASP
//
// Copyright 1998 Microsoft Corporation. All Rights Reserved.
// ************************************************************************ 
function CreateRecordset(strName,funcInit,objParent)
{	
	if (typeof(strName) != 'string' || strName == '')
		return null;

	var objRecordset = new _Recordset(strName);
	eval(strName + ' = objRecordset');
	// always fire init for recordset
	objRecordset._funcInit = funcInit;
	thisPage.advise(PAGE_ONINIT,strName + '._restoreState()',10);
	return objRecordset;
}

function _Recordset(strName)
{
	if (typeof(_bRSPrototypeCalled) == 'undefined')
		_RS__Prototype();

	// public members
	this.id = strName;
	this.name = strName;
	this.fields = null;
	this.absolutePosition = 0;
	this.BOF = true;
	this.EOF = true;
	this.maintainState = true;

	// private members
	this._rsADO = null;
	this._count = -1;
	this._allowUpdate = false;
	this._objDBConn = null;
	this._bookmark = 0;
	this._params = null;
	this._bCancelUpdate = false;
	this._bFiringOnBeforeUpdate = false;
	this._bAddNew = false;
	this._bAddNewImmediate = false;
	this._bExecuted = false;
	this._strSQL = '';
	
	// advise for default eventhandlers
	this._objEventManager = CreateEventManager();
	this._objEventManager.adviseDefaultHandler(this.name,RS_ONBEFOREOPEN);
	// set default handlers AFTER all other controls are initialized
	thisPage.advise(PAGE_ONINIT,this.name + '.adviseDefaultHandler("' + this.name + '",RS_ONROWENTER)',-10);
	thisPage.advise(PAGE_ONINIT,this.name + '.adviseDefaultHandler("' + this.name + '",RS_ONDATASETCHANGED)',-10);
	thisPage.advise(PAGE_ONINIT,this.name + '.adviseDefaultHandler("' + this.name + '",RS_ONDATASETCOMPLETE)',-10);
	thisPage.advise(PAGE_ONINIT,this.name + '.adviseDefaultHandler("' + this.name + '",RS_ONROWEXIT)',-10);
	thisPage.advise(PAGE_ONINIT,this.name + '.adviseDefaultHandler("' + this.name + '",RS_ONBEFOREUPDATE)',-10);
	thisPage.advise(PAGE_ONINIT,this.name + '.adviseDefaultHandler("' + this.name + '",RS_ONAFTERUPDATE)',-10);
}

function _RS__Prototype()
{
	//public members
	_Recordset.prototype.getCount = _RS_getCount;
	_Recordset.prototype.moveNext = _RS_moveNext;
	_Recordset.prototype.movePrevious = _RS_movePrevious;
	_Recordset.prototype.moveFirst = _RS_moveFirst;
	_Recordset.prototype.moveLast = _RS_moveLast;
	_Recordset.prototype.moveAbsolute = _RS_moveAbsolute;
	_Recordset.prototype.move = _RS_move;
	_Recordset.prototype.updateRecord = _RS_updateRecord;
	_Recordset.prototype.cancelUpdate = _RS_cancelUpdate;
	_Recordset.prototype.addRecord = _RS_addRecord;
	_Recordset.prototype.addImmediate = _RS_addImmediate;
	_Recordset.prototype.deleteRecord = _RS_deleteRecord;
	_Recordset.prototype.advise = _RS_advise;
	_Recordset.prototype.unadvise = _RS_unadvise;
	_Recordset.prototype.adviseDefaultHandler = _RS_adviseDefaultHandler;

	_Recordset.prototype.getRecordSource = _RS_getRecordSource;
	_Recordset.prototype.setRecordSource = _RS_setRecordSource;
	_Recordset.prototype.open = _RS_open;
	_Recordset.prototype.isOpen = _RS_isOpen;
	_Recordset.prototype.close = _RS_close;
	_Recordset.prototype.getConnectString = _RS_getConnectString;
	_Recordset.prototype.getSQLText = _RS_getSQLText;
	_Recordset.prototype.setSQLText = _RS_setSQLText;
	_Recordset.prototype.requery = _RS_requery;
	_Recordset.prototype.setBookmark = _RS_setBookmark;
	_Recordset.prototype.getBookmark = _RS_getBookmark;
	_Recordset.prototype.setParameter = _RS_setParameter;
	_Recordset.prototype.getParameter = _RS_getParameter;
	_Recordset.prototype.isDHTMLAware = _RS_isDHTMLAware;
	_Recordset.prototype.getDHTMLDataSourceID = _RS_getDHTMLDataSourceID;
	
	//events
	RS_ONBEFOREOPEN = 'onbeforeopen';
	RS_ONROWENTER = 'onrowenter';
	RS_ONROWEXIT = 'onrowexit';
	RS_ONDATASETCHANGED = 'ondatasetchanged';
	RS_ONDATASETCOMPLETE = 'ondatasetcomplete';
	RS_ONBEFOREUPDATE = 'onbeforeupdate';
	RS_ONAFTERUPDATE = 'onafterupdate';

	//private members
	_Recordset.prototype._syncBOFandEOF = _RS__syncBOFandEOF;
	_Recordset.prototype._fireEvent = _EM__fireEvent;
	_Recordset.prototype._preserveState = _RS__preserveState;
	_Recordset.prototype._restoreState = _RS__restoreState;
	_Recordset.prototype._hasState = _RS__hasState;
	_Recordset.prototype._isEmpty = _RS__isEmpty;
	_Recordset.prototype._resetMembers = _RS__resetMembers;
	_bRSPrototypeCalled = 1;

	//scope implementation to _RS__Prototype function

	function _RS_getCount()
	{
		if (this._count < 0)
		{
			if (this.isOpen())
			{
				if (!this.BOF || !this.EOF)
				{
					this._count = this._rsADO.RecordCount;
					if (this._count <= 0)
					{	
						var curPos = this._rsADO.AbsolutePosition;
						if (curPos > 0)
						{
							this._count = 0;
							this._rsADO.MoveFirst();
							while (!this._rsADO.EOF)
							{	
								this._count++;	
								this._rsADO.MoveNext();	
							}
							this._rsADO.AbsolutePosition = curPos;
						}
					}
				}
				else
					this._count = 0;

				return this._count;
			}
			return 0;
		}
		return this._count;
	}
	
	function _RS_moveNext(nDirection)
	{
		if (typeof(nDirection) == 'undefined')
				nDirection = 1;
				
		if (!this._isEmpty())
		{
			this._objEventManager.fireEvent(RS_ONROWEXIT);	
			this._rsADO.Move(nDirection);
			this._syncBOFandEOF();
			if (this.EOF || this.BOF)
				return false;
			this.fields._reset(this._rsADO);
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true;
		}
		return false;
	}

	function _RS_movePrevious()
	{	return this.moveNext(-1);	}

	function _RS_moveLast(bReverse)
	{
		if (!this._isEmpty())
		{
			this._objEventManager.fireEvent(RS_ONROWEXIT);
			
			if ((bReverse + '') == 'true')
				this._rsADO.MoveFirst();
			else			
				this._rsADO.MoveLast();
				
			this._syncBOFandEOF();
			this.fields._reset(this._rsADO);
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true;
		}
		return false;
	}

	function _RS_moveFirst()	
	{	return this.moveLast(true);	}

	function _RS_moveAbsolute(nIndex)
	{
		if (!this._isEmpty() && 
			typeof(nIndex) == 'number')
		{
			this._objEventManager.fireEvent(RS_ONROWEXIT);
			this._rsADO.AbsolutePosition = nIndex;
			this._syncBOFandEOF();
			this.fields._reset(this._rsADO);
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true;
		}
		return false;
	}	

	function _RS_move(nIndex)
	{	// move relative to current record
		if (!this._isEmpty() && 
			typeof(nIndex) == 'number')
		{
			this._objEventManager.fireEvent(RS_ONROWEXIT);
			this._rsADO.Move(nIndex);
			this._syncBOFandEOF();
			this.fields._reset(this._rsADO);
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true;
		}
		return false;
	}	

	function _RS_updateRecord()
	{	
		//bFiringOnBeforeUpdate: If the user is calling this function from
		//the OnBeforeUpdate, the call should be rejected.
		if (this._allowUpdate && (!this._isEmpty() || this._bAddNewImmediate) && !this._bFiringOnBeforeUpdate) 
		{ 	
			if (this._bAddNewImmediate)
			{
				if (this._count >= 0)
					++this._count;
				this._rsADO.AddNew();
				this.fields._isValid = true;
			}
			
			this._bFiringOnBeforeUpdate = true;				
			this._objEventManager.fireEvent(RS_ONBEFOREUPDATE);
			this._bFiringOnBeforeUpdate = false;	
			if (!this._bCancelUpdate)
			{
				this._rsADO.Update();
				if (this._rsADO.LockType == 4)
					this._rsADO.UpdateBatch();
		
				if (this._bAddNewImmediate)
					this._syncBOFandEOF();
					
				this._bAddNewImmediate = false;
				this._objEventManager.fireEvent(RS_ONAFTERUPDATE);
				return true;
			}
			else
				this._bCancelUpdate = false;
		} 
		return false; 
	}

	function _RS_cancelUpdate()
	{	
		if (this._allowUpdate && this.isOpen()) 
		{	
			//adEditAdd = 2
			if (this._rsADO.EditMode == 2)
			{
				if (this._bAddNewImmediate)
				{
					if (this._count >= 0)
						--this._count;
				}
				if (!this._isEmpty())
				{
					this._rsADO.CancelUpdate();	
					this._syncBOFandEOF();
					this.fields._reset(this._rsADO);	
				}
				else
				//ADO doesn't support CancelUpdate with empty recordset
					this.fields._isValid = false;
			}
			
			//adEditInProgress = 1
			if (this._rsADO.EditMode == 1)	
				this._rsADO.CancelUpdate(); 
				
			this._bAddNewImmediate = false;
			this._bCancelUpdate = true;
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true; 
		} 
		else 
			return false; 
	}

	function _RS_addRecord()
	{	
		//bFiringOnBeforeUpdate: If the user is calling this function from
		//the OnBeforeUpdate, the call should be rejected.
		if (this._allowUpdate && this.isOpen() && !this._bFiringOnBeforeUpdate) 
		{	
			this._bAddNewImmediate = false;
			this._objEventManager.fireEvent(RS_ONROWEXIT);
			// set flag to indicate new record for subsequent update
			this._bAddNew = true;
			this.fields._reset(this._rsADO);
			this.fields._newRecord = true;
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true; 
		}
		return false; 
	}
	
	function _RS_addImmediate(fieldList, fieldValues)
	{	
		if (this._allowUpdate && this.isOpen() && !this._bFiringOnBeforeUpdate) 
		{	
			this._bAddNewImmediate = false;
			this._objEventManager.fireEvent(RS_ONROWEXIT);
			this._rsADO.AddNew(fieldList, fieldValues);
			if (this._rsADO.LockType == 4)
				this._rsADO.UpdateBatch();
			this._syncBOFandEOF();
			if (this._count >= 0)
				++this._count;
			this.fields._reset(this._rsADO);
			this._objEventManager.fireEvent(RS_ONROWENTER);
			return true; 		
		}
		return false;
	}
	
	function _RS_deleteRecord()
	{	
		if (this._allowUpdate && !this._isEmpty()) 
		{ 
			this._bAddNewImmediate = false;
			this._objEventManager.fireEvent(RS_ONROWEXIT);
			this._rsADO.Delete();
			if (this._rsADO.LockType == 4)
				this._rsADO.UpdateBatch();
			this._rsADO.moveNext();
			if (this._rsADO.EOF)
				this._rsADO.movePrevious();	
									
			this._syncBOFandEOF();
			if (this._count >= 0)
				--this._count;
			this.fields._reset(this._rsADO);
			this._objEventManager.fireEvent(RS_ONROWENTER);	 				
			
			return true; 
		} 
		return false; 
	}

	function _RS_advise(strEvent,funcToCall)
	{
		if (this.isOpen() &&
			(strEvent == RS_ONROWENTER || strEvent == RS_ONDATASETCOMPLETE || strEvent == RS_ONDATASETCHANGED))
		{	// fire immediately if data is available
			this._fireEvent(funcToCall);
		}
		return this._objEventManager.advise(strEvent,funcToCall);
	}

	function _RS_unadvise(strEvent,nAdviseID)
	{
		return this._objEventManager.unadvise(strEvent,nAdviseID);	
	}
	
	function _RS_adviseDefaultHandler(strName,strEvent)
	{
		var nAdviseID = this._objEventManager.adviseDefaultHandler(strName,strEvent);
		if (this.isOpen() && nAdviseID > 0 &&
			(strEvent == RS_ONROWENTER || strEvent == RS_ONDATASETCOMPLETE || strEvent == RS_ONDATASETCHANGED))
		{	// fire immediately if data is available
			var funcToCall = strName + '_' + strEvent + '()';
			this._fireEvent(funcToCall);
		}
		return nAdviseID;
	}


	function _RS_getRecordSource()
	{	return this._rsADO;		}

	//function _RS_setRecordSource(rsADO) OR
	function _RS_setRecordSource(strConn,strSQL)
	{
		if (typeof(strConn) == 'string')
		{	// given a connect and SQL string
			this._resetMembers(true);
			this._objDBConn = Server.CreateObject('ADODB.Connection');
			this._objDBConn.ConnectionString = strConn;
			this._objDBConn.Open();
			if (!this.setSQLText(strSQL))
				return false;
		}
		else if (typeof(strConn) == 'object')
		{
			// given an ADO object
			var strBook = this._bookmark;
			this._objDBConn = null;
			this._resetMembers(true);
			this._bookmark = strBook;
			this._rsADO = strConn;
		}
		else
			return false;

		if (this._rsADO.LockType == 1)		
			this._allowUpdate = false;
		else								
			this._allowUpdate = true;

		if (this.isOpen())
		{
			this.fields = CreateFields(this._rsADO);
			if (this._bookmark != 0)
				this.setBookmark(this._bookmark);
			else
				this._syncBOFandEOF();

			this._objDBConn = this._rsADO.ActiveConnection;			
			
			this._objEventManager.fireEvent(RS_ONROWENTER);
			this._objEventManager.fireEvent(RS_ONDATASETCHANGED);
			this._objEventManager.fireEvent(RS_ONDATASETCOMPLETE);
		}
			
		return true;
	}

	function _RS_isOpen()
	{	
		if ((this._rsADO && this._rsADO.state != 0)	|| (this._bExecuted))
			return true;
		return false;
	}

	function _RS_open()
	{	
		if (this._rsADO != null)
		{
			if (!this.isOpen())
			{
				this._objEventManager.fireEvent(RS_ONBEFOREOPEN);
				if (this._params != null)
				{
					for (var i=0; i < this._params.length; i++)
					{
						if (typeof(this._params[i]) != 'undefined')
							this._rsADO.ActiveCommand.Parameters(Number(i)).value = this._params[i];		
					}
				}

				// force AbsolutePosition to work in server-side cursor for SQL
				if (this._rsADO.CursorLocation == 2)
					this._rsADO.Properties('IRowsetScroll') = true;
				
				// double-check after ONBEFOREOPEN is fired				
				if (!this.isOpen())
					this._rsADO.Open();
					
				this._objDBConn = this._rsADO.ActiveConnection;
				this.fields = CreateFields(this._rsADO);
				this._bExecuted = true;

				if (this._bookmark != 0)
					this.setBookmark(this._bookmark);
				else
					this._syncBOFandEOF();
				
// fire initial events		
				this._objEventManager.fireEvent(RS_ONROWENTER);
				this._objEventManager.fireEvent(RS_ONDATASETCHANGED);
				this._objEventManager.fireEvent(RS_ONDATASETCOMPLETE);
				return true;
			}
		}
		return false;
	}

	function _RS_close()
	{	

⌨️ 快捷键说明

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