Пример #1
0
INT CSysParams::RefreshSysParams(BOOL bLog)
{
	CMyDB db;
	if (!db.Connect())
		return ERR_CANT_CONNECT_DB;

	INT nRet = RefreshSysParams(db, bLog);

	db.Disconnect();

	return nRet;
}
Пример #2
0
INT CSysParams::GetItemList(vector<LPITEMINFO>& vList)
{
	ClearVector(&vList);

	INT nRet = ERR_UNKONW_ERROR;
	CMyDB db;
	if (!db.Connect())
		return ERR_CANT_CONNECT_DB;

	USES_CONVERSION;	// for W2A or A2W

	if (Lock(LOCK_WAIT_TIMEOUT))
	{
		try
		{
			LPCTSTR pSQL = _T("SELECT ItemID, Address, DisplayName, NeedAccumulate, InConverter, OutConverter, DataType From MonitorItem WHERE Status='A'");
			_RecordsetPtr pRS = db.GetRecordset(_variant_t(pSQL));
			if (pRS)
			{
				DWORD dwBufLen;
				while (!pRS->adoEOF)
				{
					LPITEMINFO pItem = new ITEMINFO();
					GetStringValue(pRS, 0, &(pItem->pItemID), dwBufLen);
					GetStringValue(pRS, 1, &(pItem->pAddress), dwBufLen);
					GetStringValue(pRS, 2, &(pItem->pDisplayName), dwBufLen);
					GetStringValue(pRS, 4, &(pItem->pInConverter), dwBufLen);
					GetStringValue(pRS, 5, &(pItem->pOutConverter), dwBufLen);

					_variant_t vRetVal = pRS->Fields->GetItem(_variant_t((long)6))->GetValue();
					if (VT_I4 == vRetVal.vt)
					{
						pItem->vtRequestedDataType = vRetVal.lVal;
					}

					vRetVal = pRS->Fields->GetItem(_variant_t((long)3))->GetValue();
					if (VT_BOOL == vRetVal.vt)
					{
						pItem->bNeedAccumulate = vRetVal.boolVal;
					}

					pItem->chStatus = _T('A');

					vList.push_back(pItem);

					pRS->MoveNext();
				}

				pRS->Close();
				pRS.Release();
			}
			else
			{
				nRet = db.GetLastErrorCode();
				throw nRet;
			}
		}
		catch (...) {
			Unlock();
			nRet;
		}

		Unlock();
		nRet = vList.size();
	}
	else
	{
		nRet = ERR_LOCK_TIMEOUT;
	}

	db.Disconnect();
	return nRet;
}