图书管理系统源码(C版)_第1页
图书管理系统源码(C版)_第2页
图书管理系统源码(C版)_第3页
图书管理系统源码(C版)_第4页
图书管理系统源码(C版)_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.登录界面:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespacebookpublicpartialclasslogin:Formpublicstringpassword;/用来储存密码publiclogin()InitializeComponent();privatevoidb

2、utton2_Click(objectsender,EventArgse)Application.Exit();privateboolyanzhengshuru()password=textBox3.Text;if(Typename.Text.Trim()=)MessageBox.Show(请选择登录种类,登录提示,MessageBoxButtons.OK,MessageBoxIcon.Information);Typename.Focus();returnfalse;elseif(loginid.Text.Trim()=)MessageBox.Show(请输入用户名,登录提示,Message

3、BoxButtons.OK,MessageBoxIcon.Information);loginid.Focus();returnfalse;elseif(password=)MessageBox.Show(请输入密码,登录提示,MessageBoxButtons.OK,MessageBoxIcon.Information);textBox3.Focus();word专业资料.returnfalse;elsereturntrue;privatevoidbutton1_Click(objectsender,EventArgse)userhelper.adminid=loginid.Text;/用户

4、账号password=textBox3.Text;/用户密码if(yanzhengshuru()if(Typename.Text.Trim()=管理员)stringsql=string.Format(Selectcount(*)fromadminwhereadminId=0andadminpass=1,loginid.Text,password);trySqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);Dbhelper.connection.Open();intcount=(int)command.ExecuteScalar();

5、if(count1)MessageBox.Show(用户或密码不存在!);/result=false;elseadminadmin=newadmin();admin.Show();catch(Exceptionex)MessageBox.Show(操作数据库犯错!);Console.WriteLine(ex.Message);finallyDbhelper.connection.Close();word专业资料.if(Typename.Text.Trim()=借阅者)userhelper.readerid=Convert.ToString(loginid.Text);stringsql=str

6、ing.Format(Selectcount(*)fromreaderwherereaderId=0andreaderpass=1,userhelper.readerid,textBox3.Text);try/创立Command对象SqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);翻开数据库连结Dbhelper.connection.Open();考证能否为合法用户intcount=(int)command.ExecuteScalar();if(count1)MessageBox.Show(用户或密码不存在!);/result=f

7、alse;elsereaderreader=newreader();reader.Show();catch(Exceptionex)MessageBox.Show(操作数据库犯错!);Console.WriteLine(ex.Message);/result=false;finally封闭数据库连结Dbhelper.connection.Close();privatevoidlogin_Load(objectsender,EventArgse)读者界面;word专业资料.usingSystem;usingSystem.Collections.Generic;usingSystem.Compon

8、entModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.Sql;usingSystem.Data.SqlClient;namespacebookpublicpartialclassreader:Formpublicreader()InitializeComponent();privatevoidbutton3_Click(objectsender,EventArgse)stringid=Convert.ToString(textBox1.T

9、ext);if(id!=userhelper.readerid)MessageBox.Show(输入账号与登岸账号不同样,请从头输入,提示,MessageBoxButtons.OK,MessageBoxIcon.Warning);textBox1.Text=;textBox1.Focus();elsetrystringsql=string.Format(updatereadersetislost=0wherereaderid=1,是,id);Dbhelper.connection.Open();SqlCommandcommand=newSqlCommand(sql,Dbhelper.conne

10、ction);intresult=command.ExecuteNonQuery();if(result1)MessageBox.Show(改正失败);elseMessageBox.Show(挂失成功);catchword专业资料.MessageBox.Show(error);finallyDbhelper.connection.Close();privatevoidtoolStripButton3_Click(objectsender,EventArgse)groupBox1.Visible=false;groupBox2.Visible=true;privatevoidtoolStripB

11、utton4_Click(objectsender,EventArgse)groupBox1.Visible=true;groupBox2.Visible=false;privatevoidbutton5_Click(objectsender,EventArgse)textBox2.Text=;textBox4.Text=;textBox5.Text=;privatevoidForm1_Load(objectsender,EventArgse)toolStrip1.Text=string.Format(学生:0,userhelper.readerid);privatevoidbutton4_C

12、lick(objectsender,EventArgse)stringid=Convert.ToString(textBox2.Text);if(id!=userhelper.readerid)MessageBox.Show(输入账号与登岸账号不同样,请从头输入,提示,MessageBoxButtons.OK,MessageBoxIcon.Warning);textBox1.Text=;textBox1.Focus();elseif(textBox4.Text!=textBox5.Text)MessageBox.Show(两次密码输入不一样);elsetryword专业资料.stringsql

13、=string.Format(updatereadersetreaderpass=0wherereaderid=1,textBox4.Text,id);Dbhelper.connection.Open();SqlCommandcommand=newSqlCommand(sql,Dbhelper.connection);intresult=command.ExecuteNonQuery();if(result1)MessageBox.Show(改正失败);elseMessageBox.Show(改正成功);catchMessageBox.Show(error);finallyDbhelper.c

14、onnection.Close();privatevoidtoolStripButton6_Click(objectsender,EventArgse)addreaderaddreader=newaddreader();addreader=newaddreader();privatevoidtoolStripButton1_Click(objectsender,EventArgse)readsearchbooksearchbook=newreadsearchbook();searchbook.Show();privatevoidtoolStripButton2_Click(objectsend

15、er,EventArgse)borrowa=newborrow();a.Show();privatevoidtoolStripButton5_Click(objectsender,EventArgse)readerseacherinfoa=newreaderseacherinfo();a.Show();privatevoid图书查问ToolStripMenuItem1_Click(objectsender,EventArgse)readsearchbooka=newreadsearchbook();a.Show();word专业资料.this.Close();privatevoid结束查问To

16、olStripMenuItem_Click(objectsender,EventArgse)borrowa=newborrow();a.Show();this.Close();privatevoid改正密码ToolStripMenuItem_Click(objectsender,EventArgse)groupBox1.Visible=false;groupBox2.Visible=true;privatevoid挂失ToolStripMenuItem_Click(objectsender,EventArgse)groupBox1.Visible=true;groupBox2.Visible=

17、false;privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)this.Close();privatevoidbutton2_Click(objectsender,EventArgse)Application.Exit();管理员界面;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.F

18、orms;namespacebookpublicpartialclassadmin:Formpublicadmin()InitializeComponent();word专业资料.privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)this.Close();privatevoidadmin_Load(objectsender,EventArgse)toolStrip1.Text=string.Format(管理员:登录,userhelper.adminid);privatevoidtoolStripButton4_Click

19、(objectsender,EventArgse)/录入学生信息addreaderaddreader=newaddreader();addreader.Show();this.Close();privatevoid借书信息ToolStripMenuItem_Click(objectsender,EventArgse)adminborrowa=newadminborrow();a.Show();privatevoid还书信息ToolStripMenuItem_Click(objectsender,EventArgse)adminborrowa=newadminborrow();a.Show();

20、privatevoid增添图书ToolStripMenuItem_Click(objectsender,EventArgse)addbooka=newaddbook();a.Show();privatevoid删除图书ToolStripMenuItem_Click(objectsender,EventArgse)adminearchbooka=newadminearchbook();a.Show();privatevoid查问图书ToolStripMenuItem_Click(objectsender,EventArgse)adminearchbooka=newadminearchbook()

21、;a.Show();privatevoid查问第一版社信息ToolStripMenuItem_Click(objectsender,EventArgse)publishera=newpublisher();a.Show();this.Close();word专业资料.privatevoid改正第一版社信息ToolStripMenuItem_Click(objectsender,EventArgse)publishera=newpublisher();a.Show();this.Close();privatevoid查问学生借阅信息ToolStripMenuItem_Click(objectse

22、nder,EventArgse)adminborrowa=newadminborrow();a.Show();privatevoidtoolStripButton6_Click_1(objectsender,EventArgse)/借书信息booksborrowa=newbooksborrow();a.Show();privatevoid增添ToolStripMenuItem_Click(objectsender,EventArgse)readerinfoa=newreaderinfo();a.Show();privatevoid删除ToolStripMenuItem_Click(object

23、sender,EventArgse)deletereadera=newdeletereader();a.Show();增添图书信息界面:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespacebookpublicpartialclassaddbook:Formpublicaddbo

24、ok()InitializeComponent();word专业资料.privatevoidaddbook_Load(objectsender,EventArgse)trystringsql1=selectbooktypenamefrombooktype;SqlCommandcommand=newSqlCommand(sql1,Dbhelper.connection);Dbhelper.connection.Open();SqlDataReaderdatareader=command.ExecuteReader();stringtypename=;while(datareader.Read()

25、typename=(string)datareader0;comboBox2.Items.Add(typename);datareader.Close();stringsql2=selectpublishernamefrompublisher;SqlCommandcommand1=newSqlCommand(sql2,Dbhelper.connection);/Dbhelper.connection.Open();SqlDataReaderdatareader1=command1.ExecuteReader();stringpublishername=;while(datareader1.Re

26、ad()publishername=(string)datareader10;/MessageBox.Show(publishername);comboBox1.Items.Add(publishername);datareader1.Close();catchMessageBox.Show(error);finallyDbhelper.connection.Close();privatevoidbutton2_Click(objectsender,EventArgse)textBox1.Text=null;textBox2.Text=null;textBox4.Text=null;word专

27、业资料.comboBox2.Text=null;comboBox1.Text=null;privatestringtypdid(stringa)stringid=;stringsqltypeid=string.Format(selectbooktypeidfrombooktypewherebooktypename=0,a);trySqlCommandcommand=newSqlCommand(sqltypeid,Dbhelper.connection);Dbhelper.connection.Open();id=Convert.ToString(command.ExecuteScalar();

28、catchMessageBox.Show(error);finallyDbhelper.connection.Close();returnid;privatestringpublisheid(stringa)stringid=;stringsqlpublisheid=string.Format(selectpublisheridfrompublisherwherepublishername=0,a);trySqlCommandcommand=newSqlCommand(sqlpublisheid,Dbhelper.connection);Dbhelper.connection.Open();i

29、d=Convert.ToString(command.ExecuteScalar();catchMessageBox.Show(error);finallyDbhelper.connection.Close();returnid;word专业资料.privatevoidbutton1_Click(objectsender,EventArgse)stringname=textBox1.Text;stringwritter=textBox2.Text;stringpublisher=comboBox1.Text;stringtype=comboBox2.Text;stringprice=textB

30、ox4.Text;/stringid=textBox5.Text;stringtypeid=typdid(type);stringpublisherid=publisheid(publisher);stringbianhao=textBox3.Text;tryif(bianhao!=&name!=&writter!=&publisher!=&type!=&price!=)Dbhelper.connection.Open();stringsql=string.Format(insertintobook(BOOKID,bookname,bookwritter,publisherid,booktyp

31、eid,bookprice)values(0,1,2,3,4,5),bianhao,name,writter,publisherid,typeid,price);SqlCommandcommmand=newSqlCommand(sql,Dbhelper.connection);intab=commmand.ExecuteNonQuery();if(ab!=0)MessageBox.Show(保留成功,保留);elseMessageBox.Show(增添失败);return;elseif(name=|writter=|publisher=|type=|price=)MessageBox.Show

32、(请输入所有信息,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);catch/(exceptionex)MessageBox.Show(操作数据库犯错,提示,MessageBoxButtons.OK,MessageBoxIcon.Information);word专业资料.finallyDbhelper.connection.Close();privatevoidbutton3_Click(objectsender,EventArgse)this.Close();增添读者信息界面:usingSystem;usingSystem.Collections

33、.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespacebookpublicpartialclassaddreader:Formpublicaddreader()InitializeComponent();/退出窗口privatevoidbutton3_Click(objectsender,EventArgse)/Application.Exit()

34、;this.Close();/消除所有容privatevoidbutton1_Click(objectsender,EventArgse)textBox1.Text=null;textBox2.Text=null;textBox4.Text=null;textBox3.Text=null;textBox5.Text=null;comboBox1.Text=null;comboBox2.Text=null;word专业资料.privatevoidbutton2_Click(objectsender,EventArgse)/连结数据库/定义变量stringname=textBox1.Text;st

35、ringage=textBox2.Text;stringsex=comboBox1.Text;stringstudentId=textBox3.Text;stringdept=textBox4.Text;stringzhuanye=textBox5.Text;stringmaxnumber=comboBox2.Text;stringpass=textBox6.Text;tryif(name!=&age!=&sex!=&studentId!=&dept!=&zhuanye!=&maxnumber!=&pass!=)Dbhelper.connection.Open();stringsql=stri

36、ng.Format(insertintoreader(readerid,readerpass,readername,readersex,readerage,readerdept,readerzhuanye,maxnumber)values(0,1,2,3,4,5,6,7),studentId,pass,name,sex,age,dept,zhuanye,maxnumber);SqlCommandcommmand=newSqlCommand(sql,Dbhelper.connection);intab=commmand.ExecuteNonQuery();if(ab!=0)MessageBox.

37、Show(保留成功,保留);elseMessageBox.Show(增添失败);return;elseif(name=|age=|sex=|studentId=|dept=|zhuanye=|maxnumber=)MessageBox.Show(请输入所有学生信息,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);catch/(exceptionex)MessageBox.Show(操作数据库犯错,提示,MessageBoxButtons.OK,MessageBoxIcon.Information);/Console.WriteLine(ex);wor

38、d专业资料.finallyDbhelper.connection.Close();privatevoidbutton4_Click(objectsender,EventArgse)readerinfoa=newreaderinfo();a.Show();查问图书界面:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Dat

39、a.SqlClient;namespacebookpublicpartialclassadminborrow:FormprivateDataSetdataset=newDataSet();privateSqlDataAdapterdataadapter;publicadminborrow()InitializeComponent();privatevoidbutton2_Click(objectsender,EventArgse)if(comboBox1.Text=个人)trystringid=textBox1.Text;stringsql=string.Format(selectreader

40、id,bookid,borrowtime,returntime,outtimefromborrowwherereaderid=0,id);dataadapter=newSqlDataAdapter(sql,Dbhelper.connection);dataadapter.Fill(dataset,borrow);dataGridView1.DataSource=dataset.Tablesborrow;catchMessageBox.Show(error);word专业资料.finallyDbhelper.connection.Close();elsetrystringid=textBox1.

41、Text;stringsql=string.Format(selectreaderid,bookid,borrowtime,returntime,outtimefromborrow);dataadapter=newSqlDataAdapter(sql,Dbhelper.connection);dataadapter.Fill(dataset,borrow);dataGridView1.DataSource=dataset.Tablesborrow;catchMessageBox.Show(error);finallyDbhelper.connection.Close();privatevoid

42、button1_Click(objectsender,EventArgse)groupBox1.Visible=true;privatevoidbutton3_Click(objectsender,EventArgse)dataset.Tablesborrow.Clear();privatevoidbutton4_Click(objectsender,EventArgse)stringrid=textBox2.Text;stringbid=textBox3.Text;tryif(rid!=&bid!=)Dbhelper.connection.Open();word专业资料.stringsql=

43、string.Format(updateborrowsetreturntime=getdate(),outtime=已还wherereaderid=0andbookid=1andouttime=否,rid,bid);SqlCommandcommmand=newSqlCommand(sql,Dbhelper.connection);intab=commmand.ExecuteNonQuery();stringsql1=string.Format(updatebooksetifborrow=否wherebookid=0,bid);SqlCommandco=newSqlCommand(sql1,Db

44、helper.connection);intc=co.ExecuteNonQuery();if(ab!=0&c!=0)MessageBox.Show(还书成功,保留);elseMessageBox.Show(还书失败);return;elseif(rid=|bid=)MessageBox.Show(请输入所有信息,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);catch/(exceptionex)MessageBox.Show(操作数据库犯错,提示,MessageBoxButtons.OK,MessageBoxIcon.Information);/

45、Console.WriteLine(ex);finallyDbhelper.connection.Close();usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespacebookword专业资料.publicpartialclassadminearchbook:Formprivat

46、eDataSetdataset=newDataSet();privateSqlDataAdapterdataadapter;publicadminearchbook()InitializeComponent();privatevoidbutton1_Click(objectsender,EventArgse)trystringsql;if(comboBox1.Text=书名)sql=string.Format(selectbookid,bookname,bookwritter,booktype.booktypename,bookprice,booktype.flow,publisher.pub

47、lishername,ifborrowfrombook,booktype,publisherwherebook.booktypeid=booktype.booktypeidandbook.publisherid=publisher.publisheridandbookname=0,textBox1.Text);elseif(comboBox1.Text=作者)sql=string.Format(selectbookid,bookname,bookwritter,booktype.booktypename,bookprice,booktype.flow,publisher.publisherna

48、me,ifborrowfrombook,booktype,publisherwherebook.booktypeid=booktype.booktypeidandbook.publisherid=publisher.publisheridandbookwritterlike%0%,textBox1.Text);elseif(comboBox1.Text=第一版社)sql=string.Format(selectbookid,bookname,bookwritter,booktype.booktypename,bookprice,booktype.flow,publisher.publisher

49、name,ifborrowfrombook,booktype,publisherwherebook.booktypeid=booktype.booktypeidandbook.publisherid=publisher.publisheridandbookTypeNamelike%0%,textBox1.Text);elseif(comboBox1.Text=类型)sql=string.Format(selectbookid,bookname,bookwritter,booktype.booktypename,bookprice,booktype.flow,publisher.publword

50、专业资料.ishername,ifborrowfrombook,booktype,publisherwherebook.booktypeid=booktype.booktypeidandbook.publisherid=publisher.publisheridandpublisherNamelike%0%,textBox1.Text);elsesql=selectbookid,bookname,bookwritter,booktype.booktypename,bookprice,booktype.flow,publisher.publishername,ifborrowfrombook,b

51、ooktype,publisherwherebook.booktypeid=booktype.booktypeidandbook.publisherid=publisher.publisherid;dataadapter=newSqlDataAdapter(sql,Dbhelper.connection);dataadapter.Fill(dataset,book);dataGridView1.DataSource=dataset.Tablesbook;catchMessageBox.Show(error);finallyDbhelper.connection.Close();privatev

52、oidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)if(comboBox1.Text=书名)label2.Visible=true;label3.Visible=false;label4.Visible=false;label5.Visible=false;elseif(comboBox1.Text=作者)label2.Visible=false;label3.Visible=true;label4.Visible=false;label5.Visible=false;elseif(comboBox1.Text=第一版社)lab

53、el2.Visible=false;word专业资料.label3.Visible=false;label4.Visible=true;label5.Visible=false;elseif(comboBox1.Text=类型)label2.Visible=false;label3.Visible=false;label4.Visible=false;label5.Visible=true;elselabel2.Visible=false;label3.Visible=false;label4.Visible=false;label5.Visible=false;privatevoidbutt

54、on2_Click(objectsender,EventArgse)dataset.Tablesbook.Clear();/dataadapter.Fill(dataset,book);privatevoidbutton3_Click_1(objectsender,EventArgse)if(textBox2.Text!=)tryDbhelper.connection.Open();stringsql1=string.Format(deletefromborrowwherebookid=0,textBox2.Text);SqlCommandcon=newSqlCommand(sql1,Dbhe

55、lper.connection);intc=con.ExecuteNonQuery();stringsql=string.Format(deletefrombookwherebookid=0,textBox2.Text);SqlCommandcommmand=newSqlCommand(sql,Dbhelper.connection);intab=commmand.ExecuteNonQuery();if(c!=0&ab!=0)MessageBox.Show(删除成功,保留);elseMessageBox.Show(删除失败);word专业资料.return;catch(Exceptionex

56、)MessageBox.Show(ex.ToString();finallyDbhelper.connection.Close();elseMessageBox.Show(请输入图书编号!);借书界面:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespacebookpublicpa

57、rtialclassbooksborrow:Formpublicbooksborrow()InitializeComponent();privatevoidbutton1_Click(objectsender,EventArgse)stringrid=textBox1.Text;stringbid=textBox2.Text;tryif(rid!=&bid!=)Dbhelper.connection.Open();stringsql=string.Format(insertintoborrow(readerid,bookid)values(0,1),rid,bid);SqlCommandcom

58、mmand=newSqlCommand(sql,Dbhelper.connection);word专业资料.intab=commmand.ExecuteNonQuery();stringsql1=string.Format(updatebooksetifborrow=是wherebookid=0,bid);SqlCommandco=newSqlCommand(sql1,Dbhelper.connection);intc=co.ExecuteNonQuery();if(ab!=0&c!=0)MessageBox.Show(借阅成功,保留);elseMessageBox.Show(增添失败);re

59、turn;elseif(rid=|bid=)MessageBox.Show(请输入所有信息,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);catch/(exceptionex)MessageBox.Show(操作数据库犯错,提示,MessageBoxButtons.OK,MessageBoxIcon.Information);/Console.WriteLine(ex);finallyDbhelper.connection.Close();privatevoidbutton2_Click(objectsender,EventArgse)this.C

60、lose();usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;word专业资料.usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespacebookpublicpartialclassborrow:FormprivateDataSetdataset=newDataSet();privateSqlDataAdapterdataadap

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论