123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997 |
- // RealEventDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "IDE.h"
- #include "RealEventDlg.h"
- #include <mmsystem.h>
- #include "shlwapi.h"
- #include "mainfrm.h"
- #include ".\realeventdlg.h"
- #include <io.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern BOOL g_bRun;
- extern BOOL g_bEventAlarm;
- extern CString g_strYkWave;
- extern CString g_strLoginWave;
- extern CString g_strReguWave;
- extern CString g_strSetWave;
- extern CString g_strYcWave;
- extern CString g_strYxChangeWave;
- #include "MainFrm.h"
- extern CMainFrame *g_pMainFrm;
- CRITICAL_SECTION g_csCreateWav;
- /////////////////////////////////////////////////////////////////////////////
- // CRealEventDlg dialog
- bool DeleteWav( CString strPath, CString strFileName, int nLayer )
- {
- CStringArray saFilePath;
- long hfile;
- struct _finddata_t fFile;
- CString strCurr = strPath + "\\" + strFileName;
- int nDone=0;
- hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
- if( -1L != hfile )
- {
- while( !( nDone = _findnext(hfile, &fFile) ) )
- {
- if( !strcmp(fFile.name,"..") ) continue;
- if( ( fFile.attrib==16 || fFile.attrib==18 || fFile.attrib==48 || fFile.attrib==2064 ||
- fFile.attrib==2096 || fFile.attrib==2098 || fFile.attrib==16432 || fFile.attrib==16434 ) ) //_A_SUBDIR
- {
- }
- else
- {
- CString str = fFile.name;
- CString sFileNameTemp = strPath + "\\" + str;
-
- if( -1 != str.Find( "temp" ) )
- {
- saFilePath.Add( sFileNameTemp );
- }
- }
- }
- _findclose(hfile);
- }
- for( int i=0;i<saFilePath.GetCount();i++ )
- {
- DeleteFile( saFilePath.GetAt( i ) );
- }
- return true;
- }
- CRealEventDlg::CRealEventDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CRealEventDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CRealEventDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_bStopSound = false;
- m_bExitThread = false;
- m_hPlaysound = NULL;
- m_hCreateWav = NULL;
- InitializeCriticalSection( &g_csCreateWav );
- }
- CRealEventDlg::~CRealEventDlg()
- {
- if( m_hPlaysound )
- {
- //MTVERIFY( WaitForSingleObject( m_hPlaysound, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( m_hPlaysound ) );
- m_hPlaysound = NULL;
- }
- if( m_hCreateWav )
- {
- MTVERIFY( CloseHandle( m_hCreateWav ) );
- m_hCreateWav = NULL;
- }
- DeleteCriticalSection( &g_csCreateWav );
- CDialog::~CDialog();
- }
- void CRealEventDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRealEventDlg)
- DDX_Control(pDX, IDC_LIST_GRID, m_ctrlGrid);
- DDX_Control(pDX, IDC_CONFIRM, m_Btn_Config);
- DDX_Control(pDX, IDC_HIDE, m_Btn_ConfigAll);
- DDX_Control(pDX, IDC_DELETEALL, m_BtnDel);
- DDX_Control(pDX, IDC_DELETEALL2, m_BtnDelAll);
- DDX_Control(pDX, IDC_BTN_EXIT, m_BtnExit);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CRealEventDlg, CDialog)
- //{{AFX_MSG_MAP(CRealEventDlg)
- ON_WM_PAINT()
- ON_WM_CREATE()
- ON_WM_TIMER()
- ON_BN_CLICKED(IDC_CONFIRM, OnConfirm)
- ON_BN_CLICKED(IDC_DELETEALL, OnDeleteall)
- ON_BN_CLICKED(IDC_DELETEALL2, OnDeleteall2)
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_HIDE, OnHide)
- ON_BN_CLICKED(IDC_BTN_EXIT, OnBtnEixt)
- ON_WM_SHOWWINDOW()
- //}}AFX_MSG_MAP
- ON_WM_CTLCOLOR()
- ON_WM_ERASEBKGND()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRealEventDlg message handlers
- BOOL CRealEventDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- //m_ctrlGrid.InsertColumn( 0, g_strHappentTime1 );
- //m_ctrlGrid.SetColumnWidth( 0, 135 );
- //m_ctrlGrid.InsertColumn( 1, g_strEventType );
- //m_ctrlGrid.SetColumnWidth( 1, 60);
- //m_ctrlGrid.InsertColumn( 2, g_strNormalData );
- //m_ctrlGrid.SetColumnWidth( 2, 110);
- //m_ctrlGrid.InsertColumn( 3, g_strAlarmData );
- //m_ctrlGrid.SetColumnWidth( 3, 60);
- //m_ctrlGrid.InsertColumn( 4, g_strEventInfo );
- //m_ctrlGrid.SetColumnWidth( 4, 470);
- //m_ctrlGrid.InsertColumn( 5, g_strDealStatus );
- //m_ctrlGrid.SetColumnWidth( 5, 100);
- //m_ctrlGrid.SetExtendedStyle(m_ctrlGrid.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- m_ctrlGrid.SetHeaderBKColor(213,222,242,8); //设置头部背景色
- ////m_List_Rule.SetFontHW(15,0); //设置字体高度,和宽度,0表示缺省宽度
- //m_List_Rule.SetColTextColor(2,RGB(255,255,100)); //设置列文本颜色
- //m_List_Rule.SetItemTextColor(3,1,RGB(255,0,0)); //设置单元格字体颜色
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- m_ctrlGrid.InsertColumn(0,g_strHappentTime1,LVCFMT_LEFT,145);
- m_ctrlGrid.InsertColumn(1,g_strEventType,LVCFMT_CENTER,70);
- m_ctrlGrid.InsertColumn(2,g_strNormalData,LVCFMT_CENTER,110);
- m_ctrlGrid.InsertColumn(3,g_strAlarmData,LVCFMT_CENTER,70);
- m_ctrlGrid.InsertColumn(4,g_strEventInfo,LVCFMT_LEFT,screenx-145-70-110-70-100-80-9 );//500);
- m_ctrlGrid.InsertColumn(5,g_strDealStatus,LVCFMT_LEFT,100);
- m_ctrlGrid.SetExtendedStyle(m_ctrlGrid.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- m_ctrlGrid.SetBkColor( RGB( 204,232,207 ) );
- //SetWindowLong(m_ctrlList.m_hWnd ,GWL_EXSTYLE,WS_EX_CLIENTEDGE);
- //m_ctrlList.SetExtendedStyle(LVS_EX_GRIDLINES); //设置扩展风格为网格
- //::SendMessage(m_ctrlList.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
- m_ctrlGrid.SetRowHeigt( 20 );
- CString sIDE;
- sIDE.Format( "%s",g_strDirectory );
- int nEnd = 0;
- for (int i = sIDE.GetLength()-1; i >= 0; i--)
- {
- if (sIDE[i] == '\\')
- {
- nEnd = i;
- break;
- }
- }
- m_sIoServerPath = sIDE.Left( nEnd ) + "\\new_server";
- if( g_nAlarmModeIsSound != 0 )
- {
- //LOG4C((LOG_NOTICE, "启动 ThreadPlaySound" ));
- m_hPlaysound = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadPlaySound,this,0,NULL);
- if (m_hPlaysound == NULL)
- {
-
- }
- m_hCreateWav = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadCreateWav,this,0,NULL);
- }
- SetTimer( 2,1000,NULL );//更改等待状态和时间
- //SetTimer( 3,300,NULL );//设置颜色
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CRealEventDlg::SetPos( int iWidth,int iHeight )
- {
- CRect rc1;
- rc1.left = 0;
- rc1.right = rc1.left+iWidth;
- rc1.top = 0;
- rc1.bottom = rc1.top+iHeight;
- this->MoveWindow( rc1 );
- int nBtnH = int( float(iHeight-25)/4 );
- CRect rc2;
- rc2.right = rc1.right - 5;
- rc2.left = rc2.right - 80;
- rc2.top = 0;
- rc2.bottom = rc2.top + nBtnH;
- m_Btn_ConfigAll.MoveWindow( rc2 );
- CRect rc3;
- rc3.right = rc1.right - 5;
- rc3.left = rc3.right - 80;
- rc3.top = rc2.bottom + 0;
- rc3.bottom = rc3.top + nBtnH;
- m_Btn_Config.MoveWindow( rc3 );
- CRect rc4;
- rc4.right = rc1.right - 5;
- rc4.left = rc4.right - 80;
- rc4.top = rc3.bottom + 1;
- rc4.bottom = rc4.top + nBtnH;
- m_BtnDelAll.MoveWindow( rc4 );
- CRect rc5;
- rc5.right = rc1.right - 5;
- rc5.left = rc5.right - 80;
- rc5.top = rc4.bottom + 0;
- rc5.bottom = rc5.top + nBtnH;
- m_BtnDel.MoveWindow( rc5 );
- //CRect rc6;
- //rc6.right = rc1.right - 5;
- //rc6.left = rc6.right - 100;
- //rc6.top = rc5.bottom + 1;
- //rc6.bottom = rc6.top + 20;
- //m_BtnExit.MoveWindow( rc6 );
- CRect rcList;
- rcList.left = 0;
- rcList.right = rc2.left - 1;
- rcList.top = 0;
- rcList.bottom = rc1.bottom-5;//25;rc5.bottom;//
- m_ctrlGrid.MoveWindow( rcList );
- }
- void CRealEventDlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
-
- // Do not call CDialog::OnPaint() for painting messages
- }
- int CRealEventDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- AfxEnableControlContainer();
- if (CDialog::OnCreate(lpCreateStruct) == -1)
- return -1;
- SetTimer(1, 400, NULL);
- return 0;
- }
-
- void CRealEventDlg::OnTimer(UINT nIDEvent)
- {
- // 如果不报警,直接返回
- if ( !g_bRun ) return;
-
- //判断是否跳到报警画面
- if( nIDEvent==1 )
- {
- // 取新事件,加入列表
- CAlarmEvent* pEvent = pEventServer->GetNewEvent();
- if ( pEvent != NULL )
- {
- if( strcmp(pEvent->strContent,"") == 0 )
- {
- pEvent->nGet = 1;
- return;
- }
- //自动跳到报警画面
- if( g_nAlarmToView && pEvent->strContent.Find(pVariantsManager->m_strReturnNormal) == -1 )
- {
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- CString sVarName = pVariantsManager->GetVarNameByID( pEvent->nVarID );
- pFrame->SendMessage( WM_MY_NEW_ALERT,(WPARAM)sVarName.GetBuffer(sVarName.GetLength()),0 );
- sVarName.ReleaseBuffer();
- }
- m_bComfig = true;
- AddEventInfoToList(pEvent);
- //LOG4C((LOG_NOTICE, "AddEventInfoToList %s",pEvent->strContent));
- if ( !IsWindowVisible() && g_bRun)
- {
- ShowWindow(SW_SHOW);
- }
- }
- }
- //列表状态
- if( nIDEvent==2 )
- {
- int nSize = m_ctrlGrid.GetItemCount();
- if( nSize>0 )
- {
- int nSec=0;
- CString sDeal,sTemp1;
- for( int i=0;i<nSize;i++ )
- {
- sDeal = m_ctrlGrid.GetItemText( i,5 );
- sDeal = sDeal.TrimLeft();
- CAlarmEvent* pEvent = pEventServer->GetOneEvent( i );
- //LOG4C((LOG_NOTICE, "pDevUid = %s,nVarID = %d, nAlarmIndex = %d nStatus=%d ", strUid,nVarID,nAlarmIndex,nStatus ));
- if( -1 != sDeal.Find( g_strAC_WaitConfig ) && pEvent->nDealStatus==3 )//确认成功
- {
- sDeal.Format( " %s",g_strAC_ConfigSuccess );
- m_ctrlGrid.SetItemText( i,5,sDeal );
- }
- else
- {
- if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
- {
- sTemp1 = sDeal.Mid( g_strAC_WaitConfig.GetLength()+1,sDeal.GetLength()-g_strAC_WaitConfig.GetLength()-2 );
- nSec = atoi( sTemp1 )-1;
- if( nSec>=0 )
- {
- sDeal.Format( " %s(%d)",sDeal.Left(g_strAC_WaitConfig.GetLength()),nSec );
- m_ctrlGrid.SetItemText( i,5,sDeal );
- }
- else
- {
- sDeal.Format( " %s",g_strAC_WaitOut );
- m_ctrlGrid.SetItemText( i,5,sDeal );
- }
- }
- }
- }
- }
- }
- ////
- //if( nIDEvent==3 && g_nAlarmModeIsSound != 0 )
- //{
- // int nSize = m_ctrlGrid.GetItemCount();
- // if( nSize>0 )
- // {
- // int nSec=0;
- // CString sDeal,sTemp1;
- // for( int i=0;i<nSize;i++ )
- // {
- // sDeal = m_ctrlGrid.GetItemText( i,5 );
- // sDeal = sDeal.TrimLeft();
- // //if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
- // {
- // CString strUid;
- // int nVarID=0,nStatus=0,nAlarmIndex=0,nIsSound=0,nColor=0;
- // pEventServer->GetOneEvent( i );
- // if( nIsSound==0 && nColor!=1 )
- // {
- // //pEventServer->SetOneEventInfo( i,0,1 );
- // //m_ctrlGrid.SetItemColor( 5,i,RGB(255,0,0) );
- // //m_ctrlGrid.Invalidate();
- // break;
- // }
- // else if( nIsSound==0 )
- // {
- // break;
- // }
- // else if( nIsSound==1 && nColor!=2 )
- // {
- // //pEventServer->SetOneEventInfo( i,1,2 );
- // //m_ctrlGrid.SetItemColor( 5,i,RGB(204,232,207) );
- // //m_ctrlGrid.Invalidate();
- // }
- // }
- // }
- // }
- //}
- CDialog::OnTimer(nIDEvent);
- }
- void CRealEventDlg::PlaySoundTims( CString sWavPath,int iTimes )
- {
- MSG message;
- BOOL bRet = false;
- int nTimes = 0;
- while( !m_bStopSound )
- {
- bRet = sndPlaySound( sWavPath,SND_FILENAME|SND_ASYNC|SND_NOSTOP );
- Sleep( 100 );
- if( bRet )
- {
- nTimes++;
- if( nTimes>=iTimes )
- {
- break;
- }
- }
- if(::PeekMessage (&message,NULL,0,0,PM_REMOVE))
- { //响应其他事件 如Exit按钮操作
- ::TranslateMessage (&message);
- ::DispatchMessage (&message);
- }
- }
- }
- void CRealEventDlg::OnClose()
- {
- // m_bComfig = false;
- // m_ctrlGrid.DeleteAllItems();
- // // 将所有未确定事件确定;
- // while( m_pCurEvent != NULL )
- // {
- // CAnalog *pAnalog = pVariantsManager->FindAnalog( m_pCurEvent->nVarID );
- // pAnalog->bConfirm = true;
- // m_pCurEvent->nConfirm = m_pCurEvent->nConfirm==0?1:3;
- // m_pCurEvent = pEventServer->GetUnconfirmEvent();
- // }
- //
- //#if 1
- // sndPlaySound( NULL, SND_ASYNC );
- // sndPlaySound(NULL,NULL); //停止
- //#endif
- // ShowWindow(SW_HIDE);
- }
- CString CRealEventDlg::GetWeekStr( int iDayofWeek )
- {
- CString sRet;
- switch( iDayofWeek )
- {
- case 0: sRet = "日"; break;
- case 1: sRet = "一"; break;
- case 2: sRet = "二"; break;
- case 3: sRet = "三"; break;
- case 4: sRet = "四"; break;
- case 5: sRet = "五"; break;
- case 6: sRet = "六"; break;
- }
- return sRet;
- }
- void CRealEventDlg::AddEventInfoToList(CAlarmEvent *event)
- {
- ::SendMessage( g_pMainFrm->m_hbottomDockBar,WM_MY_INVALIDATE,0,0 );
- CString sTime,sEventTye,sNormalData,sCurrentData,sContent,sDealStatus;
- 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 ) );
- sEventTye = event->nStatus==0 ? g_strAlarm : g_strReturnNormal2;
- if( event->nUpperLimit>0 || event->nLowerLimit>0 || event->nUpperLimit>event->nLowerLimit )
- {
- sNormalData.Format( "%d ≤ X ≤ %d",event->nLowerLimit,event->nUpperLimit );//sNormalData.Format( "%d<= X <=%d",event->nLowerLimit,event->nUpperLimit );
- sCurrentData.Format( "%0.1f",event->dbParaValue );
- }
- else
- {
- sNormalData.Format( "X = %d",event->nNormalState );
- sCurrentData.Format( "%d",event->nAlarmState );
- }
- sDealStatus.Format( " %s(%d)",g_strAC_WaitConfig,event->nNoticeDelay );
- int nInsertIndex = m_ctrlGrid.GetItemCount();
- m_ctrlGrid.InsertItem(nInsertIndex, sTime);
- m_ctrlGrid.SetItemText(nInsertIndex, 1, sEventTye );
- m_ctrlGrid.SetItemText(nInsertIndex, 2, sNormalData);
- m_ctrlGrid.SetItemText(nInsertIndex, 3, sCurrentData);
- m_ctrlGrid.SetItemText(nInsertIndex, 4, " "+event->strContent);
- m_ctrlGrid.SetItemText(nInsertIndex, 5, sDealStatus );
- if( event->nStatus==0 )
- {
- //if( event->strContent.Find( "通信" )==-1 )
- //{
- m_ctrlGrid.SetItemColor( 0,nInsertIndex,RGB(211,63,45) );
- m_ctrlGrid.SetItemColor( 1,nInsertIndex,RGB(211,63,45) );
- m_ctrlGrid.SetItemColor( 2,nInsertIndex,RGB(211,63,45) );
- m_ctrlGrid.SetItemColor( 3,nInsertIndex,RGB(211,63,45) );
- m_ctrlGrid.SetItemColor( 4,nInsertIndex,RGB(211,63,45) );
- m_ctrlGrid.SetItemColor( 5,nInsertIndex,RGB(211,63,45) );
- m_ctrlGrid.SetItemTextColor( 0,nInsertIndex,RGB(255,255,255) );
- m_ctrlGrid.SetItemTextColor( 1,nInsertIndex,RGB(255,255,255) );
- m_ctrlGrid.SetItemTextColor( 2,nInsertIndex,RGB(255,255,255) );
- m_ctrlGrid.SetItemTextColor( 3,nInsertIndex,RGB(255,255,255) );
- m_ctrlGrid.SetItemTextColor( 4,nInsertIndex,RGB(255,255,255) );
- m_ctrlGrid.SetItemTextColor( 5,nInsertIndex,RGB(255,255,255) );
- //}
- //else
- //{
- // m_ctrlGrid.SetItemColor( 0,nInsertIndex,RGB(215,215,0) );
- // m_ctrlGrid.SetItemColor( 1,nInsertIndex,RGB(215,215,0) );
- // m_ctrlGrid.SetItemColor( 2,nInsertIndex,RGB(215,215,0) );
- // m_ctrlGrid.SetItemColor( 3,nInsertIndex,RGB(215,215,0) );
- // m_ctrlGrid.SetItemColor( 4,nInsertIndex,RGB(215,215,0) );
- // m_ctrlGrid.SetItemColor( 5,nInsertIndex,RGB(215,215,0) );
- // m_ctrlGrid.SetItemTextColor( 0,nInsertIndex,RGB(0,0,0) );
- // m_ctrlGrid.SetItemTextColor( 1,nInsertIndex,RGB(0,0,0) );
- // m_ctrlGrid.SetItemTextColor( 2,nInsertIndex,RGB(0,0,0) );
- // m_ctrlGrid.SetItemTextColor( 3,nInsertIndex,RGB(0,0,0) );
- // m_ctrlGrid.SetItemTextColor( 4,nInsertIndex,RGB(0,0,0) );
- // m_ctrlGrid.SetItemTextColor( 5,nInsertIndex,RGB(0,0,0) );
- //}
- }
- else
- {
- m_ctrlGrid.SetItemColor( 0,nInsertIndex,RGB(80,128,30) );
- m_ctrlGrid.SetItemColor( 1,nInsertIndex,RGB(80,128,30) );
- m_ctrlGrid.SetItemColor( 2,nInsertIndex,RGB(80,128,30) );
- m_ctrlGrid.SetItemColor( 3,nInsertIndex,RGB(80,128,30) );
- m_ctrlGrid.SetItemColor( 4,nInsertIndex,RGB(80,128,30) );
- m_ctrlGrid.SetItemColor( 5,nInsertIndex,RGB(80,128,30) );
- }
- m_ctrlGrid.EnsureVisible(nInsertIndex, FALSE);
- if( g_nAlarmModeIsSound==1 )
- {
- EnterCriticalSection( &g_csCreateWav );
- CString strFileName;
- strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, event->strUid, event->nVarID,event->nAlarmIndex );
- m_saWavPath.Add( strFileName );
- m_saWavContent.Add( event->strContent );
- LeaveCriticalSection( &g_csCreateWav );
- }
- }
- CString CRealEventDlg::GetAlarmFile(int type)
- {
- #if 0
- switch (type)
- {
- case YC_LOWALARM:
- case YC_UPALARM:
- case YC_BACK:
- return g_strYcWave;
- case LOGIN:
- case LOGOUT:
- return g_strLoginWave;
- case YK:
- return g_strYkWave;
- case YX_CHANGE:
- return g_strYxChangeWave;
- case SET:
- return g_strSetWave;
- }
- #endif
- return "";
- }
- bool CRealEventDlg::IsCreateWavOK( CString sWavPath )
- {
- bool bRet = true;
- CString sPath;
- for( int i=0;i<m_saWavPath.GetCount();i++ )
- {
- sPath = m_saWavPath.GetAt( 0 );
- if( sPath==sWavPath )
- {
- bRet = false;
- break;
- }
- }
- return bRet;
- }
- DWORD WINAPI CRealEventDlg::ThreadPlaySound( CRealEventDlg *pDlg )
- {//(M1)458=00(M4)268=00(W14)469=00()=00
- do
- {
- int nSize = pDlg->m_ctrlGrid.GetItemCount();
- if( nSize > 0 )
- {
- int nSec=0;
- CString sDeal,sContent;
- for( int i=0;i<nSize;i++ )
- {
- sContent = pDlg->m_ctrlGrid.GetItemText( i,4 );
- sDeal = pDlg->m_ctrlGrid.GetItemText( i,5 );
- sDeal = sDeal.TrimLeft();
- //if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
- {
- nSize = pDlg->m_ctrlGrid.GetItemCount();
- if( i>=nSize )
- continue;
- EnterCriticalSection( &g_csCreateWav );
- CAlarmEvent* pEvent = pEventServer->GetOneEvent( i );
- LeaveCriticalSection( &g_csCreateWav );
- if( pEvent->nSoundTimes<g_nAlarmModeSoundPlayNum && -1 == sDeal.Find( g_strAC_ConfigSuccess ) )
- {
- pEvent->nSoundTimes++;
- CString strFileName;
-
- if( g_nAlarmModeIsSound==1 && pEvent->nWarningLevel>=g_nCommWavLevel )//IDE生成
- {
- strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", g_strDirectory, pEvent->strUid, pEvent->nVarID,pEvent->nAlarmIndex );
- if( !pDlg->IsCreateWavOK( strFileName ) )
- continue;
- if( pDlg->ExistFile(strFileName ) )
- {
- pDlg->m_bStopSound = false;
- pDlg->PlaySoundTims( strFileName,1 );
- LOG4C((LOG_NOTICE, "1:%s",strFileName ));
- }
- }
- else if( g_nAlarmModeIsSound==2 && pEvent->nWarningLevel>=g_nCommWavLevel )//IOServer生成
- {
- strFileName.Format("%s\\wav\\temp_%s_%d_%d_IDE.wav", pDlg->m_sIoServerPath, pEvent->strUid, pEvent->nVarID,pEvent->nAlarmIndex );
- //LOG4C((LOG_NOTICE, "strFileName = %s", strFileName ));
- if( !PathFileExists( strFileName ) )
- {
- LOG4C((LOG_NOTICE, "不存在 %s", strFileName ));
- }
- if( pDlg->ExistFile( strFileName ) )
- {
- pDlg->m_bStopSound = false;
- pDlg->PlaySoundTims( strFileName,1 );
- LOG4C((LOG_NOTICE, "2:%s",strFileName ));
- }
- }
- }
- }
- nSize = pDlg->m_ctrlGrid.GetItemCount();
- Sleep( 1000 );
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
- return 0;
- }
- DWORD WINAPI CRealEventDlg::ThreadCreateWav( CRealEventDlg *pDlg )
- {
- do
- {
- static bool sbCreateNow = false;
- int nSize1 = pDlg->m_saWavPath.GetCount();
- int nSize2 = pDlg->m_saWavContent.GetCount();
- if( nSize1>0 && nSize2>0 && !sbCreateNow )
- {
- if( g_nAlarmModeIsSound==1 && pStoneUDLLTxtToWav )
- {
- sbCreateNow = true;
- EnterCriticalSection( &g_csCreateWav );
- CString sPath = pDlg->m_saWavPath.GetAt(0);
- CString sContent = pDlg->m_saWavContent.GetAt(0);
-
- try
- {
- pStoneUDLLTxtToWav( (char *)(LPCTSTR)sContent, (char *)(LPCTSTR)sPath,g_nTTSType,-5,300 );
- }
- catch(...)
- {
- LOG4C((LOG_NOTICE, "pDBMonitorDLLTxtToWav 出错"));
- }
-
- pDlg->m_saWavPath.RemoveAt(0);
- pDlg->m_saWavContent.RemoveAt(0);
-
- LeaveCriticalSection( &g_csCreateWav );
- sbCreateNow = false;
- }
- }
- else if( nSize1==0 && nSize2==0 )
- {
- CTime ctNow = CTime::GetCurrentTime();
- int nHour;
- nHour = ctNow.GetHour();
- static bool bCanDelWav = true;
- if( nHour == 23 && bCanDelWav )
- {
- bCanDelWav = false;
- CString strDectory;
- strDectory.Format("%s\\wav", g_strDirectory );
- DeleteWav( strDectory,"*.*",0 );
- LOG4C((LOG_NOTICE, "清空语音文件" ));
- }
- else if( nHour != 23 )
- {
- bCanDelWav = true;
- }
- }
- Sleep( 100 );
- }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
- return 0;
- }
- bool CRealEventDlg::ExistFile(CString strFileName)
- {
- CFileStatus status;
- CString msg;
- if(!CFile::GetStatus(strFileName,status))
- {
- return false;
- }
- return true;
- }
- HBRUSH CRealEventDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // TODO: 在此更改 DC 的任何属性
- // TODO: 如果默认的不是所需画笔,则返回另一个画笔
- return hbr;
- }
- BOOL CRealEventDlg::OnEraseBkgnd(CDC* pDC)
- {
- CBrush br1;
- CRect rect;
- GetWindowRect(&rect);
- ScreenToClient(&rect);
- br1.CreateSolidBrush(RGB(230, 241, 249));
- pDC->FillRect(rect,&br1);
- DeleteObject( br1 );
-
- return TRUE;
- //return CDialog::OnEraseBkgnd(pDC);
- }
- //确认全部
- void CRealEventDlg::OnHide()
- {
- int nSize = m_ctrlGrid.GetItemCount();
- if( nSize==0 )
- return;
- //if( MessageBox( g_strAC_ConfigAllEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
- // return;
- int nSec=0;
- CString sDeal,sTemp1;
- for( int i=0;i<nSize;i++ )
- {
- sDeal = m_ctrlGrid.GetItemText( i,5 );
- sDeal = sDeal.TrimLeft();
- if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
- {
- CAlarmEvent* pEvent = pEventServer->GetOneEvent( i );
- //pEventServer->SetOneEventInfo( i,1,1 );
- m_bStopSound = true;
- sndPlaySound( NULL, SND_ASYNC );
- sndPlaySound( NULL,NULL );
- Sleep( 100 );
- pDevicesManager->ConfigAlarm( pEvent->strUid,pEvent->nVarID,pEvent->nStatus,pEvent->nAlarmIndex );
- //m_ctrlGrid.SetItemText( i,5," 确认成功" );
- }
- }
- }
- //确认所选
- void CRealEventDlg::OnConfirm()
- {
- int iListCount = m_ctrlGrid.GetItemCount();
- POSITION pos = m_ctrlGrid.GetFirstSelectedItemPosition();
- int nListSel = m_ctrlGrid.GetNextSelectedItem(pos);
- if(nListSel>=iListCount || nListSel==-1)
- {
- MessageBox( g_strMsgSelectDel, g_strTip, MB_ICONINFORMATION);
- return;
- }
- //if( MessageBox( g_strAC_ConfigChooseEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
- // return;
- pos = m_ctrlGrid.GetFirstSelectedItemPosition();
- if(NULL == pos)
- {
- }
- else
- {
- CString sDeal,sTemp1;
- while(pos)
- {
- int nItem = m_ctrlGrid.GetNextSelectedItem(pos);
- sDeal = m_ctrlGrid.GetItemText( nItem,5 );
- if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
- {
- CAlarmEvent* pEvent = pEventServer->GetOneEvent( nItem );
- //pEventServer->SetOneEventInfo( nItem,1,1 );
- m_bStopSound = true;
- sndPlaySound( NULL, SND_ASYNC );
- sndPlaySound( NULL,NULL );
- Sleep( 100 );
- pDevicesManager->ConfigAlarm( pEvent->strUid,pEvent->nVarID,pEvent->nStatus,pEvent->nAlarmIndex );
- //m_ctrlGrid.SetItemText( nItem,5," 确认成功" );
- }
- }
- }
- }
- //删除全部
- void CRealEventDlg::OnDeleteall2()
- {
- bool bCanExit=true;
- int nSize = m_ctrlGrid.GetItemCount();
- if( nSize>0 )
- {
- //if( MessageBox( g_strAC_DelAllEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
- // return;
- int nSec=0;
- CString sDeal,sTemp1;
- EnterCriticalSection( &g_csCreateWav );
- for( int i=nSize-1;i>=0;i-- )
- {
- sDeal = m_ctrlGrid.GetItemText( i,5 );
- sDeal = sDeal.TrimLeft();
- if( -1 == sDeal.Find( g_strAC_WaitConfig ) )
- {
- pEventServer->DeleteOneEvent( i );
- m_ctrlGrid.DeleteItem( i );
- }
- }
- LeaveCriticalSection( &g_csCreateWav );
- }
- }
- //删除所选
- void CRealEventDlg::OnDeleteall()
- {
- int iListCount = m_ctrlGrid.GetItemCount();
- POSITION pos = m_ctrlGrid.GetFirstSelectedItemPosition();
- int nListSel = m_ctrlGrid.GetNextSelectedItem(pos);
- if(nListSel>=iListCount || nListSel==-1)
- {
- MessageBox( g_strMsgSelectDel, g_strTip, MB_ICONINFORMATION);
- return;
- }
- //if( MessageBox( g_strAC_DelChooseEvent, g_strTip, MB_YESNO|MB_ICONINFORMATION)!=IDYES )
- // return;
- pos = m_ctrlGrid.GetFirstSelectedItemPosition();
- if(NULL == pos)
- {
- }
- else
- {
- CString sDeal,sTemp1;
- EnterCriticalSection( &g_csCreateWav );
- while(pos)
- {
- int nItem = m_ctrlGrid.GetNextSelectedItem(pos);
- sDeal = m_ctrlGrid.GetItemText( nItem,5 );
- if( -1 == sDeal.Find( g_strAC_WaitConfig ) )
- {
- pEventServer->DeleteOneEvent( nItem );
- m_ctrlGrid.DeleteItem( nItem );
-
- pos = m_ctrlGrid.GetFirstSelectedItemPosition();
- }
- }
- LeaveCriticalSection( &g_csCreateWav );
- }
- int a=0;
- }
- //关闭对话框
- void CRealEventDlg::OnBtnEixt()
- {
- //bool bCanExit=true;
- //int nSize = m_ctrlGrid.GetItemCount();
- //if( nSize>0 )
- //{
- // int nSec=0;
- // CString sDeal,sTemp1;
- // for( int i=0;i<nSize;i++ )
- // {
- // sDeal = m_ctrlGrid.GetItemText( i,5 );
- // sDeal = sDeal.TrimLeft();
- // if( -1 != sDeal.Find( g_strAC_WaitConfig ) )
- // {
- // bCanExit = false;
- // break;
- // }
- // }
- //}
- //if( bCanExit )
- //{
- // if( nSize>0 )
- // {
- // for( int i=nSize-1;i>=0;i-- )
- // {
- // pEventServer->DeleteOneEvent( i );
- // m_ctrlGrid.DeleteItem( i );
- // }
- // }
- // OnOK();
- //}
- //else
- // MessageBox( "还有等待确认状态的事件尚未处理,不能关闭对话框", g_strTip, MB_ICONINFORMATION);
- }
- BOOL CRealEventDlg::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: 在此添加专用代码和/或调用基类
- if( pMsg->message == WM_KEYDOWN )
- {
- if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_ESCAPE)
- {
- return TRUE;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void CRealEventDlg::DeleteAllNotice()
- {
- bool bCanExit=true;
- int nSize = m_ctrlGrid.GetItemCount();
- if( nSize>0 )
- {
- int nSec=0;
- CString sDeal,sTemp1;
- for( int i=nSize-1;i>=0;i-- )
- {
- pEventServer->DeleteOneEvent( i );
- m_ctrlGrid.DeleteItem( i );
- }
- }
- }
|