图书管理系统的设计
一、
二、
三、
四、
系统分析 ................................................................................................................................................ 2
1. 开发背景 ................................................................................................................................................ 2
2. 需求分析 ................................................................................................................................................ 2
系统设计 ................................................................................................................................................ 2
1. 系统总体结构 ........................................................................................................................................ 2
2. 数据库设计............................................................................................................................................ 3
3. 编码设计 ................................................................................................................................................ 4
系统实施 ................................................................................................................................................ 4
1. 登录 .........................................................................................................................................................4
2. 系统主界面............................................................................................................................................ 5
3. 书库管理 ................................................................................................................................................ 6
1) 新书登记:.................................................................................................................................... 6
2) 借书/还书:................................................................................................................................... 9
1) 缴费 .............................................................................................................................................. 15
2) 书籍挂失:.................................................................................................................................. 18
3) 图书信息查询:.......................................................................................................................... 22
4) 借书信息查询:.......................................................................................................................... 23
4. 借阅证管理: ...................................................................................................................................... 24
1) 办理借阅证: .............................................................................................................................. 24
2) 借阅证信息查询: ...................................................................................................................... 26
3) 借阅证挂失: .............................................................................................................................. 26
5. 系统/其它:......................................................................................................................................... 28
1) 添加账号:.................................................................................................................................. 28
2) 修改密码:.................................................................................................................................. 30
3) 退出:.......................................................................................................................................... 31
总结(体会、经验与教训) .............................................................................................................. 31
一、 系统分析
1. 开发背景
随着人们知识层次的提高,图书馆成为日常生活中不可缺少的一部分。而图书馆的存
数量和业务量庞大,仅仅靠传统的记账式管理是不可行的。图书馆管理系统应运而生,逐
渐成为信息化建设的重要组成部分。图书馆管理系统为学校或社会型图书馆的管理员提供
所有借阅者的详细信息,以及馆内库存的详细情况,对借书和还书两大功能进行合理操纵
并登记。
2. 需求分析
经过仔细分析系统需求之后,本图书管理系统主要完成的主要功能如下:
进入系统前需要身份验证、用户名、密码,输入正确后方可进入。
用户可以根据需要进行书库管理。
用户可以进行借书证的办理、查询、挂失等操作。
用户可以添加账户和修改密码。
身份验证:提供系统的访问控制功能。
书库管理:包括新书登记、借书、还书、书籍挂失、图书信息查询、借书信息查询等
功能。
借阅证管理:提供办理借阅证、借阅证信息查询、借阅证挂失功能。
系统管理功能:包括添加账号、修改密码和退出系统等功能。
二、 系统设计
1. 系统总体结构
通过对图书管理系统的功能分析,可以定义出系统的功能模块图如下:
2. 数据库设计
管理员基本信息表
字段名称
WorkID
User_Name
Password
数据类型
int
VARCHAR(24)
VARCHAR(24)
约束条件
可否为空
NOT NULL 主键
NOT NULL 无
NOT NULL 无
图书信息表
字段名称
Book_ID
Book_Name
Writer
Press
Price
InLibrary_Date
Total_Amount
Now_Amount
约束条件
可否为空
数据类型
VARCHAR(50) NOT NULL 主键
VARCHAR(50) NOT NULL 无
VARCHAR(50) NOT NULL 无
VARCHAR(50) NOT NULL 无
NOT NULL 无
float
NOT NULL 无
datetime
int
NOT NULL 无
NOT NULL 无
int
说明
成员 ID
姓名
密码
说明
书籍 ID
书名
作者
出版社
单价
入库时间
总量
现存量
借阅卡信息表
字段名称
Proof_ID
Name
Sex
可否为空
数据类型
VARCHAR(50) NOT NULL 主键
VARCHAR(50) NOT NULL 无
VARCHAR(50) NOT NULL 无
约束条件 说明
借阅卡 ID
姓名
性别
Birth_Time
Address
ID_Number
Tel_Number
Now_Borrow_Amount
借书信息表
datetime
NOT NULL 无
VARCHAR(50) NOT NULL 无
VARCHAR(50) NOT NULL 无
VARCHAR(50) NOT NULL 无
NOT NULL 无
int
出生日期
地址
身份证号
电话号码
现借书量
字段名称
BorrowID
Proof_ID
Book_ID
Borrow_Date
数据类型
int
VARCHAR(50)
VARCHAR(50)
datetime
罚单信息表
约束条件
可否为空
NOT NULL 主键
NOT NULL 外键(Proof_Info) 借书卡 ID
NOT NULL 外键(Book_Info) 书籍 ID
NOT NULL 无
说明
借书 ID
借出时间
字段名称
Puni_ID
Proof_ID
Book_ID
Borrow_Date
Return_Date
Puni_Money
数据类型
int
VARCHAR(50)
VARCHAR(50)
datetime
datetime
float
约束条件
可否为空
NOT NULL 主键
NOT NULL 无
NOT NULL 无
NOT NULL 无
NOT NULL 无
NOT NULL 无
说明
罚单 ID
借书卡 ID
书籍 ID
借出时间
还书时间
罚金
3. 编码设计
WorkID,BorrowID,Puni_ID 都设置了标识规范,增加记录时自动加 1,保持其唯
一性。
Borrow_Date,Return_Date,InLibrary_Date 都设置成 datetime 类型,插入记录时自
动获取当前日期,不需要管理员输入日期。
Proof_ID,Book_ID,ID_Number,Tel_Number,Proof_ID 由于它们只是代表一个标
识,不是一个表示大小的数字,所以用 VARCHAR 类型,用 int 或 long 可能会有溢
出现象。
三、 系统实施
1. 登录
功能说明:验证管理员的用户名和密码是否正确,正确则进入主界面。
源代码:
头文件:using System.Data.SqlClient;
连接数据库:
SqlConnection
con
new
=
SqlConnection("server=20100310-1827\\SQLEXPRESS;database=Library;Integrated
Security=True");
程序主体:
private void button_exit_Click(object sender, EventArgs e)//退出
{
Application.Exit();
}
private void button_log_Click(object sender, EventArgs e)//登录
{
if (this.UserName.Text.Trim() == "" || this.PassWord.Text.Trim() == "")
MessageBox.Show("用户名和密码都不能为空!");
if (con.State == ConnectionState.Closed)
con.Open();
String str = "select count(*) from Admin_Info where User_Name='" + this.UserName.Text.Trim() +
"' and Password='" + this.PassWord.Text + "'";
SqlCommand com = new SqlCommand(str, con);
int i = Convert.ToInt32(com.ExecuteScalar());
if (i > 0)
{
Form2 form2 = new Form2();//系统主界面
form2.Show();
this.Visible = false;
}
else
{
MessageBox.Show("用户名或密码输入有误,请重新输入!");
this.UserName.Text = "";
this.PassWord.Text = "";
}
}
界面演示:
登录名和密码正确的话进入系统主界面(图一);登录名或者密码不正确的话会弹出提
示对话框,并将用户名、密码栏置空(图二);如果用户名或者密码有空,弹出对话框并将
用户名、密码栏置空(图三)。
图 1
图 2
图 3
图 4
2. 系统主界面
功能说明:选择各个功能模块
源代码:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void button_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button_new_book_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();//新书登记
form3.Show();
}
//初始化对应界面,和上面类似,不再赘述
……
界面演示:如图 4
3. 书库管理
1) 新书登记:
功能说明:
入库的实现过程是首先要输入书籍的各种信息,包括书的书号、书名、作者、出版社、
价钱、总量、现存量等,这里书的数量由两个变量来记录,总量代表图书馆中这种这种书
的总量,现存量是目前正在管中的量,两者之差就是被读者借出去的数量。其中每个信息
不能有遗漏或者格式不正确,因为这是每一本书的基本信息,在函数的实现过程中有检验
的功能。然后判断图书馆中是否存在这种图书,如果存在,那么时间简单的把库存的数量
加上新加入的数量,如果不存在,那么就要新建记录。
源代码:
连接数据库:
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
程序主体:
//主界面调用的每个模块的返回按钮都是隐藏本体,以后不再写出返回按钮的操作带代码
private void button_back_Click(object sender, EventArgs e)//返回
{
this.Visible = false;
}
private void button_in_Click(object sender, EventArgs e)//入库
{
int res;
//检验输入数据是否合法
if (this.textBox_book_no.Text.Trim() == ""||this.textBox_name .Text .Trim ()==""
||this.comboBox_press .Text .Trim ()==""||this.textBox_price .Text .Trim ()==""
||this.textBox_total .Text .Trim ()==""||this.textBox_writer .Text .Trim ()=="")
{
MessageBox.Show ("请正确填写要求的数据!", "新书入库登记");
this.textBox_book_no.Text = "";
this.textBox_name.Text = "";
this.comboBox_press .Text = "";
this.textBox_price.Text = "";
this.textBox_total.Text = "";
this.textBox_writer.Text = "";
}
//判断书库中是否有该书,有,仅把数量加进去,没有,加进一条新的记录
else
{
if (con.State == ConnectionState.Closed)
con.Open();
String str1 = "select Total_Amount from Book_Info where Book_ID='"
+ this.textBox_book_no.Text.Trim() + "'";
SqlCommand com1 = new SqlCommand(str1, con);
int total_num = Convert.ToInt32(com1.ExecuteScalar());
String str2 = "select Now_Amount from Book_Info where Book_ID='"
+ this.textBox_book_no.Text.Trim() + "'";
SqlCommand com2 = new SqlCommand(str2, con);
int now_num = Convert.ToInt32(com2.ExecuteScalar());
int num1 = Convert.ToInt32(this.textBox_total.Text);
total_num += num1;
now_num += num1;
String str = "select count(*) from Book_Info where Book_ID='"
+ this.textBox_book_no.Text.Trim() + "'";
SqlCommand com = new SqlCommand(str, con);
int i = Convert.ToInt32(com.ExecuteScalar());
if (i > 0)
{
String str3 = "update dbo.Book_Info set Total_Amount= '" +
total_num.ToString ().Trim () +"' ,Now_Amount='" + now_num.ToString() .Trim ()
+ "'where Book_ID='" + this.textBox_book_no.Text.Trim() + "'";
da.UpdateCommand = new SqlCommand(str3, con);
res=da.UpdateCommand.ExecuteNonQuery();
if(res>0)
MessageBox.Show("新书入库成功!","新书登记");
else
MessageBox.Show("新书入库失败!", "新书登记");
}
else
{
String bookid = this.textBox_book_no.Text .ToString().Trim();
String name = this.textBox_name.Text .ToString().Trim();
String writer = this.textBox_writer.Text .ToString().Trim();
String press = this.comboBox_press .Text .ToString().Trim();
float
String dt = DateTime.Now.ToString();
int totalaccount = Convert.ToInt32(total_num.ToString().Trim());
int nowacount =Convert .ToInt32 (now_num.ToString().Trim());
String str3 = "insert into dbo.Book_Info (Book_ID,Book_Name,Writer,Press,Price,"+
price =(float) Convert.ToDouble (this.textBox_price.Text .ToString().Trim());
"InLibrary_Date,Total_Amount,Now_Amount) " +"values ('"+bookid+"','"+name+"','"
+writer+"','"+press+"','"+price+"','" + dt + "','"+totalaccount+"','"+nowacount+"')";
da.InsertCommand = new SqlCommand(str3, con);
res=da.InsertCommand.ExecuteNonQuery();
if (res > 0)
MessageBox.Show("新书入库成功!", "新书登记");
else
MessageBox.Show("新书入库失败!", "新书登记");
}
con.Close();
}
}
//主界面调用的每个模块的关闭按钮都是隐藏本体,以后不再写出关闭按钮的操作带代码
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
{
this.Visible = false;
}
private void button_check_Click(object sender, EventArgs e)//查询
{
if (con.State == ConnectionState.Closed)
con.Open();
int i;
String str1;
ds.Tables.Clear();
if (this.textBox_book_no.Text.Trim() == "" && this.textBox_name.Text.Trim() == ""
&& this.comboBox_press .Text.Trim() == "" && this.textBox_price.Text.Trim() == ""
&& this.textBox_total.Text.Trim() == "" && this.textBox_writer.Text.Trim() == "")
{
}
MessageBox.Show("请填写任一项进行查询!", "新书入库登记");
else
{
if (this.textBox_book_no.Text != "")//按书号查找
{
String str = "select count(*) from dbo.Book_Info where Book_ID='" +
this.textBox_book_no.Text.ToString().Trim() + "'";
da.SelectCommand = new SqlCommand(str, con);
i = Convert.ToInt32(da.SelectCommand.ExecuteScalar());
if (i > 0)
{
str1 = "select * from dbo.Book_Info where Book_ID='" +
this.textBox_book_no.Text.ToString().Trim() + "'";
da.SelectCommand = new SqlCommand(str1, con);
da.Fill(ds, "selectifo2");
dataGridView_result.DataSource = ds.Tables["selectifo2"];
dataGridView_result.Refresh();
}
else
{
MessageBox.Show("不存在此记录!");
}
}
else if (this.textBox_name.Text != "")//按书名查找
{
……//和上面类似
}
else if (this.textBox_writer.Text != "")//按作者查找
{
……//和上面类似
}
else if (this.textBox_price.Text != "")//按单价查找
{
……//和上面类似
}
else if (this.comboBox_press.Text != "")//按出版社查找
{
……//和上面类似
}
else if (this.textBox_total.Text != "")//按总量查找
{
……//和上面类似
}
}
con.Close();
}
//更新的代码操作就是将控件内容置空,每个模块都是,所以以后的更新操作不再给出具体代码
private void button_update_Click(object sender, EventArgs e)//更新
{
this.textBox_book_no.Text = "";
this.textBox_name.Text = "";
this.comboBox_press .Text = "";
this.textBox_price.Text = "";
this.textBox_total.Text = "";
this.textBox_writer.Text = "";
}
private void dataGridView_result_CellClick(object sender, DataGridViewCellEventArgs e)
{
int i = dataGridView_result.CurrentRow.Index;//dataGridView当前选中行
this.textBox_book_no.Text = ds.Tables["selectifo2"].Rows[i][0].ToString();
this.textBox_name.Text = ds.Tables["selectifo2"].Rows[i][1].ToString();
this.textBox_writer.Text = ds.Tables["selectifo2"].Rows[i][2].ToString();
this.textBox_price.Text = ds.Tables["selectifo2"].Rows[i][4].ToString();