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

📄 dbmsexampleappui.cpp

📁 SymbianOS的DBMS实例 详细的代码揭示SymbianOS数据库管理系统的使用 很规范
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CDBMSexampleAppUi from DBMSexampleAppUi.h
*  Part of  : DBMSexample
*  Created  : 02/28/2003 by Forum Nokia
*  Implementation notes:
*  Version  :
*  Copyright: Nokia Corporation, 2003
* ============================================================================
*/

// INCLUDE FILES
#include "DBMSexampleAppUi.h"
#include "DBMSengine.h"
#include <DBMSexample.rsg>
#include "dbmsexample.hrh"
#include <aknquerydialog.h>

#include <avkon.hrh>
#include <akntitle.h>
#include <e32std.h>
#include <eikmenup.h>

#include "DBMSexampleContainer.h"

/*
-----------------------------------------------------------------------------

    CDBMSexampleAppUi::ConstructL()

	Description: Second-phase constructor
	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleAppUi::ConstructL()
    {
    BaseConstructL();

	// Create a container here
    iAppContainer = new (ELeave) CDBMSexampleContainer;

    iAppContainer->SetMopParent(this);
    iAppContainer->ConstructL( ClientRect() );
    AddToStackL( iAppContainer );	
	
	iIsDatabaseCreated = iAppContainer->GetEngine()->IsDatabaseCreatedL();
    }

/*
-----------------------------------------------------------------------------

    CDBMSexampleAppUi::~CDBMSexampleAppUi()

	Description: Destructor, free reserved resources
	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
CDBMSexampleAppUi::~CDBMSexampleAppUi()
    {
    if (iAppContainer)
        {
        RemoveFromStack( iAppContainer );
        delete iAppContainer;
        }
   }


/*
-----------------------------------------------------------------------------

    CDBMSexampleAppUi::::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)

	Description: This function is called by the EIKON framework just before it displays
				 a menu pane. Its default implementation is empty, and by overriding it,
				 the application can set the state of menu items dynamically according
				 to the state of application data.
	Comments:
    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleAppUi::DynInitMenuPaneL(
    TInt aResourceId, CEikMenuPane* aMenuPane )
    {
    if ( aResourceId == R_DBMSEXAMPLE_MENU )
		{
		// Check whether the database has been created or not
		if ( !iIsDatabaseCreated )
			{
			aMenuPane->SetItemDimmed( EDBMSexampleCmdCreateRecord, ETrue );
			aMenuPane->SetItemDimmed( EDBMSexampleCmdDeleteRecord, ETrue );
			aMenuPane->SetItemDimmed( EDBMSexampleCmdUpdateRecord, ETrue ); 			
			aMenuPane->SetItemDimmed( EDBMSexampleCmdRetrieveRecord, ETrue ); 			
			}
		else if ( !iAppContainer->IsListBoxConstructed() )
			{
			aMenuPane->SetItemDimmed( EDBMSexampleCmdDeleteRecord, ETrue );
			aMenuPane->SetItemDimmed( EDBMSexampleCmdUpdateRecord, ETrue ); 			
			aMenuPane->SetItemDimmed( EDBMSexampleCmdRetrieveRecord, ETrue );
			}
		}
    }

/*
-----------------------------------------------------------------------------

	CDBMSexampleAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)

	Description: Handle key events
	Comments:

    Return values: whether key is processed or not

-----------------------------------------------------------------------------
*/
TKeyResponse CDBMSexampleAppUi::HandleKeyEventL(
    const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
    {
    return EKeyWasNotConsumed;
    }


/*
-----------------------------------------------------------------------------

    CDBMSexampleAppUi::HandleCommandL(TInt aCommand)

	Description: Handle menu commands etc
	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleAppUi::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
        {
        case EEikCmdExit:
		case EAknSoftkeyExit:
		case EAknSoftkeyBack:
            {
            Exit();
            break;
            }

		case EDBMSexampleCmdCreateRecord:
			// Create a new record, however, the name and id field should not conflict
			// with the ones in any previous records in database.
	        iAppContainer->DisplayFormL( R_MANAGE_DATABASE_DIALOG, EDBMSexampleCmdCreateRecord, this );
			SetAppTitleTextL( R_CREATE_RECORD );
			break;

		case EDBMSexampleCmdDeleteRecord:
			{
			// Delete the current record at the current index in the list.
	        iAppContainer->DisplayFormL( R_MANAGE_DATABASE_DIALOG, EDBMSexampleCmdDeleteRecord, this ); 
			SetAppTitleTextL( R_DELETE_RECORD );
			break;
			}

		case EDBMSexampleCmdUpdateRecord:
			{
			// Get the current index and the contents.
	        iAppContainer->DisplayFormL( R_MANAGE_DATABASE_DIALOG, EDBMSexampleCmdUpdateRecord, this );
			SetAppTitleTextL( R_UPDATE_RECORD );
			break;
			}

		case EDBMSexampleCmdCreateDatabase:
			// Create a new database. If a previous named database has existed, it could be
			// overwritten if a user chooses so.
			iAppContainer->GetEngine()->CreateL();
			iIsDatabaseCreated = ETrue;
			iAppContainer->ClearContentsInListBox();
			UpdateViewL();
			break;

		case EDBMSexampleCmdRetrieveRecord:
			// Retrieve a record from database at the current index in the listbox.
	        iAppContainer->DisplayFormL( R_MANAGE_DATABASE_DIALOG, EDBMSexampleCmdRetrieveRecord, this );
			SetAppTitleTextL( R_RECORD_INFO_TEXT );
			break;

        case EDBMSexampleCmdAppTest:
            {
            break;
            }
        default:
            break;      
        }
    }

/*
-----------------------------------------------------------------------------

    CDBMSexampleAppUi::SetAppTitleTextL(TInt aResourceId)

	Description: Changes the application title text
	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleAppUi::SetAppTitleTextL(TInt aResourceId)
{
	CAknTitlePane* titlePane = STATIC_CAST( CAknTitlePane*,
    StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );

	// Read the resource and display it.
    TBuf<256> titleText( NULL );
    iEikonEnv->ReadResource( titleText, aResourceId );
    titlePane->SetTextL( titleText );
}

/*
-----------------------------------------------------------------------------

    CDBMSexampleAppUi::UpdateView()

	Description: callback function to update the list if there is change in its
				 contents.
	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleAppUi::UpdateViewL()
{
	if( iAppContainer )
		{
		// Reflect the new changes into listbox.
		iAppContainer->DisplayRecordsL();
		}
}

⌨️ 快捷键说明

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