图书管理系统课程设计报告.doc

上传人:good****022 文档编号:116524665 上传时间:2022-07-05 格式:DOC 页数:16 大小:864.50KB
返回 下载 相关 举报
图书管理系统课程设计报告.doc_第1页
第1页 / 共16页
图书管理系统课程设计报告.doc_第2页
第2页 / 共16页
图书管理系统课程设计报告.doc_第3页
第3页 / 共16页
点击查看更多>>
资源描述
管理信息系统实习报告专 业 班 级 学 生 姓 名 指 导 教 师 王 桃 群 时 间 2012.3.132012.3.23 成 绩 评 语 一、课程设计题目 图书管理系统二、系统需求1.系统的准备操作系统:Windows xp数据库系统:SQL Server 2000 或 SQL Server 2005客户端开发工具:Visual Studio 2005或其他开发工具2.知识准备熟悉SQL Server 2000 或 SQL Server 2005的使用;熟悉C#、ASP.NET或其他语言进行数据库编程。3.系统分析图书信息包括:每种图书都有书名、ISBN、一名或多名作者(译者)、出版社、定价和内容简介等;读者信息包括:借书证记录有借阅者的姓名、密码、所在单位和类别等;读者凭借书证借书,教师最多借书15本书,借书期限最长为90天,学生最多借书8本书,借书期限最长为30天。对于超期未还的读者不能继续借书,每本书每超期一天罚款0.05元。三、系统设计1.体系结构本系统使用c/s模式的两层结构,表示层(USL)和数据访问层(DAL)。表示层(USL):为客户提供对应用程序的访问,以Windows应用程序或Web应用程序的形式提供实现的功能。业务逻辑层(BLL):实现应用程序的业务功能,以类库的形式为表示层提供服务。数据访问层(DAL):实现整个系统所有的数据库连接、数据存取操作,以组件类库的形式为业务逻辑层提供服务。此外,实体类,简单地说是描述一个业务实体的类。业务实体直观一点的理解就是整个应用系统业务所涉及的对象,从数据存储来讲,业务实体就是存储应用系统信息的数据表,将数据表中的每一个字段定义成属性,并将这些属性用一个类封装,这个类就称为实体类。2.功能模块框图图 书 管 理借 书图 书 管 理借书图书更新图书删除图书查找图书添加3.数据库设计1. 读者类别表(ReaderType)字段名数据类型说明rdTypeSmallInt读者类别【主键】rdTypeNameVarchar(8)读者类别名称CanLendQtyInt可借书数量CanLendDayInt可借书天数CanContinueTimesInt可续借的次数PunishRateFloat罚款率(分/天/本)DateValidSmallInt证书有效日期2. 读者信息表(Reader)字段名数据类型说明rdIDInt读者序号【主键】rdNamevarchar(10)读者姓名rdPwdvarchar (10)读者密码,初值为“123”rdSexBit性别,0-男,1-女rdTypeSmallInt读者类别【外键】rdDeptChar(8)单位代码rdPhonevarchar(25)电话号码rdEmailvarchar(25)电子邮件rdDateRegsmalldatetime读者登记日期rdBorrowQtyInt已借书数量3. 图书信息表(Book)字段名数据类型说明bkIDInt图书序号【主键】bkCodeChar(20)图书编号bkNameVarchar(50)书名bkAuthorVarchar(30)作者bkPressVarchar(50)出版社bkDatePressSmalldatetime出版日期bkISBNChar(15)书号bkCatalogVarchar(30)分类名bkLanguageSmallInt语言,0-中文,1-英文,2-日文,3-俄文,4-德文,5-法文bkPagesInt页数bkPriceMoney价格bkDateInSmallDateTime入馆日期bkBriefText内容简介bkCoverVarchar(100) 或image图书封面照片bkIsInLabChar(4)是否在馆4. 借阅信息表(Borrow)字段名数据类型说明rdIDInt读者序号【主键】bkIDInt图书序号【主键】ldContinueTimesInt续借次数(第一次借时,记为1)ldDateOutSmallDateTime借书日期ldDateRetPlanSmallDateTime应还日期ldDateRetActSmallDateTime实际还书日期ldOverDayInt超期天数ldOverMoneyMoney超期金额ldPunishMoneyMoney罚款金额lsHasReturnBit是否已经还书,缺省为0-未还OperatorLendVarChar(10)借书操作员OperatorRetVarChar(10)还书操作员四、系统实现 登录的代码实现:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace BooksMng public partial class BookLogin : Form public BookLogin() InitializeComponent(); private void textBox2_TextChanged(object sender, EventArgs e) private void btnlogin_Click(object sender, EventArgs e) /连接数据库 SqlConnection conn = new SqlConnection(server=.;database=Booksmng; integrated security=True); conn.Open(); SqlCommand cmd = conn.CreateCommand(); /cmd.CommandText=select count(*) from Users where userName=+txtName.Text+and userPwd=+txtPwd.Text+; cmd.CommandText = select count(*) from Users where userName=userName and userPwd=userPwd; cmd.Parameters.Add(userName, SqlDbType.VarChar, 20).Value = txtName.Text; cmd.Parameters.Add(userPwd, SqlDbType.VarChar, 20).Value = txtPwd.Text; try int count = Convert.ToInt32(cmd.ExecuteScalar(); if (count != 0) MessageBox.Show(登陆成功!); BookMain frm = new BookMain(); frm.Show(); catch (SqlException ex) /MessageBox.Show(登录失败!); MessageBox.Show(ex.Message); private void FrmLogin_Load(object sender, EventArgs e) 图书管理部分,主要的代码实现如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace BooksMng public partial class BookManage : Form public BookManage() InitializeComponent(); private void Form2_Load(object sender, EventArgs e) DataBind(); private void DataBind() /连接数据库 SqlConnection conn = new SqlConnection(server=.; database=BooksMng;integrated security=True); /SqlConnection conn = new SqlConnection(server=.; database=BooksMng;integrated security=True); conn.Open(); SqlCommand cmd = conn.CreateCommand(); /mandText = select * from Book; cmd.CommandText = select bkID 编号, bkName 书名,bkAuthor 作者,bkPages 页数,bkPress 出版社 from Book; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); dgvBooks.DataSource = ds.Tables0; txtName.DataBindings.Clear(); txtAuthor.DataBindings.Clear(); txtPage.DataBindings.Clear(); txtPress.DataBindings.Clear(); txtName.DataBindings.Add(Text,ds.Tables0,书名); txtAuthor.DataBindings.Add(Text,ds.Tables0,作者); txtPage.DataBindings.Add(Text,ds.Tables0,页数); txtPress.DataBindings.Add(Text, ds.Tables0, 出版社); /上面的代码是在窗体Load时,将Books表中的所有记录,即所有的图书信息显示在网格DataGrid空间中。 / /下面是实现添加功能 private void btnAdd_click(object sender, EventArgs e) SqlConnection conn = new SqlConnection(server=.; database=BooksMng;integrated security=True); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = insert into Book(bkName, bkAuthor,bkPages,bkPress) values(bkName,bkAuthor,bkPages,bkPress); cmd.Parameters.Add(bkName, SqlDbType.VarChar, 30).Value = txtName.Text; cmd.Parameters.Add(bkAuthor, SqlDbType.VarChar, 30).Value = txtAuthor.Text; cmd.Parameters.Add(bkPages, SqlDbType.Int).Value =Convert.ToInt32(txtPage.Text);/类型转换 cmd.Parameters.Add(bkPress, SqlDbType.VarChar, 50).Value = txtPress.Text; try cmd.ExecuteNonQuery(); /执行上述SQL命令 MessageBox.Show(图书添加成功!); DataBind(); /重新将数据库绑定到DataGrid catch (SqlException ex) MessageBox.Show(图书添加失败); MessageBox.Show(ex.Message); private void btnSearch_Click(object sender, EventArgs e) /连接数据库 SqlConnection conn = new SqlConnection(server=.; database=BooksMng;integrated security=True); conn.Open(); SqlCommand cmd = conn.CreateCommand(); String sql = ; /按作者查找 if (txtAuthor.Text != ) sql += select bkID 编号, bkName 书名,bkPages 页数,bkPress 出版社 from Book where bkAuthor=bkAuthor; try cmd.CommandText=sql; cmd.Parameters.Add(bkAuthor, SqlDbType.VarChar, 30).Value = txtAuthor.Text; SqlDataAdapter sda=new SqlDataAdapter(cmd); DataSet ds=new DataSet(); sda.Fill(ds); dgvBooks.DataSource = ds.Tables0; catch(SqlException ex) MessageBox.Show(查找失败); MessageBox.Show(ex.Message); private void btnDelete_Click(object sender, EventArgs e) /连接数据库 SqlConnection conn = new SqlConnection(server=.; database=BooksMng;integrated security=True); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = delete from Book where bkID=bkID; cmd.Parameters.Add(bkID, SqlDbType.Int).Value = Convert.ToInt32(dgvBooks0, dgvBooks.CurrentRow.Index.Value); try if (MessageBox.Show(确定要删除该图书吗?, 确定删除, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.OK) cmd.ExecuteNonQuery(); MessageBox.Show(删除成功!); DataBind(); catch (SqlException ex) MessageBox.Show(删除失败); MessageBox.Show(ex.Message); /下面做更新图书信息 private void btnUpdate_Click(object sender, EventArgs e) SqlConnection conn = new SqlConnection(server=.; database=BooksMng;integrated security=True); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = update Book set bkName=bkName, bkAuthor=bkAuthor, bkPages=bkPages,bkPress=bkPress where bkID=bkID; cmd.Parameters.Add(bkID, SqlDbType.Int).Value = Convert.ToInt32(dgvBooks0, dgvBooks.CurrentRow.Index.Value); cmd.Parameters.Add(bkName, SqlDbType.VarChar, 30).Value = txtName.Text; cmd.Parameters.Add(bkAuthor, SqlDbType.VarChar, 30).Value =txtAuthor.Text; cmd.Parameters.Add(bkPages, SqlDbType.Int).Value = Convert.ToInt32(txtPage.Text);/类型转换 cmd.Parameters.Add(bkPress, SqlDbType.VarChar, 50).Value = txtPress.Text; try if (MessageBox.Show(确定要更新图书信息吗?, 确认更新, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.OK) cmd.ExecuteNonQuery(); MessageBox.Show(更新成功!); DataBind(); catch (SqlException ex) MessageBox.Show(更新失败); MessageBox.Show(ex.Message); /图书可以添加成功借书实现主要代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace BooksMng public partial class BookBorrow : Form public BookBorrow() InitializeComponent(); /获取读者可借天数 private int GetLendDay(int rdID) SqlConnection conn = new SqlConnection(server=.;database=BooksMng;integrated security=true); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = select CanLendDay from ReaderType where rdType=(select rdType from Reader where rdID= + rdID + ); return Convert.ToInt32(cmd.ExecuteScalar(); private void btnBorrow_Click(object sender, EventArgs e) SqlConnection conn = new SqlConnection(server=.;database=BooksMng;integrated security=true); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = insert into Borrow(rdID,bkID,ldContinueTimes,IdDateOut,ldDateRetPlan,lsHasReturn) values(rdID,bkID,0,IdDateOut,ldDateRetPlan,0); cmd.Parameters.Add(rdID, SqlDbType.Int).Value = Convert.ToInt32(txtrdID.Text); cmd.Parameters.Add(bkID, SqlDbType.Int).Value = Convert.ToInt32(txtbkID.Text);/类型转换 cmd.Parameters.Add(IdDateOut, SqlDbType.DateTime).Value = DateTime.Now;/借书时间为当前的系统时间 /应还日期为=借书日期+可借天数cmd.Parameters.Add(ldDateRetPlan, SqlDbType.DateTime).Value = DateTime.Now.AddDays(GetLendDay(Convert.ToInt32(txtrdID.Text); try cmd.ExecuteNonQuery(); MessageBox.Show(借书成功!); catch (SqlException ex) MessageBox.Show(借书失败); MessageBox.Show(ex.Message); 五、系统运行效果 图书管理模块的运行结果如下:首先,设计一个用户登录界面,以管理员的身份登录来实现图书的添加、查找、删除、更新的功能。 登录界面的设计:登录成功的效果登录成功以后,跳到图书管理主界面:图书管理主界面如下:登录成功以后,跳到图书管理的页面:图书管理的页面如下: 此界面可以对图书实现添加、查找、删除和信息更新这四个功能。从图书管理主界面跳到借书界面:六、遇到的问题及解决方法 在实现借书这个功能时,老是借书失败,并且提示: 凭借这个提示是不可能找到错误的,为了找到这个错误,我设置了一个断点如图: 然后逐句运行,发现错误在 “catch (SqlException ex)”这句,并且提示:点击获取错误的帮助,软件给出的帮助是:我不知道这是什么错误,但是我知道错误不在“catch (SqlException ex)”这句,因为每当执行“cmd.ExecuteNonQuery();”这句时,就会跳到“catch (SqlException ex)”这句,并且提示有错误。我上网搜索了“cmd.ExecuteNonQuery();”此语句,发现有这么一段解释: cmd.Parameters.Add(New OleDbParameter(用户名, OleDbType.VarChar) 首先你的insertinto这个SQL语句是错误的,应该是insert into Enternumber(username,password,sex,work,tel,mail) values (用户名,密码,性别,职业,电话,邮箱) 其次就是最关键的错误,parameters这个方法使用时一定要有这样一个语句mandtypeCommandType.StoredProcedure这个语句的作用是用存储方法来传值的,也就是说在你的数据库中一定要一个存储过程, parameters方法的使用前面应该有,mandtype=commandtype.storedprocedure mandtext=存储过程 cmd.parameters.add(new oledbparameter(存储变量的一个变量名,数值) 此时我终于知道了,是数据库插入于具有问题,经过我反复的比较数据库中的各个键的属性,左最终改掉了所有的错误,程序运行正确。七、心得与体会这次的课程设计主要使用c#和SQL Server这两种知识来设计一个图书管理系统,而对于这两种知识我们曾经都开了课程,并且进行了系统的学习。我曾经自认为SQL Server还学得不错,因为书上的东西差不多都弄懂了,然而这次课程设计我却发现书上的东西我几乎忘得差不多了,一个很简单的查询语句都不知道怎么去写。我恍然间发觉自己做的很差,对于已经学的东西没有很好地进行运用,以至于很多已经学了的东西都已经忘记了。虽然如此,但老师仍很耐心的给我们讲解,知道我们如何一步一步地去做,真的很感谢老师为我们的付出。通过这两个星期的课程设计,是我对所学知识有了更深一步的理解与掌握,理论与实践也能更好地结合在一起,这一过程中我遇到了很多困难,但这更使我觉得其中的乐趣和那种战胜困难后的成就感。同时感到学无止境,在今后的学习和工作中,我会不断地充实自己。
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸下载 > CAXA图纸下载


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!