C# 图书馆信息管理系统

更新时间:2024-04-14 19:36:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

《C#程序设计》

课程设计报告

课程设计任务书 课题名称 指导教师 图书馆信息管理系统 职称 讲师 学生姓名 完成时间 16周 班 级 总体设计要求和技术要点 1. 总体功能描述 本系统实现图书馆日常管理事务最主要的功能,包括图书的借出与归还,图书信息、读者信息、员工信息的录入、修改和查询。 2. 开发工具:本系统采用SQL Server 创建后台数据库,前台开发工具采用Visual Studio 2010,编程语言为C#。 3. 基本要求: ? 操作简便 ? 功能齐全,风格统一 ? 没有明显错误和异常 ? 数据格式验证 工作内容及时间进度安排 1.15周:需求分析及项目的设计与实现 2.16周:项目验收与答辩,撰写课程设计报告 课程设计成果 1.图书馆信息管理系统软件 2.课程设计报告

摘要

随着着科学技术的高速发展,我们已步入数字化、网络化、信息化的时代。图书馆是学校的文献信息中心,是为全校教学和科学研究服务的学术性机构,是学校信息化的重要基地。图书馆的工作是学校教学和科学研究工作的重要组成部分,是全校师生学习和研究的重要场所。为了更好地适应这种网络数字化信息的环境,提高利用图书馆检索信息的效率,一种成功的跟踪最新技术、充分利用软硬件资源、扎根于准、新、全数字资源的\图书馆信息管理系统\已孕育而生。

图书馆在正常运营中面对大量书籍、读者信息以及两者间相互联系产生的借书信息、还书信息、图书预约信息等。人工记录方法既效率低又错误过多,大大影响了图书馆的正常管理工作。因此需要对书籍信息、读者信息、借书信息、还书信息、图书预约信息等进行统一管理,及时了解各个环节中信息的变更,有利于管理效率的提高,同时为了提高工作效率、服务质量和管理水平,并使图书馆管理人员从繁琐的工作中解脱出来,故开发该图书馆信息管理系统。本系统在实现现有系统功能的基础之上,为用户提供便利的功能,使得本软件能够更好的满足用户的需求、更具人性化、使用起来更加方便。

关键词:信息化 图书馆 管理 人性化

目 录

课程设计任务书 .......................................................... 1 摘要 .................................................................... 2 目 录 .................................................................. 0 第1章 绪论 ............................................................ 2

1.1课题研究现状分析 ................................................ 2

1.1.1 本领域内已开展的研究工作 ........................................................................ 2 1.1.2 已经取得的研究成果 .................................................................................... 2 1.2选题的目的及意义 ................................................ 2 第2章 系统需求分析 .................................................... 3

2.1 问题的提出 ...................................................... 3 2.2 系统的设计目标 .................................................. 3 第3章 系统总体设计 .................................................... 4

3.1系统功能设计 .................................................... 4

一、系统登录 .................................................................................................. 4 二、借阅归还处理模块 .................................................................................. 5 三、图书信息管理模块 .................................................................................. 6 四、读者信息管理模块 .................................................................................. 6 五、员工信息管理模块 .................................................................................. 7 六、信息查询模块 .......................................................................................... 8

3.2数据库的设计 .................................................... 9 3.3数据库中各个表的设计 ............................................ 9 第4章 系统实现 ....................................................... 12

4.1 数据库操作类 ................................................... 12 4.2 登录模块实现 ................................................... 12 4.3 借阅归还模块实现 ............................................... 16 4.4 图书管理模块实现 ............................................... 22 4.5 读者管理模块实现 ............................................... 29 4.6 员工管理模块实现 ............................................... 32 第5章 系统使用说明 ................................................... 44 第6章 课程设计总结 ................................................... 46

6.1 主要问题及解决办法 ............................................. 46 6.2 课程设计体会 ................................................... 46 6.3 自我评定 ....................................................... 46

参考文献 ............................................................... 47

第1章 绪论

随着信息产业的飞速发展,信息化管理已经引入并应用到各行业管理领域,各种形式的百货商场、大型仓储超市、便利店、连锁超市和专卖店等形式的零售业鳞次栉比,不断改变、影响着人们的价值观念和生活方式。因此,要提升企业竞争力,就要大力推进企业信息化建设,利用先进的办公自动化系统来实现企业内部信息管理、共享及交流,才能使企业在竞争激烈的21世纪取得先机。

1.1课题研究现状分析

在日常的图书馆信息管理中,事务繁琐、工作量大,如果通过使用计算机管理软件可以减少大量的手工操作,提高工作效率。图书馆信息管理过去采用人工处理方式,由于工作量巨大,极易出现管理上的错误,给人们带来诸多的不便利。为了提高工作效率,方便管理,因此需要开发一个图书馆信息管理系统,以应对日趋复杂的图书馆管理系统。

本次课题为:图书馆信息管理系统,它的主要功能是先通过用户身份验证,然后根据不同的身份,拥有不同的功能。读者登录系统后可完成对个人信息的管理,管理员登录系统后可完成对图书、读者、员工的信息管理和借阅图书、归还图书的功能。

1.1.1 本领域内已开展的研究工作 1. 理论研究基础

(1) 后台以SQL数据库支持。

(2) 前台以 Microsoft Visual Studio 2010为开发环境,实现图书馆信息的管理 2. 技术层面的支持

(1)系统的设计与实现采用C#中典型的三层架构分层模式。

(2)系统界面采用MDI方式,即用户登录后进入主窗体,主窗体通过按钮进入子窗体。 1.1.2 已经取得的研究成果

社会上已存在形形色色的图书馆信息管理系统,各大图书馆均已实现对图书馆的信息化管理。

1.2选题的目的及意义 目的:解决

意义:通过此图书馆信息管理系统可以有效的对图书馆的基本信息进行管理,提高图书馆的事务处理流程。

2

第2章 系统需求分析

随着经济全球化的推进以及企业激烈的竞争,改善企业内部及整个供应链各环节的管理、调度及资源配置,迅速适应客户的新需求和市场新机遇,是企业赢得竞争胜利的决定性因素。

系统采用先进的两层体系结构,Client(客户端)负责提供表达逻辑、显示用户界面信息、基本操作;Server(服务器端)负责实现数据服务。

2.1 问题的提出

为了提高工作效率,方便管理,因此需要开发一个图书馆信息管理系统,以应对日趋复杂的图书馆管理系统。

2.2 系统的设计目标

本系统是对图书馆进行一体化管理的软件系统,其主要功能是先通过用户身份验证,然后根据不同的身份,拥有不同的功能。读者登录系统后可完成对个人信息的管理,管理员登录系统后可完成对图书、读者、员工的信息管理和借阅图书、归还图书的功能。

3

第3章 系统总体设计

3.1系统功能设计

本系统总体分为借阅处理模块、信息查询模块、图书信息管理模块、读者信息管理模块、员工信息管理模块、系统设置模块。如图3-1所示:

图3-1 系统功能模块图

各功能模块设计:

? 借阅处理模块:用于完成图书的借阅和归还功能。

? 信息查询模块:查询读者、图书的基本信息和读者的借阅信息。 ? 图书信息管理模块:实现对图书信息的增加、修改和删除。 ? 读者信息管理模块:实现对读者信息的增加、修改和删除。 ? 员工信息管理模块:实现对读者信息的增加、修改和删除 ? 系统设置模块:登录系统。 一、系统登录

登录为用户使用系统的起始点,用户必须先通过身份验证,方可登录图书馆信息管理系统进行相关操作,登录流程如下图所示:

4

开始输入用户名、密码验证用户名、密码成功登录相应主窗体失败结束图 3-2 登录模块流程图

简要说明及功能描述:

功能主要是用于确保用户在提供正确的验证信息之后,可以进一步使用本系统。 二、借阅归还处理模块

开始输入图书编号和读者编号判断有无此图书是否判断有无此读者是借阅(归还)图书否结束图 3-3 图书处理模块流程图

简要说明及功能描述:

功能主要是完成读者借阅图书和归还图书的操作。

5

三、图书信息管理模块

开始删除、修改或添加图书判断信息是否正确否是将相应的操作写入数据库结束图 3-4 图书信息管理模块流程图

简要说明及功能描述:

功能主要是完成对图书信息的管理,对图书信息进行删除、修改、添加等操作。

四、读者信息管理模块

开始删除或添加读者判断信息是否正确否是将相应的操作写入数据库结束图 3-5 读者信息管理模块流程图

6

简要说明及功能描述:

功能主要是完成对读者信息的管理,包括对读者信息的删除和添加。

五、员工信息管理模块

开始删除、修改或添加员工判断信息是否正确否是将相应的操作写入数据库结束图 3-6 员工信息管理模块流程图

简要说明及功能描述:

功能主要是完成对员工信息的管理,包括对员工信息的删除、删除和添加。

7

六、信息查询模块

开始输入查询内容查询有无查询结果是显示否结束图 3-7 信息查询模块流程图

简要说明及功能描述:

功能主要是完成基本信息的查询,包括读者、图书的基本信息和读者的借阅信息。

8

3.2数据库的设计

本系统采用SQL Server 2005数据库管理系统,创建的数据库名称为:LibraryManageSystem,数据库中包含5张表,各表功能及描述如表3-1所示:

表3-1 数据库中的表 表名 BookInformation ReaderInformation lendInformation ManagerInformation workInformation 记录图书的基本信息 记录读者的基本信息 记录读者的借阅信息 记录管理员的基本信息 记录图书馆员工的基本信息 作用 3.3数据库中各个表的设计 一、图书基本信息表 图书基本信息表

BookInformation

用于维护图书的基本情况,主键为BookId。表中各字段

表3-2 BookInformation表 定义及描述如表3-2所示。

图书信息表(BookInformation) 列名 图书编号(BookId) 图书类别(BookType) 图书名称(BookName) 图书作者(BookWriter) 出版社(BookPress) 图书库存(BookStore) 补充说明 数据类型(精度范围) varchar (10) varchar (10) varchar (50) varchar(20) varchar(50) varchar(10) 非空 空/非空 约束条件 主键

二、读者基本信息表

读者基本信息表ReaderInformation用于维护读者的基本情况,主键为ReaderId。表中各字段定义及描述如表3-3所示。

9

表3-3 ReaderInformation表

读者信息表(ReaderInformation) 列名 读者学号(ReaderId) 读者姓名(ReaderName) 读者密码(ReaderPwd) 读者班级(ReaderClass) 联系方式(ReaderPhone) 补充说明 数据类型(精度范围) varchar (10) varchar(20) varchar(20) varchar (5) varchar(20) 非空 空/非空 约束条件 主键

三、读者借阅信息表

读者借阅信息表lindInformation用于读者的借阅信息,主键以Id和ReaderId作为联合主键。表中各字段定义及描述如表3-4所示。

表3-4 lindInformation表

借阅信息表(lindInformation) 列名 序列号(Id) 读者学号(ReaderId) 图书编号(BookId) 借阅时间(BorrowTime) 图书名称(Bookname) 借书人(borrower) 补充说明 数据类型(精度范围) varchar (10) varchar (10) varchar(10) datatime varchar(20) varchar(20) 非空 非空 空/非空 约束条件 主键 主键

四、管理员信息表

管理员信息表ManagerInformation用于维护管理员的基本情况,主键为ManagerId。表中各字段定义及描述如表3-5所示。

表3-5 ManagerInformation表

管理员信息表(ManagerInformation) 列名 管理员编号(ManagerId) 管理员姓名(ManagerName) 管理员密码(ManagerPwd) 补充说明 数据类型(精度范围) varchar (10) varchar(20) varchar(20) 非空 空/非空 约束条件 主键

10

五、员工基本信息表

员工基本信息表workerInformation用于维护员工的基本情况,主键为workerId。表中各字段定义及描述如表3-7所示。

表3-7 workInformation表

员工信息表(workInformation) 列名 员工编号(workerid) 员工姓名(workerName) 联系方式(workerPhone) 补充说明 数据类型(精度范围) varchar (10) varchar(20) varchar(20) 非空 空/非空 约束条件 主键

11

第4章 系统实现

4.1 数据库操作类

DBHelper类用于实现数据库的连接

class DBHelper {

//定义连接数据库字符串

public static string connectStr = \ +\;

//创建连接对象connect

public static SqlConnection connect = new SqlConnection(connectStr);

}

4.2 登录模块实现

本系统的登录界面如图4-1所示,输入用户名和密码,选择登录角色,点击登录,判断用户名和密码是否正确,正确可进入相应角色的系统主界面,否则提示错误信息。点击重置,退用户名和密码清空。

图4-1 登录界面

登录按钮的代码为:

12

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 System.Data.SqlClient;

namespace Lesson {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void BtnLog_Click(object sender, EventArgs e) {

SqlCommand cmd = new SqlCommand();//执行Dsql语句 cmd.Connection = DBhelp.conn;//连接字符串 try {

DBhelp.conn.Open();

if(RadBtnManager.Checked)//判断

cmd.CommandText = \管理员登录名ManagerName='\ + txtName.Text + \;

else if(RadBtnReader.Checked)

cmd.CommandText = \读者姓名ResderName='\ + txtName.Text + \;

SqlDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) {

MessageBox.Show(\用户名不存在,请重新输入!\, \错误\, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else {

string strPsw = (string)reader[\登录密码LoginPwd\]; if (txtPwd.Text != strPsw) {

MessageBox.Show(\密码错误请重新输入!\, \错误\, MessageBoxButtons.OK,

13

MessageBoxIcon.Warning); }

else if (RadBtnReader.Checked) {

Reader re = new Reader();//类¤¨¤的ì?传??递ìY re.ReaderId = (int)reader[0];

re.ReaderName = reader[1].ToString(); re.LoginPwd = reader[2].ToString(); re.ReaderClass = reader[3].ToString(); re.ReaderTelp = reader[4].ToString(); ReaderForm read = new ReaderForm(); read.Tag = re; read.Show(); } else {

ManagerForm manager = new ManagerForm(); manager.Show(); } }

reader.Close(); }

catch (SqlException ex) {

MessageBox.Show(ex.Message); } finally {

DBhelp.conn.Close(); } }

private void BtnRset_Click(object sender, EventArgs e)//重置按钮清空用户名和密码 {

txtName.Text = \; txtPwd.Clear(); }

private void Form1_Load(object sender, EventArgs e) {

RadBtnReader.Checked = true; timer1.Start();

label3.Text = DateTime.Now.ToShortDateString();

14

lbltime.Text = DateTime.Now.ToLongTimeString(); }

private void timer1_Tick(object sender, EventArgs e) {

lbltime.Text = DateTime.Now.ToLongTimeString(); label3.Text = DateTime.Now.ToShortDateString(); }

} }

图4-2 错误的用户名和密码

15

4.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; using System.Data.SqlClient;

namespace Lesson {

public partial class ReaderbookForm : Form {

SqlDataAdapter dataAdapter;// 数据适配器 DataSet dataSet = new DataSet();// 数据集 public ReaderbookForm() {

InitializeComponent(); }

private void btnbooksearch_Click(object sender, EventArgs e)//查询 { try

16

{

btnreadborrow.Enabled = true;

dataSet.Clear();

string sqlSelectStr = \

if (txtCondition.Text.Trim() == \如果查询条件为空 则显示全部学生信息 {

sqlSelectStr = \图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation\ } else {

switch (cmbCondition.Text)//根据查询条件 进行相应的查询(允许模糊查询) {

case \图书编号\

sqlSelectStr = string.Format(\图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书编号BookId like '%{0}%'\ break; case \图书作者\

sqlSelectStr = \图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书作者BookAuthor like '%\ break;

case \图书出版社\

sqlSelectStr = \图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 出版社BookPublish like '%\ break; case \图书分类\

sqlSelectStr = \图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书类别BookType like '%\ break; case \图书名称\

sqlSelectStr = \图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书名称BookName like '%\ break; } }

dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象

//dataSet = new DataSet();

17

dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

dataGridvinf.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性) }

catch (Exception) {

MessageBox.Show(\输入有误!内容不存在!\ } finally {

DBhelp.conn.Close();

} }

private void btnrdbkborrow_Click(object sender, EventArgs e)//已借图书查询 {

Reader chuan = new Reader(); chuan =(Reader)this.Tag; dataSet.Clear();

string sqlSelectStr = \

sqlSelectStr = string.Format(\序列号Id,读者学号ReaderID,图书编号BookId,图书名称BookName,借阅时间BrrowLendTime,借书人borrower from LendInformation where 读者学号ReaderID='{0}'\chuan.ReaderId);

dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象 dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

dataGridVborrow.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性)

}

private void btnreadborrow_Click(object sender, EventArgs e)//借阅 {

DialogResult result = MessageBox.Show(\确定要借阅吗?\提示\MessageBoxIcon.Question);

if (result == DialogResult.Yes) {

Reader chua = new Reader(); chua =(Reader)this.Tag;

if (int.Parse(dataGridvinf.CurrentRow.Cells[5].Value.ToString()) == 0) {

MessageBox.Show(\本书现无库存\提示\

18

MessageBoxIcon.Information); } else {

DBhelp.conn.Open();// 打开数据库连接 string sql = \

sql = string.Format(\BookInformation set 图书剩余数量BookNum=图书剩余数量BookNum-1 where 图书编号BookId='{0}'\ SqlCommand command = new SqlCommand(sql, DBhelp.conn); command.ExecuteNonQuery();

string sqll = \

sqll = string.Format(\into LendInformation(读者学号ReaderID,图书编号BookId,图书名称BookName,借阅时间BrrowLendTime,借书人borrower) values

('{0}','{1}','{2}','{3}','{4}')\dataGridvinf.CurrentRow.Cells[2].Value, dateTimePicker1.Value, chua.ReaderName); SqlCommand comman = new SqlCommand(sqll, DBhelp.conn); comman.ExecuteNonQuery(); DBhelp.conn.Close();

MessageBox.Show(\借阅成功\提示\MessageBoxIcon.Information);

btnbooksearch_Click(sender, e); } } }

private void dataGridvinf_CellContentClick(object sender, DataGridViewCellEventArgs e) {

}

private void ReaderbookForm_Load(object sender, EventArgs e) {

btnreadborrow.Enabled = false; }

private void label1_Click(object sender, EventArgs e) {

} } }

19

还书界面“提交”按钮代码:

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 System.Data.SqlClient;

namespace Lesson {

public partial class ManlendForm : Form {

SqlDataAdapter dataAdapter;// 数据适配器 DataSet dataSet = new DataSet();// 数据集 public ManlendForm() {

InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { try {

20

dataSet.Clear();

string sqlSelectStr = \

if (txtCondition.Text.Trim() == \如果查询条件为空 则显示全部学生信息 {

sqlSelectStr = \读者学号ReaderID,图书编号BookId,图书名称BookName,借阅时间BrrowLendTime,借书人borrower from LendInformation\ } else {

switch (cmbCondition.Text)//根据查询条件 进行相应的查询(允许模糊查询) {

case \读者学号\

sqlSelectStr = \读者学号ReaderID,图书编号BookId,图书名称BookName,借阅时间BrrowLendTime,借书人borrower from LendInformation where 读者学号ReaderID like '%\txtCondition.Text + \

break; case \图书名称\

sqlSelectStr = \读者学号ReaderID,图书编号BookId,图书名称BookName,借阅时间BrrowLendTime ,借书人borrower from LendInformation where 图书名称BookName like '%\txtCondition.Text + \

break; case \图书编号\

sqlSelectStr = \读者学号ReaderID,图书编号BookId,图书名称BookName,借阅时间BrrowLendTime,借书人borrower from LendInformation where 图书编号BookId like '%\txtCondition.Text + \

break; } }

dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象

//dataSet = new DataSet();

dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

dataGridVlend.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性) }

catch (Exception) {

MessageBox.Show(\输入有误!内容不存在!\ } finally {

DBhelp.conn.Close();

21

} }

private void button2_Click(object sender, EventArgs e) {

DialogResult result = MessageBox.Show(\确定要归还吗?\提示\MessageBoxIcon.Question);

if (result == DialogResult.Yes) {

DBhelp.conn.Open();// 打开数据库连接 string sql = \

sql = string.Format(\图书编号BookId='{0}'\dataGridVlend.CurrentRow.Cells[1].Value);

SqlCommand command = new SqlCommand(sql, DBhelp.conn); command.ExecuteNonQuery(); string sqll = \

sqll = string.Format(\图书剩余数量BookNum=图书剩余数量BookNum+1 where 图书编号BookId='{0}'\ SqlCommand comman = new SqlCommand(sqll, DBhelp.conn); comman.ExecuteNonQuery(); DBhelp.conn.Close();

MessageBox.Show(\归还成功\提示\MessageBoxIcon.Information);

button1_Click(sender, e); } }

private void dataGridVlend_CellContentClick(object sender, DataGridViewCellEventArgs e) {

}

private void ManlendForm_Load(object sender, EventArgs e) {

} } }

4.4 图书管理模块实现

本系统的图书管理界面如图4-5所示,图书管理主要针对图书基本信息的查询、图书信息的修改、图书的增加和删除。

22

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 System.Data.SqlClient;

namespace Lesson {

public partial class ManbookForm : Form {

SqlDataAdapter dataAdapter;// 数据适配器 DataSet dataSet = new DataSet();// 数据 public ManbookForm()

图4-5 图书管理界面

23

{

InitializeComponent(); }

private void btnmanbooksearch_Click(object sender, EventArgs e) { try {

btnmanbookadd.Enabled = true; btnmanbookdel.Enabled = true; btnreset.Enabled = true; dataSet.Clear();

string sqlSelectStr = \

if (txtCondition.Text.Trim() == \如果查询条件为空 则显示全部学生信息 {

sqlSelectStr = \图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation\ } else {

switch (cmbCondition.Text)//根据查询条件 进行相应的查询(允许模糊查询) {

case \图书编号\

sqlSelectStr = string.Format(\图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书编号BookId like '%{0}%'\ break; case \图书作者\

sqlSelectStr = \ 图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书作者BookAuthor like '%\ break;

case \图书出版社\

sqlSelectStr = \ 图书编号BookId,图书类别BookType,图书名称

24

BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 出版社BookPublish like '%\ break; case \图书分类\

sqlSelectStr = \ 图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书类别BookType like '%\ break; case \图书名称\

sqlSelectStr = \ 图书编号BookId,图书类别BookType,图书名称BookName,图书作者BookAuthor,出版社BookPublish,图书剩余数量BookNum from BookInformation where 图书名称BookName like '%\ break; } }

dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象

//dataSet = new DataSet();

dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

datagrevbook.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性) }

catch (Exception) {

MessageBox.Show(\输入有误!内容不存在!\ } finally {

DBhelp.conn.Close();

} }

private void btnmanbookadd_Click(object sender, EventArgs e)//添加图书

25

{ try {

if (dataSet != null)//如果dataSet不为空 {

DBhelp.conn.Open();

string sql = \* from BookInformation where 图书编号BookId='\+ datagrevbook.CurrentRow.Cells[0].Value + \

SqlCommand com = new SqlCommand(sql, DBhelp.conn); SqlDataReader dr = com.ExecuteReader();

//string s=string.Format(\图书编号BookId from BookInformation\ if (dr.Read()) {

DBhelp.conn.Close();

MessageBox.Show(\该图书编号已存在!\\提示\MessageBoxButtons.OK, MessageBoxIcon.Information);

DBhelp.conn.Close(); dr.Close(); } else {

dr.Close();

DialogResult result = MessageBox.Show(\确定要添加吗?\\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) {

// 自动生成用于更新的命令

SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(dataSet, \将数据集中修改过的数据,提交到数据库

MessageBox.Show(\添加成功\\提示\MessageBoxButtons.OK, MessageBoxIcon.Information); } }

26

} }

catch (SqlException ex) {

MessageBox.Show(ex.Message); } finally {

DBhelp.conn.Close();

} }

private void btnmanbookdel_Click(object sender, EventArgs e)//删除图书 {

DialogResult result = MessageBox.Show(\确定要删除吗?\提示\MessageBoxIcon.Question);

if (result == DialogResult.Yes) {

foreach (DataGridViewRow dr in datagrevbook.SelectedRows) {

this.datagrevbook.Rows.Remove(dr); }

SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);

// 将数据集中修改过的数据,提交到数据库

dataAdapter.Update(dataSet, \ MessageBox.Show(\MessageBoxIcon.Information); }

MessageBox.Show(\保存成功\提示\ }

private void btnreset_Click(object sender, EventArgs e)//修改图书 {

27

删除成功\\提示\MessageBoxButtons.OK,

datagrevbook.CurrentRow.Cells[0].ReadOnly = false;

DialogResult result = MessageBox.Show(\确定要执行此操作吗?\\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question); DBhelp.conn.Open(); string strSql = \

strSql = string.Format(\图书类别BookType='{0}',图书名称BookName='{1}',图书作者BookAuthor='{2}',出版社BookPublish='{3}',图书剩余数量BookNum='{4}' where 图书编号BookId='{5}'\datagrevbook.CurrentRow.Cells[3].Value,

datagrevbook.CurrentRow.Cells[4].Value,

datagrevbook.CurrentRow.Cells[5].Value, datagrevbook.CurrentRow.Cells[0].Value); SqlCommand cmd = new SqlCommand(strSql, DBhelp.conn); cmd.ExecuteNonQuery(); DBhelp.conn.Close(); MessageBox.Show(\MessageBoxIcon.Information);

btnmanbooksearch_Click(sender, e); }

private void ManbookForm_Load(object sender, EventArgs e) {

btnmanbookadd.Enabled = false; btnmanbookdel.Enabled = false; btnreset.Enabled = false; }

private void datagrevbook_CellClick(object sender, DataGridViewCellEventArgs e) {

datagrevbook.CurrentRow.Cells[0].ReadOnly = true; }

private void cmbCondition_SelectedIndexChanged(object sender, EventArgs e) {

} }

28

操作完成!\\提示\MessageBoxButtons.OK,

}

4.5 读者管理模块实现

本系统的读者管理界面如图4-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 System.Data.SqlClient;

namespace Lesson {

public partial class ReaderSearch : Form

29

图4-6 读者管理界面

{

//SqlDataAdapter dataAdapter;// 数据适配器 //DataSet dataSet = new DataSet();// 数据集 public ReaderSearch() {

InitializeComponent(); }

private void btnreaderclear_Click(object sender, EventArgs e) {

txtreadertel.Clear(); txtreaderpwd.Clear(); txtreadername.Clear(); txtreaderclass.Clear(); }

private void btnreaderreset_Click(object sender, EventArgs e) {

txtreaderclass.Enabled = true; txtreadername.Enabled = true; txtreaderpwd.Enabled = true; txtreadertel.Enabled = true;

}

private void btnreaderok_Click(object sender, EventArgs e) {

// if (dataSet != null)//如果dataSet不为空 // {

// DialogResult result = MessageBox.Show(\确定要保存修改吗?\MessageBoxButtons.YesNo, MessageBoxIcon.Question);

// if (result == DialogResult.Yes)

30

\提示\

// {

// // 自动生成用于更新的命令

// SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);

// if(dataAdapter.Update(dataSet, \将数据集中修改过的数据,提交到数据库

// MessageBox.Show(\保存成功\\提示\MessageBoxButtons.OK, MessageBoxIcon.Information);

// } // }

DialogResult result = MessageBox.Show(\确定要保存修改吗?\\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question);

DBhelp.conn.Open();

string strSql = \ReaderInformation set 读者姓名txtreadername.Text + \读者学号ReaderId='\

SqlCommand cmd = new SqlCommand(strSql, DBhelp.conn); cmd.ExecuteNonQuery(); DBhelp.conn.Close(); MessageBox.Show(\MessageBoxIcon.Information);

}

private void ReaderSearch_Load(object sender, EventArgs e) {

Reader re = new Reader(); re =(Reader)this.Tag;

txtreaderclass.Text = re.ReaderClass; txtreadername.Text = re.ReaderName;

txtreadernumber.Text = re.ReaderId.ToString(); txtreadertel.Text = re.ReaderTelp; txtreaderpwd.Text = re.LoginPwd; txtreadernumber.Enabled = false; txtreaderclass.Enabled = false; txtreadername.Enabled = false; txtreaderpwd.Enabled = false;

31

ResderName='\+

保存成功\\提示\MessageBoxButtons.OK,

txtreadertel.Enabled = false; //Reader rea = new Reader(); //rea = (Reader)this.Tag;

lblwelcome.Text = \欢迎您:\同学\ }

private void txtreaderpwd_TextChanged(object sender, EventArgs e) {

} } }

4.6 员工管理模块实现

本系统的读者管理界面如图4-7所示,读者管理主要针对读者基本信息的查询、修改和读者的增加、删除。其功能实现方法与图书管理的实现方法类似。

图4-7 员工管理界面

32

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 System.Data.SqlClient;

namespace Lesson {

public partial class workForm : Form {

SqlDataAdapter dataAdapter;// 数据适配器 DataSet dataSet = new DataSet();// 数据 public workForm() {

InitializeComponent(); }

private void btnworkinf_Click(object sender, EventArgs e) { try {

button1.Enabled = true; btnworkadd.Enabled = true; btnworkdel.Enabled = true; dataSet.Clear();

//string sqlSelectStr = \

//sqlSelectStr = \员工号workerid,员工姓名workername,员工联系方式workertelp from workerinformation\

//dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象

//dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

//dataGridVwork.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性)

string sqlSelectStr = \

if (txtCondition.Text.Trim() == \如果查询条件为空 则显示全部学生信息 {

sqlSelectStr = \员工号workerid,员工姓名workername,员工联系方式workertelp from workerinformation\

33

} else {

switch (cmbCondition.Text)//根据查询条件 进行相应的查询(允许模糊查询) {

case \员工号\

sqlSelectStr = string.Format(\员工号workerid,员工姓名workername,员工联系方式workertelp from workerinformation where 员工号workerid like '%{0}%'\txtCondition.Text.Trim());

break; case \员工姓名\

sqlSelectStr = \员工号workerid,员工姓名workername,员工联系方式workertelp from workerinformation where 员工姓名workername like '%\ break;

case \员工联系方式\

sqlSelectStr = string.Format(\员工号workerid,员工姓名workername,员工联系方式workertelp from workerinformation where 员工联系方式workertelp like '%{0}%'\txtCondition.Text.Trim());

break; } }

dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象

//dataSet = new DataSet();

dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

dataGridVwork.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性)

}

catch (Exception) {

MessageBox.Show(\输入有误!内容不存在!\ } finally {

DBhelp.conn.Close();

} }

private void btnworkadd_Click(object sender, EventArgs e) { try

34

{

if (dataSet != null)//如果dataSet不为空 {

DBhelp.conn.Open();

string sql = \员工号workerid='\dataGridVwork.CurrentRow.Cells[0].Value + \

SqlCommand com = new SqlCommand(sql, DBhelp.conn); SqlDataReader dr = com.ExecuteReader();

//string s=string.Format(\图书编号BookId from BookInformation\ if (dr.Read()) {

DBhelp.conn.Close();

MessageBox.Show(\改员工Id已存在!\提示\MessageBoxIcon.Information);

DBhelp.conn.Close(); dr.Close(); } else {

dr.Close();

DialogResult result = MessageBox.Show(\确定要添加吗?\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) {

// 自动生成用于更新的命令

SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(dataSet, \将数据集中修改过的数据,提交到数据库

MessageBox.Show(\添加成功\提示\MessageBoxIcon.Information); } } } }

catch (SqlException ex) {

MessageBox.Show(ex.Message); } finally {

DBhelp.conn.Close();

} }

35

private void btnworkdel_Click(object sender, EventArgs e) {

DialogResult result = MessageBox.Show(\确定要删除吗?\提示\MessageBoxIcon.Question); DBhelp.conn.Open();

string strSql = \员工号workerid='\dataGridVwork.CurrentRow.Cells[0].Value + \

SqlCommand cmd = new SqlCommand(strSql, DBhelp.conn); cmd.ExecuteNonQuery(); DBhelp.conn.Close();

MessageBox.Show(\删除成功\提示\ foreach (DataGridViewRow dr in dataGridVwork.SelectedRows) {

this.dataGridVwork.Rows.Remove(dr); } }

private void textBox1_TextChanged(object sender, EventArgs e) {

}

private void button1_Click(object sender, EventArgs e) {

DialogResult result = MessageBox.Show(\确定要保存修改吗?\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question); DBhelp.conn.Open(); string strSql = \

strSql = string.Format(\workerinformation set 员工姓名workername='{0}',员工联系方式workertelp='{1}' where 员工号workerid='{2}'\dataGridVwork.CurrentRow.Cells[2].Value, dataGridVwork.CurrentRow.Cells[0].Value); SqlCommand cmd = new SqlCommand(strSql, DBhelp.conn); cmd.ExecuteNonQuery(); DBhelp.conn.Close();

MessageBox.Show(\保存成功\提示\ btnworkinf_Click(sender,e); }

private void dataGridVwork_CellClick(object sender, DataGridViewCellEventArgs e) {

if (dataGridVwork.CurrentRow.Cells[0].Value.ToString().Trim() != null) dataGridVwork.CurrentRow.Cells[0].ReadOnly = true; else

36

dataGridVwork.CurrentRow.Cells[0].ReadOnly = false; }

private void workForm_Load(object sender, EventArgs e) {

button1.Enabled = false; btnworkadd.Enabled = false; btnworkdel.Enabled = false; } } }

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 Lesson {

public partial class ManagerForm : Form {

public ManagerForm() {

InitializeComponent(); }

private void btnManread_Click(object sender, EventArgs e) {

37

Mangreader b = new Mangreader(); b.Show(); }

private void btnManbook_Click(object sender, EventArgs e) {

ManbookForm d = new ManbookForm(); d.Show(); }

private void btnManyuang_Click(object sender, EventArgs e) {

workForm f= new workForm(); f.Show(); }

private void button1_Click(object sender, EventArgs e) {

ManlendForm h = new ManlendForm(); h.Show(); }

private void ManagerForm_Load(object sender, EventArgs e) {

} }

}

using System;

using System.Collections.Generic;

38

using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms;

namespace Lesson {

public partial class ReaderForm : Form {

public ReaderForm() {

InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) {

ReaderSearch a=new ReaderSearch(); a.Tag = this.Tag; a.Show(); //this.Hide();

}

private void ReaderForm_Load(object sender, EventArgs e) {

Reader re = new Reader(); re = (Reader)this.Tag;

lblWelcome.Text = \欢迎您:\同学\ }

private void btnbooksearch_Click(object sender, EventArgs e) {

ReaderbookForm c = new ReaderbookForm(); c.Tag = this.Tag; c.Show(); // this.Hide(); }

private void btnlogout_Click(object sender, EventArgs e) {

Application.Exit(); }

39

} }

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 System.Data.SqlClient;

namespace Lesson {

public partial class Mangreader : Form {

SqlDataAdapter dataAdapter;// 数据适配器 DataSet dataSet = new DataSet();// 数据集 public Mangreader() {

InitializeComponent(); }

public void btnsearch_Click(object sender, EventArgs e) {

40

try {

btnadd.Enabled = true; btnreset.Enabled = true; btndel.Enabled = true;

dataSet.Clear();//清空原来数据

string sqlSelectStr = \

if (txtCondition.Text.Trim() == \如果查询条件为空 则显示全部学生信息 {

sqlSelectStr = \读者学号ReaderId,读者姓名ResderName,登录密码LoginPwd,读者班级ReaderClass,读者电话ReaderTelp from ReaderInformation\ } else {

switch (cmbCondition.Text)//根据查询条件 进行相应的查询(允许模糊查询) {

case \读者学号\

sqlSelectStr = string.Format(\读者学号ReaderId,读者姓名ResderName,登录密码LoginPwd,读者班级ReaderClass,读者电话ReaderTelp from ReaderInformation where 读者学号ReaderId like '%{0}%'\ break; case \读者姓名\

sqlSelectStr = \读者学号ReaderId,读者姓名ResderName,登录密码LoginPwd,读者班级ReaderClass,读者电话ReaderTelp from ReaderInformation where 读者姓名ResderName like '%\ break; case \读者班级\

sqlSelectStr = \读者学号ReaderId,读者姓名ResderName,登录密码LoginPwd,读者班级ReaderClass,读者电话ReaderTelp from ReaderInformation where 读者班级ReaderClass like '%\ break; } }

dataAdapter = new SqlDataAdapter(sqlSelectStr, DBhelp.conn);//实例化SqlDataAdapter的对象

dataAdapter.Fill(dataSet, \调用SqlDataAdapter对象的Fill()方法为dataSet填充数据

dataGridVreadinf.DataSource = dataSet.Tables[\指定DataGridView控件的数据源(DataSource属性)

dataGridVreadinf.CurrentRow.Cells[0].ReadOnly = true; }

catch (Exception)

41

{

MessageBox.Show(\输入有误!内容不存在!\ } finally {

DBhelp.conn.Close();

} }

private void btnreset_Click(object sender, EventArgs e) {

if (dataSet != null)//如果dataSet不为空 {

DialogResult result = MessageBox.Show(\确定要保存修改吗?\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) {

// 自动生成用于更新的命令

SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);

if (dataAdapter.Update(dataSet, \将数据集中修改过的数据,提交到数据库 {

MessageBox.Show(\保存成功\提示\MessageBoxIcon.Information); } } } }

private void btndel_Click(object sender, EventArgs e) {

DialogResult result = MessageBox.Show(\确定要删除吗?\提示\MessageBoxIcon.Question);

if (result == DialogResult.Yes) {

foreach (DataGridViewRow dr in dataGridVreadinf.SelectedRows) {

this.dataGridVreadinf.Rows.Remove(dr); }

SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);

42

// 将数据集中修改过的数据,提交到数据库

dataAdapter.Update(dataSet, \ MessageBox.Show(\删除成功\提示\MessageBoxIcon.Information);

}

MessageBox.Show(\保存成功\提示\ }

private void btnadd_Click(object sender, EventArgs e) { try {

if (dataSet != null)//如果dataSet不为空 {

DBhelp.conn.Open();

string sql = \读者学号ReaderId='\dataGridVreadinf.CurrentRow.Cells[0].Value + \

SqlCommand com = new SqlCommand(sql, DBhelp.conn); SqlDataReader dr = com.ExecuteReader();

//string s=string.Format(\图书编号BookId from BookInformation\ if (dr.Read()) {

DBhelp.conn.Close(); DBhelp.conn.Open();

MessageBox.Show(\该学生Id已存在!\提示\MessageBoxIcon.Information);

DBhelp.conn.Close(); dr.Close(); } else {

dr.Close();

DialogResult result = MessageBox.Show(\确定要添加吗?\提示\MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) {

// 自动生成用于更新的命令

SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(dataSet, \将数据集中修改过的

43

数据,提交到数据库

MessageBox.Show(\添加成功\提示\MessageBoxIcon.Information); } } } }

catch (SqlException ex) {

MessageBox.Show(ex.Message); } finally {

DBhelp.conn.Close();

} }

private void dataGridVreadinf_CellClick(object sender, DataGridViewCellEventArgs e) {

dataGridVreadinf.CurrentRow.Cells[0].ReadOnly = true; }

private void Mangreader_Load(object sender, EventArgs e) {

btnadd.Enabled = false; btnreset.Enabled = false; btndel.Enabled = false; } }

}

第5章 系统使用说明

图书馆信息管理系统可分为管理员和读者两种使用角色。用户可根据自己的身份在登录界面选择相应的角色。待用户名和密码验证成功后,可进入相应角色的主界面。 一. 读者用户

44

读者进入系统后,可查阅读者的个人基本信息、登录信息(用户名和密码)、个人的击“修改”按钮激活读者信息,但不允许修改读者的编号。修改成功后点击“提交”按钮,系统给出相应的提示信息。读者查询图书信息可根据图书的书名、作者、ISBN号、出版社进行查询,并支持模糊查询。 二. 管理员用户

管理员用户包括图书借阅、图书归还、图书管理、读者管理、员工管理五大模块。

(1) 图书借阅

管理员输入读者编号和读者所借图书的编号,点击“提交”按钮,若借阅信息正确,提示借书成功。否则显示相应的提示。若读者尚有违规金额未缴纳,缴纳成功后方可借书。 (2) 图书归还

管理员输入读者编号和读者所还图书的编号,点击“提交”按钮,若归还信息正确,提示归还成功。若图书所借时间超过最大借阅期限(30天)应缴纳相应的违规金额。 (3) 图书管理

管理员修改图书信息时,应先在图书信息列表中选中要修改的图书,图书详细信息会显示在相应的文本框中,在文本框中修改图书信息,点击“修改”按钮,若信息正确,则显示修改成功;否则显示相应的错误信息。在删除图书信息时,选中要删除的图书,点击“删除”按钮,显示删除成功。在文本框中添加图书信息,点击“添加”按钮,若信息正确,则显示添加成功;否则显示相应的错误信息。 (4) 读者管理

管理员在删除读者信息时,选中要删除的读者,点击“删除”按钮,显示删除成功。在文本框中添加读者信息,点击“添加”按钮,若信息正确,则显示添加成功;否则显示相应的错误信息。 (5) 员工管理

管理员修改员工信息时,应先在员工信息列表中选中要修改的员工,员工详细信息会显示在相应的文本框中,在文本框中修改员工信息,点击“修改”按钮,若信息正确,则显示修改成功;否则显示相应的错误信息。在删除员工信息时,选中要删除的员工,点击“删除”按钮,显示删除成功。在文本框中添加员工信息,点击“添加”按钮,若信息正确,则显示添加成功;否则显示相应的错误信息。

借阅信息和图书信息。读者可以修改自己的基本信息、登录信息。在修改过程中应现点

45

第6章 课程设计总结

6.1 主要问题及解决办法

在课程设计之前对C#中三层架构的知识了解得不够全面,通过自身的学习和老师、同学的帮助对三层架构有了进一步的认识。

在数据库设计时应考虑数据库的规范化,以减少数据的冗余,为后续的编码做好铺垫。

6.2 课程设计体会

在本次课程设计中运用所学知识,较快地完成了课程设计任务。从需求分析开始摸拟整个软件开发的过程,从中能够体会到许多不能在课堂上学到的知识。语言的学习得注重实践,本次课程设计在理论学习的基础上,提高了C#的应用水平,增加了自身的编程经验。 6.3 自我评定

认真完成课程设计任务书中的内容,达到预期目的,各功能实现完整,系统能够准确无误的运行。

46

本文来源:https://www.bwwdw.com/article/6flp.html

Top