16,471
社区成员
发帖
与我相关
我的任务
分享
BOOL COprHistClientDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
HWND hWnd;
COPYDATASTRUCT cpd;
cpd.dwData = NULL;
cpd.cbData = NULL;
cpd.lpData = NULL;
hWnd=::FindWindowA(NULL,"操作记录消息发送者");
if(hWnd==NULL)
{
MessageBox("未找到SimuMMI");
}
else
{
switch(pCopyDataStruct->dwData)
{
case GetCopyDataMessage_LoginVerification://登录验证
{CString SQLstr,pw;
Login* pLogin = (Login*)(pCopyDataStruct->lpData);
CurrentOnlineUsers=pLogin->Account;
pw=pLogin->PW;
//SQLstr.Format("select * from operator where account='%s'",CurrentOnlineUsers);
SQLstr.Format("select * from operator where account='%s'",pLogin->Account);
G_READO.Rec(SQLstr);
if (!G_READO.IsRecEmpty())
{
//G_READO.RecClose();
//CTime timeNow;
int nYear, nMonth, nDate,nh,nm,ns;
char timeTemp[timeTempValue];
sprintf_s(timeTemp,"20%s",G_READO.GetFieldValue("OnlineDate"));//加入_s的与不加的区别在于加入的有非法的格式化字符串直接跳出
sscanf_s(timeTemp, "%d-%d-%d", &nYear, &nMonth, &nDate);
sscanf_s(G_READO.GetFieldValue("OnlineTime"),"%d:%d:%d",&nh,&nm,&ns);
CTime timeData(nYear, nMonth, nDate,nh,nm,ns);
//timeNow=CTime::GetCurrentTime();跟踪到此弹出debug错误窗口
SYSTEMTIME stUTC;//用这个也一样!跟踪到此弹出debug错误窗口
//::GetSystemTime(&stUTC);
::GetLocalTime(&stUTC);
CTime timeNow(stUTC);
nYear=stUTC.wYear;
CTimeSpan ts=timeNow-timeData;
if(G_READO.GetFieldValue("pw")!=pw)
{
//MessageBox("密码错误");
cpd.dwData = CopyDataLogin_PWorUSER_ERROR;
::SendMessageTimeout(hWnd,WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cpd,SMTO_ABORTIFHUNG,SendMessageTimeout_time,NULL);
cpd.dwData = NULL;
CurrentOnlineUsers.Format("");
}
else if (G_READO.GetFieldValue("OnlineStatus")!="0")
{
if(ts.GetDays()==0)
{
if(ts.GetMinutes()<=Offline)//设置判断超时时间的长度,单位分钟
{
//MessageBox("此用户当前在线");
cpd.dwData = CopyDataLogin_Online_ERROR;
::SendMessageTimeout(hWnd,WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cpd,SMTO_ABORTIFHUNG,SendMessageTimeout_time,NULL);
cpd.dwData = NULL;
CurrentOnlineUsers.Format("");
}
else
{
//MessageBox("大于1分钟,视为已经掉线,并允许正常登陆");
cpd.dwData = CopyDataLogin_Pass;
G_READO.RecClose();
SQLstr.Format("update operator set OnlineStatus='-1' where account='%s'",CurrentOnlineUsers);
G_READO.Rec(SQLstr);
::SendMessageTimeout(hWnd,WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cpd,SMTO_ABORTIFHUNG,SendMessageTimeout_time,NULL);
cpd.dwData = NULL;
}
}
else
{
//MessageBox("日期大于等于1天,表示已经掉线,允许正常登陆");
cpd.dwData = CopyDataLogin_Pass;
G_READO.RecClose();
SQLstr.Format("update operator set OnlineStatus='-1' where account='%s'",CurrentOnlineUsers);
G_READO.Rec(SQLstr);
::SendMessageTimeout(hWnd,WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cpd,SMTO_ABORTIFHUNG,SendMessageTimeout_time,NULL);
cpd.dwData = NULL;
}
}
else
{
//当前用户不在线
cpd.dwData = CopyDataLogin_Pass;
G_READO.RecClose();
SQLstr.Format("update operator set OnlineStatus='-1' where account='%s'",CurrentOnlineUsers);
G_READO.Rec(SQLstr);
::SendMessageTimeout(hWnd,WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cpd,SMTO_ABORTIFHUNG,SendMessageTimeout_time,NULL);
cpd.dwData = NULL;
}
}
else
{
//用户名错误
//MessageBox("用户名错误");
cpd.dwData = CopyDataLogin_PWorUSER_ERROR;
::SendMessageTimeout(hWnd,WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cpd,SMTO_ABORTIFHUNG,SendMessageTimeout_time,NULL);
cpd.dwData = NULL;
CurrentOnlineUsers.Format("");
}
G_READO.RecClose();}
break;
case GetCopyDataMessage_OnlineVerification://接收在线验证消息
{
if (CurrentOnlineUsers!="")
{
int dy,dm,dd,th,tm,ts;
char dateTemp[dateTempValue],timeTemp[timeTempValue];
CString SQLstr;
CTime timeNow;
timeNow=CTime::GetCurrentTime();
dy=timeNow.GetYear();
dm=timeNow.GetMonth();
dd=timeNow.GetDay();
th=timeNow.GetHour();
tm=timeNow.GetMinute();
ts=timeNow.GetSecond();
sprintf_s(dateTemp,"%d-%d-%d",dy,dm,dd);
sscanf_s(dateTemp,"20%d-%d-%d",&dy,&dm,&dd);
sprintf_s(dateTemp,"%d-%d-%d",dy,dm,dd);
sprintf_s(timeTemp,"%d:%d:%d",th,tm,ts);
SQLstr.Format("update operator set OnlineDate='%s',OnlineTime='%s' where account='%s'",dateTemp,timeTemp,CurrentOnlineUsers);
G_READO.Rec(SQLstr);
}
}
break;
case GetCopyDataMessage_LogoutVerification://注销当前用户
{
if (CurrentOnlineUsers!="")
{
CString SQLstr;
SQLstr.Format("update operator set OnlineStatus='0' where account='%s'",CurrentOnlineUsers);
G_READO.Rec(SQLstr);
CurrentOnlineUsers.Format("");
}
}
break;
case GetCopyDataMessage_OperationRecords://接收操作记录
{
if (CurrentOnlineUsers!="")
{
CString Device,Description,time,SQLstr,flow;
Rec* pRec = (Rec*)(pCopyDataStruct->lpData);
flow.Format("%d",pRec->Flow);
Device=pRec->Device;
Description=pRec->Description;
int dy,dm,dd,th,tm,ts;
char dateTemp[dateTempValue],timeTemp[timeTempValue];
CTime timeNow;
timeNow=CTime::GetCurrentTime();
dy=timeNow.GetYear();
dm=timeNow.GetMonth();
dd=timeNow.GetDay();
th=timeNow.GetHour();
tm=timeNow.GetMinute();
ts=timeNow.GetSecond();
sprintf_s(dateTemp,"%d-%d-%d",dy,dm,dd);
sscanf_s(dateTemp,"20%d-%d-%d",&dy,&dm,&dd);
sprintf_s(dateTemp,"%d-%d-%d",dy,dm,dd);
sprintf_s(timeTemp,"%d:%d:%d",th,tm,ts);
if(Device!="" && Description!="")
{
SQLstr.Format("INSERT INTO rec(OperatorName,flow,OperDate,OperTime,device,description) values('%s','%s','%s','%s','%s','%s')"
,CurrentOnlineUsers,flow,dateTemp,timeTemp,Device,Description);
G_READO.Rec(SQLstr);
G_READO.RecClose();
}
else
{
MessageBox("设备名和操作记录不能为空");
}
}
}
break;
default:
break;
}
}
return CDialogEx::OnCopyData(pWnd, pCopyDataStruct);
}