📄 listoperdlg.cpp
字号:
// ListOperDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ListOper.h"
#include "ListOperDlg.h"
#include "MyDefine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern char names[10000][10];//用户存放用户姓名
extern int usernum;//用户个数
extern LNode *Head;
CString SClickStr="";
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CListOperDlg dialog
CListOperDlg::CListOperDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListOperDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListOperDlg)
m_edt_add = _T("");
m_edt_mod = _T("");
m_edt_query = _T("*");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CListOperDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListOperDlg)
DDX_Control(pDX, IDC_LIST_USER, m_list_user);
DDX_Text(pDX, IDC_EDT_ADD, m_edt_add);
DDX_Text(pDX, IDC_EDT_MOD, m_edt_mod);
DDX_Text(pDX, IDC_EDT_QUERY, m_edt_query);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListOperDlg, CDialog)
//{{AFX_MSG_MAP(CListOperDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
ON_LBN_SELCHANGE(IDC_LIST_USER, OnSelchangeListUser)
ON_BN_CLICKED(IDC_BTN_MODIFY, OnBtnModify)
ON_BN_CLICKED(IDC_BNT_DEL, OnBntDel)
ON_BN_CLICKED(IDC_BNT_ADD, OnBntAdd)
ON_BN_CLICKED(IDC_BTN_SAVE, OnBtnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListOperDlg message handlers
BOOL CListOperDlg::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
Head=CreateList(Head);
ReadTxtFile("userinfo.txt");
Head=Head->next;
return TRUE; // return TRUE unless you set the focus to a control
}
void CListOperDlg::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 CListOperDlg::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 CListOperDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CListOperDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
UpdateData();
if(strcmp(m_edt_query,"")==0)
{
MessageBox("查询数据不能为空!");
return;
}
if(Head==NULL)
{
MessageBox("没有数据!");
return;
}
Head=ReadDataList(Head,(LPSTR)(LPCSTR)m_edt_query);
InsertListBox();
UpdateData(FALSE);
}
////////////////
//返回列表中当前选中的值
CString CListOperDlg::SingleClick()
{
CString strValue;
m_list_user.GetText(m_list_user.GetCurSel(),strValue);
return strValue;
}
void CListOperDlg::OnSelchangeListUser()
{//单击列表消息函数
// TODO: Add your control notification handler code here
SClickStr=SingleClick();
}
void CListOperDlg::OnBtnModify()
{
// TODO: Add your control notification handler code here
UpdateData();
if(strcmp(m_edt_mod,"")==0)
{
MessageBox("修改的新数据不能为空!");
return;
}
if(strcmp(SClickStr,"")==0)
{
MessageBox("请选择被修改数据!");
return;
}
Head=ModifyDataList(Head,(LPSTR)(LPCSTR)SClickStr,(LPSTR)(LPCSTR)m_edt_mod);
SClickStr="";
Head=ReadDataList(Head);
InsertListBox();
UpdateData(FALSE);
}
////////////////
//向ListBox中插入数据
void CListOperDlg::InsertListBox()
{
CString strname;
m_list_user.ResetContent();
for(int i=0;i<usernum;i++)
{
strname=names[i];
m_list_user.AddString(strname);
}
usernum=0;
}
void CListOperDlg::OnBntDel()
{
// TODO: Add your control notification handler code here
UpdateData();
if(strcmp(SClickStr,"")==0)
{
MessageBox("请选择被删除数据!");
return;
}
Head=DeleteDataList(Head,(LPSTR)(LPCSTR)SClickStr);
SClickStr="";
Head=ReadDataList(Head);
InsertListBox();
UpdateData(FALSE);
}
void CListOperDlg::OnBntAdd()
{
// TODO: Add your control notification handler code here
UpdateData();
if(strcmp(m_edt_add,"")==0)
{
MessageBox("新增的数据不能为空!");
return;
}
Head=InsertDataList(Head,(LPSTR)(LPCSTR)m_edt_add);
Head=ReadDataList(Head);
InsertListBox();
UpdateData(FALSE);
}
void CListOperDlg::OnBtnSave()
{
// TODO: Add your control notification handler code here
WirteTxtFile("userinfo.txt");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -