|
//向服务器提交数据
void CRDAExamDlg::OnBtnpush()
{
ISSCERDA* pCERDA = NULL;
BSTR bStr = NULL;
BSTR bConnectStr = NULL;
BSTR bLocalConnectStr = NULL;
BSTR bLocalTableName = NULL;
SYSTEMTIME systemtime; // 系统时间
double timeTotal; // 总共消耗的时间
__int64 timeStart = 0; // 开始操作时的时间
__int64 timeStop; // 结束操作时的时间
WCHAR wszBuffer[512];
CDlgPush dlgPush;
if (dlgPush.DoModal())
{
//得到pCERDA接口
HRESULT hr = CoCreateInstance(CLSID_RemoteDataAccess, NULL, CLSCTX_INPROC_SERVER, IID_ISSCERDA, (LPVOID *)&pCERDA);
ASSERT(hr == S_OK);
ASSERT(pCERDA != NULL);
//1、设置Internet URL
bStr = SysAllocString(dlgPush.m_internetURL);
pCERDA->put_InternetURL(bStr);
SysFreeString(bStr);
//2、设置Internet userName
bStr = SysAllocString(dlgPush.m_internetUsername);
pCERDA->put_InternetLogin(bStr);
SysFreeString(bStr);
//3、设置Internet password
bStr = SysAllocString(dlgPush.m_internetPassword);
pCERDA->put_InternetPassword(bStr);
SysFreeString(bStr);
//4、设置服务器连接串
bConnectStr = SysAllocString(dlgPush.m_connectStr);
//5、设置本地数据库连接串
bLocalConnectStr = SysAllocString(dlgPush.m_localConnectStr);
pCERDA->put_LocalConnectionString(bLocalConnectStr);
SysFreeString(bStr);
//6、设置本地表名
bLocalTableName = SysAllocString(dlgPush.m_localTableName);
//记录向服务器提交数据前的时间
GetLocalTime(&systemtime);
SystemTimeToFileTime(&systemtime, (FILETIME*)&timeStart);
//向服务器提交数据
hr = pCERDA->Push(bLocalTableName,bConnectStr, BATCHINGOFF);
SysFreeString(bLocalTableName);
SysFreeString(bConnectStr);
if (SUCCEEDED(hr))
{
//记录向服务器提交数据后的时间
GetLocalTime(&systemtime);
SystemTimeToFileTime(&systemtime, (FILETIME*)&timeStop);
//记录向服务器提交数据总的时间
timeTotal = ((double)(timeStop - timeStart) / 10000000);
swprintf(wszBuffer, _T("向服务器提交数据成功\r\n\r\总共消耗 = %8.3f秒"), timeTotal);
AfxMessageBox(wszBuffer);
}
else
{
//显示向服务器提交数据失败信息
ISSCEErrors *pISSCEErrors = NULL;
if(SUCCEEDED(hr = pCERDA->get_ErrorRecords(&pISSCEErrors)))
{
ShowErrors(pISSCEErrors);
pISSCEErrors->Release();
}
}
//释放远程访问接口
pCERDA->Release();
} |
|