图书馆管理系统设计(附带源代码)

发布时间:2011-10-03   来源:文档文库   
字号:


毕业设计_图书管理系统



一、数据库设计数据库设

CREATE DATABASE TSGL GO USE TSGL GO



CREATE TABLE Bmanage ( bId varchar(10 PRIMARY KEY, bName varchar(50, bNumber

--添加图书

--图书编号
--书名 --书数目 --分类
varchar(10, bSore varchar(50


GO CREATE TABLE Madmin ( mName varchar(10PRIMARY KEY, mPwd varchar(25, mAge varchar(8, mSex varchar(4, mNumber varchar(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, rAdress

--读者信息表reader
--读者号 --姓名 --密码 --年龄 --性别
--状态 --电话号码
--电子邮件 --地址 --年级 --班级 --角色
varChar(50, rGrade varChar(15, rClass varchar(15, rRole varchar(8
GO

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(8PRIMARY KEY, rState varchar(8, Fine float(25, rDay varchar(8

--读者角色 --读者可借书数 --过期罚款设置 --可借书天数

二、界面截图及说明

1 登录窗口(实现管理员和馆长的登陆)




2 管理员窗口



3 馆长窗口




4 关于窗口



5 新增图书窗口



6 新增管理员、查找及修改窗口




7 新增读者、查找及修改窗口



8 图书的查找及修改窗口




9 借阅窗口



10系统设置窗口




三、主要代码主要代

1 登录窗口(实现管理员和馆长的登陆)


登陆检查:


using System;
using System.Collections.Generic; using System.Linq; using System.Text; using System.Data;
using prjTSGL.ClassLib.DBAccess;

namespace prjTSGL.ClassLib.Logic {
class clsLoginCheck {
public static { {


string SQLstmt = "select mName,mPwd,mRole from Madmin where mName= '" + UserId
+ "'and mPwd= '" + PWD + "'";
DataTable dt = clsGlobalVar.GetDataTable(SQLstmt; return dt;
}
DataTable CheckLogin(string UserId, string PWD



}

} }

登陆:


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;

namespace prjTSGL.TSGL_UI {
public partial {
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(strUserID, strPWD; if (dt.Rows.Count == 0
{
MessageBox.Show("登陆失败,请重新输入!";
loginpwd.Focus(;
return;
}
else
{
class frmLogin : Form



type = dt.Rows[0]["mRole"].ToString(.Trim(;
if (cboLT.Text.Trim(=="馆长"
{
if (type == "馆长"

{
this.Hide(;
frmManager objManager = new frmManager(;
objManager.Show(;

}
else
{
MessageBox.Show("您没有权限!";
loginpwd.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 System.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 {
public frmAdmin(
{
InitializeComponent(;
}


private void ShowForm(Form frmToShow {
this.Cursor = Cursors.WaitCursor; foreach (Form frmChild in {
if (frmChild.GetType( == frmToShow.GetType(
class frmAdmin : Form
this.MdiChildren
{
frmToShow.Dispose(; frmChild.Activate(;
this.Cursor = Cursors.Default; return;
} }
frmToShow.MdiParent = this;



frmToShow.Show(;
this.Cursor = Cursors.Default;
}


private void 读者信息修改ToolStripMenuItem_Click(object sender, EventArgs e {
ShowForm(new frmUpdateReader(;
}


private void 新增图书ToolStripMenuItem_Click(object sender, EventArgs e {
ShowForm(new frmAddNewBook(;
}


private void 图书的查找和修改ToolStripMenuItem_Click(object sender, EventArgs e {
ShowForm(new frmUpdateBook(;
}


private void 流通管理ToolStripMenuItem_Click(object sender, EventArgs e {
ShowForm(new frmBorrow(;
}


private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e {
ShowForm(new frmAbout(;
}


private void 退出ToolStripMenuItem_Click(object sender, EventArgs e {
Application.Exit(;
} } }

3 馆长窗口


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;

namespace prjTSGL.TSGL_UI {
public partial {
public frmManager(
{
InitializeComponent(;
}


private void ShowForm(Form frmToShow {
this.Cursor = Cursors.WaitCursor;
class frmManager : Form
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_FormClosed(object sender, FormClosedEventArgs e {
Application.Exit(;
}


private void 管理员信息管理ToolStripMenuItem_Click_1(object sender, EventArgs e
{
ShowForm(new frmSelectAdmin(; }



private void 系统设置ToolStripMenuItem_Click_1(object sender, EventArgs e
{
ShowForm(new frmSys(;
}


private void 关于ToolStripMenuItem_Click(object sender, EventArgs e {
ShowForm(new frmAbout(;
}


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 System.Text;
using System.Windows.Forms;

namespace prjTSGL.TSGL_UI {
public partial {
public frmAbout(
{
InitializeComponent(;
}


private void button1_Click(object sender, EventArgs e {
this.Close(;
} }
class frmAbout : Form

}

5 新增图书窗口


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.DBAccess;

namespace prjTSGL.TSGL_UI {
public partial {
public frmAddNewBook(
{
InitializeComponent(; }


private bool ValidatInput( {
if (textBox1.Text == ""

{
MessageBox.Show("请输入图书编号!", "输入提示", MessageBoxButtons.OK,
MessageBoxIcon.Information; textBox1.Focus(;
return false;
}
if (textBox2.Text == ""

{
MessageBox.Show("请输入图书名称!", "输入提示", MessageBoxButtons.OK,
class frmAddNewBook : Form
MessageBoxIcon.Information; textBox2.Focus(;
return false;
}
if (textBox3.Text == ""

{
MessageBox.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(object 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.Rows.Count == 0
{
string SQL = "insert into Bmanage(bId,bName,bNumber,bSorevalues('" +
textBox1.Text.Trim( + " ','" + textBox2.Text.Trim( + " ','" + textBox3.Text.Trim( + " ','" + comboBox1.Text.Trim( + " '";
try {
bool result = clsGlobalVar.ExecSQL(SQL;

if (result
{
MessageBox.Show("添加成功!", "操作提示", MessageBoxButtons.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.OK,
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.Generic; 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 {
public frmSelectAdmin(
{
InitializeComponent(; }
string name = ""; 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 = "";
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.Text = ""; cboSex.Text = ""; txtTel.Text = ""; cboRole.Text = "";

}
else
class frmSelectAdmin : Form



{ {
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.Columns[intJ].ColumnName, 200, HorizontalAlignment.Center;
}


for (int intI = 0; intI < dt.Rows.Count; intI++ {
intIndex = intI + 1;
LV.Items.Add(intIndex.ToString(;
LV.Items[intI].SubItems.Add(dt.Rows[intI]["用户名 "].ToString(.Trim(;
LV.Items[intI].SubItems.Add(dt.Rows[intI]["密码 "].ToString(.Trim(;
LV.Items[intI].SubItems.Add(dt.Rows[intI]["年龄 "].ToString(.Trim(;
LV.Items[intI].SubItems.Add(dt.Rows[intI]["性别 "].ToString(.Trim(;
LV.Items[intI].SubItems.Add(dt.Rows[intI]["电话 "].ToString(.Trim(;
LV.Items[intI].SubItems.Add(dt.Rows[intI]["角色 "].ToString(.Trim(; } }
}

}//连接数据库,将数据读取出放入MadminData
catch (Exception ex
{
MessageBox.Show("查询数据库出错!", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.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='" +
txtPWD.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 = 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
{
MessageBox.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.SubItems[1].Text.Trim(; txtPWD.Text = LV.FocusedItem.SubItems[2].Text.Trim(; txtAge.Text = LV.FocusedItem.SubItems[3].Text.Trim(; cboSex.Text = LV.FocusedItem.SubItems[4].Text.Trim(; txtTel.Text = LV.FocusedItem.SubItems[5].Text.Trim(; cboRole.Text = LV.FocusedItem.SubItems[6].Text.Trim(; name = LV.FocusedItem.SubItems[1].Text.Trim(; PWD = LV.FocusedItem.SubItems[2].Text.Trim(; Age = LV.FocusedItem.SubItems[3].Text.Trim(; Sex = LV.FocusedItem.SubItems[4].Text.Trim(; Tel = LV.FocusedItem.SubItems[5].Text.Trim(;
Role = LV.FocusedItem.SubItems[6].Text.Trim(;

}


private void frmSelectAdmin_Load(object sender, EventArgs e {
this.btnSearch_Click(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='" + txtName.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 (clsGlobalVar.ExecSQL(SQL == true

{
//txtName.Text = "";
txtPWD.Text = ""; txtAge.Text = ""; cboSex.Text = ""; txtTel.Text = "";
cboRole.Text = "";


MessageBox.Show("成功添加新管理员!"; SelectAdmin(; }
else
{
Exception ex = new }

}
else
{
MessageBox.Show("用户名已存在,请选择其他用户名!", "结果提示",
MessageBoxButtons.OK, MessageBoxIcon.Information; txtName.Text = ""; }

}
}


private void btnDelete_Click(object sender, EventArgs e {
Exception(;
MessageBox.Show(ex.Message.ToString(;



if (txtName.Text == "" || cboRole.Text == ""

{
MessageBox.Show("请选择要删除的管理员用户!";
}
else
{
DialogResult dr = MessageBox.Show("此操作不可撤销,确定要删除此用户信息吗?",
"提示", MessageBoxButtons.YesNo, 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(; }
else
{
Exception ex = new } }

}
}


private void btnReset_Click(object sender, EventArgs e {
txtName.Text = ""; txtPWD.Text = ""; txtAge.Text = ""; cboSex.Text = ""; txtTel.Text = ""; cboRole.Text = ""; } } }

Exception(;
MessageBox.Show(ex.Message.ToString(;
7 新增读者、查找及修改窗口




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.DBAccess;

namespace prjTSGL.TSGL_UI {
public partial {
public frmUpdateReader(
{
InitializeComponent(; }


string Sno = "";
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 读者姓名,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( + "'";
class frmUpdateReader : Form

try
{
DataTable dt = clsGlobalVar.GetDataTable(SQL + 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.Columns[intJ].ColumnName, 200, HorizontalAlignment.Center; }
for (int intI = 0; intI < dt.Rows.Count; intI++
{
intIndex = intI + 1;
LV.Items.Add(intIndex.ToString(;
for (int j=1; j < dt.Columns.Count; j++
{
LV.Items[intI].SubItems.Add(dt.Rows[intI][j].ToString(; }
//LV.Items[intI].SubItems.Add(dt.Rows[intI]["读者编号"].ToString(;
//LV.Items[intI].SubItems.Add(dt.Rows[intI]["读者姓名"].ToString(;
//LV.Items[intI].SubItems.Add(dt.Rows[intI]["密码"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["年龄"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["性别"].ToString(;
//LV.Items[intI].SubItems.Add(dt.Rows[intI]["借书状态"].ToString(;
//LV.Items[intI].SubItems.Add(dt.Rows[intI]["地址"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["电话"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["邮箱"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["年级"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["班级"].ToString(; //LV.Items[intI].SubItems.Add(dt.Rows[intI]["角色"].ToString(;
}

}



}
catch (Exception ex
{
MessageBox.Show("查询数据库出错!", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
}

}
//实现查找功能

private void btnSearch_Click(object sender, EventArgs e
{

SelectStudent(;

}


//实现修改功能

private void btnUpdata_Click(object sender, EventArgs e
{
if (textBox2.Text == ""

{
MessageBox.Show("请选择要修改的用户!";
}
else
//string sql = "SELECT * from Reader WHERE rSno='" + textBox2.Text.Trim( + "' "; //DataTable dt = clsGlobalVar.GetDataTable(sql; //if (dt.Rows.Count == 0 //{
{
string SQL = "UPDATE Reader SET rSno='" + textBox2.Text.Trim( + "',rPwd='" + textBox3.Text.Trim( + "',rAge='" + textBox1.Text.Trim( + "',rName='" +
txtReaderName.Text.Trim( + "',rSex='" + cboSex.Text.Trim( + "',rState='" + textBox4.Text.Trim( + "',rAdress='" + textBox5.Text.Trim( + "',rNumber='" + textBox6.Text.Trim( + "',rEmail='" + textBox7.Text.Trim( + "',rGrade='" + textBox8.Text.Trim( + "',rClass='" + textBox9.Text.Trim( + "' ,rRole='" + cboRole.Text.Trim( + "'";


string strfilter = "where rSno='" + Sno + "'";
try
{
bool result = clsGlobalVar.ExecSQL(SQL + strfilter;



if (result
{
textBox2.Text = "";
textBox3.Text = ""; textBox1.Text = "";
cboSex.Text = "";
textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = "";
cboRole.Text = "";
MessageBox.Show("修改已成功";


SelectStudent(; }
else
{
MessageBox.Show("读者信息不存在!", "操作提示", MessageBoxButtons.OK,
MessageBoxIcon.Error; }
}


catch (Exception ex {
MessageBox.Show("操作数据库出错!", "操作演示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
} }
//}
//else //{
// MessageBox.Show("用户名已存在,请选择其他用户名!", "结果提示",
MessageBoxButtons.OK, MessageBoxIcon.Information;
// textBox2.Text = ""; //}
}


private void btnExit_Click(object sender, EventArgs e
{



this.Close(;

}


private void LV_SelectedIndexChanged(object sender, EventArgs e {
textBox2.Text = LV.FocusedItem.SubItems[1].Text.Trim(;
txtReaderName.Text = LV.FocusedItem.SubItems[2].Text.Trim(;
textBox3.Text = LV.FocusedItem.SubItems[3].Text.Trim(;
textBox1.Text = LV.FocusedItem.SubItems[4].Text.Trim(; cboSex.Text = LV.FocusedItem.SubItems[5].Text.Trim(; textBox4.Text = LV.FocusedItem.SubItems[6].Text.Trim(; textBox5.Text = LV.FocusedItem.SubItems[7].Text.Trim(; textBox6.Text = LV.FocusedItem.SubItems[8].Text.Trim(; textBox7.Text = LV.FocusedItem.SubItems[9].Text.Trim(; textBox8.Text = LV.FocusedItem.SubItems[10].Text.Trim(; textBox9.Text = LV.FocusedItem.SubItems[11].Text.Trim(; cboRole.Text = LV.FocusedItem.SubItems[12].Text.Trim(;

Sno = LV.FocusedItem.SubItems[1].Text.Trim(; name = LV.FocusedItem.SubItems[2].Text.Trim(; Pwd = LV.FocusedItem.SubItems[3].Text.Trim(;
Age = LV.FocusedItem.SubItems[4].Text.Trim(; Sex = LV.FocusedItem.SubItems[5].Text.Trim(; State = LV.FocusedItem.SubItems[6].Text.Trim(; Adress = LV.FocusedItem.SubItems[7].Text.Trim(; Number = LV.FocusedItem.SubItems[8].Text.Trim(; Email = LV.FocusedItem.SubItems[9].Text.Trim(; Grade = LV.FocusedItem.SubItems[10].Text.Trim(; Class= LV.FocusedItem.SubItems[11].Text.Trim(; Role = LV.FocusedItem.SubItems[12].Text.Trim(; }


private void btnReset_Click(object sender, EventArgs e {
textBox2.Text = ""; textBox3.Text = ""; txtReaderName.Text = ""; textBox1.Text = ""; cboSex.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = "";



textBox9.Text = "";
cboRole.Text = "";

}


private void btnAdd_Click(object sender, EventArgs e {
string SQL="";
if (textBox2.Text == "" || textBox3.Text == "" || txtReaderName.Text == "" ||
textBox4.Text == "" || textBox5.Text == ""

{
MessageBox.Show("请至少输入读者姓名,用户名,密码,借书状态和角色!";
}
else
{
string sql = "SELECT * from Reader WHERE rSno='" + textBox2.Text.Trim( + "'
";
DataTable dt = clsGlobalVar.GetDataTable(sql; if (dt.Rows.Count == 0
{
if(cboRole.Text.Trim(=="教师"

SQL = "INSERT INTO Reader
(rSno,rPwd,rName,rAge,rSex,rState,rAdress,rNumber,rEmail,rGrade,rClass,rRoleVALUES ('" + textBox2.Text.Trim( + "','" + textBox3.Text.Trim( + "','" + txtReaderName.Text.Trim( + "','" + textBox1.Text.Trim( + "','" + cboSex.Text.Trim( + "','" + textBox4.Text.Trim( + "','" + textBox5.Text.Trim( + "','" + textBox6.Text.Trim( + "','" + textBox7.Text.Trim( + "','" + "NULL"+ "','" + "NULL" + "','" + cboRole.Text.Trim( + "'";
else
SQL = "INSERT INTO Reader
(rSno,rPwd,rName,rAge,rSex,rState,rAdress,rNumber,rEmail,rGrade,rClass,rRoleVALUES ('" + textBox2.Text.Trim( + "','" + textBox3.Text.Trim( + "','" + txtReaderName.Text.Trim( + "','" + textBox1.Text.Trim( + "','" + cboSex.Text.Trim( + "','" + textBox4.Text.Trim( + "','" + textBox5.Text.Trim( + "','" + textBox6.Text.Trim( + "','" + textBox7.Text.Trim( + "','" + textBox8.Text.Trim( + "','" + textBox9.Text.Trim( + "','" + cboRole.Text.Trim( + "'";


if (clsGlobalVar.ExecSQL(SQL == true {

textBox2.Text = ""; textBox3.Text = ""; textBox1.Text = ""; cboSex.Text = ""; textBox4.Text = "";



textBox5.Text = "";
textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = "";
cboRole.Text = "";
MessageBox.Show("成功添加此用户!";
SelectStudent(; }
else
{
Exception ex = new }

}
else
{
MessageBox.Show("用户名已存在,请选择其他用户名!", "结果提示",
MessageBoxButtons.OK, MessageBoxIcon.Information; textBox2.Text = ""; }

}
}


private void btnDel_Click(object sender, EventArgs e {
if (textBox2.Text == ""

{
MessageBox.Show("请选择要删除的用户!";
}
else
{
DialogResult dt= MessageBox.Show("此操作不可撤销,确定要删除此用户信息吗?", " 提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question;
if (dt == DialogResult.Yes
{
string SQL = "DELETE FROM Reader where rSno='" + Sno + "'"; if (clsGlobalVar.ExecSQL(SQL == true

{
textBox2.Text = ""; textBox3.Text = "";
Exception(;
MessageBox.Show(ex.Message.ToString(;



textBox1.Text = ""; cboSex.Text = "";
textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; textBox9.Text = "";
cboRole.Text = "";
MessageBox.Show("删除此用户成功!";
SelectStudent(; }
else
{
Exception ex = new } } }
}


private void frmUpdateReader_Load(object sender, EventArgs e {
SelectStudent(; } } }

Exception(;
MessageBox.Show(ex.Message.ToString(;
8 图书的查找及修改窗口


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.DBAccess;

namespace prjTSGL.TSGL_UI {



public partial {
public frmUpdateBook(
{
InitializeComponent(; }


string bookid = "";
string bookname = "";

//查找图书

private void SelectBook(
{
string SQL = "";
if (textBox1.Text.Trim( == "" && textBox2.Text.Trim( == ""

{
MessageBox.Show("请输入图书编号或图书名称。", "输入提示", MessageBoxButtons.OK,
MessageBoxIcon.Information; textBox2.Focus(; }
else
{
if (textBox1.Text.Trim( == "" && textBox2.Text.Trim( != ""

{
SQL = "select bId AS 图书编号,bName AS 图书名称,bNumber AS 数目,bSore AS from Bmanage where bName like '%" + textBox2.Text.Trim( + "%'"; }
if (textBox1.Text.Trim( != "" && textBox2.Text.Trim( == ""

{
SQL = "select bId AS 图书编号,bName AS 图书名称,bNumber AS 数目,bSore AS from Bmanage where bId='" + textBox1.Text.Trim( + "' "; }
if (textBox1.Text.Trim( != "" && textBox2.Text.Trim( != ""

{
SQL = "select bId AS 图书编号,bName AS 图书名称,bNumber AS 数目,bSore AS from Bmanage where bId='" + textBox1.Text.Trim( + "' "; }
try
{
DataTable dt = clsGlobalVar.GetDataTable(SQL; if (dt.Rows.Count == 0
{
MessageBox.Show("抱歉,没有您要找的图书!", "结果提示",
MessageBoxButtons.OK, MessageBoxIcon.Information;
class frmUpdateBook : Form



textBox1.Focus(; }
else
{
DG.DataSource = dt;

textBox1.DataBindings.Clear(;
textBox2.DataBindings.Clear(; textBox4.DataBindings.Clear(;
comboBox1.DataBindings.Clear(;

textBox1.DataBindings.Add("Text", dt, "图书编号";
textBox2.DataBindings.Add("Text", dt, "图书名称";
textBox4.DataBindings.Add("Text", dt, "数目"; comboBox1.DataBindings.Add("Text", dt, "类别"; bookid = textBox1.Text.Trim(; bookname = textBox2.Text.Trim(; }

}//连接数据库,将数据读取出放入BmanageData
catch (Exception ex
{
MessageBox.Show("查询数据库出错!", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
} }
}


private void btnSelect_Click_1(object sender, EventArgs e {
SelectBook(;
}


private void btnUpdata_Click_1(object sender, EventArgs e {
if (textBox1.Text.Trim( == "" || textBox2.Text.Trim( == "" || textBox4.Text.Trim(
== "" || comboBox1.Text.Trim( == "" {
MessageBox.Show("信息不能为空!";
}
else
{



string SQL = "UPDATE Bmanage SET bId='" + textBox1.Text.Trim( + "',bName='" + textBox2.Text.Trim( + "',bNumber='" + textBox4.Text.Trim( + "',bSore='" + comboBox1.Text.Trim( + "' where bId='" + bookid + "'";
try
{
bool result = clsGlobalVar.ExecSQL(SQL;

if (result
{
MessageBox.Show("修改已成功"; this.btnReset_Click(sender, e;


}
else
{
MessageBox.Show("修改失败!", "操作提示", MessageBoxButtons.OK,
MessageBoxIcon.Error;

} }
catch (Exception ex
{
MessageBox.Show("操作数据库出错!", "操作演示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
} }
}


private void btnDel_Click_1(object sender, EventArgs e {
if (textBox1.Text.Trim( == "" || textBox2.Text.Trim( == "" || textBox4.Text.Trim(
== "" || comboBox1.Text.Trim( == "" {
MessageBox.Show("信息不能为空!";
}
else
{
DialogResult dr = MessageBox.Show("此操作不可撤销,确定要删除此用户信息吗?",
"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question;
if (dr == DialogResult.Yes
{
string SQL = "DELETE FROM Bmanage WHERE bId='" + textBox1.Text.Trim( + "'"; if (clsGlobalVar.ExecSQL(SQL == true






{

MessageBox.Show("成功删除图书信息!";

this.btnReset_Click(sender, e;

}
else
{
Exception ex = new

} } }
}


private void btnReset_Click(object sender, EventArgs e {
textBox1.Text=""; textBox2.Text=""; textBox4.Text=""; comboBox1.Text="";
}


private void btnExit_Click_1(object sender, EventArgs e {
this.Close(;
}

} }

Exception(;
MessageBox.Show(ex.Message.ToString(;
9 借阅窗口


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.DBAccess;



namespace prjTSGL.TSGL_UI {
public partial {
public frmBorrow(
{
InitializeComponent(; }
int state1; int state2; int state3; int state; int Day; float x; int y; float z;

private void btnSearch_Click(object sender, EventArgs e
{


if (txtReader.Text == ""

{
MessageBox.Show("读者号不能为空,请重新输入";


}
else //获取读者借书状态

{


//获取读者可以接几本书

string SQL = "SElECT R.rName AS Name,R.rState AS State1,S.rState AS State2,S.rDay
AS Day From Reader R INNER JOIN SysSet S ON R.rRole=S.rRole WHERE rSno='" + txtReader.Text.Trim( + "'";
try
{
DataTable dt = clsGlobalVar.GetDataTable(SQL; if (dt.Rows.Count == 0
{
MessageBox.Show("读者信息不存在!", "操作提示", MessageBoxButtons.OK,
class frmBorrow : Form
MessageBoxIcon.Error; }

else
{
txtReaderName.Text = dt.Rows[0]["Name"].ToString(.Trim(; state1 = Int32.Parse(dt.Rows[0]["State1"].ToString(.Trim(;
state2 = Int32.Parse(dt.Rows[0]["State2"].ToString(.Trim(;
Day = Int32.Parse(dt.Rows[0]["Day"].ToString(.Trim(; state = state2-state1;
txtState.Text = state.ToString(.Trim(;

}

}
catch (Exception ex
{
MessageBox.Show("操作数据库出错!", "操作演示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
}

}

}


private void btnBookSelect_Click(object sender, EventArgs e {
if (txtBookId.Text == ""

{
MessageBox.Show("图书编号不能为空,请重新输入";


}
else
{
string SQL = "SELECT bName,bNumber FROM Bmanage WHERE bId='" + txtBookId.Text
+ "'";
try
{
DataTable dt = clsGlobalVar.GetDataTable(SQL; if (dt.Rows.Count == 0
{
MessageBox.Show("无此图书!", "操作提示", MessageBoxButtons.OK,
MessageBoxIcon.Error;



}
else
{
txtBookName.Text = dt.Rows[0]["bName"].ToString(.Trim(; txtBooksState.Text = dt.Rows[0]["bNumber"].ToString(.Trim(; state3 = Int32.Parse(dt.Rows[0]["bNumber"].ToString(.Trim(;

}

}
catch (Exception ex
{
MessageBox.Show("操作数据库出错!", "操作演示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
} }
}


private void btnBorrow_Click(object sender, EventArgs e {
if (state > 0 && state3 > 0
{
state3--;
string a = state3.ToString(.Trim(;
string SQL = "UPDATE Bmanage SET bNumber=" + a + "WHERE bId='" + txtBookId.Text
+ "'";
clsGlobalVar.ExecSQL(SQL; //{
// MessageBox.Show("更新成功!"; //}
state1++;
string b = state1.ToString(.Trim(;
string sql = "UPDATE Reader SET rState=" + b + "WHERE rSno='" +
txtReader.Text.Trim( + "' ";


clsGlobalVar.ExecSQL(sql;
//{
// MessageBox.Show("更新成功!"; //}
//DateTime.Now.ToShortTimeString(; DateTime dt = DateTime.Now;



string time = dt.ToShortDateString(.ToString(.Trim(; DateTime beBackTime = dt.AddDays(Day; string strsql = "INSERT INTO
Rrecord(rSno,rName,bId,bName,bTime,beBackTimeVALUES('" + txtReader.Text.Trim( + "','" + txtReaderName.Text.Trim( + "','" + txtBookId.Text.Trim( + "','" + txtBookName.Text.Trim( + "','" + time + "','" + beBackTime.ToShortDateString(.ToString(.Trim( + "'";
if (clsGlobalVar.ExecSQL(strsql
{
MessageBox.Show("借书成功!";
txtBorrowDate.Text = time;
this.btnSearch_Click(sender, e; this.btnBookSelect_Click(sender, e;


}
else
{
MessageBox.Show("借书失败!";
}

}
}


private void btnBackBook_Click(object sender, EventArgs e {
if (txtBookId.Text == ""

{
MessageBox.Show("读者编号和图书编号不能为空!";
}
else
{
this.btnSearch_Click(sender, e; this.btnBookSelect_Click(sender, e;


state3++;
string a = state3.ToString(.Trim(;
string SQL = "UPDATE Bmanage SET bNumber=" + a + "WHERE bId='" + txtBookId.Text
+ "'";
clsGlobalVar.ExecSQL(SQL; //{
// MessageBox.Show("更新成功!"; //}



state1--;
string b = state1.ToString(.Trim(;
string sql = "UPDATE Reader SET rState=" + b + "WHERE rSno='" +
txtReader.Text.Trim( + "' ";


clsGlobalVar.ExecSQL(sql;
//{
// MessageBox.Show("更新成功!"; //}

string strsql1 = "SELECT S.Fine AS Fine,S.rDay AS rDay ,Rr.bTime AS bTime FROM
SysSet S INNER JOIN (Reader R INNER JOIN Rrecord Rr ON R.rSno=Rr.rSno ON S.rRole=R.rRole WHERE
R.rSno='" + txtReader.Text.Trim( + "'AND Rr.bId='" + txtBookId.Text.Trim( + "'";
DataTable ds = clsGlobalVar.GetDataTable(strsql1; if (ds.Rows.Count == 0
{
MessageBox.Show("查询错误!";
}
else
{

x = float.Parse(ds.Rows[0]["Fine"].ToString(.Trim(; y = Int32.Parse(ds.Rows[0]["rDay"].ToString(.Trim(; txtBorrowDate.Text = ds.Rows[0]["bTime"].ToString(.Trim(;

}


DateTime time = DateTime.Now;
string T = time.ToShortDateString(.ToString(.Trim(;
txtBackDate.Text = T;
TimeSpan span = time.Subtract(DateTime.Parse(txtBorrowDate.Text; int i = span.Days;
string strsql = "DELETE FROM Rrecord WHERE rSno='" + txtReader.Text.Trim( +
"'AND bId='" + txtBookId.Text.Trim( + "'";
if (clsGlobalVar.ExecSQL(strsql
{
if (i > y
{
z = x * (i - y;
txtFine.Text = z.ToString(.Trim(;
MessageBox.Show("还书成功,请交罚款" + txtFine.Text.Trim( + "元!";
//MessageBox.Show("还书成功!"; this.btnSearch_Click(sender, e;



} {


this.btnBookSelect_Click(sender, e; //txtBorrowDate.Text = ""; //txtBackDate.Text = "";
else
MessageBox.Show("还书成功!"; this.btnSearch_Click(sender, e; this.btnBookSelect_Click(sender, e; //txtBorrowDate.Text = ""; //txtBackDate.Text = "";
}

}
else
{
MessageBox.Show("还书失败!";
}
}

}


private void button4_Click(object sender, EventArgs e {
this.Close(;
}


private void btnReset_Click(object sender, EventArgs e {
txtReader.Text = ""; txtReaderName.Text = ""; txtBookId.Text = ""; txtBookName.Text = ""; txtBorrowDate.Text = ""; txtBackDate.Text = ""; txtFine.Text = ""; txtState.Text = ""; txtBooksState.Text = "";

}



private void btnQuery_Click(object sender, EventArgs e
{
if (txtReader.Text == ""

{
MessageBox.Show("读者编号不能为空,请重新输入";


}
else
{
string SQL = "SELECT rSno AS 读者编号,rName AS 读者姓名,bId AS 图书编号,bName
AS 图书名称,bTime AS 借书日期,beBackTime AS 到期日期 FROM Rrecord WHERE rSno='" + txtReader.Text.Trim( + "'";
try
{
DataTable dt = clsGlobalVar.GetDataTable(SQL; if (dt.Rows.Count == 0
{
MessageBox.Show("无借阅信息!", "操作提示", MessageBoxButtons.OK,
MessageBoxIcon.Error; }
else
{
DG.DataSource = dt;

}

}
catch (Exception ex
{
MessageBox.Show("操作数据库出错!", "操作演示", MessageBoxButtons.OK,
MessageBoxIcon.Error;
Console.WriteLine(ex.Message;
}

} }

}
}

10系统设置窗口


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.DBAccess;

namespace prjTSGL.TSGL_UI {
public partial {
public frmSys(
{
InitializeComponent(;
}


private void btnCancel_Click(object sender, EventArgs e {
this.Close(;
}


private void btnOK_Click(object sender, EventArgs e {
if (txtMoney.Text.Trim( == "" && txtNumber.Text.Trim( == "" && txtDay.Text.Trim(
== "" || cboRole.Text.Trim( == "" {
MessageBox.Show("请输入设置信息!";
}
else
{


string sql = "SELECT *FROM SysSet WHERE rRole='" + cboRole.Text.Trim( + "'"; DataTable dt = clsGlobalVar.GetDataTable(sql;
label7.Text = cboRole.Text.Trim(;
if (dt.Rows.Count == 0
{
string SQL = "INSERT INTO SysSet (rRole,rState,Fine,rDayVALUES ('" +
cboRole.Text.Trim( + "','" + txtNumber.Text.Trim( + "','" + txtMoney.Text.Trim( + "','" + txtDay.Text.Trim( + "'";
if (clsGlobalVar.ExecSQL(SQL == true

{
txtNumber.Text = ""; txtMoney.Text = "";
class frmSys : Form



txtDay.Text = "";


MessageBox.Show("Set New Data Success!"; }
else
{
Exception ex = new }

}
else
{
MessageBox.Show("" + cboRole.Text.Trim( + "信息已设置!";
cboRole.Focus(; }

}
}


private void btnQuery_Click(object sender, EventArgs e {
if (cboRole.Text.Trim( == ""

{
MessageBox.Show("请选择角色!";
}
else
{


string SQL = "SELECT rRole,rState,Fine,rDay FROM SysSet WHERE rRole='" +
cboRole.Text.Trim( + "' ";
DataTable dt = clsGlobalVar.GetDataTable(SQL;
label7.Text = cboRole.Text.Trim(;
if (dt.Rows.Count==0
{
MessageBox.Show("抱歉,查询失败!", "结果提示", MessageBoxButtons.OK,
MessageBoxIcon.Information; }
else
{
Exception(;
MessageBox.Show(ex.Message.ToString(;



cboRole.Text = dt.Rows[0]["rRole"].ToString(.Trim(; txtNumber.Text = dt.Rows[0]["rState"].ToString(.Trim(; txtMoney.Text = dt.Rows[0]["Fine"].ToString(.Trim(; txtDay.Text = dt.Rows[0]["rDay"].ToString(.Trim(;

}

}
}


private void btnUpdate_Click(object sender, EventArgs e {
if (cboRole.Text.Trim( == ""

{
MessageBox.Show("请选择角色!";
}
else
{
label7.Text = cboRole.Text.Trim(;
string SQL = "UPDATE SysSet SET rState='" + txtNumber.Text.Trim( + "',Fine='" + txtMoney.Text.Trim( + "',rDay='" + txtDay.Text.Trim( + "' WHERE rRole='" + cboRole.Text.Trim( + "' ";


if (clsGlobalVar.ExecSQL(SQL
{
txtNumber.Text = ""; txtMoney.Text = ""; txtDay.Text = "";
MessageBox.Show("修改已成功";


}
else
{
MessageBox.Show("修改失败!", "操作提示", MessageBoxButtons.OK,
MessageBoxIcon.Error; } } }

} }

11连接数据库




using System;
using System.Collections.Generic; using System.Linq; using System.Text;
using System.Data.SqlClient; using System.Data;
using QCI.OF_Common;

namespace prjTSGL.ClassLib.DBAccess {
public class clsGlobalVar {
public static string StrConn = "Data Source=CA1070649;Persist Security Info=True;Initial
Catalog=TSGL;User ID=TEST;PASSWORD =TEST;";
public static

public static {
try
{

conn = new SqlConnection(StrConn;
if (conn.State == ConnectionState.Closed
{
conn.Open(; }
SqlDataAdapter Adap = new DataTable ds = new Adap.Fill(ds; conn.Close(;
return ds;
}
catch (Exception ex
{
throw ex;
} }


public static {
string fieldValue = "";
string GetFieldValue(string strSQL
SqlDataAdapter(strSQL, conn;
DataTable(;
SqlConnection conn = null;
DataTable GetDataTable(string strSQL



conn = new SqlConnection(StrConn;
if (conn.State == ConnectionState.Closed
{
conn.Open(; }
using (SqlCommand sqlCommand = new SqlCommand(strSQL, conn
{
try
{
object objFieldValue = sqlCommand.ExecuteScalar(; if (objFieldValue != null

{
fieldValue = objFieldValue.ToString(; } }
catch (Exception e
{
throw new Exception(e.Message, e;
}
return fieldValue;
} }


public static bool ExecSQL(string strSQL
{

conn = new SqlConnection(StrConn;
if (conn.State == ConnectionState.Closed
{
conn.Open(; }
bool result;
using (SqlCommand sqlcommand = new SqlCommand(strSQL, conn
{
try
{
sqlcommand.ExecuteNonQuery(; result = true; }
catch (Exception e
{
throw e;
}
return result;



} } }
}

本文来源:https://www.2haoxitong.net/k/doc/9274e71b10a6f524ccbf85a7.html

《图书馆管理系统设计(附带源代码).doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式