图书管理系统的C#代码完整版.docx
《图书管理系统的C#代码完整版.docx》由会员分享,可在线阅读,更多相关《图书管理系统的C#代码完整版.docx(25页珍藏版)》请在冰豆网上搜索。
图书管理系统的C#代码完整版
C#代码清单
共1个项目,包含5个类。
项目:
librarysystem
类:
Program.csReaders.csManage.csMenu.csPublications.cs
主类代码:
namespacelibrarysystem
{///
///类名:
Program
///功能:
项目主类
///时间:
2015-11-19
///
classProgram
{
staticvoidMain(string[]args)
{
Menumeu=newMenu();
meu.ShowMainMenu();
Console.ReadLine();
}
}
}
出版物类代码:
namespacelibrarysystem
{///
///类名:
Publications
///功能:
馆藏出版物信息
///时间:
2015-11-19
///
classPublications
{
/*出版物编号*/
privatestringPublicationISBN;
publicstringPublicationIsbn
{
get
{
returnPublicationISBN;
}
set
{
PublicationISBN=value;
}
}
/*出版物名称*/
publicstringPublicationName;
/*出版物作者或出版机构*/
publicstringPublicationAuthor;
/*出版物在架状态*/
publicboolPublicationStatus;
/*出版物类型*/
publicstringPublicationType;
publicPublications()
{
}
publicPublications(stringPublicationISBN,stringPublicationName,stringPublicationAuthor,stringPublicationType,boolPublicationStatus)
{
this.PublicationISBN=PublicationISBN;
this.PublicationName=PublicationName;
this.PublicationAuthor=PublicationAuthor;
this.PublicationType=PublicationType;
this.PublicationStatus=PublicationStatus;
}
}
}
读者类代码:
namespacelibrarysystem
{///
///类名:
Readers
///功能:
已获取权限读者的信息
///时间:
2015-11-19
///
classReaders
{
privatestringReaderID;
publicstringReaderId
{
get
{
returnReaderID;
}
set
{
ReaderID=value;
}
}
publicstringReaderName;
publicstringReaderSex;
publicstringReaderDepartment;
publicstringReaderMajor;
publicstring[]BowPublication=newstring[10]{"","","","","","","","","",""};
publicReaders()
{
}
publicReaders(stringReaderID,stringReaderName,stringReaderSex,stringReaderDepartment,stringReaderMajor)
{
this.ReaderID=ReaderID;
this.ReaderName=ReaderName;
this.ReaderSex=ReaderSex;
this.ReaderDepartment=ReaderDepartment;
this.ReaderMajor=ReaderMajor;
}
}
}
管理类代码:
namespacelibrarysystem
{///
///类名:
Manage
///功能:
管理员执行图书管理操作
///时间:
2015-11-19
///
classManage
{
publicboolBorrowFlag=false;/*借阅操作成功标志*/
publicboolReturnFlag=false;/*归还操作成功标志*/
publicPublicationspub_search;/*保存查询到的出版物*/
publicReadersRed_valid;/*保存查询到的合法用户*/
/*声明馆藏出版物数组*/
publicPublications[]pubs=newPublications[200];
/*声明注册读者数组*/
publicReaders[]reds=newReaders[30];
/*实例化馆藏出版物对象*/
publicPublicationspub0=newPublications("000000","C#从入门到精通","明日科技","书籍",true);
publicPublicationspub1=newPublications("000001","数值分析","清朗","书籍",true);
publicPublicationspub2=newPublications("000002","模式识别","学工","书籍",true);
publicPublicationspub3=newPublications("000003","中国地理","地理科学院","杂志",true);
publicPublicationspub4=newPublications("000004","意林","市文学艺术界联合会","杂志",true);
publicPublicationspub5=newPublications("000005","大学报","大学","报纸",true);
publicPublicationspub6=newPublications("000006","经济学人","伦敦经济学人报纸有限公司","杂志",true);
publicPublicationspub7=newPublications("000007","计算机网络","谢希仁","书籍",true);
publicPublicationspub8=newPublications("000008","红楼梦","曹雪芹","书籍",true);
publicPublicationspub9=newPublications("000009","新东方雅思培训课程","俞敏洪","音像制品",true);
publicPublicationspub10=newPublications("000010","MATLAB实用教程","世杰","音像制品",true);
/*实例化已注册读者对象*/
publicReadersred0=newReaders("20150000","华","男","电子信息学院","电子与通信工程");
publicReadersred1=newReaders("20150001","王鹏","男","物理学院","微电子学");
publicReadersred2=newReaders("20150002","建豪","男","数学学院","现代数学分析");
publicReadersred3=newReaders("20150003","莉","女","化学化工学院","化学分析");
publicReadersred4=newReaders("20150004","吴娜","女","医学院","口腔医学");
publicReadersred5=newReaders("20150005","宋雅茹","女","电子信息学院","光学工程");
/*初始化出版物数组*/
publicvoidPublicationsInitial()
{
pubs[0]=pub0;
pubs[1]=pub1;
pubs[2]=pub2;
pubs[3]=pub3;
pubs[4]=pub4;
pubs[5]=pub5;
pubs[6]=pub6;
pubs[7]=pub7;
pubs[8]=pub8;
pubs[9]=pub9;
pubs[10]=pub10;
}
/*初始化读者数组*/
publicvoidReadersInitial()
{
reds[0]=red0;
reds[1]=red1;
reds[2]=red2;
reds[3]=red3;
reds[4]=red4;
reds[5]=red5;
}
/*查询图书操作*/
publicboolSearchPublications()
{
stringPub_Name;
boolSearchFlag=false;
Pub_Name=Console.ReadLine();
foreach(Publicationspubinpubs)
{
if(pub!
=null&&pub.PublicationName==Pub_Name)
{
SearchFlag=true;
pub_search=pub;
}
}
returnSearchFlag;
}
/*借阅图书操作*/
publicvoidBorrow()
{
stringRed_Name;
stringPub_Name;
boolReaderFlag=false;
Red_Name=Console.ReadLine();
foreach(Readersredinreds)
{
if(red!
=null&&red.ReaderName==Red_Name)
{
ReaderFlag=true;
Red_valid=red;
}
}
if(ReaderFlag)
{
Console.Write("请输入您需要借阅出版物的名称:
");
Pub_Name=Console.ReadLine();
foreach(Publicationspubinpubs)
{
if(pub!
=null&&pub.PublicationName==Pub_Name)
{
BorrowFlag=true;
pub.PublicationStatus=false;
AddToReders(pub.PublicationName,Red_valid);
}
}
}
else
{
Console.WriteLine("抱歉,您是非法读者,不能借阅图书");
}
}
/*归还图书操作*/
publicvoidReturn()
{
stringRed_Name;
stringPub_Name;
boolReaderFlag=false;
Red_Name=Console.ReadLine();
foreach(Readersredinreds)
{
if(red!
=null&&red.ReaderName==Red_Name)
{
ReaderFlag=true;
Red_valid=red;
}
}
if(ReaderFlag)
{
Console.Write("请输入您需要归还出版物的名称:
");
Pub_Name=Console.ReadLine();
foreach(Publicationspubinpubs)
{
if(pub!
=null&&pub.PublicationName==Pub_Name)
{
for(inti=0;i<10;i++)
{
if(Red_valid.BowPublication[i]==Pub_Name)
{
ReturnFlag=true;
pub.PublicationStatus=true;
RemoveFromReders(Pub_Name,Red_valid);
}
}
}
}
}
else
{
Console.WriteLine("抱歉,您是非法读者,无归还图书信息");
}
}
/*添加图书到读者*/
privatevoidAddToReders(stringPublicationName,Readersred)
{
/*设置借阅上限为10本*/
for(inti=0;i<10;i++)
{
if(red!
=null&&red.BowPublication[i]=="")
{
red.BowPublication[i]=PublicationName;
break;
}
}
}
/*从读者对象中移除图书*/
privatevoidRemoveFromReders(stringPublicationName,Readersred)
{
/*设置借阅上限为10本*/
for(inti=0;i<10;i++)
{
if(red!
=null&&red.BowPublication[i]==PublicationName)
{
red.BowPublication[i]=red.BowPublication[i+1];
}
}
}
/*新书入库操作*/
publicvoidAddPublications(Publicationspub)
{
for(inti=11;i<200;i++)
{
if(pubs[i]==null)
{
pubs[i]=pub;
}
}
}
/*添加新读者操作*/
publicvoidAddReaders(Readersred)
{
for(inti=6;i<30;i++)
{
if(reds[i]==null)
{
reds[i]=red;
}
}
}
/*查询读者信息*/
publicvoidRedIndex()
{
stringRed_Name;
boolReaderFlag=false;
Red_Name=Console.ReadLine();
foreach(Readersredinreds)
{
if(red!
=null&&red.ReaderName==Red_Name)
{
ReaderFlag=true;
Red_valid=red;
}
}
if(!
ReaderFlag)
{
Console.WriteLine("抱歉,您是非法读者,无法查到您的借阅信息");
}
}
}
}
菜单类代码:
namespacelibrarysystem
{///
///类名:
Menu
///功能:
显示服务页面
///时间:
2015-11-19
///
classMenu
{
//创建一个具体的管理对象
Managemag=newManage();
//声明一个读者对象
Readersred;
//声明一个出版物对象
Publicationspub;
publicvoidShowMainMenu()
{
mag.PublicationsInitial();
mag.ReadersInitial();
Console.WriteLine("欢迎使用图书管理系统V1.0");
Console.WriteLine("-------------------------------------------------------------------");
Console.WriteLine("1.查询图书");
Console.WriteLine("2.借书服务");
Console.WriteLine("3.还书服务");
Console.WriteLine("4.新出版物入库");
Console.WriteLine("5.录入新读者");
Console.WriteLine("6.查询读者的借阅信息");
Console.WriteLine("7.退出管理系统");
Console.WriteLine("-------------------------------------------------------------------");
boolflag;
do
{
flag=false;
Console.WriteLine("请选择:
");
stringkey=Console.ReadLine();
switch(key)
{
case"1":
Console.Write("请输入需要查询图书的书名:
");
ShowPubInfo();
break;
case"2":
Console.Write("请输入您的姓名:
");
mag.Borrow();
ShowBorrowInfo();
break;
case"3":
Console.Write("请输入您的姓名:
");
mag.Return();
ShowReturnInfo();
break;
case"4":
Console.WriteLine("请按照提示逐步输入需要入库出版物的信息……");
ShowAddPublications();
break;
case"5":
Console.WriteLine("请按照提示逐步输入新注册读者的信息……");
ShowAddReaders();
break;
case"6":
Console.Write("请输入您的姓名:
");
mag.RedIndex();
ShowRedPubInfo(mag.Red_valid);
break;
case"7":
flag=false;
break;
default:
Console.WriteLine("无此业务,是否重新选择(y/n)?
");
stringanswer=Console.ReadLine();
if(answer!
="y")
{
flag=false;
}
else
{
flag=true;
}
break;
}
}while(flag);
}
/*显示查询到的出版物信息*/
publicvoidShowPubInfo()
{
if(mag.SearchPublications())
{
Console.WriteLine("您要查询的出版物信息:
");
Console.WriteLine("-------------------------------------------------------------------");
Console.WriteLine("编号:
"+mag.pub_search.PublicationIsbn);
Console.WriteLine("出版物名字:
"+mag.pub_search.PublicationName);
Console.WriteLine("出版物作者:
"+mag.pub_search.PublicationAuthor);
Console.WriteLine("出版物类型:
"+mag.pub_search.PublicationType);
if(mag.pub_search.PublicationStatus)
{
Console.WriteLine("出版物状态:
在架,可借");
}
else
{
Console.WriteLine("出版物状态:
未在架,不可借");
}
Console.WriteLine("-------------------------------------------------------------------");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("是否办理其他业务(y/n)?
");
stringanswer=Console.ReadLine();
if(answer=="y")
{
ShowMainMenu();
Console.WriteLine();
}
else
{
Console.WriteLine("结束");
}
}
else
{
Console.WriteLine("抱歉,未找到该图书!
");
Console.WriteLine("是否办理其他业务(y/n)?
");
stringanswer=Console.ReadLine();
if(answer=="