?? userdelview.cpp
字號(hào):
// UserDelView.cpp : implementation file
//
#include "stdafx.h"
#include "lock.h"
#include "UserDelView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// UserDelView
IMPLEMENT_DYNCREATE(UserDelView, CFormView)
UserDelView::UserDelView()
: CFormView(UserDelView::IDD)
{
//{{AFX_DATA_INIT(UserDelView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
UserDelView::~UserDelView()
{
}
void UserDelView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(UserDelView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(UserDelView, CFormView)
//{{AFX_MSG_MAP(UserDelView)
ON_BN_CLICKED(IDC_BUTTON_OPEN_ALL, OnButtonOpenAll)
ON_BN_CLICKED(IDC_DELUQUIT_C, OnDeluquitC)
ON_NOTIFY(NM_CLICK, IDC_LIST_USER_DEL, OnClickListUserDel)
ON_BN_CLICKED(IDOK, OnOK)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// UserDelView diagnostics
#ifdef _DEBUG
void UserDelView::AssertValid() const
{
CFormView::AssertValid();
}
void UserDelView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// UserDelView message handlers
void UserDelView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
m_id = 0;
// TODO: Add your specialized code here and/or call the base class
CListCtrl * pList = (CListCtrl *)GetDlgItem(IDC_LIST_USER_DEL);
pList->InsertColumn(0,"編號(hào)",LVCFMT_CENTER,50);
pList->InsertColumn(1,"姓名",LVCFMT_CENTER,50);
pList->InsertColumn(2,"性別",LVCFMT_CENTER,50);
pList->InsertColumn(3,"出生日期",LVCFMT_CENTER,70);
pList->InsertColumn(4,"證件類型",LVCFMT_CENTER,70);
pList->InsertColumn(5,"證件號(hào)碼",LVCFMT_CENTER,70);
pList->InsertColumn(6,"電話",LVCFMT_CENTER,50);
pList->InsertColumn(7,"工作單位",LVCFMT_CENTER,70);
pList->InsertColumn(8,"工作部門",LVCFMT_CENTER,70);
pList->InsertColumn(9,"職務(wù)",LVCFMT_CENTER,50);
pList->InsertColumn(10,"地址",LVCFMT_CENTER,50);
pList->InsertColumn(11,"備注",LVCFMT_CENTER,50);
pList->SetExtendedStyle(
LVS_EX_FLATSB // 扁平風(fēng)格滾動(dòng)
| LVS_EX_FULLROWSELECT // 允許正航選中
| LVS_EX_HEADERDRAGDROP // 允許標(biāo)題拖拽
| LVS_EX_GRIDLINES // 畫出網(wǎng)格線
) ;
}
void UserDelView::OnButtonOpenAll()
{
// TODO: Add your control notification handler code here
// DB operation
CLockApp * pApp = (CLockApp *)AfxGetApp();
_RecordsetPtr m_pRecordset;
if( FAILED(m_pRecordset.CreateInstance( __uuidof( Recordset ))))
{
::MessageBox(NULL,"create record set fail!","Promote", MB_OK | MB_ICONWARNING);
return ;
}
CString strSQLT;
strSQLT = "select * from user_1";
try
{
m_pRecordset->Open(strSQLT.AllocSysString(),
pApp->m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
//AfxMessageBox("open table successefully");
}
catch (_com_error e)
{
::MessageBox(NULL,"open table failed ","promote", MB_OK | MB_ICONWARNING);
CString strError;
strError.Format("Warning: exception when insert a record! \n %s", e.ErrorMessage());
}
CListCtrl * pList = (CListCtrl *)GetDlgItem(IDC_LIST_USER_DEL);
pList->DeleteAllItems();
m_pRecordset->MoveFirst();
// Display
int nItem=0;
_variant_t var;
while (!m_pRecordset->adoEOF)
{
CString str;
pList->InsertItem(nItem,str);
for (int i = 0; i < 12; i++)
{
var = m_pRecordset->GetCollect(_variant_t(long(i)));
str = pApp->VariantToCString(var);
pList->SetItemText(nItem,i,str);
}
m_pRecordset->MoveNext();
nItem++;
};
m_pRecordset->MoveFirst();
m_pRecordset->Close();
m_pRecordset = NULL;
}
void UserDelView::OnDeluquitC()
{
// TODO: Add your control notification handler code here
m_userid = "";
GetDlgItem(IDC_USID_C)->SetWindowText(m_userid);
m_username = "";
GetDlgItem(IDC_USNAME_C)->SetWindowText(m_username);
m_sex = "";
GetDlgItem(IDC_COMBO_SEX_C)->SetWindowText(m_sex);
m_BirthDay = "";
GetDlgItem(IDC_BIRTHDAY_C)->SetWindowText(m_BirthDay);
m_usercom = "";
GetDlgItem(IDC_USCOM_C)->SetWindowText(m_usercom);
m_userdep = "";
GetDlgItem(IDC_USDEP_C)->SetWindowText(m_userdep);
m_userpost = "";
GetDlgItem(IDC_USPOST_C)->SetWindowText(m_userpost);
m_idtype = "";
GetDlgItem(IDC_COMBO_IDTYPE_C)->SetWindowText(m_idtype);
m_useridnum = "";
GetDlgItem(IDC_USIDNO_C)->SetWindowText(m_useridnum);
m_usertel = "";
GetDlgItem(IDC_USTEL_C)->SetWindowText(m_usertel);
m_useraddr = "";
GetDlgItem(IDC_USADD_C)->SetWindowText(m_useraddr);
m_userremark = "";
GetDlgItem(IDC_USREM_C)->SetWindowText(m_userremark);
CLockApp * pApp = (CLockApp *)AfxGetApp();
pApp->SwitchView(0);
}
void UserDelView::OnOK()
{
// TODO: Add your control notification handler code here
if (m_id == 0)
{
AfxMessageBox("請(qǐng)選擇需要?jiǎng)h除的記錄");
return;
}
// DB
CLockApp * pApp = (CLockApp *)AfxGetApp();
_RecordsetPtr m_pRecordset;
_variant_t RecordsAffected;
CString sql;
// sql.Format("UPDATE user_1 SET Name = '%s',Gender = '%s', BirthDay = '%s',IDType = '%s',IDNum = '%s',TelNum = '%s',Company = '%s',Department = '%s',Pos = '%s', HomeAdd = '%s',Remark = '%s' WHERE UserID = %d",m_username,m_sex,m_BirthDay,m_idtype,m_useridnum,m_usertel, m_usercom,m_userdep,m_userpost,m_useraddr,m_userremark,m_id);
sql.Format("DELETE from user_1 WHERE UserID = %d", m_id);
try
{
pApp->m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch (_com_error e)
{
::MessageBox(NULL,"revise a record failed ","promote", MB_OK | MB_ICONWARNING);
CString strError;
strError.Format("Warning: exception when revise a record! \n %s", e.ErrorMessage());
}
OnButtonOpenAll();
AfxMessageBox("修改成功");
m_userid = "";
GetDlgItem(IDC_USID_C)->SetWindowText(m_userid);
m_username = "";
GetDlgItem(IDC_USNAME_C)->SetWindowText(m_username);
m_sex = "";
GetDlgItem(IDC_COMBO_SEX_C)->SetWindowText(m_sex);
m_BirthDay = "";
GetDlgItem(IDC_BIRTHDAY_C)->SetWindowText(m_BirthDay);
m_usercom = "";
GetDlgItem(IDC_USCOM_C)->SetWindowText(m_usercom);
m_userdep = "";
GetDlgItem(IDC_USDEP_C)->SetWindowText(m_userdep);
m_userpost = "";
GetDlgItem(IDC_USPOST_C)->SetWindowText(m_userpost);
m_idtype = "";
GetDlgItem(IDC_COMBO_IDTYPE_C)->SetWindowText(m_idtype);
m_useridnum = "";
GetDlgItem(IDC_USIDNO_C)->SetWindowText(m_useridnum);
m_usertel = "";
GetDlgItem(IDC_USTEL_C)->SetWindowText(m_usertel);
m_useraddr = "";
GetDlgItem(IDC_USADD_C)->SetWindowText(m_useraddr);
m_userremark = "";
GetDlgItem(IDC_USREM_C)->SetWindowText(m_userremark);
}
void UserDelView::OnClickListUserDel(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CListCtrl * pList = ((CListCtrl *)GetDlgItem(IDC_LIST_USER_DEL));
POSITION pos = pList->GetFirstSelectedItemPosition();
int nItem = (int) pos;
m_userid = "";
m_userid = pList->GetItemText(nItem-1,0);
GetDlgItem(IDC_USID_C)->SetWindowText(m_userid);
m_username = pList->GetItemText(nItem-1,1);
GetDlgItem(IDC_USNAME_C)->SetWindowText(m_username);
m_sex = pList->GetItemText(nItem-1,2);
GetDlgItem(IDC_COMBO_SEX_C)->SetWindowText(m_sex);
m_BirthDay = pList->GetItemText(nItem-1,3);
GetDlgItem(IDC_BIRTHDAY_C)->SetWindowText(m_BirthDay);
m_usercom = pList->GetItemText(nItem-1,7);
GetDlgItem(IDC_USCOM_C)->SetWindowText(m_usercom);
m_userdep = pList->GetItemText(nItem-1,8);
GetDlgItem(IDC_USDEP_C)->SetWindowText(m_userdep);
m_userpost = pList->GetItemText(nItem-1,9);
GetDlgItem(IDC_USPOST_C)->SetWindowText(m_userpost);
m_idtype = pList->GetItemText(nItem-1,4);
GetDlgItem(IDC_COMBO_IDTYPE_C)->SetWindowText(m_idtype);
m_useridnum = pList->GetItemText(nItem-1,5);
GetDlgItem(IDC_USIDNO_C)->SetWindowText(m_useridnum);
m_usertel = pList->GetItemText(nItem-1,6);
GetDlgItem(IDC_USTEL_C)->SetWindowText(m_usertel);
m_useraddr = pList->GetItemText(nItem-1,10);
GetDlgItem(IDC_USADD_C)->SetWindowText(m_useraddr);
m_userremark = pList->GetItemText(nItem-1,11);
GetDlgItem(IDC_USREM_C)->SetWindowText(m_userremark);
m_id = atol(m_userid);
*pResult = 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -