📄 mdf.cpp
字号:
// MDF.cpp : Defines the class behaviors for the application.
#include "stdafx.h"
#include "mdf.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=465286A2008C
CMDFApp::CMDFApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMDFApp object
CMDFApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMDFApp initialization
//##ModelId=465286A2008D
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("数据库连接参数不正确,请在注册表中设置数据库连接信息!D",MB_ICONERROR|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();
WriteTxtLog("开启控制窗体...");
dlgServer = new CMDFDlg();
dlgServer->Create(IDD_MDFMAIN);
//m_pMainWnd = dlgServer;
dlgServer->ShowWindow(SW_HIDE);
//注释********************************************
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();
//开始监测并轮询设备状态
m_pMonitor = new CMonitor();
m_pMonitor->ShowWindow(SW_HIDE);
//起动监测服务先暂停
/*******************************************************/
if (m_Baseinfo.Autostart== 1)
{
if (StartMonitoring())
WriteTxtLog("服务起动成功...");
}
/*******************************************************/
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=465286A2009C
int CMDFApp::ExitInstance()
{
if (theApp.m_Baseinfo.MonitorStatus == 1 )
{
StopMonitoring();
}
if (m_pAdoDB)
{
m_pAdoDB->CloseDB();
delete m_pAdoDB ;
}
//delete m_pMedia ;
return CWinApp::ExitInstance();
}
//保存设置文件
//##ModelId=465286A2006D
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" ;
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=465286A2005D
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=465286A20040
int CMDFApp::Show(CString strTip)
{
//try
//{
if( strTip.IsEmpty() )
return -1 ;
CString strTime,strTemp,strShow ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -