《圖書管理系統》

/*! @file
/********************************************************************************
模塊名       :	CAdmin 類聲明文件
文件名       :	administrator.h
相關文件     :	administrator.cpp
				person.h
				AdminManager.h
文件實現功能 :	CAdmin類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :	基類爲CPerson類
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef ADMINISTRATOR_H_INCLUDED
#define ADMINISTRATOR_H_INCLUDED

#include <string>
#include "Person.h"

extern const std::string ADMINLIST[];

/*! @class
******************************************************************************
類名稱	 : CAdmin
功能	 : 管理員可以進行的操作,包括登錄、查找、修改、顯示、寫入到文件等功能
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/
class CAdmin:public CPerson
{
public:
	bool Login(char* ,char*);				//管理員登錄
	void Solve();							//主功能
	void ShowList();						//顯示菜單
	bool Find(bool=false);					//查詢管理員
	void Modify();							//修改管理員
	void NewAdmin();						//添加管理員
	void Display();							//顯示管理員
	void WriteToFile();						//向文件裏寫入
};

#endif
/*! @file
/********************************************************************************
模塊名       :	CAdminManage 類聲明文件
文件名       :	AdminManager.h
相關文件     :	AdminManager.cpp
				administrator.h
文件實現功能 :	CAdminManage類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef ADMINMANAGER_H_INCLUDED
#define ADMINMANAGER_H_INCLUDED

#include <string>


/*! @class
******************************************************************************
類名稱	 : CAdminManage
功能	 : 對管理員進行的操作,添加、修改、刪除管理員等
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CAdminManage
{
	static const std::string LIST[];			//菜單
	char m_chKey;								//輸入選擇
public:
	void AddAdmin();							//添加管理員
	void ModifyAdmin();							//修改管理員
	void DeleteAdmin();							//刪除管理員
	void GatherAdminInf();						//統計管理員信息
	void Solve();								//主功能
	void ShowList();							//顯示菜單
	void GetKey();								//獲取輸入選擇
};
#endif

/*! @file
/********************************************************************************
模塊名       :	CBookManager 類聲明文件
文件名       :	BookManager.h
相關文件     :	BookManager.cpp
				BOOKS.H
文件實現功能 :	CBookManager類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef BOOKMANAGER_H_INCLUDED
#define BOOKMANAGER_H_INCLUDED

#include <string>
#include "BOOKS.H"

using namespace std;


/*! @class
******************************************************************************
類名稱	 : CBookManager
功能	 : 對圖書進行的操作,包括增加、修改、刪除、統計圖書
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CBookManager
{
	static const string LIST[];								//菜單
	char m_chKey;											//輸入選擇
public:
	void InsertNewBook();									//增加圖書
	void ChangeBookInf();									//修改圖書
	void DeleteBook();										//刪除圖書
	void GatherStatistics();								//統計圖書
	bool FindBook(CBook&,bool = false);						//查找圖書
	bool FindBook(char*,CBook&,char = '1',bool = false);	//查找圖書,有刪除功能
	void Solve();											//主功能
	void ShowList1();										//顯示菜單
	void ShowList2();										//顯示另一套菜單
	void ShowList3();										//顯示更另一套菜單
	void GetKey();											//獲取輸入
};
#endif

/*! @file
/********************************************************************************
模塊名       :	CBook 類聲明文件
文件名       :	BOOKS.H
相關文件     :	BOOKS.CPP
				BookManager.h
文件實現功能 :	CBook類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef BOOKS_H_INCLUDED
#define BOOKS_H_INCLUDED

#include <string>
#include <fstream>
#include "style.h"
#include "record.h"
using namespace std;

extern const string BOOKLIST[];


/*! @class
******************************************************************************
類名稱	 : CBook
功能	 : 記錄圖書的有關信息和對圖書的一些操作
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CBook
{
	char m_chTag;							//是否刪除的標誌
	char m_sName[ NAME_LENGTH ];			//圖書名
	char m_sISBN[ ISBN_LENGTH ];			//密碼
	int m_nTotal;							//數量
	int m_nLeft;							//剩餘數量
	int m_nLend;							//借出數量
public:
	void GetInf();							//獲取圖書信息
	void AppToFile(char *FileName);			//添加到文件
	bool ReadFromFile(fstream &file);		//從文件裏讀取
	int Display();							//顯示信息
	static void ShowLine();					//顯示錶頭
	void ADisplay();						//顯示錶頭和信息,用於顯示單本圖書時
	void ModifyInf();						//修改圖書信息
	bool Equal(char*, char);				//查詢兩本書是否一致
	char*GetISBN();							//返回圖書編號
	char*GetName();							//返回圖書名
	void Lend(CRecord);						//借閱圖書
	bool Return(CRecord);					//歸還圖書
};

#endif

/*! @file
/********************************************************************************
模塊名       :	CFinalMana 類聲明文件
文件名       :	finalMana.h
相關文件     :	finalMana.cpp
文件實現功能 :	CFinalMana類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef FINALMANAGER_H_INCLUDED
#define FINALMANAGER_H_INCLUDED

#include <string>
#include "style.h"
using namespace std;


/*! @class
******************************************************************************
類名稱	 : CFinalMana
功能	 : 最高一層的管理菜單,包括選擇登錄方式,重置系統等
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CFinalMana
{
	static const string LIST[];				//菜單
	char m_chKey;							//輸入選擇
	char m_sUserName[ NAME_LENGTH ];		//用戶名
	char m_sPassword[ PASSWORD_LENGTH ];	//密碼
public:
	static void ShowList();					//顯示菜單
	static void ShowList2();				//顯示另一個菜單
	void Reset();							//重置系統
	void GetKey();							//獲取輸入選擇
	void Solve();							//主功能
	void ShowLogin();						//顯示登錄菜單
	void ClearBook();						//清空圖書
	void ClearAdmin();						//清空管理員
	void ClearReaderCard();					//清空讀者卡
	void ClearReaderRecord();				//清空借閱記錄
	void ClearRecord();						//清空記錄
	bool ShowAsk(char*);					//詢問
	void ResetPassword();					//設置重置密碼
};

#endif

/*! @file
/********************************************************************************
模塊名       :	CLendManage 類聲明文件
文件名       :	LendManager.h
相關文件     :	LendManager.cpp
文件實現功能 :	CLendManage類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef LENDMANAGER_H_INCLUDED
#define LENDMANAGER_H_INCLUDED

#include <string>
#include "BOOKS.H"


/*! @class
******************************************************************************
類名稱	 : CLendManage
功能	 : 借閱、查找、歸還、統計圖書
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CLendManage
{
	static const std::string LIST[];	//菜單
	char m_chKey;						//輸入選擇
public:
	bool FindBook(CBook &book);		//查找圖書
	void LendBook();				//借閱圖書
	void ReturnBook();				//歸還圖書
	void GatherLendStatistics();	//借閱圖書統計
	void ExpireBook();				//到期圖書統計
	void GatherFineInf();			//罰款統計
	void Solve();					//借閱的主功能
	void ShowList1();				//顯示菜單
	void GetKey();					//獲取輸入
};
#endif
/*! @file
/********************************************************************************
模塊名       :	CPerson 類聲明文件
文件名       :	Person.h
相關文件     :	reader.h
				administrator.h
文件實現功能 :	CPerson類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef PERSON_H_INCLUDED
#define PERSON_H_INCLUDED

#include <iostream>
#include <iomanip>
#include "style.h"
using namespace std;


/*! @class
******************************************************************************
類名稱	 : CPerson
功能	 : 作爲reader和admin的基類,有兩者共同需要的功能:登錄,創建密碼等
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CPerson
{
protected:
	char m_chTag;							//是否刪除的標誌
	char m_sUserName[ NAME_LENGTH ];		//用戶名
	char m_sPassword[ PASSWORD_LENGTH ];	//密碼
	char m_chKey;							//輸入選擇
public:
	virtual bool Login(char* ,char*)=0;		//登錄的虛函數
	virtual void Solve()=0;					//主功能的虛函數
	virtual void ShowList()=0;				//顯示錶頭的虛函數
	char*GetName()							//返回用戶名
	{
		return m_sUserName;
	}
	void GetKey()							//獲取輸入選擇
	{
		cin >> m_chKey;
		cin.clear();
	}
	void NewPassword()						//新建密碼
	{
		char pass2[ PASSWORD_LENGTH ];
		do
		{
			cout < < setw( WID3 ) << "請輸入密碼:";
			GetPassword(m_sPassword);
			cout << setw( WID3 ) << "請再次輸入密碼:";
			GetPassword(pass2);
			if(strcmp( m_sPassword, pass2 ))
			{
				cout << "兩次輸入不一致,請重新輸入!" << endl;
			}
		}while(strcmp( m_sPassword, pass2 ));
	}
};

#endif

/*! @file
/********************************************************************************
模塊名       :	CReader 類聲明文件
文件名       :	reader.h
相關文件     :	Person.h
				reader.cpp
文件實現功能 :	CReader類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef READER_H_INCLUDED
#define READER_H_INCLUDED

#include "Person.h"
#include "BOOKS.H"
#include "record.h"

extern const string READERLIST[];


/*! @class
******************************************************************************
類名稱	 : CReader
功能	 : 讀者的基本信息及其操作
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CReader:public CPerson
{
	int m_nCardNum;					//讀者卡號
public:
	bool Login(char* ,char*);		//驗證登錄
	void Solve();					//讀者的主功能
	void ShowList();				//顯示菜單
	void ShowList2();				//顯示另一個菜單
	void BorrowBook(CRecord);		//借閱圖書
	bool ReturnBook(CRecord);		//歸還圖書
	bool Find(int,bool=false);		//查詢讀者
	int Display();					//顯示讀者信息
	void NewReader(int);			//新建讀者
	void AppToFile();				//添加到文件
	void Modify();					//修改讀者
	void GetBorrowInf();			//顯示借閱信息
	void ShowHead();				//顯示錶頭
};

#endif

/*! @file
/********************************************************************************
模塊名       :	CReaderManage 類聲明文件
文件名       :	ReaderManager.h
相關文件     :	ReaderManager.cpp
				reader.h
文件實現功能 :	CReaderManage類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef READERMANAGER_H_INCLUDED
#define READERMANAGER_H_INCLUDED

#include <string>


/*! @class
******************************************************************************
類名稱	 : CReaderManage
功能	 : 管理讀者類,申請、刪除、修改、統計讀者卡
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CReaderManage
{
	static const std::string LIST[];	//菜單信息
	char m_chKey;						//輸入選擇
	static int s_nCardNum;				//當前要給的卡號
public:
	void ApplyReaderCard();			//申請讀者卡
	void DeleteReaderCard();		//刪除讀者卡
	void ModifyReaderCard();		//修改讀者卡
	void GatherReaderLendInf();		//某人借書統計
	void GatherCardInf();			//卡號統計
	void Sovle();					//該類地主功能
	void ShowList();				//顯示錶頭
	void GetKey();					//獲得輸入
};
#endif

/*! @file
/********************************************************************************
模塊名       :	CRecord 類聲明文件
文件名       :	record.h
相關文件     :	record.cpp
文件實現功能 :	CRecord類中函數及數據的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef RECORD_H_INCLUDED
#define RECORD_H_INCLUDED

#include "style.h"
#include <string>
#include <time .h>

extern const std::string RECORDLINE[];


/*! @class
******************************************************************************
類名稱	 : CRecord
功能	 : 借閱記錄的相關內容及功能
--------------------------------------------------------------------------------
作者	 : 任震宇
*****************************************************************************/

