?? usermanage.cpp
字號:
// UserManage.cpp : implementation file
//
#include "stdafx.h"
#include "libraryMS.h"
#include "UserManage.h"
/////////////////////////////////////////////
#include "column.h"
#include "columns.h"
////////////////////////////////////////////
#include "datagrid.h"
#include "adodc.h"
#include "ADOConn.h"
#include "UserAdd.h"
#include "UserChange.h"
#include "LogLibrary.h"
////////////////////////////////////////////////
#include "COMDEF.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _bstr_t ConnectionString;
extern _bstr_t UserID;
extern _bstr_t Password;
extern _bstr_t strConnect;
/////////////////////////////////////////////////////////////////////////////
// CUserManage dialog
CUserManage::CUserManage(CWnd* pParent /*=NULL*/)
: CDialog(CUserManage::IDD, pParent)
{
//{{AFX_DATA_INIT(CUserManage)
m_QUser = _T("");
//}}AFX_DATA_INIT
}
void CUserManage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUserManage)
DDX_Control(pDX, IDC_Condition, m_condition);
DDX_Control(pDX, IDC_ADODC1, m_adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
DDX_Text(pDX, IDC_User_EDIT, m_QUser);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUserManage, CDialog)
//{{AFX_MSG_MAP(CUserManage)
ON_BN_CLICKED(IDAdd, OnAdd)
ON_BN_CLICKED(IDC_exit, Onexit)
ON_BN_CLICKED(IDC_change, Onchange)
ON_BN_CLICKED(IDDelete, OnDelete)
ON_BN_CLICKED(IDC_Query, OnQuery)
ON_BN_CLICKED(IDC_QueryAll, OnQueryAll)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUserManage message handlers
BOOL CUserManage::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_condition.SetCurSel(0);
UpdateData(false);
m_adodc.SetConnectionString(strConnect);
//m_adodc.SetRecordSource("SELECT IDUser as 用戶名,NameUser as 身份, PaswUser as 用戶密碼 FROM t_User");
m_adodc.Refresh();
/* _variant_t vIndex;
vIndex = long(0);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(80);
vIndex = long(1);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(90);
*/
//vIndex = long(2);
//m_datagrid.GetColumns().GetItem(vIndex).SetWidth(80);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CUserManage::OnAdd()
{
// TODO: Add extra validation here
CUserAdd add_dlg;
add_dlg.DoModal();
m_adodc.Refresh();
}
BEGIN_EVENTSINK_MAP(CUserManage, CDialog)
//{{AFX_EVENTSINK_MAP(CUserManage)
//ON_EVENT(CUserManage, IDC_DATAGRID1, -601 /* DblClick */, OnDblClickDatagrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
//DEL void CUserManage::OnDblClickDatagrid1()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL CString sRecord;
//DEL sRecord = "用戶名:"+m_datagrid.GetItem(0)+"\n";
//DEL sRecord += "身份:"+m_datagrid.GetItem(1)+"\n";
//DEL sRecord += "密碼:"+m_datagrid.GetItem(2)+"\n";
//DEL
//DEL MessageBox(sRecord);
//DEL
//DEL }
void CUserManage::Onexit()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CUserManage::Onchange()
{
// TODO: Add your control notification handler code here
//if(m_datagrid.GetItem(0))
CUserChange change_dlg;
change_dlg.m_IDUser = m_datagrid.GetItem(0);
change_dlg.m_NameUser = m_datagrid.GetItem(1);
change_dlg.m_PwdUser = m_datagrid.GetItem(2);
change_dlg.DoModal();
m_adodc.Refresh();
}
//DEL void CUserManage::OnRefresh()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL m_adodc.Refresh();
//DEL
//DEL }
void CUserManage::OnDelete()
{
// TODO: Add your control notification handler code here
// if(m_adodc.GetRecordset().GetEof() == 1)
// {
// MessageBox("沒有數據");
// return;
// }
CUsers user;
user.SetIDUser (m_datagrid.GetItem(0));
user.SetNameUser (m_datagrid.GetItem(1));//刪除功能可以不用設置NameUser
//user.SetPwdUser (m_datagrid.GetItem(2));//刪除功能可以不用設置PwdUser
CString str;
if(user.GetNameUser() == "超級管理員")
{
MessageBox("超級管理員不能刪除");
return;
}
str="ID: "+user.GetIDUser()+"\n"+"身份: "+user.GetNameUser()+"\n";
int nChoice = MessageBox(str,"確定要刪除嗎",MB_OKCANCEL|MB_ICONQUESTION);
if(nChoice == IDOK)
{
CLogLibrary Log_dlg;
Log_dlg.DoModal();
user.SetLogUser(Log_dlg.m_logMS);
MessageBox("刪除進行");
user.sql_delete(user.GetIDUser());
}
m_adodc.Refresh();
}
void CUserManage::OnQuery()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_adodc.SetRecordSource("SELECT IDUser as 用戶名, NameUser as 身份, PwdUser as 用戶密碼 FROM t_User where IDUser = '"+m_QUser+"'");
m_adodc.Refresh();
}
void CUserManage::OnQueryAll()
{
// TODO: Add your control notification handler code here
m_adodc.SetRecordSource("SELECT IDUser as 用戶名, NameUser as 身份, PwdUser as 用戶密碼 FROM t_User ");
m_adodc.Refresh();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -