void CValueDescriptionDlg::OnClickedOk()
{
    UpdateData(TRUE);
    BOOL bRetValue = TRUE;
    // Validate data
    if ( m_omStrValueDescriptor.IsEmpty() == TRUE )
    {
        AfxMessageBox("Signal Description cannot be emtpy!",MB_OK);
        GetDlgItem(IDC_EDIT_VALUE_DESC)->SetFocus();
        bRetValue = FALSE;
    }

    if ( bRetValue == TRUE)
    {
        if ( m_omStrValue.IsEmpty() == TRUE )
        {
            AfxMessageBox("Signal value cannot be emtpy!",MB_OK);
            GetDlgItem(IDC_EDIT_VAL)->SetFocus();
            bRetValue = FALSE;
        }

        if ( bRetValue == TRUE )
        {
            // Get appropriate msg structure ptr
            CMsgSignal* pTempMsgSg = NULL;
            pTempMsgSg = *((CMsgSignal**)(m_sDbParams.m_ppvActiveDB));

            if ( pTempMsgSg != NULL )
            {
                // Check if description is duplicate
                if ( m_omStrPrevDesc != m_omStrValueDescriptor )
                {
                    if(pTempMsgSg->bIsDuplicateValueDescription(m_omStrMessageCode,
                            m_omStrSgName,
                            m_omStrValue,
                            m_omStrValueDescriptor,
                            m_nIndex,
                            m_bMode))
                    {
                        AfxMessageBox("Signal Descriptor already exists!",MB_OK);
                        GetDlgItem(IDC_EDIT_VALUE_DESC)->SetFocus();
                        bRetValue = FALSE;
                    }
                }

                // Check if signal value is duplicate
                if ( bRetValue == TRUE )
                {
                    if ( m_omStrPrevSignalVal  != m_omStrValue )
                    {
                        if ( pTempMsgSg->bIsDuplicateSignalValue(m_omStrMessageCode,
                                m_omStrSgName,
                                m_omStrValue,
                                m_omStrValueDescriptor,
                                m_nIndex,
                                m_bMode))
                        {
                            AfxMessageBox("Signal Value already exists!", MB_OK);
                            GetDlgItem(IDC_EDIT_VAL )->SetFocus();
                            bRetValue = FALSE;
                        }
                    }
                }

                // Check if the signal value is within the range
                if ( bRetValue == TRUE )
                {
                    if (pTempMsgSg->bIsSignalValueOutofRange(m_omStrMessageCode,
                            m_omStrSgName,
                            m_omStrValue ))
                    {
                        AfxMessageBox( MSG_SG_VAL_OUT_OF_RANGE, MB_OK);
                        GetDlgItem(IDC_EDIT_VAL )->SetFocus();
                        bRetValue = FALSE;
                    }

                    if ( bRetValue == TRUE )
                    {
                        // Update the desc into the data structure
                        CSignalDescVal* pNew = new CSignalDescVal;
                        CMainFrame* pMainFrame =
                            static_cast<CMainFrame*> (AfxGetApp()->m_pMainWnd);

                        if ( pNew       != NULL &&
                                pMainFrame != NULL)
                        {
                            CString omStrPrevDesc = STR_EMPTY;
                            if ( MD_ADD == m_bMode )
                            {
                                // new desc and val hence allocate memory
                                pTempMsgSg->bAddSgDescVal( m_omStrMessageCode,
                                                           m_omStrSgName );
                            }
                            // convert string to int
                            pNew->m_n64SignalVal =
                                pMainFrame->nConvertStringToInt( m_omStrValue );
                            pNew->m_omStrSignalDescriptor =
                                m_omStrValueDescriptor;
                            if (MD_EDIT == m_bMode)
                            {
                                //m_omStrPrevDesc = m_omStrValueDescriptor;
                            }
                            // update the edited values to the data structure
                            if ( !pTempMsgSg->bUpdateSgDescVal( m_omStrMessageCode,
                                                                m_omStrSgName,
                                                                m_omStrPrevDesc,
                                                                pNew ))
                            {
                                AfxMessageBox("Could not update...",
                                              MB_OK|MB_ICONINFORMATION);
                            }
                            // clean up
                            delete pNew;
                            pNew = NULL;
                            CDialog::OnOK();
                        }
                    }
                }
            }
        }
    }
}
void CValueDescriptionDlg::OnClickedOk()
{
    UpdateData(TRUE);
    BOOL bRetValue = TRUE;
    BOOL bModifiedFlag = FALSE;
    // Validate data
    if ( m_omStrDescriptor.IsEmpty() == TRUE )
    {
        AfxMessageBox("Signal Description cannot be emtpy!",MB_OK);
        GetDlgItem(IDC_EDIT_VALUE_DESC)->SetFocus();
        bRetValue = FALSE;
    }

    if ( bRetValue == TRUE)
    {
        if ( m_omStrValue.IsEmpty() == TRUE )
        {
            AfxMessageBox("Signal value cannot be emtpy!",MB_OK);
            GetDlgItem(IDC_EDIT_VAL)->SetFocus();
            bRetValue = FALSE;
        }

        if ( bRetValue == TRUE )
        {
            // Get appropriate msg structure ptr
            CMsgSignal* pTempMsgSg = NULL;
            pTempMsgSg = *((CMsgSignal**)(m_sDbParams.m_ppvActiveDB));

            if ( pTempMsgSg != NULL )
            {
                // Check if description is duplicate
                if ( m_omStrPrevDesc != m_omStrDescriptor )
                {
                    if(pTempMsgSg->bIsDuplicateValueDescription(m_omStrMessageCode,
                            m_omStrSgName,
                            m_omStrValue,
                            m_omStrDescriptor,
                            m_nIndex,
                            m_bMode))
                    {
                        AfxMessageBox("Signal Descriptor already exists!",MB_OK);
                        GetDlgItem(IDC_EDIT_VALUE_DESC)->SetFocus();
                        bRetValue = FALSE;
                    }
                }

                // Check if signal value is duplicate
                if ( bRetValue == TRUE )
                {
                    if ( m_omStrPrevSignalVal  != m_omStrValue )
                    {
                        if ( pTempMsgSg->bIsDuplicateSignalValue(m_omStrMessageCode,
                                m_omStrSgName,
                                m_omStrValue,
                                m_omStrDescriptor,
                                m_nIndex,
                                m_bMode))
                        {
                            AfxMessageBox("Signal Value already exists!", MB_OK);
                            GetDlgItem(IDC_EDIT_VAL )->SetFocus();
                            bRetValue = FALSE;
                        }
                    }
                }

                // Check if the signal value is within the range
                if ( bRetValue == TRUE )
                {
                    if (pTempMsgSg->bIsSignalValueOutofRange(m_omStrMessageCode,
                            m_omStrSgName,
                            m_omStrValue ))
                    {
                        AfxMessageBox( MSG_SG_VAL_OUT_OF_RANGE, MB_OK);
                        GetDlgItem(IDC_EDIT_VAL )->SetFocus();
                        bRetValue = FALSE;
                    }

                    //check the value is changed or not
                    if (bIsDataModified()&&( bRetValue == TRUE ))
                    {
                        bModifiedFlag = TRUE;
                        // Update the desc into the data structure
                        CSignalDescVal* pNew = new CSignalDescVal;
                        //                      CMainFrame* pMainFrame =
                        //                          static_cast<CMainFrame*> (AfxGetApp()->m_pMainWnd);

                        if (pNew != NULL)
                        {
                            CString omStrPrevDesc = STR_EMPTY;
                            if ( MD_ADD == m_bMode )
                            {
                                // new desc and val hence allocate memory
                                pTempMsgSg->bAddSgDescVal( m_omStrMessageCode,
                                                           m_omStrSgName );
                            }
                            //                              pNew->m_n64SignalVal = _strtoi64( m_omStrValue, NULL, 10);
                            if(bSignalType.CompareNoCase(defSIGNED_INT) == 0)
                            {
                                pNew->m_DescValue.n64Value = _strtoi64( m_omStrValue, NULL, 10);
                            }
                            else
                            {
                                pNew->m_DescValue.un64Value = _strtoui64( m_omStrValue, NULL, 10);
                            }

                            //                              // convert string to int
                            //                              pNew->m_n64SignalVal = pMainFrame->nConvertStringToInt( m_omStrValue );
                            pNew->m_omStrSignalDescriptor = m_omStrDescriptor;

                            if (MD_EDIT == m_bMode)
                            {
                                m_omStrPrevDesc = m_omStrDescriptor;
                            }
                            // update the edited values to the data structure
                            if ( !pTempMsgSg->bUpdateSgDescVal( m_omStrMessageCode,
                                                                m_omStrSgName,
                                                                m_omStrPrevDesc,
                                                                pNew ))
                            {
                                AfxMessageBox("Could not update...",
                                              MB_OK|MB_ICONINFORMATION);
                                bRetValue = FALSE;
                            }
                            // clean up
                            delete pNew;
                            pNew = NULL;
                        }
                    }
                }
            }
        }
    }

    if(bRetValue == TRUE)//no error occurs
    {
        if(bModifiedFlag == TRUE)//some modification done
        {
            CDialog::OnOK();
        }
        else //no modification
        {
            CDialog::OnCancel();
        }
    }
}