📄 rfid_desktopreaderdoc.cpp
字号:
// RFID_DesktopReaderDoc.cpp : implementation of the CRFID_DesktopReaderDoc class
//
#include "stdafx.h"
#include "RFID_DesktopReader.h"
#include "RFID_DesktopReaderDoc.h"
#include "adoDB.h"
//#include "MailFrame.h"
//#include "MailView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderDoc
IMPLEMENT_DYNCREATE(CRFID_DesktopReaderDoc, CDocument)
BEGIN_MESSAGE_MAP(CRFID_DesktopReaderDoc, CDocument)
//{{AFX_MSG_MAP(CRFID_DesktopReaderDoc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderDoc construction/destruction
CRFID_DesktopReaderDoc::CRFID_DesktopReaderDoc()
: m_bUnmapedOnly(false)
{
// TODO: add one-time construction code here
m_strDataSource="";
m_strUDLFile="";
m_strQueryTableName="";
m_strDbIniFile="Db.ini";
m_CurrentRFID.strContent=_T("");
m_CurrentRFID.bValid=false;
m_CurrentRFID.strRFID=_T("");
m_CurrentRFID.strContent=_T("");
LoadDBiniFile(m_strDbIniFile);
}
CRFID_DesktopReaderDoc::~CRFID_DesktopReaderDoc()
{
}
BOOL CRFID_DesktopReaderDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderDoc serialization
void CRFID_DesktopReaderDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderDoc diagnostics
#ifdef _DEBUG
void CRFID_DesktopReaderDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CRFID_DesktopReaderDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
int CRFID_DesktopReaderDoc::AssociateDevice(int nDevice, CString strRFID)
{
m_adoRFIDMap.OpenSql(m_OutputTable.m_strTableName);
if(m_adoRFIDMap.AddNew())
{
m_adoRFIDMap.SetFieldValue(m_OutputTable.m_Field[0].strFieldName,(long)nDevice);
m_adoRFIDMap.SetFieldValue(m_OutputTable.m_Field[1].strFieldName,strRFID);
m_adoRFIDMap.Update();
m_CurrentRFID.bMaped=true;
}
return 0;
}
int CRFID_DesktopReaderDoc::DeassociateDevice(CString strRFID)
{
CString strCon;
strCon="WHERE RFID='"+strRFID+"'";
m_adoRFIDMap.OpenSql(m_OutputTable.m_strTableName,"*",strCon);
if(m_adoRFIDMap.GetFieldCount()>0)
{
if(m_adoRFIDMap.Delete())
m_CurrentRFID.bMaped=false;
else
AfxMessageBox("取消RFID与设备关联失败!");
}
m_adoRFIDMap.Update();
m_adoRFIDMap.Close();
return 0;
}
int CRFID_DesktopReaderDoc::DeassociateDevice(int nID)
{
CString strCon;
strCon.Format("WHERE 设备ID=%d",nID);
if(m_adoRFIDMap.OpenSql(m_OutputTable.m_strTableName,"*",strCon))
{
if(m_adoRFIDMap.GetFieldCount()>0)
if(!m_adoRFIDMap.Delete())
AfxMessageBox("取消RFID与设备关联失败!");
m_adoRFIDMap.Update();
m_adoRFIDMap.Close();
}
return 0;
}
int CRFID_DesktopReaderDoc::ReplaceAssociateCard(long lDeviceID, CString strWithRFID)
{
return 0;
}
int CRFID_DesktopReaderDoc::LoadDBiniFile(CString strIniFileName)
{
try{
CStdioFile dbIniFile(strIniFileName,CStdioFile::modeRead);
CString strTemp;
int i=0;
int nIndex;
CString strPrimary;
int nPos;
dbIniFile.ReadString(strTemp);
do
{
//读取数据源文件名
if(strTemp=="[DATABASE]")
{
CString strDbSource;
dbIniFile.ReadString(strDbSource);
if(strDbSource.Find("UDL=")>=0)
{
m_strUDLFile=strDbSource.TrimLeft("UDL=");
}
else
{
AfxMessageBox("文件格式错误!");
dbIniFile.Close();
return -2;
}
dbIniFile.ReadString(strTemp);
}
//读取输入表结构
if(strTemp=="[INPUT TABLE]")
{
strTemp=GetTableField(&dbIniFile,&m_InputTable);
}
//读取输出表结构
if(strTemp=="[OUTPUT TABLE]")
{
strTemp=GetTableField(&dbIniFile,&m_OutputTable);
}
//读出输入 输出表的关系
if(strTemp=="[RELATIONSHIP]")
{
dbIniFile.ReadString(m_strRelationship);
dbIniFile.ReadString(strTemp);
}
//读出输入 输出表的关系
if(strTemp=="[QUERY TABLE]")
{
dbIniFile.ReadString(m_strQueryTableName);
if(m_strQueryTableName.Find("TableName=")>=0)
{
m_strQueryTableName.TrimLeft("TableName=");
}
else
{
AfxMessageBox("文件格式错误!");
dbIniFile.Close();
return -2;
}
dbIniFile.ReadString(strTemp);
}
}while(dbIniFile.ReadString(strTemp));
dbIniFile.Close();
}
catch(...)
{
AfxMessageBox("打开Db.ini文件错误!");
return -1;
}
return 0;
}
CString CRFID_DesktopReaderDoc::GetTableField(CStdioFile* pFile, CDbTable* pDbTable)
{
//读取输入表结构
ASSERT_VALID(pFile);
// ASSERT_VALID(pDbTable);
CString strTable;
CString strField;
CString strIndex;
CString strPrimary;
do {
if(!pFile->ReadString(strTable))
break;
}while(strTable=="");
if(strTable.Find("TableName=")>=0)
{
pDbTable->m_strTableName=strTable.TrimLeft("TableName=");
do {
if(!pFile->ReadString(strField))
break;
}while((strField=="") );
int i=0;
while(strField.Find("Field=")>=0)
{
strField.TrimLeft("Field=");
int nPos=0;
strIndex=strField.Tokenize(",",nPos);
pDbTable->m_Field[i].strFieldName=strField.Tokenize(",",nPos);
pDbTable->m_Field[i].strtype=strField.Tokenize(",",nPos);
strPrimary=strField.Tokenize(",",nPos);
if(strPrimary=="primary")
pDbTable->m_Field[i].bPrimary=true;
else
pDbTable->m_Field[i].bPrimary=false;
i++;
strField="";
do
{
if(!pFile->ReadString(strField))
break;
}while(strField=="");
}
}
else
{
AfxMessageBox("文件格式错误!");
return "";
}
return strField;
}
CADODataset* CRFID_DesktopReaderDoc::GetAssociationDevice()
{
//CString strTable;
//CString strField;
//CString strCon;
//strTable=m_InputTable.m_strTableName+","+m_OutputTable.m_strTableName;
//strCon="WHERE "+m_strRelationship;
m_adoMapedDevice.OpenSql(m_strQueryTableName);
if(m_adoMapedDevice.IsOpen())
return &m_adoMapedDevice;
else
return NULL;
}
CADODataset* CRFID_DesktopReaderDoc::GetUnassociationDevice()
{
CString strCon;
strCon="WHERE 设备信息表.ID NOT IN(SELECT 设备信息表.ID FROM 设备信息表,RFID设备关联表 WHERE "+m_strRelationship+")";
m_adoUnmapedDevice.OpenSql(m_InputTable.m_strTableName,"*",strCon);
if(m_adoUnmapedDevice.IsOpen())
return &m_adoUnmapedDevice;
else
return NULL;
}
CADODataset* CRFID_DesktopReaderDoc::GetUnassociationDevice(CString strCon)
{
CString strCon1;
strCon1="WHERE 设备信息表.ID NOT IN(SELECT 设备信息表.ID FROM 设备信息表,RFID设备关联表 WHERE "+m_strRelationship+")";
if(strCon!="")
{
strCon.TrimLeft("WHERE ");
strCon1=strCon1+" AND "+strCon;
}
m_adoUnmapedDevice.OpenSql(m_InputTable.m_strTableName,"*",strCon1);
if(m_adoUnmapedDevice.IsOpen())
return &m_adoUnmapedDevice;
else
return NULL;
}
CADODataset* CRFID_DesktopReaderDoc::GetAssociationDevice(CString strCon)
{
//CString strTable;
//CString strField;
//CString strCon;
//strTable=m_InputTable.m_strTableName+","+m_OutputTable.m_strTableName;
//strCon="WHERE "+m_strRelationship;
m_adoMapedDevice.OpenSql(m_strQueryTableName,"*",strCon);
if(m_adoMapedDevice.IsOpen())
return &m_adoMapedDevice;
else
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -