Websharp use Instructions (5)

Source: Internet
Author: User
Tags definition interface
Query
for Web objects




Websharp provides the ability to query objects, which is provided through the query interface. The definition of the Query interface can be seen as follows: attached 1:websharp main interface definition--query





can use the query interface in the following ways:





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 a data access interface for direct manipulation of the database--dataaccess, which encapsulates the ado.net, which makes it easier for programmers to use ado.net functionality and can mask the differences between different databases. The definition of this interface can be seen as follows: attached 1:websharp main interface definition--dataaccess





can initialize a DataAccess object through the PersistenceManager newdataaccess method, and then invoke the appropriate methods to perform the desired function.










The processing of
business logic





With the above work, we can combine these objects and write our business logic. In object-oriented systems, business logic behaves as an interaction between objects. In some simple systems, there is no complex business logic, just some data maintenance work, then, with the above two parts of the work, we may actually have forgotten that most of the work.





The following is a simple example that represents the process of a warehouse receipt, in which you need to modify the inventory on hand for each product on the storage list:





public void Storeintowarehouse (Form insertform)





{





Formdetail Detail=insertform.formdetail;





detail. A ();





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





}





}








can see that, after using Websharp, the writing of business logic can become a very natural process, but also can save a lot of code.
















Provision of
Business services





The purpose of the Business Facade layer (Business façade) is to isolate the providers and users of system functionality, or, more specifically, the user interface of the software that isolates the business logic (see facade design patterns). You can use any of the existing methods to build this hierarchy, and in the example we provide, we use the Web service.








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.