📄 managerdlg.cpp
字号:
// ManagerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "QGZX_InfoPlat.h"
#include "ManagerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CManagerDlg property page
IMPLEMENT_DYNCREATE(CManagerDlg, CPropertyPage)
CManagerDlg::CManagerDlg() : CPropertyPage(CManagerDlg::IDD)
{
//{{AFX_DATA_INIT(CManagerDlg)
m_strID = _T("");
m_strName = _T("");
m_strPassword = _T("");
m_strAccount = _T("");
//}}AFX_DATA_INIT
m_ds = new CData();
m_ds->InitData();
}
CManagerDlg::~CManagerDlg()
{
}
void CManagerDlg::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CManagerDlg)
DDX_Control(pDX, IDC_LIST_MANAGER, m_listManager);
DDX_Text(pDX, IDC_EDIT_ID, m_strID);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassword);
DDX_Text(pDX, IDC_EDIT_ACCOUNT, m_strAccount);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CManagerDlg, CPropertyPage)
//{{AFX_MSG_MAP(CManagerDlg)
ON_EN_CHANGE(IDC_EDIT_ID, OnChangeEditId)
ON_EN_KILLFOCUS(IDC_EDIT_ID, OnKillfocusEditId)
ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
ON_NOTIFY(NM_CLICK, IDC_LIST_MANAGER, OnClickListManager)
ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CManagerDlg message handlers
BOOL CManagerDlg::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
((CButton*)GetDlgItem(IDC_RADIO_COMMON))->SetCheck(BST_CHECKED);
m_listManager.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_listManager.InsertColumn(0, "管理员编号", LVCFMT_LEFT, 80);
m_listManager.InsertColumn(1, "登录帐号", LVCFMT_LEFT, 100);
m_listManager.InsertColumn(2, "管理员姓名", LVCFMT_LEFT, 90);
m_listManager.InsertColumn(3, "权限", LVCFMT_LEFT, 80);
RefreshListView(NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CManagerDlg::OnChangeEditId()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CPropertyPage::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
((CButton*)GetDlgItem(IDC_BTN_ADD))->EnableWindow(TRUE);
// TODO: Add your control notification handler code here
}
void CManagerDlg::OnKillfocusEditId()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE); //数据将要返回
if(m_strID == "")
{
((CButton*)GetDlgItem(IDC_BTN_ADD))->EnableWindow(FALSE);
}
}
void CManagerDlg::OnBtnAdd()
{
// TODO: Add your control notification handler code here
CString strRadioCheck = 3; //1 普通管理员 0 系统管理员 2 guest
CString strSQL;
UpdateData(TRUE);
if(this->m_strID == "" || this->m_strAccount == "" ||
this->m_strName == "" || this->m_strPassword == "")
{
MessageBox("提示:输入的信息不完整!", "提示", MB_ICONINFORMATION | MB_OK);
return;
}
else
{
//判断Radio按钮
if(((CButton*)GetDlgItem(IDC_RADIO_COMMON))->GetCheck() == 1)
{
strRadioCheck = "1";
}
else if(((CButton*)GetDlgItem(IDC_RADIO_SYS))->GetCheck() == 1)
{
strRadioCheck = "0";
}
else if(((CButton*)GetDlgItem(IDC_RADIO_GUEST))->GetCheck() == 1)
{
strRadioCheck = "2";
}
if(strRadioCheck == 3)
{
MessageBox("提示:请选择管理员权限!", "提示", MB_ICONINFORMATION | MB_OK);
return;
}
strSQL.Format("Insert Into _tSysManager(ManagerID, ManagerAccount, \
ManagerName, Password, Power) values('%s', '%s', '%s', '%s', '%s')",\
this->m_strID, this->m_strAccount, this->m_strName, \
this->m_strPassword, strRadioCheck);
m_ds->ExecuteOther(strSQL);
MessageBox("提示:添加管理员成功!", "提示", MB_ICONINFORMATION | MB_OK);
RefreshListView(NULL);
}
}
BOOL CManagerDlg::RefreshListView(CListCtrl *listview)
{
int nRecordCount = 0;
m_listManager.DeleteAllItems();
m_ds->ExecuteSQL("Select * From _tSysManager");
nRecordCount = m_ds->GetRecordCount();
for(int i = 0; i < nRecordCount; i++)
{
m_listManager.InsertItem(i, "");
m_listManager.SetItemText(i, 0 , m_ds->GetAsString("ManagerID"));
m_listManager.SetItemText(i, 1 , m_ds->GetAsString("ManagerAccount"));
m_listManager.SetItemText(i, 2 , m_ds->GetAsString("ManagerName"));
m_listManager.SetItemText(i, 3 , m_ds->GetAsString("Power"));
m_ds->MoveNext();
}
return TRUE;
}
void CManagerDlg::OnClickListManager(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nCurRow;
CString strPower;
nCurRow = m_listManager.GetSelectionMark();
this->m_strID = m_listManager.GetItemText(nCurRow, 0);
this->m_strAccount = m_listManager.GetItemText(nCurRow, 1);
this->m_strName = m_listManager.GetItemText(nCurRow, 2);
strPower = m_listManager.GetItemText(nCurRow, 3);
if(strPower == "1")
{
((CButton*)GetDlgItem(IDC_RADIO_COMMON))->SetCheck(BST_CHECKED);
((CButton*)GetDlgItem(IDC_RADIO_SYS))->SetCheck(BST_UNCHECKED);
((CButton*)GetDlgItem(IDC_RADIO_GUEST))->SetCheck(BST_UNCHECKED);
}
else if(strPower == "2")
{
((CButton*)GetDlgItem(IDC_RADIO_GUEST))->SetCheck(BST_CHECKED);
((CButton*)GetDlgItem(IDC_RADIO_COMMON))->SetCheck(BST_UNCHECKED);
((CButton*)GetDlgItem(IDC_RADIO_SYS))->SetCheck(BST_UNCHECKED);
}
else if(strPower == "0")
{
((CButton*)GetDlgItem(IDC_RADIO_SYS))->SetCheck(BST_CHECKED);
((CButton*)GetDlgItem(IDC_RADIO_COMMON))->SetCheck(BST_UNCHECKED);
((CButton*)GetDlgItem(IDC_RADIO_GUEST))->SetCheck(BST_UNCHECKED);
}
else
{
MessageBox("错误:管理员权限不存在,请重新选择权限期!", "权限错误", MB_ICONERROR | MB_OK);
}
// ((CButton*)GetDlgItem(IDC_BTN_ALTER))->EnableWindow(TRUE);
((CButton*)GetDlgItem(IDC_BTN_DEL))->EnableWindow(TRUE);
UpdateData(FALSE);
*pResult = 0;
}
void CManagerDlg::OnBtnDel()
{
// TODO: Add your control notification handler code here
int nCurRow;
CString strManagerID, strSQL;
nCurRow = m_listManager.GetSelectionMark();
strManagerID = m_listManager.GetItemText(nCurRow, 0);
strSQL.Format("Delete From _tSysManager Where ManagerID = '%s'", strManagerID);
m_ds->ExecuteOther(strSQL);
RefreshListView(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -