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

📄 setpara2dlg.cpp

📁 安防智能报警系统
💻 CPP
字号:
// SetPara2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Alert.h"
#include "SetParaDlg.h"
#include "SetPara2Dlg.h"
#include "SetPara3Dlg.h"
#include "ChjDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSetPara2Dlg dialog


CSetPara2Dlg::CSetPara2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSetPara2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetPara2Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_nSel=0;
	m_nAct=0;
}


void CSetPara2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetPara2Dlg)
	DDX_Control(pDX, IDC_LIST1, m_chjList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetPara2Dlg, CDialog)
	//{{AFX_MSG_MAP(CSetPara2Dlg)
	ON_BN_CLICKED(IDPREV, OnPrev)
	ON_BN_CLICKED(IDFINISH, OnFinish)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDNEXT, OnNext)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_EDIT, OnEdit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetPara2Dlg message handlers

void CSetPara2Dlg::OnPrev() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK();
	CSetParaDlg* pStep1= (CSetParaDlg*)GetParent();
	pStep1->ShowWindow(SW_SHOW);
}

void CSetPara2Dlg::OnFinish() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK();
	
	CSetParaDlg* pStep1= (CSetParaDlg*)GetParent();
	::SendMessage(pStep1->m_hWnd,WM_CLOSE,0,0);
}

void CSetPara2Dlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CDialog::OnClose();

	CSetParaDlg* pStep1= (CSetParaDlg*)GetParent();
	::SendMessage(pStep1->m_hWnd,WM_CLOSE,0,0);
}

void CSetPara2Dlg::OnNext() 
{
	//TODO: Add your control notification handler code here
	ShowWindow(SW_HIDE);
	CSetPara3Dlg dlg;
	dlg.DoModal();
}

BOOL CSetPara2Dlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//初始化
	m_chjList.InsertColumn(0,"处警名称");
	m_chjList.InsertColumn(1,"端口属性");
	m_chjList.InsertColumn(2,"端口编号");
	m_chjList.InsertColumn(3,"动作类型");
	m_chjList.InsertColumn(4,"信号发码");
	m_chjList.InsertColumn(5,"电话号码");

	CRect rect;
	m_chjList.GetClientRect(&rect);
	m_chjList.SetColumnWidth(0,rect.Width()/6);
	m_chjList.SetColumnWidth(1,rect.Width()/6);
	m_chjList.SetColumnWidth(2,rect.Width()/6);
	m_chjList.SetColumnWidth(3,rect.Width()/6);
	m_chjList.SetColumnWidth(4,rect.Width()/6);
	m_chjList.SetColumnWidth(5,rect.Width()/6);

	_RecordsetPtr r;
	r.CreateInstance(_uuidof(Recordset));
	CString s="select * from ChujingSet";
	_bstr_t bs=s.AllocSysString();
	CAlertApp* pApp=(CAlertApp*)::AfxGetApp();
	r->Open(bs,(IDispatch*)pApp->m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);

	m_chjList.DeleteAllItems();
	if(addListItem(r))
		m_nSel=0;
	r->Close();
	r=NULL;
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetPara2Dlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	m_nSel=-1;
	m_nAct=0;
	CChjDlg dlg(this);
	dlg.DoModal();	
}

void CSetPara2Dlg::OnDelete() 
{
	// TODO: Add your control notification handler code here
	m_nSel= m_chjList.GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
	if(m_nSel==-1)
	{
		::AfxMessageBox("请选择一条记录");
		return;
	}
	int res=::AfxMessageBox("确定删除该条记录?",MB_YESNO);
	if(res==IDNO)
		return;

	_RecordsetPtr r;
	r.CreateInstance(_uuidof(Recordset));
	CString tempcjName;
	m_chjList.GetItemText(m_nSel,0,tempcjName.GetBuffer(100),100);
	tempcjName.ReleaseBuffer();
	CString s="select * from chujingset where cjname = '" +tempcjName + "'";
	_bstr_t bs=s.AllocSysString();
	TRY
	{
		CAlertApp* pApp=(CAlertApp*)::AfxGetApp();
		r->Open(bs,(IDispatch*)pApp->m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
		if(!r->adoEOF && !r->BOF)
		{
			r->Delete(adAffectCurrent);
			r->Update();
		}
	}
	CATCH(CException,e)
	{
		::AfxMessageBox("请再次检查数据");
		e->ReportError();
	}
	END_CATCH
	
	m_chjList.DeleteItem(m_nSel);	//从listctrl中删除该条记录

	r->Close();
	r=NULL;	
}

void CSetPara2Dlg::OnEdit() 
{
	// TODO: Add your control notification handler code here
	m_nSel= m_chjList.GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
	if(m_nSel==-1)
	{
		::AfxMessageBox("请选择一条记录");
		return;
	}
	m_nAct=1;
	CChjDlg dlg(this);
	dlg.DoModal();
}

//将打开的表r加入listview的item中,如果r不为空集的话,则返回true,反之为false
BOOL CSetPara2Dlg::addListItem(_RecordsetPtr r)
{
	//如果r为空集,则不用加入list control中
	if(r->adoEOF || r->BOF)
		return FALSE;

	r->MoveFirst();
	while(!r->adoEOF)
	{
		//将name、code、property、Number、promote赋成打开的记录集的字段值(按顺序)
		CString cjname,property,typeact,infocode,number,telnumber;

		cjname = LPTSTR(_bstr_t(r->GetCollect("cjname")));
		if(cjname=="")
		{
			::AfxMessageBox("此纪录无主键");
			continue;
		}

		property=LPTSTR(_bstr_t(r->GetCollect("property")));
		if(property=="")
			property="-";

		typeact=LPTSTR(_bstr_t(r->GetCollect("typeact")));
		if(typeact=="")
			typeact="-";

		if(typeact=="-")
		{
			infocode=telnumber="-";
		}
		if(typeact=="发码")
		{
			infocode=LPTSTR(_bstr_t(r->GetCollect("infocode")));
			telnumber="-";
		}
		if(typeact=="拨号")
		{
			infocode="-";
			telnumber=LPTSTR(_bstr_t(r->GetCollect("telnumber")));
		}

		number = LPTSTR(_bstr_t(r->GetCollect("number")));
	
		int nItem = m_chjList.InsertItem(m_chjList.GetItemCount(),cjname);
		m_chjList.SetItemText(nItem,1,property);
		m_chjList.SetItemText(nItem,2,number);
		m_chjList.SetItemText(nItem,3,typeact);
		m_chjList.SetItemText(nItem,4,infocode);
		m_chjList.SetItemText(nItem,5,telnumber);

		r->MoveNext();
	}

	return TRUE;	
}

⌨️ 快捷键说明

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