📄 secondfight.cpp
字号:
// SecondFight.cpp : implementation file
//
#include "stdafx.h"
#include "MyFight.h"
#include "SecondFight.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SecondFight dialog
SecondFight::SecondFight(CWnd* pParent /*=NULL*/)
: CDialog(SecondFight::IDD, pParent)
{
//{{AFX_DATA_INIT(SecondFight)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void SecondFight::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SecondFight)
DDX_Control(pDX, IDC_LIST1, m_SecList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SecondFight, CDialog)
//{{AFX_MSG_MAP(SecondFight)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_WATCH, OnWatch)
ON_BN_CLICKED(IDC_OK, OnOk)
ON_BN_CLICKED(IDC_CANCLE, OnCancle)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SecondFight message handlers
void SecondFight::OnSave()
{
// TODO: Add your control notification handler code here
CString cspath;
TCHAR szFilters[]=_T("Text And csv Files (*.txt,*.csv)|*.txt,*.csv|All Files (*.*)|*.*||");
CFileDialog file1(false,"d:\\",".txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
szFilters,this);
if(IDOK==file1.DoModal())
{
cspath=file1.m_ofn.lpstrFile;
}
CStdioFile file(cspath,CFile::modeCreate | CFile::modeWrite | CFile::typeText);
for(int i=0;i<m_SecList.GetItemCount();i++)
{
CString str="";
for(int j=0;j<m_SecList.GetCountPerPage();j++)
{
str+=m_SecList.GetItemText(i,j);
str+="\t";
}
str+="\n";
file.WriteString(str);
}
}
void SecondFight::OnWatch()
{
// TODO: Add your control notification handler code here
CString str;
CString cs;
int nMark=m_SecList.GetNextItem(-1,LVNI_SELECTED );
str=m_SecList.GetItemText(nMark,0);
int i=1;
while(str!="")
{
cs+=str;
cs+="\t";
str=m_SecList.GetItemText(nMark,i);
i++;
}
MessageBox(cs);
}
void SecondFight::OnOk()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void SecondFight::OnCancle()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
BOOL SecondFight::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
OnStartFight();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void SecondFight::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString str;
CString cs;
int nMark=m_SecList.GetNextItem(-1,LVNI_SELECTED );
str=m_SecList.GetItemText(nMark,0);
int i=1;
while(str!="")
{
cs+=str;
cs+="\t";
str=m_SecList.GetItemText(nMark,i);
i++;
}
MessageBox(cs);
*pResult = 0;
}
void SecondFight::OnStartFight()
{
if(m_csStandfile==""||m_csArmfile=="")
{
MessageBox("请输入打假文件");
return ;
}
this->ShowWindow(SW_SHOW);
this->SetWindowText("二级打假中,请稍后....");
SetCursor(LoadCursor(NULL, IDC_WAIT));
for(int i=0;i<10;i++)
m_SecList.DeleteColumn(0);
m_SecList.DeleteAllItems();
CString cspath2=m_csArmfile; //打假数据文件路径;
ReadFile2(cspath2);
// SetCursor(LoadCursor(NULL, IDC_NO));
SetWindowText("打假完毕");
if(m_SecList.GetItemCount==0)
MessageBox("没找到假劣药品");
}
void SecondFight::ReadFile2(CString csPath)
{
CString cspath1=m_csStandfile; //打假标准文件路径 ;
CStdioFile file2;
file2.Open(csPath,CFile::modeRead );
int n=1;
CString str2;
while(file2.ReadString(str2))
{
if(str2.IsEmpty())
{
// MessageBox("str2==""");
continue;
}
else
{
CStringArray ar2;
while(!str2.IsEmpty()) //将每一行转换成一个字符窜数组保存;
{
int pos=str2.Find((char)44);
if(pos==-1)break;
ar2.Add(str2.Left(pos));
str2=str2.Right(str2.GetLength()-pos-1);
}
ar2.Add(str2);
if(n==1) //第一行为标题;不比较;
{
for(int d=0;d<ar2.GetSize();d++) //将标题行插入到列表中;
{
m_SecList.InsertColumn(d,ar2[d],LVCFMT_LEFT,100);
}
}
else
ReadFile1(ar2,cspath1);
n++;
}
}
file2.Close();
}
void SecondFight::ReadFile1(CStringArray & ar2, CString csPath)
{
BOOL bname=0;
BOOL bmode=0;
BOOL bnum=0; //比较标号;
BOOL bfac=0;
CString sname2=ar2[0];
CString smode2=ar2[2];
CString snum2=ar2[3];
CString sfac2=ar2[4];
CStdioFile file1; //打假标准数据;
file1.Open(csPath,CFile::modeRead );
// int m=1;
CString str1;
while(file1.ReadString(str1))
{
if(str1=="")
{
// MessageBox("empty");
continue;
}
else
{
CString sname1;
CString smode1;
CString snum1;
CString sfac1;
CStringArray ar1;
while(!str1.IsEmpty()) //将每一行转换成一个字符窜数组保存;
{
int pos=str1.Find((char)44);
if(pos==-1)break;
ar1.Add(str1.Left(pos));
str1=str1.Right(str1.GetLength()-pos-1);
}
ar1.Add(str1);
sname1=ar1[0];
smode1=ar1[2];
snum1=ar1[3];
sfac1=ar1[4];
bname= sname1==sname2 ? 1:0;
bmode= smode1==smode2 ? 1:0;
bnum = snum1==snum2 ? 1:0;
bfac = sfac1==sfac2 ? 1:0;
if(bname&&bmode&&bnum&&bfac) //如果两者相同,则跳出循环比较打假数据下一行;
break;
}
}
if(!(bname||bmode||bnum||bfac)) //如果打假数据跟标准数据每一行都不相同;
{
int nItem;
for(int d=0;d<ar2.GetSize();d++) //将假劣药品显示在列表中;
{
if(d==0)
nItem=m_SecList.InsertItem(0,ar2[d]);
else
m_SecList.SetItemText(nItem,d,ar2[d]);
m_SecList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
}
}
file1.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -