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

📄 accountmanager.cpp

📁 短信群发系统
💻 CPP
字号:
// AccountManager.cpp : implementation file
//

#include "stdafx.h"
#include "notesendsystem.h"
#include "AccountManager.h"
#include "AdoRecordSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAccountManager dialog


CAccountManager::CAccountManager(CWnd* pParent /*=NULL*/)
	: CDialog(CAccountManager::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAccountManager)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

}


void CAccountManager::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAccountManager)
	DDX_Control(pDX, IDC_ACCOUNT_LIST, m_list);
	DDX_Control(pDX, IDC_TAB, m_tab);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAccountManager, CDialog)
	//{{AFX_MSG_MAP(CAccountManager)
	ON_WM_CLOSE()
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
	ON_NOTIFY(NM_CLICK, IDC_ACCOUNT_LIST, OnClickAccountList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAccountManager message handlers

void CAccountManager::OnOK() 
{
	// TODO: Add extra validation here
	
//	CDialog::OnOK();
}

void CAccountManager::OnCancel() 
{
	// TODO: Add extra cleanup here
	
//	CDialog::OnCancel();
}

void CAccountManager::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	delete addaccount;
	delete amendaccount;
	delete amendpwd;
	CDialog::OnCancel();
	CDialog::OnClose();
}



BOOL CAccountManager::OnInitDialog() 
{
	CDialog::OnInitDialog();

	addaccount		= new CPageAddAccount;
	amendaccount	= new CPageAmendAccount;
	amendpwd		= new CPageAmendPwd;
	if (!amendpwd->m_hWnd || !amendaccount->m_hWnd || !amendpwd->m_hWnd)
 	{
		m_tab.InsertItem(0, "添加账户");				
 		m_tab.InsertItem(1, "修改密码");
 		m_tab.InsertItem(2, "修改/删除账户");			//只有管理员可以修改删除帐户
 		addaccount->Create(IDP_ADDACCOUNT, &m_tab);
 		amendpwd->Create(IDP_AMENDPWD, &m_tab);
 		amendaccount->Create(IDP_AMENDACCOUNT, &m_tab);	
 		//设置页面的位置在m_tab控件范围内  		
 		CRect			rs; 		
 		m_tab.GetClientRect(rs); 	
 		rs.top		+= 20; 	
		rs.bottom	-= 4; 	
 		rs.left		+= 4; 	
 		rs.right	-= 4;  		
 		addaccount->MoveWindow(rs); 	
 		amendaccount->MoveWindow(rs); 
 		amendpwd->MoveWindow(rs);  		
 		addaccount->ShowWindow(TRUE); 		
 		m_tab.SetCurSel(0); 
 	}	
 
	//初始化列表控件
	m_list.ModifyStyle(0, LVS_REPORT);
	
	CString	str[3] = {"帐户名", "用户权限", "创建时间"};
	int		i;
	for (i = 0; i < 3; i++)
	{
		m_list.InsertColumn(i, str[i], LVCFMT_LEFT, 160);
	}
	//设置列表控件初始化属性
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);	
 	//读取帐户列表
	UpdateListView();
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	if (pApp->CulUserAuth == 1)
	{
		amendaccount->EnableWindow(FALSE);
		addaccount->EnableWindow(FALSE);
	}
 	
 	return TRUE; 
}

void CAccountManager::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int CurSel; 
	
	CurSel=m_tab.GetCurSel(); 
	
	switch(CurSel) 
	{ 
	case 0:
		addaccount->ShowWindow(TRUE); 		
		amendpwd->ShowWindow(FALSE);
		amendaccount->ShowWindow(FALSE); 
		break;
	case 1:
		addaccount->ShowWindow(FALSE); 		
		amendpwd->ShowWindow(TRUE);
		amendaccount->ShowWindow(FALSE);  
		break;
	case 2:
		addaccount->ShowWindow(FALSE); 
		amendpwd->ShowWindow(FALSE);  
		amendaccount->ShowWindow(TRUE); 
		break;
	default:
		break;
	}
	*pResult = 0;
}


void CAccountManager::UpdateListView()
{
	if( m_list.m_hWnd )
 	m_list.DeleteAllItems();
	//读取用户列表
	CAdoRecordSet			record;
	CString					command;
	CString					acc_type;
	CString					textstr;
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();	
	command.Format("select * from Users");
	pApp->m_pConnection.GetRecordSet(command, record);	
	//读取用户列表到结构体
	AccountInfo				acc_info;
	while (!record.IsEof())
	{
		record.GetValue("ID", acc_info.id);
		record.GetValue("UserName", acc_info.user);
		record.GetValue("Passwd", acc_info.pwd);
		record.GetValue("Authority", acc_info.account_type);
		record.GetValue("CreateTime", acc_info.time);
		pApp->AccountInfoVect.push_back(acc_info);
		record.MoveNext();
	} 
	//显示用户列表
	int len = pApp->AccountInfoVect.size();
	for (int i=0; i<len; i++)
	{
		textstr.Format("%s", pApp->AccountInfoVect[i].user);		
		m_list.InsertItem(i, textstr);
		textstr.Empty();
		if (pApp->AccountInfoVect[i].account_type == 0)
		{
			acc_type = "管理员";
		}
		else
		{
			acc_type = "普通用户";
		}
		textstr.Format("%s", acc_type);
		m_list.SetItemText(i, 1, textstr);			
		textstr.Empty();
		
		textstr = pApp->AccountInfoVect[i].time.Format("%Y-%m-%d %H:%M:%S");
 		m_list.SetItemText(i, 2, textstr);
 		textstr.Empty();
	}
	pApp->AccountInfoVect.clear();
}

void CAccountManager::OnClickAccountList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	//如果用户是在修改密码那个页面,那么显示出当前点击的用户名
	CString			cur_sel_user;
	CString			account_type;
	int				nItem;
	int				acc_type;
	POSITION pos = m_list.GetFirstSelectedItemPosition();
	nItem =	m_list.GetNextSelectedItem(pos);	
	cur_sel_user = m_list.GetItemText(nItem, 0);
	//发送消息给修改用户页面,把当前点击的用户名发给他
	amendpwd->SendMessage(WM_AMENDPWD, (WPARAM)&cur_sel_user, 0);
	//把当前帐户的权限也发送过去
	account_type = m_list.GetItemText(nItem, 1);
	if (account_type == "管理员")
	{
		acc_type = 0;
	}
	else
	{
		acc_type = 1;
	}
	amendaccount->SendMessage(WM_AMENDACCOUNT, (WPARAM)&cur_sel_user, acc_type);
	*pResult = 0;
}



⌨️ 快捷键说明

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