Esempio n. 1
0
BOOL CADORecordset::GetFieldValue(int nIndex, CString& strValue, CString strDateFormat)
{
	CString str;
	_variant_t vtFld;
	_variant_t vtIndex;

	vtIndex.vt = VT_I2;
	vtIndex.iVal = nIndex;
	
	try
	{
		vtFld = m_pRecordset->Fields->GetItem(vtIndex)->Value;
		switch(vtFld.vt) 
		{
		case VT_R4:
			str = DblToStr(vtFld.fltVal);
			break;
		case VT_R8:
			str = DblToStr(vtFld.dblVal);
			break;
		case VT_BSTR:
			str = vtFld.bstrVal;
			break;
		case VT_I2:
		case VT_UI1:
			str = IntToStr(vtFld.iVal);
			break;
		case VT_INT:
			str = IntToStr(vtFld.intVal);
			break;
		case VT_I4:
			str = LongToStr(vtFld.lVal);
			break;
		case VT_UI4:
			str = ULongToStr(vtFld.ulVal);
			break;
		case VT_DECIMAL:
			{
			//Corrected by José Carlos Martínez Galán
			double val = vtFld.decVal.Lo32;
			val *= (vtFld.decVal.sign == 128)? -1 : 1;
			val /= pow(10, vtFld.decVal.scale); 
			str = DblToStr(val);
			}
			break;
		case VT_DATE:
			{
				COleDateTime dt(vtFld);
				
				if(strDateFormat.IsEmpty())
					strDateFormat = _T("%Y-%m-%d %H:%M:%S");
				str = dt.Format(strDateFormat);
			}
			break;
		case VT_CY:		//Added by John Andy Johnson!!!
			{
				vtFld.ChangeType(VT_R8);
 
				CString str;
				str.Format(_T("%f"), vtFld.dblVal);
 
				_TCHAR pszFormattedNumber[64];
 
				//	LOCALE_USER_DEFAULT
				if(GetCurrencyFormat(
						LOCALE_USER_DEFAULT,	// locale for which string is to be formatted 
						0,						// bit flag that controls the function's operation
						str,					// pointer to input number string
						NULL,					// pointer to a formatting information structure
												//	NULL = machine default locale settings
						pszFormattedNumber,		// pointer to output buffer
						63))					// size of output buffer
				{
					str = pszFormattedNumber;
				}
			}
			break;
		case VT_BOOL:
			str = vtFld.boolVal == VARIANT_TRUE? 'T':'F';
			break;
		case VT_EMPTY:
		case VT_NULL:
			str.Empty();
			break;
		default:
			str.Empty();
			return FALSE;
		}
		strValue = str;
		return TRUE;
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
		return FALSE;
	}
}
Esempio n. 2
0
BOOL CADORecordset::GetFieldValue(LPCTSTR lpFieldName, wstring& strValue, wstring strDateFormat)
{
	wstring str;
	_variant_t vtFld;

	try
	{
		vtFld = m_pRecordset->Fields->GetItem(lpFieldName)->Value;
		switch(vtFld.vt) 
		{
		case VT_R4:
			str = DblToStr(vtFld.fltVal);
			break;
		case VT_R8:
			str = DblToStr(vtFld.dblVal);
			break;
		case VT_BSTR:
			str = vtFld.bstrVal;
			break;
		case VT_I2:
		case VT_UI1:
			str = IntToStr(vtFld.iVal);
			break;
		case VT_INT:
			str = IntToStr(vtFld.intVal);
			break;
		case VT_I4:
			str = LongToStr(vtFld.lVal);
			break;
		case VT_UI4:
			str = ULongToStr(vtFld.ulVal);
			break;
		case VT_DECIMAL:
			{
			double val = vtFld.decVal.Lo32;
			val *= (vtFld.decVal.sign == 128)? -1 : 1;
			val /= pow((float)10, vtFld.decVal.scale); 
			str = DblToStr(val);
			}
			break;
		case VT_DATE:
			{
#if 0 /*lanshh **/
				COleDateTime dt(vtFld);

				if(strDateFormat.IsEmpty())
					strDateFormat = _T("%Y-%m-%d %H:%M:%S");
				str = dt.Format(strDateFormat);
#endif
			}
			break;
#if 0
		case VT_CY:		
			{
				vtFld.ChangeType(VT_R8);
 
				wstring str;
				str.Format(_T("%f"), vtFld.dblVal);
 
				_TCHAR pszFormattedNumber[64];
 
				//	LOCALE_USER_DEFAULT
				if(GetCurrencyFormat(
						LOCALE_USER_DEFAULT,	// locale for which string is to be formatted 
						0,						// bit flag that controls the function's operation
						str,					// pointer to input number string
						NULL,					// pointer to a formatting information structure
												//	NULL = machine default locale settings
						pszFormattedNumber,		// pointer to output buffer
						63))					// size of output buffer
				{
					str = pszFormattedNumber;
				}
			}
			break;
#endif
		case VT_EMPTY:
		case VT_NULL:
            str.clear();
			break;
		case VT_BOOL:
			str = vtFld.boolVal == VARIANT_TRUE? _T('T'):_T('F');
			break;
		default:
            str.clear();
			return FALSE;
		}
		strValue = str;
		return TRUE;
	}
	catch(_com_error &e)
	{
		dump_com_error(e);
		return FALSE;
	}
}
Esempio n. 3
0
void TIniFile::WriteULong(const wxString &Section, const wxString &Ident,
  unsigned long Value)
{
	WriteString(Section, Ident, ULongToStr(Value));
}
Esempio n. 4
0
BOOL GetFieldValue(_CommandPtr pCmd, const char* lpFieldName, char* strValue, int size, bool/* autoTrim*/)
{
	//CString str = _T("");
	//char str[50] = "";
	_variant_t vtFld;
	_bstr_t b;

	try
	{
		vtFld = pCmd->Parameters->GetItem(lpFieldName)->Value;
		switch(vtFld.vt) 
		{
		case VT_R4:
			DblToStr(vtFld.fltVal, strValue, 50);
			break;
		case VT_R8:
			DblToStr(vtFld.dblVal, strValue, 50);
			break;
		case VT_BSTR:
			b = vtFld.bstrVal;
			strcpy(strValue, b);
			//memcpy(strValue, (char*)vtFld.bstrVal, sizeof(vtFld.bstrVal));

			break;
		case VT_I2:
		case VT_UI1:
			IntToStr(vtFld.iVal, strValue, size);
			break;
		case VT_INT:
			IntToStr(vtFld.intVal, strValue, size);
			break;
		case VT_I4:
			LongToStr(vtFld.lVal, strValue, size);
			break;
		case VT_UI4:
			ULongToStr(vtFld.ulVal, strValue, size);
			break;
		case VT_DECIMAL:
			{
				//Corrected by Jos?Carlos Martínez Galán
				double val = vtFld.decVal.Lo32;
				val *= (vtFld.decVal.sign == 128)? -1 : 1;
				val /= pow(10, vtFld.decVal.scale); 
				DblToStr(val, strValue, size);
			}
			break;
		case VT_DATE:
			//{
			//	COleDateTime dt(vtFld);

			//	if( 0 == strlen(strDateFormat) )
			//		strDateFormat = "%Y-%m-%d %H:%M:%S";
			//	sprintf(str, strDateFormat, );
			//	strcpy(str, dt.Format(strDateFormat));
			//}
			break;
		case VT_EMPTY:
		case VT_NULL:
			//str.Empty();
			break;
		case VT_BOOL:
			strValue[0] = vtFld.boolVal == VARIANT_TRUE? 'T':'F';
			break;
		default:
			return FALSE;
		}

		//strcpy(strValue, str);
		return TRUE;
	}
	catch(_com_error &e)
	{
		PrintComError(e);
		return FALSE;
	}
}
Esempio n. 5
0
unsigned long TIniFile::ReadULong(const wxString &Section,
  const wxString &Ident, unsigned long Default)
{
	return StrToULong(ReadString(Section, Ident, ULongToStr(Default)));
}