class CRecord
{
	int m_nNum;						//借閱者卡號
	time_t m_dBorrowTime;			//借出時間
	time_t m_dDeadline;				//截止日期
	time_t m_dReturnTime;			//歸還時間
	bool m_bReturn;					//是否歸還的標誌
	bool m_bReturnFine;				//是否歸還欠款
	char m_sISBN[ ISBN_LENGTH ];	//所借圖書的編號
public:	
	double GetFine();				//計算欠款並返回
	void ShowRecord();				//顯示借閱記錄
	static void ShowLine();			//顯示錶頭
	bool SetRecord();				//添加借閱記錄
	bool ReturnBook();				//歸還圖書記錄
	char*GetISBN();					//返回所借圖書編號
	bool IsReturn();				//返回是否歸還圖書
	void Copy(CRecord);				//有選擇的拷貝記錄
	int GetNum();					//返回借閱者的卡號
	time_t GetBorrowTime();			//返回借閱時間
	time_t GetDeadline();			//返回截止日期
};

#endif

/*! @file
/********************************************************************************
模塊名       :	格式控制及公用函數聲明
文件名       :	style.h
相關文件     :	style.cpp
文件實現功能 :	輸出控制及一些公用函數的聲明
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#ifndef STYLE_H_INCLUDED
#define STYLE_H_INCLUDED

//菜單格式控制聲明的一些量
extern const int WID1;
extern const int WID2;
extern const int WID3;
extern const int WID4;
extern const int WID5;
extern const int WID6;
extern const int LENGTH0;
extern const int LENGTH1_1;
extern const int LENGTH1_2;
extern const int LENGTH3;
extern const int CARD_NUM_START;

const int PATH_LENGTH = 40;						//保存路徑的最大長度
const int NAME_LENGTH = 40;						//名字最大長度
const int PASSWORD_LENGTH = 40;					//密碼最大長度
const int ISBN_LENGTH = 30;						//圖書編號的最大長度

extern char *BOOKINFPATH;						//圖書信息保存的路徑
extern char *LENDPATH;							//所有信息保存的目錄
extern char *LENDRECORD;						//借閱記錄保存的路徑
extern char *USERINF;							//讀者信息保存的路徑
extern char *ADMININF;							//管理員信息保存的路徑
extern char *PROGRAMDATA;						//程序配置文件保存的路徑

void MyPut(const char ch,const int length);		//講字符ch輸出length次
void ShowError();								//顯示錯誤信息
void PutLine();									//輸出一行**
void ShowChoice();								//顯示選擇
void ShowHeader();								//顯示錶頭
void GetPassword(char *);						//獲取用戶輸入的密碼
#endif

/*! @file
/********************************************************************************
模塊名       :	CAdmin 類定義文件
文件名       :	administrator.cpp
相關文件     :	administrator.h
				person.h
				AdminManager.h
文件實現功能 :	CAdmin類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :	基類爲CPerson類
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include "style.h"
#include "administrator.h"
#include "BookManager.h"
#include "LendManager.h"
#include "ReaderManager.h"
#include "AdminManager.h"
using namespace std;

const string ADMINLIST[]={
		"歡迎 ",
		"*       1      圖書管理      *",
		"*       2      借閱管理      *",
		"*       3      讀者管理      *",
		"*       4      館員管理      *",
		"請輸入管理員名稱:",
		"添加成功!",
};

/*! @function
******************************************************************************
<pre>
函數名	 : Solve()
功能	 : 算是這個類地一個main函數,對各種功能的調用
--------------------------------------------------------------------------------
作者	 : 任震宇
</pre>
*****************************************************************************/
void CAdmin::Solve()
{
	do
	{
		ShowList();
		GetKey();
		CBookManager bookMana;
		CLendManage lendMana;
		CReaderManage readMana;
		CAdminManage adminMana;
		switch( m_chKey )
		{
		case '1':bookMana.Solve();break;
		case '2':lendMana.Solve();break;
		case '3':readMana.Sovle();break;
		case '4':adminMana.Solve();break;
		case 'B':break;
		case 'E':exit(0);
		default:ShowError();
		}
	}while( m_chKey != 'B' );
}

/*! @function
******************************************************************************
<pre>
函數名	 : Login()
功能	 : 管理員登錄驗證函數
參數	 :
		[IN] username : 傳入要驗證的用戶名
		[IN] password : 傳入要驗證的密碼
返回值   :	用戶名和密碼是否匹配
--------------------------------------------------------------------------------
作者	 : 任震宇
</pre>
*****************************************************************************/

bool CAdmin::Login(char *username,char *password)
{
	fstream file(ADMININF,ios::in);
	if(!file)
	{
		cout < < "當前用戶個數爲0" << endl;
		return false;
	}
	bool IsExist = false;
	while(file.read((char*)this,sizeof(CAdmin)))
	{		
		if( m_chTag == '#' && !strcmp( m_sUserName, username ) )
		{
			IsExist = true;
			if( !strcmp( m_sPassword, password ))
			{
				cout << "登錄成功!" << endl;
				file.close();
				system("pause");
				return true;
			}
		}
	}
	file.close();
	if( IsExist )
	{
		cout << "密碼輸入錯誤,請重試!" << endl;
	}
	else
	{
		cout << "用戶名不存在!" << endl;
	}
	system("pause");
	return false;
}

/*! @function
******************************************************************************
<PRE>
函數名	 : ShowList()
功能	 : 顯示菜單以供用戶選擇
--------------------------------------------------------------------------------
作者	 : 任震宇
</iomanip></iostream></pre>
*****************************************************************************/

void CAdmin::ShowList()
{
	ShowHeader();
	cout < < setw( WID5 ) << ADMINLIST[0] << m_sUserName << endl;
	PutLine();
	int i;
	for(i = 0 ; i < 4 ; i++ )
	{
		cout << setw( WID2 ) << ADMINLIST[ i+1 ] << endl;
	}
	ShowChoice();
}

/*! @function
******************************************************************************
<PRE>
函數名	 : Find()
功能	 : 查詢管理員功能
參數	 :
		[IN] IsErase  : 是否刪除的標記,真則刪除		
返回值   :	是否查找到此管理員
--------------------------------------------------------------------------------
作者	 : 任震宇
</iomanip></iostream></pre>
*****************************************************************************/

bool CAdmin::Find(bool IsErase)
{
	fstream file(ADMININF,ios::in | ios::out);
	cout < < setw( WID3 ) << ADMINLIST[ 5 ];
	char name[ NAME_LENGTH ];
	cin >> name;
	while( file.read( (char*)this, sizeof(CAdmin) ) )
	{
		if( m_chTag == '#' && strcmp( m_sUserName, name ) == 0)
		{
			if(IsErase)
			{
				file.seekp(-sizeof(CAdmin)+4,ios::cur);
				file.put('*');
			}
			file.close();
			return true;
		}
	}
	cout < < "未找到此管理員!" << endl;
	system("pause");
	file.close();
	return false;
}

/*! @function
******************************************************************************
<PRE>
函數名	 : NewAdmin()
功能	 : 添加管理員功能
--------------------------------------------------------------------------------
作者	 : 任震宇

*****************************************************************************/

void CAdmin::NewAdmin()
{
	cout < < setw( WID3 ) << ADMINLIST[ 5 ];
	cin >> m_sUserName;
	NewPassword();
	cout < < setw( WID3 ) << ADMINLIST[ 6 ] << endl;
	m_chTag = '#';
	system("pause");
}

void CAdmin::Display()
{
	if(m_chTag == '#' )
	cout << m_sUserName << endl;
}

void CAdmin::Modify()
{
	cout << setw( WID3 ) << "新用戶名:";
	cin >> m_sUserName;
}

void CAdmin::WriteToFile()
{
	fstream file(ADMININF,ios::out|ios::app);
	file.write((char*)this,sizeof(CAdmin));
	file.close();
}

