⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfightdlg.cpp

📁 这是个基于MFC开发的药品打假应用程序
💻 CPP
字号:
// MyFightDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MyFight.h"
#include "MyFightDlg.h"
#include "Play.h"
#include "FirstFight.h"
#include "SecondFight.h"
#include "BasicFight.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyFightDlg dialog

CString CMyFightDlg::m_csCurrentPath=_T("");                 //当前路径初始化;
CMyFightDlg::CMyFightDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyFightDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyFightDlg)
	m_csPath1 = _T("");
	m_csPath2 = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyFightDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyFightDlg)
	DDX_Text(pDX, IDC_EDIT1, m_csPath1);
	DDX_Text(pDX, IDC_EDIT2, m_csPath2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyFightDlg, CDialog)
	//{{AFX_MSG_MAP(CMyFightDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BROWSE1, OnBrowse1)
	ON_BN_CLICKED(IDC_BROWSE2, OnBrowse2)
	ON_BN_CLICKED(IDC_FIRST, OnFirst)
	ON_BN_CLICKED(IDC_SECOND, OnSecond)
	ON_BN_CLICKED(IDC_BASIC, OnBasic)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyFightDlg message handlers

BOOL CMyFightDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	char path[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,path);
	m_csCurrentPath=path;                         //得到当前路径;

	OnPlay();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyFightDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMyFightDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyFightDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyFightDlg::OnBrowse1() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData(TRUE);
    
	CFileDialog fidlg(TRUE,
		              NULL,
		              NULL,
		              OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
					  NULL,
					  NULL);
	fidlg.m_ofn.lpstrInitialDir="d:\\";
	if(IDOK==fidlg.DoModal())
	{
		m_csPath1=fidlg.m_ofn.lpstrFile;
	}

	this->UpdateData(FALSE);
	
}

void CMyFightDlg::OnBrowse2() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData(TRUE);
//	TCHAR szFilter[]="Text and csv files(*.txt,*.csv)|(*.txt)|All Files(*.*)|(*.*)||";
	CFileDialog fidlg(TRUE,
		              NULL,
		              NULL,
		              OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
					  NULL,
					  NULL);
	fidlg.m_ofn.lpstrInitialDir="d:\\";
	if(IDOK==fidlg.DoModal())
	{
		m_csPath2=fidlg.m_ofn.lpstrFile;
	}

	this->UpdateData(FALSE);
	
}

void CMyFightDlg::OnFirst() 
{	
    FirstFight fstdlg;
	fstdlg.m_csStandFile=m_csPath1;
	fstdlg.m_csAdmin=m_csPath2;
	
	
	
	fstdlg.DoModal();
	
}

void CMyFightDlg::OnSecond() 
{
	SecondFight dlg;
	dlg.m_csStandfile=m_csPath1;
	dlg.m_csArmfile=m_csPath2;
	dlg.DoModal();


	
}

void CMyFightDlg::OnBasic() 
{
	
	BasicFight dlg;
	dlg.DoModal();
	
}

void CMyFightDlg::OnPlay() 
{
	
	Play*dlg=NULL;
	dlg=new Play();
	dlg->Create(IDD_PLAY,NULL);
	dlg->ShowWindow(SW_SHOW);
	
}

void CMyFightDlg::ReadFile2(CString csPath)
{
	CString cspath1=m_csPath1;                             //打假标准文件路径 ;

	CStdioFile  file2;                                         
	file2.Open(csPath,CFile::modeRead ); 

	int n=1;
	CString str2;
	while(file2.ReadString(str2))
	{

		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_pSecDlg->m_SecList.InsertColumn(d,ar2[d],LVCFMT_LEFT,100);
			}
		}
		else
			ReadFile1(ar2,cspath1);
		
		n++;

	}
	file2.Close();

}

void CMyFightDlg::ReadFile1(CStringArray & ar2, CString csPath)
{
	BOOL bname=0;
    BOOL bmode=0;
	BOOL bnum=0;                                                 //比较标号;
	
	CString sname2=ar2[0];
	CString smode2=ar2[2];
	CString snum2=ar2[3];

	
	CStdioFile  file1;                                            //打假标准数据;
	file1.Open(csPath,CFile::modeRead );

   
	
//	int m=1;
    CString str1;
    while(file1.ReadString(str1))
	{ 
		CString sname1;
		CString smode1;
		CString snum1;

		
		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];


		bname= sname1==sname2 ? 1:0;
		bmode= smode1==smode2 ? 1:0;
		bnum = snum1==snum2 ? 1:0;

		if(bname&&bmode&&bnum)                       //如果两者相同,则跳出循环比较打假数据下一行;
			break;
	}
		
	if(!(bname||bmode||bnum))                       //如果打假数据跟标准数据每一行都不相同;
	{        
		int nItem;
		for(int d=0;d<ar2.GetSize();d++)             //将假劣药品显示在列表中;
		{
			
			if(d==0)
				nItem=m_pSecDlg->m_SecList.InsertItem(0,ar2[d]);
			else
				m_pSecDlg->m_SecList.SetItemText(nItem,d,ar2[d]);
			m_pSecDlg->m_SecList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
		}
		
	}

    file1.Close();


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -