/******************************************************************************
* Class AccountPage :: AccountPage - Constructor for the account page         *
*                                                                             *
* Define yourself as an IMultiCellCanvas                                      *
* Create generic page buttons                                                 *
* Create generic page container buttons                                       *
* Create static text for the user ID                                          *
* Create static text for the node                                             *
* Create entryfield for the user ID                                           *
* Create entryfield for the node                                              *
* Define a null container pointer                                             *
* Define a null container object pointer                                      *
* Define a null container column pointer                                      *
* Define a null container column pointer                                      *
* Create an account data object given the key                                 *
* Create a empty account data object                                          *
* Set the key in your private data                                            *
* Set the isQuery in your private data                                        *
* Create the notebook page settings                                           *
* Create a select handler and later attach to the container                   *
******************************************************************************/
AccountPage::AccountPage(  IWindow* pParent,
                           const IString& aKey )
     :IMultiCellCanvas     ( ID_ACCOUNT_PAGE, pParent, pParent ),
      pageButtons          ( ID_ACCOUNT_PAGE_BUTTONS, this, this, false ),
      pageCnrButtons       ( ID_ACCOUNT_PAGE_CNRBUTTONS,
                             this, this, false ),
      userIdText           ( ID_NO_ITEM, this, this ),
      nodeSysText          ( ID_NO_ITEM, this, this ),
      userId               ( ID_ACC_USERID_EF, this, this,
                             IRectangle(),
                             IEntryField::classDefaultStyle
                             | IControl::tabStop),
      nodeSys              ( ID_ACC_NODESYS_EF, this, this,
                             IRectangle(),
                             IEntryField::classDefaultStyle
                             | IControl::tabStop ),
      pCnr                 ( (IContainerControl*) NULL ),
      pAcctCnrObj          ( (AcctCnrObj*) NULL ),
      pColUserID           ( (IContainerColumn*) NULL ),
      pColNodeSys          ( (IContainerColumn*) NULL ),
      acctData             ( aKey ),
      origAcctData         (),
      Key                  ( aKey ),
      isAquery             ( false ),
      thePageSettings      ( IApplication::current().userResourceLibrary().
                             loadString( STR_ACC_ACCOUNT_TAB ), NULL,
                             INotebook::PageSettings::autoPageSize
                             | INotebook::PageSettings::majorTab ),
      cnrSelHandler        ( this )

{
/*-----------------------------------------------------------------------------
| Save the account data to another object in case the user wishes to          |
|  undo any changes.                                                          |
| Label the static text objects.                                              |
| Set the limit for the entryfields.                                          |
-----------------------------------------------------------------------------*/
   origAcctData = acctData;
   userIdText.setText( STR_ACC_USERID );
   nodeSysText.setText( STR_ACC_NODESYS );
   userId.setLimit(  DISPLAY_LARGE );
   nodeSys.setLimit( DISPLAY_LARGE );

/*-----------------------------------------------------------------------------
| Fill the container from the database.                                       |
| Set the objects on yourself (IMultiCellCanvas).                             |
| Start handling the events.                                                  |
-----------------------------------------------------------------------------*/
   fillCnr();
   setCells();
   handleIt();
};
// Handle WinEvent coming from the server-window
void HandleDevice::handleWinEvent(MSG *m, long *result)
{
    LPBYTE lpb;
    UINT dwSize;
    RAWINPUT *raw;
    int msgType = m->message;

    if (msgType == WM_INPUT)
    {
        GetRawInputData((HRAWINPUT)m->lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
        lpb = (LPBYTE)malloc(sizeof(LPBYTE) * dwSize);

        if (lpb == NULL)
            printf("NULL\n");

        if (GetRawInputData((HRAWINPUT)m->lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
            printf("GetRawInputData doesn't return correct size !\n");

        raw = (RAWINPUT*)lpb;

        switch (raw->header.dwType)
        {
        case RIM_TYPEHID:
            handleIt(raw);
            break;

        case RIM_TYPEKEYBOARD:
            handleIt(raw);
            break;

        case RIM_TYPEMOUSE:
        default:
            break;
        }
    }
}
//*****************************************************************************
// CLASS GeneralPage - Contructor
//*****************************************************************************
GeneralPage :: GeneralPage(IWindow* pParent,
                           const IString empNum)
             : IMultiCellCanvas(ID_GENERAL_PAGE, pParent, pParent),
               employeeData(empNum ),
               pageButtons(ID_GENERAL_PAGE_BUTTONS,
                          this,this, false),
               employeeIdText  (ID_NO_ITEM, this, this ),
               lastNameText    (ID_NO_ITEM, this, this ),
               firstNameText   (ID_NO_ITEM, this, this ),
               middleNameText  (ID_NO_ITEM, this, this ),
               intPhoneText    (ID_NO_ITEM, this, this ),
               extPhoneText    (ID_NO_ITEM, this, this ),
               roomText        (ID_NO_ITEM, this, this ),
               deptText        (ID_NO_ITEM, this, this ),
               bldgText        (ID_NO_ITEM, this, this ),
               divText         (ID_NO_ITEM, this, this ),
               mgrEmpNumText   (ID_NO_ITEM, this, this ),
               mgrEmpNameText  (ID_NO_ITEM, this, this ),
               employeeId     (ID_GEN_EMPLOYEE_ID_EF   , this, this,
                              IRectangle(),
                              IEntryField::classDefaultStyle |
                              IControl::tabStop),
               lastName       (ID_GEN_LAST_NAME_EF     , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               firstName      (ID_GEN_FIRST_NAME_EF    , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               middleInitial  (ID_GEN_MIDDLE_INITIAL_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               intPhone       (ID_GEN_INT_PHONE_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               extPhone       (ID_GEN_EXT_PHONE_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               room           (ID_GEN_ROOM_EF     , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               building       (ID_GEN_BUILDING_EF , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               deptName       (ID_GEN_DEPT_EF     , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               division       (ID_GEN_DIVISION_EF , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               employeeType   (this),
               mgrEmpId       (ID_GEN_MGR_EMP_ID_EF, this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               mgrName        (ID_GEN_MGR_NAME_EF  , this, this,
                               IRectangle(),
                               IEntryField::classDefaultStyle |
                               IControl::tabStop),
               Key(empNum),
               thePageSettings( IApplication::current().userResourceLibrary().loadString(
                                STR_GEN_GENERAL_TAB), NULL,
                                INotebook::PageSettings::autoPageSize
                                | INotebook::PageSettings::majorTab ),
              isAquery(false)
{
   // set up the fields
   setUp();
   if ( employeeId.text().length() )
      employeeId.disableDataUpdate();

   // set up the page
   setCells();

   // populate the page from any database info
   displayData();
   handleIt();
}
//-*****************************************************************************
void ErrorHandler::operator()( ErrorHandler::UnknownExceptionFlag kFlag,
                               const std::string &iMsg )
{
    handleIt( iMsg + "\nERROR: UNKNOWN EXCEPTION\n" );
}
//-*****************************************************************************
void ErrorHandler::operator()( const std::string &iErr,
                               const std::string &iMsg )
{
    handleIt( ( iMsg + "\nERROR:\n" ) + iErr
              /*+ "\n" */ );
}
//-*****************************************************************************
void ErrorHandler::operator()( std::exception &iExc,
                               const std::string &iMsg )
{
    handleIt( ( iMsg + "\nERROR: EXCEPTION:\n" ) + iExc.what()
              /*+ "\n" + boost::diagnostic_information( iExc )*/ );
}