外文翻译 - Web的开发教程_第1页
外文翻译 - Web的开发教程_第2页
外文翻译 - Web的开发教程_第3页
外文翻译 - Web的开发教程_第4页
外文翻译 - Web的开发教程_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

0外文原文WebDevelopmentTutorialsfromIntroductionAswebdevelopers,ourlivesrevolvearoundworkingwithdata.Wecreatedatabasestostorethedata,codetoretrieveandmodifyit,andwebpagestocollectandsummarizeit.ThisisthefirsttutorialinalengthyseriesthatwillexploretechniquesforimplementingthesecommonpatternsinASP.WellstartwithcreatingasoftwarearchitecturecomposedofaDataAccessLayer(DAL)usingTypedDataSets,aBusinessLogicLayer(BLL)thatenforcescustombusinessrules,andapresentationlayercomposedofASPpagesthatshareacommonpagelayout.Oncethisbackendgroundworkhasbeenlaid,wellmoveintoreporting,showinghowtodisplay,summarize,collect,andvalidatedatafromawebapplication.Thesetutorialsaregearedtobeconciseandprovidestep-by-stepinstructionswithplentyofscreenshotstowalkyouthroughtheprocessvisually.EachtutorialisavailableinC#andVisualBasicversionsandincludesadownloadofthecompletecodeused.(Thisfirsttutorialisquitelengthy,buttherestarepresentedinmuchmoredigestiblechunks.)ForthesetutorialswellbeusingaMicrosoftSQLServer2005ExpressEditionversionoftheNorthwinddatabaseplacedintheApp_Datadirectory.Inadditiontothedatabasefile,theApp_DatafolderalsocontainstheSQLscriptsforcreatingthedatabase,incaseyouwanttouseadifferentdatabaseversion.ThesescriptscanbealsobedownloadeddirectlyfromMicrosoft,ifyoudprefer.IfyouuseadifferentSQLServerversionoftheNorthwinddatabase,youwillneedtoupdatetheNORTHWNDConnectionStringsettingintheapplicationsWeb.configfile.ThewebapplicationwasbuiltusingVisualStudio20051ProfessionalEditionasafilesystem-basedWebsiteproject.However,allofthetutorialswillworkequallywellwiththefreeversionofVisualStudio2005,VisualWebDeveloper.InthistutorialwellstartfromtheverybeginningandcreatetheDataAccessLayer(DAL),followedbycreatingtheBusinessLogicLayer(BLL)inthesecondtutorial,andworkingonpagelayoutandnavigationinthethird.Thetutorialsafterthethirdonewillbuilduponthefoundationlaidinthefirstthree.Wevegotalottocoverinthisfirsttutorial,sofireupVisualStudioandletsgetstarted!Step1:CreatingaWebProjectandConnectingtotheDatabaseBeforewecancreateourDataAccessLayer(DAL),wefirstneedtocreateawebsiteandsetupourdatabase.Startbycreatinganewfilesystem-basedASPwebsite.Toaccomplishthis,gototheFilemenuandchooseNewWebSite,displayingtheNewWebSitedialogbox.ChoosetheASPWebSitetemplate,settheLocationdrop-downlisttoFileSystem,chooseafoldertoplacethewebsite,andsetthelanguagetoC#.ThiswillcreateanewwebsitewithaDefault.aspxASPpageandanApp_Datafolder.Withthewebsitecreated,thenextstepistoaddareferencetothedatabaseinVisualStudiosServerExplorer.ByaddingadatabasetotheServerExploreryoucanaddtables,storedprocedures,views,andsoonallfromwithinVisualStudio.YoucanalsoviewtabledataorcreateyourownquerieseitherbyhandorgraphicallyviatheQueryBuilder.Furthermore,whenwebuildtheTypedDataSetsfortheDALwellneedtopointVisualStudiotothedatabasefromwhichtheTypedDataSetsshouldbeconstructed.Whilewecanprovidethisconnectioninformationatthatpointintime,VisualStudioautomaticallypopulatesadrop-downlistofthedatabasesalreadyregisteredintheServerExplorer.ThestepsforaddingtheNorthwinddatabasetotheServerExplorerdependonwhetheryouwanttousetheSQLServer2005ExpressEditiondatabaseintheApp_DatafolderorifyouhaveaMicrosoftSQLServer2000or2005databaseserversetupthatyouwanttouseinstead.UsingaDatabaseintheApp_DataFolder2IfyoudonothaveaSQLServer2000or2005databaseservertoconnectto,oryousimplywanttoavoidhavingtoaddthedatabasetoadatabaseserver,youcanusetheSQLServer2005ExpressEditionversionoftheNorthwinddatabasethatislocatedinthedownloadedwebsitesApp_Datafolder(NORTHWND.MDF).AdatabaseplacedintheApp_DatafolderisautomaticallyaddedtotheServerExplorer.AssumingyouhaveSQLServer2005ExpressEditioninstalledonyourmachineyoushouldseeanodenamedNORTHWND.MDFintheServerExplorer,whichyoucanexpandandexploreitstables,views,storedprocedure,andsoon(seeFigure2).TheApp_DatafoldercanalsoholdMicrosoftAccess.mdbfiles,which,liketheirSQLServercounterparts,areautomaticallyaddedtotheServerExplorer.IfyoudontwanttouseanyoftheSQLServeroptions,youcanalwaysdownloadaMicrosoftAccessversionoftheNorthwinddatabasefileanddropintotheApp_Datadirectory.Keepinmind,however,thatAccessdatabasesarentasfeature-richasSQLServer,andarentdesignedtobeusedinwebsitescenarios.Furthermore,acoupleofthe35+tutorialswillutilizecertaindatabase-levelfeaturesthatarentsupportedbyAccess.ConnectingtotheDatabaseinaMicrosoftSQLServer2000or2005DatabaseServerAlternatively,youmayconnecttoaNorthwinddatabaseinstalledonadatabaseserver.IfthedatabaseserverdoesnotalreadyhavetheNorthwinddatabaseinstalled,youfirstmustaddittodatabaseserverbyrunningtheinstallationscriptincludedinthistutorialsdownloadorbydownloadingtheSQLServer2000versionofNorthwindandinstallationscriptdirectlyfromMicrosoftswebsite.Onceyouhavethedatabaseinstalled,gototheServerExplorerinVisualStudio,right-clickontheDataConnectionsnode,andchooseAddConnection.IfyoudontseetheServerExplorergototheView/ServerExplorer,orhitCtrl+Alt+S.ThiswillbringuptheAddConnectiondialogbox,whereyoucanspecifytheservertoconnectto,theauthenticationinformation,andthedatabasename.OnceyouhavesuccessfullyconfiguredthedatabaseconnectioninformationandclickedtheOKbutton,thedatabasewillbeaddedasanode3underneaththeDataConnectionsnode.Youcanexpandthedatabasenodetoexploreitstables,views,storedprocedures,andsoon.Step2:CreatingtheDataAccessLayerWhenworkingwithdataoneoptionistoembedthedata-specificlogicdirectlyintothepresentationlayer(inawebapplication,theASPpagesmakeupthepresentationlayer).ThismaytaketheformofwritingADOcodeintheASPpagescodeportionorusingtheSqlDataSourcecontrolfromthemarkupportion.Ineithercase,thisapproachtightlycouplesthedataaccesslogicwiththepresentationlayer.Therecommendedapproach,however,istoseparatethedataaccesslogicfromthepresentationlayer.ThisseparatelayerisreferredtoastheDataAccessLayer,DALforshort,andistypicallyimplementedasaseparateClassLibraryproject.Thebenefitsofthislayeredarchitecturearewelldocumented(seetheFurtherReadingssectionattheendofthistutorialforinformationontheseadvantages)andistheapproachwewilltakeinthisseries.Allcodethatisspecifictotheunderlyingdatasourcesuchascreatingaconnectiontothedatabase,issuingSELECT,INSERT,UPDATE,andDELETEcommands,andsoonshouldbelocatedintheDAL.Thepresentationlayershouldnotcontainanyreferencestosuchdataaccesscode,butshouldinsteadmakecallsintotheDALforanyandalldatarequests.DataAccessLayerstypicallycontainmethodsforaccessingtheunderlyingdatabasedata.TheNorthwinddatabase,forexample,hasProductsandCategoriestablesthatrecordtheproductsforsaleandthecategoriestowhichtheybelong.InourDALwewillhavemethodslike:GetCategories(),whichwillreturninformationaboutallofthecategoriesGetProducts(),whichwillreturninformationaboutalloftheproductsGetProductsByCategoryID(categoryID),whichwillreturnallproductsthatbelongtoaspecifiedcategoryGetProductByProductID(productID),whichwillreturninformationaboutaparticularproduct4Thesemethods,wheninvoked,willconnecttothedatabase,issuetheappropriatequery,andreturntheresults.Howwereturntheseresultsisimportant.ThesemethodscouldsimplyreturnaDataSetorDataReaderpopulatedbythedatabasequery,butideallytheseresultsshouldbereturnedusingstrongly-typedobjects.Astrongly-typedobjectisonewhoseschemaisrigidlydefinedatcompiletime,whereastheopposite,aloosely-typedobject,isonewhoseschemaisnotknownuntilruntime.Forexample,theDataReaderandtheDataSet(bydefault)areloosely-typedobjectssincetheirschemaisdefinedbythecolumnsreturnedbythedatabasequeryusedtopopulatethem.Toaccessaparticularcolumnfromaloosely-typedDataTableweneedtousesyntaxlike:DataTable.RowsindexcolumnName.TheDataTablesloosetypinginthisexampleisexhibitedbythefactthatweneedtoaccessthecolumnnameusingastringorordinalindex.Astrongly-typedDataTable,ontheotherhand,willhaveeachofitscolumnsimplementedasproperties,resultingincodethatlookslike:DataTable.Rowsindex.ColumnName.Toreturnstrongly-typedobjects,developerscaneithercreatetheirowncustombusinessobjectsoruseTypedDataSets.Abusinessobjectisimplementedbythedeveloperasaclasswhosepropertiestypicallyreflectthecolumnsoftheunderlyingdatabasetablethebusinessobjectrepresents.ATypedDataSetisaclassgeneratedforyoubyVisualStudiobasedonadatabaseschemaandwhosemembersarestrongly-typedaccordingtothisschema.TheTypedDataSetitselfconsistsofclassesthatextendtheADODataSet,DataTable,andDataRowclasses.Inadditiontostrongly-typedDataTables,TypedDataSetsnowalsoincludeTableAdapters,whichareclasseswithmethodsforpopulatingtheDataSetsDataTablesandpropagatingmodificationswithintheDataTablesbacktothedatabase.Note:FormoreinformationontheadvantagesanddisadvantagesofusingTypedDataSetsversuscustombusinessobjects,refertoDesigningDataTierComponentsandPassingDataThroughTiers.5Wellusestrongly-typedDataSetsforthesetutorialsarchitecture.Figure3illustratestheworkflowbetweenthedifferentlayersofanapplicationthatusesTypedDataSets.CreatingaTypedDataSetandTableAdapterTobegincreatingourDAL,westartbyaddingaTypedDataSettoourproject.Toaccomplishthis,right-clickontheprojectnodeintheSolutionExplorerandchooseAddaNewItem.SelecttheDataSetoptionfromthelistoftemplatesandnameitNorthwind.xsd.AfterclickingAdd,whenpromptedtoaddtheDataSettotheApp_Codefolder,chooseYes.TheDesignerfortheTypedDataSetwillthenbedisplayed,andtheTableAdapterConfigurationWizardwillstart,allowingyoutoaddyourfirstTableAdaptertotheTypedDataSet.ATypedDataSetservesasastrongly-typedcollectionofdata;itiscomposedofstrongly-typedDataTableinstances,eachofwhichisinturncomposedofstrongly-typedDataRowinstances.Wewillcreateastrongly-typedDataTableforeachoftheunderlyingdatabasetablesthatweneedtoworkwithinthistutorialsseries.LetsstartwithcreatingaDataTablefortheProductstable.Keepinmindthatstrongly-typedDataTablesdonotincludeanyinformationonhowtoaccessdatafromtheirunderlyingdatabasetable.InordertoretrievethedatatopopulatetheDataTable,weuseaTableAdapterclass,whichfunctionsasourDataAccessLayer.ForourProductsDataTable,theTableAdapterwillcontainthemethodsGetProducts(),GetProductByCategoryID(categoryID),andsoonthatwellinvokefromthepresentationlayer.TheDataTablesroleistoserveasthestrongly-typedobjectsusedtopassdatabetweenthelayers.TheTableAdapterConfigurationWizardbeginsbypromptingyoutoselectwhichdatabasetoworkwith.Thedrop-downlistshowsthosedatabasesintheServerExplorer.IfyoudidnotaddtheNorthwinddatabasetotheServerExplorer,youcanclicktheNewConnectionbuttonatthistimetodoso.AfterselectingthedatabaseandclickingNext,youllbeaskedifyouwanttosavetheconnectionstringintheWeb.configfile.Bysavingtheconnectionstringyoullavoidhaving6ithardcodedintheTableAdapterclasses,whichsimplifiesthingsiftheconnectionstringinformationchangesinthefuture.Ifyouopttosavetheconnectionstringintheconfigurationfileitsplacedinthesection,whichcanbeoptionallyencryptedforimprovedsecurityormodifiedlaterthroughthenewASPPropertyPagewithintheIISGUIAdminTool,whichismoreidealforadministrators.7中文翻译Web的开发教程随着网络的发展,我们的生活围绕着工作与数据。我们建立数据库来存储数据,代码来检索和修改它,网页,收集和总结。这是一个漫长的时间将探讨落实这些常见的ASP模式的技术教程。我们将首先建立一个软件架构组成的一个数据访问层(DAL)使用,类型化DataSet商业逻辑层(BLL),负责执行自定义的业务规则,并表示层由ASP页面共享一个共同的页面布局。一旦这个后端基础已经奠定,我们将进入报告,说明如何显示,汇总,收集和验证的Web应用程序的数据。这些教程面向精简,提供逐步与屏幕截图大量一步的指示,走过你的过程可视化。每个教程可在C和VisualBasic版本,并包括完整的使用代码下载。(这第一个教程是相当漫长的,但其余的是更消化块介绍。)对于这些教程,我们将使用MicrosoftSQLServer2005Express版是在App_Data目录中的Northwind数据库的版本。除了数据库文件,App_Data文件夹中还包含用于创建数据库的SQL脚本,如果你想使用不同的数据库版本。这些脚本也可以直接从微软下载,如果您希望。如果您使用不同的SQLServerNorthwind数据库的版本,您将需要更新应用程序的Web.config文件NORTHWNDConnectionString设置。Web应用程序是使用内置的文件系统的VisualStudio2005专业版的网站项目。然而,所有的教程将同样出色的VisualStudio2005的免费版本,VisualWebDeveloper中。在本教程中,我们将从头开始创建数据访问层(DAL),通过创造业务逻辑层(BLL)在随后的第二个教程,和页面布局和导航工作在第三。之后第三个将建立在前三奠定了基础的教程。我们有很多,在这第一个教程,所以火了VisualStudio中,让我们开始吧!步骤1:创建一个Web项目,并连接到数据库在我们可以创造我们的数据访问层(DAL),我们首先需要创建一个网站,并安装我们的数据库。首先创建一个新的文件系统为基础的ASP网站。要做到这一点,请转到文件菜单并选择新建网站,显示新建网站对话框。选择ASP网站模板,设置位置下拉列表的文件系统,选择一个文件夹放在网站,并设置语言为C。这将创建一个Default.aspx的ASP页App_Data文件夹和一个新网站。随着创建的网站网址,下一步就是添加一个引用到VisualStudio的服务器资源管理器数据库。加入数据库的服务器资源管理器,您可以添加表,存储过程,视图,以及一切都在VisualStudio。您还可以查看表中的数据或创建自己的查询无论是通过手或图形化的查询生成器。此外,当我们建立的DAL我们需要指出的VisualStudio来从该类型的DataSet应当建立数据库类型的DataSet。虽然我们可以提供在这一时间点连接信息,VisualStudio会自动填充下拉已在服务器资源管理器注册的数据库列表。8为Northwind数据库添加到服务器资源管理器的步骤取决于您是否要使用App_Data文件夹中的SQLServer2005ExpressEdition数据库,或者如果您有一个MicrosoftSQLServer2000或2005数据库服务器安装您要来代替。使用在App_Data文件夹数据库如果您没有SQLServer2000或2005数据库服务器连接,或您只是希望避免数据库添加到数据库服务器,可以使用SQLServer2005Express的Northwind数据库的版版,位于在下载网站的App_Data文件夹(NORTHWND.MDF)。App_Data文件夹中放置一个数据库,自动添加到服务器资源管理器。假设你有SQLServer2005ExpressEdition的计算机上你应该看到一个名为在服务器资源管理器,NORTHWND.MDF你可以扩大和探讨其表一节点上安装,视图,存储过程等(见图2)。App_Data文件夹也可举办的MicrosoftAccess。mdb文件,其中,像他们的SQLServer的同行,会自动添加到服务器资源管理器。如果您不希望使用SQLServer的任何选项,您可以随时下载到App_Data目录1Northwind数据库的文件拖放MicrosoftAccess版本。请记住,但是,Access数据库的功能并不丰富的如SQLServer,而不是在设计网站的情况下使用。此外,对教程将利用某些数据库级别的访问不被支持的功能。连接到在微软SQLServer2000或2005数据库数据库服务器或者,您可以连接到Northwind数据库在数据库服务器上安装。如果数据库服务器不已Northwind数据库的安装,您首先必须添加通过运行安装脚本到数据库服务器包括在本教程的下载或下载的SQLServer2000的Northwind和安装脚本从微软的网站上直接版本。一旦你的数据库中安装,到服务器资源管理器在VisualStudio中,右键单击数据连接节点,并选择添加连接。如果您没有看到服务器资源管理器去浏览/服务器资源管理器,或按Ctrl+Alt键+号这将弹出添加连接对话框,在这里您可以指定服务器连接,身份验证信息和数据库的名称。一旦你成功地配置数据库连接信息,并点击确定按钮,该数据库将被作为下的数据连接节点的节点。您可以展开数据库节点,探讨其表,视图,存储过程等。第2步:创建数据访问层当数据一个选择的工作是嵌入到数据层的特定逻辑直接(在Web应用程序的ASP页弥补层)。这可能需要编写在ASP页面的代码部分ADO代码或标记的部分使用SqlDataSource控件的形式。无论是哪种情况,这种方法紧密夫妇的数据表示层的访问逻辑。推荐的方法,但是,独立于层的数据访问逻辑。这个单独的层称为数据访问层,达勒为短,通常实现为一个单独的类库项目。所有代码特定于底层数据源,如创建一个连接到数据库,发出的SELECT,INSERT,UPDATE和DELETE命令,等等-应在DAL位置。表示层不应该包含任何这些数据访问代码的引用,而应该有作任何及所有数据请求达勒电话。数据访问层通常包含用于访问基础数据库数据的方法。Northwind数据库,例如,产品及目录表,记录销售的产品类别和其所属。在我们的达尔我们将有这样的方法:GetCategories(),这将返回有关类别的所有信息GetProducts(),这将返回有关产品的所有信息9GetProductsByCategoryID(类别ID),将返回所有的产品属于指定分类GetProductByProductID(产品ID),它将返回一个特定产品的信息这些方法,调用时,将连接到数据库,发出适当的查询,并返回结果。我们如何回报这些结果是重要的。这些方法可以简单地返回DataSet或DataReader的数据库查询人口,但理

温馨提示

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

评论

0/150

提交评论