⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdf.cpp

📁 MDF监控源码2
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		strTime = CTime::GetCurrentTime().Format ( "%Y-%m-%d %H:%M:%S" ) ;	//获取当前时间

		strTemp = "\r\n > "+strTip + "... \r\n > " + strTime ;
		strShow = m_strTip ;
		m_strTip.Empty() ;
		m_strTip = strShow + strTemp ;
		m_pMainWnd->SetDlgItemText(IDC_SHOW,m_strTip) ;
		
		//定位位置条
		int linenum=((CEdit *)(m_pMainWnd->GetDlgItem(IDC_SHOW)))->GetLineCount();
		((CEdit *)(m_pMainWnd->GetDlgItem(IDC_SHOW)))->LineScroll(linenum);
		
		WriteTxtLog(strTemp) ;
		return 0;
	//}
	//catch(_com_error e)
	//{
	//	strTip.Format("CMDFApp::Show 发生异常:%s",(LPCSTR)e.Description()) ;
	//	WriteTxtLog(strTip) ;
	//	return -1 ;
	//}
}

//##ModelId=465286A2002E
int CMDFApp::Refresh()
{
	return 0 ;
}

//##ModelId=465286A20021
int CMDFApp::ReStart()
{
	CString strTip ;
	try
	{
		if( m_bReStart )
			return 1 ;
		m_bReStart = TRUE ;
		strTip.Format("系统:MDF 监测中心 进行重启") ;
		Show(strTip) ;
		theApp.OutPut(strTip) ;
		//m_pComm->StopComm();
		//m_pComm->StartComm();

		m_bReStart = FALSE ;
	}
	catch(_com_error e)
	{
		strTip.Format("异常:关闭Web服务时 发生异常:%s",(LPCSTR)e.Description()) ;
		theApp.OutPut(strTip) ;
		return -1 ;
	}

	return 0 ;
}


//##ModelId=465286A103AB
BOOL CMDFApp::WriteTxtLog(CString strTxt)
{
	CString strPath,strTime;
	CFile fileLog ;
	char *cbuf;
	int nRet ;
	CMutex mutex;
	try
	{
		cbuf = new char[strTxt.GetLength()];
		cbuf = strTxt.GetBuffer();
		cbuf[strTxt.GetLength()] = '\0';
		if (dlgServer)
		{
			SendMessage(dlgServer->m_hWnd,WM_SHOWLOG,(WPARAM)cbuf,0);
		}
		if (m_Baseinfo.SaveLog == 1)
		{
			strTime = CTime::GetCurrentTime().Format ( "%Y-%m-%d %H:%M:%S" ) ;	//获取当前时间
			mutex.Lock();
			strPath = m_strPath + "Data\\log.txt" ;
			if (!PathFileExists((LPCTSTR)strPath))
				nRet = fileLog.Open( strPath, CFile::modeReadWrite | CFile::modeCreate );
			else
				nRet = fileLog.Open( strPath, CFile::modeWrite | CFile::modeRead );

			if(nRet)
			{
				fileLog.SeekToEnd();
				strTime += " ";
				strTime += strTxt;
				strTime += "\r\n";
				fileLog.Write(strTime.GetBuffer(0),strTime.GetLength()) ;
				if (m_Baseinfo.SaveLog == 1 && m_pAdoDB->GetConnectState() )
				{
					m_pAdoDB->WriteLog(strTime);
				}
			}
			fileLog.Close() ;
			mutex.Unlock();
			if (nRet) 
				return TRUE;
			else
				return FALSE;
		}
		
	}
	catch(_com_error e)
	{
		CString strTip ;
		strTip.Format("异常:CMDFApp::AddDebugAlarm() 发生异常:%s",(LPCSTR)e.Description()) ;
		TRACE(strTip);
		return FALSE ;
	}
	return FALSE;
}



// 输出函数
//##ModelId=465286A200EF
int CMDFApp::OutPut(CString sNote)
{
	//输出信息到调试窗口
	if (sNote.GetLength() == 0)
		return 0;
	WriteTxtLog(sNote);
	return 0;
}

