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

📄 usermanagedlg.cpp

📁 家庭财务管理系统
💻 CPP
字号:
// UserManageDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Money.h"
#include "UserManageDlg.h"

#include "UserEditDlg.h"
#include "COMDEF.H"
#include "Columns.h"
#include "Column.h"
#include "_recordset.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUserManageDlg dialog


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


void CUserManageDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUserManageDlg)
	DDX_Control(pDX, IDC_ADODC1, m_adodc);
	DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUserManageDlg, CDialog)
	//{{AFX_MSG_MAP(CUserManageDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
	ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUserManageDlg message handlers

//刷新数据
void CUserManageDlg::RefreshData()
{
	//设置记录源
	CString cSource;
	cSource = "SELECT UserId AS 代码,UserName AS 用户名,UserPwd AS 密码,UserType AS 用户类型"
		" FROM Users "
		" ORDER BY UserName";

	m_adodc.SetRecordSource(cSource);
	m_adodc.Refresh();
	//设置表格列宽度
	_variant_t vIndex;
	vIndex = long(0);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(30);
	vIndex = long(1);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
	vIndex = long(2);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(30);
	vIndex = long(3);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(100);

}

void CUserManageDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	CUserEditDlg dlg;
	dlg.iUserType = 2;
	if (dlg.DoModal() == IDOK)
		RefreshData(); 
}

void CUserManageDlg::OnDelButton() 
{
	UpdateData(TRUE);
	// TODO: Add your control notification handler code here
	if (m_adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要修改的记录");
		return;
	}

	if (m_datagrid.GetItem(0) == "xgwang")
	{
		MessageBox("不能删除xgwang用户");
		return;
	}
	if (MessageBox("是否删除当前用户","请确认", MB_YESNO) == IDYES)
	{
		CUsers usr;
		usr.sql_delete(m_datagrid.GetItem(1));
		RefreshData();
	}
	
}

void CUserManageDlg::OnModiButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if (m_adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要修改的记录");
		return;
	}
	//编辑用户信息
	CUserEditDlg dlg;
	
	dlg.cUserName = m_datagrid.GetItem(1);
	dlg.m_UserName = m_datagrid.GetItem(1);
	if(m_datagrid.GetItem(3) == "系统管理员")
		dlg.iUserType = 1;
	else
		dlg.iUserType = 2;
	if (dlg.DoModal() == IDOK)
		RefreshData(); 

}

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

BOOL CUserManageDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	RefreshData();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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