图书馆管理系统程序的设计代码
图书馆管理系统源代码
以我给的标题写原创文档,最低1200字,要求以Markdown文本格式输出,不要带图片和AI、人工智能、Markdown、GPT等关键词,标题为:图书馆管理系统源代码# 图书馆管理系统源代码## 一、引言图书馆作为一个重要的知识资源和学术场所,对于学生和研究人员具有重要意义。
为了更好地管理图书馆资源和提供服务,图书馆管理系统应运而生。
本文将介绍图书馆管理系统的源代码设计和实现。
## 二、系统功能需求### 1. 登录功能- 提供管理员和用户登录功能- 管理员可进行图书管理、借阅管理等操作- 用户可查询图书信息、借阅情况等### 2. 图书管理- 添加新书籍信息- 修改或删除现有书籍信息- 查询图书信息,包括书名、作者、出版社等### 3. 借阅管理- 用户借阅图书- 用户归还图书- 管理员监管借阅情况### 4. 查询功能- 用户可以根据条件查询图书信息- 管理员可以查询借阅情况、用户信息等## 三、系统设计### 1. 数据库设计- 数据库包括图书信息表、用户信息表、借阅记录表等- 表之间建立关联,保证数据一致性和完整性### 2. 源代码结构```- books- README.md- book.js- bookRouter.js- users- README.md- user.js- userRouter.js- borrows- README.md- borrow.js- borrowRouter.js- index.js```### 3. 源代码逻辑- 使用Node.js构建后端服务- 使用Express框架处理路由和请求- 使用MongoDB作为数据库存储## 四、系统实现### 1. 登录功能```javascript// 用户登录router.post('/login', (req, res) => {// 处理登录逻辑});// 管理员登录router.post('/admin/login', (req, res) => { // 处理管理员登录逻辑});```### 2. 图书管理```javascript// 添加新书籍router.post('/addBook', (req, res) => {// 处理添加书籍逻辑});// 修改书籍信息router.put('/updateBook/:id', (req, res) => {// 处理修改书籍信息逻辑});// 删除书籍router.delete('/deleteBook/:id', (req, res) => {// 处理删除书籍逻辑});```### 3. 借阅管理```javascript// 用户借阅图书router.post('/borrowBook', (req, res) => {// 处理借阅图书逻辑});// 用户归还图书router.put('/returnBook/:id', (req, res) => {// 处理归还图书逻辑});```## 五、总结通过本文介绍,读者可以了解图书馆管理系统源代码的设计和实现逻辑。
C语言课程设计图书馆管理系统程序代码
#include〈stdio.h〉#include<windows.h〉#include〈string。
h〉#include<conio。
h>#define M 100struct books{char tsmc[12];inttsbh;float dj;char zz[12];char czzt[12];char xm[12];char xb[12];intxh; }s[M];int N;bool flag;intmain (){intsele;flag=0;sele=1;void sr();void cx();void sc();void js();void hs();void tc();void jsh();//system ("tsgl”);printf("\n\n");printf(" ************************\n"); printf(" 1:输入2:查询3:删除\n");printf(”4:借书5:还书0:退出\n");printf(” ************************\n"); while(1){printf(”\n\n请输入功能序号:");scanf (”%d",&sele);if(sele>=0 && sele<=5){switch(sele){case 1:sr();break;case 2:cx();break;case 3:sc();break;case 4:js();break;case 5:hs();break;case 0:jsh();break;}if(flag)break;printf(”\n\n");printf(” ************************\n”); printf(" 1:输入2:查询3:删除\n");printf(”4:借书5:还书0:退出\n”);printf(” ************************\n”);}else{printf(”输入错误请再次输入|\n\n");printf("\n\n");printf(” ************************\n”);printf(" 1:输入2:查询3:删除\n”);printf(”4:借书5:还书0:退出\n");printf(" ************************\n");}printf("\n\n让任意键继续\n”);} //wr_file();}/******主函数***//*********输入*********/void sr(){intn,i;N=0;printf("可输入的书本数:");scanf("%d",&n);N=n+N;printf("请输入相关信息:\n");for(i=1;i<=n;i++){printf(”图书名称:”);scanf(”%s",s[N-n-1+i]。
原创c语言图书馆管理系统源代码
原创C语言图书馆管理系统源代码介绍图书馆作为一个重要的知识储备和学习场所,必须进行有效的管理和组织。
使用C语言编写的图书馆管理系统可以帮助图书馆实现自动化的借阅、归还和管理功能。
本文将介绍一个原创的C语言图书馆管理系统的源代码。
功能概述这个图书馆管理系统具有以下核心功能: - 图书管理:包括添加图书、删除图书、查询图书等操作。
- 借阅管理:可以进行借阅操作,记录借阅者和借阅时间。
- 归还管理:可以进行归还操作,并更新图书的可借状态。
- 用户管理:管理借阅者的信息,包括添加用户、删除用户、查询用户等操作。
数据结构设计该图书馆管理系统使用了以下几种数据结构: 1. 图书(Book)结构体:包含图书的ID、书名、作者、可借状态等字段。
2. 用户(User)结构体:包含用户的ID、姓名、地址等字段。
3. 借阅记录(BorrowRecord)结构体:包含借阅者ID、图书ID、借阅时间等字段。
系统流程整个系统的流程可以分为以下几个步骤: 1. 用户打开系统,进入主菜单。
2. 用户选择不同的功能选项(如图书管理、借阅管理、用户管理等)。
3. 根据用户选择的功能,进入相应的功能界面。
4. 用户可以根据提示,输入相应的信息进行图书管理、借阅管理或用户管理操作。
5. 用户完成操作后,可以选择返回主菜单或退出系统。
代码实现以下是一个简化版的C语言图书馆管理系统的源代码:```c #include <stdio.h>// 定义结构体 struct Book { int id; char name[50]; char author[50]; int isAvailable; };struct User { int id; char name[50]; char address[100]; };struct BorrowRecord { int userId; int bookId; char borrowDate[20]; };// 函数声明 void addBook(); void deleteBook(); void searchBook(); void borrowBook(); void returnBook(); void addUser(); void deleteUser(); void searchUser();int main() { int choice;do {// 显示主菜单printf(\。
图书管理系统毕业设计源代码
图书管理系统毕业设计源代码1. 简介图书管理系统是一个用于管理图书馆藏书及借阅情况的软件系统。
本文档将详细介绍图书管理系统的毕业设计源代码。
2. 源代码结构图书管理系统的源代码采用模块化的设计,分为以下几个模块: - 用户管理模块:负责管理员和读者的管理,包括用户注册、登录、修改密码等功能。
- 图书管理模块:负责图书的录入、删除、查找等功能。
- 借阅管理模块:负责借阅记录的管理,包括借书、还书、查看借阅历史等功能。
- 统计分析模块:负责统计图书馆的借阅情况、读者喜好等信息。
- 权限管理模块:负责管理不同角色的权限,例如管理员有更高的权限。
3. 技术选型•后端开发语言:采用Java语言进行开发,利用Java的面向对象和多线程的特性来实现系统的各个功能模块。
•前端开发:采用HTML、CSS和JavaScript进行前端开发,使用Bootstrap框架来实现页面的美化和响应式布局。
•数据库:采用MySQL关系数据库管理系统,存储图书馆的图书信息、用户信息及借阅记录等数据。
4. 代码实现细节4.1 用户管理模块用户管理模块的主要功能包括用户注册、登录、修改密码等。
- 用户注册:用户可以填写注册表单,并将信息提交到服务器进行注册。
服务器会将用户的信息存储到数据库中,并为用户分配一个唯一的ID。
- 用户登录:用户在登录页面输入用户名和密码,服务器会校验用户的登录信息,并根据用户的角色跳转到相应的首页。
- 修改密码:用户可以在个人信息页面修改密码,需要输入原密码和新密码。
4.2 图书管理模块图书管理模块的主要功能包括图书的录入、删除、查找等。
- 图书录入:管理员可以在后台管理页面输入图书的信息,包括书名、作者、出版社、ISBN等,并提交保存到数据库中。
- 图书删除:管理员可以根据图书的ID或其他关键字进行图书的删除操作,同时删除数据库中的对应记录。
- 图书查找:管理员和读者可以根据图书的关键字进行查找,系统会显示匹配的图书列表。
图书信息管理系统设计源代码
头函数名:#include<stdio.h>#include<stdlib.h>#include<string.h>/*********图书信息结构体*********//***包括登录号,书名,作者名,分类号,出版单位,出版时间,价格等***/ struct bookinf{ int num; ******************************************************登录号char bname[20];***************************************书名char wname[10];***************************************作者名char clanum[14];***************************************分类号char pubcom[10];***************************************出版单位char pubtime[10];***************************************出版时间float price;*********************************************价格};一管理员登录系统模块:(1)来到图书信息管理系统页面void index(){char input; 注释:运行时printf("\n\n\t\t\t*****************************\n"); 直接进入printf("\t\t\t 图书信息管理系统\n"); 这个页面printf("\t\t\t*****************************\n\n\n");printf(" ------------------------------------------------------------------------------\n");printf("\t<按任意键进入>\n\t");input=getchar();}(2)管理员登陆进入功能菜单页面FILE *fp;struct manage pswd;if ((fp=fopen("password.txt","r"))==NULL) {printf("\n\n\n\tCannot open file!\n\t");}else{do{printf("\n\n\t请输入管理员帐号:");scanf("%s",name);printf("\n\n\t请输入管理员密码:");scanf("%s",password);fp=fopen("password.txt","r");fread(&pswd,sizeof(struct manage),1,fp);fclose(fp);w=strcmp(pswd.manage_name,name);k=strcmp(pswd.password,password);adm_servelist();}while (w!=0||k!=0);adm_servelist();}}(3)来到功能菜单页面{void book_add();void book_view();void change();void del();void book_search();void login();void pwchange();int in; 注释:菜单列出的服务种类char input; 从1,2,3,4,5,6 do 所对应的功能进行选择{printf("\n\n\n\t--欢迎使用信息管理系统--");printf("\n\n\t1.图书信息录入\n");printf("\t2.图书信息浏览\n");printf("\t3.图书信息查询\n");printf("\t4.图书信息删除\n");printf("\t5.图书信息修改\n");printf("\t6.退出管理模式\n");printf("\n\t请选择服务种类:");scanf("%d",&in);if (in!=1&&in!=2&&in!=3&&in!=4&&in!=5&&in!=6){printf("\n\t没有这项服务~\n");printf("\t按任意键重新选择");input=getchar();}}while (in!=1&&in!=2&&in!=3&&in!=4&&in!=5&&in!=6);switch (in){case 1: book_add(); break; 注释:选择自己所需要case 2: book_view(); break; 后摁下数字键则case 3: book_search(); break; 则进入此功能页面case 4: del(); break;case 5: change();break;case 6: login(); break;}}(3)图书信息录入功能模块void book_add(){void book_add();int i=0,j;FILE *fp;char input; 注释:输入的图书信息struct bookinf books; 是通过文件进行struct bookinf book_taxis[30]; 保存的printf("\n\n\n\t---请输入图书信息---\n\n");printf("\t登录号:");scanf("%d",&books.num);printf("\n\t书名:");scanf("%s",books.bname);printf("\n\t作者名:");scanf("%s",books.wname);printf("\n\t分类号:");scanf("%s",books.clanum);printf("\n\t出版单位:");scanf("%s",books.pubcom);printf("\n\t出版时间:");scanf("%s",books.pubtime);printf("\n\t价格:");scanf("%f",&books.price);if ((fp=fopen("book.txt","r"))!=NULL){do{fread(&book_taxis[i],sizeof(struct bookinf),1,fp);i=i+1;}while(!feof(fp));fclose(fp);for (j=0;j<=i;j++)if (books.num==book_taxis[j].num){printf("\n\n\n\t对不起,这个编号已经使用过了~\n");printf("\t按任意键返回管理菜单~");input=getchar();adm_servelist();break;}}if ((fp=fopen("book.txt","r"))==NULL){fp=fopen("book.txt","w");}else{fclose(fp);fp=fopen("book.txt","a");}fwrite(&books,sizeof(struct bookinf),1,fp);fclose(fp);printf("\n\n\n\t信息输入完毕~按任意键继续\n");input=getchar();adm_servelist();}(4)图书信息浏览功能模块void book_view(){void adm_servelist();void book_view();int inp,i=0,n=0;FILE *fp;char input;struct bookinf bookview[20];if ((fp=fopen("book.txt","r"))==NULL){printf("\n\n\n\t数据尚未初始化~~\n\n\t请在管理菜单中增加图书信息~~~\n"); printf("\n\t<按任意键返回管理菜单>\n\t");input=getchar();adm_servelist();}else{do{fread(&bookview[i],sizeof(struct bookinf),1,fp);i=i+1;}while (!feof(fp));fclose(fp);do{printf("\n\t--------共有%d条记录--------",i-1);printf("\n\n\t登录号: %d\n",bookview[n].num);printf("\n\t书名: %s\n",bookview[n].bname);printf("\n\t作者名: %s\n",bookview[n].wname);printf("\n\t分类号: %s\n",bookview[n].clanum);printf("\n\t出版单位: %s\n",bookview[n].pubcom);printf("\n\t出版时间: %s\n",bookview[n].pubtime);printf("\n\t价格: %f\n",bookview[n].price);printf("\n\n\t1.上一页\t2.下一页\t3.回目录\n");printf("\n\t请选择:");scanf("%d",&inp);switch (inp){case 1:{if (n==0){printf("\n\t已到达首页\n\t按任意键重新选择");input=getchar();}else n=n-1; break;}case 2:{if (n==i-2){printf("\n\t已到达最末页\n\t按任意键重新选择");input=getchar();}else n=n+1; break;}case 3:{adm_servelist();break;}default:{printf("\n\t没有这项服务\n\t按任意键重新选择");input=getchar();}}}while (inp!=3);}}(5)图书信息修改与删除功能模块修改:void change(int x){int inp,i=0,j;void book_search();FILE *fp,*fp1;char input;struct bookinf books,book_taxis[20];do{printf("\n\n\n\t注意:您确定要修改该记录吗?\n"); printf("\n\t1.是\t2.否\n");printf("\n\t请输入:");scanf("%d",&inp);if (inp!=1&&inp!=2){printf("\n\t对不起~没有这项服务~\n");printf("\t按任意键重新选择\n\t");input=getchar();}}while (inp!=1&&inp!=2);if (inp==2)book_search();if (inp==1){printf("\n\n\n\t---请输入图书信息---\n\n");printf("\t登录号:");scanf("%d",&books.num);printf("\n\t书名:");scanf("%s",books.bname);printf("\n\t作者名:");scanf("%s",books.wname);printf("\n\t分类号:");scanf("%s",books.clanum);printf("\n\t出版单位:");scanf("%s",books.pubcom);printf("\n\t出版时间:");scanf("%s",books.pubtime);printf("\n\t价格:");scanf("%f",&books.price);if ((fp1=fopen("book.txt","r"))!=NULL){do{fread(&book_taxis[i],sizeof(struct bookinf),1,fp1);i=i+1;}while(!feof(fp1));fclose(fp1);for (j=0;j<x;j++)if (books.num==book_taxis[j].num){printf("\n\n\n\t对不起,这个编号已经使用过了~\n");printf("\t按任意键返回管理菜单~");printf("0");input=getchar();book_search();break;}for (j=x+1;j<i-2;j++)if (books.num==book_taxis[j].num){printf("\n\n\n\t对不起,这个编号已经使用过了~\n");printf("1");printf("\t按任意键返回管理菜单~");input=getchar();book_search();break;}}book_taxis[x]=books;fp=fopen("book.txt","w");for (j=0;j<i-1;j++)fwrite(&book_taxis[j],sizeof(struct bookinf),1,fp);fclose(fp);printf("\n\n\t信息修改完成!按任意键返回");input=getchar();book_search();}}S删除:void del(int y){char input;FILE *fp;int inp,i=0,j;struct bookinf book_taxis[20];void book_search();void adm_servelist();do{printf("\n\n\n\t注意:您确定要删除该记录吗?\n"); printf("\n\t1.是\t2.否\n");printf("\n\t请输入:");scanf("%d",&inp);if (inp!=1&&inp!=2){printf("\n\t对不起~没有这项服务~\n");printf("\t按任意键重新选择\n\t");input=getchar();}}while (inp!=1&&inp!=2);if (inp==2)book_search();if (inp==1){if ((fp=fopen("book.txt","r"))!=NULL){do{fread(&book_taxis[i],sizeof(struct bookinf),1,fp);i=i+1;}while(!feof(fp));fclose(fp);}if (i>2){fp=fopen("book.txt","w");for (j=0;j<y;j++)fwrite(&book_taxis[j],sizeof(struct bookinf),1,fp);fclose(fp);fp=fopen("book.txt","a");for (j=y+1;j<i-1;j++)fwrite(&book_taxis[j],sizeof(struct bookinf),1,fp);fclose(fp);}else{remove("book.txt");}printf("\n\n\t记录已删除!\n\n\t按任意键返回\n\t");input=getchar();adm_servelist();}}(6)图书信息查询功能模块void book_search(){void adm_servelist();void id_search();void wr_search();void bn_search();char input;FILE *fp;int inp;if ((fp=fopen("book.txt","r"))==NULL){printf("\n\n\n\t数据尚未初始化~~\n\n\t请在管理菜单中增加图书信息~~~\n"); printf("\n\t<按任意键返回管理菜单>\n\t");input=getchar();adm_servelist();}else{do{printf("\n\n\n\t1.按图书登录号查询\n");printf("\n\t2.按图书作者查询\n");printf("\n\t3.按图书名查询\n");printf("\n\t4.回到主菜单\n");printf("\n\n\t请选择查询类别:");scanf("%d",&inp);if (inp!=1&&inp!=2&&inp!=3&&inp!=4){printf("\n\n\t没有这项服务~\n\t按任意键重新选择~");input=getchar();}}while (inp!=1&&inp!=2&&inp!=3&&inp!=4);fclose(fp);switch (inp){case 1: id_search(); break;case 2: wr_search(); break;case 3: bn_search(); break;case 4: adm_servelist(); break;}}}。
图书管理系统程序源代码
源程序1.主窗体Private Sub add_back_Click() frmbackbookinfo.ShowEnd SubPrivate Sub add_binf_Click() frmaddbookinfo.ShowEnd SubPrivate Sub add_book_style_Click() frmaddbookstyle.ShowEnd SubPrivate Sub add_manager_Click() frmadduser.ShowEnd SubPrivate Sub add_rinf_Click() frmaddreaderinfo.ShowEnd SubPrivate Sub add_rstyle_Click() frmaddreaderstyle.ShowEnd SubPrivate Sub change_binf_Click() frmmodifybookinfo.ShowEnd SubPrivate Sub change_book_style_Click() frmmodifybookstyle.ShowEnd SubPrivate Sub delete_binf_Click() frmmodifybookinfo.ShowEnd SubPrivate Sub delete_book_style_Click() frmmodifybookstyle.ShowEnd SubPrivate Sub delete_rstyle_Click() frmmodifyreaderstyle.ShowEnd SubPrivate Sub exit_Click()EndEnd SubPrivate Sub find_binf_Click() frmfindbook.ShowEnd SubPrivate Sub find_lend_Click() frmfindborrowinfo.ShowEnd SubPrivate Sub find_rinf_Click()frmfindreader.ShowEnd SubPrivate Sub password_Click()frmchangepwd.ShowEnd Sub2.LoginOption ExplicitPrivate Sub cmdOK_Click()Dim strUserName As StringDim strPassword As StringDim strTargetAsp As StringDim conn As ADODB.ConnectionDim rsLogin As ADODB.RecordsetDim strSQL As StringIf Trim(txtUserName.Text) = "" ThenMsgBox "“用户名”不能为空!"Exit SubElsestrUserName = Trim(txtUserName.Text)End IfIf Trim(txtPassword.Text) = "" ThenMsgBox "“口令”不能为空!"Exit SubElsestrPassword = Trim(txtPassword.Text)End If'检查口令、用户身份Set conn = New ADODB.Connectionconn.Provider = "Microsoft.jet.OLEDB.4.0"conn.ConnectionString = "D:\图书管理系统\book.mdb"conn.OpenstrUserName = Replace(strUserName, "'", "“")strSQL = "select*from 系统管理where 用户名='" & strUserName & "'and 密码='" & strPassword & "'"Set rsLogin = conn.Execute(strSQL)If rsLogin.EOF Or rsLogin.BOF ThenMsgBox "用户名或口令错误,请检查!"txtPassword.SelStart = 0txtPassword.SelLength = Len(txtPassword.Text)txtPassword.SetFocusElseSelect Case rsLogin("权限")Case "领导"strTargetAsp = "LeadersMain.asp"Case "主任"strTargetAsp = "ZhuRenMain.asp"Case "秘书"strTargetAsp = "MishuMain.asp"Case "图书管理员"strTargetAsp = "TuShuManagerMain.asp"Case ElsestrTargetAsp = "OtherMain.asp"End SelectSaveSetting "JGYOA", "Login", "UserName", strUserNameHyperlink.NavigateTo "HTTP://" & "/oa/" & strTargetAspEnd If'释放变量Set rsLogin = NothingSet conn = NothingEnd Sub3.frmaddbookinfoPrivate Sub Command1_Click()Dim rs_addbook As New ADODB.RecordsetDim sql As StringIf Trim(Combo1.Text) = " " ThenMsgBox "请选择图书种类", vbOKOnly + vbExclamation, ""Combo1.SetFocusExit SubEnd IfIf Trim(Text1.Text) = " " ThenMsgBox "图书编号不能为空", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = " " ThenMsgBox "书名不能为空", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd IfIf Not IsDate(Text5.Text) ThenMsgBox "请按照yyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""Text5.SetFocusExit SubEnd IfIf Not IsDate(Text6.Text) ThenMsgBox "请按照yyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""Text6.SetFocusExit SubEnd Ifsql = "select * from 书籍信息where 书籍编号='" & Text1.Text & "'" rs_addbook.Open sql, conn, adOpenKeyset, adLockPessimisticIf rs_addbook.EOF Thenrs_addbook.AddNewrs_addbook.Fields(0) = Trim(Text1.Text)rs_addbook.Fields(1) = Trim(Text2.Text)rs_addbook.Fields(2) = Trim(Combo1.Text)rs_addbook.Fields(3) = Trim(Text3.Text)rs_addbook.Fields(4) = Trim(Text4.Text)rs_addbook.Fields(5) = Trim(Text5.Text)rs_addbook.Fields(6) = Trim(Text6.Text)rs_addbook.Fields(7) = "否"rs_addbook.UpdateMsgBox "添加图书信息成功!", vbOKOnly, ""rs_addbook.CloseElseMsgBox "图书编号重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""rs_addbook.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_leibie As New ADODB.RecordsetDim sql As Stringsql = "select * from 图书类别"rs_leibie.Open sql, conn, adOpenKeyset, adLockPessimisticrs_leibie.MoveFirstDo While Not rs_leibie.EOFCombo1.AddItem rs_leibie.Fields(0)rs_leibie.MoveNextLooprs_leibie.CloseEnd Sub4.frmaddbookstylePrivate Sub Command1_Click()Dim rs_bookstyle As New ADODB.RecordsetDim sql As StringIf Trim(Text1.Text) = "" ThenMsgBox "图书种类不能为空", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = "" ThenMsgBox "种类编号不能为空", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd Ifsql = " select * from 图书类别where 类别名称='" & Text1.Text & "'" rs_bookstyle.Open sql, conn, adOpenKeyset, adLockOptimisticIf rs_bookstyle.EOF Thenrs_bookstyle.AddNewrs_bookstyle.Fields(0) = Trim(Text1.Text)rs_bookstyle.Fields(1) = Trim(Text2.Text)rs_bookstyle.UpdateMsgBox "添加图书类别成功!", vbOKOnly, ""rs_bookstyle.CloseElseMsgBox "读者类别重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = " "rs_bookstyle.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub5.frmaddreaderinfoOption ExplicitDim rs_addreader As New ADODB.RecordsetPrivate Sub Command1_Click()Dim sql As StringIf Trim(Combo1.Text) = "" ThenMsgBox "请选择读者种类", vbOKOnly + vbExclamation, ""Combo1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = "" ThenMsgBox "读者姓名不能为空", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text3.Text) = "" ThenMsgBox "读者编号不能为空", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd Ifsql = "select * from 读者信息where 读者编号='" & Text2.Text & "'" rs_addreader.Open sql, conn, adOpenKeyset, adLockPessimisticIf rs_addreader.EOF Thenrs_addreader.AddNewrs_addreader.Fields(0) = Trim(Text2.Text)rs_addreader.Fields(1) = Trim(Text3.Text)rs_addreader.Fields(2) = Trim(Combo2.Text)rs_addreader.Fields(3) = Trim(Combo1.Text)rs_addreader.Fields(4) = Trim(Text5.Text)rs_addreader.Fields(5) = Trim(Text6.Text)rs_addreader.Fields(6) = Trim(Text4.Text)rs_addreader.Fields(7) = CDate(Text1.Text)rs_addreader.UpdateMsgBox "添加读者信息成功!", vbOKOnly, ""rs_addreader.CloseElseMsgBox "读者编号重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""rs_addreader.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Combo2.AddItem "男"Combo2.AddItem "女"Dim rs_leibie As New ADODB.RecordsetDim sql As Stringsql = "select * from 读者类别"rs_leibie.Open sql, conn, adOpenKeyset, adLockPessimisticrs_leibie.MoveFirstDo While Not rs_leibie.EOFCombo1.AddItem rs_leibie.Fields(0)rs_leibie.MoveNextLooprs_leibie.CloseEnd Sub6.frmaddreaderstyleOption ExplicitDim rs_readerstyle As New ADODB.RecordsetPrivate Sub Command1_Click()Dim sql As StringIf Trim(Text1.Text) = "" ThenMsgBox "读者种类不能为空!", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = "" ThenMsgBox "借书数量不能为空!", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd IfIf Trim(Text3.Text) = "" ThenMsgBox "借书期限不能为空!", vbOKOnly + vbExclamation, ""Text3.SetFocusExit SubEnd IfIf Trim(Text4.Text) = "" ThenMsgBox "有限期限不能为空!", vbOKOnly + vbExclamation, ""Text4.SetFocusExit SubEnd Ifsql = "select*from 读者类别where 种类名称='" & Text1.Text & "'" rs_readerstyle.Open sql, conn, adOpenKeyset, adLockPessimisticIf rs_readerstyle.EOF Thenrs_readerstyle.AddNewrs_readerstyle.Fields(0) = Trim(Text1.Text)rs_readerstyle.Fields(1) = Trim(Text2.Text)rs_readerstyle.Fields(2) = Trim(Text3.Text)rs_readerstyle.Fields(3) = Trim(Text4.Text)rs_readerstyle.UpdateMsgBox "添加读者类别成功!", vbOKOnly, ""rs_readerstyle.CloseElseMsgBox "读者类别重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""rs_readerstyle.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub7.frmadduserPrivate Sub Command1_Click()Dim sql As StringDim rs_add As New ADODB.RecordsetIf Trim(Text1.Text) = "" ThenMsgBox "用户名不能为空", vbOKOnly + vbExclamation, ""Exit SubText1.SetFocusElsesql = "select * from 系统管理"rs_add.Open sql, conn, adOpenKeyset, adLockPessimisticWhile (rs_add.EOF = False)If Trim(rs_add.Fields(0)) = Trim(Text1.Text) ThenMsgBox "已有这个用户", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""Text2.Text = ""Text3.Text = ""Combo1.Text = ""Exit SubElsers_add.MoveNextEnd IfWendIf Trim(Text2.Text) <> Trim(Text3.Text) ThenMsgBox "两次密码不一致", vbOKOnly + vbExclamation, ""Text2.SetFocusText2.Text = ""Text3.Text = ""Exit SubElseIf Trim(Combo1.Text) <> "system" And Trim(Combo1.Text) <> "guest" Then MsgBox "请选择正确的用户权限", vbOKOnly + vbExclamation, ""Combo1.SetFocusCombo1.Text = ""Exit SubElsers_add.AddNewrs_add.Fields(0) = Text1.Textrs_add.Fields(1) = Text2.Textrs_add.Updaters_add.CloseMsgBox "添加用户成功", vbOKOnly + vbExclamation, ""Unload MeEnd IfEnd IfEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Combo1.AddItem "system"Combo1.AddItem "guest"End Sub8.frmbackbookinfoPrivate Sub Combo1_Click()Combo2.ListIndex = Combo1.ListIndexEnd SubPrivate Sub Combo2_Click()Combo1.ListIndex = Combo2.ListIndexEnd SubPrivate Sub Combo3_Click()Combo4.ListIndex = Combo3.ListIndexEnd SubPrivate Sub Combo4_Click()Combo3.ListIndex = Combo4.ListIndexEnd SubPrivate Sub Command1_Click()Dim book_num As StringDim reader_num As StringDim answer As StringDim rs_back As New ADODB.RecordsetDim sql As StringOn Error GoTo delerrorbook_num = DataGrid1.Columns(3).CellV alue(DataGrid1.Bookmark) reader_num = DataGrid1.Columns(1).CellV alue(DataGrid1.Bookmark) answer = MsgBox("确定要还这本书吗?", vbY esNo, "")If answer = vbY es Thensql = "select * from 借阅信息where 书籍编号='" & book_num & "'"rs_back.CursorLocation = adUseClientrs_back.Open sql, conn, adOpenKeyset, adLockPessimisticrs_back.Deleters_back.Updaters_back.Closesql = "select * from 书籍信息where 书籍编号='" & book_num & "'"rs_back.CursorLocation = adUseClientrs_back.Open sql, conn, adOpenKeyset, adLockPessimisticrs_back.Fields(7) = "否"rs_back.Updaters_back.Closesql = "select * from 读者信息where 读者编号='" & reader_num & "'"rs_back.CursorLocation = adUseClientrs_back.Open sql, conn, adOpenKeyset, adLockPessimisticrs_back.Fields(8) = rs_back.Fields(8) - 1rs_back.Updaters_back.CloseIf findform = True ThenCommand1_ClickElseCommand2_ClickEnd IfMsgBox "成功删除!", vbOKOnly + vbExclamation, ""DataGrid1.AllowDelete = FalseElseExit SubEnd Ifdelerror:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Command3_Click()Dim rs_reader As New ADODB.RecordsetDim sql As Stringfindform = Turesql = "select*from 借阅信息where 读者姓名='" & Combo2.Text & "'" rs_reader.CursorLocation = adUseClientrs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticSet DataGrid1.DataSource = rs_readerDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseEnd SubPrivate Sub Command4_Click()Dim rs_book As New ADODB.RecordsetDim sql As Stringfindform = Falsesql = "select * from 借阅信息where 书籍编号='" & Combo3.Text & "'" rs_book.CursorLocation = adUseClientrs_book.Open sql, conn, adOpenKeyset, adLockPessimisticSet DataGrid1.DataSource = rs_bookDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseEnd SubPrivate Sub Form_Load()Dim rs_reader As New ADODB.RecordsetDim rs_book As New ADODB.RecordsetDim sql As Stringsql = "select * from 读者信息"rs_reader.CursorLocation = adUseClientrs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_reader.EOF ThenDo While Not rs_reader.EOFCombo1.AddItem rs_reader.Fields(1)Combo2.AddItem rs_reader.Fields(0)rs_reader.MoveNextLoopEnd Ifrs_reader.Closesql = "select * from 借阅信息"rs_book.CursorLocation = adUseClientrs_book.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_book.EOF ThenDo While Not rs_book.EOFCombo3.AddItem rs_book.Fields(3)Combo4.AddItem rs_book.Fields(4)rs_book.MoveNextLoopEnd Ifrs_book.CloseEnd Sub9.frmborrowbookOption ExplicitDim leibie As StringDim qixian As IntegerDim shumu As IntegerDim maxnum As IntegerPrivate Sub Combo1_Change()Combo2.ListIndex = Combo1.ListIndexEnd SubPrivate Sub Combo2_Change()Combo1.ListIndex = Combo2.ListIndexEnd SubPrivate Sub Command1_Click()Dim rs_borrowbook As New ADODB.RecordsetDim sql As Stringsql = "select * from读者信息where读者编号='" & Combo1.Text & "" rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticleibie = rs_borrowbook.Fields(3)shumu = rs_borrowbook.Fields(8)rs_borrowbook.Closesql = "select * from读者类别where种类名称='" & leibie & ""rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimistic qixian = rs_borrowbook.Fields(2)maxnum = rs_borrowbook.Fields(1)rs_borrowbook.CloseIf shumu >= maxnum ThenMsgBox "该读者借书数额已满!", vbOKOnly + vbExclamation Exit SubEnd Ifsql = "select * from借阅信息"rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticrs_borrowbook.AddNewrs_borrowbook.Fields(1) = Combo1.Textrs_borrowbook.Fields(2) = Combo2.Textrs_borrowbook.Fields(3) = Label8.Captionrs_borrowbook.Fields(4) = Label9.Captionrs_borrowbook.Fields(5) = Daters_borrowbook.Fields(6) = DateAdd("Ww", qixian, Date)rs_borrowbook.Updaters_borrowbook.Closesql = "select * from书籍信息where书籍编号='" & book_num & ""rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticrs_borrowbook.Fields(7) = "是"rs_borrowbook.Updaters_borrowbook.Closesql = "select * from读者信息where读者编号='" & Combo1.Text & "" rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticrs_borrowbook.Fields(8) = rs_borrowbook.Fields(8) + 1rs_borrowbook.Updaters_borrowbook.CloseMsgBox "本书借阅成功!", vbOKOnly + vbExclamationUnload MeEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_borrow As New ADODB.RecordsetDim rs_reader As New ADODB.RecordsetDim sql As Stringsql = "select * from 书籍信息where 书籍编号= '" & book_num & "'" rs_borrow.Open sql, conn, adOpenKeyset, adLockPessimisticLabel8.Caption = rs_borrow.Fields(0)Label9.Caption = rs_borrow.Fields(1)Label10.Caption = rs_borrow.Fields(2)Label11.Caption = rs_borrow.Fields(3)Label12.Caption = rs_borrow.Fields(4)Label13.Caption = rs_borrow.Fields(5)Label14.Caption = rs_borrow.Fields(6)sql = "select * from 读者信息"rs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_reader.EOF ThenDo While Not rs_reader.EOFCombo1.AddItem rs_reader.Fields(1)Combo2.AddItem rs_reader.Fields(0)rs_reader.MoveNextLoopElseMsgBox "请先登记读者", vbOKOnly + vbExclamationExit SubEnd Ifrs_borrow.Closers_reader.CloseEnd Sub10.frmchangepwdPrivate Sub Command1_Click()Dim rs_chang As New ADODB.RecordsetDim sql As StringIf Trim(Text1.Text) <> Trim(Text2.Text) ThenMsgBox "密码不一致", vbOKOnly + vbExclamation, ""Text2.SetFocusText1.Text = ""Text2.Text = ""Elsesql = "select*from 系统管理where 用户名='" & userID & "'"rs_chang.Open sql, conn, adOpenKeyset, adLockPessimisticrs_chang.Fields(1) = Text1.Textrs_chang.Updaters_chang.CloseMsgBox "密码修改成功", vbOKOnly + vbExclamation, ""Unload MeEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub11.frmfindbookOption ExplicitDim panduan As StringPrivate Sub Command1_Click()Dim rs_findbook As New ADODB.RecordsetDim sql As StringIf Check1.V alue = vbChecked Thensql = "书名='" & Trim(Text1.Text & "") & "'"End IfIf Check2.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "类别='" & Trim(Combo1.Text & "") & "'"Elsesql = sql & "and 书名='" & Trim(Combo1.Text & "") & "'"End IfEnd IfIf Check3.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "作者='" & Trim(Text2.Text & "") & "'"Elsesql = sql & "and 作者='" & Trim(Text2.Text & "") & "'"End IfEnd IfIf Check4.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "出版社='" & Trim(Text3.Text & "") & "'"Elsesql = sql & "and 出版社='" & Trim(Text3.Text & "") & "'"End IfEnd IfIf Check5.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "书籍编号='" & Trim(Text4.Text & "") & "'"Elsesql = sql & "and 书籍编号='" & Trim(Text4.Text & "") & "'"End IfEnd IfIf Trim(sql) = "" ThenMsgBox "请选择查询方式!", vbOKOnly + vbExclamationExit SubEnd Ifsql = "select * from 书籍信息where " & sqlrs_findbook.CursorLocation = adUseClientrs_findbook.Open sql, conn, adOpenKeyset, adLockPessimisticDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseSet DataGrid1.DataSource = rs_findbookEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Command3_Click()If Trim(book_num) = "" ThenMsgBox "请选择要借阅的图书!", vbOKOnly + vbExclamationExit SubEnd IfIf panduan = "是" ThenMsgBox "此书已被借出!", vbOKOnly + vbExclamationExit SubEnd Iffrmborrowbook.ShowEnd SubPrivate Sub DataGrid1_RowColChange(LastRow As V ariant, ByV al LastCol As Integer) book_num = DataGrid1.Columns(0).CellV alue(DataGrid1.Bookmark)panduan = DataGrid1.Columns(7).CellV alue(DataGrid1.Bookmark)End SubPrivate Sub Form_Load()Dim rs_find As New ADODB.RecordsetDim sql As Stringsql = "select * from 图书类别"rs_find.Open sql, conn, adOpenKeyset, adLockPessimisticrs_find.MoveFirstIf Not rs_find.EOF ThenDo While Not rs_find.EOFCombo1.AddItem rs_find.Fields(0)rs_find.MoveNextLoopCombo1.ListIndex = 0End Ifrs_find.CloseEnd Sub12.frmfindborrowinfoPrivate Sub Command1_Click()Dim sql As StringDim rs_find As New ADODB.RecordsetIf Option1.V alue = True Thensql = "select * from 书籍信息where 是否被借出='是'"End IfIf Option2.V alue = True Thensql = "select * from 书籍信息where 是否被借出='否'"End IfIf Option3.V alue = True Thensql = "select * from 书籍信息where 读者姓名='" & Text1.Text & "'" End Ifrs_find.CursorLocation = adUseClientrs_find.Open sql, conn, adOpenKeyset, adLockPessimisticDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseSet DataGrid1.DataSource = rs_findEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub13.frmfindreaderOption ExplicitPrivate Sub Command1_Click()Dim rs_findreader As New ADODB.RecordsetDim sql As StringIf Check1.V alue = vbChecked Thensql = "读者编号='" & Trim(Text1.Text & "") & "'"End IfIf Check2.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "读者姓名='" & Trim(Text2.Text & "") & "'"Elsesql = sql & "and读者姓名='" & Trim(Text2.Text & "") & "'" End IfEnd IfIf Check3.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "读者类别='" & Trim(Combo1.Text & "") & "'"Elsesql = sql & "and读者类别='" & Trim(Combo1.Text & "") & "'" End IfEnd Ifsql = "select * from 读者信息where " & sqlrs_findreader.CursorLocation = adUseClientrs_findreader.Open sql, conn, adOpenKeyset, adLockPessimistic DataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseSet DataGrid1.DataSource = rs_findreader'rs_findreader.CloseEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_find As New ADODB.RecordsetDim sql As Stringsql = "select * from 读者类别"rs_find.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_find.EOF ThenDo While Not rs_find.EOFCombo1.AddItem rs_find.Fields(0)rs_find.MoveNextLoopCombo1.ListIndex = 0End Ifrs_find.CloseEnd Sub14.frmmodifybookinfoOption ExplicitDim rs_book As New ADODB.RecordsetPrivate Sub cmdcancel_Click()rs_book.CancelUpdateDataGrid1.AllowAddNew = FalseDataGrid1.AllowUpdate = Falsecmdmodify.Enabled = Truecmddel.Enabled = Falsecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseEnd SubPrivate Sub cmddel_Click()Dim answer As StringOn Error GoTo delerroranswer = MsgBox("确定要删除吗?", vbY esNo, "")If answer = vbY es ThenDataGrid1.AllowDelete = Truers_book.Deleters_book.UpdateDataGrid1.RefreshMsgBox "成功删除!", vbOKOnly + vbExclamation, "" DataGrid1.AllowDelete = FalseElseExit SubEnd Ifdelerror:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdmodify_Click()Dim answer As StringOn Error GoTo cmdmodifycmddel.Enabled = Falsecmdmodify.Enabled = Falsecmdupdate.Enabled = Truecmdcancel.Enabled = TrueDataGrid1.AllowUpdate = Truecmdmodify:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdupdate_Click()If Not IsNull(DataGrid1.Bookmark) Thenrs_book.UpdateEnd Ifcmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseDataGrid1.AllowUpdate = FalseMsgBox "修改成功!", vbOKOnly + vbExclamation, "" End SubPrivate Sub Form_Load()Dim sql As StringOn Error GoTo loaderrorsql = "select * from 书籍信息"rs_book.CursorLocation = adUseClientrs_book.Open sql, conn, adOpenKeyset, adLockPessimistic cmdupdate.Enabled = FalseDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseIf userpow = "guest" ThenFrame2.Enabled = FalseEnd IfSet DataGrid1.DataSource = rs_bookExit Subloaderror:MsgBox Err.DescriptionEnd SubPrivate Sub Form_Unload(Cancel As Integer)Set DataGrid1.DataSource = Nothingrs_book.CloseEnd Sub15.frmmodifybookstyleOption ExplicitDim rs_reader As New ADODB.RecordsetPrivate Sub cmdcancel_Click()rs_reader.CancelUpdateDataGrid1.AllowAddNew = FalseDataGrid1.AllowUpdate = Falsecmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseEnd SubPrivate Sub cmddel_Click()Dim answer As StringOn Error GoTo delerroranswer = MsgBox("确定要删除吗?", vbY esNo, "")If answer = vbY es ThenDataGrid1.AllowDelete = Truers_reader.Deleters_reader.UpdateDataGrid1.RefreshMsgBox "成功删除!", vbOKOnly + vbExclamation, ""DataGrid1.AllowDelete = FalseElseExit SubEnd Ifdelerror:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdmodify_Click()Dim answer As StringOn Error GoTo cmdmodifycmddel.Enabled = Falsecmdmodify.Enabled = Falsecmdupdate.Enabled = Truecmdcancel.Enabled = TrueDataGrid1.AllowUpdate = Truecmdmodify:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdupdate_Click()If Not IsNull(DataGrid1.Bookmark) Thenrs_reader.UpdateEnd Ifcmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseDataGrid1.AllowUpdate = FalseMsgBox "修改成功!", vbOKOnly + vbExclamation, ""End SubPrivate Sub Form_Load()Dim sql As StringOn Error GoTo loaderrorsql = "select * from 图书类别"rs_reader.CursorLocation = adUseClientrs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticcmdupdate.Enabled = False '窗体刚刚加载时,"取消"按钮应设置为不可用,即将其Enabled属性设为False'设定DataGrid控件属性DataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseIf userpow = "guest" ThenFrame2.Enabled = FalseEnd If'添加错误处理语句Set DataGrid1.DataSource = rs_reader '使用DataGrid控件来显示图书类型数据表中的数据信息Exit Subloaderror:MsgBox Err.DesctiptionEnd SubPrivate Sub Form_Unload(Cancel As Integer)Set DataGrid1.DataSource = Nothingrs_reader.CloseEnd Sub16.frmmodifyreaderstyleOption ExplicitDim rs_reader As New ADODB.RecordsetPrivate Sub cmdcancel_Click()rs_reader.CancelUpdateDataGrid1.RefreshDataGrid1.AllowAddNew = FalseDataGrid1.AllowUpdate = Falsecmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseEnd SubPrivate Sub cmddel_Click()Dim answer As StringOn Error GoTo delerroranswer = MsgBox("确定要删除吗?", vbY esNo, "")If answer = vbY es ThenDataGrid1.AllowDelete = Truers_reader.Deleters_reader.UpdateDataGrid1.RefreshMsgBox "成功删除!", vbOKOnly + vbExclamation, ""DataGrid1.AllowDelete = FalseElseExit Sub。
C语言图书管理系统代码
#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1234;char a,d,b[10],b1[10]="yjk";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n\n\n");printf(" ********** 欢迎光临**********\n\n");printf(" ********************** 图书信息管理系统************************\n\n\n");printf("\n\n");printf(" ============1-用户登录===========\n");printf(" ============0-退出系统===========\n");printf(" 请输入您的选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名:");gets(b);printf("\n");printf(" 请输入您的密码:");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");printf(" ------------------\n");printf(" *图书信息管理系统*\n");printf(" ------------------\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf(" || 1-添加图书2-删除图书||\n\n");printf(" || 3-图书列表4-图书排序||\n\n");printf(" || 5-查询图书6-修改图书||\n\n");printf(" || 7-录入数据0-退出系统||\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 您的输入有误! 请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p2=head;ptr=p;while((ptr->num>p2->num)&&(p2->next!=NULL)){ p1=p2;p2=p2->next;}if(ptr->num<=p2->num){if(head==p2)head=ptr;else{p1->next=ptr;p->next=p2;}}else{p2->next=ptr;p->next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m){struct book *p;p=head;while(p!=NULL){if(p->num==m)break;p=p->next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1->next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1->num,p1->bname,p1->wname,p1->press,p1->sort ,p1->time,p1->price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1->num,p1->bname,p1->wname,p1->press,p1->sort,&p1-> time,&p1->price);if(head==NULL)head=p1;elsetail->next=p1;tail=p1;}tail->next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head){struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("==========================================================\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr->next)printf(" %d %s %s %s %s %d %.2f\n",ptr->num,ptr->bname,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("==========================================================\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1->num==a&&p1->next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1->num!=a&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->next==NULL){if(p1->num==a){p2->next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2->next=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("==========================================================\n");printf(" ** 1-按图书编号查询2-按图书名查询**\n");printf(" ** 3-按图书类别查询4-按作者名查询**\n");printf(" ** 5-按出版时间查询0-退出查询**\n");printf("==========================================================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);printf("====================================================================== ===\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->bname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->bname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);}p=p->next;}printf("====================================================================== ===\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->wname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->wname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p->sort,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->sort,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->time==a){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(p->time==a){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("============================================================\n");printf(" ** 1-编号2-图书名3-作者名**\n");printf(" ** 4-出版社5-类别6-出版时间**\n");printf(" ** 7-价格8-修改全部0-放弃修改**\n");printf("============================================================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p->bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p->wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p->press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p->sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p->time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p->price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p->num);printf("请输入新图书名:");scanf("%s",p->bname);getchar();printf("请输入新作者名:");scanf("%s",p->wname);getchar();printf("请输入新出版社:");scanf("%s",p->press);getchar();printf("请输入新类别:");scanf("%s",p->sort);getchar();printf("请输入新出版时间:");scanf("%d",&p->time);getchar();printf("请输入新价格:");scanf("%f",&p->price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n");scanf("%c",&c);getchar();switch(c){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}}}//图书排序void paixu(struct book *head){int a;printf("================================================================\n");printf(" ** 1-按图书编号排序2-按出版时间排序**\n");printf(" ** 3-按图书价格排序4-按图书名排序**\n");printf(" ** 5-按作者名排序0-取消排序操作**\n");printf("================================================================\n");printf("请输入您选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_paixu(head);break;time_paixu(head);break;case 3:price_paixu(head);break;case 4:bname_paixu(head);break;case 5:wname_paixu(head);break;default:printf("您的输入有误!\n");break;}}//按图书编号排序void num_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->num<a[index]->num)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);switch(b){case 'n':break;case 'y':printf("================================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("================================================================\n");break;default:printf("您的输入有误!\n");break;}}//按出版时间排序void time_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->time<a[index]->time)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按图书价格排序void price_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->price<a[index]->price)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按图书名排序void bname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->bname,a[i]->bname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按作者名排序void wname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->wname,a[i]->wname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}。
图书管理系统代码
E:\图书管理系统\BookSystem1\BookSystem1\obj\Debug\er.resources
E:\图书管理系统\BookSystem1\BookSystem1\obj\Debug\BookSystem1.Properties.Resources.resources
E:\图书管理系统\BookSystem1\BookSystem1\obj\Debug\BookSystem1.csproj.GenerateResource.Cache
E:\图书管理系统\BookSystem1\BookSystem1\bin\Debug\BLL.pdb
E:\图书管理系统\BookSystem1\BookSystem1\bin\Debug\DAL.pdb
E:\图书管理系统\BookSystem1\BookSystem1\obj\Debug\ResolveAssemblyReference.cache
E:\Microsoft Visual Studio 9.0\Projects\图书管理系统\BookSystem1\BookSystem1\obj\Debug\BookSystem1.Login.resources
E:\BookSystem1\BookSystem1\obj\Debug\ResolveAssemblyReference.cache
E:\BookSystem1\BookSystem1\obj\Debug\BookSystem1.frmMain.resources
图书管理系统程序代码
#include<fstream〉#include<iostream〉#include<stdlib.h〉#include〈ctime〉#include<cmath>#include〈termios.h〉#include <sstream〉#include<string。
h〉#include<assert.h〉//改变字体颜色#define NONE "\033[m"#define RED "\033[0;32;31m”#define GREEN ”\033[0;32;32m”#define BLUE "\033[0;32;34m”#define YELLOW ”\033[1;33m”#define LIGHT_RED ”\033[1;31m”#define LIGHT_GREEN "\033[1;32m"#define LIGHT_BLUE "\033[1;34m”/*程序导读:1。
程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,flag=1按用户ID号或编号来操作3。
本程序分5个部分,具体已标识如(1)图书管理。
.*/using namespace std;class Book{public:string book_name;string book_num;//编号string book_pre;//出版社string book_aut;//作者int book_con;//这样的书还有几本int book_mux;//这样的书总共有几本public:Book(){book_con=0;book_mux=0;}void show_book();};/****************************************(1)图书管理*******************************************/void Book::show_book(){cout<〈"书名:”<〈book_name<〈endl;cout〈〈”出版社:"〈<book_pre〈〈endl;cout<<”此书的作者:"〈<book_aut〈<endl;cout〈<”ISBN编号:”<〈book_num<〈endl;cout<<"此书共有"〈<book_mux<<”本”〈〈endl;cout<<”还有"<<book_con〈〈”本书未借出!"〈<endl;}class BookNode{public:Book book;BookNode *next;};BookNode *headbook=NULL;class BookManage{public:int totolbook;public:BookManage(){totolbook=0;}void addbook();void delbook(string s,int num,int flag);void findbook(string s,int flag);//查询图书};void BookManage::addbook(){string h;cout〈〈"添加输入0,退出输入—1"<〈endl;cin>>h;if(h==”-1”)return;else if(h=="0”)while(1){if(h==”-1”)break;else if(h==”0”){string na,nu,p1,aut;int con;BookNode *p=new BookNode;cout<<”请输入书名:"〈〈endl;cin〉>na;p—〉book.book_name=na;cout<〈"请输入ISBN编号:”<<endl;cin>〉nu;p->book。
图书管理系统的C#代码完整版
C#代码清单共1个项目,包含5个类。
项目: librarysystem类:主类代码:namespace librarysystem{ PublicationISBN = PublicationISBN;= PublicationName;= PublicationAuthor;= PublicationType;= PublicationStatus;}}}读者类代码:namespace librarysystem{ 询图书");("2.借书服务");("3.还书服务");("4.新出版物入库");("5.录入新读者");("6.查询读者的借阅信息");("7.退出管理系统");("-------------------------------------------------------------------");bool flag;do{flag = false;("请选择:");string key = ();switch (key){case"1":("请输入需要查询图书的书名:");ShowPubInfo();break;case"2":("请输入您的姓名:");();ShowBorrowInfo();("请输入您的姓名:");();ShowReturnInfo();break;case"4":("请按照提示逐步输入需要入库出版物的信息……");ShowAddPublications();break;case"5":("请按照提示逐步输入新注册读者的信息……");ShowAddReaders();break;case"6":("请输入您的姓名: ");();ShowRedPubInfo;break;case"7":flag = false;break;default:("无此业务,是否重新选择(y/n)");string answer = ();if (answer != "y"){flag = false;}else{flag = true;}break;}} while (flag);}/*显示查询到的出版物信息*/public void ShowPubInfo(){if ()){("您要查询的出版物信息:");("-------------------------------------------------------------------"); ("编号: " + ("出版物名字: " + ("出版物作者: " + ("出版物类型: " + if {("出版物状态:在架,可借");else{("出版物状态:未在架,不可借");}("-------------------------------------------------------------------"); ("");("");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}else{("抱歉,未找到该图书!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}/*显示借阅操作结果*/public void ShowBorrowInfo(){if{("恭喜,借阅成功!");ShowRedPubInfo;}{("抱歉,借阅失败!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}/*显示归还操作结果*/public void ShowReturnInfo(){if{("恭喜,归还成功!");ShowRedPubInfo;}else{("抱歉,归还失败!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}public void ShowRedPubInfo(Readers red){("当前你的借阅信息如下:");("--------------------------------------------------------------------"); ("编号: " + ;("姓名: " + ;("性别: " + ;("主修专业: " + ;("已借图书: ");for (int{if [i] != ""){(" "+[i]);}}("");("--------------------------------------------------------------------"); ("");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}/*显示新出版物入库的信息*/public void ShowAddPublications(){pub = new Publications();("请输入出版物的编号: ");=();("请输入出版物的名称: ");= ();("请输入出版物的编者: ");= ();("请输入出版物的类型: ");= ();= true;(pub);("新出版物入库成功!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}/*显示新读者注册的信息*/public void ShowAddReaders(){red = new Readers();("请输入新注册读者的编号: "); = ();("请输入新注册读者的姓名: "); = ();("请输入新注册读者的性别: "); = ();("请输入新注册读者的院系: "); = ();("请输入新注册读者的专业: "); = ();for(int i=0;i<10;i++){[i]="";}(red);("新读者注册成功!");("是否办理其他业务(y/n) ");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}}。
图书管理完整代码
1.登录Login.javaimport java.awt.event.*;import javax.swing.*;import java.awt.*;import java.awt.Container;import java.util.*;import java.sql.*;class Login extends JFrame implements ActionListener{ Container cp=null;JFrame f=null;JButton j1,j2;JTextField t1;JPasswordField t2;JLabel jlable1,jlable2;Color c;JPanel jp1,jp2;Login(){f=new JFrame("小型图书管理系统");j1=new JButton("确定");j2=new JButton("取消");cp=f.getContentPane();jlable1=new JLabel(" 输入用户名");jlable2=new JLabel(" 用户密码");jp1=new JPanel();jp2=new JPanel();t1=new JTextField(18);t2=new JPasswordField(18);jp1.add(jlable1);jp1.add(t1);jp1.add(jlable2);jp1.add(t2);JLabel JL=new JLabel("<html><font color=#CC00FF size='7'><i> 欢迎登录</i></font>",SwingConstants.CENTER);cp.add(JL,"North");jp2.add(j1);jp2.add(j2);cp.add(jp1,"Center");cp.add("South",jp2);jp1.setBackground(new Color(255,155,255));Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*///setSize(x,y); /*让系统窗口平铺整个显示器窗口*/f.setSize(300,300);int xcenter=(x-300)/2;int ycenter=(y-300)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//-----------------------------------------------------j1.addActionListener(this);//注册事件监听器j2.addActionListener(this);f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0);}});}public void confirm()//验证用户和密码是否存在{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM");Statement sql=con.createStatement();String uname=t1.getText().trim();String Mima=t2.getText().trim();String queryMima="select * from YONGHU where 用户名='"+uname+"'AND 密码='"+Mima+"'";ResultSet rs=sql.executeQuery(queryMima);if(rs.next()) {new Book(uname);f.hide();con.close();}else{ JOptionPane.showMessageDialog(null,"该用户不存在","提示!",JOptionPane.YES_NO_OPTION);}t1.setText("");t2.setText("");} catch(SQLException g){ System.out.println("E Code"+g.getErrorCode());System.out.println("E M"+g.getMessage());}}public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){confirm(); }else if(cmd.equals("取消")){f.dispose();}}public static void main(String args[]){Login a=new Login();}2.主界面Book.javaimport .*;import java.sql.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import java.util.*;class Book extends JFrame implements ActionListener{JButton QueryScore=new JButton("图书查询");JButton QueryXuefen=new JButton("图书入库");JButton jiangfa=new JButton("图书删除");JButton xuanke=new JButton("图书概览");JButton gaiMima=new JButton("修改密码");JMenuBar mb = new JMenuBar();//菜单栏JPanel jp=new JPanel();//用来填放子模块Container cp=getContentPane();String username; Book(){}Book(String username){ ername=username;mb.add(QueryScore);mb.add(QueryXuefen);mb.add(jiangfa);mb.add(xuanke);mb.add(gaiMima);cp.add(mb,"North");// 设置边框jp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineB order(Color.blue, 2),null, TitledBorder.CENTER, TitledBorder.TOP));jp.setLayout(new BorderLayout());JLabel label1 = new JLabel(new ImageIcon("4.jpg"));jp.add(label1);/* JLabel JL=new JLabel("<html><font color=#CC00FF size='7'><i>欢迎登陆</i></font>",SwingConstants.CENTER);jp.add(JL,"North");*/JLabel label2 = new JLabel(new ImageIcon("2.jpg"));//jp.add(label2,"South");JScrollPane scrollpane=new JScrollPane(jp);cp.add(scrollpane);setTitle("欢迎登陆");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*///setSize(x,y); /*让系统窗口平铺整个显示器窗口*/setSize(600,600);int xcenter=(x-600)/2;int ycenter=(y-600)/2;setLocation(xcenter,ycenter);/*显示在窗口中央*/setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//注册临听器QueryScore.addActionListener(this);QueryXuefen.addActionListener(this);jiangfa.addActionListener(this);xuanke.addActionListener(this);gaiMima.addActionListener(this);}public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if (cmd.equals("图书查询")){ new QueryBook(); }if (cmd.equals("图书入库")){ new BookIn(); }if (cmd.equals("图书删除")){ new RemoveBook(); }if (cmd.equals("图书概览")){ new BookBrower().showRecord();}if (cmd.equals("修改密码")){ new UpdateMima(username);}}public static void main(String args[]){ new Book(""); }}3.图书查询QueryBook.javaimport java.awt.event.*;import javax.swing.*;import java.awt.*;import java.util.*;import java.awt.Container;import java.sql.*;class QueryBook implements ActionListener{JFrame f3; Container cp;JPanel jp1,jp2,jp3,jp4,jp,jpanelWest;JButton jbt1,jbt2;//按钮,确定、取消JLabel label; //标签:请输入图书号JTextField tf,tf1,tf2,tf3,tf4,tf5,tf6; //定义文本框JLabel label1,label2,label3,label4;QueryBook(){ f3=new JFrame();cp=f3.getContentPane(); // 初始化面板、按钮、标签、文本框jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jpanelWest=new JPanel();jp=new JPanel();//------------------------------------------------jbt1=new JButton("确定");jbt2=new JButton("取消");//------------------------------------------------label=new JLabel("<html><font color=#CC00FF size='4'>请输入图书号:</font>",SwingConstants.CENTER);label.setForeground(Color.blue);tf=new JTextField(20);//------------------------------------------------tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);//------------------------------------------------//布局,添加控件JPanel jpanel=new JPanel();jpanel.add(label);jpanel.add(tf);JPanel pp4=new JPanel();JPanel jpane4=new JPanel();cp.add(jpanel,"North");JPanel pp2=new JPanel(new GridLayout(6,1));JPanel pp3=new JPanel();pp4.setLayout(new GridLayout(6,1));pp4.add(new JLabel("图书名",SwingConstants.CENTER));pp2.add(tf1);pp4.add(new JLabel("图书号",SwingConstants.CENTER));pp2.add(tf2);pp4.add(new JLabel("单价",SwingConstants.CENTER));pp2.add(tf3);pp4.add(new JLabel("作者",SwingConstants.CENTER));pp2.add(tf4);pp4.add(new JLabel("出版社",SwingConstants.CENTER));pp2.add(tf5);pp4.add(new JLabel("入库时间",SwingConstants.CENTER));pp2.add(tf6); pp3.add(jbt1); pp3.add(jbt2);cp.add(pp4,"West");cp.add(pp2,"Center");cp.add(pp3,"South");cp.add(jpane4,"East");//------------------------------------------------Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*/f3.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f3.setLocation(xcenter,ycenter);/*显示在窗口中央*/f3.setVisible(true);//-------------------------------------------------jbt1.addActionListener(this);//注册监听器jbt2.addActionListener(this);/*f3.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0);}});*/}//------------------------------------------------public void showRecord(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM");Statement sql;String ql=tf.getText().trim();String s="select * from BOOK where 图书号 ='"+ql +"'";sql=con.createStatement();ResultSet rs=sql.executeQuery(s);if(rs.next()) {String bname=rs.getString(1);String bno=rs.getString(2);String price=rs.getString(3);String writer=rs.getString(4);String publish=rs.getString(5);String indate=rs.getString(6);tf1.setText(bname);tf2.setText(bno);tf3.setText(price);tf4.setText(writer);tf5.setText(publish);tf6.setText(indate);}else{JOptionPane.showMessageDialog(null,"您输入的图书号不存在,请重新输入","输入错误", JOptionPane.YES_NO_OPTION);}con.close();}catch(SQLException g){ System.out.println("E Code"+g.getErrorCode());System.out.println("E M"+g.getMessage());}tf1.setEditable(false);tf2.setEditable(false);tf3.setEditable(false);tf4.setEditable(false);tf5.setEditable(false);tf6.setEditable(false);}public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){ showRecord();tf.setText("");}else if(cmd.equals("取消"))f3.hide();}public static void main(String args[]){ QueryBook a=new QueryBook(); }}4.图书入库BookIn.javaimport java.awt.event.*;import javax.swing.*;import java.awt.*;import java.util.*;import java.sql.*;import javax.swing.text.JTextComponent;//extends JFrameclass BookIn implements ActionListener{JFrame f3; Container cp;JPanel jp1,jp2,jp3,jp4,jp,jpanelWest;JButton jbt1,jbt2;//按钮:确定、取消、JLabel label; //标签JTextField tf1,tf2,tf3,tf4,tf5,tf6; //定义文本框JLabel label1,label2,label3,label4;String sno; BookIn(){f3=new JFrame();cp=f3.getContentPane(); // 初始化面板、按钮、标签、文本框jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();jpanelWest=new JPanel();jp=new JPanel();//------------------------------------------------jbt1=new JButton("确定");jbt2=new JButton("取消");//------------------------------------------------JLabel label=new JLabel("<html><font color=#CC00FF size='4'> 图书入库</font>",SwingConstants.CENTER);label.setForeground(Color.blue);//------------------------------------------------tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);//------------------------------------------------//布局,添加控件jp1.add(jbt1);jp1.add(jbt2);sno=tf4.getText();jp1.add(new JLabel("您好"+sno+"欢迎登陆学生信息系统")); JPanel jpanel=new JPanel();jpanel.add(label);JPanel pp4=new JPanel();JPanel jpane4=new JPanel();cp.add(jpanel,"North");JPanel pp2=new JPanel(new GridLayout(6,1));JPanel pp3=new JPanel();pp4.setLayout(new GridLayout(6,1));pp4.add(new JLabel("图书名",SwingConstants.CENTER)); pp2.add(tf1);pp4.add(new JLabel("图书号",SwingConstants.CENTER)); pp2.add(tf2);pp4.add(new JLabel("单价",SwingConstants.CENTER)); pp2.add(tf3);pp4.add(new JLabel("作者",SwingConstants.CENTER)); pp2.add(tf4);pp4.add(new JLabel("出版社",SwingConstants.CENTER)); pp2.add(tf5);pp4.add(new JLabel("入库时间",SwingConstants.CENTER)); pp2.add(tf6);pp3.add(jbt1);pp3.add(jbt2);cp.add(pp4,"West");cp.add(pp2,"Center");cp.add(pp3,"South");cp.add(jpane4,"East");//------------------------------------------------Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*/f3.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f3.setLocation(xcenter,ycenter);/*显示在窗口中央*/f3.setVisible(true);//-------------------------------------------------jbt1.addActionListener(this);//注册监听器jbt2.addActionListener(this);/*f3.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0);}});*/}//------------------------------------------------public void insertRecord(){if(tf1.getText().equals("")||tf2.getText().equals("")||tf3.getText().eq uals("")||tf4.getText().equals("")||tf5.getText().equals("")||tf6.getText().equals("")){JOptionPane.showMessageDialog(f3,"请填写图书资料");return;}try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM");Statement sql;String s="insert into BOOKvalues('"+tf1.getText()+"','"+tf2.getText()+"','"+tf3.getText()+"','"+tf4.getText()+"','"+tf5.getText()+"','"+tf6.getText()+"');";//查询输入的图书号是否在数据库中存在String query="select * from BOOK where 图书号='"+tf2.getText()+"'"; sql=con.createStatement();ResultSet rs=sql.executeQuery(query);//返回查询结果集boolean moreRecords=rs.next();//判断结果集是否有数据if(moreRecords){ JOptionPane.showMessageDialog(f3,"图书号已经被使用,请重新输入"); con.close();tf2.setText("");}int insert=sql.executeUpdate(s);if(insert==1){ JOptionPane.showMessageDialog(null,"图书信息录入成功!");tf1.setText("");tf2.setText("");tf3.setText("");tf4.setText("");tf5.setText("");tf6.setText("");}}catch(SQLException g){ System.out.println("E Code"+g.getErrorCode());System.out.println("E M"+g.getMessage());}}public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){ insertRecord(); }else if(cmd.equals("取消"))f3.hide();}public static void main(String args[]){ BookIn a=new BookIn(); }}5.图书删除RemoveBook.javaimport java.awt.event.*;import javax.swing.*;import java.awt.*;import java.util.*;import java.awt.Container ;import java.sql.*;class RemoveBook implements ActionListener{JFrame f;Container cp;JPanel jpS,jpanelWest;JButton jbt1,jbt2,jbt3;//按钮,查询、取消、修改JLabel label,L; //标签:请输入图书名JTextField tf; //定义文本框JTable table;//用来接收数据库中返回的信息Object columnName[]={"图书名","图书号","单价","作者","出版社","入库时间"}; Object ar[][] =new Object[80][6];String sno;String count="xx";RemoveBook(){f=new JFrame();cp=f.getContentPane(); // 初始化面板、按钮、标签、文本框jpS=new JPanel();jpanelWest=new JPanel();//------------------------------------------------jbt1=new JButton("查询");jbt2=new JButton("取消");jbt3=new JButton("删除");//------------------------------------------------label=new JLabel("<html><font color=#CC00FF size='4'>请输入要删除的图书名:</font>",SwingConstants.CENTER);label.setForeground(Color.blue);L=new JLabel("该种图书共有"+count+"本");//------------------------------------------------table=new JTable(ar,columnName);//ar 存放表中的数据,columnname 表示列名JScrollPane scrollpane = new JScrollPane(table);//------------------------------------------------tf=new JTextField(18);//------------------------------------------------//布局,添加控件jpS.add(jbt1);jpS.add(jbt2);jpS.add(jbt3);JPanel jpanel=new JPanel();jpanel.add(label);jpanel.add(tf);JPanel pp4=new JPanel();JPanel jpE=new JPanel();cp.add(jpanel,"North");JPanel jp=new JPanel();//jp.add(scrollpane);JPanel p=new JPanel();//用来放两个表p.setLayout(new BorderLayout());p.add(L,"North");p.add(scrollpane);cp.add(pp4,"West");cp.add(p,"Center");cp.add(jpS,"South");cp.add(jpE,"East");//------------------------------------------------Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*/f.setSize(400,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//-------------------------------------------------jbt1.addActionListener(this);//注册监听器jbt2.addActionListener(this);jbt3.addActionListener(this);/*f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0);}}}//------------------------------------------------int i=0;public void showRecord(String ql){while(i>=0){ ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM"); Statement sql;String s="select * from BOOK where 图书名 ='"+ql +"'";sql=con.createStatement();ResultSet rs=sql.executeQuery(s);while(rs.next()){String bname=rs.getString(1);String bno=rs.getString(2);String price=rs.getString(3);String writer=rs.getString(4);String publish=rs.getString(5);String indate=rs.getString(6);ar[i][0]=bname;ar[i][1]=bno;ar[i][2]=price;ar[i][3]=writer;ar[i][4]=publish;ar[i][5]=indate;i++;}count=""+i+"";L.setText("该种图书共有"+count+"本");f.repaint();con.close();System.out.println(ar[0][1]);}catch(SQLException g){ System.out.println("E Code"+g.getErrorCode());System.out.println("E M"+g.getMessage());}}public void deleteRecord(int index)try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM");Statement sql;String ql=(String)(ar[index][1]);String s="delete * from BOOK where 图书号 ='"+ql +"'";sql=con.createStatement();int del=sql.executeUpdate(s);if(del==1){JOptionPane.showMessageDialog(null,"删除成功!","信息", JOptionPane.YES_NO_OPTION);}con.close();f.repaint();}catch(SQLException g){System.out.println("E Code"+g.getErrorCode());System.out.println("E M"+g.getMessage());}}public void actionPerformed(ActionEvent e){String remember="";String ql="";String cmd=e.getActionCommand();if(cmd.equals("查询")){ql=tf.getText().trim();remember=ql;showRecord(ql);}if(cmd.equals("删除")){int index=table.getSelectedRow();if( index==-1)JOptionPane.showMessageDialog(null,"请选定要删除的表格行","输入错误", JOptionPane.YES_NO_OPTION);else {deleteRecord(index);//showRecord(remember);}}if(cmd.equals("取消"))f.hide();}public static void main(String args[]){ RemoveBook a=new RemoveBook(); }}6.图书概览BookBrower.javaimport java.awt.event.*;import javax.swing.*;import java.awt.*;import java.util.*;import java.awt.Container;import java.sql.*;class BookBrower implements ActionListener{JFrame f;Container cp;JPanel jpS,jpanelWest;JButton jbt1,jbt2;//按钮,查询、取消、修改JLabel label,L; //标签//定义文本框JTable table;//用来接收数据库中返回的信息Object columnName[]={"图书名","图书号","单价","作者","出版社","入库时间"}; Object ar[][] =new Object[80][6];String sno;String count="xx";BookBrower(){f=new JFrame();cp=f.getContentPane(); // 初始化面板、按钮、标签、文本框jpS=new JPanel();jpanelWest=new JPanel();//------------------------------------------------jbt1=new JButton("确定");jbt2=new JButton("返回");//------------------------------------------------JLabel label=new JLabel("<html><font color=#CC00FF size='4'> 图书概览</font>",SwingConstants.CENTER);label.setForeground(Color.blue);L=new JLabel("书库现在共有图书"+count+"本");//------------------------------------------------table=new JTable(ar,columnName);//ar 存放表中的数据,columnname 表示列名 JScrollPane scrollpane = new JScrollPane(table);//------------------------------------------------//布局,添加控件jpS.add(jbt1);jpS.add(jbt2);JPanel jpanel=new JPanel();jpanel.add(label);JPanel pp4=new JPanel();JPanel jpE=new JPanel();cp.add(jpanel,"North");JPanel jp=new JPanel();//jp.add(scrollpane);JPanel p=new JPanel();//用来放两个表p.setLayout(new BorderLayout());p.add(L,"North");p.add(scrollpane);cp.add(pp4,"West");cp.add(p,"Center");cp.add(jpS,"South");cp.add(jpE,"East");//------------------------------------------------Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*/f.setSize(400,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//-------------------------------------------------jbt1.addActionListener(this);//注册监听器jbt2.addActionListener(this);/* f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0);}});*/}//------------------------------------------------int i=0;public void showRecord(){while(i>=0){ ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM"); String s="select * from BOOK ";Statement sql=con.createStatement();ResultSet rs=sql.executeQuery(s);while(rs.next()){String bname=rs.getString(1);String bno=rs.getString(2);String price=rs.getString(3);String writer=rs.getString(4);String publish=rs.getString(5);String indate=rs.getString(6);ar[i][0]=bname;ar[i][1]=bno;ar[i][2]=price;ar[i][3]=writer;ar[i][4]=publish;ar[i][5]=indate;i++;}count=""+i+"";L.setText("书库现在共有图书"+count+"本");f.repaint();con.close();}catch(SQLException g){ System.out.println("E Code"+g.getErrorCode());System.out.println("E M"+g.getMessage());}}public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){ f.hide(); }if(cmd.equals("返回"))f.hide();}public static void main(String args[]){ BookBrower a=new BookBrower();a.showRecord();}}7.密码修改UpdateMima.javaimport java.awt.event.*;import javax.swing.*;import java.awt.*;import java.util.*;import java.awt.Container ;import java.sql.*;class RemoveBook implements ActionListener{JFrame f;Container cp;JPanel jpS,jpanelWest;JButton jbt1,jbt2,jbt3;//按钮,查询、取消、修改JLabel label,L; //标签:请输入图书名JTextField tf; //定义文本框JTable table;//用来接收数据库中返回的信息Object columnName[]={"图书名","图书号","单价","作者","出版社","入库时间"}; Object ar[][] =new Object[80][6];String sno;String count="xx";RemoveBook(){f=new JFrame();cp=f.getContentPane(); // 初始化面板、按钮、标签、文本框jpS=new JPanel();jpanelWest=new JPanel();//------------------------------------------------jbt1=new JButton("查询");jbt2=new JButton("取消");jbt3=new JButton("删除");//------------------------------------------------label=new JLabel("<html><font color=#CC00FF size='4'>请输入要删除的图书名:</font>",SwingConstants.CENTER);label.setForeground(Color.blue);L=new JLabel("该种图书共有"+count+"本");//------------------------------------------------table=new JTable(ar,columnName);//ar 存放表中的数据,columnname 表示列名JScrollPane scrollpane = new JScrollPane(table);//------------------------------------------------tf=new JTextField(18);//------------------------------------------------//布局,添加控件jpS.add(jbt1);jpS.add(jbt2);jpS.add(jbt3);JPanel jpanel=new JPanel();jpanel.add(label);jpanel.add(tf);JPanel pp4=new JPanel();JPanel jpE=new JPanel();cp.add(jpanel,"North");JPanel jp=new JPanel();//jp.add(scrollpane);JPanel p=new JPanel();//用来放两个表p.setLayout(new BorderLayout());p.add(L,"North");p.add(scrollpane);cp.add(pp4,"West");cp.add(p,"Center");cp.add(jpS,"South");cp.add(jpE,"East");//------------------------------------------------Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; /*取得显示器窗口的宽度*/int y=screen.height; /*取得显示器窗口的高度*/f.setSize(400,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//-------------------------------------------------jbt1.addActionListener(this);//注册监听器jbt2.addActionListener(this);jbt3.addActionListener(this);/*f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){ System.exit(0);}});*/}//------------------------------------------------int i=0;public void showRecord(String ql){while(i>=0){ ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.println("加载驱动程序失败!");}try{Connectioncon=DriverManager.getConnection("jdbc:odbc:TEST","SYSTEM","SYSTEM"); Statement sql;String s="select * from BOOK where 图书名 ='"+ql +"'";sql=con.createStatement();ResultSet rs=sql.executeQuery(s);。
书籍管理 php源代码
书籍管理 php源代码以下是一个简单的书籍管理 PHP 源代码示例,包含了添加、查看、修改和删除书籍的基本功能:```php<?php// 连接数据库$servername = "localhost";$username = "你的用户名";$password = "你的密码";$dbname = "你的数据库名称";// 创建连接$conn = new mysqli($servername, $username, $password, $dbname);// 检查连接if ($conn->connect_error) {die("连接失败: ". $conn->connect_error);}// 定义操作函数function addBook($title, $author, $isbn) {$sql = "INSERT INTO books (title, author, isbn) VALUES ('".$title."', '".$author."', '".$isbn."')";if ($conn->query($sql) === TRUE) {echo "图书添加成功";} else {echo "图书添加失败: ". $conn->error;}}function viewBooks() {$sql = "SELECT * FROM books";$result = $conn->query($sql);if ($result->num_rows > 0) {while($row = $result->fetch_assoc()) {echo "标题: ". $row["title"]. " ". "作者: ". $row["author"]. " ". "ISBN: ". $row["isbn"]. "<br>";}} else {echo "没有图书记录";}}function updateBook($id, $title, $author, $isbn) {$sql = "UPDATE books SET title = '".$title."', author = '".$author."', isbn = '".$isbn."' WHERE id = ".$id;if ($conn->query($sql) === TRUE) {echo "图书修改成功";} else {echo "图书修改失败: ". $conn->error;}}function deleteBook($id) {$sql = "DELETE FROM books WHERE id = ".$id;if ($conn->query($sql) === TRUE) {echo "图书删除成功";} else {echo "图书删除失败: ". $conn->error;}}// 处理表单操作if ($_SERVER["REQUEST_METHOD"] == "POST") {if (isset($_POST["addBook"])) {addBook($_POST["title"], $_POST["author"], $_POST["isbn"]);} else if (isset($_POST["viewBooks"])) {viewBooks();} else if (isset($_POST["updateBook"])) {updateBook($_POST["id"], $_POST["title"], $_POST["author"], $_POST["isbn"]);} else if (isset($_POST["deleteBook"])) {deleteBook($_POST["id"]);}}// 显示图书管理页面><!DOCTYPE html><html><head><title>图书管理</title></head><body><h1>图书管理</h1><form action="" method="post"><input type="submit" name="addBook" value="添加图书"></form><form action="" method="post"><input type="submit" name="viewBooks" value="查看图书"></form><form action="" method="post"><input type="submit" name="updateBook" value="修改图书"></form><form action="" method="post"><input type="submit" name="deleteBook" value="删除图书"></form></body></html><?php// 关闭数据库连接$conn->close();>```上述代码实现了一个简单的图书管理系统,包含了添加、查看、修改和删除图书的功能。
图书管理系统-详细设计编码
可行性研究
领域分析
需求分析
设计
编码
测试
交付
开始
我们的进度,在这里
从界面jTextField控件获得图书 编号bid、借书证编号sid
“借阅”按钮功能程序流 程图:
调用BookRegistrationDAO类 insertBorrowInfo(bid,sid)方法插 入借阅信息,返回的借阅信息封 装到BorrowView对象b中。
将BorrowView对象b封装的属 性:书名,ISBN,借阅时间, 归还时间显示到界面。
N Y
提示图书已经借 出,不能再借
B.getBook_state().equls(“借出未还”)
Y
结束
可行性研究
领域分析
可行性研究
领域分析
需求分析
设计
编码
测试
交付
我们的进度,在这里
【步骤二】、考虑实现此用例,需要哪些数据,数 据从哪里来。 ◦ 需要图书证编号、借阅证编号 ◦ 可以从界面的jTextFiled控件中通过getText方 法获得。
可行性研究
领域分析
需求分析
设计
编码
测试
交付
我们的进度,在这里
【步骤三】、需要哪些操作来处理数据,这些操作 在哪里获得? 1.向数据库“借阅信息”表中插入一条新记录,并 获得这条新记录。 2.更改“图书”表中的图书状态为“借出未还”。
测试
交付
我们的进度,在这里
【步骤五】:把1-4步的结果进行汇总,形成“借阅” 按钮处理事件的详细设计: 1.从GUI界面的jTextFiled获得,借阅证编号sid,图 书编号bid 2.使用BookRegistrationDAO类的方法BorrowView
图书管理系统(源代码)
#include"stdio.h"#include"stdlib.h"#include"string.h"#define MENU_ADMIN_COUNT 2#define MENU_SEARCH_BOOK_COUNT 6 #define MENU_USER_COUNT 7#define BOOK_FILE "books.dat"#define USER_FILE "user.dat"#define MAX_BOOK_NAME 20#define MAX_PUBLISHER 20#define MAX_DATE 10#define MAX_AUTHOR 20#define MAX_ISBN 20typedef struct _book_info{ char book_name[MAX_BOOK_NAME]; char author[MAX_AUTHOR];char publisher[MAX_PUBLISHER];char pub_date[MAX_DA TE];char ISBN[MAX_ISBN];int pages;}book_info;typedef struct _book{ book_info bi;struct _book* next;}book;#define MAX_USERNAME 10#define MAX_PASSWORD 10typedef enum _USER_TYPE{ADMIN=0,USER}USER_TYPE;typedef struct _user_info{char username[MAX_USERNAME];char password[MAX_PASSWORD]; USER_TYPE user_type;}user_info;typedef struct _user{ user_info ui;struct _user* next;}user;void init_user();void load_users();USER_TYPE login();void add_user();void search_user();void save_users();void clear_users();void save_users_to_file();user* get_last_user();user* get_previous_user(user* p);user* find_user(char* name);void show_user(user_info* info);void input_user(user_info* info);void delete_user(user* p);void update_user(user* p);void init_book();void load_books();void add_book();void view_book();void delete_book();void save_books();void clear_books();void search_book_by_name();void search_book_by_author();void search_book_by_publisher();void search_book_by_pubdate();void search_book_by_isbn();int findstr(char *source,char *str);void save_books_to_file();book* get_last_book();book* get_previous_book(book* p);void input_book(book_info* info);void show_book(book_info* info);void show_admin_menu();void show_search_book_menu();void show_user_menu();void admin_exit();void user_exit();book *first_book=NULL;user* first_user=NULL;char menu_title[]="=========================================\n" "| 图书管理系统|\n""+---------------------------------------+\n";char menu_admin[]="| |\n" "| (1)图书管理|\n" "| (2)用户管理|\n" "| (3)退出系统|\n" "+---------------------------------------+\n";char admin_menu1[]="-----------------------------------------\n""| 图书管理|\n" "----------------------------------------|\n""| <1>新增图书|\n" "| <2>浏览图书|\n" "| <3>查找图书|\n" "| <4>删除图书|\n" "| <5>保存图书|\n" "| <0>返回主菜单|\n" "-----------------------------------------\n";char admin_menu2[]="----------------------------------------\n"" 用户管理|\n" "----------------------------------------|\n""| <1>新增用户|\n" "| <2>查找用户|\n" "| <3>保存用户|\n" "| <0>返回主菜单|\n" "|---------------------------------------|\n";void(*menu1_fun[])()={add_book,view_book,show_search_book_menu,delete_book,save_books,};void(*menu2_func[])()={add_user,search_user,save_users,};char menu_admin_search_book[]="| 查找图书:|\n" "| <1>按书名查找|\n" "| <2>按作者查找|\n" "| <3>按出版社查找|\n" "| <4>按出版日期查找|\n" "| <5>按国际标准书号(ISBN)查找|\n" "| <0>返回主菜单|\n" "+--------------------------------------+\n";void (*admin_search_book_func[])()={search_book_by_name,search_book_by_author,search_book_by_publisher,search_book_by_pubdate,search_book_by_isbn,};char menu_user[]="| <1>浏览图书|\n" "| <2>按书名查找图书|\n" "| <3>按作者查找图书|\n" "| <4>按出版社查找图书|\n" "| <5>按出版日期查找图书|\n" "| <6>按国际标准书号(ISBN)查找图书|\n" "| <0>退出系统|\n" "+--------------------------------------+\n";void (*user_func[])()={view_book,search_book_by_name,search_book_by_author,search_book_by_publisher,search_book_by_pubdate,search_book_by_isbn,user_exit};void add_book(){ char try_again='Y';book *p=NULL;book *new_book=NULL;while(try_again=='Y' || try_again=='y'){ new_book=(book*)malloc(sizeof(book));memset(new_book,0,sizeof(book));new_book->next=NULL;printf(">新增图书...\n");input_book(&(new_book->bi));p=get_last_book();if(p==NULL){ first_book=new_book;}else{ p->next=new_book;}printf(">继续添加图书吗?(y or n):");getchar();try_again=getchar();}}void view_book(){ book *p=NULL;char input='Y';int count=0;while(input=='y' || input=='Y'){ count=0;p=first_book;printf("+---------------------------------------+\n");printf("| 书名| 作者|\n");printf("+---------------------------------------+\n");while(p!=NULL){ printf("|%20s|%20s|\n",p->bi.book_name,p->bi.author);printf("+-------------------------------------+\n");count++;if(count==5){ count=0;printf(">显示下一页吗?(y or n):");getchar();input=getchar();if(input!='y' && input!='Y'){ break;}}p=p->next;}printf(">再次浏览图书吗?(y or n):");getchar();input=getchar();}}void search_book_by_name(){ book *p=NULL;char s[MAX_BOOK_NAME]={0};char input='Y';int count=0;int i=0;printf(">查找图书...\n");while(input=='Y' || input=='y'){ count=0;p=first_book;memset(s,0,MAX_BOOK_NAME);printf(">请输入书名(最大长度为%d):",MAX_BOOK_NAME);scanf("%s",s);while(p!=NULL){ if(findstr(p->bi.book_name,s)!=-1){ show_book(&(p->bi));count++;}p=p->next;}if(count==0){ printf(">没有找到图书%s。
图书管理系统的设计(C语言)
图书管理系统设计图书管理信息包括:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等功能描述:1 .新进熟土基本信息的输入2 .图书基本信息的查询3 .对撤销图书信息的删除4 .为借书人办理注册5 .办理借书手续6 .办理换书手续要求:以文件方式存储数据,系统以菜单方式工作。
这是本人大一第二学期初 C 语言课程设计的作品,嘿嘿,本来以为已经找不到原稿了,今天无意中居然在QQ 网络硬盘中找到了当初的teta 版,发布于此,以作记念。
C 源代码如下:#include〈stdio 。
h〉#include<stdlib。
h〉#include〈string 。
h>struct book {char book_name [30];int bianhao;double price;char author[20];char state [20] ;char name[20];char sex [10];int xuehao;struct book *book_next;};struct club {char name [20];char sex[10];int xuehao;char borrow [30];struct club *club_next;};void Print_Book(struct book *head_book);/*浏览所有图书信息*/void Print_Club(struct club *head_club);/*浏览所有会员信息*/struct book *Create_New_Book();/*创建新的图书库, 图书编号输入为0 时结束*/struct book *Search_Book_bianhao(int bianhao,struct book *head_book);struct book *Search_Book_name (char *b_name,struct book *head_book);struct book *Search_Book_price (double price_h,double price_l,struct book *head_book);struct book *Insert_Book (struct book *head_book,struct book *stud_book) ;/*增加图书,逐个添加*/struct book *Delete_Book(struct book *head_book,int bianhao);/*删除图书*/struct club *Create_New_Club() ;struct club *Search_Club_xuehao(int xuehao,struct club *head_club);struct club *Search_Club_name (char *c_name,struct club *head_club);struct club *Insert_Club (struct club *head_club,struct club *stud_club);struct club *Delete_Club (struct club *head_club,int xuehao);struct book *Lent_Book (int bianhao ,int xuehao,struct book *head_book,struct club *head_club);struct book *back (int bianhao,int xuehao,struct book *head_book,struct club *head_club); int main(){struct book *head_book,*p_book;char book_name [30],name [20],author [20],sex [10];int bianhao;double price,price_h,price_l;int size_book=sizeof(struct book);int m=1,n=1,f;char *b_name,*c_name;struct club *head_club,*p_club;int xuehao;int size_club=sizeof (struct club) ;int choice;printf ("\n 欢迎您第一次进入图书管理系统!\n\n");printf("---——>[向导]————-〉[新建图书库] \n\n”) ;printf ("注意:当输入图书编号为0 时,进入下一步.\n\n");head_book=Create_New_Book();system(”cls”) ;printf("\n 欢迎您第一次进入图书管理系统!\n\n") ;printf("----—〉[向导]——---〉[新建会员库]\n\n”);printf(”注意:当输入会员学号为0 时,进入主菜单.\n\n”);head_club=Create_New_Club () ;system (”cls”);do {printf(”\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n”);printf("\n”);printf ("\t\t\t[1] :借书办理\t");printf(" [6]:还书办理\n”);printf (”\n");printf(”\t\t\t[2]:查询图书\t");printf(" [7]:查询会员\n”);printf (” \t\t\t[3]:添加图书\t");printf (" [8]:添加会员\n”);printf ("\t\t\t[4]:删除图书\t");printf (” [9] :删除会员\n") ;printf (” \t\t\t[5]:遍历图书\t");printf (” [10]:遍历会员\n\n”) ;printf ("\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\n”);printf("\t\t\t0:退出\n\n”) ;printf(”请选择〈0~10〉:”);scanf(”%d",&choice);switch(choice) {case 1:printf ("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");printf (”输入所借图书编号:\n");scanf (”%d",&bianhao);printf ("输入借书人的学号:\n”);scanf ("%d",&xuehao);head_book=Lent_Book(bianhao,xuehao,head_book,head_club);system (”cls");printf (” \n 借阅成功!\n\n");printf (”相关信息如下:\n\n");head_book=Search_Book_bianhao (bianhao,head_book);break;case 2:system ("cls”) ;printf(”\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n”); printf ("1。
图书管理系统代码
图书管理系统代码//***********************//图书馆管理系统//***********************#include<stdio.h>#include<string.h>#include<malloc.h>#define null 0#define max 65536static int n;//*********************// 图书结构体//*********************typedef struct{char num[10]; //书号char name[9]; //书名char addr[31]; //作者int Nowcounter; //现存量int Allcounter; //总库存量}datatype;datatype *x[max]; //定义两个指针数组datatype *p;//*****************************//图书功能函数列表//*****************************void redo(); //主递归函数void creatlist(datatype *x[]); //图书建立函数int menu_select(); //功能菜单函数void find(datatype *x[],int n); //查找函数void delnode(datatype *x[]); //插入函数void printlist(datatype *x[]); //显示函数void jieyue(datatype *x[],int n); //借阅函数void guihuan(datatype *x[],int n); //归还函数//*****************************//主递归函数程序//*****************************void redo(){int i=0,j,n1,k=0,flage;for( ; ;){switch( menu_select()){case 1: //选项1的实现printf("***********************\n");printf("* 图书的建立*\n");printf("***********************\n");creatlist(x);break;case 2: //选项2的实现printf("***********************\n");printf("* 新图书信息的添加*\n");printf("***********************\n");printf(" 插入的个数:");scanf("%d",&n1); //输入插入新图书的个数for(i=0;i<n1;i++){flage=0;p=(datatype *)malloc(sizeof(datatype)); //分配一个节点空间printf(" 书名: ");scanf("%s",p->name); //输入插入书的书名if(flage==0){for(j=0;j<n;j++){if(strcmp(x[j]->name,p->name) == 0 )//调用比较函数查看书名是否已知{x[j]->Allcounter++;x[j]->Nowcounter++;flage=1;}}if(flage==0){n++;printf(" 第%d 个图书数据:\n",n); //插入新的图书p=(datatype *)malloc(sizeof(datatype));x[n-1]=p;printf(" 书名:");scanf("%s",x[n-1]->name); //输入书名printf(" 编号:");scanf(" %s",x[n-1]->num); //输入书号printf(" 作者:");scanf(" %s",x[n-1]->addr); // 输入作者名printf(" 总库存量:");scanf("%d",&x[n-1]->Allcounter); //输入总库存量x[n-1]->Nowcounter=x[n-1]->Allcounter;}}}break;case 3:printf("***********************\n");printf("* 图书信息的查询*\n");printf("***********************\n");find(x,n);break;case 4:printf("************************\n");printf("* 图书信息的删除*\n");printf("************************\n");delnode(x);break;case 5:printf("************************\n");printf("* 图书信息的显示*\n");printf("************************\n");printlist(x);break;case 6:printf("************************\n");printf(" 图书的借阅\n");printf("************************\n");jieyue(x,n);break;case 7:printf("************************\n");printf(" 图书的归还\n");printf("************************\n");guihuan(x,n);break;case 0:printf("\t 谢谢使用,再见! \n");return;}}//*************************//主函数程序//*************************void main (){redo(); //调用主递归函数}//*************************//功能菜单函数//*************************int menu_select(){int i;printf(" 欢迎进入图书管理系统!\n");printf("===========================\n");printf(" 1. 图书信息的采集\n");printf(" 2. 新图书的插入\n");printf(" 3. 图书信息的查询\n");printf(" 4. 图书的删除\n");printf(" 5. 图书的显示\n");printf(" 6. 图书的借阅\n");printf(" 7. 图书的归还\n");printf(" 0. 退出管理系统\n");printf("===========================\n");printf(" 请选择0-7: ");scanf("%d",&i);while(i<0||i>7){printf("\n\t输入出错,重选0-7: ");scanf("%d",&i);}return i;}//********************************// 建立链表图书建造函数//********************************void creatlist(datatype *x[]){int i;printf(" 请输入要建立图书的个数:");scanf("%d",&n);for(i=0;i<n;i++)printf(" 第%d 个图书数据:\n",i+1);p=(datatype *)malloc(sizeof(datatype)); //分配一个节点空间x[i]=p;printf(" 书名:"); //输入图书各项内容scanf("%s",x[i]->name);printf(" 编号:");scanf(" %s",x[i]->num);printf(" 作者:");scanf(" %s",x[i]->addr);printf(" 总库存量:");scanf("%d",&x[i]->Allcounter);x[i]->Nowcounter=x[i]->Allcounter;}}//**********************************// 查找函数程序//*********************************void find(datatype *x[],int n){char num[10];char name[9];int t,i;printf("=================\n"); //输出查找方式printf(" 1.按编号查询\n");printf(" 2.按书名查询\n");printf("=================\n");printf(" 请选择: ");scanf("%d",&t); //输入选择信息if(t==1){printf(" 请输入要查找者的编号: ");scanf("%s",num); //输入书号for(i=0;i<n;i++){if(strcmp(x[i]->num,num)==0) //调用strcmp函数{printf(" 编号书名作者现库存量总库存量\n");//输出要查询书的信息printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i]->Nowcounter,x[i]->Allcounter);elsecontinue;}}else{printf(" 请输入要查询的书名: ");scanf("%s",name); // 输入书名for(i=0;i<n;i++){if(strcmp(x[i]->name,name)==0){printf("编号书名作者现库存量总库存量\n"); //输出要查询书的信息printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i ]->Nowcounter,x[i]->Allcounter);}elsecontinue;}}}//******************************//删除函数程序//******************************void delnode(datatype *x[]){char num1[10],name1[10]; //定义两个字符数组int i,j,m=1,p;printf(" 1.按编号删除\n"); //输出选择方式printf(" 2.按书名删除\n");printf(" 3.返回\n");printf(" 请选择:\n");scanf("%d",&p); //输入选择信息if(p>3||p<1){printf(" 您的输入有误,请重新输入!\n");scanf("%d",&p); //重新输入选择信息}switch(p) //实现删除程序{case 1:printf(" 输入要删除书的编号:\n");scanf(" %s",num1);for(i=0;i<n;i++){if(strcmp(x[i]->num,num1)==0) //调用strcmp函数{m=0;n--;for(j=i;j<n;j++)x[j]=x[j+1]; //将该书信息删除printf(" 该书已删除!\n");}}if(m==1)printf(" 没有这样的的图书\n");break;case 2:printf(" 输入要删除书的名字:\n");scanf("%s",&name1);for(i=0;i<n;i++){if(strcmp(x[i]->name,name1)==0) //调用strcmp函数{m=0;n--;for(j=i;j<n;j++) //将该书信息删除x[j]=x[j+1];printf(" 该书已删除!\n");}}if(m==1)printf(" 没有这样的的图书\n");break;case 3:break;}}//////////////////////////////借阅函数程序/////////////////////////void jieyue(datatype *x[],int n){int i,m=1,p;char name1[10],num1[10]; //定义两个字符数组printf(" 1.按名字借阅\n"); //输出选择方式printf(" 2.按编号借阅\n");printf(" 3.返回\n");printf(" 请选择\n");scanf("%d",&p); //输入选择信息if(p>3||p<1){printf(" 您的输入有误!\n");scanf("%d",&p); //重新输入选择信息}switch(p) //实现查询程序{case 1:printf(" 请输入你要的书的名字!\n");scanf("%s",&name1); // 输入书名for(i=0;i<n;i++){if(strcmp(x[i]->name,name1)==0) //调用strcmp函数{m=0;if(x[i]->Nowcounter!=0)x[i]->Nowcounter--;printf(" 借书成功!\n");if(x[i]->Nowcounter==0)printf(" 这本书已经没有了\n");}}if(m==1)printf(" 您要的书不存在!\n");break;case 2:printf(" 请输入你要的书的编号!\n");scanf("%s",&num1); // 输入书号for(i=0;i<n;i++){if(strcmp(x[i]->num,num1)==0) //调用strcmp函数{m=0;if(x[i]->Nowcounter!=0)x[i]->Nowcounter--; //现存书数量减1printf(" 借书成功!\n");if(x[i]->Nowcounter==0)printf(" 这本书已经没有了\n");}}if(m==1)printf(" 您要的书不存在!\n");break;case 3:break;}}////////////////////////////归还程序//////////////////////void guihuan(datatype *x[],int n){int i,q,m=1;char name1[10],num1[10]; //定义两个字符数组printf(" 1.按书名归还\n"); //输出可选择方式printf(" 2.按书号归还\n");printf(" 3.返回\n");printf(" 请选择\n");scanf("%d",&q); //输入选择信息if(q>3||q<1){printf(" 您的输入有误!\n");scanf("%d",&q); //重新输入选择信息}switch(q) //实现归还程序{case 1:printf(" 输入归还书的书名: ");scanf("%s",&name1); // 输入书名for(i=0;i<n;i++){if(strcmp(x[i]->name,name1)==0){m=0;x[i]->Nowcounter++;printf("此书归还成功!\n");printf("此书的存储情况\n");printf("编号书名作者现存量总存量\n"); printf("===============================================\n");printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i]->Nowcounter,x[i]->Allcounter);printf("===============================================\n");}if(strcmp(x[i]->name,name1)==0)continue;}if(m==1)printf("此书不是图书馆的!\n");break;case 2:printf("输入归还书的书号\n");scanf("%s",&num1); // 输入书号for(i=0;i<n;i++){if(strcmp(x[i]->num,num1)==0){m=0;x[i]->Nowcounter++; //显存书增加1printf("此书归还成功!\n");printf("此书的存储情况\n");printf("编号书名作者现存量总存量\n"); printf("==============================================\n");printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i]->Nowcounter,x[i]->Allcounter);printf("==============================================\n");}if(strcmp(x[i]->num,num1)==0) //调用strcmp 函数continue;}if(m==1)printf("此书不是图书馆的!\n");break;case 3:break;}}//**************************************// 输出程序//**************************************void printlist(datatype *x[]){int i;printf("编号书名作者现存量总存量\n");//输出图书各项信息for(i=0;i<n;i++){printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i ]->Nowcounter,x[i]->Allcounter);}printf("===============================================\n");}。
C语言图书管理系统源代码
#include<stdio。
h〉#include<stdlib.h〉#include〈string。
h〉struct tushu{ /*图书结构体*/ char num[10]; /*编号*/char name[20];/*书名*/char writer[20];/*作者*/char press[20];/*出版社*/char kind[20];/*类别*/double time; /*时间*/double price;/*价格*/struct tushu *next;};struct stu /*学生结构体*/ {int snum;/*学号*/char mima[10]; /*密码*/struct stu *next;};FILE *fp; /*图书文件*/FILE *fp1; /*管理员信息文件*/ FILE *fp2; /*学生信息文件*/void menu();/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/void xmenu();/*学生主菜单(学生进入可对图书,密码进行操作)*/void gfind(); /*管理员查询(管理员可按一定的方式查询图书)*/void xfind();/*学生查询(学生可按一定的方式查询图书)*/ void secret();/*管理员权限(管理员登陆所用,输入错误次数过多自动退出)*/void sort();/*排序(管理员可按一定的方式对图书进行排序,排序完之后可选择文件进行保存)*/void fprint(struct tushu *head);/*保存(可追加的保存,如添加可用)*/void fprint_(struct tushu *head);/*保存(可覆盖保存如修改,删除,排序后用)*/void hfprint(struct tushu *head); /*还书保存(还书成功后自动保存到文件)*/void jfprint_(struct tushu *head);/*借书保存(借书成功之后自动从图书馆删除)*/struct tushu * Input(); /*图书添加(可进行图书的添加)*/struct tushu *create(); /*从文件创建链表(从文件中读出信息,建立单链表)*/void gBrowse(struct tushu *head);/*管理员浏览(对图书进行遍历)*/void xBrowse(struct tushu *head);/*学生浏览(学生对图书进行遍历)*/void count(struct tushu *head); /*统计数量(管理员可对图书进行统计)*/void Findofname(struct tushu *head); /*按书名查找*/ void Findofwriter(struct tushu *head); /*按作者查找*/void Findofkind(struct tushu *head); /*按类别查找*/void xFindofname(struct tushu *head);/*学生按书名查找*/void xFindofwriter(struct tushu *head);/*学生按作者查找*/ void xFindofkind(struct tushu *head); /*学生按类别查找*/ void Sort_time(struct tushu * head); /*按时间排序(管理员按时间对图书进行排序,排序完之后可选择文件进行保存)*/ void Sort_price(struct tushu *head); /*按价格排序*/void Sort_num(struct tushu * head);/*按编号排序*/ void Delete(struct tushu * head,char m[15]);/*按编号删除(管理员可按编号删除图书)*/void Revise(struct tushu *head);/*修改(管理员可对图书进行修改,并选择是否保存)*/void borrow(struct tushu *head); /*借书*/void huanshu(); /*还书(学生借完书之后进行还书,若没有图书则不能借)*/void gxinxi(); /*管理员信息(有管理员的账号及密码,可进行修改)*/void xmima(struct stu *head1);/*学生密码修改(学生可对自己的密码进行修改)*/struct stu *xcreate();/*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/void xsecret(struct stu *head1);/*学生权限(学生登陆所用)*/void menu() /*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/{int choice,n=0;struct tushu *head;struct stu *head1,*p;char m[15];there:printf("┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n"); printf(" ┃┃socat 图书管理系统printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(" ┃●[0]退出系统┃\n");printf(” ┃┃\n”);prin tf(” ┃●[1]帮助┃\n");printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n");printf(” ┃●[3]统计图书数目┃\n”);printf(" ┃┃\n”);printf(” ┃●[4]查询┃\n”);printf(” ┃printf(” ┃●[5]添加┃\n");printf(” ┃┃\n”);printf(” ┃●[6]排序┃\n");printf(” ┃┃\n");printf(" ┃●[7]修改┃\n”);printf(” ┃┃\n");printf(" ┃●[8]删除┃\n”);printf(" ┃┃\n”);printf(" ┃●[9]修改账号及密码┃\n");printf(” ┃┃\n”);printf(” ┃●[10]学生信息printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");printf(” 请选择:”);fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//help();printf(”没有内容!\n”);system("pause”);system(”cls”);menu();}else if(choice==2){system(”cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause");system("cls");menu();}gBrowse(head);}else if(choice==3){system(”cls");count(head);}else if(choice==4){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause”);system(”cls”);menu();}gfind();}else if(choice==5){Input();}else if(choice==6){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”); system("pause”);system(”cls”);menu();}sort(head);}else if(choice==7){system("cls”);if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause");system("cls”);menu();}Revise(head);}else if(choice==8){if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause");system(”cls");menu();}printf(" 请输入想要删除的图书编号:”);scanf(”%s",m);Delete(head,m);}else if(choice==9){gxinxi();else if(choice==10){system(”cls”);head1=xcreate();if(head1==NULL){printf("没有学生信息,请到xuesheng_list.txt添加!\n”); sys tem(”pause”);system(”cls”);menu();}for(p=head1;p!=NULL;p=p—>next){printf(”学生学号密码\n”);printf("%d %s\n",p->snum,p—>mima);}system(”pause”);system("cls”);menu();}else if(choice==0)system(”cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);exit(0);}else{system("cls");printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ");system("pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");system(”pause");exit(0);}goto there;}}void xmenu()/*学生主菜单(学生进入可对图书,密码进行操作)*/{struct tushu *head;struct stu *head1;int choice,n=0;there:printf(”┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(” ┃●[0]退出系统┃\n”);printf(” ┃printf(” ┃●[1]帮助┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n”);printf(" ┃●[3]查询┃\n”);printf(” ┃┃\n”);printf(” ┃●[4]借书┃\n");printf(” ┃┃\n”);printf(" ┃●[5]还书┃\n");printf(" ┃┃\n”);printf(” ┃●[6]修改密码printf("┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”); printf(" 请选择:");fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//xhelp();printf(”没有内容!\n");system(”pa use");system(”cls”);xmenu();}else if(choice==2){system("cls");if(head==NULL){printf(”没有图书!\n");system("pause”);xmenu();}xBrowse(head);}else if(choice==3){if(head==NULL){printf(”没有图书!\n”);system(”pause”);system(”cls”);xmenu();}xfind();}else if(choice==4){if(head==NULL){printf(”没有图书!\n");system(”pause”);xmenu();}borrow(head);}else if(choice==5){huanshu(head);}else if(choice==6){system("cls”);head1=xcreate();if(head1==NULL){printf(”学生信息被清空!!\n”);system("pause");system("cls”);xmenu();}xmima(head1); ;}else if(choice==0){system("cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");exit(0);}else{system("cls”);printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void gfind()/*管理员查询(管理员可按一定的方式查询图书)*/{int choice,n=0;struct tushu *head;there:system(”cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书借阅系统┃┃\n”);printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");printf(" ┃●[0]返回┃\n");printf(" ┃┃\n”);printf(" ┃●[1]按书名查找┃\n”);printf(" ┃┃\n”);printf(" ┃●[2]按作者查找┃\n”);printf(” ┃┃\n”);printf(" ┃●[3]按类别查找┃\n”);printf(" ┃┃\n”);printf(" ┃● ┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf(”%d”,&choice);if(choice==1){system(”cls");Findofname(head); }else if(choice==2){system(”cls”); Findofwriter(head); }else if(choice==3){system(”cls");Findofkind(head); }else if(choice==0){system(”cls”);menu();}else{system(”cls”);printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system("pause");system(”cls");n++;if(n==3){printf(" \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system(”pause”);exit(0);}goto there;}}void xfind()/*学生查询(学生可按一定的方式查询图书)*/ {struct tushu *head;int choice,n=0;there:system("cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书借阅系统┃┃\n”);printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");printf(” ┃●[0]返回┃\n”);printf(” ┃┃\n");printf(" ┃●[1]按书名查找┃\n”);printf(” ┃┃\n”);printf(" ┃●[2]按作者查找┃\n”);printf(" ┃┃\n");printf(” ┃●[3]按类别查找┃\n");printf(” ┃┃\n”);printf(" ┃● ┃\n");printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n"); printf(” 请选择:");fflush(stdin);head=create();scanf(”%d",&choice);if(choice==1){system(”cls”);xFindofname(head);}else if(choice==2){system(”cls”);xFindofwriter(head);}else if(choice==3){system("cls");xFindofkind(head);}else if(choice==0){system(”cls");xmenu();}else{system("cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls");n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void sort(){struct tushu *head;int choice,n=0;there:system("cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(" ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n”);printf(" ┃●[0]返回┃\n”);printf(” ┃┃\n");printf(” ┃●[1]按时间排序┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]按价格排序┃\n");printf(" ┃┃\n”);printf(” ┃●[3]按编号排序┃\n”);printf(" ┃┃\n”);printf(” ┃●┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf("%d",&choice);if(choice==1){system("cls”); Sort_time(head);}else if(choice==2){sys tem(”cls");Sort_price(head);}else if(choice==3){system(”cls”);Sort_num(head); }else if(choice==0){system("cls”); menu();}else{system(”cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}struct tushu *Input(){struct tushu *p1,*p2,*head,*ptr;char num;int x,i=0;system("cls”);p1=(struct tushu *)malloc(sizeof(struct tushu));head=p1;p1-〉price=—1;while(i!=1){printf(”请输入编号,以’#’结束\n”);scanf("%s",p1—>num);if(strcmp(p1-〉num,”#")==0)i=1;while(i!=1){printf(”请依次输入书名作者出版社类别出版时间价格\n”); scanf(”%s%s%s%s%lf%lf”,p1—>name,p1—>writer,p1—〉press,p1-〉kind,&p1-〉time,&p1—〉price);p2=p1;p1=(struct tushu *)malloc(sizeof(struct tushu));p2—〉next=p1;break;}}if(p1-〉price!=-1)p2—〉next=NULL;elsehead=NULL;system("cls”);printf("\n\n\n\t\t\t图书信息输入结束!\n\n\n”);system(”pause”);system(”cls”);printf(”\n\n\n\t\t\t是否保存图书信息?(1。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.1程序设计代码登录模块if(username.Text.Trim()==""||password.Text.Trim()=="")MessageBox.Show("请输入用户名和密码","提示");else{if (radioManage.Checked == true){string strcon = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;"; //连接数据库的字符串,用于指定数据库地址,名称,账号,密码,连接方式SqlConnection sqlCon = new SqlConnection(strcon); //实例化并定义一个数据库连接sqlCon.Open(); //打开数据库连接string sql = "select * from login where usernum=usernum anduserpassword=suerpassword"; //定义要查询sql语句SqlCommand cmd = new SqlCommand(sql, sqlCon); //实例化并定义sql语句和数据库路径cmd.Parameters.Add("usernum", SqlDbType.NChar, 20); //定义cmd查询命令的字段属性,loginname sqldbtype nchar(20)cmd.Parameters.Add("suerpassword", SqlDbType.NChar, 20); //同上cmd.Parameters["usernum"].Value = username.Text; //将username中的text保存到变量loginnamecmd.Parameters["suerpassword"].Value = password.Text; //同上SqlDataReader dr = cmd.ExecuteReader();if (dr.Read()){this.Visible=false;Form2 Formmain = new Form2(); //应该是实例化一个主窗体的this.Hide(); //应该是切换到主窗口的或关闭自己的Formmain.Show(); //应该是打开一个主窗体的dr.Close();//关闭dr的数据库连接}else// if (dr.Read())读取失败则执行如下代码MessageBox.Show("密码错误,请重新输入!"); //显示提示信息}else if (radioPerson.Checked==true){string strcon = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;"; //连接数据库的字符串,用于指定数据库地址,名称,账号,密码,连接方式SqlConnection sqlCon = new SqlConnection(strcon); //实例化并定义一个数据库连接sqlCon.Open(); //打开数据库连接string sql1 = "select * from reader where usernum=usernum anduserpassword=suerpassword"; //定义要查询sql语句SqlCommand cmd1 = new SqlCommand(sql1, sqlCon); //实例化并定义sql语句和数据库路径cmd1.Parameters.Add("usernum", SqlDbType.NChar, 20); //定义cmd查询命令的字段属性,loginname sqldbtype nchar(20)cmd1.Parameters.Add("suerpassword", SqlDbType.NChar, 20); //同上cmd1.Parameters["usernum"].Value = username.Text; //将username中的text保存到变量loginnamecmd1.Parameters["suerpassword"].Value = password.Text; //同上mandText=sql1;SqlDataReader dr = cmd1.ExecuteReader();if (dr.Read()){this.Visible=false;Form9 Formmain = new Form9(); //应该是实例化一个主窗体的this.Hide(); //应该是切换到主窗口的或关闭自己的dr.Close();//关闭dr的数据库连接Formmain.Show(); //应该是打开一个主窗体的}elseMessageBox.Show("用户名或密码错ª误","警告");}elseMessageBox.Show("没有选择角色", "提示");}}添加图书代码SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;InitialCatalog=lkl2;Integrated Security=True;");string str = "insert into dbo.bookvalues(bnum,bname,bauthor,bpublic,bclasses,benshu)";sqlcon.Open();SqlCommand cmd = new SqlCommand(str, sqlcon);cmd.Parameters.Add("bnum", SqlDbType.NChar, 20);cmd.Parameters.Add("bname", SqlDbType.NChar, 20);cmd.Parameters.Add("bauthor", SqlDbType.NChar, 20);cmd.Parameters.Add("bpublic", SqlDbType.NChar, 20);cmd.Parameters.Add("bclasses", SqlDbType.NChar, 20);cmd.Parameters.Add("benshu", SqlDbType.TinyInt);cmd.Parameters["bnum"].Value = bnum.Text;cmd.Parameters["bname"].Value = bname.Text;cmd.Parameters["bauthor"].Value = bauthor.Text;cmd.Parameters["bpublic"].Value = bpublic.Text;cmd.Parameters["bclasses"].Value = bclasses.Text;cmd.Parameters["benshu"].Value = benshu.Text;cmd.ExecuteNonQuery();sqlcon.Close();this.bnum.Clear();this.bname.Clear();this.bauthor.Clear();this.bpublic.Clear();this.benshu.Clear();this.bclasses.Clear();MessageBox.Show("添加成功!");删除图书代码SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;InitialCatalog=lkl2;Integrated Security=True");sqlcon.Open();string str = "delete from book where bnum=bnum";SqlCommand cmd = new SqlCommand(str, sqlcon);cmd.Parameters.Add("bnum", SqlDbType.NChar, 20);cmd.Parameters["bnum"].Value = this.tnum.Text;cmd.ExecuteNonQuery();sqlcon.Close();this.tnum.Clear();this.tno.Clear();this.tname.Clear();this.tpublisher.Clear();this.tauthor.Clear();this.tclasses.Clear();this.tbenshu.Clear();MessageBox.Show("删除成功!")查询图书代码SqlConnection con = new SqlConnection();//建立数据库连接con.ConnectionString = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;";con.Open();//打开连接SqlCommand cmd = new SqlCommand("select * from book where bname=bname", con);cmd.Parameters.Add("bname", SqlDbType.NChar, 20);cmd.Parameters["bname"].Value = bookname.Text;SqlDataAdapter da = new SqlDataAdapter(cmd);DataTable dt = new DataTable("图书记录表");da.TableMappings.Add("BorrowRecord", "借阅记录表");da.TableMappings[0].ColumnMappings.Add("bnum", "图书号");da.TableMappings[0].ColumnMappings.Add("bname", "图书名");da.TableMappings[0].ColumnMappings.Add("bauthor", "作者");da.TableMappings[0].ColumnMappings.Add("bpublic", "");da.TableMappings[0].ColumnMappings.Add("bclasses", "类别");da.TableMappings[0].ColumnMappings.Add("benshu", "本数");da.Fill(dt);dataGridView1.DataSource = dt;con.Close();图书更新代码SqlConnection con1 = new SqlConnection("Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True;");con1.Open();SqlCommand cmd1 = new SqlCommand("update book setbname=bname,bauthor=bauthor,bpublic=bpublic,bclasses=bclasses,benshu=benshu where bnum=bnum;", con1);cmd1.Parameters.Add("bnum", SqlDbType.NChar, 20);cmd1.Parameters.Add("bname", SqlDbType.NChar, 20);cmd1.Parameters.Add("bauthor", SqlDbType.NChar, 20);cmd1.Parameters.Add("bpublic", SqlDbType.NChar, 20);cmd1.Parameters.Add("bclasses", SqlDbType.NChar, 20);cmd1.Parameters.Add("benshu", SqlDbType.NChar, 20);cmd1.Parameters["bnum"].Value =um.Text;cmd1.Parameters["bname"].Value =ame.Text;cmd1.Parameters["bauthor"].Value = cauthor.Text;cmd1.Parameters["bpublic"].Value = cpublic.Text;cmd1.Parameters["bclasses"].Value = cclasses.Text;cmd1.Parameters["benshu"].Value = cbenshu.Text;cmd1.ExecuteNonQuery();con1.Close();um.Clear();ame.Clear();this.cauthor.Clear();this.cpublic.Clear();lasses.Clear();this.cbenshu.Clear();MessageBox.Show("更新成功!");添加用户代码SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;InitialCatalog=lkl2;Integrated Security=True;");string str = "insert into dbo.readervalues(usernum,username,userpassword,usertype)";sqlcon.Open();SqlCommand cmd = new SqlCommand(str, sqlcon);cmd.Parameters.Add("usernum", SqlDbType.NChar, 20);cmd.Parameters.Add("username", SqlDbType.NChar, 20);cmd.Parameters.Add("userpassword", SqlDbType.NChar, 20);cmd.Parameters.Add("usertype", SqlDbType.NChar, 20);cmd.Parameters["usernum"].Value =usernum.Text;cmd.Parameters["username"].Value = username.Text;cmd.Parameters["userpassword"].Value = userpassword.Text;cmd.Parameters["usertype"].Value = usertype.Text;cmd.ExecuteNonQuery();sqlcon.Close();ernum.Clear();ername.Clear();erpassword.Clear();ertype.Clear();MessageBox.Show("用户添加成功!"删除用户代码SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;InitialCatalog=lkl2;Integrated Security=True");sqlcon.Open();string str = "delete from reader where usernum=usernum";SqlCommand cmd = new SqlCommand(str, sqlcon);cmd.Parameters.Add("usernum", SqlDbType.NChar, 20);cmd.Parameters["usernum"].Value = this.num.Text;cmd.ExecuteNonQuery();sqlcon.Close();MessageBox.Show("删除成功!");修改密码代码SqlConnection con1 = new SqlConnection("Data Source=SIMON-VAIO;InitialCatalog=lkl2;Integrated Security=True;");con1.Open();SqlCommand cmd1 = new SqlCommand("update reader set userpassword=userpassword where usernum=usernum;", con1);cmd1.Parameters.Add("usernum", SqlDbType.NChar, 20);cmd1.Parameters.Add("userpassword", SqlDbType.NChar, 20);cmd1.Parameters["usernum"].Value = cusernum.Text;cmd1.Parameters["userpassword"].Value = cuserpassword.Text;cmd1.ExecuteNonQuery();con1.Close();this.cusernum.Clear();this.cuserpassword.Clear();MessageBox.Show("修改成功请从新登陆!");完善读者信息代码SqlConnection sqlcon = new SqlConnection("Data Source=SIMON-VAIO;InitialCatalog=lkl2;Integrated Security=True;");string str = "insert into dbo.readerifovalues(usernum,username,usersex,usergrade,telephone)";sqlcon.Open();SqlCommand cmd = new SqlCommand(str, sqlcon);cmd.Parameters.Add("usernum", SqlDbType.NChar, 20);cmd.Parameters.Add("username", SqlDbType.NChar, 20);cmd.Parameters.Add("usersex", SqlDbType.NChar, 20);cmd.Parameters.Add("usergrade", SqlDbType.NChar, 20);cmd.Parameters.Add("telephone", SqlDbType.NChar, 20);cmd.Parameters["usernum"].Value = usernum.Text;cmd.Parameters["username"].Value = username.Text;cmd.Parameters["usersex"].Value = usersex.Text;cmd.Parameters["usergrade"].Value = usergrade.Text;cmd.Parameters["telephone"].Value =telephone.Text;cmd.ExecuteNonQuery();sqlcon.Close();ernum.Clear();ername.Clear();erpassword.Clear();ertype.Clear();ersex.Clear();ergrade.Clear();this.telephone.Clear();MessageBox.Show("添加信息成功!");检索用户信息代码if (num.Text == ""){MessageBox.Show("请输入学生学号!");}else{string strcon = "Data Source=SIMON-VAIO;Initial Catalog=lkl2;Integrated Security=True";SqlConnection sqlCon = new SqlConnection(strcon);sqlCon.Open();string sql = "select * from readerifo where usernum=usernum ";SqlCommand cmd = new SqlCommand(sql, sqlCon);cmd.Parameters.Add("usernum", SqlDbType.NChar, 20);cmd.Parameters["usernum"].Value = num.Text;//创建 SqlDataReader,必须调用 SqlCommand 对象的 ExecuteReader 方法,而不要直接使用构造函数。