void CDlsjzDlg::ReadData()
{
if(m_pRecordset- >adoEOF||m_pRecordset->BOF)
{
m_name.Empty();
m_ghao.Empty();
UpdateData(FALSE);
return;
}
char *m_pBMPBuffer1;
long lDataSize = m_pRecordset- >GetFields()->GetItem("photo")->ActualSize;
if(lDataSize > 0)
{
_variant_t varBLOB;
varBLOB = m_pRecordset- >GetFields()->GetItem("photo")->GetChunk(lDataSize);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
if(m_pBMPBuffer1 = new char[lDataSize+1]) {
char *pBuf = NULL;
SafeArrayAccessData(varBLOB.parray,(void **) &pBuf);
memcpy(m_pBMPBuffer1,pBuf,lDataSize);
SafeArrayUnaccessData (varBLOB.parray);
m_nFileLen = lDataSize;
Picture.Load((BYTE *)m_pBMPBuffer1,lDataSize);
m_Display.SetBitmap((HBITMAP)Picture.GetSafeHandle());
}
}
}
else
{
Picture.Load(IDB_BITMAP1, "BMP");
m_Display.SetBitmap((HBITMAP)Picture.GetSafeHandle());
}
m_name=m_pRecordset- >GetCollect(_variant_t("syz")).bstrVal;
if(m_name <=''0'') m_name=_T("");
m_ghao=m_pRecordset- >GetCollect(_variant_t("gonghao")).bstrVal;
if(m_ghao <''0'') m_ghao=_T("");
m_ddd=m_pRecordset- >GetCollect(_variant_t("jcdata"));
m_ddd.vt=VT_DATE;
m_jcdate.SetValue(m_ddd);
m_ddd=m_pRecordset- >GetCollect(_variant_t("sjdata"));
m_ddd.vt=VT_DATE;
m_sjdate.SetValue(m_ddd);
m_jqbh.Format( "%d",m_pRecordset->GetCollect(_variant_t("jqbh")).intVal);
if(m_jqbh==''0'')
m_jqbh= "公用";
else
m_jqbh=m_jqbh+ "號工作站";
m_pBMPBuffer1=NULL;
UpdateData(FALSE);
}
void CDlsjzDlg::Save()
{
UpdateData();
char *pBuf = m_pBMPBuffer;
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound;
m_pRecordset- >PutCollect("syz",_variant_t(m_name));
m_pRecordset- >PutCollect("jqbh",atol(m_jqbh));
m_pRecordset- >PutCollect("gonghao",_variant_t(m_ghao));
m_pRecordset- >PutCollect("jcdata",m_jcdate.GetValue());
m_pRecordset- >PutCollect("sjdata",m_sjdate.GetValue());
if(pBuf)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = m_nFileLen;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
for (long i = 0; i < (long)m_nFileLen; i++)
SafeArrayPutElement (psa, &i, pBuf++);
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
m_pRecordset- >GetFields()->GetItem("photo")->AppendChunk(varBLOB);
}
m_pBMPBuffer=NULL;
m_pRecordset- >Update();
}