RealEventDlg.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. extern BOOL g_bRun;
  16. extern BOOL g_bEventAlarm;
  17. extern CString g_strYkWave;
  18. extern CString g_strLoginWave;
  19. extern CString g_strReguWave;
  20. extern CString g_strSetWave;
  21. extern CString g_strYcWave;
  22. extern CString g_strYxChangeWave;
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CRealEventDlg dialog
  25. #define NOTICE_DELAY 30 //通知延时
  26. CRealEventDlg::CRealEventDlg(CWnd* pParent /*=NULL*/)
  27. : CDialog(CRealEventDlg::IDD, pParent)
  28. {
  29. //{{AFX_DATA_INIT(CRealEventDlg)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. m_bStopSound = false;
  33. m_bExitThread = false;
  34. m_hPlaysound = NULL;
  35. }
  36. CRealEventDlg::~CRealEventDlg()
  37. {
  38. if( m_hPlaysound != NULL )
  39. {
  40. //MTVERIFY( WaitForSingleObject( m_hPlaysound, INFINITE ) != WAIT_FAILED );
  41. MTVERIFY( CloseHandle( m_hPlaysound ) );
  42. m_hPlaysound = NULL;
  43. }
  44. CDialog::~CDialog();
  45. }
  46. void CRealEventDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CDialog::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CRealEventDlg)
  50. DDX_Control(pDX, IDC_LIST_GRID, m_ctrlGrid);
  51. DDX_Control(pDX, IDC_CONFIRM, m_Btn_Config);
  52. DDX_Control(pDX, IDC_HIDE, m_Btn_ConfigAll);
  53. DDX_Control(pDX, IDC_DELETEALL, m_BtnDel);
  54. DDX_Control(pDX, IDC_BTN_EXIT, m_BtnExit);
  55. //}}AFX_DATA_MAP
  56. }
  57. BEGIN_MESSAGE_MAP(CRealEventDlg, CDialog)
  58. //{{AFX_MSG_MAP(CRealEventDlg)
  59. ON_WM_PAINT()
  60. ON_WM_CREATE()
  61. ON_WM_TIMER()
  62. ON_BN_CLICKED(IDC_CONFIRM, OnConfirm)
  63. ON_BN_CLICKED(IDC_DELETEALL, OnDeleteall)
  64. ON_WM_CLOSE()
  65. ON_BN_CLICKED(IDC_HIDE, OnHide)
  66. ON_BN_CLICKED(IDC_BTN_EXIT, OnBtnEixt)
  67. ON_WM_SHOWWINDOW()
  68. //}}AFX_MSG_MAP
  69. ON_WM_CTLCOLOR()
  70. ON_WM_ERASEBKGND()
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CRealEventDlg message handlers
  74. BOOL CRealEventDlg::OnInitDialog()
  75. {
  76. CDialog::OnInitDialog();
  77. // TODO: Add extra initialization here
  78. //m_ctrlGrid.InsertColumn( 0, g_strHappentTime1 );
  79. //m_ctrlGrid.SetColumnWidth( 0, 135 );
  80. //m_ctrlGrid.InsertColumn( 1, g_strEventType );
  81. //m_ctrlGrid.SetColumnWidth( 1, 60);
  82. //m_ctrlGrid.InsertColumn( 2, g_strNormalData );
  83. //m_ctrlGrid.SetColumnWidth( 2, 110);
  84. //m_ctrlGrid.InsertColumn( 3, g_strAlarmData );
  85. //m_ctrlGrid.SetColumnWidth( 3, 60);
  86. //m_ctrlGrid.InsertColumn( 4, g_strEventInfo );
  87. //m_ctrlGrid.SetColumnWidth( 4, 470);
  88. //m_ctrlGrid.InsertColumn( 5, g_strDealStatus );
  89. //m_ctrlGrid.SetColumnWidth( 5, 100);
  90. //m_ctrlGrid.SetExtendedStyle(m_ctrlGrid.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  91. m_ctrlGrid.SetHeaderBKColor(213,222,242,8); //设置头部背景色
  92. ////m_List_Rule.SetFontHW(15,0); //设置字体高度,和宽度,0表示缺省宽度
  93. //m_List_Rule.SetColTextColor(2,RGB(255,255,100)); //设置列文本颜色
  94. //m_List_Rule.SetItemTextColor(3,1,RGB(255,0,0)); //设置单元格字体颜色
  95. m_ctrlGrid.InsertColumn(0,g_strHappentTime1,LVCFMT_LEFT,145);
  96. m_ctrlGrid.InsertColumn(1,g_strEventType,LVCFMT_CENTER,70);
  97. m_ctrlGrid.InsertColumn(2,g_strNormalData,LVCFMT_CENTER,110);
  98. m_ctrlGrid.InsertColumn(3,g_strAlarmData,LVCFMT_CENTER,70);
  99. m_ctrlGrid.InsertColumn(4,g_strEventInfo,LVCFMT_LEFT,480);
  100. m_ctrlGrid.InsertColumn(5,g_strDealStatus,LVCFMT_LEFT,100);
  101. m_ctrlGrid.SetExtendedStyle(m_ctrlGrid.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  102. m_ctrlGrid.SetBkColor( RGB( 204,232,207 ) );
  103. //SetWindowLong(m_ctrlList.m_hWnd ,GWL_EXSTYLE,WS_EX_CLIENTEDGE);
  104. //m_ctrlList.SetExtendedStyle(LVS_EX_GRIDLINES); //设置扩展风格为网格
  105. //::SendMessage(m_ctrlList.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
  106. m_ctrlGrid.SetRowHeigt( 20 );
  107. CString sIDE;
  108. sIDE.Format( "%s",g_strDirectory );
  109. int nEnd = 0;
  110. for (int i = sIDE.GetLength()-1; i >= 0; i--)
  111. {
  112. if (sIDE[i] == '\\')
  113. {
  114. nEnd = i;
  115. break;
  116. }
  117. }
  118. m_sIoServerPath = sIDE.Left( nEnd ) + "\\new_server";
  119. if( g_nAlarmModeIsSound != 0 )
  120. {
  121. m_hPlaysound = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadPlaySound,this,0,NULL);
  122. if (m_hPlaysound == NULL)
  123. {
  124. }
  125. }
  126. SetTimer( 2,1000,NULL );//更改等待状态和时间
  127. SetTimer( 3,300,NULL );//设置颜色
  128. return TRUE; // return TRUE unless you set the focus to a control
  129. // EXCEPTION: OCX Property Pages should return FALSE
  130. }
  131. void CRealEventDlg::OnPaint()
  132. {
  133. CPaintDC dc(this); // device context for painting
  134. // TODO: Add your message handler code here
  135. // Do not call CDialog::OnPaint() for painting messages
  136. }
  137. int CRealEventDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  138. {
  139. AfxEnableControlContainer();
  140. if (CDialog::OnCreate(lpCreateStruct) == -1)
  141. return -1;
  142. SetTimer(1, 400, NULL);
  143. return 0;
  144. }
  145. void CRealEventDlg::OnTimer(UINT nIDEvent)
  146. {
  147. // 如果不报警,直接返回
  148. if ( !g_bRun ) return;
  149. if( nIDEvent==1 )
  150. {
  151. // 取新事件,加入列表
  152. CAlarmEvent* pEvent = pEventServer->GetNewEvent();
  153. if ( pEvent != NULL )
  154. {
  155. if( strcmp(pEvent->strContent,"") == 0 )
  156. {
  157. pEvent->nGet = 1;
  158. return;
  159. }
  160. //自动跳到报警画面
  161. if( g_nAlarmToPic && pEvent->strContent.Find(pVariantsManager->m_strReturnNormal) == -1 )
  162. {
  163. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  164. CString sVarName = pVariantsManager->GetVarNameByID( pEvent->nVarID );
  165. pFrame->SendMessage( WM_MY_NEW_ALERT,(WPARAM)sVarName.GetBuffer(sVarName.GetLength()),0 );
  166. sVarName.ReleaseBuffer();
  167. }
  168. m_bComfig = true;
  169. AddEventInfoToList(pEvent);
  170. //LOG4C((LOG_NOTICE, "AddEventInfoToList %s",pEvent->strContent));
  171. if ( !IsWindowVisible() && g_bRun)
  172. {
  173. ShowWindow(SW_SHOW);
  174. }
  175. }
  176. }
  177. if( nIDEvent==2 )
  178. {
  179. int nSize = m_ctrlGrid.GetItemCount();
  180. if( nSize>0 )
  181. {
  182. int nSec=0;
  183. CString sDeal,sTemp1;
  184. for( int i=0;i<nSize;i++ )
  185. {
  186. sDeal = m_ctrlGrid.GetItemText( i,5 );
  187. sDeal = sDeal.TrimLeft();
  188. if( -1 != sDeal.Find( "等待确认" ) )
  189. {
  190. sTemp1 = sDeal.Mid( 9,sDeal.GetLength()-8-4 );
  191. nSec = atoi( sTemp1 )-1;
  192. if( nSec>=0 )
  193. {
  194. sDeal.Format( " %s(%d秒)",sDeal.Left(8),nSec );
  195. m_ctrlGrid.SetItemText( i,5,sDeal );
  196. }
  197. else
  198. {
  199. sDeal.Format( " %s","等待过时" );
  200. m_ctrlGrid.SetItemText( i,5,sDeal );
  201. }
  202. }
  203. }
  204. }
  205. }
  206. if( nIDEvent==3 && g_nAlarmModeIsSound != 0 )
  207. {
  208. int nSize = m_ctrlGrid.GetItemCount();
  209. if( nSize>0 )
  210. {
  211. int nSec=0;
  212. CString sDeal,sTemp1;
  213. for( int i=0;i<nSize;i++ )
  214. {
  215. sDeal = m_ctrlGrid.GetItemText( i,5 );
  216. sDeal = sDeal.TrimLeft();
  217. //if( -1 != sDeal.Find( "等待确认" ) )
  218. {
  219. CString strUid;
  220. int nVarID=0,nStatus=0,nAlarmIndex=0,nIsSound=0,nColor=0;
  221. pEventServer->GetOneEventInfo( i,strUid,nVarID,nStatus,nAlarmIndex,nIsSound,nColor );
  222. if( nIsSound==0 && nColor!=1 )
  223. {
  224. pEventServer->SetOneEventInfo( i,0,1 );
  225. m_ctrlGrid.SetItemColor( 5,i,RGB(255,0,0) );
  226. m_ctrlGrid.Invalidate();
  227. break;
  228. }
  229. else if( nIsSound==0 )
  230. {
  231. break;
  232. }
  233. else if( nIsSound==1 && nColor!=2 )
  234. {
  235. pEventServer->SetOneEventInfo( i,1,2 );
  236. m_ctrlGrid.SetItemColor( 5,i,RGB(204,232,207) );
  237. m_ctrlGrid.Invalidate();
  238. }
  239. }
  240. }
  241. }
  242. }
  243. CDialog::OnTimer(nIDEvent);
  244. }
  245. void CRealEventDlg::PlaySoundTims( CString sWavPath,int iTimes )
  246. {
  247. MSG message;
  248. BOOL bRet = false;
  249. int nTimes = 0;
  250. while( !m_bStopSound )
  251. {
  252. bRet = sndPlaySound( sWavPath,SND_FILENAME|SND_ASYNC|SND_NOSTOP );
  253. Sleep( 100 );
  254. if( bRet )
  255. {
  256. nTimes++;
  257. if( nTimes>=iTimes )
  258. {
  259. break;
  260. }
  261. }
  262. if(::PeekMessage (&message,NULL,0,0,PM_REMOVE))
  263. { //响应其他事件 如Exit按钮操作
  264. ::TranslateMessage (&message);
  265. ::DispatchMessage (&message);
  266. }
  267. }
  268. }
  269. void CRealEventDlg::OnClose()
  270. {
  271. // m_bComfig = false;
  272. // m_ctrlGrid.DeleteAllItems();
  273. // // 将所有未确定事件确定;
  274. // while( m_pCurEvent != NULL )
  275. // {
  276. // CAnalog *pAnalog = pVariantsManager->FindAnalog( m_pCurEvent->nVarID );
  277. // pAnalog->bConfirm = true;
  278. // m_pCurEvent->nConfirm = m_pCurEvent->nConfirm==0?1:3;
  279. // m_pCurEvent = pEventServer->GetUnconfirmEvent();
  280. // }
  281. //
  282. //#if 1
  283. // sndPlaySound( NULL, SND_ASYNC );
  284. // sndPlaySound(NULL,NULL); //停止
  285. //#endif
  286. // ShowWindow(SW_HIDE);
  287. }
  288. CString CRealEventDlg::GetWeekStr( int iDayofWeek )
  289. {
  290. CString sRet;
  291. switch( iDayofWeek )
  292. {
  293. case 0: sRet = "日"; break;
  294. case 1: sRet = "一"; break;
  295. case 2: sRet = "二"; break;
  296. case 3: sRet = "三"; break;
  297. case 4: sRet = "四"; break;
  298. case 5: sRet = "五"; break;
  299. case 6: sRet = "六"; break;
  300. }
  301. return sRet;
  302. }
  303. void CRealEventDlg::AddEventInfoToList(CAlarmEvent *event)
  304. {
  305. CString sTime,sEventTye,sNormalData,sCurrentData,sContent,sDealStatus;
  306. sTime.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 ) );
  307. sEventTye = event->nStatus==0 ? "报警" : "恢复正常";
  308. if( event->nUpperLimit>0 || event->nLowerLimit>0 || event->nUpperLimit>event->nLowerLimit )
  309. {
  310. sNormalData.Format( "X>=%d && X<=%d",event->nLowerLimit,event->nUpperLimit );//sNormalData.Format( "%d<= X <=%d",event->nLowerLimit,event->nUpperLimit );
  311. sCurrentData.Format( "%0.1f",event->dbParaValue );
  312. }
  313. else
  314. {
  315. sNormalData.Format( "X = %d",event->nNormalState );
  316. sCurrentData.Format( "%d",event->nAlarmState );
  317. }
  318. sDealStatus.Format( " 等待确认(%d秒)",NOTICE_DELAY );
  319. int nInsertIndex = m_ctrlGrid.GetItemCount();
  320. m_ctrlGrid.InsertItem(nInsertIndex, sTime);
  321. m_ctrlGrid.SetItemText(nInsertIndex, 1, sEventTye );
  322. m_ctrlGrid.SetItemText(nInsertIndex, 2, sNormalData);
  323. m_ctrlGrid.SetItemText(nInsertIndex, 3, sCurrentData);
  324. m_ctrlGrid.SetItemText(nInsertIndex, 4, " "+event->strContent);
  325. m_ctrlGrid.SetItemText(nInsertIndex, 5, sDealStatus );
  326. m_ctrlGrid.EnsureVisible(nInsertIndex, FALSE);
  327. }
  328. CString CRealEventDlg::GetAlarmFile(int type)
  329. {
  330. #if 0
  331. switch (type)
  332. {
  333. case YC_LOWALARM:
  334. case YC_UPALARM:
  335. case YC_BACK:
  336. return g_strYcWave;
  337. case LOGIN:
  338. case LOGOUT:
  339. return g_strLoginWave;
  340. case YK:
  341. return g_strYkWave;
  342. case YX_CHANGE:
  343. return g_strYxChangeWave;
  344. case SET:
  345. return g_strSetWave;
  346. }
  347. #endif
  348. return "";
  349. }
  350. DWORD WINAPI CRealEventDlg::ThreadPlaySound( CRealEventDlg *pDlg )
  351. {
  352. do
  353. {
  354. int nSize = pDlg->m_ctrlGrid.GetItemCount();
  355. if( nSize > 0 )
  356. {
  357. int nSec=0;
  358. CString sDeal,sContent;
  359. for( int i=0;i<nSize;i++ )
  360. {
  361. sContent = pDlg->m_ctrlGrid.GetItemText( i,4 );
  362. sDeal = pDlg->m_ctrlGrid.GetItemText( i,5 );
  363. sDeal = sDeal.TrimLeft();
  364. if( -1 != sDeal.Find( "等待确认" ) )
  365. {
  366. CString strUid;
  367. int nVarID=0,nStatus=0,nAlarmIndex=0,nIsSound=0,nColor=0;
  368. pEventServer->GetOneEventInfo( i,strUid,nVarID,nStatus,nAlarmIndex,nIsSound,nColor );
  369. if( nIsSound==0 )
  370. {
  371. CString strFileName;
  372. if( g_nAlarmModeIsSound==1 )
  373. {
  374. strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, strUid, nVarID,nAlarmIndex );
  375. pStoneUDLLTxtToWav( (char *)(LPCTSTR)sContent, (char *)(LPCTSTR)strFileName,g_nTTSType,-5,300 );
  376. UINT uFlag = SND_ASYNC|SND_LOOP|SND_NODEFAULT;
  377. pDlg->m_bStopSound = false;
  378. pDlg->PlaySoundTims( strFileName,g_nAlarmModeSoundPlayNum );
  379. pEventServer->SetOneEventInfo( i,1,1 );
  380. if( PathFileExists(strFileName) )
  381. DeleteFile( strFileName );
  382. }
  383. else if( g_nAlarmModeIsSound==2 )
  384. {
  385. strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", pDlg->m_sIoServerPath, strUid, nVarID,nAlarmIndex );
  386. UINT uFlag = SND_ASYNC|SND_LOOP|SND_NODEFAULT;
  387. pDlg->m_bStopSound = false;
  388. pDlg->PlaySoundTims( strFileName,g_nAlarmModeSoundPlayNum );
  389. pEventServer->SetOneEventInfo( i,1,1 );
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  396. return 0;
  397. }
  398. HBRUSH CRealEventDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  399. {
  400. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  401. // TODO: 在此更改 DC 的任何属性
  402. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  403. return hbr;
  404. }
  405. BOOL CRealEventDlg::OnEraseBkgnd(CDC* pDC)
  406. {
  407. CBrush br1;
  408. CRect rect;
  409. GetWindowRect(&rect);
  410. ScreenToClient(&rect);
  411. br1.CreateSolidBrush(RGB(230, 241, 249));
  412. pDC->FillRect(rect,&br1);
  413. DeleteObject( br1 );
  414. return TRUE;
  415. //return CDialog::OnEraseBkgnd(pDC);
  416. }
  417. //确认全部
  418. void CRealEventDlg::OnHide()
  419. {
  420. int nSize = m_ctrlGrid.GetItemCount();
  421. if( nSize==0 )
  422. return;
  423. if( MessageBox( "确定要确认全部事件(在等待确认状态的事件才能确认 )?", g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  424. return;
  425. int nSec=0;
  426. CString sDeal,sTemp1;
  427. for( int i=0;i<nSize;i++ )
  428. {
  429. sDeal = m_ctrlGrid.GetItemText( i,5 );
  430. sDeal = sDeal.TrimLeft();
  431. if( -1 != sDeal.Find( "等待确认" ) )
  432. {
  433. CString strUid;
  434. int nVarID=0,nStatus=0,nAlarmIndex=0,nIsSound=0,nColor=0;
  435. pEventServer->GetOneEventInfo( i,strUid,nVarID,nStatus,nAlarmIndex,nIsSound,nColor );
  436. pEventServer->SetOneEventInfo( i,1,1 );
  437. m_bStopSound = true;
  438. sndPlaySound( NULL, SND_ASYNC );
  439. sndPlaySound( NULL,NULL );
  440. Sleep( 100 );
  441. pDevicesManager->ConfigAlarm( strUid,nVarID,nStatus,nAlarmIndex );
  442. m_ctrlGrid.SetItemText( i,5," 已经确认" );
  443. }
  444. }
  445. }
  446. //确认所选
  447. void CRealEventDlg::OnConfirm()
  448. {
  449. int iListCount = m_ctrlGrid.GetItemCount();
  450. POSITION pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  451. int nListSel = m_ctrlGrid.GetNextSelectedItem(pos);
  452. if(nListSel>=iListCount || nListSel==-1)
  453. {
  454. return;
  455. }
  456. if( MessageBox( "确定要确认所选择的事件(等待确认状态的事件才能确认 )?", g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  457. return;
  458. pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  459. if(NULL == pos)
  460. {
  461. }
  462. else
  463. {
  464. CString sDeal,sTemp1;
  465. while(pos)
  466. {
  467. int nItem = m_ctrlGrid.GetNextSelectedItem(pos);
  468. sDeal = m_ctrlGrid.GetItemText( nItem,5 );
  469. if( -1 != sDeal.Find( "等待确认" ) )
  470. {
  471. CString strUid;
  472. int nVarID=0,nStatus=0,nAlarmIndex=0,nIsSound=0,nColor=0;
  473. pEventServer->GetOneEventInfo( nItem,strUid,nVarID,nStatus,nAlarmIndex,nIsSound,nColor );
  474. pEventServer->SetOneEventInfo( nItem,1,1 );
  475. m_bStopSound = true;
  476. sndPlaySound( NULL, SND_ASYNC );
  477. sndPlaySound( NULL,NULL );
  478. Sleep( 100 );
  479. pDevicesManager->ConfigAlarm( strUid,nVarID,nStatus,nAlarmIndex );
  480. m_ctrlGrid.SetItemText( nItem,5," 已经确认" );
  481. }
  482. }
  483. }
  484. }
  485. //删除所选
  486. void CRealEventDlg::OnDeleteall()
  487. {
  488. int iListCount = m_ctrlGrid.GetItemCount();
  489. POSITION pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  490. int nListSel = m_ctrlGrid.GetNextSelectedItem(pos);
  491. if(nListSel>=iListCount || nListSel==-1)
  492. {
  493. return;
  494. }
  495. if( MessageBox( "确定要删除所选择的事件(等待确认状态的事件不能删除 )?", g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
  496. return;
  497. pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  498. if(NULL == pos)
  499. {
  500. }
  501. else
  502. {
  503. CString sDeal,sTemp1;
  504. while(pos)
  505. {
  506. int nItem = m_ctrlGrid.GetNextSelectedItem(pos);
  507. sDeal = m_ctrlGrid.GetItemText( nItem,5 );
  508. if( -1 == sDeal.Find( "等待确认" ) )
  509. {
  510. pEventServer->DeleteOneEvent( nItem );
  511. m_ctrlGrid.DeleteItem( nItem );
  512. pos = m_ctrlGrid.GetFirstSelectedItemPosition();
  513. }
  514. }
  515. }
  516. int a=0;
  517. }
  518. //关闭对话框
  519. void CRealEventDlg::OnBtnEixt()
  520. {
  521. bool bCanExit=true;
  522. int nSize = m_ctrlGrid.GetItemCount();
  523. if( nSize>0 )
  524. {
  525. int nSec=0;
  526. CString sDeal,sTemp1;
  527. for( int i=0;i<nSize;i++ )
  528. {
  529. sDeal = m_ctrlGrid.GetItemText( i,5 );
  530. sDeal = sDeal.TrimLeft();
  531. if( -1 != sDeal.Find( "等待确认" ) )
  532. {
  533. bCanExit = false;
  534. break;
  535. }
  536. }
  537. }
  538. if( bCanExit )
  539. {
  540. if( nSize>0 )
  541. {
  542. for( int i=nSize-1;i>=0;i-- )
  543. {
  544. pEventServer->DeleteOneEvent( i );
  545. m_ctrlGrid.DeleteItem( i );
  546. }
  547. }
  548. OnOK();
  549. }
  550. else
  551. MessageBox( "还有等待确认状态的事件尚未处理,不能关闭对话框", g_strTip, MB_ICONINFORMATION);
  552. }
  553. BOOL CRealEventDlg::PreTranslateMessage(MSG* pMsg)
  554. {
  555. // TODO: 在此添加专用代码和/或调用基类
  556. if( pMsg->message == WM_KEYDOWN )
  557. {
  558. if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_ESCAPE)
  559. {
  560. return TRUE;
  561. }
  562. }
  563. return CDialog::PreTranslateMessage(pMsg);
  564. }