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

📄 commonfunc.cpp

📁 LibraryManageDM.rar 数据库设计图书馆管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		e->Delete();
		pDB->Close();
		return FALSE;
	}
	//[3]
	strSQL = _T("Insert Into BookLibraryDM.SYSDBA.BookInfo \
		Values('TP312C705','Visual C++ 项目设计案例','旧书',\
		'杨小平','科学出版社',40.00,'2003-06-20','2008-09-09', 20, 0,\
		'从应用出发,以实际项目为背景,对C/S结果、三层分布式结构和网\
		络应用项目开发实例进行了详细的讨论')");
	try
	{
		pDB->ExecuteSQL(strSQL);
	}
	catch (CDBException* e)
	{
		e->ReportError();
		e->Delete();
		pDB->Close();
		return FALSE;
	}
	return TRUE;
}
BOOL InsertReader(CDatabase *pDB)
{
	if (!pDB->IsOpen())return FALSE;
	
	CString strSQL;
	//[1]
	strSQL = _T("Insert Into BookLibraryDM.SYSDBA.ReaderInfo \
		Values('B001','R001','男','本科生','HUSTCS0503','027-87556910',\
		'15946823654','r001stu@163.com','2008-09-09',\
		'address1',0.00,'快要毕业了,却还很迷茫!')");
	try
	{
		pDB->ExecuteSQL(strSQL);
	}
	catch (CDBException* e)
	{
		e->ReportError();
		e->Delete();
		pDB->Close();
		return FALSE;
	}
	//[2]
	strSQL = _T("Insert Into BookLibraryDM.SYSDBA.ReaderInfo \
		Values('B002','R002','男','本科生','HUSTCS0503','027-87548817',\
		'15946871263','r002stu@163.com','2008-09-09',\
		'address2',0.00,'要工作了!')");
	try
	{
		pDB->ExecuteSQL(strSQL);
	}
	catch (CDBException* e)
	{
		e->ReportError();
		e->Delete();
		pDB->Close();
		return FALSE;
	}
	return TRUE;
}

BOOL InitializeData(CDatabase * pDB)
{
	if (!pDB->IsOpen())return FALSE;
	BOOL ret[6];	
	// 首先向用户信息表中插入数据
	ret[0] = InsertUser(pDB);	
	// 向图书类型信息表中插入数据
	ret[1] = InsertBookType(pDB);
	// 向读者类型信息表中插入数据
	ret[2] = InsertReaderType(pDB);
	// 向罚款类型信息表中插入数据
	ret[3] = InsertPunishType(pDB);	
	// 向图书信息表中插入数据
	ret[4] = InsertBook(pDB);
	// 向读者类型信息表中插入数据
	ret[5] = InsertReader(pDB);
	return ret[0] && ret[1] && ret[2] && ret[3] && ret[4] && ret[5];
}

BOOL CopyDatabaseToFile(CString strPathName)
{
	BOOL ret[7];
	CString strFileName;
	strFileName = strPathName + "UserInfo.bak";
	ret[0] = CopyUserDataToFile(strFileName);// 备份用户信息表
	strFileName = strPathName + "BookType.bak";
	ret[1] = CopyBookTypeDataToFile(strFileName);// 备份图书类型表
	strFileName = strPathName + "BookInfo.bak";
	ret[2] = CopyBookDataToFile(strFileName);// 备份图书信息表
	strFileName = strPathName + "ReaderType.bak";
	ret[3] = CopyReaderTypeDataToFile(strFileName);// 备份读者类型表
	strFileName = strPathName + "ReaderInfo.bak";
	ret[4] = CopyReaderDataToFile(strFileName);// 备份读者信息表
	strFileName = strPathName + "PunishType.bak";
	ret[5] = CopyPunishTypeDataToFile(strFileName);// 备份罚款类型表
	strFileName = strPathName + "BorrowInfo.bak";
	ret[6] = CopyBorrowDataToFile(strFileName);// 备份借阅信息表
	return ret[0] && ret[1] && ret[2] && ret[3] && ret[4] && ret[5] && ret[6];
}

