stop();
 
 
/*==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+
 
 |          flashPash recordset demo          |
 
 +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+
 
 |              version 1.0 *RC1*             |
 
 |                                            |
 
 | last update on 2003-07-07 by si*sshnug.com |
 
 |                                            |
 
 |   Copyright (c) 2002-2003, Simon Mckenna   |
 
 |            All rights reserved             |
 
 +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==+
 
 | source best viewed with tab space set to 2 |
 
 +==-==-==-==-==-==-==-==-==-==-==-==-==-==-==*/
 
 
/*
 
Tim Chungs's tkcDataGrid demo uses a recordset called 'rc'
 
 
"flashPash using recordset" demo code simply sits on top of his.
 
*/
 
 
var rootLocation  = 'http://flashpash.sshnug.com';
 
var rootLocation = 'http://localhost/flashPash/demo';
 
 
katsiConnection = new LocalConnection();
 
 
xml_format = flashPashXML_txt.getTextFormat();
 
log_format = flashPashLog_txt.getTextFormat();
 
xml_format.url = rootLocation + '/load.flashPash.log.php?logfile=log.recordset.demo.xml';
 
log_format.url = rootLocation + '/load.flashPash.log.php?logfile=log.recordset.demo.html';
 
xml_format.target = "_blank";
 
log_format.target = "_blank";
 
flashPashXML_txt.setTextFormat( xml_format );
 
flashPashLog_txt.setTextFormat( log_format );
 
 
globalStyleFormat.shadow      = 0x9DB9C8;
 
globalStyleFormat.darkshadow  = 0x558097;
 
globalStyleFormat.scrollTrack = 0xCEDCE3;
 
globalStyleFormat.highlight   = 0x9DB9C8;
 
globalStyleFormat.highlight3D = 0xCEDCE3;
 
globalStyleFormat.applyChanges();
 
 
doFlashPash_btn.useHandCursor     = true;
 
_level0.addItem_btn.useHandCursor = true;
 
_level0.doPrev_btn.useHandCursor  = true;
 
_level0.doNext_btn.useHandCursor  = true;
 
_level0.btnH.useHandCursor = true;
 
_level0.btnV.useHandCursor = true;
 
_level0.btnclrcellcolors.useHandCursor = true;
 
_level0.btnclrreccolors.useHandCursor  = true;
 
 
var metaCalled = false;
 
 
with ( flashPash_rs )
 
{
 
    setFlashPashURL( rootLocation + "/run.recordset.demo.php" );
 
 
    // define our flashPash recordset properties
 
    setField( "datagrid", "keyfield", flashPash_rs.FP_ADODB_CHARACTER );
 
    setField( "datagrid", "firstname", flashPash_rs.FP_ADODB_CHARACTER );
 
    setField( "datagrid", "lastname", flashPash_rs.FP_ADODB_CHARACTER );
 
    setField( "datagrid", "alias", flashPash_rs.FP_ADODB_CHARACTER );
 
    setField( "datagrid", "securitycode", flashPash_rs.FP_ADODB_CHARACTER );
 
    setField( "datagrid", "country", flashPash_rs.FP_ADODB_CHARACTER );
 
    setField( "datagrid", "pokes", flashPash_rs.FP_ADODB_INTEGER );
 
    setField( "datagrid", "booly", flashPash_rs.FP_ADODB_BOOLEAN );
 
    setKey( "datagrid", "keyfield" );
 
}
 
 
doFlashPash_click();
 
 
function doFlashPash_click()
 
{
 
        switch ( flashPash_grp.getValue() )
 
    {
 
        case 'doSelect' :
 
            if ( metaCalled )
 
                flashPash_rs.doMeta( flashPash_rs.FP_META_TYPE_SQL, "SELECT * FROM datagrid", true, false );
 
            else
 
                flashPash_rs.doSelect();
 
            break;
 
 
        case 'doInsert' :
 
            flashPash_rs.doInsert();
 
            break;
 
 
        case 'doUpdate' :
 
            flashPash_rs.doUpdate();
 
            break;
 
 
        case 'doDelete' :
 
            flashPash_rs.doDelete();
 
            break;
 
 
        case 'doSQL' :
 
            flashPash_rs.doSQL( "SELECT firstname, lastname FROM datagrid GROUP BY lastname" );
 
            break;
 
 
        case 'doMeta' :
 
            metaCalled = true;
 
            flashPash_rs.doMeta( flashPash_rs.FP_META_TYPE_SQL, "SELECT * FROM timeInfo", true, false );
 
            break;
 
    }
 
}
 
 
function fpRadioButton_click()
 
{
 
    doFlashPash_btn.setLabel( flashPash_grp.getValue() );
 
    switch ( flashPash_grp.getValue() )
 
    {
 
        case 'doSelect' :
 
            flashPash_label.text = 'Description: Retrieves information from database on server and then populates recordset associated with datagrid' + chr( 10 );
 
            flashPash_label.text += 'eg. flashPash_rs.doSelect();';
 
            break;
 
 
        case 'doInsert' :
 
            flashPash_label.text = 'Description: Generates an INSERT type SQL query based upon the current record\'s data' + chr( 10 );
 
            flashPash_label.text += 'eg. flashPash_rs.doInsert();';
 
            break;
 
 
        case 'doUpdate' :
 
            flashPash_label.text = 'Description: Generates an UPDATE type SQL query based upon the current record\'s data' + chr( 10 );
 
            flashPash_label.text += 'eg. flashPash_rs.doUpdate();';
 
            break;
 
 
        case 'doDelete' :
 
            flashPash_label.text = 'Description: Generates a DELETE type SQL query based upon the current record\'s key field(s)' + chr( 10 );
 
            flashPash_label.text += 'eg. flashPash_rs.doDelete();';
 
            break;
 
 
        case 'doSQL' :
 
            flashPash_label.text = 'Description: Generates an SQL query based upon doSQL parameter or flashPash SQLcondition property.' + chr( 10 );
 
            flashPash_label.text += 'eg. flashPash_rs.doSQL( "SELECT firstname, lastname FROM datagrid" );';
 
            break;
 
 
        case 'doMeta' :
 
            flashPash_label.text = 'Description: Retrieves meta-data from database. It is possible to retrieve databases, tables, fields and field meta-data' + chr( 10 );
 
            flashPash_label.text += 'eg. flashPash_rs.doMeta( flashPash_rs.FP_META_TYPE_SQL, "SELECT * FROM timeInfo", true, false );';
 
            break;
 
    }
 
}
 
 
function onDebug( fpObj, fpEvent, debugText )
 
{
 
    flashPash_log.text += debugText + chr( 10 );
 
    flashPash_log.scroll = flashPash_log.maxscroll;
 
}
 
 
function onStateChange( fpObj, fpEvent, oldState, newState, stateTimeTaken, bytesRead, bytesTotal )
 
{
 
    katsiConnection.send( 'katsi', 'event', fpEvent, oldState, newState );
 
    if ( oldState == newState )
 
    {
 
        if ( oldState == flashPash_rs.FP_STATE_LOADING )
 
        {
 
            flashPash_log.text += 'state update> ' + fpEvent + ' - loading ' + bytesRead;
 
            if ( bytesTotal == 0 )
 
                flashPash_log.text += ' bytes downloaded' + chr( 10 );
 
            else
 
                flashPash_log.text += ' out of ' + bytesTotal + ' bytes' + chr( 10 );
 
        }
 
        else if ( oldState == flashPash_rs.FP_STATE_WAITING )
 
        {
 
            flashPash_log.text += 'state update> waiting - ' + flashPash_rs.time2string( stateTimeTaken ) + ' elapsed ' + chr( 10 );
 
        }
 
    }
 
    else
 
    {
 
        switch ( oldState )
 
        {
 
            case flashPash_rs.FP_STATE_SLEEPING : var oldText = 'sleeping'; break;
 
            case flashPash_rs.FP_STATE_WORKING  : var oldText = 'working';  break;
 
            case flashPash_rs.FP_STATE_WAITING  : var oldText = 'waiting';  break;
 
            case flashPash_rs.FP_STATE_LOADING  : var oldText = 'loading';  break;
 
            case flashPash_rs.FP_STATE_UPDATING : var oldText = 'updating'; break;
 
        }
 
        switch ( newState )
 
        {
 
            case flashPash_rs.FP_STATE_SLEEPING : var newText = 'sleeping again';break;
 
            case flashPash_rs.FP_STATE_WORKING  : var newText = 'working';  break;
 
            case flashPash_rs.FP_STATE_WAITING  : var newText = 'waiting';  break;
 
            case flashPash_rs.FP_STATE_LOADING  : var newText = 'loading';  break;
 
            case flashPash_rs.FP_STATE_UPDATING : var newText = 'updating'; break;
 
        }
 
 
        flashPash_log.text += 'state change> from ' + oldText + ' to ' + newText + chr( 10 );
 
    }
 
    flashPash_log.scroll = flashPash_log.maxscroll;
 
}
 
 
function beforeEvent( fpObj, fpEvent )
 
{
 
    processing.startWaiting();
 
    
 
    flashPash_log.text = '';
 
    flashPash_log.text = 'event> ' + fpEvent + chr( 10 );
 
    
 
    if (( fpEvent == 'beforeUpdate' ) || ( fpEvent == 'beforeInsert' ) || ( fpEvent == 'beforeDelete' ))
 
    {
 
        if ( mmRecordSet.flashPash.currentIndex < 0 )
 
        {
 
            flashPash_log.text += 'demo> hang on!  you need to have a record selected in the grid, aborting...' + chr( 10 );
 
            flashPash_log.scroll = flashPash_log.maxscroll;
 
            return false;
 
        }
 
    
 
        /* Ensure data is entered for both firstname and lastname */
 
        var mmRecordSet = fpObj.getDataSource();
 
        var rsColumns   = mmRecordSet.getColumnNames();
 
 
        for ( var i = 0; i < rsColumns.length; i++ )
 
        {
 
            fieldName = rsColumns[ i ];
 
            fieldValue  = mmRecordSet.getItemAt( mmRecordSet.flashPash.currentIndex )[ fieldName ];
 
            if (( fieldName == 'firstname' ) || ( fieldName == 'lastname' ))
 
                if ( fieldValue.length == 0 )
 
                {
 
                    flashPash_log.text += 'demo> hang on!  firstname and lastname should values entered, aborting...' + chr( 10 );
 
                    flashPash_log.scroll = flashPash_log.maxscroll;
 
                    return false;
 
                }
 
        }
 
        if (( fpEvent == 'beforeDelete' ) && ( fpObj.getDataSource().getLength() <= 1 ))
 
        {
 
            flashPash_log.text += 'demo> hang on!  at least one record should be left in the table for others, aborting...' + chr( 10 );
 
            flashPash_log.scroll = flashPash_log.maxscroll;
 
            return false;
 
        }
 
    }
 
    else if ( fpEvent == 'beforeSelect' )
 
    {
 
        var mmRecordSet = eval( fpObj.dataSource );
 
        mmRecordSet.removeAll();
 
        _level0.datagrid_users.refresh();
 
    }
 
}
 
 
function afterEvent( fpObj, fpEvent, recordCount, fpXMLresult )
 
{
 
    processing.stopWaiting();
 
 
    flashPash_log.text += 'event> ' + fpEvent + '  recordCount: ' + recordCount + chr( 10 );
 
    flashPash_log.scroll = flashPash_log.maxscroll;
 
    katsiConnection.send( 'katsi', 'event', fpEvent, recordCount );
 
    switch ( fpEvent )
 
    {
 
            case 'afterSelect' :
 
                break;
 
            case 'afterDelete' :
 
            if (( flashPash_rs.error == flashPash_rs.FP_ERROR_NONE ) && ( recordCount == 1 ))
 
            {
 
                var mmRecordSet = eval( flashPash_rs.dataSource );
 
                mmRecordSet.removeItemAt( mmRecordSet.flashPash.currentIndex );
 
            }
 
            break;
 
        case 'afterMeta' :
 
            _level0.datagrid_users.setRecordSet( _global.rc );
 
            flashPash_rs.doSelect();
 
            break;
 
    }
 
    _level0.datagrid_users.setRecordsToDisplay( 8 );
 
    _level0.datagrid_users.refresh();
 
}
 
 
function onError( fpObj, fpEvent, error, errorText )
 
{
 
    processing.stopWaiting();
 
 
    flashPash_log.text += 'error> ' + fpEvent + '  error ' + error + ' - ' + errorText + chr( 10 );
 
    flashPash_log.scroll = flashPash_log.maxscroll;
 
    katsiConnection.send( 'katsi', 'event', fpEvent );
 
}
 
 
/* routine to generate a unique ID.  Curtesy of Kent :: Pure Vanilla. */
 
function genid()
 
{
 
    var _st = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
 
    var id  = '';
 
    for ( i = 0; i < 12; i++ )
 
    {
 
        sl = Math.floor( math.random() * 64 );
 
        id += _st.slice( sl, sl + 1 );
 
    }
 
    return id;
 
}
 
 
 |