1、C#面向对象程序设计课程设计图书借阅管理系统源码下载地址:院 系:计算机学院专 业:计算机科学和技术年 级:级学生姓名:/ 学 号:/教 师:/日 期: 6月6日开发和运行环境- 开发环境:Windows 10-1703;- 开发工具:Visual Studio 013 Update5;- 数据库工具:Mysql 5.7 + NaviCat;- 运行环境:Windows 10-1703;需求分析1.【角色】用户经过【注册】成为本系统可访问组员,经过【登陆】进入系统。用户能够操作功效有:-查看图书馆全部图书信息,图书是否可借阅信息;-搜索功效:经过输入关键字,来查找是否有自己需要图书;-借阅功效
2、:未被其它用户借阅书籍能够直接借阅;-还书功效:若存在之前借阅书籍,在未归还情况下,能够进行还书操作,若未存在需要还书籍,提醒:未有需要归还书籍;-个人信息:修改除了【用户名】以外之前注册全部信息;-借阅信息:能够查看借阅历史,曾经借书日期和还书日期,是否有未归还书等等;2.【角色】管理员经过【登陆】进入用户进入不了管理系统。管理员能够操作功效有:-图书信息修改:修改除了图书名现有全部图书信息;-添加图书:添加新图书;-查看用户信息:能够查看用户表部分用户信息;3数据保留:需要长久保留在数据库数据有:-图书信息:图书基础信息;-读者信息:读者基础信息;-借阅信息:图书借阅信息;-帐号信息:图书
3、管理员和读者登录帐号; 系统步骤图(不包含注册功效)数据库设计说明- 管理员表:adminInfo;- 图书信息表:bookInfo;- 借阅信息表:borrowed;- 用户信息表:userInfo;adminInfo表列名数据类型可否为空长度说明adminIdint否11管理员IDadminNamevarchar否255管理员用户名adminPasswordvarchar否255管理员密码bookInfo表列名数据类型可否为空长度说明bookIdint否11图书编号IDbookNamevarchar否255图书名bookAuthorvarchar否255图书作者bookPriceint否1
4、1图书价格bookPressvarchar否255图书出版社bookTypevarchar是255图书类型isBorrowedtinyint是11是否被借阅borrowIdint是11借阅人IDBorrowedTimedatetime是0被借阅时间borrowed表列名数据类型可否为空长度说明borrowedIdint否11借阅信息IDuserIdint是11操作人IDuserNamevarchar是255操作人用户名bookIdint是11图书IDeditTimedatatime是0操作时间bookNamevarchar是255图书名editvarchar是255操作名UserInfo表列名
5、数据类型可否为空长度说明userIdint否11用户IDuserNamevarchar否255用户名userPasswordvarchar否255用户密码userSexvarchar是255用户性别模块分析cs文件:主界面:关键显示代码 mainCenter.cs :public mainCenter() InitializeComponent(); string sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /依据自己设置 MySqlConnection conn = new MyS
6、qlConnection(sql); conn.Open();/打开数据库连接 MySqlDataAdapter data1 = new MySqlDataAdapter();/实例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(SELECT bookName as 图书名,bookAuthor as 作者,bookPrice as 图书价格,bookPress as 出版社,bookType as 图书类型,(CASE isBorrowed WHEN 0 THEN 未借阅 ELSE 已借阅 END) as借阅情况 FROM c#libr
7、arycenter.bookinfo, conn);/sql语句 data1.SelectCommand = cmd1;/设置为已实例化SqlDataAdapter查询命令 DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把数据填充到datatable dataGridView1.DataSource = dt;/将数据集绑定datagridview,完成显示 dataGridView1.AllowUserToAddRows = false; / login login = new login(); label1.Text
8、 = 这里是SMART-LIBRARY!用户: + login.username; / 查找功效:关键实现代码:private void button1_Click(object sender, EventArgs e) String so = textBox1.Text; String sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /依据自己设置 MySqlConnection conn = new MySqlConnection(sql); conn.Open();/打开数据库连接
9、 MySqlDataAdapter data1 = new MySqlDataAdapter();/实例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(SELECT bookName as 图书名,bookAuthor as 作者,bookPrice as 图书价格,bookPress as 出版社,bookType as 图书类型,(CASE isBorrowed WHEN 0 THEN 未借阅 ELSE 已借阅 END) as借阅情况 FROM c#librarycenter.bookinfo where bookName like
10、%+ so +% , conn);/sql语句 data1.SelectCommand = cmd1;/设置为已实例化SqlDataAdapter查询命令 /DataSet ds1 = new DataSet();/实例化dataset DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把数据填充到datatable dataGridView1.DataSource = dt;/将数据集绑定datagridview,完成显示 dataGridView1.AllowUserToAddRows = false; 借阅功效:关键实
11、现代码 - borrow.cs:private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) int r = this.dataGridView1.CurrentRow.Index; string h = this.dataGridView1.Rowsr.Cells1.Value.ToString(); string s = this.dataGridView1.Rowsr.Cells2.Value.ToString(); / login login = new login();
12、String userId = ; DateTime dt = DateTime.Now; String borrowedTime = dt.ToString(yyyy-MM-dd HH:mm:ss); string sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /依据自己设置 MySqlConnection conn = new MySqlConnection(sql); String updateBorrow1 = select userId from userInfo where
13、 userName = +login.username+; MySqlCommand mysqlcommand = new MySqlCommand(updateBorrow1,conn); conn.Open(); MySqlDataReader mdr = mysqlcommand.ExecuteReader(); if (mdr.Read() userId = mdr.GetString(0).ToString(); mdr.Close(); String updateBorrow2 = update bookInfo set isBorrowed = 1, borrowId = + u
14、serId + ,borrowedTime = + borrowedTime + where bookId = + h + ; / MySqlCommand mysqlcommand2 = new MySqlCommand(updateBorrow2, conn); int i = mysqlcommand2.ExecuteNonQuery(); if (i != -1) MessageBox.Show(login.username + rn恭喜你借 + rn这本书 + 成功); else MessageBox.Show(系统出了点问题,请联络管理员!); /更新借阅表 String upda
15、teBorrow3 = insert into borrowed(userId,userName,bookId,editTime,bookName,edit) values( + userId + , + login.username + , + h + , + borrowedTime + , + s + ,借书); MySqlCommand mysqlcommand3 = new MySqlCommand(updateBorrow3, conn); mysqlcommand3.ExecuteNonQuery(); /刷新dataGridView1,重新绑定数据源 f5(); 归还图书功效:
16、关键实现代码 returnbook.cs:private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) int r = this.dataGridView1.CurrentRow.Index; string h = this.dataGridView1.Rowsr.Cells1.Value.ToString(); string s = this.dataGridView1.Rowsr.Cells2.Value.ToString(); DateTime dt = DateTime.N
17、ow; String returnedTime = dt.ToString(yyyy-MM-dd HH:mm:ss); String userId = ; string sql = server=localhost;user id=root;password=123456;database=C#librarycenter; /依据自己设置 MySqlConnection conn = new MySqlConnection(sql); conn.Open(); / String updateBorrow1 = update bookInfo set isBorrowed = 0,borrowI
18、d = null,borrowedTime = null where bookId = +h+; MySqlCommand mysqlcommand2 = new MySqlCommand(updateBorrow1, conn); int i = mysqlcommand2.ExecuteNonQuery(); if (i != -1) MessageBox.Show(login.username + rn rn这本书,还书成功); else MessageBox.Show(系统出了点问题,请联络管理员!); /更新借阅表 String updateBorrow = select userI
19、d from userInfo where userName = + login.username + ; MySqlCommand mysqlcommand = new MySqlCommand(updateBorrow, conn); MySqlDataReader mdr = mysqlcommand.ExecuteReader(); if (mdr.Read() userId = mdr.GetString(0).ToString(); mdr.Close(); String updateBorrow2 = insert into borrowed(userId,userName,bo
20、okId,editTime,bookName,edit) values( + userId + , + login.username + , + h + , + returnedTime + , + s + ,还书); MySqlCommand mysqlcommand3 = new MySqlCommand(updateBorrow2, conn); mysqlcommand3.ExecuteNonQuery(); /刷新dataGridView1,重新绑定数据源 f5(); 修改个人信息:关键实现代码 editUser.cs:private void button1_Click(objec
21、t sender, EventArgs e) login login = new login(); String pw = textBox1.Text; String npw = textBox2.Text; String un = login.username; String userPassword = ; String userId = ; if (male.Checked = true) ans = male; if (female.Checked = true) ans = female; String sql = server=localhost;user id=root;pass
22、word=123456;database=C#librarycenter; /依据自己设置 MySqlConnection conn = new MySqlConnection(sql); conn.Open(); / String yanzheng = SELECT userPassword FROM userinfo where userName = +login.username+; MySqlCommand yz = new MySqlCommand(yanzheng,conn); MySqlDataReader mdr2 = yz.ExecuteReader(); if (mdr2.
23、Read() userPassword = mdr2.GetString(0); mdr2.Close(); if (textBox2.Text.Trim() != ) if (pw = userPassword) / String editsql1 = select userId from userInfo where userName = + login.username + ; MySqlCommand cmd1 = new MySqlCommand(editsql1, conn); MySqlDataReader mdr = cmd1.ExecuteReader(); if (mdr.
24、Read() userId = mdr.GetString(0); else mdr.Close(); / String editsql2 = update userInfo set userPassword = + npw + , userSex = + ans + where userId = + userId + ; MySqlCommand cmd2 = new MySqlCommand(editsql2, conn); int i = cmd2.ExecuteNonQuery(); if (i = 1) MessageBox.Show(login.username + rn您信息修改
25、成功!rn请切记您现在密码); else MessageBox.Show(修改失败,请联络管理员); else MessageBox.Show(你原密码输入错误,请重新输入啊啊啊); else MessageBox.Show(新密码请不要填空!); 查询借阅信息:关键实现代码 borrowedinfo.cs:public borrowedinfo() InitializeComponent(); label1.Text = login.username + ,以下是您借阅统计:; String sql = server=localhost;user id=root;password=12345
26、6;database=C#librarycenter; /依据自己设置 MySqlConnection conn = new MySqlConnection(sql); conn.Open();/打开数据库连接 String userId = ; MySqlCommand cmd = new MySqlCommand(select userId from borrowed where userName = + login.username +,conn); MySqlDataReader mdr = cmd.ExecuteReader(); if (mdr.Read() userId = md
27、r.GetString(0); mdr.Close(); MySqlDataAdapter data1 = new MySqlDataAdapter();/实例化sqldataadpter MySqlCommand cmd1 = new MySqlCommand(select bookId as 图书编号,bookName as 图书名,editTime as 操作时间,edit as 操作 from borrowed where userId = + userId +, conn);/sql语句 data1.SelectCommand = cmd1;/设置为已实例化SqlDataAdapte
28、r查询命令 /DataSet ds1 = new DataSet();/实例化dataset DataTable dt = new DataTable(); dt.Clear(); data1.Fill(dt);/把数据填充到datatable dataGridView1.DataSource = dt;/将数据集绑定datagridview,完成显示 dataGridView1.AllowUserToAddRows = false; 后台管理系统:关键实现代码 adminCenter.cs:private void 相关ToolStripMenuItem_Click(object sende
29、r, EventArgs e) MessageBox.Show(制作者:Matthew Hanrn完成时间:-6-4); private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e) System.Environment.Exit(0); private void 图书管理ToolStripMenuItem_Click(object sender, EventArgs e) editMain editMain = new editMain(); editMain.FormBorderStyle = FormBorder
30、Style.None; editMain.Dock = DockStyle.Fill; editMain.TopLevel = false; this.panel1.Controls.Clear(); this.panel1.Controls.Add(editMain); editMain.Show(); private void 添加图书ToolStripMenuItem_Click(object sender, EventArgs e) edit2 edit2 = new edit2(); edit2.Show(); private void 用户管理ToolStripMenuItem_C
31、lick(object sender, EventArgs e) edit3 edit3 = new edit3(); edit3.FormBorderStyle = FormBorderStyle.None; edit3.Dock = DockStyle.Fill; edit3.TopLevel = false; this.panel1.Controls.Clear(); this.panel1.Controls.Add(edit3); edit3.Show(); 修改图书信息:关键实现代码 editMain.cs & edit1.cs:public static string bookna
32、me; public static string bookauthor; public static string bookprice; public static string bookpress; public static string booktype;/说明:这里用是全局静态变量,把表格获取到数据保留起来,进行数据传输。private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) int r = this.dataGridView1.CurrentRow.Index; s
33、tring bn = this.dataGridView1.Rowsr.Cells1.Value.ToString(); string ba = this.dataGridView1.Rowsr.Cells2.Value.ToString(); string bp1 = this.dataGridView1.Rowsr.Cells3.Value.ToString(); string bp2 = this.dataGridView1.Rowsr.Cells4.Value.ToString(); string bt = this.dataGridView1.Rowsr.Cells5.Value.T
34、oString(); / editMain editMain = new editMain(); editMain.bookname = bn.ToString(); editMain.bookauthor = ba.ToString(); editMain.bookprice = bp1.ToString(); editMain.bookpress = bp2.ToString(); editMain.booktype = bt.ToString(); / edit1 edit1 = new edit1(); edit1.Show(); /接下来是edit1.cs中提交新数据,update数据库。public edit1() InitializeComponent(); editMain editMain = new editMain(); label6.Text = editMain.bookname; textBox1.Text = editMain.bookauthor; textBox2.Text = editMain.bookprice; textBox3.Text = editMain.bookpress; textBox4.Text = editMain.booktype; private void button1_Click(ob