?? 手機查詢系統dlg.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 + -