📄 hlr.cpp
字号:
// Hlr.cpp: implementation of the CHlr class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RandomPhone.h"
#include "Hlr.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CHlr::CHlr()
{
}
CHlr::~CHlr()
{
POSITION pos = m_data.GetHeadPosition();
while (pos != NULL)
{
delete m_data.GetNext(pos);
}
m_data.RemoveAll();
}
void CHlr::LoadFromFile(const CString & hlrfile)
{
CHlrItem* pdata = NULL;
CFile f;
if( !f.Open( (LPCSTR)hlrfile, CFile::modeRead ) )
{
AfxMessageBox("hlr.dat文件打开失败!");
return;
}
CArchive ar( &f, CArchive::load);
CString temp;
char p[100],c[100],l[100];
unsigned int pc, hf,ht,uf,ut;
BOOL ret;
while( (ret = ar.ReadString(temp)) == TRUE )
{
//ar.ReadString(temp);
pdata = new CHlrItem;
// p c l pre hf ht uf ut
sscanf((LPCSTR)temp,"%s\t%s\t%s\t%u\t%u\t%u\t%u\t%u", p,c,l,&pc,&hf,&ht,&uf,&ut);
//sscanf((LPCSTR)temp,"%s\t%s\t%s\t%d", p,c,l,&pc);
pdata->province = p;
pdata->city = c;
pdata->longCode = l;
pdata->prefixcode = pc;
pdata->hlrfrom = hf;
pdata->hlrto = ht;
pdata->usercode_from = uf;
pdata->usercode_to = ut;
m_data.AddTail( pdata );
}
/*
pdata->province = "甘肃省";
pdata->city = "兰州";
pdata->longCode = "0931";
pdata->prefixcode = 139;
pdata->hlrfrom = 931;
pdata->hlrto = 933;
pdata->usercode_from = 0;
pdata->usercode_to = 9999;
m_data.AddTail( pdata );
// ---------
pdata = new CHlrItem;
pdata->province = "甘肃省";
pdata->city = "兰州2";
pdata->longCode = "0932";
pdata->prefixcode = 138;
pdata->hlrfrom = 931;
pdata->hlrto = 933;
pdata->usercode_from = 0;
pdata->usercode_to = 9999;
m_data.AddTail( pdata );
*/
}
//这里的 phone是没有 13的,因此在 pre_code中需要手动添加
void CHlr::GetHlr(const CString &phone, CString &province, CString &city, CString &longcode)
{
province = "";
city = "";
longcode = "";
unsigned int pre_code;
unsigned int hlr_code;
unsigned int user_code;
CString temp;
temp = "13";
temp += phone.Left(1);
pre_code = (unsigned int)atol( (LPCSTR) temp );
hlr_code = (unsigned int)atol( (LPCSTR)phone.Mid(1,4));
user_code = (unsigned int)atol( (LPCSTR)phone.Right(4));
POSITION pos = m_data.GetHeadPosition();
while (pos != NULL)
{
CHlrItem *pdata = m_data.GetNext(pos);
if ( pre_code == pdata ->prefixcode
&& hlr_code >= pdata->hlrfrom
&& hlr_code <= pdata->hlrto
&& user_code >= pdata->usercode_from
&& user_code <= pdata->usercode_to
)
{
province = pdata->province;
city = pdata->city;
longcode = pdata->longCode;
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -