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

📄 bookm.cpp

📁 用mfc写的图书馆信息管理系统界面
💻 CPP
字号:
// BOOKM.cpp : implementation file
//

#include "stdafx.h"
#include "LibMgr.h"
#include "BOOKM.h"
#include "LibMgrDlg.h"


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

extern BLink BHead;
extern linkN;
/////////////////////////////////////////////////////////////////////////////
// CBOOKM dialog


CBOOKM::CBOOKM(CWnd* pParent /*=NULL*/)
	: CDialog(CBOOKM::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBOOKM)
	m_author = _T("");
	m_date = _T("");
	m_lab = _T("");
	m_name = _T("");
	m_num = _T("");
	m_price = _T("");
	m_pub = _T("");
	//}}AFX_DATA_INIT
}


void CBOOKM::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBOOKM)
	DDX_Control(pDX, IDC_BOOKLIST, m_blist);
	DDX_Text(pDX, IDC_AUEDIT, m_author);
	DDX_Text(pDX, IDC_DATEEDIT, m_date);
	DDX_Text(pDX, IDC_LABEDIT, m_lab);
	DDX_Text(pDX, IDC_NAMEEDIT, m_name);
	DDX_Text(pDX, IDC_NUMEDIT, m_num);
	DDX_Text(pDX, IDC_PRICEEDIT, m_price);
	DDX_Text(pDX, IDC_PUBEDIT, m_pub);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBOOKM, CDialog)
	//{{AFX_MSG_MAP(CBOOKM)
	ON_BN_CLICKED(IDC_ADDBUTTON, OnAddbutton)
	ON_BN_CLICKED(IDC_SHOWBUTTON, OnShowbutton)
	ON_BN_CLICKED(IDC_SEACHBUTTON, OnSeachbutton)
	ON_NOTIFY(NM_CLICK, IDC_BOOKLIST, OnClickBooklist)
	ON_BN_CLICKED(IDC_MOBUTTON, OnMobutton)
	ON_BN_CLICKED(IDC_DELBUTTON, OnDelbutton)
	ON_BN_CLICKED(IDC_DELALLBUTTON, OnDelallbutton)
	ON_BN_CLICKED(IDC_SAVEBUTTON, OnSavebutton)
	ON_BN_CLICKED(IDC_READBUTTON, OnReadbutton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBOOKM message handlers



BOOL CBOOKM::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_blist.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	CRect rt;
	m_blist.GetClientRect(&rt);
	m_blist.InsertColumn(0,"图书编号",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(1,"中图分类号",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(2,"书名",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(3,"作者",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(4,"出版社",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(5,"出版日期",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(6,"定价",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(7,"借阅状态",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(8,"预约",LVCFMT_LEFT,rt.right/10,0);
	m_blist.InsertColumn(9,"借书证号",LVCFMT_LEFT,rt.right/10,0);
	//linkN=0;
//	book.InitList();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}



void CBOOKM::OnAddbutton() 
{
	// TODO: Add your control notification handler code here
	//Head=book.GetHead();
	UpdateData(TRUE);
	Num=m_num;
	Lable=m_lab;
	Name=m_name;
	Author=m_author;
	Pub=m_pub;
	Date=m_date;
	Price=m_price;
	if(Num=="") MessageBox("请输入图书编号!");
	else if(book.Find(BHead,Num)!=NULL) MessageBox("该图书编号已存在!");
	else if(Lable=="") MessageBox("请输入图书分类号!");
	else if(Name=="") MessageBox("请输入书名!");
	else if(Author=="") MessageBox("请输入作者!");
	else if(Pub=="") MessageBox("请输入出版社!");
	else if(Date=="") MessageBox("请输入出版日期!");
	else if(Price=="") MessageBox("请输入定价!");
	else
	{
		book.Insert(BHead,Num,Lable,Name,Author,Pub,Date,Price,linkN);
		if(book.Inok)
		{
			linkN = linkN+1;
		}

		OnShowbutton();
	}

}

void CBOOKM::OnShowbutton() 
{
	// TODO: Add your control notification handler code here
	//Head=book.GetHead();
	BLink p;
	p=BHead->Next;
	CString t,s;
	int i=0;
	m_blist.DeleteAllItems();
	while(p!=NULL)
	{
		if(p->onshelf==0) s="在库";
		else s="借出";
		if(p->tag==0) t="可";
		else t="否";
		
		m_blist.InsertItem(i,p->Num);
		m_blist.SetItemText(i,1,p->Lable);
		m_blist.SetItemText(i,2,p->Name);
		m_blist.SetItemText(i,3,p->Author);
		m_blist.SetItemText(i,4,p->Pub);
		m_blist.SetItemText(i,5,p->Date);
		m_blist.SetItemText(i,6,p->Price);
		m_blist.SetItemText(i,7,s);
		m_blist.SetItemText(i,8,t);
		m_blist.SetItemText(i,9,p->RNum);
		p=p->Next;
		i=i+1;
	}
	SetDlgItemText(IDC_NUMEDIT,"");//将各编辑框清空,以便下次输入
	SetDlgItemText(IDC_LABEDIT,"");
	SetDlgItemText(IDC_NAMEEDIT,"");
	SetDlgItemText(IDC_AUEDIT,"");
	SetDlgItemText(IDC_PUBEDIT,"");
	SetDlgItemText(IDC_DATEEDIT,"");
	SetDlgItemText(IDC_PRICEEDIT,"");


}


void CBOOKM::OnSeachbutton() 
{
	// TODO: Add your control notification handler code here
	CString num,s,t;
	
	UpdateData(TRUE);
	num=m_num;
	BLink temp;
	//Head=book.GetHead();
	temp=book.Find(BHead,num);
	if(temp!=NULL)
	{
		m_blist.DeleteAllItems();
		if(temp->onshelf==0) s="在库";
		else s="借出";
		if(temp->tag==0) t="可";
		else t="否";
		m_blist.InsertItem(0,temp->Num);
		m_blist.SetItemText(0,1,temp->Lable);
		m_blist.SetItemText(0,2,temp->Name);
		m_blist.SetItemText(0,3,temp->Author);
		m_blist.SetItemText(0,4,temp->Pub);
		m_blist.SetItemText(0,5,temp->Date);
		m_blist.SetItemText(0,6,temp->Price);
		m_blist.SetItemText(0,7,s);
		m_blist.SetItemText(0,8,t);
		m_blist.SetItemText(0,9,temp->RNum);

	SetDlgItemText(IDC_NUMEDIT,temp->Num);//在编辑框中显示查找到的图书信息
	SetDlgItemText(IDC_LABEDIT,temp->Lable);
	SetDlgItemText(IDC_NAMEEDIT,temp->Name);
	SetDlgItemText(IDC_AUEDIT,temp->Author);
	SetDlgItemText(IDC_PUBEDIT,temp->Pub);
	SetDlgItemText(IDC_DATEEDIT,temp->Date);
	SetDlgItemText(IDC_PRICEEDIT,temp->Price);
	}
	else
	{
		MessageBox("无法找到该图书!");
		SetDlgItemText(IDC_NUMEDIT,"");//将各编辑框清空,以便下次输入
		SetDlgItemText(IDC_LABEDIT,"");
		SetDlgItemText(IDC_NAMEEDIT,"");
		SetDlgItemText(IDC_AUEDIT,"");
		SetDlgItemText(IDC_PUBEDIT,"");
		SetDlgItemText(IDC_DATEEDIT,"");
		SetDlgItemText(IDC_PRICEEDIT,"");
	}


}

void CBOOKM::OnClickBooklist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int i=m_blist.GetSelectionMark();
	m_num=m_blist.GetItemText(i,0);
	m_lab=m_blist.GetItemText(i,1);
	m_name=m_blist.GetItemText(i,2);
	m_author=m_blist.GetItemText(i,3);
	m_pub=m_blist.GetItemText(i,4);
	m_date=m_blist.GetItemText(i,5);
	m_price=m_blist.GetItemText(i,6);
	UpdateData(FALSE);
	*pResult = 0;
}



void CBOOKM::OnMobutton() 
{
	// TODO: Add your control notification handler code here
	int pos,temp;
	BLink p;
	pos=m_blist.GetSelectionMark();
	temp=linkN;
	linkN=pos;
	p=book.GetList(BHead,pos);
	p->Num="";
	OnAddbutton();
	book.Delete(BHead,pos+1);
	OnShowbutton();
	linkN=temp;
}


void CBOOKM::OnDelbutton() 
{
	// TODO: Add your control notification handler code here
	int i=m_blist.GetSelectionMark();
	book.Delete(BHead,i);
	if(book.Delok)
	{
		linkN=linkN-1;
	}
	OnShowbutton();
}



void CBOOKM::OnDelallbutton() 
{
	// TODO: Add your control notification handler code here
	for(int i=0;i<linkN;i++)
	{
		book.Delete(BHead,0);

	}
	linkN=0;
	OnShowbutton();
}

void CBOOKM::OnSavebutton() 
{
	// TODO: Add your control notification handler code here
	CString Filter;
	Filter = "文本文件(*.txt)|*.txt||";

	CFileDialog FileDlg (FALSE, ".txt", NULL, OFN_OVERWRITEPROMPT, Filter);

	if(FileDlg.DoModal()==IDOK)
	{
		CString filename=FileDlg.GetPathName();
		BText.Open(filename,CFile::modeCreate | CFile::modeWrite);
		BLink pr;
		CString content,s,t;
//		Head=book.GetHead();
		pr=BHead->Next;
		while(pr!=NULL)
		{
			if(pr->onshelf==0) s="在库";
		else s="借出";
		if(pr->tag==0) t="可";
		else t="否";
		content=pr->Num+","+pr->Lable+","+pr->Name+","+pr->Author+","+pr->Pub+","+pr->Date+","+pr->Price+","+s+","+t+","+pr->RNum+";"+"\n";
		BText.WriteString(content);
			pr=pr->Next;
		}
		BText.Close();
	}
}

void CBOOKM::OnReadbutton() 
{
	// TODO: Add your control notification handler code here
	CString Filter;
	int pos,n;
	int i,j;
	int k=0;
	Filter = "文本文件(*.txt)|*.txt||";
	CFileDialog FileDlg (TRUE, NULL, NULL, OFN_HIDEREADONLY, Filter);

	if (FileDlg.DoModal () == IDOK)
	{
		book.InitList();
		BHead=book.GetHead();
		BLink pr;
		pr=BHead->Next;
		linkN=0;
		CString filename=FileDlg.GetPathName();
		BText.Open(filename,CFile::modeReadWrite);
		CString num,lab,name,author,pub,date,price,s,t,content,rnum;
		while(BText.ReadString(content))
		{
			pos=content.Find(",");            //以逗号作为分隔符
			num=content.Mid(0,pos);
			n=pos;
			pos=content.Find(",",pos+1);           
			lab=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			name=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			author=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			pub=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			date=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			price=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			s=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(",",pos+1);           
			t=content.Mid(n+1,pos-n-1);
			n=pos;
			pos=content.Find(";",pos+1);           
			rnum=content.Mid(n+1,pos-n-1);
			n=pos;
			if(s=="在库") i=0;
			else i=1;
			if(t=="可") j=0;
			else j=1;
			book.Insert(BHead,num,lab,name,author,pub,date,price,linkN);
			pr=book.GetList(BHead,k);
			pr->onshelf=i;
			pr->tag=j;
			pr->RNum=rnum;
			k++;
			linkN=linkN+1;
		}
		BText.Close();
		OnShowbutton();
	}
}

⌨️ 快捷键说明

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