1、毕业设计_图书管理系统 一、数据库设计数据库设CREATE DATABASE TSGL GO USE TSGL GO CREATE TABLE Bmanage( bId varchar(10) PRIMARY KEY,bName varchar(50),-添加图书-图书编号-书名bNumber varchar(10), -书数目) GO bSore varchar(50) -分类CREATE TABLE Madmin( mName varchar(10)PRIMARY KEY,mPwd varchar(25),mAge varchar(8),mSex varchar(4),mNumber va
2、rchar(15),mrole varchar(8) GO -图书员管理-图书管理员姓名-图书管理员密码-图书管理员年龄-图书管理员性别-图书管理员电话-图书管理员角色CREATE TABLE Reader( rSno varchar(10) PRIMARY KEY,rName varchar(10),rPwd varchar(25),rAge varchar(8),rSex varchar(4),rState varchar(8),rNumber varchar(15),rEmail varchar(25),-读者信息表reader -读者号-姓名-密码-年龄-性别-状态-电话号码-电子邮件
3、rAdress varChar(50), -地址) GO rGrade varChar(15),rClass varchar(15),rRole varchar(8)-年级-班级-角色CREATE TABLE Rrecord( rSno varchar(10) PRIMARY KEY,rName varChar(10),bId varchar(10),bName varChar(50),bTime varchar(10),bBackTime varchar(10) GO CREATE TABLE SysSet( rRole varchar(8)PRIMARY KEY,rState varcha
4、r(8),Fine float(25),rDay varchar(8)-读者编号学号-读者姓名-图书编号-图书名称-借书时间-还书时间-读者角色-读者可借书数-过期罚款设置-可借书天数)二、界面截图及说明1) 登录窗口(实现管理员和馆长的登陆) 2) 管理员窗口 3) 馆长窗口 4) 关于窗口 5) 新增图书窗口 6) 新增管理员、查找及修改窗口 7) 新增读者、查找及修改窗口 8) 图书的查找及修改窗口 9) 借阅窗口 10)系统设置窗口 三、主要代码主要代1) 登录窗口(实现管理员和馆长的登陆) 登陆检查: using System; using System.Collections.Ge
5、neric; using System.Linq; using System.Text; using System.Data; using prjTSGL.ClassLib.DBAccess; namespace prjTSGL.ClassLib.Logic class clsLoginCheck public static DataTable CheckLogin(string UserId, string PWD) string SQLstmt = “select mName,mPwd,mRole from Madmin where mName= “ + UserId + “and mPw
6、d= “ + PWD + “; DataTable dt = clsGlobalVar.GetDataTable(SQLstmt); return dt; 登陆: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using prjTSGL.ClassLib.Logic; name
7、space prjTSGL.TSGL_UI public partial class frmLogin : Form public frmLogin() InitializeComponent(); private void btnLogin_Click(object sender, EventArgs e) string strUserID = loginid.Text.Trim(); string strPWD = loginpwd.Text.Trim(); string type = “; try DataTable dt = clsLoginCheck.CheckLogin(strUs
8、erID, strPWD); if (dt.Rows.Count = 0) MessageBox.Show(“登陆失败,请重新输入!“); loginpwd.Focus(); return; else type = dt.Rows0“mRole“.ToString().Trim(); if (cboLT.Text.Trim()=“馆长“ ) if (type = “馆长“) this.Hide(); frmManager objManager = new frmManager(); objManager.Show(); else MessageBox.Show(“您没有权限!“); login
9、pwd.Focus(); return; else if (type =“管理员“ ) this.Hide(); frmAdmin objAdmin = new frmAdmin(); objAdmin.Show(); else MessageBox.Show(“您没有权限!“); loginpwd.Focus(); return; catch (Exception ex) throw ex; private void btnExit_Click(object sender, EventArgs e) this.Close(); 2) 管理员窗口 using System; using Sys
10、tem.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace prjTSGL.TSGL_UI public partial class frmAdmin : Form public frmAdmin() InitializeComponent(); private void ShowForm(Form frmToSho
11、w) this.Cursor = Cursors.WaitCursor; foreach (Form frmChild in this.MdiChildren) if (frmChild.GetType() = frmToShow.GetType() frmToShow.Dispose(); frmChild.Activate(); this.Cursor = Cursors.Default; return; frmToShow.MdiParent = this; frmToShow.Show(); this.Cursor = Cursors.Default; private void 读者信
12、息修改ToolStripMenuItem_Click(object sender, EventArgs e) ShowForm(newfrmUpdateReader(); private void 新增图书ToolStripMenuItem_Click(object sender, EventArgs e) ShowForm(newfrmAddNewBook(); private void 图书的查找和修改ToolStripMenuItem_Click(object sender, EventArgs e) ShowForm(newfrmUpdateBook(); private void 流
13、通管理ToolStripMenuItem_Click(object sender, EventArgs e) ShowForm(newfrmBorrow(); private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e) ShowForm(newfrmAbout(); private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) Application.Exit(); 3) 馆长窗口 using System; using System.Collect
14、ions.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace prjTSGL.TSGL_UI public partial class frmManager : Form public frmManager() InitializeComponent(); private void ShowForm(Form frmToShow) this
15、.Cursor = Cursors.WaitCursor; foreach (Form frmChild in this.MdiChildren) if (frmChild.GetType() = frmToShow.GetType() frmToShow.Dispose(); frmChild.Activate(); this.Cursor = Cursors.Default; return; frmToShow.MdiParent = this; frmToShow.Show(); this.Cursor = Cursors.Default; private void frmManager
16、_FormClosed(object sender, FormClosedEventArgs e) Application.Exit(); private void 管理员信息管理ToolStripMenuItem_Click_1(object sender, EventArgs e) ShowForm(newfrmSelectAdmin(); private void 系统设置ToolStripMenuItem_Click_1(object sender, EventArgs e) ShowForm(newfrmSys(); private void 关于ToolStripMenuItem_
17、Click(object sender, EventArgs e) ShowForm(newfrmAbout(); private void 退出ToolStripMenuItem_Click_1(object sender, EventArgs e) Application.Exit(); 4) 关于窗口 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using Sy
18、stem.Text; using System.Windows.Forms; namespace prjTSGL.TSGL_UI public partial class frmAbout : Form public frmAbout() InitializeComponent(); private void button1_Click(object sender, EventArgs e) this.Close(); 5) 新增图书窗口 using System; using System.Collections.Generic; using System.ComponentModel; u
19、sing System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using prjTSGL.ClassLib.DBAccess; namespace prjTSGL.TSGL_UI public partial class frmAddNewBook : Form public frmAddNewBook() InitializeComponent(); private bool ValidatInput() if (textBox1.Text =
20、 “) MessageBox.Show(“请输入图书编号!“, “ 输入提示“, MessageBoxButtons .OK, MessageBoxIcon.Information); textBox1.Focus(); return false; if (textBox2.Text = “) MessageBox.Show(“请输入图书名称!“, “ 输入提示“, MessageBoxButtons .OK, MessageBoxIcon.Information); textBox2.Focus(); return false; if (textBox3.Text = “) MessageB
21、ox.Show(“请输入图书数目!“, “ 输入提示“, MessageBoxButtons .OK, MessageBoxIcon.Information); textBox3.Focus(); return false; if (comboBox1.Text = “) MessageBox.Show(“请选择图书类别!“, “ 输入提示“, MessageBoxButtons .OK, MessageBoxIcon.Information); textBox3.Focus(); return false; return true; private void btnOK_Click_1(ob
22、ject sender, EventArgs e) if (ValidatInput() /string id = textBox1.Text; /string name = textBox2.Text; /string Number = textBox3.Text; /string sore = comboBox1.Text; string sql = “SELECT *FROM Bmanage WHERE bId=“ + textBox1.Text.Trim() + “ “; DataTable dt = clsGlobalVar.GetDataTable(sql); if (dt.Row
23、s.Count = 0) string SQL = “insert into Bmanage(bId,bName,bNumber,bSore)values(“ + textBox1.Text.Trim() + “ ,“ + textBox2.Text.Trim() + “ ,“ + textBox3.Text.Trim() + “ ,“+ comboBox1.Text.Trim() + “ )“; try bool result = clsGlobalVar.ExecSQL(SQL); if (result) MessageBox.Show(“添加成功!“, “ 操作提示“, MessageB
24、oxButtons.OK, MessageBoxIcon.Information); textBox1.Text = “; textBox2.Text = “; textBox3.Text = “; comboBox1.Text = “; textBox1.Focus(); else MessageBox.Show(“添加失败!“, “ 操作提示“, MessageBoxButtons.OK, MessageBoxIcon.Error); catch (Exception ex) MessageBox.Show(“操作数据库出错!“, “ 操作演示“, MessageBoxButtons .O
25、K, MessageBoxIcon.Error); Console.WriteLine(ex.Message); else MessageBox.Show(“图书编号已存在!“, “ 操作提示“, MessageBoxButtons .OK, MessageBoxIcon.Information); textBox1.Focus(); private void btnCancel_Click(object sender, EventArgs e) this.Close(); 6) 新增管理员、查找及修改窗口 using System; using System.Collections.Gene
26、ric; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using prjTSGL.ClassLib.DBAccess; namespace prjTSGL.TSGL_UI public partial class frmSelectAdmin : Form public frmSelectAdmin() InitializeComponent(); string nam
27、e = “; string SQL = “; string PWD = “; string Age = “; string Sex = “; string Tel = “; string Role = “; private void SelectAdmin() string strfilter = “; string SQL = “select mName AS 用户名 ,mPwd AS 密码,mAge AS 年龄 ,mSex AS 性别,mNumber AS 电话 ,mRole AS 角色 from Madmin “; if (txtName.Text = “) strfilter = “;
28、 else strfilter = “where mName=“ + txtName.Text.Trim() + “; try DataTable dt = clsGlobalVar.GetDataTable(SQL + strfilter); int intIndex = 0; if (dt.Rows.Count = 0) MessageBox.Show(“抱歉,没有您要找的用户!“, “ 结果提示“, MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Text = “; txtPWD.Text = “; txtAge.Te
29、xt = “; cboSex.Text = “; txtTel.Text = “; cboRole.Text = “; else LV.Columns.Clear(); LV.Items.Clear(); LV.Columns.Add(“序号“ , 100, HorizontalAlignment.Center); for (int intJ = 0; intJ dt.Columns.Count; intJ+) LV.Columns.Add(dt.ColumnsintJ.ColumnName, 200, HorizontalAlignment.Center); for (int intI =
30、0; intI dt.Rows.Count; intI+) intIndex = intI + 1; LV.Items.Add(intIndex.ToString(); LV.ItemsintI.SubItems.Add(dt.RowsintI“用户名“.ToString().Trim(); LV.ItemsintI.SubItems.Add(dt.RowsintI“密码“.ToString().Trim(); LV.ItemsintI.SubItems.Add(dt.RowsintI“年龄“.ToString().Trim(); LV.ItemsintI.SubItems.Add(dt.Ro
31、wsintI“性别“.ToString().Trim(); LV.ItemsintI.SubItems.Add(dt.RowsintI“电话“.ToString().Trim(); LV.ItemsintI.SubItems.Add(dt.RowsintI“角色“.ToString().Trim(); /连接数据库,将数据读取出放入MadminData catch (Exception ex) MessageBox.Show(“查询数据库出错!“, “ 提示“, MessageBoxButtons .OK, MessageBoxIcon.Error); Console.WriteLine(ex
32、.Message); private void btnSearch_Click(object sender, EventArgs e) SelectAdmin();/调用函数 /实现修改功能 private void btnUpdata_Click(object sender, EventArgs e) if (txtName.Text = “ | cboRole.Text=“) MessageBox.Show(“请选择要修改的用户!“); else SQL = “UPDATE Madmin SET mName=“ + txtName.Text.Trim() + “,mPwd=“ + txtP
33、WD.Text.Trim() + “,mAge=“ + txtAge.Text.Trim() + “,mSex=“ + cboSex.Text.Trim() + “,mNumber=“ + txtTel.Text.Trim() + “,mRole=“ + cboRole.Text.Trim() + “ where mName=“ + name + “AND mPwd=“ + PWD + “AND mAge=“ + Age + “AND mSex=“ + Sex + “AND mNumber=“ + Tel + “AND mRole=“ + Role + “; try bool result =
34、 clsGlobalVar.ExecSQL(SQL); if (result) /txtName.Text = “; txtPWD.Text = “; txtAge.Text = “; cboSex.Text = “; txtTel.Text = “; cboRole.Text = “; MessageBox.Show(“修改已成功“); SelectAdmin(); else MessageBox.Show(“更新失败!“, “ 操作提示“, MessageBoxButtons.OK, MessageBoxIcon.Error); catch (Exception ex) MessageBo
35、x.Show(“操作数据库出错!“, “ 操作演示“, MessageBoxButtons .OK, MessageBoxIcon.Error); Console.WriteLine(ex.Message); private void btnExit_Click(object sender, EventArgs e) this.Close(); private void LV_SelectedIndexChanged_1(object sender, EventArgs e) txtName.Text = LV.FocusedItem.SubItems1.Text.Trim(); txtPWD
36、.Text = LV.FocusedItem.SubItems2.Text.Trim(); txtAge.Text = LV.FocusedItem.SubItems3.Text.Trim(); cboSex.Text = LV.FocusedItem.SubItems4.Text.Trim(); txtTel.Text = LV.FocusedItem.SubItems5.Text.Trim(); cboRole.Text = LV.FocusedItem.SubItems6.Text.Trim(); name = LV.FocusedItem.SubItems1.Text.Trim();
37、PWD = LV.FocusedItem.SubItems2.Text.Trim(); Age = LV.FocusedItem.SubItems3.Text.Trim(); Sex = LV.FocusedItem.SubItems4.Text.Trim(); Tel = LV.FocusedItem.SubItems5.Text.Trim(); Role = LV.FocusedItem.SubItems6.Text.Trim(); private void frmSelectAdmin_Load(object sender, EventArgs e) this.btnSearch_Cli
38、ck(sender, e); private void btnAdd_Click(object sender, EventArgs e) if (txtName.Text = “ | txtPWD.Text = “ | txtAge.Text = “ |cboSex.Text = “ | txtTel.Text=“ |cboRole.Text = “) MessageBox.Show(“请至少输入用户名,密码和角色!“); else SQL = “SELECT mName,mPwd,mAge ,mSex,mNumber,mRole from Madmin WHERE mName=“ + txt
39、Name.Text.Trim() + “ “; DataTable dt = clsGlobalVar.GetDataTable(SQL); if (dt.Rows.Count = 0) SQL = “INSERT INTO Madmin VALUES (“ + txtName.Text.Trim() + “,“ + txtPWD.Text.Trim() + “,“ + txtAge.Text.Trim() + “,“ + cboSex.Text.Trim() + “,“ + txtTel.Text.Trim() + “,“ + cboRole.Text.Trim() + “)“; if (c
40、lsGlobalVar.ExecSQL(SQL) = true) /txtName.Text = “; txtPWD.Text = “; txtAge.Text = “; cboSex.Text = “; txtTel.Text = “; cboRole.Text = “; MessageBox.Show(“成功添加新管理员!“); SelectAdmin(); else Exception ex = new Exception(); MessageBox.Show(ex.Message.ToString(); else MessageBox.Show(“用户名已存在,请选择其他用户名!“,
41、“ 结果提示“ , MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Text = “; private void btnDelete_Click(object sender, EventArgs e) if (txtName.Text = “ | cboRole.Text = “) MessageBox.Show(“请选择要删除的管理员用户!“); else DialogResult dr = MessageBox.Show(“此操作不可撤销,确定要删除此用户信息吗?“ , “提示“, MessageBoxButtons.Y
42、esNo, MessageBoxIcon .Question); if (dr = DialogResult.Yes) SQL = “DELETE FROM Madmin WHERE mName=“ + name + “AND mPwd=“ + PWD + “AND mAge=“ + Age + “AND mSex=“ + Sex + “AND mNumber=“ + Tel + “AND mRole=“ + Role + “; if (clsGlobalVar.ExecSQL(SQL) = true) MessageBox.Show(“成功删除此管理信息!“); SelectAdmin();
43、 else Exception ex = new Exception(); MessageBox.Show(ex.Message.ToString(); private void btnReset_Click(object sender, EventArgs e) txtName.Text = “; txtPWD.Text = “; txtAge.Text = “; cboSex.Text = “; txtTel.Text = “; cboRole.Text = “; 7) 新增读者、查找及修改窗口 using System; using System.Collections.Generic;
44、 using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using prjTSGL.ClassLib.DBAccess; namespace prjTSGL.TSGL_UI public partial class frmUpdateReader : Form public frmUpdateReader() InitializeComponent(); string Sno =
45、 “; string Pwd = “; string Age = “; string name = “; string Sex = “; string State = “; string Adress = “; string Number = “; string Email = “; string Grade = “; string Class = “; string Role = “; /查找学生读者 private void SelectStudent() string strfilter = “; string SQL = “select rSno AS 读者编号,rName AS 读者
46、姓名,rPwd AS 密码,rAge AS 年龄,rSex AS 性别,rState AS 借书状态,rAdress AS 地址,rNumber AS 电话,rEmail AS 邮箱,rGrade AS 年级,rClass AS 班级 ,rRole AS 角色 from Reader “; if (txtReaderName.Text = “) strfilter = “; else strfilter = “where rName=“ + txtReaderName.Text.Trim() + “; try DataTable dt = clsGlobalVar.GetDataTable(S
47、QL + strfilter); int intIndex = 0; if (dt.Rows.Count=0) MessageBox.Show(“抱歉,没有您要找的读者信息!“, “ 结果提示“, MessageBoxButtons.OK, MessageBoxIcon.Information); else LV.Columns.Clear(); LV.Items.Clear(); LV.Columns.Add(“序号“ , 100, HorizontalAlignment.Center); for (int intJ = 0; intJ dt.Columns.Count; intJ+) LV.Columns.Add(dt.ColumnsintJ.ColumnName, 200, HorizontalAlignment.Center); for (int intI = 0; intI dt.Rows.Count; intI+) intIndex = intI + 1; LV.Items.