?? recordfile.cpp
字號:
// RecordFile.cpp : implementation file
//
#include "stdafx.h"
#include "MyRecord.h"
#include "RecordFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMyRecordApp theApp; // 在此引用應用類中的theApp來獲取庫連接指針
/////////////////////////////////////////////////////////////////////////////
// CRecordFile dialog
CRecordFile::CRecordFile(CWnd* pParent /*=NULL*/)
: CDialog(CRecordFile::IDD, pParent)
{
//{{AFX_DATA_INIT(CRecordFile)
m_fileitem = _T("");
m_filename = _T("");
m_filenote = _T("");
m_filetime = _T("");
//}}AFX_DATA_INIT
flagstr="NO";
}
void CRecordFile::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRecordFile)
DDX_Control(pDX, IDC_FILETIME, m_timeedit);
DDX_Control(pDX, IDC_FILENOTE, m_noteedit);
DDX_Control(pDX, IDC_FILENAME, m_nameedit);
DDX_Control(pDX, IDC_FILEITEM, m_itemedit);
DDX_Text(pDX, IDC_FILEITEM, m_fileitem);
DDX_Text(pDX, IDC_FILENAME, m_filename);
DDX_Text(pDX, IDC_FILENOTE, m_filenote);
DDX_Text(pDX, IDC_FILETIME, m_filetime);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRecordFile, CDialog)
//{{AFX_MSG_MAP(CRecordFile)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_RECTIFY, OnRectify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRecordFile message handlers
BOOL CRecordFile::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
_variant_t var;
CString strSQL;
strSQL="Select * from info where patientname='"+namestr+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset"); //連接Access數據庫
m_pRecordset->Open((_variant_t)strSQL,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); //執行SQL語句
while(!m_pRecordset->adoEOF)
{
var=m_pRecordset->GetCollect("patientname");
if(var.vt!=VT_NULL)
m_filename=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("operationtime");
if(var.vt!=VT_NULL)
m_filetime=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("operationitem");
if(var.vt!=VT_NULL)
m_fileitem=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("note");
if(var.vt!=VT_NULL)
m_filenote=(LPCSTR)_bstr_t(var);
UpdateData(false);
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
}
catch(_com_error e) //捕捉異常
{
CString temp;
temp.Format("讀取數據庫出錯:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRecordFile::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
_variant_t varBLOB;
HRESULT hr;
HGLOBAL hGlobal = NULL;
long nWidth,nHeight;
long x, y, cx, cy;
CRect rect1,rect2,rect3;
CWnd *pWnd1=GetDlgItem(IDC_FILEPICTURE1);
CDC *pDC1=pWnd1->GetDC();
pWnd1->GetClientRect(&rect1);
CWnd *pWnd2=GetDlgItem(IDC_FILEPICTURE2);
CDC *pDC2=pWnd2->GetDC();
pWnd2->GetClientRect(&rect2);
CWnd *pWnd3=GetDlgItem(IDC_FILEPICTURE3);
CDC *pDC3=pWnd3->GetDC();
pWnd3->GetClientRect(&rect3);
CString strSQL = "Select * from info where patientname= '"+namestr+"'"; //通過姓名來獲取數據庫中的那一行信息
try
{
m_pRecordset.CreateInstance("ADODB.Recordset"); //連接access數據庫
m_pRecordset->Open((_variant_t)strSQL,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); //執行SQL語句
if(!m_pRecordset->adoEOF)
{
long nSize1 = m_pRecordset->GetFields()->GetItem("picture1")->ActualSize;
long nSize2 = m_pRecordset->GetFields()->GetItem("picture2")->ActualSize;
long nSize3 = m_pRecordset->GetFields()->GetItem("picture3")->ActualSize;
//-------------------第一張圖片顯示--------------------------------------------//
//-----------------------------------------------------------------------------//
if(nSize1 > 0)
{
varBLOB = m_pRecordset->GetFields()->GetItem("picture1")->GetChunk(nSize1);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
char *pBuf = NULL;
LPVOID pBuf2 = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
hGlobal = GlobalAlloc(GMEM_MOVEABLE,nSize1);
pBuf2 = GlobalLock(hGlobal);
memcpy(pBuf2,pBuf,nSize1);///復制數據到緩沖區m_pBMPBuffer
::GlobalUnlock(hGlobal);
SafeArrayUnaccessData (varBLOB.parray);
// 由 HGLOBAL 得到 IStream,參數 TRUE 表示釋放 IStream 的同時,釋放內存
hr = ::CreateStreamOnHGlobal( hGlobal, TRUE, &pStream );
hr = ::OleLoadPicture( pStream, nSize1, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
//獲得picture大小
pPicture->get_Width(&nWidth);
pPicture->get_Height(&nHeight);
CSize sz( nWidth, nHeight );
pDC1->HIMETRICtoDP( &sz );
//自動適應窗口
double fRatePic, fRateWnd;
fRatePic = (double)sz.cx / (double)sz.cy;
fRateWnd = (double)rect1.Width() / (double)rect1.Height();
if (fRatePic > fRateWnd)
{
cx = rect1.Width();
cy = (long)(rect1.Width() / fRatePic);
}
else
{
cx = (long)(rect1.Height() * fRatePic);
cy = rect1.Height();
}
if (cx == rect1.Width())
{
x = 0;
y = rect1.Height() / 2 - cy / 2;
}
if (cy == rect1.Height())
{
x = rect1.Width() / 2 - cx / 2;
y = 0;
}
pPicture->Render(pDC1->m_hDC, x, y, cx, cy, 0, nHeight, nWidth, -nHeight, &rect1);
}
}
//--------------------------第二張圖片顯示------------------------------------//
//----------------------------------------------------------------------------//
if(nSize2 > 0)
{
varBLOB = m_pRecordset->GetFields()->GetItem("picture2")->GetChunk(nSize2);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
char *pBuf = NULL;
LPVOID pBuf2 = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
hGlobal = GlobalAlloc(GMEM_MOVEABLE,nSize2);
pBuf2 = GlobalLock(hGlobal);
memcpy(pBuf2,pBuf,nSize2);///復制數據到緩沖區m_pBMPBuffer
::GlobalUnlock(hGlobal);
SafeArrayUnaccessData (varBLOB.parray);
// 由 HGLOBAL 得到 IStream,參數 TRUE 表示釋放 IStream 的同時,釋放內存
hr = ::CreateStreamOnHGlobal( hGlobal, TRUE, &pStream );
hr = ::OleLoadPicture( pStream, nSize2, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
//獲得picture大小
pPicture->get_Width(&nWidth);
pPicture->get_Height(&nHeight);
CSize sz( nWidth, nHeight );
pDC2->HIMETRICtoDP( &sz );
//自動適應窗口
double fRatePic, fRateWnd;
fRatePic = (double)sz.cx / (double)sz.cy;
fRateWnd = (double)rect2.Width() / (double)rect2.Height();
if (fRatePic > fRateWnd)
{
cx = rect2.Width();
cy = (long)(rect2.Width() / fRatePic);
}
else
{
cx = (long)(rect2.Height() * fRatePic);
cy = rect2.Height();
}
if (cx == rect2.Width())
{
x = 0;
y = rect2.Height() / 2 - cy / 2;
}
if (cy == rect2.Height())
{
x = rect2.Width() / 2 - cx / 2;
y = 0;
}
pPicture->Render(pDC2->m_hDC, x, y, cx, cy, 0, nHeight, nWidth, -nHeight, &rect2);
}
}
//------------------------第三張圖片顯示--------------------------------------//
//----------------------------------------------------------------------------//
if(nSize3 > 0)
{
varBLOB = m_pRecordset->GetFields()->GetItem("picture3")->GetChunk(nSize3);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
char *pBuf = NULL;
LPVOID pBuf2 = NULL;
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
hGlobal = GlobalAlloc(GMEM_MOVEABLE,nSize3);
pBuf2 = GlobalLock(hGlobal);
memcpy(pBuf2,pBuf,nSize3);///復制數據到緩沖區m_pBMPBuffer
::GlobalUnlock(hGlobal);
SafeArrayUnaccessData (varBLOB.parray);
// 由 HGLOBAL 得到 IStream,參數 TRUE 表示釋放 IStream 的同時,釋放內存
hr = ::CreateStreamOnHGlobal( hGlobal, TRUE, &pStream );
hr = ::OleLoadPicture( pStream, nSize3, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
//獲得picture大小
pPicture->get_Width(&nWidth);
pPicture->get_Height(&nHeight);
CSize sz( nWidth, nHeight );
pDC3->HIMETRICtoDP( &sz );
//自動適應窗口
double fRatePic, fRateWnd;
fRatePic = (double)sz.cx / (double)sz.cy;
fRateWnd = (double)rect3.Width() / (double)rect3.Height();
if (fRatePic > fRateWnd)
{
cx = rect3.Width();
cy = (long)(rect3.Width() / fRatePic);
}
else
{
cx = (long)(rect3.Height() * fRatePic);
cy = rect3.Height();
}
if (cx == rect3.Width())
{
x = 0;
y = rect3.Height() / 2 - cy / 2;
}
if (cy == rect3.Height())
{
x = rect3.Width() / 2 - cx / 2;
y = 0;
}
pPicture->Render(pDC3->m_hDC, x, y, cx, cy, 0, nHeight, nWidth, -nHeight, &rect3);
}
}
if ( pPicture ) pPicture->Release();// 釋放 IPicture 指針
if ( pStream ) pStream->Release(); // 釋放 IStream 指針,同時釋放了 hMem
}
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("讀取圖片出錯:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
// Do not call CDialog::OnPaint() for painting messages
}
void CRecordFile::OnRectify()
{
// TODO: Add your control notification handler code here
CString sql;
_variant_t RecordsAffected;
UpdateData(TRUE);
if (AfxMessageBox("保存修改嗎?",MB_YESNO)==IDYES)
{
sql="Update info set operationtime='"+m_filetime+
"',operationitem='"+m_fileitem+
"',note='"+m_filenote+
"' where patientname='"+m_filename+
"'";
// MessageBox(sql);
try
{
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
UpdateData(FALSE);
flagstr="YES";
//InitListData();
AfxMessageBox("修改信息成功!");
CDialog::OnCancel();
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("修改信息出錯:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -