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

📄 手机查询系统dlg.cpp

📁 手机查询系统:可以在指定目录建立数据文件存储手机数据
💻 CPP
字号:
// 手机查询系统Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "手机查询系统.h"
#include "手机查询系统Dlg.h"
#include <iostream.h>
#include <fstream.h>
#include <stdlib.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()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_edit_mobile = _T("");
	m_edit_name = _T("");
	//}}AFX_DATA_INIT

	MaxNum = 0;
	for(int i=0;i<1000;i++)
	{
		user[i].name = "";
		user[i].mobile = "";
	}
	myfile.open("c:\\usermobile.txt",ios::in);
	if(!myfile)
	{
		CString error_msg;
		error_msg = "打开文件usermobile.txt失败!!! ";
		AfxMessageBox(error_msg);
		abort();
	}
	
	while(!myfile.eof())
	{
		char name[10],mobile[13];
		CString msg,mid_para;
		 
		myfile.getline(name,sizeof(name));
		user[MaxNum].name = name;
		myfile.getline(mobile,sizeof(mobile));
		user[MaxNum].mobile = mobile;
		/*msg = "文件中的数据存入数组为: ";
		msg += "\r\n\n";
		mid_para.Format("user[%d].name = %s",MaxNum,user[MaxNum].name);
		msg += mid_para;
		msg += "\r\n";
		mid_para.Format("user[%d].mobile = %s",MaxNum,user[MaxNum].mobile);
		msg += mid_para;
		AfxMessageBox(msg);*/
		MaxNum++;
	}

	myfile.close();

	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, ID_DELETE, m_delete);
	DDX_Control(pDX, ID_QUERY, m_query);
	DDX_Control(pDX, ID_MODIFY, m_modify);
	DDX_Control(pDX, ID_INCREASE, m_increase);
	DDX_Text(pDX, IDC_EDIT_MOBILE, m_edit_mobile);
	DDV_MaxChars(pDX, m_edit_mobile, 11);
	DDX_Text(pDX, IDC_EDIT_NAME, m_edit_name);
	DDV_MaxChars(pDX, m_edit_name, 8);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_INCREASE, OnIncrease)
	ON_BN_CLICKED(ID_QUERY, OnQuery)
	ON_BN_CLICKED(ID_DELETE, OnDelete)
	ON_BN_CLICKED(ID_MODIFY, OnModify)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::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
	/*CString test;
	AfxMessageBox("aaaaaaaaaaaaaaaa");
	test.Format("%s",CDialog::GetFont());
	AfxMessageBox(test);
	CDialog::SetFont("8");
	test.Format("%s",CDialog::GetFont());
	AfxMessageBox(test);*/
	//CDialog::SetDialogBkColor (RGB (0, 0, 255 ), RGB ( 255 , 255 , 0 ) ) ;

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

void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::OnIncrease() 
{
	// TODO: Add your control notification handler code here
	
	CString msg;
	CString mid_parameter;
	int i = 0;
	UpdateData();


	if((m_edit_name.IsEmpty()==FALSE)&&(m_edit_mobile.IsEmpty()==FALSE))
	{
		//user[MaxNum].name = m_edit_name;
		//user[MaxNum].mobile = m_edit_mobile;
		myfile.open("c:\\usermobile.txt",ios::out|ios::app);
		myfile<<m_edit_name<<endl<<m_edit_mobile<<endl;
		msg = " 一个用户手机号码成功存入手机查询系统! ";
		msg += "\r\n\n";
		msg += "姓    名: ";
		msg += m_edit_name;
		msg += "\r\n";
		msg += "手机号码: ";
		msg += m_edit_mobile;
		msg += "\r\n\n";
		msg += "增加的数据存放在: C:/usermobile.txt";
		//msg += "\r\n";
		//mid_parameter.Format("user[%d].name = %s",MaxNum,user[MaxNum].name);
		//msg += mid_parameter;
		//msg += "\r\n";
		//mid_parameter.Format("user[%d].mobile = %s",MaxNum,user[MaxNum].mobile);
		//msg += mid_parameter;
		MaxNum++;
		myfile.close();
	}
	else
	{
		msg = "用户手机号码存入手机查询系统失败!!! ";
		msg += "\r\n\n";
		msg += "必须正确输入用户姓名和手机号码!!! ";
	}
	MessageBox(msg,"操作结果",MB_OK|MB_ICONINFORMATION);
    m_edit_mobile = _T("");
	m_edit_name = _T("");
	UpdateData(FALSE);
	
}

void CMyDlg::OnQuery() 
{
	// TODO: Add your control notification handler code here
	CString msg;
	MaxNum = 0;
	CString mid_parameter;
	int i;
	UpdateData();

	myfile.open("c:\\usermobile.txt",ios::in);
	if(!myfile)
	{
		CString error_msg;
		error_msg = "打开文件usermobile.txt失败!!! ";
		MessageBox(error_msg,"操作结果",MB_OK|MB_ICONSTOP);
		abort();
	}
	
	while(!myfile.eof())
	{
		char name[10],mobile[13];
		CString msg,mid_para,mid;
		 
		myfile.getline(name,sizeof(name));
		user[MaxNum].name = name;
		myfile.getline(mobile,sizeof(mobile));
		user[MaxNum].mobile = mobile;
		/*msg = "文件中的数据存入数组为: ";
		msg += "\r\n\n";
		mid_para.Format("user[%d].name = %s",MaxNum,user[MaxNum].name);
		msg += mid_para;
		msg += "\r\n";
		mid_para.Format("user[%d].mobile = %s",MaxNum,user[MaxNum].mobile);
		msg += mid_para;
		AfxMessageBox(msg);
		
		mid.Format("MaxNum = %d",MaxNum);
		AfxMessageBox(mid);*/
		MaxNum++;
	}

	MaxNum--;

	if(MaxNum==0)
	{
		msg = "手机查询系统中没有任何数据信息可以搜索查询!!! ";
		user[0].name="";
		user[0].mobile="";
		
		MessageBox(msg,"操作结果",MB_OK|MB_ICONSTOP);

		goto exit;
	}

	
	if((m_edit_name.IsEmpty()==TRUE)&&(m_edit_mobile.IsEmpty()==TRUE))
		msg = "必须正确输入所要查询的姓名或手机号码!!!";
	else
	{
		for(i=0;i<MaxNum;i++)
		{
			if((user[i].name==m_edit_name)||(user[i].mobile==m_edit_mobile))
			{
				msg = "手机查询系统中含有要查询的信息!";
				msg += "\r\n\n";
				msg += "姓    名: ";
				msg += user[i].name;
				msg += "\r\n";
				msg += "手机号码: ";
				msg += user[i].mobile;
				msg += "\r\n\n";
				msg += "查询的信息位于文件:";//查询的数据存放在文件C:\usermobile.txt中";
				msg += "\r\n";
				msg += "C:/usermobile.txt";
				msg += "\r\n";
				mid_parameter.Format("第%d行用户手机信息记录",i+1);
				//AfxMessageBox(mid_parameter);
				msg += mid_parameter;
				break;
			}
			else
			msg = "手机查询系统中没有所要查询的信息!!!";
		}
	}

	MessageBox(msg,"操作结果",MB_OK|MB_ICONINFORMATION);

exit:	myfile.close();	
	m_edit_name = _T("");
	m_edit_mobile = _T("");
	UpdateData(FALSE);
}

void CMyDlg::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CString msg;
	CString mid_parameter;
	int i,j;
	MaxNum = 0;
	UpdateData();

	myfile.open("c:\\usermobile.txt",ios::in);
	if(!myfile)
	{
		CString error_msg;
		error_msg = "打开文件usermobile.txt失败!!! ";
		MessageBox(error_msg,"操作结果",MB_OK|MB_ICONSTOP);
		abort();
	}
	
	while(!myfile.eof())
	{
		char name[10],mobile[13];
		//CString msg,mid_para;
		 
		myfile.getline(name,sizeof(name));
		user[MaxNum].name = name;
		myfile.getline(mobile,sizeof(mobile));
		user[MaxNum].mobile = mobile;
		/*msg = "文件中的数据存入数组为: ";
		msg += "\r\n\n";
		mid_para.Format("user[%d].name = %s",MaxNum,user[MaxNum].name);
		msg += mid_para;
		msg += "\r\n";
		mid_para.Format("user[%d].mobile = %s",MaxNum,user[MaxNum].mobile);
		msg += mid_para;
		AfxMessageBox(msg);*/

		MaxNum++;
	}
	
	MaxNum--;

	myfile.close();

	if(MaxNum==0)
	{
		msg = "手机查询系统中没有任何数据信息可以删除!!! ";
		MessageBox(msg,"操作结果",MB_OK|MB_ICONINFORMATION);

		goto exit;
	}

	if((m_edit_name.IsEmpty()==TRUE)&&(m_edit_mobile.IsEmpty()==TRUE))
		msg = "必须正确输入所要删除的姓名或手机号码!!!";
	else
	{
		for(i=0;i<MaxNum;i++)
		{
			if((user[i].name==m_edit_name)||(user[i].mobile==m_edit_mobile))
			{
				msg = "手机查询系统中含有要删除的信息!";
				msg += "\r\n\n";
				msg += "姓    名: ";
				msg += user[i].name;
				msg += "\r\n";
				msg += "手机号码: ";
				msg += user[i].mobile;
				msg += "\r\n\n";
				msg += "删除的数据存放在文件: ";
				msg += "\r\n";
				msg += "C:/usermobile.txt中";
				msg += "\r\n";
				mid_parameter.Format("第%d行",i+1);
				msg += mid_parameter;

				for(j=i;j<MaxNum;j++)
				{
					user[j].name = user[j+1].name;
					user[j].mobile = user[j+1].mobile;
				}
				msg += "\r\n\n";
				msg += "该数据已经成功删除! ";
				MaxNum--;
				myfile.open("c:\\usermobile.txt",ios::out);
				for(i=0;i<MaxNum;i++)
				{
					myfile<<user[i].name<<endl<<user[i].mobile<<endl;
				}
				myfile.close();
				break;
			}
			else
			msg = "手机查询系统中没有所要删除的信息!!!";
		}
	}

	MessageBox(msg,"操作结果",MB_OK|MB_ICONINFORMATION);

		
exit:
	m_edit_name = _T("");
	m_edit_mobile = _T("");
	UpdateData(FALSE);

	
}

void CMyDlg::OnModify() 
{
	// TODO: Add your control notification handler code here
	CString msg;
	CString mid_parameter;
	int i;
	MaxNum = 0;
	UpdateData();

	myfile.open("C:\\usermobile.txt",ios::in);
	if(!myfile)
	{
		CString error_msg;
		error_msg = "打开文件usermobile.txt失败!!! ";
		MessageBox(error_msg,"操作结果",MB_OK|MB_ICONSTOP);
		abort();
	}
	
	while(!myfile.eof())
	{
		char name[10],mobile[13];
		 
		myfile.getline(name,sizeof(name));
		user[MaxNum].name = name;
		myfile.getline(mobile,sizeof(mobile));
		user[MaxNum].mobile = mobile;
		MaxNum++;
	}
	
	MaxNum--;

	myfile.close();

	if(MaxNum==0)
	{
		msg = "手机查询系统中没有任何数据信息可以修改!!! ";
		AfxMessageBox(msg);
		goto exit;
	}
	
	if((m_edit_name.IsEmpty()==TRUE)&&(m_edit_mobile.IsEmpty()==TRUE))
		msg = "必须正确输入所要修改的姓名或手机号码!!!";
	else
	{
		for(i=0;i<MaxNum;i++)
		{
			if(user[i].name==m_edit_name)
			{
				msg = "手机查询系统中含有要修改的信息!";
				msg += "\r\n\n";
				msg += "修改前信息为: ";
				msg += "\r\n";
				msg += "姓    名: ";
				msg += user[i].name;
				msg += "\r\n";
				msg += "手机号码: ";
				msg += user[i].mobile;
				msg += "\r\n\n";
				msg += "查询的数据存放在文件: ";
				msg += "\r\n";
				msg += "C:/usermobile中 ";
				msg += "\r\n";
				mid_parameter.Format("第%d行",i+1);
				msg += mid_parameter;

				user[i].name = m_edit_name;
				user[i].mobile = m_edit_mobile;

				msg += "\r\n\n";
				msg += "修改后信息为: ";
				msg += "\r\n";
				msg += "姓    名: ";
				msg += user[i].name;
				msg += "\r\n";
				msg += "手机号码: ";
				msg += user[i].mobile;
				msg += "\r\n\n";
				msg += "该数据已经成功修改! ";

				myfile.open("c:\\usermobile.txt",ios::out);
				for(i=0;i<MaxNum;i++)
				{
					myfile<<user[i].name<<endl<<user[i].mobile<<endl;
				}
				myfile.close();

				break;
			}
			else
			msg = "手机查询系统中没有所要修改的信息!!!";
		}
	}

	MessageBox(msg,"操作结果",MB_OK|MB_ICONINFORMATION);

		
exit:
	m_edit_name = _T("");
	m_edit_mobile = _T("");
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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