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

📄 recordset.asp

📁 网上商城的设计与实现
💻 ASP
📖 第 1 页 / 共 3 页
字号:
							}
						}
					}
				}
				else if (nAbsPos == -2)		// adPosBOF
					rsADO.MoveFirst();
				else if (nAbsPos == -3)		// adPosEOF
					rsADO.MoveLast();


				if (bSeek)
				{	// use key fields to seek to bookmarked record
					var strWhere = '';
					var nKeys = 0;
					for (var keyName in keyFields)
					{
						if (typeof(rsADO.Fields(keyName)) != 'undefined')
						{
							var keyValue = keyFields[keyName];						
							var keyType = rsADO.Fields(keyName).type;
							// put single quotes around the following field types
							// adChar, adVarChar, adLongVarChar, adWChar, adVarWChar, adLongVarWChar,
							// adBSTR, adDate, adGUID, adVariant, adUserDefined,
							// adDBDate, adDBTime, adDBTimeStamp
							if (keyType == 129 || keyType == 200 || keyType == 201 || keyType == 130 || keyType == 202 || keyType == 203 ||
								keyType == 8 || keyType == 7 || keyType == 72 || keyType == 12 || keyType == 132 ||
								keyType == 133 || keyType == 134 || keyType == 135)
								keyValue = "'" + keyValue + "'";
							if (nKeys > 0)	strWhere += ' AND ';
							strWhere += keyName + '=' + keyValue;
							nKeys++;
						}
						else
						{	// abort, field names do not match
							nKeys = 0;
							break;
						}
					}
					var bSeekFailed = false;
					if (nKeys == 1)
					{	// single key field, seek using Find
						rsADO.MoveFirst();
						rsADO.Find(strWhere);
						if (rsADO.AbsolutePosition < 1)
							bSeekFailed = true;
					}
					else if (nKeys > 1)
					{	// multiple key fields, seek using Filter
						var strPrevFilter = rsADO.Filter;
						rsADO.Filter = strWhere;
						if (rsADO.RecordCount)
						{
							var tmpBookmark = rsADO.Bookmark;
							rsADO.Filter = '';
							rsADO.Filter = strPrevFilter;
							rsADO.Bookmark = tmpBookmark;
						}
						else
						{	// seek failed
							bSeekFailed = true;
							rsADO.Filter = '';
							rsADO.Filter = strPrevFilter;
						}
					}
					if (bSeekFailed)
					{	// use previous position OR first record
						if (nAbsPos > 0)
							rsADO.AbsolutePosition = (nAbsPos * 1);
						else
							rsADO.MoveFirst();

						this._allowUpdate = false;
						@if (@trace_warnings)
							thisPage._traceWarning('Err 438: Unable to find record associated with argument [bookmark = "' + bookmark + '"].','recordset.asp',this.name + '.setBookmark(bookmark)');
						@end
					}
				}
				this._syncBOFandEOF();
				@if (@trace_events)
					thisPage._traceEvent(this.name,RS_ONROWENTER);
				@end
				this._objEventManager.fireEvent(RS_ONROWENTER);
			}
		}
		@if (@trace_warnings)
			if (isNaN(parseInt(nAbsPos)))
				thisPage._traceWarning('Err 419: Invalid argument [bookmark = "' + bookmark + '"]. Use getBookmark() to retrieve a valid bookmark.','recordset.asp',this.name + '.setBookmark(bookmark)');
		@end
	}

	function _RS_getBookmark()
	{		
		if (this.isOpen())
		{	// use absolute position to bookmark across recordset sessions
			var rsADO = this._rsADO;
			this._bookmark = this.absolutePosition + ';';
			if (!this.BOF && !this.EOF)
			{	// look for key fields
				var bCursorLoc = rsADO.CursorLocation;
				for (var i=0; i < rsADO.Fields.Count; i++)
				{	// store key fields to validate absolute position
					var bKeyField =  (rsADO.Fields(i).Properties('KeyColumn') == 1);
					if (bKeyField)
					{	// append keyfield name/value pairs to bookmark
						var fieldValue = rsADO.Fields(i);
						var fieldType = rsADO.Fields(i).type;
						//avoid JScript formating for the following field types:
						//adDate, adDBDate, adDBTime, adDBTimeStamp, adBinary
						if ((fieldType == 7) || (fieldType == 133) || (fieldType == 134) || (fieldType == 135))
								this._bookmark += rsADO.Fields(i).name + '=' + escape(Server.HTMLEncode(fieldValue)) + ';';
						//if the field is adBinary there is nothing to do
						else if (fieldType != 128)
							this._bookmark += rsADO.Fields(i).name + '=' + escape(fieldValue) + ';';	
					}
				}
			}
		}
		return this._bookmark;
	}

	function _RS_setParameter(nIndex,value)
	{
		@if (@debug)
			if (typeof(value) == 'object')
			{
				thisPage._reportError(null,'recordset.asp', this.name + '.setParameter(nIndex,value)',
								 'Err 430: Invalid argument [value]. Cannot pass an object as a parameter value. ' +
								 'Provide a scalar value or a scalar property of the object instead.');
			}
		@end
	  
		if (typeof(nIndex) == 'number' && typeof(value) != 'undefined')
		{
			if (this.isOpen())
				this._rsADO.ActiveCommand.Parameters(Number(nIndex)).value = value;
			else
			{
				if (this._params == null)	this._params = new Array;
				this._params[nIndex] = value;
			}
			return true;
		}
		
		@if (@trace_warnings)
			if (typeof(nIndex) != 'number')
				thisPage._traceWarning('Err 440: Wrong argument type [nIndex = ' + nIndex + ']. Expect a number.','recordset.asp',this.name + '.setParameter(nIndex,value)');
			else
				thisPage._traceWarning('Err 403: Argument [value] is undefined.','recordset.asp',this.name + '.setParameter(nIndex,value)');
		@end
		return false;
	}

	function _RS_getParameter(nIndex)
	{
		if (typeof(nIndex) == 'number')
		{
			if (this.isOpen())
				return this._rsADO.ActiveCommand.Parameters(Number(nIndex)).value;
			else if (this.params != null)
				return this._params[nIndex];
		}
		
		@if (@trace_warnings)
			thisPage._traceWarning('Err 440: Wrong argument type [nIndex = ' + nIndex + ']. Expect a number.','recordset.asp',this.name + '.getParameter(nIndex)');
		@end
		return '';
	}

	function _RS_isDHTMLAware()
	{	return false;	}

	function _RS_getDHTMLDataSourceID()
	{	return '';	}

	function _RS__syncBOFandEOF()
	{
		if (this.isOpen())
		{	
			this.EOF = this._rsADO.EOF;	
			this.BOF = this._rsADO.BOF;
			this.absolutePosition = this._rsADO.AbsolutePosition;
		}
	}

	function _RS__preserveState()
	{
		if (this.maintainState)
		{	// preserve state in hidden field
			var bState = false;
			var state = new Object;
		
			if (this._bAddNew)
			{
				bState = true;
				state._addNew = true;
			}
			if (this.isOpen())
			{
				bState = true;
				state._bOpen = true;
				if (this._strSQL != '')
					state._strSQL = this._strSQL;
			}
			if (this._params != null)
			{
				bState = true;
				state._pCount = 0;
				state._pCount = this._params.length;
				for (var i=0; i < state._pCount; i++)
				{
					if (typeof(this._params[i]) != 'undefined') 
						state['p' + i] = this._params[i];
				}
			}
			if (bState)
				return thisPage.persistState(this.name,state);
		}
		return false;
	}

	function _RS__restoreState()
	{
		var r = false;
		this._fireEvent(this._funcInit);
		
		if (this.maintainState)
		{	// attempt to restore previous state
			var state = thisPage.unpersistState(this.name);
			if (state != null)
			{	// restore previous state
				if (state._addNew != null)
					this._bAddNewImmediate = true;
					
				if (!this.isOpen())
				{
					if (state._strSQL != null)
						this.setSQLText(state._strSQL);
						
					if (typeof(state._pCount) != null)
					{
						state._pCount = Number(state._pCount);
						if (state._pCount > 0)
						{
							this._params = new Array;
							for (var i=0; i < state._pCount; i++)
							{
								if (typeof(state['p' + i]) != 'undefined') 
									this._params[i] = state['p' + i];
							}
						}
					}
				
					if (state._bOpen != null)
						this.open();
				}
					
				r = true;
			}		
		}
			
		return r;
	}

	function _RS__hasState()
	{
		if (this.maintainState)
			return thisPage.isStatePersisted(this.name);
		return false;
	}
	
	function _RS__isEmpty()
	{
		return (!this.isOpen() || (this.BOF && this.EOF))
	}
	
	function _RS__resetMembers(bAll)
	{
		this._count = -1;
		this.absolutePosition = 0;
		this._bookmark = 0;
		this._bAddNew = false;
		this._bAddNewImmediate = false;
		this._bCancelUpdate = false;
		this._bFiringOnBeforeUpdate = false;
		if (typeof(bAll) != 'undefined' && bAll)
		{
			this.BOF = true;
			this.EOF = true;
			this._bExecuted = false;
			this.fields = null;
			this._strSQL = '';
			this._params = null;
		}
	}
	
@if (@debug)
	function _RS__reportError(e,action)
	{
		thisPage._reportError(e,'recordset.asp', this.name + '.open()',
						 'Err 418: Failed to ' + action + ' the ADO recordset. Check for the following possible causes:<br><ul>' +
						 '<li>An invalid SQL statement.</li>' +
						 '<li>Missing or invalid database object name (check recordset DTC properties).</li>' +
						 '<li>Missing parameters or parameter type mismatch (parameters must be set before ' + action + ').</li></ul>' +
						 '<em>CommandType =</em> ' + this._rsADO.ActiveCommand.CommandType + '<br>' +
						 '<em>CommandText =</em> "' + this._rsADO.ActiveCommand.CommandText + '"');
	}
@end

}	// end of _RS__Prototype function


// ************************************************************************ 
// Fields Object
// ************************************************************************ 

function CreateFields(rsADO)
{
	if (typeof(rsADO) == 'object' && rsADO != null && rsADO.state != 0)
		return new _Fields(rsADO);
	return null;	
}

function _Fields(rsADO)
{	
	if (typeof(_bFSPrototypeCalled) == 'undefined')
		_FS__Prototype();

	this._rsFields = rsADO.Fields;
	this._reset(rsADO);
}

function _FS__Prototype()
{
	_Fields.prototype.getName = _FS_getName;
	_Fields.prototype.getValue = _FS_getValue;
	_Fields.prototype.setValue = _FS_setValue;
	_Fields.prototype.getCount = _FS_getCount;
	_Fields.prototype._reset = _FS__reset;
	_bFSPrototypeCalled = 1;
	//scope implementation to _FS__Prototype function

	function _FS_getName(nIndex)
	{
		if (typeof(nIndex) == 'number' && nIndex >= 0 && nIndex < this.getCount())
			return this._rsFields(nIndex).name;
		@if (@trace_warnings)
			thisPage._traceWarning('Err 431: Invalid argument or argument out of bounds. [nIndex =' + nIndex + ']','recordset.asp','Fields.getName(nIndex)');
		@end
		return '';
	}

	function _FS_getValue(field)
	{
		var r = '';
		if (!this._newRecord && this._isValid &&
			(typeof(field) == 'number' || typeof(field) == 'string'))
		{
			if (this._rsFields(field).value != null)
			{
				var fieldType = this._rsFields(field).type;
				//avoid JScript formating for the following field types:
				//adDate, adDBDate, adDBTime, adDBTimeStamp, adSingle
				if ((fieldType == 7) || (fieldType == 133) || (fieldType == 134) || (fieldType == 135) || (fieldType == 4))
					r = Server.HTMLEncode(this._rsFields(field));
				else
					r = this._rsFields(field).value;
			}	
		}
		@if (@trace_warnings)
			if (typeof(field) != 'number' && typeof(field) != 'string')
				thisPage._traceWarning('Err 432: Invalid argument. [field] must be a number or string.','recordset.asp','Fields.getValue(field)');
			else if (!this._isValid)
				thisPage._traceWarning('Err 404: Attempt to access fields when recordset is at BOF or EOF.','recordset.asp','Fields.getValue(field)');
		@end
		return r;
	}

	function _FS_setValue(field,value)
	{
		if ((typeof(field) == 'number' || typeof(field) == 'string') && typeof(value) != 'undefined')
		{	// validate field as updatable
			if (this._isValid)
			{
				var nAttributes = Number(this._rsFields(field).Attributes);
				if ((nAttributes & 4) || (nAttributes & 8))
				{	// field may be updated, adFldUpdatable=4, adFldUnknownUpdatable=8
					if (value == '' && (nAttributes & 32))
					{	// field is nullable, adFldIsNullable=32
						value = null;
					}
    				this._rsFields(field).value = value;
					return true;
				}
			}
			@if (@trace_warnings)
			else
				thisPage._traceWarning('Err 404: Attempt to access fields when recordset is at BOF or EOF.','recordset.asp','Fields.setValue(field,value)');
			@end
		}
		@if (@trace_warnings)
		else
			thisPage._traceWarning('Err 433: Invalid argument. [field] must be a number or string. [value] must match datatype of field.','recordset.asp','Fields.setValue(field,value)');
		@end
		return false;
	}

	function _FS_getCount()
	{
		if (typeof(this._rsFields) == 'object')
    		return this._rsFields.count;
		return 0;
	}
	
	function _FS__reset(rsADO)
	{
		this._isValid = !(rsADO.BOF || rsADO.EOF);
		this._newRecord = false;
	}
	
}	// end of _FS__Prototype function

</SCRIPT>

⌨️ 快捷键说明

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