10913郭亚丽图书管理系统报告.docx
《10913郭亚丽图书管理系统报告.docx》由会员分享,可在线阅读,更多相关《10913郭亚丽图书管理系统报告.docx(68页珍藏版)》请在冰豆网上搜索。
10913郭亚丽图书管理系统报告
实验报告
《数据库开发技术》实验报告
题目:
图书管理系统开发
姓名
郭亚丽
日期
2012-4-27
实验环境:
MicrosoftVisualStudio2005
MicrosoftSQLServer2005
实验内容与完成情况:
第一个类:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Configuration;
namespacelibrary
{
publicclassBookInfo
{
privatestringtitleID;
privatestringtitleName;
privatestringauthor;
privatestringisbn;
privatestringtype;
privatedoubleprice;
privateintpages;
privatestringpublisherID;
privatePublisherpublisher;
privatestringstrConn;
privateSqlConnectioncn;
publicstringTitleID
{
get{returntitleID;}
set{titleID=value;}
}
publicstringName
{
get{returntitleName;}
set{titleName=value;}
}
publicstringAuthor
{
get{returnauthor;}
set{author=value;}
}
publicstringIsbn
{
get{returnisbn;}
set{isbn=value;}
}
publicstringType
{
get{returntype;}
set{type=value;}
}
publicdoublePrice
{
get{returnprice;}
set{price=value;}
}
publicintPages
{
get{returnpages;}
set{pages=value;}
}
publicstringPublisherID
{
get{returnpublisherID;}
set{publisherID=value;}
}
publicPublisherPublisher
{
get
{
if(publisher==null)
{
publisher=newPublisher();
publisher.FindByPublisherID(this.publisherID);
}
returnpublisher;
}
}
publicBookInfo()
{
strConn=ConfigurationManager.ConnectionStrings["library.Properties.Settings.图书馆管理系统ConnectionString"].ConnectionString;
cn=newSqlConnection(strConn);
}
publicBookInfo(stringtitleID,stringname,stringisbn,stringauthor,stringpublisherID,stringtype,doubleprice,intpages)
{
this.titleID=titleID;
this.titleName=name;
this.isbn=isbn;
this.author=author;
this.publisherID=publisherID;
this.type=type;
this.price=price;
this.pages=pages;
}
publicDataTableFindBook(stringcolumn,stringcondition)
{
try
{
SqlCommandselCmd=newSqlCommand();
selCmd.Connection=cn;
selCmd.CommandType=CommandType.StoredProcedure;
selCmd.CommandText="p_bookStock";
SqlParameterp1=selCmd.Parameters.Add("@column",SqlDbType.NVarChar,20);
SqlParameterp2=selCmd.Parameters.Add("@value",SqlDbType.NVarChar,50);
p1.Value=column;
p2.Value=condition;
SqlDataAdapterda=newSqlDataAdapter(selCmd);
DataTablebookList=newDataTable();
da.Fill(bookList);
returnbookList;
}
catch(SqlExceptionex)
{
returnnull;
}
}
publicintFindByTitleID(stringtitleID)
{
//try
//{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="SELECT*FROMBookInfoWHEREtitleID='"+titleID+"'";
SqlDataReaderdr=cmd.ExecuteReader();
if(dr.Read())
{
this.titleID=titleID;
this.titleName=dr[1].ToString();
this.isbn=dr[2].ToString();
this.author=dr[3].ToString();
this.publisherID=dr[4].ToString();
this.type=dr[5].ToString();
this.price=Convert.ToDouble(dr[6].ToString());
this.pages=Convert.ToInt32(dr[7].ToString());
dr.Close();
cn.Close();
return1;
}
else
{
dr.Close();
cn.Close();
return0;
}
//}
//catch(SqlExceptionex)
//{
//cn.Close();
//return0;
//}
}
publicboolInsert()
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="INSERTINTObookInfoVALUES(@tITLEid,@bookName,@isbn,@author,@publisherID,@type,@price,@pages)";
cmd.Parameters.Add("@titleID",SqlDbType.NVarChar,10);
cmd.Parameters.Add("@bookName",SqlDbType.NVarChar,50);
cmd.Parameters.Add("@isbn",SqlDbType.Char,13);
cmd.Parameters.Add("@author",SqlDbType.NVarChar,20);
cmd.Parameters.Add("@publisherID",SqlDbType.Char,4);
cmd.Parameters.Add("@type",SqlDbType.NVarChar,10);
cmd.Parameters.Add("@price",SqlDbType.Decimal,10);
cmd.Parameters.Add("@pages",SqlDbType.Int);
cmd.Parameters[0].Value=titleID;
cmd.Parameters[1].Value=titleName;
cmd.Parameters[2].Value=isbn;
cmd.Parameters[3].Value=author;
cmd.Parameters[4].Value=publisherID;
cmd.Parameters[5].Value=type;
cmd.Parameters[6].Value=price;
cmd.Parameters[7].Value=pages;
intresult=cmd.ExecuteNonQuery();
cn.Close();
return(result==1);
}
catch(SqlExceptionex)
{
cn.Close();
returnfalse;
}
}
publicboolRemove()
{
try
{
BookItembooks=newBookItem();
books.RemoveByTitleID(this.titleID);
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="DELETEFROMbookInfoWHEREtitleID='"+this.titleID+"'";
intresult=cmd.ExecuteNonQuery();
cn.Close();
return(result==1);
}
catch(SqlExceptionex)
{
cn.Close();
returnfalse;
}
}
publicboolUpdata(stringtitleID,stringname,stringisbn,stringauthor,stringpublisherID,stringtype,doubleprice,intpages)
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="UPDATEbookInfoSETtitleID=@titleID,titleName=@bookName,isbn=@isbn,author=@author,publisherID=@publisherID,type=@type,price=@price,pages=@pagesWHEREtitleID='"+this.titleID+"'";
cmd.Parameters.Add("@titleID",SqlDbType.NVarChar,10);
cmd.Parameters.Add("@bookName",SqlDbType.NVarChar,50);
cmd.Parameters.Add("@isbn",SqlDbType.Char,13);
cmd.Parameters.Add("@author",SqlDbType.NVarChar,20);
cmd.Parameters.Add("@publisherID",SqlDbType.Char,4);
cmd.Parameters.Add("@type",SqlDbType.NVarChar,10);
cmd.Parameters.Add("@price",SqlDbType.Decimal,10);
cmd.Parameters.Add("@pages",SqlDbType.Int);
cmd.Parameters[0].Value=titleID;
cmd.Parameters[1].Value=titleName;
cmd.Parameters[2].Value=isbn;
cmd.Parameters[3].Value=author;
cmd.Parameters[4].Value=publisherID;
cmd.Parameters[5].Value=type;
cmd.Parameters[6].Value=price;
cmd.Parameters[7].Value=pages;
intresult=cmd.ExecuteNonQuery();
cn.Close();
return(result==1);
}
catch(SqlExceptionex)
{
cn.Close();
returnfalse;
}
}
}
}
第二个类:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Configuration;
namespacelibrary
{
classBookItem
{
privatestringbookID;//图书条码
privatestringstate;//图书状态
privatestringtitleID;//图书对应的书籍编号
privateBookInfoinfo;//图书信息
privatestringstrConn;//数据库连接串
privateSqlConnectioncn;//数据库连接对象
publicstringBookID
{
get{returnbookID;}
set{bookID=value;}
}
publicstringState
{
get{returnstate;}
set{state=value;}
}
publicstringTitleID
{
get{returntitleID;}
set{titleID=value;}
}
publicBookInfoInfo
{
get
{
if(info==null)
{
info=newBookInfo();
info.FindByTitleID(this.titleID);
}
returninfo;
}
}
publicBookItem()
{
strConn=ConfigurationManager.ConnectionStrings["library.Properties.Settings.图书馆管理系统ConnectionString"].ConnectionString;
cn=newSqlConnection(strConn);
}
//构造函数
publicBookItem(stringbookID,stringtitleID)
{
this.bookID=bookID;
this.state="馆内";
this.titleID=titleID;
strConn=ConfigurationManager.ConnectionStrings["library.Properties.Settings.图书馆管理系统ConnectionString"].ConnectionString;
cn=newSqlConnection(strConn);
}
publicintFindByBookID(stringbookID)
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="SELECT*FROMbookItemWHEREbookID='"+bookID+"'";
SqlDataReaderdr=cmd.ExecuteReader();
if(dr.Read())
{
this.bookID=bookID;
this.state=dr[1].ToString();
this.titleID=dr[2].ToString();
dr.Close();
cn.Close();
return1;
}
else
{
dr.Close();
cn.Close();
return0;
}
}
catch(SqlExceptionex)
{
cn.Close();
return0;
}
}
publicDataTableFindByTitleID(stringtitleID)
{
stringstrSql="SELECTbookID,stateFROMbookItemWHEREtitleID='"+titleID+"'";
try
{
SqlDataAdapterda=newSqlDataAdapter(strSql,strConn);
DataTableitemList=newDataTable();
da.Fill(itemList);
return(itemList);
}
catch(SqlExceptionex)
{
returnnull;
}
}
//借出,修改数据库状态字段为“借出”
publicintLend()
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="UPDATAbookItemSETstate='借出'WHEREbookID='"+bookID+"'";
intresult=cmd.ExecuteNonQuery();
returnresult;
cn.Close();
}
catch(SqlExceptionex)
{
return0;
}
}
//归还,修改数据库状态字段为“馆内”
publicboolBack()
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="UPDATEbookItemSETstate='馆内'WHEREbookID='"
+bookID+"'";
intresult=cmd.ExecuteNonQuery();
return(result==1);
}
catch(SqlExceptionex)
{
cn.Close();
returnfalse;
}
}
//当前图书添加到数据库
publicboolInsert()
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="INSERTINTObookItemVALUES('"+bookID
+"','馆内','"+titleID+"')";
intresult=cmd.ExecuteNonQuery();
cn.Close();
return(result==1);
}
catch(SqlExceptionex)
{
cn.Close();
returnfalse;
}
}
//从数据库删除该图书
publicboolRemove()
{
try
{
cn.Open();
SqlCommandcmd=newSqlCommand();
cmd.Connection=cn;
cmd.CommandText="DELETEFROMbookItemWHEREbookID='"+bookID+"'";
intresult=cmd.ExecuteNonQuery();
return(result==1);
}
catch(SqlExceptionex)
{
cn.Close();
returnfalse;
}
}
//按照图书编号titleID删除所有馆藏图书
publicintRemoveByTitleID(stringtitleID)
{
try
{
cn.Open();
SqlCommandcmd=n