Aquarium Express Primer 1 Aquarium Express Primer Aquarium Express is a new standard code generator project provided as an introduction to the capabilities of Data Aquarium Framework. This project can be used as a solid foundation for Web 2.0 applications of any complexity. Your application will be built with the state-of-the-art ASP.NET 3.5 and Ajax Control Toolkit. Aquarium Express Primer will showcase the capabilities of Data Aquarium Framework and includes complete source code in VB.NET and Visual C#. We will be developing a web order management application for a mail order company Northwind with Microsoft SQL Server 2005 and Code OnTime Generator. You have to have Visual Studio 2008 or free Visual Web Developer Express 2008 installed on your computer to work with the generated application. Click here to see a live demo of Aquarium Express Primer. Aquarium Express Primer 2 Start the code generator and create new Aquarium Express project named Northwind. Leave default settings and complete project source code generation. A browser window will open up with a default sample page. Close the browser and run your version of Visual Studio. Select File | Open Web Site menu option and browse to [My Documents]\Code OnTime\Aquarium Express\Northwind folder. Click Open button to open the project. Selection of Customers Create Forms folder in the root of the web site. Right-click Forms folder and select Add New Item option. Create a web form with name Customers and make sure to select its master page MasterPage.master available in the root of the web site. Change the page as shown below. <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Customers.aspx.cs" Inherits="Forms_Customers" Title="Customers" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="Header1Placeholder" runat="Server"> Customers </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="Header2Placeholder" runat="Server"> Northwind </asp:Content> <asp:Content ID="Content4" ContentPlaceHolderID="BodyPlaceholder" runat="Server"> <div id="CustomerList" runat="server" /> <aquarium:DataViewExtender ID="CustomerExtender" runat="server" Controller="Customers" Aquarium Express Primer 3 View="grid1" TargetControlID="CustomerList" /> </asp:Content> Control DataViewExtender is a cornerstone of web applications created with Data Aquarium Framework. Two key properties Controller and TargetControlID are providing data controller descriptor and presentation container target accordingly. If you view the page in a browser then the following presentation is rendered. Notice that whenever you click on any link in the left-most column the grid view is switch into form mode and customer details are presented. Let's change this behavior and have the page redirect to another web form and pass along ID of a selected customer. Open ~/Controllers/Customers.aspx page and change the actions with Grid scope to read as shown in example. <actionGroup scope="Grid"> <action commandName="Navigate" headerText="Show Orders" commandArgument="Orders.aspx?CustomerID={CustomerID}"/> Aquarium Express Primer 4 <action commandName="Select" commandArgument="editForm1" headerText="View Customer Information"/> <action commandName="Edit" /> <action commandName="Delete" confirmation="Delete?" /> <action whenLastCommandName="Edit" commandName="Update" headerText="Save" /> <action whenLastCommandName="Edit" commandName="Cancel" /> </actionGroup> Reference to the CustomerID field in the curly brackets will be replaced with an actual value when the first action is executed in a web browser. This happens if user clicks on a link or selects Show Orders context menu option. Order List Add Orders web form to the ~/Forms folder while following the same routine described above. Make the page markup look like this. <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Orders.aspx.cs" Inherits="Forms_Orders" Title="Orders" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="Header1Placeholder" runat="Server"> Orders </asp:Content> Aquarium Express Primer 5 <asp:Content ID="Content3" ContentPlaceHolderID="Header2Placeholder" runat="Server"> Northwind </asp:Content> <asp:Content ID="Content4" ContentPlaceHolderID="BodyPlaceholder" runat="Server"> <div id="Customer" runat="server" class="CustomerInfo" /> <aquarium:DataViewExtender ID="CustomerExtender" runat="server" Controller="Customers" View="editForm1" TargetControlID="Customer" ShowActionBar="false" /> <div id="OrderList" runat="server" /> <aquarium:DataViewExtender ID="OrderExtender" runat="server" Controller="Orders" View="grid1" TargetControlID="OrderList" /> </asp:Content> Open Customers form in a web browser and select any customer. The following views will be presented. Aquarium Express Primer 6 The form automatically filters orders to match the customer ID in the URL of the browser. You can immediately edit customer information and make all sorts of changes to the orders . As good as this screen looks there are quite a few deficiencies. The form is too long and we don't know what is the total amount of each order. Plus we don't really want to allow any order changes and would rather use a dedicated order edit form. First, we will make the form shorter. Add the following markup anywhere in the Content4 in Orders web form. <div id="Customers_editForm1" style="display: none"> <table style="width: 100%"> <tr> <td> {CustomerID} </td> <td style="font-weight: bold"> {CompanyName} </td> <td> {ContactName} </td> <td> {ContactTitle} </td> <td> {Phone} </td> <td> {City} </td> <td> {Country} </td> </tr> Aquarium Express Primer 7 </table> </div> This creates an invisible form templates, which is automatically used by Web.DataView java script component of Data Aquarium Framework. The component will use the field names in the curly brackets as placeholders for the data fields rendered in a browser. Refresh Orders page and the following view will be displayed. Notice that template ID is matched to editForm1 view when rendered for Customers controller. You can read additional discussion about form templates here. This new look is a substantial improvement over the previous version. Let's take out the row with the buttons under the customer form and descriptive text above the form. This will leave a clean panel with customer information above the orders. Create a CSS style sheet with name Northwind.css in ~/App_Themes/MyCompany folder. Enter the following text in the style sheet body. Aquarium Express Primer 8 .CustomerInfo .HeaderTextRow, .CustomerInfo .BottomButtonsRow { display:none; } The first Div element of the form is defined with a CSS class name. <div id="Customer" runat="server" class="CustomerInfo" /> Class CustomerInfo allows us to customize presentation of the header row with descriptive text and the bottom action buttons row. Customization is quite simple - we are not displaying either of them. Refresh the page to see it like that. Now let's add a total amount to each order line. Data Aquarium Framework automatically parses the queries in your data controller to construct select, update, insert, and delete SQL statements. We will create an additional view in Northwind database and join this view to the query in ~/Controllers/Orders.xml file. Please create Aquarium Express Primer 9 the following SQL view with SQL Management Studio or your favorite database management tool. CREATE view [dbo].[OrderTotals] as select "OrderDetails"."OrderID", sum("OrderDetails"."UnitPrice" * "OrderDetails"."Quantity" * (1 - "OrderDetails"."Discount")) "ItemsTotal" from "dbo"."Order Details" "OrderDetails" group by "OrderDetails"."OrderID" Then open the data controller file and change the text of command1 as shown below. <text> <![CDATA[ select "Orders"."OrderID" "OrderID" ,"Orders"."CustomerID" "CustomerID" ,"Customer"."CompanyName" "CustomerCompanyName" ,"Orders"."EmployeeID" "EmployeeID" ,"Employee"."LastName" "EmployeeLastName" ,"Orders"."OrderDate" "OrderDate" ,"Orders"."RequiredDate" "RequiredDate" ,"Orders"."ShippedDate" "ShippedDate" ,"Orders"."ShipVia" "ShipVia" ,"ShipVia"."CompanyName" "ShipViaCompanyName" ,"Orders"."Freight" "Freight" ,"Orders"."ShipName" "ShipName" ,"Orders"."ShipAddress" "ShipAddress" ,"Orders"."ShipCity" "ShipCity" ,"Orders"."ShipRegion" "ShipRegion" ,"Orders"."ShipPostalCode" "ShipPostalCode" ,"Orders"."ShipCountry" "ShipCountry" Aquarium Express Primer 10 ,(cast("OrderTotals"."ItemsTotal" as money)) "ItemsTotal" ,(cast("OrderTotals"."ItemsTotal" + "Orders"."Freight" as money)) "OrderTotal" from "dbo"."Orders" "Orders" left join "dbo"."Customers" "Customer" on "Orders"."CustomerID" = "Customer"."CustomerID" left join "dbo"."Employees" "Employee" on "Orders"."EmployeeID" = "Employee"."EmployeeID" left join "dbo"."Shippers" "ShipVia" on "Orders"."ShipVia" = "ShipVia"."ShipperID" left join "OrderTotals" on "Orders"."OrderID" = "OrderTotals"."OrderID" ]]> </text> The main points of interest are the left join at the bottom of the query and two fields at the end of the field clause. Both fields are defined as expression, which must be enclosed with parenthesis to help the regular expressions of Data Aquarium Framework to correctly identify the expression and the corresponding alias. The left join is linking in the new view. Add two new fields into /dataController/fields element. <field name="ItemsTotal" type="Decimal" readOnly="true" label="Items Total" dataFormatString="c"/> <field name="OrderTotal" type="Decimal" readOnly="true" label="Total" dataFormatString="c"/> Make sure to mark both fields as read-only. The data format string will ensure that both fields are displayed as currency. You can use alternative syntax for the data format string: {0:c}, which is compatible with String.Format function that you know and love. Move the grid view grid1 to be after the form view editForm1 to ensure that the edit form will become the default presentation view for Orders controller. Format fields in grid1 as displayed here.
Description: