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

📄 recordset.htm

📁 网上商城的设计与实现
💻 HTM
📖 第 1 页 / 共 2 页
字号:
// ************************************************************************<BR>
// Microsoft Script Library<BR>
// Visual InterDev 6.0 Recordset Object for DHTML<BR>
// Copyright 1998 Microsoft Corporation. All Rights Reserved.<BR>
// <B>Do not modify in design view. Switch to source view.</B><BR>
// ************************************************************************<BR>
// <SCRIPT>
function CreateRecordset(strName,funcInit,objParent)
{
	if (typeof(strName) != 'string' || strName == '')
		return null;

	var objRecordset = new _Recordset(strName);
	eval(strName + ' = objRecordset');

	var strSpan = '<' + 'SPAN id="' + strName + '_SPAN"></SPAN>';
	strSpan = strSpan + '<' + 'SPAN id="' + strName + '_SPAN_AUX" datasrc=#' + strName + '_RDS datafld=0 ></SPAN>';

	if ((typeof(objParent) == 'object') && (objParent != null))
		objParent.insertAdjacentHTML('BeforeEnd',strSpan);
	else
		document.write(strSpan);

	objRecordset._spanTag = document.all[strName + '_SPAN'];

	// always fire init for recordset
	_EM__fireEvent('_RS__onbeforefuncinit(' + objRecordset.id + ')');
	_EM__fireEvent(funcInit);
	return objRecordset;
}

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

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

	// private members
	this._rsRDS = null;
	this._rsADO = null;
	this._spanTag = null;
	this._count = -1;
	this._bookmark = 0;
	this._strConn = '';
	this._strSQL = '';
	this._bDelete = false;
	this._bDSChanged = false;
	this._bDSComplete = false;
	this._bCancelUpdate = false;
	this._bFiringOnBeforeUpdate = false;
	this._bFiringOnRowEnter = false;

	// advise for default eventhandlers
	this._objEventManager = CreateEventManager();
}

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.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.isDHTMLAware = _RS_isDHTMLAware;
	_Recordset.prototype.getDHTMLDataSourceID = _RS_getDHTMLDataSourceID;

	//events
	RS_ONBEFOREOPEN = 'onbeforeopen';
	RS_ONAFTEROPEN = 'onafteropen';
	RS_ONROWENTER = 'onrowenter';
	RS_ONROWEXIT = 'onrowexit';
	RS_ONDATASETCHANGED = 'ondatasetchanged';
	RS_ONDATASETCOMPLETE = 'ondatasetcomplete';
	RS_ONBEFOREUPDATE = 'onbeforeupdate';
	RS_ONAFTERUPDATE = 'onafterupdate';

	//private members 
	_Recordset.prototype._connect = _RS__connect;
	_Recordset.prototype._syncBOFandEOF = _RS__syncBOFandEOF;
	_Recordset.prototype._fireEvent = _RS__fireEvent;
	_Recordset.prototype._isEmpty = _RS__isEmpty;
	_bRSPrototypeCalled = 1;
}

function _RS__syncBOFandEOF()
{
	if (this._rsRDS != null)
	{
		if (this._bDelete)
		{
			//If the recordset becomes empty by deleting,
			//RDS won't set BOF and EOF.
			this._bDelete = false;
			var nCount = this._rsRDS.recordset.RecordCount;
			if (nCount <= 0)
			{
				this.BOF = true;
				this.EOF = true;
			}

			if (this.absolutePosition > nCount)
				this.absolutePosition = nCount;
		}
		else
		{
			this.BOF = false;
			this.EOF = false;
			this.absolutePosition = this._rsRDS.recordset.AbsolutePosition;
			if ((this.absolutePosition == -2) || (this.absolutePosition == -1))	// adPosBOF or adPosUnk
				this.BOF = true;
			if ((this.absolutePosition == -3) || (this.absolutePosition == -1))	// adPosEOF or adPosUnk
				this.EOF = true;
		}
	}
}

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

function _RS_moveNext(bReverse)
{
	if (!this._isEmpty())
	{
		if ((bReverse + '') == 'true')
		{
			this._rsRDS.recordset.MovePrevious();
			if (this.BOF)	return false;
		}
		else
		{
			this._rsRDS.recordset.MoveNext();
			if (this.EOF)	return false;
		}

		return true;
	}
	return false;
}

function _RS_movePrevious()
{	return this.moveNext(true);	}

function _RS_moveLast(bReverse)
{
	if (!this._isEmpty())
	{
		if ((bReverse + '') == 'true')
			this._rsRDS.recordset.MoveFirst();
		else
			this._rsRDS.recordset.MoveLast();

		return true;
	}
	return false;
}

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

function _RS_moveAbsolute(nIndex)
{
	if (typeof(nIndex) == 'number' && !this._isEmpty())
	{
		this._rsRDS.recordset.AbsolutePosition = nIndex;
		return true;
	}
	return false;
}

function _RS_move(nIndex)
{	// move relative to current record
	if (typeof(nIndex) == 'number' && !this._isEmpty())
	{
		this._rsRDS.recordset.Move(nIndex);
		return true;
	}
	return false;
}

function _RS_updateRecord()
{
	if (this.isOpen() && !this._bFiringOnBeforeUpdate)
	{
		this._bFiringOnBeforeUpdate = true;
		this._objEventManager.fireEvent(RS_ONBEFOREUPDATE);
		this._bFiringOnBeforeUpdate = false;
		if (!this._bCancelUpdate)
		{
			this._rsRDS.SubmitChanges();
			this._objEventManager.fireEvent(RS_ONAFTERUPDATE);
			return true;
		}
		this._bCancelUpdate = false;
	}
	return false;
}

function _RS_cancelUpdate()
{
	if (this.isOpen())
	{
		this._count = -1;
		this._bCancelUpdate = true;
		this._rsRDS.CancelUpdate();
		return true;
	}
	return false;
}

function _RS_addRecord()
{
	if (this.isOpen() && !this._bFiringOnBeforeUpdate)
	{
		if (this._count >= 0)
			++this._count;
		this._rsRDS.recordset.AddNew();
		return true;
	}
	return false;
}

function _RS_addImmediate(fieldList, fieldValues)
{
	if (this.isOpen() && !this._bFiringOnBeforeUpdate)
	{
		if (this._count >= 0)
			++this._count;
		this._rsRDS.recordset.AddNew(fieldList, fieldValues);
		this.updateRecord();
		return true;
	}
	return false;
}

function _RS_deleteRecord()
{
	if (!this._isEmpty())
	{
		if (this._count >= 0)
			--this._count;
		this._bDelete = true;
		this._rsRDS.recordset.Delete();
		this.updateRecord();
		return true;
	}
	return false;
}

function _RS_advise(strEvent,funcToCall)
{
	if (this.isOpen() &&
		((strEvent == RS_ONROWENTER && this._bDSChanged) ||
		 (strEvent == RS_ONDATASETCHANGED && this._bDSChanged) ||
		 (strEvent == RS_ONDATASETCOMPLETE && this._bDSComplete)))
	{
		this._fireEvent(funcToCall);
	}
	return this._objEventManager.advise(strEvent,funcToCall);
}

function _RS_unadvise(strEvent,nAdviseID)

⌨️ 快捷键说明

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