/*! @file
/********************************************************************************
模塊名       :	CAdminManage 類定義文件
文件名       :	AdminManager.cpp
相關文件     :	AdminManager.h
				administrator.h
文件實現功能 :	CAdminManage類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>
#include <fstream>
#include <iomanip>
#include "AdminManager.h"
#include "administrator.h"
#include "style.h"

using namespace std;

const string CAdminManage::LIST[]={
	"************館員管理**********",
	"*       1    增加管理員      *",
		"*       2    修改管理員      *",
		"*       3    刪除管理員      *",
		"*       4      管員統計      *",
};


void CAdminManage::Solve()
{
	do
	{
		ShowList();
		GetKey();
		switch(m_chKey)
		{
		case '1':
			AddAdmin();
			break;
		case '2':
			ModifyAdmin();
			break;
		case '3':
			DeleteAdmin();
			break;
		case '4':
			GatherAdminInf();
			break;
		case 'B':
			break;
		case 'E':
			exit(0);
		default:
			ShowError();
		}		
	}while( m_chKey != 'B' );
}

void CAdminManage::AddAdmin()
{
	CAdmin admin;
	admin.NewAdmin();
	admin.WriteToFile();
}

void CAdminManage::ModifyAdmin()
{
	CAdmin admin;
	admin.Find(true);
	admin.Modify();
	admin.WriteToFile();
	cout < < "修改完畢!" << endl;
	system("pause");
	
}


void CAdminManage::DeleteAdmin()
{
	CAdmin admin;
	admin.Find(true);
	cout << "成功刪除!" << endl;
	system("pause");
}


void CAdminManage::GatherAdminInf()
{
	CAdmin admin;
	fstream file(ADMININF,ios::in);
	while(file.read((char*)&admin,sizeof(admin)))
	{
		admin.Display();
	}
	file.close();
	system("pause");
}

void CAdminManage::GetKey()
{
	cin >> m_chKey;
	cin.clear();
}

void CAdminManage::ShowList()
{
	ShowHeader();
	for(int i = 0; i < 5; i++)
	{
		cout << setw( WID2 ) << LIST[ i ] << endl;
	}
	ShowChoice();
}

/*! @file
/********************************************************************************
模塊名       :	CBookManager 類定義文件
文件名       :	BookManager.cpp
相關文件     :	BookManager.h
				BOOKS.H
文件實現功能 :	CBookManager類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include "BookManager.h"
#include "BOOKS.H"
#include "style.h"
#include "finalMana.h"

using namespace std;

const string CBookManager::LIST[] = {
	"圖書管理系統",
		"************圖書管理**********",
		"*       1      增加圖書      *",
		"*       2      修改圖書      *",
		"*       3      刪除圖書      *",
		"*       4      統計圖書      *",
		"*       B          返回      *",
		"*       E          退出      *",
		"請輸入你的選擇:",
		"*       0    按照圖書名      *",
		"*       1  按照ISBN號碼      *",
		"請輸入圖書名  :",
		"請輸入ISBN號碼:",
		"圖書名",
		"ISBN號碼",
		"庫存數量",
		"借出數量",
		"總數",
		"************修改圖書**********",
		"************刪除圖書**********",
};



void CBookManager::Solve()
{
	do
	{
		ShowList1();
		GetKey();
		switch( m_chKey )
		{
		case '1':
			InsertNewBook();
			break;
		case '2':
			ChangeBookInf();
			break;
		case '3':
			DeleteBook();
			break;
		case '4':
			GatherStatistics();
			break;
		case 'B':
			break;
		case 'E':
			exit(0);
		default :
			ShowError();			
		}
	}while( m_chKey != 'B' );
}


//添加圖書
void CBookManager::InsertNewBook()
{
	CBook NewBook;
	NewBook.GetInf();
	NewBook.AppToFile(BOOKINFPATH);
}


bool CBookManager::FindBook(char * ToFind, CBook &Book, char flag, bool IsErase)
{
	fstream file(BOOKINFPATH,ios::in | ios::out);
	bool IsFind = false;
	CBook book;
	while( !IsFind && book.ReadFromFile(file) )
	{
		if( book.Equal(ToFind, flag) )
		{
			IsFind = true;
			Book = book;
			file.seekp( -sizeof(CBook), ios::cur);
			if( IsErase ) file.put('*');
			break;
		}		
	}
	file.close();	
	return IsFind;
}


//查找圖書
bool CBookManager::FindBook(CBook &Book,bool IsErase)
{
	
	ShowList2();
	
	GetKey();
	char ToFind[ ISBN_LENGTH ];
	
	int i = 11;
	switch (m_chKey)
	{
	case '1':
		i++;
	case '0':		
		break;
	case 'B':
		m_chKey = '0';
		return false;
	case 'E':
		exit(0);
	default:
		ShowError();
		return false;
	}
	
	cout < < setw( WID3 ) << LIST[ i ];
	cin >> ToFind;

	bool IsFind = FindBook(ToFind,Book,m_chKey,IsErase);
	if(!IsFind)
	{
		cout < < "未找到此圖書" << endl;
		system("pause");
	}

	return IsFind;
}


//修改圖書
void CBookManager::ChangeBookInf()
{
	CBook book;
	cout << setw( WID2 ) << LIST[ 18 ] << endl;
	if( !FindBook(book,true) ) return ;
	
	book.ADisplay();	
	book.ModifyInf();
	book.AppToFile(BOOKINFPATH);
}


//刪除圖書
void CBookManager::DeleteBook()
{
	CBook book;
	cout << setw( WID2 ) << LIST[ 19 ] << endl;
	if(FindBook(book,true))
	{
		cout << "刪除成功!" << endl;
		system("pause");
	}
}


//統計圖書
void CBookManager::GatherStatistics()    
{
	fstream file(BOOKINFPATH,ios::in | ios:: binary);
	CBook book;
	
	if( !file )
	{
		cout << "0書目" << endl;
		system("pause");
		return;
	}
	CBook::ShowLine();
	int total = 0;
	while( !file.eof() && book.ReadFromFile( file ) )
	{
		total += book.Display();
	}
	cout << endl;
	cout << "                      共 " << total << " 種圖書" << endl;
	file.close();
	system("pause");
}


void CBookManager::ShowList1()
{
	ShowHeader();
	for(int i = 0 ; i < 5 ; i++ )
	{
		cout << setw( WID2 ) << LIST[ i+1 ] << endl;
	}
	ShowChoice();
}


void CBookManager::ShowList2()
{
	cout << setw( WID2 ) << LIST[ 9 ] << endl;
	cout << setw( WID2 ) << LIST[ 10 ] << endl;
	ShowChoice();
}

void CBookManager::GetKey()
{
	cin >> m_chKey;
	cin.clear();
}

/*! @file
/********************************************************************************
模塊名       :	CBook 類定義文件
文件名       :	BOOKS.CPP
相關文件     :	BOOKS.H
				BookManager.h
文件實現功能 :	CBook類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <fstream>
#include "style.h"
#include "BOOKS.H"

using namespace std;

const string BOOKLIST[] = {
		"請輸入圖書名  :",
		"請輸入ISBN號碼:",
		"請輸入數量    :",
		"輸入錯誤,數的總數不能爲負數!",
		"請重新輸入	   :",
		"************修改圖書**********",
		"*       0    修改圖書名      *",
		"*       1  修改ISBN號碼      *",
		"*       2  修改庫存數量      *",
		"圖書名",
		"ISBN號碼",
		"庫存數量",
		"借出數量",
		"總數",
};

void CBook::GetInf()
{
	m_chTag = '#';
	cout < < setw( WID3 ) << BOOKLIST[ 0 ];	cin >> m_sName;
	cout < < setw( WID3 ) << BOOKLIST[ 1 ];	cin >> m_sISBN;
	cout < < setw( WID3 ) << BOOKLIST[ 2 ];	cin >> m_nTotal;
	m_nLeft = m_nTotal;
	m_nLend = 0;
}



void CBook::AppToFile(char *FileName)
{
	fstream file(FileName , ios::app | ios::out | ios::binary);
	file.write((char*)this,sizeof(CBook));
	file.close();
}


int CBook::Display()
{
	if( m_chTag == '#' )
	{
		cout < < setw( WID6 ) << m_sName;
		cout << setw( WID6 ) << m_sISBN;
		cout << setw( WID6 ) << m_nLeft;
		cout << setw( WID6 ) << m_nLend;
		cout << setw( WID6 ) << m_nTotal;
		cout << endl;
		return 1;
	}
	return 0;
}


void CBook::ADisplay()
{
	ShowLine();
	Display();
}


void CBook::ModifyInf()
{
	int i;
	for( i = 5; i < 9 ; i++ )
	{
		cout << setw( WID2 ) << BOOKLIST[ i ] << endl;
	}
	ShowChoice();

	char ch;
	cin >> ch;
	switch( ch )
	{
	case '0':
		cout < < setw( WID3 ) << BOOKLIST[ 0 ];
		cin >> m_sName;
		break;
	case '1':
		cout < < setw( WID3 ) << BOOKLIST[ 1 ];
		cin >> m_sISBN;
		break;
	case '2':
		cout < < setw( WID3 ) << BOOKLIST[ 2 ];
		m_nTotal -= m_nLeft;
		cin >> m_nLeft;
		m_nTotal += m_nLeft;
	case 'B':
		break;
	case 'E':
		AppToFile(BOOKINFPATH);
		exit(0);
	default:
		ShowError();
	}
	cin.clear();
}


bool CBook::ReadFromFile(fstream &file)
{
	if( file.read((char*)this,sizeof(CBook)) ) return true;
	return false;
}


bool CBook::Equal(char* ToFind, char flag)
{
	if( m_chTag == '*' ) return false;
	if( flag == '0' && strcmp(ToFind , m_sName) == 0 ) return true;
	if( flag == '1' && strcmp(ToFind , m_sISBN) == 0 ) return true;
	return false;
}

void CBook::ShowLine()
{
	int i = 9;
	for( ; i < 14 ; i ++ ) 
		cout << setw( WID6 ) << BOOKLIST[ i ];
	cout << endl;
}

char*CBook::GetISBN()
{
	return m_sISBN;
}

void CBook::Lend(CRecord record)
{
	fstream file(LENDRECORD,ios::out | ios::app );
	file.write((char*)&record,sizeof(record));
	file.close();
	m_nLeft--;
	m_nLend++;
	AppToFile(BOOKINFPATH);
}

bool CBook::Return(CRecord record)
{
	fstream file(LENDRECORD,ios::in | ios::out);
	CRecord rec;
	while(file.read((char*)&rec,sizeof(rec)))
	{
		if( rec.GetNum() == record.GetNum() && !strcmp( rec.GetISBN(), record.GetISBN()) && !rec.IsReturn() )
		{
			file.seekp(-sizeof(rec),ios::cur);
			rec.Copy(record);
			file.write((char*)&rec,sizeof(rec));
			file.close();
			m_nLeft++;
			m_nLend--;
			AppToFile(BOOKINFPATH);
			return true;
		}
	}
	file.close();
	cout << "未找到此書~~" << endl;
	return false;
}

char *CBook::GetName()
{
	return m_sName;
}

/*! @file
/********************************************************************************
模塊名       :	CFinalMana 類定義文件
文件名       :	finalMana.cpp
相關文件     :	finalMana.h
文件實現功能 :	CFinalMana類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <stdlib .h>
#include <conio .h>
#include "style.h"
#include "finalMana.h"
#include "reader.h"
#include "administrator.h"
#include "AdminManager.h"
using namespace std;

const string CFinalMana::LIST[] = {
		"*       0      讀者登錄      *",
		"*       1    管理員登錄      *",
		"*       2      系統重置      *",
		"    登錄",
		"用戶名: ",
		"密  碼: ",
		"重置密碼(初始密碼爲1111):",
		"************系統重置**********",		
		"*       1    清空讀者卡      *",
		"*       2  清空借書記錄      *",
		"*       3    清空管理員      *",
		"*       4    清空書  籍      *",
		"*       5    清空所  有      *",
		"*       6  修改重置密碼      *",
};


void CFinalMana::Solve()
{
	CPerson *p;
	CReader reader;
	CAdmin admin;
	do
	{
		ShowList();
		GetKey();
		switch( m_chKey )
		{
		case '0' :
			p=&reader;
			break;
		case '1' :	
			p=&admin;
			break;
		case '2':
			Reset();
			continue;
		case 'B':
			exit(0);
		case 'E' :
			exit(0);
		default  :
			ShowError();
			continue;
		}
		
		ShowLogin();
		
		if( p->Login(m_sUserName, m_sPassword) )
		{
			p->Solve();
		}
	}while( m_chKey != 'B' );
}





//顯示菜單
void CFinalMana::ShowList()
{
	ShowHeader();
	PutLine();
	int i;
	for(i=0;i<3;i++)
	{
		cout < < setw( WID2 ) << LIST[i] << endl;
	}
	ShowChoice();
}


void CFinalMana::ShowList2()
{
	ShowHeader();
	int i;
	for( i = 7; i < 14 ; i++ )
	{
		cout << setw( WID2 ) << LIST[ i ] << endl;
	}
	ShowChoice();
}


//系統重置
void CFinalMana::Reset()
{
	cout << setw( WID3 ) << LIST[ 6 ];
	char password[ PASSWORD_LENGTH ];
	char pass[ PASSWORD_LENGTH ] = "1111";
	GetPassword(password);

	fstream file( PROGRAMDATA, ios::in );
	if(!file.fail())
	{
		file.seekp(sizeof(int));
		file.read(pass,sizeof(pass));
		file.close();
	}else
	{
		fstream file1( PROGRAMDATA, ios::out);
		int b=1000;
		file1.write((char*)&b,sizeof(int));
		file1.write(pass,sizeof(pass));
		file1.close();
	}
	if( strcmp( password, pass ) )
	{
		cout << "密碼錯誤!" << endl;		
		system("pause");
		return;
	}
	do
	{
		ShowList2();
		GetKey();
		switch( m_chKey )
		{
		case '1':
			if( !ShowAsk("讀者卡") )break;
			ClearReaderCard();
			ClearReaderRecord();
			break;
		case '2':
			if( !ShowAsk("借書記錄") )break;
			ClearReaderRecord();
			ClearRecord();
			break;
		case '3':
			if( !ShowAsk("管理員") )break;
			ClearAdmin();
			break;
		case '4':
			if( !ShowAsk("書籍") )break;
			ClearBook();
			break;
		case '5':
			if( !ShowAsk("所有") )break;
			ClearReaderCard();
			ClearReaderRecord();			
			ClearRecord();
			ClearBook();
			ClearAdmin();
			break;
		case '6':
			ResetPassword();
			break;
		case 'B':
			m_chKey = 'A';
			return;
		case 'E':
			exit(0);
		default:
			ShowError();
		}
	}while( m_chKey != 'B' );
}

void CFinalMana::ResetPassword()
{
	char pass[ PASSWORD_LENGTH ],pass2[ PASSWORD_LENGTH ];
	cout << setw( WID3 ) << "請輸入密碼:";
	GetPassword(pass);
	cout << setw( WID3 ) << "請確認密碼:";
	GetPassword(pass2);
	if( strcmp( pass, pass2 ) )
	{
		cout << "兩次密碼輸入不一致!";
		return;
	}
	fstream file( PROGRAMDATA, ios::out|ios::in );
	file.seekp(sizeof(int));
	file.write( pass,sizeof(pass));
	file.close();
}


void CFinalMana::GetKey()
{
	cin >> m_chKey;
	cin.clear();
}



void CFinalMana::ShowLogin()
{
	ShowHeader();	
	
	cout < < setw( WID4 ) << LIST[ 3 ] << endl << endl;
	cout << setw( WID4 ) << LIST[ 4 ];    cin >> m_sUserName;	
	cout < < setw( WID4 ) << LIST[ 5 ];
	
	GetPassword( m_sPassword );
}


void CFinalMana::ClearReaderCard()
{
	char path[ PATH_LENGTH ] = "del ";
	strcat( path, USERINF );
	system(path);
	fstream file(PROGRAMDATA,ios::out|ios::in);
	int b=1000;
	file.write((char*)&b,sizeof(int));
	file.close();
}

void CFinalMana::ClearReaderRecord()
{
	char path[ PATH_LENGTH ] = "del ";
	strcat( path, LENDPATH );
	strcat( path, "file*.dat" );
	system( path );
}


void CFinalMana::ClearAdmin()
{
	char path[ PATH_LENGTH ] = "del ";
	strcat( path, ADMININF );
	system(path);
	cout << setw( WID3 ) << "請建立一個管理員:" << endl;
	CAdminManage adminMana;
	adminMana.AddAdmin();
}

void CFinalMana::ClearRecord()
{
	char path[ PATH_LENGTH ] = "del ";
	strcat( path, LENDRECORD );
	system( path );
}

void CFinalMana::ClearBook()
{
	char path[ PATH_LENGTH ] ="del ";
	strcat( path, BOOKINFPATH );
	system( path );
}

bool CFinalMana::ShowAsk(char *data)
{
	char path[ PATH_LENGTH ] = "您確定要清空";
	strcat(path, data);
	strcat(path,"嗎?Y/N :");
	cout << setw( WID3 ) << path;
	GetKey();
	while( m_chKey != 'Y' && m_chKey != 'N' )
	{
		ShowError();
		GetKey();
	}
	if( m_chKey == 'N' )return false;
	return true;
}

/*! @file
/********************************************************************************
模塊名       :	CLendManage 類定義文件
文件名       :	LendManager.cpp
相關文件     :	LendManager.h
文件實現功能 :	CLendManage類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <time .h>
#include <iostream>
#include <iomanip>
#include "LendManager.h"
#include "style.h"
#include "BookManager.h"
#include "BOOKS.H"
#include "reader.h"
using namespace std;

const string CLendManage::LIST[] = {
		"************借閱管理**********",
		"*       1      查找圖書      *",
		"*       2      借閱圖書      *",
		"*       3      歸還圖書      *",
		"*       4  借閱圖書統計      *",
		"*       5  到期圖書統計      *",
		"*       6      罰款統計      *",		
		"*       0    按照圖書名      *",
		"*       1  按照ISBN號碼      *",
		"請輸入圖書名  :",
		"請輸入ISBN號碼:",
		"圖書名",
		"ISBN號碼",
		"庫存數量",
		"借出數量",
		"總數",
		"************歸還圖書**********",
		"************借閱圖書**********",
		"************查找圖書**********",
};

void CLendManage::Solve()
{
	do
	{
		ShowList1();
		GetKey();
		CBook book;
		switch( m_chKey )
		{
		case '1':
			cout < < setw( WID2 ) << LIST[18] << endl;
			FindBook(book);
			break;
		case '2':
			LendBook();
			break;
		case '3':
			ReturnBook();
			break;
		case '4':
			GatherLendStatistics();
			break;
		case '5':
			ExpireBook();
			break;
		case '6':
			GatherFineInf();
			break;		
		case 'B':
			break;
		case 'E':
			exit(0);
		default:
			ShowError();
		}		
	}while( m_chKey != 'B' );
}


//查找圖書
bool CLendManage::FindBook(CBook &book)				
{
	CBookManager bookMana;
	if( bookMana.FindBook(book) )
	{
		book.ADisplay();
		system("pause");
		return true;
	}
	return false;
}


//借閱圖書
void CLendManage::LendBook()
{
	CRecord record;	
	if(record.SetRecord())
	{
		cout << "借閱成功!" << endl;
		system("pause");
	}
}


//歸還圖書
void CLendManage::ReturnBook()
{
	CRecord record;
	if(record.ReturnBook())
	{
		cout << "歸還成功!" << endl;
		system("pause");
	}
}


//借閱圖書統計
void CLendManage::GatherLendStatistics()
{
	CRecord record;
	tm date;
	
	cout << "請輸入要查詢的日期:" << endl;
	
	cout << setw( WID3 ) << "年:";
	cin >> date.tm_year;
	date.tm_year -= 1900;
	
	cout < < setw( WID3 ) << "月:";
	cin >> date.tm_mon;
	date.tm_mon--;

	cout < < setw( WID3 ) << "日:";
	cin >> date.tm_mday;


	fstream file(LENDRECORD,ios::in);
	if(!file)
	{
		cout < < "0條記錄" << endl;
		return;
	}
	CRecord::ShowLine();
	int totRecord = 0;
	while(file.read((char *)&record,sizeof(CRecord)))
	{
		time_t ti = record.GetBorrowTime();
		tm tp = *localtime( &ti );
		
		if(tp.tm_year == date.tm_year && tp.tm_mon == date.tm_mon && tp.tm_mday == date.tm_mday)
		{
			record.ShowRecord();
			totRecord++;
		}
	}
	cout << "共" << totRecord << "條記錄" << endl;
	system("pause");
}


//到期圖書統計
void CLendManage::ExpireBook()
{
	CRecord record;
	fstream file(LENDRECORD,ios::in);
	record.ShowLine();
	while(file.read((char*)&record,sizeof(record)))
	{
		if(!record.IsReturn() && record.GetDeadline() < time(NULL))
		{
			record.ShowRecord();
		}
	}
	file.close();
	system("pause");
}


//罰款統計
void CLendManage::GatherFineInf()
{
	CRecord record;
	fstream file(LENDRECORD,ios::in);
	record.ShowLine();
	while(file.read((char*)&record,sizeof(record)))
	{
		if(record.GetFine()>0)
		{
			record.ShowRecord();
		}
	}
	file.close();
	system("pause");
}


void CLendManage::ShowList1()
{
	ShowHeader();
	for( int i = 0 ; i < 7 ; i++ )
	{
		cout << setw( WID2 ) << LIST[i] << endl;
	}
	ShowChoice();
}


void CLendManage::GetKey()
{
	cin >> m_chKey;
	cin.clear();
}
</iomanip></iostream></time></pre>
<pre lang="CPP" line="1" colla="-">
#include <iostream>
#include <fstream>
#include "finalMana.h"
using namespace std;
int main()
{
	CFinalMana finalMana;
	finalMana.Solve();
	return true;
}

/*! @file
/********************************************************************************
模塊名       :	CReader 類定義文件
文件名       :	reader.cpp
相關文件     :	Person.h
				reader.h
文件實現功能 :	CReader類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>

#include "reader.h"
#include "BOOKS.H"
#include "record.h"
#include "BookManager.h"
#include <string .h>

using namespace std;

const string READERLIST[]={
	"請輸入讀者名:",
		"請輸入密碼  :",
		"請再次輸入以確認您的密碼:",
		"兩次輸入不一致,請重新輸入!",
		"您的卡號是:",
		"請牢記您的卡號!",
		"************讀者登錄**********",
		"*       1      查找圖書      *",
		"*       2      借閱查詢      *",
		"*       3      修改信息      *",
		"************查找圖書**********",
		"卡號",
		"用戶名",
		"************修改信息**********",
		"*       1    修改用戶名      *",
		"*       2      修改密碼      *",		
};

bool CReader::Login(char* username,char* password)
{
	fstream file(USERINF,ios::in);
	if(!file)
	{
		cout < < "當前用戶個數爲0" << endl;
		return false;
	}
	bool IsExist = false;
	while(file.read((char*)this,sizeof(CReader)))
	{		
		if( m_chTag == '#' && !strcmp( m_sUserName, username ) )
		{
			IsExist = true;
			if( !strcmp( m_sPassword, password ))
			{
				cout << "登錄成功!" << endl;
				file.close();
				system("pause");
				return true;
			}
		}
	}
	file.close();
	if( IsExist )
	{
		cout << "密碼輸入錯誤,請重試!" << endl;
	}
	else
	{
		cout << "用戶名不存在!" << endl;
	}
	system("pause");
	return false;
}


void CReader::Solve()
{
	do
	{
		ShowList();
		GetKey();
		CBookManager bookMana;
		CBook book;
		switch(m_chKey)
		{
		case '1':
			cout << setw( WID2 ) << READERLIST[ 10 ] << endl;
			bookMana.FindBook(book);
			book.Display();
			system("pause");
			break;
		case '2':
			GetBorrowInf();
			system("pause");
			break;
		case '3':
			Find(m_nCardNum,true);
			Modify();
			break;
		case 'B':
			break;
		case 'E':
			exit(0);
		default:
			ShowError();
		}
	}while( m_chKey != 'B' );
}


void CReader::ShowList()
{
	ShowHeader();
	for(int i = 6 ; i < 10 ; i++ )
	{
		cout << setw( WID2 ) << READERLIST[ i ] << endl;
	}
	ShowChoice();
}


bool CReader::Find(int num,bool IsErase)
{
	fstream file(USERINF,ios::in | ios::out);
	while(file.read((char*)this,sizeof(CReader)))
	{
		if( m_chTag == '#' && m_nCardNum == num)
		{
			if(IsErase)
			{
				file.seekp(-sizeof(CReader)+4,ios::cur);
				file.put('*');
			}
			file.close();
			return true;
		}
	}
	file.close();
	return false;
}


int CReader::Display()
{
	if(m_chTag == '#')
	{
		
		cout << setw( WID6 ) << m_nCardNum;
		cout << setw( WID6 ) << m_sUserName;
		cout << endl;
		return 1;
	}
	return 0;
}

void CReader::BorrowBook(CRecord record)
{
	char path[ PATH_LENGTH ];
	sprintf(path, "%sfile%d.dat",LENDPATH,m_nCardNum);
	fstream file(path,ios::out | ios::app);
	file.write((char*)&record,sizeof(record));
	file.close();	
}

void CReader::NewReader(int cardNum)
{
	m_chTag = '#';
	cout << setw( WID3 ) << READERLIST[ 0 ];
	cin >> m_sUserName;
	NewPassword();
	cout < < setw( WID3 ) << READERLIST[ 4 ] << cardNum << endl;
	cout << setw( WID3 ) << READERLIST[ 5 ] << endl;
	m_nCardNum = cardNum;
	AppToFile();
	system("pause");
}

void CReader::AppToFile()
{
	fstream file(USERINF,ios::app | ios::out);
	file.write((char*)this,sizeof(CReader) );
	file.close();
}

void CReader::GetBorrowInf()
{
	char path[ PATH_LENGTH ];
	sprintf(path, "%sfile%d.dat",LENDPATH,m_nCardNum);
	fstream file(path,ios::in);
	CRecord record;
	CRecord::ShowLine();
	while(file.read((char*)&record,sizeof(record)))
	{
		record.ShowRecord();
	}
	file.close();	
}

void CReader::ShowList2()
{
	for(int i= 13;i<16;i++)
	{
		cout << setw( WID2 ) << READERLIST[ i ] << endl;
	}
	ShowChoice();
}

void CReader::Modify()
{
	ShowList2();
	GetKey();
	switch(m_chKey)
	{
	case '1':
		cout << setw( WID3 ) << READERLIST[ 0 ];
		cin >> m_sUserName;
		break;	
	case '2':
		NewPassword();
	case 'B':
		break;
	case 'E':
		AppToFile();
		exit(0);
	default:
		ShowError();
	}
	AppToFile();
}


bool CReader::ReturnBook(CRecord record)
{
	char path[ PATH_LENGTH ];
	sprintf(path, "%sfile%d.dat",LENDPATH,m_nCardNum);
	
	fstream file(path, ios::in | ios::out);
	CRecord rec;
	while(file.read((char*)&rec,sizeof(rec)))
	{
		if( !strcmp( rec.GetISBN(), record.GetISBN()) && !rec.IsReturn() )
		{
			file.seekp(-sizeof(rec),ios::cur);
			rec.Copy(record);
			file.write((char*)&rec,sizeof(rec));
			file.close();
			return true;
		}
	}
	file.close();
	cout < < "未找到此書~~" << endl;
	return false;
}

void CReader::ShowHead()
{
	cout << setw( WID6 ) << READERLIST[ 11 ];
	cout << setw( WID6 ) << READERLIST[ 12 ];
	cout << endl;
}

/*! @file
/********************************************************************************
模塊名       :	CReaderManage 類定義文件
文件名       :	ReaderManager.cpp
相關文件     :	ReaderManager.h
				reader.h
文件實現功能 :	CReaderManage類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include <iostream>
#include "ReaderManager.h"
#include <string>
#include <iomanip>
#include "style.h"
#include "reader.h"
using namespace std;

const string CReaderManage::LIST[]={
		"************讀者管理**********",
		"*       1    申請讀者卡      *",
		"*       2    刪除讀者卡      *",
		"*       3    修改讀者卡      *",
		"*       4      借書統計      *",
		"*       5      卡號統計      *",
		"請輸入要刪除的讀者卡號:",
		"請輸入要查找的讀者卡號:",
		"請輸入要修改的讀者卡號:",
		"刪除成功!",
		"未找到此卡號!",
};

int CReaderManage::s_nCardNum = CARD_NUM_START;

void CReaderManage::ShowList()
{
	ShowHeader();
	for( int i = 0 ; i < 6 ; i++ )
	{
		cout << setw( WID2 ) << LIST[i] << endl;
	}
	ShowChoice();
}


void CReaderManage::Sovle()
{
	do
	{
		ShowList();
		GetKey();
		switch( m_chKey )
		{
		case '1':
			ApplyReaderCard();
			break;
		case '2':
			DeleteReaderCard();
			break;
		case '3':
			ModifyReaderCard();
			break;
		case '4':
			GatherReaderLendInf();
			break;
		case '5':
			GatherCardInf();
			break;
		case 'B':
			break;
		case 'E':
			exit(0);
		default:
			ShowError();
		}
	}while( m_chKey != 'B' );
}


//申請讀者卡
void CReaderManage::ApplyReaderCard()
{
	CReader reader;
	fstream file(PROGRAMDATA,ios::in|ios::out);	
	file.read((char*)&s_nCardNum,sizeof(int));
		
	reader.NewReader(s_nCardNum);
	s_nCardNum++;
	file.seekp(-sizeof(int),ios::cur);
	file.write((char*)&s_nCardNum,sizeof(int));
	file.close();
}


//刪除讀者卡
void CReaderManage::DeleteReaderCard()
{
	cout << LIST[ 6 ];
	int num;
	cin >> num;
	CReader reader;
	if(reader.Find(num,true))
	{
		cout < < LIST[ 9 ] << endl;
	}else
	{
		cout << LIST[ 10 ] << endl;
	}
	system("pause");
}


//修改讀者卡
void CReaderManage::ModifyReaderCard()
{
	cout << LIST[ 8 ];
	int num;
	cin >> num;
	CReader reader;
	if(reader.Find(num,true))
	{
		reader.Modify();
	}else
	{
		cout < < LIST[ 8 ] << endl;
		system("pause");
	}
}


//某人借書統計
void CReaderManage::GatherReaderLendInf()
{
	cout << LIST[ 7 ];
	int num;
	cin >> num;
	CReader reader;
	if(reader.Find(num))
	{
		reader.GetBorrowInf();
	}else
	{
		cout < < LIST[ 10 ] << endl;
	}
	system("pause");
}


//卡號統計
void CReaderManage::GatherCardInf()
{
	fstream file(USERINF,ios::in);
	CReader reader;
	reader.ShowHead();
	int total = 0;
	while(file.read((char*)&reader,sizeof(reader)))
	{
		total += reader.Display();
	}
	cout << endl;
	cout << "           共 " << total << " 個讀者" << endl;
	system("pause");
}

void CReaderManage::GetKey()
{
	cin >> m_chKey;
	cin.clear();
}

/*! @file
/********************************************************************************
模塊名       :	CRecord 類定義文件
文件名       :	record.cpp
相關文件     :	record.h
文件實現功能 :	CRecord類中函數及數據的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include "record.h"
#include "reader.h"
#include "BookManager.h"
#include "BOOKS.H"
#include "style.h"
#include <iomanip>
#include <string .h>
#include <iomanip>
#include <time .h>

using namespace std;

const string RECORDLIST[]={
		"書名",
		"ISBN號碼",
		"借書人",
		"借出日期",
		"截止日期",
		"歸還日期",
		"罰款",
		"是否支付",
		"未歸還",
		"未支付",
		"已支付",
		"************借閱圖書**********",
		"************歸還圖書**********",
};


double CRecord::GetFine()
{
	int day;
	time_t sec;
	if( m_bReturn ) 
	{
		sec = m_dReturnTime;
	}else
	{
		sec = time(NULL);
	}

	if( sec < = m_dDeadline ) return 0;
	day = ( sec - m_dDeadline ) / ( 60 * 60 * 24 );
	
	return day * 0.1;
}


void CRecord::ShowLine()
{
	for( int i = 0 ; i < 8 ; i ++ )
	{
		cout << setw( WID6 ) << RECORDLIST[ i ];
	}
	cout << endl;
}


bool CRecord::SetRecord()
{
	cout << setw( WID3 ) << "請輸入讀者卡號:"; 
	cin >> m_nNum;
	CReader reader;
	if( !reader.Find(m_nNum) )return false;
	reader.ShowHead();
	reader.Display();

	CBook book;
	CBookManager bookMana;
	m_bReturn = false;
	m_bReturnFine = false;
	cout < < setw( WID2 ) << RECORDLIST[11] << endl;
	if( !bookMana.FindBook(book,true) ) return false;	
	book.ADisplay();
	strcpy(m_sISBN,book.GetISBN());	
	

	m_dBorrowTime = time(NULL);
	m_dDeadline = m_dBorrowTime + 60 * 60 * 24 * 30;

	reader.BorrowBook(*this);
	book.Lend(*this);
	return true;
}


bool CRecord::ReturnBook()
{
	cout << setw( WID3 ) << "請輸入讀者卡號:"; 
	cin >> m_nNum;
	CReader reader;
	if( !reader.Find(m_nNum) )return false;
	reader.ShowHead();
	reader.Display();

	CBook book;
	CBookManager bookMana;
	m_bReturn = true;

	
	cout < < setw( WID2 ) << RECORDLIST[12] << endl;
	if( !bookMana.FindBook(book,true) ) return false;	
	book.ADisplay();
	strcpy(m_sISBN,book.GetISBN());

	m_bReturn = true;
	
	m_dReturnTime = time( NULL );


	if(reader.ReturnBook(*this))
	{
		book.Return(*this);
		return true;
	}
	return false;
}

void CRecord::Copy(CRecord b)
{
	m_bReturn = b.m_bReturn;
	m_bReturnFine = b.m_bReturnFine;
	m_dReturnTime = b.m_dReturnTime;
}

int CRecord::GetNum()
{
	return m_nNum;
}


char*CRecord::GetISBN()
{
	return m_sISBN;
}

bool CRecord::IsReturn()
{
	return m_bReturn;
}


void CRecord::ShowRecord()
{
	CBookManager bookMana;
	CBook book;
	CReader reader;
	bookMana.FindBook( m_sISBN, book);
	reader.Find(m_nNum);
	
	cout << setw( WID6 ) << book.GetName();
	cout << setw( WID6 ) << book.GetISBN();
	cout << setw( WID6 ) << reader.GetName();

	char *ti = ctime(&m_dBorrowTime);
	ti[strlen(ti)-1] = '\0';
	cout << setw( WID6 ) << ti;
	
	ti = ctime(&m_dDeadline);
	ti[strlen(ti)-1] = '\0';
	cout << setw( WID6 ) << ti;
	
	if( m_bReturn )
	{
		char *ti = ctime(&m_dReturnTime);
		ti[strlen(ti)-1] = '\0';
		cout << setw( WID6 ) << ti;	
	}
	else
	{
		cout << setw( WID6 ) << RECORDLIST[ 8 ];
	}
	cout << setw( WID6 ) << GetFine();
	int i = 9;
	if( m_bReturnFine ) i++;
	cout << setw( WID6 ) << RECORDLIST[ i ];
	cout << endl;
}

time_t CRecord::GetBorrowTime()
{
	return m_dBorrowTime;
}

time_t CRecord::GetDeadline()
{
	return m_dDeadline;
}

/*! @file
/********************************************************************************
模塊名       :	格式控制及公用函數定義
文件名       :	style.cpp
相關文件     :	style.h
文件實現功能 :	輸出控制及一些公用函數的定義
作者         :	任震宇
版本         :	1.0
--------------------------------------------------------------------------------
備註         :
--------------------------------------------------------------------------------
修改記錄 : 
日 期        版本     修改人              修改內容
2011/6/10	 1.0      任震宇				創建
*******************************************************************************/
#include "style.h"
#include <iostream>
#include <iomanip>
#include <conio .h>
using namespace std;

