⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgalarmlook.cpp

📁 电子监控的网络编程实例
💻 CPP
字号:
// DlgAlarmLook.cpp : implementation file
//

#include "stdafx.h"
#include "videocapture.h"
#include "DlgAlarmLook.h"
#include "VideoCaptureView.h"
#include "adodb.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgAlarmLook dialog


CDlgAlarmLook::CDlgAlarmLook(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgAlarmLook::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgAlarmLook)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgAlarmLook::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgAlarmLook)

	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgAlarmLook, CDialog)
	//{{AFX_MSG_MAP(CDlgAlarmLook)
	ON_BN_CLICKED(IDC_OK, OnOk)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_BUTTON_P, OnButtonP)
	ON_BN_CLICKED(IDC_BUTTON_N, OnButtonN)
	ON_BN_CLICKED(IDC_BUTTON_D, OnButtonD)
	ON_BN_CLICKED(IDC_BUTTON_T, OnButtonT)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
	ON_CBN_CLOSEUP(IDC_COMBO_HPHZ, OnCloseupComboHphz)
	ON_EN_KILLFOCUS(IDC_EDIT_HPHM, OnKillfocusEditHphm)
	ON_LBN_SELCHANGE(IDC_LIST_BKHP, OnSelchangeListBkhp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgAlarmLook message handlers

void CDlgAlarmLook::SetAlarm(CString XH,CString PASSTIME,CString PPHP,CString HPHM,CString HPYS,CString BJDM)
{
	
	GetDlgItem(IDC_EDIT_XH)->SetWindowText(XH);
	GetDlgItem(IDC_EDIT_JGSJ)->SetWindowText(PASSTIME);
	GetDlgItem(IDC_EDIT_PPHP)->SetWindowText(PPHP);
	GetDlgItem(IDC_EDIT_HPHM)->SetWindowText(HPHM);
	int i=((CComboBox *)GetDlgItem(IDC_COMBO_CPYS))->FindString(0,HPYS);
//	GetDlgItem(IDC_EDIT_XH)->SetWindowText(XH);


}

void CDlgAlarmLook::OnOk() 
{
	Save2DB();
}

BOOL CDlgAlarmLook::Save2DB()
{
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView) return false;

	CString sHPHM,sXYHP="",sql;
	CString XYHPs,BKYYs;
	CString ssss;
	GetDlgItem(IDC_EDIT_HPHM)->GetWindowText(sHPHM);
	CString sCLLX;
	CComboBox *pComb=(CComboBox *)GetDlgItem(IDC_COMBO_CLLX);
	int i;
	i=pComb->GetCurSel();
	if (i>-1) {
		sCLLX.Format("%0.2d",pComb->GetItemData(i));
	}else{
		sCLLX="00";
	}
		

	CListBox *pList=(CListBox *)GetDlgItem(IDC_LIST_BKHP);
	i=pList->GetCurSel();
	if (i>-1) {
		pList->GetText(i,sXYHP);
		long nBKYY=pList->GetItemData(i);
		ssss.Format("%s,%d",sXYHP,nBKYY);
		BKYYs=pView->Array_FindInBKYYList(nBKYY);
	}
	
	
	CListCtrl* pLC=(CListCtrl*)pView->GetDlgItem(IDC_LIST_ZDJC);
	int maxCount=pLC->GetItemCount();
	long lll;	
	for(i=0;i<maxCount;i++){
		lll=atol(pLC->GetItemText(i,0)); 		
		if(lll==m_nXH){
			pLC->SetItemText(i,1,sHPHM);
			pLC->SetItemText(i,7,sXYHP);
			pLC->SetItemText(i,8,BKYYs);			
			break;
		}
	}

	sql.Format("update record set hphm ='%s',hpzl='%s',xyhp='%s' where XH=%ld",sHPHM,sCLLX,ssss,m_nXH);	
	
	try{
		pView->pConn->Execute(sql);
		return true;
	}catch (...) {
	}
	
	return false;
}

BOOL CDlgAlarmLook::OnInitDialog() 
{
	CDialog::OnInitDialog();

	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView) return FALSE;

	
	/************************************************************************/
	/*    初始化界面控件													*/
	/************************************************************************/
	//传输标志
	if(pView->m_bAutoTrans)
		GetDlgItem(IDC_BUTTON_T)->EnableWindow(FALSE);
	else 
		GetDlgItem(IDC_BUTTON_T)->EnableWindow(TRUE);
	
	CComboBox *pComb;
	long nValue,nIndex;
	CString sValue;

	CADODataset *pRst=new CADODataset();
	CString sql;
	pRst->SetConnection(pView->pConn);

	//车辆类型
	try{
		pComb=(CComboBox *)GetDlgItem(IDC_COMBO_CLLX);
		sql="select hpzl,zlms from hpzl order by hpzl asc";
		pRst->Open(sql,CADODataset::openQuery);
		
		while (!pRst->IsEof()) {
			pRst->GetFieldValue("hpzl",sValue);
			nValue=atoi(sValue);
			pRst->GetFieldValue("zlms",sValue);
			nIndex=pComb->AddString(sValue);
			pComb->SetItemData(nIndex,nValue);
			pRst->MoveNext();
		}
		
	}catch (...) {		
	}


	//号牌汉字
	try{
		pComb=(CComboBox *)GetDlgItem(IDC_COMBO_HPHZ);
		if (pRst->IsOpen()) {
			pRst->Close();
		}
		sql="select HZ,PY from HPHZ order by py asc";
		pRst->Open(sql,CADODataset::openQuery);
		
		while (!pRst->IsEof()) {
			pRst->GetFieldValue("HZ",sValue);	
			pComb->AddString(sValue);
			pRst->GetFieldValue("PY",sValue);
			pRst->MoveNext();
		}
		
	}catch (...) {		
	}
		
	if (pRst->IsOpen()) {
		pRst->Close();
	}
	delete pRst;

	/************************************************************************/
	
	OpenRecord(m_nXH);
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//pos==0 首条记录 
//pos==1 前条记录 
//pos==2 后条记录 
//pos==3 末条记录 
bool CDlgAlarmLook::RecordChange(long pos,bool IfShowBox)
{

	//只能选择 当前的几条记录
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView)
		return FALSE;
	int m_nCurrentItem=-1;
	CListCtrl* pLC=(CListCtrl*)pView->GetDlgItem(IDC_LIST_ZDJC);
	int maxCount=pLC->GetItemCount();
	long lll,ll;	
	for(long i=0;i<maxCount;i++){
		lll=atol(pLC->GetItemText(i,0)); 		
		if(lll==m_nXH){
			m_nCurrentItem=i;
			break;
		}
	}
	
	switch(pos) {
	case 0://pos==0 首条记录 
		m_nCurrentItem=maxCount-1;
		break;
	case 1://pos==1 前条记录 
		m_nCurrentItem++;
		break;
	case 2://pos==2 后条记录 
		m_nCurrentItem--;
		break;
	case 3://pos==3 末条记录	
		m_nCurrentItem=0;
	}
	
	if (m_nCurrentItem<0 || m_nCurrentItem>=maxCount ) {
		if(IfShowBox)
			ShowMessage2("已经到达纪录边界,不得再移动!");
		return TRUE;
	}
	else{
		ll=atol(pLC->GetItemText(m_nCurrentItem,0));		
		m_nXH=ll;
		if (OpenRecord(m_nXH))
		{
			Invalidate();
		}else
			if(IfShowBox)
				ShowMessage2("该条纪录已经删除。");
			return true;
			
	}
	return TRUE;
}

void CDlgAlarmLook::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect rect;
	if (m_hpDib.m_hDIB) {
		GetDlgItem(IDC_STATIC_HPTP)->GetClientRect(&rect);
		ScreenToClient(&rect);
		m_hpDib.PaintDIB(dc,CRect(550,120,750,170),CRect(0,0,m_hpDib.DIBWidth(),m_hpDib.DIBHeight()));
	}
	if (m_txDib.m_hDIB) {
		GetDlgItem(IDC_STATIC_TXTP)->GetClientRect(&rect);
		ScreenToClient(&rect);
		m_txDib.PaintDIB(dc,CRect(5,5,520,400),CRect(0,0,768,576));
	}
}

void CDlgAlarmLook::OnButtonP() 
{
	// TODO: Add your control notification handler code here
	RecordChange(1);
}

void CDlgAlarmLook::OnButtonN() 
{
	// TODO: Add your control notification handler code here
	RecordChange(2);
}

void CDlgAlarmLook::OnButtonD() 
{

	//只能选择 当前的几条记录
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView)
		return ;
	CString sql;	
	sql.Format("delete from record where xh=%d",m_nXH);
	pView->pConn->Execute(sql);
	CListCtrl* pLC=(CListCtrl*)pView->GetDlgItem(IDC_LIST_ZDJC);
	int maxCount=pLC->GetItemCount();
	long lll;	
	for(long i=0;i<maxCount;i++){
		lll=atol(pLC->GetItemText(i,0)); 		
		if(lll==m_nXH){
			pLC->DeleteItem(i);
			break;
		}
	}
	maxCount=pLC->GetItemCount();
	if (maxCount>0) {
		lll=atol(pLC->GetItemText(i,0)); 
		OpenRecord(lll);
		Invalidate();
	}else{
		EndDialog(0);
	}
	
	
}

