⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useraddview.cpp

📁 酒店电子锁管理
💻 CPP
字号:
// UserAddView.cpp : implementation file
//

#include "stdafx.h"
#include "lock.h"
#include "UserAddView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// UserAddView

IMPLEMENT_DYNCREATE(UserAddView, CFormView)

UserAddView::UserAddView()
	: CFormView(UserAddView::IDD)
{
	//{{AFX_DATA_INIT(UserAddView)
	//}}AFX_DATA_INIT
}

UserAddView::~UserAddView()
{
}

void UserAddView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(UserAddView)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(UserAddView, CFormView)
	//{{AFX_MSG_MAP(UserAddView)
	ON_BN_CLICKED(IDC_ADURQUIT_A, OnAdurquitA)
	ON_BN_CLICKED(IDOK, OnOK)
	ON_BN_CLICKED(IDCANCEL, OnCancel)
	ON_NOTIFY(NM_CLICK, IDC_LIST_USER_ADD, OnClickListUserAdd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// UserAddView diagnostics

#ifdef _DEBUG
void UserAddView::AssertValid() const
{
	CFormView::AssertValid();
}

void UserAddView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// UserAddView message handlers

void UserAddView::OnOK() 
{
	// TODO: Add your control notification handler code here

// 	CString m_userid;
// 	CString	m_username;
	GetDlgItem(IDC_USNAME_A)->GetWindowText(m_username);
// 	CString m_sex;
	GetDlgItem(IDC_COMBO_SEX_A)->GetWindowText(m_sex);
//	CString m_BirthDay;
	GetDlgItem(IDC_BIRTHDAY_A)->GetWindowText(m_BirthDay);
// 	CString	m_usercom;
	GetDlgItem(IDC_USCOM_A)->GetWindowText(m_usercom);
// 	CString	m_userdep;
	GetDlgItem(IDC_USDEP_A)->GetWindowText(m_userdep);
// 	CString	m_userpost;
	GetDlgItem(IDC_USPOST_A)->GetWindowText(m_userpost);
// 	CString m_idtype;
	GetDlgItem(IDC_COMBO_IDTYPE_A)->GetWindowText(m_idtype);
// 	CString	m_useridnum;
	GetDlgItem(IDC_USIDNO_A)->GetWindowText(m_useridnum);
// 	CString	m_usertel;
	GetDlgItem(IDC_USTEL_A)->GetWindowText(m_usertel);
// 	CString	m_useraddr;
	GetDlgItem(IDC_USADD_A)->GetWindowText(m_useraddr);
// 	CString	m_userremark;
	GetDlgItem(IDC_USREM_A)->GetWindowText(m_userremark);


// 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());
	}
	
	//数据插入测试
	try
	{
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("Name",_variant_t(m_username));
		m_pRecordset->PutCollect("Gender",_variant_t(m_sex));
		m_pRecordset->PutCollect("BirthDay",_variant_t(m_BirthDay));
		m_pRecordset->PutCollect("IDType",_variant_t(m_idtype));
		m_pRecordset->PutCollect("IDNum",_variant_t(m_useridnum));
		m_pRecordset->PutCollect("TelNum",_variant_t(m_usertel));
		m_pRecordset->PutCollect("Company",_variant_t(m_usercom));
		m_pRecordset->PutCollect("Department",_variant_t(m_userdep));
		m_pRecordset->PutCollect("Pos",_variant_t(m_userpost));
		m_pRecordset->PutCollect("HomeAdd",_variant_t(m_useraddr));
		m_pRecordset->PutCollect("Remark",_variant_t(m_userremark));

		//更新数据库
		m_pRecordset->Update();		
		//当前记录移动到最后
		m_pRecordset->MoveLast();
	}
	catch (_com_error e)
	{
		CString strError;
		strError.Format("Warning: exception when insert a record! \n %s", e.ErrorMessage());
		AfxMessageBox(strError);
	}
	
	m_pRecordset->Close();	
	m_pRecordset=NULL;

	AfxMessageBox("插入成功!");

	// DB Grid 中显示

	int nItem;
	CListCtrl * pList = ((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD));
	nItem = pList->InsertItem(0,m_username);
	pList->SetItemText(nItem,1,m_sex);
	pList->SetItemText(nItem,2,m_BirthDay);
	pList->SetItemText(nItem,3,m_usercom);
	pList->SetItemText(nItem,4,m_userdep);
	pList->SetItemText(nItem,5,m_userpost);
	pList->SetItemText(nItem,6,m_idtype);
	pList->SetItemText(nItem,7,m_useridnum);
	pList->SetItemText(nItem,8,m_usertel);
	pList->SetItemText(nItem,9,m_useraddr);
	pList->SetItemText(nItem,10,m_userremark);

	m_username = "";
	GetDlgItem(IDC_USNAME_A)->SetWindowText(m_username);
	m_sex = "";
	GetDlgItem(IDC_COMBO_SEX_A)->SetWindowText(m_sex);
	m_BirthDay = "";
	GetDlgItem(IDC_BIRTHDAY_A)->SetWindowText(m_BirthDay);
	m_usercom = "";
	GetDlgItem(IDC_USCOM_A)->SetWindowText(m_usercom);
	m_userdep = "";
	GetDlgItem(IDC_USDEP_A)->SetWindowText(m_userdep);
	m_userpost = "";
	GetDlgItem(IDC_USPOST_A)->SetWindowText(m_userpost);
	m_idtype = "";
	GetDlgItem(IDC_COMBO_IDTYPE_A)->SetWindowText(m_idtype);
	m_useridnum = "";
	GetDlgItem(IDC_USIDNO_A)->SetWindowText(m_useridnum);
	m_usertel = "";
	GetDlgItem(IDC_USTEL_A)->SetWindowText(m_usertel);
	m_useraddr = "";
	GetDlgItem(IDC_USADD_A)->SetWindowText(m_useraddr);
	m_userremark = "";
	GetDlgItem(IDC_USREM_A)->SetWindowText(m_userremark);

}


void UserAddView::OnInitialUpdate() 
{


	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(0,"姓名",LVCFMT_CENTER,50);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(1,"性别",LVCFMT_CENTER,50);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(2,"出生日期",LVCFMT_CENTER,70);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(3,"工作单位",LVCFMT_CENTER,70);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(4,"工作部门",LVCFMT_CENTER,70);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(5,"职务",LVCFMT_CENTER,50);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(6,"证件类型",LVCFMT_CENTER,70);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(7,"证件号码",LVCFMT_CENTER,70);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(8,"电话",LVCFMT_CENTER,50);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(9,"地址",LVCFMT_CENTER,50);
	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->InsertColumn(10,"备注",LVCFMT_CENTER,50);

	((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD))->SetExtendedStyle(
          LVS_EX_FLATSB				// 扁平风格滚动
        | LVS_EX_FULLROWSELECT		// 允许正航选中
        | LVS_EX_HEADERDRAGDROP		// 允许标题拖拽
        | LVS_EX_GRIDLINES			// 画出网格线
        ) ;
}

void UserAddView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CFormView::CalcWindowRect(lpClientRect, nAdjustType);
}

void UserAddView::OnCancel() 
{
	MessageBox("Cancel");
	// TODO: Add your control notification handler code here
	m_username = "";
	GetDlgItem(IDC_USNAME_A)->SetWindowText(m_username);
	m_sex = "";
	GetDlgItem(IDC_COMBO_SEX_A)->SetWindowText(m_sex);
	m_BirthDay = "";
	GetDlgItem(IDC_BIRTHDAY_A)->SetWindowText(m_BirthDay);
	m_usercom = "";
	GetDlgItem(IDC_USCOM_A)->SetWindowText(m_usercom);
	m_userdep = "";
	GetDlgItem(IDC_USDEP_A)->SetWindowText(m_userdep);
	m_userpost = "";
	GetDlgItem(IDC_USPOST_A)->SetWindowText(m_userpost);
	m_idtype = "";
	GetDlgItem(IDC_COMBO_IDTYPE_A)->SetWindowText(m_idtype);
	m_useridnum = "";
	GetDlgItem(IDC_USIDNO_A)->SetWindowText(m_useridnum);
	m_usertel = "";
	GetDlgItem(IDC_USTEL_A)->SetWindowText(m_usertel);
	m_useraddr = "";
	GetDlgItem(IDC_USADD_A)->SetWindowText(m_useraddr);
	m_userremark = "";
	GetDlgItem(IDC_USREM_A)->SetWindowText(m_userremark);	
}

void UserAddView::OnAdurquitA() 
{
	// TODO: Add your control notification handler code here
	CLockApp * pApp = (CLockApp *)AfxGetApp();

	pApp->SwitchView(0);
	
}

	//AfxMessageBox("Item ckicked!");





void UserAddView::OnClickListUserAdd(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
/************************************************************************/
/* Choose an item                                                       */
/************************************************************************/
// 	CListCtrl * pList = ((CListCtrl *)GetDlgItem(IDC_LIST_USER_ADD));
// 	POSITION pos = pList->GetFirstSelectedItemPosition();
// 
// 	int nItem = (int) pos;
// 
// 	CString output;
// 	output.Format("Choose item %d",nItem);
// 
// 	AfxMessageBox(output);

	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -