WebSharp instructions (5)

zhaozj2021-02-16  47

Object query

Websharp provides the function of the object query, which is available through the Query interface. The definition of the Query interface can be seen: attached 1: Websharp main interface definition - Query

You can use the Query interface by the following approach:

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 also provides data access interfaces for direct manipulating databases - DataAccess, this interface has been packaged in ADO.NET, allowing programmers to use ADO.NET's functionality, and can block different databases. The definition of this interface can be seen: attached 1: Websharp main interface definition - DataAccess

A DataAccess object can be initially initialized through the NewDataAccess method of the PersistenceManager and then call the appropriate way to perform the features you need.

Business logic processing

With the work above, we can combine these objects to write our business logic. In an object-oriented system, the business logic appears to be interactive between objects. In some simple systems, there is no complex business logic, just some data maintenance work, then there are two parts of the above, we actually have already forgotten most of the work.

The following is a simple example, which means a process of incorporating a library list. In this process, you need to modify the existing stock of each product on the library:

Public Void StoreIntoWarehouse (form insertform)

{

Formdetail Detail = Insertform.formDetail;

Detail.first ();

PersistenceManager PM = persistenceManagerFactory.instance (). CREATEPERSISISTENCEMANAGER ();

TransactionTM = 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 ();

}

}

It can be seen that after using Websharp, the writing of business logic can become a very natural process, and many code quantities can also be saved.

Business service

转载请注明原文地址:https://www.9cbs.com/read-26559.html

New Post(0)