课设题目
图书管理系统
课设要求
①利用MFC的向导,创建基于对话框的应用程序,添加按钮、编辑框等控件;
②设计图书信息的数据结构(如:以数组或者动态链表)和相应的类;
③完成对图书信息记录的增加、修改、删除和显示。
将图书信息存入文件。能够打开并显示其中所存的图书信息,并可以按图书ID、图书名称、出版社、作者、价格或图书分类等信息查询图书。
程序运行界面
源码
部分
// Class Address listDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Class Address list.h"
#include "Class Address listDlg.h"
#include <vector>
#include<ostream>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class Student{
public:
CString ID;
CString name;
CString address;
CString zuozhe;
CString jiage;
CString leibie;
};
vector <Student>stu;
int n = -1;
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()
/////////////////////////////////////////////////////////////////////////////
// CClassAddresslistDlg dialog
CClassAddresslistDlg::CClassAddresslistDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClassAddresslistDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClassAddresslistDlg)
m_ID = _T("");
m_Name = _T("");
m_Address = _T("");
m_jiage = _T("");
m_leibie = _T("");
m_zuozhe = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClassAddresslistDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClassAddresslistDlg)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_EDIT_ID, m_ID);
DDX_Text(pDX, IDC_EDIT_Name, m_Name);
DDX_Text(pDX, IDC_EDIT_Address, m_Address);
DDX_Text(pDX, IDC_EDIT_jiage, m_jiage);
DDX_Text(pDX, IDC_EDIT_leibie, m_leibie);
DDX_Text(pDX, IDC_EDIT_zuozhe, m_zuozhe);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClassAddresslistDlg, CDialog)
//{{AFX_MSG_MAP(CClassAddresslistDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONincrease, OnBUTTONincrease)
ON_BN_CLICKED(IDC_BUTTONchange, OnBUTTONchange)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_BUTTONdelete, OnBUTTONdelete)
ON_BN_CLICKED(IDC_BUTTON6, OnButtontuichu)
ON_BN_CLICKED(IDC_BUTTONpreserve, OnBUTTONpreserve)
ON_BN_CLICKED(IDC_BUTTONduqu, OnBUTTONduqu)
ON_BN_CLICKED(IDC_BUTTONSearch, OnBUTTONSearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClassAddresslistDlg message handlers
BOOL CClassAddresslistDlg::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
m_list.SetExtendedStyle(LVS_EX_FLATSB //扁平风格滚动条
|LVS_EX_FULLROWSELECT //选择整行
|LVS_EX_HEADERDRAGDROP //报表头可以拖拽
|LVS_EX_ONECLICKACTIVATE //单击激活
|LVS_EX_GRIDLINES); //绘制表格
//设置表头
m_list.InsertColumn(0,"图书ID",LVCFMT_LEFT,90);
m_list.InsertColumn(1,"图书名称",LVCFMT_LEFT,90);
m_list.InsertColumn(2,"出版社",LVCFMT_LEFT,90);
m_list.InsertColumn(3,"作者",LVCFMT_LEFT,90);
m_list.InsertColumn(4,"价格",LVCFMT_LEFT,90);
m_list.InsertColumn(5,"图书类别",LVCFMT_LEFT,90);
return TRUE; // return TRUE unless you set the focus to a control
}
void CClassAddresslistDlg::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 CClassAddresslistDlg::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 CClassAddresslistDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CClassAddresslistDlg::OnBUTTONincrease()
{
// TODO: Add your control notification handler code here
int flag = 0;//以便于选择性执行if语句
UpdateData(true);
if(m_Name==""||m_ID==""||m_leibie==""||
m_Address==""||m_jiage==""||m_zuozhe=="")
{
flag = 1;
MessageBox("输入信息不完善,请重新输入!");
}
if (flag==0)
for (int i = 0;i < stu.size();i++)
{
if ( stu[i].name == m_Name&&stu[i].ID == m_ID&&stu[i].leibie == m_leibie&&stu[i].jiage ==
m_jiage&&stu[i].zuozhe == m_zuozhe&&stu[i].address == m_Address)
{
flag = 1;
MessageBox("该图书信息已经添加!");
break;
}
}
if (flag==0)
{
int n=m_list.GetItemCount();
m_list.InsertItem(n,"");
m_list.SetItemText(n,0,m_ID);
m_list.SetItemText(n,1,m_Name);
m_list.SetItemText(n,2,m_Address);
m_list.SetItemText(n,3,m_zuozhe);
m_list.SetItemText(n,4,m_jiage);
m_list.SetItemText(n,5,m_leibie);
stu.reserve(stu.size()+1);//增加容量以防止溢出
Student s1;
s1.name = m_Name;
s1.ID = m_ID;
s1.jiage = m_jiage;
s1.leibie = m_leibie;
s1.zuozhe = m_zuozhe;
s1.address = m_Address;
stu.push_back(s1);//往向量末尾加新信息
MessageBox("添加成功!");
m_Name="";
m_ID="";
m_Address="";
m_zuozhe="";
m_jiage="";
m_leibie=""; //清空编辑框
UpdateData(false);
}
}
}
源码及课设报告
需要的小伙伴请在海轰的微信公众号:海轰Pro
回复:海轰
O(∩_∩)O哈哈~