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

📄 borrow.cpp

📁 基于MFC实现的图书管管理系统
💻 CPP
字号:
// borrow.cpp : implementation file
//

#include "stdafx.h"
#include "图书馆管理系统.h"
#include "borrow.h"
#include "client.h"
#include "BookSystem.h"

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

/////////////////////////////////////////////////////////////////////////////
// borrow dialog
BookSystem * student;

borrow::borrow(int i, CWnd* pParent /*=NULL*/)
	: CDialog(borrow::IDD, pParent),booksystem(i)
{
	//{{AFX_DATA_INIT(borrow)
	m_bookname = _T("");
	m_author = _T("");
	m_booktype = _T("");
	//}}AFX_DATA_INIT
}


void borrow::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(borrow)
	DDX_Control(pDX, IDC_BOOKLIST, m_booklist);
	DDX_Control(pDX, IDC_BOOKWR, m_bauthor);
	DDX_Control(pDX, IDC_BOOKNAME, m_bname);
	DDX_Control(pDX, IDC_COMBO_PUBLISH, m_press);
	DDX_Text(pDX, IDC_BOOKNAME, m_bookname);
	DDX_Text(pDX, IDC_BOOKWR, m_author);
	DDX_Text(pDX, IDC_BOOKTYPE, m_booktype);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(borrow, CDialog)
	//{{AFX_MSG_MAP(borrow)
	ON_BN_CLICKED(IDD_ABOUTBOX12, OnSEARCH)
	ON_BN_CLICKED(IDD_ABOUTBOX11, OnBORROW)
	ON_BN_CLICKED(IDD_ABOUTBOX13, OnAboutbox13)
	ON_EN_CHANGE(IDC_BOOKTYPE, OnChangeBooktype)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// borrow message handlers

void borrow::OnSEARCH() //查找功能
{
	// TODO: Add your control notification handler code here
 	
	UpdateData(1);
	int pressnum = m_press.GetCurSel();
	
	if (m_booktype=="")
	{
    if (m_bookname=="" && m_author==""&&pressnum==-1 ) MessageBox("请输入你要查找的书!","注意");
	else if (m_author==""&&pressnum==-1)
	{ 
		student->Print_Bookname(m_bookname,student,m_booklist);
	         }
       else if (m_bookname==""&&pressnum==-1) {student->Print_Author(m_author,student,m_booklist);
	           }

	    else if (m_bookname==""&&m_author=="") {m_press.GetLBText(pressnum,m_publish);
		         student->Print_Press(m_publish,student,m_booklist);
		       }

		  else if (pressnum==-1) {student->Print_BandA(m_bookname,m_author,student,m_booklist);
		          }

		    else if (m_bookname=="") {m_press.GetLBText(pressnum,m_publish);student->Print_PandA(m_publish,m_author,student,m_booklist);
		           }

			  else if (m_author=="") {m_press.GetLBText(pressnum,m_publish);student->Print_PandB(m_publish,m_bookname,student,m_booklist);
			         }

			    else {m_press.GetLBText(pressnum,m_publish);student->Print_PandBandA(m_publish,m_bookname,m_author,student,m_booklist);
			         }
	}
     else student->Print_Type(m_booktype,student,m_booklist);
				m_bookname = '\0';
				m_author = '\0';
			//	m_booktype = '\0';
				m_press.SetCurSel(-1);
				UpdateData(0);
				
}

void borrow::OnBORROW() 
{
	// TODO: Add your control notification handler code here
	CFile write;
    if (!write.Open(m_path,CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate))
				{ 
				   MessageBox ("Openning file error!");
				    return;
				}
	else MessageBox ("Success!");
      int listnum = m_booklist.GetCurSel();
	  m_booklist.GetText(listnum,list);
	  list += '&';
	  MessageBox(list);
	  write.SeekToEnd();
      write.Write(list,list.GetLength());
	 
	write.Close();


}

