RealEventDlg.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. // RealEventDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "RealEventDlg.h"
  6. #include <mmsystem.h>
  7. #include "shlwapi.h"
  8. #include "mainfrm.h"
  9. #include ".\realeventdlg.h"
  10. #include <io.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. extern BOOL g_bRun;
  17. extern BOOL g_bEventAlarm;
  18. extern CString g_strYkWave;
  19. extern CString g_strLoginWave;
  20. extern CString g_strReguWave;
  21. extern CString g_strSetWave;
  22. extern CString g_strYcWave;
  23. extern CString g_strYxChangeWave;
  24. #include "MainFrm.h"
  25. extern CMainFrame *g_pMainFrm;
  26. CRITICAL_SECTION g_csCreateWav;
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CRealEventDlg dialog
  29. bool DeleteWav( CString strPath, CString strFileName, int nLayer )
  30. {
  31. CStringArray saFilePath;
  32. long hfile;
  33. struct _finddata_t fFile;
  34. CString strCurr = strPath + "\\" + strFileName;
  35. int nDone=0;
  36. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  37. if( -1L != hfile )
  38. {
  39. while( !( nDone = _findnext(hfile, &fFile) ) )
  40. {
  41. if( !strcmp(fFile.name,"..") ) continue;
  42. if( ( fFile.attrib==16 || fFile.attrib==18 || fFile.attrib==48 || fFile.attrib==2064 ||
  43. fFile.attrib==2096 || fFile.attrib==2098 || fFile.attrib==16432 || fFile.attrib==16434 ) ) //_A_SUBDIR
  44. {
  45. }
  46. else
  47. {
  48. CString str = fFile.name;
  49. CString sFileNameTemp = strPath + "\\" + str;
  50. if( -1 != str.Find( "temp" ) )
  51. {
  52. saFilePath.Add( sFileNameTemp );
  53. }
  54. }
  55. }
  56. _findclose(hfile);
  57. }
  58. for( int i=0;i<saFilePath.GetCount();i++ )
  59. {
  60. DeleteFile( saFilePath.GetAt( i ) );
  61. }
  62. return true;
  63. }
  64. CRealEventDlg::CRealEventDlg(CWnd* pParent /*=NULL*/)
  65. : CDialog(CRealEventDlg::IDD, pParent)
  66. {
  67. //{{AFX_DATA_INIT(CRealEventDlg)
  68. // NOTE: the ClassWizard will add member initialization here
  69. //}}AFX_DATA_INIT
  70. m_bStopSound = false;
  71. m_bExitThread = false;
  72. m_hPlaysound = NULL;
  73. m_hCreateWav = NULL;
  74. InitializeCriticalSection( &g_csCreateWav );
  75. }
  76. CRealEventDlg::~CRealEventDlg()
  77. {
  78. if( m_hPlaysound )
  79. {
  80. //MTVERIFY( WaitForSingleObject( m_hPlaysound, INFINITE ) != WAIT_FAILED );
  81. MTVERIFY( CloseHandle( m_hPlaysound ) );
  82. m_hPlaysound = NULL;
  83. }
  84. if( m_hCreateWav )
  85. {
  86. MTVERIFY( CloseHandle( m_hCreateWav ) );
  87. m_hCreateWav = NULL;
  88. }
  89. DeleteCriticalSection( &g_csCreateWav );
  90. CDialog::~CDialog();
  91. }
  92. void CRealEventDlg::DoDataExchange(CDataExchange* pDX)
  93. {
  94. CDialog::DoDataExchange(pDX);
  95. //{{AFX_DATA_MAP(CRealEventDlg)
  96. DDX_Control(pDX, IDC_LIST_GRID, m_ctrlGrid);
  97. DDX_Control(pDX, IDC_CONFIRM, m_Btn_Config);
  98. DDX_Control(pDX, IDC_HIDE, m_Btn_ConfigAll);
  99. DDX_Control(pDX, IDC_DELETEALL, m_BtnDel);
  100. DDX_Control(pDX, IDC_DELETEALL2, m_BtnDelAll);
  101. DDX_Control(pDX, IDC_BTN_EXIT, m_BtnExit);
  102. //}}AFX_DATA_MAP
  103. }
  104. BEGIN_MESSAGE_MAP(CRealEventDlg, CDialog)
  105. //{{AFX_MSG_MAP(CRealEventDlg)
  106. ON_WM_PAINT()
  107. ON_WM_CREATE()
  108. ON_WM_TIMER()
  109. ON_BN_CLICKED(IDC_CONFIRM, OnConfirm)
  110. ON_BN_CLICKED(IDC_DELETEALL, OnDeleteall)
  111. ON_BN_CLICKED(IDC_DELETEALL2, OnDeleteall2)
  112. ON_WM_CLOSE()
  113. ON_BN_CLICKED(IDC_HIDE, OnHide)
  114. ON_BN_CLICKED(IDC_BTN_EXIT, OnBtnEixt)
  115. ON_WM_SHOWWINDOW()
  116. //}}AFX_MSG_MAP
  117. ON_WM_CTLCOLOR()
  118. ON_WM_ERASEBKGND()
  119. END_MESSAGE_MAP()
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CRealEventDlg message handlers
  122. BOOL CRealEventDlg::OnInitDialog()
  123. {
  124. CDialog::OnInitDialog();
  125. // TODO: Add extra initialization here
  126. //m_ctrlGrid.InsertColumn( 0, g_strHappentTime1 );
  127. //m_ctrlGrid.SetColumnWidth( 0, 135 );
  128. //m_ctrlGrid.InsertColumn( 1, g_strEventType );
  129. //m_ctrlGrid.SetColumnWidth( 1, 60);
  130. //m_ctrlGrid.InsertColumn( 2, g_strNormalData );
  131. //m_ctrlGrid.SetColumnWidth( 2, 110);
  132. //m_ctrlGrid.InsertColumn( 3, g_strAlarmData );
  133. //m_ctrlGrid.SetColumnWidth( 3, 60);
  134. //m_ctrlGrid.InsertColumn( 4, g_strEventInfo );
  135. //m_ctrlGrid.SetColumnWidth( 4, 470);
  136. //m_ctrlGrid.InsertColumn( 5, g_strDealStatus );
  137. //m_ctrlGrid.SetColumnWidth( 5, 100);
  138. //m_ctrlGrid.SetExtendedStyle(m_ctrlGrid.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  139. m_ctrlGrid.SetHeaderBKColor(213,222,242,8); //设置头部背景色
  140. ////m_List_Rule.SetFontHW(15,0); //设置字体高度,和宽度,0表示缺省宽度
  141. //m_List_Rule.SetColTextColor(2,RGB(255,255,100)); //设置列文本颜色
  142. //m_List_Rule.SetItemTextColor(3,1,RGB(255,0,0)); //设置单元格字体颜色
  143. int screenx=GetSystemMetrics(SM_CXSCREEN);
  144. int screeny=GetSystemMetrics(SM_CYSCREEN);
  145. m_ctrlGrid.InsertColumn(0,g_strHappentTime1,LVCFMT_LEFT,145);
  146. m_ctrlGrid.InsertColumn(1,g_strEventType,LVCFMT_CENTER,70);
  147. m_ctrlGrid.InsertColumn(2,g_strNormalData,LVCFMT_CENTER,110);
  148. m_ctrlGrid.InsertColumn(3,g_strAlarmData,LVCFMT_CENTER,70);
  149. m_ctrlGrid.InsertColumn(4,g_strEventInfo,LVCFMT_LEFT,screenx-145-70-110-70-100-80-9 );//500);
  150. m_ctrlGrid.InsertColumn(5,g_strDealStatus,LVCFMT_LEFT,100);
  151. m_ctrlGrid.SetExtendedStyle(m_ctrlGrid.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  152. m_ctrlGrid.SetBkColor( RGB( 204,232,207 ) );
  153. //SetWindowLong(m_ctrlList.m_hWnd ,GWL_EXSTYLE,WS_EX_CLIENTEDGE);
  154. //m_ctrlList.SetExtendedStyle(LVS_EX_GRIDLINES); //设置扩展风格为网格
  155. //::SendMessage(m_ctrlList.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
  156. m_ctrlGrid.SetRowHeigt( 20 );
  157. CString sIDE;
  158. sIDE.Format( "%s",g_strDirectory );
  159. int nEnd = 0;
  160. for (int i = sIDE.GetLength()-1; i >= 0; i--)
  161. {
  162. if (sIDE[i] == '\\')
  163. {
  164. nEnd = i;
  165. break;
  166. }
  167. }
  168. m_sIoServerPath = sIDE.Left( nEnd ) + "\\new_server";
  169. if( g_nAlarmModeIsSound != 0 )
  170. {
  171. //LOG4C((LOG_NOTICE, "启动 ThreadPlaySound" ));
  172. m_hPlaysound = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadPlaySound,this,0,NULL);
  173. if (m_hPlaysound == NULL)
  174. {
  175. }
  176. m_hCreateWav = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadCreateWav,this,0,NULL);
  177. }
  178. SetTimer( 2,1000,NULL );//更改等待状态和时间
  179. //SetTimer( 3,300,NULL );//设置颜色
  180. return TRUE; // return TRUE unless you set the focus to a control
  181. // EXCEPTION: OCX Property Pages should return FALSE
  182. }
  183. void CRealEventDlg::SetPos( int iWidth,int iHeight )
  184. {
  185. CRect rc1;
  186. rc1.left = 0;
  187. rc1.right = rc1.left+iWidth;
  188. rc1.top = 0;
  189. rc1.bottom = rc1.top+iHeight;
  190. this->MoveWindow( rc1 );
  191. int nBtnH = int( float(iHeight-25)/4 );
  192. CRect rc2;
  193. rc2.right = rc1.right - 5;
  194. rc2.left = rc2.right - 80;
  195. rc2.top = 0;
  196. rc2.bottom = rc2.top + nBtnH;
  197. m_Btn_ConfigAll.MoveWindow( rc2 );
  198. CRect rc3;
  199. rc3.right = rc1.right - 5;
  200. rc3.left = rc3.right - 80;
  201. rc3.top = rc2.bottom + 0;
  202. rc3.bottom = rc3.top + nBtnH;
  203. m_Btn_Config.MoveWindow( rc3 );
  204. CRect rc4;
  205. rc4.right = rc1.right - 5;
  206. rc4.left = rc4.right - 80;
  207. rc4.top = rc3.bottom + 1;
  208. rc4.bottom = rc4.top + nBtnH;
  209. m_BtnDelAll.MoveWindow( rc4 );
  210. CRect rc5;
  211. rc5.right = rc1.right - 5;
  212. rc5.left = rc5.right - 80;
  213. rc5.top = rc4.bottom + 0;
  214. rc5.bottom = rc5.top + nBtnH;
  215. m_BtnDel.MoveWindow( rc5 );
  216. //CRect rc6;
  217. //rc6.right = rc1.right - 5;
  218. //rc6.left = rc6.right - 100;
  219. //rc6.top = rc5.bottom + 1;
  220. //rc6.bottom = rc6.top + 20;
  221. //m_BtnExit.MoveWindow( rc6 );
  222. CRect rcList;
  223. rcList.left = 0;
  224. rcList.right = rc2.left - 1;
  225. rcList.top = 0;
  226. rcList.bottom = rc1.bottom-5;//25;rc5.bottom;//
  227. m_ctrlGrid.MoveWindow( rcList );
  228. }
  229. void CRealEventDlg::OnPaint()
  230. {
  231. CPaintDC dc(this); // device context for painting
  232. // TODO: Add your message handler code here
  233. // Do not call CDialog::OnPaint() for painting messages
  234. }
  235. int CRealEventDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  236. {
  237. AfxEnableControlContainer();
  238. if (CDialog::OnCreate(lpCreateStruct) == -1)
  239. return -1;
  240. SetTimer(1, 400, NULL);
  241. return 0;
  242. }
  243. void CRealEventDlg::OnTimer(UINT nIDEvent)
  244. {
  245. // 如果不报警,直接返回
  246. if ( !g_bRun ) return;
  247. //判断是否跳到报警画面
  248. if( nIDEvent==1 )
  249. {
  250. // 取新事件,加入列表
  251. CAlarmEvent* pEvent = pEventServer->GetNewEvent();
  252. if ( pEvent != NULL )
  253. {
  254. if( strcmp(pEvent->strContent,"") == 0 )
  255. {
  256. pEvent->nGet = 1;
  257. return;
  258. }
  259. //自动跳到报警画面
  260. if( g_nAlarmToView && pEvent->strContent.Find(pVariantsManager->m_strReturnNormal) == -1 )
  261. {
  262. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  263. CString sVarName = pVariantsManager->GetVarNameByID( pEvent->nVarID );
  264. pFrame->SendMessage( WM_MY_NEW_ALERT,(WPARAM)sVarName.GetBuffer(sVarName.GetLength()),0 );
  265. sVarName.ReleaseBuffer();
  266. }
  267. m_bComfig = true;
  268. AddEventInfoToList(pEvent);
  269. //LOG4C((LOG_NOTICE, "AddEventInfoToList %s",pEvent->strContent));
  270. if ( !IsWindowVisible() && g_bRun)
  271. {
  272. ShowWindow(SW_SHOW);
  273. }
  274. }
  275. }
  276. //列表状态
  277. if( nIDEvent==2 )
  278. {
  279. int nSize = m_ctrlGrid.GetItemCount();
  280. if( nSize>0 )
  281. {
  282. int nSec=0;
  283. CString sDeal,sTemp1;
  284. for( int i=0;i<nSize;i++ )
  285. {
  286. sDeal = m_ctrlGrid.GetItemText( i,5 );
  287. sDeal = sDeal.TrimLeft();
  288. CAlarmEvent* pEvent = pEventServer->GetOneEvent( i );
  289. //LOG4C((LOG_NOTICE, "pDevUid = %s,nVarID = %d, nAlarmIndex = %d nStatus=%d ", strUid,nVarID,nAlarmIndex,nStatus ));
  290. if( -1 != sDeal.Find( g_strAC_WaitConfig ) && pEvent->nDealStatus==3 )//确认成功
  291. {
  292. sDeal.Format( " %s",g_strAC_ConfigSuccess );
  293. m_ctrlGrid.SetItemText( i,5,sDeal );
  294. }
  295. else
  296. {
  297. if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
  298. {
  299. sTemp1 = sDeal.Mid( g_strAC_WaitConfig.GetLength()+1,sDeal.GetLength()-g_strAC_WaitConfig.GetLength()-2 );
  300. nSec = atoi( sTemp1 )-1;
  301. if( nSec>=0 )
  302. {
  303. sDeal.Format( " %s(%d)",sDeal.Left(g_strAC_WaitConfig.GetLength()),nSec );
  304. m_ctrlGrid.SetItemText( i,5,sDeal );
  305. }
  306. else
  307. {
  308. sDeal.Format( " %s",g_strAC_WaitOut );
  309. m_ctrlGrid.SetItemText( i,5,sDeal );
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. ////
  317. //if( nIDEvent==3 && g_nAlarmModeIsSound != 0 )
  318. //{
  319. // int nSize = m_ctrlGrid.GetItemCount();
  320. // if( nSize>0 )
  321. // {
  322. // int nSec=0;
  323. // CString sDeal,sTemp1;
  324. // for( int i=0;i<nSize;i++ )
  325. // {
  326. // sDeal = m_ctrlGrid.GetItemText( i,5 );
  327. // sDeal = sDeal.TrimLeft();
  328. // //if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
  329. // {
  330. // CString strUid;
  331. // int nVarID=0,nStatus=0,nAlarmIndex=0,nIsSound=0,nColor=0;
  332. // pEventServer->GetOneEvent( i );
  333. // if( nIsSound==0 && nColor!=1 )
  334. // {
  335. // //pEventServer->SetOneEventInfo( i,0,1 );
  336. // //m_ctrlGrid.SetItemColor( 5,i,RGB(255,0,0) );
  337. // //m_ctrlGrid.Invalidate();
  338. // break;
  339. // }
  340. // else if( nIsSound==0 )
  341. // {
  342. // break;
  343. // }
  344. // else if( nIsSound==1 && nColor!=2 )
  345. // {
  346. // //pEventServer->SetOneEventInfo( i,1,2 );
  347. // //m_ctrlGrid.SetItemColor( 5,i,RGB(204,232,207) );
  348. // //m_ctrlGrid.Invalidate();
  349. // }
  350. // }
  351. // }
  352. // }
  353. //}
  354. CDialog::OnTimer(nIDEvent);
  355. }
  356. void CRealEventDlg::PlaySoundTims( CString sWavPath,int iTimes )
  357. {
  358. MSG message;
  359. BOOL bRet = false;
  360. int nTimes = 0;
  361. while( !m_bStopSound )
  362. {
  363. bRet = sndPlaySound( sWavPath,SND_FILENAME|SND_ASYNC|SND_NOSTOP );
  364. Sleep( 100 );
  365. if( bRet )
  366. {
  367. nTimes++;
  368. if( nTimes>=iTimes )
  369. {
  370. break;
  371. }
  372. }
  373. if(::PeekMessage (&message,NULL,0,0,PM_REMOVE))
  374. { //响应其他事件 如Exit按钮操作
  375. ::TranslateMessage (&message);
  376. ::DispatchMessage (&message);
  377. }
  378. }
  379. }
  380. void CRealEventDlg::OnClose()
  381. {
  382. // m_bComfig = false;
  383. // m_ctrlGrid.DeleteAllItems();
  384. // // 将所有未确定事件确定;
  385. // while( m_pCurEvent != NULL )
  386. // {
  387. // CAnalog *pAnalog = pVariantsManager->FindAnalog( m_pCurEvent->nVarID );
  388. // pAnalog->bConfirm = true;
  389. // m_pCurEvent->nConfirm = m_pCurEvent->nConfirm==0?1:3;
  390. // m_pCurEvent = pEventServer->GetUnconfirmEvent();
  391. // }
  392. //
  393. //#if 1
  394. // sndPlaySound( NULL, SND_ASYNC );
  395. // sndPlaySound(NULL,NULL); //停止
  396. //#endif
  397. // ShowWindow(SW_HIDE);
  398. }
  399. CString CRealEventDlg::GetWeekStr( int iDayofWeek )
  400. {
  401. CString sRet;
  402. switch( iDayofWeek )
  403. {
  404. case 0: sRet = "日"; break;
  405. case 1: sRet = "一"; break;
  406. case 2: sRet = "二"; break;
  407. case 3: sRet = "三"; break;
  408. case 4: sRet = "四"; break;
  409. case 5: sRet = "五"; break;
  410. case 6: sRet = "六"; break;
  411. }
  412. return sRet;
  413. }
  414. void CRealEventDlg::AddEventInfoToList(CAlarmEvent *event)
  415. {
  416. ::SendMessage( g_pMainFrm->m_hbottomDockBar,WM_MY_INVALIDATE,0,0 );
  417. CString sTime,sEventTye,sNormalData,sCurrentData,sContent,sDealStatus;
  418. sTime = event->strWarningTime;//.Format(g_strTime, event->time.wYear,event->time.wMonth,event->time.wDay,event->time.wHour, event->time.wMinute, event->time.wSecond,GetWeekStr( event->time.wDayOfWeek ) );
  419. sEventTye = event->nStatus==0 ? g_strAlarm : g_strReturnNormal2;
  420. if( event->nUpperLimit>0 || event->nLowerLimit>0 || event->nUpperLimit>event->nLowerLimit )
  421. {
  422. sNormalData.Format( "%d ≤ X ≤ %d",event->nLowerLimit,event->nUpperLimit );//sNormalData.Format( "%d<= X <=%d",event->nLowerLimit,event->nUpperLimit );
  423. sCurrentData.Format( "%0.1f",event->dbParaValue );
  424. }
  425. else
  426. {
  427. sNormalData.Format( "X = %d",event->nNormalState );
  428. sCurrentData.Format( "%d",event->nAlarmState );
  429. }
  430. sDealStatus.Format( " %s(%d)",g_strAC_WaitConfig,event->nNoticeDelay );
  431. int nInsertIndex = m_ctrlGrid.GetItemCount();
  432. m_ctrlGrid.InsertItem(nInsertIndex, sTime);
  433. m_ctrlGrid.SetItemText(nInsertIndex, 1, sEventTye );
  434. m_ctrlGrid.SetItemText(nInsertIndex, 2, sNormalData);
  435. m_ctrlGrid.SetItemText(nInsertIndex, 3, sCurrentData);
  436. m_ctrlGrid.SetItemText(nInsertIndex, 4, " "+event->strContent);
  437. m_ctrlGrid.SetItemText(nInsertIndex, 5, sDealStatus );
  438. if( event->nStatus==0 )
  439. {
  440. //if( event->strContent.Find( "通信" )==-1 )
  441. //{
  442. m_ctrlGrid.SetItemColor( 0,nInsertIndex,RGB(211,63,45) );
  443. m_ctrlGrid.SetItemColor( 1,nInsertIndex,RGB(211,63,45) );
  444. m_ctrlGrid.SetItemColor( 2,nInsertIndex,RGB(211,63,45) );
  445. m_ctrlGrid.SetItemColor( 3,nInsertIndex,RGB(211,63,45) );
  446. m_ctrlGrid.SetItemColor( 4,nInsertIndex,RGB(211,63,45) );
  447. m_ctrlGrid.SetItemColor( 5,nInsertIndex,RGB(211,63,45) );
  448. m_ctrlGrid.SetItemTextColor( 0,nInsertIndex,RGB(255,255,255) );
  449. m_ctrlGrid.SetItemTextColor( 1,nInsertIndex,RGB(255,255,255) );
  450. m_ctrlGrid.SetItemTextColor( 2,nInsertIndex,RGB(255,255,255) );
  451. m_ctrlGrid.SetItemTextColor( 3,nInsertIndex,RGB(255,255,255) );
  452. m_ctrlGrid.SetItemTextColor( 4,nInsertIndex,RGB(255,255,255) );
  453. m_ctrlGrid.SetItemTextColor( 5,nInsertIndex,RGB(255,255,255) );
  454. //}
  455. //else
  456. //{
  457. // m_ctrlGrid.SetItemColor( 0,nInsertIndex,RGB(215,215,0) );
  458. // m_ctrlGrid.SetItemColor( 1,nInsertIndex,RGB(215,215,0) );
  459. // m_ctrlGrid.SetItemColor( 2,nInsertIndex,RGB(215,215,0) );
  460. // m_ctrlGrid.SetItemColor( 3,nInsertIndex,RGB(215,215,0) );
  461. // m_ctrlGrid.SetItemColor( 4,nInsertIndex,RGB(215,215,0) );
  462. // m_ctrlGrid.SetItemColor( 5,nInsertIndex,RGB(215,215,0) );
  463. // m_ctrlGrid.SetItemTextColor( 0,nInsertIndex,RGB(0,0,0) );
  464. // m_ctrlGrid.SetItemTextColor( 1,nInsertIndex,RGB(0,0,0) );
  465. // m_ctrlGrid.SetItemTextColor( 2,nInsertIndex,RGB(0,0,0) );
  466. // m_ctrlGrid.SetItemTextColor( 3,nInsertIndex,RGB(0,0,0) );
  467. // m_ctrlGrid.SetItemTextColor( 4,nInsertIndex,RGB(0,0,0) );
  468. // m_ctrlGrid.SetItemTextColor( 5,nInsertIndex,RGB(0,0,0) );
  469. //}
  470. }
  471. else
  472. {
  473. m_ctrlGrid.SetItemColor( 0,nInsertIndex,RGB(80,128,30) );
  474. m_ctrlGrid.SetItemColor( 1,nInsertIndex,RGB(80,128,30) );
  475. m_ctrlGrid.SetItemColor( 2,nInsertIndex,RGB(80,128,30) );
  476. m_ctrlGrid.SetItemColor( 3,nInsertIndex,RGB(80,128,30) );
  477. m_ctrlGrid.SetItemColor( 4,nInsertIndex,RGB(80,128,30) );
  478. m_ctrlGrid.SetItemColor( 5,nInsertIndex,RGB(80,128,30) );
  479. }
  480. m_ctrlGrid.EnsureVisible(nInsertIndex, FALSE);
  481. if( g_nAlarmModeIsSound==1 )
  482. {
  483. EnterCriticalSection( &g_csCreateWav );
  484. CString strFileName;
  485. strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, event->strUid, event->nVarID,event->nAlarmIndex );
  486. m_saWavPath.Add( strFileName );
  487. m_saWavContent.Add( event->strContent );
  488. LeaveCriticalSection( &g_csCreateWav );
  489. }
  490. }
  491. CString CRealEventDlg::GetAlarmFile(int type)
  492. {
  493. #if 0
  494. switch (type)
  495. {
  496. case YC_LOWALARM:
  497. case YC_UPALARM:
  498. case YC_BACK:
  499. return g_strYcWave;
  500. case LOGIN:
  501. case LOGOUT:
  502. return g_strLoginWave;
  503. case YK:
  504. return g_strYkWave;
  505. case YX_CHANGE:
  506. return g_strYxChangeWave;
  507. case SET:
  508. return g_strSetWave;
  509. }
  510. #endif
  511. return "";
  512. }
  513. bool CRealEventDlg::IsCreateWavOK( CString sWavPath )
  514. {
  515. bool bRet = true;
  516. CString sPath;
  517. for( int i=0;i<m_saWavPath.GetCount();i++ )
  518. {
  519. sPath = m_saWavPath.GetAt( 0 );
  520. if( sPath==sWavPath )
  521. {
  522. bRet = false;
  523. break;
  524. }
  525. }
  526. return bRet;
  527. }
  528. DWORD WINAPI CRealEventDlg::ThreadPlaySound( CRealEventDlg *pDlg )
  529. {//(M1)458=00(M4)268=00(W14)469=00()=00
  530. do
  531. {
  532. int nSize = pDlg->m_ctrlGrid.GetItemCount();
  533. if( nSize > 0 )
  534. {
  535. int nSec=0;
  536. CString sDeal,sContent;
  537. for( int i=0;i<nSize;i++ )
  538. {
  539. sContent = pDlg->m_ctrlGrid.GetItemText( i,4 );
  540. sDeal = pDlg->m_ctrlGrid.GetItemText( i,5 );
  541. sDeal = sDeal.TrimLeft();
  542. //if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
  543. {
  544. nSize = pDlg->m_ctrlGrid.GetItemCount();
  545. if( i>=nSize )
  546. continue;
  547. EnterCriticalSection( &g_csCreateWav );
  548. CAlarmEvent* pEvent = pEventServer->GetOneEvent( i );
  549. LeaveCriticalSection( &g_csCreateWav );
  550. if( pEvent->nSoundTimes<g_nAlarmModeSoundPlayNum && -1 == sDeal.Find( g_strAC_ConfigSuccess ) )
  551. {
  552. pEvent->nSoundTimes++;
  553. CString strFileName;
  554. if( g_nAlarmModeIsSound==1 && pEvent->nWarningLevel>=g_nCommWavLevel )//IDE生成
  555. {
  556. strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, pEvent->strUid, pEvent->nVarID,pEvent->nAlarmIndex );
  557. if( !pDlg->IsCreateWavOK( strFileName ) )
  558. continue;
  559. if( pDlg->ExistFile(strFileName ) )
  560. {
  561. pDlg->m_bStopSound = false;
  562. pDlg->PlaySoundTims( strFileName,1 );
  563. LOG4C((LOG_NOTICE, "1:%s",strFileName ));
  564. }
  565. }
  566. else if( g_nAlarmModeIsSound==2 && pEvent->nWarningLevel>=g_nCommWavLevel )//IOServer生成
  567. {
  568. strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", pDlg->m_sIoServerPath, pEvent->strUid, pEvent->nVarID,pEvent->nAlarmIndex );
  569. //LOG4C((LOG_NOTICE, "strFileName = %s", strFileName ));
  570. if( !PathFileExists( strFileName ) )
  571. {
  572. LOG4C((LOG_NOTICE, "不存在 %s", strFileName ));
  573. }
  574. if( pDlg->ExistFile( strFileName ) )
  575. {
  576. pDlg->m_bStopSound = false;
  577. pDlg->PlaySoundTims( strFileName,1 );
  578. LOG4C((LOG_NOTICE, "2:%s",strFileName ));
  579. }
  580. }
  581. }
  582. }
  583. nSize = pDlg->m_ctrlGrid.GetItemCount();
  584. Sleep( 1000 );
  585. }
  586. }
  587. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  588. return 0;
  589. }
  590. DWORD WINAPI CRealEventDlg::ThreadCreateWav( CRealEventDlg *pDlg )
  591. {
  592. do
  593. {
  594. static bool sbCreateNow = false;
  595. int nSize1 = pDlg->m_saWavPath.GetCount();
  596. int nSize2 = pDlg->m_saWavContent.GetCount();
  597. if( nSize1>0 && nSize2>0 && !sbCreateNow )
  598. {
  599. if( g_nAlarmModeIsSound==1 && pStoneUDLLTxtToWav )
  600. {
  601. sbCreateNow = true;
  602. EnterCriticalSection( &g_csCreateWav );
  603. CString sPath = pDlg->m_saWavPath.GetAt(0);
  604. CString sContent = pDlg->m_saWavContent.GetAt(0);
  605. try
  606. {
  607. pStoneUDLLTxtToWav( (char *)(LPCTSTR)sContent, (char *)(LPCTSTR)sPath,g_nTTSType,-5,300 );
  608. }
  609. catch(...)
  610. {
  611. LOG4C((LOG_NOTICE, "pDBMonitorDLLTxtToWav 出错"));
  612. }
  613. pDlg->m_saWavPath.RemoveAt(0);
  614. pDlg->m_saWavContent.RemoveAt(0);
  615. LeaveCriticalSection( &g_csCreateWav );
  616. sbCreateNow = false;
  617. }
  618. }
  619. else if( nSize1==0 && nSize2==0 )
  620. {
  621. CTime ctNow = CTime::GetCurrentTime();
  622. int nHour;
  623. nHour = ctNow.GetHour();
  624. static bool bCanDelWav = true;
  625. if( nHour == 23 && bCanDelWav )
  626. {
  627. bCanDelWav = false;
  628. CString strDectory;
  629. strDectory.Format("%s\\wav", g_strDirectory );
  630. DeleteWav( strDectory,"*.*",0 );
  631. LOG4C((LOG_NOTICE, "清空语音文件" ));
  632. }
  633. else if( nHour != 23 )
  634. {
  635. bCanDelWav = true;
  636. }
  637. }
  638. Sleep( 100 );
  639. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  640. return 0;
  641. }
  642. bool CRealEventDlg::ExistFile(CString strFileName)
  643. {
  644. CFileStatus status;
  645. CString msg;
  646. if(!CFile::GetStatus(strFileName,status))
  647. {
  648. return false;
  649. }
  650. return true;
  651. }
  652. HBRUSH CRealEventDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  653. {
  654. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  655. // TODO: 在此更改 DC 的任何属性
  656. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  657. return hbr;
  658. }
  659. BOOL CRealEventDlg::OnEraseBkgnd(CDC* pDC)
  660. {
  661. CBrush br1;
  662. CRect rect;
  663. GetWindowRect(&rect);
  664. ScreenToClient(&rect);
  665. br1.CreateSolidBrush(RGB(230, 241, 249));
  666. pDC->FillRect(rect,&br1);
  667. DeleteObject( br1 );
  668. return TRUE;
  669. //return CDialog::OnEraseBkgnd(pDC);
  670. }
  671. //确认全部
  672. void CRealEventDlg::OnHide()
  673. {
  674. int nSize = m_ctrlGrid.GetItemCount();
  675. if( nSize==0 )
  676. return;
  677. //if( MessageBox( g_strAC_ConfigAllEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  678. // return;
  679. int nSec=0;
  680. CString sDeal,sTemp1;
  681. for( int i=0;i<nSize;i++ )
  682. {
  683. sDeal = m_ctrlGrid.GetItemText( i,5 );
  684. sDeal = sDeal.TrimLeft();
  685. if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
  686. {
  687. CAlarmEvent* pEvent = pEventServer->GetOneEvent( i );
  688. //pEventServer->SetOneEventInfo( i,1,1 );
  689. m_bStopSound = true;
  690. sndPlaySound( NULL, SND_ASYNC );
  691. sndPlaySound( NULL,NULL );
  692. Sleep( 100 );
  693. pDevicesManager->ConfigAlarm( pEvent->strUid,pEvent->nVarID,pEvent->nStatus,pEvent->nAlarmIndex );
  694. //m_ctrlGrid.SetItemText( i,5," 确认成功" );
  695. }
  696. }
  697. }
  698. //确认所选
  699. void CRealEventDlg::OnConfirm()
  700. {
  701. int iListCount = m_ctrlGrid.GetItemCount();
  702. POSITION pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  703. int nListSel = m_ctrlGrid.GetNextSelectedItem(pos);
  704. if(nListSel>=iListCount || nListSel==-1)
  705. {
  706. MessageBox( g_strMsgSelectDel, g_strTip, MB_ICONINFORMATION);
  707. return;
  708. }
  709. //if( MessageBox( g_strAC_ConfigChooseEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  710. // return;
  711. pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  712. if(NULL == pos)
  713. {
  714. }
  715. else
  716. {
  717. CString sDeal,sTemp1;
  718. while(pos)
  719. {
  720. int nItem = m_ctrlGrid.GetNextSelectedItem(pos);
  721. sDeal = m_ctrlGrid.GetItemText( nItem,5 );
  722. if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
  723. {
  724. CAlarmEvent* pEvent = pEventServer->GetOneEvent( nItem );
  725. //pEventServer->SetOneEventInfo( nItem,1,1 );
  726. m_bStopSound = true;
  727. sndPlaySound( NULL, SND_ASYNC );
  728. sndPlaySound( NULL,NULL );
  729. Sleep( 100 );
  730. pDevicesManager->ConfigAlarm( pEvent->strUid,pEvent->nVarID,pEvent->nStatus,pEvent->nAlarmIndex );
  731. //m_ctrlGrid.SetItemText( nItem,5," 确认成功" );
  732. }
  733. }
  734. }
  735. }
  736. //删除全部
  737. void CRealEventDlg::OnDeleteall2()
  738. {
  739. bool bCanExit=true;
  740. int nSize = m_ctrlGrid.GetItemCount();
  741. if( nSize>0 )
  742. {
  743. //if( MessageBox( g_strAC_DelAllEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  744. // return;
  745. int nSec=0;
  746. CString sDeal,sTemp1;
  747. EnterCriticalSection( &g_csCreateWav );
  748. for( int i=nSize-1;i>=0;i-- )
  749. {
  750. sDeal = m_ctrlGrid.GetItemText( i,5 );
  751. sDeal = sDeal.TrimLeft();
  752. if( -1 == sDeal.Find( g_strAC_WaitConfig ) )
  753. {
  754. pEventServer->DeleteOneEvent( i );
  755. m_ctrlGrid.DeleteItem( i );
  756. }
  757. }
  758. LeaveCriticalSection( &g_csCreateWav );
  759. }
  760. }
  761. //删除所选
  762. void CRealEventDlg::OnDeleteall()
  763. {
  764. int iListCount = m_ctrlGrid.GetItemCount();
  765. POSITION pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  766. int nListSel = m_ctrlGrid.GetNextSelectedItem(pos);
  767. if(nListSel>=iListCount || nListSel==-1)
  768. {
  769. MessageBox( g_strMsgSelectDel, g_strTip, MB_ICONINFORMATION);
  770. return;
  771. }
  772. //if( MessageBox( g_strAC_DelChooseEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  773. // return;
  774. pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  775. if(NULL == pos)
  776. {
  777. }
  778. else
  779. {
  780. CString sDeal,sTemp1;
  781. EnterCriticalSection( &g_csCreateWav );
  782. while(pos)
  783. {
  784. int nItem = m_ctrlGrid.GetNextSelectedItem(pos);
  785. sDeal = m_ctrlGrid.GetItemText( nItem,5 );
  786. if( -1 == sDeal.Find( g_strAC_WaitConfig ) )
  787. {
  788. pEventServer->DeleteOneEvent( nItem );
  789. m_ctrlGrid.DeleteItem( nItem );
  790. pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  791. }
  792. }
  793. LeaveCriticalSection( &g_csCreateWav );
  794. }
  795. int a=0;
  796. }
  797. //关闭对话框
  798. void CRealEventDlg::OnBtnEixt()
  799. {
  800. //bool bCanExit=true;
  801. //int nSize = m_ctrlGrid.GetItemCount();
  802. //if( nSize>0 )
  803. //{
  804. // int nSec=0;
  805. // CString sDeal,sTemp1;
  806. // for( int i=0;i<nSize;i++ )
  807. // {
  808. // sDeal = m_ctrlGrid.GetItemText( i,5 );
  809. // sDeal = sDeal.TrimLeft();
  810. // if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
  811. // {
  812. // bCanExit = false;
  813. // break;
  814. // }
  815. // }
  816. //}
  817. //if( bCanExit )
  818. //{
  819. // if( nSize>0 )
  820. // {
  821. // for( int i=nSize-1;i>=0;i-- )
  822. // {
  823. // pEventServer->DeleteOneEvent( i );
  824. // m_ctrlGrid.DeleteItem( i );
  825. // }
  826. // }
  827. // OnOK();
  828. //}
  829. //else
  830. // MessageBox( "还有等待确认状态的事件尚未处理,不能关闭对话框", g_strTip, MB_ICONINFORMATION);
  831. }
  832. BOOL CRealEventDlg::PreTranslateMessage(MSG* pMsg)
  833. {
  834. // TODO: 在此添加专用代码和/或调用基类
  835. if( pMsg->message == WM_KEYDOWN )
  836. {
  837. if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_ESCAPE)
  838. {
  839. return TRUE;
  840. }
  841. }
  842. return CDialog::PreTranslateMessage(pMsg);
  843. }
  844. void CRealEventDlg::DeleteAllNotice()
  845. {
  846. bool bCanExit=true;
  847. int nSize = m_ctrlGrid.GetItemCount();
  848. if( nSize>0 )
  849. {
  850. int nSec=0;
  851. CString sDeal,sTemp1;
  852. for( int i=nSize-1;i>=0;i-- )
  853. {
  854. pEventServer->DeleteOneEvent( i );
  855. m_ctrlGrid.DeleteItem( i );
  856. }
  857. }
  858. }