void CDlgAlarmLook::OnButtonT() 
{
	Save2DB();
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView)
		return ;
	CString sql;	
	sql.Format("update record set SDCS='1'  where xh=%d",m_nXH);
	pView->pConn->Execute(sql);
	
}

bool CDlgAlarmLook::OpenRecord(long nXH)
{
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView) return FALSE;
	
	CString sql;	
	long id=nXH;
	CADODataset* pRst1=new CADODataset();
	pRst1->SetConnection(pView->pConn);
	sql.Format("select * from record where xh=%d",id);
	if(pRst1->Open(sql,CADODataset::openQuery))
	{
		if(pRst1->IsEof())
		{
			pRst1->Close();
			delete pRst1;
			return FALSE;
		}
		//序号
		sql.Format("%ld",id);		
		GetDlgItem(IDC_EDIT_XH)->SetWindowText(sql);
		pRst1->GetFieldValue("WZSJ",sql);
		GetDlgItem(IDC_EDIT_JGSJ)->SetWindowText(sql);

		//获得车辆类型
		CString HPZL;
		pRst1->GetFieldValue("HPZL",HPZL);
		CComboBox *pComb=(CComboBox *)GetDlgItem(IDC_COMBO_CLLX);
		int iSum;
		int i;
		iSum=pComb->GetCount();
		for(i=0;i<iSum-1;i++){
			if((pComb->GetItemData(i)==atol(HPZL))){
				pComb->SetCurSel(i);
				break;
			}			
			
		}
		if (i==iSum-1) {
			pComb->SetCurSel(0);
		}

		//号牌图片
		pRst1->GetFieldValue("HPTP",sql);
		CFileFind hFind;
		BOOL bFind;	
		bFind=hFind.FindFile(sql);
		hFind.Close();
		if(bFind)
		{
			m_hpDib.LoadJPG(sql);
		}

		pRst1->GetFieldValue("HPHM",sql);
		GetDlgItem(IDC_EDIT_HPHM)->SetWindowText(sql);
		CString sHead;
		sHead=sql;
		if (sHead.GetLength()>0) {
			sHead=sHead.Left(2);
			CComboBox *pWnd=(CComboBox *)GetDlgItem(IDC_COMBO_HPHZ);
			int iIndex;
			iIndex=pWnd->FindString(0,sHead);
			if (iIndex>-1) {
				pWnd->SetCurSel(iIndex);
			}
		}

		//特写图片
		pRst1->GetFieldValue("bmp",sql);
		CString bmpFile[12];
		for (i=0;i<12;i++)
			bmpFile[i]="";
		for (i=0;i<12;i++)
		{
			
			int pos=sql.Find(",");
			if(pos!=-1)
			{
				bmpFile[i]=sql.Left(pos);
				sql=sql.Right(sql.GetLength()-pos-1);
			}
			else 
			{
				if(sql!=""){
					bmpFile[i]=sql;
					//bmpFile[i]=sql;
				}
				break;
			}
		}	
		
		try{
			bFind=hFind.FindFile(bmpFile[i]);
			hFind.Close();
			if(bFind)
			{
				m_txDib.LoadJPG(bmpFile[0]);		
			}
			
		}catch (...) {
		}

		
		
		//读取嫌疑号牌
		CListBox *pList=(CListBox *)GetDlgItem(IDC_LIST_BKHP);
		pList->ResetContent();
		GetDlgItem(IDC_EDIT_BJMS)->SetWindowText("");

		pRst1->GetFieldValue("XYHP",sql);
		if (sql.GetLength()>0) {
			CString tmpStr1,tmpStr2;
			int iPos;
			int iPos2;
			tmpStr2=sql;
			iPos=tmpStr2.Find(";",0);
			int iNum=0,iBKYY;
			CString sXYHP;
			while (iPos+1>0) {
				tmpStr1=tmpStr2.Left(iPos+1);
				tmpStr2=tmpStr2.Mid(iPos+1);
				iPos=tmpStr2.Find(";",0);
				iPos2=tmpStr1.Find(",",0);				
				if (iPos2+1>0) {
					sXYHP=tmpStr1.Left(iPos2);
					tmpStr1=tmpStr1.Mid(iPos2+1);
					iBKYY=atoi(tmpStr1.GetBuffer(0));
				}else{
					sXYHP=tmpStr1;
					iBKYY=-1;
				}
				iNum=pList->AddString(sXYHP);
				pList->SetItemData(iNum,iBKYY);
			}

			tmpStr1=tmpStr2;
			iPos2=tmpStr1.Find(",",0);				
			if (iPos2+1>0) {
				sXYHP=tmpStr1.Left(iPos2);
				tmpStr1=tmpStr1.Mid(iPos2+1);
				iBKYY=atoi(tmpStr1.GetBuffer(0));
			}else{
				sXYHP=tmpStr1;
				iBKYY=-1;
			}
			iNum=pList->AddString(sXYHP);
			pList->SetItemData(iNum,iBKYY);	
			
			pList->SetTopIndex(0);
			iBKYY=pList->GetItemData(0);

			
			CString sBKYY=pView->Array_FindInBKYYList(iBKYY);			
			GetDlgItem(IDC_EDIT_BJMS)->SetWindowText(sBKYY);
		
		}

	}
	else
	{
		pRst1->Close();
		delete pRst1;
		pRst1=NULL;
		return FALSE;
	}
	pRst1->Close();
	delete pRst1;
	pRst1=NULL;
	return TRUE;


}

