实验七列表页面设计与实现文档格式.docx
《实验七列表页面设计与实现文档格式.docx》由会员分享,可在线阅读,更多相关《实验七列表页面设计与实现文档格式.docx(29页珍藏版)》请在冰豆网上搜索。
![实验七列表页面设计与实现文档格式.docx](https://file1.bdocx.com/fileroot1/2023-1/30/7dcb6200-65d6-417c-a179-1b06e6c48c32/7dcb6200-65d6-417c-a179-1b06e6c48c321.gif)
2.实验指导书预习及要求
先在草稿纸上编写主要程序代码,再上机调试。
3.其他准备
无
五、实验原理或操作要点简介
1.ASP.NET应用程序开发的一般步骤。
2.掌握三层开发的一般方法。
六、注意事项
⏹及时保存文件,避免死机或断电造成的文件丢失。
⏹实验过程中容易出现的问题:
1.机房装有2个操作系统。
注意选择第二个“应用软件编程系统”。
2.新建项目时,注意选择项目类型“C#”。
3.在C#.NET,窗口比较多,操作不当破坏了窗口的布局后,可通过“工具|选项”命令,在其对话框中选择“重制窗口布局”,恢复默认布局。
七、实验过程与指导
实现步骤如下:
步骤一:
在数据库中添加五个存储过程,代码如下:
//添加商品
CREATEPROCEDUREdbo.AddStorage
(
@NameNVarChar(500),
@TypeIDInt,
@ImageNVarChar(500),
@WriterNVarChar(500),
@PublisherNText,
@PublishDateDateTime,
@PublishTimesInt,
@ISBNNVarChar(50),
@PageCountInt,
@Pricefloat,
@IntroNText,
@ContentsNText,
@StorageCountInt,
@GoodsIDIntOutput
)
AS
INSERTINTOStorage
(SName,STypeID,SImage,SWriter,SPublisher,SPublishDate,SPublishTimes,SISBN,SPageCount,SPrice,SIntro,SContents,SStorageCount)
VALUES
(@Name,@TypeID,@Image,@Writer,@Publisher,@PublishDate,@PublishTimes,@ISBN,@PageCount,@Price,@Intro,@Contents,@StorageCount)
SET@GoodsID=@@IDENTITY
//通过ID号获取商品
CREATEPROCEDUREdbo.GetStorageBySID
(
@SIDInt
)
SELECT*FROMStorageWHERESID=@SID
//通过分类号获取商品
CREATEPROCEDUREdbo.GetStorageByCategoryID
@CategoryIDInt
SELECT*FROMStorageWHERESTypeID=@CategoryID
//修改商品
CREATEPROCEDUREdbo.ModifyStorage
@NameNVarChar(500),
@GoodsIDInt
UPDATEStorage
SET
SName=@Name,
SImage=@Image,
SWriter=@Writer,
SPublisher=@Publisher,
SPublishDate=@PublishDate,
SPublishTimes=@PublishTimes,
SISBN=@ISBN,
SPageCount=@PageCount,
SPrice=@Price,
SIntro=@Intro,
SContents=@Contents,
SStorageCount=@StorageCount
WHERESID=@GoodsID
//删除商品
CREATEPROCEDUREdbo.DeleteStorageByID
@IDint
deletefromStoragewhereSID=@ID
return
步骤二:
由于针对CatogoryTable表的CatogoryTable实体类前面的实验已经实现,这里不再实现,只定义一个针对Storage表的Storage实体类代码如下:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Xml.Linq;
///<
summary>
///Storage的摘要说明
/summary>
publicclassStorage
{
int_SID;
publicintSID
{
get{return_SID;
}
set{_SID=value;
string_SName;
publicstringSName
get{return_SName;
set{_SName=value;
int_STypeID;
publicintSTypeID
get{return_STypeID;
set{_STypeID=value;
string_SImage;
publicstringSImage
get{return_SImage;
set{_SImage=value;
string_SWriter;
publicstringSWriter
get{return_SWriter;
set{_SWriter=value;
string_SPublisher;
publicstringSPublisher
get{return_SPublisher;
set{_SPublisher=value;
DateTime_SPublishDate;
publicDateTimeSPublishDate
get{return_SPublishDate;
set{_SPublishDate=value;
int_SPublishTimes;
publicintSPublishTimes
get{return_SPublishTimes;
set{_SPublishTimes=value;
string_SISBN;
publicstringSISBN
get{return_SISBN;
set{_SISBN=value;
int_SPageCount;
publicintSPageCount
get{return_SPageCount;
set{_SPageCount=value;
string_SPageSize;
publicstringSPageSize
get{return_SPageSize;
set{_SPageSize=value;
int_SWordCount;
publicintSWordCount
get{return_SWordCount;
set{_SWordCount=value;
float_SPrice;
publicfloatSPrice
get{return_SPrice;
set{_SPrice=value;
string_SIntro;
publicstringSIntro
get{return_SIntro;
set{_SIntro=value;
int_SStorageCount;
publicintSStorageCount
get{return_SStorageCount;
set{_SStorageCount=value;
string_SContents;
publicstringSContents
get{return_SContents;
set{_SContents=value;
DateTime_SInTime;
publicDateTimeSInTime
get{return_SInTime;
set{_SInTime=value;
publicStorage()
//
//TODO:
在此处添加构造函数逻辑
}
步骤三:
定义一个针对Storage表操作的StorageAccess数据访问类,实现五个操作方法,代码如下:
usingSystem.Data.SqlClient;
///StorageAccess的摘要说明
publicclassStorageAccess
DataAccessda=newDataAccess();
publicStorageAccess()
///<
///添加商品
paramname="
storage"
>
<
/param>
returns>
/returns>
publicboolAddStorage(Storagegoods)
SqlParameter[]sqlparams=newSqlParameter[]{
newSqlParameter("
@Name"
SqlDbType.NVarChar,500),
@TypeID"
SqlDbType.Int),
@Image"
@Writer"
@Publisher"
SqlDbType.NText),
@PublishDate"
SqlDbType.DateTime),
@PublishTimes"
SqlDbType.Int),
@ISBN"
SqlDbType.NVarChar,50),
@PageCount"
@Price"
SqlDbType.Float),
@Intro"
@Contents"
@StorageCount"
@GoodsID"
SqlDbType.Int)
};
sqlparams[0].Value=goods.SName;
sqlparams[1].Value=goods.STypeID;
sqlparams[2].Value=goods.SImage;
sqlparams[3].Value=goods.SWriter;
sqlparams[4].Value=goods.SPublisher;
sqlparams[5].Value=goods.SPublishDate;
sqlparams[6].Value=goods.SPublishTimes;
sqlparams[7].Value=goods.SISBN;
sqlparams[8].Value=goods.SPageCount;
sqlparams[9].Value=goods.SPrice;
sqlparams[10].Value=goods.SIntro;
sqlparams[11].Value=goods.SContents;
sqlparams[12].Value=goods.SStorageCount;
sqlparams[13].Direction=ParameterDirection.Output;
intresult=da.ExecuteNonQuery("
AddStorage"
sqlparams);
if(result>
0)
goods.SID=Convert.ToInt32(sqlparams[13].Value);
returntrue;
else
returnfalse;
///根据分类ID获取货物列表
categoryID"
publicDataSetGetStorageByCategoryID(intcategoryID)
@CategoryID"
sqlparams[0].Value=categoryID;
returnda.ExecuteQuery("
GetStorageByCategoryID"
///获取一个商品对象实体
sid"
publicStorageGetModel(intsid)
@SID"
sqlparams[0].Value=sid;
DataSetds=da.ExecuteQuery("
GetStorageBySID"
Storagegoods=newStorage();
if(ds.Tables[0].Rows.Count>
goods.SID=int.Parse(ds.Tables[0].Rows[0]["
SID"
].ToString());
goods.SName=ds.Tables[0].Rows[0]["
SName"
].ToString();
if(ds.Tables[0].Rows[0]["
STypeID"
].ToString()!
="
"
goods.STypeID=int.Parse(ds.Tables[0].Rows[0]["
goods.SImage=ds.Tables[0].Rows[0]["
SImage"
goods.SWriter=ds.Tables[0].Rows[0]["
SWriter"
goods.SPublisher=ds.Tables[0].Rows[0]["
SPublisher"
SPublishDate"
goods.SPublishDate=DateTime.Parse(ds.Tables[0].Rows[0]["
SPublishTimes"
goods.SPublishTimes=int.Parse(ds.Tables[0].Rows[0]["
goods.SISBN=ds.Tables[0].Rows[0]["
SISBN"
SPageCount"
goods.SPageCount=int.Parse(ds.Tables[0].Rows[0]["
SPrice"
goods.SPrice=float.Parse(ds.Tables[0].Rows[0]["
goods.SIntro=ds.Tables[0].Rows[0]["
SIntro"
goods.SContents=ds.Tables[0].Rows[0]["
SContents"
SStorageCount"
goods.SStorageCount=int.Parse(ds.Tables[0].Rows[0]["
returngoods;
returnnull;
}
///根据商品ID号删除指定商品
publicboolDelete(intID)
SqlParameter[]sqlparams={
newSqlParameter("
@ID"
SqlDbType.Int,4)};
sqlparams[0].Va