|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "AuthorityMgr.h"
|
|
|
|
|
#include "MsgBox.h"
|
|
|
|
|
#include "FileMgr.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "PropertieMgr.h"
|
|
|
|
|
#include "Propertie.h"
|
|
|
|
|
|
|
|
|
|
#define LAIPU_NAME "laipu"
|
|
|
|
|
#define LAIPU_PASSWORD "laipu"
|
|
|
|
|
#define FILE_PATH _T("\\Parameter\\Authority\\Authority.par")
|
|
|
|
|
|
|
|
|
|
bool CompareUser(CAccount Account1,CAccount Account2)
|
|
|
|
|
{
|
|
|
|
|
return Account1.m_Authority>Account2.m_Authority;
|
|
|
|
|
}
|
|
|
|
|
CAuthorityMgr *gAuthorityMgr = new CAuthorityMgr;
|
|
|
|
|
CAuthorityMgr::CAuthorityMgr(void)
|
|
|
|
|
{
|
|
|
|
|
m_CurAuthority = _USER;//<2F><>ǰȨ<C7B0><C8A8>
|
|
|
|
|
m_AutoFactory = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԱȨ<D4B1><C8A8>
|
|
|
|
|
}
|
|
|
|
|
CAuthorityMgr::~CAuthorityMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CMFCPropertyGridProperty *CAuthorityMgr::CreatGridProperty()
|
|
|
|
|
{
|
|
|
|
|
CString PropertyName;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CString Description;//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
CString Path = _T("AuthorityMgr");//<2F>洢·<E6B4A2><C2B7>
|
|
|
|
|
CString Name;
|
|
|
|
|
//-------------------------------------------------------------------------------//
|
|
|
|
|
PropertyName = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>");
|
|
|
|
|
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
|
|
|
|
|
//-------------------------------------------------------------------------------//
|
|
|
|
|
if(gAuthorityMgr->CheckAuthority(_FACTORY))
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ӳ<EFBFBD><D3B3>
|
|
|
|
|
Name = _T("m_AutoFactory");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CPropertie *pPropertie = new CPropertie;
|
|
|
|
|
pPropertie->SetpVal((void*)&m_AutoFactory);
|
|
|
|
|
pPropertie->SetType(_PROP_TYPE_BOOL);
|
|
|
|
|
pPropertie->SetpModule(this);
|
|
|
|
|
pPropertie->SetPath(Path);
|
|
|
|
|
pPropertie->SetName(Name);
|
|
|
|
|
pPropertie->WriteRead(true);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
PropertyName = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>");
|
|
|
|
|
Description = _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_AutoFactory, Description);
|
|
|
|
|
pGroup->AddSubItem(p);
|
|
|
|
|
|
|
|
|
|
gDevicePropertieMgr.Insert(p, pPropertie);
|
|
|
|
|
}
|
|
|
|
|
//-------------------------------------------------------------------------------//
|
|
|
|
|
return pGroup;
|
|
|
|
|
}
|
|
|
|
|
void CAuthorityMgr::Ini()
|
|
|
|
|
{
|
|
|
|
|
SaveOrLoad(false);//<2F><>ȡ<EFBFBD>ļ<EFBFBD>
|
|
|
|
|
if(m_AutoFactory)
|
|
|
|
|
m_CurAuthority = _FACTORY;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>鵱ǰȨ<C7B0><C8A8>
|
|
|
|
|
bool CAuthorityMgr::CheckAuthority(AUTHORITY_TYPE authority,bool bShowMsgbox)
|
|
|
|
|
{
|
|
|
|
|
if((int)m_CurAuthority >= (int)authority)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(bShowMsgbox)
|
|
|
|
|
{
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
CString str = "<EFBFBD><EFBFBD>Ҫ["+GetAccountName(authority) + "]Ȩ<><C8A8>!";
|
|
|
|
|
MsgBox.Show(str, true);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>¼
|
|
|
|
|
bool CAuthorityMgr::IsLogin()
|
|
|
|
|
{
|
|
|
|
|
return m_CurAuthority != _NO_LOGIN;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ȩ<EFBFBD>ޱ<EFBFBD><DEB1><EFBFBD>δ<EFBFBD><CEB4>¼
|
|
|
|
|
void CAuthorityMgr::Lock()
|
|
|
|
|
{
|
|
|
|
|
SetAuthority(_NO_LOGIN);
|
|
|
|
|
m_CurUserName = "<EFBFBD><EFBFBD>";
|
|
|
|
|
}
|
|
|
|
|
//<2F><>¼
|
|
|
|
|
bool CAuthorityMgr::Login(CString name,CString PassWord)
|
|
|
|
|
{
|
|
|
|
|
bool ret = false;
|
|
|
|
|
AUTHORITY_TYPE authority = GetCurAuthority();
|
|
|
|
|
if(name == LAIPU_NAME && PassWord == LAIPU_PASSWORD)
|
|
|
|
|
{
|
|
|
|
|
ret = true;
|
|
|
|
|
authority = _FACTORY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vector<CAccount>::iterator iter = m_UserVec.begin();
|
|
|
|
|
vector<CAccount>::iterator iter_end = m_UserVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
if((*iter).m_Name == name)
|
|
|
|
|
{
|
|
|
|
|
if((*iter).m_PassWord == PassWord)
|
|
|
|
|
{
|
|
|
|
|
ret = true;
|
|
|
|
|
authority = (*iter).m_Authority;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
MsgBox.Show("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺Ų<EFBFBD>ƥ<EFBFBD><EFBFBD>");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(iter==iter_end)
|
|
|
|
|
{
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
MsgBox.Show("<EFBFBD>˺Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(ret)
|
|
|
|
|
{
|
|
|
|
|
SetAuthority(authority);
|
|
|
|
|
m_CurUserName = name;
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
CString str("<EFBFBD><EFBFBD>¼<EFBFBD>ɹ<EFBFBD>---->");
|
|
|
|
|
str += ("[Type:") + GetCurAccountName() + "]";
|
|
|
|
|
str += ("[Name:") + m_CurUserName + "]";
|
|
|
|
|
MsgBox.Show(str);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
CString CAuthorityMgr::GetAccountName(AUTHORITY_TYPE authority)
|
|
|
|
|
{
|
|
|
|
|
if(authority==_FACTORY)
|
|
|
|
|
return ACCOUNT_FACTORY;
|
|
|
|
|
if(authority==_ADMIN)
|
|
|
|
|
return ACCOUNT_ADMIN;
|
|
|
|
|
if(authority==_USER)
|
|
|
|
|
return ACCOUNT_USER;
|
|
|
|
|
return ACCOUNT_NO_LOGIN;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ǰ<EFBFBD>˻<EFBFBD><CBBB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CString CAuthorityMgr::GetCurAccountName()
|
|
|
|
|
{
|
|
|
|
|
return GetAccountName(GetCurAuthority());
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>ȡ
|
|
|
|
|
void CAuthorityMgr::SaveOrLoad(bool bSave)
|
|
|
|
|
{
|
|
|
|
|
CFileMgr FileMgr;
|
|
|
|
|
char filepath[1024];
|
|
|
|
|
FileMgr.GetFullFilePath(filepath,FILE_PATH);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
|
|
|
|
|
if(bSave)
|
|
|
|
|
{
|
|
|
|
|
CFile file(filepath,CFile::modeReadWrite|CFile::modeCreate);
|
|
|
|
|
CArchive ar(&file,CArchive::store);
|
|
|
|
|
SaveOrLoadExt(ar);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CFile file;
|
|
|
|
|
if(file.Open(filepath,CFile::modeRead))
|
|
|
|
|
{
|
|
|
|
|
CArchive ar(&file,CArchive::load);
|
|
|
|
|
SaveOrLoadExt(ar);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gLogMgr->WriteDebugLog("Ȩ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡʧ<EFBFBD><EFBFBD>", _LOG_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CAuthorityMgr::SaveOrLoadExt(CArchive &ar)
|
|
|
|
|
{
|
|
|
|
|
int size = 0;
|
|
|
|
|
if(ar.IsStoring())
|
|
|
|
|
{
|
|
|
|
|
size = m_UserVec.size();//area <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ar<<size;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ar>>size;
|
|
|
|
|
for(int i=0;i<size;i++)
|
|
|
|
|
{
|
|
|
|
|
CAccount Area;
|
|
|
|
|
m_UserVec.push_back(Area);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<size;i++)
|
|
|
|
|
{
|
|
|
|
|
m_UserVec[i].Serialize(ar);
|
|
|
|
|
}
|
|
|
|
|
if(!ar.IsStoring())
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SortUserVec();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CAuthorityMgr::AddAccount(CAccount Account)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>
|
|
|
|
|
vector<CAccount>::iterator iter = m_UserVec.begin();
|
|
|
|
|
vector<CAccount>::iterator iter_end = m_UserVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
if((*iter).m_Name == Account.m_Name)
|
|
|
|
|
{
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
CString str(_T("<EFBFBD>û<EFBFBD>:"));
|
|
|
|
|
str += Account.m_Name + "<EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>!";
|
|
|
|
|
MsgBox.Show(str);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_UserVec.push_back(Account);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SortUserVec();
|
|
|
|
|
SaveOrLoad(true);
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
MsgBox.Show("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!");
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>
|
|
|
|
|
void CAuthorityMgr::DelUser(int idx)
|
|
|
|
|
{
|
|
|
|
|
if(gAuthorityMgr->CheckAuthority(_ADMIN,true)==false)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
vector<CAccount>::iterator iter = m_UserVec.begin();
|
|
|
|
|
vector<CAccount>::iterator iter_end = m_UserVec.end();
|
|
|
|
|
for(int i=0;iter!=iter_end;iter++,i++)
|
|
|
|
|
{
|
|
|
|
|
if(i==idx)
|
|
|
|
|
{
|
|
|
|
|
CMsgBox MsgBox;
|
|
|
|
|
|
|
|
|
|
if((*iter).m_Authority>m_CurAuthority)
|
|
|
|
|
{
|
|
|
|
|
MsgBox.Show(_T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CString str(_T("ɾ<EFBFBD><EFBFBD>"));
|
|
|
|
|
str += (*iter).m_Name + "?";
|
|
|
|
|
if(MsgBox.ConfirmOkCancel(str))
|
|
|
|
|
{
|
|
|
|
|
m_UserVec.erase(iter);
|
|
|
|
|
SortUserVec();
|
|
|
|
|
SaveOrLoad(true);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CAuthorityMgr::InsertToList(CListCtrl &List)
|
|
|
|
|
{
|
|
|
|
|
int size = m_UserVec.size();
|
|
|
|
|
for(int i=0;i<size;i++)
|
|
|
|
|
{
|
|
|
|
|
int idx = 0;
|
|
|
|
|
List.InsertItem(i," ");//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
List.SetItemText(i,idx++,GetAccountName(m_UserVec[i].m_Authority));//Ȩ<><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
List.SetItemText(i,idx++,(m_UserVec[i].m_Name));//<2F>û<EFBFBD><C3BB><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CAuthorityMgr::SortUserVec()
|
|
|
|
|
{
|
|
|
|
|
sort(m_UserVec.begin(),m_UserVec.end(),CompareUser);
|
|
|
|
|
}
|