Wednesday, May 30, 2012

Configuring a Multi-Line Text Box

The application generator automatically configures memo (long text) fields as multi-line text boxes. The column Categories.Description from the Northwind sample is an example of a memo field.

Description field on Categories edit form rendered as a multiline text box.

The property Rows of the Categories.Description data field has a default value of “5”. Changing the number of rows of the data field to “1” will convert the field into a single-line text box.

Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Double-click on Categories / Fields / Description field node.

Description field of Categories controller in the Project Explorer.

At the top of the Designer window, switch to the Data Fields tab. Change all data fields as shown next:

Property New Value
Rows 1

Change all Categories data fields Rows property to '1'.

Save all changes, and click Browse on the toolbar.

When the web app opens in your default web browser, navigate to the Categories page and edit a record. The Description field is now rendered as a single-line text box.

Description field on Categories edit form rendered as a single line text box.

The Rows property of standard string fields is blank. Changing it to any value greater than “1” will convert the data field into a multi-line text box.

Multi-Field Copy

When a new order is created in the Northwind database, users will select a customer using the Customer Company Name lookup field. This action can result in automatic population of the shipping information.

Orders create form with a selected customer. The shipping information is not copied over.

Let’s make an assumption that fields Ship Name, Ship Address, Ship City, Ship Region, Ship Postal Code, and Ship Country should default to the customer’s Contact Name, Address, City, Region, Postal Code, and Country values when a lookup value is selected.

Lookup list of Customers

Start the Project Designer. In the Project Explorer, switch to the Controllers tab. Double-click on Orders / Fields / CustomerID field node.

CustomerID field of Orders controller in the Project Explorer.

List the fields that will be copied in the Copy property. The field on the right is from the lookup, and the field on the left is the copy destination. Note that the field must be present in the lookup view in order for the value to be copied. If a field needs to be copied but not displayed to the end user, add the field as hidden.

Property New Value
Copy

ShipName=ContactName
ShipAddress=Address
ShipCity=City
ShipRegion=Region
ShipPostalCode=PostalCode
ShipCountry=Country

Press OK to save the field. On the tool bar, press Browse.

When the web application opens in your default web browser, navigate to the Orders page and create an order. Select a customer using the lookup. The shipping information will be copied from the customer to the order.

Orders create form with a selected customer. The shipping information is copied from the Customer.

Navigate to Customers page and select a customer Bon app’ in the master view. On the action bar of the detail view Orders, click New Orders. The client library will automatically perform reverse lookup. The customer is already known, and the contact information will be copied over by the Customer Company Name lookup field, despite the fact that it is hidden on the form.

Reverse Lookup in action in web application created with Code On Time.

Data Views: Search On Start

By default, grid and data sheet views will open the first page of records.

Suppliers grid view showing the first page of suppliers.

If the number of records is small, then it works great. If the number of records is very large, then it is pointless to display the first page before the users specify what they are looking for. The data view can be configured to not request any records and have Advanced Search Bar open by default.

Start the Project Designer. Double-click on Region / Suppliers / container1 / view1 data view node.

'View1' on Suppliers page of Project Explorer.

Change the following property:

Property New Value
Search On Start True

Press OK to save the data view, and click on Browse to generate the web application.

When the web page opens in the browser, navigate to the Suppliers page. The data view will open in search mode.

Suppliers grid view opened in search mode with Advanced Seearch Bar displayed and no records requested.

You can pull the first page of data by pressing the Search button without specifying any search parameters. If you enter parameters, then the matching records will show up.

Pressing 'Search' on the search bar will request the first page of records.

If the search bar is disabled, then the Quick Find will be available to enter the initial search criteria.

Search On Start allows users to enter criteria in the Quick Find if Advanced Search Bar is unavailable.

Controlling Data Field Search Modes

The Advanced Search Bar allows the user to combine specific search parameters in order to find data. When the search bar is first opened, the first three data fields in the grid view are displayed.

Customers advanced search bar with default Search Mode settings.

The end user can change the filter field using the field name dropdown. By default, all data fields that exist in the grid view are searchable. The user can be forced to enter a value in some search fields, while other fields may be suggested as additional options when the search bar opens for the first time. Users can also be prevented from searching by specific fields.

Start the Project Designer. Right-click on Customers / container1 / view1 / grid1 view node, and click Show All Data Fields option.

Show all data fields for grid1 view of Customers controller.

Make the following changes to the list of data fields:

Field Name Search
CompanyName Required
ContactName Forbidden
ContactTitle Forbidden
Address Suggested
City Suggested

Save the data fields, and select Browse on the tool bar to regenerate the web application.

When the browser window opens, navigate to the Customers page and open the advanced search bar. The data fields with Search Mode of “Required” or “Suggested” will be displayed initially.

Advanced search bar of Customers grid displaying required and suggested fields.

The first field is required, and cannot be changed.

The required field cannot be changed.

If a search is performed without entering a parameter into required Company Name field, the user will be informed that the field is required.

Search performed without entering a parameter into the required field will give a prompt to the end user.

Fields marked as “Forbidden” are not displayed on the list of fields available for search.

Forbidden fields are not displayed on the list of fields.

Using Data Format String to Display Images

Data Format String can be used to produce any custom HTML markup in place of a data field. For example, you can create an img tag that uses field values to reference static images stored elsewhere. Suppose that the Northwind sample application has an Images folder that contains images of each employee. The file name of each image not counting the extension is the same as the EmployeeID.

Images folder containing images of all employees with file name matching the EmployeeID.

Let’s create a calculated field that will display the image from the folder.

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

Create New Field for Employees controller in Project Explorer.

Give this field the following properties:

Property Value
Name PathToImage
Type String
Allow Null Values True
The value of this field is computed at run-time by SQL expression. True
SQL Formula
"Employees"."EmployeeID"
Label Image
Values of this field cannot be edited True
HTML Encoding False
Data Format String
<img src="../images/{0}.png" style="width: 100px; border-radius: 10px;"/>

The Data Format String property references the value of the field as {0}.

Press OK to save the field. In the Project Explorer, right-click on Employees / Views / grid1 view node, and click New Data Field.

New Data Field in grid1 view of Employees controller.

Use the following values:

Property Value
Field Name PhotoPathImage

Press OK to save the data field, and click Browse on the tool bar to generate the web application.

When your default web browser opens, navigate to Employees page. There will be an Image column that displays the images from the external folder.

Image field displaying the photo from the external folder.

Friday, May 25, 2012

Show Action Bar

The action bar is at the top of every view, and allows the user to access Advanced Search Bar, Quick Find, and various actions within “Action Bar” scope.

Employees grid view with Action Bar enabled.

You may want to hide the action bar in certain situations.

Start the Project Designer. In the Project Explorer, double-click on Employees / container1 / view1 data view node.

'View1' data view on Employees page in Code On Time Project Explorer.

Change the following properties:

Property New Value
Show Action Bar False

Press OK to save the data view, and click Browse on the tool bar.

Navigate to the Employees page. The action bar is no longer displayed. Users can still create, edit, and delete records using the context menu on each row.

Employees grid view with Action Bar disabled.

Feature: Automatic Search Bar

The Advanced Search Bar is available in all grid and data sheet views. The Search Bar can be activated by clicking on the Chevron icon Advanced Search Bar on the action bar next to Quick Find. It requires no additional configuration and automatically displays the first three data fields in the view.

Advanced Search Bar activated in the Employees grid view.

It allows end users to form complex and specific queries to find the data they need. This capability complements Quick Find.

Advanced search bar with complex search query.

When necessary, the available fields and filter options can be configured.

Learn more about using Advanced Search Bar.

Using Automatic Search Bar

The Quick Find box is used to perform quick searches of the data. If a more specific query needs to be composed, the Search Bar is a readily available option. The Search Bar can be activated by clicking on the Chevron icon Automatic Search Bar on the action bar next to Quick Find.

Click on the chevron icon to the left of Quick Find to open the Search Bar.

The Search Bar will open under the action bar. By default, the first three visible data fields are available for filtering.

Developers can preconfigure the search bar to display specific fields and available filtering operations when the action bar is activated for the first time. The search bar may be displayed on start without retrieving the first page of data in page data views and lookup fields.

Employee grid view with Advanced Search Bar activated.

The first dropdown allows you to select a filter field. Visible and hidden data fields are available for selection.

The first dropdown on the Search Bar determines the field.

The second dropdown specifies the filter operation on the field. The type of the field determines which operations are available. The filter operations are configurable.

The second dropdown on the Search Bar determines the filter operation.

Enter your filtering parameters in the textbox. The textbox has autocomplete capabilities.

Search parameter field has auto complete capabilities.

If the filter parameters are dates, then a date picker is available.

image

You can clear a filter by clicking the Clear Filter iconClear Filter on the right side of the input field.

Clear the filter using the Clear Filter icon on the right side of the field.

You can add additional filters by clicking on the Plus iconAdd Filter or on the link Add search condition at the bottom of the search bar. Remove a filter by clicking on the Minus icon Remove Filter to the right of the filter.

Add search condition by clicking on the '+' icon.

The Reset button on the right side will reset the filter parameters in the search bar to match the current filter in the grid view.

The Reset button resets the filter to match the grid filter.

You can close the Search Bar and bring back Quick Find by clicking on the Chevron icon Advanced Search on the left side of the action bar.

Close or open the search by clicking on the chevron icon on the left side of the action bar.

Thursday, May 24, 2012

Conditional CSS Styling

Suppose that you need to visually highlight order details with a Unit Price above $30 or a Discount equal to or greater than 15% in the following data view.

Order Details page without any conditional CSS styling.

Start the Project Designer. In the Project Explorer, switch to the Controllers tab, and double-click on OrderDetails / Views / grid1 view node.

'Grid1' view of OrderDetails controller in Project Explorer.

In the left top corner of the Designer window, switch to the Styles tab. On the action bar, select New | New Style option.

Create a new Style on the Styles tab of Project Designer.

Give this style the following properties:

Property Value
Css Class
HighDiscount
Test [Discount]>=.15

Press OK to save. Create another style:

Property Value
Css Class
TooExpensive
Test [UnitPrice]>=30

Press OK to save the style. On the tool bar, press Browse to generate the web application. Navigate to the Order Details page.

We will be using Internet Explorer 9’s Developer Tools. Many other browser have similar tools or add-ons.

On your keyboard, press F12 to access Developer Tools. On the tool bar, click on the Refresh icon and then click on the Arrow icon to enter Inspection mode. Mouse over a row that has a Unit Price above $30 and click on it.

Inspecting a row in the Order Details grid view, you can see that the proper CSS classes have been assigned.

The selected HTML element will be displayed on the HTML tab. You can see that the row has the classes “Row” and “TooExpensive” – we can use this class to assign a style to rows. If you scroll down, you can find rows with the class “HighDiscount” as well.

Switch back to the web application generator, click on the project name, and choose Develop to open the project in Visual Studio. In the Solution Explorer, right-click on ~\App_Themes\MyCompany, and press Add New Item option. If you changed your namespace, add the item in the corresponding folder.

Add New Item to MyCompany folder of the project.

Select Style Sheet item, and press Add to create a new style sheet.

Add a Style Sheet file to the folder.

Replace the default text with the following rules:

tr.TooExpensive td.Cell
{
    background-color:#ffe79c!important;
    border-color:#ffe79c!important;
}

tr.HighDiscount td.Discount
{
    background-image:none!important;
    background-color:#9C0B12!important;
    color:white;
}

tr.TooExpensive.Highlight td.Cell
{
    background-color:#C5C5C5!important;
    border-color:#9E9E9E!important;
}

The first class will change the background color of all Order Details with Unit Price above $30 to yellow. The second class will change the background color of all Discount cells greater than 15% to red. The third class will improve the presentation for selected items.

Save the file, and refresh the web page. You will see that the CSS styles work as planned, and the relevant information is much easier to see at a glance.

Order Details grid view with conditional CSS styling.

You can find more about Code OnTime Generator, Data Aquarium Framework, and other great products here.


© 2010 Code OnTime LLC. Intelligent code generation software for ASP.NET. Visit us at http://codeontime.com