const int WID1 = 30;
const int WID2 = 40;
const int WID3 = 20;
const int WID4 = 25;
const int WID5 = 50;
const int WID6 = 30;
const int LENGTH0 = 5;
const int LENGTH1_1 = 10;
const int LENGTH1_2 = 30;
const int LENGTH3 = 50;
const int CARD_NUM_START = 1000;

char *BOOKINFPATH = "DATA\\book.dat";
char *LENDPATH = "DATA\\";
char *LENDRECORD = "DATA\\lend.dat";
char *USERINF = "DATA\\userInf.dat";
char *ADMININF = "DATA\\adminInf.dat";
char *PROGRAMDATA = "DATA\\program.dat";

//將字符ch輸出length次
void MyPut(const char ch,const int length)
{
	cout < < setfill( ch ) << setw( length ) << ch << setfill(' ');
}


void ShowError()
{
	cerr << "輸入錯誤!請重新輸入!" << endl;
	system("pause");
}

void PutLine()
{
	MyPut(' ', LENGTH1_1);
	MyPut('*', LENGTH1_2);
	cout << endl;
}

void ShowChoice()
{
	cout << setw( WID2 ) << "*       B          返回      *" << endl;
	cout << setw( WID2 ) << "*       E          退出      *" << endl;
	PutLine();
	cout << endl;
	cout << setw( WID3 ) << "請輸入你的選擇:";
}

//顯示錶頭
void ShowHeader()
{
	system("cls");
	MyPut('\n',LENGTH0 );
	MyPut('#',LENGTH3);
	cout << endl << endl;
	cout << setw( WID1 ) << "圖書管理系統" << endl;
	cout << endl;
	MyPut('#',LENGTH3);
	cout << endl << endl;
}

void GetPassword(char *pass)
{
	char password;
	int i = 0;
	while( (password = getch()) != '\r' )
	{
		pass[ i++ ] = password;
		putchar('*');
	}
	pass[ i ] = '\0';
	cout << endl;
}



發佈了48 篇原創文章 · 獲贊 9 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章