下面这个程序怎样实现模糊查询,里面有模糊查询的代码,但就是不能实现!请各位高手鼎力相助!
void CHamiltonWebDBManagerDlg::OnCreateDatabase()
{
if (::MessageBox(0, "执行本操作将重新创建“用户信息数据库”,点击“是”继续,点击“否”退出", "提示信息", MB_YESNO) == IDYES)
{
if (m_hFile == 0)
{
m_hFile = CreateFile("c:\\userinfo.mdb", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, 0x80, 0);
if (m_hFile == (HANDLE)-1)
{//打开或创建文件失败
m_hFile = 0;
::MessageBox(0, "创建“用户信息数据库”失败", "错误信息", 0);
return;
}
memset(&database, 0, sizeof(database));
updata_file();
m_close_file();
}
}}void CHamiltonWebDBManagerDlg::OnBtnList()
{
CompanyList cl;
cl.DoModal();
}bool CHamiltonWebDBManagerDlg::update_gInfo(GDATABASE_CELL& gbc)
{
DWORD dw;
HANDLE hFile;
hFile = CreateFile("c:\\gInfo.MDB", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0x80, 0);
if (hFile == (HANDLE)-1)
{//打开或创建文件失败
hFile = 0;
return false;
}
if (ReadFile(hFile, &g_database, sizeof(g_database), &dw, 0) == FALSE)
{
CloseHandle(hFile);
hFile = 0;
return false;
}
if (dw != sizeof(g_database))
{
CloseHandle(hFile);
hFile = 0;
return false;
}
int i, j;
for (i=0,j=0; i<MAX_GROUP; i++)
{
if(g_database.data[i].ye_wu_yuan[0] == 0)
{
if(j==0)
j = i;
}
else
{
if(strcmp(g_database.data[i].ye_wu_yuan, gbc.ye_wu_yuan) == 0) //已存在组,退出
{
CloseHandle(hFile);
return true;
}
}
}
strcpy(g_database.data[j].ye_wu_yuan, gbc.ye_wu_yuan);
strcpy(g_database.data[j].number, gbc.number);
g_database.data[j].is_open = false; SetFilePointer(hFile, 0, 0, FILE_BEGIN);
WriteFile(hFile, &g_database, sizeof(g_database), &dw, 0); CloseHandle(hFile);
return true;
}void CHamiltonWebDBManagerDlg::OnChangeYeWuYuan()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}void CHamiltonWebDBManagerDlg::OnChangeLianXiDiZhi()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask
// TODO: Add your control notification handler code here
}//BOOL BlurFindStr(CString &strSource,CString &strFindCell)
//TODO: Add your control notification handler code here
//void CHamiltonWebDBManagerDlg::OnBtnList()
//{
bool IsBlur(BYTE c1,BYTE c2,char c)
{
static unsigned char cEnd[23*5+1] = "啊澳a芭怖b擦错c搭堕d蛾贰e发咐f噶过g哈紕h肌骏j喀阔k垃络l妈那m娜诺n哦沤o啪瀑p期群q然弱r撒所s塌唾t挖误w昔迅x压孕y匝座z";
static int nWord[23][2] = {0};
int i=0;
if(nWord[0][0] == 0)
{//初始化nWord
for(i = 0;i < 23; i++)
{
nWord[i][0] = cEnd[i*5]*256 + cEnd[i*5+1];
nWord[i][1] = cEnd[i*5+2]*256 + cEnd[i*5+3];
}
}
int nWordChinese = c1 * 256 + c2;
int nLeft = 0,nRight = 22;
bool bMatch = FALSE;
while(nLeft <= nRight)
{
i = (nLeft + nRight)/2;
if(nWordChinese > nWord[i][1])
nLeft = i+1;
else if(nWordChinese < nWord[i][0])
nRight = i-1;
else
{
if(cEnd[i*5+4] == c)
bMatch = TRUE;
break;
}
}
return bMatch;
} bool BlurFindStr(CString &strSource,CString &strFindCell)
{
int nLenCell = strFindCell.GetLength();
int nLenSource = strSource.GetLength();
if(nLenCell < 1)
return TRUE;
if(nLenSource <1)
return FALSE;
strSource.MakeLower();
strFindCell.MakeLower();
bool bContainChar = FALSE;
int i,j,k;
for(i=0; i< nLenCell; i++)
{
if( !(strFindCell.GetAt(i)&0x80) )
{
bContainChar = TRUE;
break;
}
}
j = 0;
int nMatchCharCount = 0;
bool bEqual = FALSE;
int ik;
for(i = 0; i< nLenCell && j < nLenSource; i++)
{
ik = i;
char c = strFindCell.GetAt(i);
if(c&0x80)//汉字
{
i++;
while(j < nLenSource)
{
char cs = strSource.GetAt(j++);
k = j;
if(cs&0x80)//汉字
j++;
if(cs == c && k < nLenSource && strSource.GetAt(k) == strFindCell.GetAt(i))
{
if(ik == 0)
bEqual = TRUE;
nMatchCharCount += 2;
break;
}
else if(i > 0)
{
bEqual = FALSE;
nMatchCharCount = 0;
i = 0;
break;
}
}
}
else//字母
{
while(j < nLenSource)
{
char cs = strSource.GetAt(j++);
k = j;
if(cs&0x80)//汉字
{
j++;
if(IsBlur(cs,strSource.GetAt(k),c))
{
if(ik == 0)
bEqual = TRUE;
nMatchCharCount++;
break;
}
else if(i > 0)
{
bEqual = FALSE;
nMatchCharCount = 0;
i = 0;
break;
}
}
else if(cs == c)
{
if(ik == 0)
bEqual = TRUE;
nMatchCharCount++;
break;
}
else if(i > 0)
{
bEqual = FALSE;
nMatchCharCount = 0;
i = 0;
break;
}
}
}
}
if(bEqual && i == nLenCell && j == nLenSource)
return TRUE;
else
return (nMatchCharCount == nLenCell);
}
void CHamiltonWebDBManagerDlg::OnCreateDatabase()
{
if (::MessageBox(0, "执行本操作将重新创建“用户信息数据库”,点击“是”继续,点击“否”退出", "提示信息", MB_YESNO) == IDYES)
{
if (m_hFile == 0)
{
m_hFile = CreateFile("c:\\userinfo.mdb", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, 0x80, 0);
if (m_hFile == (HANDLE)-1)
{//打开或创建文件失败
m_hFile = 0;
::MessageBox(0, "创建“用户信息数据库”失败", "错误信息", 0);
return;
}
memset(&database, 0, sizeof(database));
updata_file();
m_close_file();
}
}}void CHamiltonWebDBManagerDlg::OnBtnList()
{
CompanyList cl;
cl.DoModal();
}bool CHamiltonWebDBManagerDlg::update_gInfo(GDATABASE_CELL& gbc)
{
DWORD dw;
HANDLE hFile;
hFile = CreateFile("c:\\gInfo.MDB", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0x80, 0);
if (hFile == (HANDLE)-1)
{//打开或创建文件失败
hFile = 0;
return false;
}
if (ReadFile(hFile, &g_database, sizeof(g_database), &dw, 0) == FALSE)
{
CloseHandle(hFile);
hFile = 0;
return false;
}
if (dw != sizeof(g_database))
{
CloseHandle(hFile);
hFile = 0;
return false;
}
int i, j;
for (i=0,j=0; i<MAX_GROUP; i++)
{
if(g_database.data[i].ye_wu_yuan[0] == 0)
{
if(j==0)
j = i;
}
else
{
if(strcmp(g_database.data[i].ye_wu_yuan, gbc.ye_wu_yuan) == 0) //已存在组,退出
{
CloseHandle(hFile);
return true;
}
}
}
strcpy(g_database.data[j].ye_wu_yuan, gbc.ye_wu_yuan);
strcpy(g_database.data[j].number, gbc.number);
g_database.data[j].is_open = false; SetFilePointer(hFile, 0, 0, FILE_BEGIN);
WriteFile(hFile, &g_database, sizeof(g_database), &dw, 0); CloseHandle(hFile);
return true;
}void CHamiltonWebDBManagerDlg::OnChangeYeWuYuan()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}void CHamiltonWebDBManagerDlg::OnChangeLianXiDiZhi()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask
// TODO: Add your control notification handler code here
}//BOOL BlurFindStr(CString &strSource,CString &strFindCell)
//TODO: Add your control notification handler code here
//void CHamiltonWebDBManagerDlg::OnBtnList()
//{
bool IsBlur(BYTE c1,BYTE c2,char c)
{
static unsigned char cEnd[23*5+1] = "啊澳a芭怖b擦错c搭堕d蛾贰e发咐f噶过g哈紕h肌骏j喀阔k垃络l妈那m娜诺n哦沤o啪瀑p期群q然弱r撒所s塌唾t挖误w昔迅x压孕y匝座z";
static int nWord[23][2] = {0};
int i=0;
if(nWord[0][0] == 0)
{//初始化nWord
for(i = 0;i < 23; i++)
{
nWord[i][0] = cEnd[i*5]*256 + cEnd[i*5+1];
nWord[i][1] = cEnd[i*5+2]*256 + cEnd[i*5+3];
}
}
int nWordChinese = c1 * 256 + c2;
int nLeft = 0,nRight = 22;
bool bMatch = FALSE;
while(nLeft <= nRight)
{
i = (nLeft + nRight)/2;
if(nWordChinese > nWord[i][1])
nLeft = i+1;
else if(nWordChinese < nWord[i][0])
nRight = i-1;
else
{
if(cEnd[i*5+4] == c)
bMatch = TRUE;
break;
}
}
return bMatch;
} bool BlurFindStr(CString &strSource,CString &strFindCell)
{
int nLenCell = strFindCell.GetLength();
int nLenSource = strSource.GetLength();
if(nLenCell < 1)
return TRUE;
if(nLenSource <1)
return FALSE;
strSource.MakeLower();
strFindCell.MakeLower();
bool bContainChar = FALSE;
int i,j,k;
for(i=0; i< nLenCell; i++)
{
if( !(strFindCell.GetAt(i)&0x80) )
{
bContainChar = TRUE;
break;
}
}
j = 0;
int nMatchCharCount = 0;
bool bEqual = FALSE;
int ik;
for(i = 0; i< nLenCell && j < nLenSource; i++)
{
ik = i;
char c = strFindCell.GetAt(i);
if(c&0x80)//汉字
{
i++;
while(j < nLenSource)
{
char cs = strSource.GetAt(j++);
k = j;
if(cs&0x80)//汉字
j++;
if(cs == c && k < nLenSource && strSource.GetAt(k) == strFindCell.GetAt(i))
{
if(ik == 0)
bEqual = TRUE;
nMatchCharCount += 2;
break;
}
else if(i > 0)
{
bEqual = FALSE;
nMatchCharCount = 0;
i = 0;
break;
}
}
}
else//字母
{
while(j < nLenSource)
{
char cs = strSource.GetAt(j++);
k = j;
if(cs&0x80)//汉字
{
j++;
if(IsBlur(cs,strSource.GetAt(k),c))
{
if(ik == 0)
bEqual = TRUE;
nMatchCharCount++;
break;
}
else if(i > 0)
{
bEqual = FALSE;
nMatchCharCount = 0;
i = 0;
break;
}
}
else if(cs == c)
{
if(ik == 0)
bEqual = TRUE;
nMatchCharCount++;
break;
}
else if(i > 0)
{
bEqual = FALSE;
nMatchCharCount = 0;
i = 0;
break;
}
}
}
}
if(bEqual && i == nLenCell && j == nLenSource)
return TRUE;
else
return (nMatchCharCount == nLenCell);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货