void borrow::OnAboutbox13() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}


//////////////////////////////////////////////////////////////初始化函数
BOOL borrow::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// TODO: Add extra initialization here

if (booksystem)  m_bookname="",m_author="",m_press.ResetContent();

	CFile Read_BookStore;
    student=new BookSystem;

	CString temp_bookname;
	CString temp_author;
	CString temp_press;
	CString temp_type;
	CString temp_number;

	int create = 0; //数据文件建立标志;
    int flag1 = 1;
    int flag2 = 1;
    int flag3 = 1;
    int flag4 = 1;
	int flag5 = 1;
	///////////////////////////////////////////////////////////建立连表
	if(booksystem)
	{
	if(Read_BookStore.Open("BookStore\\BookStore.txt",CFile::modeRead))
		{ create = 1;
		  char temp[1];
		  while(Read_BookStore.Read(temp,1))//while
			{
	          while(temp[0]!='~'&&temp[0]!='\n')//读取一个文本对象信息;
			  {
	            if(flag1){while(temp[0]!='#'){temp_bookname+=temp[0];Read_BookStore.Read(temp,1);}flag1 = 0;}
	            else{
	              if(flag2){Read_BookStore.Read(temp,1);while(temp[0]!='#'){temp_author+=temp[0];Read_BookStore.Read(temp,1);}flag2 = 0;}
	               else{
	                 if(flag3){Read_BookStore.Read(temp,1);while(temp[0]!='#'){temp_press+=temp[0];Read_BookStore.Read(temp,1);}flag3 = 0;}
	                  else{
	                    if(flag4){Read_BookStore.Read(temp,1);while(temp[0]!='#'){temp_type+=temp[0];Read_BookStore.Read(temp,1);}flag4 = 0;}
						 else{
							 if(flag5){Read_BookStore.Read(temp,1);while(temp[0]!='~'){temp_number+=temp[0];Read_BookStore.Read(temp,1);}flag5 = 0;}}}}}
		
			  }
	////////////////******************
	// MessageBox(temp_bookname+" "+temp_author+" "+temp_press+" "+temp_type+" "+temp_number); //读出检验
	 student->InsertBookSystem(temp_press,temp_bookname,temp_author,temp_type,student);//链表建立

		 flag1 = 1;temp_bookname.Empty();//数据回原;
		 flag2 = 1;temp_type.Empty();
		 flag3 = 1;temp_author.Empty();
	     flag4 = 1;temp_press.Empty();
		 flag5 = 1;temp_number.Empty();

			}//end while;
         Read_BookStore.Close();//关闭文件;

	}//读取信息文件;
else{
	if(Read_BookStore.Open("BookStore\\BookStore.txt",CFile::modeCreate))
		create = 1;
	  Read_BookStore.Close();//关闭文件;
	}//bookname创建信息文Type件;

   booksystem = 0;
	}
////////////////////////////
		if (create) {}
		else MessageBox("系统出现问题!","警告");
		booksystem = 0;


	////////////////////读入出版社资料
	CFile file;
	CString pb;
	char t[1];
	
	file.Open("Publish.txt",CFile::modeRead);
	///////////////////////读文档
    while (file.Read(t,1))
	{
		
      if(t[0] == '&')
	  {
	    type=pb;
		m_press.AddString(type);
	
		 pb = "";
		 continue;
	  }
	  pb+=t[0];

	}
  UpdateData(1);
   	file.Close();
	///////////////////////读入完毕

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void borrow::OnChangeBooktype() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(1);
	if (m_booktype!="")
	{ m_bname.EnableWindow(0);
	  m_bauthor.EnableWindow(0);
	  m_press.EnableWindow(0);
	}
	else 
	{
		 m_bname.EnableWindow(1);
	     m_bauthor.EnableWindow(1);
	     m_press.EnableWindow(1);
	}
		
	UpdateData(0);
}

⌨️ 快捷键说明

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