?? insertreader.cpp
字號:
// InsertReader.cpp : implementation file
//
#include "stdafx.h"
#include "librarym.h"
#include "InsertReader.h"
#include "ReaderList.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInsertReader dialog
CInsertReader::CInsertReader(CWnd* pParent /*=NULL*/)
: CDialog(CInsertReader::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertReader)
m_address = _T("");
m_email = _T("");
m_gender = _T("");
m_phone = _T("");
m_ps = _T("");
m_readerid = _T("");
m_readername = _T("");
m_readertypeid = _T("");
m_workunit = _T("");
//}}AFX_DATA_INIT
}
void CInsertReader::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertReader)
DDX_Text(pDX, IDC_EDIT_ADDRESS, m_address);
DDX_Text(pDX, IDC_EDIT_EMAIL, m_email);
DDX_Text(pDX, IDC_EDIT_GENDER, m_gender);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phone);
DDX_Text(pDX, IDC_EDIT_PS, m_ps);
DDX_Text(pDX, IDC_EDIT_READERID, m_readerid);
DDX_Text(pDX, IDC_EDIT_READERNAME, m_readername);
DDX_Text(pDX, IDC_EDIT_READERTYPEID, m_readertypeid);
DDX_Text(pDX, IDC_EDIT_WORKUNIT, m_workunit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertReader, CDialog)
//{{AFX_MSG_MAP(CInsertReader)
ON_BN_CLICKED(IDC_BUTTON_INSERTREADERRECORDCANCEL, OnButtonInsertreaderrecordcancel)
ON_BN_CLICKED(IDC_BUTTON_INSERTREADERRECORD, OnButtonInsertreaderrecord)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInsertReader message handlers
BOOL CInsertReader::OnInitDialog()
{
CDialog::OnInitDialog();
//初始化數(shù)據(jù)庫連接
HRESULT result;
try
{
//實(shí)例化連接對象
result=m_pConnection.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(result))
{
//設(shè)置連接屬性為UDL文件
m_pConnection->ConnectionString="File Name=LIBRARYM.udl";
//設(shè)置等待連接打開的時間為20s
m_pConnection->ConnectionTimeout=20;
result=m_pConnection->Open("","","",adConnectUnspecified);
if(FAILED(result))
{
AfxMessageBox("open failed");
return TRUE;
}
}
else
{
AfxMessageBox("createinstance of connection failed!");
return TRUE;
}
}
catch(_com_error e)
{
//輸出異常信息
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
AfxMessageBox(bstrSource+bstrDescription);
return TRUE;
}
return TRUE;
}
void CInsertReader::OnButtonInsertreaderrecordcancel()
{
CDialog::OnCancel();
}
void CInsertReader::OnButtonInsertreaderrecord()
{
UpdateData(TRUE); //得到輸入
//判斷是否輸入了要插入的數(shù)據(jù)項(xiàng)
if(m_address.IsEmpty() || m_phone.IsEmpty() ||m_gender.IsEmpty()
|| m_readerid.IsEmpty() || m_readername.IsEmpty() ||m_readertypeid.IsEmpty()
)
{
AfxMessageBox("empty input!");
return;
}
_RecordsetPtr pset;
pset.CreateInstance(_uuidof(Recordset));
HRESULT hr;
try
{
hr=pset->Open("select * from ReaderInfo",m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
//添加記錄
if(SUCCEEDED(hr))
{
pset->AddNew();
//寫入每個字段值
pset->PutCollect("ReaderID",_variant_t(m_readerid));
pset->PutCollect("ReaderName",_variant_t(m_readername));
pset->PutCollect("ReaderTypeID",_variant_t(m_readertypeid));
pset->PutCollect("Gender",_variant_t(m_gender));
pset->PutCollect("WorkUnit",_variant_t(m_workunit));
pset->PutCollect("Address",_variant_t(m_address));
pset->PutCollect("Phone",_variant_t(m_phone));
pset->PutCollect("Email",_variant_t(m_email));
pset->PutCollect("PS",_variant_t(m_ps));
pset->Update();
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
pset->Close();
pset=NULL;
AfxMessageBox("successful inserted!");
CDialog::OnOK();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -