WebEngine项目中CMPServices类库的用法简介
2007-03-22 15:47
465 查看
由于WebEngine项目将完全采用CMP做底层,所以有必要对CMPServices类库的用法作一下简单的介绍。 1、web.config文件中的相关配置 <configuration> <configSections> <section name="DataConfig" type="Lanx.WebEngine.CMPServices.CMPConfigurationHandler, Lanx.WebEngine.CMPServices"/> </configSections> <DataConfig> <ContainerMappingSet> <!--相关CMP元数据--> <ContainerMapping> </ContainerMapping> </ContainerMappingSet> </DataConfig> </configuration> 2、命名空间的引用方式 using Lanx.WebEngine.CMPServices; 3、持久对象类示例 using System; using System.Data; using Lanx.WebEngine.CMPServices; namespace Lanx.WebEngine.ProductCatalog.Data { /// <summary> /// ProductBrowseSet负责存储产品列表显示的数据集。 /// </summary> public class ProductBrowseSet : PersistableObjectSet { private int categoryId; private string searchKey; public int CategoryId { get { return categoryId; } set { categoryId = value; } } public string SearchKey { get { return searchKey; } set { searchKey = value; } } public override void FinalizeData() { ProductBrowseSet.FinalizeData( internalData ); } new public static void FinalizeData( DataSet scratchData ) { // perform finalization on scratchData. } } } 4、CMP元数据示例 <configuration> <DataConfig> <ContainerMappingSet> <!--产品快速搜索容器--> <ContainerMapping> <ContainerMappingId>QuickSearch</ContainerMappingId> <ContainedClass>ProductBrowseSet</ContainedClass> <Select> <CommandName>sp_Products_QuickSearch</CommandName> <Parameter> <ClassMember>SearchKey</ClassMember> <ParameterName>@searchKey</ParameterName> <DbTypeHint>Varchar</DbTypeHint> <ParamDirection>Input</ParamDirection> <Size>200</Size> </Parameter> </Select> </ContainerMapping> </ContainerMappingSet> </DataConfig> </configuration> 5、存储过程写法示例 /**** 产品目录快速搜索 ****/ CREATE PROCEDURE sp_Products_QuickSearch @SearchKey varchar(200) AS SELECT Products.ProductId, Name, ShortDescription, LongDescription, Deleted, ProductSkus.RetailPrice, ProductSkus.ActualPrice, ProductSkus.Description SkuDesc, ProductSkus.SKU, Products.CategoryId, ParentCategoryId = ( SELECT ParentCategoryId FROM Products_Categories cats WHERE cats.CategoryId = Products.CategoryId ) From Products_Products Products INNER JOIN ProductSKUs ON Products.ProductId = ProductSKUs.ProductId WHERE NAME LIKE '%' + @SearchKey+ '%' OR ShortDescription LIKE '%'+@SearchKey+'%' OR LongDescription LIKE '%'+@SearchKey+'%' OR ProductSkus.Description LIKE '%'+@SearchKey+'%' ORDER BY Name ASC, ProductSkus.ActualPrice DESC GO 6、CMP类库使用示例 #region 产品快速搜索容器 /// <summary> /// 产品快速搜索 /// </summary> /// <param name="searchKey">搜索关键字</param> /// <returns>产品搜索结果列表</returns> public static DataSet QuickSearch( string searchKey ) { SqlPersistenceContainer spc = new SqlPersistenceContainer( CMPConfigurationHandler.ContainerMaps["QuickSearch"]); ProductBrowseSet pbs = new ProductBrowseSet(); pbs.SearchKey = searchKey; spc.Select( pbs ); pbs.FinalizeData(); return pbs.ResultSet; } #endregion 7、全局文件要做的内容如下: a)Global.asax文件中<%@ Application Codebehind="Global.asax.cs" %> b)Global.asax.cs文件中 using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; using System.Data; using System.Data.SqlClient; using System.Web.Caching; using Lanx.WebEngine.ConfigurationServices; using Lanx.WebEngine.ProductCatalog.Business; namespace Lanx.WebEngine { /// <summary> /// Summary description for Global. /// </summary> public class Global : System.Web.HttpApplication { public Global() { InitializeComponent(); } protected void Application_Start(Object sender, EventArgs e) { System.Configuration.ConfigurationSettings.GetConfig("DataConfig"); SiteProfile.DefaultDataSource = System.Configuration.ConfigurationSettings.AppSettings["DefaultDataSource"]; SiteProfile.DbTypeHints["Varchar"] = System.Data.SqlDbType.VarChar; SiteProfile.DbTypeHints["Int"] = System.Data.SqlDbType.Int; SiteProfile.DbTypeHints["Date"] = System.Data.SqlDbType.DateTime; SiteProfile.DbTypeHints["Text"] = System.Data.SqlDbType.Text; SiteProfile.DbTypeHints["Bit"] = System.Data.SqlDbType.Bit; SiteProfile.DbTypeHints["Money"] = System.Data.SqlDbType.Money; DataTable categorySet = ProductCatalog.GetCategories(); Context.Cache.Insert("Categories", categorySet ); } protected void Session_Start(Object sender, EventArgs e) { } protected void Application_BeginRequest(Object sender, EventArgs e) { } protected void Application_EndRequest(Object sender, EventArgs e) { } protected void Application_AuthenticateRequest(Object sender, EventArgs e) { } protected void Application_Error(Object sender, EventArgs e) { } protected void Session_End(Object sender, EventArgs e) { } protected void Application_End(Object sender, EventArgs e) { } #region Web Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { } #endregion } } 8、原设计方式是把所有的CMP元数据都写在web.config文件中。准备修改为在web.config文件中记录各模板元数据储存的XML文件路径。 |
相关文章推荐
- WebUserControl的简单用法,最近的几个项目都反复用到TextBox,CheckBox,RadiobuttonList,所以玩一下webusercontrol,有个投票功能哦。
- 类库项目使用网站web.config中定义的连接字符串
- SDWebImage类库的用法
- 完美解决“换另一台电脑上用VS2008继续开发web项目时出现“System.Runtime.InteropServices.COMException”,然后是加载不了项目。”
- 完美解决“换另一台电脑上用VS2008继续开发web项目时出现“System.Runtime.InteropServices.COMException”,然后是加载不了项目。”
- ArcGIS Server .Net Web ADF的类库简介(转载)
- 0-Github项目webtest简介
- EHCache 在WEB项目的用法
- ASP.NET MVC2 Web项目中公用类库的问题
- C# Web下的类库 项目中获取程序的运行路径
- 用 Amazon Web Services 进行云计算,第 1 部分: 简介
- [转] Web Services Webpshere 项目管理
- 终于在visual studio.net 2005 找到了创建 XML Web services 的项目的方法
- 关于网络一_WebView用法简介
- Web Services&XML--XML Schema用法
- Mail,Memcache Python API——Google App Engine Services简介
- ASIHTTPRequest类库简介和使用说明以及Google App Engine for ios(转)
- ASP.NET MVC2 Web项目中公用类库的问题
- extjs4+sh+springmvc web系统的基础模块开发(一)-项目简介
- Images, Users, URL Fetch Python API——Google App Engine Services简介