欢迎大家光临【无师自通-教程网】您的到来是我们的荣幸。本站提供photoshop教程,ps教程,flash教程,cad教程,网页制作教程,excel教程,asp教程,vb教程,3d教程,c语言教程,html教程,coreldraw教程,dreamweaver教程,java教程,3dmax教程 等各种教程为主题的内容和服务,相信您会在这里找到您所需要的东东。无师自通伴您一生-谢谢您的光临!!
网站地图 设为首页
简繁切换 加入收藏
栏目待定 留言本站
您现在的位置: 无师自通-教程网 >> WEB开发 >> ASP.NET教程 >> .NET Framework >> 教程正文

  没有公告

教程: ASP.NET教程-.NET Framework-Websharp使用说明 更多...
教程: ASP.NET教程-.NET Framework-Websharp使用说明

if(AutoInit)

form.NewRecord("FormDetail");

}

public FormDetail(EntityData entity)

{

form=entity;

}

#endregion

#region 属性

public string FormDetailID

{

get{return form["FormDetailID","FormDetail"].ToString();}

set{form["FormDetailID","FormDetail"]=value;}

}

public string FormID

{

get{return form["FormID","FormDetail"].ToString();}

set{form["FormID","FormDetail"]=value;}

}

public string ProductID

{

get{return form["ProductID","FormDetail"].ToString();}

set{form["ProductID","FormDetail"]=value;}

}

public decimal InCount

{

get{return form.GetDecimal("InCount","FormDetail");}

set{form["InCount","FormDetail"]=value;}

}

#endregion

#region PersistenceCapable 成员

public int ObjectCount

{

get

{

return form.Tables["FormDetail"].Rows.Count;

}

}

public EntityData EntityData

{

get

{

return form;

}

set

{

form=value;

}

}

public bool Next()

{

return form.Next("FormDetail");

}

public void First()

{

form.First("FormDetail");

}

public void AddNew()

{

form.NewRecord("FormDetail");

}

#endregion

}

数据的存取方式

数据存取的目的,是持久化保存对象。在Websharp中,定义了PersistenceManager接口来实现这个功能。PersistenceManager的定义可以见:附1:Websharp主要接口定义——PersistenceManager

我们可以使用如下的方式来持久化保存一个对象:

Product product=new Product (true);

……//处理product

PersistenceManager pm = PersistenceManagerFactory.Instance().

CreatePersistenceManager();

pm.PersistNewObject(p);

pm.Close();

代码非常简明和直观,没有一大堆数据库操纵的代码,也不容易发生差错。

也可以通过向PersistenceManagerFactory 传递一个PersistenceProperty参数来初始化一个PersistenceManager,如:

PersistenceProperty pp=new PersistenceProperty();

pp……//设置pp的属性

PersistenceManager pm = PersistenceManagerFactory.Instance().CreatePersistenceManager(pp);

关于PersistenceProperty的说明,可以见后面的系统持久化配置信息一节。

事务处理

在很多时候,在处理对象保存的时候,我们需要使用事务处理,特别是在处理上上面示例中的类似于入库单的一对多结构的对象的时候。在Websharp中,我们可以通过Transaction 接口来完成这个功能。Transaction接口的定义可以见:附1:Websharp主要接口定义——Transaction

下面是使用事务处理的一个例子:

Product product=new Product (true);

……//处理product

PersistenceManager pm = PersistenceManagerFactory.Instance().

CreatePersistenceManager();

Transaction trans=pm.CurrentTransaction;

trans.Begin();

try

{

pm.PersistNewObject(p);

trans.Commit();

}

catch(Excption e)

{

trans.Rollback();

}

finally

{

pm.Close();

}

对象的查询

Websharp提供了对对象查询的功能,这个功能通过Query接口提供。Query接口的定义可以见:附1:Websharp主要接口定义——Query

可以通过下面的办法来使用Query接口:

PersistenceManager pm=PersistenceManagerFactory.Instance().CreatePersistenceManager(pp);

Query q=pm.NewQuery("Product");

q.Filter="ProductID='P001'";

q.Open();

EntityData entity=q.QueryData();

dataGrid1.DataSource=entity;

q.Close();

pm.Close();

Websharp也提供了直接操纵数据库的数据访问接口——DataAccess,这个接口对ADO.Net进行了一些封装,可以使程序员更加容易的使用ADO.Net的功能,并且能够屏蔽不同数据库之间的差别。这个接口的定义可以见:附1:Websharp主要接口定义——DataAccess

能够通过PersistenceManager的NewDataAccess方法来初始化一个DataAccess对象,然后调用相应的办法来执行需要的功能。

业务逻辑的处理

有了上面的工作,我们就可以把这些对象组合起来,编写我们的业务逻辑。在面向对象的系统中,业务逻辑表现为对象之间的交互。在一些简单的系统中,没有复杂的业务逻辑,只是一些数据的维护工作,那么,有了上面两个部分的工作,我们实际上可能已经忘成了大部分的工作。

下面是一个简单的例子,表示了一张入库单入库的过程,在这个过程中,需要修改入库单上每种产品的现有库存量:

public void StoreIntoWarehouse(Form insertForm)

{

FormDetail detail=insertForm.FormDetail;

detail.First();

PersistenceManager pm = PersistenceManagerFactory.Instance().CreatePersistenceManager();

Transaction tm=pm.CurrentTransaction;

tm.Begin();

try

{

if(detail.ObjectCount>0)

{

do

{

Product product=(Product)pm.FindObjectByPrimaryKey

(detail.ProductID,Type.GetType

("LogisticsDemo.EntityDefinitions.Product"));

product.CurrentCount =detail.InCount;

pm.UpdateObject(product);

}while(detail.Next());

}

pm.PersistNewObject(insertForm);

tm.Commit();

}

catch(Exception e)

{

tm.Rollback();

throw e;

}

finally

{

pm.Close();

}

}

可以看到,在使用Websharp后,对于业务逻辑的编写,可以变成一个非常自然的过程,也能够节省很多代码量。

业务服务的提供

业务外观层(Business Facade)的目的,是隔离系统功能的提供者和使用者,更明确地说,是隔离业务逻辑的软件的用户界面(可以参见Facade设计模式)。可以使用现有的任何方法来构建构建这个层次,在我们提供的例子中,我们使用了Web Service。

Websharp应用系统的配置

1、 缓存的配置

Websharp使用了微软的Cached Application Block来缓存数据,因此,下面的缓存信息必须在应用程序中添加。关于Cached Application Block,可以参见微软的相关文档。

<configuration>

<configSections>

<section name="CacheManagerSettings" type="Microsoft.ApplicationBlocks.Cache.CacheConfigurationHandler,Microsoft.ApplicationBlocks.Cache" />

<section name="WebsharpExpirationPolicy" type="Websharp.Service.WebsharpCofigurationHandler,Websharp" />

</configSections>

<CacheManagerSettings>

<!-- DATA PROTECTION SETTINGS

Use DataProtectionInfo to set the assembly and class which implement

the dataprotection interfaces for the cache.

-->

<DataProtectionInfo AssemblyName="Microsoft.ApplicationBlocks.Cache"

ClassName="Microsoft.ApplicationBlocks.Cache.DataProtection.DefaultDataProtection"

ValidationKey="Oci44OQ9C3xAdQ3/BMHpksPfzeTezLkXen/ahQ8T7nVk/KMgAFnssQJr00KUNhRso MpLVwAinGep6i14X9M A=="

Validation="SHA1"/>

<!-- STORAGE SETTINGS

Use StorageInfo to set the assembly and class which implement

the storage interfaces for the cache.

Modes: InProc, OutProc

-->

<StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Storages.SingletonCacheStorage" Mode="InProc" Validated="true" Encrypted="true" RemotingUrl="tcp://localhost:8282/CacheService" />

<!--StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Storages.SqlServerCacheStorage" Mode="InProc" ConnectionString="user id=sa;password=msljkdv1;Network=DBMSSOCN;DATABASE=cacheab;SERVER=msljksrv02" Encrypted="true" Validated="true" ApplicationName="Sports" RemotingUrl="tcp://localhost:8282/CacheService" /-->

<!--<StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Storages.MmfCacheStorage" Mode="InProc" BasePath="c:\mmfcache\" Encrypted="true" Validated="true" MmfDictionarySize="1048576" RemotingUrl="tcp://localhost:8282/CacheService"/>-->

<!--

MmfDictionarySize - It is the size (in bytes) of the dictionary object (in MmfCacheStorage) used to store the references of cache items.

-->

<!-- SCAVENGING SETTINGS

Use the ScavengingAlgorithm to set a class that will be executed when

scavenging is performed.

-->

<ScavengingInfo AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.Scavenging.LruScavenging" MemoryPollingPeriod="60" UtilizationForScavenging="80" MaximumSize="5"/>

<!-- EXPIRATION SETTINGS

Use the ExpirationCheckInterval to change the interval to check for

cache items expiration. The value attribute is represented in seconds.

-->

<ExpirationInfo Interval="1" />

</CacheManagerSettings>

<WebsharpExpirationPolicy>

<ExpirationPolicy ExpirationCheckInterval="60" AssemblyName="Microsoft.ApplicationBlocks.Cache" ClassName="Microsoft.ApplicationBlocks.Cache.ExpirationsImplementations.SlidingTime" />

</WebsharpExpirationPolicy>

</configuration>

2、 系统持久化配置信息

配置PersistenceProperty,对于Web应用系统,可以在Global.asax中配置,对于Windows应用程序,可以在程序初始化时设置。

下面是设置的一个例子:

PersistenceProperty pp=new PersistenceProperty();

pp.ConnectionString="server=127.0.0.1;uid=sa;pwd=;database=logisticsDemo;";//数据库连接字符串

pp.DatabaseType=DatabaseType.MSSQLServer; //数据库类型

pp.MapFileLocation=@"WebsharpTestLib,WebsharpTestLib.xml"; //XML定义文件的路径

pp.MapFileLocationTye=MapFileLocationType.Assembly; //XML文件路径的类型

pp.UserID="sa"; //数据库用户名,必须与数据库连接字符串中的用户名一致

pp.Password=""


[3] [4] [5] [6] [7] [8]

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 下一页

教程录入:admin    责任编辑:admin 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     
     
     
     

    asp连接mysql数据库

    asp连接mysql数据库-2

    frontpage2000教程---制作主页
    免责声明!本站资料大部分来自于互联网,其版权归原作者或其他合法者所有.如内容涉及或侵犯了您的权益,请通知本人,我将尽快处理!.欢迎您的光临。
    辽ICP备07003958号
    无师自通,伴你一生-教程网