Blog: Posts from September, 2012

Labels
AJAX(112) App Studio(7) Apple(1) Application Builder(245) Application Factory(207) ASP.NET(95) ASP.NET 3.5(45) ASP.NET Code Generator(72) ASP.NET Membership(28) Azure(18) Barcode(2) Barcodes(3) BLOB(18) Business Rules(1) Business Rules/Logic(140) BYOD(13) Caching(2) Calendar(5) Charts(29) Cloud(14) Cloud On Time(2) Cloud On Time for Windows 7(2) Code Generator(54) Collaboration(11) command line(1) Conflict Detection(1) Content Management System(12) COT Tools for Excel(26) CRUD(1) Custom Actions(1) Data Aquarium Framework(122) Data Sheet(9) Data Sources(22) Database Lookups(50) Deployment(22) Designer(177) Device(1) DotNetNuke(12) EASE(20) Email(6) Features(101) Firebird(1) Form Builder(14) Globalization and Localization(6) How To(1) Hypermedia(2) Inline Editing(1) Installation(5) JavaScript(20) Kiosk(1) Low Code(3) Mac(1) Many-To-Many(4) Maps(6) Master/Detail(36) Microservices(4) Mobile(63) Mode Builder(3) Model Builder(3) MySQL(10) Native Apps(5) News(18) OAuth(9) OAuth Scopes(1) OAuth2(13) Offline(20) Offline Apps(4) Offline Sync(5) Oracle(11) PKCE(2) Postgre SQL(1) PostgreSQL(2) PWA(2) QR codes(2) Rapid Application Development(5) Reading Pane(2) Release Notes(183) Reports(48) REST(29) RESTful(29) RESTful Workshop(15) RFID tags(1) SaaS(7) Security(81) SharePoint(12) SPA(6) SQL Anywhere(3) SQL Server(26) SSO(1) Stored Procedure(4) Teamwork(15) Tips and Tricks(87) Tools for Excel(2) Touch UI(93) Transactions(5) Tutorials(183) Universal Windows Platform(3) User Interface(338) Video Tutorial(37) Web 2.0(100) Web App Generator(101) Web Application Generator(607) Web Form Builder(40) Web.Config(9) Workflow(28)
Archive
Blog
Posts from September, 2012
Wednesday, September 19, 2012PrintSubscribe
Web App as Application Server

Code On Time web applications have a classic multitier architecture.

  • A backend database engine (Oracle, SQL Server, MySQL, etc.) provides the data tier.
  • The application tier is a generated application. It includes a standard framework with custom business rules created by a developer. Application framework interacts with the data tier. It automatically creates data manipulation SQL statements and invokes business rules as defined by the app configuration.
  • The presentation tier is a standard library implemented in JavaScript. The library is stored with the application files on the web server. The client library is downloaded by a web browser with application pages. The client library components interact with the server-side application framework and business rules.

The client library of the presentation tier has a model-view-controller architecture. It retrieves the model and view configuration from the application tier and presents data in a web browser window. It also sends user-initiated actions to the application framework for execution.

A web app configuration information and data are traveling between application and presentation tiers over HTTP protocol through a single web service implemented in the application framework. The presence of configuration information allows the same client library to be used in many applications without the need for heavy customization of generated apps.

The standard client library can be enhanced with new capabilities and even replaced to support new types of client devices.

Here is an example of Customers data controller from the Northwind sample created with Code On Time.

The highlighted view createForm1 includes the fields from the model  The highlighted action ag3 / a1 requires command New to be executed with the argument createForm1

The highlighted view createForm1 includes the fields from the model.

The highlighted action ag3 / a1 specifies that New command must be executed with the argument createForm1.

These application configuration elements do not imply any specific implementation. A developer can put together a custom app based on such configuration. The client library of a Code On Time web application provides just one of the many possible implementations.

This is how the client library of a Code On Time web app interprets the application configuration of the 'Customers' data controller

Northwind database is the data management system of a mail order trading company. In minutes, a developer can generate a fully functional secure web app straight from the database. The app can be used for back office data management of orders and inventory by company employees.

Today, it is expected that the business data is available literally everywhere – any device and any platform must be supported.

Suppose that the public-facing web site of Northwind Traders must be enhanced to allow self-registration of customers. The web site is deployed to a Linux web server.

This is how the form may look.

This sample form can be used to register new customers in a web app created with Code On Time Unlimited edition

The registration form users are anonymous and have no access to the back office system. The operating system of the web app is Microsoft Windows. The app is deployed to a dedicated Windows Azure server, while the public web site is running on a Linux server hosted by a different provider.

A web app created with Code On Time offers an amazingly simple and powerful solution to this challenge.

Create a file with “.htm” extension with the following HTML markup.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Customer Registration Form</title>
</head>
<body>
    <form action="http://demo.codeontime.com/northwind/appservices/Customers" method="post">
    <table>
        <tr>
            <td>
                Customer ID
            </td>
            <td>
                <input type="text" name="CustomerID" size="5" />
            </td>
        </tr>
        <tr>
            <td>
                Company Name
            </td>
            <td>
                <input type="text" name="CompanyName" size="40" />
            </td>
        </tr>
        <tr>
            <td>
                Phone
            </td>
            <td>
                <input type="text" name="Phone" size="24" />
            </td>
        </tr>
    </table>
    <input type="submit" value="Register" />
    <!-- redirection parameters  -->
    <input type="hidden" name="_successUrl" value="http://codeontime.com/buy" />
    <input type="hidden" name="_errorUrl" value="http://codeontime.com/support" />
    </form>
</body>
</html>

Open the file in your favorite web browser, fill the form, and hit “Register” button. If the primary key of the new customer is unique, then a new customer record will be automatically created in the database of http://demo.codeontime.com/northwind web app and you will be redirected to the URL specified in _successUrl parameter. Otherwise the browser will be redirected to the URL specified in _errorUrl parameter. The _error variable added to the URL will indicate the source of the problem.

Sign in the application to locate the new registration record at http://demo.codeontime.com/Northwind/Pages/Customers.aspx. Enter admin/admin123% credentials to access the page if prompted.

The data records of a self-registered customer created as a result of standard HTML form submission

The demo application at http://demo.codeontime.com/northwind “listens” to HTTP requests that start with “/appservices” prefix.

If you click on the link http://demo.codeontime.com/northwind/appservices/Customers specified in the “action” attribute of the form, then an XML list of customers will be returned. The web browser will use HTTP GET method when requesting the URL.

The form declares that HTTP POST method shall be used when the form is submitted. The demo app will interpret the request as a command to insert a data row. The application data controller will automatically use createForm1 to perform the action. If there are any custom business rules defined in the app, then they will be automatically engaged as well and may effect the result of the action.

The application framework of a Code On Time web app provides a full fledged custom application server. Developer creates application server APIs  by customizing views, actions, and business rules in the application data controllers. From the developer’s prospective, the customization of these project configuration elements results in a made-to-measure user interface. All of a sudden this work goes a long way towards creating a highly reusable application server.

The user interface of a Code On Time web app can be used on its own or function as a test platform for the application server APIs of the next killer app created for any platform supporting HTTP, JSON, and XML.

The application framework includes components that implement support for Representational State Transfer also known as REST.  The application can handle HTTP requests to the  built-in custom application server with responses encoded in JSON or XML when enabled.

Tuesday, September 11, 2012PrintSubscribe
Creating Calculated Fields

The picture below shows the Order Details form in edit mode.

Order Details edit form displayed without an Extended Price field.

Let’s create a calculated field called Extended Price that will display the extended price of the Order Details item.

Calculated fields are also known as virtual fields. The field value is not stored in the database - it is calculated at runtime based on values of other fields in the data row.

Creating the virtual Field

Activate the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on OrderDetails / Fields node, and press New Field.

New Field context menu option for OrderDetails controller in the Project Explorer.

Assign the following values:

Property Value
Name ExtendedPrice
Type Currency
Label Extended Price
Allow Query-by-Example true
Allow Sorting true

Press OK to save. Drag OrderDetails / Fields / ExtendedPrice node onto OrderDetails / Views / grid1 node to bind the field to the view grid1.

Dragging ExtendedPrice field node onto 'grid1' view.     Data field 'ExtendedPrice' created in view 'grid1'.

Drag OrderDetails / Fields / ExtendedPrice node onto OrderDetails / Views / editForm1 / c1 – Order Details node to bind the field to view editForm1.

Dragging 'ExtendedPrice' field onto 'c1 - Order Details' category node.     Data Field 'ExtendedPrice' created in 'c1 - Order Details' category.

Finally, drag OrderDetails / Fields / ExtendedPrice node onto OrderDetails / Views / createForm1 node.

Dragging 'ExtendedPrice' field onto 'createForm1' view node.     Data field 'ExtendedPrice' created in view 'createForm1'.

A binding of field to a view is called a data field.

On the toolbar, press Browse and navigate to the Order Manager page. The Extended Price data field is visible in the grid and in the form views of Order Details. However, the field is rendered as blank.

Extended Price field is available as a blank field in grid view and create form.

Note that if you have a custom category template associated with the form view, then the field will not be visible automatically. In that case, the custom category template for editForm1 needs to be updated to display the data field.

Read the next section to learn how to include the new virtual data field in the template, or skip to the following section discussing how to provide an SQL Formula for the field.

Updating the Custom Category Template

Switch to the Project Designer. In the Project Explorer, switch to the Pages tab. Right-click on Order Manager / c103 / control1 node and press Edit in Visual Studio.

Edit in Visual Studio context menu option in the Project Explorer.

The template file will be opened in Visual Studio. Replace the existing code after the <%@ Control %> element with the following:

<div style="display: none;">
    <div id="OrderDetails_editForm1_c1">
        <table>
            <tr>
                <td style="padding-right: 36px;font-weight:bold;">Product:</td>
                <td style="padding-right: 18px;">
                    <span class="FieldPlaceholder DataOnly">{ProductID}</span>
                </td>
                <td style="padding-right: 18px;">Discount:</td>
                <td>
                    <span class="FieldPlaceholder DataOnly">{Discount}</span>
                </td>                
            </tr>
            <tr>
                <td>Unit Price:</td>
                <td>
                    <span class="FieldPlaceholder DataOnly">{UnitPrice}</span>
                </td>
                <td>Quantity:</td>
                <td>
                    <span class="FieldPlaceholder DataOnly">{Quantity}</span>
                </td>
                <td style="padding-left:18px;"><i>Extended Price:</i></td>
                <td>
                    <span class="FieldPlaceholder DataOnly">{ExtendedPrice}</span>
                </td>
            </tr>
        </table>
    </div>
</div>

Save the file, and refresh the webpage. The Extended Price data field will be displayed in edit form.

Extended Price field has been added to the Order Details category.

SQL Formula

Let’s provide an SQL expression evaluated when the data rows of order details are selected from the database.

In the Project Explorer, switch to the Controllers tab and double-click on OrderDetails / Fields / ExtendedPrice node.

ExtendedPrice field node of OrderDetails controller in the Project Explorer.

Change the following:

Property New Value
The value of this field is computed at run-time by SQL expression. true
SQL Formula
OrderDetails.UnitPrice * OrderDetails.Quantity * (1 - OrderDetails.Discount)
Values of this field cannot be edited true
Data Format String c

Press OK to save the field. On the toolbar, press Browse. The Extended Price field will not be editable, and the value will be presented when the form is rendered.

Extended Price is rendered as a read-only field that is calculated when the form is rendered.

SQL Formula provides the highest possible performance for the calculation since it is being evaluated by the database engine. The complexity of calculated fields depends on the capabilities of the database engine. There are numerous built-in functions that the developer can take advantage of.

Fields based on SQL Formula can be sorted and filtered with the highest possible performance as well.

Calculating Field Values Just-in-Time

Extended Price is not recalculated when a user changes values of Unit Price, Discount, or Quantity fields.

Extended Price field is not updated when the other fields are changed.

The SQL Formula of the Extended Price field is evaluated only when the data is selected from the database. If the user makes changes in the browser window, the values will not be submitted to the server until the record is saved. Developers can implement a server-side or client-side calculation that will be performed just-in-time as users change the values of the formula’s base fields.

The application framework includes a business rule engine that allows implementing rules in SQL, C#/Visual Basic, or JavaScript.

SQL and C#/Visual Basic business rules require a round-trip between the web browser and the web server. They can look up database information and interact with external systems when necessary.

JavaScript business rules are executed in the browser and provide the highest possible performance when server-side data is not required for calculation.

Let’s consider implementing the calculation using all three flavors of business rules. Note that the developer needs only one of them to accomplish just-in-time calculation of Extended Price.

SQL Business Rule

In the Project Explorer, double-click on OrderDetails / Fields / ExtendedPrice node.

ExtendedPrice field in the OrderDetails controller.

Make the following changes:

Property New Value
The value of this field is calculated by a business rule expression. true
Context Fields UnitPrice,Quantity,Discount

Press OK to save. Right-click on OrderDetails / Business Rules node, and press New Business Rule.

New Business Rule context menu option for OrderDetails controller in the Project Explorer.

Assign these values:

Property Value
Type SQL
Command Name Calculate
Phase Execute
Script
set @ExtendedPrice = @UnitPrice * @Quantity * (1 - @Discount)

Press OK to save. On the toolbar, press Browse. Select and start editing an Order Details record.

Order Details form without any changed values.

Change the value in Quantity field. Press Enter or shift the focus to a different field. The Extended Price will be updated.

When focus is shifted away from the field, the Extended Price field will be recalculated.

The client library executes Calculate action, which causes transfer of field values to the server. The application framework will pass the business rule script along with the parameter values to the database engine for execution. Then, it evaluates parameters and returns changed values to the client web browser.

SQL business rules involve client, application server, and database engine tiers. The advantage of SQL business rules is the ability to access any database information when necessary.

Code Business Rule

The business rule can also be implemented using C# or Visual Basic.

If you have the SQL business rule created in the previous section, then you will need to delete or rename the business rule. Double-click on OrderDetails / Business Rules / Calculate node.

Calculate business rule in Order Details controller.

Change the Command Name property:

Property Value
Command Name DoNotRun

Press OK to save. Alternatively, business rule r100 can be deleted.

Right-click on OrderDetails / Business Rules node, and press New Business Rule.

New Business Rule context menu option for Order Details controller in the Project Explorer.

Assign these values:

Property Value
Type C# / Visual Basic
Command Name Calculate
Phase Execute

Press OK to save.

Code business rule files do not exist until the application generator has created them. On Project Designer toolbar, press Browse.

When complete, right-click OrderDetails / Business Rules / Calculate business rule node, and press Edit Rule in Visual Studio.

Edit Rule in Visual Studio context menu option for Code business rule.

The file will be opened in Visual Studio. The entire class definition and parameters of the business rule method are already defined.

Replace the body of the rule with the call of UpdateFieldValue method:

C#:

using System;
using MyCompany.Data;

namespace MyCompany.Rules
{
    public partial class OrderDetailsBusinessRules : MyCompany.Data.BusinessRules
    {
        
        [Rule("r101")]
        public void r101Implementation(int? orderID, 
            string orderCustomerID, string orderCustomerCompanyName, 
            string orderEmployeeLastName, string orderShipViaCompanyName, 
            int? productID, string productProductName, string productCategoryCategoryName, 
            string productSupplierCompanyName, decimal? unitPrice, short? quantity, 
            float? discount, decimal? extendedPrice)
        {
            UpdateFieldValue("ExtendedPrice", 
                Convert.ToDouble(unitPrice.Value) * quantity.Value * (1 - discount.Value));
        }
    }
}

Visual Basic:

Imports MyCompany.Data
Imports System

Namespace MyCompany.Rules

    Partial Public Class OrderDetailsBusinessRules
        Inherits MyCompany.Data.BusinessRules

        <Rule("r101")> _
        Public Sub r101Implementation(
                ByVal orderID As Nullable(Of Integer),
                ByVal orderCustomerID As String,
                ByVal orderCustomerCompanyName As String,
                ByVal orderEmployeeLastName As String,
                ByVal orderShipViaCompanyName As String,
                ByVal productID As Nullable(Of Integer),
                ByVal productProductName As String,
                ByVal productCategoryCategoryName As String,
                ByVal productSupplierCompanyName As String,
                ByVal unitPrice As Nullable(Of Decimal),
                ByVal quantity As Nullable(Of Short),
                ByVal discount As Nullable(Of Single),
                ByVal extendedPrice As Nullable(Of Decimal)
            )
            UpdateFieldValue("ExtendedPrice",
                Convert.ToDouble(unitPrice.Value) * quantity.Value * (1 - discount.Value))
        End Sub
    End Class
End Namespace

Save the file, and refresh the webpage.

The same behavior as with the SQL business rule will be exhibited every time a context field is changed in the form. The client library will make a short trip to the web server to perform the calculation. The application framework will call the business rules class method which is linked to the business rule defined in OrderDetails data controller.

JavaScript Business Rule

If the values of the base fields are known on the client at the time when a calculation needs to be performed, then the web server round-trip is redundant. JavaScript business rules offer an option to implement complex logic executed by the web browser.

First, disable execution of the previously created C#/Visual Basic business rule. Double-click on OrderDetails / Business Rules / Calculate node.

SQL business rule 'Calculate' of OrderDetails controller in the Project Explorer.

Change the Command Name property:

Property Value
Command Name DoNotRun

Press OK to save. Alternatively, business rule r101 can be deleted.

Right-click on OrderDetails / Business Rules node, and press New Business Rule.

New Business Rule context menu option for Order Details controller.

Assign these values:

Property Value
Type JavaScript
Command Name Calculate
Phase Execute
Script
[ExtendedPrice] = [UnitPrice] * [Quantity] * (1 - [Discount]);
this.preventDefault();

At runtime, the client library will automatically translate the script into the following JavaScript code:

this.updateFieldValue('ExtendedPrice', 
    this.selectFieldValue('UnitPrice') * 
    this.selectFieldValue('Quantity') * 
    (1 - this.selectFieldValue('Discount')));
this.preventDefault();

Press OK to save. On the toolbar, press Browse. Open the form view of an order detail.

Order Details form without any changed values.

Change a value in one of the fields. Press Tab to shift focus away from the field. The Extended Price will automatically be updated without performing a server request.

When focus is shifted from a field, the Extended Price will be recalculated.

The call of the method preventDefault() will prevent the client library from processing the Calculate action on the server.

Friday, September 7, 2012PrintSubscribe
Creating Many-to-Many Fields

The Northwind database features a many-to-many relationship between Territories and Employees.

Many-to-many relationship between Employees and Territories.

The app generator will create a page for EmployeeTerritories that allows editing records directly.

Employee Territories page allows setting up relationships between employees and territories directly.

EmployeeTerritories is also available as a child data view on the Employees page. Selecting an employee will reveal a list of related territories.

Employee Territories child data view allows editing territories associated with the selected employee.

Let’s create a many-to-many field on the employee edit form that will allow selecting territories in a check box list. Each option in the list will represent a territory from the Territories table. The checkbox next to the territory name will be checked if there is a record in the EmployeeTerritories table linking the selected employee with the territory. The relevant EmployeeTerritories records will be inserted or deleted when the user changes the selection of checkboxes and saves the employee record.

Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Right-click on Employees / Fields node, and press New Field.

New Field context menu option for Employees controller.

Give this field the following values:

Property Value
Name Territories
Allow null values true
The value of this field is computed at run-time by SQL expression. true
Label Territories
Items Style Check Box List
Items Data Controller Territories
Data Value Field TerritoryId
Data Text Field TerritoryDescription
Target Controller EmployeeTerritories

Press OK to save the field.

Drag Employees / Fields / Territories field node onto Employees / Views / editForm1 view node.

Dragging Territories field node onto 'editForm1' view node.

Double-click on Employees / Views / editForm1 / Territories data field node.

Territories data field node in editForm1 view of Employees controller.

Change the Columns property:

Property Value
Columns 5

Press OK to save. Switch to the Pages tab. Right-click on Employees page node, and press View in Browser.

View in Browser context menu option for Employees page.

View the details for an employee. Territories field will display a comma-separated list of values associated with the employee.

Territories many-to-many field will render a comma separated list of values.

Press Edit button. All territories will be rendered as a check box list.

When the form is in edit mode, all territories are rendered in a check box list.

Check or uncheck several values, and press OK to save the record. Select the record to verify that the changes were persisted.

Changing the Child Views

The Employee Territories child data view is now unnecessary.

Switch back to the Project Designer. In the Project Explorer, right-click on Employees / container2 / view4 node, and press Delete.

Delete context menu option for 'view4' on Employees page.

Drag view3 node on the left side of view2 to place it in the first position.

Dragging 'view3' view node on the left side of 'view2' view node.     View 'view3' has been placed before 'view2'.

Right-click on Employees page node, and press View in Browser.

View in Browser context menu option for Employees page node in the Project Explorer.

Select an employee from the list, and the Orders and Employees child data view tabs will appear below. The Employee Territories child data view tab is no longer present. The picture also shows the many-to-many field Territories in the master grid view.

Employees page no longer has the Employee Territories data view.

Continue to Configuring Charts