BOOL CopyUserDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CUserSet rs ;
    CString strSQL = _T("SELECT * FROM UserInfo");
    if (rs.IsOpen())rs.Close();
    if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
    {
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
        if (nRecordCount > 0)
        {
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.strUserName_;
				ar<<rs.strPassword_;
				ar<<rs.bAdmin_;
				rs.MoveNext();
			}
        }
        rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyBookTypeDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CBookTypeSet rs ;
	CString strSQL = _T("SELECT * FROM BookType");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
		if (nRecordCount > 0)
		{
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.strTypeName_;
				ar<<rs.nNumber_;
				ar<<rs.strRemarks_;
				rs.MoveNext();
			}
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyBookDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CBookSet rs ;
	CString strSQL = _T("SELECT * FROM BookInfo");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
		if (nRecordCount > 0)
		{
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.strBookID_;
				ar<<rs.strBookName_;
				ar<<rs.strBookType_;
				ar<<rs.strAuthor_;
				ar<<rs.strPress_;
				ar<<rs.dPrice_;
				ar<<rs.olePressDT_;
				ar<<rs.oleInDT_;
				ar<<rs.nInNumber_;
				ar<<rs.nOutNumber_;
				ar<<rs.strDescription_;
				rs.MoveNext();
			}
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyReaderTypeDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CReaderTypeSet rs ;
	CString strSQL = _T("SELECT * FROM ReaderType");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
		if (nRecordCount > 0)
		{
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.strTypeName_;
				ar<<rs.nNumber_;
				ar<<rs.dPunishLimit_;
				rs.MoveNext();
			}
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyReaderDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CReaderInfoSet rs ;
	CString strSQL = _T("SELECT * FROM ReaderInfo");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
		if (nRecordCount > 0)
		{
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.m_ReaderID;
				ar<<rs.m_ReaderName;
				ar<<rs.m_Sex;
				ar<<rs.m_Type;
				ar<<rs.m_Dept;
				ar<<rs.m_PhoneNO;
				ar<<rs.m_TelNO;
				ar<<rs.m_Email;
				ar<<rs.m_RegDate;
				ar<<rs.m_Address;
				ar<<rs.m_Punish;
				ar<<rs.m_Description;
				rs.MoveNext();
			}
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyPunishTypeDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CPunishTypeSet rs ;
	CString strSQL = _T("SELECT * FROM PunishType");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
		if (nRecordCount > 0)
		{
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.strTypeName_;
				ar<<rs.dNumber_;
				ar<<rs.strRemarks_;
				rs.MoveNext();
			}
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}
BOOL CopyBorrowDataToFile(CString strFileName)
{
	CFile file(strFileName, CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&file, CArchive::store);
	int nRecordCount = 0;
	CBorrowInfoSet rs ;
	CString strSQL = _T("SELECT * FROM BorrowInfo");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		if (0 != rs.GetRecordCount())
		{
			while(!rs.IsEOF())
			{
				++nRecordCount;
				rs.MoveNext();
			}
			rs.MoveFirst();
		}
		if (nRecordCount > 0)
		{
			ar<<nRecordCount;
			while(!rs.IsEOF())
			{
				ar<<rs.lRecordID_;
				ar<<rs.strReaderID_;
				ar<<rs.strBookID_;
				ar<<rs.oleBorrowDT_;
				ar<<rs.oleReturnDT_;
				ar<<rs.bReturned_;
				ar<<rs.bRenewed_;
				ar<<rs.strOperator_;
				ar<<rs.oleDeadLineDT_;
				rs.MoveNext();
			}
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToDatabase(CString strPathName)
{
	BOOL ret[7];
	CString strFileName;
	strFileName = strPathName + "UserInfo.bak";
	ret[0] = CopyFileToUserData(strFileName);      // 还原用户信息表
	strFileName = strPathName + "BookType.bak";
	ret[1] = CopyFileToBookTypeData(strFileName);  // 还原图书类型表
	strFileName = strPathName + "BookInfo.bak";
	ret[2] = CopyFileToBookData(strFileName);      // 还原图书信息表
	strFileName = strPathName + "ReaderType.bak";
	ret[3] = CopyFileToReaderTypeData(strFileName);// 还原份读者类型表
	strFileName = strPathName + "ReaderInfo.bak";
	ret[4] = CopyFileToReaderData(strFileName);    // 还原读者信息表
	strFileName = strPathName + "PunishType.bak";
	ret[5] = CopyFileToPunishTypeData(strFileName);// 还原罚款类型表
	strFileName = strPathName + "BorrowInfo.bak";
	ret[6] = CopyFileToBorrowData(strFileName);    // 还原借阅信息表
	return ret[0] && ret[1] && ret[2] && ret[3] && ret[4] && ret[5] && ret[6];
}

BOOL CopyFileToUserData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CUserSet rs;
	CString strSQL = _T("SELECT * FROM UserInfo");
    if (rs.IsOpen())rs.Close();
    if(rs.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL))
    {// 数据库表打开成功
		ar>>nRecordCount;        // 读取记录条数
        while (nRecordCount > 0) // 还有记录可读
        {
			rs.AddNew();         // 向数据库中插入记录
			ar>>rs.strUserName_; // 读取用户名
			ar>>rs.strPassword_; // 读取密码
			ar>>rs.bAdmin_;      // 读取管理员标志
			rs.Update();         // 更新数据库
			--nRecordCount;
        }
        rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToBookTypeData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CBookTypeSet rs ;
	CString strSQL = _T("SELECT * FROM BookType");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		ar>>nRecordCount;
		while (nRecordCount > 0)
		{
			rs.AddNew();
			ar>>rs.strTypeName_;
			ar>>rs.nNumber_;
			ar>>rs.strRemarks_;
			rs.Update();
			rs.Requery();
			--nRecordCount;
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToBookData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CBookSet rs ;
	CString strSQL = _T("SELECT * FROM BookInfo");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		ar>>nRecordCount;
		while (nRecordCount > 0)
		{
			rs.AddNew();
			ar>>rs.strBookID_;
			ar>>rs.strBookName_;
			ar>>rs.strBookType_;
			ar>>rs.strAuthor_;
			ar>>rs.strPress_;
			ar>>rs.dPrice_;
			ar>>rs.olePressDT_;
			ar>>rs.oleInDT_;
			ar>>rs.nInNumber_;
			ar>>rs.nOutNumber_;
			ar>>rs.strDescription_;
			rs.Update();
			rs.Requery();
			--nRecordCount;
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToReaderTypeData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CReaderTypeSet rs ;
	CString strSQL = _T("SELECT * FROM ReaderType");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		ar>>nRecordCount;
		while (nRecordCount > 0)
		{
			rs.AddNew();
			ar>>rs.strTypeName_;
			ar>>rs.nNumber_;
			ar>>rs.dPunishLimit_;
			rs.Update();
			rs.Requery();
			--nRecordCount;
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToReaderData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CReaderInfoSet rs ;
	CString strSQL = _T("SELECT * FROM ReaderInfo");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		ar>>nRecordCount;
		while (nRecordCount > 0)
		{
			rs.AddNew();
			ar>>rs.m_ReaderID;
			ar>>rs.m_ReaderName;
			ar>>rs.m_Sex;
			ar>>rs.m_Type;
			ar>>rs.m_Dept;
			ar>>rs.m_PhoneNO;
			ar>>rs.m_TelNO;
			ar>>rs.m_Email;
			ar>>rs.m_RegDate;
			ar>>rs.m_Address;
			ar>>rs.m_Punish;
			ar>>rs.m_Description;
			rs.Update();
			rs.Requery();
			--nRecordCount;
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToPunishTypeData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CPunishTypeSet rs ;
	CString strSQL = _T("SELECT * FROM PunishType");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		ar>>nRecordCount;
		while (nRecordCount > 0)
		{
			rs.AddNew();
			ar>>rs.strTypeName_;
			ar>>rs.dNumber_;
			ar>>rs.strRemarks_;
			rs.Update();
			rs.Requery();
			--nRecordCount;
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

BOOL CopyFileToBorrowData(CString strFileName)
{
	CFile file(strFileName, CFile::modeRead);
	CArchive ar(&file, CArchive::load);
	int nRecordCount = 0;
	CBorrowInfoSet rs ;
	CString strSQL = _T("SELECT * FROM BorrowInfo");
	if (rs.IsOpen())rs.Close();
	if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		ar>>nRecordCount;
		while (nRecordCount > 0)
		{
			rs.AddNew();
			ar>>rs.lRecordID_;
			ar>>rs.strReaderID_;
			ar>>rs.strBookID_;
			ar>>rs.oleBorrowDT_;
			ar>>rs.oleReturnDT_;
			ar>>rs.bReturned_;
			ar>>rs.bRenewed_;
			ar>>rs.strOperator_;
			ar>>rs.oleDeadLineDT_;
			rs.Update();
			rs.Requery();
			--nRecordCount;
		}
		rs.Close();
		return TRUE;
    }
	return FALSE;
}

⌨️ 快捷键说明

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