Esempio n. 1
0
bool CSettingsDlg::CheckDBPaths()
{
    CDBConnection dbConnection;

	try
	{
        dbConnection.Open((_bstr_t)m_strDBFrom);
        dbConnection.Close();
	}
	catch(_com_error&) 
	{
		dbConnection.Close();
        AfxMessageBox("Failed exchange db path");
		return false;
	}

	try
	{
        dbConnection.Open((_bstr_t)m_strDBTo);
        dbConnection.Close();
	}
	catch(_com_error&)
	{
		dbConnection.Close();
        AfxMessageBox("Failed ETS db path");
		return false;
	}

    return true;
}
Esempio n. 2
0
//------------------------------------------------------------------------------------------------------
STDMETHODIMP CEtsDivColl::Reload(void)
{
	try
	{
		CDBConnection	dbConnection;

		if(!dbConnection.IsOpened())
			dbConnection.Open(CGenegalSettings::GetDBConnectionString(), 10, 120, 300, 300);

		if (dbConnection.IsOpened())
		{
			Clear();
			CStoredProc<> db(dbConnection, L"usp_Dividends_Get");
			
			//push parameters
			db << m_nAssetID;

			CClientRecordset rs;
			rs.Open(db);

			DATE dtDividendDate;
			DOUBLE dDividendAmmount;
			for(rs.MoveFirst(); !rs.IsEOF(); ++rs) 
			{
				dtDividendDate = (vt_date)rs[L"DivYtes"];
				dDividendAmmount = rs[L"DivAmnt"];
				_CHK(AddNonUnique(dtDividendDate, dDividendAmmount), _T("Fail to Add Dividend payment date."));
			};

			dbConnection.Close();
		};
	}
	catch (_com_error& err)
	{
		TRACE_COM_ERROR(err);
	}
	catch (...)
	{
		TRACE_UNKNOWN_ERROR();
	}
	return S_OK;
}
Esempio n. 3
0
void CSettingsDlg::OnSetup() 
{
    CDBConnection db;
    try 
    {
        IDataSourceLocatorPtr spLocator;

        HRESULT hr = spLocator.CreateInstance (__uuidof (DataLinks));
        if (FAILED(hr))
            utils::ThrowErrorNoSetErrorInfo(hr, L"Failed to create DataLinks object.");
      
        spLocator->hWnd = (long)m_hWnd;

        _ConnectionPtr  spConnection;
    	hr = spConnection.CreateInstance (__uuidof (Connection));
        if (FAILED(hr))
            utils::ThrowErrorNoSetErrorInfo(hr, L"Failed to create Connection object.");
    
        spConnection->ConnectionString = (LPCTSTR)m_DBConnectionStringFull;

        CComPtr<IDispatch> spDispatch = spConnection;
        if (spDispatch == 0)
            utils::ThrowErrorNoSetErrorInfo(E_NOINTERFACE, L"Failed to get IDispatch interface.");

        if (spLocator->PromptEdit(&spDispatch.p) == VARIANT_TRUE)
        {
            _ConnectionPtr  spNewConnection = spDispatch;

            if (spNewConnection == 0)
                utils::ThrowErrorNoSetErrorInfo(E_NOINTERFACE, L"Failed to get IDispatch interface.");

            CString strConnectionString = (LPCTSTR)spNewConnection->ConnectionString;
            
            try
            {
                db.Open((LPCTSTR)strConnectionString, 120, 120);
                CStoredProc<CDefaultRecordset> spVer(db, L"usp_DataInfo_Get");	
                spVer << 1;
                spVer.Open();
                spVer[L"vcKeyValue"];
                spVer.Close();
                db.Close();

                if (m_DBConnectionStringFull != strConnectionString)
                {
                    m_DBConnectionStringFull = strConnectionString;
					m_DBConnectionString = 
						    GetShortStringFromFull(spNewConnection->ConnectionString);
                    UpdateData(FALSE);
                }
            }
            catch (_com_error& e)
            {
                try
                {
                    if (db.IsOpened())
                        db.Close();
                } catch (_com_error&) { }

                CString err = _T("Invalid database. ");
                err += (LPTSTR) e.Description();
                AfxMessageBox(err);
            }
        }
    }
    catch (_com_error& e)
    {
        CString err = _T("Can't show database connection dialog.");
        err += (LPTSTR) e.Description();
        AfxMessageBox(err);
    }	
}