📄 basicfight.cpp
字号:
// BasicFight.cpp : implementation file
//
#include "stdafx.h"
#include "MyFight.h"
#include "BasicFight.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// BasicFight dialog
BasicFight::BasicFight(CWnd* pParent /*=NULL*/)
: CDialog(BasicFight::IDD, pParent)
{
//{{AFX_DATA_INIT(BasicFight)
m_csName = _T("");
m_csFactory = _T("");
m_csNum = _T("");
m_csMark = _T("");
m_bFactory = FALSE;
m_bName = FALSE;
m_bNum = FALSE;
m_bMark = FALSE;
//}}AFX_DATA_INIT
}
void BasicFight::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(BasicFight)
DDX_Control(pDX, IDC_LIST1, m_BasicList);
DDX_Text(pDX, IDC_EDIT1, m_csName);
DDX_Text(pDX, IDC_EDIT2, m_csFactory);
DDX_Text(pDX, IDC_EDIT3, m_csNum);
DDX_Text(pDX, IDC_EDIT4, m_csMark);
DDX_Check(pDX, IDC_FAC, m_bFactory);
DDX_Check(pDX, IDC_NAME, m_bName);
DDX_Check(pDX, IDC_NUM, m_bNum);
DDX_Check(pDX, IDC_STANDARD, m_bMark);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(BasicFight, CDialog)
//{{AFX_MSG_MAP(BasicFight)
ON_BN_CLICKED(IDC_NAME, OnName)
ON_BN_CLICKED(IDC_FAC, OnFac)
ON_BN_CLICKED(IDC_NUM, OnNum)
ON_BN_CLICKED(IDC_STANDARD, OnStandard)
ON_BN_CLICKED(IDC_SEARCH, OnSearch)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_BN_CLICKED(IDC_CANCLE1, OnCancle1)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// BasicFight message handlers
BOOL BasicFight::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH,path);
m_csCurrentPath=path;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void BasicFight::OnName()
{
// TODO: Add your control notification handler code here
this->UpdateData(1);
this->UpdateData(0);
}
void BasicFight::OnFac()
{
// TODO: Add your control notification handler code here
this->UpdateData(1);
this->UpdateData(0);
}
void BasicFight::OnNum()
{
// TODO: Add your control notification handler code here
this->UpdateData(1);
this->UpdateData(0);
}
void BasicFight::OnStandard()
{
// TODO: Add your control notification handler code here
this->UpdateData(1);
this->UpdateData(0);
}
void BasicFight::OnSearch()
{
// TODO: Add your control notification handler code here
m_nIsRead=0; //标记文件是否被第一次读取;
this->UpdateData();
m_BasicList.DeleteAllItems();
for(int i=0;i<10;i++)
m_BasicList.DeleteColumn(0);
SetCursor(LoadCursor(NULL, IDC_APPSTARTING));
if(!m_bName&&!m_bFactory&&!m_bNum&&!m_bMark)
{
MessageBox("请选择要比较的条目");
return ;
}
else
{
CString str="";
if(m_bName)
str+=m_csName;
str+="\t";
if(m_bFactory)
str+=m_csFactory;
str+="\t";
if(m_bNum)
str+=m_csNum;
str+="\t";
if(m_bMark)
str+=m_csMark;
str+="\t";
// MessageBox(str);
if(str.GetLength()==4)
{
MessageBox("请输入打假信息");
return ;
}
}
this->SetWindowText("查找中,请稍后....");
CStringArray arr;
arr.Add(m_csName);
arr.Add(m_csFactory);
arr.Add(m_csNum);
arr.Add(m_csMark);
CString csPath=m_csCurrentPath;
csPath+="\\";
if(m_bMark)
csPath+="药品批准文号"; //国药准字号在药品批准文号中查找;
else
csPath+="质量公报";
FileFind(csPath,arr);
this->SetWindowText("查找完毕");
if(m_BasicList.GetItemCount()==0)
MessageBox("没找到伪劣药品");
}
void BasicFight::FileFind(CString csPath, CStringArray & arr)
{
CString strDir;
strDir=csPath;
CFileFind ff;
if(strDir.Right(1)!="\\")
strDir+="\\";
strDir+="*.*";
BOOL bfound=ff.FindFile(strDir); //递归搜索.csv打假标准文件;
while(bfound)
{
bfound=ff.FindNextFile();
if(ff.IsDirectory()&&!ff.IsDots())
{
CString cs=ff.GetFilePath();
FileFind(cs,arr);
}
else if(!ff.IsDirectory()&&!ff.IsDots()&&ff.GetFilePath().Right(4)==".csv")//找到.csv打假标准文件;
{
m_nIsRead++; //找到.csv文件就加1,避免重复插入标题到列表中;
CString cspath=ff.GetFilePath(); //得到文件路径;
m_csTitle=ff.GetFileTitle();
if(m_bMark)
SearchMark(cspath,arr);
else
SearchExact(cspath,arr);
}
}
}
void BasicFight::SearchExact(CString csPath, CStringArray & arr1)
{
// MessageBox(csPath);
CStdioFile file; //打假标准文件;
file.Open(csPath,CFile::modeRead );
BOOL bname=0; //比较标志符;
BOOL bfactory=0;
BOOL bnum=1;
CString sname1=arr1[0];
CString sfac1=arr1[1];
CString snum1=arr1[2];
int n=1;
CString str1;
while(file.ReadString(str1))
{
CString sname2;
CString sfac2;
CString snum2;
CStringArray arr2;
while(!str1.IsEmpty()) //将每一行转换成一个字符窜数组保存;
{
int pos=str1.Find((char)44);
if(pos==-1)break;
arr2.Add(str1.Left(pos));
str1=str1.Right(str1.GetLength()-pos-1);
}
sname2=arr2[0];
sfac2=arr2[1];
snum2=arr2[2];
if(n==1&&m_nIsRead==1) //第一行为标题;不比较;
{
for(int i=0;i<10;i++)
m_BasicList.DeleteColumn(0);
int d=1;
m_BasicList.InsertColumn(0,"文件名",LVCFMT_LEFT,80);
for(;d<=arr2.GetSize();d++) //将标题行插入到列表中;
m_BasicList.InsertColumn(d,arr2[d-1],LVCFMT_LEFT,80);
m_BasicList.InsertColumn(d,"被抽样单位",LVCFMT_LEFT,80);
}
else
{
if(m_bName)
bname=CompareName(arr1.GetAt(0),arr2.GetAt(0));
// bname=CompareName(sname1,sname2);
if(m_bFactory)
bfactory=CompareFac(arr1.GetAt(1),arr2.GetAt(1));
// bfactory=CompareFac(sfac1,sfac2);
if(m_bNum)
bnum=CompareNum(arr1.GetAt(2),arr2.GetAt(2));
// bnum=CompareNum(snum1,snum2);
if(bnum&&(bname||bfactory))
{
m_BasicList.InsertItem(0,m_csTitle); //插入打假标准文件名;
for(int m=0;m<arr2.GetSize();m++)
{
m_BasicList.SetItemText(0,m+1,arr2.GetAt(m));
m_BasicList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
}
}
}
n++;
}
}
BOOL BasicFight::CompareName(CString s1, CString s2)
{
int pos=0;
int count=0;
for(int i=0;i<s1.GetLength();i++) //比较品名,ar1[0]为品名;
{
TCHAR aa=s1.GetAt(i);
CString ff=aa;
i++;
ff+=s1.GetAt(i);
pos=s2.Find(ff,pos);
if(pos!=-1) count++;
if(count==2) //品名要求前两个汉字相同;
{
return 1;
break;
}
}
return 0;
}
BOOL BasicFight::CompareFac(CString s1, CString s2)
{
int pos=0;
int count=0;
for( int i=0;i<s1.GetLength();i++) //比较厂家,ar1[1]为厂家;
{
TCHAR aa=s1.GetAt(i);
CString ff=aa;
i++;
ff+=s1.GetAt(i);
pos=s2.Find(ff,pos);
if(pos!=-1) count++;
if(count==6) //厂家要求前六个汉字相同;
{
return 1;
break;
}
}
return 0;
}
BOOL BasicFight::CompareNum(CString s1, CString s2)
{
if(s1==s2)
return 1;
else
return 0;
}
void BasicFight::SearchMark(CString csPath, CStringArray & arr1)
{
// MessageBox(csPath);
CStdioFile file; //打假标准文件;
file.Open(csPath,CFile::modeRead );
CString smark1=arr1[3];
int n=0;
CString str1;
while(file.ReadString(str1))
{
CStringArray arr2;
while(!str1.IsEmpty()) //将每一行转换成一个字符窜数组保存;
{
int pos=str1.Find((char)44);
if(pos==-1)break;
arr2.Add(str1.Left(pos));
str1=str1.Right(str1.GetLength()-pos-1);
}
arr2.Add(str1);
CString smark2=arr2[3].Right(arr2[3].GetLength()-8); //只比较数字部分
smark2=smark2.Left(smark2.GetLength()-2); //去掉乱码;
if(n==0&&m_nIsRead==1) //第一行为标题;不比较;
{
int d=1;
for(int i=0;i<10;i++)
m_BasicList.DeleteColumn(0);
m_BasicList.InsertColumn(0,"文件名",LVCFMT_LEFT,80);
for(;d<=arr2.GetSize();d++) //将标题行插入到列表中;
m_BasicList.InsertColumn(d,arr2[d-1],LVCFMT_LEFT,80);
}
else
{
if(smark1==smark2)
{
m_BasicList.InsertItem(0,m_csTitle); //插入打假标准文件名;
for(int m=0;m<arr2.GetSize();m++)
{
m_BasicList.SetItemText(0,m+1,arr2.GetAt(m));
m_BasicList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
}
}
}
n++;
}
}
void BasicFight::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString str;
CString cs;
int nMark=m_BasicList.GetNextItem(-1,LVNI_SELECTED );
str=m_BasicList.GetItemText(nMark,0);
int i=1;
while(str!="")
{
cs+=str;
cs+="\t";
str=m_BasicList.GetItemText(nMark,i);
i++;
}
MessageBox(cs);
*pResult = 0;
}
void BasicFight::OnCancle1()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
void BasicFight::OnSave()
{
// TODO: Add your control notification handler code here
CString path;
path=m_csCurrentPath;
path+='\\';
path+="save.txt";
CStdioFile file(path,CFile::modeCreate | CFile::modeWrite | CFile::typeText);
for(int i=0;i<m_BasicList.GetItemCount();i++)
{
CString str="";
for(int j=0;j<m_BasicList.GetCountPerPage();j++)
{
str+= m_BasicList.GetItemText(i,j);
str+="\t";
}
str+='\n';
file.WriteString(str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -