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

📄 mdf.cpp

📁 电信机房MDF、电源柜监控源码,主要用在通信机房配线设备监控、电源柜监控
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MDF.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "mdf.h"
#include "Atlbase.h"
#include "Shlwapi.h"
#include "afxmt.h"

#include "MainFrm.h"
#include "SerialDoc.h"
#include "LeftView.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#define WM_SHOW WM_USER + 1
/////////////////////////////////////////////////////////////////////////////
// CMDFApp

BEGIN_MESSAGE_MAP(CMDFApp, CWinApp)
	//{{AFX_MSG_MAP(CMDFApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	//ON_COMMAND(ID_HELP, CWinApp::OnHelp)
	
	ON_COMMAND(ID_CM_STOP, OnCmStop)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMDFApp construction

//##ModelId=44B6F8850322
CMDFApp::CMDFApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
	
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMDFApp object

CMDFApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMDFApp initialization

//##ModelId=44B6F885032C
BOOL CMDFApp::InitInstance()
{
	
	InitCommonControls();

	CWinApp::InitInstance();

	//数据库嵌入对象初始化

	// 初始化 OLE 库
	if (!AfxOleInit())
	{
		AfxMessageBox(_T("OLE初始化失败..."));
		return FALSE;
	}
	AfxEnableControlContainer();


	//通讯函数初始化
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}
	LoadIcon(IDR_MAINFRAME);
	

	//#ifdef _AFXDLL
	//	Enable3dControls();			// Call this when using MFC in a shared DLL
	//#else
	//	Enable3dControlsStatic();	// Call this when linking to MFC statically
	//#endif
	//CoInitializeEx(NULL,COINIT_MULTITHREADED);

	/******************************************************************/
	//Task:初始化基本配置信息,增加基本信息的存储及读取函数
	//日期:2006-6-22

	//m_Baseinfo.DBIP			= _T("192.168.0.35");
	//m_Baseinfo.DBNam		= _T("MDFDB");

	m_Baseinfo.DBIP			= _T("192.168.0.34");
	m_Baseinfo.DBNam		= _T("MDFDB");
	
	m_Baseinfo.WebPort		= 8901;
	m_Baseinfo.DevicePort	= 9001;
	m_Baseinfo.GSMPort		= 1;
	m_Baseinfo.SMSCenter	= _T("8613800755500");
	m_Baseinfo.SMSOpen		= TRUE;
	m_Baseinfo.UserID		= _T("sa");
	m_Baseinfo.UserPassword	= _T("");
	m_Baseinfo.VoiceOpen	= FALSE;
	m_Baseinfo.SMSOpen		= FALSE;
	m_Baseinfo.MonitorStatus= 0;
	m_Baseinfo.Autostart	= 0;
	
	/******************************************************************/

	
	/******************************************************************/
	//初始数据库
	DWORD size = MAX_PATH;
	char Buffer[MAX_PATH];
	CRegKey regkey;
	if(regkey.Open(HKEY_LOCAL_MACHINE,"Software\\CenturyMan\\CM2005") == ERROR_SUCCESS)
	{
		memset(Buffer,0,MAX_PATH);
		regkey.QueryValue(Buffer, _T("SERVERNAME"), &size);
		m_Baseinfo.DBIP = Buffer;
		memset(Buffer,0,MAX_PATH);
		regkey.QueryValue(Buffer, _T("DBNAME"), &size);
		m_Baseinfo.DBNam = Buffer;
		memset(Buffer,0,MAX_PATH);
		regkey.QueryValue(Buffer, _T("USERNAME"), &size);
		m_Baseinfo.UserID = Buffer;
		memset(Buffer,0,MAX_PATH);
		regkey.QueryValue(Buffer, _T("PWD"), &size);
		m_Baseinfo.UserPassword = Buffer;
		regkey.Close();

	}
	else
	{
		AfxMessageBox("数据库配置信息不存在,请正确设置数据库服务器信息!");
		//MessageBox("数据库连接失败,请正确设置数据库服务器。" , "连接" , MB_OK);
		PostQuitMessage(WM_QUIT);
		return false;
	}

	m_pAdoDB = new CAdoDB () ;	//创建数据库操作对象

	if (m_pAdoDB->InitDB(m_Baseinfo) == FALSE)
	{
		//TRACE("数据库初始化失败...");
		WriteTxtLog("数据库初始化失败...");
		AfxMessageBox("数据库初始化失败...");
		return 0;
	}
	

	WriteTxtLog("数据库初始完成...");
	
	
	/******************************************************************/	
	//初始系统基本参数
	IniBaseInfo(m_Baseinfo);
	WriteTxtLog("系统基本参数初始完成...");


	/******************************************************************/
	//初始化串口通讯组件
	//取得串口号-->开始-->开始监测

	SetRegistryKey(IDS_STRAPPTITLLE);
	LoadStdProfileSettings(4);  // 加载标准 INI 文件选项(包括 MRU)
	

	//CTestDialog dlg;
	//dlg.DoModal();
	


/*	注释**********************************************/

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CSerialDoc),
		RUNTIME_CLASS(CMainFrame),       // 主 SDI 框架窗口
		RUNTIME_CLASS(CLeftView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);
	// 分析标准外壳命令、DDE、打开文件操作的命令行
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	// 调度在命令行中指定的命令。如果
	// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	
	


	WriteTxtLog("开启主窗体...");
	m_pMainWnd->ShowWindow(SW_HIDE);
	m_pMainWnd->UpdateWindow();
	 
	
	WriteTxtLog("开启控制窗体...");
	dlgServer = new CMDFDlg();
	dlgServer->Create(IDD_MDFMAIN);
	dlgServer->ShowWindow(SW_SHOW);


	//开始监测并轮询设备状态


	m_pMonitor = new CMonitor();
	m_pMonitor->ShowWindow(SW_HIDE);
	if (m_Baseinfo.Autostart== 1)
	{
		if (StartMonitoring())
			WriteTxtLog("服务起动成功...");
	}

	/*注释***********************************************/



	//此部分功能已经用上面的语句替代

	
	/*
	BOOL blResult = m_pMonitor->StartMonitoring();

	if (blResult)
	{
		if(m_pMonitor->StartAsking(1000))
			m_Baseinfo.MonitorStatus = 1;
	}
	*/
	
	/******************************************************************/	

	m_bRefresh = FALSE ;
	m_bReStart = FALSE ;

	m_bTOMsg = FALSE ;
	m_bTOScan = FALSE ;
	m_bTOVoice = FALSE ;
	m_bTOConnect  = FALSE ;

	m_bTest =FALSE; //程序测试时为TRUE,发行时为FALSE 
	m_hRefresh = CreateEvent( NULL, FALSE, TRUE , NULL ) ;
	m_hTxt  = CreateEvent( NULL , FALSE , TRUE , NULL ) ;

	return TRUE;
}

//##ModelId=44B6F885032E
int CMDFApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	//delete m_pComm ;
	
	if (theApp.m_Baseinfo.MonitorStatus == 1 )
	{
		StopMonitoring();	
	}
	m_pAdoDB->CloseDB();
	delete m_pAdoDB ;
	//delete m_pMedia ;

	return CWinApp::ExitInstance();

}

//保存设置文件
//##ModelId=44B6F88502FE
int CMDFApp::WriteINI(CString strSys)
{
	CFile file ;
	CString strError ;
	CString strPath ;
	//int i,k ;
	int nCount,nKNum ;
	const char cKey[] ={ 0x0F,0x08,0x0B,0x01,0x0A } ;//对称简单加密KEY
	char buf[1024] ;
	try
	{
		nKNum = sizeof(cKey) ;
		memset(buf,0,sizeof(buf)) ;
		nCount = strSys.GetLength() ;

		if( nCount >= 1024 )
			return 2 ;

		strcpy(buf,strSys.GetBuffer(0)) ;
		
		//::GetCurrentDirectory(MAX_PATH,strPath.GetBuffer(MAX_PATH)); 
		
		strPath = m_strPath + "Data\\MDFSys.ini" ;
		//AfxMessageBox(strPath) ;
		//AfxMessageBox(buf) ;

		//if(RegQueryValueEx (hKey,"Software\MDF监测中心",NULL,&dwDataType,(LPBYTE)address,&dwLeng)!=ERROR_SUCCESS)
			//return 0 ;
		
		if(!file.Open( strPath,CFile::modeWrite | CFile::modeRead ))
		{
			TRACE("写配置文件时出错") ;
			file.Close() ;
		}
		else
		{
			file.Write(buf,nCount) ;
			file.Close() ;
		}
	}
	catch(_com_error e)
	{
		strError.Format("异常:写配置文件出错:%s",(LPCSTR)e.Description()) ;
		TRACE(strError) ;
		m_pAdoDB->WriteLog(strError) ;
		return -1 ;
	}
	return 0 ;
}

//读取设置文件
//##ModelId=44B6F88502F1
int CMDFApp::ReadINI(CString &strSys)
{
	HKEY hKey;
	char address[140]={0};
	DWORD dwLeng=sizeof(address);
	DWORD dwDataType;
	CFile file ;
	CString strError ;
	CString strPath ;
	//int i,k ;
	//int nKNum ;
	long nCount;
	//char cFileName[255] ;
	//const char cKey[] ={ 0x0F,0x08,0x0B,0x01,0x0A } ;//对称简单解密KEY
	char buf[1024] ;

	try
	{
		dwDataType=REG_SZ;

		memset(buf,0,sizeof(buf)) ;

		strPath ="Software\\MDF监测中心" ;

		if( ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,strPath,0, KEY_EXECUTE,&hKey) != ERROR_SUCCESS )
		{
			AfxMessageBox("注册表未进行注册") ;
			memset(address,0,sizeof(address)) ;
		}

		if(::RegQueryValueEx (hKey,"InstallPath",NULL,&dwDataType,(LPBYTE)address,&dwLeng)!=ERROR_SUCCESS)
		{
			AfxMessageBox("找不到 Software\\MDF监测中心\\InstallPath 键值") ;
			memset(address,0,sizeof(address)) ;
		}

		strPath = address ;

		if( strPath.IsEmpty())
			m_strPath = strPath ;
		else
			m_strPath = strPath + "\\" ;

		strPath = m_strPath + "Data\\MDFsys.ini" ;

		if( !file.Open( strPath, CFile::modeRead ) )
		{
			AfxMessageBox("不能打开配置文件") ;
			file.Close() ;
			return 3 ;
		}
		nCount = file.GetLength() ;

		if( nCount >= 1024 )
			return 2 ;

		file.Read(buf,nCount) ;

		file.Close() ;

		strSys = buf ;
	}
	catch(_com_error e)
	{
		strError.Format("异常:读配置文件出错:%s",(LPCSTR)e.Description()) ;
		Show(strError) ;
		m_pAdoDB->WriteLog(strError) ;
		return -1 ;
	}
	return 0 ;
}
//写配置文件
//##ModelId=44B6F88502F0
int CMDFApp::WriteConfig()
{
	//UCHAR ucTemp ;

	return 0 ;

}
//读配置文件
//##ModelId=44B6F88502EF
int CMDFApp::ReadConfig()
{

	//MSXML::IXMLDOMDocumentPtr pCommandDoc;


	return 1 ;
}

//##ModelId=44B6F88502E2
int CMDFApp::Show(CString strTip)
{
	try
	{
		if( strTip.IsEmpty() )
			return -1 ;

		CString strTime,strTemp,strShow ;

		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=44B6F88502DF
int CMDFApp::DebugShow(CString strTip)
{
	/*
	try
	{
		if(!m_pComm->m_bIsDebug )
			return -1 ;
		((CMDFDlg*)(m_pMainWnd))->m_UI.m_DebugDlg.ShowMsg(strTip) ;
		return 0 ;
	}
	catch(_com_error e)
	{
		CString strTip ;
		strTip.Format("异常:CMDFApp::Show 发生异常:%s",(LPCSTR)e.Description()) ;
		return -1 ;
	}
	*/
	return 0 ;
} 

//##ModelId=44B6F88502DE
int CMDFApp::Refresh()
{
	

⌨️ 快捷键说明

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