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

📄 userview.cpp

📁 实现一个图书馆管理系统
💻 CPP
字号:
// UserView.cpp : implementation file
//

#include "stdafx.h"
#include "library.h"
#include "UserView.h"
#include "UserSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUserView
extern CDatabase db;
extern CString CurUser;
extern CString CurPsw;
DWORD WINAPI settime(LPVOID Parameter);

IMPLEMENT_DYNCREATE(CUserView, CFormView)

CUserView::CUserView()
	: CFormView(CUserView::IDD)
{
	//{{AFX_DATA_INIT(CUserView)
	m_psw = _T("");
	m_newpsw2 = _T("");
	m_newpsw1 = _T("");
	//}}AFX_DATA_INIT
}

CUserView::~CUserView()
{
}

void CUserView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUserView)
	DDX_Control(pDX, IDC_STATIC_NAME, m_name);
	DDX_Control(pDX, IDC_STATIC_CLASS, m_class);
	DDX_Control(pDX, IDC_STATIC_SEX, m_sex);
	DDX_Control(pDX, IDC_STATIC_TIME, m_time);
	DDX_Text(pDX, IDC_EDIT_PSW, m_psw);
	DDX_Text(pDX, IDC_EDIT_NEWPSW2, m_newpsw2);
	DDX_Text(pDX, IDC_EDIT_NEWPSW1, m_newpsw1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUserView, CFormView)
	//{{AFX_MSG_MAP(CUserView)
	ON_BN_CLICKED(IDC_BUT_MODIFYPSW, OnButModifypsw)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUserView diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CUserView message handlers

void CUserView::OnButModifypsw() 
{
	// TODO: Add your control notification handler code here
	CUserSet *user=new CUserSet(&db);
	m_psw.TrimRight();
	m_newpsw1.TrimRight();
	m_newpsw2.TrimRight();
	UpdateData();
	if(m_psw.IsEmpty() || m_newpsw1.IsEmpty() || m_newpsw2.IsEmpty())
	{
		MessageBox("所填写的内容不能为空!");
		return;
	}
	if(m_psw!=CurPsw)
	{
		MessageBox("与原密码不符!");
		return;
	}
	if(m_newpsw1!=m_newpsw2)
	{
		MessageBox("两次密码填写不一致!");
		return;
	}
	CurUser.TrimRight();
	user->Open();
	user->MoveFirst();
	user->m_UserID.TrimRight();
	if(user->m_UserID!=CurUser)
	{
		do
		{
			user->MoveNext();
			user->m_UserID.TrimRight();
		}while(user->m_UserID!=CurUser);
	}

	user->m_Password.TrimRight();
	if(user->CanUpdate())
	{
		user->Edit();
		user->m_Password=m_newpsw1;
		user->Update();
		MessageBox("修改密码成功!");
	}
	else
		MessageBox("修改密码失败!");
	user->Close();
}

void CUserView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	::CreateThread(0,0,settime,(LPVOID)m_time.m_hWnd,0,0);
	CUserSet *user=new CUserSet(&db);
	user->Open();
	user->MoveFirst();
	user->m_UserID.TrimRight();
	if(user->m_UserID!=CurUser)
	{
		user->MoveNext();
		user->m_UserID.TrimRight();
		while(user->m_UserID!=CurUser || user->IsEOF())
		{
			user->MoveNext();
			user->m_UserID.TrimRight();
		}
	}
	::SetWindowText(m_name.m_hWnd,user->m_Name);
	CString sex;
	if(user->m_Sex==1) 
		sex="男";
	else 
		sex="女";
	::SetWindowText(m_sex.m_hWnd,sex);
	::SetWindowText(m_class.m_hWnd,user->m_Class);
	user->Close();
}

DWORD WINAPI settime(LPVOID Parameter)
{
	struct HWND__ * hwnd;
	hwnd=(struct HWND__ *)Parameter;
	SYSTEMTIME systime;
	char info[50];
	while(1)
	{
		::GetLocalTime(&systime);
		sprintf(info,"%u年%u月%u日  %u:%u:%u",\
			systime.wYear,systime.wMonth,systime.wDay,systime.wHour,systime.wMinute,systime.wSecond);
		::SetWindowText(hwnd,info);
		Sleep(1000);
	}
	return 0;
}

BOOL CUserView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
    //cs.lpszClass="nick";
	return CFormView::PreCreateWindow(cs);
}

⌨️ 快捷键说明

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