// 初始化基本配置信息
//##ModelId=465286A2010C
int CMDFApp::IniBaseInfo(CBaseInfo & m_Info)
{
	CString strSQL,strTable,strTip,strField,strValue ;		//SQL语句
	_variant_t var;
	int iResult;
	_RecordsetPtr pRsPtr ;
	int iValue;
	m_Baseinfo.DBIP			= _T("192.168.1.27");
	m_Baseinfo.DBNam		= _T("CM2005DB");
	m_Baseinfo.UserID		= _T("sa");
	m_Baseinfo.UserPassword	= _T("");
	m_Baseinfo.WebPort		= 9001;
	m_Baseinfo.DevicePort	= 9002;
	m_Baseinfo.GSMPort		= 1;
	m_Baseinfo.SMSCenter	= _T("8613800755500");
	m_Baseinfo.SMSOpen		= FALSE;
	m_Baseinfo.VoiceOpen	= FALSE;
	m_Baseinfo.SMSOpen		= FALSE;
	m_Baseinfo.Interval		= 500;
	m_Baseinfo.SaveLog		= 0;
	m_Baseinfo.PlaySound    = 1;
	m_Baseinfo.Autostart	= 1;
	
	/********************************************/
	//因数据表更改,使用默认值,后续更改。
	//return(0);
	/********************************************/
	
	pRsPtr.CreateInstance(__uuidof(Recordset));
	strSQL = "Select * From CMTParamSet Order By paramID ";
	
	iResult = m_pAdoDB->ReadDB(strSQL,pRsPtr,strTip);
	if(iResult == 0)
	{
		while (!pRsPtr->adoEOF)
		{
			m_pAdoDB->GetFieldValue("paramName",pRsPtr,strField);
			if (strField.Compare("WEBPORT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.WebPort);		//WEB接收端口
			}else if (strField.Compare("DEVICEPORT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.DevicePort);		//设备监测端口
			}else if (strField.Compare("GSMPORT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,strValue);					//GSM发送端口
				strValue.Replace("COM","");
				iValue = atoi(strValue.GetBuffer());
				m_Baseinfo.GSMPort = iValue;
			}else if (strField.Compare("SMSCENTER") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.SMSCenter);		//短信息中心号码
			}else if (strField.Compare("SERVERPORT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.ServerPort);		//与WEB服务接收端口
			}else if (strField.Compare("ISSENDMSG") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.Phone);			//短信电话号码
			}else if (strField.Compare("ISPLAYSOUND") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.CallTel);		//语音告警号码
			}else if (strField.Compare("INTERVAL") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.Interval);		//轮询时间间隔(毫秒)
			}else if (strField.Compare("WEBIP") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.WebIP);			//WEB服务器的IP地址
			}else if (strField.Compare("SAVELOG") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.SaveLog);		//保存日志
			}else if (strField.Compare("AUTOSTART") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.Autostart);		//是否自动起动监测服务
			}else if (strField.Compare("PLAYSOUND") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.PlaySound);		//是否播放告警声音
			}else if (strField.Compare("CURRENTLEVEL") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.AlarmRange);		//当前选定告警范围级别
			}else if (strField.Compare("GSMBORT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.GSMBORT);		//GSMMODEM波特率
			}else if (strField.Compare("GSMDBIT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.GSMDBIT);		//GSMMODEM数据位
			}else if (strField.Compare("GSMCBIT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.GSMCBIT);		//GSMMODEM校验位
			}else if (strField.Compare("GSMSBIT") == 0)
			{
				m_pAdoDB->GetFieldValue("paramValue",pRsPtr,m_Baseinfo.GSMSBIT);		//GSMMODEM停止位
			}
			pRsPtr->MoveNext();
		}
		pRsPtr->Close();
	}
	
	//pRsPtr.Release();

	return 0;
}

// 重新起动监测服务
//##ModelId=465286A20119
BOOL CMDFApp::RestartMonitoring(void)
{
	BOOL bResult = FALSE ;
	CString strNote;
	if (m_Baseinfo.MonitorStatus)
	{
		bResult = m_pMonitor->StopMonitoring();
		if(bResult )
		{
			delete m_pMonitor;
			m_Baseinfo.MonitorStatus = 0;
			strNote = "监测服务器已经关闭...";
			m_pMonitor = new CMonitor();
			if(m_pMonitor->StartMonitoring())
				if (m_pMonitor->StartAsking(100))
				{
					m_Baseinfo.MonitorStatus = 1;
					return(TRUE);
				}
		}
		else
			strNote = "监测服务器正在忙,还未关闭,请稍候重试...";
	}
	return FALSE;
}

//##ModelId=465286A2011B
void CMDFApp::OnCmStop()
{
	StopMonitoring();
}

// 起动监测服务
BOOL CMDFApp::StartMonitoring(void)
{
	BOOL bResult = FALSE ;
	CString strNote;
	if (m_Baseinfo.MonitorStatus != TRUE)
	{	
		strNote = "准备起动监测服务器...";
		WriteTxtLog(strNote);
		if(!m_pMonitor)
			m_pMonitor = new CMonitor();
		
		if(m_pMonitor->StartMonitoring())
		{
			Sleep(1000);
			if (m_pMonitor->StartAsking(500))
			{
				m_Baseinfo.MonitorStatus = 1;
				strNote = "监测服务器起动成功...";
				WriteTxtLog(strNote);
				bResult = TRUE;
				PostMessage(dlgServer->m_hWnd,WM_SERVICESTATUS,1,NULL);
			}
			else
				PostMessage(dlgServer->m_hWnd,WM_SERVICESTATUS,0,NULL);
		}else
			PostMessage(dlgServer->m_hWnd,WM_SERVICESTATUS,0,NULL);

		//起动GSM MODEM设备
		if (!m_Baseinfo.SMSOpen )
		{
			bResult = m_pMonitor->IniGsmInfo();
			m_Baseinfo.SMSOpen = bResult;
		}
	}else
	{
		strNote = "监测服务器正在运行...";
		WriteTxtLog(strNote);
		bResult = FALSE;
	}
	return bResult;
}

// 停止监测服务
//##ModelId=465286A2012B
BOOL CMDFApp::StopMonitoring(void)
{
	BOOL bResult = FALSE;	
	if(m_Baseinfo.MonitorStatus == 1  )
	{

		m_pMonitor->StopAnalyseing();
		Sleep(200);
		bResult = m_pMonitor->StopMonitoring();

		if (bResult)
			PostMessage(dlgServer->m_hWnd,WM_SERVICESTATUS,0,NULL);
	}


	if (m_Baseinfo.SMSOpen)
	{
		bResult = m_pMonitor->ClsoeGSM();
		if(bResult == TRUE)
		{
			m_Baseinfo.SMSOpen = FALSE;
		}
		else
		{
			m_Baseinfo.SMSOpen = TRUE;
		}
	}

	delete m_pMonitor;
	m_pMonitor = NULL;

	if (bResult)
	{
		m_Baseinfo.MonitorStatus = 0;
		bResult = TRUE;
		WriteTxtLog("监测服务器已经停止运行...");
	}
	else
	{
		bResult = FALSE;
		m_Baseinfo.MonitorStatus = 1;
		WriteTxtLog("监测服务器正在忙,稍后在停止...");

	}
	return bResult;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -