Пример #1
0
void CMsgSignalDBWnd::OnClose()
{
    // Get active frame
    CMainFrame* pFrame =
        static_cast<CMainFrame*> (AfxGetApp()->m_pMainWnd);

    if (pFrame != NULL)
    {
        // Get appropriate data structure
        CMsgSignal** ppTempMsgSg = NULL;
        ppTempMsgSg = (CMsgSignal**)(m_sDbParams.m_ppvActiveDB);
        //CMsgSgDetView* podMsgSg =
        pFrame->podGetMsgSgDetView(m_sDbParams.m_eBus);

        if ((*ppTempMsgSg)->bGetModifiedFlag() == FALSE)
        {
            UINT bRetVal =  AfxMessageBox(ASK_SAVE_PROMPT,
                                          MB_YESNO|MB_ICONQUESTION);

            if ( bRetVal == IDYES )
            {
                (*ppTempMsgSg)->
                bWriteIntoDatabaseFileFromDataStructure(
                    m_sDbParams.m_omDBPath );

                if ((*ppTempMsgSg)->bGetDBAcitveFlagStatus() == TRUE)
                {
                    pFrame->vPostMsgToSendMsgDlg(m_sDbParams.m_eBus);
                }

                // Check if the modified file is being loaded or not.
                //If yes then prompt the user whether he wants to
                //import it or not.
                CStringArray omImportedDBNames;
                CMsgSignal** m_ppsMSTemp = (CMsgSignal**)(m_sDbParams.m_ppvImportedDBs);

                if ((*m_ppsMSTemp) != NULL)
                {
                    (*m_ppsMSTemp)->vGetDataBaseNames(&omImportedDBNames);

                    for (INT nDBCount = 0; nDBCount < omImportedDBNames.GetSize();
                            nDBCount++)
                    {
                        if (m_sDbParams.m_omDBPath ==
                                omImportedDBNames.GetAt(nDBCount))
                        {
                            CString omText;
                            omText.Format( _T("File  \"%s\"  has been modified which is currently being loaded.\nDo you want to re-import it to reflect the changes?"),
                                           m_sDbParams.m_omDBPath);

                            if (MessageBox(omText, "", MB_ICONQUESTION | MB_YESNO) == IDYES)
                            {
                                switch (m_sDbParams.m_eBus)
                                {
                                    case CAN:
                                    {
                                        pFrame->dLoadDataBaseFile(m_sDbParams.m_omDBPath, FALSE);
                                    }
                                    break;

                                    case J1939:
                                    {
                                        pFrame->dLoadJ1939DBFile(m_sDbParams.m_omDBPath, FALSE);
                                    }
                                    break;
                                };
                            }
                        }
                    }
                }

                //Checking ends

                // Set the modified flag as saved
                if (NULL != (*ppTempMsgSg))
                {
                    (*ppTempMsgSg)->vSetModifiedFlag(TRUE);
                }
            }
            else if( bRetVal == IDNO )
            {
                // if this is new database
                // then delete the memory and the file itself
                if ( pFrame->vGetNewDatabaseFlag())
                {
                    // This file is no longer required
                    CFile::Remove( m_sDbParams.m_omDBPath );
                    pFrame->vSetNewDatabaseFlag(FALSE);
                }
            }
        }
        else
        {
            // If the user just creates new database,
            // and closes the window
            // delete the file
            if ( pFrame->vGetNewDatabaseFlag() )
            {
                // This file is no longer required
                CFile::Remove( m_sDbParams.m_omDBPath );
                pFrame->vSetNewDatabaseFlag(FALSE);
            }
        }

        // delete previously allocated memory if any
        (*ppTempMsgSg)->bDeAllocateMemoryInactive();

        // Reset the flag to indicate the closing of database window
        if (m_sDbParams.m_eBus == CAN)
        {
            CFlags* pFlags = theApp.pouGetFlagsPtr();

            if ( pFlags != NULL )
            {
                pFlags->vSetFlagStatus( DBOPEN, FALSE );
            }
        }
        else if (m_sDbParams.m_eBus == J1939)
        {
            CMsgSignalDBWnd::sm_bValidJ1939Wnd = FALSE;
        }

        CMDIChildWnd::OnClose();
    }
}
Пример #2
0
void CMsgSignalDBWnd::OnClose() 
{
    // Get active frame
    CMainFrame *pFrame = 
                (CMainFrame*)AfxGetApp()->m_pMainWnd;
    
    if (pFrame != NULL)
    {
        // Get appropriate data structure
        CMsgSignal** ppTempMsgSg = NULL;

        ppTempMsgSg = (CMsgSignal**)(m_sDbParams.m_ppvActiveDB);
        
        //CMsgSgDetView* podMsgSg = 
        pFrame->podGetMsgSgDetView(m_sDbParams.m_eBus);

        if ((*ppTempMsgSg)->bGetModifiedFlag() == FALSE)
        {
            UINT bRetVal =  AfxMessageBox(ASK_SAVE_PROMPT,
                                    MB_YESNO|MB_ICONQUESTION);
            if ( bRetVal == IDYES )
            {
                //save the database modificatins.
				vSaveModifiedDBs(ppTempMsgSg);
            }
            else if( bRetVal == IDNO )
            {
                // if this is new database
                // then delete the memory and the file itself
                if ( pFrame->vGetNewDatabaseFlag())
                {
                    // This file is no longer required
                    CFile::Remove( m_sDbParams.m_omDBPath );
                    pFrame->vSetNewDatabaseFlag(FALSE);
                }
            }

        }
        else
        {
            // If the user just creates new database,
            // and closes the window
            // delete the file
            if ( pFrame->vGetNewDatabaseFlag() )
            {
                // This file is no longer required
                CFile::Remove( m_sDbParams.m_omDBPath );
                pFrame->vSetNewDatabaseFlag(FALSE);
            }

        }

         // delete previously allocated memory if any
         (*ppTempMsgSg)->bDeAllocateMemoryInactive();

        // Reset the flag to indicate the closing of database window
        if (m_sDbParams.m_eBus == CAN)
        {
            CFlags* pFlags = theApp.pouGetFlagsPtr();
            if ( pFlags != NULL )
            {
                pFlags->vSetFlagStatus( DBOPEN, FALSE );
            }
        }
        else if (m_sDbParams.m_eBus == J1939)
        {
            CMsgSignalDBWnd::sm_bValidJ1939Wnd = FALSE;
        }
        CMDIChildWnd::OnClose();
    }
}