www.pudn.com > duanxinfangwei.rar > CodeQuery.cpp
// CodeQuery.cpp: implementation of the CCodeQuery class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "smspreventforgery.h"
#include "CodeQuery.h"
#include "DbInterface.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCodeQuery::CCodeQuery()
{
RETURNINFO_DBOPERROR = "数据库操作错误";
RETURNINFO_NONQUERYER = "查询者信息丢失";
RETURNINFO_NONWUERYINFO = "请输入要查询的防伪号";
RETURNINFO_NGCODE = "您查询的防伪号不存在,谨防假冒";
RETURNINFO_CODEFRISTQUERY = "您所查询的防伪号正常,您的产品是正品,请放心使用";
RETURNINFO_CODEMUIQUERY = "你所查询的防伪号已被查询%d次,谨防假冒";
}
CCodeQuery::~CCodeQuery()
{
}
/**********************************************************************
* 函数名: QueryCode
* 功 能: 查询防伪码
* 参 数: CString 查询者
* : CString 查询内容
* 返回值: void
*********************************************************************/
CString CCodeQuery::QueryCode(CString queryer, CString code)
{
CDbInterface db; //数据库操作接口
CString strRetInfo; //返回信息
/* 参数处理 */
queryer.TrimLeft();
queryer.TrimRight();
code.TrimLeft();
code.TrimRight();
/* 检查参数 */
if(queryer.IsEmpty())
{
return RETURNINFO_NONQUERYER;
}
if(code.IsEmpty())
{
return RETURNINFO_NONWUERYINFO;
}
/* 记录查询流水 */
QUERYREC queryRec;
queryRec.queryer = queryer;
queryRec.queryinfo = code;
CTime currentTime = CTime::GetCurrentTime();
queryRec.querytime = currentTime.Format("%Y-%m-%d %H:%M:%S");
db.AppendQueryRec(queryRec);
/* 取得被查防伪号次数 */
CODEINFO codeinfo;
codeinfo.code = code;
if(db.GetCodeInfo(codeinfo))
{
/* 查检查所查号是否存在 */
if(codeinfo.querytimes == -1)
{//被查防伪号不存在
/* 追加到防伪号码库,并标记为假冒号 */
codeinfo.stateflag = NGCODE;
codeinfo.gentime = currentTime.Format("%Y%m%d%H%M%S");
codeinfo.outflag = NGFACTORY;
codeinfo.querytimes = 1;
codeinfo.productId = VAILPRODUCT;
db.AppendNewCode(codeinfo);
strRetInfo = RETURNINFO_NGCODE;
}
else
{//被查防伪号存在
db.UpdateCodeQueryTimes(code);
if(codeinfo.stateflag == OKCODE)
{//号码正常
if(codeinfo.querytimes == 0)
{
strRetInfo = RETURNINFO_CODEFRISTQUERY;
}
else
{
strRetInfo.Format(RETURNINFO_CODEMUIQUERY, codeinfo.querytimes);
}
}
else
{//以前被查询过的假冒号
strRetInfo = RETURNINFO_NGCODE;
}
}
}
else
{
strRetInfo = RETURNINFO_DBOPERROR;
}
return strRetInfo;
}