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

📄 rfid_desktopreaderview.cpp

📁 RFID读卡器源码,vc.net编写,bcgp界面控件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CRFID_DesktopReaderView::DoDataExchange(CDataExchange* pDX)
{
	// TODO: 在此添加专用代码和/或调用基类

	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LST_ASSOCIATION, m_cListAssociation);
	DDX_Control(pDX, IDC_LIT_UNASSOCIATION, m_cListUnassociation);
	//	DDX_Control(pDX, IDC_ADODC1, m_AdoDC);
	//	DDX_Control(pDX, IDC_DATAGRID2, m_DataGrid);
	DDX_Control(pDX, IDC_COB_FIELD0, m_cCOBField0);
	DDX_Control(pDX, IDC_COB_FIELD1, m_cCOBField1);
	DDX_Control(pDX, IDC_COB_FIELD2, m_cCOBField2);
	DDX_Control(pDX, IDC_COB_FIELD3, m_cCOBField3);
}

void CRFID_DesktopReaderView::OnFinalRelease()
{
	// TODO: 在此添加专用代码和/或调用基类

//	if(g_padoConnection!=NULL)
//		delete g_padoConnection;
//	g_padoConnection=NULL;

	CFormView::OnFinalRelease();
}

void CRFID_DesktopReaderView::OnRfidAssociate()
{
	// TODO: 在此添加命令处理程序代码
	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	
	if(pDoc->m_CurrentRFID.bValid)
	{
		if(!pDoc->m_CurrentRFID.bMaped)
		{
			POSITION pos;
			pos=m_cListUnassociation.GetFirstSelectedItemPosition();
			if(pos==NULL)
				AfxMessageBox("请在未关联设备列表中一条选择记录!");
			else
			{

				CString str=m_cListUnassociation.GetItemText(long(pos)-1,0);
				int nID=atoi(str.GetString());
				pDoc->AssociateDevice(nID,pDoc->m_CurrentRFID.strRFID);
				this->FillAssociationList();
				this->FillUnassociationList();
			}
		}
		else AfxMessageBox("该卡已经与设备关联!");
	}
	else
		AfxMessageBox("请将卡放入读卡器!!");
}

void CRFID_DesktopReaderView::OnRfidDeassociate()
{
	// TODO: 在此添加命令处理程序代码
	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	
	if(pDoc->m_CurrentRFID.bValid)
	{
		POSITION pos;
		pos=m_cListAssociation.GetFirstSelectedItemPosition();
		if(pos==NULL)
			AfxMessageBox("请在关联设备列表中选择记录!");
		else
		{
			CString strRFID=m_cListAssociation.GetItemText(long(pos)-1,6);

			if(strRFID==pDoc->m_CurrentRFID.strRFID)
			{

				pDoc->DeassociateDevice(strRFID);
				this->FillAssociationList();
				this->FillUnassociationList();
			}
			else AfxMessageBox("当前RFID与记录不符,请选择相同的记录!");
		}
	}
	else
		AfxMessageBox("请将卡放入读卡器!!");
}

void CRFID_DesktopReaderView::FillAssociationList(void)
{
	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	CString strTemp;
	CString strCon;
	int nSel;
	nSel=m_cCOBField0.GetCurSel();
	m_cCOBField0.GetLBText(nSel,strTemp);
	strCon="";
	if(strTemp!="ALL")
	{
		strCon=pDoc->m_InputTable.m_Field[1].strFieldName+"='"+strTemp+"'";
	}

	nSel=m_cCOBField1.GetCurSel();
	m_cCOBField1.GetLBText(nSel,strTemp);
	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon=pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
	}


	nSel=m_cCOBField2.GetCurSel();
	m_cCOBField2.GetLBText(nSel,strTemp);
	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon=pDoc->m_InputTable.m_Field[3].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[3].strFieldName+"='"+strTemp+"'";
	}

	nSel=m_cCOBField3.GetCurSel();
	m_cCOBField3.GetLBText(nSel,strTemp);

	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon=pDoc->m_InputTable.m_Field[4].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[4].strFieldName+"='"+strTemp+"'";
	}

	if(strCon!="")
		strCon="WHERE "+strCon;

	pDoc->GetAssociationDevice(strCon);
	pDoc->m_adoMapedDevice.FillList(m_cListAssociation);

}

void CRFID_DesktopReaderView::FillUnassociationList(void)
{
	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	CString strTemp;
	CString strCon;
	int nSel;

	nSel=m_cCOBField0.GetCurSel();
	m_cCOBField0.GetLBText(nSel,strTemp);

	strCon="";
	if(strTemp!="ALL")
	{
		strCon=pDoc->m_InputTable.m_Field[1].strFieldName+"='"+strTemp+"'";
	}

	nSel=m_cCOBField1.GetCurSel();
	m_cCOBField1.GetLBText(nSel,strTemp);
	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon=pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
	}

	nSel=m_cCOBField2.GetCurSel();
	m_cCOBField2.GetLBText(nSel,strTemp);

	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon=pDoc->m_InputTable.m_Field[3].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[3].strFieldName+"='"+strTemp+"'";
	}

	nSel=m_cCOBField3.GetCurSel();
	m_cCOBField3.GetLBText(nSel,strTemp);

	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon=pDoc->m_InputTable.m_Field[4].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[4].strFieldName+"='"+strTemp+"'";
	}

	if(strCon!="")
		strCon="WHERE "+strCon;

    pDoc->GetUnassociationDevice(strCon);
	pDoc->m_adoUnmapedDevice.FillList(m_cListUnassociation);

}

LRESULT CRFID_DesktopReaderView::OnMapedRFID(WPARAM wParam, LPARAM lParam)
{
	return LRESULT();
}

void CRFID_DesktopReaderView::OnRfidCancle()
{
	// TODO: 在此添加命令处理程序代码
	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	POSITION pos;
	pos=m_cListAssociation.GetFirstSelectedItemPosition();
	if(pos==NULL)
		AfxMessageBox("请在关联设备列表中选择记录!");
	else
	{

		if(AfxMessageBox("警告:作废卡将造成卡信息丢失,请在确认RFID卡已经损坏的情况下进行!\n\n    确认进行操作吗?",MB_YESNO)==IDYES)
		{
			CString strID=m_cListAssociation.GetItemText(long(pos)-1,0);
			int nID=atoi(strID.GetString());

			pDoc->DeassociateDevice(nID);
			this->FillAssociationList();
			this->FillUnassociationList();
		}
	}



}

int CRFID_DesktopReaderView::FillFieldCOB(CComboBox& comboBox,CString strFieldName,CString strCon)
{
	CADODataset dataset;

	int nCount=comboBox.GetCount();
	for(int i=nCount-1;i>=0;i--)
		comboBox.DeleteString(i);

	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	CRFID_DesktopReaderApp* pApp=(CRFID_DesktopReaderApp*)AfxGetApp();

	dataset.SetConnection(&(pApp->m_adoConnection));

	CString strSelect;

	strSelect="SELECT  DISTINCT "+strFieldName
		+" FROM "+pDoc->m_InputTable.m_strTableName+" "+strCon;
	if(dataset.Open(strSelect))
	{
		CString strTemp;
		comboBox.InsertString(0,"ALL");

		int nCount=dataset.GetRecordCount();
		for(int i=0;i<nCount;i++)
		{
			dataset.GetFieldValue(strFieldName,strTemp);
			comboBox.InsertString(i+1,strTemp);
			dataset.MoveNext();
		}
		comboBox.SetCurSel(0);
	}

//	dataset.Close();


	return 0;
}

void CRFID_DesktopReaderView::FillCOB(void)
{
	CRFID_DesktopReaderDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	this->FillFieldCOB(m_cCOBField0,pDoc->m_InputTable.m_Field[1].strFieldName);
	this->FillFieldCOB(m_cCOBField1,pDoc->m_InputTable.m_Field[2].strFieldName);
	this->FillFieldCOB(m_cCOBField2,pDoc->m_InputTable.m_Field[3].strFieldName);
	this->FillFieldCOB(m_cCOBField3,pDoc->m_InputTable.m_Field[4].strFieldName);



}

