一、编辑或添加数据库(建表与添加数据)
代码示例:
二、打开Vs工具添加项目名为‘barSys’,然后'添加三层架构'并'添加依赖关系'
如图所示:
三、在网站随便下载一个模板:这里以‘模板之家’为例
五、在“BrasServer”文件中添加一个‘母版页’名为‘Bratheme’
六,’母版页‘是种固定网页‘头部’和‘尾部’一致性,也就是在不改变网页‘头部’和‘尾部’时,只改变“中间”部分内容
这是一个‘空母版页’
添加完后代码示例(由于代码太多就不截图了):
七、编辑好'母版页'后,我们继续在‘BrasServer’文件添加一个’Web窗体‘名为‘BraClothList’,然后、选择‘母版页’名为‘Bratheme’
如图所示(选择母版页)
八、这就‘BraClothList窗体’对应'母版页里面ContentPlaceHolder’控件内容
九、现在开始布局内容并实现功能
首先,我先把‘分类’信息从'数据库'加载出来,先在‘数据库’实现功能后,在到前台调用
SQL代码加载分类功能:
代码示例
USE[BarsSys]GO/******Object:StoredProcedure[dbo].[Xyy_Categories_GetList]ScriptDate:02/06/201713:52:23******/SETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGOALTERproc[dbo].[Xyy_Categories_GetList]asbeginselectCateId,NamefromCategorieswhereVis=1endViewCode十、创建一个'分类类',字段跟数据库分类名称一样,然后在创建'数据访问层'编辑调用数据库方法,
创建用'业务逻辑层'调用'数据访问层',最够再创建用'表示层'调用'业务逻辑层'
1、如图所示(类):
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceModels{publicclassCategories{//种类publicintCateId{get;set;}publicstringEnglishName{get;set;}publicstringName{get;set;}publicstringDescription{get;set;}publicboolVis{get;set;}}}ViewCode2、如图所示(数据访问层)
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingModels;usingDBUtility;usingSystem.Data.SqlClient;usingSystem.Data;namespaceDAL{publicclassCategoriesService{//获取种类publicList
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingDAL;usingModels;namespaceBLL{publicclassCategoriesManager{CategoriesServicedal=newCategoriesService();//获取种类publicList
如图所示(修改属性)
十二、修改完后,现在点击“查看源码”进入页面实现加载功能并调用
1、如图所示(LinkButton控件):实现日期排序
2、如图所示(Repeater控件):绑定数据库相对应字符
布局方法:在“添加相应模板”里面“添加相对表格”
3、如图所示(LinkButton控件):主要实现分页功能
(Label):主要实现显示信息内容
并创建“类”编辑“数据访问层”,“业务逻辑层”,“表示层”
1、如图所示(数据库):
USE[BarsSys]GO/******Object:StoredProcedure[dbo].[Xyy_BarGetpageList]ScriptDate:02/06/201715:25:10******/SETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGOALTERproc[dbo].[Xyy_BarGetpageList]@Keyvarchar(200),@StartIdenxvarchar(20),@EndIdenxvarchar(20),@OrderKeyvarchar(20)asbegindeclare@Sqlvarchar(max)set@Sql='select*from(selectrow_number()over(Orderby'+@OrderKey+'desc)asRqwNumber,ProductId,ProductName,Price,ImgSrc,PublishDatefromBars'+@Key+')bankwherebank.RqwNumberbetween'+@StartIdenx+'and'+@EndIdenxexec(@Sql)endViewCode2、如图所示(类):
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceModels{publicclassBars{publicintProductId{get;set;}publicstringProductName{get;set;}publicstringBrand{get;set;}publicintCategoryId{get;set;}publicdecimalPrice{get;set;}publicstringnContent{get;set;}publicstringImgSrc{get;set;}publicDateTimePublishDate{get;set;}publicboolVis{get;set;}}}ViewCode3、如图所示(数据访问层):
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingModels;usingDAL;namespaceBLL{publicclassBarManager{BarsServicedal=newBarsService();//日期publicList
1、如图所示:(加载数据与分页)
2、如图所示(设置按钮状态与页面索引)
3、如图所示(设置总页数属性)
4、1:如图所示:(实现“上一页”与“下一页”,”点击事件“)
4、2:如图所示:(实现“上一页”与“下一页”,”点击事件“)
USE[BarsSys]GO/******Object:StoredProcedure[dbo].[XYY_Product_Count_Key]ScriptDate:02/06/201719:22:42******/SETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGOALTERproc[dbo].[XYY_Product_Count_Key]@categoryidvarchar(20)asbeginif(@categoryid=0)selectCOUNT(*)fromBarswhereVis=1elseselectCOUNT(*)fromBarswhereCategoryId=@categoryidandVis=1endViewCode十七、一样套路:编辑“数据访问层”,“业务逻辑层”,“表示层”
1、如图所示(数据访问层):
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingModels;usingDAL;namespaceBLL{publicclassBarManager{BarsServicedal=newBarsService();//日期publicList