void CDlgAlarmLook::OnButtonExit() 
{
	EndDialog(0);
}


void CDlgAlarmLook::OnCloseupComboHphz() 
{
	CString s,s1;
	GetDlgItem(IDC_COMBO_HPHZ)->GetWindowText(s);	
	GetDlgItem(IDC_EDIT_HPHM)->GetWindowText(s1);	
	if (s1.GetLength()>2 && s.GetLength()>0) {
		s1=s1.Mid(2);
	}
	
	s1=s+s1;
	GetDlgItem(IDC_EDIT_HPHM)->SetWindowText(s1);
}

void CDlgAlarmLook::OnKillfocusEditHphm() 
{
	CString sHPHM;
	GetDlgItem(IDC_EDIT_HPHM)->GetWindowText(sHPHM);
	CString sBKYYS,sXYHP,XYHPs;
	if (sHPHM.GetLength()<0) {
		return;
	}
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView) return ;

	pView->Array_CompareInBKList(sHPHM,sBKYYS);
	
	
	//读取嫌疑号牌
	CListBox *pList=(CListBox *)GetDlgItem(IDC_LIST_BKHP);
	pList->ResetContent();
	GetDlgItem(IDC_EDIT_BJMS)->SetWindowText("");

	if (sBKYYS.GetLength()>0) {
		CString tmpStr1,tmpStr2;
		int iPos;
		int iPos2;
		tmpStr2=sBKYYS;
		iPos=tmpStr2.Find(";",0);
		int iNum=0,iBKYY;		
		while (iPos+1>0) {
			tmpStr1=tmpStr2.Left(iPos);
			tmpStr2=tmpStr2.Mid(iPos+1);
			iPos=tmpStr2.Find(";",0);
			iPos2=tmpStr1.Find(",",0);				
			if (iPos2+1>0) {
					sXYHP=tmpStr1.Left(iPos2);
					tmpStr1=tmpStr1.Mid(iPos2+1);
					iBKYY=atoi(tmpStr1.GetBuffer(0));				
			}else{
					sXYHP=tmpStr1;
					iBKYY=-1;
			}
			iNum=pList->AddString(sXYHP);
			pList->SetItemData(iNum,iBKYY);
			
		}
		
		tmpStr1=tmpStr2;
		iPos2=tmpStr1.Find(",",0);				
		if (iPos2+1>0) {
			sXYHP=tmpStr1.Left(iPos2);
			tmpStr1=tmpStr1.Mid(iPos2+1);
			iBKYY=atoi(tmpStr1.GetBuffer(0));
		}else{
			sXYHP=tmpStr1;
			iBKYY=-1;
		}
		iNum=pList->AddString(sXYHP);
		pList->SetItemData(iNum,iBKYY);	

		pList->SetCurSel(0);
		iBKYY=pList->GetItemData(0);
		CString sBKYY=pView->Array_FindInBKYYList(iBKYY);	
		GetDlgItem(IDC_EDIT_BJMS)->SetWindowText(sBKYY);
	}

				
}

void CDlgAlarmLook::OnSelchangeListBkhp() 
{
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView) return ;
	CListBox *pList=(CListBox *)GetDlgItem(IDC_LIST_BKHP);
	int iIndex=pList->GetCurSel();
	if (iIndex<0) {
		return;
	}
	long nBKYY;
	nBKYY=pList->GetItemData(iIndex);
	CString sBKYY;
	sBKYY=pView->Array_FindInBKYYList(nBKYY);
	GetDlgItem(IDC_EDIT_BJMS)->SetWindowText(sBKYY);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -