Remark by Jimmy on June 4th 2010 am
According to the user's cost profit center set limit to subscribers,So that the largest number of user login to control the ERP.
X++ code below as:
the method inside of sysUserLog table sub insert method.
AX 2009 test successful

User Login Control in ERP ssytem_4thUser Login Control in ERP ssytem_4th_02代码
public void Jimmy_startupPostUserControl()
{
/**
remark by Jimmy on June 4th 2010 am
According to the user's cost profit center set limit to subscribers,So that the largest number of user login to control the ERP.
X++ code below as:
the method inside of sysUserLog table sub insert method.
AX 2009 test successful
*/
SysGlobalCache cache
= appl.globalCache();
info info
= new info();
xSession session;
UserInfo userInfo;
UserId currentUserId;
QVS_UserLoginControl UserLoginControl;
Str
50 costCenter;
int counter;
int num = 0;
int maxSessions = Info::licensedUsersTotal();
;
currentUserId
= curuserid();
for(counter = 1; counter < maxSessions;counter++ )
{
session
= new xSession(counter, true);
if(session && session.userId())
{
select firstOnly userInfo
where userInfo.id == session.userId();

if (userInfo && (currentUserId == session.userId()))
{
num
++ ;
}
}
}

costCenter
= QVS_UserInfo::find(currentUserId).Dimension[2];
select firstonly UserLoginControl
where UserLoginControl.Dimension[2] == costCenter
&& UserLoginControl.Actived == Noyes::Yes;

if(num > UserLoginControl.counts && UserLoginControl)
{
box::info(strfmt(
"The current user (%1) has exceeded the departments's (%2) set to the maximum extent( %3 ).",currentUserId,costCenter,numeralsToTxt_CN(UserLoginControl.counts,false,false,5)));
cache.
set(classstr(info), identifierstr(Autologoff), true);//自动注销保存当前所有操作
info.shutDown(true);
infolog.shutDown(
true);
return ;
}
if (num > 1 && !UserLoginControl)
{

info(strfmt(
"%1,%2",costCenter,num));
box::info(strfmt(
"The same user %1 can't log in twice",currentUserId));
cache.
set(classstr(info), identifierstr(Autologoff), true);//自动注销保存当前所有操作
info.shutDown(true); //
infolog.shutDown(true);
return;

/*
if(box::yesno("The same user id can't log in twice. Do you want to log in anyway? ",
DialogButton::Yes, "Log in", "Log out") == DialogButton::No)
{
infolog.shutDown(true);
}
*/
}

}