数据库课程设计报告_第1页
数据库课程设计报告_第2页
数据库课程设计报告_第3页
数据库课程设计报告_第4页
数据库课程设计报告_第5页
已阅读5页,还剩45页未读 继续免费阅读

下载本文档

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

文档简介

资料内容仅供您学习参考,如有不当之处,请联系改正或者删除。数据库课程设计报告系院):计算机科学学院专业班级:计算机科学与技术姓名:学号:指导教师:设计时间:.12.12-.12.23设计地点:目录一、课程设计目的 3二、设计任务及要求 3三、需求分析 4四、总体设计 4五、详细设计与实现 51、数据库操作公共类: 52、登陆界面及代码实现 103、系统管理员 124、图书管理员 145、读者管理员 205、读者 27六、课程设计小结 28指导老师意见: 30一、课程设计目的经过对图书管理信息系统的系统分析、系统设计、编码和调试等工作的实践,了解管理信息系统的一般设计方法和实现思路,深入了解数据库设计的基本理论及方法。二、设计任务及要求要求完成一个具有一定实用价值的图书管理信息系统,主要任务包括:在SQLServer或SQLServer环境下建立图书管理信息系统所使用的数据库,利用企业管理器或查询分析器建立各种数据库对象,包括:数据表、视图、约束、存储过程和触发器等;‚了解数据库引擎技术,并掌握使用ADO.NET连接数据库服务器和客户端应用程序;ƒ掌握使用C#或其它语言开发一个数据库系统的基本方法和步骤,应用程序的功能包括:数据的输入、修改和删除;数据的浏览和查询;数据的图形化、报表以及打印输出;系统的用户登录和权限管理;„了解多层C/S或B/S体系结构的数据库系统的开发过程:需求分析、系统设计、系统实现及文档的收集和整理。三、需求分析在做这个课程设计,主要涉及到的是我们以前学习过的C#的相关技术和数据库的一些知识,就感觉上来讲,这两部分比重应该都差不多。要做出图书管理系统,首先要对数据库的建立、修改和维护能够比较熟悉的掌握,另外就是数据库与VS之间的连接,是直接的绑定到VS里面还是经过查询语句让表的内容在DataGridView控件中显示出来,以及这两种之间的优点和坏处,在开始做这个课设之前,我们心里都要有数,另外,考虑到的就是提高访问的速度以及可维护性了。至于其它的功能的实现,就各凭本事了。四、总体设计该系统主要由五大功能模块组成:图书管理、读者管理、借阅管理、数据统计和系统管理。各大功能模块又由一些子功能模块构成,其总体的设计框架如下。五、详细设计与实现1、数据库操作公共类:classSQLhelper{privatestaticSqlConnectionconn=newSqlConnection(@"DataSource=.\SQLEXPRESS;AttachDbFilename=D:\计算机的学习\数据库\数据库课程设计\汪刚\数据库课程设计\数据库课程设计\MSI_KS.mdf;IntegratedSecurity=True;ConnectTimeout=30;UserInstance=True");//Decrypt(System.Configuration.ConfigurationManager.AppSettings["connectionString"]));//打开数据库链接publicstaticvoidOpenConn(){try{if(conn.State==ConnectionState.Closed)conn.Open();}catch{thrownewException("数据库连接失败!");}}//关闭数据库连接privatestaticvoidCloseConn(){if(conn!=null){if(conn.State==ConnectionState.Open){conn.Close();}}}publicstaticintExecuteNonQuery(stringsql){introws=0;try{OpenConn();SqlCommandcmd=newSqlCommand(sql,conn);rows=cmd.ExecuteNonQuery();}catch(SqlExceptionex){thrownewException(ex.Message);}finally{CloseConn();}returnrows;}publicstaticintExecuteNonQuery(stringsql,SqlParameter[]parameters){introws=0;try{OpenConn();SqlCommandcmd=newSqlCommand(sql,conn);if(parameters!=null){foreach(SqlParameterparameterinparameters){cmd.Parameters.Add(parameter);}}rows=cmd.ExecuteNonQuery();}catch(SqlExceptionex){thrownewException(ex.Message);}finally{CloseConn();}returnrows;}publicstaticintExecuteStoredProc(stringstoredProcName,SqlParameter[]parameters){introws=0;try{OpenConn();SqlCommandcmd=newSqlCommand();cmd.CommandType=CommandType.StoredProcedure;cmd.CommandText=storedProcName;cmd.Connection=conn;if(parameters!=null){foreach(SqlParameterparameterinparameters){cmd.Parameters.Add(parameter);}}rows=cmd.ExecuteNonQuery();}catch(SqlExceptionex){thrownewException(ex.Message);}finally{CloseConn();}returnrows;}///<summary>///执行简单的SQL语句,返回结果集中的首行首列///</summary>///<paramname="sql">要执行的SQL查询语句</param>///<returns></returns>publicstaticobjectExecuteScalar(stringsql){objectobj=null;try{OpenConn();SqlCommandcmd=newSqlCommand(sql,conn);obj=cmd.ExecuteScalar();}catch(SqlExceptionex){thrownewException(ex.Message);}finally{CloseConn();}returnobj;}///<summary>///执行简单的SQL语句,返回结果集中的首行首列///</summary>///<paramname="sql">要执行的SQL查询语句</param>///<paramname="parameters"></param>///<returns></returns>publicstaticobjectExecuteScalar(stringsql,SqlParameter[]parameters){objectobj=null;try{OpenConn();SqlCommandcmd=newSqlCommand(sql,conn);if(parameters!=null){foreach(SqlParameterparameterinparameters){cmd.Parameters.Add(parameter);}}obj=cmd.ExecuteScalar();}catch(SqlExceptionex){thrownewException(ex.Message);}finally{CloseConn();}returnobj;}///<summary>///执行一条带参数的SQL语句,返回DataTable对象///</summary>///<paramname="sql">SQL查询语句</param>///<paramname="parameters"></param>///<paramname="TableName">DataSet中的表名</param>///<returns></returns>publicstaticDataTableGetDataTable(stringsql,SqlParameter[]parameters,stringTableName){DataTabledt=null;{OpenConn();SqlCommandcmd=newSqlCommand(sql,conn);if(parameters!=null){foreach(SqlParameterparameterinparameters){cmd.Parameters.Add(parameter);}}SqlDataAdaptersda=newSqlDataAdapter(cmd);DataSetds=newDataSet();sda.Fill(ds,TableName);dt=ds.Tables[0];}returndt;}///<summary>///执行存储过程,返回DataTable对象///</summary>///<paramname="storedProcName">存储过程名</param>///<paramname="parameters"></param>///<paramname="TableName">Data中的表名</param>///<returns></returns>publicstaticDataTableExecuteStoredProc(stringstoredProcName,SqlParameter[]parameters,stringTableName){DataTabledt=null;try{OpenConn();SqlCommandcmd=newSqlCommand();cmd.CommandType=CommandType.StoredProcedure;cmd.CommandText=storedProcName;cmd.Connection=conn;if(parameters!=null){foreach(SqlParameterparameterinparameters){cmd.Parameters.Add(parameter);}}SqlDataAdaptersda=newSqlDataAdapter(cmd);DataSetds=newDataSet();sda.Fill(ds,TableName);dt=ds.Tables[0];}catch(SqlExceptionex){thrownewException(ex.Message);}finally{CloseConn();}returndt;}2、登陆界面及代码实现代码实现:(主要是验证用户名和密码)stringname=User_Name.Text;stringcode=User_Code.Text;stringsql=string.Format("select*fromReader_sortwherereader_name='{0}'",name);DataTabletemp=SQLhelper.GetDataTable(sql,null,"Reader_sort");if(temp.Rows.Count!=0){if(temp.Rows[0][3].ToString()==name){if(temp.Rows[0][2].ToString()==code){stringtemp_sort=temp.Rows[0][1].ToString();if(User_Sort.Text==temp_sort){switch(temp_sort){case"系统管理员":stringname_temp=User_Name.Text;System_administratorSystem_admin_temp=newSystem_administrator(name_temp);System_admin_temp.Show();this.Hide();break;case"图书管理员":stringname_temp1=User_Name.Text;Book_administratorbook_admin_temp=newBook_administrator(name_temp1);book_admin_temp.Show();this.Hide();break;case"读者管理员":stringname_temp2=User_Name.Text;Reader_administratorReader_admin_temp=newReader_administrator(name_temp2);Reader_admin_temp.Show();this.Hide();break;case"读者":stringname_temp3=User_Name.Text;Common_Readerreader_temp=newCommon_Reader(name_temp3);reader_temp.Show();this.Hide();break;}}elseMessageBox.Show("权限错误!");}else{MessageBox.Show("密码不正确,请重新输入!");User_Code.Text=null;}}elseMessageBox.Show("用户名不存在!");}else{MessageBox.Show("用户不存在!");}图形界面:3、系统管理员代码实现:(一些主要功能)添加:System_administratoradmin_temp=newSystem_administrator(null);stringsql_update=string.Format("select*fromReader_sort");admin_temp.dataGridView1.DataSource=SQLhelper.GetDataTable(sql_update,null,"Reader_sort");inti=admin_temp.dataGridView1.NewRowIndex;//获取新行的行号i=i+1;stringreader_name=add_reader_name.Text;intcode=int.Parse(add_code.Text);stringitem_sort=add_sort.Text;stringsql=string.Format("insertintoReader_sortvalues('{0}','{1}','{2}','{3}')",i,item_sort,code,reader_name);introws=SQLhelper.ExecuteNonQuery(sql);if(rows<=0){MessageBox.Show("添加失败!");}修改:update_index=update_index+1;stringreader_name=modify_reader_name.Text;intcode=int.Parse(modify_code.Text);stringitem_sort=modify_sort.Text;stringsql=string.Format("updateReader_sortsetsort_name='{0}',sort_code='{1}',reader_name='{2}'wheresort_ID='{3}'",item_sort,code,reader_name,update_index);introws=SQLhelper.ExecuteNonQuery(sql);if(rows<=0){MessageBox.Show("修改失败!");}删除:DialogResulttemp=MessageBox.Show(this,"是否删除该选中行","确定删除",MessageBoxButtons.YesNo,MessageBoxIcon.Question);if(temp==DialogResult.Yes){stringdelete_currentcell=dataGridView1.CurrentRow.Cells[0].Value.ToString();stringsql=string.Format("deleteReader_sortwheresort_ID='{0}'",delete_currentcell);introws=SQLhelper.ExecuteNonQuery(sql);if(rows<=0){MessageBox.Show("删除失败");}else{dataGridView1.Rows.Remove(dataGridView1.CurrentRow);//删除选中行}}图形界面:4、图书管理员关于添加、修改、删除的操作与系统管理员类似,这里不再赘述,图书管理员中,主要用到的技术有:C/S或B/S模式:业务实体类:publicclassBook_entiry{#region私有字段privateintBook_id;privatestringbook_code;privatestringbook_name;privatestringbook_author;privatestringbook_press;privatestringbook_datapress;privatestringbook_isbn;privatestringbook_catalog;privatestringbook_languague;privateintbook_pages;privatestringbook_price;privatestringbook_datain;privatestringbook_brief;privatestringbook_cover;privatestringbook_sum;#endregion#region公有属性publicintbkID{get{returnBook_id;}set{Book_id=value;}}publicstringbkCode{get{returnbook_code;}set{book_code=value;}}publicstringbkName{get{returnbook_name;}set{book_name=value;}}publicstringbkAuthor{get{returnbook_author;}set{book_author=value;}}publicstringbkPress{get{returnbook_press;}set{book_press=value;}}publicstringbkDatePress{get{returnbook_datapress;}set{book_datapress=value;}}publicstringbkISBN{get{returnbook_isbn;}set{book_isbn=value;}}publicstringbkCatalog{get{returnbook_catalog;}set{book_catalog=value;}}publicstringbkLanguage{get{returnbook_languague;}set{book_languague=value;}}publicintbkPages{get{returnbook_pages;}set{book_pages=value;}}publicstringbkPrice{get{returnbook_price;}set{book_price=value;}}publicstringbkDateIn{get{returnbook_datain;}set{book_datain=value;}}publicstringbkBrief{get{returnbook_brief;}set{book_brief=value;}}publicstringbkCover{get{returnbook_cover;}set{book_cover=value;}}publicstringbkIsInlab{get{returnbook_sum;}set{book_sum=value;}}#endregion}数据访问层:classBookTypeDAL{publicDataTableGetAllReader(){stringsql="select*fromBook";returnSQLhelper.GetDataTable(sql,null,"Book");}publicvoidAddBook(数据库课程设计.Book_entirybook){};try{SQLhelper.ExecuteStoredProc("add_book",parameters);}catch(SqlExceptionex){thrownewException(ex.Message);}}}业务逻辑层:classBookBLL{BookTypeDALBDAL=newBookTypeDAL();//得到所有的读者publicDataTableGetAllReader(){returnBDAL.GetAllReader();}//添加读者publicvoidAddBook(数据库课程设计.Book_entirybook){try{BDAL.AddBook(book);MessageBox.Show("添加成功!");}catch(Exceptionex){MessageBox.Show("添加失败!");thrownewException(ex.Message);}}}表示层:数据库课程设计.Book_entirybook=newBook_entiry();//引用存储过程book.bkID=Convert.ToInt32(Book_add_bkID.Text);book.bkCode=Book_add_bkcode.Text;book.bkName=Book_add_bkName.Text;book.bkLanguage=Book_add_bkLanguage.Text;book.bkPages=Convert.ToInt32(Book_addpages.Text);book.bkPrice=Book_add_bkPrice.Text;book.bkDateIn=Book_add_bkDateIn.Text;book.bkBrief=Book_add_bkBrief.Text;book.bkCover=picture_address.Text;book.bkIsInlab=Book_add_bkIsInlab.Text;数据库课程设计.Book_book.BookBLLbook_temp=new数据库课程设计.Book_book.BookBLL();book_temp.AddBook(book);图形界面:读者信息管理页面:代码实现:鼠标点击首记录:introw=this.dataGridView1.CurrentRow.Index+1;if(row>this.dataGridView1.RowCount-2)row=0;this.dataGridView1.CurrentCell=this.dataGridView1[0,row];鼠标点击下一记录:introw=this.dataGridView1.CurrentRow.Index-1;if(row<0)row=this.dataGridView1.RowCount-2;this.dataGridView1.CurrentCell=this.dataGridView1[0,row];5、读者管理员代码实现:这里也用到了三层模式,添加、修改、删除也大致与前面类似。借书:stringsql_find_sort=string.Format("select*fromReaderTypewhererdTypeName='{0}'",lend_rdTypeName.Text);DataTablefind_Type=SQLhelper.GetDataTable(sql_find_sort,null,"ReaderType");stringfind_CanlendQty=find_Type.Rows[0][2].ToString();intfind_CanLendDay=int.Parse(find_Type.Rows[0][3].ToString());if(int.Parse(find_CanlendQty)>int.Parse(lend_rdBorrowQty.Text)){if(this.dataGridView2.CurrentRow==null){MessageBox.Show("请选中要借阅的书籍所在的行!");}else{stringbkID_temp=this.dataGridView2.CurrentRow.Cells[0].Value.ToString();//获得借阅书的bkIDstringbkName_temp=this.dataGridView2.CurrentRow.Cells[2].Value.ToString();//获得借阅书的名称intsum=int.Parse(this.dataGridView2.CurrentRow.Cells[14].Value.ToString());//获得bkisinlab的值(现存量)stringadd_rows_temp=lend_rdName.Text;//获得读者名称intbkID_have_lended=int.Parse(lend_rdID.Text);//获得读者的rdIDintsum_have_lended=int.Parse(lend_rdBorrowQty.Text);//获得已借书总量if(sum==0){MessageBox.Show("这本书现存量为0,请等待该书归还后再借,谢谢!");}else{stringsql_confrim_lend=string.Format("insertinto{0}select*fromBookwherebkID='{1}'",add_rows_temp,bkID_temp);//将借阅书籍插入到个人借阅信息表中sum_have_lended=sum_have_lended+1;stringsql_update0=string.Format("updateReadersetrdBorrowQty='{0}'whererdID='{1}'",sum_have_lended,bkID_have_lended);introw=SQLhelper.ExecuteNonQuery(sql_confrim_lend);introw0=SQLhelper.ExecuteNonQuery(sql_update0);if(row<=0||row0<=0){MessageBox.Show("借书失败,请重新执行操作!");}else{sum=sum-1;DateTimetime_lend=System.DateTime.Today;//借书的时间stringsql_update1=string.Format("updateBooksetbkIsInLab='{0}'wherebkID='{1}'",sum,bkID_temp);//图书存量的变化stringsql_update2=string.Format("update{0}setbkIsInLab='{1}'wherebkID='{2}'",add_rows_temp,sum,bkID_temp);//个人借阅信息表中图书存量的变化stringsql_update3=string.Format("insertintoBorrowvalues('{0}','{1}','1','{2}','{3}','','','','','false','{4}','')",lend_rdID.Text,bkID_temp,time_lend,time_lend.AddDays(+find_CanLendDay),operate_person.Text);//借阅表Borrow中的变化stringsql_update4=string.Format("insertintoBorrow_informationvalues('{0}','{1}','{2}','{3}','{4}','{5}','{6}','','{7}','')",lend_rdID.Text,lend_rdName.Text,lend_rdTypeName.Text,lend_rdDept.Text,bkID_temp,bkName_temp,time_lend,time_lend.AddDays(+find_CanLendDay));//借阅信息表Borrow_information的变化introws1=SQLhelper.ExecuteNonQuery(sql_update1);introws2=SQLhelper.ExecuteNonQuery(sql_update2);introws3=SQLhelper.ExecuteNonQuery(sql_update3);introws4=SQLhelper.ExecuteNonQuery(sql_update4);if(rows1>0&&rows2>0&&rows3>0&&rows4>0){MessageBox.Show("借书成功!");stringupdate_link1=string.Format("select*from{0}",lend_rdName.Text);//重新绑定数据dataGridView1.DataSource=SQLhelper.GetDataTable(update_link1,null,lend_rdName.Text);stringupdate_link2="select*fromBook";dataGridView2.DataSource=SQLhelper.GetDataTable(update_link2,null,"Book");lend_rdBorrowQty.Text=sum_have_lended.ToString();}else{MessageBox.Show("借书失败!请检查更新错误的数据文件!");}}}}}else{MessageBox.Show("超出了你所能借的书的数量!");}借书过程中,主要是要实现三个表中数据的变化,这三个表中的变化对应改变好了,就没有问题了,关于续借和还书,只要借书回了,举一反三,关于其它的自己也就能够实现了,图形界面:查询借阅信息:查找实现的具体过程stringrdID_temp=search_rdID.Text;stringrdName_temp=search_rdName.Text;stringrdType_temp=search_rdType.Text;stringrdDept_temp=search_rdDept.Text;stringbkCode_temp=search_bkCode.Text;stringbkName_temp=search_bkName.Text;stringldDateOut_temp=search_ldDateOut.Text;stringldDateRetAct_temp=search_ldDateRetAct.Text;stringsql=string.Format("select*fromBorrow_informationwhererdID='{0}'orrdName='{1}'orrdType='{2}'orrdDept='{3}'orbkID='{4}'orbkName='{5}'orldDateOut='{6}'orldDateRetPlan='{7}'",rdID_temp,rdName_temp,rdType_temp,rdDept_temp,bkCode_temp,bkName_temp,ldDateOut_temp,ldDateRetAct_temp);this.dataGridView1.DataSource=SQLhelper.GetDataTable(sql,null,"Borrow_information");里面有打印预览功能:PrintPreviewDialogppd=newPrintPreviewDialog();PrintDocumentpd=newPrintDocument();pd.PrintPage+=newPrintPageEventHandler(pd_PrintPage);DrawLine(newPoint(start_point_x+width,start_point_y),newPoint(start_point_x+width,height),e.Graphics);//得最右边的线for(inti=0;i<line_sum;i++)//画每一列的线{DrawLine(newPoint(start_point_x+line_temp,start_point_y),newPoint(start_point_x+line_temp,height),e.Graphics);e.Graphics.DrawString(dataGridView1.Columns[i].HeaderText,show_font,alertBrush,start_point_x+line_temp,start_point_y+row_height/2);for(introw=0;row<row_sum-1;row++){e.Graphics.DrawString(dataGridView1.Rows[row].Cells[i].Value.ToString(),show_font,alertBrush,start_point_x+line_temp,start_point_y+row_height/2+row_height*(row+1));}line_temp=line_temp+line_width;}效果图:输出到excel的功能:SaveFileDialogexcel_data=newSaveFileDialog();excel_data.

温馨提示

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

评论

0/150

提交评论