void CRFID_DesktopReaderView::OnCbnSelchangeCobField0()
{
	// TODO: 在此添加控件通知处理程序代码
	CRFID_DesktopReaderDoc* pDoc=GetDocument();

	ASSERT_VALID(pDoc);
	int nSelected;

	CString strCon;
	CString strTemp;
	nSelected=m_cCOBField0.GetCurSel();
	m_cCOBField0.GetLBText(nSelected,strTemp);
	
	if(strTemp!="ALL")
        strCon="WHERE "+pDoc->m_InputTable.m_Field[1].strFieldName+"='"+strTemp+"'";

	FillFieldCOB(m_cCOBField1,pDoc->m_InputTable.m_Field[2].strFieldName,strCon);
	FillFieldCOB(m_cCOBField2,pDoc->m_InputTable.m_Field[3].strFieldName,strCon);
	FillFieldCOB(m_cCOBField3,pDoc->m_InputTable.m_Field[4].strFieldName,strCon);

	this->FillAssociationList();
	this->FillUnassociationList();

}

void CRFID_DesktopReaderView::OnCbnSelchangeCobField1()
{
	// TODO: 在此添加控件通知处理程序代码
	CRFID_DesktopReaderDoc* pDoc=GetDocument();

	ASSERT_VALID(pDoc);
	int nSelected;

	CString strCon="";
	CString strTemp="";
	nSelected=m_cCOBField0.GetCurSel();
	m_cCOBField0.GetLBText(nSelected,strTemp);
	if(strTemp!="ALL")
        strCon="WHERE "+pDoc->m_InputTable.m_Field[1].strFieldName+"='"+strTemp+"'";

	nSelected=m_cCOBField1.GetCurSel();
	m_cCOBField1.GetLBText(nSelected,strTemp);
	
	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon="WHERE "+pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
	}


	FillFieldCOB(m_cCOBField2,pDoc->m_InputTable.m_Field[3].strFieldName,strCon);
	FillFieldCOB(m_cCOBField3,pDoc->m_InputTable.m_Field[4].strFieldName,strCon);
	this->FillAssociationList();
	this->FillUnassociationList();

}

void CRFID_DesktopReaderView::OnCbnSelchangeCobField2()
{
	// TODO: 在此添加控件通知处理程序代码
	CRFID_DesktopReaderDoc* pDoc=GetDocument();

	ASSERT_VALID(pDoc);
	int nSelected;

	CString strCon="";
	CString strTemp="";
	nSelected=m_cCOBField0.GetCurSel();
	m_cCOBField0.GetLBText(nSelected,strTemp);
	if(strTemp!="ALL")
        strCon="WHERE "+pDoc->m_InputTable.m_Field[1].strFieldName+"='"+strTemp+"'";

	nSelected=m_cCOBField1.GetCurSel();
	m_cCOBField1.GetLBText(nSelected,strTemp);
	if(strTemp!="ALL")
	{
		if(strCon=="")
            strCon="WHERE "+pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[2].strFieldName+"='"+strTemp+"'";

	}
	nSelected=m_cCOBField2.GetCurSel();
	m_cCOBField2.GetLBText(nSelected,strTemp);
	
	if(strTemp!="ALL")
	{
		if(strCon=="")
			strCon="WHERE "+pDoc->m_InputTable.m_Field[3].strFieldName+"='"+strTemp+"'";
		else
			strCon=strCon+" AND "+pDoc->m_InputTable.m_Field[3].strFieldName+"='"+strTemp+"'";
	}

	FillFieldCOB(m_cCOBField3,pDoc->m_InputTable.m_Field[4].strFieldName,strCon);

	this->FillAssociationList();
	this->FillUnassociationList();

}

void CRFID_DesktopReaderView::OnCbnSelchangeCobField3()
{
	// TODO: 在此添加控件通知处理程序代码


		this->FillAssociationList();
		this->FillUnassociationList();

}

void CRFID_DesktopReaderView::OnBnClickedResetAll()
{
	// TODO: 在此添加控件通知处理程序代码
		this->FillCOB();
		this->FillAssociationList();
		this->FillUnassociationList();
}

⌨️ 快捷键说明

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