📄 userrevview.cpp
字号:
// UserRevView.cpp : implementation file
//
#include "stdafx.h"
#include "lock.h"
#include "UserRevView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// UserRevView
IMPLEMENT_DYNCREATE(UserRevView, CFormView)
UserRevView::UserRevView()
: CFormView(UserRevView::IDD)
{
//{{AFX_DATA_INIT(UserRevView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
UserRevView::~UserRevView()
{
}
void UserRevView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(UserRevView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(UserRevView, CFormView)
//{{AFX_MSG_MAP(UserRevView)
ON_BN_CLICKED(IDC_BUTTON_OPEN_RECORD, OnButtonOpenRecord)
ON_BN_CLICKED(IDC_REVUQUIT_B, OnRevuquitB)
ON_BN_CLICKED(ID_USER_REV, OnUserRev)
ON_NOTIFY(NM_CLICK, IDC_LIST_USER_REV, OnClickListUserRev)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_USER_REV, OnDblclkListUserRev)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// UserRevView diagnostics
#ifdef _DEBUG
void UserRevView::AssertValid() const
{
CFormView::AssertValid();
}
void UserRevView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// UserRevView message handlers
void UserRevView::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_REV);
pList->InsertColumn(0,"编号",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,"证件号码",LVCFMT_CENTER,70);
pList->InsertColumn(6,"电话",LVCFMT_CENTER,50);
pList->InsertColumn(7,"工作单位",LVCFMT_CENTER,70);
pList->InsertColumn(8,"工作部门",LVCFMT_CENTER,70);
pList->InsertColumn(9,"职务",LVCFMT_CENTER,50);
pList->InsertColumn(10,"地址",LVCFMT_CENTER,50);
pList->InsertColumn(11,"备注",LVCFMT_CENTER,50);
pList->SetExtendedStyle(
LVS_EX_FLATSB // 扁平风格滚动
| LVS_EX_FULLROWSELECT // 允许正航选中
| LVS_EX_HEADERDRAGDROP // 允许标题拖拽
| LVS_EX_GRIDLINES // 画出网格线
) ;
}
void UserRevView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
// TODO: Add your specialized code here and/or call the base class
CFormView::CalcWindowRect(lpClientRect, nAdjustType);
}
void UserRevView::OnButtonOpenRecord()
{
// TODO: Add your control notification handler code here
//AfxMessageBox("open");
// Read Record from database
// 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_REV);
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 UserRevView::OnRevuquitB()
{
// TODO: Add your control notification handler code here
// CListCtrl * pList = (CListCtrl *)GetDlgItem(IDC_LIST_USER_REV);
// pList->DeleteAllItems();
m_userid = "";
GetDlgItem(IDC_USID_B)->SetWindowText(m_userid);
m_username = "";
GetDlgItem(IDC_USNAME_B)->SetWindowText(m_username);
m_sex = "";
GetDlgItem(IDC_COMBO_SEX_B)->SetWindowText(m_sex);
m_BirthDay = "";
GetDlgItem(IDC_BIRTHDAY_B)->SetWindowText(m_BirthDay);
m_usercom = "";
GetDlgItem(IDC_USCOM_B)->SetWindowText(m_usercom);
m_userdep = "";
GetDlgItem(IDC_USDEP_B)->SetWindowText(m_userdep);
m_userpost = "";
GetDlgItem(IDC_USPOST_B)->SetWindowText(m_userpost);
m_idtype = "";
GetDlgItem(IDC_COMBO_IDTYPE_B)->SetWindowText(m_idtype);
m_useridnum = "";
GetDlgItem(IDC_USIDNO_B)->SetWindowText(m_useridnum);
m_usertel = "";
GetDlgItem(IDC_USTEL_B)->SetWindowText(m_usertel);
m_useraddr = "";
GetDlgItem(IDC_USADD_B)->SetWindowText(m_useraddr);
m_userremark = "";
GetDlgItem(IDC_USREM_B)->SetWindowText(m_userremark);
CLockApp * pApp = (CLockApp *)AfxGetApp();
pApp->SwitchView(0);
}
void UserRevView::OnUserRev()
{
// TODO: Add your control notification handler code here
m_username = "";
GetDlgItem(IDC_USNAME_B)->GetWindowText(m_username);
m_sex = "";
GetDlgItem(IDC_COMBO_SEX_B)->GetWindowText(m_sex);
m_BirthDay = "";
GetDlgItem(IDC_BIRTHDAY_B)->GetWindowText(m_BirthDay);
m_usercom = "";
GetDlgItem(IDC_USCOM_B)->GetWindowText(m_usercom);
m_userdep = "";
GetDlgItem(IDC_USDEP_B)->GetWindowText(m_userdep);
m_userpost = "";
GetDlgItem(IDC_USPOST_B)->GetWindowText(m_userpost);
m_idtype = "";
GetDlgItem(IDC_COMBO_IDTYPE_B)->GetWindowText(m_idtype);
m_useridnum = "";
GetDlgItem(IDC_USIDNO_B)->GetWindowText(m_useridnum);
m_usertel = "";
GetDlgItem(IDC_USTEL_B)->GetWindowText(m_usertel);
m_useraddr = "";
GetDlgItem(IDC_USADD_B)->GetWindowText(m_useraddr);
m_userremark = "";
GetDlgItem(IDC_USREM_B)->GetWindowText(m_userremark);
// 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);
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());
}
OnButtonOpenRecord();
AfxMessageBox("修改成功");
m_userid = "";
GetDlgItem(IDC_USID_B)->SetWindowText(m_userid);
m_username = "";
GetDlgItem(IDC_USNAME_B)->SetWindowText(m_username);
m_sex = "";
GetDlgItem(IDC_COMBO_SEX_B)->SetWindowText(m_sex);
m_BirthDay = "";
GetDlgItem(IDC_BIRTHDAY_B)->SetWindowText(m_BirthDay);
m_usercom = "";
GetDlgItem(IDC_USCOM_B)->SetWindowText(m_usercom);
m_userdep = "";
GetDlgItem(IDC_USDEP_B)->SetWindowText(m_userdep);
m_userpost = "";
GetDlgItem(IDC_USPOST_B)->SetWindowText(m_userpost);
m_idtype = "";
GetDlgItem(IDC_COMBO_IDTYPE_B)->SetWindowText(m_idtype);
m_useridnum = "";
GetDlgItem(IDC_USIDNO_B)->SetWindowText(m_useridnum);
m_usertel = "";
GetDlgItem(IDC_USTEL_B)->SetWindowText(m_usertel);
m_useraddr = "";
GetDlgItem(IDC_USADD_B)->SetWindowText(m_useraddr);
m_userremark = "";
GetDlgItem(IDC_USREM_B)->SetWindowText(m_userremark);
}
void UserRevView::OnClickListUserRev(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void UserRevView::OnDblclkListUserRev(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CListCtrl * pList = ((CListCtrl *)GetDlgItem(IDC_LIST_USER_REV));
POSITION pos = pList->GetFirstSelectedItemPosition();
int nItem = (int) pos;
m_userid = "";
m_userid = pList->GetItemText(nItem-1,0);
GetDlgItem(IDC_USID_B)->SetWindowText(m_userid);
m_username = pList->GetItemText(nItem-1,1);
GetDlgItem(IDC_USNAME_B)->SetWindowText(m_username);
m_sex = pList->GetItemText(nItem-1,2);
GetDlgItem(IDC_COMBO_SEX_B)->SetWindowText(m_sex);
m_BirthDay = pList->GetItemText(nItem-1,3);
GetDlgItem(IDC_BIRTHDAY_B)->SetWindowText(m_BirthDay);
m_usercom = pList->GetItemText(nItem-1,7);
GetDlgItem(IDC_USCOM_B)->SetWindowText(m_usercom);
m_userdep = pList->GetItemText(nItem-1,8);
GetDlgItem(IDC_USDEP_B)->SetWindowText(m_userdep);
m_userpost = pList->GetItemText(nItem-1,9);
GetDlgItem(IDC_USPOST_B)->SetWindowText(m_userpost);
m_idtype = pList->GetItemText(nItem-1,4);
GetDlgItem(IDC_COMBO_IDTYPE_B)->SetWindowText(m_idtype);
m_useridnum = pList->GetItemText(nItem-1,5);
GetDlgItem(IDC_USIDNO_B)->SetWindowText(m_useridnum);
m_usertel = pList->GetItemText(nItem-1,6);
GetDlgItem(IDC_USTEL_B)->SetWindowText(m_usertel);
m_useraddr = pList->GetItemText(nItem-1,10);
GetDlgItem(IDC_USADD_B)->SetWindowText(m_useraddr);
m_userremark = pList->GetItemText(nItem-1,11);
GetDlgItem(IDC_USREM_B)->SetWindowText(m_userremark);
m_id = atol(m_userid);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -