实验九添加及修改信息功能实现.docx

上传人:b****2 文档编号:2831091 上传时间:2023-05-04 格式:DOCX 页数:20 大小:61.07KB
下载 相关 举报
实验九添加及修改信息功能实现.docx_第1页
第1页 / 共20页
实验九添加及修改信息功能实现.docx_第2页
第2页 / 共20页
实验九添加及修改信息功能实现.docx_第3页
第3页 / 共20页
实验九添加及修改信息功能实现.docx_第4页
第4页 / 共20页
实验九添加及修改信息功能实现.docx_第5页
第5页 / 共20页
实验九添加及修改信息功能实现.docx_第6页
第6页 / 共20页
实验九添加及修改信息功能实现.docx_第7页
第7页 / 共20页
实验九添加及修改信息功能实现.docx_第8页
第8页 / 共20页
实验九添加及修改信息功能实现.docx_第9页
第9页 / 共20页
实验九添加及修改信息功能实现.docx_第10页
第10页 / 共20页
实验九添加及修改信息功能实现.docx_第11页
第11页 / 共20页
实验九添加及修改信息功能实现.docx_第12页
第12页 / 共20页
实验九添加及修改信息功能实现.docx_第13页
第13页 / 共20页
实验九添加及修改信息功能实现.docx_第14页
第14页 / 共20页
实验九添加及修改信息功能实现.docx_第15页
第15页 / 共20页
实验九添加及修改信息功能实现.docx_第16页
第16页 / 共20页
实验九添加及修改信息功能实现.docx_第17页
第17页 / 共20页
实验九添加及修改信息功能实现.docx_第18页
第18页 / 共20页
实验九添加及修改信息功能实现.docx_第19页
第19页 / 共20页
实验九添加及修改信息功能实现.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验九添加及修改信息功能实现.docx

《实验九添加及修改信息功能实现.docx》由会员分享,可在线阅读,更多相关《实验九添加及修改信息功能实现.docx(20页珍藏版)》请在冰点文库上搜索。

实验九添加及修改信息功能实现.docx

实验九添加及修改信息功能实现

实验九、添加及修改信息功能实现

一、教学目的

1.掌握三层架构应用程序的开发。

2.FileUpLoad控件实现上传功能。

3.通用创建目录和提示方法方法的实现。

4.添加及修改功能的实现方法。

二、实验内容

1.以网上书店的数据库BookShop中的Storage表为例设计一个添加货物信息的功能,设计界面效果如下

分析一下,本界面执行思路如下:

(1)从列表页跳转到本页,如果是添加新书,将是空白,如果是修改书籍信息,将显示书籍信息;

(2)点浏览按钮选择要上传的图片文件;

(3)如果是添加新书,将只会显示添加按钮,点添加按钮,如果添加成功会显示如下提示。

(4)如果是修改书籍,将只会显示修改按钮,点修改按钮,将出现修改成功对话框,确定将返回。

2.首先在Entity文件夹中定义一个专门针对Storage表操作的Storage实体类。

3.新建二个存储过程,用于添加和修改商品信息。

4.再根据前面设计的实现思路,实现方法如下,在数据访问层DataAccess中新建一个StorageAccess.cs文件中添加如下方法,并实现代码:

publicboolAddStorage(Storagegoods)方法;

publicboolModifyStorage(Storagegoods)方法;

5.再在业务逻辑层下,新建一个StorageBLL.cs文件,在其中添加如下逻辑方法,并实现代码:

publicboolAddStorage(Storagegoods)方法;

publicboolModifyStorage(Storagegoods)方法;

5.最后进入界面下的后台,从文本框及其他控件读取数据,然后执行添加和修改功能即可完成。

三、仪器、设备、材料

微机(VS2008)

四、实验准备

1.理论知识预习及要求

ASP.NET应用程序开发的一般步骤。

类设计的一般步骤。

2.实验指导书预习及要求

先在草稿纸上编写主要程序代码,再上机调试。

3.其他准备

五、实验原理或操作要点简介

1.ASP.NET应用程序开发的一般步骤。

2.掌握三层开发的一般方法。

六、注意事项

⏹及时保存文件,避免死机或断电造成的文件丢失。

⏹实验过程中容易出现的问题:

1.机房装有2个操作系统。

注意选择第二个“应用软件编程系统”。

2.新建项目时,注意选择项目类型“C#”。

3.在C#.NET,窗口比较多,操作不当破坏了窗口的布局后,可通过“工具|选项”命令,在其对话框中选择“重制窗口布局”,恢复默认布局。

七、实验过程与指导

1.在Entity目录下新建一个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;

///

///Storage的摘要说明

///

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:

在此处添加构造函数逻辑

//

}

}

3.实现步骤如下:

步骤一:

定义一个添加和修改商品信息页面,效果如上图:

步骤二:

在数据库中添加二个存储过程,代码如下:

//添加商品

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

//修改商品

ALTERPROCEDUREdbo.ModifyStorage

@NameNVarChar(500),

@ImageNVarChar(500),

@WriterNVarChar(500),

@PublisherNText,

@PublishDateDateTime,

@PublishTimesInt,

@ISBNNVarChar(50),

@PageCountInt,

@Pricefloat,

@IntroNText,

@ContentsNText,

@StorageCountInt,

@GoodsIDInt

AS

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

步骤三:

定义一个数据访问类StorageAccess文件,在其中定义一个添加货物信息的方法和一个修改商品信息的方法,代码如下:

///

///添加商品

///

///

///

publicboolAddStorage(Storagegoods)

{

SqlParameter[]sqlparams=newSqlParameter[]{

newSqlParameter("@Name",SqlDbType.NVarChar,500),

newSqlParameter("@TypeID",SqlDbType.Int),

newSqlParameter("@Image",SqlDbType.NVarChar,500),

newSqlParameter("@Writer",SqlDbType.NVarChar,500),

newSqlParameter("@Publisher",SqlDbType.NText),

newSqlParameter("@PublishDate",SqlDbType.DateTime),

newSqlParameter("@PublishTimes",SqlDbType.Int),

newSqlParameter("@ISBN",SqlDbType.NVarChar,50),

newSqlParameter("@PageCount",SqlDbType.Int),

newSqlParameter("@Price",SqlDbType.Float),

newSqlParameter("@Intro",SqlDbType.NText),

newSqlParameter("@Contents",SqlDbType.NText),

newSqlParameter("@StorageCount",SqlDbType.Int),

newSqlParameter("@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;

}

}

///

///修改商品

///

///

///

publicboolModifyStorage(Storagegoods)

{

SqlParameter[]sqlparams=newSqlParameter[]{

newSqlParameter("@Name",SqlDbType.NVarChar,500),

newSqlParameter("@Image",SqlDbType.NVarChar,500),

newSqlParameter("@Writer",SqlDbType.NVarChar,500),

newSqlParameter("@Publisher",SqlDbType.NText),

newSqlParameter("@PublishDate",SqlDbType.DateTime),

newSqlParameter("@PublishTimes",SqlDbType.Int),

newSqlParameter("@ISBN",SqlDbType.NVarChar,50),

newSqlParameter("@PageCount",SqlDbType.Int),

newSqlParameter("@Price",SqlDbType.Float),

newSqlParameter("@Intro",SqlDbType.NText),

newSqlParameter("@Contents",SqlDbType.NText),

newSqlParameter("@StorageCount",SqlDbType.Int),

newSqlParameter("@GoodsID",SqlDbType.Int)

};

sqlparams[0].Value=goods.SName;

sqlparams[1].Value=goods.SImage;

sqlparams[2].Value=goods.SWriter;

sqlparams[3].Value=goods.SPublisher;

sqlparams[4].Value=goods.SPublishDate;

sqlparams[5].Value=goods.SPublishTimes;

sqlparams[6].Value=goods.SISBN;

sqlparams[7].Value=goods.SPageCount;

sqlparams[8].Value=goods.SPrice;

sqlparams[9].Value=goods.SIntro;

sqlparams[10].Value=goods.SContents;

sqlparams[11].Value=goods.SStorageCount;

sqlparams[12].Value=goods.SID;

intresult=da.ExecuteNonQuery("ModifyStorage",sqlparams);

if(result>0)

{

returntrue;

}

else

returnfalse;

}

步骤四:

定义一个定义业务逻辑类StorageBLL文件,在其中定义一个添加商品信息的方法和修改商品信息的方法,代码如下:

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;

///

///StorageBLL的摘要说明

///

publicclassStorageBLL

{

StorageAccesssa=newStorageAccess();

publicStorageBLL()

{

//

//TODO:

在此处添加构造函数逻辑

//

}

///

///添加商品

///

///

///

publicboolAddStorage(Storagegoods)

{

returnsa.AddStorage(goods);

}

}

///

///修改商品

///

///

///

publicboolModifyStorage(Storagegoods)

{

returnsa.ModifyStorage(goods);

}

步骤五:

双击按钮进入界面下的后台文件,添加后台代码如下:

usingSystem;

usingSystem.Collections;

usingSystem.Configuration;

usingSystem.Data;

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;

publicpartialclassAdmin_Goods_GoodsAdd:

System.Web.UI.Page

{

StorageBLLsb=newStorageBLL();

objectgoodsid;

protectedvoidPage_Load(objectsender,EventArgse)

{

if(!

IsPostBack)

{

goodsid=Request.Params["goodsid"];

SetControl(goodsid);

}

}

publicvoidSetControl(objectid)

{

if(goodsid==null)

{

Label1.Text="添加新书籍";

hlkImage.Visible=false;

btnAdd.Visible=true;

btnUpdate.Visible=false;

hfTypeID.Value=Request.Params["typeid"];

}

else

{

Label1.Text="修改书籍信息";

hlkImage.Visible=true;

btnAdd.Visible=false;

btnUpdate.Visible=true;

BindBookInfo(Convert.ToInt32(goodsid));

}

}

privatevoidBindBookInfo(intbo

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2