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

📄 dlgsetroad.cpp

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

#include "stdafx.h"
#include "videocapture.h"
#include "DlgSetRoad.h"
#include "ADODB.h"
#include "VideoCaptureView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgSetRoad dialog


CDlgSetRoad::CDlgSetRoad(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSetRoad::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSetRoad)
	m_miaoshu = _T("");
	m_code = _T("");
	//}}AFX_DATA_INIT
}


void CDlgSetRoad::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgSetRoad)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Text(pDX, IDC_EDIT_ROAD, m_miaoshu);
	DDV_MaxChars(pDX, m_miaoshu, 255);
	DDX_Text(pDX, IDC_EDIT_DLBM, m_code);
	DDV_MaxChars(pDX, m_code, 10);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgSetRoad, CDialog)
	//{{AFX_MSG_MAP(CDlgSetRoad)
	ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSetRoad message handlers

BOOL CDlgSetRoad::OnInitDialog() 
{
	CDialog::OnInitDialog();
	/*
	try
	{
		CStdioFile* pTxtFile = new CStdioFile();
		if(!pTxtFile->Open(".\\Road.dat",CFile::modeRead | CFile::typeText))
		{
			ShowMessage("Road.dat文件不存在\n系统将新建该文件!",MB_OK|MB_ICONEXCLAMATION);
			
			pTxtFile->Open(".\\Road.dat",CFile::modeWrite | CFile::modeCreate);
			pTxtFile->WriteString("测试路段");
			m_list.InsertString(0,"测试路段");
		}
		
		
		CString str;
		while(pTxtFile->GetPosition()<pTxtFile->GetLength())
		{
			pTxtFile->ReadString(str);
			m_list.InsertString(m_list.GetCount(),str);
		}
		pTxtFile->Close();
		delete pTxtFile;
	}
	catch (...) {
		WriteLog("读写文件Road.dat失败");
		ShowMessage("读写文件Road.dat失败",MB_OK|MB_ICONERROR);
		return FALSE;
	}
	*/
	m_list.SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
	m_list.InsertColumn(0,"道路代码",LVCFMT_LEFT,80);
	m_list.InsertColumn(1,"道路描述",LVCFMT_LEFT,600);
	
	CVideoCaptureView* pView=CVideoCaptureView::GetView();
	if(!pView)
		return FALSE;
	CADODataset* pRst=new CADODataset();
	try
	{	
		pRst->SetConnection(pView->pConn);
		pRst->Open("Select * from DLBM order by DLBM desc");
		CString str;
		while (!pRst->IsEof()) {
			pRst->GetFieldValue("DLBM",str);
			int item=m_list.InsertItem(0,str);
			pRst->GetFieldValue("DLMC",str);
			m_list.SetItemText(item,1,str);
			pRst->MoveNext();
		}
		pRst->Close();
		delete pRst;		
		
	}
	catch (...) {
		WriteLog("维护道路代码--数据读取出错");
		ShowMessage("维护道路代码--数据读取出错",MB_OK | MB_ICONERROR);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgSetRoad::OnButtonAdd() 
{
	/*
	try{
		UpdateData();
		if(m_strRoad.GetLength()>0)
		{
			m_list.InsertString(m_list.GetCurSel()+1,m_strRoad);
			m_list.SetCurSel(m_list.GetCurSel()+1);
			m_strRoad="";
			UpdateData(FALSE);
		}		
	}
	catch (...) {
		WriteLog("添加路段失败");
		ShowMessage("添加路段失败",MB_OK|MB_ICONERROR);		
	}	
	*/
	try{
		CVideoCaptureView* pView=CVideoCaptureView::GetView();
		if(!pView)
			return;
		CADODataset* pRst = new CADODataset();
		pRst->SetConnection(pView->pConn);
		
		
		CString str;
		
		UpdateData();
		
		str.Format("select * from DLBM where DLBM='%s'",m_code);
		pRst->Open(str,CADODataset::openQuery);
		if(pRst->IsEof())//insert
		{
			str.Format("insert into DLBM(DLBM,DLMC) values('%s','%s')",m_code,m_miaoshu);
			pRst->ExecSql(str);
			nItem=m_list.InsertItem(0,m_code);
			m_list.SetItemText(nItem,1,m_miaoshu);
			m_list.SetHotItem(nItem);
		}
		else //update
		{
			str.Format("update DLBM set DLMC ='%s' where DLBM='%s'",m_miaoshu,m_code);
			pRst->ExecSql(str);
			for(int i=0;i<m_list.GetItemCount();i++)
			{	
				str=m_list.GetItemText(i,0);
				str.MakeUpper();
				m_code.MakeUpper();
				if(lstrcmp(str,m_code)==0)
				{
					m_list.SetHotItem(i);
					nItem=i;
					m_list.SetItemText(nItem,1,m_miaoshu);
					break;
				}
			}
		}
		UpdateData(FALSE);
	}
	catch (...) {
		WriteLog("添加修改道路代码失败!");
		ShowMessage("添加修改道路代码失败!",MB_OK | MB_ICONERROR);
	}
}

void CDlgSetRoad::OnButtonDel() 
{
	/*
	try{
		int index=m_list.GetCurSel();
		if (index!=LB_ERR) 
		{
			m_list.DeleteString(index);
			if (index!=0)
				m_list.SetCurSel(--index);
			else if (m_list.GetCount()!=LB_ERR)
				m_list.SetCurSel(0);	
		}
	}
	catch (...) {
		WriteLog("删除路段失败");
		ShowMessage("删除路段失败",MB_OK|MB_ICONERROR);		
	}
	*/
	try{
		CVideoCaptureView* pView=CVideoCaptureView::GetView();
		if(!pView)
			return;
		CString str;
		
		
		CString str1=m_list.GetItemText(nItem,0);
		str.Format("DELETE from DLBM where DLBM='%s'",str1);
		pView->pConn->Execute(str);
		m_list.DeleteItem(nItem);
		if(m_list.GetItemCount()<=nItem)
			nItem--;
		m_list.SetHotItem(nItem);
		
		str=m_list.GetItemText(nItem,0);
		m_code=str;
		str=m_list.GetItemText(nItem,0);
		m_miaoshu=m_list.GetItemText(nItem,1);
		
		UpdateData(FALSE);
	}
	catch (...) {
		WriteLog("删除道路编码失败!");
		ShowMessage("删除道路编码失败!",MB_OK | MB_ICONERROR);
	}
}

BOOL CDlgSetRoad::DestroyWindow() 
{/*
	try{
		CStdioFile* pTxtFile = new CStdioFile();
		pTxtFile->Open(".\\Road.dat",CFile::modeCreate | CFile::modeWrite);
		BYTE a=0x0A;
		CString str;
		
		int count=m_list.GetCount();	
		if(count!=LB_ERR)
		{
			for(int i=0;i<count;i++)
			{
				m_list.GetText(i,str);
				pTxtFile->WriteString(str);
				pTxtFile->Write(&a,1);					
			}
		}
		pTxtFile->Close();
		delete pTxtFile;
	}
	catch (...) {
		WriteLog("保存路段修改失败");
		ShowMessage("保存路段修改失败",MB_OK|MB_ICONERROR);		
	}
	*/
	return CDialog::DestroyWindow();
}



void CDlgSetRoad::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	nItem=pNMListView->iItem;
	
	CString str=m_list.GetItemText(nItem,0);
	m_code=str;
	str=m_list.GetItemText(nItem,0);
	m_miaoshu=m_list.GetItemText(nItem,1);
	
	UpdateData(FALSE);
	*pResult = 0;
}

⌨️ 快捷键说明

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