图书馆管理系统的分析与设计CSQLServer2000_第1页
图书馆管理系统的分析与设计CSQLServer2000_第2页
图书馆管理系统的分析与设计CSQLServer2000_第3页
图书馆管理系统的分析与设计CSQLServer2000_第4页
图书馆管理系统的分析与设计CSQLServer2000_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、图书馆管理系统的分析与设计采用的开发环境主要是基于数据库系统的SQL Server 2000和基于面向对象程序设计的C#。利用SQL Server 2000创建图书馆管理各信息表用户信息表,图书信息表。利用C#和数据库建立连接后,利用C#中的控制按钮以及一些程序代码实现一些特定的功能,例如用户图书信息查询,书库借出查询,密码修改,查找图书,个人信息查询,添加用户等,极大地提高了图书馆管理的效率。系统详细设计与实现 为了实现该系统,建立名为Book的解决方案,建立三层架构,用户访问层BookUI,数据访问层BooKDAL,逻辑业务层BookBLL 其中用户访问层位于最外层,离用户最近。用于显示数

2、据和接受用户输入的数据,为用户提供一种交互式操作的界面。 本实例系统主要操作都需要与数据库发生交互,为了减少重复的代码提高代码的重要性和规范性,把数据库交互的功能单独放在一个类中,在该类中实现数据库的增加,删除,修改,查询等通用功能。因此创建databa.cs类,放在BookUtility方案下,实现对数据库的操作,代码如下: namespace BookUtility public class Database private static string _connStr = "Data Source=.;Initial Catalog=BookManage;Integrated

3、Security=True" private static SqlConnection sqlcon = null; private static void CreateConnection() if (sqlcon = null) sqlcon = new SqlConnection(_connStr); sqlcon.Open(); else if (sqlcon.State = ConnectionState.Closed | sqlcon.State = ConnectionState.Broken) sqlcon.Close(); sqlcon.Open(); public

4、 static SqlCommand Querry(string strsql) try CreateConnection(); SqlCommand sqlcmd = new SqlCommand(strsql, sqlcon); sqlcmd.CommandText = strsql; return sqlcmd; catch return null; /执行Insert/update/delete,不带参数 public static int ExecuteNoQuery(string strsql) int i; try CreateConnection(); SqlCommand s

5、qlcmd = new SqlCommand(strsql, sqlcon); i = sqlcmd.ExecuteNonQuery(); sqlcon.Close(); return i; catch return -1; /执行Insert/update/delete,带参数 public static int ExecuteNoQuery(string strsql, params SqlParameter param) int i; try CreateConnection(); SqlCommand sqlcmd = new SqlCommand(strsql, sqlcon); /

6、sqlcmd.Parameters.Add(param); foreach (SqlParameter par in param) /遍历数组将参数对象添加到操作命令中 sqlcmd.Parameters.Add(par); i = sqlcmd.ExecuteNonQuery(); return i; catch return -1; public static DataSet GetDataSet(string strsql) CreateConnection(); SqlDataAdapter sda = new SqlDataAdapter(strsql, sqlcon); DataS

7、et ds = new DataSet(); try sda.Fill(ds); return ds; catch return null; public static DataSet GetDataSet(string strsql, params SqlParameter param) CreateConnection(); SqlDataAdapter sda = new SqlDataAdapter(strsql, sqlcon); DataSet ds = new DataSet(); foreach (SqlParameter par in param) sda.SelectCom

8、mand.Parameters.Add(par); try sda.Fill(ds); return ds; catch return null; public static DataTable GetTable(string strsql) try CreateConnection(); SqlDataAdapter sda = new SqlDataAdapter(strsql, sqlcon); DataSet ds = new DataSet(); sda.Fill(ds, "temp"); sqlcon.Close(); return ds.Tables"

9、;temp" catch return null; public static DataTable GetTable(string strsql, params SqlParameter param) try CreateConnection(); string str = strsql; SqlDataAdapter sda = new SqlDataAdapter(strsql, sqlcon); foreach (SqlParameter par in param) sda.SelectCommand.Parameters.Add(par); DataSet ds = new

10、DataSet(); sda.Fill(ds, "temp"); sqlcon.Close(); return ds.Tables"temp" catch return null; 数据访问层创建了两个类,BookAccess.cs和UserAccess.cs,分别实现访问存放书籍和用户的信息的功能,代码如下:namespace BookDAL public class BookAccess public DataTable BookQuarry(Book b) string str = "select * from BookInfo wher

11、e BookType='" + b.Booktype + "' or BookName like'%" + b.Bookname + "%' or BookAuthor='%" + b.Bookauthor + "%'or BookID='" + b.Bookid + "'" return Database.GetTable(str); public DataTable QuarryAll() string str = "selec

12、t * from BookInfo" return Database.GetTable(str); public DataTable QuarryMyBook(string id) SqlParameter param = new SqlParameter new SqlParameter("UID",id); string str = "select BookIssue,BookID,BookName,BookType,BookAuthor,BookPub,BookOutTime from BookOut where UID=UID" ret

13、urn Database.GetTable(str,param); public DataTable QuarryAllOut() string str = "select * from BookOut" return Database.GetTable(str); public SqlCommand QuarryByID(string id) string str = "select * from BookInfo where BookID='" + id + "'" return Database.Querry(s

14、tr); public int AddBook(Book b) SqlParameter parm = new SqlParameter new SqlParameter("BookID", b.Bookid), new SqlParameter("BookName", b.Bookname), new SqlParameter("BookType", b.Booktype), new SqlParameter("BookAuthor", b.Bookauthor), new SqlParameter("

15、BookPrice", b.Bookprice), new SqlParameter("BookPub", b.Bookpub), new SqlParameter("BookContent", b.Bookcontent), new SqlParameter("BookIssue", b.Bookissue) ; string str = "insert into BookInfo values(BookID,BookName,BookType,BookAuthor,BookPrice,BookPub,BookC

16、ontent,BookIssue)" int i = Database.ExecuteNoQuery(str, parm); return i; public int BookOut(Bookout bo) SqlParameter parm = new SqlParameter new SqlParameter("BookIssue", bo.Bookissue), new SqlParameter("BookID", bo.Bookid), new SqlParameter("BookName", bo.Bookname

17、), new SqlParameter("BookType", bo.Booktype), new SqlParameter("BookAuthor", bo.Bookauthor), new SqlParameter("BookPub", bo.Bookpub), new SqlParameter("UIdentify", bo.Uidentify), new SqlParameter("BookOutTime", bo.Bookouttime),new SqlParameter("

18、UID", bo.Uid) ; string str = "insert into BookOut values(BookIssue,BookID,BookName,BookType,BookAuthor,BookPub,UIdentify,BookOutTime,UID)" int i = Database.ExecuteNoQuery(str, parm); return i; public int UpdateBook(Book b) SqlParameter parm = new SqlParameter new SqlParameter("Bo

19、okID", b.Bookid), new SqlParameter("BookName", b.Bookname), new SqlParameter("BookType", b.Booktype), new SqlParameter("BookAuthor", b.Bookauthor), new SqlParameter("BookPrice", b.Bookprice), new SqlParameter("BookPub", b.Bookpub), new SqlParame

20、ter("BookContent", b.Bookcontent), new SqlParameter("BookIssue", b.Bookissue) ; string str = "update BookInfo set BookName=BookName,BookType=BookType,BookAuthor=BookAuthor,BookPrice=BookPrice,BookPub=BookPub,BookContent=BookContent,BookIssue=BookIssue where BookID=BookID&quo

21、t; int i = Database.ExecuteNoQuery(str, parm); return i; public int DeleteBook(string bookid) string str = "delete BookInfo where BookID='" + bookid + "'" int i = Database.ExecuteNoQuery(str); return i; public DataTable DeleteMybook(string bookissue) SqlParameter param =

22、new SqlParameter new SqlParameter("BookIssue", bookissue) ; string str = "delete BookOut where BookIssue=BookIssue" return Database.GetTable(str, param); 界面设计及实现登录界面及代码本系统的用户分为普通用户(读者)和管理员用户,管理员用户具有系统提供的所有权限,普通用户可以查询图书、借阅图书、查询个人借阅信息。系统登录界面是判断用户身份的一个交互窗体,在其中输入正确的用户名和密码后,单击“确定”按钮,可

23、根据用户角色在主界面中拥有相应的权限。登录界面如图所示:图书管理窗口,浏览图书信息,实现管理员对图书的增删改查操作。添加图书窗口:完成图书的入库操作管理员有权限可以将图书添加到数据库中,图书入库界面如上图所示。在分组框中添加标签和文本框,用来接收管理员输人的图书信息,以便保存到数据库中。代码如下:public partial class AddBook : Form public AddBook() InitializeComponent(); BookMessage bm = new BookMessage(); Book books = new Book(); private void b

24、utton1_Click(object sender, EventArgs e) if (textBox1.Text.Trim() = "" | textBox2.Text.Trim() = "" | textBox3.Text.Trim() = "" | textBox4.Text.Trim() = "" | textBox5.Text.Trim() = "" | textBox6.Text.Trim() = "" | textBox7.Text.Trim() = &quo

25、t;" | comboBox1.Text.Trim() = "") MessageBox.Show("信息输入不完整,请重新输入", "确定"); else books.Bookid = textBox1.Text.Trim(); books.Bookname = textBox2.Text.Trim(); books.Booktype = comboBox1.Text.Trim(); books.Bookauthor = textBox5.Text.Trim(); books.Bookprice = textBox4.Text.Trim(); books.Bookpub = textBo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论