?? recordset.asp
字號:
<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 == '')
{
@if (@trace_warnings)
thisPage._traceWarning('Err 428: Invalid argument [strName]. Must provide a valid string.','recordset.asp','CreateRecordset(strName)');
@end
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;
@if (@debug)
_Recordset.prototype._reportError = _RS__reportError;
@end
//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 (@trace_warnings)
var funcName = ((nDirection < 0) ? '.movePrevious()' : '.moveNext()');
@end
if (!this._isEmpty())
{
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
this._rsADO.Move(nDirection);
this._syncBOFandEOF();
this.fields._reset(this._rsADO);
if (this.EOF || this.BOF)
{
return false;
}
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
thisPage._traceWarning('Err 414: Cannot move a closed or empty recordset.','recordset.asp',this.name + funcName);
@end
return false;
}
function _RS_movePrevious()
{
return this.moveNext(-1);
}
function _RS_moveLast(bReverse)
{
if (!this._isEmpty())
{
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
if ((bReverse + '') == 'true')
this._rsADO.MoveFirst();
else
this._rsADO.MoveLast();
this._syncBOFandEOF();
this.fields._reset(this._rsADO);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
var funcName = (((bReverse + '') == 'true') ? '.moveFirst()' : '.moveLast()');
thisPage._traceWarning('Err 414: Cannot move a closed or empty recordset.','recordset.asp',this.name + funcName);
@end
return false;
}
function _RS_moveFirst()
{
return this.moveLast(true);
}
function _RS_moveAbsolute(nIndex)
{
if (!this._isEmpty() && typeof(nIndex) == 'number')
{
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
this._rsADO.AbsolutePosition = nIndex;
this._syncBOFandEOF();
this.fields._reset(this._rsADO);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
if (typeof(nIndex) != 'number')
thisPage._traceWarning('Err 421: Invalid argument [nIndex = ' + nIndex + ']. Must be a number.','recordset.asp',this.name + '.moveAbsolute(nIndex)');
else
thisPage._traceWarning('Err 414: Cannot move a closed or empty recordset.','recordset.asp',this.name + '.moveAbsolute(nIndex)');
@end
return false;
}
function _RS_move(nIndex)
{
// move relative to current record
if (!this._isEmpty() && typeof(nIndex) == 'number')
{
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
this._rsADO.Move(nIndex);
this._syncBOFandEOF();
this.fields._reset(this._rsADO);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
if (typeof(nIndex) != 'number')
thisPage._traceWarning('Err 421: Invalid argument [nIndex = ' + nIndex + ']. Must be a number.','recordset.asp',this.name + '.move(nIndex)');
else
thisPage._traceWarning('Err 414: Cannot move a closed or empty recordset.','recordset.asp',this.name + '.move(nIndex)');
@end
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;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONBEFOREUPDATE);
@end
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;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONAFTERUPDATE);
@end
this._objEventManager.fireEvent(RS_ONAFTERUPDATE);
return true;
}
else
this._bCancelUpdate = false;
}
@if (@trace_warnings)
if (this._isEmpty())
thisPage._traceWarning('Err 416: Cannot update a closed or empty recordset.','recordset.asp',this.name + '.updateRecord()');
else if (this._rsADO.LockType == 1)
thisPage._traceWarning('Err 417: Cannot update a read-only recordset.','recordset.asp',this.name + '.updateRecord()');
else if (this._bFiringOnBeforeUpdate == true)
thisPage._traceWarning('Err 407: Calling updateRecord is not allowed during the onbeforeupdate event.','recordset.asp',this.name + '.updateRecord()');
@end
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;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
if (this._isEmpty())
thisPage._traceWarning('Err 410: Cannot cancel update of a closed or empty recordset.','recordset.asp',this.name + '.cancelUpdate()');
else if (this._rsADO.LockType == 1)
thisPage._traceWarning('Err 411: Cannot cancel update of a read-only recordset.','recordset.asp',this.name + '.cancelUpdate()');
@end
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;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
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;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
if (!this.isOpen())
thisPage._traceWarning('Err 408: Cannot add a new record to a closed recordset.','recordset.asp',this.name + '.addRecord()');
else if (this._rsADO.LockType == 1)
thisPage._traceWarning('Err 409: Cannot add a new record to a read-only recordset.','recordset.asp',this.name + '.addRecord()');
else if (this._bFiringOnBeforeUpdate == true)
thisPage._traceWarning('Err 406: Calling addRecord is not allowed during the onbeforeupdate event.','recordset.asp',this.name + '.addRecord()');
@end
return false;
}
function _RS_addImmediate(fieldList, fieldValues)
{
if (this._allowUpdate && this.isOpen() && !this._bFiringOnBeforeUpdate)
{
this._bAddNewImmediate = false;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -