IDE.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. // IDE.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. //#include <vld.h>
  5. #include "IDE.h"
  6. #include "MainFrm.h"
  7. #include "ChildFrm.h"
  8. #include "IDEDoc.h"
  9. #include "IDEView.h"
  10. #include "SysLib.h"
  11. #include ".\ide.h"
  12. #include "StartupDlg.h"
  13. #include "Login.h"
  14. #include "gooddc.h"
  15. #include "public.h"
  16. #include "md5class.h"
  17. //#include "conv.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #endif
  21. HANDLE g_hScriptThread = NULL; //线程对象
  22. #if IS_MULTHREAD_REQUEST
  23. HANDLE *g_pFreshVarThread = NULL;
  24. #else
  25. HANDLE g_hFreshVarThread = NULL;
  26. HANDLE g_hFreshVarCurPicThread = NULL;
  27. #endif
  28. HANDLE g_hReConnectSrvThread = NULL;
  29. INT g_nFreshVarThreadCount = 0;
  30. DWORD WINAPI FreshVarThread( void *pData );
  31. DWORD WINAPI FreshVarCurPicThread( void *pData );
  32. DWORD WINAPI ReConnectSrvThread( void *pData );
  33. extern CRITICAL_SECTION g_CSLimit;
  34. // CIDEApp
  35. BEGIN_MESSAGE_MAP(CIDEApp, CWinApp)
  36. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  37. // 基于文件的标准文档命令
  38. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  39. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  40. // 标准打印设置命令
  41. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  42. ON_COMMAND(ID_APP_EXIT, OnAppExit)
  43. END_MESSAGE_MAP()
  44. // CIDEApp 构造
  45. CIDEApp::CIDEApp()
  46. {
  47. // TODO: 在此处添加构造代码,
  48. // 将所有重要的初始化放置在 InitInstance 中
  49. }
  50. // 唯一的一个 CIDEApp 对象
  51. CIDEApp theApp;
  52. CMainFrame *g_pMainFrm = NULL;
  53. int InitClientTTS()
  54. {
  55. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  56. wsprintf(strFile, "%s\\TTSDll.dll", g_strDirectory);
  57. //wsprintf(strFile, "E:\\Work\\version\\new_server\\dll\\TTSDll.dll");
  58. g_hTTSModule = AfxLoadLibrary(strFile);
  59. if (NULL != g_hTTSModule)
  60. {
  61. pStoneUDllRegisterTTS = (MySTONEU_DLLRegisterTTS)::GetProcAddress(g_hTTSModule, "STONEU_DLLRegisterTTS");
  62. pStoneUDllUnRegisterTTS = (MySTONEU_DLLUnRegisterTTS)::GetProcAddress(g_hTTSModule, "STONEU_DLLUnRegisterTTS");
  63. pStoneUDLLTxtToWav = (MySTONEU_DLLTxtToWav)::GetProcAddress(g_hTTSModule, "STONEU_DLLTxtToWav");
  64. }
  65. if( ( NULL != g_hTTSModule ) && ( NULL != pStoneUDllRegisterTTS ) )
  66. {
  67. pStoneUDllRegisterTTS();
  68. }
  69. else
  70. {
  71. FreeLibrary( g_hTTSModule );
  72. g_hTTSModule = NULL;
  73. }
  74. return 0;
  75. }
  76. int UnInitClientTTS()
  77. {
  78. if( NULL != g_hTTSModule && NULL != pStoneUDllUnRegisterTTS )
  79. {
  80. pStoneUDllUnRegisterTTS();
  81. AfxFreeLibrary( g_hTTSModule );
  82. g_hTTSModule = NULL;
  83. }
  84. return 0;
  85. }
  86. // CIDEApp 初始化
  87. HANDLE hMutex;
  88. BOOL CIDEApp::InitInstance()
  89. {
  90. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  91. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  92. //则需要 InitCommonControls()。否则,将无法创建窗口。
  93. CString StrName="DBMonitor Client";
  94. hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,StrName);
  95. if(hMutex==NULL)
  96. {
  97. hMutex=::CreateMutex(NULL,NULL,StrName);
  98. }
  99. else
  100. {
  101. MessageBox(NULL,"客户端已经打开!","温馨提示",MB_ICONINFORMATION);
  102. return FALSE;
  103. }
  104. InitializeCriticalSection(&g_CSLimit);
  105. InitCommonControls();
  106. CoInitialize( NULL );
  107. CWinApp::InitInstance();
  108. //// 初始化 OLE 库
  109. if (!AfxOleInit())
  110. {
  111. AfxMessageBox(IDP_OLE_INIT_FAILED);
  112. return FALSE;
  113. }
  114. AfxEnableControlContainer();
  115. // 标准初始化
  116. // 如果未使用这些功能并希望减小
  117. // 最终可执行文件的大小,则应移除下列
  118. // 不需要的特定初始化例程
  119. // 更改用于存储设置的注册表项
  120. // TODO: 应适当修改该字符串,
  121. // 例如修改为公司或组织名
  122. SetRegistryKey(g_strAppwizardCreateApp);
  123. LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
  124. // START GDI+ SUB SYSTEM
  125. GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);
  126. MTVERIFY( g_hRunObject = ::CreateEvent(
  127. NULL, /* Security */
  128. TRUE, /* Manual event */
  129. 0, /* Clear on creation */
  130. 0 ));//"IDE::g_hRunObject") );
  131. //InitPrintQueue();
  132. GetSysData();
  133. if( !g_FindProcess( "ShortCut.exe" ) )
  134. {
  135. CString sTemp;
  136. sTemp = g_strDirectory;
  137. sTemp += "\\ShortCut.exe";//
  138. ShellExecute( NULL, NULL, sTemp,0,NULL, SW_SHOWNORMAL );
  139. }
  140. CString strFileName;
  141. strFileName.Format("%s\\log4crc", g_strDirectory);
  142. ///设置日志配置文件名
  143. LOG4C_PARAM_CFG_FILE_NAME(strFileName);
  144. ///设置日志级别
  145. LOG4C_PARAM_LOG_LEVEL("unknown");
  146. ///设置日志文件大小
  147. LOG4C_PARAM_LOG_FILE_SIZE(10240);
  148. ///设置生成日志文件个数,达到最大个数将自动覆盖最旧的日志
  149. LOG4C_PARAM_LOG_FILE_NUM(5);
  150. ///设置每次记录日志都重新读取日志配置文件
  151. LOG4C_PARAM_REREAD_LOG_CFG_FILE(1);
  152. ///带参数日志模块初始化,以上所有设置了的参数都将生效,没有设置的采用缺省值
  153. LOG4C_INIT_WITH_PARAM();
  154. LOG4C((LOG_NOTICE, "系统成功启动!"));
  155. LOG4C((LOG_NOTICE, "【ver:%s】",g_strVersion ));
  156. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  157. if( strcmp(g_strLanguage, "CHS") == 0 )
  158. {
  159. wsprintf(strFile, "%s\\ChineseRes.dll", g_strDirectory);
  160. }
  161. else if( strcmp(g_strLanguage, "CHT") == 0 )
  162. {
  163. wsprintf(strFile, "%s\\TaiwanRes.dll", g_strDirectory);
  164. }
  165. else if( strcmp(g_strLanguage, "ENG") == 0 )
  166. {
  167. wsprintf(strFile, "%s\\EnglishRes.dll", g_strDirectory);
  168. }
  169. g_hLangDLL = ::LoadLibrary(strFile);
  170. AfxSetResourceHandle(g_hLangDLL);
  171. GetResourceString();
  172. if( g_nIsDemo == 0 )
  173. {
  174. try
  175. {
  176. int nCount=0;
  177. while( 1 )
  178. {
  179. if( !CDBConnection::GetInstancePtr()->OpenDataBase(g_strConnectString) )
  180. {
  181. if( !g_iAutoRunSystem )
  182. {
  183. MessageBox(NULL,g_strMsgDBConnectionFail, g_strTip, MB_ICONWARNING);
  184. return FALSE;
  185. }
  186. if( nCount++>=50 )
  187. {
  188. MessageBox(NULL,g_strMsgDBConnectionFail, g_strTip, MB_ICONWARNING);
  189. return FALSE;
  190. }
  191. Sleep( 5000 );
  192. }
  193. else
  194. break;
  195. }
  196. CDBConnection::GetInstancePtr()->DBConnectionCheckThreadStart();
  197. CDBInterface::GetInstancePtr()->SetDBType(g_strDBType);
  198. }
  199. catch( ... )
  200. {
  201. CString str;
  202. str.Format( "连接数据库失败,可能原因是没有添加数据库 %s",g_strConnectString );
  203. MessageBox(NULL,str, g_strTip, MB_ICONWARNING);
  204. return FALSE;
  205. }
  206. }
  207. CStartupDlg dlg;
  208. dlg.Create(IDD_STARTUP);
  209. char* lpBmpFile = "Bitmap\\home.bmp";
  210. BITMAPFILEHEADER bf;
  211. BITMAPINFOHEADER bi;
  212. FILE* fp = fopen(lpBmpFile,"rb");
  213. if (fp)
  214. {
  215. fread(&bf,sizeof(bf),1,fp);
  216. fread(&bi,sizeof(bi),1,fp);
  217. fclose(fp);
  218. int nCX = GetSystemMetrics(SM_CXSCREEN);
  219. int nCY = GetSystemMetrics(SM_CYSCREEN);
  220. int nW = bi.biWidth;
  221. int nH = bi.biHeight;
  222. dlg.MoveWindow((nCX-nW)/2,(nCY-nH)/2,nW,nH);
  223. }
  224. dlg.ShowWindow(TRUE);
  225. CDC* pDC = dlg.GetDC();
  226. CRect rect;
  227. dlg.GetClientRect(rect);
  228. int screenx=GetSystemMetrics(SM_CXSCREEN);
  229. int screeny=GetSystemMetrics(SM_CYSCREEN);
  230. DisplayBMP(pDC, 0, 0, rect.Width(), rect.Height(), lpBmpFile, FALSE);
  231. dlg.ReleaseDC(pDC);
  232. Sleep(3000);
  233. dlg.ShowWindow(FALSE);
  234. PMS_InitSDK();
  235. CDBInterface::GetInstancePtr()->AddGroupToDll();
  236. CDBInterface::GetInstancePtr()->AddUserToDll();
  237. if( g_nIsDemo == 0 )
  238. {
  239. // 登录
  240. //int nRet = IsNoDlgLogin();
  241. //if( nRet==-1 )
  242. {
  243. CLogin udlg;
  244. if( udlg.DoModal() != IDOK )
  245. {
  246. return FALSE;
  247. }
  248. CString sContent;
  249. sContent.Format("用戶< %s >登录",udlg.m_sUserID );
  250. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_LOGIN,0,"",(char *)(LPCTSTR)sContent );
  251. }
  252. }
  253. if( g_nIsDemo == 0 )
  254. {
  255. if( g_nAlarmModeIsSound == 1 )
  256. {
  257. InitClientTTS();
  258. }
  259. }
  260. // 注册应用程序的文档模板。文档模板
  261. // 将用作文档、框架窗口和视图之间的连接
  262. CMultiDocTemplate* pDocTemplate;
  263. pDocTemplate = new CMultiDocTemplate(IDR_MAINFRAME,
  264. RUNTIME_CLASS(CIDEDoc),
  265. RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
  266. RUNTIME_CLASS(CIDEView));
  267. AddDocTemplate(pDocTemplate);
  268. // 创建主 MDI 框架窗口
  269. CMainFrame* pMainFrame = new CMainFrame;
  270. pMainFrame->m_pDoc = (CIDEDoc *)pDocTemplate->CreateNewDocument();
  271. if ( !pMainFrame )
  272. {
  273. MessageBox(NULL,"pMainFrame == NULL", g_strTip, MB_ICONWARNING);
  274. return FALSE;
  275. }
  276. if ( !pMainFrame->LoadFrame(IDR_MAINFRAME) )
  277. {
  278. MessageBox(NULL,"资源文件不对1", g_strTip, MB_ICONWARNING);
  279. return FALSE;
  280. }
  281. m_pMainWnd = pMainFrame;
  282. // 仅当具有后缀时才调用 DragAcceptFiles
  283. // 在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生
  284. // 分析标准外壳命令、DDE、打开文件操作的命令行
  285. CCommandLineInfo cmdInfo;
  286. ParseCommandLine(cmdInfo);
  287. // 调度在命令行中指定的命令。如果
  288. // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
  289. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  290. if (!ProcessShellCommand(cmdInfo))
  291. {
  292. MessageBox(NULL,"资源文件不对2", g_strTip, MB_ICONWARNING);
  293. return FALSE;
  294. }
  295. // 主窗口已初始化,因此显示它并对其进行更新
  296. m_pMainWnd->SetWindowText(g_strStoneuIspcms);
  297. pMainFrame->ShowWindow(m_nCmdShow);
  298. //if( g_bFullScreen )
  299. //{
  300. // m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);//窗口最大化 关于全屏
  301. //}
  302. pMainFrame->UpdateWindow();
  303. g_pMainFrm = pMainFrame;
  304. if( g_nIsDemo == 0 && g_bStartRun==1 )
  305. {
  306. MTVERIFY( g_hFreshVarCurPicThread =
  307. ::CreateThread(
  308. NULL,
  309. 0,
  310. FreshVarCurPicThread,
  311. 0,
  312. 0,
  313. 0) );
  314. MTVERIFY( g_hReConnectSrvThread = ::CreateThread(NULL, 0, ReConnectSrvThread, 0, 0, 0) );
  315. DWORD thredid;
  316. g_hScriptThread = (HANDLE) ::CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ScriptRunProc,NULL,0,&thredid); //脚本处理
  317. }
  318. return TRUE;
  319. }
  320. int CIDEApp::ExitInstance()
  321. {
  322. // TODO: 在此添加专用代码和/或调用基类
  323. LOG4C((LOG_NOTICE, "ExitInstance!"));
  324. GdiplusShutdown( m_gdiplusToken );
  325. if( g_hRunObject )
  326. MTVERIFY( SetEvent( g_hRunObject ) );
  327. if( pDevicesManager != NULL )
  328. {
  329. if( g_nIsDemo == 0 )
  330. {
  331. //if (g_bStartRun)
  332. {
  333. for( int iPortIndex=0;iPortIndex<2;iPortIndex++ )
  334. {
  335. CString sPortTemp;
  336. sPortTemp.Format("%d",atoi(g_strServerPort)+iPortIndex );
  337. pDevicesManager->DisConnection(sPortTemp);
  338. }
  339. }
  340. }
  341. }
  342. if( g_nIsDemo == 0 )
  343. {
  344. if( g_nAlarmModeIsSound == 1 )
  345. {
  346. UnInitClientTTS();
  347. }
  348. if( g_hScriptThread != NULL )
  349. {
  350. if( g_hScriptThread )
  351. {
  352. MTVERIFY( WaitForSingleObject( g_hScriptThread, INFINITE ) != WAIT_FAILED );
  353. MTVERIFY( CloseHandle(g_hScriptThread) );
  354. }
  355. g_hScriptThread = NULL;
  356. // 清除脚本队列
  357. POSITION pos = g_ScriptParamList.GetHeadPosition();
  358. while (pos != NULL)
  359. {
  360. POSITION tmpPos = pos;
  361. ScriptParam* pScriptParam = g_ScriptParamList.GetNext( pos );
  362. g_ScriptParamList.RemoveAt( tmpPos );
  363. delete pScriptParam;
  364. }
  365. }
  366. #if IS_MULTHREAD_REQUEST
  367. for( int i = 0; i < g_nFreshVarThreadCount; i++ )
  368. {
  369. if( g_pFreshVarThread[i] != NULL )
  370. {
  371. MTVERIFY( WaitForSingleObject( g_pFreshVarThread[i], INFINITE ) != WAIT_FAILED );
  372. MTVERIFY( CloseHandle( g_pFreshVarThread[i] ) );
  373. g_pFreshVarThread[i] = NULL;
  374. }
  375. }
  376. if( g_pFreshVarThread )
  377. {
  378. delete []g_pFreshVarThread;
  379. g_pFreshVarThread = NULL;
  380. }
  381. #else
  382. if( g_hFreshVarThread != NULL )
  383. {
  384. MTVERIFY( WaitForSingleObject( g_hFreshVarThread, INFINITE ) != WAIT_FAILED );
  385. MTVERIFY( CloseHandle( g_hFreshVarThread ) );
  386. g_hFreshVarThread = NULL;
  387. }
  388. if( g_hFreshVarCurPicThread != NULL )
  389. {
  390. MTVERIFY( WaitForSingleObject( g_hFreshVarCurPicThread, INFINITE ) != WAIT_FAILED );
  391. MTVERIFY( CloseHandle( g_hFreshVarCurPicThread ) );
  392. g_hFreshVarCurPicThread = NULL;
  393. }
  394. #endif
  395. if( g_hReConnectSrvThread != NULL )
  396. {
  397. MTVERIFY( WaitForSingleObject( g_hReConnectSrvThread, INFINITE ) != WAIT_FAILED );
  398. MTVERIFY( CloseHandle( g_hReConnectSrvThread ) );
  399. g_hReConnectSrvThread = NULL;
  400. }
  401. }
  402. if( pDevicesManager != NULL )
  403. {
  404. //chn mem
  405. for( int iPortIndex=0;iPortIndex<2;iPortIndex++ )
  406. {
  407. CString sPortTemp;
  408. sPortTemp.Format("%d",atoi(g_strServerPort)+iPortIndex );
  409. pDevicesManager->Release( sPortTemp );
  410. }
  411. delete pDevicesManager;
  412. pDevicesManager = NULL;
  413. }
  414. if( pVariantsManager != NULL )
  415. {
  416. delete pVariantsManager;
  417. pVariantsManager = NULL;
  418. }
  419. if( pEventServer != NULL )
  420. {
  421. delete pEventServer;
  422. pEventServer = NULL;
  423. }
  424. if( g_hRunObject )
  425. MTVERIFY( CloseHandle( g_hRunObject ) );
  426. //chn mem
  427. CDBInterface::GetInstancePtr()->Release();
  428. //UninitPrintQueue();
  429. //if( g_nIsDemo == 0 )
  430. {
  431. CDBConnection::GetInstancePtr()->DBConnectionCheckThreadStop();
  432. CDBConnection::GetInstancePtr()->CloseDataBase();
  433. //DBConnectionThreadEnd();
  434. //chn mem
  435. CDBConnection::GetInstancePtr()->Release();
  436. }
  437. if(g_hLangDLL)
  438. {
  439. AfxFreeLibrary(g_hLangDLL);
  440. }
  441. LOG4C((LOG_NOTICE, "系统成功退出!"));
  442. ///关闭日志模块防止内存/资源泄漏
  443. LOG4C_FINI();
  444. // Shutdown GDI+ subystem
  445. GdiplusShutdown(m_gdiplusToken);
  446. //释放权限所占的内存
  447. PMS_UnInitSDK();
  448. ::CloseHandle( hMutex );
  449. hMutex = NULL;
  450. DeleteCriticalSection( &g_CSLimit );
  451. CoUninitialize();
  452. return CWinApp::ExitInstance();
  453. }
  454. void CIDEApp::OnAppExit()
  455. {
  456. // TODO: 在此添加命令处理程序代码
  457. CMainFrame *pMainFrm=(CMainFrame*)m_pMainWnd;
  458. pMainFrm->m_nViewCount = 0;
  459. pMainFrm->OnSuperEnd();
  460. }
  461. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  462. class CAboutDlg : public CDialog
  463. {
  464. public:
  465. CAboutDlg();
  466. // 对话框数据
  467. enum { IDD = IDD_ABOUTBOX };
  468. protected:
  469. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  470. // 实现
  471. protected:
  472. DECLARE_MESSAGE_MAP()
  473. public:
  474. virtual BOOL OnInitDialog();
  475. };
  476. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  477. {
  478. }
  479. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  480. {
  481. CDialog::DoDataExchange(pDX);
  482. }
  483. BOOL CAboutDlg::OnInitDialog()
  484. {
  485. CDialog::OnInitDialog();
  486. // TODO: 在此添加额外的初始化
  487. CString str;
  488. str.Format("【ver:%s】",g_strVersion );
  489. GetDlgItem(IDC_STA_VERSION)->SetWindowText(str);
  490. return TRUE; // return TRUE unless you set the focus to a control
  491. // 异常: OCX 属性页应返回 FALSE
  492. }
  493. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  494. END_MESSAGE_MAP()
  495. // 用于运行对话框的应用程序命令
  496. void CIDEApp::OnAppAbout()
  497. {
  498. CAboutDlg aboutDlg;
  499. aboutDlg.DoModal();
  500. }
  501. DWORD WINAPI FreshVarThread( void *pData )
  502. {
  503. #if IS_MULTHREAD_REQUEST
  504. CString strUid = CString((char *)pData);
  505. #else
  506. CString strUid = "";
  507. #endif
  508. do
  509. {
  510. if (g_bStartRun)
  511. {
  512. if( g_bRun )
  513. {
  514. //TRACE("设备Uid=%s\r\n", strUid);
  515. pVariantsManager->Fresh(strUid);
  516. }
  517. }
  518. Sleep(10);
  519. }while( WaitForSingleObject( g_hRunObject, 10L ) == WAIT_TIMEOUT );
  520. return 0;
  521. }
  522. //读取当前画面的变量
  523. DWORD WINAPI FreshVarCurPicThread( void *pData )
  524. {
  525. CString strUid = "";
  526. do
  527. {
  528. if (g_bStartRun)
  529. {
  530. if( g_bRun )
  531. {
  532. //TRACE("设备Uid=%s\r\n", strUid);
  533. //if( !pVariantsManager->m_bIsChangeView )
  534. //{
  535. // EnterCriticalSection( &g_CSLimit );
  536. pVariantsManager->FreshCurPic( );
  537. // LeaveCriticalSection( &g_CSLimit );
  538. //}
  539. }
  540. }
  541. Sleep(10);
  542. }while( WaitForSingleObject( g_hRunObject, 10L ) == WAIT_TIMEOUT );
  543. return 0;
  544. }
  545. DWORD WINAPI ReConnectSrvThread( void *pData )
  546. {
  547. do
  548. {
  549. //if (g_bStartRun)
  550. {
  551. for( int iPortIndex=0;iPortIndex<2;iPortIndex++ )
  552. {
  553. CString sPortTemp;
  554. sPortTemp.Format("%d",atoi(g_strServerPort)+iPortIndex );
  555. if( FALSE == pDevicesManager->GetSocketStatus(sPortTemp) )
  556. {
  557. pVariantsManager->SetSysComunicationVar( 1.0 );
  558. if( pDevicesManager->GetOpenStatus(sPortTemp) == TRUE )
  559. {
  560. pDevicesManager->DisConnection(sPortTemp);
  561. }
  562. if( !pDevicesManager->Connection(g_strServerIP, sPortTemp) )
  563. {
  564. pDevicesManager->SetSocketStatus(FALSE,sPortTemp);
  565. }
  566. else
  567. {
  568. pVariantsManager->SetSysComunicationVar( 0.0 );
  569. pDevicesManager->SetSocketStatus(TRUE,sPortTemp);
  570. //从新连接上IOServer时清空报警列表
  571. if( iPortIndex==0 && g_pMainFrm->m_dlgEvent )
  572. {
  573. g_pMainFrm->m_dlgEvent->DeleteAllNotice();
  574. }
  575. if( iPortIndex==0 )
  576. pDevicesManager->GetServerVer( sPortTemp );
  577. }
  578. }
  579. }
  580. }
  581. //Sleep(2000);
  582. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  583. return 0;
  584. }
  585. // CIDEApp 消息处理程序
  586. int CIDEApp::IsNoDlgLogin()//自动登录 -1:不是 0:失败 1:成功
  587. {
  588. int nRet = -1;
  589. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  590. wsprintf(strFile, "%s\\set.ini", g_strDirectory);
  591. char RUN[MAX_PATH] = {0};
  592. memset(RUN, 0, sizeof(RUN));
  593. ////是否是没对话框登录
  594. //if ( GetPrivateProfileString("User", "NoDlgLogin","",RUN, 10, strFile) != 0)
  595. //{
  596. // if( RUN[0] == '0' )
  597. // return nRet;
  598. //}
  599. //WritePrivateProfileString("User", "NoDlgLogin", "0", strFile);
  600. if( g_iAutoRunSystem==0 )
  601. return nRet;
  602. GetPrivateProfileString("User", "UserID","", g_strLoginUserID,sizeof(g_strLoginUserID), strFile );
  603. memset(g_strDefaultUserID, 0, sizeof(g_strDefaultUserID) );
  604. strcpy(g_strDefaultUserID, g_strLoginUserID);
  605. GetPrivateProfileString("User", "UserPwd","", g_strLoginPwd,sizeof(g_strLoginPwd), strFile );
  606. memset(g_strDefaultUserPwd, 0, sizeof(g_strDefaultUserPwd) );
  607. strcpy(g_strDefaultUserPwd, g_strLoginPwd);
  608. CString sUserID,sUserPwd;
  609. sUserID = g_strLoginUserID;
  610. sUserPwd = g_strLoginPwd;
  611. if( sUserID=="" || sUserPwd=="" )
  612. return nRet;
  613. ///////////////////////////////////////////////////////////////////////////////
  614. char Path[_MAX_PATH] = {0};
  615. strcat(Path, g_strDirectory);
  616. strcat(Path,"\\");
  617. strcat(Path, _PROJECTDIR);
  618. strcat(Path,"\\");
  619. strcat(Path, "runpara.ini");
  620. //CString str;
  621. if ( GetPrivateProfileString("RUNPARA", "STARTRUN","",RUN, 10, Path) != 0)
  622. {
  623. g_bStartRun = (RUN[0] == '1' ? true:false);
  624. }
  625. if ( GetPrivateProfileString("RUNPARA", "FULLSCREEN","",RUN, 10, Path) != 0)
  626. {
  627. g_bFullScreen = RUN[0] == '1' ? true:false;
  628. }
  629. CMD5 md5;
  630. md5.setPlainText( (char *)(LPCTSTR)sUserPwd );
  631. if( ( ( strcmp(g_strDefaultUserPwd, "") != 0 ) && (strcmp(g_strLoginUserID, (char*)(LPCTSTR)sUserID) != 0 ) ) ||
  632. ( strcmp(g_strDefaultUserPwd, "") == 0 ) ||
  633. (strcmp(g_strLoginUserID, (char*)(LPCTSTR)sUserID) != 0 ) ||
  634. ( strcmp(g_strDefaultUserPwd, sUserPwd) != 0 ) ||
  635. (strcmp(g_strLoginUserID, "") == 0) )
  636. {
  637. sUserPwd = CString(md5.getMD5Digest());
  638. }
  639. nRet = CDBInterface::GetInstancePtr()->ValidateUser((char*)(LPCTSTR)sUserID, (char *)(LPCTSTR)sUserPwd);
  640. //LOG4C((LOG_NOTICE, "ValidateUser return %d", nRet));
  641. if( nRet < 1 )
  642. {
  643. MessageBox(NULL,g_strMsgUserInvalid, g_strTip, MB_ICONWARNING);
  644. return 0;
  645. }
  646. CHAR chStatus[MAX_STATUS_LENGTH + 1] = {0};
  647. CDBInterface::GetInstancePtr()->ValidateUserEnable( (char*)(LPCTSTR)sUserID, chStatus );
  648. if( atoi(chStatus) == 1 )
  649. {
  650. MessageBox(NULL,g_strMsgUserDisable, g_strTip, MB_ICONWARNING);
  651. return 0;
  652. }
  653. //cHn add
  654. CDBInterface::GetInstancePtr()->GetUserIDByName( sUserID,g_nUserID );
  655. if( g_bStartRun==0 && -1==PMS_VerifyUserPermit( g_nUserID,PMS_EDIT_STATUS_MANAGE,"" ) )
  656. {
  657. MessageBox(NULL,g_strNoPermit, g_strTip, MB_ICONWARNING);
  658. return 0;
  659. }
  660. return 1;
  661. }