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

📄 dbmsexampleform.cpp

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

#include <eikcapc.h>
#include "DBMSexampleForm.h"
#include <aknquerydialog.h>
#include <DBMSexample.rsg>
#include <eikmenup.h>
#include "DBMSobserver.h"
#include "DBMSengine.h"
#include "DBMSexampleAppUi.h"

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

	CDBMSexampleForm* CDBMSexampleForm::NewL( TInt aType, CDBMSengine *aEngine, 
					MDBMSobserver *aObserver )

	Description: two-phased constructor

	Comments:

    Return values: created form obj pointer

-----------------------------------------------------------------------------
*/
CDBMSexampleForm* CDBMSexampleForm::NewL( TInt aType, CDBMSengine *aEngine, MDBMSobserver *aObserver )
    {
    CDBMSexampleForm* self = 
        new (ELeave) CDBMSexampleForm( aType, aEngine, aObserver );
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop();
    return self;
    }


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

	CDBMSexampleForm::~CDBMSexampleForm()

	Description: destructor

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
CDBMSexampleForm::~CDBMSexampleForm()
    {
    DiscardArrays();
    }


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

	CDBMSexampleForm::CDBMSexampleForm()

	Description: constructor

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
CDBMSexampleForm::CDBMSexampleForm( TInt aType, CDBMSengine *aEngine, 
									MDBMSobserver *aObserver ) : 
	iType ( aType ), iEngine( aEngine ), iObserver( aObserver)
    {
	iTextArray = NULL;
    iValueTextArray = NULL;
    iTextValues[ 0 ] = NULL;
	iSex = 0;
    }

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

	CDBMSexampleForm::ConstructL()

	Description: second-phase constructor

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleForm::ConstructL()
    {
    CAknForm::ConstructL();
    }


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

	CDBMSexampleForm::ExecuteLD( TInt aResourceId )

	Description: launches the form

	Comments:

    Return values: 

-----------------------------------------------------------------------------
*/
TInt CDBMSexampleForm::ExecuteLD( TInt aResourceId )
    {
    iCurrentId = aResourceId;

    return CAknForm::ExecuteLD( aResourceId );
    }


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

	CDBMSexampleForm::PrepareLC( TInt aResourceId )

	Description:

	Comments:

    Return values: 

-----------------------------------------------------------------------------
*/
void CDBMSexampleForm::PrepareLC( TInt aResourceId )
    {
    iCurrentId = aResourceId;

    CAknForm::PrepareLC( aResourceId );
    }

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

	CDBMSexampleForm::SaveFormDataL()

	Description: Save form data

	Comments:

    Return values: ETrue if the operation is successful, otherwise, EFalse.

-----------------------------------------------------------------------------
*/
TBool CDBMSexampleForm::SaveFormDataL()
    {

	// This function is used to save the form data into its variables.
	if ( ControlOrNull( EAknFormDlgCtrlIdEdwin_Name ) )
		{
        GetEdwinText(iEdwinName, EAknFormDlgCtrlIdEdwin_Name );
		}
	if ( ControlOrNull( EAknFormDlgCtrlIdEdwin_Sex ) )
		{
        GetEdwinText(iEdwinSex, EAknFormDlgCtrlIdEdwin_Sex );
		}
	if ( ControlOrNull( EAknFormDlgCtrlIdDate_Birth ) )
		{
        iDateBirth = TTimeEditorValue( EAknFormDlgCtrlIdDate_Birth );
		}
	if ( ControlOrNull( EAknFormDlgCtrlIdNumber_Id ) )
		{
        iNumberId = NumberEditorValue(EAknFormDlgCtrlIdNumber_Id);
		}
	if( ControlOrNull( EAknPopFieldDlgCtrlIdText_Sex ) )
        {
        iSex = iTextValues[ 0 ]->CurrentValueIndex();
        }

    return ETrue;
    }

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

	CDBMSexampleForm::DoNotSaveFormDataL()

	Description: Does not save form data.

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleForm::DoNotSaveFormDataL()
    {
	
	// This function is used to save the form data into its variables.
	if ( ControlOrNull( EAknFormDlgCtrlIdEdwin_Name ) )
		{
        SetEdwinTextL( EAknFormDlgCtrlIdEdwin_Name, &iEdwinName );
		}
	if ( ControlOrNull( EAknFormDlgCtrlIdEdwin_Sex ) )
		{
        SetEdwinTextL( EAknFormDlgCtrlIdEdwin_Sex, &iEdwinSex );
		}
	if ( ControlOrNull( EAknFormDlgCtrlIdDate_Birth ) )
		{
        SetTTimeEditorValue(EAknFormDlgCtrlIdDate_Birth, iDateBirth);
		}
	if ( ControlOrNull( EAknFormDlgCtrlIdNumber_Id ) )
		{
        SetNumberEditorValue(EAknFormDlgCtrlIdNumber_Id, iNumberId);
		}
    }

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

	CDBMSexampleForm::PostLayoutDynInitL()

	Description: Set default field value to member data.

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleForm::PostLayoutDynInitL()
    {
    CAknForm::PostLayoutDynInitL();
	DoNotSaveFormDataL();
    ConfigurePopfieldValueL();
	if ( iType == EDBMSexampleCmdUpdateRecord || iType == EDBMSexampleCmdCreateRecord )
		SetEditableL( ETrue );
	else
		SetEditableL( EFalse );
	}

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

	CDBMSexampleForm::QuerySaveChangesL()

	Description: Show save query. If user answers "No" to this query.
				 return field value to the value which is before editing.
				 This is called Back-softkey when edit mode.
	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
TBool CDBMSexampleForm::QuerySaveChangesL()
    {
    TBool isAnsYes(CAknForm::QuerySaveChangesL());

    if (isAnsYes)
        {
        SaveFormDataL();
        }
    else 
        {
        // Case that answer "No" to query.
        DoNotSaveFormDataL();
        }

    return isAnsYes;
    }

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

	CDBMSexampleForm::OkToExitL( TInt aButtonId )

	Description: 

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
TBool CDBMSexampleForm::OkToExitL( TInt aButtonId )
    {	
	switch ( aButtonId )
		{
		case EDBMSexampleCmdSaveRecord:
			SaveFormDataL();
			CreateRecordL( );			
			break;

		case EDBMSexampleCmdChangeRecord:
			SaveFormDataL();
			UpdateRecordL( );
			break;

		case EDBMSexampleCmdRemoveRecord:
			{
			CAknQueryDialog* dlg = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);

			dlg->PrepareLC( R_CONFIRMATION_QUERY_DELETE );
			if ( dlg->RunLD() )
				{
				// If the answer is yes, delete the record, and go ahead.
				DeleteRecordL( );			
				}
			break;
			}

		case EAknSoftkeyCancel:
			break;
		}
	
	// Change back application title
	STATIC_CAST(CDBMSexampleAppUi*, iAvkonAppUi)->SetAppTitleTextL( R_APPLICATION_NAME_TEXT );

	// Update the view and destroy the form.
	iObserver->UpdateViewL();
	return ETrue;
	}

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

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

	Description: Dynamically changes the menu item state

	Comments:

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CDBMSexampleForm::DynInitMenuPaneL( TInt /* aResourceId */, 
     CEikMenuPane* /* aMenuPane */ )
{
}

⌨️ 快捷键说明

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